6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
22 #include "exec/exec-all.h"
24 #include "tcg-op-gvec.h"
27 #include "translate.h"
28 #include "internals.h"
29 #include "qemu/host-utils.h"
31 #include "hw/semihosting/semihost.h"
32 #include "exec/gen-icount.h"
34 #include "exec/helper-proto.h"
35 #include "exec/helper-gen.h"
38 #include "trace-tcg.h"
39 #include "translate-a64.h"
40 #include "qemu/atomic128.h"
42 static TCGv_i64 cpu_X[32];
43 static TCGv_i64 cpu_pc;
45 /* Load/store exclusive handling */
46 static TCGv_i64 cpu_exclusive_high;
48 static const char *regnames[] = {
49 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
50 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
51 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
52 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
56 A64_SHIFT_TYPE_LSL = 0,
57 A64_SHIFT_TYPE_LSR = 1,
58 A64_SHIFT_TYPE_ASR = 2,
59 A64_SHIFT_TYPE_ROR = 3
62 /* Table based decoder typedefs - used when the relevant bits for decode
63 * are too awkwardly scattered across the instruction (eg SIMD).
65 typedef void AArch64DecodeFn(DisasContext *s, uint32_t insn);
67 typedef struct AArch64DecodeTable {
70 AArch64DecodeFn *disas_fn;
73 /* Function prototype for gen_ functions for calling Neon helpers */
74 typedef void NeonGenOneOpEnvFn(TCGv_i32, TCGv_ptr, TCGv_i32);
75 typedef void NeonGenTwoOpFn(TCGv_i32, TCGv_i32, TCGv_i32);
76 typedef void NeonGenTwoOpEnvFn(TCGv_i32, TCGv_ptr, TCGv_i32, TCGv_i32);
77 typedef void NeonGenTwo64OpFn(TCGv_i64, TCGv_i64, TCGv_i64);
78 typedef void NeonGenTwo64OpEnvFn(TCGv_i64, TCGv_ptr, TCGv_i64, TCGv_i64);
79 typedef void NeonGenNarrowFn(TCGv_i32, TCGv_i64);
80 typedef void NeonGenNarrowEnvFn(TCGv_i32, TCGv_ptr, TCGv_i64);
81 typedef void NeonGenWidenFn(TCGv_i64, TCGv_i32);
82 typedef void NeonGenTwoSingleOPFn(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_ptr);
83 typedef void NeonGenTwoDoubleOPFn(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_ptr);
84 typedef void NeonGenOneOpFn(TCGv_i64, TCGv_i64);
85 typedef void CryptoTwoOpFn(TCGv_ptr, TCGv_ptr);
86 typedef void CryptoThreeOpIntFn(TCGv_ptr, TCGv_ptr, TCGv_i32);
87 typedef void CryptoThreeOpFn(TCGv_ptr, TCGv_ptr, TCGv_ptr);
88 typedef void AtomicThreeOpFn(TCGv_i64, TCGv_i64, TCGv_i64, TCGArg, TCGMemOp);
90 /* initialize TCG globals. */
91 void a64_translate_init(void)
95 cpu_pc = tcg_global_mem_new_i64(cpu_env,
96 offsetof(CPUARMState, pc),
98 for (i = 0; i < 32; i++) {
99 cpu_X[i] = tcg_global_mem_new_i64(cpu_env,
100 offsetof(CPUARMState, xregs[i]),
104 cpu_exclusive_high = tcg_global_mem_new_i64(cpu_env,
105 offsetof(CPUARMState, exclusive_high), "exclusive_high");
108 static inline int get_a64_user_mem_index(DisasContext *s)
110 /* Return the core mmu_idx to use for A64 "unprivileged load/store" insns:
111 * if EL1, access as if EL0; otherwise access at current EL
115 switch (s->mmu_idx) {
116 case ARMMMUIdx_S12NSE1:
117 useridx = ARMMMUIdx_S12NSE0;
119 case ARMMMUIdx_S1SE1:
120 useridx = ARMMMUIdx_S1SE0;
123 g_assert_not_reached();
125 useridx = s->mmu_idx;
128 return arm_to_core_mmu_idx(useridx);
131 static void reset_btype(DisasContext *s)
134 TCGv_i32 zero = tcg_const_i32(0);
135 tcg_gen_st_i32(zero, cpu_env, offsetof(CPUARMState, btype));
136 tcg_temp_free_i32(zero);
141 static void set_btype(DisasContext *s, int val)
145 /* BTYPE is a 2-bit field, and 0 should be done with reset_btype. */
146 tcg_debug_assert(val >= 1 && val <= 3);
148 tcg_val = tcg_const_i32(val);
149 tcg_gen_st_i32(tcg_val, cpu_env, offsetof(CPUARMState, btype));
150 tcg_temp_free_i32(tcg_val);
154 void gen_a64_set_pc_im(uint64_t val)
156 tcg_gen_movi_i64(cpu_pc, val);
160 * Handle Top Byte Ignore (TBI) bits.
162 * If address tagging is enabled via the TCR TBI bits:
163 * + for EL2 and EL3 there is only one TBI bit, and if it is set
164 * then the address is zero-extended, clearing bits [63:56]
165 * + for EL0 and EL1, TBI0 controls addresses with bit 55 == 0
166 * and TBI1 controls addressses with bit 55 == 1.
167 * If the appropriate TBI bit is set for the address then
168 * the address is sign-extended from bit 55 into bits [63:56]
170 * Here We have concatenated TBI{1,0} into tbi.
172 static void gen_top_byte_ignore(DisasContext *s, TCGv_i64 dst,
173 TCGv_i64 src, int tbi)
176 /* Load unmodified address */
177 tcg_gen_mov_i64(dst, src);
178 } else if (s->current_el >= 2) {
179 /* FIXME: ARMv8.1-VHE S2 translation regime. */
180 /* Force tag byte to all zero */
181 tcg_gen_extract_i64(dst, src, 0, 56);
183 /* Sign-extend from bit 55. */
184 tcg_gen_sextract_i64(dst, src, 0, 56);
187 TCGv_i64 tcg_zero = tcg_const_i64(0);
190 * The two TBI bits differ.
191 * If tbi0, then !tbi1: only use the extension if positive.
192 * if !tbi0, then tbi1: only use the extension if negative.
194 tcg_gen_movcond_i64(tbi == 1 ? TCG_COND_GE : TCG_COND_LT,
195 dst, dst, tcg_zero, dst, src);
196 tcg_temp_free_i64(tcg_zero);
201 static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src)
204 * If address tagging is enabled for instructions via the TCR TBI bits,
205 * then loading an address into the PC will clear out any tag.
207 gen_top_byte_ignore(s, cpu_pc, src, s->tbii);
211 * Return a "clean" address for ADDR according to TBID.
212 * This is always a fresh temporary, as we need to be able to
213 * increment this independently of a dirty write-back address.
215 static TCGv_i64 clean_data_tbi(DisasContext *s, TCGv_i64 addr)
217 TCGv_i64 clean = new_tmp_a64(s);
218 gen_top_byte_ignore(s, clean, addr, s->tbid);
222 typedef struct DisasCompare64 {
227 static void a64_test_cc(DisasCompare64 *c64, int cc)
231 arm_test_cc(&c32, cc);
233 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
234 * properly. The NE/EQ comparisons are also fine with this choice. */
235 c64->cond = c32.cond;
236 c64->value = tcg_temp_new_i64();
237 tcg_gen_ext_i32_i64(c64->value, c32.value);
242 static void a64_free_cc(DisasCompare64 *c64)
244 tcg_temp_free_i64(c64->value);
247 static void gen_exception_internal(int excp)
249 TCGv_i32 tcg_excp = tcg_const_i32(excp);
251 assert(excp_is_internal(excp));
252 gen_helper_exception_internal(cpu_env, tcg_excp);
253 tcg_temp_free_i32(tcg_excp);
256 static void gen_exception_internal_insn(DisasContext *s, uint64_t pc, int excp)
258 gen_a64_set_pc_im(pc);
259 gen_exception_internal(excp);
260 s->base.is_jmp = DISAS_NORETURN;
263 static void gen_exception_insn(DisasContext *s, uint64_t pc, int excp,
264 uint32_t syndrome, uint32_t target_el)
266 gen_a64_set_pc_im(pc);
267 gen_exception(excp, syndrome, target_el);
268 s->base.is_jmp = DISAS_NORETURN;
271 static void gen_exception_bkpt_insn(DisasContext *s, uint32_t syndrome)
275 gen_a64_set_pc_im(s->pc_curr);
276 tcg_syn = tcg_const_i32(syndrome);
277 gen_helper_exception_bkpt_insn(cpu_env, tcg_syn);
278 tcg_temp_free_i32(tcg_syn);
279 s->base.is_jmp = DISAS_NORETURN;
282 static void gen_step_complete_exception(DisasContext *s)
284 /* We just completed step of an insn. Move from Active-not-pending
285 * to Active-pending, and then also take the swstep exception.
286 * This corresponds to making the (IMPDEF) choice to prioritize
287 * swstep exceptions over asynchronous exceptions taken to an exception
288 * level where debug is disabled. This choice has the advantage that
289 * we do not need to maintain internal state corresponding to the
290 * ISV/EX syndrome bits between completion of the step and generation
291 * of the exception, and our syndrome information is always correct.
294 gen_swstep_exception(s, 1, s->is_ldex);
295 s->base.is_jmp = DISAS_NORETURN;
298 static inline bool use_goto_tb(DisasContext *s, int n, uint64_t dest)
300 /* No direct tb linking with singlestep (either QEMU's or the ARM
301 * debug architecture kind) or deterministic io
303 if (s->base.singlestep_enabled || s->ss_active ||
304 (tb_cflags(s->base.tb) & CF_LAST_IO)) {
308 #ifndef CONFIG_USER_ONLY
309 /* Only link tbs from inside the same guest page */
310 if ((s->base.tb->pc & TARGET_PAGE_MASK) != (dest & TARGET_PAGE_MASK)) {
318 static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)
320 TranslationBlock *tb;
323 if (use_goto_tb(s, n, dest)) {
325 gen_a64_set_pc_im(dest);
326 tcg_gen_exit_tb(tb, n);
327 s->base.is_jmp = DISAS_NORETURN;
329 gen_a64_set_pc_im(dest);
331 gen_step_complete_exception(s);
332 } else if (s->base.singlestep_enabled) {
333 gen_exception_internal(EXCP_DEBUG);
335 tcg_gen_lookup_and_goto_ptr();
336 s->base.is_jmp = DISAS_NORETURN;
341 void unallocated_encoding(DisasContext *s)
343 /* Unallocated and reserved encodings are uncategorized */
344 gen_exception_insn(s, s->pc_curr, EXCP_UDEF, syn_uncategorized(),
345 default_exception_el(s));
348 static void init_tmp_a64_array(DisasContext *s)
350 #ifdef CONFIG_DEBUG_TCG
351 memset(s->tmp_a64, 0, sizeof(s->tmp_a64));
353 s->tmp_a64_count = 0;
356 static void free_tmp_a64(DisasContext *s)
359 for (i = 0; i < s->tmp_a64_count; i++) {
360 tcg_temp_free_i64(s->tmp_a64[i]);
362 init_tmp_a64_array(s);
365 TCGv_i64 new_tmp_a64(DisasContext *s)
367 assert(s->tmp_a64_count < TMP_A64_MAX);
368 return s->tmp_a64[s->tmp_a64_count++] = tcg_temp_new_i64();
371 TCGv_i64 new_tmp_a64_zero(DisasContext *s)
373 TCGv_i64 t = new_tmp_a64(s);
374 tcg_gen_movi_i64(t, 0);
379 * Register access functions
381 * These functions are used for directly accessing a register in where
382 * changes to the final register value are likely to be made. If you
383 * need to use a register for temporary calculation (e.g. index type
384 * operations) use the read_* form.
386 * B1.2.1 Register mappings
388 * In instruction register encoding 31 can refer to ZR (zero register) or
389 * the SP (stack pointer) depending on context. In QEMU's case we map SP
390 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
391 * This is the point of the _sp forms.
393 TCGv_i64 cpu_reg(DisasContext *s, int reg)
396 return new_tmp_a64_zero(s);
402 /* register access for when 31 == SP */
403 TCGv_i64 cpu_reg_sp(DisasContext *s, int reg)
408 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
409 * representing the register contents. This TCGv is an auto-freed
410 * temporary so it need not be explicitly freed, and may be modified.
412 TCGv_i64 read_cpu_reg(DisasContext *s, int reg, int sf)
414 TCGv_i64 v = new_tmp_a64(s);
417 tcg_gen_mov_i64(v, cpu_X[reg]);
419 tcg_gen_ext32u_i64(v, cpu_X[reg]);
422 tcg_gen_movi_i64(v, 0);
427 TCGv_i64 read_cpu_reg_sp(DisasContext *s, int reg, int sf)
429 TCGv_i64 v = new_tmp_a64(s);
431 tcg_gen_mov_i64(v, cpu_X[reg]);
433 tcg_gen_ext32u_i64(v, cpu_X[reg]);
438 /* Return the offset into CPUARMState of a slice (from
439 * the least significant end) of FP register Qn (ie
441 * (Note that this is not the same mapping as for A32; see cpu.h)
443 static inline int fp_reg_offset(DisasContext *s, int regno, TCGMemOp size)
445 return vec_reg_offset(s, regno, 0, size);
448 /* Offset of the high half of the 128 bit vector Qn */
449 static inline int fp_reg_hi_offset(DisasContext *s, int regno)
451 return vec_reg_offset(s, regno, 1, MO_64);
454 /* Convenience accessors for reading and writing single and double
455 * FP registers. Writing clears the upper parts of the associated
456 * 128 bit vector register, as required by the architecture.
457 * Note that unlike the GP register accessors, the values returned
458 * by the read functions must be manually freed.
460 static TCGv_i64 read_fp_dreg(DisasContext *s, int reg)
462 TCGv_i64 v = tcg_temp_new_i64();
464 tcg_gen_ld_i64(v, cpu_env, fp_reg_offset(s, reg, MO_64));
468 static TCGv_i32 read_fp_sreg(DisasContext *s, int reg)
470 TCGv_i32 v = tcg_temp_new_i32();
472 tcg_gen_ld_i32(v, cpu_env, fp_reg_offset(s, reg, MO_32));
476 static TCGv_i32 read_fp_hreg(DisasContext *s, int reg)
478 TCGv_i32 v = tcg_temp_new_i32();
480 tcg_gen_ld16u_i32(v, cpu_env, fp_reg_offset(s, reg, MO_16));
484 /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64).
485 * If SVE is not enabled, then there are only 128 bits in the vector.
487 static void clear_vec_high(DisasContext *s, bool is_q, int rd)
489 unsigned ofs = fp_reg_offset(s, rd, MO_64);
490 unsigned vsz = vec_full_reg_size(s);
493 TCGv_i64 tcg_zero = tcg_const_i64(0);
494 tcg_gen_st_i64(tcg_zero, cpu_env, ofs + 8);
495 tcg_temp_free_i64(tcg_zero);
498 tcg_gen_gvec_dup8i(ofs + 16, vsz - 16, vsz - 16, 0);
502 void write_fp_dreg(DisasContext *s, int reg, TCGv_i64 v)
504 unsigned ofs = fp_reg_offset(s, reg, MO_64);
506 tcg_gen_st_i64(v, cpu_env, ofs);
507 clear_vec_high(s, false, reg);
510 static void write_fp_sreg(DisasContext *s, int reg, TCGv_i32 v)
512 TCGv_i64 tmp = tcg_temp_new_i64();
514 tcg_gen_extu_i32_i64(tmp, v);
515 write_fp_dreg(s, reg, tmp);
516 tcg_temp_free_i64(tmp);
519 TCGv_ptr get_fpstatus_ptr(bool is_f16)
521 TCGv_ptr statusptr = tcg_temp_new_ptr();
524 /* In A64 all instructions (both FP and Neon) use the FPCR; there
525 * is no equivalent of the A32 Neon "standard FPSCR value".
526 * However half-precision operations operate under a different
527 * FZ16 flag and use vfp.fp_status_f16 instead of vfp.fp_status.
530 offset = offsetof(CPUARMState, vfp.fp_status_f16);
532 offset = offsetof(CPUARMState, vfp.fp_status);
534 tcg_gen_addi_ptr(statusptr, cpu_env, offset);
538 /* Expand a 2-operand AdvSIMD vector operation using an expander function. */
539 static void gen_gvec_fn2(DisasContext *s, bool is_q, int rd, int rn,
540 GVecGen2Fn *gvec_fn, int vece)
542 gvec_fn(vece, vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
543 is_q ? 16 : 8, vec_full_reg_size(s));
546 /* Expand a 2-operand + immediate AdvSIMD vector operation using
547 * an expander function.
549 static void gen_gvec_fn2i(DisasContext *s, bool is_q, int rd, int rn,
550 int64_t imm, GVecGen2iFn *gvec_fn, int vece)
552 gvec_fn(vece, vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
553 imm, is_q ? 16 : 8, vec_full_reg_size(s));
556 /* Expand a 3-operand AdvSIMD vector operation using an expander function. */
557 static void gen_gvec_fn3(DisasContext *s, bool is_q, int rd, int rn, int rm,
558 GVecGen3Fn *gvec_fn, int vece)
560 gvec_fn(vece, vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
561 vec_full_reg_offset(s, rm), is_q ? 16 : 8, vec_full_reg_size(s));
564 /* Expand a 4-operand AdvSIMD vector operation using an expander function. */
565 static void gen_gvec_fn4(DisasContext *s, bool is_q, int rd, int rn, int rm,
566 int rx, GVecGen4Fn *gvec_fn, int vece)
568 gvec_fn(vece, vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
569 vec_full_reg_offset(s, rm), vec_full_reg_offset(s, rx),
570 is_q ? 16 : 8, vec_full_reg_size(s));
573 /* Expand a 2-operand + immediate AdvSIMD vector operation using
576 static void gen_gvec_op2i(DisasContext *s, bool is_q, int rd,
577 int rn, int64_t imm, const GVecGen2i *gvec_op)
579 tcg_gen_gvec_2i(vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
580 is_q ? 16 : 8, vec_full_reg_size(s), imm, gvec_op);
583 /* Expand a 3-operand AdvSIMD vector operation using an op descriptor. */
584 static void gen_gvec_op3(DisasContext *s, bool is_q, int rd,
585 int rn, int rm, const GVecGen3 *gvec_op)
587 tcg_gen_gvec_3(vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
588 vec_full_reg_offset(s, rm), is_q ? 16 : 8,
589 vec_full_reg_size(s), gvec_op);
592 /* Expand a 3-operand operation using an out-of-line helper. */
593 static void gen_gvec_op3_ool(DisasContext *s, bool is_q, int rd,
594 int rn, int rm, int data, gen_helper_gvec_3 *fn)
596 tcg_gen_gvec_3_ool(vec_full_reg_offset(s, rd),
597 vec_full_reg_offset(s, rn),
598 vec_full_reg_offset(s, rm),
599 is_q ? 16 : 8, vec_full_reg_size(s), data, fn);
602 /* Expand a 3-operand + env pointer operation using
603 * an out-of-line helper.
605 static void gen_gvec_op3_env(DisasContext *s, bool is_q, int rd,
606 int rn, int rm, gen_helper_gvec_3_ptr *fn)
608 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
609 vec_full_reg_offset(s, rn),
610 vec_full_reg_offset(s, rm), cpu_env,
611 is_q ? 16 : 8, vec_full_reg_size(s), 0, fn);
614 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
615 * an out-of-line helper.
617 static void gen_gvec_op3_fpst(DisasContext *s, bool is_q, int rd, int rn,
618 int rm, bool is_fp16, int data,
619 gen_helper_gvec_3_ptr *fn)
621 TCGv_ptr fpst = get_fpstatus_ptr(is_fp16);
622 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
623 vec_full_reg_offset(s, rn),
624 vec_full_reg_offset(s, rm), fpst,
625 is_q ? 16 : 8, vec_full_reg_size(s), data, fn);
626 tcg_temp_free_ptr(fpst);
629 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
630 * than the 32 bit equivalent.
632 static inline void gen_set_NZ64(TCGv_i64 result)
634 tcg_gen_extr_i64_i32(cpu_ZF, cpu_NF, result);
635 tcg_gen_or_i32(cpu_ZF, cpu_ZF, cpu_NF);
638 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
639 static inline void gen_logic_CC(int sf, TCGv_i64 result)
642 gen_set_NZ64(result);
644 tcg_gen_extrl_i64_i32(cpu_ZF, result);
645 tcg_gen_mov_i32(cpu_NF, cpu_ZF);
647 tcg_gen_movi_i32(cpu_CF, 0);
648 tcg_gen_movi_i32(cpu_VF, 0);
651 /* dest = T0 + T1; compute C, N, V and Z flags */
652 static void gen_add_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
655 TCGv_i64 result, flag, tmp;
656 result = tcg_temp_new_i64();
657 flag = tcg_temp_new_i64();
658 tmp = tcg_temp_new_i64();
660 tcg_gen_movi_i64(tmp, 0);
661 tcg_gen_add2_i64(result, flag, t0, tmp, t1, tmp);
663 tcg_gen_extrl_i64_i32(cpu_CF, flag);
665 gen_set_NZ64(result);
667 tcg_gen_xor_i64(flag, result, t0);
668 tcg_gen_xor_i64(tmp, t0, t1);
669 tcg_gen_andc_i64(flag, flag, tmp);
670 tcg_temp_free_i64(tmp);
671 tcg_gen_extrh_i64_i32(cpu_VF, flag);
673 tcg_gen_mov_i64(dest, result);
674 tcg_temp_free_i64(result);
675 tcg_temp_free_i64(flag);
677 /* 32 bit arithmetic */
678 TCGv_i32 t0_32 = tcg_temp_new_i32();
679 TCGv_i32 t1_32 = tcg_temp_new_i32();
680 TCGv_i32 tmp = tcg_temp_new_i32();
682 tcg_gen_movi_i32(tmp, 0);
683 tcg_gen_extrl_i64_i32(t0_32, t0);
684 tcg_gen_extrl_i64_i32(t1_32, t1);
685 tcg_gen_add2_i32(cpu_NF, cpu_CF, t0_32, tmp, t1_32, tmp);
686 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
687 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
688 tcg_gen_xor_i32(tmp, t0_32, t1_32);
689 tcg_gen_andc_i32(cpu_VF, cpu_VF, tmp);
690 tcg_gen_extu_i32_i64(dest, cpu_NF);
692 tcg_temp_free_i32(tmp);
693 tcg_temp_free_i32(t0_32);
694 tcg_temp_free_i32(t1_32);
698 /* dest = T0 - T1; compute C, N, V and Z flags */
699 static void gen_sub_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
702 /* 64 bit arithmetic */
703 TCGv_i64 result, flag, tmp;
705 result = tcg_temp_new_i64();
706 flag = tcg_temp_new_i64();
707 tcg_gen_sub_i64(result, t0, t1);
709 gen_set_NZ64(result);
711 tcg_gen_setcond_i64(TCG_COND_GEU, flag, t0, t1);
712 tcg_gen_extrl_i64_i32(cpu_CF, flag);
714 tcg_gen_xor_i64(flag, result, t0);
715 tmp = tcg_temp_new_i64();
716 tcg_gen_xor_i64(tmp, t0, t1);
717 tcg_gen_and_i64(flag, flag, tmp);
718 tcg_temp_free_i64(tmp);
719 tcg_gen_extrh_i64_i32(cpu_VF, flag);
720 tcg_gen_mov_i64(dest, result);
721 tcg_temp_free_i64(flag);
722 tcg_temp_free_i64(result);
724 /* 32 bit arithmetic */
725 TCGv_i32 t0_32 = tcg_temp_new_i32();
726 TCGv_i32 t1_32 = tcg_temp_new_i32();
729 tcg_gen_extrl_i64_i32(t0_32, t0);
730 tcg_gen_extrl_i64_i32(t1_32, t1);
731 tcg_gen_sub_i32(cpu_NF, t0_32, t1_32);
732 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
733 tcg_gen_setcond_i32(TCG_COND_GEU, cpu_CF, t0_32, t1_32);
734 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
735 tmp = tcg_temp_new_i32();
736 tcg_gen_xor_i32(tmp, t0_32, t1_32);
737 tcg_temp_free_i32(t0_32);
738 tcg_temp_free_i32(t1_32);
739 tcg_gen_and_i32(cpu_VF, cpu_VF, tmp);
740 tcg_temp_free_i32(tmp);
741 tcg_gen_extu_i32_i64(dest, cpu_NF);
745 /* dest = T0 + T1 + CF; do not compute flags. */
746 static void gen_adc(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
748 TCGv_i64 flag = tcg_temp_new_i64();
749 tcg_gen_extu_i32_i64(flag, cpu_CF);
750 tcg_gen_add_i64(dest, t0, t1);
751 tcg_gen_add_i64(dest, dest, flag);
752 tcg_temp_free_i64(flag);
755 tcg_gen_ext32u_i64(dest, dest);
759 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
760 static void gen_adc_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
763 TCGv_i64 result, cf_64, vf_64, tmp;
764 result = tcg_temp_new_i64();
765 cf_64 = tcg_temp_new_i64();
766 vf_64 = tcg_temp_new_i64();
767 tmp = tcg_const_i64(0);
769 tcg_gen_extu_i32_i64(cf_64, cpu_CF);
770 tcg_gen_add2_i64(result, cf_64, t0, tmp, cf_64, tmp);
771 tcg_gen_add2_i64(result, cf_64, result, cf_64, t1, tmp);
772 tcg_gen_extrl_i64_i32(cpu_CF, cf_64);
773 gen_set_NZ64(result);
775 tcg_gen_xor_i64(vf_64, result, t0);
776 tcg_gen_xor_i64(tmp, t0, t1);
777 tcg_gen_andc_i64(vf_64, vf_64, tmp);
778 tcg_gen_extrh_i64_i32(cpu_VF, vf_64);
780 tcg_gen_mov_i64(dest, result);
782 tcg_temp_free_i64(tmp);
783 tcg_temp_free_i64(vf_64);
784 tcg_temp_free_i64(cf_64);
785 tcg_temp_free_i64(result);
787 TCGv_i32 t0_32, t1_32, tmp;
788 t0_32 = tcg_temp_new_i32();
789 t1_32 = tcg_temp_new_i32();
790 tmp = tcg_const_i32(0);
792 tcg_gen_extrl_i64_i32(t0_32, t0);
793 tcg_gen_extrl_i64_i32(t1_32, t1);
794 tcg_gen_add2_i32(cpu_NF, cpu_CF, t0_32, tmp, cpu_CF, tmp);
795 tcg_gen_add2_i32(cpu_NF, cpu_CF, cpu_NF, cpu_CF, t1_32, tmp);
797 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
798 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
799 tcg_gen_xor_i32(tmp, t0_32, t1_32);
800 tcg_gen_andc_i32(cpu_VF, cpu_VF, tmp);
801 tcg_gen_extu_i32_i64(dest, cpu_NF);
803 tcg_temp_free_i32(tmp);
804 tcg_temp_free_i32(t1_32);
805 tcg_temp_free_i32(t0_32);
810 * Load/Store generators
814 * Store from GPR register to memory.
816 static void do_gpr_st_memidx(DisasContext *s, TCGv_i64 source,
817 TCGv_i64 tcg_addr, int size, int memidx,
819 unsigned int iss_srt,
820 bool iss_sf, bool iss_ar)
823 tcg_gen_qemu_st_i64(source, tcg_addr, memidx, s->be_data + size);
828 syn = syn_data_abort_with_iss(0,
834 0, 0, 0, 0, 0, false);
835 disas_set_insn_syndrome(s, syn);
839 static void do_gpr_st(DisasContext *s, TCGv_i64 source,
840 TCGv_i64 tcg_addr, int size,
842 unsigned int iss_srt,
843 bool iss_sf, bool iss_ar)
845 do_gpr_st_memidx(s, source, tcg_addr, size, get_mem_index(s),
846 iss_valid, iss_srt, iss_sf, iss_ar);
850 * Load from memory to GPR register
852 static void do_gpr_ld_memidx(DisasContext *s,
853 TCGv_i64 dest, TCGv_i64 tcg_addr,
854 int size, bool is_signed,
855 bool extend, int memidx,
856 bool iss_valid, unsigned int iss_srt,
857 bool iss_sf, bool iss_ar)
859 TCGMemOp memop = s->be_data + size;
867 tcg_gen_qemu_ld_i64(dest, tcg_addr, memidx, memop);
869 if (extend && is_signed) {
871 tcg_gen_ext32u_i64(dest, dest);
877 syn = syn_data_abort_with_iss(0,
883 0, 0, 0, 0, 0, false);
884 disas_set_insn_syndrome(s, syn);
888 static void do_gpr_ld(DisasContext *s,
889 TCGv_i64 dest, TCGv_i64 tcg_addr,
890 int size, bool is_signed, bool extend,
891 bool iss_valid, unsigned int iss_srt,
892 bool iss_sf, bool iss_ar)
894 do_gpr_ld_memidx(s, dest, tcg_addr, size, is_signed, extend,
896 iss_valid, iss_srt, iss_sf, iss_ar);
900 * Store from FP register to memory
902 static void do_fp_st(DisasContext *s, int srcidx, TCGv_i64 tcg_addr, int size)
904 /* This writes the bottom N bits of a 128 bit wide vector to memory */
905 TCGv_i64 tmp = tcg_temp_new_i64();
906 tcg_gen_ld_i64(tmp, cpu_env, fp_reg_offset(s, srcidx, MO_64));
908 tcg_gen_qemu_st_i64(tmp, tcg_addr, get_mem_index(s),
911 bool be = s->be_data == MO_BE;
912 TCGv_i64 tcg_hiaddr = tcg_temp_new_i64();
914 tcg_gen_addi_i64(tcg_hiaddr, tcg_addr, 8);
915 tcg_gen_qemu_st_i64(tmp, be ? tcg_hiaddr : tcg_addr, get_mem_index(s),
917 tcg_gen_ld_i64(tmp, cpu_env, fp_reg_hi_offset(s, srcidx));
918 tcg_gen_qemu_st_i64(tmp, be ? tcg_addr : tcg_hiaddr, get_mem_index(s),
920 tcg_temp_free_i64(tcg_hiaddr);
923 tcg_temp_free_i64(tmp);
927 * Load from memory to FP register
929 static void do_fp_ld(DisasContext *s, int destidx, TCGv_i64 tcg_addr, int size)
931 /* This always zero-extends and writes to a full 128 bit wide vector */
932 TCGv_i64 tmplo = tcg_temp_new_i64();
936 TCGMemOp memop = s->be_data + size;
937 tmphi = tcg_const_i64(0);
938 tcg_gen_qemu_ld_i64(tmplo, tcg_addr, get_mem_index(s), memop);
940 bool be = s->be_data == MO_BE;
943 tmphi = tcg_temp_new_i64();
944 tcg_hiaddr = tcg_temp_new_i64();
946 tcg_gen_addi_i64(tcg_hiaddr, tcg_addr, 8);
947 tcg_gen_qemu_ld_i64(tmplo, be ? tcg_hiaddr : tcg_addr, get_mem_index(s),
949 tcg_gen_qemu_ld_i64(tmphi, be ? tcg_addr : tcg_hiaddr, get_mem_index(s),
951 tcg_temp_free_i64(tcg_hiaddr);
954 tcg_gen_st_i64(tmplo, cpu_env, fp_reg_offset(s, destidx, MO_64));
955 tcg_gen_st_i64(tmphi, cpu_env, fp_reg_hi_offset(s, destidx));
957 tcg_temp_free_i64(tmplo);
958 tcg_temp_free_i64(tmphi);
960 clear_vec_high(s, true, destidx);
964 * Vector load/store helpers.
966 * The principal difference between this and a FP load is that we don't
967 * zero extend as we are filling a partial chunk of the vector register.
968 * These functions don't support 128 bit loads/stores, which would be
969 * normal load/store operations.
971 * The _i32 versions are useful when operating on 32 bit quantities
972 * (eg for floating point single or using Neon helper functions).
975 /* Get value of an element within a vector register */
976 static void read_vec_element(DisasContext *s, TCGv_i64 tcg_dest, int srcidx,
977 int element, TCGMemOp memop)
979 int vect_off = vec_reg_offset(s, srcidx, element, memop & MO_SIZE);
982 tcg_gen_ld8u_i64(tcg_dest, cpu_env, vect_off);
985 tcg_gen_ld16u_i64(tcg_dest, cpu_env, vect_off);
988 tcg_gen_ld32u_i64(tcg_dest, cpu_env, vect_off);
991 tcg_gen_ld8s_i64(tcg_dest, cpu_env, vect_off);
994 tcg_gen_ld16s_i64(tcg_dest, cpu_env, vect_off);
997 tcg_gen_ld32s_i64(tcg_dest, cpu_env, vect_off);
1001 tcg_gen_ld_i64(tcg_dest, cpu_env, vect_off);
1004 g_assert_not_reached();
1008 static void read_vec_element_i32(DisasContext *s, TCGv_i32 tcg_dest, int srcidx,
1009 int element, TCGMemOp memop)
1011 int vect_off = vec_reg_offset(s, srcidx, element, memop & MO_SIZE);
1014 tcg_gen_ld8u_i32(tcg_dest, cpu_env, vect_off);
1017 tcg_gen_ld16u_i32(tcg_dest, cpu_env, vect_off);
1020 tcg_gen_ld8s_i32(tcg_dest, cpu_env, vect_off);
1023 tcg_gen_ld16s_i32(tcg_dest, cpu_env, vect_off);
1027 tcg_gen_ld_i32(tcg_dest, cpu_env, vect_off);
1030 g_assert_not_reached();
1034 /* Set value of an element within a vector register */
1035 static void write_vec_element(DisasContext *s, TCGv_i64 tcg_src, int destidx,
1036 int element, TCGMemOp memop)
1038 int vect_off = vec_reg_offset(s, destidx, element, memop & MO_SIZE);
1041 tcg_gen_st8_i64(tcg_src, cpu_env, vect_off);
1044 tcg_gen_st16_i64(tcg_src, cpu_env, vect_off);
1047 tcg_gen_st32_i64(tcg_src, cpu_env, vect_off);
1050 tcg_gen_st_i64(tcg_src, cpu_env, vect_off);
1053 g_assert_not_reached();
1057 static void write_vec_element_i32(DisasContext *s, TCGv_i32 tcg_src,
1058 int destidx, int element, TCGMemOp memop)
1060 int vect_off = vec_reg_offset(s, destidx, element, memop & MO_SIZE);
1063 tcg_gen_st8_i32(tcg_src, cpu_env, vect_off);
1066 tcg_gen_st16_i32(tcg_src, cpu_env, vect_off);
1069 tcg_gen_st_i32(tcg_src, cpu_env, vect_off);
1072 g_assert_not_reached();
1076 /* Store from vector register to memory */
1077 static void do_vec_st(DisasContext *s, int srcidx, int element,
1078 TCGv_i64 tcg_addr, int size, TCGMemOp endian)
1080 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
1082 read_vec_element(s, tcg_tmp, srcidx, element, size);
1083 tcg_gen_qemu_st_i64(tcg_tmp, tcg_addr, get_mem_index(s), endian | size);
1085 tcg_temp_free_i64(tcg_tmp);
1088 /* Load from memory to vector register */
1089 static void do_vec_ld(DisasContext *s, int destidx, int element,
1090 TCGv_i64 tcg_addr, int size, TCGMemOp endian)
1092 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
1094 tcg_gen_qemu_ld_i64(tcg_tmp, tcg_addr, get_mem_index(s), endian | size);
1095 write_vec_element(s, tcg_tmp, destidx, element, size);
1097 tcg_temp_free_i64(tcg_tmp);
1100 /* Check that FP/Neon access is enabled. If it is, return
1101 * true. If not, emit code to generate an appropriate exception,
1102 * and return false; the caller should not emit any code for
1103 * the instruction. Note that this check must happen after all
1104 * unallocated-encoding checks (otherwise the syndrome information
1105 * for the resulting exception will be incorrect).
1107 static inline bool fp_access_check(DisasContext *s)
1109 assert(!s->fp_access_checked);
1110 s->fp_access_checked = true;
1112 if (!s->fp_excp_el) {
1116 gen_exception_insn(s, s->pc_curr, EXCP_UDEF,
1117 syn_fp_access_trap(1, 0xe, false), s->fp_excp_el);
1121 /* Check that SVE access is enabled. If it is, return true.
1122 * If not, emit code to generate an appropriate exception and return false.
1124 bool sve_access_check(DisasContext *s)
1126 if (s->sve_excp_el) {
1127 gen_exception_insn(s, s->pc_curr, EXCP_UDEF, syn_sve_access_trap(),
1131 return fp_access_check(s);
1135 * This utility function is for doing register extension with an
1136 * optional shift. You will likely want to pass a temporary for the
1137 * destination register. See DecodeRegExtend() in the ARM ARM.
1139 static void ext_and_shift_reg(TCGv_i64 tcg_out, TCGv_i64 tcg_in,
1140 int option, unsigned int shift)
1142 int extsize = extract32(option, 0, 2);
1143 bool is_signed = extract32(option, 2, 1);
1148 tcg_gen_ext8s_i64(tcg_out, tcg_in);
1151 tcg_gen_ext16s_i64(tcg_out, tcg_in);
1154 tcg_gen_ext32s_i64(tcg_out, tcg_in);
1157 tcg_gen_mov_i64(tcg_out, tcg_in);
1163 tcg_gen_ext8u_i64(tcg_out, tcg_in);
1166 tcg_gen_ext16u_i64(tcg_out, tcg_in);
1169 tcg_gen_ext32u_i64(tcg_out, tcg_in);
1172 tcg_gen_mov_i64(tcg_out, tcg_in);
1178 tcg_gen_shli_i64(tcg_out, tcg_out, shift);
1182 static inline void gen_check_sp_alignment(DisasContext *s)
1184 /* The AArch64 architecture mandates that (if enabled via PSTATE
1185 * or SCTLR bits) there is a check that SP is 16-aligned on every
1186 * SP-relative load or store (with an exception generated if it is not).
1187 * In line with general QEMU practice regarding misaligned accesses,
1188 * we omit these checks for the sake of guest program performance.
1189 * This function is provided as a hook so we can more easily add these
1190 * checks in future (possibly as a "favour catching guest program bugs
1191 * over speed" user selectable option).
1196 * This provides a simple table based table lookup decoder. It is
1197 * intended to be used when the relevant bits for decode are too
1198 * awkwardly placed and switch/if based logic would be confusing and
1199 * deeply nested. Since it's a linear search through the table, tables
1200 * should be kept small.
1202 * It returns the first handler where insn & mask == pattern, or
1203 * NULL if there is no match.
1204 * The table is terminated by an empty mask (i.e. 0)
1206 static inline AArch64DecodeFn *lookup_disas_fn(const AArch64DecodeTable *table,
1209 const AArch64DecodeTable *tptr = table;
1211 while (tptr->mask) {
1212 if ((insn & tptr->mask) == tptr->pattern) {
1213 return tptr->disas_fn;
1221 * The instruction disassembly implemented here matches
1222 * the instruction encoding classifications in chapter C4
1223 * of the ARM Architecture Reference Manual (DDI0487B_a);
1224 * classification names and decode diagrams here should generally
1225 * match up with those in the manual.
1228 /* Unconditional branch (immediate)
1230 * +----+-----------+-------------------------------------+
1231 * | op | 0 0 1 0 1 | imm26 |
1232 * +----+-----------+-------------------------------------+
1234 static void disas_uncond_b_imm(DisasContext *s, uint32_t insn)
1236 uint64_t addr = s->pc_curr + sextract32(insn, 0, 26) * 4;
1238 if (insn & (1U << 31)) {
1239 /* BL Branch with link */
1240 tcg_gen_movi_i64(cpu_reg(s, 30), s->base.pc_next);
1243 /* B Branch / BL Branch with link */
1245 gen_goto_tb(s, 0, addr);
1248 /* Compare and branch (immediate)
1249 * 31 30 25 24 23 5 4 0
1250 * +----+-------------+----+---------------------+--------+
1251 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1252 * +----+-------------+----+---------------------+--------+
1254 static void disas_comp_b_imm(DisasContext *s, uint32_t insn)
1256 unsigned int sf, op, rt;
1258 TCGLabel *label_match;
1261 sf = extract32(insn, 31, 1);
1262 op = extract32(insn, 24, 1); /* 0: CBZ; 1: CBNZ */
1263 rt = extract32(insn, 0, 5);
1264 addr = s->pc_curr + sextract32(insn, 5, 19) * 4;
1266 tcg_cmp = read_cpu_reg(s, rt, sf);
1267 label_match = gen_new_label();
1270 tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ,
1271 tcg_cmp, 0, label_match);
1273 gen_goto_tb(s, 0, s->base.pc_next);
1274 gen_set_label(label_match);
1275 gen_goto_tb(s, 1, addr);
1278 /* Test and branch (immediate)
1279 * 31 30 25 24 23 19 18 5 4 0
1280 * +----+-------------+----+-------+-------------+------+
1281 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1282 * +----+-------------+----+-------+-------------+------+
1284 static void disas_test_b_imm(DisasContext *s, uint32_t insn)
1286 unsigned int bit_pos, op, rt;
1288 TCGLabel *label_match;
1291 bit_pos = (extract32(insn, 31, 1) << 5) | extract32(insn, 19, 5);
1292 op = extract32(insn, 24, 1); /* 0: TBZ; 1: TBNZ */
1293 addr = s->pc_curr + sextract32(insn, 5, 14) * 4;
1294 rt = extract32(insn, 0, 5);
1296 tcg_cmp = tcg_temp_new_i64();
1297 tcg_gen_andi_i64(tcg_cmp, cpu_reg(s, rt), (1ULL << bit_pos));
1298 label_match = gen_new_label();
1301 tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ,
1302 tcg_cmp, 0, label_match);
1303 tcg_temp_free_i64(tcg_cmp);
1304 gen_goto_tb(s, 0, s->base.pc_next);
1305 gen_set_label(label_match);
1306 gen_goto_tb(s, 1, addr);
1309 /* Conditional branch (immediate)
1310 * 31 25 24 23 5 4 3 0
1311 * +---------------+----+---------------------+----+------+
1312 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1313 * +---------------+----+---------------------+----+------+
1315 static void disas_cond_b_imm(DisasContext *s, uint32_t insn)
1320 if ((insn & (1 << 4)) || (insn & (1 << 24))) {
1321 unallocated_encoding(s);
1324 addr = s->pc_curr + sextract32(insn, 5, 19) * 4;
1325 cond = extract32(insn, 0, 4);
1329 /* genuinely conditional branches */
1330 TCGLabel *label_match = gen_new_label();
1331 arm_gen_test_cc(cond, label_match);
1332 gen_goto_tb(s, 0, s->base.pc_next);
1333 gen_set_label(label_match);
1334 gen_goto_tb(s, 1, addr);
1336 /* 0xe and 0xf are both "always" conditions */
1337 gen_goto_tb(s, 0, addr);
1341 /* HINT instruction group, including various allocated HINTs */
1342 static void handle_hint(DisasContext *s, uint32_t insn,
1343 unsigned int op1, unsigned int op2, unsigned int crm)
1345 unsigned int selector = crm << 3 | op2;
1348 unallocated_encoding(s);
1353 case 0b00000: /* NOP */
1355 case 0b00011: /* WFI */
1356 s->base.is_jmp = DISAS_WFI;
1358 case 0b00001: /* YIELD */
1359 /* When running in MTTCG we don't generate jumps to the yield and
1360 * WFE helpers as it won't affect the scheduling of other vCPUs.
1361 * If we wanted to more completely model WFE/SEV so we don't busy
1362 * spin unnecessarily we would need to do something more involved.
1364 if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) {
1365 s->base.is_jmp = DISAS_YIELD;
1368 case 0b00010: /* WFE */
1369 if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) {
1370 s->base.is_jmp = DISAS_WFE;
1373 case 0b00100: /* SEV */
1374 case 0b00101: /* SEVL */
1375 /* we treat all as NOP at least for now */
1377 case 0b00111: /* XPACLRI */
1378 if (s->pauth_active) {
1379 gen_helper_xpaci(cpu_X[30], cpu_env, cpu_X[30]);
1382 case 0b01000: /* PACIA1716 */
1383 if (s->pauth_active) {
1384 gen_helper_pacia(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1387 case 0b01010: /* PACIB1716 */
1388 if (s->pauth_active) {
1389 gen_helper_pacib(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1392 case 0b01100: /* AUTIA1716 */
1393 if (s->pauth_active) {
1394 gen_helper_autia(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1397 case 0b01110: /* AUTIB1716 */
1398 if (s->pauth_active) {
1399 gen_helper_autib(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1402 case 0b11000: /* PACIAZ */
1403 if (s->pauth_active) {
1404 gen_helper_pacia(cpu_X[30], cpu_env, cpu_X[30],
1405 new_tmp_a64_zero(s));
1408 case 0b11001: /* PACIASP */
1409 if (s->pauth_active) {
1410 gen_helper_pacia(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1413 case 0b11010: /* PACIBZ */
1414 if (s->pauth_active) {
1415 gen_helper_pacib(cpu_X[30], cpu_env, cpu_X[30],
1416 new_tmp_a64_zero(s));
1419 case 0b11011: /* PACIBSP */
1420 if (s->pauth_active) {
1421 gen_helper_pacib(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1424 case 0b11100: /* AUTIAZ */
1425 if (s->pauth_active) {
1426 gen_helper_autia(cpu_X[30], cpu_env, cpu_X[30],
1427 new_tmp_a64_zero(s));
1430 case 0b11101: /* AUTIASP */
1431 if (s->pauth_active) {
1432 gen_helper_autia(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1435 case 0b11110: /* AUTIBZ */
1436 if (s->pauth_active) {
1437 gen_helper_autib(cpu_X[30], cpu_env, cpu_X[30],
1438 new_tmp_a64_zero(s));
1441 case 0b11111: /* AUTIBSP */
1442 if (s->pauth_active) {
1443 gen_helper_autib(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1447 /* default specified as NOP equivalent */
1452 static void gen_clrex(DisasContext *s, uint32_t insn)
1454 tcg_gen_movi_i64(cpu_exclusive_addr, -1);
1457 /* CLREX, DSB, DMB, ISB */
1458 static void handle_sync(DisasContext *s, uint32_t insn,
1459 unsigned int op1, unsigned int op2, unsigned int crm)
1464 unallocated_encoding(s);
1475 case 1: /* MBReqTypes_Reads */
1476 bar = TCG_BAR_SC | TCG_MO_LD_LD | TCG_MO_LD_ST;
1478 case 2: /* MBReqTypes_Writes */
1479 bar = TCG_BAR_SC | TCG_MO_ST_ST;
1481 default: /* MBReqTypes_All */
1482 bar = TCG_BAR_SC | TCG_MO_ALL;
1488 /* We need to break the TB after this insn to execute
1489 * a self-modified code correctly and also to take
1490 * any pending interrupts immediately.
1493 gen_goto_tb(s, 0, s->base.pc_next);
1497 if (crm != 0 || !dc_isar_feature(aa64_sb, s)) {
1498 goto do_unallocated;
1501 * TODO: There is no speculation barrier opcode for TCG;
1502 * MB and end the TB instead.
1504 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC);
1505 gen_goto_tb(s, 0, s->base.pc_next);
1510 unallocated_encoding(s);
1515 static void gen_xaflag(void)
1517 TCGv_i32 z = tcg_temp_new_i32();
1519 tcg_gen_setcondi_i32(TCG_COND_EQ, z, cpu_ZF, 0);
1528 tcg_gen_or_i32(cpu_NF, cpu_CF, z);
1529 tcg_gen_subi_i32(cpu_NF, cpu_NF, 1);
1532 tcg_gen_and_i32(cpu_ZF, z, cpu_CF);
1533 tcg_gen_xori_i32(cpu_ZF, cpu_ZF, 1);
1535 /* (!C & Z) << 31 -> -(Z & ~C) */
1536 tcg_gen_andc_i32(cpu_VF, z, cpu_CF);
1537 tcg_gen_neg_i32(cpu_VF, cpu_VF);
1540 tcg_gen_or_i32(cpu_CF, cpu_CF, z);
1542 tcg_temp_free_i32(z);
1545 static void gen_axflag(void)
1547 tcg_gen_sari_i32(cpu_VF, cpu_VF, 31); /* V ? -1 : 0 */
1548 tcg_gen_andc_i32(cpu_CF, cpu_CF, cpu_VF); /* C & !V */
1550 /* !(Z | V) -> !(!ZF | V) -> ZF & !V -> ZF & ~VF */
1551 tcg_gen_andc_i32(cpu_ZF, cpu_ZF, cpu_VF);
1553 tcg_gen_movi_i32(cpu_NF, 0);
1554 tcg_gen_movi_i32(cpu_VF, 0);
1557 /* MSR (immediate) - move immediate to processor state field */
1558 static void handle_msr_i(DisasContext *s, uint32_t insn,
1559 unsigned int op1, unsigned int op2, unsigned int crm)
1562 int op = op1 << 3 | op2;
1564 /* End the TB by default, chaining is ok. */
1565 s->base.is_jmp = DISAS_TOO_MANY;
1568 case 0x00: /* CFINV */
1569 if (crm != 0 || !dc_isar_feature(aa64_condm_4, s)) {
1570 goto do_unallocated;
1572 tcg_gen_xori_i32(cpu_CF, cpu_CF, 1);
1573 s->base.is_jmp = DISAS_NEXT;
1576 case 0x01: /* XAFlag */
1577 if (crm != 0 || !dc_isar_feature(aa64_condm_5, s)) {
1578 goto do_unallocated;
1581 s->base.is_jmp = DISAS_NEXT;
1584 case 0x02: /* AXFlag */
1585 if (crm != 0 || !dc_isar_feature(aa64_condm_5, s)) {
1586 goto do_unallocated;
1589 s->base.is_jmp = DISAS_NEXT;
1592 case 0x05: /* SPSel */
1593 if (s->current_el == 0) {
1594 goto do_unallocated;
1596 t1 = tcg_const_i32(crm & PSTATE_SP);
1597 gen_helper_msr_i_spsel(cpu_env, t1);
1598 tcg_temp_free_i32(t1);
1601 case 0x1e: /* DAIFSet */
1602 t1 = tcg_const_i32(crm);
1603 gen_helper_msr_i_daifset(cpu_env, t1);
1604 tcg_temp_free_i32(t1);
1607 case 0x1f: /* DAIFClear */
1608 t1 = tcg_const_i32(crm);
1609 gen_helper_msr_i_daifclear(cpu_env, t1);
1610 tcg_temp_free_i32(t1);
1611 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1612 s->base.is_jmp = DISAS_UPDATE;
1617 unallocated_encoding(s);
1622 static void gen_get_nzcv(TCGv_i64 tcg_rt)
1624 TCGv_i32 tmp = tcg_temp_new_i32();
1625 TCGv_i32 nzcv = tcg_temp_new_i32();
1627 /* build bit 31, N */
1628 tcg_gen_andi_i32(nzcv, cpu_NF, (1U << 31));
1629 /* build bit 30, Z */
1630 tcg_gen_setcondi_i32(TCG_COND_EQ, tmp, cpu_ZF, 0);
1631 tcg_gen_deposit_i32(nzcv, nzcv, tmp, 30, 1);
1632 /* build bit 29, C */
1633 tcg_gen_deposit_i32(nzcv, nzcv, cpu_CF, 29, 1);
1634 /* build bit 28, V */
1635 tcg_gen_shri_i32(tmp, cpu_VF, 31);
1636 tcg_gen_deposit_i32(nzcv, nzcv, tmp, 28, 1);
1637 /* generate result */
1638 tcg_gen_extu_i32_i64(tcg_rt, nzcv);
1640 tcg_temp_free_i32(nzcv);
1641 tcg_temp_free_i32(tmp);
1644 static void gen_set_nzcv(TCGv_i64 tcg_rt)
1646 TCGv_i32 nzcv = tcg_temp_new_i32();
1648 /* take NZCV from R[t] */
1649 tcg_gen_extrl_i64_i32(nzcv, tcg_rt);
1652 tcg_gen_andi_i32(cpu_NF, nzcv, (1U << 31));
1654 tcg_gen_andi_i32(cpu_ZF, nzcv, (1 << 30));
1655 tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_ZF, cpu_ZF, 0);
1657 tcg_gen_andi_i32(cpu_CF, nzcv, (1 << 29));
1658 tcg_gen_shri_i32(cpu_CF, cpu_CF, 29);
1660 tcg_gen_andi_i32(cpu_VF, nzcv, (1 << 28));
1661 tcg_gen_shli_i32(cpu_VF, cpu_VF, 3);
1662 tcg_temp_free_i32(nzcv);
1665 /* MRS - move from system register
1666 * MSR (register) - move to system register
1669 * These are all essentially the same insn in 'read' and 'write'
1670 * versions, with varying op0 fields.
1672 static void handle_sys(DisasContext *s, uint32_t insn, bool isread,
1673 unsigned int op0, unsigned int op1, unsigned int op2,
1674 unsigned int crn, unsigned int crm, unsigned int rt)
1676 const ARMCPRegInfo *ri;
1679 ri = get_arm_cp_reginfo(s->cp_regs,
1680 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP,
1681 crn, crm, op0, op1, op2));
1684 /* Unknown register; this might be a guest error or a QEMU
1685 * unimplemented feature.
1687 qemu_log_mask(LOG_UNIMP, "%s access to unsupported AArch64 "
1688 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1689 isread ? "read" : "write", op0, op1, crn, crm, op2);
1690 unallocated_encoding(s);
1694 /* Check access permissions */
1695 if (!cp_access_ok(s->current_el, ri, isread)) {
1696 unallocated_encoding(s);
1701 /* Emit code to perform further access permissions checks at
1702 * runtime; this may result in an exception.
1705 TCGv_i32 tcg_syn, tcg_isread;
1708 gen_a64_set_pc_im(s->pc_curr);
1709 tmpptr = tcg_const_ptr(ri);
1710 syndrome = syn_aa64_sysregtrap(op0, op1, op2, crn, crm, rt, isread);
1711 tcg_syn = tcg_const_i32(syndrome);
1712 tcg_isread = tcg_const_i32(isread);
1713 gen_helper_access_check_cp_reg(cpu_env, tmpptr, tcg_syn, tcg_isread);
1714 tcg_temp_free_ptr(tmpptr);
1715 tcg_temp_free_i32(tcg_syn);
1716 tcg_temp_free_i32(tcg_isread);
1719 /* Handle special cases first */
1720 switch (ri->type & ~(ARM_CP_FLAG_MASK & ~ARM_CP_SPECIAL)) {
1724 tcg_rt = cpu_reg(s, rt);
1726 gen_get_nzcv(tcg_rt);
1728 gen_set_nzcv(tcg_rt);
1731 case ARM_CP_CURRENTEL:
1732 /* Reads as current EL value from pstate, which is
1733 * guaranteed to be constant by the tb flags.
1735 tcg_rt = cpu_reg(s, rt);
1736 tcg_gen_movi_i64(tcg_rt, s->current_el << 2);
1739 /* Writes clear the aligned block of memory which rt points into. */
1740 tcg_rt = cpu_reg(s, rt);
1741 gen_helper_dc_zva(cpu_env, tcg_rt);
1746 if ((ri->type & ARM_CP_FPU) && !fp_access_check(s)) {
1748 } else if ((ri->type & ARM_CP_SVE) && !sve_access_check(s)) {
1752 if ((tb_cflags(s->base.tb) & CF_USE_ICOUNT) && (ri->type & ARM_CP_IO)) {
1756 tcg_rt = cpu_reg(s, rt);
1759 if (ri->type & ARM_CP_CONST) {
1760 tcg_gen_movi_i64(tcg_rt, ri->resetvalue);
1761 } else if (ri->readfn) {
1763 tmpptr = tcg_const_ptr(ri);
1764 gen_helper_get_cp_reg64(tcg_rt, cpu_env, tmpptr);
1765 tcg_temp_free_ptr(tmpptr);
1767 tcg_gen_ld_i64(tcg_rt, cpu_env, ri->fieldoffset);
1770 if (ri->type & ARM_CP_CONST) {
1771 /* If not forbidden by access permissions, treat as WI */
1773 } else if (ri->writefn) {
1775 tmpptr = tcg_const_ptr(ri);
1776 gen_helper_set_cp_reg64(cpu_env, tmpptr, tcg_rt);
1777 tcg_temp_free_ptr(tmpptr);
1779 tcg_gen_st_i64(tcg_rt, cpu_env, ri->fieldoffset);
1783 if ((tb_cflags(s->base.tb) & CF_USE_ICOUNT) && (ri->type & ARM_CP_IO)) {
1784 /* I/O operations must end the TB here (whether read or write) */
1785 s->base.is_jmp = DISAS_UPDATE;
1786 } else if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) {
1787 /* We default to ending the TB on a coprocessor register write,
1788 * but allow this to be suppressed by the register definition
1789 * (usually only necessary to work around guest bugs).
1791 s->base.is_jmp = DISAS_UPDATE;
1796 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1797 * +---------------------+---+-----+-----+-------+-------+-----+------+
1798 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1799 * +---------------------+---+-----+-----+-------+-------+-----+------+
1801 static void disas_system(DisasContext *s, uint32_t insn)
1803 unsigned int l, op0, op1, crn, crm, op2, rt;
1804 l = extract32(insn, 21, 1);
1805 op0 = extract32(insn, 19, 2);
1806 op1 = extract32(insn, 16, 3);
1807 crn = extract32(insn, 12, 4);
1808 crm = extract32(insn, 8, 4);
1809 op2 = extract32(insn, 5, 3);
1810 rt = extract32(insn, 0, 5);
1813 if (l || rt != 31) {
1814 unallocated_encoding(s);
1818 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
1819 handle_hint(s, insn, op1, op2, crm);
1821 case 3: /* CLREX, DSB, DMB, ISB */
1822 handle_sync(s, insn, op1, op2, crm);
1824 case 4: /* MSR (immediate) */
1825 handle_msr_i(s, insn, op1, op2, crm);
1828 unallocated_encoding(s);
1833 handle_sys(s, insn, l, op0, op1, op2, crn, crm, rt);
1836 /* Exception generation
1838 * 31 24 23 21 20 5 4 2 1 0
1839 * +-----------------+-----+------------------------+-----+----+
1840 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1841 * +-----------------------+------------------------+----------+
1843 static void disas_exc(DisasContext *s, uint32_t insn)
1845 int opc = extract32(insn, 21, 3);
1846 int op2_ll = extract32(insn, 0, 5);
1847 int imm16 = extract32(insn, 5, 16);
1852 /* For SVC, HVC and SMC we advance the single-step state
1853 * machine before taking the exception. This is architecturally
1854 * mandated, to ensure that single-stepping a system call
1855 * instruction works properly.
1860 gen_exception_insn(s, s->base.pc_next, EXCP_SWI,
1861 syn_aa64_svc(imm16), default_exception_el(s));
1864 if (s->current_el == 0) {
1865 unallocated_encoding(s);
1868 /* The pre HVC helper handles cases when HVC gets trapped
1869 * as an undefined insn by runtime configuration.
1871 gen_a64_set_pc_im(s->pc_curr);
1872 gen_helper_pre_hvc(cpu_env);
1874 gen_exception_insn(s, s->base.pc_next, EXCP_HVC,
1875 syn_aa64_hvc(imm16), 2);
1878 if (s->current_el == 0) {
1879 unallocated_encoding(s);
1882 gen_a64_set_pc_im(s->pc_curr);
1883 tmp = tcg_const_i32(syn_aa64_smc(imm16));
1884 gen_helper_pre_smc(cpu_env, tmp);
1885 tcg_temp_free_i32(tmp);
1887 gen_exception_insn(s, s->base.pc_next, EXCP_SMC,
1888 syn_aa64_smc(imm16), 3);
1891 unallocated_encoding(s);
1897 unallocated_encoding(s);
1901 gen_exception_bkpt_insn(s, syn_aa64_bkpt(imm16));
1905 unallocated_encoding(s);
1908 /* HLT. This has two purposes.
1909 * Architecturally, it is an external halting debug instruction.
1910 * Since QEMU doesn't implement external debug, we treat this as
1911 * it is required for halting debug disabled: it will UNDEF.
1912 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1914 if (semihosting_enabled() && imm16 == 0xf000) {
1915 #ifndef CONFIG_USER_ONLY
1916 /* In system mode, don't allow userspace access to semihosting,
1917 * to provide some semblance of security (and for consistency
1918 * with our 32-bit semihosting).
1920 if (s->current_el == 0) {
1921 unsupported_encoding(s, insn);
1925 gen_exception_internal_insn(s, s->base.pc_next, EXCP_SEMIHOST);
1927 unsupported_encoding(s, insn);
1931 if (op2_ll < 1 || op2_ll > 3) {
1932 unallocated_encoding(s);
1935 /* DCPS1, DCPS2, DCPS3 */
1936 unsupported_encoding(s, insn);
1939 unallocated_encoding(s);
1944 /* Unconditional branch (register)
1945 * 31 25 24 21 20 16 15 10 9 5 4 0
1946 * +---------------+-------+-------+-------+------+-------+
1947 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1948 * +---------------+-------+-------+-------+------+-------+
1950 static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)
1952 unsigned int opc, op2, op3, rn, op4;
1953 unsigned btype_mod = 2; /* 0: BR, 1: BLR, 2: other */
1957 opc = extract32(insn, 21, 4);
1958 op2 = extract32(insn, 16, 5);
1959 op3 = extract32(insn, 10, 6);
1960 rn = extract32(insn, 5, 5);
1961 op4 = extract32(insn, 0, 5);
1964 goto do_unallocated;
1976 goto do_unallocated;
1978 dst = cpu_reg(s, rn);
1983 if (!dc_isar_feature(aa64_pauth, s)) {
1984 goto do_unallocated;
1988 if (rn != 0x1f || op4 != 0x1f) {
1989 goto do_unallocated;
1992 modifier = cpu_X[31];
1994 /* BRAAZ, BRABZ, BLRAAZ, BLRABZ */
1996 goto do_unallocated;
1998 modifier = new_tmp_a64_zero(s);
2000 if (s->pauth_active) {
2001 dst = new_tmp_a64(s);
2003 gen_helper_autia(dst, cpu_env, cpu_reg(s, rn), modifier);
2005 gen_helper_autib(dst, cpu_env, cpu_reg(s, rn), modifier);
2008 dst = cpu_reg(s, rn);
2013 goto do_unallocated;
2015 gen_a64_set_pc(s, dst);
2016 /* BLR also needs to load return address */
2018 tcg_gen_movi_i64(cpu_reg(s, 30), s->base.pc_next);
2024 if (!dc_isar_feature(aa64_pauth, s)) {
2025 goto do_unallocated;
2027 if ((op3 & ~1) != 2) {
2028 goto do_unallocated;
2030 btype_mod = opc & 1;
2031 if (s->pauth_active) {
2032 dst = new_tmp_a64(s);
2033 modifier = cpu_reg_sp(s, op4);
2035 gen_helper_autia(dst, cpu_env, cpu_reg(s, rn), modifier);
2037 gen_helper_autib(dst, cpu_env, cpu_reg(s, rn), modifier);
2040 dst = cpu_reg(s, rn);
2042 gen_a64_set_pc(s, dst);
2043 /* BLRAA also needs to load return address */
2045 tcg_gen_movi_i64(cpu_reg(s, 30), s->base.pc_next);
2050 if (s->current_el == 0) {
2051 goto do_unallocated;
2056 goto do_unallocated;
2058 dst = tcg_temp_new_i64();
2059 tcg_gen_ld_i64(dst, cpu_env,
2060 offsetof(CPUARMState, elr_el[s->current_el]));
2063 case 2: /* ERETAA */
2064 case 3: /* ERETAB */
2065 if (!dc_isar_feature(aa64_pauth, s)) {
2066 goto do_unallocated;
2068 if (rn != 0x1f || op4 != 0x1f) {
2069 goto do_unallocated;
2071 dst = tcg_temp_new_i64();
2072 tcg_gen_ld_i64(dst, cpu_env,
2073 offsetof(CPUARMState, elr_el[s->current_el]));
2074 if (s->pauth_active) {
2075 modifier = cpu_X[31];
2077 gen_helper_autia(dst, cpu_env, dst, modifier);
2079 gen_helper_autib(dst, cpu_env, dst, modifier);
2085 goto do_unallocated;
2087 if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) {
2091 gen_helper_exception_return(cpu_env, dst);
2092 tcg_temp_free_i64(dst);
2093 /* Must exit loop to check un-masked IRQs */
2094 s->base.is_jmp = DISAS_EXIT;
2098 if (op3 != 0 || op4 != 0 || rn != 0x1f) {
2099 goto do_unallocated;
2101 unsupported_encoding(s, insn);
2107 unallocated_encoding(s);
2111 switch (btype_mod) {
2113 if (dc_isar_feature(aa64_bti, s)) {
2114 /* BR to {x16,x17} or !guard -> 1, else 3. */
2115 set_btype(s, rn == 16 || rn == 17 || !s->guarded_page ? 1 : 3);
2120 if (dc_isar_feature(aa64_bti, s)) {
2121 /* BLR sets BTYPE to 2, regardless of source guarded page. */
2126 default: /* RET or none of the above. */
2127 /* BTYPE will be set to 0 by normal end-of-insn processing. */
2131 s->base.is_jmp = DISAS_JUMP;
2134 /* Branches, exception generating and system instructions */
2135 static void disas_b_exc_sys(DisasContext *s, uint32_t insn)
2137 switch (extract32(insn, 25, 7)) {
2138 case 0x0a: case 0x0b:
2139 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
2140 disas_uncond_b_imm(s, insn);
2142 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
2143 disas_comp_b_imm(s, insn);
2145 case 0x1b: case 0x5b: /* Test & branch (immediate) */
2146 disas_test_b_imm(s, insn);
2148 case 0x2a: /* Conditional branch (immediate) */
2149 disas_cond_b_imm(s, insn);
2151 case 0x6a: /* Exception generation / System */
2152 if (insn & (1 << 24)) {
2153 if (extract32(insn, 22, 2) == 0) {
2154 disas_system(s, insn);
2156 unallocated_encoding(s);
2162 case 0x6b: /* Unconditional branch (register) */
2163 disas_uncond_b_reg(s, insn);
2166 unallocated_encoding(s);
2172 * Load/Store exclusive instructions are implemented by remembering
2173 * the value/address loaded, and seeing if these are the same
2174 * when the store is performed. This is not actually the architecturally
2175 * mandated semantics, but it works for typical guest code sequences
2176 * and avoids having to monitor regular stores.
2178 * The store exclusive uses the atomic cmpxchg primitives to avoid
2179 * races in multi-threaded linux-user and when MTTCG softmmu is
2182 static void gen_load_exclusive(DisasContext *s, int rt, int rt2,
2183 TCGv_i64 addr, int size, bool is_pair)
2185 int idx = get_mem_index(s);
2186 TCGMemOp memop = s->be_data;
2188 g_assert(size <= 3);
2190 g_assert(size >= 2);
2192 /* The pair must be single-copy atomic for the doubleword. */
2193 memop |= MO_64 | MO_ALIGN;
2194 tcg_gen_qemu_ld_i64(cpu_exclusive_val, addr, idx, memop);
2195 if (s->be_data == MO_LE) {
2196 tcg_gen_extract_i64(cpu_reg(s, rt), cpu_exclusive_val, 0, 32);
2197 tcg_gen_extract_i64(cpu_reg(s, rt2), cpu_exclusive_val, 32, 32);
2199 tcg_gen_extract_i64(cpu_reg(s, rt), cpu_exclusive_val, 32, 32);
2200 tcg_gen_extract_i64(cpu_reg(s, rt2), cpu_exclusive_val, 0, 32);
2203 /* The pair must be single-copy atomic for *each* doubleword, not
2204 the entire quadword, however it must be quadword aligned. */
2206 tcg_gen_qemu_ld_i64(cpu_exclusive_val, addr, idx,
2207 memop | MO_ALIGN_16);
2209 TCGv_i64 addr2 = tcg_temp_new_i64();
2210 tcg_gen_addi_i64(addr2, addr, 8);
2211 tcg_gen_qemu_ld_i64(cpu_exclusive_high, addr2, idx, memop);
2212 tcg_temp_free_i64(addr2);
2214 tcg_gen_mov_i64(cpu_reg(s, rt), cpu_exclusive_val);
2215 tcg_gen_mov_i64(cpu_reg(s, rt2), cpu_exclusive_high);
2218 memop |= size | MO_ALIGN;
2219 tcg_gen_qemu_ld_i64(cpu_exclusive_val, addr, idx, memop);
2220 tcg_gen_mov_i64(cpu_reg(s, rt), cpu_exclusive_val);
2222 tcg_gen_mov_i64(cpu_exclusive_addr, addr);
2225 static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,
2226 TCGv_i64 addr, int size, int is_pair)
2228 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
2229 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
2232 * [addr + datasize] = {Rt2};
2238 * env->exclusive_addr = -1;
2240 TCGLabel *fail_label = gen_new_label();
2241 TCGLabel *done_label = gen_new_label();
2244 tcg_gen_brcond_i64(TCG_COND_NE, addr, cpu_exclusive_addr, fail_label);
2246 tmp = tcg_temp_new_i64();
2249 if (s->be_data == MO_LE) {
2250 tcg_gen_concat32_i64(tmp, cpu_reg(s, rt), cpu_reg(s, rt2));
2252 tcg_gen_concat32_i64(tmp, cpu_reg(s, rt2), cpu_reg(s, rt));
2254 tcg_gen_atomic_cmpxchg_i64(tmp, cpu_exclusive_addr,
2255 cpu_exclusive_val, tmp,
2257 MO_64 | MO_ALIGN | s->be_data);
2258 tcg_gen_setcond_i64(TCG_COND_NE, tmp, tmp, cpu_exclusive_val);
2259 } else if (tb_cflags(s->base.tb) & CF_PARALLEL) {
2260 if (!HAVE_CMPXCHG128) {
2261 gen_helper_exit_atomic(cpu_env);
2262 s->base.is_jmp = DISAS_NORETURN;
2263 } else if (s->be_data == MO_LE) {
2264 gen_helper_paired_cmpxchg64_le_parallel(tmp, cpu_env,
2269 gen_helper_paired_cmpxchg64_be_parallel(tmp, cpu_env,
2274 } else if (s->be_data == MO_LE) {
2275 gen_helper_paired_cmpxchg64_le(tmp, cpu_env, cpu_exclusive_addr,
2276 cpu_reg(s, rt), cpu_reg(s, rt2));
2278 gen_helper_paired_cmpxchg64_be(tmp, cpu_env, cpu_exclusive_addr,
2279 cpu_reg(s, rt), cpu_reg(s, rt2));
2282 tcg_gen_atomic_cmpxchg_i64(tmp, cpu_exclusive_addr, cpu_exclusive_val,
2283 cpu_reg(s, rt), get_mem_index(s),
2284 size | MO_ALIGN | s->be_data);
2285 tcg_gen_setcond_i64(TCG_COND_NE, tmp, tmp, cpu_exclusive_val);
2287 tcg_gen_mov_i64(cpu_reg(s, rd), tmp);
2288 tcg_temp_free_i64(tmp);
2289 tcg_gen_br(done_label);
2291 gen_set_label(fail_label);
2292 tcg_gen_movi_i64(cpu_reg(s, rd), 1);
2293 gen_set_label(done_label);
2294 tcg_gen_movi_i64(cpu_exclusive_addr, -1);
2297 static void gen_compare_and_swap(DisasContext *s, int rs, int rt,
2300 TCGv_i64 tcg_rs = cpu_reg(s, rs);
2301 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2302 int memidx = get_mem_index(s);
2303 TCGv_i64 clean_addr;
2306 gen_check_sp_alignment(s);
2308 clean_addr = clean_data_tbi(s, cpu_reg_sp(s, rn));
2309 tcg_gen_atomic_cmpxchg_i64(tcg_rs, clean_addr, tcg_rs, tcg_rt, memidx,
2310 size | MO_ALIGN | s->be_data);
2313 static void gen_compare_and_swap_pair(DisasContext *s, int rs, int rt,
2316 TCGv_i64 s1 = cpu_reg(s, rs);
2317 TCGv_i64 s2 = cpu_reg(s, rs + 1);
2318 TCGv_i64 t1 = cpu_reg(s, rt);
2319 TCGv_i64 t2 = cpu_reg(s, rt + 1);
2320 TCGv_i64 clean_addr;
2321 int memidx = get_mem_index(s);
2324 gen_check_sp_alignment(s);
2326 clean_addr = clean_data_tbi(s, cpu_reg_sp(s, rn));
2329 TCGv_i64 cmp = tcg_temp_new_i64();
2330 TCGv_i64 val = tcg_temp_new_i64();
2332 if (s->be_data == MO_LE) {
2333 tcg_gen_concat32_i64(val, t1, t2);
2334 tcg_gen_concat32_i64(cmp, s1, s2);
2336 tcg_gen_concat32_i64(val, t2, t1);
2337 tcg_gen_concat32_i64(cmp, s2, s1);
2340 tcg_gen_atomic_cmpxchg_i64(cmp, clean_addr, cmp, val, memidx,
2341 MO_64 | MO_ALIGN | s->be_data);
2342 tcg_temp_free_i64(val);
2344 if (s->be_data == MO_LE) {
2345 tcg_gen_extr32_i64(s1, s2, cmp);
2347 tcg_gen_extr32_i64(s2, s1, cmp);
2349 tcg_temp_free_i64(cmp);
2350 } else if (tb_cflags(s->base.tb) & CF_PARALLEL) {
2351 if (HAVE_CMPXCHG128) {
2352 TCGv_i32 tcg_rs = tcg_const_i32(rs);
2353 if (s->be_data == MO_LE) {
2354 gen_helper_casp_le_parallel(cpu_env, tcg_rs,
2355 clean_addr, t1, t2);
2357 gen_helper_casp_be_parallel(cpu_env, tcg_rs,
2358 clean_addr, t1, t2);
2360 tcg_temp_free_i32(tcg_rs);
2362 gen_helper_exit_atomic(cpu_env);
2363 s->base.is_jmp = DISAS_NORETURN;
2366 TCGv_i64 d1 = tcg_temp_new_i64();
2367 TCGv_i64 d2 = tcg_temp_new_i64();
2368 TCGv_i64 a2 = tcg_temp_new_i64();
2369 TCGv_i64 c1 = tcg_temp_new_i64();
2370 TCGv_i64 c2 = tcg_temp_new_i64();
2371 TCGv_i64 zero = tcg_const_i64(0);
2373 /* Load the two words, in memory order. */
2374 tcg_gen_qemu_ld_i64(d1, clean_addr, memidx,
2375 MO_64 | MO_ALIGN_16 | s->be_data);
2376 tcg_gen_addi_i64(a2, clean_addr, 8);
2377 tcg_gen_qemu_ld_i64(d2, a2, memidx, MO_64 | s->be_data);
2379 /* Compare the two words, also in memory order. */
2380 tcg_gen_setcond_i64(TCG_COND_EQ, c1, d1, s1);
2381 tcg_gen_setcond_i64(TCG_COND_EQ, c2, d2, s2);
2382 tcg_gen_and_i64(c2, c2, c1);
2384 /* If compare equal, write back new data, else write back old data. */
2385 tcg_gen_movcond_i64(TCG_COND_NE, c1, c2, zero, t1, d1);
2386 tcg_gen_movcond_i64(TCG_COND_NE, c2, c2, zero, t2, d2);
2387 tcg_gen_qemu_st_i64(c1, clean_addr, memidx, MO_64 | s->be_data);
2388 tcg_gen_qemu_st_i64(c2, a2, memidx, MO_64 | s->be_data);
2389 tcg_temp_free_i64(a2);
2390 tcg_temp_free_i64(c1);
2391 tcg_temp_free_i64(c2);
2392 tcg_temp_free_i64(zero);
2394 /* Write back the data from memory to Rs. */
2395 tcg_gen_mov_i64(s1, d1);
2396 tcg_gen_mov_i64(s2, d2);
2397 tcg_temp_free_i64(d1);
2398 tcg_temp_free_i64(d2);
2402 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2403 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2405 static bool disas_ldst_compute_iss_sf(int size, bool is_signed, int opc)
2407 int opc0 = extract32(opc, 0, 1);
2411 regsize = opc0 ? 32 : 64;
2413 regsize = size == 3 ? 64 : 32;
2415 return regsize == 64;
2418 /* Load/store exclusive
2420 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2421 * +-----+-------------+----+---+----+------+----+-------+------+------+
2422 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2423 * +-----+-------------+----+---+----+------+----+-------+------+------+
2425 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2426 * L: 0 -> store, 1 -> load
2427 * o2: 0 -> exclusive, 1 -> not
2428 * o1: 0 -> single register, 1 -> register pair
2429 * o0: 1 -> load-acquire/store-release, 0 -> not
2431 static void disas_ldst_excl(DisasContext *s, uint32_t insn)
2433 int rt = extract32(insn, 0, 5);
2434 int rn = extract32(insn, 5, 5);
2435 int rt2 = extract32(insn, 10, 5);
2436 int rs = extract32(insn, 16, 5);
2437 int is_lasr = extract32(insn, 15, 1);
2438 int o2_L_o1_o0 = extract32(insn, 21, 3) * 2 | is_lasr;
2439 int size = extract32(insn, 30, 2);
2440 TCGv_i64 clean_addr;
2442 switch (o2_L_o1_o0) {
2443 case 0x0: /* STXR */
2444 case 0x1: /* STLXR */
2446 gen_check_sp_alignment(s);
2449 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
2451 clean_addr = clean_data_tbi(s, cpu_reg_sp(s, rn));
2452 gen_store_exclusive(s, rs, rt, rt2, clean_addr, size, false);
2455 case 0x4: /* LDXR */
2456 case 0x5: /* LDAXR */
2458 gen_check_sp_alignment(s);
2460 clean_addr = clean_data_tbi(s, cpu_reg_sp(s, rn));
2462 gen_load_exclusive(s, rt, rt2, clean_addr, size, false);
2464 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
2468 case 0x8: /* STLLR */
2469 if (!dc_isar_feature(aa64_lor, s)) {
2472 /* StoreLORelease is the same as Store-Release for QEMU. */
2474 case 0x9: /* STLR */
2475 /* Generate ISS for non-exclusive accesses including LASR. */
2477 gen_check_sp_alignment(s);
2479 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
2480 clean_addr = clean_data_tbi(s, cpu_reg_sp(s, rn));
2481 do_gpr_st(s, cpu_reg(s, rt), clean_addr, size, true, rt,
2482 disas_ldst_compute_iss_sf(size, false, 0), is_lasr);
2485 case 0xc: /* LDLAR */
2486 if (!dc_isar_feature(aa64_lor, s)) {
2489 /* LoadLOAcquire is the same as Load-Acquire for QEMU. */
2491 case 0xd: /* LDAR */
2492 /* Generate ISS for non-exclusive accesses including LASR. */
2494 gen_check_sp_alignment(s);
2496 clean_addr = clean_data_tbi(s, cpu_reg_sp(s, rn));
2497 do_gpr_ld(s, cpu_reg(s, rt), clean_addr, size, false, false, true, rt,
2498 disas_ldst_compute_iss_sf(size, false, 0), is_lasr);
2499 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
2502 case 0x2: case 0x3: /* CASP / STXP */
2503 if (size & 2) { /* STXP / STLXP */
2505 gen_check_sp_alignment(s);
2508 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
2510 clean_addr = clean_data_tbi(s, cpu_reg_sp(s, rn));
2511 gen_store_exclusive(s, rs, rt, rt2, clean_addr, size, true);
2515 && ((rt | rs) & 1) == 0
2516 && dc_isar_feature(aa64_atomics, s)) {
2518 gen_compare_and_swap_pair(s, rs, rt, rn, size | 2);
2523 case 0x6: case 0x7: /* CASPA / LDXP */
2524 if (size & 2) { /* LDXP / LDAXP */
2526 gen_check_sp_alignment(s);
2528 clean_addr = clean_data_tbi(s, cpu_reg_sp(s, rn));
2530 gen_load_exclusive(s, rt, rt2, clean_addr, size, true);
2532 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
2537 && ((rt | rs) & 1) == 0
2538 && dc_isar_feature(aa64_atomics, s)) {
2539 /* CASPA / CASPAL */
2540 gen_compare_and_swap_pair(s, rs, rt, rn, size | 2);
2546 case 0xb: /* CASL */
2547 case 0xe: /* CASA */
2548 case 0xf: /* CASAL */
2549 if (rt2 == 31 && dc_isar_feature(aa64_atomics, s)) {
2550 gen_compare_and_swap(s, rs, rt, rn, size);
2555 unallocated_encoding(s);
2559 * Load register (literal)
2561 * 31 30 29 27 26 25 24 23 5 4 0
2562 * +-----+-------+---+-----+-------------------+-------+
2563 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2564 * +-----+-------+---+-----+-------------------+-------+
2566 * V: 1 -> vector (simd/fp)
2567 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2568 * 10-> 32 bit signed, 11 -> prefetch
2569 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2571 static void disas_ld_lit(DisasContext *s, uint32_t insn)
2573 int rt = extract32(insn, 0, 5);
2574 int64_t imm = sextract32(insn, 5, 19) << 2;
2575 bool is_vector = extract32(insn, 26, 1);
2576 int opc = extract32(insn, 30, 2);
2577 bool is_signed = false;
2579 TCGv_i64 tcg_rt, clean_addr;
2583 unallocated_encoding(s);
2587 if (!fp_access_check(s)) {
2592 /* PRFM (literal) : prefetch */
2595 size = 2 + extract32(opc, 0, 1);
2596 is_signed = extract32(opc, 1, 1);
2599 tcg_rt = cpu_reg(s, rt);
2601 clean_addr = tcg_const_i64(s->pc_curr + imm);
2603 do_fp_ld(s, rt, clean_addr, size);
2605 /* Only unsigned 32bit loads target 32bit registers. */
2606 bool iss_sf = opc != 0;
2608 do_gpr_ld(s, tcg_rt, clean_addr, size, is_signed, false,
2609 true, rt, iss_sf, false);
2611 tcg_temp_free_i64(clean_addr);
2615 * LDNP (Load Pair - non-temporal hint)
2616 * LDP (Load Pair - non vector)
2617 * LDPSW (Load Pair Signed Word - non vector)
2618 * STNP (Store Pair - non-temporal hint)
2619 * STP (Store Pair - non vector)
2620 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2621 * LDP (Load Pair of SIMD&FP)
2622 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2623 * STP (Store Pair of SIMD&FP)
2625 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2626 * +-----+-------+---+---+-------+---+-----------------------------+
2627 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2628 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2630 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2632 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2633 * V: 0 -> GPR, 1 -> Vector
2634 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2635 * 10 -> signed offset, 11 -> pre-index
2636 * L: 0 -> Store 1 -> Load
2638 * Rt, Rt2 = GPR or SIMD registers to be stored
2639 * Rn = general purpose register containing address
2640 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2642 static void disas_ldst_pair(DisasContext *s, uint32_t insn)
2644 int rt = extract32(insn, 0, 5);
2645 int rn = extract32(insn, 5, 5);
2646 int rt2 = extract32(insn, 10, 5);
2647 uint64_t offset = sextract64(insn, 15, 7);
2648 int index = extract32(insn, 23, 2);
2649 bool is_vector = extract32(insn, 26, 1);
2650 bool is_load = extract32(insn, 22, 1);
2651 int opc = extract32(insn, 30, 2);
2653 bool is_signed = false;
2654 bool postindex = false;
2657 TCGv_i64 clean_addr, dirty_addr;
2662 unallocated_encoding(s);
2669 size = 2 + extract32(opc, 1, 1);
2670 is_signed = extract32(opc, 0, 1);
2671 if (!is_load && is_signed) {
2672 unallocated_encoding(s);
2678 case 1: /* post-index */
2683 /* signed offset with "non-temporal" hint. Since we don't emulate
2684 * caches we don't care about hints to the cache system about
2685 * data access patterns, and handle this identically to plain
2689 /* There is no non-temporal-hint version of LDPSW */
2690 unallocated_encoding(s);
2695 case 2: /* signed offset, rn not updated */
2698 case 3: /* pre-index */
2704 if (is_vector && !fp_access_check(s)) {
2711 gen_check_sp_alignment(s);
2714 dirty_addr = read_cpu_reg_sp(s, rn, 1);
2716 tcg_gen_addi_i64(dirty_addr, dirty_addr, offset);
2718 clean_addr = clean_data_tbi(s, dirty_addr);
2722 do_fp_ld(s, rt, clean_addr, size);
2724 do_fp_st(s, rt, clean_addr, size);
2726 tcg_gen_addi_i64(clean_addr, clean_addr, 1 << size);
2728 do_fp_ld(s, rt2, clean_addr, size);
2730 do_fp_st(s, rt2, clean_addr, size);
2733 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2734 TCGv_i64 tcg_rt2 = cpu_reg(s, rt2);
2737 TCGv_i64 tmp = tcg_temp_new_i64();
2739 /* Do not modify tcg_rt before recognizing any exception
2740 * from the second load.
2742 do_gpr_ld(s, tmp, clean_addr, size, is_signed, false,
2743 false, 0, false, false);
2744 tcg_gen_addi_i64(clean_addr, clean_addr, 1 << size);
2745 do_gpr_ld(s, tcg_rt2, clean_addr, size, is_signed, false,
2746 false, 0, false, false);
2748 tcg_gen_mov_i64(tcg_rt, tmp);
2749 tcg_temp_free_i64(tmp);
2751 do_gpr_st(s, tcg_rt, clean_addr, size,
2752 false, 0, false, false);
2753 tcg_gen_addi_i64(clean_addr, clean_addr, 1 << size);
2754 do_gpr_st(s, tcg_rt2, clean_addr, size,
2755 false, 0, false, false);
2761 tcg_gen_addi_i64(dirty_addr, dirty_addr, offset);
2763 tcg_gen_mov_i64(cpu_reg_sp(s, rn), dirty_addr);
2768 * Load/store (immediate post-indexed)
2769 * Load/store (immediate pre-indexed)
2770 * Load/store (unscaled immediate)
2772 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2773 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2774 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2775 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2777 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2779 * V = 0 -> non-vector
2780 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2781 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2783 static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn,
2789 int rn = extract32(insn, 5, 5);
2790 int imm9 = sextract32(insn, 12, 9);
2791 int idx = extract32(insn, 10, 2);
2792 bool is_signed = false;
2793 bool is_store = false;
2794 bool is_extended = false;
2795 bool is_unpriv = (idx == 2);
2796 bool iss_valid = !is_vector;
2800 TCGv_i64 clean_addr, dirty_addr;
2803 size |= (opc & 2) << 1;
2804 if (size > 4 || is_unpriv) {
2805 unallocated_encoding(s);
2808 is_store = ((opc & 1) == 0);
2809 if (!fp_access_check(s)) {
2813 if (size == 3 && opc == 2) {
2814 /* PRFM - prefetch */
2816 unallocated_encoding(s);
2821 if (opc == 3 && size > 1) {
2822 unallocated_encoding(s);
2825 is_store = (opc == 0);
2826 is_signed = extract32(opc, 1, 1);
2827 is_extended = (size < 3) && extract32(opc, 0, 1);
2845 g_assert_not_reached();
2849 gen_check_sp_alignment(s);
2852 dirty_addr = read_cpu_reg_sp(s, rn, 1);
2854 tcg_gen_addi_i64(dirty_addr, dirty_addr, imm9);
2856 clean_addr = clean_data_tbi(s, dirty_addr);
2860 do_fp_st(s, rt, clean_addr, size);
2862 do_fp_ld(s, rt, clean_addr, size);
2865 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2866 int memidx = is_unpriv ? get_a64_user_mem_index(s) : get_mem_index(s);
2867 bool iss_sf = disas_ldst_compute_iss_sf(size, is_signed, opc);
2870 do_gpr_st_memidx(s, tcg_rt, clean_addr, size, memidx,
2871 iss_valid, rt, iss_sf, false);
2873 do_gpr_ld_memidx(s, tcg_rt, clean_addr, size,
2874 is_signed, is_extended, memidx,
2875 iss_valid, rt, iss_sf, false);
2880 TCGv_i64 tcg_rn = cpu_reg_sp(s, rn);
2882 tcg_gen_addi_i64(dirty_addr, dirty_addr, imm9);
2884 tcg_gen_mov_i64(tcg_rn, dirty_addr);
2889 * Load/store (register offset)
2891 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2892 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2893 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2894 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2897 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2898 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2900 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2901 * opc<0>: 0 -> store, 1 -> load
2902 * V: 1 -> vector/simd
2903 * opt: extend encoding (see DecodeRegExtend)
2904 * S: if S=1 then scale (essentially index by sizeof(size))
2905 * Rt: register to transfer into/out of
2906 * Rn: address register or SP for base
2907 * Rm: offset register or ZR for offset
2909 static void disas_ldst_reg_roffset(DisasContext *s, uint32_t insn,
2915 int rn = extract32(insn, 5, 5);
2916 int shift = extract32(insn, 12, 1);
2917 int rm = extract32(insn, 16, 5);
2918 int opt = extract32(insn, 13, 3);
2919 bool is_signed = false;
2920 bool is_store = false;
2921 bool is_extended = false;
2923 TCGv_i64 tcg_rm, clean_addr, dirty_addr;
2925 if (extract32(opt, 1, 1) == 0) {
2926 unallocated_encoding(s);
2931 size |= (opc & 2) << 1;
2933 unallocated_encoding(s);
2936 is_store = !extract32(opc, 0, 1);
2937 if (!fp_access_check(s)) {
2941 if (size == 3 && opc == 2) {
2942 /* PRFM - prefetch */
2945 if (opc == 3 && size > 1) {
2946 unallocated_encoding(s);
2949 is_store = (opc == 0);
2950 is_signed = extract32(opc, 1, 1);
2951 is_extended = (size < 3) && extract32(opc, 0, 1);
2955 gen_check_sp_alignment(s);
2957 dirty_addr = read_cpu_reg_sp(s, rn, 1);
2959 tcg_rm = read_cpu_reg(s, rm, 1);
2960 ext_and_shift_reg(tcg_rm, tcg_rm, opt, shift ? size : 0);
2962 tcg_gen_add_i64(dirty_addr, dirty_addr, tcg_rm);
2963 clean_addr = clean_data_tbi(s, dirty_addr);
2967 do_fp_st(s, rt, clean_addr, size);
2969 do_fp_ld(s, rt, clean_addr, size);
2972 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2973 bool iss_sf = disas_ldst_compute_iss_sf(size, is_signed, opc);
2975 do_gpr_st(s, tcg_rt, clean_addr, size,
2976 true, rt, iss_sf, false);
2978 do_gpr_ld(s, tcg_rt, clean_addr, size,
2979 is_signed, is_extended,
2980 true, rt, iss_sf, false);
2986 * Load/store (unsigned immediate)
2988 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2989 * +----+-------+---+-----+-----+------------+-------+------+
2990 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2991 * +----+-------+---+-----+-----+------------+-------+------+
2994 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2995 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2997 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2998 * opc<0>: 0 -> store, 1 -> load
2999 * Rn: base address register (inc SP)
3000 * Rt: target register
3002 static void disas_ldst_reg_unsigned_imm(DisasContext *s, uint32_t insn,
3008 int rn = extract32(insn, 5, 5);
3009 unsigned int imm12 = extract32(insn, 10, 12);
3010 unsigned int offset;
3012 TCGv_i64 clean_addr, dirty_addr;
3015 bool is_signed = false;
3016 bool is_extended = false;
3019 size |= (opc & 2) << 1;
3021 unallocated_encoding(s);
3024 is_store = !extract32(opc, 0, 1);
3025 if (!fp_access_check(s)) {
3029 if (size == 3 && opc == 2) {
3030 /* PRFM - prefetch */
3033 if (opc == 3 && size > 1) {
3034 unallocated_encoding(s);
3037 is_store = (opc == 0);
3038 is_signed = extract32(opc, 1, 1);
3039 is_extended = (size < 3) && extract32(opc, 0, 1);
3043 gen_check_sp_alignment(s);
3045 dirty_addr = read_cpu_reg_sp(s, rn, 1);
3046 offset = imm12 << size;
3047 tcg_gen_addi_i64(dirty_addr, dirty_addr, offset);
3048 clean_addr = clean_data_tbi(s, dirty_addr);
3052 do_fp_st(s, rt, clean_addr, size);
3054 do_fp_ld(s, rt, clean_addr, size);
3057 TCGv_i64 tcg_rt = cpu_reg(s, rt);
3058 bool iss_sf = disas_ldst_compute_iss_sf(size, is_signed, opc);
3060 do_gpr_st(s, tcg_rt, clean_addr, size,
3061 true, rt, iss_sf, false);
3063 do_gpr_ld(s, tcg_rt, clean_addr, size, is_signed, is_extended,
3064 true, rt, iss_sf, false);
3069 /* Atomic memory operations
3071 * 31 30 27 26 24 22 21 16 15 12 10 5 0
3072 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
3073 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
3074 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
3076 * Rt: the result register
3077 * Rn: base address or SP
3078 * Rs: the source register for the operation
3079 * V: vector flag (always 0 as of v8.3)
3083 static void disas_ldst_atomic(DisasContext *s, uint32_t insn,
3084 int size, int rt, bool is_vector)
3086 int rs = extract32(insn, 16, 5);
3087 int rn = extract32(insn, 5, 5);
3088 int o3_opc = extract32(insn, 12, 4);
3089 TCGv_i64 tcg_rs, clean_addr;
3090 AtomicThreeOpFn *fn;
3092 if (is_vector || !dc_isar_feature(aa64_atomics, s)) {
3093 unallocated_encoding(s);
3097 case 000: /* LDADD */
3098 fn = tcg_gen_atomic_fetch_add_i64;
3100 case 001: /* LDCLR */
3101 fn = tcg_gen_atomic_fetch_and_i64;
3103 case 002: /* LDEOR */
3104 fn = tcg_gen_atomic_fetch_xor_i64;
3106 case 003: /* LDSET */
3107 fn = tcg_gen_atomic_fetch_or_i64;
3109 case 004: /* LDSMAX */
3110 fn = tcg_gen_atomic_fetch_smax_i64;
3112 case 005: /* LDSMIN */
3113 fn = tcg_gen_atomic_fetch_smin_i64;
3115 case 006: /* LDUMAX */
3116 fn = tcg_gen_atomic_fetch_umax_i64;
3118 case 007: /* LDUMIN */
3119 fn = tcg_gen_atomic_fetch_umin_i64;
3122 fn = tcg_gen_atomic_xchg_i64;
3125 unallocated_encoding(s);
3130 gen_check_sp_alignment(s);
3132 clean_addr = clean_data_tbi(s, cpu_reg_sp(s, rn));
3133 tcg_rs = read_cpu_reg(s, rs, true);
3135 if (o3_opc == 1) { /* LDCLR */
3136 tcg_gen_not_i64(tcg_rs, tcg_rs);
3139 /* The tcg atomic primitives are all full barriers. Therefore we
3140 * can ignore the Acquire and Release bits of this instruction.
3142 fn(cpu_reg(s, rt), clean_addr, tcg_rs, get_mem_index(s),
3143 s->be_data | size | MO_ALIGN);
3147 * PAC memory operations
3149 * 31 30 27 26 24 22 21 12 11 10 5 0
3150 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3151 * | size | 1 1 1 | V | 0 0 | M S | 1 | imm9 | W | 1 | Rn | Rt |
3152 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3154 * Rt: the result register
3155 * Rn: base address or SP
3156 * V: vector flag (always 0 as of v8.3)
3157 * M: clear for key DA, set for key DB
3158 * W: pre-indexing flag
3161 static void disas_ldst_pac(DisasContext *s, uint32_t insn,
3162 int size, int rt, bool is_vector)
3164 int rn = extract32(insn, 5, 5);
3165 bool is_wback = extract32(insn, 11, 1);
3166 bool use_key_a = !extract32(insn, 23, 1);
3168 TCGv_i64 clean_addr, dirty_addr, tcg_rt;
3170 if (size != 3 || is_vector || !dc_isar_feature(aa64_pauth, s)) {
3171 unallocated_encoding(s);
3176 gen_check_sp_alignment(s);
3178 dirty_addr = read_cpu_reg_sp(s, rn, 1);
3180 if (s->pauth_active) {
3182 gen_helper_autda(dirty_addr, cpu_env, dirty_addr, cpu_X[31]);
3184 gen_helper_autdb(dirty_addr, cpu_env, dirty_addr, cpu_X[31]);
3188 /* Form the 10-bit signed, scaled offset. */
3189 offset = (extract32(insn, 22, 1) << 9) | extract32(insn, 12, 9);
3190 offset = sextract32(offset << size, 0, 10 + size);
3191 tcg_gen_addi_i64(dirty_addr, dirty_addr, offset);
3193 /* Note that "clean" and "dirty" here refer to TBI not PAC. */
3194 clean_addr = clean_data_tbi(s, dirty_addr);
3196 tcg_rt = cpu_reg(s, rt);
3197 do_gpr_ld(s, tcg_rt, clean_addr, size, /* is_signed */ false,
3198 /* extend */ false, /* iss_valid */ !is_wback,
3199 /* iss_srt */ rt, /* iss_sf */ true, /* iss_ar */ false);
3202 tcg_gen_mov_i64(cpu_reg_sp(s, rn), dirty_addr);
3206 /* Load/store register (all forms) */
3207 static void disas_ldst_reg(DisasContext *s, uint32_t insn)
3209 int rt = extract32(insn, 0, 5);
3210 int opc = extract32(insn, 22, 2);
3211 bool is_vector = extract32(insn, 26, 1);
3212 int size = extract32(insn, 30, 2);
3214 switch (extract32(insn, 24, 2)) {
3216 if (extract32(insn, 21, 1) == 0) {
3217 /* Load/store register (unscaled immediate)
3218 * Load/store immediate pre/post-indexed
3219 * Load/store register unprivileged
3221 disas_ldst_reg_imm9(s, insn, opc, size, rt, is_vector);
3224 switch (extract32(insn, 10, 2)) {
3226 disas_ldst_atomic(s, insn, size, rt, is_vector);
3229 disas_ldst_reg_roffset(s, insn, opc, size, rt, is_vector);
3232 disas_ldst_pac(s, insn, size, rt, is_vector);
3237 disas_ldst_reg_unsigned_imm(s, insn, opc, size, rt, is_vector);
3240 unallocated_encoding(s);
3243 /* AdvSIMD load/store multiple structures
3245 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
3246 * +---+---+---------------+---+-------------+--------+------+------+------+
3247 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
3248 * +---+---+---------------+---+-------------+--------+------+------+------+
3250 * AdvSIMD load/store multiple structures (post-indexed)
3252 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
3253 * +---+---+---------------+---+---+---------+--------+------+------+------+
3254 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
3255 * +---+---+---------------+---+---+---------+--------+------+------+------+
3257 * Rt: first (or only) SIMD&FP register to be transferred
3258 * Rn: base address or SP
3259 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3261 static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)
3263 int rt = extract32(insn, 0, 5);
3264 int rn = extract32(insn, 5, 5);
3265 int rm = extract32(insn, 16, 5);
3266 int size = extract32(insn, 10, 2);
3267 int opcode = extract32(insn, 12, 4);
3268 bool is_store = !extract32(insn, 22, 1);
3269 bool is_postidx = extract32(insn, 23, 1);
3270 bool is_q = extract32(insn, 30, 1);
3271 TCGv_i64 clean_addr, tcg_rn, tcg_ebytes;
3272 TCGMemOp endian = s->be_data;
3274 int ebytes; /* bytes per element */
3275 int elements; /* elements per vector */
3276 int rpt; /* num iterations */
3277 int selem; /* structure elements */
3280 if (extract32(insn, 31, 1) || extract32(insn, 21, 1)) {
3281 unallocated_encoding(s);
3285 if (!is_postidx && rm != 0) {
3286 unallocated_encoding(s);
3290 /* From the shared decode logic */
3321 unallocated_encoding(s);
3325 if (size == 3 && !is_q && selem != 1) {
3327 unallocated_encoding(s);
3331 if (!fp_access_check(s)) {
3336 gen_check_sp_alignment(s);
3339 /* For our purposes, bytes are always little-endian. */
3344 /* Consecutive little-endian elements from a single register
3345 * can be promoted to a larger little-endian operation.
3347 if (selem == 1 && endian == MO_LE) {
3351 elements = (is_q ? 16 : 8) / ebytes;
3353 tcg_rn = cpu_reg_sp(s, rn);
3354 clean_addr = clean_data_tbi(s, tcg_rn);
3355 tcg_ebytes = tcg_const_i64(ebytes);
3357 for (r = 0; r < rpt; r++) {
3359 for (e = 0; e < elements; e++) {
3361 for (xs = 0; xs < selem; xs++) {
3362 int tt = (rt + r + xs) % 32;
3364 do_vec_st(s, tt, e, clean_addr, size, endian);
3366 do_vec_ld(s, tt, e, clean_addr, size, endian);
3368 tcg_gen_add_i64(clean_addr, clean_addr, tcg_ebytes);
3372 tcg_temp_free_i64(tcg_ebytes);
3375 /* For non-quad operations, setting a slice of the low
3376 * 64 bits of the register clears the high 64 bits (in
3377 * the ARM ARM pseudocode this is implicit in the fact
3378 * that 'rval' is a 64 bit wide variable).
3379 * For quad operations, we might still need to zero the
3382 for (r = 0; r < rpt * selem; r++) {
3383 int tt = (rt + r) % 32;
3384 clear_vec_high(s, is_q, tt);
3390 tcg_gen_addi_i64(tcg_rn, tcg_rn, rpt * elements * selem * ebytes);
3392 tcg_gen_add_i64(tcg_rn, tcg_rn, cpu_reg(s, rm));
3397 /* AdvSIMD load/store single structure
3399 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3400 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3401 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3402 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3404 * AdvSIMD load/store single structure (post-indexed)
3406 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3407 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3408 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3409 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3411 * Rt: first (or only) SIMD&FP register to be transferred
3412 * Rn: base address or SP
3413 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3414 * index = encoded in Q:S:size dependent on size
3416 * lane_size = encoded in R, opc
3417 * transfer width = encoded in opc, S, size
3419 static void disas_ldst_single_struct(DisasContext *s, uint32_t insn)
3421 int rt = extract32(insn, 0, 5);
3422 int rn = extract32(insn, 5, 5);
3423 int rm = extract32(insn, 16, 5);
3424 int size = extract32(insn, 10, 2);
3425 int S = extract32(insn, 12, 1);
3426 int opc = extract32(insn, 13, 3);
3427 int R = extract32(insn, 21, 1);
3428 int is_load = extract32(insn, 22, 1);
3429 int is_postidx = extract32(insn, 23, 1);
3430 int is_q = extract32(insn, 30, 1);
3432 int scale = extract32(opc, 1, 2);
3433 int selem = (extract32(opc, 0, 1) << 1 | R) + 1;
3434 bool replicate = false;
3435 int index = is_q << 3 | S << 2 | size;
3437 TCGv_i64 clean_addr, tcg_rn, tcg_ebytes;
3439 if (extract32(insn, 31, 1)) {
3440 unallocated_encoding(s);
3443 if (!is_postidx && rm != 0) {
3444 unallocated_encoding(s);
3450 if (!is_load || S) {
3451 unallocated_encoding(s);
3460 if (extract32(size, 0, 1)) {
3461 unallocated_encoding(s);
3467 if (extract32(size, 1, 1)) {
3468 unallocated_encoding(s);
3471 if (!extract32(size, 0, 1)) {
3475 unallocated_encoding(s);
3483 g_assert_not_reached();
3486 if (!fp_access_check(s)) {
3490 ebytes = 1 << scale;
3493 gen_check_sp_alignment(s);
3496 tcg_rn = cpu_reg_sp(s, rn);
3497 clean_addr = clean_data_tbi(s, tcg_rn);
3498 tcg_ebytes = tcg_const_i64(ebytes);
3500 for (xs = 0; xs < selem; xs++) {
3502 /* Load and replicate to all elements */
3503 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
3505 tcg_gen_qemu_ld_i64(tcg_tmp, clean_addr,
3506 get_mem_index(s), s->be_data + scale);
3507 tcg_gen_gvec_dup_i64(scale, vec_full_reg_offset(s, rt),
3508 (is_q + 1) * 8, vec_full_reg_size(s),
3510 tcg_temp_free_i64(tcg_tmp);
3512 /* Load/store one element per register */
3514 do_vec_ld(s, rt, index, clean_addr, scale, s->be_data);
3516 do_vec_st(s, rt, index, clean_addr, scale, s->be_data);
3519 tcg_gen_add_i64(clean_addr, clean_addr, tcg_ebytes);
3522 tcg_temp_free_i64(tcg_ebytes);
3526 tcg_gen_addi_i64(tcg_rn, tcg_rn, selem * ebytes);
3528 tcg_gen_add_i64(tcg_rn, tcg_rn, cpu_reg(s, rm));
3533 /* Loads and stores */
3534 static void disas_ldst(DisasContext *s, uint32_t insn)
3536 switch (extract32(insn, 24, 6)) {
3537 case 0x08: /* Load/store exclusive */
3538 disas_ldst_excl(s, insn);
3540 case 0x18: case 0x1c: /* Load register (literal) */
3541 disas_ld_lit(s, insn);
3543 case 0x28: case 0x29:
3544 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
3545 disas_ldst_pair(s, insn);
3547 case 0x38: case 0x39:
3548 case 0x3c: case 0x3d: /* Load/store register (all forms) */
3549 disas_ldst_reg(s, insn);
3551 case 0x0c: /* AdvSIMD load/store multiple structures */
3552 disas_ldst_multiple_struct(s, insn);
3554 case 0x0d: /* AdvSIMD load/store single structure */
3555 disas_ldst_single_struct(s, insn);
3558 unallocated_encoding(s);
3563 /* PC-rel. addressing
3564 * 31 30 29 28 24 23 5 4 0
3565 * +----+-------+-----------+-------------------+------+
3566 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
3567 * +----+-------+-----------+-------------------+------+
3569 static void disas_pc_rel_adr(DisasContext *s, uint32_t insn)
3571 unsigned int page, rd;
3575 page = extract32(insn, 31, 1);
3576 /* SignExtend(immhi:immlo) -> offset */
3577 offset = sextract64(insn, 5, 19);
3578 offset = offset << 2 | extract32(insn, 29, 2);
3579 rd = extract32(insn, 0, 5);
3583 /* ADRP (page based) */
3588 tcg_gen_movi_i64(cpu_reg(s, rd), base + offset);
3592 * Add/subtract (immediate)
3594 * 31 30 29 28 24 23 22 21 10 9 5 4 0
3595 * +--+--+--+-----------+-----+-------------+-----+-----+
3596 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
3597 * +--+--+--+-----------+-----+-------------+-----+-----+
3599 * sf: 0 -> 32bit, 1 -> 64bit
3600 * op: 0 -> add , 1 -> sub
3602 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
3604 static void disas_add_sub_imm(DisasContext *s, uint32_t insn)
3606 int rd = extract32(insn, 0, 5);
3607 int rn = extract32(insn, 5, 5);
3608 uint64_t imm = extract32(insn, 10, 12);
3609 int shift = extract32(insn, 22, 2);
3610 bool setflags = extract32(insn, 29, 1);
3611 bool sub_op = extract32(insn, 30, 1);
3612 bool is_64bit = extract32(insn, 31, 1);
3614 TCGv_i64 tcg_rn = cpu_reg_sp(s, rn);
3615 TCGv_i64 tcg_rd = setflags ? cpu_reg(s, rd) : cpu_reg_sp(s, rd);
3616 TCGv_i64 tcg_result;
3625 unallocated_encoding(s);
3629 tcg_result = tcg_temp_new_i64();
3632 tcg_gen_subi_i64(tcg_result, tcg_rn, imm);
3634 tcg_gen_addi_i64(tcg_result, tcg_rn, imm);
3637 TCGv_i64 tcg_imm = tcg_const_i64(imm);
3639 gen_sub_CC(is_64bit, tcg_result, tcg_rn, tcg_imm);
3641 gen_add_CC(is_64bit, tcg_result, tcg_rn, tcg_imm);
3643 tcg_temp_free_i64(tcg_imm);
3647 tcg_gen_mov_i64(tcg_rd, tcg_result);
3649 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
3652 tcg_temp_free_i64(tcg_result);
3655 /* The input should be a value in the bottom e bits (with higher
3656 * bits zero); returns that value replicated into every element
3657 * of size e in a 64 bit integer.
3659 static uint64_t bitfield_replicate(uint64_t mask, unsigned int e)
3669 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
3670 static inline uint64_t bitmask64(unsigned int length)
3672 assert(length > 0 && length <= 64);
3673 return ~0ULL >> (64 - length);
3676 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
3677 * only require the wmask. Returns false if the imms/immr/immn are a reserved
3678 * value (ie should cause a guest UNDEF exception), and true if they are
3679 * valid, in which case the decoded bit pattern is written to result.
3681 bool logic_imm_decode_wmask(uint64_t *result, unsigned int immn,
3682 unsigned int imms, unsigned int immr)
3685 unsigned e, levels, s, r;
3688 assert(immn < 2 && imms < 64 && immr < 64);
3690 /* The bit patterns we create here are 64 bit patterns which
3691 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
3692 * 64 bits each. Each element contains the same value: a run
3693 * of between 1 and e-1 non-zero bits, rotated within the
3694 * element by between 0 and e-1 bits.
3696 * The element size and run length are encoded into immn (1 bit)
3697 * and imms (6 bits) as follows:
3698 * 64 bit elements: immn = 1, imms = <length of run - 1>
3699 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
3700 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
3701 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
3702 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
3703 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
3704 * Notice that immn = 0, imms = 11111x is the only combination
3705 * not covered by one of the above options; this is reserved.
3706 * Further, <length of run - 1> all-ones is a reserved pattern.
3708 * In all cases the rotation is by immr % e (and immr is 6 bits).
3711 /* First determine the element size */
3712 len = 31 - clz32((immn << 6) | (~imms & 0x3f));
3714 /* This is the immn == 0, imms == 0x11111x case */
3724 /* <length of run - 1> mustn't be all-ones. */
3728 /* Create the value of one element: s+1 set bits rotated
3729 * by r within the element (which is e bits wide)...
3731 mask = bitmask64(s + 1);
3733 mask = (mask >> r) | (mask << (e - r));
3734 mask &= bitmask64(e);
3736 /* ...then replicate the element over the whole 64 bit value */
3737 mask = bitfield_replicate(mask, e);
3742 /* Logical (immediate)
3743 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3744 * +----+-----+-------------+---+------+------+------+------+
3745 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
3746 * +----+-----+-------------+---+------+------+------+------+
3748 static void disas_logic_imm(DisasContext *s, uint32_t insn)
3750 unsigned int sf, opc, is_n, immr, imms, rn, rd;
3751 TCGv_i64 tcg_rd, tcg_rn;
3753 bool is_and = false;
3755 sf = extract32(insn, 31, 1);
3756 opc = extract32(insn, 29, 2);
3757 is_n = extract32(insn, 22, 1);
3758 immr = extract32(insn, 16, 6);
3759 imms = extract32(insn, 10, 6);
3760 rn = extract32(insn, 5, 5);
3761 rd = extract32(insn, 0, 5);
3764 unallocated_encoding(s);
3768 if (opc == 0x3) { /* ANDS */
3769 tcg_rd = cpu_reg(s, rd);
3771 tcg_rd = cpu_reg_sp(s, rd);
3773 tcg_rn = cpu_reg(s, rn);
3775 if (!logic_imm_decode_wmask(&wmask, is_n, imms, immr)) {
3776 /* some immediate field values are reserved */
3777 unallocated_encoding(s);
3782 wmask &= 0xffffffff;
3786 case 0x3: /* ANDS */
3788 tcg_gen_andi_i64(tcg_rd, tcg_rn, wmask);
3792 tcg_gen_ori_i64(tcg_rd, tcg_rn, wmask);
3795 tcg_gen_xori_i64(tcg_rd, tcg_rn, wmask);
3798 assert(FALSE); /* must handle all above */
3802 if (!sf && !is_and) {
3803 /* zero extend final result; we know we can skip this for AND
3804 * since the immediate had the high 32 bits clear.
3806 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3809 if (opc == 3) { /* ANDS */
3810 gen_logic_CC(sf, tcg_rd);
3815 * Move wide (immediate)
3817 * 31 30 29 28 23 22 21 20 5 4 0
3818 * +--+-----+-------------+-----+----------------+------+
3819 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
3820 * +--+-----+-------------+-----+----------------+------+
3822 * sf: 0 -> 32 bit, 1 -> 64 bit
3823 * opc: 00 -> N, 10 -> Z, 11 -> K
3824 * hw: shift/16 (0,16, and sf only 32, 48)
3826 static void disas_movw_imm(DisasContext *s, uint32_t insn)
3828 int rd = extract32(insn, 0, 5);
3829 uint64_t imm = extract32(insn, 5, 16);
3830 int sf = extract32(insn, 31, 1);
3831 int opc = extract32(insn, 29, 2);
3832 int pos = extract32(insn, 21, 2) << 4;
3833 TCGv_i64 tcg_rd = cpu_reg(s, rd);
3836 if (!sf && (pos >= 32)) {
3837 unallocated_encoding(s);
3851 tcg_gen_movi_i64(tcg_rd, imm);
3854 tcg_imm = tcg_const_i64(imm);
3855 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_imm, pos, 16);
3856 tcg_temp_free_i64(tcg_imm);
3858 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3862 unallocated_encoding(s);
3868 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3869 * +----+-----+-------------+---+------+------+------+------+
3870 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3871 * +----+-----+-------------+---+------+------+------+------+
3873 static void disas_bitfield(DisasContext *s, uint32_t insn)
3875 unsigned int sf, n, opc, ri, si, rn, rd, bitsize, pos, len;
3876 TCGv_i64 tcg_rd, tcg_tmp;
3878 sf = extract32(insn, 31, 1);
3879 opc = extract32(insn, 29, 2);
3880 n = extract32(insn, 22, 1);
3881 ri = extract32(insn, 16, 6);
3882 si = extract32(insn, 10, 6);
3883 rn = extract32(insn, 5, 5);
3884 rd = extract32(insn, 0, 5);
3885 bitsize = sf ? 64 : 32;
3887 if (sf != n || ri >= bitsize || si >= bitsize || opc > 2) {
3888 unallocated_encoding(s);
3892 tcg_rd = cpu_reg(s, rd);
3894 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3895 to be smaller than bitsize, we'll never reference data outside the
3896 low 32-bits anyway. */
3897 tcg_tmp = read_cpu_reg(s, rn, 1);
3899 /* Recognize simple(r) extractions. */
3901 /* Wd<s-r:0> = Wn<s:r> */
3902 len = (si - ri) + 1;
3903 if (opc == 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
3904 tcg_gen_sextract_i64(tcg_rd, tcg_tmp, ri, len);
3906 } else if (opc == 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
3907 tcg_gen_extract_i64(tcg_rd, tcg_tmp, ri, len);
3910 /* opc == 1, BFXIL fall through to deposit */
3911 tcg_gen_shri_i64(tcg_tmp, tcg_tmp, ri);
3914 /* Handle the ri > si case with a deposit
3915 * Wd<32+s-r,32-r> = Wn<s:0>
3918 pos = (bitsize - ri) & (bitsize - 1);
3921 if (opc == 0 && len < ri) {
3922 /* SBFM: sign extend the destination field from len to fill
3923 the balance of the word. Let the deposit below insert all
3924 of those sign bits. */
3925 tcg_gen_sextract_i64(tcg_tmp, tcg_tmp, 0, len);
3929 if (opc == 1) { /* BFM, BFXIL */
3930 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_tmp, pos, len);
3932 /* SBFM or UBFM: We start with zero, and we haven't modified
3933 any bits outside bitsize, therefore the zero-extension
3934 below is unneeded. */
3935 tcg_gen_deposit_z_i64(tcg_rd, tcg_tmp, pos, len);
3940 if (!sf) { /* zero extend final result */
3941 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3946 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3947 * +----+------+-------------+---+----+------+--------+------+------+
3948 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3949 * +----+------+-------------+---+----+------+--------+------+------+
3951 static void disas_extract(DisasContext *s, uint32_t insn)
3953 unsigned int sf, n, rm, imm, rn, rd, bitsize, op21, op0;
3955 sf = extract32(insn, 31, 1);
3956 n = extract32(insn, 22, 1);
3957 rm = extract32(insn, 16, 5);
3958 imm = extract32(insn, 10, 6);
3959 rn = extract32(insn, 5, 5);
3960 rd = extract32(insn, 0, 5);
3961 op21 = extract32(insn, 29, 2);
3962 op0 = extract32(insn, 21, 1);
3963 bitsize = sf ? 64 : 32;
3965 if (sf != n || op21 || op0 || imm >= bitsize) {
3966 unallocated_encoding(s);
3968 TCGv_i64 tcg_rd, tcg_rm, tcg_rn;
3970 tcg_rd = cpu_reg(s, rd);
3972 if (unlikely(imm == 0)) {
3973 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3974 * so an extract from bit 0 is a special case.
3977 tcg_gen_mov_i64(tcg_rd, cpu_reg(s, rm));
3979 tcg_gen_ext32u_i64(tcg_rd, cpu_reg(s, rm));
3982 tcg_rm = cpu_reg(s, rm);
3983 tcg_rn = cpu_reg(s, rn);
3986 /* Specialization to ROR happens in EXTRACT2. */
3987 tcg_gen_extract2_i64(tcg_rd, tcg_rm, tcg_rn, imm);
3989 TCGv_i32 t0 = tcg_temp_new_i32();
3991 tcg_gen_extrl_i64_i32(t0, tcg_rm);
3993 tcg_gen_rotri_i32(t0, t0, imm);
3995 TCGv_i32 t1 = tcg_temp_new_i32();
3996 tcg_gen_extrl_i64_i32(t1, tcg_rn);
3997 tcg_gen_extract2_i32(t0, t0, t1, imm);
3998 tcg_temp_free_i32(t1);
4000 tcg_gen_extu_i32_i64(tcg_rd, t0);
4001 tcg_temp_free_i32(t0);
4007 /* Data processing - immediate */
4008 static void disas_data_proc_imm(DisasContext *s, uint32_t insn)
4010 switch (extract32(insn, 23, 6)) {
4011 case 0x20: case 0x21: /* PC-rel. addressing */
4012 disas_pc_rel_adr(s, insn);
4014 case 0x22: case 0x23: /* Add/subtract (immediate) */
4015 disas_add_sub_imm(s, insn);
4017 case 0x24: /* Logical (immediate) */
4018 disas_logic_imm(s, insn);
4020 case 0x25: /* Move wide (immediate) */
4021 disas_movw_imm(s, insn);
4023 case 0x26: /* Bitfield */
4024 disas_bitfield(s, insn);
4026 case 0x27: /* Extract */
4027 disas_extract(s, insn);
4030 unallocated_encoding(s);
4035 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
4036 * Note that it is the caller's responsibility to ensure that the
4037 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
4038 * mandated semantics for out of range shifts.
4040 static void shift_reg(TCGv_i64 dst, TCGv_i64 src, int sf,
4041 enum a64_shift_type shift_type, TCGv_i64 shift_amount)
4043 switch (shift_type) {
4044 case A64_SHIFT_TYPE_LSL:
4045 tcg_gen_shl_i64(dst, src, shift_amount);
4047 case A64_SHIFT_TYPE_LSR:
4048 tcg_gen_shr_i64(dst, src, shift_amount);
4050 case A64_SHIFT_TYPE_ASR:
4052 tcg_gen_ext32s_i64(dst, src);
4054 tcg_gen_sar_i64(dst, sf ? src : dst, shift_amount);
4056 case A64_SHIFT_TYPE_ROR:
4058 tcg_gen_rotr_i64(dst, src, shift_amount);
4061 t0 = tcg_temp_new_i32();
4062 t1 = tcg_temp_new_i32();
4063 tcg_gen_extrl_i64_i32(t0, src);
4064 tcg_gen_extrl_i64_i32(t1, shift_amount);
4065 tcg_gen_rotr_i32(t0, t0, t1);
4066 tcg_gen_extu_i32_i64(dst, t0);
4067 tcg_temp_free_i32(t0);
4068 tcg_temp_free_i32(t1);
4072 assert(FALSE); /* all shift types should be handled */
4076 if (!sf) { /* zero extend final result */
4077 tcg_gen_ext32u_i64(dst, dst);
4081 /* Shift a TCGv src by immediate, put result in dst.
4082 * The shift amount must be in range (this should always be true as the
4083 * relevant instructions will UNDEF on bad shift immediates).
4085 static void shift_reg_imm(TCGv_i64 dst, TCGv_i64 src, int sf,
4086 enum a64_shift_type shift_type, unsigned int shift_i)
4088 assert(shift_i < (sf ? 64 : 32));
4091 tcg_gen_mov_i64(dst, src);
4093 TCGv_i64 shift_const;
4095 shift_const = tcg_const_i64(shift_i);
4096 shift_reg(dst, src, sf, shift_type, shift_const);
4097 tcg_temp_free_i64(shift_const);
4101 /* Logical (shifted register)
4102 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4103 * +----+-----+-----------+-------+---+------+--------+------+------+
4104 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
4105 * +----+-----+-----------+-------+---+------+--------+------+------+
4107 static void disas_logic_reg(DisasContext *s, uint32_t insn)
4109 TCGv_i64 tcg_rd, tcg_rn, tcg_rm;
4110 unsigned int sf, opc, shift_type, invert, rm, shift_amount, rn, rd;
4112 sf = extract32(insn, 31, 1);
4113 opc = extract32(insn, 29, 2);
4114 shift_type = extract32(insn, 22, 2);
4115 invert = extract32(insn, 21, 1);
4116 rm = extract32(insn, 16, 5);
4117 shift_amount = extract32(insn, 10, 6);
4118 rn = extract32(insn, 5, 5);
4119 rd = extract32(insn, 0, 5);
4121 if (!sf && (shift_amount & (1 << 5))) {
4122 unallocated_encoding(s);
4126 tcg_rd = cpu_reg(s, rd);
4128 if (opc == 1 && shift_amount == 0 && shift_type == 0 && rn == 31) {
4129 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
4130 * register-register MOV and MVN, so it is worth special casing.
4132 tcg_rm = cpu_reg(s, rm);
4134 tcg_gen_not_i64(tcg_rd, tcg_rm);
4136 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
4140 tcg_gen_mov_i64(tcg_rd, tcg_rm);
4142 tcg_gen_ext32u_i64(tcg_rd, tcg_rm);
4148 tcg_rm = read_cpu_reg(s, rm, sf);
4151 shift_reg_imm(tcg_rm, tcg_rm, sf, shift_type, shift_amount);
4154 tcg_rn = cpu_reg(s, rn);
4156 switch (opc | (invert << 2)) {
4159 tcg_gen_and_i64(tcg_rd, tcg_rn, tcg_rm);
4162 tcg_gen_or_i64(tcg_rd, tcg_rn, tcg_rm);
4165 tcg_gen_xor_i64(tcg_rd, tcg_rn, tcg_rm);
4169 tcg_gen_andc_i64(tcg_rd, tcg_rn, tcg_rm);
4172 tcg_gen_orc_i64(tcg_rd, tcg_rn, tcg_rm);
4175 tcg_gen_eqv_i64(tcg_rd, tcg_rn, tcg_rm);
4183 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
4187 gen_logic_CC(sf, tcg_rd);
4192 * Add/subtract (extended register)
4194 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
4195 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4196 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
4197 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4199 * sf: 0 -> 32bit, 1 -> 64bit
4200 * op: 0 -> add , 1 -> sub
4203 * option: extension type (see DecodeRegExtend)
4204 * imm3: optional shift to Rm
4206 * Rd = Rn + LSL(extend(Rm), amount)
4208 static void disas_add_sub_ext_reg(DisasContext *s, uint32_t insn)
4210 int rd = extract32(insn, 0, 5);
4211 int rn = extract32(insn, 5, 5);
4212 int imm3 = extract32(insn, 10, 3);
4213 int option = extract32(insn, 13, 3);
4214 int rm = extract32(insn, 16, 5);
4215 int opt = extract32(insn, 22, 2);
4216 bool setflags = extract32(insn, 29, 1);
4217 bool sub_op = extract32(insn, 30, 1);
4218 bool sf = extract32(insn, 31, 1);
4220 TCGv_i64 tcg_rm, tcg_rn; /* temps */
4222 TCGv_i64 tcg_result;
4224 if (imm3 > 4 || opt != 0) {
4225 unallocated_encoding(s);
4229 /* non-flag setting ops may use SP */
4231 tcg_rd = cpu_reg_sp(s, rd);
4233 tcg_rd = cpu_reg(s, rd);
4235 tcg_rn = read_cpu_reg_sp(s, rn, sf);
4237 tcg_rm = read_cpu_reg(s, rm, sf);
4238 ext_and_shift_reg(tcg_rm, tcg_rm, option, imm3);
4240 tcg_result = tcg_temp_new_i64();
4244 tcg_gen_sub_i64(tcg_result, tcg_rn, tcg_rm);
4246 tcg_gen_add_i64(tcg_result, tcg_rn, tcg_rm);
4250 gen_sub_CC(sf, tcg_result, tcg_rn, tcg_rm);
4252 gen_add_CC(sf, tcg_result, tcg_rn, tcg_rm);
4257 tcg_gen_mov_i64(tcg_rd, tcg_result);
4259 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
4262 tcg_temp_free_i64(tcg_result);
4266 * Add/subtract (shifted register)
4268 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4269 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4270 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
4271 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4273 * sf: 0 -> 32bit, 1 -> 64bit
4274 * op: 0 -> add , 1 -> sub
4276 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
4277 * imm6: Shift amount to apply to Rm before the add/sub
4279 static void disas_add_sub_reg(DisasContext *s, uint32_t insn)
4281 int rd = extract32(insn, 0, 5);
4282 int rn = extract32(insn, 5, 5);
4283 int imm6 = extract32(insn, 10, 6);
4284 int rm = extract32(insn, 16, 5);
4285 int shift_type = extract32(insn, 22, 2);
4286 bool setflags = extract32(insn, 29, 1);
4287 bool sub_op = extract32(insn, 30, 1);
4288 bool sf = extract32(insn, 31, 1);
4290 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4291 TCGv_i64 tcg_rn, tcg_rm;
4292 TCGv_i64 tcg_result;
4294 if ((shift_type == 3) || (!sf && (imm6 > 31))) {
4295 unallocated_encoding(s);
4299 tcg_rn = read_cpu_reg(s, rn, sf);
4300 tcg_rm = read_cpu_reg(s, rm, sf);
4302 shift_reg_imm(tcg_rm, tcg_rm, sf, shift_type, imm6);
4304 tcg_result = tcg_temp_new_i64();
4308 tcg_gen_sub_i64(tcg_result, tcg_rn, tcg_rm);
4310 tcg_gen_add_i64(tcg_result, tcg_rn, tcg_rm);
4314 gen_sub_CC(sf, tcg_result, tcg_rn, tcg_rm);
4316 gen_add_CC(sf, tcg_result, tcg_rn, tcg_rm);
4321 tcg_gen_mov_i64(tcg_rd, tcg_result);
4323 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
4326 tcg_temp_free_i64(tcg_result);
4329 /* Data-processing (3 source)
4331 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
4332 * +--+------+-----------+------+------+----+------+------+------+
4333 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
4334 * +--+------+-----------+------+------+----+------+------+------+
4336 static void disas_data_proc_3src(DisasContext *s, uint32_t insn)
4338 int rd = extract32(insn, 0, 5);
4339 int rn = extract32(insn, 5, 5);
4340 int ra = extract32(insn, 10, 5);
4341 int rm = extract32(insn, 16, 5);
4342 int op_id = (extract32(insn, 29, 3) << 4) |
4343 (extract32(insn, 21, 3) << 1) |
4344 extract32(insn, 15, 1);
4345 bool sf = extract32(insn, 31, 1);
4346 bool is_sub = extract32(op_id, 0, 1);
4347 bool is_high = extract32(op_id, 2, 1);
4348 bool is_signed = false;
4353 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
4355 case 0x42: /* SMADDL */
4356 case 0x43: /* SMSUBL */
4357 case 0x44: /* SMULH */
4360 case 0x0: /* MADD (32bit) */
4361 case 0x1: /* MSUB (32bit) */
4362 case 0x40: /* MADD (64bit) */
4363 case 0x41: /* MSUB (64bit) */
4364 case 0x4a: /* UMADDL */
4365 case 0x4b: /* UMSUBL */
4366 case 0x4c: /* UMULH */
4369 unallocated_encoding(s);
4374 TCGv_i64 low_bits = tcg_temp_new_i64(); /* low bits discarded */
4375 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4376 TCGv_i64 tcg_rn = cpu_reg(s, rn);
4377 TCGv_i64 tcg_rm = cpu_reg(s, rm);
4380 tcg_gen_muls2_i64(low_bits, tcg_rd, tcg_rn, tcg_rm);
4382 tcg_gen_mulu2_i64(low_bits, tcg_rd, tcg_rn, tcg_rm);
4385 tcg_temp_free_i64(low_bits);
4389 tcg_op1 = tcg_temp_new_i64();
4390 tcg_op2 = tcg_temp_new_i64();
4391 tcg_tmp = tcg_temp_new_i64();
4394 tcg_gen_mov_i64(tcg_op1, cpu_reg(s, rn));
4395 tcg_gen_mov_i64(tcg_op2, cpu_reg(s, rm));
4398 tcg_gen_ext32s_i64(tcg_op1, cpu_reg(s, rn));
4399 tcg_gen_ext32s_i64(tcg_op2, cpu_reg(s, rm));
4401 tcg_gen_ext32u_i64(tcg_op1, cpu_reg(s, rn));
4402 tcg_gen_ext32u_i64(tcg_op2, cpu_reg(s, rm));
4406 if (ra == 31 && !is_sub) {
4407 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
4408 tcg_gen_mul_i64(cpu_reg(s, rd), tcg_op1, tcg_op2);
4410 tcg_gen_mul_i64(tcg_tmp, tcg_op1, tcg_op2);
4412 tcg_gen_sub_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
4414 tcg_gen_add_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
4419 tcg_gen_ext32u_i64(cpu_reg(s, rd), cpu_reg(s, rd));
4422 tcg_temp_free_i64(tcg_op1);
4423 tcg_temp_free_i64(tcg_op2);
4424 tcg_temp_free_i64(tcg_tmp);
4427 /* Add/subtract (with carry)
4428 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
4429 * +--+--+--+------------------------+------+-------------+------+-----+
4430 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | 0 0 0 0 0 0 | Rn | Rd |
4431 * +--+--+--+------------------------+------+-------------+------+-----+
4434 static void disas_adc_sbc(DisasContext *s, uint32_t insn)
4436 unsigned int sf, op, setflags, rm, rn, rd;
4437 TCGv_i64 tcg_y, tcg_rn, tcg_rd;
4439 sf = extract32(insn, 31, 1);
4440 op = extract32(insn, 30, 1);
4441 setflags = extract32(insn, 29, 1);
4442 rm = extract32(insn, 16, 5);
4443 rn = extract32(insn, 5, 5);
4444 rd = extract32(insn, 0, 5);
4446 tcg_rd = cpu_reg(s, rd);
4447 tcg_rn = cpu_reg(s, rn);
4450 tcg_y = new_tmp_a64(s);
4451 tcg_gen_not_i64(tcg_y, cpu_reg(s, rm));
4453 tcg_y = cpu_reg(s, rm);
4457 gen_adc_CC(sf, tcg_rd, tcg_rn, tcg_y);
4459 gen_adc(sf, tcg_rd, tcg_rn, tcg_y);
4464 * Rotate right into flags
4465 * 31 30 29 21 15 10 5 4 0
4466 * +--+--+--+-----------------+--------+-----------+------+--+------+
4467 * |sf|op| S| 1 1 0 1 0 0 0 0 | imm6 | 0 0 0 0 1 | Rn |o2| mask |
4468 * +--+--+--+-----------------+--------+-----------+------+--+------+
4470 static void disas_rotate_right_into_flags(DisasContext *s, uint32_t insn)
4472 int mask = extract32(insn, 0, 4);
4473 int o2 = extract32(insn, 4, 1);
4474 int rn = extract32(insn, 5, 5);
4475 int imm6 = extract32(insn, 15, 6);
4476 int sf_op_s = extract32(insn, 29, 3);
4480 if (sf_op_s != 5 || o2 != 0 || !dc_isar_feature(aa64_condm_4, s)) {
4481 unallocated_encoding(s);
4485 tcg_rn = read_cpu_reg(s, rn, 1);
4486 tcg_gen_rotri_i64(tcg_rn, tcg_rn, imm6);
4488 nzcv = tcg_temp_new_i32();
4489 tcg_gen_extrl_i64_i32(nzcv, tcg_rn);
4491 if (mask & 8) { /* N */
4492 tcg_gen_shli_i32(cpu_NF, nzcv, 31 - 3);
4494 if (mask & 4) { /* Z */
4495 tcg_gen_not_i32(cpu_ZF, nzcv);
4496 tcg_gen_andi_i32(cpu_ZF, cpu_ZF, 4);
4498 if (mask & 2) { /* C */
4499 tcg_gen_extract_i32(cpu_CF, nzcv, 1, 1);
4501 if (mask & 1) { /* V */
4502 tcg_gen_shli_i32(cpu_VF, nzcv, 31 - 0);
4505 tcg_temp_free_i32(nzcv);
4509 * Evaluate into flags
4510 * 31 30 29 21 15 14 10 5 4 0
4511 * +--+--+--+-----------------+---------+----+---------+------+--+------+
4512 * |sf|op| S| 1 1 0 1 0 0 0 0 | opcode2 | sz | 0 0 1 0 | Rn |o3| mask |
4513 * +--+--+--+-----------------+---------+----+---------+------+--+------+
4515 static void disas_evaluate_into_flags(DisasContext *s, uint32_t insn)
4517 int o3_mask = extract32(insn, 0, 5);
4518 int rn = extract32(insn, 5, 5);
4519 int o2 = extract32(insn, 15, 6);
4520 int sz = extract32(insn, 14, 1);
4521 int sf_op_s = extract32(insn, 29, 3);
4525 if (sf_op_s != 1 || o2 != 0 || o3_mask != 0xd ||
4526 !dc_isar_feature(aa64_condm_4, s)) {
4527 unallocated_encoding(s);
4530 shift = sz ? 16 : 24; /* SETF16 or SETF8 */
4532 tmp = tcg_temp_new_i32();
4533 tcg_gen_extrl_i64_i32(tmp, cpu_reg(s, rn));
4534 tcg_gen_shli_i32(cpu_NF, tmp, shift);
4535 tcg_gen_shli_i32(cpu_VF, tmp, shift - 1);
4536 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
4537 tcg_gen_xor_i32(cpu_VF, cpu_VF, cpu_NF);
4538 tcg_temp_free_i32(tmp);
4541 /* Conditional compare (immediate / register)
4542 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4543 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4544 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
4545 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4548 static void disas_cc(DisasContext *s, uint32_t insn)
4550 unsigned int sf, op, y, cond, rn, nzcv, is_imm;
4551 TCGv_i32 tcg_t0, tcg_t1, tcg_t2;
4552 TCGv_i64 tcg_tmp, tcg_y, tcg_rn;
4555 if (!extract32(insn, 29, 1)) {
4556 unallocated_encoding(s);
4559 if (insn & (1 << 10 | 1 << 4)) {
4560 unallocated_encoding(s);
4563 sf = extract32(insn, 31, 1);
4564 op = extract32(insn, 30, 1);
4565 is_imm = extract32(insn, 11, 1);
4566 y = extract32(insn, 16, 5); /* y = rm (reg) or imm5 (imm) */
4567 cond = extract32(insn, 12, 4);
4568 rn = extract32(insn, 5, 5);
4569 nzcv = extract32(insn, 0, 4);
4571 /* Set T0 = !COND. */
4572 tcg_t0 = tcg_temp_new_i32();
4573 arm_test_cc(&c, cond);
4574 tcg_gen_setcondi_i32(tcg_invert_cond(c.cond), tcg_t0, c.value, 0);
4577 /* Load the arguments for the new comparison. */
4579 tcg_y = new_tmp_a64(s);
4580 tcg_gen_movi_i64(tcg_y, y);
4582 tcg_y = cpu_reg(s, y);
4584 tcg_rn = cpu_reg(s, rn);
4586 /* Set the flags for the new comparison. */
4587 tcg_tmp = tcg_temp_new_i64();
4589 gen_sub_CC(sf, tcg_tmp, tcg_rn, tcg_y);
4591 gen_add_CC(sf, tcg_tmp, tcg_rn, tcg_y);
4593 tcg_temp_free_i64(tcg_tmp);
4595 /* If COND was false, force the flags to #nzcv. Compute two masks
4596 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
4597 * For tcg hosts that support ANDC, we can make do with just T1.
4598 * In either case, allow the tcg optimizer to delete any unused mask.
4600 tcg_t1 = tcg_temp_new_i32();
4601 tcg_t2 = tcg_temp_new_i32();
4602 tcg_gen_neg_i32(tcg_t1, tcg_t0);
4603 tcg_gen_subi_i32(tcg_t2, tcg_t0, 1);
4605 if (nzcv & 8) { /* N */
4606 tcg_gen_or_i32(cpu_NF, cpu_NF, tcg_t1);
4608 if (TCG_TARGET_HAS_andc_i32) {
4609 tcg_gen_andc_i32(cpu_NF, cpu_NF, tcg_t1);
4611 tcg_gen_and_i32(cpu_NF, cpu_NF, tcg_t2);
4614 if (nzcv & 4) { /* Z */
4615 if (TCG_TARGET_HAS_andc_i32) {
4616 tcg_gen_andc_i32(cpu_ZF, cpu_ZF, tcg_t1);
4618 tcg_gen_and_i32(cpu_ZF, cpu_ZF, tcg_t2);
4621 tcg_gen_or_i32(cpu_ZF, cpu_ZF, tcg_t0);
4623 if (nzcv & 2) { /* C */
4624 tcg_gen_or_i32(cpu_CF, cpu_CF, tcg_t0);
4626 if (TCG_TARGET_HAS_andc_i32) {
4627 tcg_gen_andc_i32(cpu_CF, cpu_CF, tcg_t1);
4629 tcg_gen_and_i32(cpu_CF, cpu_CF, tcg_t2);
4632 if (nzcv & 1) { /* V */
4633 tcg_gen_or_i32(cpu_VF, cpu_VF, tcg_t1);
4635 if (TCG_TARGET_HAS_andc_i32) {
4636 tcg_gen_andc_i32(cpu_VF, cpu_VF, tcg_t1);
4638 tcg_gen_and_i32(cpu_VF, cpu_VF, tcg_t2);
4641 tcg_temp_free_i32(tcg_t0);
4642 tcg_temp_free_i32(tcg_t1);
4643 tcg_temp_free_i32(tcg_t2);
4646 /* Conditional select
4647 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
4648 * +----+----+---+-----------------+------+------+-----+------+------+
4649 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
4650 * +----+----+---+-----------------+------+------+-----+------+------+
4652 static void disas_cond_select(DisasContext *s, uint32_t insn)
4654 unsigned int sf, else_inv, rm, cond, else_inc, rn, rd;
4655 TCGv_i64 tcg_rd, zero;
4658 if (extract32(insn, 29, 1) || extract32(insn, 11, 1)) {
4659 /* S == 1 or op2<1> == 1 */
4660 unallocated_encoding(s);
4663 sf = extract32(insn, 31, 1);
4664 else_inv = extract32(insn, 30, 1);
4665 rm = extract32(insn, 16, 5);
4666 cond = extract32(insn, 12, 4);
4667 else_inc = extract32(insn, 10, 1);
4668 rn = extract32(insn, 5, 5);
4669 rd = extract32(insn, 0, 5);
4671 tcg_rd = cpu_reg(s, rd);
4673 a64_test_cc(&c, cond);
4674 zero = tcg_const_i64(0);
4676 if (rn == 31 && rm == 31 && (else_inc ^ else_inv)) {
4678 tcg_gen_setcond_i64(tcg_invert_cond(c.cond), tcg_rd, c.value, zero);
4680 tcg_gen_neg_i64(tcg_rd, tcg_rd);
4683 TCGv_i64 t_true = cpu_reg(s, rn);
4684 TCGv_i64 t_false = read_cpu_reg(s, rm, 1);
4685 if (else_inv && else_inc) {
4686 tcg_gen_neg_i64(t_false, t_false);
4687 } else if (else_inv) {
4688 tcg_gen_not_i64(t_false, t_false);
4689 } else if (else_inc) {
4690 tcg_gen_addi_i64(t_false, t_false, 1);
4692 tcg_gen_movcond_i64(c.cond, tcg_rd, c.value, zero, t_true, t_false);
4695 tcg_temp_free_i64(zero);
4699 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
4703 static void handle_clz(DisasContext *s, unsigned int sf,
4704 unsigned int rn, unsigned int rd)
4706 TCGv_i64 tcg_rd, tcg_rn;
4707 tcg_rd = cpu_reg(s, rd);
4708 tcg_rn = cpu_reg(s, rn);
4711 tcg_gen_clzi_i64(tcg_rd, tcg_rn, 64);
4713 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
4714 tcg_gen_extrl_i64_i32(tcg_tmp32, tcg_rn);
4715 tcg_gen_clzi_i32(tcg_tmp32, tcg_tmp32, 32);
4716 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
4717 tcg_temp_free_i32(tcg_tmp32);
4721 static void handle_cls(DisasContext *s, unsigned int sf,
4722 unsigned int rn, unsigned int rd)
4724 TCGv_i64 tcg_rd, tcg_rn;
4725 tcg_rd = cpu_reg(s, rd);
4726 tcg_rn = cpu_reg(s, rn);
4729 tcg_gen_clrsb_i64(tcg_rd, tcg_rn);
4731 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
4732 tcg_gen_extrl_i64_i32(tcg_tmp32, tcg_rn);
4733 tcg_gen_clrsb_i32(tcg_tmp32, tcg_tmp32);
4734 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
4735 tcg_temp_free_i32(tcg_tmp32);
4739 static void handle_rbit(DisasContext *s, unsigned int sf,
4740 unsigned int rn, unsigned int rd)
4742 TCGv_i64 tcg_rd, tcg_rn;
4743 tcg_rd = cpu_reg(s, rd);
4744 tcg_rn = cpu_reg(s, rn);
4747 gen_helper_rbit64(tcg_rd, tcg_rn);
4749 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
4750 tcg_gen_extrl_i64_i32(tcg_tmp32, tcg_rn);
4751 gen_helper_rbit(tcg_tmp32, tcg_tmp32);
4752 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
4753 tcg_temp_free_i32(tcg_tmp32);
4757 /* REV with sf==1, opcode==3 ("REV64") */
4758 static void handle_rev64(DisasContext *s, unsigned int sf,
4759 unsigned int rn, unsigned int rd)
4762 unallocated_encoding(s);
4765 tcg_gen_bswap64_i64(cpu_reg(s, rd), cpu_reg(s, rn));
4768 /* REV with sf==0, opcode==2
4769 * REV32 (sf==1, opcode==2)
4771 static void handle_rev32(DisasContext *s, unsigned int sf,
4772 unsigned int rn, unsigned int rd)
4774 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4777 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
4778 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
4780 /* bswap32_i64 requires zero high word */
4781 tcg_gen_ext32u_i64(tcg_tmp, tcg_rn);
4782 tcg_gen_bswap32_i64(tcg_rd, tcg_tmp);
4783 tcg_gen_shri_i64(tcg_tmp, tcg_rn, 32);
4784 tcg_gen_bswap32_i64(tcg_tmp, tcg_tmp);
4785 tcg_gen_concat32_i64(tcg_rd, tcg_rd, tcg_tmp);
4787 tcg_temp_free_i64(tcg_tmp);
4789 tcg_gen_ext32u_i64(tcg_rd, cpu_reg(s, rn));
4790 tcg_gen_bswap32_i64(tcg_rd, tcg_rd);
4794 /* REV16 (opcode==1) */
4795 static void handle_rev16(DisasContext *s, unsigned int sf,
4796 unsigned int rn, unsigned int rd)
4798 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4799 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
4800 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
4801 TCGv_i64 mask = tcg_const_i64(sf ? 0x00ff00ff00ff00ffull : 0x00ff00ff);
4803 tcg_gen_shri_i64(tcg_tmp, tcg_rn, 8);
4804 tcg_gen_and_i64(tcg_rd, tcg_rn, mask);
4805 tcg_gen_and_i64(tcg_tmp, tcg_tmp, mask);
4806 tcg_gen_shli_i64(tcg_rd, tcg_rd, 8);
4807 tcg_gen_or_i64(tcg_rd, tcg_rd, tcg_tmp);
4809 tcg_temp_free_i64(mask);
4810 tcg_temp_free_i64(tcg_tmp);
4813 /* Data-processing (1 source)
4814 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4815 * +----+---+---+-----------------+---------+--------+------+------+
4816 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
4817 * +----+---+---+-----------------+---------+--------+------+------+
4819 static void disas_data_proc_1src(DisasContext *s, uint32_t insn)
4821 unsigned int sf, opcode, opcode2, rn, rd;
4824 if (extract32(insn, 29, 1)) {
4825 unallocated_encoding(s);
4829 sf = extract32(insn, 31, 1);
4830 opcode = extract32(insn, 10, 6);
4831 opcode2 = extract32(insn, 16, 5);
4832 rn = extract32(insn, 5, 5);
4833 rd = extract32(insn, 0, 5);
4835 #define MAP(SF, O2, O1) ((SF) | (O1 << 1) | (O2 << 7))
4837 switch (MAP(sf, opcode2, opcode)) {
4838 case MAP(0, 0x00, 0x00): /* RBIT */
4839 case MAP(1, 0x00, 0x00):
4840 handle_rbit(s, sf, rn, rd);
4842 case MAP(0, 0x00, 0x01): /* REV16 */
4843 case MAP(1, 0x00, 0x01):
4844 handle_rev16(s, sf, rn, rd);
4846 case MAP(0, 0x00, 0x02): /* REV/REV32 */
4847 case MAP(1, 0x00, 0x02):
4848 handle_rev32(s, sf, rn, rd);
4850 case MAP(1, 0x00, 0x03): /* REV64 */
4851 handle_rev64(s, sf, rn, rd);
4853 case MAP(0, 0x00, 0x04): /* CLZ */
4854 case MAP(1, 0x00, 0x04):
4855 handle_clz(s, sf, rn, rd);
4857 case MAP(0, 0x00, 0x05): /* CLS */
4858 case MAP(1, 0x00, 0x05):
4859 handle_cls(s, sf, rn, rd);
4861 case MAP(1, 0x01, 0x00): /* PACIA */
4862 if (s->pauth_active) {
4863 tcg_rd = cpu_reg(s, rd);
4864 gen_helper_pacia(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4865 } else if (!dc_isar_feature(aa64_pauth, s)) {
4866 goto do_unallocated;
4869 case MAP(1, 0x01, 0x01): /* PACIB */
4870 if (s->pauth_active) {
4871 tcg_rd = cpu_reg(s, rd);
4872 gen_helper_pacib(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4873 } else if (!dc_isar_feature(aa64_pauth, s)) {
4874 goto do_unallocated;
4877 case MAP(1, 0x01, 0x02): /* PACDA */
4878 if (s->pauth_active) {
4879 tcg_rd = cpu_reg(s, rd);
4880 gen_helper_pacda(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4881 } else if (!dc_isar_feature(aa64_pauth, s)) {
4882 goto do_unallocated;
4885 case MAP(1, 0x01, 0x03): /* PACDB */
4886 if (s->pauth_active) {
4887 tcg_rd = cpu_reg(s, rd);
4888 gen_helper_pacdb(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4889 } else if (!dc_isar_feature(aa64_pauth, s)) {
4890 goto do_unallocated;
4893 case MAP(1, 0x01, 0x04): /* AUTIA */
4894 if (s->pauth_active) {
4895 tcg_rd = cpu_reg(s, rd);
4896 gen_helper_autia(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4897 } else if (!dc_isar_feature(aa64_pauth, s)) {
4898 goto do_unallocated;
4901 case MAP(1, 0x01, 0x05): /* AUTIB */
4902 if (s->pauth_active) {
4903 tcg_rd = cpu_reg(s, rd);
4904 gen_helper_autib(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4905 } else if (!dc_isar_feature(aa64_pauth, s)) {
4906 goto do_unallocated;
4909 case MAP(1, 0x01, 0x06): /* AUTDA */
4910 if (s->pauth_active) {
4911 tcg_rd = cpu_reg(s, rd);
4912 gen_helper_autda(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4913 } else if (!dc_isar_feature(aa64_pauth, s)) {
4914 goto do_unallocated;
4917 case MAP(1, 0x01, 0x07): /* AUTDB */
4918 if (s->pauth_active) {
4919 tcg_rd = cpu_reg(s, rd);
4920 gen_helper_autdb(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4921 } else if (!dc_isar_feature(aa64_pauth, s)) {
4922 goto do_unallocated;
4925 case MAP(1, 0x01, 0x08): /* PACIZA */
4926 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4927 goto do_unallocated;
4928 } else if (s->pauth_active) {
4929 tcg_rd = cpu_reg(s, rd);
4930 gen_helper_pacia(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4933 case MAP(1, 0x01, 0x09): /* PACIZB */
4934 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4935 goto do_unallocated;
4936 } else if (s->pauth_active) {
4937 tcg_rd = cpu_reg(s, rd);
4938 gen_helper_pacib(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4941 case MAP(1, 0x01, 0x0a): /* PACDZA */
4942 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4943 goto do_unallocated;
4944 } else if (s->pauth_active) {
4945 tcg_rd = cpu_reg(s, rd);
4946 gen_helper_pacda(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4949 case MAP(1, 0x01, 0x0b): /* PACDZB */
4950 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4951 goto do_unallocated;
4952 } else if (s->pauth_active) {
4953 tcg_rd = cpu_reg(s, rd);
4954 gen_helper_pacdb(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4957 case MAP(1, 0x01, 0x0c): /* AUTIZA */
4958 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4959 goto do_unallocated;
4960 } else if (s->pauth_active) {
4961 tcg_rd = cpu_reg(s, rd);
4962 gen_helper_autia(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4965 case MAP(1, 0x01, 0x0d): /* AUTIZB */
4966 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4967 goto do_unallocated;
4968 } else if (s->pauth_active) {
4969 tcg_rd = cpu_reg(s, rd);
4970 gen_helper_autib(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4973 case MAP(1, 0x01, 0x0e): /* AUTDZA */
4974 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4975 goto do_unallocated;
4976 } else if (s->pauth_active) {
4977 tcg_rd = cpu_reg(s, rd);
4978 gen_helper_autda(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4981 case MAP(1, 0x01, 0x0f): /* AUTDZB */
4982 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4983 goto do_unallocated;
4984 } else if (s->pauth_active) {
4985 tcg_rd = cpu_reg(s, rd);
4986 gen_helper_autdb(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4989 case MAP(1, 0x01, 0x10): /* XPACI */
4990 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4991 goto do_unallocated;
4992 } else if (s->pauth_active) {
4993 tcg_rd = cpu_reg(s, rd);
4994 gen_helper_xpaci(tcg_rd, cpu_env, tcg_rd);
4997 case MAP(1, 0x01, 0x11): /* XPACD */
4998 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4999 goto do_unallocated;
5000 } else if (s->pauth_active) {
5001 tcg_rd = cpu_reg(s, rd);
5002 gen_helper_xpacd(tcg_rd, cpu_env, tcg_rd);
5007 unallocated_encoding(s);
5014 static void handle_div(DisasContext *s, bool is_signed, unsigned int sf,
5015 unsigned int rm, unsigned int rn, unsigned int rd)
5017 TCGv_i64 tcg_n, tcg_m, tcg_rd;
5018 tcg_rd = cpu_reg(s, rd);
5020 if (!sf && is_signed) {
5021 tcg_n = new_tmp_a64(s);
5022 tcg_m = new_tmp_a64(s);
5023 tcg_gen_ext32s_i64(tcg_n, cpu_reg(s, rn));
5024 tcg_gen_ext32s_i64(tcg_m, cpu_reg(s, rm));
5026 tcg_n = read_cpu_reg(s, rn, sf);
5027 tcg_m = read_cpu_reg(s, rm, sf);
5031 gen_helper_sdiv64(tcg_rd, tcg_n, tcg_m);
5033 gen_helper_udiv64(tcg_rd, tcg_n, tcg_m);
5036 if (!sf) { /* zero extend final result */
5037 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
5041 /* LSLV, LSRV, ASRV, RORV */
5042 static void handle_shift_reg(DisasContext *s,
5043 enum a64_shift_type shift_type, unsigned int sf,
5044 unsigned int rm, unsigned int rn, unsigned int rd)
5046 TCGv_i64 tcg_shift = tcg_temp_new_i64();
5047 TCGv_i64 tcg_rd = cpu_reg(s, rd);
5048 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
5050 tcg_gen_andi_i64(tcg_shift, cpu_reg(s, rm), sf ? 63 : 31);
5051 shift_reg(tcg_rd, tcg_rn, sf, shift_type, tcg_shift);
5052 tcg_temp_free_i64(tcg_shift);
5055 /* CRC32[BHWX], CRC32C[BHWX] */
5056 static void handle_crc32(DisasContext *s,
5057 unsigned int sf, unsigned int sz, bool crc32c,
5058 unsigned int rm, unsigned int rn, unsigned int rd)
5060 TCGv_i64 tcg_acc, tcg_val;
5063 if (!dc_isar_feature(aa64_crc32, s)
5064 || (sf == 1 && sz != 3)
5065 || (sf == 0 && sz == 3)) {
5066 unallocated_encoding(s);
5071 tcg_val = cpu_reg(s, rm);
5085 g_assert_not_reached();
5087 tcg_val = new_tmp_a64(s);
5088 tcg_gen_andi_i64(tcg_val, cpu_reg(s, rm), mask);
5091 tcg_acc = cpu_reg(s, rn);
5092 tcg_bytes = tcg_const_i32(1 << sz);
5095 gen_helper_crc32c_64(cpu_reg(s, rd), tcg_acc, tcg_val, tcg_bytes);
5097 gen_helper_crc32_64(cpu_reg(s, rd), tcg_acc, tcg_val, tcg_bytes);
5100 tcg_temp_free_i32(tcg_bytes);
5103 /* Data-processing (2 source)
5104 * 31 30 29 28 21 20 16 15 10 9 5 4 0
5105 * +----+---+---+-----------------+------+--------+------+------+
5106 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
5107 * +----+---+---+-----------------+------+--------+------+------+
5109 static void disas_data_proc_2src(DisasContext *s, uint32_t insn)
5111 unsigned int sf, rm, opcode, rn, rd;
5112 sf = extract32(insn, 31, 1);
5113 rm = extract32(insn, 16, 5);
5114 opcode = extract32(insn, 10, 6);
5115 rn = extract32(insn, 5, 5);
5116 rd = extract32(insn, 0, 5);
5118 if (extract32(insn, 29, 1)) {
5119 unallocated_encoding(s);
5125 handle_div(s, false, sf, rm, rn, rd);
5128 handle_div(s, true, sf, rm, rn, rd);
5131 handle_shift_reg(s, A64_SHIFT_TYPE_LSL, sf, rm, rn, rd);
5134 handle_shift_reg(s, A64_SHIFT_TYPE_LSR, sf, rm, rn, rd);
5137 handle_shift_reg(s, A64_SHIFT_TYPE_ASR, sf, rm, rn, rd);
5140 handle_shift_reg(s, A64_SHIFT_TYPE_ROR, sf, rm, rn, rd);
5142 case 12: /* PACGA */
5143 if (sf == 0 || !dc_isar_feature(aa64_pauth, s)) {
5144 goto do_unallocated;
5146 gen_helper_pacga(cpu_reg(s, rd), cpu_env,
5147 cpu_reg(s, rn), cpu_reg_sp(s, rm));
5156 case 23: /* CRC32 */
5158 int sz = extract32(opcode, 0, 2);
5159 bool crc32c = extract32(opcode, 2, 1);
5160 handle_crc32(s, sf, sz, crc32c, rm, rn, rd);
5165 unallocated_encoding(s);
5171 * Data processing - register
5172 * 31 30 29 28 25 21 20 16 10 0
5173 * +--+---+--+---+-------+-----+-------+-------+---------+
5174 * | |op0| |op1| 1 0 1 | op2 | | op3 | |
5175 * +--+---+--+---+-------+-----+-------+-------+---------+
5177 static void disas_data_proc_reg(DisasContext *s, uint32_t insn)
5179 int op0 = extract32(insn, 30, 1);
5180 int op1 = extract32(insn, 28, 1);
5181 int op2 = extract32(insn, 21, 4);
5182 int op3 = extract32(insn, 10, 6);
5187 /* Add/sub (extended register) */
5188 disas_add_sub_ext_reg(s, insn);
5190 /* Add/sub (shifted register) */
5191 disas_add_sub_reg(s, insn);
5194 /* Logical (shifted register) */
5195 disas_logic_reg(s, insn);
5203 case 0x00: /* Add/subtract (with carry) */
5204 disas_adc_sbc(s, insn);
5207 case 0x01: /* Rotate right into flags */
5209 disas_rotate_right_into_flags(s, insn);
5212 case 0x02: /* Evaluate into flags */
5216 disas_evaluate_into_flags(s, insn);
5220 goto do_unallocated;
5224 case 0x2: /* Conditional compare */
5225 disas_cc(s, insn); /* both imm and reg forms */
5228 case 0x4: /* Conditional select */
5229 disas_cond_select(s, insn);
5232 case 0x6: /* Data-processing */
5233 if (op0) { /* (1 source) */
5234 disas_data_proc_1src(s, insn);
5235 } else { /* (2 source) */
5236 disas_data_proc_2src(s, insn);
5239 case 0x8 ... 0xf: /* (3 source) */
5240 disas_data_proc_3src(s, insn);
5245 unallocated_encoding(s);
5250 static void handle_fp_compare(DisasContext *s, int size,
5251 unsigned int rn, unsigned int rm,
5252 bool cmp_with_zero, bool signal_all_nans)
5254 TCGv_i64 tcg_flags = tcg_temp_new_i64();
5255 TCGv_ptr fpst = get_fpstatus_ptr(size == MO_16);
5257 if (size == MO_64) {
5258 TCGv_i64 tcg_vn, tcg_vm;
5260 tcg_vn = read_fp_dreg(s, rn);
5261 if (cmp_with_zero) {
5262 tcg_vm = tcg_const_i64(0);
5264 tcg_vm = read_fp_dreg(s, rm);
5266 if (signal_all_nans) {
5267 gen_helper_vfp_cmped_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5269 gen_helper_vfp_cmpd_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5271 tcg_temp_free_i64(tcg_vn);
5272 tcg_temp_free_i64(tcg_vm);
5274 TCGv_i32 tcg_vn = tcg_temp_new_i32();
5275 TCGv_i32 tcg_vm = tcg_temp_new_i32();
5277 read_vec_element_i32(s, tcg_vn, rn, 0, size);
5278 if (cmp_with_zero) {
5279 tcg_gen_movi_i32(tcg_vm, 0);
5281 read_vec_element_i32(s, tcg_vm, rm, 0, size);
5286 if (signal_all_nans) {
5287 gen_helper_vfp_cmpes_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5289 gen_helper_vfp_cmps_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5293 if (signal_all_nans) {
5294 gen_helper_vfp_cmpeh_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5296 gen_helper_vfp_cmph_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5300 g_assert_not_reached();
5303 tcg_temp_free_i32(tcg_vn);
5304 tcg_temp_free_i32(tcg_vm);
5307 tcg_temp_free_ptr(fpst);
5309 gen_set_nzcv(tcg_flags);
5311 tcg_temp_free_i64(tcg_flags);
5314 /* Floating point compare
5315 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
5316 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5317 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
5318 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5320 static void disas_fp_compare(DisasContext *s, uint32_t insn)
5322 unsigned int mos, type, rm, op, rn, opc, op2r;
5325 mos = extract32(insn, 29, 3);
5326 type = extract32(insn, 22, 2);
5327 rm = extract32(insn, 16, 5);
5328 op = extract32(insn, 14, 2);
5329 rn = extract32(insn, 5, 5);
5330 opc = extract32(insn, 3, 2);
5331 op2r = extract32(insn, 0, 3);
5333 if (mos || op || op2r) {
5334 unallocated_encoding(s);
5347 if (dc_isar_feature(aa64_fp16, s)) {
5352 unallocated_encoding(s);
5356 if (!fp_access_check(s)) {
5360 handle_fp_compare(s, size, rn, rm, opc & 1, opc & 2);
5363 /* Floating point conditional compare
5364 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
5365 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5366 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
5367 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5369 static void disas_fp_ccomp(DisasContext *s, uint32_t insn)
5371 unsigned int mos, type, rm, cond, rn, op, nzcv;
5373 TCGLabel *label_continue = NULL;
5376 mos = extract32(insn, 29, 3);
5377 type = extract32(insn, 22, 2);
5378 rm = extract32(insn, 16, 5);
5379 cond = extract32(insn, 12, 4);
5380 rn = extract32(insn, 5, 5);
5381 op = extract32(insn, 4, 1);
5382 nzcv = extract32(insn, 0, 4);
5385 unallocated_encoding(s);
5398 if (dc_isar_feature(aa64_fp16, s)) {
5403 unallocated_encoding(s);
5407 if (!fp_access_check(s)) {
5411 if (cond < 0x0e) { /* not always */
5412 TCGLabel *label_match = gen_new_label();
5413 label_continue = gen_new_label();
5414 arm_gen_test_cc(cond, label_match);
5416 tcg_flags = tcg_const_i64(nzcv << 28);
5417 gen_set_nzcv(tcg_flags);
5418 tcg_temp_free_i64(tcg_flags);
5419 tcg_gen_br(label_continue);
5420 gen_set_label(label_match);
5423 handle_fp_compare(s, size, rn, rm, false, op);
5426 gen_set_label(label_continue);
5430 /* Floating point conditional select
5431 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5432 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5433 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
5434 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5436 static void disas_fp_csel(DisasContext *s, uint32_t insn)
5438 unsigned int mos, type, rm, cond, rn, rd;
5439 TCGv_i64 t_true, t_false, t_zero;
5443 mos = extract32(insn, 29, 3);
5444 type = extract32(insn, 22, 2);
5445 rm = extract32(insn, 16, 5);
5446 cond = extract32(insn, 12, 4);
5447 rn = extract32(insn, 5, 5);
5448 rd = extract32(insn, 0, 5);
5451 unallocated_encoding(s);
5464 if (dc_isar_feature(aa64_fp16, s)) {
5469 unallocated_encoding(s);
5473 if (!fp_access_check(s)) {
5477 /* Zero extend sreg & hreg inputs to 64 bits now. */
5478 t_true = tcg_temp_new_i64();
5479 t_false = tcg_temp_new_i64();
5480 read_vec_element(s, t_true, rn, 0, sz);
5481 read_vec_element(s, t_false, rm, 0, sz);
5483 a64_test_cc(&c, cond);
5484 t_zero = tcg_const_i64(0);
5485 tcg_gen_movcond_i64(c.cond, t_true, c.value, t_zero, t_true, t_false);
5486 tcg_temp_free_i64(t_zero);
5487 tcg_temp_free_i64(t_false);
5490 /* Note that sregs & hregs write back zeros to the high bits,
5491 and we've already done the zero-extension. */
5492 write_fp_dreg(s, rd, t_true);
5493 tcg_temp_free_i64(t_true);
5496 /* Floating-point data-processing (1 source) - half precision */
5497 static void handle_fp_1src_half(DisasContext *s, int opcode, int rd, int rn)
5499 TCGv_ptr fpst = NULL;
5500 TCGv_i32 tcg_op = read_fp_hreg(s, rn);
5501 TCGv_i32 tcg_res = tcg_temp_new_i32();
5504 case 0x0: /* FMOV */
5505 tcg_gen_mov_i32(tcg_res, tcg_op);
5507 case 0x1: /* FABS */
5508 tcg_gen_andi_i32(tcg_res, tcg_op, 0x7fff);
5510 case 0x2: /* FNEG */
5511 tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000);
5513 case 0x3: /* FSQRT */
5514 fpst = get_fpstatus_ptr(true);
5515 gen_helper_sqrt_f16(tcg_res, tcg_op, fpst);
5517 case 0x8: /* FRINTN */
5518 case 0x9: /* FRINTP */
5519 case 0xa: /* FRINTM */
5520 case 0xb: /* FRINTZ */
5521 case 0xc: /* FRINTA */
5523 TCGv_i32 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(opcode & 7));
5524 fpst = get_fpstatus_ptr(true);
5526 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5527 gen_helper_advsimd_rinth(tcg_res, tcg_op, fpst);
5529 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5530 tcg_temp_free_i32(tcg_rmode);
5533 case 0xe: /* FRINTX */
5534 fpst = get_fpstatus_ptr(true);
5535 gen_helper_advsimd_rinth_exact(tcg_res, tcg_op, fpst);
5537 case 0xf: /* FRINTI */
5538 fpst = get_fpstatus_ptr(true);
5539 gen_helper_advsimd_rinth(tcg_res, tcg_op, fpst);
5545 write_fp_sreg(s, rd, tcg_res);
5548 tcg_temp_free_ptr(fpst);
5550 tcg_temp_free_i32(tcg_op);
5551 tcg_temp_free_i32(tcg_res);
5554 /* Floating-point data-processing (1 source) - single precision */
5555 static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn)
5557 void (*gen_fpst)(TCGv_i32, TCGv_i32, TCGv_ptr);
5558 TCGv_i32 tcg_op, tcg_res;
5562 tcg_op = read_fp_sreg(s, rn);
5563 tcg_res = tcg_temp_new_i32();
5566 case 0x0: /* FMOV */
5567 tcg_gen_mov_i32(tcg_res, tcg_op);
5569 case 0x1: /* FABS */
5570 gen_helper_vfp_abss(tcg_res, tcg_op);
5572 case 0x2: /* FNEG */
5573 gen_helper_vfp_negs(tcg_res, tcg_op);
5575 case 0x3: /* FSQRT */
5576 gen_helper_vfp_sqrts(tcg_res, tcg_op, cpu_env);
5578 case 0x8: /* FRINTN */
5579 case 0x9: /* FRINTP */
5580 case 0xa: /* FRINTM */
5581 case 0xb: /* FRINTZ */
5582 case 0xc: /* FRINTA */
5583 rmode = arm_rmode_to_sf(opcode & 7);
5584 gen_fpst = gen_helper_rints;
5586 case 0xe: /* FRINTX */
5587 gen_fpst = gen_helper_rints_exact;
5589 case 0xf: /* FRINTI */
5590 gen_fpst = gen_helper_rints;
5592 case 0x10: /* FRINT32Z */
5593 rmode = float_round_to_zero;
5594 gen_fpst = gen_helper_frint32_s;
5596 case 0x11: /* FRINT32X */
5597 gen_fpst = gen_helper_frint32_s;
5599 case 0x12: /* FRINT64Z */
5600 rmode = float_round_to_zero;
5601 gen_fpst = gen_helper_frint64_s;
5603 case 0x13: /* FRINT64X */
5604 gen_fpst = gen_helper_frint64_s;
5607 g_assert_not_reached();
5610 fpst = get_fpstatus_ptr(false);
5612 TCGv_i32 tcg_rmode = tcg_const_i32(rmode);
5613 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5614 gen_fpst(tcg_res, tcg_op, fpst);
5615 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5616 tcg_temp_free_i32(tcg_rmode);
5618 gen_fpst(tcg_res, tcg_op, fpst);
5620 tcg_temp_free_ptr(fpst);
5623 write_fp_sreg(s, rd, tcg_res);
5624 tcg_temp_free_i32(tcg_op);
5625 tcg_temp_free_i32(tcg_res);
5628 /* Floating-point data-processing (1 source) - double precision */
5629 static void handle_fp_1src_double(DisasContext *s, int opcode, int rd, int rn)
5631 void (*gen_fpst)(TCGv_i64, TCGv_i64, TCGv_ptr);
5632 TCGv_i64 tcg_op, tcg_res;
5637 case 0x0: /* FMOV */
5638 gen_gvec_fn2(s, false, rd, rn, tcg_gen_gvec_mov, 0);
5642 tcg_op = read_fp_dreg(s, rn);
5643 tcg_res = tcg_temp_new_i64();
5646 case 0x1: /* FABS */
5647 gen_helper_vfp_absd(tcg_res, tcg_op);
5649 case 0x2: /* FNEG */
5650 gen_helper_vfp_negd(tcg_res, tcg_op);
5652 case 0x3: /* FSQRT */
5653 gen_helper_vfp_sqrtd(tcg_res, tcg_op, cpu_env);
5655 case 0x8: /* FRINTN */
5656 case 0x9: /* FRINTP */
5657 case 0xa: /* FRINTM */
5658 case 0xb: /* FRINTZ */
5659 case 0xc: /* FRINTA */
5660 rmode = arm_rmode_to_sf(opcode & 7);
5661 gen_fpst = gen_helper_rintd;
5663 case 0xe: /* FRINTX */
5664 gen_fpst = gen_helper_rintd_exact;
5666 case 0xf: /* FRINTI */
5667 gen_fpst = gen_helper_rintd;
5669 case 0x10: /* FRINT32Z */
5670 rmode = float_round_to_zero;
5671 gen_fpst = gen_helper_frint32_d;
5673 case 0x11: /* FRINT32X */
5674 gen_fpst = gen_helper_frint32_d;
5676 case 0x12: /* FRINT64Z */
5677 rmode = float_round_to_zero;
5678 gen_fpst = gen_helper_frint64_d;
5680 case 0x13: /* FRINT64X */
5681 gen_fpst = gen_helper_frint64_d;
5684 g_assert_not_reached();
5687 fpst = get_fpstatus_ptr(false);
5689 TCGv_i32 tcg_rmode = tcg_const_i32(rmode);
5690 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5691 gen_fpst(tcg_res, tcg_op, fpst);
5692 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5693 tcg_temp_free_i32(tcg_rmode);
5695 gen_fpst(tcg_res, tcg_op, fpst);
5697 tcg_temp_free_ptr(fpst);
5700 write_fp_dreg(s, rd, tcg_res);
5701 tcg_temp_free_i64(tcg_op);
5702 tcg_temp_free_i64(tcg_res);
5705 static void handle_fp_fcvt(DisasContext *s, int opcode,
5706 int rd, int rn, int dtype, int ntype)
5711 TCGv_i32 tcg_rn = read_fp_sreg(s, rn);
5713 /* Single to double */
5714 TCGv_i64 tcg_rd = tcg_temp_new_i64();
5715 gen_helper_vfp_fcvtds(tcg_rd, tcg_rn, cpu_env);
5716 write_fp_dreg(s, rd, tcg_rd);
5717 tcg_temp_free_i64(tcg_rd);
5719 /* Single to half */
5720 TCGv_i32 tcg_rd = tcg_temp_new_i32();
5721 TCGv_i32 ahp = get_ahp_flag();
5722 TCGv_ptr fpst = get_fpstatus_ptr(false);
5724 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd, tcg_rn, fpst, ahp);
5725 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5726 write_fp_sreg(s, rd, tcg_rd);
5727 tcg_temp_free_i32(tcg_rd);
5728 tcg_temp_free_i32(ahp);
5729 tcg_temp_free_ptr(fpst);
5731 tcg_temp_free_i32(tcg_rn);
5736 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
5737 TCGv_i32 tcg_rd = tcg_temp_new_i32();
5739 /* Double to single */
5740 gen_helper_vfp_fcvtsd(tcg_rd, tcg_rn, cpu_env);
5742 TCGv_ptr fpst = get_fpstatus_ptr(false);
5743 TCGv_i32 ahp = get_ahp_flag();
5744 /* Double to half */
5745 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd, tcg_rn, fpst, ahp);
5746 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5747 tcg_temp_free_ptr(fpst);
5748 tcg_temp_free_i32(ahp);
5750 write_fp_sreg(s, rd, tcg_rd);
5751 tcg_temp_free_i32(tcg_rd);
5752 tcg_temp_free_i64(tcg_rn);
5757 TCGv_i32 tcg_rn = read_fp_sreg(s, rn);
5758 TCGv_ptr tcg_fpst = get_fpstatus_ptr(false);
5759 TCGv_i32 tcg_ahp = get_ahp_flag();
5760 tcg_gen_ext16u_i32(tcg_rn, tcg_rn);
5762 /* Half to single */
5763 TCGv_i32 tcg_rd = tcg_temp_new_i32();
5764 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd, tcg_rn, tcg_fpst, tcg_ahp);
5765 write_fp_sreg(s, rd, tcg_rd);
5766 tcg_temp_free_ptr(tcg_fpst);
5767 tcg_temp_free_i32(tcg_ahp);
5768 tcg_temp_free_i32(tcg_rd);
5770 /* Half to double */
5771 TCGv_i64 tcg_rd = tcg_temp_new_i64();
5772 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd, tcg_rn, tcg_fpst, tcg_ahp);
5773 write_fp_dreg(s, rd, tcg_rd);
5774 tcg_temp_free_i64(tcg_rd);
5776 tcg_temp_free_i32(tcg_rn);
5784 /* Floating point data-processing (1 source)
5785 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
5786 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5787 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
5788 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5790 static void disas_fp_1src(DisasContext *s, uint32_t insn)
5792 int mos = extract32(insn, 29, 3);
5793 int type = extract32(insn, 22, 2);
5794 int opcode = extract32(insn, 15, 6);
5795 int rn = extract32(insn, 5, 5);
5796 int rd = extract32(insn, 0, 5);
5799 unallocated_encoding(s);
5804 case 0x4: case 0x5: case 0x7:
5806 /* FCVT between half, single and double precision */
5807 int dtype = extract32(opcode, 0, 2);
5808 if (type == 2 || dtype == type) {
5809 unallocated_encoding(s);
5812 if (!fp_access_check(s)) {
5816 handle_fp_fcvt(s, opcode, rd, rn, dtype, type);
5820 case 0x10 ... 0x13: /* FRINT{32,64}{X,Z} */
5821 if (type > 1 || !dc_isar_feature(aa64_frint, s)) {
5822 unallocated_encoding(s);
5829 /* 32-to-32 and 64-to-64 ops */
5832 if (!fp_access_check(s)) {
5835 handle_fp_1src_single(s, opcode, rd, rn);
5838 if (!fp_access_check(s)) {
5841 handle_fp_1src_double(s, opcode, rd, rn);
5844 if (!dc_isar_feature(aa64_fp16, s)) {
5845 unallocated_encoding(s);
5849 if (!fp_access_check(s)) {
5852 handle_fp_1src_half(s, opcode, rd, rn);
5855 unallocated_encoding(s);
5860 unallocated_encoding(s);
5865 /* Floating-point data-processing (2 source) - single precision */
5866 static void handle_fp_2src_single(DisasContext *s, int opcode,
5867 int rd, int rn, int rm)
5874 tcg_res = tcg_temp_new_i32();
5875 fpst = get_fpstatus_ptr(false);
5876 tcg_op1 = read_fp_sreg(s, rn);
5877 tcg_op2 = read_fp_sreg(s, rm);
5880 case 0x0: /* FMUL */
5881 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
5883 case 0x1: /* FDIV */
5884 gen_helper_vfp_divs(tcg_res, tcg_op1, tcg_op2, fpst);
5886 case 0x2: /* FADD */
5887 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
5889 case 0x3: /* FSUB */
5890 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
5892 case 0x4: /* FMAX */
5893 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
5895 case 0x5: /* FMIN */
5896 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
5898 case 0x6: /* FMAXNM */
5899 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
5901 case 0x7: /* FMINNM */
5902 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
5904 case 0x8: /* FNMUL */
5905 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
5906 gen_helper_vfp_negs(tcg_res, tcg_res);
5910 write_fp_sreg(s, rd, tcg_res);
5912 tcg_temp_free_ptr(fpst);
5913 tcg_temp_free_i32(tcg_op1);
5914 tcg_temp_free_i32(tcg_op2);
5915 tcg_temp_free_i32(tcg_res);
5918 /* Floating-point data-processing (2 source) - double precision */
5919 static void handle_fp_2src_double(DisasContext *s, int opcode,
5920 int rd, int rn, int rm)
5927 tcg_res = tcg_temp_new_i64();
5928 fpst = get_fpstatus_ptr(false);
5929 tcg_op1 = read_fp_dreg(s, rn);
5930 tcg_op2 = read_fp_dreg(s, rm);
5933 case 0x0: /* FMUL */
5934 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
5936 case 0x1: /* FDIV */
5937 gen_helper_vfp_divd(tcg_res, tcg_op1, tcg_op2, fpst);
5939 case 0x2: /* FADD */
5940 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
5942 case 0x3: /* FSUB */
5943 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
5945 case 0x4: /* FMAX */
5946 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
5948 case 0x5: /* FMIN */
5949 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
5951 case 0x6: /* FMAXNM */
5952 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
5954 case 0x7: /* FMINNM */
5955 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
5957 case 0x8: /* FNMUL */
5958 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
5959 gen_helper_vfp_negd(tcg_res, tcg_res);
5963 write_fp_dreg(s, rd, tcg_res);
5965 tcg_temp_free_ptr(fpst);
5966 tcg_temp_free_i64(tcg_op1);
5967 tcg_temp_free_i64(tcg_op2);
5968 tcg_temp_free_i64(tcg_res);
5971 /* Floating-point data-processing (2 source) - half precision */
5972 static void handle_fp_2src_half(DisasContext *s, int opcode,
5973 int rd, int rn, int rm)
5980 tcg_res = tcg_temp_new_i32();
5981 fpst = get_fpstatus_ptr(true);
5982 tcg_op1 = read_fp_hreg(s, rn);
5983 tcg_op2 = read_fp_hreg(s, rm);
5986 case 0x0: /* FMUL */
5987 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
5989 case 0x1: /* FDIV */
5990 gen_helper_advsimd_divh(tcg_res, tcg_op1, tcg_op2, fpst);
5992 case 0x2: /* FADD */
5993 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
5995 case 0x3: /* FSUB */
5996 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
5998 case 0x4: /* FMAX */
5999 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
6001 case 0x5: /* FMIN */
6002 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
6004 case 0x6: /* FMAXNM */
6005 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
6007 case 0x7: /* FMINNM */
6008 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
6010 case 0x8: /* FNMUL */
6011 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
6012 tcg_gen_xori_i32(tcg_res, tcg_res, 0x8000);
6015 g_assert_not_reached();
6018 write_fp_sreg(s, rd, tcg_res);
6020 tcg_temp_free_ptr(fpst);
6021 tcg_temp_free_i32(tcg_op1);
6022 tcg_temp_free_i32(tcg_op2);
6023 tcg_temp_free_i32(tcg_res);
6026 /* Floating point data-processing (2 source)
6027 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6028 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6029 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
6030 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6032 static void disas_fp_2src(DisasContext *s, uint32_t insn)
6034 int mos = extract32(insn, 29, 3);
6035 int type = extract32(insn, 22, 2);
6036 int rd = extract32(insn, 0, 5);
6037 int rn = extract32(insn, 5, 5);
6038 int rm = extract32(insn, 16, 5);
6039 int opcode = extract32(insn, 12, 4);
6041 if (opcode > 8 || mos) {
6042 unallocated_encoding(s);
6048 if (!fp_access_check(s)) {
6051 handle_fp_2src_single(s, opcode, rd, rn, rm);
6054 if (!fp_access_check(s)) {
6057 handle_fp_2src_double(s, opcode, rd, rn, rm);
6060 if (!dc_isar_feature(aa64_fp16, s)) {
6061 unallocated_encoding(s);
6064 if (!fp_access_check(s)) {
6067 handle_fp_2src_half(s, opcode, rd, rn, rm);
6070 unallocated_encoding(s);
6074 /* Floating-point data-processing (3 source) - single precision */
6075 static void handle_fp_3src_single(DisasContext *s, bool o0, bool o1,
6076 int rd, int rn, int rm, int ra)
6078 TCGv_i32 tcg_op1, tcg_op2, tcg_op3;
6079 TCGv_i32 tcg_res = tcg_temp_new_i32();
6080 TCGv_ptr fpst = get_fpstatus_ptr(false);
6082 tcg_op1 = read_fp_sreg(s, rn);
6083 tcg_op2 = read_fp_sreg(s, rm);
6084 tcg_op3 = read_fp_sreg(s, ra);
6086 /* These are fused multiply-add, and must be done as one
6087 * floating point operation with no rounding between the
6088 * multiplication and addition steps.
6089 * NB that doing the negations here as separate steps is
6090 * correct : an input NaN should come out with its sign bit
6091 * flipped if it is a negated-input.
6094 gen_helper_vfp_negs(tcg_op3, tcg_op3);
6098 gen_helper_vfp_negs(tcg_op1, tcg_op1);
6101 gen_helper_vfp_muladds(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
6103 write_fp_sreg(s, rd, tcg_res);
6105 tcg_temp_free_ptr(fpst);
6106 tcg_temp_free_i32(tcg_op1);
6107 tcg_temp_free_i32(tcg_op2);
6108 tcg_temp_free_i32(tcg_op3);
6109 tcg_temp_free_i32(tcg_res);
6112 /* Floating-point data-processing (3 source) - double precision */
6113 static void handle_fp_3src_double(DisasContext *s, bool o0, bool o1,
6114 int rd, int rn, int rm, int ra)
6116 TCGv_i64 tcg_op1, tcg_op2, tcg_op3;
6117 TCGv_i64 tcg_res = tcg_temp_new_i64();
6118 TCGv_ptr fpst = get_fpstatus_ptr(false);
6120 tcg_op1 = read_fp_dreg(s, rn);
6121 tcg_op2 = read_fp_dreg(s, rm);
6122 tcg_op3 = read_fp_dreg(s, ra);
6124 /* These are fused multiply-add, and must be done as one
6125 * floating point operation with no rounding between the
6126 * multiplication and addition steps.
6127 * NB that doing the negations here as separate steps is
6128 * correct : an input NaN should come out with its sign bit
6129 * flipped if it is a negated-input.
6132 gen_helper_vfp_negd(tcg_op3, tcg_op3);
6136 gen_helper_vfp_negd(tcg_op1, tcg_op1);
6139 gen_helper_vfp_muladdd(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
6141 write_fp_dreg(s, rd, tcg_res);
6143 tcg_temp_free_ptr(fpst);
6144 tcg_temp_free_i64(tcg_op1);
6145 tcg_temp_free_i64(tcg_op2);
6146 tcg_temp_free_i64(tcg_op3);
6147 tcg_temp_free_i64(tcg_res);
6150 /* Floating-point data-processing (3 source) - half precision */
6151 static void handle_fp_3src_half(DisasContext *s, bool o0, bool o1,
6152 int rd, int rn, int rm, int ra)
6154 TCGv_i32 tcg_op1, tcg_op2, tcg_op3;
6155 TCGv_i32 tcg_res = tcg_temp_new_i32();
6156 TCGv_ptr fpst = get_fpstatus_ptr(true);
6158 tcg_op1 = read_fp_hreg(s, rn);
6159 tcg_op2 = read_fp_hreg(s, rm);
6160 tcg_op3 = read_fp_hreg(s, ra);
6162 /* These are fused multiply-add, and must be done as one
6163 * floating point operation with no rounding between the
6164 * multiplication and addition steps.
6165 * NB that doing the negations here as separate steps is
6166 * correct : an input NaN should come out with its sign bit
6167 * flipped if it is a negated-input.
6170 tcg_gen_xori_i32(tcg_op3, tcg_op3, 0x8000);
6174 tcg_gen_xori_i32(tcg_op1, tcg_op1, 0x8000);
6177 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
6179 write_fp_sreg(s, rd, tcg_res);
6181 tcg_temp_free_ptr(fpst);
6182 tcg_temp_free_i32(tcg_op1);
6183 tcg_temp_free_i32(tcg_op2);
6184 tcg_temp_free_i32(tcg_op3);
6185 tcg_temp_free_i32(tcg_res);
6188 /* Floating point data-processing (3 source)
6189 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
6190 * +---+---+---+-----------+------+----+------+----+------+------+------+
6191 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
6192 * +---+---+---+-----------+------+----+------+----+------+------+------+
6194 static void disas_fp_3src(DisasContext *s, uint32_t insn)
6196 int mos = extract32(insn, 29, 3);
6197 int type = extract32(insn, 22, 2);
6198 int rd = extract32(insn, 0, 5);
6199 int rn = extract32(insn, 5, 5);
6200 int ra = extract32(insn, 10, 5);
6201 int rm = extract32(insn, 16, 5);
6202 bool o0 = extract32(insn, 15, 1);
6203 bool o1 = extract32(insn, 21, 1);
6206 unallocated_encoding(s);
6212 if (!fp_access_check(s)) {
6215 handle_fp_3src_single(s, o0, o1, rd, rn, rm, ra);
6218 if (!fp_access_check(s)) {
6221 handle_fp_3src_double(s, o0, o1, rd, rn, rm, ra);
6224 if (!dc_isar_feature(aa64_fp16, s)) {
6225 unallocated_encoding(s);
6228 if (!fp_access_check(s)) {
6231 handle_fp_3src_half(s, o0, o1, rd, rn, rm, ra);
6234 unallocated_encoding(s);
6238 /* Floating point immediate
6239 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
6240 * +---+---+---+-----------+------+---+------------+-------+------+------+
6241 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
6242 * +---+---+---+-----------+------+---+------------+-------+------+------+
6244 static void disas_fp_imm(DisasContext *s, uint32_t insn)
6246 int rd = extract32(insn, 0, 5);
6247 int imm5 = extract32(insn, 5, 5);
6248 int imm8 = extract32(insn, 13, 8);
6249 int type = extract32(insn, 22, 2);
6250 int mos = extract32(insn, 29, 3);
6256 unallocated_encoding(s);
6269 if (dc_isar_feature(aa64_fp16, s)) {
6274 unallocated_encoding(s);
6278 if (!fp_access_check(s)) {
6282 imm = vfp_expand_imm(sz, imm8);
6284 tcg_res = tcg_const_i64(imm);
6285 write_fp_dreg(s, rd, tcg_res);
6286 tcg_temp_free_i64(tcg_res);
6289 /* Handle floating point <=> fixed point conversions. Note that we can
6290 * also deal with fp <=> integer conversions as a special case (scale == 64)
6291 * OPTME: consider handling that special case specially or at least skipping
6292 * the call to scalbn in the helpers for zero shifts.
6294 static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode,
6295 bool itof, int rmode, int scale, int sf, int type)
6297 bool is_signed = !(opcode & 1);
6298 TCGv_ptr tcg_fpstatus;
6299 TCGv_i32 tcg_shift, tcg_single;
6300 TCGv_i64 tcg_double;
6302 tcg_fpstatus = get_fpstatus_ptr(type == 3);
6304 tcg_shift = tcg_const_i32(64 - scale);
6307 TCGv_i64 tcg_int = cpu_reg(s, rn);
6309 TCGv_i64 tcg_extend = new_tmp_a64(s);
6312 tcg_gen_ext32s_i64(tcg_extend, tcg_int);
6314 tcg_gen_ext32u_i64(tcg_extend, tcg_int);
6317 tcg_int = tcg_extend;
6321 case 1: /* float64 */
6322 tcg_double = tcg_temp_new_i64();
6324 gen_helper_vfp_sqtod(tcg_double, tcg_int,
6325 tcg_shift, tcg_fpstatus);
6327 gen_helper_vfp_uqtod(tcg_double, tcg_int,
6328 tcg_shift, tcg_fpstatus);
6330 write_fp_dreg(s, rd, tcg_double);
6331 tcg_temp_free_i64(tcg_double);
6334 case 0: /* float32 */
6335 tcg_single = tcg_temp_new_i32();
6337 gen_helper_vfp_sqtos(tcg_single, tcg_int,
6338 tcg_shift, tcg_fpstatus);
6340 gen_helper_vfp_uqtos(tcg_single, tcg_int,
6341 tcg_shift, tcg_fpstatus);
6343 write_fp_sreg(s, rd, tcg_single);
6344 tcg_temp_free_i32(tcg_single);
6347 case 3: /* float16 */
6348 tcg_single = tcg_temp_new_i32();
6350 gen_helper_vfp_sqtoh(tcg_single, tcg_int,
6351 tcg_shift, tcg_fpstatus);
6353 gen_helper_vfp_uqtoh(tcg_single, tcg_int,
6354 tcg_shift, tcg_fpstatus);
6356 write_fp_sreg(s, rd, tcg_single);
6357 tcg_temp_free_i32(tcg_single);
6361 g_assert_not_reached();
6364 TCGv_i64 tcg_int = cpu_reg(s, rd);
6367 if (extract32(opcode, 2, 1)) {
6368 /* There are too many rounding modes to all fit into rmode,
6369 * so FCVTA[US] is a special case.
6371 rmode = FPROUNDING_TIEAWAY;
6374 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
6376 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
6379 case 1: /* float64 */
6380 tcg_double = read_fp_dreg(s, rn);
6383 gen_helper_vfp_tosld(tcg_int, tcg_double,
6384 tcg_shift, tcg_fpstatus);
6386 gen_helper_vfp_tosqd(tcg_int, tcg_double,
6387 tcg_shift, tcg_fpstatus);
6391 gen_helper_vfp_tould(tcg_int, tcg_double,
6392 tcg_shift, tcg_fpstatus);
6394 gen_helper_vfp_touqd(tcg_int, tcg_double,
6395 tcg_shift, tcg_fpstatus);
6399 tcg_gen_ext32u_i64(tcg_int, tcg_int);
6401 tcg_temp_free_i64(tcg_double);
6404 case 0: /* float32 */
6405 tcg_single = read_fp_sreg(s, rn);
6408 gen_helper_vfp_tosqs(tcg_int, tcg_single,
6409 tcg_shift, tcg_fpstatus);
6411 gen_helper_vfp_touqs(tcg_int, tcg_single,
6412 tcg_shift, tcg_fpstatus);
6415 TCGv_i32 tcg_dest = tcg_temp_new_i32();
6417 gen_helper_vfp_tosls(tcg_dest, tcg_single,
6418 tcg_shift, tcg_fpstatus);
6420 gen_helper_vfp_touls(tcg_dest, tcg_single,
6421 tcg_shift, tcg_fpstatus);
6423 tcg_gen_extu_i32_i64(tcg_int, tcg_dest);
6424 tcg_temp_free_i32(tcg_dest);
6426 tcg_temp_free_i32(tcg_single);
6429 case 3: /* float16 */
6430 tcg_single = read_fp_sreg(s, rn);
6433 gen_helper_vfp_tosqh(tcg_int, tcg_single,
6434 tcg_shift, tcg_fpstatus);
6436 gen_helper_vfp_touqh(tcg_int, tcg_single,
6437 tcg_shift, tcg_fpstatus);
6440 TCGv_i32 tcg_dest = tcg_temp_new_i32();
6442 gen_helper_vfp_toslh(tcg_dest, tcg_single,
6443 tcg_shift, tcg_fpstatus);
6445 gen_helper_vfp_toulh(tcg_dest, tcg_single,
6446 tcg_shift, tcg_fpstatus);
6448 tcg_gen_extu_i32_i64(tcg_int, tcg_dest);
6449 tcg_temp_free_i32(tcg_dest);
6451 tcg_temp_free_i32(tcg_single);
6455 g_assert_not_reached();
6458 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
6459 tcg_temp_free_i32(tcg_rmode);
6462 tcg_temp_free_ptr(tcg_fpstatus);
6463 tcg_temp_free_i32(tcg_shift);
6466 /* Floating point <-> fixed point conversions
6467 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6468 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6469 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
6470 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6472 static void disas_fp_fixed_conv(DisasContext *s, uint32_t insn)
6474 int rd = extract32(insn, 0, 5);
6475 int rn = extract32(insn, 5, 5);
6476 int scale = extract32(insn, 10, 6);
6477 int opcode = extract32(insn, 16, 3);
6478 int rmode = extract32(insn, 19, 2);
6479 int type = extract32(insn, 22, 2);
6480 bool sbit = extract32(insn, 29, 1);
6481 bool sf = extract32(insn, 31, 1);
6484 if (sbit || (!sf && scale < 32)) {
6485 unallocated_encoding(s);
6490 case 0: /* float32 */
6491 case 1: /* float64 */
6493 case 3: /* float16 */
6494 if (dc_isar_feature(aa64_fp16, s)) {
6499 unallocated_encoding(s);
6503 switch ((rmode << 3) | opcode) {
6504 case 0x2: /* SCVTF */
6505 case 0x3: /* UCVTF */
6508 case 0x18: /* FCVTZS */
6509 case 0x19: /* FCVTZU */
6513 unallocated_encoding(s);
6517 if (!fp_access_check(s)) {
6521 handle_fpfpcvt(s, rd, rn, opcode, itof, FPROUNDING_ZERO, scale, sf, type);
6524 static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof)
6526 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
6527 * without conversion.
6531 TCGv_i64 tcg_rn = cpu_reg(s, rn);
6537 tmp = tcg_temp_new_i64();
6538 tcg_gen_ext32u_i64(tmp, tcg_rn);
6539 write_fp_dreg(s, rd, tmp);
6540 tcg_temp_free_i64(tmp);
6544 write_fp_dreg(s, rd, tcg_rn);
6547 /* 64 bit to top half. */
6548 tcg_gen_st_i64(tcg_rn, cpu_env, fp_reg_hi_offset(s, rd));
6549 clear_vec_high(s, true, rd);
6553 tmp = tcg_temp_new_i64();
6554 tcg_gen_ext16u_i64(tmp, tcg_rn);
6555 write_fp_dreg(s, rd, tmp);
6556 tcg_temp_free_i64(tmp);
6559 g_assert_not_reached();
6562 TCGv_i64 tcg_rd = cpu_reg(s, rd);
6567 tcg_gen_ld32u_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_32));
6571 tcg_gen_ld_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_64));
6574 /* 64 bits from top half */
6575 tcg_gen_ld_i64(tcg_rd, cpu_env, fp_reg_hi_offset(s, rn));
6579 tcg_gen_ld16u_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_16));
6582 g_assert_not_reached();
6587 static void handle_fjcvtzs(DisasContext *s, int rd, int rn)
6589 TCGv_i64 t = read_fp_dreg(s, rn);
6590 TCGv_ptr fpstatus = get_fpstatus_ptr(false);
6592 gen_helper_fjcvtzs(t, t, fpstatus);
6594 tcg_temp_free_ptr(fpstatus);
6596 tcg_gen_ext32u_i64(cpu_reg(s, rd), t);
6597 tcg_gen_extrh_i64_i32(cpu_ZF, t);
6598 tcg_gen_movi_i32(cpu_CF, 0);
6599 tcg_gen_movi_i32(cpu_NF, 0);
6600 tcg_gen_movi_i32(cpu_VF, 0);
6602 tcg_temp_free_i64(t);
6605 /* Floating point <-> integer conversions
6606 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6607 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6608 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
6609 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6611 static void disas_fp_int_conv(DisasContext *s, uint32_t insn)
6613 int rd = extract32(insn, 0, 5);
6614 int rn = extract32(insn, 5, 5);
6615 int opcode = extract32(insn, 16, 3);
6616 int rmode = extract32(insn, 19, 2);
6617 int type = extract32(insn, 22, 2);
6618 bool sbit = extract32(insn, 29, 1);
6619 bool sf = extract32(insn, 31, 1);
6623 goto do_unallocated;
6631 case 4: /* FCVTAS */
6632 case 5: /* FCVTAU */
6634 goto do_unallocated;
6637 case 0: /* FCVT[NPMZ]S */
6638 case 1: /* FCVT[NPMZ]U */
6640 case 0: /* float32 */
6641 case 1: /* float64 */
6643 case 3: /* float16 */
6644 if (!dc_isar_feature(aa64_fp16, s)) {
6645 goto do_unallocated;
6649 goto do_unallocated;
6651 if (!fp_access_check(s)) {
6654 handle_fpfpcvt(s, rd, rn, opcode, itof, rmode, 64, sf, type);
6658 switch (sf << 7 | type << 5 | rmode << 3 | opcode) {
6659 case 0b01100110: /* FMOV half <-> 32-bit int */
6661 case 0b11100110: /* FMOV half <-> 64-bit int */
6663 if (!dc_isar_feature(aa64_fp16, s)) {
6664 goto do_unallocated;
6667 case 0b00000110: /* FMOV 32-bit */
6669 case 0b10100110: /* FMOV 64-bit */
6671 case 0b11001110: /* FMOV top half of 128-bit */
6673 if (!fp_access_check(s)) {
6677 handle_fmov(s, rd, rn, type, itof);
6680 case 0b00111110: /* FJCVTZS */
6681 if (!dc_isar_feature(aa64_jscvt, s)) {
6682 goto do_unallocated;
6683 } else if (fp_access_check(s)) {
6684 handle_fjcvtzs(s, rd, rn);
6690 unallocated_encoding(s);
6697 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
6698 * 31 30 29 28 25 24 0
6699 * +---+---+---+---------+-----------------------------+
6700 * | | 0 | | 1 1 1 1 | |
6701 * +---+---+---+---------+-----------------------------+
6703 static void disas_data_proc_fp(DisasContext *s, uint32_t insn)
6705 if (extract32(insn, 24, 1)) {
6706 /* Floating point data-processing (3 source) */
6707 disas_fp_3src(s, insn);
6708 } else if (extract32(insn, 21, 1) == 0) {
6709 /* Floating point to fixed point conversions */
6710 disas_fp_fixed_conv(s, insn);
6712 switch (extract32(insn, 10, 2)) {
6714 /* Floating point conditional compare */
6715 disas_fp_ccomp(s, insn);
6718 /* Floating point data-processing (2 source) */
6719 disas_fp_2src(s, insn);
6722 /* Floating point conditional select */
6723 disas_fp_csel(s, insn);
6726 switch (ctz32(extract32(insn, 12, 4))) {
6727 case 0: /* [15:12] == xxx1 */
6728 /* Floating point immediate */
6729 disas_fp_imm(s, insn);
6731 case 1: /* [15:12] == xx10 */
6732 /* Floating point compare */
6733 disas_fp_compare(s, insn);
6735 case 2: /* [15:12] == x100 */
6736 /* Floating point data-processing (1 source) */
6737 disas_fp_1src(s, insn);
6739 case 3: /* [15:12] == 1000 */
6740 unallocated_encoding(s);
6742 default: /* [15:12] == 0000 */
6743 /* Floating point <-> integer conversions */
6744 disas_fp_int_conv(s, insn);
6752 static void do_ext64(DisasContext *s, TCGv_i64 tcg_left, TCGv_i64 tcg_right,
6755 /* Extract 64 bits from the middle of two concatenated 64 bit
6756 * vector register slices left:right. The extracted bits start
6757 * at 'pos' bits into the right (least significant) side.
6758 * We return the result in tcg_right, and guarantee not to
6761 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
6762 assert(pos > 0 && pos < 64);
6764 tcg_gen_shri_i64(tcg_right, tcg_right, pos);
6765 tcg_gen_shli_i64(tcg_tmp, tcg_left, 64 - pos);
6766 tcg_gen_or_i64(tcg_right, tcg_right, tcg_tmp);
6768 tcg_temp_free_i64(tcg_tmp);
6772 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
6773 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6774 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
6775 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6777 static void disas_simd_ext(DisasContext *s, uint32_t insn)
6779 int is_q = extract32(insn, 30, 1);
6780 int op2 = extract32(insn, 22, 2);
6781 int imm4 = extract32(insn, 11, 4);
6782 int rm = extract32(insn, 16, 5);
6783 int rn = extract32(insn, 5, 5);
6784 int rd = extract32(insn, 0, 5);
6785 int pos = imm4 << 3;
6786 TCGv_i64 tcg_resl, tcg_resh;
6788 if (op2 != 0 || (!is_q && extract32(imm4, 3, 1))) {
6789 unallocated_encoding(s);
6793 if (!fp_access_check(s)) {
6797 tcg_resh = tcg_temp_new_i64();
6798 tcg_resl = tcg_temp_new_i64();
6800 /* Vd gets bits starting at pos bits into Vm:Vn. This is
6801 * either extracting 128 bits from a 128:128 concatenation, or
6802 * extracting 64 bits from a 64:64 concatenation.
6805 read_vec_element(s, tcg_resl, rn, 0, MO_64);
6807 read_vec_element(s, tcg_resh, rm, 0, MO_64);
6808 do_ext64(s, tcg_resh, tcg_resl, pos);
6810 tcg_gen_movi_i64(tcg_resh, 0);
6817 EltPosns eltposns[] = { {rn, 0}, {rn, 1}, {rm, 0}, {rm, 1} };
6818 EltPosns *elt = eltposns;
6825 read_vec_element(s, tcg_resl, elt->reg, elt->elt, MO_64);
6827 read_vec_element(s, tcg_resh, elt->reg, elt->elt, MO_64);
6830 do_ext64(s, tcg_resh, tcg_resl, pos);
6831 tcg_hh = tcg_temp_new_i64();
6832 read_vec_element(s, tcg_hh, elt->reg, elt->elt, MO_64);
6833 do_ext64(s, tcg_hh, tcg_resh, pos);
6834 tcg_temp_free_i64(tcg_hh);
6838 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6839 tcg_temp_free_i64(tcg_resl);
6840 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6841 tcg_temp_free_i64(tcg_resh);
6845 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
6846 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6847 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
6848 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6850 static void disas_simd_tb(DisasContext *s, uint32_t insn)
6852 int op2 = extract32(insn, 22, 2);
6853 int is_q = extract32(insn, 30, 1);
6854 int rm = extract32(insn, 16, 5);
6855 int rn = extract32(insn, 5, 5);
6856 int rd = extract32(insn, 0, 5);
6857 int is_tblx = extract32(insn, 12, 1);
6858 int len = extract32(insn, 13, 2);
6859 TCGv_i64 tcg_resl, tcg_resh, tcg_idx;
6860 TCGv_i32 tcg_regno, tcg_numregs;
6863 unallocated_encoding(s);
6867 if (!fp_access_check(s)) {
6871 /* This does a table lookup: for every byte element in the input
6872 * we index into a table formed from up to four vector registers,
6873 * and then the output is the result of the lookups. Our helper
6874 * function does the lookup operation for a single 64 bit part of
6877 tcg_resl = tcg_temp_new_i64();
6878 tcg_resh = tcg_temp_new_i64();
6881 read_vec_element(s, tcg_resl, rd, 0, MO_64);
6883 tcg_gen_movi_i64(tcg_resl, 0);
6885 if (is_tblx && is_q) {
6886 read_vec_element(s, tcg_resh, rd, 1, MO_64);
6888 tcg_gen_movi_i64(tcg_resh, 0);
6891 tcg_idx = tcg_temp_new_i64();
6892 tcg_regno = tcg_const_i32(rn);
6893 tcg_numregs = tcg_const_i32(len + 1);
6894 read_vec_element(s, tcg_idx, rm, 0, MO_64);
6895 gen_helper_simd_tbl(tcg_resl, cpu_env, tcg_resl, tcg_idx,
6896 tcg_regno, tcg_numregs);
6898 read_vec_element(s, tcg_idx, rm, 1, MO_64);
6899 gen_helper_simd_tbl(tcg_resh, cpu_env, tcg_resh, tcg_idx,
6900 tcg_regno, tcg_numregs);
6902 tcg_temp_free_i64(tcg_idx);
6903 tcg_temp_free_i32(tcg_regno);
6904 tcg_temp_free_i32(tcg_numregs);
6906 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6907 tcg_temp_free_i64(tcg_resl);
6908 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6909 tcg_temp_free_i64(tcg_resh);
6913 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
6914 * +---+---+-------------+------+---+------+---+------------------+------+
6915 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
6916 * +---+---+-------------+------+---+------+---+------------------+------+
6918 static void disas_simd_zip_trn(DisasContext *s, uint32_t insn)
6920 int rd = extract32(insn, 0, 5);
6921 int rn = extract32(insn, 5, 5);
6922 int rm = extract32(insn, 16, 5);
6923 int size = extract32(insn, 22, 2);
6924 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
6925 * bit 2 indicates 1 vs 2 variant of the insn.
6927 int opcode = extract32(insn, 12, 2);
6928 bool part = extract32(insn, 14, 1);
6929 bool is_q = extract32(insn, 30, 1);
6930 int esize = 8 << size;
6932 int datasize = is_q ? 128 : 64;
6933 int elements = datasize / esize;
6934 TCGv_i64 tcg_res, tcg_resl, tcg_resh;
6936 if (opcode == 0 || (size == 3 && !is_q)) {
6937 unallocated_encoding(s);
6941 if (!fp_access_check(s)) {
6945 tcg_resl = tcg_const_i64(0);
6946 tcg_resh = tcg_const_i64(0);
6947 tcg_res = tcg_temp_new_i64();
6949 for (i = 0; i < elements; i++) {
6951 case 1: /* UZP1/2 */
6953 int midpoint = elements / 2;
6955 read_vec_element(s, tcg_res, rn, 2 * i + part, size);
6957 read_vec_element(s, tcg_res, rm,
6958 2 * (i - midpoint) + part, size);
6962 case 2: /* TRN1/2 */
6964 read_vec_element(s, tcg_res, rm, (i & ~1) + part, size);
6966 read_vec_element(s, tcg_res, rn, (i & ~1) + part, size);
6969 case 3: /* ZIP1/2 */
6971 int base = part * elements / 2;
6973 read_vec_element(s, tcg_res, rm, base + (i >> 1), size);
6975 read_vec_element(s, tcg_res, rn, base + (i >> 1), size);
6980 g_assert_not_reached();
6985 tcg_gen_shli_i64(tcg_res, tcg_res, ofs);
6986 tcg_gen_or_i64(tcg_resl, tcg_resl, tcg_res);
6988 tcg_gen_shli_i64(tcg_res, tcg_res, ofs - 64);
6989 tcg_gen_or_i64(tcg_resh, tcg_resh, tcg_res);
6993 tcg_temp_free_i64(tcg_res);
6995 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6996 tcg_temp_free_i64(tcg_resl);
6997 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6998 tcg_temp_free_i64(tcg_resh);
7002 * do_reduction_op helper
7004 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
7005 * important for correct NaN propagation that we do these
7006 * operations in exactly the order specified by the pseudocode.
7008 * This is a recursive function, TCG temps should be freed by the
7009 * calling function once it is done with the values.
7011 static TCGv_i32 do_reduction_op(DisasContext *s, int fpopcode, int rn,
7012 int esize, int size, int vmap, TCGv_ptr fpst)
7014 if (esize == size) {
7016 TCGMemOp msize = esize == 16 ? MO_16 : MO_32;
7019 /* We should have one register left here */
7020 assert(ctpop8(vmap) == 1);
7021 element = ctz32(vmap);
7022 assert(element < 8);
7024 tcg_elem = tcg_temp_new_i32();
7025 read_vec_element_i32(s, tcg_elem, rn, element, msize);
7028 int bits = size / 2;
7029 int shift = ctpop8(vmap) / 2;
7030 int vmap_lo = (vmap >> shift) & vmap;
7031 int vmap_hi = (vmap & ~vmap_lo);
7032 TCGv_i32 tcg_hi, tcg_lo, tcg_res;
7034 tcg_hi = do_reduction_op(s, fpopcode, rn, esize, bits, vmap_hi, fpst);
7035 tcg_lo = do_reduction_op(s, fpopcode, rn, esize, bits, vmap_lo, fpst);
7036 tcg_res = tcg_temp_new_i32();
7039 case 0x0c: /* fmaxnmv half-precision */
7040 gen_helper_advsimd_maxnumh(tcg_res, tcg_lo, tcg_hi, fpst);
7042 case 0x0f: /* fmaxv half-precision */
7043 gen_helper_advsimd_maxh(tcg_res, tcg_lo, tcg_hi, fpst);
7045 case 0x1c: /* fminnmv half-precision */
7046 gen_helper_advsimd_minnumh(tcg_res, tcg_lo, tcg_hi, fpst);
7048 case 0x1f: /* fminv half-precision */
7049 gen_helper_advsimd_minh(tcg_res, tcg_lo, tcg_hi, fpst);
7051 case 0x2c: /* fmaxnmv */
7052 gen_helper_vfp_maxnums(tcg_res, tcg_lo, tcg_hi, fpst);
7054 case 0x2f: /* fmaxv */
7055 gen_helper_vfp_maxs(tcg_res, tcg_lo, tcg_hi, fpst);
7057 case 0x3c: /* fminnmv */
7058 gen_helper_vfp_minnums(tcg_res, tcg_lo, tcg_hi, fpst);
7060 case 0x3f: /* fminv */
7061 gen_helper_vfp_mins(tcg_res, tcg_lo, tcg_hi, fpst);
7064 g_assert_not_reached();
7067 tcg_temp_free_i32(tcg_hi);
7068 tcg_temp_free_i32(tcg_lo);
7073 /* AdvSIMD across lanes
7074 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7075 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7076 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7077 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7079 static void disas_simd_across_lanes(DisasContext *s, uint32_t insn)
7081 int rd = extract32(insn, 0, 5);
7082 int rn = extract32(insn, 5, 5);
7083 int size = extract32(insn, 22, 2);
7084 int opcode = extract32(insn, 12, 5);
7085 bool is_q = extract32(insn, 30, 1);
7086 bool is_u = extract32(insn, 29, 1);
7088 bool is_min = false;
7092 TCGv_i64 tcg_res, tcg_elt;
7095 case 0x1b: /* ADDV */
7097 unallocated_encoding(s);
7101 case 0x3: /* SADDLV, UADDLV */
7102 case 0xa: /* SMAXV, UMAXV */
7103 case 0x1a: /* SMINV, UMINV */
7104 if (size == 3 || (size == 2 && !is_q)) {
7105 unallocated_encoding(s);
7109 case 0xc: /* FMAXNMV, FMINNMV */
7110 case 0xf: /* FMAXV, FMINV */
7111 /* Bit 1 of size field encodes min vs max and the actual size
7112 * depends on the encoding of the U bit. If not set (and FP16
7113 * enabled) then we do half-precision float instead of single
7116 is_min = extract32(size, 1, 1);
7118 if (!is_u && dc_isar_feature(aa64_fp16, s)) {
7120 } else if (!is_u || !is_q || extract32(size, 0, 1)) {
7121 unallocated_encoding(s);
7128 unallocated_encoding(s);
7132 if (!fp_access_check(s)) {
7137 elements = (is_q ? 128 : 64) / esize;
7139 tcg_res = tcg_temp_new_i64();
7140 tcg_elt = tcg_temp_new_i64();
7142 /* These instructions operate across all lanes of a vector
7143 * to produce a single result. We can guarantee that a 64
7144 * bit intermediate is sufficient:
7145 * + for [US]ADDLV the maximum element size is 32 bits, and
7146 * the result type is 64 bits
7147 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
7148 * same as the element size, which is 32 bits at most
7149 * For the integer operations we can choose to work at 64
7150 * or 32 bits and truncate at the end; for simplicity
7151 * we use 64 bits always. The floating point
7152 * ops do require 32 bit intermediates, though.
7155 read_vec_element(s, tcg_res, rn, 0, size | (is_u ? 0 : MO_SIGN));
7157 for (i = 1; i < elements; i++) {
7158 read_vec_element(s, tcg_elt, rn, i, size | (is_u ? 0 : MO_SIGN));
7161 case 0x03: /* SADDLV / UADDLV */
7162 case 0x1b: /* ADDV */
7163 tcg_gen_add_i64(tcg_res, tcg_res, tcg_elt);
7165 case 0x0a: /* SMAXV / UMAXV */
7167 tcg_gen_umax_i64(tcg_res, tcg_res, tcg_elt);
7169 tcg_gen_smax_i64(tcg_res, tcg_res, tcg_elt);
7172 case 0x1a: /* SMINV / UMINV */
7174 tcg_gen_umin_i64(tcg_res, tcg_res, tcg_elt);
7176 tcg_gen_smin_i64(tcg_res, tcg_res, tcg_elt);
7180 g_assert_not_reached();
7185 /* Floating point vector reduction ops which work across 32
7186 * bit (single) or 16 bit (half-precision) intermediates.
7187 * Note that correct NaN propagation requires that we do these
7188 * operations in exactly the order specified by the pseudocode.
7190 TCGv_ptr fpst = get_fpstatus_ptr(size == MO_16);
7191 int fpopcode = opcode | is_min << 4 | is_u << 5;
7192 int vmap = (1 << elements) - 1;
7193 TCGv_i32 tcg_res32 = do_reduction_op(s, fpopcode, rn, esize,
7194 (is_q ? 128 : 64), vmap, fpst);
7195 tcg_gen_extu_i32_i64(tcg_res, tcg_res32);
7196 tcg_temp_free_i32(tcg_res32);
7197 tcg_temp_free_ptr(fpst);
7200 tcg_temp_free_i64(tcg_elt);
7202 /* Now truncate the result to the width required for the final output */
7203 if (opcode == 0x03) {
7204 /* SADDLV, UADDLV: result is 2*esize */
7210 tcg_gen_ext8u_i64(tcg_res, tcg_res);
7213 tcg_gen_ext16u_i64(tcg_res, tcg_res);
7216 tcg_gen_ext32u_i64(tcg_res, tcg_res);
7221 g_assert_not_reached();
7224 write_fp_dreg(s, rd, tcg_res);
7225 tcg_temp_free_i64(tcg_res);
7228 /* DUP (Element, Vector)
7230 * 31 30 29 21 20 16 15 10 9 5 4 0
7231 * +---+---+-------------------+--------+-------------+------+------+
7232 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7233 * +---+---+-------------------+--------+-------------+------+------+
7235 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7237 static void handle_simd_dupe(DisasContext *s, int is_q, int rd, int rn,
7240 int size = ctz32(imm5);
7241 int index = imm5 >> (size + 1);
7243 if (size > 3 || (size == 3 && !is_q)) {
7244 unallocated_encoding(s);
7248 if (!fp_access_check(s)) {
7252 tcg_gen_gvec_dup_mem(size, vec_full_reg_offset(s, rd),
7253 vec_reg_offset(s, rn, index, size),
7254 is_q ? 16 : 8, vec_full_reg_size(s));
7257 /* DUP (element, scalar)
7258 * 31 21 20 16 15 10 9 5 4 0
7259 * +-----------------------+--------+-------------+------+------+
7260 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7261 * +-----------------------+--------+-------------+------+------+
7263 static void handle_simd_dupes(DisasContext *s, int rd, int rn,
7266 int size = ctz32(imm5);
7271 unallocated_encoding(s);
7275 if (!fp_access_check(s)) {
7279 index = imm5 >> (size + 1);
7281 /* This instruction just extracts the specified element and
7282 * zero-extends it into the bottom of the destination register.
7284 tmp = tcg_temp_new_i64();
7285 read_vec_element(s, tmp, rn, index, size);
7286 write_fp_dreg(s, rd, tmp);
7287 tcg_temp_free_i64(tmp);
7292 * 31 30 29 21 20 16 15 10 9 5 4 0
7293 * +---+---+-------------------+--------+-------------+------+------+
7294 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
7295 * +---+---+-------------------+--------+-------------+------+------+
7297 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7299 static void handle_simd_dupg(DisasContext *s, int is_q, int rd, int rn,
7302 int size = ctz32(imm5);
7303 uint32_t dofs, oprsz, maxsz;
7305 if (size > 3 || ((size == 3) && !is_q)) {
7306 unallocated_encoding(s);
7310 if (!fp_access_check(s)) {
7314 dofs = vec_full_reg_offset(s, rd);
7315 oprsz = is_q ? 16 : 8;
7316 maxsz = vec_full_reg_size(s);
7318 tcg_gen_gvec_dup_i64(size, dofs, oprsz, maxsz, cpu_reg(s, rn));
7323 * 31 21 20 16 15 14 11 10 9 5 4 0
7324 * +-----------------------+--------+------------+---+------+------+
7325 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7326 * +-----------------------+--------+------------+---+------+------+
7328 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7329 * index: encoded in imm5<4:size+1>
7331 static void handle_simd_inse(DisasContext *s, int rd, int rn,
7334 int size = ctz32(imm5);
7335 int src_index, dst_index;
7339 unallocated_encoding(s);
7343 if (!fp_access_check(s)) {
7347 dst_index = extract32(imm5, 1+size, 5);
7348 src_index = extract32(imm4, size, 4);
7350 tmp = tcg_temp_new_i64();
7352 read_vec_element(s, tmp, rn, src_index, size);
7353 write_vec_element(s, tmp, rd, dst_index, size);
7355 tcg_temp_free_i64(tmp);
7361 * 31 21 20 16 15 10 9 5 4 0
7362 * +-----------------------+--------+-------------+------+------+
7363 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
7364 * +-----------------------+--------+-------------+------+------+
7366 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7367 * index: encoded in imm5<4:size+1>
7369 static void handle_simd_insg(DisasContext *s, int rd, int rn, int imm5)
7371 int size = ctz32(imm5);
7375 unallocated_encoding(s);
7379 if (!fp_access_check(s)) {
7383 idx = extract32(imm5, 1 + size, 4 - size);
7384 write_vec_element(s, cpu_reg(s, rn), rd, idx, size);
7391 * 31 30 29 21 20 16 15 12 10 9 5 4 0
7392 * +---+---+-------------------+--------+-------------+------+------+
7393 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
7394 * +---+---+-------------------+--------+-------------+------+------+
7396 * U: unsigned when set
7397 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7399 static void handle_simd_umov_smov(DisasContext *s, int is_q, int is_signed,
7400 int rn, int rd, int imm5)
7402 int size = ctz32(imm5);
7406 /* Check for UnallocatedEncodings */
7408 if (size > 2 || (size == 2 && !is_q)) {
7409 unallocated_encoding(s);
7414 || (size < 3 && is_q)
7415 || (size == 3 && !is_q)) {
7416 unallocated_encoding(s);
7421 if (!fp_access_check(s)) {
7425 element = extract32(imm5, 1+size, 4);
7427 tcg_rd = cpu_reg(s, rd);
7428 read_vec_element(s, tcg_rd, rn, element, size | (is_signed ? MO_SIGN : 0));
7429 if (is_signed && !is_q) {
7430 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
7435 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7436 * +---+---+----+-----------------+------+---+------+---+------+------+
7437 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7438 * +---+---+----+-----------------+------+---+------+---+------+------+
7440 static void disas_simd_copy(DisasContext *s, uint32_t insn)
7442 int rd = extract32(insn, 0, 5);
7443 int rn = extract32(insn, 5, 5);
7444 int imm4 = extract32(insn, 11, 4);
7445 int op = extract32(insn, 29, 1);
7446 int is_q = extract32(insn, 30, 1);
7447 int imm5 = extract32(insn, 16, 5);
7452 handle_simd_inse(s, rd, rn, imm4, imm5);
7454 unallocated_encoding(s);
7459 /* DUP (element - vector) */
7460 handle_simd_dupe(s, is_q, rd, rn, imm5);
7464 handle_simd_dupg(s, is_q, rd, rn, imm5);
7469 handle_simd_insg(s, rd, rn, imm5);
7471 unallocated_encoding(s);
7476 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
7477 handle_simd_umov_smov(s, is_q, (imm4 == 5), rn, rd, imm5);
7480 unallocated_encoding(s);
7486 /* AdvSIMD modified immediate
7487 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
7488 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7489 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
7490 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7492 * There are a number of operations that can be carried out here:
7493 * MOVI - move (shifted) imm into register
7494 * MVNI - move inverted (shifted) imm into register
7495 * ORR - bitwise OR of (shifted) imm with register
7496 * BIC - bitwise clear of (shifted) imm with register
7497 * With ARMv8.2 we also have:
7498 * FMOV half-precision
7500 static void disas_simd_mod_imm(DisasContext *s, uint32_t insn)
7502 int rd = extract32(insn, 0, 5);
7503 int cmode = extract32(insn, 12, 4);
7504 int cmode_3_1 = extract32(cmode, 1, 3);
7505 int cmode_0 = extract32(cmode, 0, 1);
7506 int o2 = extract32(insn, 11, 1);
7507 uint64_t abcdefgh = extract32(insn, 5, 5) | (extract32(insn, 16, 3) << 5);
7508 bool is_neg = extract32(insn, 29, 1);
7509 bool is_q = extract32(insn, 30, 1);
7512 if (o2 != 0 || ((cmode == 0xf) && is_neg && !is_q)) {
7513 /* Check for FMOV (vector, immediate) - half-precision */
7514 if (!(dc_isar_feature(aa64_fp16, s) && o2 && cmode == 0xf)) {
7515 unallocated_encoding(s);
7520 if (!fp_access_check(s)) {
7524 /* See AdvSIMDExpandImm() in ARM ARM */
7525 switch (cmode_3_1) {
7526 case 0: /* Replicate(Zeros(24):imm8, 2) */
7527 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
7528 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
7529 case 3: /* Replicate(imm8:Zeros(24), 2) */
7531 int shift = cmode_3_1 * 8;
7532 imm = bitfield_replicate(abcdefgh << shift, 32);
7535 case 4: /* Replicate(Zeros(8):imm8, 4) */
7536 case 5: /* Replicate(imm8:Zeros(8), 4) */
7538 int shift = (cmode_3_1 & 0x1) * 8;
7539 imm = bitfield_replicate(abcdefgh << shift, 16);
7544 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
7545 imm = (abcdefgh << 16) | 0xffff;
7547 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
7548 imm = (abcdefgh << 8) | 0xff;
7550 imm = bitfield_replicate(imm, 32);
7553 if (!cmode_0 && !is_neg) {
7554 imm = bitfield_replicate(abcdefgh, 8);
7555 } else if (!cmode_0 && is_neg) {
7558 for (i = 0; i < 8; i++) {
7559 if ((abcdefgh) & (1 << i)) {
7560 imm |= 0xffULL << (i * 8);
7563 } else if (cmode_0) {
7565 imm = (abcdefgh & 0x3f) << 48;
7566 if (abcdefgh & 0x80) {
7567 imm |= 0x8000000000000000ULL;
7569 if (abcdefgh & 0x40) {
7570 imm |= 0x3fc0000000000000ULL;
7572 imm |= 0x4000000000000000ULL;
7576 /* FMOV (vector, immediate) - half-precision */
7577 imm = vfp_expand_imm(MO_16, abcdefgh);
7578 /* now duplicate across the lanes */
7579 imm = bitfield_replicate(imm, 16);
7581 imm = (abcdefgh & 0x3f) << 19;
7582 if (abcdefgh & 0x80) {
7585 if (abcdefgh & 0x40) {
7596 fprintf(stderr, "%s: cmode_3_1: %x\n", __func__, cmode_3_1);
7597 g_assert_not_reached();
7600 if (cmode_3_1 != 7 && is_neg) {
7604 if (!((cmode & 0x9) == 0x1 || (cmode & 0xd) == 0x9)) {
7605 /* MOVI or MVNI, with MVNI negation handled above. */
7606 tcg_gen_gvec_dup64i(vec_full_reg_offset(s, rd), is_q ? 16 : 8,
7607 vec_full_reg_size(s), imm);
7609 /* ORR or BIC, with BIC negation to AND handled above. */
7611 gen_gvec_fn2i(s, is_q, rd, rd, imm, tcg_gen_gvec_andi, MO_64);
7613 gen_gvec_fn2i(s, is_q, rd, rd, imm, tcg_gen_gvec_ori, MO_64);
7618 /* AdvSIMD scalar copy
7619 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7620 * +-----+----+-----------------+------+---+------+---+------+------+
7621 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7622 * +-----+----+-----------------+------+---+------+---+------+------+
7624 static void disas_simd_scalar_copy(DisasContext *s, uint32_t insn)
7626 int rd = extract32(insn, 0, 5);
7627 int rn = extract32(insn, 5, 5);
7628 int imm4 = extract32(insn, 11, 4);
7629 int imm5 = extract32(insn, 16, 5);
7630 int op = extract32(insn, 29, 1);
7632 if (op != 0 || imm4 != 0) {
7633 unallocated_encoding(s);
7637 /* DUP (element, scalar) */
7638 handle_simd_dupes(s, rd, rn, imm5);
7641 /* AdvSIMD scalar pairwise
7642 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7643 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7644 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7645 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7647 static void disas_simd_scalar_pairwise(DisasContext *s, uint32_t insn)
7649 int u = extract32(insn, 29, 1);
7650 int size = extract32(insn, 22, 2);
7651 int opcode = extract32(insn, 12, 5);
7652 int rn = extract32(insn, 5, 5);
7653 int rd = extract32(insn, 0, 5);
7656 /* For some ops (the FP ones), size[1] is part of the encoding.
7657 * For ADDP strictly it is not but size[1] is always 1 for valid
7660 opcode |= (extract32(size, 1, 1) << 5);
7663 case 0x3b: /* ADDP */
7664 if (u || size != 3) {
7665 unallocated_encoding(s);
7668 if (!fp_access_check(s)) {
7674 case 0xc: /* FMAXNMP */
7675 case 0xd: /* FADDP */
7676 case 0xf: /* FMAXP */
7677 case 0x2c: /* FMINNMP */
7678 case 0x2f: /* FMINP */
7679 /* FP op, size[0] is 32 or 64 bit*/
7681 if (!dc_isar_feature(aa64_fp16, s)) {
7682 unallocated_encoding(s);
7688 size = extract32(size, 0, 1) ? MO_64 : MO_32;
7691 if (!fp_access_check(s)) {
7695 fpst = get_fpstatus_ptr(size == MO_16);
7698 unallocated_encoding(s);
7702 if (size == MO_64) {
7703 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
7704 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
7705 TCGv_i64 tcg_res = tcg_temp_new_i64();
7707 read_vec_element(s, tcg_op1, rn, 0, MO_64);
7708 read_vec_element(s, tcg_op2, rn, 1, MO_64);
7711 case 0x3b: /* ADDP */
7712 tcg_gen_add_i64(tcg_res, tcg_op1, tcg_op2);
7714 case 0xc: /* FMAXNMP */
7715 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
7717 case 0xd: /* FADDP */
7718 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
7720 case 0xf: /* FMAXP */
7721 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
7723 case 0x2c: /* FMINNMP */
7724 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
7726 case 0x2f: /* FMINP */
7727 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
7730 g_assert_not_reached();
7733 write_fp_dreg(s, rd, tcg_res);
7735 tcg_temp_free_i64(tcg_op1);
7736 tcg_temp_free_i64(tcg_op2);
7737 tcg_temp_free_i64(tcg_res);
7739 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
7740 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
7741 TCGv_i32 tcg_res = tcg_temp_new_i32();
7743 read_vec_element_i32(s, tcg_op1, rn, 0, size);
7744 read_vec_element_i32(s, tcg_op2, rn, 1, size);
7746 if (size == MO_16) {
7748 case 0xc: /* FMAXNMP */
7749 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
7751 case 0xd: /* FADDP */
7752 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
7754 case 0xf: /* FMAXP */
7755 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
7757 case 0x2c: /* FMINNMP */
7758 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
7760 case 0x2f: /* FMINP */
7761 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
7764 g_assert_not_reached();
7768 case 0xc: /* FMAXNMP */
7769 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
7771 case 0xd: /* FADDP */
7772 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
7774 case 0xf: /* FMAXP */
7775 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
7777 case 0x2c: /* FMINNMP */
7778 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
7780 case 0x2f: /* FMINP */
7781 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
7784 g_assert_not_reached();
7788 write_fp_sreg(s, rd, tcg_res);
7790 tcg_temp_free_i32(tcg_op1);
7791 tcg_temp_free_i32(tcg_op2);
7792 tcg_temp_free_i32(tcg_res);
7796 tcg_temp_free_ptr(fpst);
7801 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
7803 * This code is handles the common shifting code and is used by both
7804 * the vector and scalar code.
7806 static void handle_shri_with_rndacc(TCGv_i64 tcg_res, TCGv_i64 tcg_src,
7807 TCGv_i64 tcg_rnd, bool accumulate,
7808 bool is_u, int size, int shift)
7810 bool extended_result = false;
7811 bool round = tcg_rnd != NULL;
7813 TCGv_i64 tcg_src_hi;
7815 if (round && size == 3) {
7816 extended_result = true;
7817 ext_lshift = 64 - shift;
7818 tcg_src_hi = tcg_temp_new_i64();
7819 } else if (shift == 64) {
7820 if (!accumulate && is_u) {
7821 /* result is zero */
7822 tcg_gen_movi_i64(tcg_res, 0);
7827 /* Deal with the rounding step */
7829 if (extended_result) {
7830 TCGv_i64 tcg_zero = tcg_const_i64(0);
7832 /* take care of sign extending tcg_res */
7833 tcg_gen_sari_i64(tcg_src_hi, tcg_src, 63);
7834 tcg_gen_add2_i64(tcg_src, tcg_src_hi,
7835 tcg_src, tcg_src_hi,
7838 tcg_gen_add2_i64(tcg_src, tcg_src_hi,
7842 tcg_temp_free_i64(tcg_zero);
7844 tcg_gen_add_i64(tcg_src, tcg_src, tcg_rnd);
7848 /* Now do the shift right */
7849 if (round && extended_result) {
7850 /* extended case, >64 bit precision required */
7851 if (ext_lshift == 0) {
7852 /* special case, only high bits matter */
7853 tcg_gen_mov_i64(tcg_src, tcg_src_hi);
7855 tcg_gen_shri_i64(tcg_src, tcg_src, shift);
7856 tcg_gen_shli_i64(tcg_src_hi, tcg_src_hi, ext_lshift);
7857 tcg_gen_or_i64(tcg_src, tcg_src, tcg_src_hi);
7862 /* essentially shifting in 64 zeros */
7863 tcg_gen_movi_i64(tcg_src, 0);
7865 tcg_gen_shri_i64(tcg_src, tcg_src, shift);
7869 /* effectively extending the sign-bit */
7870 tcg_gen_sari_i64(tcg_src, tcg_src, 63);
7872 tcg_gen_sari_i64(tcg_src, tcg_src, shift);
7878 tcg_gen_add_i64(tcg_res, tcg_res, tcg_src);
7880 tcg_gen_mov_i64(tcg_res, tcg_src);
7883 if (extended_result) {
7884 tcg_temp_free_i64(tcg_src_hi);
7888 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
7889 static void handle_scalar_simd_shri(DisasContext *s,
7890 bool is_u, int immh, int immb,
7891 int opcode, int rn, int rd)
7894 int immhb = immh << 3 | immb;
7895 int shift = 2 * (8 << size) - immhb;
7896 bool accumulate = false;
7898 bool insert = false;
7903 if (!extract32(immh, 3, 1)) {
7904 unallocated_encoding(s);
7908 if (!fp_access_check(s)) {
7913 case 0x02: /* SSRA / USRA (accumulate) */
7916 case 0x04: /* SRSHR / URSHR (rounding) */
7919 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7920 accumulate = round = true;
7922 case 0x08: /* SRI */
7928 uint64_t round_const = 1ULL << (shift - 1);
7929 tcg_round = tcg_const_i64(round_const);
7934 tcg_rn = read_fp_dreg(s, rn);
7935 tcg_rd = (accumulate || insert) ? read_fp_dreg(s, rd) : tcg_temp_new_i64();
7938 /* shift count same as element size is valid but does nothing;
7939 * special case to avoid potential shift by 64.
7941 int esize = 8 << size;
7942 if (shift != esize) {
7943 tcg_gen_shri_i64(tcg_rn, tcg_rn, shift);
7944 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, 0, esize - shift);
7947 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
7948 accumulate, is_u, size, shift);
7951 write_fp_dreg(s, rd, tcg_rd);
7953 tcg_temp_free_i64(tcg_rn);
7954 tcg_temp_free_i64(tcg_rd);
7956 tcg_temp_free_i64(tcg_round);
7960 /* SHL/SLI - Scalar shift left */
7961 static void handle_scalar_simd_shli(DisasContext *s, bool insert,
7962 int immh, int immb, int opcode,
7965 int size = 32 - clz32(immh) - 1;
7966 int immhb = immh << 3 | immb;
7967 int shift = immhb - (8 << size);
7968 TCGv_i64 tcg_rn = new_tmp_a64(s);
7969 TCGv_i64 tcg_rd = new_tmp_a64(s);
7971 if (!extract32(immh, 3, 1)) {
7972 unallocated_encoding(s);
7976 if (!fp_access_check(s)) {
7980 tcg_rn = read_fp_dreg(s, rn);
7981 tcg_rd = insert ? read_fp_dreg(s, rd) : tcg_temp_new_i64();
7984 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, shift, 64 - shift);
7986 tcg_gen_shli_i64(tcg_rd, tcg_rn, shift);
7989 write_fp_dreg(s, rd, tcg_rd);
7991 tcg_temp_free_i64(tcg_rn);
7992 tcg_temp_free_i64(tcg_rd);
7995 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
7996 * (signed/unsigned) narrowing */
7997 static void handle_vec_simd_sqshrn(DisasContext *s, bool is_scalar, bool is_q,
7998 bool is_u_shift, bool is_u_narrow,
7999 int immh, int immb, int opcode,
8002 int immhb = immh << 3 | immb;
8003 int size = 32 - clz32(immh) - 1;
8004 int esize = 8 << size;
8005 int shift = (2 * esize) - immhb;
8006 int elements = is_scalar ? 1 : (64 / esize);
8007 bool round = extract32(opcode, 0, 1);
8008 TCGMemOp ldop = (size + 1) | (is_u_shift ? 0 : MO_SIGN);
8009 TCGv_i64 tcg_rn, tcg_rd, tcg_round;
8010 TCGv_i32 tcg_rd_narrowed;
8013 static NeonGenNarrowEnvFn * const signed_narrow_fns[4][2] = {
8014 { gen_helper_neon_narrow_sat_s8,
8015 gen_helper_neon_unarrow_sat8 },
8016 { gen_helper_neon_narrow_sat_s16,
8017 gen_helper_neon_unarrow_sat16 },
8018 { gen_helper_neon_narrow_sat_s32,
8019 gen_helper_neon_unarrow_sat32 },
8022 static NeonGenNarrowEnvFn * const unsigned_narrow_fns[4] = {
8023 gen_helper_neon_narrow_sat_u8,
8024 gen_helper_neon_narrow_sat_u16,
8025 gen_helper_neon_narrow_sat_u32,
8028 NeonGenNarrowEnvFn *narrowfn;
8034 if (extract32(immh, 3, 1)) {
8035 unallocated_encoding(s);
8039 if (!fp_access_check(s)) {
8044 narrowfn = unsigned_narrow_fns[size];
8046 narrowfn = signed_narrow_fns[size][is_u_narrow ? 1 : 0];
8049 tcg_rn = tcg_temp_new_i64();
8050 tcg_rd = tcg_temp_new_i64();
8051 tcg_rd_narrowed = tcg_temp_new_i32();
8052 tcg_final = tcg_const_i64(0);
8055 uint64_t round_const = 1ULL << (shift - 1);
8056 tcg_round = tcg_const_i64(round_const);
8061 for (i = 0; i < elements; i++) {
8062 read_vec_element(s, tcg_rn, rn, i, ldop);
8063 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
8064 false, is_u_shift, size+1, shift);
8065 narrowfn(tcg_rd_narrowed, cpu_env, tcg_rd);
8066 tcg_gen_extu_i32_i64(tcg_rd, tcg_rd_narrowed);
8067 tcg_gen_deposit_i64(tcg_final, tcg_final, tcg_rd, esize * i, esize);
8071 write_vec_element(s, tcg_final, rd, 0, MO_64);
8073 write_vec_element(s, tcg_final, rd, 1, MO_64);
8077 tcg_temp_free_i64(tcg_round);
8079 tcg_temp_free_i64(tcg_rn);
8080 tcg_temp_free_i64(tcg_rd);
8081 tcg_temp_free_i32(tcg_rd_narrowed);
8082 tcg_temp_free_i64(tcg_final);
8084 clear_vec_high(s, is_q, rd);
8087 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
8088 static void handle_simd_qshl(DisasContext *s, bool scalar, bool is_q,
8089 bool src_unsigned, bool dst_unsigned,
8090 int immh, int immb, int rn, int rd)
8092 int immhb = immh << 3 | immb;
8093 int size = 32 - clz32(immh) - 1;
8094 int shift = immhb - (8 << size);
8098 assert(!(scalar && is_q));
8101 if (!is_q && extract32(immh, 3, 1)) {
8102 unallocated_encoding(s);
8106 /* Since we use the variable-shift helpers we must
8107 * replicate the shift count into each element of
8108 * the tcg_shift value.
8112 shift |= shift << 8;
8115 shift |= shift << 16;
8121 g_assert_not_reached();
8125 if (!fp_access_check(s)) {
8130 TCGv_i64 tcg_shift = tcg_const_i64(shift);
8131 static NeonGenTwo64OpEnvFn * const fns[2][2] = {
8132 { gen_helper_neon_qshl_s64, gen_helper_neon_qshlu_s64 },
8133 { NULL, gen_helper_neon_qshl_u64 },
8135 NeonGenTwo64OpEnvFn *genfn = fns[src_unsigned][dst_unsigned];
8136 int maxpass = is_q ? 2 : 1;
8138 for (pass = 0; pass < maxpass; pass++) {
8139 TCGv_i64 tcg_op = tcg_temp_new_i64();
8141 read_vec_element(s, tcg_op, rn, pass, MO_64);
8142 genfn(tcg_op, cpu_env, tcg_op, tcg_shift);
8143 write_vec_element(s, tcg_op, rd, pass, MO_64);
8145 tcg_temp_free_i64(tcg_op);
8147 tcg_temp_free_i64(tcg_shift);
8148 clear_vec_high(s, is_q, rd);
8150 TCGv_i32 tcg_shift = tcg_const_i32(shift);
8151 static NeonGenTwoOpEnvFn * const fns[2][2][3] = {
8153 { gen_helper_neon_qshl_s8,
8154 gen_helper_neon_qshl_s16,
8155 gen_helper_neon_qshl_s32 },
8156 { gen_helper_neon_qshlu_s8,
8157 gen_helper_neon_qshlu_s16,
8158 gen_helper_neon_qshlu_s32 }
8160 { NULL, NULL, NULL },
8161 { gen_helper_neon_qshl_u8,
8162 gen_helper_neon_qshl_u16,
8163 gen_helper_neon_qshl_u32 }
8166 NeonGenTwoOpEnvFn *genfn = fns[src_unsigned][dst_unsigned][size];
8167 TCGMemOp memop = scalar ? size : MO_32;
8168 int maxpass = scalar ? 1 : is_q ? 4 : 2;
8170 for (pass = 0; pass < maxpass; pass++) {
8171 TCGv_i32 tcg_op = tcg_temp_new_i32();
8173 read_vec_element_i32(s, tcg_op, rn, pass, memop);
8174 genfn(tcg_op, cpu_env, tcg_op, tcg_shift);
8178 tcg_gen_ext8u_i32(tcg_op, tcg_op);
8181 tcg_gen_ext16u_i32(tcg_op, tcg_op);
8186 g_assert_not_reached();
8188 write_fp_sreg(s, rd, tcg_op);
8190 write_vec_element_i32(s, tcg_op, rd, pass, MO_32);
8193 tcg_temp_free_i32(tcg_op);
8195 tcg_temp_free_i32(tcg_shift);
8198 clear_vec_high(s, is_q, rd);
8203 /* Common vector code for handling integer to FP conversion */
8204 static void handle_simd_intfp_conv(DisasContext *s, int rd, int rn,
8205 int elements, int is_signed,
8206 int fracbits, int size)
8208 TCGv_ptr tcg_fpst = get_fpstatus_ptr(size == MO_16);
8209 TCGv_i32 tcg_shift = NULL;
8211 TCGMemOp mop = size | (is_signed ? MO_SIGN : 0);
8214 if (fracbits || size == MO_64) {
8215 tcg_shift = tcg_const_i32(fracbits);
8218 if (size == MO_64) {
8219 TCGv_i64 tcg_int64 = tcg_temp_new_i64();
8220 TCGv_i64 tcg_double = tcg_temp_new_i64();
8222 for (pass = 0; pass < elements; pass++) {
8223 read_vec_element(s, tcg_int64, rn, pass, mop);
8226 gen_helper_vfp_sqtod(tcg_double, tcg_int64,
8227 tcg_shift, tcg_fpst);
8229 gen_helper_vfp_uqtod(tcg_double, tcg_int64,
8230 tcg_shift, tcg_fpst);
8232 if (elements == 1) {
8233 write_fp_dreg(s, rd, tcg_double);
8235 write_vec_element(s, tcg_double, rd, pass, MO_64);
8239 tcg_temp_free_i64(tcg_int64);
8240 tcg_temp_free_i64(tcg_double);
8243 TCGv_i32 tcg_int32 = tcg_temp_new_i32();
8244 TCGv_i32 tcg_float = tcg_temp_new_i32();
8246 for (pass = 0; pass < elements; pass++) {
8247 read_vec_element_i32(s, tcg_int32, rn, pass, mop);
8253 gen_helper_vfp_sltos(tcg_float, tcg_int32,
8254 tcg_shift, tcg_fpst);
8256 gen_helper_vfp_ultos(tcg_float, tcg_int32,
8257 tcg_shift, tcg_fpst);
8261 gen_helper_vfp_sitos(tcg_float, tcg_int32, tcg_fpst);
8263 gen_helper_vfp_uitos(tcg_float, tcg_int32, tcg_fpst);
8270 gen_helper_vfp_sltoh(tcg_float, tcg_int32,
8271 tcg_shift, tcg_fpst);
8273 gen_helper_vfp_ultoh(tcg_float, tcg_int32,
8274 tcg_shift, tcg_fpst);
8278 gen_helper_vfp_sitoh(tcg_float, tcg_int32, tcg_fpst);
8280 gen_helper_vfp_uitoh(tcg_float, tcg_int32, tcg_fpst);
8285 g_assert_not_reached();
8288 if (elements == 1) {
8289 write_fp_sreg(s, rd, tcg_float);
8291 write_vec_element_i32(s, tcg_float, rd, pass, size);
8295 tcg_temp_free_i32(tcg_int32);
8296 tcg_temp_free_i32(tcg_float);
8299 tcg_temp_free_ptr(tcg_fpst);
8301 tcg_temp_free_i32(tcg_shift);
8304 clear_vec_high(s, elements << size == 16, rd);
8307 /* UCVTF/SCVTF - Integer to FP conversion */
8308 static void handle_simd_shift_intfp_conv(DisasContext *s, bool is_scalar,
8309 bool is_q, bool is_u,
8310 int immh, int immb, int opcode,
8313 int size, elements, fracbits;
8314 int immhb = immh << 3 | immb;
8318 if (!is_scalar && !is_q) {
8319 unallocated_encoding(s);
8322 } else if (immh & 4) {
8324 } else if (immh & 2) {
8326 if (!dc_isar_feature(aa64_fp16, s)) {
8327 unallocated_encoding(s);
8331 /* immh == 0 would be a failure of the decode logic */
8332 g_assert(immh == 1);
8333 unallocated_encoding(s);
8340 elements = (8 << is_q) >> size;
8342 fracbits = (16 << size) - immhb;
8344 if (!fp_access_check(s)) {
8348 handle_simd_intfp_conv(s, rd, rn, elements, !is_u, fracbits, size);
8351 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
8352 static void handle_simd_shift_fpint_conv(DisasContext *s, bool is_scalar,
8353 bool is_q, bool is_u,
8354 int immh, int immb, int rn, int rd)
8356 int immhb = immh << 3 | immb;
8357 int pass, size, fracbits;
8358 TCGv_ptr tcg_fpstatus;
8359 TCGv_i32 tcg_rmode, tcg_shift;
8363 if (!is_scalar && !is_q) {
8364 unallocated_encoding(s);
8367 } else if (immh & 0x4) {
8369 } else if (immh & 0x2) {
8371 if (!dc_isar_feature(aa64_fp16, s)) {
8372 unallocated_encoding(s);
8376 /* Should have split out AdvSIMD modified immediate earlier. */
8378 unallocated_encoding(s);
8382 if (!fp_access_check(s)) {
8386 assert(!(is_scalar && is_q));
8388 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO));
8389 tcg_fpstatus = get_fpstatus_ptr(size == MO_16);
8390 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
8391 fracbits = (16 << size) - immhb;
8392 tcg_shift = tcg_const_i32(fracbits);
8394 if (size == MO_64) {
8395 int maxpass = is_scalar ? 1 : 2;
8397 for (pass = 0; pass < maxpass; pass++) {
8398 TCGv_i64 tcg_op = tcg_temp_new_i64();
8400 read_vec_element(s, tcg_op, rn, pass, MO_64);
8402 gen_helper_vfp_touqd(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8404 gen_helper_vfp_tosqd(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8406 write_vec_element(s, tcg_op, rd, pass, MO_64);
8407 tcg_temp_free_i64(tcg_op);
8409 clear_vec_high(s, is_q, rd);
8411 void (*fn)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_ptr);
8412 int maxpass = is_scalar ? 1 : ((8 << is_q) >> size);
8417 fn = gen_helper_vfp_touhh;
8419 fn = gen_helper_vfp_toshh;
8424 fn = gen_helper_vfp_touls;
8426 fn = gen_helper_vfp_tosls;
8430 g_assert_not_reached();
8433 for (pass = 0; pass < maxpass; pass++) {
8434 TCGv_i32 tcg_op = tcg_temp_new_i32();
8436 read_vec_element_i32(s, tcg_op, rn, pass, size);
8437 fn(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8439 write_fp_sreg(s, rd, tcg_op);
8441 write_vec_element_i32(s, tcg_op, rd, pass, size);
8443 tcg_temp_free_i32(tcg_op);
8446 clear_vec_high(s, is_q, rd);
8450 tcg_temp_free_ptr(tcg_fpstatus);
8451 tcg_temp_free_i32(tcg_shift);
8452 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
8453 tcg_temp_free_i32(tcg_rmode);
8456 /* AdvSIMD scalar shift by immediate
8457 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8458 * +-----+---+-------------+------+------+--------+---+------+------+
8459 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8460 * +-----+---+-------------+------+------+--------+---+------+------+
8462 * This is the scalar version so it works on a fixed sized registers
8464 static void disas_simd_scalar_shift_imm(DisasContext *s, uint32_t insn)
8466 int rd = extract32(insn, 0, 5);
8467 int rn = extract32(insn, 5, 5);
8468 int opcode = extract32(insn, 11, 5);
8469 int immb = extract32(insn, 16, 3);
8470 int immh = extract32(insn, 19, 4);
8471 bool is_u = extract32(insn, 29, 1);
8474 unallocated_encoding(s);
8479 case 0x08: /* SRI */
8481 unallocated_encoding(s);
8485 case 0x00: /* SSHR / USHR */
8486 case 0x02: /* SSRA / USRA */
8487 case 0x04: /* SRSHR / URSHR */
8488 case 0x06: /* SRSRA / URSRA */
8489 handle_scalar_simd_shri(s, is_u, immh, immb, opcode, rn, rd);
8491 case 0x0a: /* SHL / SLI */
8492 handle_scalar_simd_shli(s, is_u, immh, immb, opcode, rn, rd);
8494 case 0x1c: /* SCVTF, UCVTF */
8495 handle_simd_shift_intfp_conv(s, true, false, is_u, immh, immb,
8498 case 0x10: /* SQSHRUN, SQSHRUN2 */
8499 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
8501 unallocated_encoding(s);
8504 handle_vec_simd_sqshrn(s, true, false, false, true,
8505 immh, immb, opcode, rn, rd);
8507 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
8508 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
8509 handle_vec_simd_sqshrn(s, true, false, is_u, is_u,
8510 immh, immb, opcode, rn, rd);
8512 case 0xc: /* SQSHLU */
8514 unallocated_encoding(s);
8517 handle_simd_qshl(s, true, false, false, true, immh, immb, rn, rd);
8519 case 0xe: /* SQSHL, UQSHL */
8520 handle_simd_qshl(s, true, false, is_u, is_u, immh, immb, rn, rd);
8522 case 0x1f: /* FCVTZS, FCVTZU */
8523 handle_simd_shift_fpint_conv(s, true, false, is_u, immh, immb, rn, rd);
8526 unallocated_encoding(s);
8531 /* AdvSIMD scalar three different
8532 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8533 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8534 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8535 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8537 static void disas_simd_scalar_three_reg_diff(DisasContext *s, uint32_t insn)
8539 bool is_u = extract32(insn, 29, 1);
8540 int size = extract32(insn, 22, 2);
8541 int opcode = extract32(insn, 12, 4);
8542 int rm = extract32(insn, 16, 5);
8543 int rn = extract32(insn, 5, 5);
8544 int rd = extract32(insn, 0, 5);
8547 unallocated_encoding(s);
8552 case 0x9: /* SQDMLAL, SQDMLAL2 */
8553 case 0xb: /* SQDMLSL, SQDMLSL2 */
8554 case 0xd: /* SQDMULL, SQDMULL2 */
8555 if (size == 0 || size == 3) {
8556 unallocated_encoding(s);
8561 unallocated_encoding(s);
8565 if (!fp_access_check(s)) {
8570 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8571 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8572 TCGv_i64 tcg_res = tcg_temp_new_i64();
8574 read_vec_element(s, tcg_op1, rn, 0, MO_32 | MO_SIGN);
8575 read_vec_element(s, tcg_op2, rm, 0, MO_32 | MO_SIGN);
8577 tcg_gen_mul_i64(tcg_res, tcg_op1, tcg_op2);
8578 gen_helper_neon_addl_saturate_s64(tcg_res, cpu_env, tcg_res, tcg_res);
8581 case 0xd: /* SQDMULL, SQDMULL2 */
8583 case 0xb: /* SQDMLSL, SQDMLSL2 */
8584 tcg_gen_neg_i64(tcg_res, tcg_res);
8586 case 0x9: /* SQDMLAL, SQDMLAL2 */
8587 read_vec_element(s, tcg_op1, rd, 0, MO_64);
8588 gen_helper_neon_addl_saturate_s64(tcg_res, cpu_env,
8592 g_assert_not_reached();
8595 write_fp_dreg(s, rd, tcg_res);
8597 tcg_temp_free_i64(tcg_op1);
8598 tcg_temp_free_i64(tcg_op2);
8599 tcg_temp_free_i64(tcg_res);
8601 TCGv_i32 tcg_op1 = read_fp_hreg(s, rn);
8602 TCGv_i32 tcg_op2 = read_fp_hreg(s, rm);
8603 TCGv_i64 tcg_res = tcg_temp_new_i64();
8605 gen_helper_neon_mull_s16(tcg_res, tcg_op1, tcg_op2);
8606 gen_helper_neon_addl_saturate_s32(tcg_res, cpu_env, tcg_res, tcg_res);
8609 case 0xd: /* SQDMULL, SQDMULL2 */
8611 case 0xb: /* SQDMLSL, SQDMLSL2 */
8612 gen_helper_neon_negl_u32(tcg_res, tcg_res);
8614 case 0x9: /* SQDMLAL, SQDMLAL2 */
8616 TCGv_i64 tcg_op3 = tcg_temp_new_i64();
8617 read_vec_element(s, tcg_op3, rd, 0, MO_32);
8618 gen_helper_neon_addl_saturate_s32(tcg_res, cpu_env,
8620 tcg_temp_free_i64(tcg_op3);
8624 g_assert_not_reached();
8627 tcg_gen_ext32u_i64(tcg_res, tcg_res);
8628 write_fp_dreg(s, rd, tcg_res);
8630 tcg_temp_free_i32(tcg_op1);
8631 tcg_temp_free_i32(tcg_op2);
8632 tcg_temp_free_i64(tcg_res);
8636 static void handle_3same_64(DisasContext *s, int opcode, bool u,
8637 TCGv_i64 tcg_rd, TCGv_i64 tcg_rn, TCGv_i64 tcg_rm)
8639 /* Handle 64x64->64 opcodes which are shared between the scalar
8640 * and vector 3-same groups. We cover every opcode where size == 3
8641 * is valid in either the three-reg-same (integer, not pairwise)
8642 * or scalar-three-reg-same groups.
8647 case 0x1: /* SQADD */
8649 gen_helper_neon_qadd_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8651 gen_helper_neon_qadd_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8654 case 0x5: /* SQSUB */
8656 gen_helper_neon_qsub_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8658 gen_helper_neon_qsub_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8661 case 0x6: /* CMGT, CMHI */
8662 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
8663 * We implement this using setcond (test) and then negating.
8665 cond = u ? TCG_COND_GTU : TCG_COND_GT;
8667 tcg_gen_setcond_i64(cond, tcg_rd, tcg_rn, tcg_rm);
8668 tcg_gen_neg_i64(tcg_rd, tcg_rd);
8670 case 0x7: /* CMGE, CMHS */
8671 cond = u ? TCG_COND_GEU : TCG_COND_GE;
8673 case 0x11: /* CMTST, CMEQ */
8678 gen_cmtst_i64(tcg_rd, tcg_rn, tcg_rm);
8680 case 0x8: /* SSHL, USHL */
8682 gen_helper_neon_shl_u64(tcg_rd, tcg_rn, tcg_rm);
8684 gen_helper_neon_shl_s64(tcg_rd, tcg_rn, tcg_rm);
8687 case 0x9: /* SQSHL, UQSHL */
8689 gen_helper_neon_qshl_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8691 gen_helper_neon_qshl_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8694 case 0xa: /* SRSHL, URSHL */
8696 gen_helper_neon_rshl_u64(tcg_rd, tcg_rn, tcg_rm);
8698 gen_helper_neon_rshl_s64(tcg_rd, tcg_rn, tcg_rm);
8701 case 0xb: /* SQRSHL, UQRSHL */
8703 gen_helper_neon_qrshl_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8705 gen_helper_neon_qrshl_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8708 case 0x10: /* ADD, SUB */
8710 tcg_gen_sub_i64(tcg_rd, tcg_rn, tcg_rm);
8712 tcg_gen_add_i64(tcg_rd, tcg_rn, tcg_rm);
8716 g_assert_not_reached();
8720 /* Handle the 3-same-operands float operations; shared by the scalar
8721 * and vector encodings. The caller must filter out any encodings
8722 * not allocated for the encoding it is dealing with.
8724 static void handle_3same_float(DisasContext *s, int size, int elements,
8725 int fpopcode, int rd, int rn, int rm)
8728 TCGv_ptr fpst = get_fpstatus_ptr(false);
8730 for (pass = 0; pass < elements; pass++) {
8733 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8734 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8735 TCGv_i64 tcg_res = tcg_temp_new_i64();
8737 read_vec_element(s, tcg_op1, rn, pass, MO_64);
8738 read_vec_element(s, tcg_op2, rm, pass, MO_64);
8741 case 0x39: /* FMLS */
8742 /* As usual for ARM, separate negation for fused multiply-add */
8743 gen_helper_vfp_negd(tcg_op1, tcg_op1);
8745 case 0x19: /* FMLA */
8746 read_vec_element(s, tcg_res, rd, pass, MO_64);
8747 gen_helper_vfp_muladdd(tcg_res, tcg_op1, tcg_op2,
8750 case 0x18: /* FMAXNM */
8751 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
8753 case 0x1a: /* FADD */
8754 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
8756 case 0x1b: /* FMULX */
8757 gen_helper_vfp_mulxd(tcg_res, tcg_op1, tcg_op2, fpst);
8759 case 0x1c: /* FCMEQ */
8760 gen_helper_neon_ceq_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8762 case 0x1e: /* FMAX */
8763 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
8765 case 0x1f: /* FRECPS */
8766 gen_helper_recpsf_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8768 case 0x38: /* FMINNM */
8769 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
8771 case 0x3a: /* FSUB */
8772 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
8774 case 0x3e: /* FMIN */
8775 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
8777 case 0x3f: /* FRSQRTS */
8778 gen_helper_rsqrtsf_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8780 case 0x5b: /* FMUL */
8781 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
8783 case 0x5c: /* FCMGE */
8784 gen_helper_neon_cge_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8786 case 0x5d: /* FACGE */
8787 gen_helper_neon_acge_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8789 case 0x5f: /* FDIV */
8790 gen_helper_vfp_divd(tcg_res, tcg_op1, tcg_op2, fpst);
8792 case 0x7a: /* FABD */
8793 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
8794 gen_helper_vfp_absd(tcg_res, tcg_res);
8796 case 0x7c: /* FCMGT */
8797 gen_helper_neon_cgt_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8799 case 0x7d: /* FACGT */
8800 gen_helper_neon_acgt_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8803 g_assert_not_reached();
8806 write_vec_element(s, tcg_res, rd, pass, MO_64);
8808 tcg_temp_free_i64(tcg_res);
8809 tcg_temp_free_i64(tcg_op1);
8810 tcg_temp_free_i64(tcg_op2);
8813 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
8814 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
8815 TCGv_i32 tcg_res = tcg_temp_new_i32();
8817 read_vec_element_i32(s, tcg_op1, rn, pass, MO_32);
8818 read_vec_element_i32(s, tcg_op2, rm, pass, MO_32);
8821 case 0x39: /* FMLS */
8822 /* As usual for ARM, separate negation for fused multiply-add */
8823 gen_helper_vfp_negs(tcg_op1, tcg_op1);
8825 case 0x19: /* FMLA */
8826 read_vec_element_i32(s, tcg_res, rd, pass, MO_32);
8827 gen_helper_vfp_muladds(tcg_res, tcg_op1, tcg_op2,
8830 case 0x1a: /* FADD */
8831 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
8833 case 0x1b: /* FMULX */
8834 gen_helper_vfp_mulxs(tcg_res, tcg_op1, tcg_op2, fpst);
8836 case 0x1c: /* FCMEQ */
8837 gen_helper_neon_ceq_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8839 case 0x1e: /* FMAX */
8840 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
8842 case 0x1f: /* FRECPS */
8843 gen_helper_recpsf_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8845 case 0x18: /* FMAXNM */
8846 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
8848 case 0x38: /* FMINNM */
8849 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
8851 case 0x3a: /* FSUB */
8852 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
8854 case 0x3e: /* FMIN */
8855 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
8857 case 0x3f: /* FRSQRTS */
8858 gen_helper_rsqrtsf_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8860 case 0x5b: /* FMUL */
8861 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
8863 case 0x5c: /* FCMGE */
8864 gen_helper_neon_cge_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8866 case 0x5d: /* FACGE */
8867 gen_helper_neon_acge_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8869 case 0x5f: /* FDIV */
8870 gen_helper_vfp_divs(tcg_res, tcg_op1, tcg_op2, fpst);
8872 case 0x7a: /* FABD */
8873 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
8874 gen_helper_vfp_abss(tcg_res, tcg_res);
8876 case 0x7c: /* FCMGT */
8877 gen_helper_neon_cgt_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8879 case 0x7d: /* FACGT */
8880 gen_helper_neon_acgt_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8883 g_assert_not_reached();
8886 if (elements == 1) {
8887 /* scalar single so clear high part */
8888 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
8890 tcg_gen_extu_i32_i64(tcg_tmp, tcg_res);
8891 write_vec_element(s, tcg_tmp, rd, pass, MO_64);
8892 tcg_temp_free_i64(tcg_tmp);
8894 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
8897 tcg_temp_free_i32(tcg_res);
8898 tcg_temp_free_i32(tcg_op1);
8899 tcg_temp_free_i32(tcg_op2);
8903 tcg_temp_free_ptr(fpst);
8905 clear_vec_high(s, elements * (size ? 8 : 4) > 8, rd);
8908 /* AdvSIMD scalar three same
8909 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8910 * +-----+---+-----------+------+---+------+--------+---+------+------+
8911 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8912 * +-----+---+-----------+------+---+------+--------+---+------+------+
8914 static void disas_simd_scalar_three_reg_same(DisasContext *s, uint32_t insn)
8916 int rd = extract32(insn, 0, 5);
8917 int rn = extract32(insn, 5, 5);
8918 int opcode = extract32(insn, 11, 5);
8919 int rm = extract32(insn, 16, 5);
8920 int size = extract32(insn, 22, 2);
8921 bool u = extract32(insn, 29, 1);
8924 if (opcode >= 0x18) {
8925 /* Floating point: U, size[1] and opcode indicate operation */
8926 int fpopcode = opcode | (extract32(size, 1, 1) << 5) | (u << 6);
8928 case 0x1b: /* FMULX */
8929 case 0x1f: /* FRECPS */
8930 case 0x3f: /* FRSQRTS */
8931 case 0x5d: /* FACGE */
8932 case 0x7d: /* FACGT */
8933 case 0x1c: /* FCMEQ */
8934 case 0x5c: /* FCMGE */
8935 case 0x7c: /* FCMGT */
8936 case 0x7a: /* FABD */
8939 unallocated_encoding(s);
8943 if (!fp_access_check(s)) {
8947 handle_3same_float(s, extract32(size, 0, 1), 1, fpopcode, rd, rn, rm);
8952 case 0x1: /* SQADD, UQADD */
8953 case 0x5: /* SQSUB, UQSUB */
8954 case 0x9: /* SQSHL, UQSHL */
8955 case 0xb: /* SQRSHL, UQRSHL */
8957 case 0x8: /* SSHL, USHL */
8958 case 0xa: /* SRSHL, URSHL */
8959 case 0x6: /* CMGT, CMHI */
8960 case 0x7: /* CMGE, CMHS */
8961 case 0x11: /* CMTST, CMEQ */
8962 case 0x10: /* ADD, SUB (vector) */
8964 unallocated_encoding(s);
8968 case 0x16: /* SQDMULH, SQRDMULH (vector) */
8969 if (size != 1 && size != 2) {
8970 unallocated_encoding(s);
8975 unallocated_encoding(s);
8979 if (!fp_access_check(s)) {
8983 tcg_rd = tcg_temp_new_i64();
8986 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
8987 TCGv_i64 tcg_rm = read_fp_dreg(s, rm);
8989 handle_3same_64(s, opcode, u, tcg_rd, tcg_rn, tcg_rm);
8990 tcg_temp_free_i64(tcg_rn);
8991 tcg_temp_free_i64(tcg_rm);
8993 /* Do a single operation on the lowest element in the vector.
8994 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
8995 * no side effects for all these operations.
8996 * OPTME: special-purpose helpers would avoid doing some
8997 * unnecessary work in the helper for the 8 and 16 bit cases.
8999 NeonGenTwoOpEnvFn *genenvfn;
9000 TCGv_i32 tcg_rn = tcg_temp_new_i32();
9001 TCGv_i32 tcg_rm = tcg_temp_new_i32();
9002 TCGv_i32 tcg_rd32 = tcg_temp_new_i32();
9004 read_vec_element_i32(s, tcg_rn, rn, 0, size);
9005 read_vec_element_i32(s, tcg_rm, rm, 0, size);
9008 case 0x1: /* SQADD, UQADD */
9010 static NeonGenTwoOpEnvFn * const fns[3][2] = {
9011 { gen_helper_neon_qadd_s8, gen_helper_neon_qadd_u8 },
9012 { gen_helper_neon_qadd_s16, gen_helper_neon_qadd_u16 },
9013 { gen_helper_neon_qadd_s32, gen_helper_neon_qadd_u32 },
9015 genenvfn = fns[size][u];
9018 case 0x5: /* SQSUB, UQSUB */
9020 static NeonGenTwoOpEnvFn * const fns[3][2] = {
9021 { gen_helper_neon_qsub_s8, gen_helper_neon_qsub_u8 },
9022 { gen_helper_neon_qsub_s16, gen_helper_neon_qsub_u16 },
9023 { gen_helper_neon_qsub_s32, gen_helper_neon_qsub_u32 },
9025 genenvfn = fns[size][u];
9028 case 0x9: /* SQSHL, UQSHL */
9030 static NeonGenTwoOpEnvFn * const fns[3][2] = {
9031 { gen_helper_neon_qshl_s8, gen_helper_neon_qshl_u8 },
9032 { gen_helper_neon_qshl_s16, gen_helper_neon_qshl_u16 },
9033 { gen_helper_neon_qshl_s32, gen_helper_neon_qshl_u32 },
9035 genenvfn = fns[size][u];
9038 case 0xb: /* SQRSHL, UQRSHL */
9040 static NeonGenTwoOpEnvFn * const fns[3][2] = {
9041 { gen_helper_neon_qrshl_s8, gen_helper_neon_qrshl_u8 },
9042 { gen_helper_neon_qrshl_s16, gen_helper_neon_qrshl_u16 },
9043 { gen_helper_neon_qrshl_s32, gen_helper_neon_qrshl_u32 },
9045 genenvfn = fns[size][u];
9048 case 0x16: /* SQDMULH, SQRDMULH */
9050 static NeonGenTwoOpEnvFn * const fns[2][2] = {
9051 { gen_helper_neon_qdmulh_s16, gen_helper_neon_qrdmulh_s16 },
9052 { gen_helper_neon_qdmulh_s32, gen_helper_neon_qrdmulh_s32 },
9054 assert(size == 1 || size == 2);
9055 genenvfn = fns[size - 1][u];
9059 g_assert_not_reached();
9062 genenvfn(tcg_rd32, cpu_env, tcg_rn, tcg_rm);
9063 tcg_gen_extu_i32_i64(tcg_rd, tcg_rd32);
9064 tcg_temp_free_i32(tcg_rd32);
9065 tcg_temp_free_i32(tcg_rn);
9066 tcg_temp_free_i32(tcg_rm);
9069 write_fp_dreg(s, rd, tcg_rd);
9071 tcg_temp_free_i64(tcg_rd);
9074 /* AdvSIMD scalar three same FP16
9075 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
9076 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9077 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
9078 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9079 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
9080 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
9082 static void disas_simd_scalar_three_reg_same_fp16(DisasContext *s,
9085 int rd = extract32(insn, 0, 5);
9086 int rn = extract32(insn, 5, 5);
9087 int opcode = extract32(insn, 11, 3);
9088 int rm = extract32(insn, 16, 5);
9089 bool u = extract32(insn, 29, 1);
9090 bool a = extract32(insn, 23, 1);
9091 int fpopcode = opcode | (a << 3) | (u << 4);
9098 case 0x03: /* FMULX */
9099 case 0x04: /* FCMEQ (reg) */
9100 case 0x07: /* FRECPS */
9101 case 0x0f: /* FRSQRTS */
9102 case 0x14: /* FCMGE (reg) */
9103 case 0x15: /* FACGE */
9104 case 0x1a: /* FABD */
9105 case 0x1c: /* FCMGT (reg) */
9106 case 0x1d: /* FACGT */
9109 unallocated_encoding(s);
9113 if (!dc_isar_feature(aa64_fp16, s)) {
9114 unallocated_encoding(s);
9117 if (!fp_access_check(s)) {
9121 fpst = get_fpstatus_ptr(true);
9123 tcg_op1 = read_fp_hreg(s, rn);
9124 tcg_op2 = read_fp_hreg(s, rm);
9125 tcg_res = tcg_temp_new_i32();
9128 case 0x03: /* FMULX */
9129 gen_helper_advsimd_mulxh(tcg_res, tcg_op1, tcg_op2, fpst);
9131 case 0x04: /* FCMEQ (reg) */
9132 gen_helper_advsimd_ceq_f16(tcg_res, tcg_op1, tcg_op2, fpst);
9134 case 0x07: /* FRECPS */
9135 gen_helper_recpsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
9137 case 0x0f: /* FRSQRTS */
9138 gen_helper_rsqrtsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
9140 case 0x14: /* FCMGE (reg) */
9141 gen_helper_advsimd_cge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
9143 case 0x15: /* FACGE */
9144 gen_helper_advsimd_acge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
9146 case 0x1a: /* FABD */
9147 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
9148 tcg_gen_andi_i32(tcg_res, tcg_res, 0x7fff);
9150 case 0x1c: /* FCMGT (reg) */
9151 gen_helper_advsimd_cgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
9153 case 0x1d: /* FACGT */
9154 gen_helper_advsimd_acgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
9157 g_assert_not_reached();
9160 write_fp_sreg(s, rd, tcg_res);
9163 tcg_temp_free_i32(tcg_res);
9164 tcg_temp_free_i32(tcg_op1);
9165 tcg_temp_free_i32(tcg_op2);
9166 tcg_temp_free_ptr(fpst);
9169 /* AdvSIMD scalar three same extra
9170 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
9171 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9172 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
9173 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9175 static void disas_simd_scalar_three_reg_same_extra(DisasContext *s,
9178 int rd = extract32(insn, 0, 5);
9179 int rn = extract32(insn, 5, 5);
9180 int opcode = extract32(insn, 11, 4);
9181 int rm = extract32(insn, 16, 5);
9182 int size = extract32(insn, 22, 2);
9183 bool u = extract32(insn, 29, 1);
9184 TCGv_i32 ele1, ele2, ele3;
9188 switch (u * 16 + opcode) {
9189 case 0x10: /* SQRDMLAH (vector) */
9190 case 0x11: /* SQRDMLSH (vector) */
9191 if (size != 1 && size != 2) {
9192 unallocated_encoding(s);
9195 feature = dc_isar_feature(aa64_rdm, s);
9198 unallocated_encoding(s);
9202 unallocated_encoding(s);
9205 if (!fp_access_check(s)) {
9209 /* Do a single operation on the lowest element in the vector.
9210 * We use the standard Neon helpers and rely on 0 OP 0 == 0
9211 * with no side effects for all these operations.
9212 * OPTME: special-purpose helpers would avoid doing some
9213 * unnecessary work in the helper for the 16 bit cases.
9215 ele1 = tcg_temp_new_i32();
9216 ele2 = tcg_temp_new_i32();
9217 ele3 = tcg_temp_new_i32();
9219 read_vec_element_i32(s, ele1, rn, 0, size);
9220 read_vec_element_i32(s, ele2, rm, 0, size);
9221 read_vec_element_i32(s, ele3, rd, 0, size);
9224 case 0x0: /* SQRDMLAH */
9226 gen_helper_neon_qrdmlah_s16(ele3, cpu_env, ele1, ele2, ele3);
9228 gen_helper_neon_qrdmlah_s32(ele3, cpu_env, ele1, ele2, ele3);
9231 case 0x1: /* SQRDMLSH */
9233 gen_helper_neon_qrdmlsh_s16(ele3, cpu_env, ele1, ele2, ele3);
9235 gen_helper_neon_qrdmlsh_s32(ele3, cpu_env, ele1, ele2, ele3);
9239 g_assert_not_reached();
9241 tcg_temp_free_i32(ele1);
9242 tcg_temp_free_i32(ele2);
9244 res = tcg_temp_new_i64();
9245 tcg_gen_extu_i32_i64(res, ele3);
9246 tcg_temp_free_i32(ele3);
9248 write_fp_dreg(s, rd, res);
9249 tcg_temp_free_i64(res);
9252 static void handle_2misc_64(DisasContext *s, int opcode, bool u,
9253 TCGv_i64 tcg_rd, TCGv_i64 tcg_rn,
9254 TCGv_i32 tcg_rmode, TCGv_ptr tcg_fpstatus)
9256 /* Handle 64->64 opcodes which are shared between the scalar and
9257 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
9258 * is valid in either group and also the double-precision fp ops.
9259 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
9265 case 0x4: /* CLS, CLZ */
9267 tcg_gen_clzi_i64(tcg_rd, tcg_rn, 64);
9269 tcg_gen_clrsb_i64(tcg_rd, tcg_rn);
9273 /* This opcode is shared with CNT and RBIT but we have earlier
9274 * enforced that size == 3 if and only if this is the NOT insn.
9276 tcg_gen_not_i64(tcg_rd, tcg_rn);
9278 case 0x7: /* SQABS, SQNEG */
9280 gen_helper_neon_qneg_s64(tcg_rd, cpu_env, tcg_rn);
9282 gen_helper_neon_qabs_s64(tcg_rd, cpu_env, tcg_rn);
9285 case 0xa: /* CMLT */
9286 /* 64 bit integer comparison against zero, result is
9287 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
9292 tcg_gen_setcondi_i64(cond, tcg_rd, tcg_rn, 0);
9293 tcg_gen_neg_i64(tcg_rd, tcg_rd);
9295 case 0x8: /* CMGT, CMGE */
9296 cond = u ? TCG_COND_GE : TCG_COND_GT;
9298 case 0x9: /* CMEQ, CMLE */
9299 cond = u ? TCG_COND_LE : TCG_COND_EQ;
9301 case 0xb: /* ABS, NEG */
9303 tcg_gen_neg_i64(tcg_rd, tcg_rn);
9305 tcg_gen_abs_i64(tcg_rd, tcg_rn);
9308 case 0x2f: /* FABS */
9309 gen_helper_vfp_absd(tcg_rd, tcg_rn);
9311 case 0x6f: /* FNEG */
9312 gen_helper_vfp_negd(tcg_rd, tcg_rn);
9314 case 0x7f: /* FSQRT */
9315 gen_helper_vfp_sqrtd(tcg_rd, tcg_rn, cpu_env);
9317 case 0x1a: /* FCVTNS */
9318 case 0x1b: /* FCVTMS */
9319 case 0x1c: /* FCVTAS */
9320 case 0x3a: /* FCVTPS */
9321 case 0x3b: /* FCVTZS */
9323 TCGv_i32 tcg_shift = tcg_const_i32(0);
9324 gen_helper_vfp_tosqd(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9325 tcg_temp_free_i32(tcg_shift);
9328 case 0x5a: /* FCVTNU */
9329 case 0x5b: /* FCVTMU */
9330 case 0x5c: /* FCVTAU */
9331 case 0x7a: /* FCVTPU */
9332 case 0x7b: /* FCVTZU */
9334 TCGv_i32 tcg_shift = tcg_const_i32(0);
9335 gen_helper_vfp_touqd(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9336 tcg_temp_free_i32(tcg_shift);
9339 case 0x18: /* FRINTN */
9340 case 0x19: /* FRINTM */
9341 case 0x38: /* FRINTP */
9342 case 0x39: /* FRINTZ */
9343 case 0x58: /* FRINTA */
9344 case 0x79: /* FRINTI */
9345 gen_helper_rintd(tcg_rd, tcg_rn, tcg_fpstatus);
9347 case 0x59: /* FRINTX */
9348 gen_helper_rintd_exact(tcg_rd, tcg_rn, tcg_fpstatus);
9350 case 0x1e: /* FRINT32Z */
9351 case 0x5e: /* FRINT32X */
9352 gen_helper_frint32_d(tcg_rd, tcg_rn, tcg_fpstatus);
9354 case 0x1f: /* FRINT64Z */
9355 case 0x5f: /* FRINT64X */
9356 gen_helper_frint64_d(tcg_rd, tcg_rn, tcg_fpstatus);
9359 g_assert_not_reached();
9363 static void handle_2misc_fcmp_zero(DisasContext *s, int opcode,
9364 bool is_scalar, bool is_u, bool is_q,
9365 int size, int rn, int rd)
9367 bool is_double = (size == MO_64);
9370 if (!fp_access_check(s)) {
9374 fpst = get_fpstatus_ptr(size == MO_16);
9377 TCGv_i64 tcg_op = tcg_temp_new_i64();
9378 TCGv_i64 tcg_zero = tcg_const_i64(0);
9379 TCGv_i64 tcg_res = tcg_temp_new_i64();
9380 NeonGenTwoDoubleOPFn *genfn;
9385 case 0x2e: /* FCMLT (zero) */
9388 case 0x2c: /* FCMGT (zero) */
9389 genfn = gen_helper_neon_cgt_f64;
9391 case 0x2d: /* FCMEQ (zero) */
9392 genfn = gen_helper_neon_ceq_f64;
9394 case 0x6d: /* FCMLE (zero) */
9397 case 0x6c: /* FCMGE (zero) */
9398 genfn = gen_helper_neon_cge_f64;
9401 g_assert_not_reached();
9404 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9405 read_vec_element(s, tcg_op, rn, pass, MO_64);
9407 genfn(tcg_res, tcg_zero, tcg_op, fpst);
9409 genfn(tcg_res, tcg_op, tcg_zero, fpst);
9411 write_vec_element(s, tcg_res, rd, pass, MO_64);
9413 tcg_temp_free_i64(tcg_res);
9414 tcg_temp_free_i64(tcg_zero);
9415 tcg_temp_free_i64(tcg_op);
9417 clear_vec_high(s, !is_scalar, rd);
9419 TCGv_i32 tcg_op = tcg_temp_new_i32();
9420 TCGv_i32 tcg_zero = tcg_const_i32(0);
9421 TCGv_i32 tcg_res = tcg_temp_new_i32();
9422 NeonGenTwoSingleOPFn *genfn;
9424 int pass, maxpasses;
9426 if (size == MO_16) {
9428 case 0x2e: /* FCMLT (zero) */
9431 case 0x2c: /* FCMGT (zero) */
9432 genfn = gen_helper_advsimd_cgt_f16;
9434 case 0x2d: /* FCMEQ (zero) */
9435 genfn = gen_helper_advsimd_ceq_f16;
9437 case 0x6d: /* FCMLE (zero) */
9440 case 0x6c: /* FCMGE (zero) */
9441 genfn = gen_helper_advsimd_cge_f16;
9444 g_assert_not_reached();
9448 case 0x2e: /* FCMLT (zero) */
9451 case 0x2c: /* FCMGT (zero) */
9452 genfn = gen_helper_neon_cgt_f32;
9454 case 0x2d: /* FCMEQ (zero) */
9455 genfn = gen_helper_neon_ceq_f32;
9457 case 0x6d: /* FCMLE (zero) */
9460 case 0x6c: /* FCMGE (zero) */
9461 genfn = gen_helper_neon_cge_f32;
9464 g_assert_not_reached();
9471 int vector_size = 8 << is_q;
9472 maxpasses = vector_size >> size;
9475 for (pass = 0; pass < maxpasses; pass++) {
9476 read_vec_element_i32(s, tcg_op, rn, pass, size);
9478 genfn(tcg_res, tcg_zero, tcg_op, fpst);
9480 genfn(tcg_res, tcg_op, tcg_zero, fpst);
9483 write_fp_sreg(s, rd, tcg_res);
9485 write_vec_element_i32(s, tcg_res, rd, pass, size);
9488 tcg_temp_free_i32(tcg_res);
9489 tcg_temp_free_i32(tcg_zero);
9490 tcg_temp_free_i32(tcg_op);
9492 clear_vec_high(s, is_q, rd);
9496 tcg_temp_free_ptr(fpst);
9499 static void handle_2misc_reciprocal(DisasContext *s, int opcode,
9500 bool is_scalar, bool is_u, bool is_q,
9501 int size, int rn, int rd)
9503 bool is_double = (size == 3);
9504 TCGv_ptr fpst = get_fpstatus_ptr(false);
9507 TCGv_i64 tcg_op = tcg_temp_new_i64();
9508 TCGv_i64 tcg_res = tcg_temp_new_i64();
9511 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9512 read_vec_element(s, tcg_op, rn, pass, MO_64);
9514 case 0x3d: /* FRECPE */
9515 gen_helper_recpe_f64(tcg_res, tcg_op, fpst);
9517 case 0x3f: /* FRECPX */
9518 gen_helper_frecpx_f64(tcg_res, tcg_op, fpst);
9520 case 0x7d: /* FRSQRTE */
9521 gen_helper_rsqrte_f64(tcg_res, tcg_op, fpst);
9524 g_assert_not_reached();
9526 write_vec_element(s, tcg_res, rd, pass, MO_64);
9528 tcg_temp_free_i64(tcg_res);
9529 tcg_temp_free_i64(tcg_op);
9530 clear_vec_high(s, !is_scalar, rd);
9532 TCGv_i32 tcg_op = tcg_temp_new_i32();
9533 TCGv_i32 tcg_res = tcg_temp_new_i32();
9534 int pass, maxpasses;
9539 maxpasses = is_q ? 4 : 2;
9542 for (pass = 0; pass < maxpasses; pass++) {
9543 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
9546 case 0x3c: /* URECPE */
9547 gen_helper_recpe_u32(tcg_res, tcg_op, fpst);
9549 case 0x3d: /* FRECPE */
9550 gen_helper_recpe_f32(tcg_res, tcg_op, fpst);
9552 case 0x3f: /* FRECPX */
9553 gen_helper_frecpx_f32(tcg_res, tcg_op, fpst);
9555 case 0x7d: /* FRSQRTE */
9556 gen_helper_rsqrte_f32(tcg_res, tcg_op, fpst);
9559 g_assert_not_reached();
9563 write_fp_sreg(s, rd, tcg_res);
9565 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
9568 tcg_temp_free_i32(tcg_res);
9569 tcg_temp_free_i32(tcg_op);
9571 clear_vec_high(s, is_q, rd);
9574 tcg_temp_free_ptr(fpst);
9577 static void handle_2misc_narrow(DisasContext *s, bool scalar,
9578 int opcode, bool u, bool is_q,
9579 int size, int rn, int rd)
9581 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
9582 * in the source becomes a size element in the destination).
9585 TCGv_i32 tcg_res[2];
9586 int destelt = is_q ? 2 : 0;
9587 int passes = scalar ? 1 : 2;
9590 tcg_res[1] = tcg_const_i32(0);
9593 for (pass = 0; pass < passes; pass++) {
9594 TCGv_i64 tcg_op = tcg_temp_new_i64();
9595 NeonGenNarrowFn *genfn = NULL;
9596 NeonGenNarrowEnvFn *genenvfn = NULL;
9599 read_vec_element(s, tcg_op, rn, pass, size + 1);
9601 read_vec_element(s, tcg_op, rn, pass, MO_64);
9603 tcg_res[pass] = tcg_temp_new_i32();
9606 case 0x12: /* XTN, SQXTUN */
9608 static NeonGenNarrowFn * const xtnfns[3] = {
9609 gen_helper_neon_narrow_u8,
9610 gen_helper_neon_narrow_u16,
9611 tcg_gen_extrl_i64_i32,
9613 static NeonGenNarrowEnvFn * const sqxtunfns[3] = {
9614 gen_helper_neon_unarrow_sat8,
9615 gen_helper_neon_unarrow_sat16,
9616 gen_helper_neon_unarrow_sat32,
9619 genenvfn = sqxtunfns[size];
9621 genfn = xtnfns[size];
9625 case 0x14: /* SQXTN, UQXTN */
9627 static NeonGenNarrowEnvFn * const fns[3][2] = {
9628 { gen_helper_neon_narrow_sat_s8,
9629 gen_helper_neon_narrow_sat_u8 },
9630 { gen_helper_neon_narrow_sat_s16,
9631 gen_helper_neon_narrow_sat_u16 },
9632 { gen_helper_neon_narrow_sat_s32,
9633 gen_helper_neon_narrow_sat_u32 },
9635 genenvfn = fns[size][u];
9638 case 0x16: /* FCVTN, FCVTN2 */
9639 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
9641 gen_helper_vfp_fcvtsd(tcg_res[pass], tcg_op, cpu_env);
9643 TCGv_i32 tcg_lo = tcg_temp_new_i32();
9644 TCGv_i32 tcg_hi = tcg_temp_new_i32();
9645 TCGv_ptr fpst = get_fpstatus_ptr(false);
9646 TCGv_i32 ahp = get_ahp_flag();
9648 tcg_gen_extr_i64_i32(tcg_lo, tcg_hi, tcg_op);
9649 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo, tcg_lo, fpst, ahp);
9650 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi, tcg_hi, fpst, ahp);
9651 tcg_gen_deposit_i32(tcg_res[pass], tcg_lo, tcg_hi, 16, 16);
9652 tcg_temp_free_i32(tcg_lo);
9653 tcg_temp_free_i32(tcg_hi);
9654 tcg_temp_free_ptr(fpst);
9655 tcg_temp_free_i32(ahp);
9658 case 0x56: /* FCVTXN, FCVTXN2 */
9659 /* 64 bit to 32 bit float conversion
9660 * with von Neumann rounding (round to odd)
9663 gen_helper_fcvtx_f64_to_f32(tcg_res[pass], tcg_op, cpu_env);
9666 g_assert_not_reached();
9670 genfn(tcg_res[pass], tcg_op);
9671 } else if (genenvfn) {
9672 genenvfn(tcg_res[pass], cpu_env, tcg_op);
9675 tcg_temp_free_i64(tcg_op);
9678 for (pass = 0; pass < 2; pass++) {
9679 write_vec_element_i32(s, tcg_res[pass], rd, destelt + pass, MO_32);
9680 tcg_temp_free_i32(tcg_res[pass]);
9682 clear_vec_high(s, is_q, rd);
9685 /* Remaining saturating accumulating ops */
9686 static void handle_2misc_satacc(DisasContext *s, bool is_scalar, bool is_u,
9687 bool is_q, int size, int rn, int rd)
9689 bool is_double = (size == 3);
9692 TCGv_i64 tcg_rn = tcg_temp_new_i64();
9693 TCGv_i64 tcg_rd = tcg_temp_new_i64();
9696 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9697 read_vec_element(s, tcg_rn, rn, pass, MO_64);
9698 read_vec_element(s, tcg_rd, rd, pass, MO_64);
9700 if (is_u) { /* USQADD */
9701 gen_helper_neon_uqadd_s64(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9702 } else { /* SUQADD */
9703 gen_helper_neon_sqadd_u64(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9705 write_vec_element(s, tcg_rd, rd, pass, MO_64);
9707 tcg_temp_free_i64(tcg_rd);
9708 tcg_temp_free_i64(tcg_rn);
9709 clear_vec_high(s, !is_scalar, rd);
9711 TCGv_i32 tcg_rn = tcg_temp_new_i32();
9712 TCGv_i32 tcg_rd = tcg_temp_new_i32();
9713 int pass, maxpasses;
9718 maxpasses = is_q ? 4 : 2;
9721 for (pass = 0; pass < maxpasses; pass++) {
9723 read_vec_element_i32(s, tcg_rn, rn, pass, size);
9724 read_vec_element_i32(s, tcg_rd, rd, pass, size);
9726 read_vec_element_i32(s, tcg_rn, rn, pass, MO_32);
9727 read_vec_element_i32(s, tcg_rd, rd, pass, MO_32);
9730 if (is_u) { /* USQADD */
9733 gen_helper_neon_uqadd_s8(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9736 gen_helper_neon_uqadd_s16(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9739 gen_helper_neon_uqadd_s32(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9742 g_assert_not_reached();
9744 } else { /* SUQADD */
9747 gen_helper_neon_sqadd_u8(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9750 gen_helper_neon_sqadd_u16(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9753 gen_helper_neon_sqadd_u32(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9756 g_assert_not_reached();
9761 TCGv_i64 tcg_zero = tcg_const_i64(0);
9762 write_vec_element(s, tcg_zero, rd, 0, MO_64);
9763 tcg_temp_free_i64(tcg_zero);
9765 write_vec_element_i32(s, tcg_rd, rd, pass, MO_32);
9767 tcg_temp_free_i32(tcg_rd);
9768 tcg_temp_free_i32(tcg_rn);
9769 clear_vec_high(s, is_q, rd);
9773 /* AdvSIMD scalar two reg misc
9774 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9775 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9776 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9777 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9779 static void disas_simd_scalar_two_reg_misc(DisasContext *s, uint32_t insn)
9781 int rd = extract32(insn, 0, 5);
9782 int rn = extract32(insn, 5, 5);
9783 int opcode = extract32(insn, 12, 5);
9784 int size = extract32(insn, 22, 2);
9785 bool u = extract32(insn, 29, 1);
9786 bool is_fcvt = false;
9789 TCGv_ptr tcg_fpstatus;
9792 case 0x3: /* USQADD / SUQADD*/
9793 if (!fp_access_check(s)) {
9796 handle_2misc_satacc(s, true, u, false, size, rn, rd);
9798 case 0x7: /* SQABS / SQNEG */
9800 case 0xa: /* CMLT */
9802 unallocated_encoding(s);
9806 case 0x8: /* CMGT, CMGE */
9807 case 0x9: /* CMEQ, CMLE */
9808 case 0xb: /* ABS, NEG */
9810 unallocated_encoding(s);
9814 case 0x12: /* SQXTUN */
9816 unallocated_encoding(s);
9820 case 0x14: /* SQXTN, UQXTN */
9822 unallocated_encoding(s);
9825 if (!fp_access_check(s)) {
9828 handle_2misc_narrow(s, true, opcode, u, false, size, rn, rd);
9833 /* Floating point: U, size[1] and opcode indicate operation;
9834 * size[0] indicates single or double precision.
9836 opcode |= (extract32(size, 1, 1) << 5) | (u << 6);
9837 size = extract32(size, 0, 1) ? 3 : 2;
9839 case 0x2c: /* FCMGT (zero) */
9840 case 0x2d: /* FCMEQ (zero) */
9841 case 0x2e: /* FCMLT (zero) */
9842 case 0x6c: /* FCMGE (zero) */
9843 case 0x6d: /* FCMLE (zero) */
9844 handle_2misc_fcmp_zero(s, opcode, true, u, true, size, rn, rd);
9846 case 0x1d: /* SCVTF */
9847 case 0x5d: /* UCVTF */
9849 bool is_signed = (opcode == 0x1d);
9850 if (!fp_access_check(s)) {
9853 handle_simd_intfp_conv(s, rd, rn, 1, is_signed, 0, size);
9856 case 0x3d: /* FRECPE */
9857 case 0x3f: /* FRECPX */
9858 case 0x7d: /* FRSQRTE */
9859 if (!fp_access_check(s)) {
9862 handle_2misc_reciprocal(s, opcode, true, u, true, size, rn, rd);
9864 case 0x1a: /* FCVTNS */
9865 case 0x1b: /* FCVTMS */
9866 case 0x3a: /* FCVTPS */
9867 case 0x3b: /* FCVTZS */
9868 case 0x5a: /* FCVTNU */
9869 case 0x5b: /* FCVTMU */
9870 case 0x7a: /* FCVTPU */
9871 case 0x7b: /* FCVTZU */
9873 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
9875 case 0x1c: /* FCVTAS */
9876 case 0x5c: /* FCVTAU */
9877 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
9879 rmode = FPROUNDING_TIEAWAY;
9881 case 0x56: /* FCVTXN, FCVTXN2 */
9883 unallocated_encoding(s);
9886 if (!fp_access_check(s)) {
9889 handle_2misc_narrow(s, true, opcode, u, false, size - 1, rn, rd);
9892 unallocated_encoding(s);
9897 unallocated_encoding(s);
9901 if (!fp_access_check(s)) {
9906 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
9907 tcg_fpstatus = get_fpstatus_ptr(false);
9908 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
9911 tcg_fpstatus = NULL;
9915 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
9916 TCGv_i64 tcg_rd = tcg_temp_new_i64();
9918 handle_2misc_64(s, opcode, u, tcg_rd, tcg_rn, tcg_rmode, tcg_fpstatus);
9919 write_fp_dreg(s, rd, tcg_rd);
9920 tcg_temp_free_i64(tcg_rd);
9921 tcg_temp_free_i64(tcg_rn);
9923 TCGv_i32 tcg_rn = tcg_temp_new_i32();
9924 TCGv_i32 tcg_rd = tcg_temp_new_i32();
9926 read_vec_element_i32(s, tcg_rn, rn, 0, size);
9929 case 0x7: /* SQABS, SQNEG */
9931 NeonGenOneOpEnvFn *genfn;
9932 static NeonGenOneOpEnvFn * const fns[3][2] = {
9933 { gen_helper_neon_qabs_s8, gen_helper_neon_qneg_s8 },
9934 { gen_helper_neon_qabs_s16, gen_helper_neon_qneg_s16 },
9935 { gen_helper_neon_qabs_s32, gen_helper_neon_qneg_s32 },
9937 genfn = fns[size][u];
9938 genfn(tcg_rd, cpu_env, tcg_rn);
9941 case 0x1a: /* FCVTNS */
9942 case 0x1b: /* FCVTMS */
9943 case 0x1c: /* FCVTAS */
9944 case 0x3a: /* FCVTPS */
9945 case 0x3b: /* FCVTZS */
9947 TCGv_i32 tcg_shift = tcg_const_i32(0);
9948 gen_helper_vfp_tosls(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9949 tcg_temp_free_i32(tcg_shift);
9952 case 0x5a: /* FCVTNU */
9953 case 0x5b: /* FCVTMU */
9954 case 0x5c: /* FCVTAU */
9955 case 0x7a: /* FCVTPU */
9956 case 0x7b: /* FCVTZU */
9958 TCGv_i32 tcg_shift = tcg_const_i32(0);
9959 gen_helper_vfp_touls(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9960 tcg_temp_free_i32(tcg_shift);
9964 g_assert_not_reached();
9967 write_fp_sreg(s, rd, tcg_rd);
9968 tcg_temp_free_i32(tcg_rd);
9969 tcg_temp_free_i32(tcg_rn);
9973 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
9974 tcg_temp_free_i32(tcg_rmode);
9975 tcg_temp_free_ptr(tcg_fpstatus);
9979 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
9980 static void handle_vec_simd_shri(DisasContext *s, bool is_q, bool is_u,
9981 int immh, int immb, int opcode, int rn, int rd)
9983 int size = 32 - clz32(immh) - 1;
9984 int immhb = immh << 3 | immb;
9985 int shift = 2 * (8 << size) - immhb;
9986 bool accumulate = false;
9987 int dsize = is_q ? 128 : 64;
9988 int esize = 8 << size;
9989 int elements = dsize/esize;
9990 TCGMemOp memop = size | (is_u ? 0 : MO_SIGN);
9991 TCGv_i64 tcg_rn = new_tmp_a64(s);
9992 TCGv_i64 tcg_rd = new_tmp_a64(s);
9994 uint64_t round_const;
9997 if (extract32(immh, 3, 1) && !is_q) {
9998 unallocated_encoding(s);
10001 tcg_debug_assert(size <= 3);
10003 if (!fp_access_check(s)) {
10008 case 0x02: /* SSRA / USRA (accumulate) */
10010 /* Shift count same as element size produces zero to add. */
10011 if (shift == 8 << size) {
10014 gen_gvec_op2i(s, is_q, rd, rn, shift, &usra_op[size]);
10016 /* Shift count same as element size produces all sign to add. */
10017 if (shift == 8 << size) {
10020 gen_gvec_op2i(s, is_q, rd, rn, shift, &ssra_op[size]);
10023 case 0x08: /* SRI */
10024 /* Shift count same as element size is valid but does nothing. */
10025 if (shift == 8 << size) {
10028 gen_gvec_op2i(s, is_q, rd, rn, shift, &sri_op[size]);
10031 case 0x00: /* SSHR / USHR */
10033 if (shift == 8 << size) {
10034 /* Shift count the same size as element size produces zero. */
10035 tcg_gen_gvec_dup8i(vec_full_reg_offset(s, rd),
10036 is_q ? 16 : 8, vec_full_reg_size(s), 0);
10038 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_shri, size);
10041 /* Shift count the same size as element size produces all sign. */
10042 if (shift == 8 << size) {
10045 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_sari, size);
10049 case 0x04: /* SRSHR / URSHR (rounding) */
10051 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10055 g_assert_not_reached();
10058 round_const = 1ULL << (shift - 1);
10059 tcg_round = tcg_const_i64(round_const);
10061 for (i = 0; i < elements; i++) {
10062 read_vec_element(s, tcg_rn, rn, i, memop);
10064 read_vec_element(s, tcg_rd, rd, i, memop);
10067 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
10068 accumulate, is_u, size, shift);
10070 write_vec_element(s, tcg_rd, rd, i, size);
10072 tcg_temp_free_i64(tcg_round);
10075 clear_vec_high(s, is_q, rd);
10078 /* SHL/SLI - Vector shift left */
10079 static void handle_vec_simd_shli(DisasContext *s, bool is_q, bool insert,
10080 int immh, int immb, int opcode, int rn, int rd)
10082 int size = 32 - clz32(immh) - 1;
10083 int immhb = immh << 3 | immb;
10084 int shift = immhb - (8 << size);
10086 /* Range of size is limited by decode: immh is a non-zero 4 bit field */
10087 assert(size >= 0 && size <= 3);
10089 if (extract32(immh, 3, 1) && !is_q) {
10090 unallocated_encoding(s);
10094 if (!fp_access_check(s)) {
10099 gen_gvec_op2i(s, is_q, rd, rn, shift, &sli_op[size]);
10101 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_shli, size);
10105 /* USHLL/SHLL - Vector shift left with widening */
10106 static void handle_vec_simd_wshli(DisasContext *s, bool is_q, bool is_u,
10107 int immh, int immb, int opcode, int rn, int rd)
10109 int size = 32 - clz32(immh) - 1;
10110 int immhb = immh << 3 | immb;
10111 int shift = immhb - (8 << size);
10113 int esize = 8 << size;
10114 int elements = dsize/esize;
10115 TCGv_i64 tcg_rn = new_tmp_a64(s);
10116 TCGv_i64 tcg_rd = new_tmp_a64(s);
10120 unallocated_encoding(s);
10124 if (!fp_access_check(s)) {
10128 /* For the LL variants the store is larger than the load,
10129 * so if rd == rn we would overwrite parts of our input.
10130 * So load everything right now and use shifts in the main loop.
10132 read_vec_element(s, tcg_rn, rn, is_q ? 1 : 0, MO_64);
10134 for (i = 0; i < elements; i++) {
10135 tcg_gen_shri_i64(tcg_rd, tcg_rn, i * esize);
10136 ext_and_shift_reg(tcg_rd, tcg_rd, size | (!is_u << 2), 0);
10137 tcg_gen_shli_i64(tcg_rd, tcg_rd, shift);
10138 write_vec_element(s, tcg_rd, rd, i, size + 1);
10142 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
10143 static void handle_vec_simd_shrn(DisasContext *s, bool is_q,
10144 int immh, int immb, int opcode, int rn, int rd)
10146 int immhb = immh << 3 | immb;
10147 int size = 32 - clz32(immh) - 1;
10149 int esize = 8 << size;
10150 int elements = dsize/esize;
10151 int shift = (2 * esize) - immhb;
10152 bool round = extract32(opcode, 0, 1);
10153 TCGv_i64 tcg_rn, tcg_rd, tcg_final;
10154 TCGv_i64 tcg_round;
10157 if (extract32(immh, 3, 1)) {
10158 unallocated_encoding(s);
10162 if (!fp_access_check(s)) {
10166 tcg_rn = tcg_temp_new_i64();
10167 tcg_rd = tcg_temp_new_i64();
10168 tcg_final = tcg_temp_new_i64();
10169 read_vec_element(s, tcg_final, rd, is_q ? 1 : 0, MO_64);
10172 uint64_t round_const = 1ULL << (shift - 1);
10173 tcg_round = tcg_const_i64(round_const);
10178 for (i = 0; i < elements; i++) {
10179 read_vec_element(s, tcg_rn, rn, i, size+1);
10180 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
10181 false, true, size+1, shift);
10183 tcg_gen_deposit_i64(tcg_final, tcg_final, tcg_rd, esize * i, esize);
10187 write_vec_element(s, tcg_final, rd, 0, MO_64);
10189 write_vec_element(s, tcg_final, rd, 1, MO_64);
10192 tcg_temp_free_i64(tcg_round);
10194 tcg_temp_free_i64(tcg_rn);
10195 tcg_temp_free_i64(tcg_rd);
10196 tcg_temp_free_i64(tcg_final);
10198 clear_vec_high(s, is_q, rd);
10202 /* AdvSIMD shift by immediate
10203 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
10204 * +---+---+---+-------------+------+------+--------+---+------+------+
10205 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
10206 * +---+---+---+-------------+------+------+--------+---+------+------+
10208 static void disas_simd_shift_imm(DisasContext *s, uint32_t insn)
10210 int rd = extract32(insn, 0, 5);
10211 int rn = extract32(insn, 5, 5);
10212 int opcode = extract32(insn, 11, 5);
10213 int immb = extract32(insn, 16, 3);
10214 int immh = extract32(insn, 19, 4);
10215 bool is_u = extract32(insn, 29, 1);
10216 bool is_q = extract32(insn, 30, 1);
10219 case 0x08: /* SRI */
10221 unallocated_encoding(s);
10225 case 0x00: /* SSHR / USHR */
10226 case 0x02: /* SSRA / USRA (accumulate) */
10227 case 0x04: /* SRSHR / URSHR (rounding) */
10228 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10229 handle_vec_simd_shri(s, is_q, is_u, immh, immb, opcode, rn, rd);
10231 case 0x0a: /* SHL / SLI */
10232 handle_vec_simd_shli(s, is_q, is_u, immh, immb, opcode, rn, rd);
10234 case 0x10: /* SHRN */
10235 case 0x11: /* RSHRN / SQRSHRUN */
10237 handle_vec_simd_sqshrn(s, false, is_q, false, true, immh, immb,
10240 handle_vec_simd_shrn(s, is_q, immh, immb, opcode, rn, rd);
10243 case 0x12: /* SQSHRN / UQSHRN */
10244 case 0x13: /* SQRSHRN / UQRSHRN */
10245 handle_vec_simd_sqshrn(s, false, is_q, is_u, is_u, immh, immb,
10248 case 0x14: /* SSHLL / USHLL */
10249 handle_vec_simd_wshli(s, is_q, is_u, immh, immb, opcode, rn, rd);
10251 case 0x1c: /* SCVTF / UCVTF */
10252 handle_simd_shift_intfp_conv(s, false, is_q, is_u, immh, immb,
10255 case 0xc: /* SQSHLU */
10257 unallocated_encoding(s);
10260 handle_simd_qshl(s, false, is_q, false, true, immh, immb, rn, rd);
10262 case 0xe: /* SQSHL, UQSHL */
10263 handle_simd_qshl(s, false, is_q, is_u, is_u, immh, immb, rn, rd);
10265 case 0x1f: /* FCVTZS/ FCVTZU */
10266 handle_simd_shift_fpint_conv(s, false, is_q, is_u, immh, immb, rn, rd);
10269 unallocated_encoding(s);
10274 /* Generate code to do a "long" addition or subtraction, ie one done in
10275 * TCGv_i64 on vector lanes twice the width specified by size.
10277 static void gen_neon_addl(int size, bool is_sub, TCGv_i64 tcg_res,
10278 TCGv_i64 tcg_op1, TCGv_i64 tcg_op2)
10280 static NeonGenTwo64OpFn * const fns[3][2] = {
10281 { gen_helper_neon_addl_u16, gen_helper_neon_subl_u16 },
10282 { gen_helper_neon_addl_u32, gen_helper_neon_subl_u32 },
10283 { tcg_gen_add_i64, tcg_gen_sub_i64 },
10285 NeonGenTwo64OpFn *genfn;
10288 genfn = fns[size][is_sub];
10289 genfn(tcg_res, tcg_op1, tcg_op2);
10292 static void handle_3rd_widening(DisasContext *s, int is_q, int is_u, int size,
10293 int opcode, int rd, int rn, int rm)
10295 /* 3-reg-different widening insns: 64 x 64 -> 128 */
10296 TCGv_i64 tcg_res[2];
10299 tcg_res[0] = tcg_temp_new_i64();
10300 tcg_res[1] = tcg_temp_new_i64();
10302 /* Does this op do an adding accumulate, a subtracting accumulate,
10303 * or no accumulate at all?
10321 read_vec_element(s, tcg_res[0], rd, 0, MO_64);
10322 read_vec_element(s, tcg_res[1], rd, 1, MO_64);
10325 /* size == 2 means two 32x32->64 operations; this is worth special
10326 * casing because we can generally handle it inline.
10329 for (pass = 0; pass < 2; pass++) {
10330 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10331 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10332 TCGv_i64 tcg_passres;
10333 TCGMemOp memop = MO_32 | (is_u ? 0 : MO_SIGN);
10335 int elt = pass + is_q * 2;
10337 read_vec_element(s, tcg_op1, rn, elt, memop);
10338 read_vec_element(s, tcg_op2, rm, elt, memop);
10341 tcg_passres = tcg_res[pass];
10343 tcg_passres = tcg_temp_new_i64();
10347 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10348 tcg_gen_add_i64(tcg_passres, tcg_op1, tcg_op2);
10350 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10351 tcg_gen_sub_i64(tcg_passres, tcg_op1, tcg_op2);
10353 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10354 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10356 TCGv_i64 tcg_tmp1 = tcg_temp_new_i64();
10357 TCGv_i64 tcg_tmp2 = tcg_temp_new_i64();
10359 tcg_gen_sub_i64(tcg_tmp1, tcg_op1, tcg_op2);
10360 tcg_gen_sub_i64(tcg_tmp2, tcg_op2, tcg_op1);
10361 tcg_gen_movcond_i64(is_u ? TCG_COND_GEU : TCG_COND_GE,
10363 tcg_op1, tcg_op2, tcg_tmp1, tcg_tmp2);
10364 tcg_temp_free_i64(tcg_tmp1);
10365 tcg_temp_free_i64(tcg_tmp2);
10368 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10369 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10370 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10371 tcg_gen_mul_i64(tcg_passres, tcg_op1, tcg_op2);
10373 case 9: /* SQDMLAL, SQDMLAL2 */
10374 case 11: /* SQDMLSL, SQDMLSL2 */
10375 case 13: /* SQDMULL, SQDMULL2 */
10376 tcg_gen_mul_i64(tcg_passres, tcg_op1, tcg_op2);
10377 gen_helper_neon_addl_saturate_s64(tcg_passres, cpu_env,
10378 tcg_passres, tcg_passres);
10381 g_assert_not_reached();
10384 if (opcode == 9 || opcode == 11) {
10385 /* saturating accumulate ops */
10387 tcg_gen_neg_i64(tcg_passres, tcg_passres);
10389 gen_helper_neon_addl_saturate_s64(tcg_res[pass], cpu_env,
10390 tcg_res[pass], tcg_passres);
10391 } else if (accop > 0) {
10392 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
10393 } else if (accop < 0) {
10394 tcg_gen_sub_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
10398 tcg_temp_free_i64(tcg_passres);
10401 tcg_temp_free_i64(tcg_op1);
10402 tcg_temp_free_i64(tcg_op2);
10405 /* size 0 or 1, generally helper functions */
10406 for (pass = 0; pass < 2; pass++) {
10407 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
10408 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10409 TCGv_i64 tcg_passres;
10410 int elt = pass + is_q * 2;
10412 read_vec_element_i32(s, tcg_op1, rn, elt, MO_32);
10413 read_vec_element_i32(s, tcg_op2, rm, elt, MO_32);
10416 tcg_passres = tcg_res[pass];
10418 tcg_passres = tcg_temp_new_i64();
10422 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10423 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10425 TCGv_i64 tcg_op2_64 = tcg_temp_new_i64();
10426 static NeonGenWidenFn * const widenfns[2][2] = {
10427 { gen_helper_neon_widen_s8, gen_helper_neon_widen_u8 },
10428 { gen_helper_neon_widen_s16, gen_helper_neon_widen_u16 },
10430 NeonGenWidenFn *widenfn = widenfns[size][is_u];
10432 widenfn(tcg_op2_64, tcg_op2);
10433 widenfn(tcg_passres, tcg_op1);
10434 gen_neon_addl(size, (opcode == 2), tcg_passres,
10435 tcg_passres, tcg_op2_64);
10436 tcg_temp_free_i64(tcg_op2_64);
10439 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10440 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10443 gen_helper_neon_abdl_u16(tcg_passres, tcg_op1, tcg_op2);
10445 gen_helper_neon_abdl_s16(tcg_passres, tcg_op1, tcg_op2);
10449 gen_helper_neon_abdl_u32(tcg_passres, tcg_op1, tcg_op2);
10451 gen_helper_neon_abdl_s32(tcg_passres, tcg_op1, tcg_op2);
10455 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10456 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10457 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10460 gen_helper_neon_mull_u8(tcg_passres, tcg_op1, tcg_op2);
10462 gen_helper_neon_mull_s8(tcg_passres, tcg_op1, tcg_op2);
10466 gen_helper_neon_mull_u16(tcg_passres, tcg_op1, tcg_op2);
10468 gen_helper_neon_mull_s16(tcg_passres, tcg_op1, tcg_op2);
10472 case 9: /* SQDMLAL, SQDMLAL2 */
10473 case 11: /* SQDMLSL, SQDMLSL2 */
10474 case 13: /* SQDMULL, SQDMULL2 */
10476 gen_helper_neon_mull_s16(tcg_passres, tcg_op1, tcg_op2);
10477 gen_helper_neon_addl_saturate_s32(tcg_passres, cpu_env,
10478 tcg_passres, tcg_passres);
10480 case 14: /* PMULL */
10482 gen_helper_neon_mull_p8(tcg_passres, tcg_op1, tcg_op2);
10485 g_assert_not_reached();
10487 tcg_temp_free_i32(tcg_op1);
10488 tcg_temp_free_i32(tcg_op2);
10491 if (opcode == 9 || opcode == 11) {
10492 /* saturating accumulate ops */
10494 gen_helper_neon_negl_u32(tcg_passres, tcg_passres);
10496 gen_helper_neon_addl_saturate_s32(tcg_res[pass], cpu_env,
10500 gen_neon_addl(size, (accop < 0), tcg_res[pass],
10501 tcg_res[pass], tcg_passres);
10503 tcg_temp_free_i64(tcg_passres);
10508 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
10509 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
10510 tcg_temp_free_i64(tcg_res[0]);
10511 tcg_temp_free_i64(tcg_res[1]);
10514 static void handle_3rd_wide(DisasContext *s, int is_q, int is_u, int size,
10515 int opcode, int rd, int rn, int rm)
10517 TCGv_i64 tcg_res[2];
10518 int part = is_q ? 2 : 0;
10521 for (pass = 0; pass < 2; pass++) {
10522 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10523 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10524 TCGv_i64 tcg_op2_wide = tcg_temp_new_i64();
10525 static NeonGenWidenFn * const widenfns[3][2] = {
10526 { gen_helper_neon_widen_s8, gen_helper_neon_widen_u8 },
10527 { gen_helper_neon_widen_s16, gen_helper_neon_widen_u16 },
10528 { tcg_gen_ext_i32_i64, tcg_gen_extu_i32_i64 },
10530 NeonGenWidenFn *widenfn = widenfns[size][is_u];
10532 read_vec_element(s, tcg_op1, rn, pass, MO_64);
10533 read_vec_element_i32(s, tcg_op2, rm, part + pass, MO_32);
10534 widenfn(tcg_op2_wide, tcg_op2);
10535 tcg_temp_free_i32(tcg_op2);
10536 tcg_res[pass] = tcg_temp_new_i64();
10537 gen_neon_addl(size, (opcode == 3),
10538 tcg_res[pass], tcg_op1, tcg_op2_wide);
10539 tcg_temp_free_i64(tcg_op1);
10540 tcg_temp_free_i64(tcg_op2_wide);
10543 for (pass = 0; pass < 2; pass++) {
10544 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
10545 tcg_temp_free_i64(tcg_res[pass]);
10549 static void do_narrow_round_high_u32(TCGv_i32 res, TCGv_i64 in)
10551 tcg_gen_addi_i64(in, in, 1U << 31);
10552 tcg_gen_extrh_i64_i32(res, in);
10555 static void handle_3rd_narrowing(DisasContext *s, int is_q, int is_u, int size,
10556 int opcode, int rd, int rn, int rm)
10558 TCGv_i32 tcg_res[2];
10559 int part = is_q ? 2 : 0;
10562 for (pass = 0; pass < 2; pass++) {
10563 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10564 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10565 TCGv_i64 tcg_wideres = tcg_temp_new_i64();
10566 static NeonGenNarrowFn * const narrowfns[3][2] = {
10567 { gen_helper_neon_narrow_high_u8,
10568 gen_helper_neon_narrow_round_high_u8 },
10569 { gen_helper_neon_narrow_high_u16,
10570 gen_helper_neon_narrow_round_high_u16 },
10571 { tcg_gen_extrh_i64_i32, do_narrow_round_high_u32 },
10573 NeonGenNarrowFn *gennarrow = narrowfns[size][is_u];
10575 read_vec_element(s, tcg_op1, rn, pass, MO_64);
10576 read_vec_element(s, tcg_op2, rm, pass, MO_64);
10578 gen_neon_addl(size, (opcode == 6), tcg_wideres, tcg_op1, tcg_op2);
10580 tcg_temp_free_i64(tcg_op1);
10581 tcg_temp_free_i64(tcg_op2);
10583 tcg_res[pass] = tcg_temp_new_i32();
10584 gennarrow(tcg_res[pass], tcg_wideres);
10585 tcg_temp_free_i64(tcg_wideres);
10588 for (pass = 0; pass < 2; pass++) {
10589 write_vec_element_i32(s, tcg_res[pass], rd, pass + part, MO_32);
10590 tcg_temp_free_i32(tcg_res[pass]);
10592 clear_vec_high(s, is_q, rd);
10595 static void handle_pmull_64(DisasContext *s, int is_q, int rd, int rn, int rm)
10597 /* PMULL of 64 x 64 -> 128 is an odd special case because it
10598 * is the only three-reg-diff instruction which produces a
10599 * 128-bit wide result from a single operation. However since
10600 * it's possible to calculate the two halves more or less
10601 * separately we just use two helper calls.
10603 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10604 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10605 TCGv_i64 tcg_res = tcg_temp_new_i64();
10607 read_vec_element(s, tcg_op1, rn, is_q, MO_64);
10608 read_vec_element(s, tcg_op2, rm, is_q, MO_64);
10609 gen_helper_neon_pmull_64_lo(tcg_res, tcg_op1, tcg_op2);
10610 write_vec_element(s, tcg_res, rd, 0, MO_64);
10611 gen_helper_neon_pmull_64_hi(tcg_res, tcg_op1, tcg_op2);
10612 write_vec_element(s, tcg_res, rd, 1, MO_64);
10614 tcg_temp_free_i64(tcg_op1);
10615 tcg_temp_free_i64(tcg_op2);
10616 tcg_temp_free_i64(tcg_res);
10619 /* AdvSIMD three different
10620 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
10621 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10622 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
10623 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10625 static void disas_simd_three_reg_diff(DisasContext *s, uint32_t insn)
10627 /* Instructions in this group fall into three basic classes
10628 * (in each case with the operation working on each element in
10629 * the input vectors):
10630 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
10632 * (2) wide 64 x 128 -> 128
10633 * (3) narrowing 128 x 128 -> 64
10634 * Here we do initial decode, catch unallocated cases and
10635 * dispatch to separate functions for each class.
10637 int is_q = extract32(insn, 30, 1);
10638 int is_u = extract32(insn, 29, 1);
10639 int size = extract32(insn, 22, 2);
10640 int opcode = extract32(insn, 12, 4);
10641 int rm = extract32(insn, 16, 5);
10642 int rn = extract32(insn, 5, 5);
10643 int rd = extract32(insn, 0, 5);
10646 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
10647 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
10648 /* 64 x 128 -> 128 */
10650 unallocated_encoding(s);
10653 if (!fp_access_check(s)) {
10656 handle_3rd_wide(s, is_q, is_u, size, opcode, rd, rn, rm);
10658 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
10659 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
10660 /* 128 x 128 -> 64 */
10662 unallocated_encoding(s);
10665 if (!fp_access_check(s)) {
10668 handle_3rd_narrowing(s, is_q, is_u, size, opcode, rd, rn, rm);
10670 case 14: /* PMULL, PMULL2 */
10671 if (is_u || size == 1 || size == 2) {
10672 unallocated_encoding(s);
10676 if (!dc_isar_feature(aa64_pmull, s)) {
10677 unallocated_encoding(s);
10680 if (!fp_access_check(s)) {
10683 handle_pmull_64(s, is_q, rd, rn, rm);
10687 case 9: /* SQDMLAL, SQDMLAL2 */
10688 case 11: /* SQDMLSL, SQDMLSL2 */
10689 case 13: /* SQDMULL, SQDMULL2 */
10690 if (is_u || size == 0) {
10691 unallocated_encoding(s);
10695 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10696 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10697 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10698 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10699 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10700 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10701 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
10702 /* 64 x 64 -> 128 */
10704 unallocated_encoding(s);
10708 if (!fp_access_check(s)) {
10712 handle_3rd_widening(s, is_q, is_u, size, opcode, rd, rn, rm);
10715 /* opcode 15 not allocated */
10716 unallocated_encoding(s);
10721 /* Logic op (opcode == 3) subgroup of C3.6.16. */
10722 static void disas_simd_3same_logic(DisasContext *s, uint32_t insn)
10724 int rd = extract32(insn, 0, 5);
10725 int rn = extract32(insn, 5, 5);
10726 int rm = extract32(insn, 16, 5);
10727 int size = extract32(insn, 22, 2);
10728 bool is_u = extract32(insn, 29, 1);
10729 bool is_q = extract32(insn, 30, 1);
10731 if (!fp_access_check(s)) {
10735 switch (size + 4 * is_u) {
10737 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_and, 0);
10740 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_andc, 0);
10743 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_or, 0);
10746 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_orc, 0);
10749 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_xor, 0);
10752 case 5: /* BSL bitwise select */
10753 gen_gvec_fn4(s, is_q, rd, rd, rn, rm, tcg_gen_gvec_bitsel, 0);
10755 case 6: /* BIT, bitwise insert if true */
10756 gen_gvec_fn4(s, is_q, rd, rm, rn, rd, tcg_gen_gvec_bitsel, 0);
10758 case 7: /* BIF, bitwise insert if false */
10759 gen_gvec_fn4(s, is_q, rd, rm, rd, rn, tcg_gen_gvec_bitsel, 0);
10763 g_assert_not_reached();
10767 /* Pairwise op subgroup of C3.6.16.
10769 * This is called directly or via the handle_3same_float for float pairwise
10770 * operations where the opcode and size are calculated differently.
10772 static void handle_simd_3same_pair(DisasContext *s, int is_q, int u, int opcode,
10773 int size, int rn, int rm, int rd)
10778 /* Floating point operations need fpst */
10779 if (opcode >= 0x58) {
10780 fpst = get_fpstatus_ptr(false);
10785 if (!fp_access_check(s)) {
10789 /* These operations work on the concatenated rm:rn, with each pair of
10790 * adjacent elements being operated on to produce an element in the result.
10793 TCGv_i64 tcg_res[2];
10795 for (pass = 0; pass < 2; pass++) {
10796 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10797 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10798 int passreg = (pass == 0) ? rn : rm;
10800 read_vec_element(s, tcg_op1, passreg, 0, MO_64);
10801 read_vec_element(s, tcg_op2, passreg, 1, MO_64);
10802 tcg_res[pass] = tcg_temp_new_i64();
10805 case 0x17: /* ADDP */
10806 tcg_gen_add_i64(tcg_res[pass], tcg_op1, tcg_op2);
10808 case 0x58: /* FMAXNMP */
10809 gen_helper_vfp_maxnumd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10811 case 0x5a: /* FADDP */
10812 gen_helper_vfp_addd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10814 case 0x5e: /* FMAXP */
10815 gen_helper_vfp_maxd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10817 case 0x78: /* FMINNMP */
10818 gen_helper_vfp_minnumd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10820 case 0x7e: /* FMINP */
10821 gen_helper_vfp_mind(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10824 g_assert_not_reached();
10827 tcg_temp_free_i64(tcg_op1);
10828 tcg_temp_free_i64(tcg_op2);
10831 for (pass = 0; pass < 2; pass++) {
10832 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
10833 tcg_temp_free_i64(tcg_res[pass]);
10836 int maxpass = is_q ? 4 : 2;
10837 TCGv_i32 tcg_res[4];
10839 for (pass = 0; pass < maxpass; pass++) {
10840 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
10841 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10842 NeonGenTwoOpFn *genfn = NULL;
10843 int passreg = pass < (maxpass / 2) ? rn : rm;
10844 int passelt = (is_q && (pass & 1)) ? 2 : 0;
10846 read_vec_element_i32(s, tcg_op1, passreg, passelt, MO_32);
10847 read_vec_element_i32(s, tcg_op2, passreg, passelt + 1, MO_32);
10848 tcg_res[pass] = tcg_temp_new_i32();
10851 case 0x17: /* ADDP */
10853 static NeonGenTwoOpFn * const fns[3] = {
10854 gen_helper_neon_padd_u8,
10855 gen_helper_neon_padd_u16,
10861 case 0x14: /* SMAXP, UMAXP */
10863 static NeonGenTwoOpFn * const fns[3][2] = {
10864 { gen_helper_neon_pmax_s8, gen_helper_neon_pmax_u8 },
10865 { gen_helper_neon_pmax_s16, gen_helper_neon_pmax_u16 },
10866 { tcg_gen_smax_i32, tcg_gen_umax_i32 },
10868 genfn = fns[size][u];
10871 case 0x15: /* SMINP, UMINP */
10873 static NeonGenTwoOpFn * const fns[3][2] = {
10874 { gen_helper_neon_pmin_s8, gen_helper_neon_pmin_u8 },
10875 { gen_helper_neon_pmin_s16, gen_helper_neon_pmin_u16 },
10876 { tcg_gen_smin_i32, tcg_gen_umin_i32 },
10878 genfn = fns[size][u];
10881 /* The FP operations are all on single floats (32 bit) */
10882 case 0x58: /* FMAXNMP */
10883 gen_helper_vfp_maxnums(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10885 case 0x5a: /* FADDP */
10886 gen_helper_vfp_adds(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10888 case 0x5e: /* FMAXP */
10889 gen_helper_vfp_maxs(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10891 case 0x78: /* FMINNMP */
10892 gen_helper_vfp_minnums(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10894 case 0x7e: /* FMINP */
10895 gen_helper_vfp_mins(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10898 g_assert_not_reached();
10901 /* FP ops called directly, otherwise call now */
10903 genfn(tcg_res[pass], tcg_op1, tcg_op2);
10906 tcg_temp_free_i32(tcg_op1);
10907 tcg_temp_free_i32(tcg_op2);
10910 for (pass = 0; pass < maxpass; pass++) {
10911 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32);
10912 tcg_temp_free_i32(tcg_res[pass]);
10914 clear_vec_high(s, is_q, rd);
10918 tcg_temp_free_ptr(fpst);
10922 /* Floating point op subgroup of C3.6.16. */
10923 static void disas_simd_3same_float(DisasContext *s, uint32_t insn)
10925 /* For floating point ops, the U, size[1] and opcode bits
10926 * together indicate the operation. size[0] indicates single
10929 int fpopcode = extract32(insn, 11, 5)
10930 | (extract32(insn, 23, 1) << 5)
10931 | (extract32(insn, 29, 1) << 6);
10932 int is_q = extract32(insn, 30, 1);
10933 int size = extract32(insn, 22, 1);
10934 int rm = extract32(insn, 16, 5);
10935 int rn = extract32(insn, 5, 5);
10936 int rd = extract32(insn, 0, 5);
10938 int datasize = is_q ? 128 : 64;
10939 int esize = 32 << size;
10940 int elements = datasize / esize;
10942 if (size == 1 && !is_q) {
10943 unallocated_encoding(s);
10947 switch (fpopcode) {
10948 case 0x58: /* FMAXNMP */
10949 case 0x5a: /* FADDP */
10950 case 0x5e: /* FMAXP */
10951 case 0x78: /* FMINNMP */
10952 case 0x7e: /* FMINP */
10953 if (size && !is_q) {
10954 unallocated_encoding(s);
10957 handle_simd_3same_pair(s, is_q, 0, fpopcode, size ? MO_64 : MO_32,
10960 case 0x1b: /* FMULX */
10961 case 0x1f: /* FRECPS */
10962 case 0x3f: /* FRSQRTS */
10963 case 0x5d: /* FACGE */
10964 case 0x7d: /* FACGT */
10965 case 0x19: /* FMLA */
10966 case 0x39: /* FMLS */
10967 case 0x18: /* FMAXNM */
10968 case 0x1a: /* FADD */
10969 case 0x1c: /* FCMEQ */
10970 case 0x1e: /* FMAX */
10971 case 0x38: /* FMINNM */
10972 case 0x3a: /* FSUB */
10973 case 0x3e: /* FMIN */
10974 case 0x5b: /* FMUL */
10975 case 0x5c: /* FCMGE */
10976 case 0x5f: /* FDIV */
10977 case 0x7a: /* FABD */
10978 case 0x7c: /* FCMGT */
10979 if (!fp_access_check(s)) {
10982 handle_3same_float(s, size, elements, fpopcode, rd, rn, rm);
10985 case 0x1d: /* FMLAL */
10986 case 0x3d: /* FMLSL */
10987 case 0x59: /* FMLAL2 */
10988 case 0x79: /* FMLSL2 */
10989 if (size & 1 || !dc_isar_feature(aa64_fhm, s)) {
10990 unallocated_encoding(s);
10993 if (fp_access_check(s)) {
10994 int is_s = extract32(insn, 23, 1);
10995 int is_2 = extract32(insn, 29, 1);
10996 int data = (is_2 << 1) | is_s;
10997 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
10998 vec_full_reg_offset(s, rn),
10999 vec_full_reg_offset(s, rm), cpu_env,
11000 is_q ? 16 : 8, vec_full_reg_size(s),
11001 data, gen_helper_gvec_fmlal_a64);
11006 unallocated_encoding(s);
11011 /* Integer op subgroup of C3.6.16. */
11012 static void disas_simd_3same_int(DisasContext *s, uint32_t insn)
11014 int is_q = extract32(insn, 30, 1);
11015 int u = extract32(insn, 29, 1);
11016 int size = extract32(insn, 22, 2);
11017 int opcode = extract32(insn, 11, 5);
11018 int rm = extract32(insn, 16, 5);
11019 int rn = extract32(insn, 5, 5);
11020 int rd = extract32(insn, 0, 5);
11025 case 0x13: /* MUL, PMUL */
11026 if (u && size != 0) {
11027 unallocated_encoding(s);
11031 case 0x0: /* SHADD, UHADD */
11032 case 0x2: /* SRHADD, URHADD */
11033 case 0x4: /* SHSUB, UHSUB */
11034 case 0xc: /* SMAX, UMAX */
11035 case 0xd: /* SMIN, UMIN */
11036 case 0xe: /* SABD, UABD */
11037 case 0xf: /* SABA, UABA */
11038 case 0x12: /* MLA, MLS */
11040 unallocated_encoding(s);
11044 case 0x16: /* SQDMULH, SQRDMULH */
11045 if (size == 0 || size == 3) {
11046 unallocated_encoding(s);
11051 if (size == 3 && !is_q) {
11052 unallocated_encoding(s);
11058 if (!fp_access_check(s)) {
11063 case 0x01: /* SQADD, UQADD */
11064 tcg_gen_gvec_4(vec_full_reg_offset(s, rd),
11065 offsetof(CPUARMState, vfp.qc),
11066 vec_full_reg_offset(s, rn),
11067 vec_full_reg_offset(s, rm),
11068 is_q ? 16 : 8, vec_full_reg_size(s),
11069 (u ? uqadd_op : sqadd_op) + size);
11071 case 0x05: /* SQSUB, UQSUB */
11072 tcg_gen_gvec_4(vec_full_reg_offset(s, rd),
11073 offsetof(CPUARMState, vfp.qc),
11074 vec_full_reg_offset(s, rn),
11075 vec_full_reg_offset(s, rm),
11076 is_q ? 16 : 8, vec_full_reg_size(s),
11077 (u ? uqsub_op : sqsub_op) + size);
11079 case 0x0c: /* SMAX, UMAX */
11081 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_umax, size);
11083 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_smax, size);
11086 case 0x0d: /* SMIN, UMIN */
11088 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_umin, size);
11090 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_smin, size);
11093 case 0x10: /* ADD, SUB */
11095 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_sub, size);
11097 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_add, size);
11100 case 0x13: /* MUL, PMUL */
11101 if (!u) { /* MUL */
11102 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_mul, size);
11106 case 0x12: /* MLA, MLS */
11108 gen_gvec_op3(s, is_q, rd, rn, rm, &mls_op[size]);
11110 gen_gvec_op3(s, is_q, rd, rn, rm, &mla_op[size]);
11114 if (!u) { /* CMTST */
11115 gen_gvec_op3(s, is_q, rd, rn, rm, &cmtst_op[size]);
11119 cond = TCG_COND_EQ;
11121 case 0x06: /* CMGT, CMHI */
11122 cond = u ? TCG_COND_GTU : TCG_COND_GT;
11124 case 0x07: /* CMGE, CMHS */
11125 cond = u ? TCG_COND_GEU : TCG_COND_GE;
11127 tcg_gen_gvec_cmp(cond, size, vec_full_reg_offset(s, rd),
11128 vec_full_reg_offset(s, rn),
11129 vec_full_reg_offset(s, rm),
11130 is_q ? 16 : 8, vec_full_reg_size(s));
11136 for (pass = 0; pass < 2; pass++) {
11137 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
11138 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
11139 TCGv_i64 tcg_res = tcg_temp_new_i64();
11141 read_vec_element(s, tcg_op1, rn, pass, MO_64);
11142 read_vec_element(s, tcg_op2, rm, pass, MO_64);
11144 handle_3same_64(s, opcode, u, tcg_res, tcg_op1, tcg_op2);
11146 write_vec_element(s, tcg_res, rd, pass, MO_64);
11148 tcg_temp_free_i64(tcg_res);
11149 tcg_temp_free_i64(tcg_op1);
11150 tcg_temp_free_i64(tcg_op2);
11153 for (pass = 0; pass < (is_q ? 4 : 2); pass++) {
11154 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
11155 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
11156 TCGv_i32 tcg_res = tcg_temp_new_i32();
11157 NeonGenTwoOpFn *genfn = NULL;
11158 NeonGenTwoOpEnvFn *genenvfn = NULL;
11160 read_vec_element_i32(s, tcg_op1, rn, pass, MO_32);
11161 read_vec_element_i32(s, tcg_op2, rm, pass, MO_32);
11164 case 0x0: /* SHADD, UHADD */
11166 static NeonGenTwoOpFn * const fns[3][2] = {
11167 { gen_helper_neon_hadd_s8, gen_helper_neon_hadd_u8 },
11168 { gen_helper_neon_hadd_s16, gen_helper_neon_hadd_u16 },
11169 { gen_helper_neon_hadd_s32, gen_helper_neon_hadd_u32 },
11171 genfn = fns[size][u];
11174 case 0x2: /* SRHADD, URHADD */
11176 static NeonGenTwoOpFn * const fns[3][2] = {
11177 { gen_helper_neon_rhadd_s8, gen_helper_neon_rhadd_u8 },
11178 { gen_helper_neon_rhadd_s16, gen_helper_neon_rhadd_u16 },
11179 { gen_helper_neon_rhadd_s32, gen_helper_neon_rhadd_u32 },
11181 genfn = fns[size][u];
11184 case 0x4: /* SHSUB, UHSUB */
11186 static NeonGenTwoOpFn * const fns[3][2] = {
11187 { gen_helper_neon_hsub_s8, gen_helper_neon_hsub_u8 },
11188 { gen_helper_neon_hsub_s16, gen_helper_neon_hsub_u16 },
11189 { gen_helper_neon_hsub_s32, gen_helper_neon_hsub_u32 },
11191 genfn = fns[size][u];
11194 case 0x8: /* SSHL, USHL */
11196 static NeonGenTwoOpFn * const fns[3][2] = {
11197 { gen_helper_neon_shl_s8, gen_helper_neon_shl_u8 },
11198 { gen_helper_neon_shl_s16, gen_helper_neon_shl_u16 },
11199 { gen_helper_neon_shl_s32, gen_helper_neon_shl_u32 },
11201 genfn = fns[size][u];
11204 case 0x9: /* SQSHL, UQSHL */
11206 static NeonGenTwoOpEnvFn * const fns[3][2] = {
11207 { gen_helper_neon_qshl_s8, gen_helper_neon_qshl_u8 },
11208 { gen_helper_neon_qshl_s16, gen_helper_neon_qshl_u16 },
11209 { gen_helper_neon_qshl_s32, gen_helper_neon_qshl_u32 },
11211 genenvfn = fns[size][u];
11214 case 0xa: /* SRSHL, URSHL */
11216 static NeonGenTwoOpFn * const fns[3][2] = {
11217 { gen_helper_neon_rshl_s8, gen_helper_neon_rshl_u8 },
11218 { gen_helper_neon_rshl_s16, gen_helper_neon_rshl_u16 },
11219 { gen_helper_neon_rshl_s32, gen_helper_neon_rshl_u32 },
11221 genfn = fns[size][u];
11224 case 0xb: /* SQRSHL, UQRSHL */
11226 static NeonGenTwoOpEnvFn * const fns[3][2] = {
11227 { gen_helper_neon_qrshl_s8, gen_helper_neon_qrshl_u8 },
11228 { gen_helper_neon_qrshl_s16, gen_helper_neon_qrshl_u16 },
11229 { gen_helper_neon_qrshl_s32, gen_helper_neon_qrshl_u32 },
11231 genenvfn = fns[size][u];
11234 case 0xe: /* SABD, UABD */
11235 case 0xf: /* SABA, UABA */
11237 static NeonGenTwoOpFn * const fns[3][2] = {
11238 { gen_helper_neon_abd_s8, gen_helper_neon_abd_u8 },
11239 { gen_helper_neon_abd_s16, gen_helper_neon_abd_u16 },
11240 { gen_helper_neon_abd_s32, gen_helper_neon_abd_u32 },
11242 genfn = fns[size][u];
11245 case 0x13: /* MUL, PMUL */
11246 assert(u); /* PMUL */
11248 genfn = gen_helper_neon_mul_p8;
11250 case 0x16: /* SQDMULH, SQRDMULH */
11252 static NeonGenTwoOpEnvFn * const fns[2][2] = {
11253 { gen_helper_neon_qdmulh_s16, gen_helper_neon_qrdmulh_s16 },
11254 { gen_helper_neon_qdmulh_s32, gen_helper_neon_qrdmulh_s32 },
11256 assert(size == 1 || size == 2);
11257 genenvfn = fns[size - 1][u];
11261 g_assert_not_reached();
11265 genenvfn(tcg_res, cpu_env, tcg_op1, tcg_op2);
11267 genfn(tcg_res, tcg_op1, tcg_op2);
11270 if (opcode == 0xf) {
11271 /* SABA, UABA: accumulating ops */
11272 static NeonGenTwoOpFn * const fns[3] = {
11273 gen_helper_neon_add_u8,
11274 gen_helper_neon_add_u16,
11278 read_vec_element_i32(s, tcg_op1, rd, pass, MO_32);
11279 fns[size](tcg_res, tcg_op1, tcg_res);
11282 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
11284 tcg_temp_free_i32(tcg_res);
11285 tcg_temp_free_i32(tcg_op1);
11286 tcg_temp_free_i32(tcg_op2);
11289 clear_vec_high(s, is_q, rd);
11292 /* AdvSIMD three same
11293 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11294 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11295 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11296 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11298 static void disas_simd_three_reg_same(DisasContext *s, uint32_t insn)
11300 int opcode = extract32(insn, 11, 5);
11303 case 0x3: /* logic ops */
11304 disas_simd_3same_logic(s, insn);
11306 case 0x17: /* ADDP */
11307 case 0x14: /* SMAXP, UMAXP */
11308 case 0x15: /* SMINP, UMINP */
11310 /* Pairwise operations */
11311 int is_q = extract32(insn, 30, 1);
11312 int u = extract32(insn, 29, 1);
11313 int size = extract32(insn, 22, 2);
11314 int rm = extract32(insn, 16, 5);
11315 int rn = extract32(insn, 5, 5);
11316 int rd = extract32(insn, 0, 5);
11317 if (opcode == 0x17) {
11318 if (u || (size == 3 && !is_q)) {
11319 unallocated_encoding(s);
11324 unallocated_encoding(s);
11328 handle_simd_3same_pair(s, is_q, u, opcode, size, rn, rm, rd);
11331 case 0x18 ... 0x31:
11332 /* floating point ops, sz[1] and U are part of opcode */
11333 disas_simd_3same_float(s, insn);
11336 disas_simd_3same_int(s, insn);
11342 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11344 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11345 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11346 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11347 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11349 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11350 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11353 static void disas_simd_three_reg_same_fp16(DisasContext *s, uint32_t insn)
11355 int opcode, fpopcode;
11356 int is_q, u, a, rm, rn, rd;
11357 int datasize, elements;
11360 bool pairwise = false;
11362 if (!dc_isar_feature(aa64_fp16, s)) {
11363 unallocated_encoding(s);
11367 if (!fp_access_check(s)) {
11371 /* For these floating point ops, the U, a and opcode bits
11372 * together indicate the operation.
11374 opcode = extract32(insn, 11, 3);
11375 u = extract32(insn, 29, 1);
11376 a = extract32(insn, 23, 1);
11377 is_q = extract32(insn, 30, 1);
11378 rm = extract32(insn, 16, 5);
11379 rn = extract32(insn, 5, 5);
11380 rd = extract32(insn, 0, 5);
11382 fpopcode = opcode | (a << 3) | (u << 4);
11383 datasize = is_q ? 128 : 64;
11384 elements = datasize / 16;
11386 switch (fpopcode) {
11387 case 0x10: /* FMAXNMP */
11388 case 0x12: /* FADDP */
11389 case 0x16: /* FMAXP */
11390 case 0x18: /* FMINNMP */
11391 case 0x1e: /* FMINP */
11396 fpst = get_fpstatus_ptr(true);
11399 int maxpass = is_q ? 8 : 4;
11400 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
11401 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
11402 TCGv_i32 tcg_res[8];
11404 for (pass = 0; pass < maxpass; pass++) {
11405 int passreg = pass < (maxpass / 2) ? rn : rm;
11406 int passelt = (pass << 1) & (maxpass - 1);
11408 read_vec_element_i32(s, tcg_op1, passreg, passelt, MO_16);
11409 read_vec_element_i32(s, tcg_op2, passreg, passelt + 1, MO_16);
11410 tcg_res[pass] = tcg_temp_new_i32();
11412 switch (fpopcode) {
11413 case 0x10: /* FMAXNMP */
11414 gen_helper_advsimd_maxnumh(tcg_res[pass], tcg_op1, tcg_op2,
11417 case 0x12: /* FADDP */
11418 gen_helper_advsimd_addh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11420 case 0x16: /* FMAXP */
11421 gen_helper_advsimd_maxh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11423 case 0x18: /* FMINNMP */
11424 gen_helper_advsimd_minnumh(tcg_res[pass], tcg_op1, tcg_op2,
11427 case 0x1e: /* FMINP */
11428 gen_helper_advsimd_minh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11431 g_assert_not_reached();
11435 for (pass = 0; pass < maxpass; pass++) {
11436 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_16);
11437 tcg_temp_free_i32(tcg_res[pass]);
11440 tcg_temp_free_i32(tcg_op1);
11441 tcg_temp_free_i32(tcg_op2);
11444 for (pass = 0; pass < elements; pass++) {
11445 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
11446 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
11447 TCGv_i32 tcg_res = tcg_temp_new_i32();
11449 read_vec_element_i32(s, tcg_op1, rn, pass, MO_16);
11450 read_vec_element_i32(s, tcg_op2, rm, pass, MO_16);
11452 switch (fpopcode) {
11453 case 0x0: /* FMAXNM */
11454 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
11456 case 0x1: /* FMLA */
11457 read_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11458 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_res,
11461 case 0x2: /* FADD */
11462 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
11464 case 0x3: /* FMULX */
11465 gen_helper_advsimd_mulxh(tcg_res, tcg_op1, tcg_op2, fpst);
11467 case 0x4: /* FCMEQ */
11468 gen_helper_advsimd_ceq_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11470 case 0x6: /* FMAX */
11471 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
11473 case 0x7: /* FRECPS */
11474 gen_helper_recpsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11476 case 0x8: /* FMINNM */
11477 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
11479 case 0x9: /* FMLS */
11480 /* As usual for ARM, separate negation for fused multiply-add */
11481 tcg_gen_xori_i32(tcg_op1, tcg_op1, 0x8000);
11482 read_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11483 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_res,
11486 case 0xa: /* FSUB */
11487 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
11489 case 0xe: /* FMIN */
11490 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
11492 case 0xf: /* FRSQRTS */
11493 gen_helper_rsqrtsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11495 case 0x13: /* FMUL */
11496 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
11498 case 0x14: /* FCMGE */
11499 gen_helper_advsimd_cge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11501 case 0x15: /* FACGE */
11502 gen_helper_advsimd_acge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11504 case 0x17: /* FDIV */
11505 gen_helper_advsimd_divh(tcg_res, tcg_op1, tcg_op2, fpst);
11507 case 0x1a: /* FABD */
11508 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
11509 tcg_gen_andi_i32(tcg_res, tcg_res, 0x7fff);
11511 case 0x1c: /* FCMGT */
11512 gen_helper_advsimd_cgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11514 case 0x1d: /* FACGT */
11515 gen_helper_advsimd_acgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11518 fprintf(stderr, "%s: insn %#04x, fpop %#2x @ %#" PRIx64 "\n",
11519 __func__, insn, fpopcode, s->pc_curr);
11520 g_assert_not_reached();
11523 write_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11524 tcg_temp_free_i32(tcg_res);
11525 tcg_temp_free_i32(tcg_op1);
11526 tcg_temp_free_i32(tcg_op2);
11530 tcg_temp_free_ptr(fpst);
11532 clear_vec_high(s, is_q, rd);
11535 /* AdvSIMD three same extra
11536 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
11537 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11538 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
11539 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11541 static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
11543 int rd = extract32(insn, 0, 5);
11544 int rn = extract32(insn, 5, 5);
11545 int opcode = extract32(insn, 11, 4);
11546 int rm = extract32(insn, 16, 5);
11547 int size = extract32(insn, 22, 2);
11548 bool u = extract32(insn, 29, 1);
11549 bool is_q = extract32(insn, 30, 1);
11553 switch (u * 16 + opcode) {
11554 case 0x10: /* SQRDMLAH (vector) */
11555 case 0x11: /* SQRDMLSH (vector) */
11556 if (size != 1 && size != 2) {
11557 unallocated_encoding(s);
11560 feature = dc_isar_feature(aa64_rdm, s);
11562 case 0x02: /* SDOT (vector) */
11563 case 0x12: /* UDOT (vector) */
11564 if (size != MO_32) {
11565 unallocated_encoding(s);
11568 feature = dc_isar_feature(aa64_dp, s);
11570 case 0x18: /* FCMLA, #0 */
11571 case 0x19: /* FCMLA, #90 */
11572 case 0x1a: /* FCMLA, #180 */
11573 case 0x1b: /* FCMLA, #270 */
11574 case 0x1c: /* FCADD, #90 */
11575 case 0x1e: /* FCADD, #270 */
11577 || (size == 1 && !dc_isar_feature(aa64_fp16, s))
11578 || (size == 3 && !is_q)) {
11579 unallocated_encoding(s);
11582 feature = dc_isar_feature(aa64_fcma, s);
11585 unallocated_encoding(s);
11589 unallocated_encoding(s);
11592 if (!fp_access_check(s)) {
11597 case 0x0: /* SQRDMLAH (vector) */
11600 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s16);
11603 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s32);
11606 g_assert_not_reached();
11610 case 0x1: /* SQRDMLSH (vector) */
11613 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s16);
11616 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s32);
11619 g_assert_not_reached();
11623 case 0x2: /* SDOT / UDOT */
11624 gen_gvec_op3_ool(s, is_q, rd, rn, rm, 0,
11625 u ? gen_helper_gvec_udot_b : gen_helper_gvec_sdot_b);
11628 case 0x8: /* FCMLA, #0 */
11629 case 0x9: /* FCMLA, #90 */
11630 case 0xa: /* FCMLA, #180 */
11631 case 0xb: /* FCMLA, #270 */
11632 rot = extract32(opcode, 0, 2);
11635 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, true, rot,
11636 gen_helper_gvec_fcmlah);
11639 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
11640 gen_helper_gvec_fcmlas);
11643 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
11644 gen_helper_gvec_fcmlad);
11647 g_assert_not_reached();
11651 case 0xc: /* FCADD, #90 */
11652 case 0xe: /* FCADD, #270 */
11653 rot = extract32(opcode, 1, 1);
11656 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11657 gen_helper_gvec_fcaddh);
11660 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11661 gen_helper_gvec_fcadds);
11664 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11665 gen_helper_gvec_fcaddd);
11668 g_assert_not_reached();
11673 g_assert_not_reached();
11677 static void handle_2misc_widening(DisasContext *s, int opcode, bool is_q,
11678 int size, int rn, int rd)
11680 /* Handle 2-reg-misc ops which are widening (so each size element
11681 * in the source becomes a 2*size element in the destination.
11682 * The only instruction like this is FCVTL.
11687 /* 32 -> 64 bit fp conversion */
11688 TCGv_i64 tcg_res[2];
11689 int srcelt = is_q ? 2 : 0;
11691 for (pass = 0; pass < 2; pass++) {
11692 TCGv_i32 tcg_op = tcg_temp_new_i32();
11693 tcg_res[pass] = tcg_temp_new_i64();
11695 read_vec_element_i32(s, tcg_op, rn, srcelt + pass, MO_32);
11696 gen_helper_vfp_fcvtds(tcg_res[pass], tcg_op, cpu_env);
11697 tcg_temp_free_i32(tcg_op);
11699 for (pass = 0; pass < 2; pass++) {
11700 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11701 tcg_temp_free_i64(tcg_res[pass]);
11704 /* 16 -> 32 bit fp conversion */
11705 int srcelt = is_q ? 4 : 0;
11706 TCGv_i32 tcg_res[4];
11707 TCGv_ptr fpst = get_fpstatus_ptr(false);
11708 TCGv_i32 ahp = get_ahp_flag();
11710 for (pass = 0; pass < 4; pass++) {
11711 tcg_res[pass] = tcg_temp_new_i32();
11713 read_vec_element_i32(s, tcg_res[pass], rn, srcelt + pass, MO_16);
11714 gen_helper_vfp_fcvt_f16_to_f32(tcg_res[pass], tcg_res[pass],
11717 for (pass = 0; pass < 4; pass++) {
11718 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32);
11719 tcg_temp_free_i32(tcg_res[pass]);
11722 tcg_temp_free_ptr(fpst);
11723 tcg_temp_free_i32(ahp);
11727 static void handle_rev(DisasContext *s, int opcode, bool u,
11728 bool is_q, int size, int rn, int rd)
11730 int op = (opcode << 1) | u;
11731 int opsz = op + size;
11732 int grp_size = 3 - opsz;
11733 int dsize = is_q ? 128 : 64;
11737 unallocated_encoding(s);
11741 if (!fp_access_check(s)) {
11746 /* Special case bytes, use bswap op on each group of elements */
11747 int groups = dsize / (8 << grp_size);
11749 for (i = 0; i < groups; i++) {
11750 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
11752 read_vec_element(s, tcg_tmp, rn, i, grp_size);
11753 switch (grp_size) {
11755 tcg_gen_bswap16_i64(tcg_tmp, tcg_tmp);
11758 tcg_gen_bswap32_i64(tcg_tmp, tcg_tmp);
11761 tcg_gen_bswap64_i64(tcg_tmp, tcg_tmp);
11764 g_assert_not_reached();
11766 write_vec_element(s, tcg_tmp, rd, i, grp_size);
11767 tcg_temp_free_i64(tcg_tmp);
11769 clear_vec_high(s, is_q, rd);
11771 int revmask = (1 << grp_size) - 1;
11772 int esize = 8 << size;
11773 int elements = dsize / esize;
11774 TCGv_i64 tcg_rn = tcg_temp_new_i64();
11775 TCGv_i64 tcg_rd = tcg_const_i64(0);
11776 TCGv_i64 tcg_rd_hi = tcg_const_i64(0);
11778 for (i = 0; i < elements; i++) {
11779 int e_rev = (i & 0xf) ^ revmask;
11780 int off = e_rev * esize;
11781 read_vec_element(s, tcg_rn, rn, i, size);
11783 tcg_gen_deposit_i64(tcg_rd_hi, tcg_rd_hi,
11784 tcg_rn, off - 64, esize);
11786 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, off, esize);
11789 write_vec_element(s, tcg_rd, rd, 0, MO_64);
11790 write_vec_element(s, tcg_rd_hi, rd, 1, MO_64);
11792 tcg_temp_free_i64(tcg_rd_hi);
11793 tcg_temp_free_i64(tcg_rd);
11794 tcg_temp_free_i64(tcg_rn);
11798 static void handle_2misc_pairwise(DisasContext *s, int opcode, bool u,
11799 bool is_q, int size, int rn, int rd)
11801 /* Implement the pairwise operations from 2-misc:
11802 * SADDLP, UADDLP, SADALP, UADALP.
11803 * These all add pairs of elements in the input to produce a
11804 * double-width result element in the output (possibly accumulating).
11806 bool accum = (opcode == 0x6);
11807 int maxpass = is_q ? 2 : 1;
11809 TCGv_i64 tcg_res[2];
11812 /* 32 + 32 -> 64 op */
11813 TCGMemOp memop = size + (u ? 0 : MO_SIGN);
11815 for (pass = 0; pass < maxpass; pass++) {
11816 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
11817 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
11819 tcg_res[pass] = tcg_temp_new_i64();
11821 read_vec_element(s, tcg_op1, rn, pass * 2, memop);
11822 read_vec_element(s, tcg_op2, rn, pass * 2 + 1, memop);
11823 tcg_gen_add_i64(tcg_res[pass], tcg_op1, tcg_op2);
11825 read_vec_element(s, tcg_op1, rd, pass, MO_64);
11826 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
11829 tcg_temp_free_i64(tcg_op1);
11830 tcg_temp_free_i64(tcg_op2);
11833 for (pass = 0; pass < maxpass; pass++) {
11834 TCGv_i64 tcg_op = tcg_temp_new_i64();
11835 NeonGenOneOpFn *genfn;
11836 static NeonGenOneOpFn * const fns[2][2] = {
11837 { gen_helper_neon_addlp_s8, gen_helper_neon_addlp_u8 },
11838 { gen_helper_neon_addlp_s16, gen_helper_neon_addlp_u16 },
11841 genfn = fns[size][u];
11843 tcg_res[pass] = tcg_temp_new_i64();
11845 read_vec_element(s, tcg_op, rn, pass, MO_64);
11846 genfn(tcg_res[pass], tcg_op);
11849 read_vec_element(s, tcg_op, rd, pass, MO_64);
11851 gen_helper_neon_addl_u16(tcg_res[pass],
11852 tcg_res[pass], tcg_op);
11854 gen_helper_neon_addl_u32(tcg_res[pass],
11855 tcg_res[pass], tcg_op);
11858 tcg_temp_free_i64(tcg_op);
11862 tcg_res[1] = tcg_const_i64(0);
11864 for (pass = 0; pass < 2; pass++) {
11865 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11866 tcg_temp_free_i64(tcg_res[pass]);
11870 static void handle_shll(DisasContext *s, bool is_q, int size, int rn, int rd)
11872 /* Implement SHLL and SHLL2 */
11874 int part = is_q ? 2 : 0;
11875 TCGv_i64 tcg_res[2];
11877 for (pass = 0; pass < 2; pass++) {
11878 static NeonGenWidenFn * const widenfns[3] = {
11879 gen_helper_neon_widen_u8,
11880 gen_helper_neon_widen_u16,
11881 tcg_gen_extu_i32_i64,
11883 NeonGenWidenFn *widenfn = widenfns[size];
11884 TCGv_i32 tcg_op = tcg_temp_new_i32();
11886 read_vec_element_i32(s, tcg_op, rn, part + pass, MO_32);
11887 tcg_res[pass] = tcg_temp_new_i64();
11888 widenfn(tcg_res[pass], tcg_op);
11889 tcg_gen_shli_i64(tcg_res[pass], tcg_res[pass], 8 << size);
11891 tcg_temp_free_i32(tcg_op);
11894 for (pass = 0; pass < 2; pass++) {
11895 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11896 tcg_temp_free_i64(tcg_res[pass]);
11900 /* AdvSIMD two reg misc
11901 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
11902 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11903 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
11904 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11906 static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)
11908 int size = extract32(insn, 22, 2);
11909 int opcode = extract32(insn, 12, 5);
11910 bool u = extract32(insn, 29, 1);
11911 bool is_q = extract32(insn, 30, 1);
11912 int rn = extract32(insn, 5, 5);
11913 int rd = extract32(insn, 0, 5);
11914 bool need_fpstatus = false;
11915 bool need_rmode = false;
11917 TCGv_i32 tcg_rmode;
11918 TCGv_ptr tcg_fpstatus;
11921 case 0x0: /* REV64, REV32 */
11922 case 0x1: /* REV16 */
11923 handle_rev(s, opcode, u, is_q, size, rn, rd);
11925 case 0x5: /* CNT, NOT, RBIT */
11926 if (u && size == 0) {
11929 } else if (u && size == 1) {
11932 } else if (!u && size == 0) {
11936 unallocated_encoding(s);
11938 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
11939 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
11941 unallocated_encoding(s);
11944 if (!fp_access_check(s)) {
11948 handle_2misc_narrow(s, false, opcode, u, is_q, size, rn, rd);
11950 case 0x4: /* CLS, CLZ */
11952 unallocated_encoding(s);
11956 case 0x2: /* SADDLP, UADDLP */
11957 case 0x6: /* SADALP, UADALP */
11959 unallocated_encoding(s);
11962 if (!fp_access_check(s)) {
11965 handle_2misc_pairwise(s, opcode, u, is_q, size, rn, rd);
11967 case 0x13: /* SHLL, SHLL2 */
11968 if (u == 0 || size == 3) {
11969 unallocated_encoding(s);
11972 if (!fp_access_check(s)) {
11975 handle_shll(s, is_q, size, rn, rd);
11977 case 0xa: /* CMLT */
11979 unallocated_encoding(s);
11983 case 0x8: /* CMGT, CMGE */
11984 case 0x9: /* CMEQ, CMLE */
11985 case 0xb: /* ABS, NEG */
11986 if (size == 3 && !is_q) {
11987 unallocated_encoding(s);
11991 case 0x3: /* SUQADD, USQADD */
11992 if (size == 3 && !is_q) {
11993 unallocated_encoding(s);
11996 if (!fp_access_check(s)) {
11999 handle_2misc_satacc(s, false, u, is_q, size, rn, rd);
12001 case 0x7: /* SQABS, SQNEG */
12002 if (size == 3 && !is_q) {
12003 unallocated_encoding(s);
12008 case 0x16 ... 0x1f:
12010 /* Floating point: U, size[1] and opcode indicate operation;
12011 * size[0] indicates single or double precision.
12013 int is_double = extract32(size, 0, 1);
12014 opcode |= (extract32(size, 1, 1) << 5) | (u << 6);
12015 size = is_double ? 3 : 2;
12017 case 0x2f: /* FABS */
12018 case 0x6f: /* FNEG */
12019 if (size == 3 && !is_q) {
12020 unallocated_encoding(s);
12024 case 0x1d: /* SCVTF */
12025 case 0x5d: /* UCVTF */
12027 bool is_signed = (opcode == 0x1d) ? true : false;
12028 int elements = is_double ? 2 : is_q ? 4 : 2;
12029 if (is_double && !is_q) {
12030 unallocated_encoding(s);
12033 if (!fp_access_check(s)) {
12036 handle_simd_intfp_conv(s, rd, rn, elements, is_signed, 0, size);
12039 case 0x2c: /* FCMGT (zero) */
12040 case 0x2d: /* FCMEQ (zero) */
12041 case 0x2e: /* FCMLT (zero) */
12042 case 0x6c: /* FCMGE (zero) */
12043 case 0x6d: /* FCMLE (zero) */
12044 if (size == 3 && !is_q) {
12045 unallocated_encoding(s);
12048 handle_2misc_fcmp_zero(s, opcode, false, u, is_q, size, rn, rd);
12050 case 0x7f: /* FSQRT */
12051 if (size == 3 && !is_q) {
12052 unallocated_encoding(s);
12056 case 0x1a: /* FCVTNS */
12057 case 0x1b: /* FCVTMS */
12058 case 0x3a: /* FCVTPS */
12059 case 0x3b: /* FCVTZS */
12060 case 0x5a: /* FCVTNU */
12061 case 0x5b: /* FCVTMU */
12062 case 0x7a: /* FCVTPU */
12063 case 0x7b: /* FCVTZU */
12064 need_fpstatus = true;
12066 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
12067 if (size == 3 && !is_q) {
12068 unallocated_encoding(s);
12072 case 0x5c: /* FCVTAU */
12073 case 0x1c: /* FCVTAS */
12074 need_fpstatus = true;
12076 rmode = FPROUNDING_TIEAWAY;
12077 if (size == 3 && !is_q) {
12078 unallocated_encoding(s);
12082 case 0x3c: /* URECPE */
12084 unallocated_encoding(s);
12088 case 0x3d: /* FRECPE */
12089 case 0x7d: /* FRSQRTE */
12090 if (size == 3 && !is_q) {
12091 unallocated_encoding(s);
12094 if (!fp_access_check(s)) {
12097 handle_2misc_reciprocal(s, opcode, false, u, is_q, size, rn, rd);
12099 case 0x56: /* FCVTXN, FCVTXN2 */
12101 unallocated_encoding(s);
12105 case 0x16: /* FCVTN, FCVTN2 */
12106 /* handle_2misc_narrow does a 2*size -> size operation, but these
12107 * instructions encode the source size rather than dest size.
12109 if (!fp_access_check(s)) {
12112 handle_2misc_narrow(s, false, opcode, 0, is_q, size - 1, rn, rd);
12114 case 0x17: /* FCVTL, FCVTL2 */
12115 if (!fp_access_check(s)) {
12118 handle_2misc_widening(s, opcode, is_q, size, rn, rd);
12120 case 0x18: /* FRINTN */
12121 case 0x19: /* FRINTM */
12122 case 0x38: /* FRINTP */
12123 case 0x39: /* FRINTZ */
12125 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
12127 case 0x59: /* FRINTX */
12128 case 0x79: /* FRINTI */
12129 need_fpstatus = true;
12130 if (size == 3 && !is_q) {
12131 unallocated_encoding(s);
12135 case 0x58: /* FRINTA */
12137 rmode = FPROUNDING_TIEAWAY;
12138 need_fpstatus = true;
12139 if (size == 3 && !is_q) {
12140 unallocated_encoding(s);
12144 case 0x7c: /* URSQRTE */
12146 unallocated_encoding(s);
12149 need_fpstatus = true;
12151 case 0x1e: /* FRINT32Z */
12152 case 0x1f: /* FRINT64Z */
12154 rmode = FPROUNDING_ZERO;
12156 case 0x5e: /* FRINT32X */
12157 case 0x5f: /* FRINT64X */
12158 need_fpstatus = true;
12159 if ((size == 3 && !is_q) || !dc_isar_feature(aa64_frint, s)) {
12160 unallocated_encoding(s);
12165 unallocated_encoding(s);
12171 unallocated_encoding(s);
12175 if (!fp_access_check(s)) {
12179 if (need_fpstatus || need_rmode) {
12180 tcg_fpstatus = get_fpstatus_ptr(false);
12182 tcg_fpstatus = NULL;
12185 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
12186 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12193 if (u && size == 0) { /* NOT */
12194 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_not, 0);
12199 if (u) { /* ABS, NEG */
12200 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_neg, size);
12202 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_abs, size);
12208 /* All 64-bit element operations can be shared with scalar 2misc */
12211 /* Coverity claims (size == 3 && !is_q) has been eliminated
12212 * from all paths leading to here.
12214 tcg_debug_assert(is_q);
12215 for (pass = 0; pass < 2; pass++) {
12216 TCGv_i64 tcg_op = tcg_temp_new_i64();
12217 TCGv_i64 tcg_res = tcg_temp_new_i64();
12219 read_vec_element(s, tcg_op, rn, pass, MO_64);
12221 handle_2misc_64(s, opcode, u, tcg_res, tcg_op,
12222 tcg_rmode, tcg_fpstatus);
12224 write_vec_element(s, tcg_res, rd, pass, MO_64);
12226 tcg_temp_free_i64(tcg_res);
12227 tcg_temp_free_i64(tcg_op);
12232 for (pass = 0; pass < (is_q ? 4 : 2); pass++) {
12233 TCGv_i32 tcg_op = tcg_temp_new_i32();
12234 TCGv_i32 tcg_res = tcg_temp_new_i32();
12237 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
12240 /* Special cases for 32 bit elements */
12242 case 0xa: /* CMLT */
12243 /* 32 bit integer comparison against zero, result is
12244 * test ? (2^32 - 1) : 0. We implement via setcond(test)
12247 cond = TCG_COND_LT;
12249 tcg_gen_setcondi_i32(cond, tcg_res, tcg_op, 0);
12250 tcg_gen_neg_i32(tcg_res, tcg_res);
12252 case 0x8: /* CMGT, CMGE */
12253 cond = u ? TCG_COND_GE : TCG_COND_GT;
12255 case 0x9: /* CMEQ, CMLE */
12256 cond = u ? TCG_COND_LE : TCG_COND_EQ;
12258 case 0x4: /* CLS */
12260 tcg_gen_clzi_i32(tcg_res, tcg_op, 32);
12262 tcg_gen_clrsb_i32(tcg_res, tcg_op);
12265 case 0x7: /* SQABS, SQNEG */
12267 gen_helper_neon_qneg_s32(tcg_res, cpu_env, tcg_op);
12269 gen_helper_neon_qabs_s32(tcg_res, cpu_env, tcg_op);
12272 case 0x2f: /* FABS */
12273 gen_helper_vfp_abss(tcg_res, tcg_op);
12275 case 0x6f: /* FNEG */
12276 gen_helper_vfp_negs(tcg_res, tcg_op);
12278 case 0x7f: /* FSQRT */
12279 gen_helper_vfp_sqrts(tcg_res, tcg_op, cpu_env);
12281 case 0x1a: /* FCVTNS */
12282 case 0x1b: /* FCVTMS */
12283 case 0x1c: /* FCVTAS */
12284 case 0x3a: /* FCVTPS */
12285 case 0x3b: /* FCVTZS */
12287 TCGv_i32 tcg_shift = tcg_const_i32(0);
12288 gen_helper_vfp_tosls(tcg_res, tcg_op,
12289 tcg_shift, tcg_fpstatus);
12290 tcg_temp_free_i32(tcg_shift);
12293 case 0x5a: /* FCVTNU */
12294 case 0x5b: /* FCVTMU */
12295 case 0x5c: /* FCVTAU */
12296 case 0x7a: /* FCVTPU */
12297 case 0x7b: /* FCVTZU */
12299 TCGv_i32 tcg_shift = tcg_const_i32(0);
12300 gen_helper_vfp_touls(tcg_res, tcg_op,
12301 tcg_shift, tcg_fpstatus);
12302 tcg_temp_free_i32(tcg_shift);
12305 case 0x18: /* FRINTN */
12306 case 0x19: /* FRINTM */
12307 case 0x38: /* FRINTP */
12308 case 0x39: /* FRINTZ */
12309 case 0x58: /* FRINTA */
12310 case 0x79: /* FRINTI */
12311 gen_helper_rints(tcg_res, tcg_op, tcg_fpstatus);
12313 case 0x59: /* FRINTX */
12314 gen_helper_rints_exact(tcg_res, tcg_op, tcg_fpstatus);
12316 case 0x7c: /* URSQRTE */
12317 gen_helper_rsqrte_u32(tcg_res, tcg_op, tcg_fpstatus);
12319 case 0x1e: /* FRINT32Z */
12320 case 0x5e: /* FRINT32X */
12321 gen_helper_frint32_s(tcg_res, tcg_op, tcg_fpstatus);
12323 case 0x1f: /* FRINT64Z */
12324 case 0x5f: /* FRINT64X */
12325 gen_helper_frint64_s(tcg_res, tcg_op, tcg_fpstatus);
12328 g_assert_not_reached();
12331 /* Use helpers for 8 and 16 bit elements */
12333 case 0x5: /* CNT, RBIT */
12334 /* For these two insns size is part of the opcode specifier
12335 * (handled earlier); they always operate on byte elements.
12338 gen_helper_neon_rbit_u8(tcg_res, tcg_op);
12340 gen_helper_neon_cnt_u8(tcg_res, tcg_op);
12343 case 0x7: /* SQABS, SQNEG */
12345 NeonGenOneOpEnvFn *genfn;
12346 static NeonGenOneOpEnvFn * const fns[2][2] = {
12347 { gen_helper_neon_qabs_s8, gen_helper_neon_qneg_s8 },
12348 { gen_helper_neon_qabs_s16, gen_helper_neon_qneg_s16 },
12350 genfn = fns[size][u];
12351 genfn(tcg_res, cpu_env, tcg_op);
12354 case 0x8: /* CMGT, CMGE */
12355 case 0x9: /* CMEQ, CMLE */
12356 case 0xa: /* CMLT */
12358 static NeonGenTwoOpFn * const fns[3][2] = {
12359 { gen_helper_neon_cgt_s8, gen_helper_neon_cgt_s16 },
12360 { gen_helper_neon_cge_s8, gen_helper_neon_cge_s16 },
12361 { gen_helper_neon_ceq_u8, gen_helper_neon_ceq_u16 },
12363 NeonGenTwoOpFn *genfn;
12366 TCGv_i32 tcg_zero = tcg_const_i32(0);
12368 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
12369 comp = (opcode - 0x8) * 2 + u;
12370 /* ...but LE, LT are implemented as reverse GE, GT */
12371 reverse = (comp > 2);
12375 genfn = fns[comp][size];
12377 genfn(tcg_res, tcg_zero, tcg_op);
12379 genfn(tcg_res, tcg_op, tcg_zero);
12381 tcg_temp_free_i32(tcg_zero);
12384 case 0x4: /* CLS, CLZ */
12387 gen_helper_neon_clz_u8(tcg_res, tcg_op);
12389 gen_helper_neon_clz_u16(tcg_res, tcg_op);
12393 gen_helper_neon_cls_s8(tcg_res, tcg_op);
12395 gen_helper_neon_cls_s16(tcg_res, tcg_op);
12400 g_assert_not_reached();
12404 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
12406 tcg_temp_free_i32(tcg_res);
12407 tcg_temp_free_i32(tcg_op);
12410 clear_vec_high(s, is_q, rd);
12413 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12414 tcg_temp_free_i32(tcg_rmode);
12416 if (need_fpstatus) {
12417 tcg_temp_free_ptr(tcg_fpstatus);
12421 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12423 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12424 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12425 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12426 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12427 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12428 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12430 * This actually covers two groups where scalar access is governed by
12431 * bit 28. A bunch of the instructions (float to integral) only exist
12432 * in the vector form and are un-allocated for the scalar decode. Also
12433 * in the scalar decode Q is always 1.
12435 static void disas_simd_two_reg_misc_fp16(DisasContext *s, uint32_t insn)
12437 int fpop, opcode, a, u;
12441 bool only_in_vector = false;
12444 TCGv_i32 tcg_rmode = NULL;
12445 TCGv_ptr tcg_fpstatus = NULL;
12446 bool need_rmode = false;
12447 bool need_fpst = true;
12450 if (!dc_isar_feature(aa64_fp16, s)) {
12451 unallocated_encoding(s);
12455 rd = extract32(insn, 0, 5);
12456 rn = extract32(insn, 5, 5);
12458 a = extract32(insn, 23, 1);
12459 u = extract32(insn, 29, 1);
12460 is_scalar = extract32(insn, 28, 1);
12461 is_q = extract32(insn, 30, 1);
12463 opcode = extract32(insn, 12, 5);
12464 fpop = deposit32(opcode, 5, 1, a);
12465 fpop = deposit32(fpop, 6, 1, u);
12467 rd = extract32(insn, 0, 5);
12468 rn = extract32(insn, 5, 5);
12471 case 0x1d: /* SCVTF */
12472 case 0x5d: /* UCVTF */
12479 elements = (is_q ? 8 : 4);
12482 if (!fp_access_check(s)) {
12485 handle_simd_intfp_conv(s, rd, rn, elements, !u, 0, MO_16);
12489 case 0x2c: /* FCMGT (zero) */
12490 case 0x2d: /* FCMEQ (zero) */
12491 case 0x2e: /* FCMLT (zero) */
12492 case 0x6c: /* FCMGE (zero) */
12493 case 0x6d: /* FCMLE (zero) */
12494 handle_2misc_fcmp_zero(s, fpop, is_scalar, 0, is_q, MO_16, rn, rd);
12496 case 0x3d: /* FRECPE */
12497 case 0x3f: /* FRECPX */
12499 case 0x18: /* FRINTN */
12501 only_in_vector = true;
12502 rmode = FPROUNDING_TIEEVEN;
12504 case 0x19: /* FRINTM */
12506 only_in_vector = true;
12507 rmode = FPROUNDING_NEGINF;
12509 case 0x38: /* FRINTP */
12511 only_in_vector = true;
12512 rmode = FPROUNDING_POSINF;
12514 case 0x39: /* FRINTZ */
12516 only_in_vector = true;
12517 rmode = FPROUNDING_ZERO;
12519 case 0x58: /* FRINTA */
12521 only_in_vector = true;
12522 rmode = FPROUNDING_TIEAWAY;
12524 case 0x59: /* FRINTX */
12525 case 0x79: /* FRINTI */
12526 only_in_vector = true;
12527 /* current rounding mode */
12529 case 0x1a: /* FCVTNS */
12531 rmode = FPROUNDING_TIEEVEN;
12533 case 0x1b: /* FCVTMS */
12535 rmode = FPROUNDING_NEGINF;
12537 case 0x1c: /* FCVTAS */
12539 rmode = FPROUNDING_TIEAWAY;
12541 case 0x3a: /* FCVTPS */
12543 rmode = FPROUNDING_POSINF;
12545 case 0x3b: /* FCVTZS */
12547 rmode = FPROUNDING_ZERO;
12549 case 0x5a: /* FCVTNU */
12551 rmode = FPROUNDING_TIEEVEN;
12553 case 0x5b: /* FCVTMU */
12555 rmode = FPROUNDING_NEGINF;
12557 case 0x5c: /* FCVTAU */
12559 rmode = FPROUNDING_TIEAWAY;
12561 case 0x7a: /* FCVTPU */
12563 rmode = FPROUNDING_POSINF;
12565 case 0x7b: /* FCVTZU */
12567 rmode = FPROUNDING_ZERO;
12569 case 0x2f: /* FABS */
12570 case 0x6f: /* FNEG */
12573 case 0x7d: /* FRSQRTE */
12574 case 0x7f: /* FSQRT (vector) */
12577 fprintf(stderr, "%s: insn %#04x fpop %#2x\n", __func__, insn, fpop);
12578 g_assert_not_reached();
12582 /* Check additional constraints for the scalar encoding */
12585 unallocated_encoding(s);
12588 /* FRINTxx is only in the vector form */
12589 if (only_in_vector) {
12590 unallocated_encoding(s);
12595 if (!fp_access_check(s)) {
12599 if (need_rmode || need_fpst) {
12600 tcg_fpstatus = get_fpstatus_ptr(true);
12604 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
12605 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12609 TCGv_i32 tcg_op = read_fp_hreg(s, rn);
12610 TCGv_i32 tcg_res = tcg_temp_new_i32();
12613 case 0x1a: /* FCVTNS */
12614 case 0x1b: /* FCVTMS */
12615 case 0x1c: /* FCVTAS */
12616 case 0x3a: /* FCVTPS */
12617 case 0x3b: /* FCVTZS */
12618 gen_helper_advsimd_f16tosinth(tcg_res, tcg_op, tcg_fpstatus);
12620 case 0x3d: /* FRECPE */
12621 gen_helper_recpe_f16(tcg_res, tcg_op, tcg_fpstatus);
12623 case 0x3f: /* FRECPX */
12624 gen_helper_frecpx_f16(tcg_res, tcg_op, tcg_fpstatus);
12626 case 0x5a: /* FCVTNU */
12627 case 0x5b: /* FCVTMU */
12628 case 0x5c: /* FCVTAU */
12629 case 0x7a: /* FCVTPU */
12630 case 0x7b: /* FCVTZU */
12631 gen_helper_advsimd_f16touinth(tcg_res, tcg_op, tcg_fpstatus);
12633 case 0x6f: /* FNEG */
12634 tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000);
12636 case 0x7d: /* FRSQRTE */
12637 gen_helper_rsqrte_f16(tcg_res, tcg_op, tcg_fpstatus);
12640 g_assert_not_reached();
12643 /* limit any sign extension going on */
12644 tcg_gen_andi_i32(tcg_res, tcg_res, 0xffff);
12645 write_fp_sreg(s, rd, tcg_res);
12647 tcg_temp_free_i32(tcg_res);
12648 tcg_temp_free_i32(tcg_op);
12650 for (pass = 0; pass < (is_q ? 8 : 4); pass++) {
12651 TCGv_i32 tcg_op = tcg_temp_new_i32();
12652 TCGv_i32 tcg_res = tcg_temp_new_i32();
12654 read_vec_element_i32(s, tcg_op, rn, pass, MO_16);
12657 case 0x1a: /* FCVTNS */
12658 case 0x1b: /* FCVTMS */
12659 case 0x1c: /* FCVTAS */
12660 case 0x3a: /* FCVTPS */
12661 case 0x3b: /* FCVTZS */
12662 gen_helper_advsimd_f16tosinth(tcg_res, tcg_op, tcg_fpstatus);
12664 case 0x3d: /* FRECPE */
12665 gen_helper_recpe_f16(tcg_res, tcg_op, tcg_fpstatus);
12667 case 0x5a: /* FCVTNU */
12668 case 0x5b: /* FCVTMU */
12669 case 0x5c: /* FCVTAU */
12670 case 0x7a: /* FCVTPU */
12671 case 0x7b: /* FCVTZU */
12672 gen_helper_advsimd_f16touinth(tcg_res, tcg_op, tcg_fpstatus);
12674 case 0x18: /* FRINTN */
12675 case 0x19: /* FRINTM */
12676 case 0x38: /* FRINTP */
12677 case 0x39: /* FRINTZ */
12678 case 0x58: /* FRINTA */
12679 case 0x79: /* FRINTI */
12680 gen_helper_advsimd_rinth(tcg_res, tcg_op, tcg_fpstatus);
12682 case 0x59: /* FRINTX */
12683 gen_helper_advsimd_rinth_exact(tcg_res, tcg_op, tcg_fpstatus);
12685 case 0x2f: /* FABS */
12686 tcg_gen_andi_i32(tcg_res, tcg_op, 0x7fff);
12688 case 0x6f: /* FNEG */
12689 tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000);
12691 case 0x7d: /* FRSQRTE */
12692 gen_helper_rsqrte_f16(tcg_res, tcg_op, tcg_fpstatus);
12694 case 0x7f: /* FSQRT */
12695 gen_helper_sqrt_f16(tcg_res, tcg_op, tcg_fpstatus);
12698 g_assert_not_reached();
12701 write_vec_element_i32(s, tcg_res, rd, pass, MO_16);
12703 tcg_temp_free_i32(tcg_res);
12704 tcg_temp_free_i32(tcg_op);
12707 clear_vec_high(s, is_q, rd);
12711 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12712 tcg_temp_free_i32(tcg_rmode);
12715 if (tcg_fpstatus) {
12716 tcg_temp_free_ptr(tcg_fpstatus);
12720 /* AdvSIMD scalar x indexed element
12721 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12722 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12723 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12724 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12725 * AdvSIMD vector x indexed element
12726 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12727 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12728 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12729 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12731 static void disas_simd_indexed(DisasContext *s, uint32_t insn)
12733 /* This encoding has two kinds of instruction:
12734 * normal, where we perform elt x idxelt => elt for each
12735 * element in the vector
12736 * long, where we perform elt x idxelt and generate a result of
12737 * double the width of the input element
12738 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
12740 bool is_scalar = extract32(insn, 28, 1);
12741 bool is_q = extract32(insn, 30, 1);
12742 bool u = extract32(insn, 29, 1);
12743 int size = extract32(insn, 22, 2);
12744 int l = extract32(insn, 21, 1);
12745 int m = extract32(insn, 20, 1);
12746 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
12747 int rm = extract32(insn, 16, 4);
12748 int opcode = extract32(insn, 12, 4);
12749 int h = extract32(insn, 11, 1);
12750 int rn = extract32(insn, 5, 5);
12751 int rd = extract32(insn, 0, 5);
12752 bool is_long = false;
12754 bool is_fp16 = false;
12758 switch (16 * u + opcode) {
12759 case 0x08: /* MUL */
12760 case 0x10: /* MLA */
12761 case 0x14: /* MLS */
12763 unallocated_encoding(s);
12767 case 0x02: /* SMLAL, SMLAL2 */
12768 case 0x12: /* UMLAL, UMLAL2 */
12769 case 0x06: /* SMLSL, SMLSL2 */
12770 case 0x16: /* UMLSL, UMLSL2 */
12771 case 0x0a: /* SMULL, SMULL2 */
12772 case 0x1a: /* UMULL, UMULL2 */
12774 unallocated_encoding(s);
12779 case 0x03: /* SQDMLAL, SQDMLAL2 */
12780 case 0x07: /* SQDMLSL, SQDMLSL2 */
12781 case 0x0b: /* SQDMULL, SQDMULL2 */
12784 case 0x0c: /* SQDMULH */
12785 case 0x0d: /* SQRDMULH */
12787 case 0x01: /* FMLA */
12788 case 0x05: /* FMLS */
12789 case 0x09: /* FMUL */
12790 case 0x19: /* FMULX */
12793 case 0x1d: /* SQRDMLAH */
12794 case 0x1f: /* SQRDMLSH */
12795 if (!dc_isar_feature(aa64_rdm, s)) {
12796 unallocated_encoding(s);
12800 case 0x0e: /* SDOT */
12801 case 0x1e: /* UDOT */
12802 if (is_scalar || size != MO_32 || !dc_isar_feature(aa64_dp, s)) {
12803 unallocated_encoding(s);
12807 case 0x11: /* FCMLA #0 */
12808 case 0x13: /* FCMLA #90 */
12809 case 0x15: /* FCMLA #180 */
12810 case 0x17: /* FCMLA #270 */
12811 if (is_scalar || !dc_isar_feature(aa64_fcma, s)) {
12812 unallocated_encoding(s);
12817 case 0x00: /* FMLAL */
12818 case 0x04: /* FMLSL */
12819 case 0x18: /* FMLAL2 */
12820 case 0x1c: /* FMLSL2 */
12821 if (is_scalar || size != MO_32 || !dc_isar_feature(aa64_fhm, s)) {
12822 unallocated_encoding(s);
12826 /* is_fp, but we pass cpu_env not fp_status. */
12829 unallocated_encoding(s);
12834 case 1: /* normal fp */
12835 /* convert insn encoded size to TCGMemOp size */
12837 case 0: /* half-precision */
12841 case MO_32: /* single precision */
12842 case MO_64: /* double precision */
12845 unallocated_encoding(s);
12850 case 2: /* complex fp */
12851 /* Each indexable element is a complex pair. */
12856 unallocated_encoding(s);
12864 unallocated_encoding(s);
12869 default: /* integer */
12873 unallocated_encoding(s);
12878 if (is_fp16 && !dc_isar_feature(aa64_fp16, s)) {
12879 unallocated_encoding(s);
12883 /* Given TCGMemOp size, adjust register and indexing. */
12886 index = h << 2 | l << 1 | m;
12889 index = h << 1 | l;
12894 unallocated_encoding(s);
12901 g_assert_not_reached();
12904 if (!fp_access_check(s)) {
12909 fpst = get_fpstatus_ptr(is_fp16);
12914 switch (16 * u + opcode) {
12915 case 0x0e: /* SDOT */
12916 case 0x1e: /* UDOT */
12917 gen_gvec_op3_ool(s, is_q, rd, rn, rm, index,
12918 u ? gen_helper_gvec_udot_idx_b
12919 : gen_helper_gvec_sdot_idx_b);
12921 case 0x11: /* FCMLA #0 */
12922 case 0x13: /* FCMLA #90 */
12923 case 0x15: /* FCMLA #180 */
12924 case 0x17: /* FCMLA #270 */
12926 int rot = extract32(insn, 13, 2);
12927 int data = (index << 2) | rot;
12928 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
12929 vec_full_reg_offset(s, rn),
12930 vec_full_reg_offset(s, rm), fpst,
12931 is_q ? 16 : 8, vec_full_reg_size(s), data,
12933 ? gen_helper_gvec_fcmlas_idx
12934 : gen_helper_gvec_fcmlah_idx);
12935 tcg_temp_free_ptr(fpst);
12939 case 0x00: /* FMLAL */
12940 case 0x04: /* FMLSL */
12941 case 0x18: /* FMLAL2 */
12942 case 0x1c: /* FMLSL2 */
12944 int is_s = extract32(opcode, 2, 1);
12946 int data = (index << 2) | (is_2 << 1) | is_s;
12947 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
12948 vec_full_reg_offset(s, rn),
12949 vec_full_reg_offset(s, rm), cpu_env,
12950 is_q ? 16 : 8, vec_full_reg_size(s),
12951 data, gen_helper_gvec_fmlal_idx_a64);
12957 TCGv_i64 tcg_idx = tcg_temp_new_i64();
12960 assert(is_fp && is_q && !is_long);
12962 read_vec_element(s, tcg_idx, rm, index, MO_64);
12964 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
12965 TCGv_i64 tcg_op = tcg_temp_new_i64();
12966 TCGv_i64 tcg_res = tcg_temp_new_i64();
12968 read_vec_element(s, tcg_op, rn, pass, MO_64);
12970 switch (16 * u + opcode) {
12971 case 0x05: /* FMLS */
12972 /* As usual for ARM, separate negation for fused multiply-add */
12973 gen_helper_vfp_negd(tcg_op, tcg_op);
12975 case 0x01: /* FMLA */
12976 read_vec_element(s, tcg_res, rd, pass, MO_64);
12977 gen_helper_vfp_muladdd(tcg_res, tcg_op, tcg_idx, tcg_res, fpst);
12979 case 0x09: /* FMUL */
12980 gen_helper_vfp_muld(tcg_res, tcg_op, tcg_idx, fpst);
12982 case 0x19: /* FMULX */
12983 gen_helper_vfp_mulxd(tcg_res, tcg_op, tcg_idx, fpst);
12986 g_assert_not_reached();
12989 write_vec_element(s, tcg_res, rd, pass, MO_64);
12990 tcg_temp_free_i64(tcg_op);
12991 tcg_temp_free_i64(tcg_res);
12994 tcg_temp_free_i64(tcg_idx);
12995 clear_vec_high(s, !is_scalar, rd);
12996 } else if (!is_long) {
12997 /* 32 bit floating point, or 16 or 32 bit integer.
12998 * For the 16 bit scalar case we use the usual Neon helpers and
12999 * rely on the fact that 0 op 0 == 0 with no side effects.
13001 TCGv_i32 tcg_idx = tcg_temp_new_i32();
13002 int pass, maxpasses;
13007 maxpasses = is_q ? 4 : 2;
13010 read_vec_element_i32(s, tcg_idx, rm, index, size);
13012 if (size == 1 && !is_scalar) {
13013 /* The simplest way to handle the 16x16 indexed ops is to duplicate
13014 * the index into both halves of the 32 bit tcg_idx and then use
13015 * the usual Neon helpers.
13017 tcg_gen_deposit_i32(tcg_idx, tcg_idx, tcg_idx, 16, 16);
13020 for (pass = 0; pass < maxpasses; pass++) {
13021 TCGv_i32 tcg_op = tcg_temp_new_i32();
13022 TCGv_i32 tcg_res = tcg_temp_new_i32();
13024 read_vec_element_i32(s, tcg_op, rn, pass, is_scalar ? size : MO_32);
13026 switch (16 * u + opcode) {
13027 case 0x08: /* MUL */
13028 case 0x10: /* MLA */
13029 case 0x14: /* MLS */
13031 static NeonGenTwoOpFn * const fns[2][2] = {
13032 { gen_helper_neon_add_u16, gen_helper_neon_sub_u16 },
13033 { tcg_gen_add_i32, tcg_gen_sub_i32 },
13035 NeonGenTwoOpFn *genfn;
13036 bool is_sub = opcode == 0x4;
13039 gen_helper_neon_mul_u16(tcg_res, tcg_op, tcg_idx);
13041 tcg_gen_mul_i32(tcg_res, tcg_op, tcg_idx);
13043 if (opcode == 0x8) {
13046 read_vec_element_i32(s, tcg_op, rd, pass, MO_32);
13047 genfn = fns[size - 1][is_sub];
13048 genfn(tcg_res, tcg_op, tcg_res);
13051 case 0x05: /* FMLS */
13052 case 0x01: /* FMLA */
13053 read_vec_element_i32(s, tcg_res, rd, pass,
13054 is_scalar ? size : MO_32);
13057 if (opcode == 0x5) {
13058 /* As usual for ARM, separate negation for fused
13060 tcg_gen_xori_i32(tcg_op, tcg_op, 0x80008000);
13063 gen_helper_advsimd_muladdh(tcg_res, tcg_op, tcg_idx,
13066 gen_helper_advsimd_muladd2h(tcg_res, tcg_op, tcg_idx,
13071 if (opcode == 0x5) {
13072 /* As usual for ARM, separate negation for
13073 * fused multiply-add */
13074 tcg_gen_xori_i32(tcg_op, tcg_op, 0x80000000);
13076 gen_helper_vfp_muladds(tcg_res, tcg_op, tcg_idx,
13080 g_assert_not_reached();
13083 case 0x09: /* FMUL */
13087 gen_helper_advsimd_mulh(tcg_res, tcg_op,
13090 gen_helper_advsimd_mul2h(tcg_res, tcg_op,
13095 gen_helper_vfp_muls(tcg_res, tcg_op, tcg_idx, fpst);
13098 g_assert_not_reached();
13101 case 0x19: /* FMULX */
13105 gen_helper_advsimd_mulxh(tcg_res, tcg_op,
13108 gen_helper_advsimd_mulx2h(tcg_res, tcg_op,
13113 gen_helper_vfp_mulxs(tcg_res, tcg_op, tcg_idx, fpst);
13116 g_assert_not_reached();
13119 case 0x0c: /* SQDMULH */
13121 gen_helper_neon_qdmulh_s16(tcg_res, cpu_env,
13124 gen_helper_neon_qdmulh_s32(tcg_res, cpu_env,
13128 case 0x0d: /* SQRDMULH */
13130 gen_helper_neon_qrdmulh_s16(tcg_res, cpu_env,
13133 gen_helper_neon_qrdmulh_s32(tcg_res, cpu_env,
13137 case 0x1d: /* SQRDMLAH */
13138 read_vec_element_i32(s, tcg_res, rd, pass,
13139 is_scalar ? size : MO_32);
13141 gen_helper_neon_qrdmlah_s16(tcg_res, cpu_env,
13142 tcg_op, tcg_idx, tcg_res);
13144 gen_helper_neon_qrdmlah_s32(tcg_res, cpu_env,
13145 tcg_op, tcg_idx, tcg_res);
13148 case 0x1f: /* SQRDMLSH */
13149 read_vec_element_i32(s, tcg_res, rd, pass,
13150 is_scalar ? size : MO_32);
13152 gen_helper_neon_qrdmlsh_s16(tcg_res, cpu_env,
13153 tcg_op, tcg_idx, tcg_res);
13155 gen_helper_neon_qrdmlsh_s32(tcg_res, cpu_env,
13156 tcg_op, tcg_idx, tcg_res);
13160 g_assert_not_reached();
13164 write_fp_sreg(s, rd, tcg_res);
13166 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
13169 tcg_temp_free_i32(tcg_op);
13170 tcg_temp_free_i32(tcg_res);
13173 tcg_temp_free_i32(tcg_idx);
13174 clear_vec_high(s, is_q, rd);
13176 /* long ops: 16x16->32 or 32x32->64 */
13177 TCGv_i64 tcg_res[2];
13179 bool satop = extract32(opcode, 0, 1);
13180 TCGMemOp memop = MO_32;
13187 TCGv_i64 tcg_idx = tcg_temp_new_i64();
13189 read_vec_element(s, tcg_idx, rm, index, memop);
13191 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
13192 TCGv_i64 tcg_op = tcg_temp_new_i64();
13193 TCGv_i64 tcg_passres;
13199 passelt = pass + (is_q * 2);
13202 read_vec_element(s, tcg_op, rn, passelt, memop);
13204 tcg_res[pass] = tcg_temp_new_i64();
13206 if (opcode == 0xa || opcode == 0xb) {
13207 /* Non-accumulating ops */
13208 tcg_passres = tcg_res[pass];
13210 tcg_passres = tcg_temp_new_i64();
13213 tcg_gen_mul_i64(tcg_passres, tcg_op, tcg_idx);
13214 tcg_temp_free_i64(tcg_op);
13217 /* saturating, doubling */
13218 gen_helper_neon_addl_saturate_s64(tcg_passres, cpu_env,
13219 tcg_passres, tcg_passres);
13222 if (opcode == 0xa || opcode == 0xb) {
13226 /* Accumulating op: handle accumulate step */
13227 read_vec_element(s, tcg_res[pass], rd, pass, MO_64);
13230 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13231 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
13233 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13234 tcg_gen_sub_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
13236 case 0x7: /* SQDMLSL, SQDMLSL2 */
13237 tcg_gen_neg_i64(tcg_passres, tcg_passres);
13239 case 0x3: /* SQDMLAL, SQDMLAL2 */
13240 gen_helper_neon_addl_saturate_s64(tcg_res[pass], cpu_env,
13245 g_assert_not_reached();
13247 tcg_temp_free_i64(tcg_passres);
13249 tcg_temp_free_i64(tcg_idx);
13251 clear_vec_high(s, !is_scalar, rd);
13253 TCGv_i32 tcg_idx = tcg_temp_new_i32();
13256 read_vec_element_i32(s, tcg_idx, rm, index, size);
13259 /* The simplest way to handle the 16x16 indexed ops is to
13260 * duplicate the index into both halves of the 32 bit tcg_idx
13261 * and then use the usual Neon helpers.
13263 tcg_gen_deposit_i32(tcg_idx, tcg_idx, tcg_idx, 16, 16);
13266 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
13267 TCGv_i32 tcg_op = tcg_temp_new_i32();
13268 TCGv_i64 tcg_passres;
13271 read_vec_element_i32(s, tcg_op, rn, pass, size);
13273 read_vec_element_i32(s, tcg_op, rn,
13274 pass + (is_q * 2), MO_32);
13277 tcg_res[pass] = tcg_temp_new_i64();
13279 if (opcode == 0xa || opcode == 0xb) {
13280 /* Non-accumulating ops */
13281 tcg_passres = tcg_res[pass];
13283 tcg_passres = tcg_temp_new_i64();
13286 if (memop & MO_SIGN) {
13287 gen_helper_neon_mull_s16(tcg_passres, tcg_op, tcg_idx);
13289 gen_helper_neon_mull_u16(tcg_passres, tcg_op, tcg_idx);
13292 gen_helper_neon_addl_saturate_s32(tcg_passres, cpu_env,
13293 tcg_passres, tcg_passres);
13295 tcg_temp_free_i32(tcg_op);
13297 if (opcode == 0xa || opcode == 0xb) {
13301 /* Accumulating op: handle accumulate step */
13302 read_vec_element(s, tcg_res[pass], rd, pass, MO_64);
13305 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13306 gen_helper_neon_addl_u32(tcg_res[pass], tcg_res[pass],
13309 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13310 gen_helper_neon_subl_u32(tcg_res[pass], tcg_res[pass],
13313 case 0x7: /* SQDMLSL, SQDMLSL2 */
13314 gen_helper_neon_negl_u32(tcg_passres, tcg_passres);
13316 case 0x3: /* SQDMLAL, SQDMLAL2 */
13317 gen_helper_neon_addl_saturate_s32(tcg_res[pass], cpu_env,
13322 g_assert_not_reached();
13324 tcg_temp_free_i64(tcg_passres);
13326 tcg_temp_free_i32(tcg_idx);
13329 tcg_gen_ext32u_i64(tcg_res[0], tcg_res[0]);
13334 tcg_res[1] = tcg_const_i64(0);
13337 for (pass = 0; pass < 2; pass++) {
13338 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
13339 tcg_temp_free_i64(tcg_res[pass]);
13344 tcg_temp_free_ptr(fpst);
13349 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13350 * +-----------------+------+-----------+--------+-----+------+------+
13351 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13352 * +-----------------+------+-----------+--------+-----+------+------+
13354 static void disas_crypto_aes(DisasContext *s, uint32_t insn)
13356 int size = extract32(insn, 22, 2);
13357 int opcode = extract32(insn, 12, 5);
13358 int rn = extract32(insn, 5, 5);
13359 int rd = extract32(insn, 0, 5);
13361 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
13362 TCGv_i32 tcg_decrypt;
13363 CryptoThreeOpIntFn *genfn;
13365 if (!dc_isar_feature(aa64_aes, s) || size != 0) {
13366 unallocated_encoding(s);
13371 case 0x4: /* AESE */
13373 genfn = gen_helper_crypto_aese;
13375 case 0x6: /* AESMC */
13377 genfn = gen_helper_crypto_aesmc;
13379 case 0x5: /* AESD */
13381 genfn = gen_helper_crypto_aese;
13383 case 0x7: /* AESIMC */
13385 genfn = gen_helper_crypto_aesmc;
13388 unallocated_encoding(s);
13392 if (!fp_access_check(s)) {
13396 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13397 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13398 tcg_decrypt = tcg_const_i32(decrypt);
13400 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_decrypt);
13402 tcg_temp_free_ptr(tcg_rd_ptr);
13403 tcg_temp_free_ptr(tcg_rn_ptr);
13404 tcg_temp_free_i32(tcg_decrypt);
13407 /* Crypto three-reg SHA
13408 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
13409 * +-----------------+------+---+------+---+--------+-----+------+------+
13410 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
13411 * +-----------------+------+---+------+---+--------+-----+------+------+
13413 static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn)
13415 int size = extract32(insn, 22, 2);
13416 int opcode = extract32(insn, 12, 3);
13417 int rm = extract32(insn, 16, 5);
13418 int rn = extract32(insn, 5, 5);
13419 int rd = extract32(insn, 0, 5);
13420 CryptoThreeOpFn *genfn;
13421 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13425 unallocated_encoding(s);
13430 case 0: /* SHA1C */
13431 case 1: /* SHA1P */
13432 case 2: /* SHA1M */
13433 case 3: /* SHA1SU0 */
13435 feature = dc_isar_feature(aa64_sha1, s);
13437 case 4: /* SHA256H */
13438 genfn = gen_helper_crypto_sha256h;
13439 feature = dc_isar_feature(aa64_sha256, s);
13441 case 5: /* SHA256H2 */
13442 genfn = gen_helper_crypto_sha256h2;
13443 feature = dc_isar_feature(aa64_sha256, s);
13445 case 6: /* SHA256SU1 */
13446 genfn = gen_helper_crypto_sha256su1;
13447 feature = dc_isar_feature(aa64_sha256, s);
13450 unallocated_encoding(s);
13455 unallocated_encoding(s);
13459 if (!fp_access_check(s)) {
13463 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13464 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13465 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13468 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr);
13470 TCGv_i32 tcg_opcode = tcg_const_i32(opcode);
13472 gen_helper_crypto_sha1_3reg(tcg_rd_ptr, tcg_rn_ptr,
13473 tcg_rm_ptr, tcg_opcode);
13474 tcg_temp_free_i32(tcg_opcode);
13477 tcg_temp_free_ptr(tcg_rd_ptr);
13478 tcg_temp_free_ptr(tcg_rn_ptr);
13479 tcg_temp_free_ptr(tcg_rm_ptr);
13482 /* Crypto two-reg SHA
13483 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13484 * +-----------------+------+-----------+--------+-----+------+------+
13485 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13486 * +-----------------+------+-----------+--------+-----+------+------+
13488 static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn)
13490 int size = extract32(insn, 22, 2);
13491 int opcode = extract32(insn, 12, 5);
13492 int rn = extract32(insn, 5, 5);
13493 int rd = extract32(insn, 0, 5);
13494 CryptoTwoOpFn *genfn;
13496 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
13499 unallocated_encoding(s);
13504 case 0: /* SHA1H */
13505 feature = dc_isar_feature(aa64_sha1, s);
13506 genfn = gen_helper_crypto_sha1h;
13508 case 1: /* SHA1SU1 */
13509 feature = dc_isar_feature(aa64_sha1, s);
13510 genfn = gen_helper_crypto_sha1su1;
13512 case 2: /* SHA256SU0 */
13513 feature = dc_isar_feature(aa64_sha256, s);
13514 genfn = gen_helper_crypto_sha256su0;
13517 unallocated_encoding(s);
13522 unallocated_encoding(s);
13526 if (!fp_access_check(s)) {
13530 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13531 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13533 genfn(tcg_rd_ptr, tcg_rn_ptr);
13535 tcg_temp_free_ptr(tcg_rd_ptr);
13536 tcg_temp_free_ptr(tcg_rn_ptr);
13539 /* Crypto three-reg SHA512
13540 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13541 * +-----------------------+------+---+---+-----+--------+------+------+
13542 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
13543 * +-----------------------+------+---+---+-----+--------+------+------+
13545 static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn)
13547 int opcode = extract32(insn, 10, 2);
13548 int o = extract32(insn, 14, 1);
13549 int rm = extract32(insn, 16, 5);
13550 int rn = extract32(insn, 5, 5);
13551 int rd = extract32(insn, 0, 5);
13553 CryptoThreeOpFn *genfn;
13557 case 0: /* SHA512H */
13558 feature = dc_isar_feature(aa64_sha512, s);
13559 genfn = gen_helper_crypto_sha512h;
13561 case 1: /* SHA512H2 */
13562 feature = dc_isar_feature(aa64_sha512, s);
13563 genfn = gen_helper_crypto_sha512h2;
13565 case 2: /* SHA512SU1 */
13566 feature = dc_isar_feature(aa64_sha512, s);
13567 genfn = gen_helper_crypto_sha512su1;
13570 feature = dc_isar_feature(aa64_sha3, s);
13576 case 0: /* SM3PARTW1 */
13577 feature = dc_isar_feature(aa64_sm3, s);
13578 genfn = gen_helper_crypto_sm3partw1;
13580 case 1: /* SM3PARTW2 */
13581 feature = dc_isar_feature(aa64_sm3, s);
13582 genfn = gen_helper_crypto_sm3partw2;
13584 case 2: /* SM4EKEY */
13585 feature = dc_isar_feature(aa64_sm4, s);
13586 genfn = gen_helper_crypto_sm4ekey;
13589 unallocated_encoding(s);
13595 unallocated_encoding(s);
13599 if (!fp_access_check(s)) {
13604 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13606 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13607 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13608 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13610 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr);
13612 tcg_temp_free_ptr(tcg_rd_ptr);
13613 tcg_temp_free_ptr(tcg_rn_ptr);
13614 tcg_temp_free_ptr(tcg_rm_ptr);
13616 TCGv_i64 tcg_op1, tcg_op2, tcg_res[2];
13619 tcg_op1 = tcg_temp_new_i64();
13620 tcg_op2 = tcg_temp_new_i64();
13621 tcg_res[0] = tcg_temp_new_i64();
13622 tcg_res[1] = tcg_temp_new_i64();
13624 for (pass = 0; pass < 2; pass++) {
13625 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13626 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13628 tcg_gen_rotli_i64(tcg_res[pass], tcg_op2, 1);
13629 tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
13631 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13632 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13634 tcg_temp_free_i64(tcg_op1);
13635 tcg_temp_free_i64(tcg_op2);
13636 tcg_temp_free_i64(tcg_res[0]);
13637 tcg_temp_free_i64(tcg_res[1]);
13641 /* Crypto two-reg SHA512
13642 * 31 12 11 10 9 5 4 0
13643 * +-----------------------------------------+--------+------+------+
13644 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
13645 * +-----------------------------------------+--------+------+------+
13647 static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn)
13649 int opcode = extract32(insn, 10, 2);
13650 int rn = extract32(insn, 5, 5);
13651 int rd = extract32(insn, 0, 5);
13652 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
13654 CryptoTwoOpFn *genfn;
13657 case 0: /* SHA512SU0 */
13658 feature = dc_isar_feature(aa64_sha512, s);
13659 genfn = gen_helper_crypto_sha512su0;
13662 feature = dc_isar_feature(aa64_sm4, s);
13663 genfn = gen_helper_crypto_sm4e;
13666 unallocated_encoding(s);
13671 unallocated_encoding(s);
13675 if (!fp_access_check(s)) {
13679 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13680 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13682 genfn(tcg_rd_ptr, tcg_rn_ptr);
13684 tcg_temp_free_ptr(tcg_rd_ptr);
13685 tcg_temp_free_ptr(tcg_rn_ptr);
13688 /* Crypto four-register
13689 * 31 23 22 21 20 16 15 14 10 9 5 4 0
13690 * +-------------------+-----+------+---+------+------+------+
13691 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
13692 * +-------------------+-----+------+---+------+------+------+
13694 static void disas_crypto_four_reg(DisasContext *s, uint32_t insn)
13696 int op0 = extract32(insn, 21, 2);
13697 int rm = extract32(insn, 16, 5);
13698 int ra = extract32(insn, 10, 5);
13699 int rn = extract32(insn, 5, 5);
13700 int rd = extract32(insn, 0, 5);
13706 feature = dc_isar_feature(aa64_sha3, s);
13708 case 2: /* SM3SS1 */
13709 feature = dc_isar_feature(aa64_sm3, s);
13712 unallocated_encoding(s);
13717 unallocated_encoding(s);
13721 if (!fp_access_check(s)) {
13726 TCGv_i64 tcg_op1, tcg_op2, tcg_op3, tcg_res[2];
13729 tcg_op1 = tcg_temp_new_i64();
13730 tcg_op2 = tcg_temp_new_i64();
13731 tcg_op3 = tcg_temp_new_i64();
13732 tcg_res[0] = tcg_temp_new_i64();
13733 tcg_res[1] = tcg_temp_new_i64();
13735 for (pass = 0; pass < 2; pass++) {
13736 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13737 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13738 read_vec_element(s, tcg_op3, ra, pass, MO_64);
13742 tcg_gen_xor_i64(tcg_res[pass], tcg_op2, tcg_op3);
13745 tcg_gen_andc_i64(tcg_res[pass], tcg_op2, tcg_op3);
13747 tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
13749 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13750 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13752 tcg_temp_free_i64(tcg_op1);
13753 tcg_temp_free_i64(tcg_op2);
13754 tcg_temp_free_i64(tcg_op3);
13755 tcg_temp_free_i64(tcg_res[0]);
13756 tcg_temp_free_i64(tcg_res[1]);
13758 TCGv_i32 tcg_op1, tcg_op2, tcg_op3, tcg_res, tcg_zero;
13760 tcg_op1 = tcg_temp_new_i32();
13761 tcg_op2 = tcg_temp_new_i32();
13762 tcg_op3 = tcg_temp_new_i32();
13763 tcg_res = tcg_temp_new_i32();
13764 tcg_zero = tcg_const_i32(0);
13766 read_vec_element_i32(s, tcg_op1, rn, 3, MO_32);
13767 read_vec_element_i32(s, tcg_op2, rm, 3, MO_32);
13768 read_vec_element_i32(s, tcg_op3, ra, 3, MO_32);
13770 tcg_gen_rotri_i32(tcg_res, tcg_op1, 20);
13771 tcg_gen_add_i32(tcg_res, tcg_res, tcg_op2);
13772 tcg_gen_add_i32(tcg_res, tcg_res, tcg_op3);
13773 tcg_gen_rotri_i32(tcg_res, tcg_res, 25);
13775 write_vec_element_i32(s, tcg_zero, rd, 0, MO_32);
13776 write_vec_element_i32(s, tcg_zero, rd, 1, MO_32);
13777 write_vec_element_i32(s, tcg_zero, rd, 2, MO_32);
13778 write_vec_element_i32(s, tcg_res, rd, 3, MO_32);
13780 tcg_temp_free_i32(tcg_op1);
13781 tcg_temp_free_i32(tcg_op2);
13782 tcg_temp_free_i32(tcg_op3);
13783 tcg_temp_free_i32(tcg_res);
13784 tcg_temp_free_i32(tcg_zero);
13789 * 31 21 20 16 15 10 9 5 4 0
13790 * +-----------------------+------+--------+------+------+
13791 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
13792 * +-----------------------+------+--------+------+------+
13794 static void disas_crypto_xar(DisasContext *s, uint32_t insn)
13796 int rm = extract32(insn, 16, 5);
13797 int imm6 = extract32(insn, 10, 6);
13798 int rn = extract32(insn, 5, 5);
13799 int rd = extract32(insn, 0, 5);
13800 TCGv_i64 tcg_op1, tcg_op2, tcg_res[2];
13803 if (!dc_isar_feature(aa64_sha3, s)) {
13804 unallocated_encoding(s);
13808 if (!fp_access_check(s)) {
13812 tcg_op1 = tcg_temp_new_i64();
13813 tcg_op2 = tcg_temp_new_i64();
13814 tcg_res[0] = tcg_temp_new_i64();
13815 tcg_res[1] = tcg_temp_new_i64();
13817 for (pass = 0; pass < 2; pass++) {
13818 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13819 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13821 tcg_gen_xor_i64(tcg_res[pass], tcg_op1, tcg_op2);
13822 tcg_gen_rotri_i64(tcg_res[pass], tcg_res[pass], imm6);
13824 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13825 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13827 tcg_temp_free_i64(tcg_op1);
13828 tcg_temp_free_i64(tcg_op2);
13829 tcg_temp_free_i64(tcg_res[0]);
13830 tcg_temp_free_i64(tcg_res[1]);
13833 /* Crypto three-reg imm2
13834 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13835 * +-----------------------+------+-----+------+--------+------+------+
13836 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
13837 * +-----------------------+------+-----+------+--------+------+------+
13839 static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn)
13841 int opcode = extract32(insn, 10, 2);
13842 int imm2 = extract32(insn, 12, 2);
13843 int rm = extract32(insn, 16, 5);
13844 int rn = extract32(insn, 5, 5);
13845 int rd = extract32(insn, 0, 5);
13846 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13847 TCGv_i32 tcg_imm2, tcg_opcode;
13849 if (!dc_isar_feature(aa64_sm3, s)) {
13850 unallocated_encoding(s);
13854 if (!fp_access_check(s)) {
13858 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13859 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13860 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13861 tcg_imm2 = tcg_const_i32(imm2);
13862 tcg_opcode = tcg_const_i32(opcode);
13864 gen_helper_crypto_sm3tt(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr, tcg_imm2,
13867 tcg_temp_free_ptr(tcg_rd_ptr);
13868 tcg_temp_free_ptr(tcg_rn_ptr);
13869 tcg_temp_free_ptr(tcg_rm_ptr);
13870 tcg_temp_free_i32(tcg_imm2);
13871 tcg_temp_free_i32(tcg_opcode);
13874 /* C3.6 Data processing - SIMD, inc Crypto
13876 * As the decode gets a little complex we are using a table based
13877 * approach for this part of the decode.
13879 static const AArch64DecodeTable data_proc_simd[] = {
13880 /* pattern , mask , fn */
13881 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same },
13882 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra },
13883 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff },
13884 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc },
13885 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes },
13886 { 0x0e000400, 0x9fe08400, disas_simd_copy },
13887 { 0x0f000000, 0x9f000400, disas_simd_indexed }, /* vector indexed */
13888 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
13889 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm },
13890 { 0x0f000400, 0x9f800400, disas_simd_shift_imm },
13891 { 0x0e000000, 0xbf208c00, disas_simd_tb },
13892 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn },
13893 { 0x2e000000, 0xbf208400, disas_simd_ext },
13894 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same },
13895 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra },
13896 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff },
13897 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc },
13898 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise },
13899 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy },
13900 { 0x5f000000, 0xdf000400, disas_simd_indexed }, /* scalar indexed */
13901 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm },
13902 { 0x4e280800, 0xff3e0c00, disas_crypto_aes },
13903 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha },
13904 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha },
13905 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 },
13906 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 },
13907 { 0xce000000, 0xff808000, disas_crypto_four_reg },
13908 { 0xce800000, 0xffe00000, disas_crypto_xar },
13909 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2 },
13910 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16 },
13911 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16 },
13912 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16 },
13913 { 0x00000000, 0x00000000, NULL }
13916 static void disas_data_proc_simd(DisasContext *s, uint32_t insn)
13918 /* Note that this is called with all non-FP cases from
13919 * table C3-6 so it must UNDEF for entries not specifically
13920 * allocated to instructions in that table.
13922 AArch64DecodeFn *fn = lookup_disas_fn(&data_proc_simd[0], insn);
13926 unallocated_encoding(s);
13930 /* C3.6 Data processing - SIMD and floating point */
13931 static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn)
13933 if (extract32(insn, 28, 1) == 1 && extract32(insn, 30, 1) == 0) {
13934 disas_data_proc_fp(s, insn);
13936 /* SIMD, including crypto */
13937 disas_data_proc_simd(s, insn);
13943 * @env: The cpu environment
13944 * @s: The DisasContext
13946 * Return true if the page is guarded.
13948 static bool is_guarded_page(CPUARMState *env, DisasContext *s)
13950 #ifdef CONFIG_USER_ONLY
13951 return false; /* FIXME */
13953 uint64_t addr = s->base.pc_first;
13954 int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx);
13955 unsigned int index = tlb_index(env, mmu_idx, addr);
13956 CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr);
13959 * We test this immediately after reading an insn, which means
13960 * that any normal page must be in the TLB. The only exception
13961 * would be for executing from flash or device memory, which
13962 * does not retain the TLB entry.
13964 * FIXME: Assume false for those, for now. We could use
13965 * arm_cpu_get_phys_page_attrs_debug to re-read the page
13966 * table entry even for that case.
13968 return (tlb_hit(entry->addr_code, addr) &&
13969 env_tlb(env)->d[mmu_idx].iotlb[index].attrs.target_tlb_bit0);
13974 * btype_destination_ok:
13975 * @insn: The instruction at the branch destination
13976 * @bt: SCTLR_ELx.BT
13977 * @btype: PSTATE.BTYPE, and is non-zero
13979 * On a guarded page, there are a limited number of insns
13980 * that may be present at the branch target:
13981 * - branch target identifiers,
13982 * - paciasp, pacibsp,
13985 * Anything else causes a Branch Target Exception.
13987 * Return true if the branch is compatible, false to raise BTITRAP.
13989 static bool btype_destination_ok(uint32_t insn, bool bt, int btype)
13991 if ((insn & 0xfffff01fu) == 0xd503201fu) {
13993 switch (extract32(insn, 5, 7)) {
13994 case 0b011001: /* PACIASP */
13995 case 0b011011: /* PACIBSP */
13997 * If SCTLR_ELx.BT, then PACI*SP are not compatible
13998 * with btype == 3. Otherwise all btype are ok.
14000 return !bt || btype != 3;
14001 case 0b100000: /* BTI */
14002 /* Not compatible with any btype. */
14004 case 0b100010: /* BTI c */
14005 /* Not compatible with btype == 3 */
14007 case 0b100100: /* BTI j */
14008 /* Not compatible with btype == 2 */
14010 case 0b100110: /* BTI jc */
14011 /* Compatible with any btype. */
14015 switch (insn & 0xffe0001fu) {
14016 case 0xd4200000u: /* BRK */
14017 case 0xd4400000u: /* HLT */
14018 /* Give priority to the breakpoint exception. */
14025 /* C3.1 A64 instruction index by encoding */
14026 static void disas_a64_insn(CPUARMState *env, DisasContext *s)
14030 s->pc_curr = s->base.pc_next;
14031 insn = arm_ldl_code(env, s->base.pc_next, s->sctlr_b);
14033 s->base.pc_next += 4;
14035 s->fp_access_checked = false;
14037 if (dc_isar_feature(aa64_bti, s)) {
14038 if (s->base.num_insns == 1) {
14040 * At the first insn of the TB, compute s->guarded_page.
14041 * We delayed computing this until successfully reading
14042 * the first insn of the TB, above. This (mostly) ensures
14043 * that the softmmu tlb entry has been populated, and the
14044 * page table GP bit is available.
14046 * Note that we need to compute this even if btype == 0,
14047 * because this value is used for BR instructions later
14048 * where ENV is not available.
14050 s->guarded_page = is_guarded_page(env, s);
14052 /* First insn can have btype set to non-zero. */
14053 tcg_debug_assert(s->btype >= 0);
14056 * Note that the Branch Target Exception has fairly high
14057 * priority -- below debugging exceptions but above most
14058 * everything else. This allows us to handle this now
14059 * instead of waiting until the insn is otherwise decoded.
14063 && !btype_destination_ok(insn, s->bt, s->btype)) {
14064 gen_exception_insn(s, s->pc_curr, EXCP_UDEF,
14065 syn_btitrap(s->btype),
14066 default_exception_el(s));
14070 /* Not the first insn: btype must be 0. */
14071 tcg_debug_assert(s->btype == 0);
14075 switch (extract32(insn, 25, 4)) {
14076 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
14077 unallocated_encoding(s);
14080 if (!dc_isar_feature(aa64_sve, s) || !disas_sve(s, insn)) {
14081 unallocated_encoding(s);
14084 case 0x8: case 0x9: /* Data processing - immediate */
14085 disas_data_proc_imm(s, insn);
14087 case 0xa: case 0xb: /* Branch, exception generation and system insns */
14088 disas_b_exc_sys(s, insn);
14093 case 0xe: /* Loads and stores */
14094 disas_ldst(s, insn);
14097 case 0xd: /* Data processing - register */
14098 disas_data_proc_reg(s, insn);
14101 case 0xf: /* Data processing - SIMD and floating point */
14102 disas_data_proc_simd_fp(s, insn);
14105 assert(FALSE); /* all 15 cases should be handled above */
14109 /* if we allocated any temporaries, free them here */
14113 * After execution of most insns, btype is reset to 0.
14114 * Note that we set btype == -1 when the insn sets btype.
14116 if (s->btype > 0 && s->base.is_jmp != DISAS_NORETURN) {
14121 static void aarch64_tr_init_disas_context(DisasContextBase *dcbase,
14124 DisasContext *dc = container_of(dcbase, DisasContext, base);
14125 CPUARMState *env = cpu->env_ptr;
14126 ARMCPU *arm_cpu = env_archcpu(env);
14127 uint32_t tb_flags = dc->base.tb->flags;
14128 int bound, core_mmu_idx;
14130 dc->isar = &arm_cpu->isar;
14134 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
14135 * there is no secure EL1, so we route exceptions to EL3.
14137 dc->secure_routed_to_el3 = arm_feature(env, ARM_FEATURE_EL3) &&
14138 !arm_el_is_aa64(env, 3);
14141 dc->be_data = FIELD_EX32(tb_flags, TBFLAG_ANY, BE_DATA) ? MO_BE : MO_LE;
14142 dc->condexec_mask = 0;
14143 dc->condexec_cond = 0;
14144 core_mmu_idx = FIELD_EX32(tb_flags, TBFLAG_ANY, MMUIDX);
14145 dc->mmu_idx = core_to_arm_mmu_idx(env, core_mmu_idx);
14146 dc->tbii = FIELD_EX32(tb_flags, TBFLAG_A64, TBII);
14147 dc->tbid = FIELD_EX32(tb_flags, TBFLAG_A64, TBID);
14148 dc->current_el = arm_mmu_idx_to_el(dc->mmu_idx);
14149 #if !defined(CONFIG_USER_ONLY)
14150 dc->user = (dc->current_el == 0);
14152 dc->fp_excp_el = FIELD_EX32(tb_flags, TBFLAG_ANY, FPEXC_EL);
14153 dc->sve_excp_el = FIELD_EX32(tb_flags, TBFLAG_A64, SVEEXC_EL);
14154 dc->sve_len = (FIELD_EX32(tb_flags, TBFLAG_A64, ZCR_LEN) + 1) * 16;
14155 dc->pauth_active = FIELD_EX32(tb_flags, TBFLAG_A64, PAUTH_ACTIVE);
14156 dc->bt = FIELD_EX32(tb_flags, TBFLAG_A64, BT);
14157 dc->btype = FIELD_EX32(tb_flags, TBFLAG_A64, BTYPE);
14159 dc->vec_stride = 0;
14160 dc->cp_regs = arm_cpu->cp_regs;
14161 dc->features = env->features;
14163 /* Single step state. The code-generation logic here is:
14165 * generate code with no special handling for single-stepping (except
14166 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
14167 * this happens anyway because those changes are all system register or
14169 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
14170 * emit code for one insn
14171 * emit code to clear PSTATE.SS
14172 * emit code to generate software step exception for completed step
14173 * end TB (as usual for having generated an exception)
14174 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
14175 * emit code to generate a software step exception
14178 dc->ss_active = FIELD_EX32(tb_flags, TBFLAG_ANY, SS_ACTIVE);
14179 dc->pstate_ss = FIELD_EX32(tb_flags, TBFLAG_ANY, PSTATE_SS);
14180 dc->is_ldex = false;
14181 dc->debug_target_el = FIELD_EX32(tb_flags, TBFLAG_ANY, DEBUG_TARGET_EL);
14183 /* Bound the number of insns to execute to those left on the page. */
14184 bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
14186 /* If architectural single step active, limit to 1. */
14187 if (dc->ss_active) {
14190 dc->base.max_insns = MIN(dc->base.max_insns, bound);
14192 init_tmp_a64_array(dc);
14195 static void aarch64_tr_tb_start(DisasContextBase *db, CPUState *cpu)
14199 static void aarch64_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
14201 DisasContext *dc = container_of(dcbase, DisasContext, base);
14203 tcg_gen_insn_start(dc->base.pc_next, 0, 0);
14204 dc->insn_start = tcg_last_op();
14207 static bool aarch64_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu,
14208 const CPUBreakpoint *bp)
14210 DisasContext *dc = container_of(dcbase, DisasContext, base);
14212 if (bp->flags & BP_CPU) {
14213 gen_a64_set_pc_im(dc->base.pc_next);
14214 gen_helper_check_breakpoints(cpu_env);
14215 /* End the TB early; it likely won't be executed */
14216 dc->base.is_jmp = DISAS_TOO_MANY;
14218 gen_exception_internal_insn(dc, dc->base.pc_next, EXCP_DEBUG);
14219 /* The address covered by the breakpoint must be
14220 included in [tb->pc, tb->pc + tb->size) in order
14221 to for it to be properly cleared -- thus we
14222 increment the PC here so that the logic setting
14223 tb->size below does the right thing. */
14224 dc->base.pc_next += 4;
14225 dc->base.is_jmp = DISAS_NORETURN;
14231 static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
14233 DisasContext *dc = container_of(dcbase, DisasContext, base);
14234 CPUARMState *env = cpu->env_ptr;
14236 if (dc->ss_active && !dc->pstate_ss) {
14237 /* Singlestep state is Active-pending.
14238 * If we're in this state at the start of a TB then either
14239 * a) we just took an exception to an EL which is being debugged
14240 * and this is the first insn in the exception handler
14241 * b) debug exceptions were masked and we just unmasked them
14242 * without changing EL (eg by clearing PSTATE.D)
14243 * In either case we're going to take a swstep exception in the
14244 * "did not step an insn" case, and so the syndrome ISV and EX
14245 * bits should be zero.
14247 assert(dc->base.num_insns == 1);
14248 gen_swstep_exception(dc, 0, 0);
14249 dc->base.is_jmp = DISAS_NORETURN;
14251 disas_a64_insn(env, dc);
14254 translator_loop_temp_check(&dc->base);
14257 static void aarch64_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
14259 DisasContext *dc = container_of(dcbase, DisasContext, base);
14261 if (unlikely(dc->base.singlestep_enabled || dc->ss_active)) {
14262 /* Note that this means single stepping WFI doesn't halt the CPU.
14263 * For conditional branch insns this is harmless unreachable code as
14264 * gen_goto_tb() has already handled emitting the debug exception
14265 * (and thus a tb-jump is not possible when singlestepping).
14267 switch (dc->base.is_jmp) {
14269 gen_a64_set_pc_im(dc->base.pc_next);
14273 if (dc->base.singlestep_enabled) {
14274 gen_exception_internal(EXCP_DEBUG);
14276 gen_step_complete_exception(dc);
14279 case DISAS_NORETURN:
14283 switch (dc->base.is_jmp) {
14285 case DISAS_TOO_MANY:
14286 gen_goto_tb(dc, 1, dc->base.pc_next);
14290 gen_a64_set_pc_im(dc->base.pc_next);
14293 tcg_gen_exit_tb(NULL, 0);
14296 tcg_gen_lookup_and_goto_ptr();
14298 case DISAS_NORETURN:
14302 gen_a64_set_pc_im(dc->base.pc_next);
14303 gen_helper_wfe(cpu_env);
14306 gen_a64_set_pc_im(dc->base.pc_next);
14307 gen_helper_yield(cpu_env);
14311 /* This is a special case because we don't want to just halt the CPU
14312 * if trying to debug across a WFI.
14314 TCGv_i32 tmp = tcg_const_i32(4);
14316 gen_a64_set_pc_im(dc->base.pc_next);
14317 gen_helper_wfi(cpu_env, tmp);
14318 tcg_temp_free_i32(tmp);
14319 /* The helper doesn't necessarily throw an exception, but we
14320 * must go back to the main loop to check for interrupts anyway.
14322 tcg_gen_exit_tb(NULL, 0);
14329 static void aarch64_tr_disas_log(const DisasContextBase *dcbase,
14332 DisasContext *dc = container_of(dcbase, DisasContext, base);
14334 qemu_log("IN: %s\n", lookup_symbol(dc->base.pc_first));
14335 log_target_disas(cpu, dc->base.pc_first, dc->base.tb->size);
14338 const TranslatorOps aarch64_translator_ops = {
14339 .init_disas_context = aarch64_tr_init_disas_context,
14340 .tb_start = aarch64_tr_tb_start,
14341 .insn_start = aarch64_tr_insn_start,
14342 .breakpoint_check = aarch64_tr_breakpoint_check,
14343 .translate_insn = aarch64_tr_translate_insn,
14344 .tb_stop = aarch64_tr_tb_stop,
14345 .disas_log = aarch64_tr_disas_log,