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 "exec/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 void aarch64_cpu_dump_state(CPUState *cs, FILE *f,
132 fprintf_function cpu_fprintf, int flags)
134 ARMCPU *cpu = ARM_CPU(cs);
135 CPUARMState *env = &cpu->env;
136 uint32_t psr = pstate_read(env);
138 int el = arm_current_el(env);
139 const char *ns_status;
141 cpu_fprintf(f, " PC=%016" PRIx64 " ", env->pc);
142 for (i = 0; i < 32; i++) {
144 cpu_fprintf(f, " SP=%016" PRIx64 "\n", env->xregs[i]);
146 cpu_fprintf(f, "X%02d=%016" PRIx64 "%s", i, env->xregs[i],
147 (i + 2) % 3 ? " " : "\n");
151 if (arm_feature(env, ARM_FEATURE_EL3) && el != 3) {
152 ns_status = env->cp15.scr_el3 & SCR_NS ? "NS " : "S ";
156 cpu_fprintf(f, "PSTATE=%08x %c%c%c%c %sEL%d%c",
158 psr & PSTATE_N ? 'N' : '-',
159 psr & PSTATE_Z ? 'Z' : '-',
160 psr & PSTATE_C ? 'C' : '-',
161 psr & PSTATE_V ? 'V' : '-',
164 psr & PSTATE_SP ? 'h' : 't');
166 if (!(flags & CPU_DUMP_FPU)) {
167 cpu_fprintf(f, "\n");
170 if (fp_exception_el(env, el) != 0) {
171 cpu_fprintf(f, " FPU disabled\n");
174 cpu_fprintf(f, " FPCR=%08x FPSR=%08x\n",
175 vfp_get_fpcr(env), vfp_get_fpsr(env));
177 if (cpu_isar_feature(aa64_sve, cpu) && sve_exception_el(env, el) == 0) {
178 int j, zcr_len = sve_zcr_len_for_el(env, el);
180 for (i = 0; i <= FFR_PRED_NUM; i++) {
182 if (i == FFR_PRED_NUM) {
183 cpu_fprintf(f, "FFR=");
184 /* It's last, so end the line. */
187 cpu_fprintf(f, "P%02d=", i);
200 /* More than one quadword per predicate. */
205 for (j = zcr_len / 4; j >= 0; j--) {
207 if (j * 4 + 4 <= zcr_len + 1) {
210 digits = (zcr_len % 4 + 1) * 4;
212 cpu_fprintf(f, "%0*" PRIx64 "%s", digits,
213 env->vfp.pregs[i].p[j],
214 j ? ":" : eol ? "\n" : " ");
218 for (i = 0; i < 32; i++) {
220 cpu_fprintf(f, "Z%02d=%016" PRIx64 ":%016" PRIx64 "%s",
221 i, env->vfp.zregs[i].d[1],
222 env->vfp.zregs[i].d[0], i & 1 ? "\n" : " ");
223 } else if (zcr_len == 1) {
224 cpu_fprintf(f, "Z%02d=%016" PRIx64 ":%016" PRIx64
225 ":%016" PRIx64 ":%016" PRIx64 "\n",
226 i, env->vfp.zregs[i].d[3], env->vfp.zregs[i].d[2],
227 env->vfp.zregs[i].d[1], env->vfp.zregs[i].d[0]);
229 for (j = zcr_len; j >= 0; j--) {
230 bool odd = (zcr_len - j) % 2 != 0;
232 cpu_fprintf(f, "Z%02d[%x-%x]=", i, j, j - 1);
235 cpu_fprintf(f, " [%x-%x]=", j, j - 1);
237 cpu_fprintf(f, " [%x]=", j);
240 cpu_fprintf(f, "%016" PRIx64 ":%016" PRIx64 "%s",
241 env->vfp.zregs[i].d[j * 2 + 1],
242 env->vfp.zregs[i].d[j * 2],
243 odd || j == 0 ? "\n" : ":");
248 for (i = 0; i < 32; i++) {
249 uint64_t *q = aa64_vfp_qreg(env, i);
250 cpu_fprintf(f, "Q%02d=%016" PRIx64 ":%016" PRIx64 "%s",
251 i, q[1], q[0], (i & 1 ? "\n" : " "));
256 void gen_a64_set_pc_im(uint64_t val)
258 tcg_gen_movi_i64(cpu_pc, val);
261 /* Load the PC from a generic TCG variable.
263 * If address tagging is enabled via the TCR TBI bits, then loading
264 * an address into the PC will clear out any tag in it:
265 * + for EL2 and EL3 there is only one TBI bit, and if it is set
266 * then the address is zero-extended, clearing bits [63:56]
267 * + for EL0 and EL1, TBI0 controls addresses with bit 55 == 0
268 * and TBI1 controls addressses with bit 55 == 1.
269 * If the appropriate TBI bit is set for the address then
270 * the address is sign-extended from bit 55 into bits [63:56]
272 * We can avoid doing this for relative-branches, because the
273 * PC + offset can never overflow into the tag bits (assuming
274 * that virtual addresses are less than 56 bits wide, as they
275 * are currently), but we must handle it for branch-to-register.
277 static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src)
279 /* Note that TBII is TBI1:TBI0. */
282 if (s->current_el <= 1) {
284 /* Sign-extend from bit 55. */
285 tcg_gen_sextract_i64(cpu_pc, src, 0, 56);
288 TCGv_i64 tcg_zero = tcg_const_i64(0);
291 * The two TBI bits differ.
292 * If tbi0, then !tbi1: only use the extension if positive.
293 * if !tbi0, then tbi1: only use the extension if negative.
295 tcg_gen_movcond_i64(tbi == 1 ? TCG_COND_GE : TCG_COND_LT,
296 cpu_pc, cpu_pc, tcg_zero, cpu_pc, src);
297 tcg_temp_free_i64(tcg_zero);
303 /* Force tag byte to all zero */
304 tcg_gen_extract_i64(cpu_pc, src, 0, 56);
309 /* Load unmodified address */
310 tcg_gen_mov_i64(cpu_pc, src);
313 typedef struct DisasCompare64 {
318 static void a64_test_cc(DisasCompare64 *c64, int cc)
322 arm_test_cc(&c32, cc);
324 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
325 * properly. The NE/EQ comparisons are also fine with this choice. */
326 c64->cond = c32.cond;
327 c64->value = tcg_temp_new_i64();
328 tcg_gen_ext_i32_i64(c64->value, c32.value);
333 static void a64_free_cc(DisasCompare64 *c64)
335 tcg_temp_free_i64(c64->value);
338 static void gen_exception_internal(int excp)
340 TCGv_i32 tcg_excp = tcg_const_i32(excp);
342 assert(excp_is_internal(excp));
343 gen_helper_exception_internal(cpu_env, tcg_excp);
344 tcg_temp_free_i32(tcg_excp);
347 static void gen_exception(int excp, uint32_t syndrome, uint32_t target_el)
349 TCGv_i32 tcg_excp = tcg_const_i32(excp);
350 TCGv_i32 tcg_syn = tcg_const_i32(syndrome);
351 TCGv_i32 tcg_el = tcg_const_i32(target_el);
353 gen_helper_exception_with_syndrome(cpu_env, tcg_excp,
355 tcg_temp_free_i32(tcg_el);
356 tcg_temp_free_i32(tcg_syn);
357 tcg_temp_free_i32(tcg_excp);
360 static void gen_exception_internal_insn(DisasContext *s, int offset, int excp)
362 gen_a64_set_pc_im(s->pc - offset);
363 gen_exception_internal(excp);
364 s->base.is_jmp = DISAS_NORETURN;
367 static void gen_exception_insn(DisasContext *s, int offset, int excp,
368 uint32_t syndrome, uint32_t target_el)
370 gen_a64_set_pc_im(s->pc - offset);
371 gen_exception(excp, syndrome, target_el);
372 s->base.is_jmp = DISAS_NORETURN;
375 static void gen_exception_bkpt_insn(DisasContext *s, int offset,
380 gen_a64_set_pc_im(s->pc - offset);
381 tcg_syn = tcg_const_i32(syndrome);
382 gen_helper_exception_bkpt_insn(cpu_env, tcg_syn);
383 tcg_temp_free_i32(tcg_syn);
384 s->base.is_jmp = DISAS_NORETURN;
387 static void gen_ss_advance(DisasContext *s)
389 /* If the singlestep state is Active-not-pending, advance to
394 gen_helper_clear_pstate_ss(cpu_env);
398 static void gen_step_complete_exception(DisasContext *s)
400 /* We just completed step of an insn. Move from Active-not-pending
401 * to Active-pending, and then also take the swstep exception.
402 * This corresponds to making the (IMPDEF) choice to prioritize
403 * swstep exceptions over asynchronous exceptions taken to an exception
404 * level where debug is disabled. This choice has the advantage that
405 * we do not need to maintain internal state corresponding to the
406 * ISV/EX syndrome bits between completion of the step and generation
407 * of the exception, and our syndrome information is always correct.
410 gen_exception(EXCP_UDEF, syn_swstep(s->ss_same_el, 1, s->is_ldex),
411 default_exception_el(s));
412 s->base.is_jmp = DISAS_NORETURN;
415 static inline bool use_goto_tb(DisasContext *s, int n, uint64_t dest)
417 /* No direct tb linking with singlestep (either QEMU's or the ARM
418 * debug architecture kind) or deterministic io
420 if (s->base.singlestep_enabled || s->ss_active ||
421 (tb_cflags(s->base.tb) & CF_LAST_IO)) {
425 #ifndef CONFIG_USER_ONLY
426 /* Only link tbs from inside the same guest page */
427 if ((s->base.tb->pc & TARGET_PAGE_MASK) != (dest & TARGET_PAGE_MASK)) {
435 static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)
437 TranslationBlock *tb;
440 if (use_goto_tb(s, n, dest)) {
442 gen_a64_set_pc_im(dest);
443 tcg_gen_exit_tb(tb, n);
444 s->base.is_jmp = DISAS_NORETURN;
446 gen_a64_set_pc_im(dest);
448 gen_step_complete_exception(s);
449 } else if (s->base.singlestep_enabled) {
450 gen_exception_internal(EXCP_DEBUG);
452 tcg_gen_lookup_and_goto_ptr();
453 s->base.is_jmp = DISAS_NORETURN;
458 void unallocated_encoding(DisasContext *s)
460 /* Unallocated and reserved encodings are uncategorized */
461 gen_exception_insn(s, 4, EXCP_UDEF, syn_uncategorized(),
462 default_exception_el(s));
465 static void init_tmp_a64_array(DisasContext *s)
467 #ifdef CONFIG_DEBUG_TCG
468 memset(s->tmp_a64, 0, sizeof(s->tmp_a64));
470 s->tmp_a64_count = 0;
473 static void free_tmp_a64(DisasContext *s)
476 for (i = 0; i < s->tmp_a64_count; i++) {
477 tcg_temp_free_i64(s->tmp_a64[i]);
479 init_tmp_a64_array(s);
482 TCGv_i64 new_tmp_a64(DisasContext *s)
484 assert(s->tmp_a64_count < TMP_A64_MAX);
485 return s->tmp_a64[s->tmp_a64_count++] = tcg_temp_new_i64();
488 TCGv_i64 new_tmp_a64_zero(DisasContext *s)
490 TCGv_i64 t = new_tmp_a64(s);
491 tcg_gen_movi_i64(t, 0);
496 * Register access functions
498 * These functions are used for directly accessing a register in where
499 * changes to the final register value are likely to be made. If you
500 * need to use a register for temporary calculation (e.g. index type
501 * operations) use the read_* form.
503 * B1.2.1 Register mappings
505 * In instruction register encoding 31 can refer to ZR (zero register) or
506 * the SP (stack pointer) depending on context. In QEMU's case we map SP
507 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
508 * This is the point of the _sp forms.
510 TCGv_i64 cpu_reg(DisasContext *s, int reg)
513 return new_tmp_a64_zero(s);
519 /* register access for when 31 == SP */
520 TCGv_i64 cpu_reg_sp(DisasContext *s, int reg)
525 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
526 * representing the register contents. This TCGv is an auto-freed
527 * temporary so it need not be explicitly freed, and may be modified.
529 TCGv_i64 read_cpu_reg(DisasContext *s, int reg, int sf)
531 TCGv_i64 v = new_tmp_a64(s);
534 tcg_gen_mov_i64(v, cpu_X[reg]);
536 tcg_gen_ext32u_i64(v, cpu_X[reg]);
539 tcg_gen_movi_i64(v, 0);
544 TCGv_i64 read_cpu_reg_sp(DisasContext *s, int reg, int sf)
546 TCGv_i64 v = new_tmp_a64(s);
548 tcg_gen_mov_i64(v, cpu_X[reg]);
550 tcg_gen_ext32u_i64(v, cpu_X[reg]);
555 /* Return the offset into CPUARMState of a slice (from
556 * the least significant end) of FP register Qn (ie
558 * (Note that this is not the same mapping as for A32; see cpu.h)
560 static inline int fp_reg_offset(DisasContext *s, int regno, TCGMemOp size)
562 return vec_reg_offset(s, regno, 0, size);
565 /* Offset of the high half of the 128 bit vector Qn */
566 static inline int fp_reg_hi_offset(DisasContext *s, int regno)
568 return vec_reg_offset(s, regno, 1, MO_64);
571 /* Convenience accessors for reading and writing single and double
572 * FP registers. Writing clears the upper parts of the associated
573 * 128 bit vector register, as required by the architecture.
574 * Note that unlike the GP register accessors, the values returned
575 * by the read functions must be manually freed.
577 static TCGv_i64 read_fp_dreg(DisasContext *s, int reg)
579 TCGv_i64 v = tcg_temp_new_i64();
581 tcg_gen_ld_i64(v, cpu_env, fp_reg_offset(s, reg, MO_64));
585 static TCGv_i32 read_fp_sreg(DisasContext *s, int reg)
587 TCGv_i32 v = tcg_temp_new_i32();
589 tcg_gen_ld_i32(v, cpu_env, fp_reg_offset(s, reg, MO_32));
593 static TCGv_i32 read_fp_hreg(DisasContext *s, int reg)
595 TCGv_i32 v = tcg_temp_new_i32();
597 tcg_gen_ld16u_i32(v, cpu_env, fp_reg_offset(s, reg, MO_16));
601 /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64).
602 * If SVE is not enabled, then there are only 128 bits in the vector.
604 static void clear_vec_high(DisasContext *s, bool is_q, int rd)
606 unsigned ofs = fp_reg_offset(s, rd, MO_64);
607 unsigned vsz = vec_full_reg_size(s);
610 TCGv_i64 tcg_zero = tcg_const_i64(0);
611 tcg_gen_st_i64(tcg_zero, cpu_env, ofs + 8);
612 tcg_temp_free_i64(tcg_zero);
615 tcg_gen_gvec_dup8i(ofs + 16, vsz - 16, vsz - 16, 0);
619 void write_fp_dreg(DisasContext *s, int reg, TCGv_i64 v)
621 unsigned ofs = fp_reg_offset(s, reg, MO_64);
623 tcg_gen_st_i64(v, cpu_env, ofs);
624 clear_vec_high(s, false, reg);
627 static void write_fp_sreg(DisasContext *s, int reg, TCGv_i32 v)
629 TCGv_i64 tmp = tcg_temp_new_i64();
631 tcg_gen_extu_i32_i64(tmp, v);
632 write_fp_dreg(s, reg, tmp);
633 tcg_temp_free_i64(tmp);
636 TCGv_ptr get_fpstatus_ptr(bool is_f16)
638 TCGv_ptr statusptr = tcg_temp_new_ptr();
641 /* In A64 all instructions (both FP and Neon) use the FPCR; there
642 * is no equivalent of the A32 Neon "standard FPSCR value".
643 * However half-precision operations operate under a different
644 * FZ16 flag and use vfp.fp_status_f16 instead of vfp.fp_status.
647 offset = offsetof(CPUARMState, vfp.fp_status_f16);
649 offset = offsetof(CPUARMState, vfp.fp_status);
651 tcg_gen_addi_ptr(statusptr, cpu_env, offset);
655 /* Expand a 2-operand AdvSIMD vector operation using an expander function. */
656 static void gen_gvec_fn2(DisasContext *s, bool is_q, int rd, int rn,
657 GVecGen2Fn *gvec_fn, int vece)
659 gvec_fn(vece, vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
660 is_q ? 16 : 8, vec_full_reg_size(s));
663 /* Expand a 2-operand + immediate AdvSIMD vector operation using
664 * an expander function.
666 static void gen_gvec_fn2i(DisasContext *s, bool is_q, int rd, int rn,
667 int64_t imm, GVecGen2iFn *gvec_fn, int vece)
669 gvec_fn(vece, vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
670 imm, is_q ? 16 : 8, vec_full_reg_size(s));
673 /* Expand a 3-operand AdvSIMD vector operation using an expander function. */
674 static void gen_gvec_fn3(DisasContext *s, bool is_q, int rd, int rn, int rm,
675 GVecGen3Fn *gvec_fn, int vece)
677 gvec_fn(vece, vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
678 vec_full_reg_offset(s, rm), is_q ? 16 : 8, vec_full_reg_size(s));
681 /* Expand a 2-operand + immediate AdvSIMD vector operation using
684 static void gen_gvec_op2i(DisasContext *s, bool is_q, int rd,
685 int rn, int64_t imm, const GVecGen2i *gvec_op)
687 tcg_gen_gvec_2i(vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
688 is_q ? 16 : 8, vec_full_reg_size(s), imm, gvec_op);
691 /* Expand a 3-operand AdvSIMD vector operation using an op descriptor. */
692 static void gen_gvec_op3(DisasContext *s, bool is_q, int rd,
693 int rn, int rm, const GVecGen3 *gvec_op)
695 tcg_gen_gvec_3(vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
696 vec_full_reg_offset(s, rm), is_q ? 16 : 8,
697 vec_full_reg_size(s), gvec_op);
700 /* Expand a 3-operand operation using an out-of-line helper. */
701 static void gen_gvec_op3_ool(DisasContext *s, bool is_q, int rd,
702 int rn, int rm, int data, gen_helper_gvec_3 *fn)
704 tcg_gen_gvec_3_ool(vec_full_reg_offset(s, rd),
705 vec_full_reg_offset(s, rn),
706 vec_full_reg_offset(s, rm),
707 is_q ? 16 : 8, vec_full_reg_size(s), data, fn);
710 /* Expand a 3-operand + env pointer operation using
711 * an out-of-line helper.
713 static void gen_gvec_op3_env(DisasContext *s, bool is_q, int rd,
714 int rn, int rm, gen_helper_gvec_3_ptr *fn)
716 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
717 vec_full_reg_offset(s, rn),
718 vec_full_reg_offset(s, rm), cpu_env,
719 is_q ? 16 : 8, vec_full_reg_size(s), 0, fn);
722 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
723 * an out-of-line helper.
725 static void gen_gvec_op3_fpst(DisasContext *s, bool is_q, int rd, int rn,
726 int rm, bool is_fp16, int data,
727 gen_helper_gvec_3_ptr *fn)
729 TCGv_ptr fpst = get_fpstatus_ptr(is_fp16);
730 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
731 vec_full_reg_offset(s, rn),
732 vec_full_reg_offset(s, rm), fpst,
733 is_q ? 16 : 8, vec_full_reg_size(s), data, fn);
734 tcg_temp_free_ptr(fpst);
737 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
738 * than the 32 bit equivalent.
740 static inline void gen_set_NZ64(TCGv_i64 result)
742 tcg_gen_extr_i64_i32(cpu_ZF, cpu_NF, result);
743 tcg_gen_or_i32(cpu_ZF, cpu_ZF, cpu_NF);
746 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
747 static inline void gen_logic_CC(int sf, TCGv_i64 result)
750 gen_set_NZ64(result);
752 tcg_gen_extrl_i64_i32(cpu_ZF, result);
753 tcg_gen_mov_i32(cpu_NF, cpu_ZF);
755 tcg_gen_movi_i32(cpu_CF, 0);
756 tcg_gen_movi_i32(cpu_VF, 0);
759 /* dest = T0 + T1; compute C, N, V and Z flags */
760 static void gen_add_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
763 TCGv_i64 result, flag, tmp;
764 result = tcg_temp_new_i64();
765 flag = tcg_temp_new_i64();
766 tmp = tcg_temp_new_i64();
768 tcg_gen_movi_i64(tmp, 0);
769 tcg_gen_add2_i64(result, flag, t0, tmp, t1, tmp);
771 tcg_gen_extrl_i64_i32(cpu_CF, flag);
773 gen_set_NZ64(result);
775 tcg_gen_xor_i64(flag, result, t0);
776 tcg_gen_xor_i64(tmp, t0, t1);
777 tcg_gen_andc_i64(flag, flag, tmp);
778 tcg_temp_free_i64(tmp);
779 tcg_gen_extrh_i64_i32(cpu_VF, flag);
781 tcg_gen_mov_i64(dest, result);
782 tcg_temp_free_i64(result);
783 tcg_temp_free_i64(flag);
785 /* 32 bit arithmetic */
786 TCGv_i32 t0_32 = tcg_temp_new_i32();
787 TCGv_i32 t1_32 = tcg_temp_new_i32();
788 TCGv_i32 tmp = tcg_temp_new_i32();
790 tcg_gen_movi_i32(tmp, 0);
791 tcg_gen_extrl_i64_i32(t0_32, t0);
792 tcg_gen_extrl_i64_i32(t1_32, t1);
793 tcg_gen_add2_i32(cpu_NF, cpu_CF, t0_32, tmp, t1_32, tmp);
794 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
795 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
796 tcg_gen_xor_i32(tmp, t0_32, t1_32);
797 tcg_gen_andc_i32(cpu_VF, cpu_VF, tmp);
798 tcg_gen_extu_i32_i64(dest, cpu_NF);
800 tcg_temp_free_i32(tmp);
801 tcg_temp_free_i32(t0_32);
802 tcg_temp_free_i32(t1_32);
806 /* dest = T0 - T1; compute C, N, V and Z flags */
807 static void gen_sub_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
810 /* 64 bit arithmetic */
811 TCGv_i64 result, flag, tmp;
813 result = tcg_temp_new_i64();
814 flag = tcg_temp_new_i64();
815 tcg_gen_sub_i64(result, t0, t1);
817 gen_set_NZ64(result);
819 tcg_gen_setcond_i64(TCG_COND_GEU, flag, t0, t1);
820 tcg_gen_extrl_i64_i32(cpu_CF, flag);
822 tcg_gen_xor_i64(flag, result, t0);
823 tmp = tcg_temp_new_i64();
824 tcg_gen_xor_i64(tmp, t0, t1);
825 tcg_gen_and_i64(flag, flag, tmp);
826 tcg_temp_free_i64(tmp);
827 tcg_gen_extrh_i64_i32(cpu_VF, flag);
828 tcg_gen_mov_i64(dest, result);
829 tcg_temp_free_i64(flag);
830 tcg_temp_free_i64(result);
832 /* 32 bit arithmetic */
833 TCGv_i32 t0_32 = tcg_temp_new_i32();
834 TCGv_i32 t1_32 = tcg_temp_new_i32();
837 tcg_gen_extrl_i64_i32(t0_32, t0);
838 tcg_gen_extrl_i64_i32(t1_32, t1);
839 tcg_gen_sub_i32(cpu_NF, t0_32, t1_32);
840 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
841 tcg_gen_setcond_i32(TCG_COND_GEU, cpu_CF, t0_32, t1_32);
842 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
843 tmp = tcg_temp_new_i32();
844 tcg_gen_xor_i32(tmp, t0_32, t1_32);
845 tcg_temp_free_i32(t0_32);
846 tcg_temp_free_i32(t1_32);
847 tcg_gen_and_i32(cpu_VF, cpu_VF, tmp);
848 tcg_temp_free_i32(tmp);
849 tcg_gen_extu_i32_i64(dest, cpu_NF);
853 /* dest = T0 + T1 + CF; do not compute flags. */
854 static void gen_adc(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
856 TCGv_i64 flag = tcg_temp_new_i64();
857 tcg_gen_extu_i32_i64(flag, cpu_CF);
858 tcg_gen_add_i64(dest, t0, t1);
859 tcg_gen_add_i64(dest, dest, flag);
860 tcg_temp_free_i64(flag);
863 tcg_gen_ext32u_i64(dest, dest);
867 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
868 static void gen_adc_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
871 TCGv_i64 result, cf_64, vf_64, tmp;
872 result = tcg_temp_new_i64();
873 cf_64 = tcg_temp_new_i64();
874 vf_64 = tcg_temp_new_i64();
875 tmp = tcg_const_i64(0);
877 tcg_gen_extu_i32_i64(cf_64, cpu_CF);
878 tcg_gen_add2_i64(result, cf_64, t0, tmp, cf_64, tmp);
879 tcg_gen_add2_i64(result, cf_64, result, cf_64, t1, tmp);
880 tcg_gen_extrl_i64_i32(cpu_CF, cf_64);
881 gen_set_NZ64(result);
883 tcg_gen_xor_i64(vf_64, result, t0);
884 tcg_gen_xor_i64(tmp, t0, t1);
885 tcg_gen_andc_i64(vf_64, vf_64, tmp);
886 tcg_gen_extrh_i64_i32(cpu_VF, vf_64);
888 tcg_gen_mov_i64(dest, result);
890 tcg_temp_free_i64(tmp);
891 tcg_temp_free_i64(vf_64);
892 tcg_temp_free_i64(cf_64);
893 tcg_temp_free_i64(result);
895 TCGv_i32 t0_32, t1_32, tmp;
896 t0_32 = tcg_temp_new_i32();
897 t1_32 = tcg_temp_new_i32();
898 tmp = tcg_const_i32(0);
900 tcg_gen_extrl_i64_i32(t0_32, t0);
901 tcg_gen_extrl_i64_i32(t1_32, t1);
902 tcg_gen_add2_i32(cpu_NF, cpu_CF, t0_32, tmp, cpu_CF, tmp);
903 tcg_gen_add2_i32(cpu_NF, cpu_CF, cpu_NF, cpu_CF, t1_32, tmp);
905 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
906 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
907 tcg_gen_xor_i32(tmp, t0_32, t1_32);
908 tcg_gen_andc_i32(cpu_VF, cpu_VF, tmp);
909 tcg_gen_extu_i32_i64(dest, cpu_NF);
911 tcg_temp_free_i32(tmp);
912 tcg_temp_free_i32(t1_32);
913 tcg_temp_free_i32(t0_32);
918 * Load/Store generators
922 * Store from GPR register to memory.
924 static void do_gpr_st_memidx(DisasContext *s, TCGv_i64 source,
925 TCGv_i64 tcg_addr, int size, int memidx,
927 unsigned int iss_srt,
928 bool iss_sf, bool iss_ar)
931 tcg_gen_qemu_st_i64(source, tcg_addr, memidx, s->be_data + size);
936 syn = syn_data_abort_with_iss(0,
942 0, 0, 0, 0, 0, false);
943 disas_set_insn_syndrome(s, syn);
947 static void do_gpr_st(DisasContext *s, TCGv_i64 source,
948 TCGv_i64 tcg_addr, int size,
950 unsigned int iss_srt,
951 bool iss_sf, bool iss_ar)
953 do_gpr_st_memidx(s, source, tcg_addr, size, get_mem_index(s),
954 iss_valid, iss_srt, iss_sf, iss_ar);
958 * Load from memory to GPR register
960 static void do_gpr_ld_memidx(DisasContext *s,
961 TCGv_i64 dest, TCGv_i64 tcg_addr,
962 int size, bool is_signed,
963 bool extend, int memidx,
964 bool iss_valid, unsigned int iss_srt,
965 bool iss_sf, bool iss_ar)
967 TCGMemOp memop = s->be_data + size;
975 tcg_gen_qemu_ld_i64(dest, tcg_addr, memidx, memop);
977 if (extend && is_signed) {
979 tcg_gen_ext32u_i64(dest, dest);
985 syn = syn_data_abort_with_iss(0,
991 0, 0, 0, 0, 0, false);
992 disas_set_insn_syndrome(s, syn);
996 static void do_gpr_ld(DisasContext *s,
997 TCGv_i64 dest, TCGv_i64 tcg_addr,
998 int size, bool is_signed, bool extend,
999 bool iss_valid, unsigned int iss_srt,
1000 bool iss_sf, bool iss_ar)
1002 do_gpr_ld_memidx(s, dest, tcg_addr, size, is_signed, extend,
1004 iss_valid, iss_srt, iss_sf, iss_ar);
1008 * Store from FP register to memory
1010 static void do_fp_st(DisasContext *s, int srcidx, TCGv_i64 tcg_addr, int size)
1012 /* This writes the bottom N bits of a 128 bit wide vector to memory */
1013 TCGv_i64 tmp = tcg_temp_new_i64();
1014 tcg_gen_ld_i64(tmp, cpu_env, fp_reg_offset(s, srcidx, MO_64));
1016 tcg_gen_qemu_st_i64(tmp, tcg_addr, get_mem_index(s),
1019 bool be = s->be_data == MO_BE;
1020 TCGv_i64 tcg_hiaddr = tcg_temp_new_i64();
1022 tcg_gen_addi_i64(tcg_hiaddr, tcg_addr, 8);
1023 tcg_gen_qemu_st_i64(tmp, be ? tcg_hiaddr : tcg_addr, get_mem_index(s),
1025 tcg_gen_ld_i64(tmp, cpu_env, fp_reg_hi_offset(s, srcidx));
1026 tcg_gen_qemu_st_i64(tmp, be ? tcg_addr : tcg_hiaddr, get_mem_index(s),
1028 tcg_temp_free_i64(tcg_hiaddr);
1031 tcg_temp_free_i64(tmp);
1035 * Load from memory to FP register
1037 static void do_fp_ld(DisasContext *s, int destidx, TCGv_i64 tcg_addr, int size)
1039 /* This always zero-extends and writes to a full 128 bit wide vector */
1040 TCGv_i64 tmplo = tcg_temp_new_i64();
1044 TCGMemOp memop = s->be_data + size;
1045 tmphi = tcg_const_i64(0);
1046 tcg_gen_qemu_ld_i64(tmplo, tcg_addr, get_mem_index(s), memop);
1048 bool be = s->be_data == MO_BE;
1049 TCGv_i64 tcg_hiaddr;
1051 tmphi = tcg_temp_new_i64();
1052 tcg_hiaddr = tcg_temp_new_i64();
1054 tcg_gen_addi_i64(tcg_hiaddr, tcg_addr, 8);
1055 tcg_gen_qemu_ld_i64(tmplo, be ? tcg_hiaddr : tcg_addr, get_mem_index(s),
1057 tcg_gen_qemu_ld_i64(tmphi, be ? tcg_addr : tcg_hiaddr, get_mem_index(s),
1059 tcg_temp_free_i64(tcg_hiaddr);
1062 tcg_gen_st_i64(tmplo, cpu_env, fp_reg_offset(s, destidx, MO_64));
1063 tcg_gen_st_i64(tmphi, cpu_env, fp_reg_hi_offset(s, destidx));
1065 tcg_temp_free_i64(tmplo);
1066 tcg_temp_free_i64(tmphi);
1068 clear_vec_high(s, true, destidx);
1072 * Vector load/store helpers.
1074 * The principal difference between this and a FP load is that we don't
1075 * zero extend as we are filling a partial chunk of the vector register.
1076 * These functions don't support 128 bit loads/stores, which would be
1077 * normal load/store operations.
1079 * The _i32 versions are useful when operating on 32 bit quantities
1080 * (eg for floating point single or using Neon helper functions).
1083 /* Get value of an element within a vector register */
1084 static void read_vec_element(DisasContext *s, TCGv_i64 tcg_dest, int srcidx,
1085 int element, TCGMemOp memop)
1087 int vect_off = vec_reg_offset(s, srcidx, element, memop & MO_SIZE);
1090 tcg_gen_ld8u_i64(tcg_dest, cpu_env, vect_off);
1093 tcg_gen_ld16u_i64(tcg_dest, cpu_env, vect_off);
1096 tcg_gen_ld32u_i64(tcg_dest, cpu_env, vect_off);
1099 tcg_gen_ld8s_i64(tcg_dest, cpu_env, vect_off);
1102 tcg_gen_ld16s_i64(tcg_dest, cpu_env, vect_off);
1105 tcg_gen_ld32s_i64(tcg_dest, cpu_env, vect_off);
1109 tcg_gen_ld_i64(tcg_dest, cpu_env, vect_off);
1112 g_assert_not_reached();
1116 static void read_vec_element_i32(DisasContext *s, TCGv_i32 tcg_dest, int srcidx,
1117 int element, TCGMemOp memop)
1119 int vect_off = vec_reg_offset(s, srcidx, element, memop & MO_SIZE);
1122 tcg_gen_ld8u_i32(tcg_dest, cpu_env, vect_off);
1125 tcg_gen_ld16u_i32(tcg_dest, cpu_env, vect_off);
1128 tcg_gen_ld8s_i32(tcg_dest, cpu_env, vect_off);
1131 tcg_gen_ld16s_i32(tcg_dest, cpu_env, vect_off);
1135 tcg_gen_ld_i32(tcg_dest, cpu_env, vect_off);
1138 g_assert_not_reached();
1142 /* Set value of an element within a vector register */
1143 static void write_vec_element(DisasContext *s, TCGv_i64 tcg_src, int destidx,
1144 int element, TCGMemOp memop)
1146 int vect_off = vec_reg_offset(s, destidx, element, memop & MO_SIZE);
1149 tcg_gen_st8_i64(tcg_src, cpu_env, vect_off);
1152 tcg_gen_st16_i64(tcg_src, cpu_env, vect_off);
1155 tcg_gen_st32_i64(tcg_src, cpu_env, vect_off);
1158 tcg_gen_st_i64(tcg_src, cpu_env, vect_off);
1161 g_assert_not_reached();
1165 static void write_vec_element_i32(DisasContext *s, TCGv_i32 tcg_src,
1166 int destidx, int element, TCGMemOp memop)
1168 int vect_off = vec_reg_offset(s, destidx, element, memop & MO_SIZE);
1171 tcg_gen_st8_i32(tcg_src, cpu_env, vect_off);
1174 tcg_gen_st16_i32(tcg_src, cpu_env, vect_off);
1177 tcg_gen_st_i32(tcg_src, cpu_env, vect_off);
1180 g_assert_not_reached();
1184 /* Store from vector register to memory */
1185 static void do_vec_st(DisasContext *s, int srcidx, int element,
1186 TCGv_i64 tcg_addr, int size, TCGMemOp endian)
1188 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
1190 read_vec_element(s, tcg_tmp, srcidx, element, size);
1191 tcg_gen_qemu_st_i64(tcg_tmp, tcg_addr, get_mem_index(s), endian | size);
1193 tcg_temp_free_i64(tcg_tmp);
1196 /* Load from memory to vector register */
1197 static void do_vec_ld(DisasContext *s, int destidx, int element,
1198 TCGv_i64 tcg_addr, int size, TCGMemOp endian)
1200 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
1202 tcg_gen_qemu_ld_i64(tcg_tmp, tcg_addr, get_mem_index(s), endian | size);
1203 write_vec_element(s, tcg_tmp, destidx, element, size);
1205 tcg_temp_free_i64(tcg_tmp);
1208 /* Check that FP/Neon access is enabled. If it is, return
1209 * true. If not, emit code to generate an appropriate exception,
1210 * and return false; the caller should not emit any code for
1211 * the instruction. Note that this check must happen after all
1212 * unallocated-encoding checks (otherwise the syndrome information
1213 * for the resulting exception will be incorrect).
1215 static inline bool fp_access_check(DisasContext *s)
1217 assert(!s->fp_access_checked);
1218 s->fp_access_checked = true;
1220 if (!s->fp_excp_el) {
1224 gen_exception_insn(s, 4, EXCP_UDEF, syn_fp_access_trap(1, 0xe, false),
1229 /* Check that SVE access is enabled. If it is, return true.
1230 * If not, emit code to generate an appropriate exception and return false.
1232 bool sve_access_check(DisasContext *s)
1234 if (s->sve_excp_el) {
1235 gen_exception_insn(s, 4, EXCP_UDEF, syn_sve_access_trap(),
1239 return fp_access_check(s);
1243 * This utility function is for doing register extension with an
1244 * optional shift. You will likely want to pass a temporary for the
1245 * destination register. See DecodeRegExtend() in the ARM ARM.
1247 static void ext_and_shift_reg(TCGv_i64 tcg_out, TCGv_i64 tcg_in,
1248 int option, unsigned int shift)
1250 int extsize = extract32(option, 0, 2);
1251 bool is_signed = extract32(option, 2, 1);
1256 tcg_gen_ext8s_i64(tcg_out, tcg_in);
1259 tcg_gen_ext16s_i64(tcg_out, tcg_in);
1262 tcg_gen_ext32s_i64(tcg_out, tcg_in);
1265 tcg_gen_mov_i64(tcg_out, tcg_in);
1271 tcg_gen_ext8u_i64(tcg_out, tcg_in);
1274 tcg_gen_ext16u_i64(tcg_out, tcg_in);
1277 tcg_gen_ext32u_i64(tcg_out, tcg_in);
1280 tcg_gen_mov_i64(tcg_out, tcg_in);
1286 tcg_gen_shli_i64(tcg_out, tcg_out, shift);
1290 static inline void gen_check_sp_alignment(DisasContext *s)
1292 /* The AArch64 architecture mandates that (if enabled via PSTATE
1293 * or SCTLR bits) there is a check that SP is 16-aligned on every
1294 * SP-relative load or store (with an exception generated if it is not).
1295 * In line with general QEMU practice regarding misaligned accesses,
1296 * we omit these checks for the sake of guest program performance.
1297 * This function is provided as a hook so we can more easily add these
1298 * checks in future (possibly as a "favour catching guest program bugs
1299 * over speed" user selectable option).
1304 * This provides a simple table based table lookup decoder. It is
1305 * intended to be used when the relevant bits for decode are too
1306 * awkwardly placed and switch/if based logic would be confusing and
1307 * deeply nested. Since it's a linear search through the table, tables
1308 * should be kept small.
1310 * It returns the first handler where insn & mask == pattern, or
1311 * NULL if there is no match.
1312 * The table is terminated by an empty mask (i.e. 0)
1314 static inline AArch64DecodeFn *lookup_disas_fn(const AArch64DecodeTable *table,
1317 const AArch64DecodeTable *tptr = table;
1319 while (tptr->mask) {
1320 if ((insn & tptr->mask) == tptr->pattern) {
1321 return tptr->disas_fn;
1329 * The instruction disassembly implemented here matches
1330 * the instruction encoding classifications in chapter C4
1331 * of the ARM Architecture Reference Manual (DDI0487B_a);
1332 * classification names and decode diagrams here should generally
1333 * match up with those in the manual.
1336 /* Unconditional branch (immediate)
1338 * +----+-----------+-------------------------------------+
1339 * | op | 0 0 1 0 1 | imm26 |
1340 * +----+-----------+-------------------------------------+
1342 static void disas_uncond_b_imm(DisasContext *s, uint32_t insn)
1344 uint64_t addr = s->pc + sextract32(insn, 0, 26) * 4 - 4;
1346 if (insn & (1U << 31)) {
1347 /* BL Branch with link */
1348 tcg_gen_movi_i64(cpu_reg(s, 30), s->pc);
1351 /* B Branch / BL Branch with link */
1352 gen_goto_tb(s, 0, addr);
1355 /* Compare and branch (immediate)
1356 * 31 30 25 24 23 5 4 0
1357 * +----+-------------+----+---------------------+--------+
1358 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1359 * +----+-------------+----+---------------------+--------+
1361 static void disas_comp_b_imm(DisasContext *s, uint32_t insn)
1363 unsigned int sf, op, rt;
1365 TCGLabel *label_match;
1368 sf = extract32(insn, 31, 1);
1369 op = extract32(insn, 24, 1); /* 0: CBZ; 1: CBNZ */
1370 rt = extract32(insn, 0, 5);
1371 addr = s->pc + sextract32(insn, 5, 19) * 4 - 4;
1373 tcg_cmp = read_cpu_reg(s, rt, sf);
1374 label_match = gen_new_label();
1376 tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ,
1377 tcg_cmp, 0, label_match);
1379 gen_goto_tb(s, 0, s->pc);
1380 gen_set_label(label_match);
1381 gen_goto_tb(s, 1, addr);
1384 /* Test and branch (immediate)
1385 * 31 30 25 24 23 19 18 5 4 0
1386 * +----+-------------+----+-------+-------------+------+
1387 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1388 * +----+-------------+----+-------+-------------+------+
1390 static void disas_test_b_imm(DisasContext *s, uint32_t insn)
1392 unsigned int bit_pos, op, rt;
1394 TCGLabel *label_match;
1397 bit_pos = (extract32(insn, 31, 1) << 5) | extract32(insn, 19, 5);
1398 op = extract32(insn, 24, 1); /* 0: TBZ; 1: TBNZ */
1399 addr = s->pc + sextract32(insn, 5, 14) * 4 - 4;
1400 rt = extract32(insn, 0, 5);
1402 tcg_cmp = tcg_temp_new_i64();
1403 tcg_gen_andi_i64(tcg_cmp, cpu_reg(s, rt), (1ULL << bit_pos));
1404 label_match = gen_new_label();
1405 tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ,
1406 tcg_cmp, 0, label_match);
1407 tcg_temp_free_i64(tcg_cmp);
1408 gen_goto_tb(s, 0, s->pc);
1409 gen_set_label(label_match);
1410 gen_goto_tb(s, 1, addr);
1413 /* Conditional branch (immediate)
1414 * 31 25 24 23 5 4 3 0
1415 * +---------------+----+---------------------+----+------+
1416 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1417 * +---------------+----+---------------------+----+------+
1419 static void disas_cond_b_imm(DisasContext *s, uint32_t insn)
1424 if ((insn & (1 << 4)) || (insn & (1 << 24))) {
1425 unallocated_encoding(s);
1428 addr = s->pc + sextract32(insn, 5, 19) * 4 - 4;
1429 cond = extract32(insn, 0, 4);
1432 /* genuinely conditional branches */
1433 TCGLabel *label_match = gen_new_label();
1434 arm_gen_test_cc(cond, label_match);
1435 gen_goto_tb(s, 0, s->pc);
1436 gen_set_label(label_match);
1437 gen_goto_tb(s, 1, addr);
1439 /* 0xe and 0xf are both "always" conditions */
1440 gen_goto_tb(s, 0, addr);
1444 /* HINT instruction group, including various allocated HINTs */
1445 static void handle_hint(DisasContext *s, uint32_t insn,
1446 unsigned int op1, unsigned int op2, unsigned int crm)
1448 unsigned int selector = crm << 3 | op2;
1451 unallocated_encoding(s);
1456 case 0b00000: /* NOP */
1458 case 0b00011: /* WFI */
1459 s->base.is_jmp = DISAS_WFI;
1461 case 0b00001: /* YIELD */
1462 /* When running in MTTCG we don't generate jumps to the yield and
1463 * WFE helpers as it won't affect the scheduling of other vCPUs.
1464 * If we wanted to more completely model WFE/SEV so we don't busy
1465 * spin unnecessarily we would need to do something more involved.
1467 if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) {
1468 s->base.is_jmp = DISAS_YIELD;
1471 case 0b00010: /* WFE */
1472 if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) {
1473 s->base.is_jmp = DISAS_WFE;
1476 case 0b00100: /* SEV */
1477 case 0b00101: /* SEVL */
1478 /* we treat all as NOP at least for now */
1480 case 0b00111: /* XPACLRI */
1481 if (s->pauth_active) {
1482 gen_helper_xpaci(cpu_X[30], cpu_env, cpu_X[30]);
1485 case 0b01000: /* PACIA1716 */
1486 if (s->pauth_active) {
1487 gen_helper_pacia(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1490 case 0b01010: /* PACIB1716 */
1491 if (s->pauth_active) {
1492 gen_helper_pacib(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1495 case 0b01100: /* AUTIA1716 */
1496 if (s->pauth_active) {
1497 gen_helper_autia(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1500 case 0b01110: /* AUTIB1716 */
1501 if (s->pauth_active) {
1502 gen_helper_autib(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1505 case 0b11000: /* PACIAZ */
1506 if (s->pauth_active) {
1507 gen_helper_pacia(cpu_X[30], cpu_env, cpu_X[30],
1508 new_tmp_a64_zero(s));
1511 case 0b11001: /* PACIASP */
1512 if (s->pauth_active) {
1513 gen_helper_pacia(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1516 case 0b11010: /* PACIBZ */
1517 if (s->pauth_active) {
1518 gen_helper_pacib(cpu_X[30], cpu_env, cpu_X[30],
1519 new_tmp_a64_zero(s));
1522 case 0b11011: /* PACIBSP */
1523 if (s->pauth_active) {
1524 gen_helper_pacib(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1527 case 0b11100: /* AUTIAZ */
1528 if (s->pauth_active) {
1529 gen_helper_autia(cpu_X[30], cpu_env, cpu_X[30],
1530 new_tmp_a64_zero(s));
1533 case 0b11101: /* AUTIASP */
1534 if (s->pauth_active) {
1535 gen_helper_autia(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1538 case 0b11110: /* AUTIBZ */
1539 if (s->pauth_active) {
1540 gen_helper_autib(cpu_X[30], cpu_env, cpu_X[30],
1541 new_tmp_a64_zero(s));
1544 case 0b11111: /* AUTIBSP */
1545 if (s->pauth_active) {
1546 gen_helper_autib(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1550 /* default specified as NOP equivalent */
1555 static void gen_clrex(DisasContext *s, uint32_t insn)
1557 tcg_gen_movi_i64(cpu_exclusive_addr, -1);
1560 /* CLREX, DSB, DMB, ISB */
1561 static void handle_sync(DisasContext *s, uint32_t insn,
1562 unsigned int op1, unsigned int op2, unsigned int crm)
1567 unallocated_encoding(s);
1578 case 1: /* MBReqTypes_Reads */
1579 bar = TCG_BAR_SC | TCG_MO_LD_LD | TCG_MO_LD_ST;
1581 case 2: /* MBReqTypes_Writes */
1582 bar = TCG_BAR_SC | TCG_MO_ST_ST;
1584 default: /* MBReqTypes_All */
1585 bar = TCG_BAR_SC | TCG_MO_ALL;
1591 /* We need to break the TB after this insn to execute
1592 * a self-modified code correctly and also to take
1593 * any pending interrupts immediately.
1595 gen_goto_tb(s, 0, s->pc);
1598 unallocated_encoding(s);
1603 /* MSR (immediate) - move immediate to processor state field */
1604 static void handle_msr_i(DisasContext *s, uint32_t insn,
1605 unsigned int op1, unsigned int op2, unsigned int crm)
1607 int op = op1 << 3 | op2;
1609 case 0x05: /* SPSel */
1610 if (s->current_el == 0) {
1611 unallocated_encoding(s);
1615 case 0x1e: /* DAIFSet */
1616 case 0x1f: /* DAIFClear */
1618 TCGv_i32 tcg_imm = tcg_const_i32(crm);
1619 TCGv_i32 tcg_op = tcg_const_i32(op);
1620 gen_a64_set_pc_im(s->pc - 4);
1621 gen_helper_msr_i_pstate(cpu_env, tcg_op, tcg_imm);
1622 tcg_temp_free_i32(tcg_imm);
1623 tcg_temp_free_i32(tcg_op);
1624 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1625 gen_a64_set_pc_im(s->pc);
1626 s->base.is_jmp = (op == 0x1f ? DISAS_EXIT : DISAS_JUMP);
1630 unallocated_encoding(s);
1635 static void gen_get_nzcv(TCGv_i64 tcg_rt)
1637 TCGv_i32 tmp = tcg_temp_new_i32();
1638 TCGv_i32 nzcv = tcg_temp_new_i32();
1640 /* build bit 31, N */
1641 tcg_gen_andi_i32(nzcv, cpu_NF, (1U << 31));
1642 /* build bit 30, Z */
1643 tcg_gen_setcondi_i32(TCG_COND_EQ, tmp, cpu_ZF, 0);
1644 tcg_gen_deposit_i32(nzcv, nzcv, tmp, 30, 1);
1645 /* build bit 29, C */
1646 tcg_gen_deposit_i32(nzcv, nzcv, cpu_CF, 29, 1);
1647 /* build bit 28, V */
1648 tcg_gen_shri_i32(tmp, cpu_VF, 31);
1649 tcg_gen_deposit_i32(nzcv, nzcv, tmp, 28, 1);
1650 /* generate result */
1651 tcg_gen_extu_i32_i64(tcg_rt, nzcv);
1653 tcg_temp_free_i32(nzcv);
1654 tcg_temp_free_i32(tmp);
1657 static void gen_set_nzcv(TCGv_i64 tcg_rt)
1660 TCGv_i32 nzcv = tcg_temp_new_i32();
1662 /* take NZCV from R[t] */
1663 tcg_gen_extrl_i64_i32(nzcv, tcg_rt);
1666 tcg_gen_andi_i32(cpu_NF, nzcv, (1U << 31));
1668 tcg_gen_andi_i32(cpu_ZF, nzcv, (1 << 30));
1669 tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_ZF, cpu_ZF, 0);
1671 tcg_gen_andi_i32(cpu_CF, nzcv, (1 << 29));
1672 tcg_gen_shri_i32(cpu_CF, cpu_CF, 29);
1674 tcg_gen_andi_i32(cpu_VF, nzcv, (1 << 28));
1675 tcg_gen_shli_i32(cpu_VF, cpu_VF, 3);
1676 tcg_temp_free_i32(nzcv);
1679 /* MRS - move from system register
1680 * MSR (register) - move to system register
1683 * These are all essentially the same insn in 'read' and 'write'
1684 * versions, with varying op0 fields.
1686 static void handle_sys(DisasContext *s, uint32_t insn, bool isread,
1687 unsigned int op0, unsigned int op1, unsigned int op2,
1688 unsigned int crn, unsigned int crm, unsigned int rt)
1690 const ARMCPRegInfo *ri;
1693 ri = get_arm_cp_reginfo(s->cp_regs,
1694 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP,
1695 crn, crm, op0, op1, op2));
1698 /* Unknown register; this might be a guest error or a QEMU
1699 * unimplemented feature.
1701 qemu_log_mask(LOG_UNIMP, "%s access to unsupported AArch64 "
1702 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1703 isread ? "read" : "write", op0, op1, crn, crm, op2);
1704 unallocated_encoding(s);
1708 /* Check access permissions */
1709 if (!cp_access_ok(s->current_el, ri, isread)) {
1710 unallocated_encoding(s);
1715 /* Emit code to perform further access permissions checks at
1716 * runtime; this may result in an exception.
1719 TCGv_i32 tcg_syn, tcg_isread;
1722 gen_a64_set_pc_im(s->pc - 4);
1723 tmpptr = tcg_const_ptr(ri);
1724 syndrome = syn_aa64_sysregtrap(op0, op1, op2, crn, crm, rt, isread);
1725 tcg_syn = tcg_const_i32(syndrome);
1726 tcg_isread = tcg_const_i32(isread);
1727 gen_helper_access_check_cp_reg(cpu_env, tmpptr, tcg_syn, tcg_isread);
1728 tcg_temp_free_ptr(tmpptr);
1729 tcg_temp_free_i32(tcg_syn);
1730 tcg_temp_free_i32(tcg_isread);
1733 /* Handle special cases first */
1734 switch (ri->type & ~(ARM_CP_FLAG_MASK & ~ARM_CP_SPECIAL)) {
1738 tcg_rt = cpu_reg(s, rt);
1740 gen_get_nzcv(tcg_rt);
1742 gen_set_nzcv(tcg_rt);
1745 case ARM_CP_CURRENTEL:
1746 /* Reads as current EL value from pstate, which is
1747 * guaranteed to be constant by the tb flags.
1749 tcg_rt = cpu_reg(s, rt);
1750 tcg_gen_movi_i64(tcg_rt, s->current_el << 2);
1753 /* Writes clear the aligned block of memory which rt points into. */
1754 tcg_rt = cpu_reg(s, rt);
1755 gen_helper_dc_zva(cpu_env, tcg_rt);
1760 if ((ri->type & ARM_CP_FPU) && !fp_access_check(s)) {
1762 } else if ((ri->type & ARM_CP_SVE) && !sve_access_check(s)) {
1766 if ((tb_cflags(s->base.tb) & CF_USE_ICOUNT) && (ri->type & ARM_CP_IO)) {
1770 tcg_rt = cpu_reg(s, rt);
1773 if (ri->type & ARM_CP_CONST) {
1774 tcg_gen_movi_i64(tcg_rt, ri->resetvalue);
1775 } else if (ri->readfn) {
1777 tmpptr = tcg_const_ptr(ri);
1778 gen_helper_get_cp_reg64(tcg_rt, cpu_env, tmpptr);
1779 tcg_temp_free_ptr(tmpptr);
1781 tcg_gen_ld_i64(tcg_rt, cpu_env, ri->fieldoffset);
1784 if (ri->type & ARM_CP_CONST) {
1785 /* If not forbidden by access permissions, treat as WI */
1787 } else if (ri->writefn) {
1789 tmpptr = tcg_const_ptr(ri);
1790 gen_helper_set_cp_reg64(cpu_env, tmpptr, tcg_rt);
1791 tcg_temp_free_ptr(tmpptr);
1793 tcg_gen_st_i64(tcg_rt, cpu_env, ri->fieldoffset);
1797 if ((tb_cflags(s->base.tb) & CF_USE_ICOUNT) && (ri->type & ARM_CP_IO)) {
1798 /* I/O operations must end the TB here (whether read or write) */
1800 s->base.is_jmp = DISAS_UPDATE;
1801 } else if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) {
1802 /* We default to ending the TB on a coprocessor register write,
1803 * but allow this to be suppressed by the register definition
1804 * (usually only necessary to work around guest bugs).
1806 s->base.is_jmp = DISAS_UPDATE;
1811 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1812 * +---------------------+---+-----+-----+-------+-------+-----+------+
1813 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1814 * +---------------------+---+-----+-----+-------+-------+-----+------+
1816 static void disas_system(DisasContext *s, uint32_t insn)
1818 unsigned int l, op0, op1, crn, crm, op2, rt;
1819 l = extract32(insn, 21, 1);
1820 op0 = extract32(insn, 19, 2);
1821 op1 = extract32(insn, 16, 3);
1822 crn = extract32(insn, 12, 4);
1823 crm = extract32(insn, 8, 4);
1824 op2 = extract32(insn, 5, 3);
1825 rt = extract32(insn, 0, 5);
1828 if (l || rt != 31) {
1829 unallocated_encoding(s);
1833 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
1834 handle_hint(s, insn, op1, op2, crm);
1836 case 3: /* CLREX, DSB, DMB, ISB */
1837 handle_sync(s, insn, op1, op2, crm);
1839 case 4: /* MSR (immediate) */
1840 handle_msr_i(s, insn, op1, op2, crm);
1843 unallocated_encoding(s);
1848 handle_sys(s, insn, l, op0, op1, op2, crn, crm, rt);
1851 /* Exception generation
1853 * 31 24 23 21 20 5 4 2 1 0
1854 * +-----------------+-----+------------------------+-----+----+
1855 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1856 * +-----------------------+------------------------+----------+
1858 static void disas_exc(DisasContext *s, uint32_t insn)
1860 int opc = extract32(insn, 21, 3);
1861 int op2_ll = extract32(insn, 0, 5);
1862 int imm16 = extract32(insn, 5, 16);
1867 /* For SVC, HVC and SMC we advance the single-step state
1868 * machine before taking the exception. This is architecturally
1869 * mandated, to ensure that single-stepping a system call
1870 * instruction works properly.
1875 gen_exception_insn(s, 0, EXCP_SWI, syn_aa64_svc(imm16),
1876 default_exception_el(s));
1879 if (s->current_el == 0) {
1880 unallocated_encoding(s);
1883 /* The pre HVC helper handles cases when HVC gets trapped
1884 * as an undefined insn by runtime configuration.
1886 gen_a64_set_pc_im(s->pc - 4);
1887 gen_helper_pre_hvc(cpu_env);
1889 gen_exception_insn(s, 0, EXCP_HVC, syn_aa64_hvc(imm16), 2);
1892 if (s->current_el == 0) {
1893 unallocated_encoding(s);
1896 gen_a64_set_pc_im(s->pc - 4);
1897 tmp = tcg_const_i32(syn_aa64_smc(imm16));
1898 gen_helper_pre_smc(cpu_env, tmp);
1899 tcg_temp_free_i32(tmp);
1901 gen_exception_insn(s, 0, EXCP_SMC, syn_aa64_smc(imm16), 3);
1904 unallocated_encoding(s);
1910 unallocated_encoding(s);
1914 gen_exception_bkpt_insn(s, 4, syn_aa64_bkpt(imm16));
1918 unallocated_encoding(s);
1921 /* HLT. This has two purposes.
1922 * Architecturally, it is an external halting debug instruction.
1923 * Since QEMU doesn't implement external debug, we treat this as
1924 * it is required for halting debug disabled: it will UNDEF.
1925 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1927 if (semihosting_enabled() && imm16 == 0xf000) {
1928 #ifndef CONFIG_USER_ONLY
1929 /* In system mode, don't allow userspace access to semihosting,
1930 * to provide some semblance of security (and for consistency
1931 * with our 32-bit semihosting).
1933 if (s->current_el == 0) {
1934 unsupported_encoding(s, insn);
1938 gen_exception_internal_insn(s, 0, EXCP_SEMIHOST);
1940 unsupported_encoding(s, insn);
1944 if (op2_ll < 1 || op2_ll > 3) {
1945 unallocated_encoding(s);
1948 /* DCPS1, DCPS2, DCPS3 */
1949 unsupported_encoding(s, insn);
1952 unallocated_encoding(s);
1957 /* Unconditional branch (register)
1958 * 31 25 24 21 20 16 15 10 9 5 4 0
1959 * +---------------+-------+-------+-------+------+-------+
1960 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1961 * +---------------+-------+-------+-------+------+-------+
1963 static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)
1965 unsigned int opc, op2, op3, rn, op4;
1969 opc = extract32(insn, 21, 4);
1970 op2 = extract32(insn, 16, 5);
1971 op3 = extract32(insn, 10, 6);
1972 rn = extract32(insn, 5, 5);
1973 op4 = extract32(insn, 0, 5);
1976 goto do_unallocated;
1987 goto do_unallocated;
1989 dst = cpu_reg(s, rn);
1994 if (!dc_isar_feature(aa64_pauth, s)) {
1995 goto do_unallocated;
1999 if (rn != 0x1f || op4 != 0x1f) {
2000 goto do_unallocated;
2003 modifier = cpu_X[31];
2005 /* BRAAZ, BRABZ, BLRAAZ, BLRABZ */
2007 goto do_unallocated;
2009 modifier = new_tmp_a64_zero(s);
2011 if (s->pauth_active) {
2012 dst = new_tmp_a64(s);
2014 gen_helper_autia(dst, cpu_env, cpu_reg(s, rn), modifier);
2016 gen_helper_autib(dst, cpu_env, cpu_reg(s, rn), modifier);
2019 dst = cpu_reg(s, rn);
2024 goto do_unallocated;
2027 gen_a64_set_pc(s, dst);
2028 /* BLR also needs to load return address */
2030 tcg_gen_movi_i64(cpu_reg(s, 30), s->pc);
2036 if (!dc_isar_feature(aa64_pauth, s)) {
2037 goto do_unallocated;
2039 if (op3 != 2 || op3 != 3) {
2040 goto do_unallocated;
2042 if (s->pauth_active) {
2043 dst = new_tmp_a64(s);
2044 modifier = cpu_reg_sp(s, op4);
2046 gen_helper_autia(dst, cpu_env, cpu_reg(s, rn), modifier);
2048 gen_helper_autib(dst, cpu_env, cpu_reg(s, rn), modifier);
2051 dst = cpu_reg(s, rn);
2053 gen_a64_set_pc(s, dst);
2054 /* BLRAA also needs to load return address */
2056 tcg_gen_movi_i64(cpu_reg(s, 30), s->pc);
2061 if (s->current_el == 0) {
2062 goto do_unallocated;
2067 goto do_unallocated;
2069 dst = tcg_temp_new_i64();
2070 tcg_gen_ld_i64(dst, cpu_env,
2071 offsetof(CPUARMState, elr_el[s->current_el]));
2074 case 2: /* ERETAA */
2075 case 3: /* ERETAB */
2076 if (!dc_isar_feature(aa64_pauth, s)) {
2077 goto do_unallocated;
2079 if (rn != 0x1f || op4 != 0x1f) {
2080 goto do_unallocated;
2082 dst = tcg_temp_new_i64();
2083 tcg_gen_ld_i64(dst, cpu_env,
2084 offsetof(CPUARMState, elr_el[s->current_el]));
2085 if (s->pauth_active) {
2086 modifier = cpu_X[31];
2088 gen_helper_autia(dst, cpu_env, dst, modifier);
2090 gen_helper_autib(dst, cpu_env, dst, modifier);
2096 goto do_unallocated;
2098 if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) {
2102 gen_helper_exception_return(cpu_env, dst);
2103 tcg_temp_free_i64(dst);
2104 if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) {
2107 /* Must exit loop to check un-masked IRQs */
2108 s->base.is_jmp = DISAS_EXIT;
2112 if (op3 != 0 || op4 != 0 || rn != 0x1f) {
2113 goto do_unallocated;
2115 unsupported_encoding(s, insn);
2121 unallocated_encoding(s);
2125 s->base.is_jmp = DISAS_JUMP;
2128 /* Branches, exception generating and system instructions */
2129 static void disas_b_exc_sys(DisasContext *s, uint32_t insn)
2131 switch (extract32(insn, 25, 7)) {
2132 case 0x0a: case 0x0b:
2133 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
2134 disas_uncond_b_imm(s, insn);
2136 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
2137 disas_comp_b_imm(s, insn);
2139 case 0x1b: case 0x5b: /* Test & branch (immediate) */
2140 disas_test_b_imm(s, insn);
2142 case 0x2a: /* Conditional branch (immediate) */
2143 disas_cond_b_imm(s, insn);
2145 case 0x6a: /* Exception generation / System */
2146 if (insn & (1 << 24)) {
2147 if (extract32(insn, 22, 2) == 0) {
2148 disas_system(s, insn);
2150 unallocated_encoding(s);
2156 case 0x6b: /* Unconditional branch (register) */
2157 disas_uncond_b_reg(s, insn);
2160 unallocated_encoding(s);
2166 * Load/Store exclusive instructions are implemented by remembering
2167 * the value/address loaded, and seeing if these are the same
2168 * when the store is performed. This is not actually the architecturally
2169 * mandated semantics, but it works for typical guest code sequences
2170 * and avoids having to monitor regular stores.
2172 * The store exclusive uses the atomic cmpxchg primitives to avoid
2173 * races in multi-threaded linux-user and when MTTCG softmmu is
2176 static void gen_load_exclusive(DisasContext *s, int rt, int rt2,
2177 TCGv_i64 addr, int size, bool is_pair)
2179 int idx = get_mem_index(s);
2180 TCGMemOp memop = s->be_data;
2182 g_assert(size <= 3);
2184 g_assert(size >= 2);
2186 /* The pair must be single-copy atomic for the doubleword. */
2187 memop |= MO_64 | MO_ALIGN;
2188 tcg_gen_qemu_ld_i64(cpu_exclusive_val, addr, idx, memop);
2189 if (s->be_data == MO_LE) {
2190 tcg_gen_extract_i64(cpu_reg(s, rt), cpu_exclusive_val, 0, 32);
2191 tcg_gen_extract_i64(cpu_reg(s, rt2), cpu_exclusive_val, 32, 32);
2193 tcg_gen_extract_i64(cpu_reg(s, rt), cpu_exclusive_val, 32, 32);
2194 tcg_gen_extract_i64(cpu_reg(s, rt2), cpu_exclusive_val, 0, 32);
2197 /* The pair must be single-copy atomic for *each* doubleword, not
2198 the entire quadword, however it must be quadword aligned. */
2200 tcg_gen_qemu_ld_i64(cpu_exclusive_val, addr, idx,
2201 memop | MO_ALIGN_16);
2203 TCGv_i64 addr2 = tcg_temp_new_i64();
2204 tcg_gen_addi_i64(addr2, addr, 8);
2205 tcg_gen_qemu_ld_i64(cpu_exclusive_high, addr2, idx, memop);
2206 tcg_temp_free_i64(addr2);
2208 tcg_gen_mov_i64(cpu_reg(s, rt), cpu_exclusive_val);
2209 tcg_gen_mov_i64(cpu_reg(s, rt2), cpu_exclusive_high);
2212 memop |= size | MO_ALIGN;
2213 tcg_gen_qemu_ld_i64(cpu_exclusive_val, addr, idx, memop);
2214 tcg_gen_mov_i64(cpu_reg(s, rt), cpu_exclusive_val);
2216 tcg_gen_mov_i64(cpu_exclusive_addr, addr);
2219 static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,
2220 TCGv_i64 addr, int size, int is_pair)
2222 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
2223 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
2226 * [addr + datasize] = {Rt2};
2232 * env->exclusive_addr = -1;
2234 TCGLabel *fail_label = gen_new_label();
2235 TCGLabel *done_label = gen_new_label();
2238 tcg_gen_brcond_i64(TCG_COND_NE, addr, cpu_exclusive_addr, fail_label);
2240 tmp = tcg_temp_new_i64();
2243 if (s->be_data == MO_LE) {
2244 tcg_gen_concat32_i64(tmp, cpu_reg(s, rt), cpu_reg(s, rt2));
2246 tcg_gen_concat32_i64(tmp, cpu_reg(s, rt2), cpu_reg(s, rt));
2248 tcg_gen_atomic_cmpxchg_i64(tmp, cpu_exclusive_addr,
2249 cpu_exclusive_val, tmp,
2251 MO_64 | MO_ALIGN | s->be_data);
2252 tcg_gen_setcond_i64(TCG_COND_NE, tmp, tmp, cpu_exclusive_val);
2253 } else if (tb_cflags(s->base.tb) & CF_PARALLEL) {
2254 if (!HAVE_CMPXCHG128) {
2255 gen_helper_exit_atomic(cpu_env);
2256 s->base.is_jmp = DISAS_NORETURN;
2257 } else if (s->be_data == MO_LE) {
2258 gen_helper_paired_cmpxchg64_le_parallel(tmp, cpu_env,
2263 gen_helper_paired_cmpxchg64_be_parallel(tmp, cpu_env,
2268 } else if (s->be_data == MO_LE) {
2269 gen_helper_paired_cmpxchg64_le(tmp, cpu_env, cpu_exclusive_addr,
2270 cpu_reg(s, rt), cpu_reg(s, rt2));
2272 gen_helper_paired_cmpxchg64_be(tmp, cpu_env, cpu_exclusive_addr,
2273 cpu_reg(s, rt), cpu_reg(s, rt2));
2276 tcg_gen_atomic_cmpxchg_i64(tmp, cpu_exclusive_addr, cpu_exclusive_val,
2277 cpu_reg(s, rt), get_mem_index(s),
2278 size | MO_ALIGN | s->be_data);
2279 tcg_gen_setcond_i64(TCG_COND_NE, tmp, tmp, cpu_exclusive_val);
2281 tcg_gen_mov_i64(cpu_reg(s, rd), tmp);
2282 tcg_temp_free_i64(tmp);
2283 tcg_gen_br(done_label);
2285 gen_set_label(fail_label);
2286 tcg_gen_movi_i64(cpu_reg(s, rd), 1);
2287 gen_set_label(done_label);
2288 tcg_gen_movi_i64(cpu_exclusive_addr, -1);
2291 static void gen_compare_and_swap(DisasContext *s, int rs, int rt,
2294 TCGv_i64 tcg_rs = cpu_reg(s, rs);
2295 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2296 int memidx = get_mem_index(s);
2297 TCGv_i64 addr = cpu_reg_sp(s, rn);
2300 gen_check_sp_alignment(s);
2302 tcg_gen_atomic_cmpxchg_i64(tcg_rs, addr, tcg_rs, tcg_rt, memidx,
2303 size | MO_ALIGN | s->be_data);
2306 static void gen_compare_and_swap_pair(DisasContext *s, int rs, int rt,
2309 TCGv_i64 s1 = cpu_reg(s, rs);
2310 TCGv_i64 s2 = cpu_reg(s, rs + 1);
2311 TCGv_i64 t1 = cpu_reg(s, rt);
2312 TCGv_i64 t2 = cpu_reg(s, rt + 1);
2313 TCGv_i64 addr = cpu_reg_sp(s, rn);
2314 int memidx = get_mem_index(s);
2317 gen_check_sp_alignment(s);
2321 TCGv_i64 cmp = tcg_temp_new_i64();
2322 TCGv_i64 val = tcg_temp_new_i64();
2324 if (s->be_data == MO_LE) {
2325 tcg_gen_concat32_i64(val, t1, t2);
2326 tcg_gen_concat32_i64(cmp, s1, s2);
2328 tcg_gen_concat32_i64(val, t2, t1);
2329 tcg_gen_concat32_i64(cmp, s2, s1);
2332 tcg_gen_atomic_cmpxchg_i64(cmp, addr, cmp, val, memidx,
2333 MO_64 | MO_ALIGN | s->be_data);
2334 tcg_temp_free_i64(val);
2336 if (s->be_data == MO_LE) {
2337 tcg_gen_extr32_i64(s1, s2, cmp);
2339 tcg_gen_extr32_i64(s2, s1, cmp);
2341 tcg_temp_free_i64(cmp);
2342 } else if (tb_cflags(s->base.tb) & CF_PARALLEL) {
2343 if (HAVE_CMPXCHG128) {
2344 TCGv_i32 tcg_rs = tcg_const_i32(rs);
2345 if (s->be_data == MO_LE) {
2346 gen_helper_casp_le_parallel(cpu_env, tcg_rs, addr, t1, t2);
2348 gen_helper_casp_be_parallel(cpu_env, tcg_rs, addr, t1, t2);
2350 tcg_temp_free_i32(tcg_rs);
2352 gen_helper_exit_atomic(cpu_env);
2353 s->base.is_jmp = DISAS_NORETURN;
2356 TCGv_i64 d1 = tcg_temp_new_i64();
2357 TCGv_i64 d2 = tcg_temp_new_i64();
2358 TCGv_i64 a2 = tcg_temp_new_i64();
2359 TCGv_i64 c1 = tcg_temp_new_i64();
2360 TCGv_i64 c2 = tcg_temp_new_i64();
2361 TCGv_i64 zero = tcg_const_i64(0);
2363 /* Load the two words, in memory order. */
2364 tcg_gen_qemu_ld_i64(d1, addr, memidx,
2365 MO_64 | MO_ALIGN_16 | s->be_data);
2366 tcg_gen_addi_i64(a2, addr, 8);
2367 tcg_gen_qemu_ld_i64(d2, addr, memidx, MO_64 | s->be_data);
2369 /* Compare the two words, also in memory order. */
2370 tcg_gen_setcond_i64(TCG_COND_EQ, c1, d1, s1);
2371 tcg_gen_setcond_i64(TCG_COND_EQ, c2, d2, s2);
2372 tcg_gen_and_i64(c2, c2, c1);
2374 /* If compare equal, write back new data, else write back old data. */
2375 tcg_gen_movcond_i64(TCG_COND_NE, c1, c2, zero, t1, d1);
2376 tcg_gen_movcond_i64(TCG_COND_NE, c2, c2, zero, t2, d2);
2377 tcg_gen_qemu_st_i64(c1, addr, memidx, MO_64 | s->be_data);
2378 tcg_gen_qemu_st_i64(c2, a2, memidx, MO_64 | s->be_data);
2379 tcg_temp_free_i64(a2);
2380 tcg_temp_free_i64(c1);
2381 tcg_temp_free_i64(c2);
2382 tcg_temp_free_i64(zero);
2384 /* Write back the data from memory to Rs. */
2385 tcg_gen_mov_i64(s1, d1);
2386 tcg_gen_mov_i64(s2, d2);
2387 tcg_temp_free_i64(d1);
2388 tcg_temp_free_i64(d2);
2392 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2393 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2395 static bool disas_ldst_compute_iss_sf(int size, bool is_signed, int opc)
2397 int opc0 = extract32(opc, 0, 1);
2401 regsize = opc0 ? 32 : 64;
2403 regsize = size == 3 ? 64 : 32;
2405 return regsize == 64;
2408 /* Load/store exclusive
2410 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2411 * +-----+-------------+----+---+----+------+----+-------+------+------+
2412 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2413 * +-----+-------------+----+---+----+------+----+-------+------+------+
2415 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2416 * L: 0 -> store, 1 -> load
2417 * o2: 0 -> exclusive, 1 -> not
2418 * o1: 0 -> single register, 1 -> register pair
2419 * o0: 1 -> load-acquire/store-release, 0 -> not
2421 static void disas_ldst_excl(DisasContext *s, uint32_t insn)
2423 int rt = extract32(insn, 0, 5);
2424 int rn = extract32(insn, 5, 5);
2425 int rt2 = extract32(insn, 10, 5);
2426 int rs = extract32(insn, 16, 5);
2427 int is_lasr = extract32(insn, 15, 1);
2428 int o2_L_o1_o0 = extract32(insn, 21, 3) * 2 | is_lasr;
2429 int size = extract32(insn, 30, 2);
2432 switch (o2_L_o1_o0) {
2433 case 0x0: /* STXR */
2434 case 0x1: /* STLXR */
2436 gen_check_sp_alignment(s);
2439 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
2441 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2442 gen_store_exclusive(s, rs, rt, rt2, tcg_addr, size, false);
2445 case 0x4: /* LDXR */
2446 case 0x5: /* LDAXR */
2448 gen_check_sp_alignment(s);
2450 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2452 gen_load_exclusive(s, rt, rt2, tcg_addr, size, false);
2454 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
2458 case 0x8: /* STLLR */
2459 if (!dc_isar_feature(aa64_lor, s)) {
2462 /* StoreLORelease is the same as Store-Release for QEMU. */
2464 case 0x9: /* STLR */
2465 /* Generate ISS for non-exclusive accesses including LASR. */
2467 gen_check_sp_alignment(s);
2469 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
2470 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2471 do_gpr_st(s, cpu_reg(s, rt), tcg_addr, size, true, rt,
2472 disas_ldst_compute_iss_sf(size, false, 0), is_lasr);
2475 case 0xc: /* LDLAR */
2476 if (!dc_isar_feature(aa64_lor, s)) {
2479 /* LoadLOAcquire is the same as Load-Acquire for QEMU. */
2481 case 0xd: /* LDAR */
2482 /* Generate ISS for non-exclusive accesses including LASR. */
2484 gen_check_sp_alignment(s);
2486 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2487 do_gpr_ld(s, cpu_reg(s, rt), tcg_addr, size, false, false, true, rt,
2488 disas_ldst_compute_iss_sf(size, false, 0), is_lasr);
2489 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
2492 case 0x2: case 0x3: /* CASP / STXP */
2493 if (size & 2) { /* STXP / STLXP */
2495 gen_check_sp_alignment(s);
2498 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
2500 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2501 gen_store_exclusive(s, rs, rt, rt2, tcg_addr, size, true);
2505 && ((rt | rs) & 1) == 0
2506 && dc_isar_feature(aa64_atomics, s)) {
2508 gen_compare_and_swap_pair(s, rs, rt, rn, size | 2);
2513 case 0x6: case 0x7: /* CASPA / LDXP */
2514 if (size & 2) { /* LDXP / LDAXP */
2516 gen_check_sp_alignment(s);
2518 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2520 gen_load_exclusive(s, rt, rt2, tcg_addr, size, true);
2522 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
2527 && ((rt | rs) & 1) == 0
2528 && dc_isar_feature(aa64_atomics, s)) {
2529 /* CASPA / CASPAL */
2530 gen_compare_and_swap_pair(s, rs, rt, rn, size | 2);
2536 case 0xb: /* CASL */
2537 case 0xe: /* CASA */
2538 case 0xf: /* CASAL */
2539 if (rt2 == 31 && dc_isar_feature(aa64_atomics, s)) {
2540 gen_compare_and_swap(s, rs, rt, rn, size);
2545 unallocated_encoding(s);
2549 * Load register (literal)
2551 * 31 30 29 27 26 25 24 23 5 4 0
2552 * +-----+-------+---+-----+-------------------+-------+
2553 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2554 * +-----+-------+---+-----+-------------------+-------+
2556 * V: 1 -> vector (simd/fp)
2557 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2558 * 10-> 32 bit signed, 11 -> prefetch
2559 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2561 static void disas_ld_lit(DisasContext *s, uint32_t insn)
2563 int rt = extract32(insn, 0, 5);
2564 int64_t imm = sextract32(insn, 5, 19) << 2;
2565 bool is_vector = extract32(insn, 26, 1);
2566 int opc = extract32(insn, 30, 2);
2567 bool is_signed = false;
2569 TCGv_i64 tcg_rt, tcg_addr;
2573 unallocated_encoding(s);
2577 if (!fp_access_check(s)) {
2582 /* PRFM (literal) : prefetch */
2585 size = 2 + extract32(opc, 0, 1);
2586 is_signed = extract32(opc, 1, 1);
2589 tcg_rt = cpu_reg(s, rt);
2591 tcg_addr = tcg_const_i64((s->pc - 4) + imm);
2593 do_fp_ld(s, rt, tcg_addr, size);
2595 /* Only unsigned 32bit loads target 32bit registers. */
2596 bool iss_sf = opc != 0;
2598 do_gpr_ld(s, tcg_rt, tcg_addr, size, is_signed, false,
2599 true, rt, iss_sf, false);
2601 tcg_temp_free_i64(tcg_addr);
2605 * LDNP (Load Pair - non-temporal hint)
2606 * LDP (Load Pair - non vector)
2607 * LDPSW (Load Pair Signed Word - non vector)
2608 * STNP (Store Pair - non-temporal hint)
2609 * STP (Store Pair - non vector)
2610 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2611 * LDP (Load Pair of SIMD&FP)
2612 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2613 * STP (Store Pair of SIMD&FP)
2615 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2616 * +-----+-------+---+---+-------+---+-----------------------------+
2617 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2618 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2620 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2622 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2623 * V: 0 -> GPR, 1 -> Vector
2624 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2625 * 10 -> signed offset, 11 -> pre-index
2626 * L: 0 -> Store 1 -> Load
2628 * Rt, Rt2 = GPR or SIMD registers to be stored
2629 * Rn = general purpose register containing address
2630 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2632 static void disas_ldst_pair(DisasContext *s, uint32_t insn)
2634 int rt = extract32(insn, 0, 5);
2635 int rn = extract32(insn, 5, 5);
2636 int rt2 = extract32(insn, 10, 5);
2637 uint64_t offset = sextract64(insn, 15, 7);
2638 int index = extract32(insn, 23, 2);
2639 bool is_vector = extract32(insn, 26, 1);
2640 bool is_load = extract32(insn, 22, 1);
2641 int opc = extract32(insn, 30, 2);
2643 bool is_signed = false;
2644 bool postindex = false;
2647 TCGv_i64 tcg_addr; /* calculated address */
2651 unallocated_encoding(s);
2658 size = 2 + extract32(opc, 1, 1);
2659 is_signed = extract32(opc, 0, 1);
2660 if (!is_load && is_signed) {
2661 unallocated_encoding(s);
2667 case 1: /* post-index */
2672 /* signed offset with "non-temporal" hint. Since we don't emulate
2673 * caches we don't care about hints to the cache system about
2674 * data access patterns, and handle this identically to plain
2678 /* There is no non-temporal-hint version of LDPSW */
2679 unallocated_encoding(s);
2684 case 2: /* signed offset, rn not updated */
2687 case 3: /* pre-index */
2693 if (is_vector && !fp_access_check(s)) {
2700 gen_check_sp_alignment(s);
2703 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2706 tcg_gen_addi_i64(tcg_addr, tcg_addr, offset);
2711 do_fp_ld(s, rt, tcg_addr, size);
2713 do_fp_st(s, rt, tcg_addr, size);
2715 tcg_gen_addi_i64(tcg_addr, tcg_addr, 1 << size);
2717 do_fp_ld(s, rt2, tcg_addr, size);
2719 do_fp_st(s, rt2, tcg_addr, size);
2722 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2723 TCGv_i64 tcg_rt2 = cpu_reg(s, rt2);
2726 TCGv_i64 tmp = tcg_temp_new_i64();
2728 /* Do not modify tcg_rt before recognizing any exception
2729 * from the second load.
2731 do_gpr_ld(s, tmp, tcg_addr, size, is_signed, false,
2732 false, 0, false, false);
2733 tcg_gen_addi_i64(tcg_addr, tcg_addr, 1 << size);
2734 do_gpr_ld(s, tcg_rt2, tcg_addr, size, is_signed, false,
2735 false, 0, false, false);
2737 tcg_gen_mov_i64(tcg_rt, tmp);
2738 tcg_temp_free_i64(tmp);
2740 do_gpr_st(s, tcg_rt, tcg_addr, size,
2741 false, 0, false, false);
2742 tcg_gen_addi_i64(tcg_addr, tcg_addr, 1 << size);
2743 do_gpr_st(s, tcg_rt2, tcg_addr, size,
2744 false, 0, false, false);
2750 tcg_gen_addi_i64(tcg_addr, tcg_addr, offset - (1 << size));
2752 tcg_gen_subi_i64(tcg_addr, tcg_addr, 1 << size);
2754 tcg_gen_mov_i64(cpu_reg_sp(s, rn), tcg_addr);
2759 * Load/store (immediate post-indexed)
2760 * Load/store (immediate pre-indexed)
2761 * Load/store (unscaled immediate)
2763 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2764 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2765 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2766 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2768 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2770 * V = 0 -> non-vector
2771 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2772 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2774 static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn,
2780 int rn = extract32(insn, 5, 5);
2781 int imm9 = sextract32(insn, 12, 9);
2782 int idx = extract32(insn, 10, 2);
2783 bool is_signed = false;
2784 bool is_store = false;
2785 bool is_extended = false;
2786 bool is_unpriv = (idx == 2);
2787 bool iss_valid = !is_vector;
2794 size |= (opc & 2) << 1;
2795 if (size > 4 || is_unpriv) {
2796 unallocated_encoding(s);
2799 is_store = ((opc & 1) == 0);
2800 if (!fp_access_check(s)) {
2804 if (size == 3 && opc == 2) {
2805 /* PRFM - prefetch */
2807 unallocated_encoding(s);
2812 if (opc == 3 && size > 1) {
2813 unallocated_encoding(s);
2816 is_store = (opc == 0);
2817 is_signed = extract32(opc, 1, 1);
2818 is_extended = (size < 3) && extract32(opc, 0, 1);
2836 g_assert_not_reached();
2840 gen_check_sp_alignment(s);
2842 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2845 tcg_gen_addi_i64(tcg_addr, tcg_addr, imm9);
2850 do_fp_st(s, rt, tcg_addr, size);
2852 do_fp_ld(s, rt, tcg_addr, size);
2855 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2856 int memidx = is_unpriv ? get_a64_user_mem_index(s) : get_mem_index(s);
2857 bool iss_sf = disas_ldst_compute_iss_sf(size, is_signed, opc);
2860 do_gpr_st_memidx(s, tcg_rt, tcg_addr, size, memidx,
2861 iss_valid, rt, iss_sf, false);
2863 do_gpr_ld_memidx(s, tcg_rt, tcg_addr, size,
2864 is_signed, is_extended, memidx,
2865 iss_valid, rt, iss_sf, false);
2870 TCGv_i64 tcg_rn = cpu_reg_sp(s, rn);
2872 tcg_gen_addi_i64(tcg_addr, tcg_addr, imm9);
2874 tcg_gen_mov_i64(tcg_rn, tcg_addr);
2879 * Load/store (register offset)
2881 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2882 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2883 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2884 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2887 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2888 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2890 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2891 * opc<0>: 0 -> store, 1 -> load
2892 * V: 1 -> vector/simd
2893 * opt: extend encoding (see DecodeRegExtend)
2894 * S: if S=1 then scale (essentially index by sizeof(size))
2895 * Rt: register to transfer into/out of
2896 * Rn: address register or SP for base
2897 * Rm: offset register or ZR for offset
2899 static void disas_ldst_reg_roffset(DisasContext *s, uint32_t insn,
2905 int rn = extract32(insn, 5, 5);
2906 int shift = extract32(insn, 12, 1);
2907 int rm = extract32(insn, 16, 5);
2908 int opt = extract32(insn, 13, 3);
2909 bool is_signed = false;
2910 bool is_store = false;
2911 bool is_extended = false;
2916 if (extract32(opt, 1, 1) == 0) {
2917 unallocated_encoding(s);
2922 size |= (opc & 2) << 1;
2924 unallocated_encoding(s);
2927 is_store = !extract32(opc, 0, 1);
2928 if (!fp_access_check(s)) {
2932 if (size == 3 && opc == 2) {
2933 /* PRFM - prefetch */
2936 if (opc == 3 && size > 1) {
2937 unallocated_encoding(s);
2940 is_store = (opc == 0);
2941 is_signed = extract32(opc, 1, 1);
2942 is_extended = (size < 3) && extract32(opc, 0, 1);
2946 gen_check_sp_alignment(s);
2948 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2950 tcg_rm = read_cpu_reg(s, rm, 1);
2951 ext_and_shift_reg(tcg_rm, tcg_rm, opt, shift ? size : 0);
2953 tcg_gen_add_i64(tcg_addr, tcg_addr, tcg_rm);
2957 do_fp_st(s, rt, tcg_addr, size);
2959 do_fp_ld(s, rt, tcg_addr, size);
2962 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2963 bool iss_sf = disas_ldst_compute_iss_sf(size, is_signed, opc);
2965 do_gpr_st(s, tcg_rt, tcg_addr, size,
2966 true, rt, iss_sf, false);
2968 do_gpr_ld(s, tcg_rt, tcg_addr, size,
2969 is_signed, is_extended,
2970 true, rt, iss_sf, false);
2976 * Load/store (unsigned immediate)
2978 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2979 * +----+-------+---+-----+-----+------------+-------+------+
2980 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2981 * +----+-------+---+-----+-----+------------+-------+------+
2984 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2985 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2987 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2988 * opc<0>: 0 -> store, 1 -> load
2989 * Rn: base address register (inc SP)
2990 * Rt: target register
2992 static void disas_ldst_reg_unsigned_imm(DisasContext *s, uint32_t insn,
2998 int rn = extract32(insn, 5, 5);
2999 unsigned int imm12 = extract32(insn, 10, 12);
3000 unsigned int offset;
3005 bool is_signed = false;
3006 bool is_extended = false;
3009 size |= (opc & 2) << 1;
3011 unallocated_encoding(s);
3014 is_store = !extract32(opc, 0, 1);
3015 if (!fp_access_check(s)) {
3019 if (size == 3 && opc == 2) {
3020 /* PRFM - prefetch */
3023 if (opc == 3 && size > 1) {
3024 unallocated_encoding(s);
3027 is_store = (opc == 0);
3028 is_signed = extract32(opc, 1, 1);
3029 is_extended = (size < 3) && extract32(opc, 0, 1);
3033 gen_check_sp_alignment(s);
3035 tcg_addr = read_cpu_reg_sp(s, rn, 1);
3036 offset = imm12 << size;
3037 tcg_gen_addi_i64(tcg_addr, tcg_addr, offset);
3041 do_fp_st(s, rt, tcg_addr, size);
3043 do_fp_ld(s, rt, tcg_addr, size);
3046 TCGv_i64 tcg_rt = cpu_reg(s, rt);
3047 bool iss_sf = disas_ldst_compute_iss_sf(size, is_signed, opc);
3049 do_gpr_st(s, tcg_rt, tcg_addr, size,
3050 true, rt, iss_sf, false);
3052 do_gpr_ld(s, tcg_rt, tcg_addr, size, is_signed, is_extended,
3053 true, rt, iss_sf, false);
3058 /* Atomic memory operations
3060 * 31 30 27 26 24 22 21 16 15 12 10 5 0
3061 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
3062 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
3063 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
3065 * Rt: the result register
3066 * Rn: base address or SP
3067 * Rs: the source register for the operation
3068 * V: vector flag (always 0 as of v8.3)
3072 static void disas_ldst_atomic(DisasContext *s, uint32_t insn,
3073 int size, int rt, bool is_vector)
3075 int rs = extract32(insn, 16, 5);
3076 int rn = extract32(insn, 5, 5);
3077 int o3_opc = extract32(insn, 12, 4);
3078 TCGv_i64 tcg_rn, tcg_rs;
3079 AtomicThreeOpFn *fn;
3081 if (is_vector || !dc_isar_feature(aa64_atomics, s)) {
3082 unallocated_encoding(s);
3086 case 000: /* LDADD */
3087 fn = tcg_gen_atomic_fetch_add_i64;
3089 case 001: /* LDCLR */
3090 fn = tcg_gen_atomic_fetch_and_i64;
3092 case 002: /* LDEOR */
3093 fn = tcg_gen_atomic_fetch_xor_i64;
3095 case 003: /* LDSET */
3096 fn = tcg_gen_atomic_fetch_or_i64;
3098 case 004: /* LDSMAX */
3099 fn = tcg_gen_atomic_fetch_smax_i64;
3101 case 005: /* LDSMIN */
3102 fn = tcg_gen_atomic_fetch_smin_i64;
3104 case 006: /* LDUMAX */
3105 fn = tcg_gen_atomic_fetch_umax_i64;
3107 case 007: /* LDUMIN */
3108 fn = tcg_gen_atomic_fetch_umin_i64;
3111 fn = tcg_gen_atomic_xchg_i64;
3114 unallocated_encoding(s);
3119 gen_check_sp_alignment(s);
3121 tcg_rn = cpu_reg_sp(s, rn);
3122 tcg_rs = read_cpu_reg(s, rs, true);
3124 if (o3_opc == 1) { /* LDCLR */
3125 tcg_gen_not_i64(tcg_rs, tcg_rs);
3128 /* The tcg atomic primitives are all full barriers. Therefore we
3129 * can ignore the Acquire and Release bits of this instruction.
3131 fn(cpu_reg(s, rt), tcg_rn, tcg_rs, get_mem_index(s),
3132 s->be_data | size | MO_ALIGN);
3136 * PAC memory operations
3138 * 31 30 27 26 24 22 21 12 11 10 5 0
3139 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3140 * | size | 1 1 1 | V | 0 0 | M S | 1 | imm9 | W | 1 | Rn | Rt |
3141 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3143 * Rt: the result register
3144 * Rn: base address or SP
3145 * V: vector flag (always 0 as of v8.3)
3146 * M: clear for key DA, set for key DB
3147 * W: pre-indexing flag
3150 static void disas_ldst_pac(DisasContext *s, uint32_t insn,
3151 int size, int rt, bool is_vector)
3153 int rn = extract32(insn, 5, 5);
3154 bool is_wback = extract32(insn, 11, 1);
3155 bool use_key_a = !extract32(insn, 23, 1);
3157 TCGv_i64 tcg_addr, tcg_rt;
3159 if (size != 3 || is_vector || !dc_isar_feature(aa64_pauth, s)) {
3160 unallocated_encoding(s);
3165 gen_check_sp_alignment(s);
3167 tcg_addr = read_cpu_reg_sp(s, rn, 1);
3169 if (s->pauth_active) {
3171 gen_helper_autda(tcg_addr, cpu_env, tcg_addr, cpu_X[31]);
3173 gen_helper_autdb(tcg_addr, cpu_env, tcg_addr, cpu_X[31]);
3177 /* Form the 10-bit signed, scaled offset. */
3178 offset = (extract32(insn, 22, 1) << 9) | extract32(insn, 12, 9);
3179 offset = sextract32(offset << size, 0, 10 + size);
3180 tcg_gen_addi_i64(tcg_addr, tcg_addr, offset);
3182 tcg_rt = cpu_reg(s, rt);
3184 do_gpr_ld(s, tcg_rt, tcg_addr, size, /* is_signed */ false,
3185 /* extend */ false, /* iss_valid */ !is_wback,
3186 /* iss_srt */ rt, /* iss_sf */ true, /* iss_ar */ false);
3189 tcg_gen_mov_i64(cpu_reg_sp(s, rn), tcg_addr);
3193 /* Load/store register (all forms) */
3194 static void disas_ldst_reg(DisasContext *s, uint32_t insn)
3196 int rt = extract32(insn, 0, 5);
3197 int opc = extract32(insn, 22, 2);
3198 bool is_vector = extract32(insn, 26, 1);
3199 int size = extract32(insn, 30, 2);
3201 switch (extract32(insn, 24, 2)) {
3203 if (extract32(insn, 21, 1) == 0) {
3204 /* Load/store register (unscaled immediate)
3205 * Load/store immediate pre/post-indexed
3206 * Load/store register unprivileged
3208 disas_ldst_reg_imm9(s, insn, opc, size, rt, is_vector);
3211 switch (extract32(insn, 10, 2)) {
3213 disas_ldst_atomic(s, insn, size, rt, is_vector);
3216 disas_ldst_reg_roffset(s, insn, opc, size, rt, is_vector);
3219 disas_ldst_pac(s, insn, size, rt, is_vector);
3224 disas_ldst_reg_unsigned_imm(s, insn, opc, size, rt, is_vector);
3227 unallocated_encoding(s);
3230 /* AdvSIMD load/store multiple structures
3232 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
3233 * +---+---+---------------+---+-------------+--------+------+------+------+
3234 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
3235 * +---+---+---------------+---+-------------+--------+------+------+------+
3237 * AdvSIMD load/store multiple structures (post-indexed)
3239 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
3240 * +---+---+---------------+---+---+---------+--------+------+------+------+
3241 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
3242 * +---+---+---------------+---+---+---------+--------+------+------+------+
3244 * Rt: first (or only) SIMD&FP register to be transferred
3245 * Rn: base address or SP
3246 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3248 static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)
3250 int rt = extract32(insn, 0, 5);
3251 int rn = extract32(insn, 5, 5);
3252 int rm = extract32(insn, 16, 5);
3253 int size = extract32(insn, 10, 2);
3254 int opcode = extract32(insn, 12, 4);
3255 bool is_store = !extract32(insn, 22, 1);
3256 bool is_postidx = extract32(insn, 23, 1);
3257 bool is_q = extract32(insn, 30, 1);
3258 TCGv_i64 tcg_addr, tcg_rn, tcg_ebytes;
3259 TCGMemOp endian = s->be_data;
3261 int ebytes; /* bytes per element */
3262 int elements; /* elements per vector */
3263 int rpt; /* num iterations */
3264 int selem; /* structure elements */
3267 if (extract32(insn, 31, 1) || extract32(insn, 21, 1)) {
3268 unallocated_encoding(s);
3272 if (!is_postidx && rm != 0) {
3273 unallocated_encoding(s);
3277 /* From the shared decode logic */
3308 unallocated_encoding(s);
3312 if (size == 3 && !is_q && selem != 1) {
3314 unallocated_encoding(s);
3318 if (!fp_access_check(s)) {
3323 gen_check_sp_alignment(s);
3326 /* For our purposes, bytes are always little-endian. */
3331 /* Consecutive little-endian elements from a single register
3332 * can be promoted to a larger little-endian operation.
3334 if (selem == 1 && endian == MO_LE) {
3338 elements = (is_q ? 16 : 8) / ebytes;
3340 tcg_rn = cpu_reg_sp(s, rn);
3341 tcg_addr = tcg_temp_new_i64();
3342 tcg_gen_mov_i64(tcg_addr, tcg_rn);
3343 tcg_ebytes = tcg_const_i64(ebytes);
3345 for (r = 0; r < rpt; r++) {
3347 for (e = 0; e < elements; e++) {
3349 for (xs = 0; xs < selem; xs++) {
3350 int tt = (rt + r + xs) % 32;
3352 do_vec_st(s, tt, e, tcg_addr, size, endian);
3354 do_vec_ld(s, tt, e, tcg_addr, size, endian);
3356 tcg_gen_add_i64(tcg_addr, tcg_addr, tcg_ebytes);
3362 /* For non-quad operations, setting a slice of the low
3363 * 64 bits of the register clears the high 64 bits (in
3364 * the ARM ARM pseudocode this is implicit in the fact
3365 * that 'rval' is a 64 bit wide variable).
3366 * For quad operations, we might still need to zero the
3369 for (r = 0; r < rpt * selem; r++) {
3370 int tt = (rt + r) % 32;
3371 clear_vec_high(s, is_q, tt);
3377 tcg_gen_mov_i64(tcg_rn, tcg_addr);
3379 tcg_gen_add_i64(tcg_rn, tcg_rn, cpu_reg(s, rm));
3382 tcg_temp_free_i64(tcg_ebytes);
3383 tcg_temp_free_i64(tcg_addr);
3386 /* AdvSIMD load/store single structure
3388 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3389 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3390 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3391 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3393 * AdvSIMD load/store single structure (post-indexed)
3395 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3396 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3397 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3398 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3400 * Rt: first (or only) SIMD&FP register to be transferred
3401 * Rn: base address or SP
3402 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3403 * index = encoded in Q:S:size dependent on size
3405 * lane_size = encoded in R, opc
3406 * transfer width = encoded in opc, S, size
3408 static void disas_ldst_single_struct(DisasContext *s, uint32_t insn)
3410 int rt = extract32(insn, 0, 5);
3411 int rn = extract32(insn, 5, 5);
3412 int rm = extract32(insn, 16, 5);
3413 int size = extract32(insn, 10, 2);
3414 int S = extract32(insn, 12, 1);
3415 int opc = extract32(insn, 13, 3);
3416 int R = extract32(insn, 21, 1);
3417 int is_load = extract32(insn, 22, 1);
3418 int is_postidx = extract32(insn, 23, 1);
3419 int is_q = extract32(insn, 30, 1);
3421 int scale = extract32(opc, 1, 2);
3422 int selem = (extract32(opc, 0, 1) << 1 | R) + 1;
3423 bool replicate = false;
3424 int index = is_q << 3 | S << 2 | size;
3426 TCGv_i64 tcg_addr, tcg_rn, tcg_ebytes;
3428 if (extract32(insn, 31, 1)) {
3429 unallocated_encoding(s);
3432 if (!is_postidx && rm != 0) {
3433 unallocated_encoding(s);
3439 if (!is_load || S) {
3440 unallocated_encoding(s);
3449 if (extract32(size, 0, 1)) {
3450 unallocated_encoding(s);
3456 if (extract32(size, 1, 1)) {
3457 unallocated_encoding(s);
3460 if (!extract32(size, 0, 1)) {
3464 unallocated_encoding(s);
3472 g_assert_not_reached();
3475 if (!fp_access_check(s)) {
3479 ebytes = 1 << scale;
3482 gen_check_sp_alignment(s);
3485 tcg_rn = cpu_reg_sp(s, rn);
3486 tcg_addr = tcg_temp_new_i64();
3487 tcg_gen_mov_i64(tcg_addr, tcg_rn);
3488 tcg_ebytes = tcg_const_i64(ebytes);
3490 for (xs = 0; xs < selem; xs++) {
3492 /* Load and replicate to all elements */
3493 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
3495 tcg_gen_qemu_ld_i64(tcg_tmp, tcg_addr,
3496 get_mem_index(s), s->be_data + scale);
3497 tcg_gen_gvec_dup_i64(scale, vec_full_reg_offset(s, rt),
3498 (is_q + 1) * 8, vec_full_reg_size(s),
3500 tcg_temp_free_i64(tcg_tmp);
3502 /* Load/store one element per register */
3504 do_vec_ld(s, rt, index, tcg_addr, scale, s->be_data);
3506 do_vec_st(s, rt, index, tcg_addr, scale, s->be_data);
3509 tcg_gen_add_i64(tcg_addr, tcg_addr, tcg_ebytes);
3515 tcg_gen_mov_i64(tcg_rn, tcg_addr);
3517 tcg_gen_add_i64(tcg_rn, tcg_rn, cpu_reg(s, rm));
3520 tcg_temp_free_i64(tcg_ebytes);
3521 tcg_temp_free_i64(tcg_addr);
3524 /* Loads and stores */
3525 static void disas_ldst(DisasContext *s, uint32_t insn)
3527 switch (extract32(insn, 24, 6)) {
3528 case 0x08: /* Load/store exclusive */
3529 disas_ldst_excl(s, insn);
3531 case 0x18: case 0x1c: /* Load register (literal) */
3532 disas_ld_lit(s, insn);
3534 case 0x28: case 0x29:
3535 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
3536 disas_ldst_pair(s, insn);
3538 case 0x38: case 0x39:
3539 case 0x3c: case 0x3d: /* Load/store register (all forms) */
3540 disas_ldst_reg(s, insn);
3542 case 0x0c: /* AdvSIMD load/store multiple structures */
3543 disas_ldst_multiple_struct(s, insn);
3545 case 0x0d: /* AdvSIMD load/store single structure */
3546 disas_ldst_single_struct(s, insn);
3549 unallocated_encoding(s);
3554 /* PC-rel. addressing
3555 * 31 30 29 28 24 23 5 4 0
3556 * +----+-------+-----------+-------------------+------+
3557 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
3558 * +----+-------+-----------+-------------------+------+
3560 static void disas_pc_rel_adr(DisasContext *s, uint32_t insn)
3562 unsigned int page, rd;
3566 page = extract32(insn, 31, 1);
3567 /* SignExtend(immhi:immlo) -> offset */
3568 offset = sextract64(insn, 5, 19);
3569 offset = offset << 2 | extract32(insn, 29, 2);
3570 rd = extract32(insn, 0, 5);
3574 /* ADRP (page based) */
3579 tcg_gen_movi_i64(cpu_reg(s, rd), base + offset);
3583 * Add/subtract (immediate)
3585 * 31 30 29 28 24 23 22 21 10 9 5 4 0
3586 * +--+--+--+-----------+-----+-------------+-----+-----+
3587 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
3588 * +--+--+--+-----------+-----+-------------+-----+-----+
3590 * sf: 0 -> 32bit, 1 -> 64bit
3591 * op: 0 -> add , 1 -> sub
3593 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
3595 static void disas_add_sub_imm(DisasContext *s, uint32_t insn)
3597 int rd = extract32(insn, 0, 5);
3598 int rn = extract32(insn, 5, 5);
3599 uint64_t imm = extract32(insn, 10, 12);
3600 int shift = extract32(insn, 22, 2);
3601 bool setflags = extract32(insn, 29, 1);
3602 bool sub_op = extract32(insn, 30, 1);
3603 bool is_64bit = extract32(insn, 31, 1);
3605 TCGv_i64 tcg_rn = cpu_reg_sp(s, rn);
3606 TCGv_i64 tcg_rd = setflags ? cpu_reg(s, rd) : cpu_reg_sp(s, rd);
3607 TCGv_i64 tcg_result;
3616 unallocated_encoding(s);
3620 tcg_result = tcg_temp_new_i64();
3623 tcg_gen_subi_i64(tcg_result, tcg_rn, imm);
3625 tcg_gen_addi_i64(tcg_result, tcg_rn, imm);
3628 TCGv_i64 tcg_imm = tcg_const_i64(imm);
3630 gen_sub_CC(is_64bit, tcg_result, tcg_rn, tcg_imm);
3632 gen_add_CC(is_64bit, tcg_result, tcg_rn, tcg_imm);
3634 tcg_temp_free_i64(tcg_imm);
3638 tcg_gen_mov_i64(tcg_rd, tcg_result);
3640 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
3643 tcg_temp_free_i64(tcg_result);
3646 /* The input should be a value in the bottom e bits (with higher
3647 * bits zero); returns that value replicated into every element
3648 * of size e in a 64 bit integer.
3650 static uint64_t bitfield_replicate(uint64_t mask, unsigned int e)
3660 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
3661 static inline uint64_t bitmask64(unsigned int length)
3663 assert(length > 0 && length <= 64);
3664 return ~0ULL >> (64 - length);
3667 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
3668 * only require the wmask. Returns false if the imms/immr/immn are a reserved
3669 * value (ie should cause a guest UNDEF exception), and true if they are
3670 * valid, in which case the decoded bit pattern is written to result.
3672 bool logic_imm_decode_wmask(uint64_t *result, unsigned int immn,
3673 unsigned int imms, unsigned int immr)
3676 unsigned e, levels, s, r;
3679 assert(immn < 2 && imms < 64 && immr < 64);
3681 /* The bit patterns we create here are 64 bit patterns which
3682 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
3683 * 64 bits each. Each element contains the same value: a run
3684 * of between 1 and e-1 non-zero bits, rotated within the
3685 * element by between 0 and e-1 bits.
3687 * The element size and run length are encoded into immn (1 bit)
3688 * and imms (6 bits) as follows:
3689 * 64 bit elements: immn = 1, imms = <length of run - 1>
3690 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
3691 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
3692 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
3693 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
3694 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
3695 * Notice that immn = 0, imms = 11111x is the only combination
3696 * not covered by one of the above options; this is reserved.
3697 * Further, <length of run - 1> all-ones is a reserved pattern.
3699 * In all cases the rotation is by immr % e (and immr is 6 bits).
3702 /* First determine the element size */
3703 len = 31 - clz32((immn << 6) | (~imms & 0x3f));
3705 /* This is the immn == 0, imms == 0x11111x case */
3715 /* <length of run - 1> mustn't be all-ones. */
3719 /* Create the value of one element: s+1 set bits rotated
3720 * by r within the element (which is e bits wide)...
3722 mask = bitmask64(s + 1);
3724 mask = (mask >> r) | (mask << (e - r));
3725 mask &= bitmask64(e);
3727 /* ...then replicate the element over the whole 64 bit value */
3728 mask = bitfield_replicate(mask, e);
3733 /* Logical (immediate)
3734 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3735 * +----+-----+-------------+---+------+------+------+------+
3736 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
3737 * +----+-----+-------------+---+------+------+------+------+
3739 static void disas_logic_imm(DisasContext *s, uint32_t insn)
3741 unsigned int sf, opc, is_n, immr, imms, rn, rd;
3742 TCGv_i64 tcg_rd, tcg_rn;
3744 bool is_and = false;
3746 sf = extract32(insn, 31, 1);
3747 opc = extract32(insn, 29, 2);
3748 is_n = extract32(insn, 22, 1);
3749 immr = extract32(insn, 16, 6);
3750 imms = extract32(insn, 10, 6);
3751 rn = extract32(insn, 5, 5);
3752 rd = extract32(insn, 0, 5);
3755 unallocated_encoding(s);
3759 if (opc == 0x3) { /* ANDS */
3760 tcg_rd = cpu_reg(s, rd);
3762 tcg_rd = cpu_reg_sp(s, rd);
3764 tcg_rn = cpu_reg(s, rn);
3766 if (!logic_imm_decode_wmask(&wmask, is_n, imms, immr)) {
3767 /* some immediate field values are reserved */
3768 unallocated_encoding(s);
3773 wmask &= 0xffffffff;
3777 case 0x3: /* ANDS */
3779 tcg_gen_andi_i64(tcg_rd, tcg_rn, wmask);
3783 tcg_gen_ori_i64(tcg_rd, tcg_rn, wmask);
3786 tcg_gen_xori_i64(tcg_rd, tcg_rn, wmask);
3789 assert(FALSE); /* must handle all above */
3793 if (!sf && !is_and) {
3794 /* zero extend final result; we know we can skip this for AND
3795 * since the immediate had the high 32 bits clear.
3797 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3800 if (opc == 3) { /* ANDS */
3801 gen_logic_CC(sf, tcg_rd);
3806 * Move wide (immediate)
3808 * 31 30 29 28 23 22 21 20 5 4 0
3809 * +--+-----+-------------+-----+----------------+------+
3810 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
3811 * +--+-----+-------------+-----+----------------+------+
3813 * sf: 0 -> 32 bit, 1 -> 64 bit
3814 * opc: 00 -> N, 10 -> Z, 11 -> K
3815 * hw: shift/16 (0,16, and sf only 32, 48)
3817 static void disas_movw_imm(DisasContext *s, uint32_t insn)
3819 int rd = extract32(insn, 0, 5);
3820 uint64_t imm = extract32(insn, 5, 16);
3821 int sf = extract32(insn, 31, 1);
3822 int opc = extract32(insn, 29, 2);
3823 int pos = extract32(insn, 21, 2) << 4;
3824 TCGv_i64 tcg_rd = cpu_reg(s, rd);
3827 if (!sf && (pos >= 32)) {
3828 unallocated_encoding(s);
3842 tcg_gen_movi_i64(tcg_rd, imm);
3845 tcg_imm = tcg_const_i64(imm);
3846 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_imm, pos, 16);
3847 tcg_temp_free_i64(tcg_imm);
3849 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3853 unallocated_encoding(s);
3859 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3860 * +----+-----+-------------+---+------+------+------+------+
3861 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3862 * +----+-----+-------------+---+------+------+------+------+
3864 static void disas_bitfield(DisasContext *s, uint32_t insn)
3866 unsigned int sf, n, opc, ri, si, rn, rd, bitsize, pos, len;
3867 TCGv_i64 tcg_rd, tcg_tmp;
3869 sf = extract32(insn, 31, 1);
3870 opc = extract32(insn, 29, 2);
3871 n = extract32(insn, 22, 1);
3872 ri = extract32(insn, 16, 6);
3873 si = extract32(insn, 10, 6);
3874 rn = extract32(insn, 5, 5);
3875 rd = extract32(insn, 0, 5);
3876 bitsize = sf ? 64 : 32;
3878 if (sf != n || ri >= bitsize || si >= bitsize || opc > 2) {
3879 unallocated_encoding(s);
3883 tcg_rd = cpu_reg(s, rd);
3885 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3886 to be smaller than bitsize, we'll never reference data outside the
3887 low 32-bits anyway. */
3888 tcg_tmp = read_cpu_reg(s, rn, 1);
3890 /* Recognize simple(r) extractions. */
3892 /* Wd<s-r:0> = Wn<s:r> */
3893 len = (si - ri) + 1;
3894 if (opc == 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
3895 tcg_gen_sextract_i64(tcg_rd, tcg_tmp, ri, len);
3897 } else if (opc == 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
3898 tcg_gen_extract_i64(tcg_rd, tcg_tmp, ri, len);
3901 /* opc == 1, BXFIL fall through to deposit */
3902 tcg_gen_extract_i64(tcg_tmp, tcg_tmp, ri, len);
3905 /* Handle the ri > si case with a deposit
3906 * Wd<32+s-r,32-r> = Wn<s:0>
3909 pos = (bitsize - ri) & (bitsize - 1);
3912 if (opc == 0 && len < ri) {
3913 /* SBFM: sign extend the destination field from len to fill
3914 the balance of the word. Let the deposit below insert all
3915 of those sign bits. */
3916 tcg_gen_sextract_i64(tcg_tmp, tcg_tmp, 0, len);
3920 if (opc == 1) { /* BFM, BXFIL */
3921 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_tmp, pos, len);
3923 /* SBFM or UBFM: We start with zero, and we haven't modified
3924 any bits outside bitsize, therefore the zero-extension
3925 below is unneeded. */
3926 tcg_gen_deposit_z_i64(tcg_rd, tcg_tmp, pos, len);
3931 if (!sf) { /* zero extend final result */
3932 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3937 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3938 * +----+------+-------------+---+----+------+--------+------+------+
3939 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3940 * +----+------+-------------+---+----+------+--------+------+------+
3942 static void disas_extract(DisasContext *s, uint32_t insn)
3944 unsigned int sf, n, rm, imm, rn, rd, bitsize, op21, op0;
3946 sf = extract32(insn, 31, 1);
3947 n = extract32(insn, 22, 1);
3948 rm = extract32(insn, 16, 5);
3949 imm = extract32(insn, 10, 6);
3950 rn = extract32(insn, 5, 5);
3951 rd = extract32(insn, 0, 5);
3952 op21 = extract32(insn, 29, 2);
3953 op0 = extract32(insn, 21, 1);
3954 bitsize = sf ? 64 : 32;
3956 if (sf != n || op21 || op0 || imm >= bitsize) {
3957 unallocated_encoding(s);
3959 TCGv_i64 tcg_rd, tcg_rm, tcg_rn;
3961 tcg_rd = cpu_reg(s, rd);
3963 if (unlikely(imm == 0)) {
3964 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3965 * so an extract from bit 0 is a special case.
3968 tcg_gen_mov_i64(tcg_rd, cpu_reg(s, rm));
3970 tcg_gen_ext32u_i64(tcg_rd, cpu_reg(s, rm));
3972 } else if (rm == rn) { /* ROR */
3973 tcg_rm = cpu_reg(s, rm);
3975 tcg_gen_rotri_i64(tcg_rd, tcg_rm, imm);
3977 TCGv_i32 tmp = tcg_temp_new_i32();
3978 tcg_gen_extrl_i64_i32(tmp, tcg_rm);
3979 tcg_gen_rotri_i32(tmp, tmp, imm);
3980 tcg_gen_extu_i32_i64(tcg_rd, tmp);
3981 tcg_temp_free_i32(tmp);
3984 tcg_rm = read_cpu_reg(s, rm, sf);
3985 tcg_rn = read_cpu_reg(s, rn, sf);
3986 tcg_gen_shri_i64(tcg_rm, tcg_rm, imm);
3987 tcg_gen_shli_i64(tcg_rn, tcg_rn, bitsize - imm);
3988 tcg_gen_or_i64(tcg_rd, tcg_rm, tcg_rn);
3990 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3996 /* Data processing - immediate */
3997 static void disas_data_proc_imm(DisasContext *s, uint32_t insn)
3999 switch (extract32(insn, 23, 6)) {
4000 case 0x20: case 0x21: /* PC-rel. addressing */
4001 disas_pc_rel_adr(s, insn);
4003 case 0x22: case 0x23: /* Add/subtract (immediate) */
4004 disas_add_sub_imm(s, insn);
4006 case 0x24: /* Logical (immediate) */
4007 disas_logic_imm(s, insn);
4009 case 0x25: /* Move wide (immediate) */
4010 disas_movw_imm(s, insn);
4012 case 0x26: /* Bitfield */
4013 disas_bitfield(s, insn);
4015 case 0x27: /* Extract */
4016 disas_extract(s, insn);
4019 unallocated_encoding(s);
4024 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
4025 * Note that it is the caller's responsibility to ensure that the
4026 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
4027 * mandated semantics for out of range shifts.
4029 static void shift_reg(TCGv_i64 dst, TCGv_i64 src, int sf,
4030 enum a64_shift_type shift_type, TCGv_i64 shift_amount)
4032 switch (shift_type) {
4033 case A64_SHIFT_TYPE_LSL:
4034 tcg_gen_shl_i64(dst, src, shift_amount);
4036 case A64_SHIFT_TYPE_LSR:
4037 tcg_gen_shr_i64(dst, src, shift_amount);
4039 case A64_SHIFT_TYPE_ASR:
4041 tcg_gen_ext32s_i64(dst, src);
4043 tcg_gen_sar_i64(dst, sf ? src : dst, shift_amount);
4045 case A64_SHIFT_TYPE_ROR:
4047 tcg_gen_rotr_i64(dst, src, shift_amount);
4050 t0 = tcg_temp_new_i32();
4051 t1 = tcg_temp_new_i32();
4052 tcg_gen_extrl_i64_i32(t0, src);
4053 tcg_gen_extrl_i64_i32(t1, shift_amount);
4054 tcg_gen_rotr_i32(t0, t0, t1);
4055 tcg_gen_extu_i32_i64(dst, t0);
4056 tcg_temp_free_i32(t0);
4057 tcg_temp_free_i32(t1);
4061 assert(FALSE); /* all shift types should be handled */
4065 if (!sf) { /* zero extend final result */
4066 tcg_gen_ext32u_i64(dst, dst);
4070 /* Shift a TCGv src by immediate, put result in dst.
4071 * The shift amount must be in range (this should always be true as the
4072 * relevant instructions will UNDEF on bad shift immediates).
4074 static void shift_reg_imm(TCGv_i64 dst, TCGv_i64 src, int sf,
4075 enum a64_shift_type shift_type, unsigned int shift_i)
4077 assert(shift_i < (sf ? 64 : 32));
4080 tcg_gen_mov_i64(dst, src);
4082 TCGv_i64 shift_const;
4084 shift_const = tcg_const_i64(shift_i);
4085 shift_reg(dst, src, sf, shift_type, shift_const);
4086 tcg_temp_free_i64(shift_const);
4090 /* Logical (shifted register)
4091 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4092 * +----+-----+-----------+-------+---+------+--------+------+------+
4093 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
4094 * +----+-----+-----------+-------+---+------+--------+------+------+
4096 static void disas_logic_reg(DisasContext *s, uint32_t insn)
4098 TCGv_i64 tcg_rd, tcg_rn, tcg_rm;
4099 unsigned int sf, opc, shift_type, invert, rm, shift_amount, rn, rd;
4101 sf = extract32(insn, 31, 1);
4102 opc = extract32(insn, 29, 2);
4103 shift_type = extract32(insn, 22, 2);
4104 invert = extract32(insn, 21, 1);
4105 rm = extract32(insn, 16, 5);
4106 shift_amount = extract32(insn, 10, 6);
4107 rn = extract32(insn, 5, 5);
4108 rd = extract32(insn, 0, 5);
4110 if (!sf && (shift_amount & (1 << 5))) {
4111 unallocated_encoding(s);
4115 tcg_rd = cpu_reg(s, rd);
4117 if (opc == 1 && shift_amount == 0 && shift_type == 0 && rn == 31) {
4118 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
4119 * register-register MOV and MVN, so it is worth special casing.
4121 tcg_rm = cpu_reg(s, rm);
4123 tcg_gen_not_i64(tcg_rd, tcg_rm);
4125 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
4129 tcg_gen_mov_i64(tcg_rd, tcg_rm);
4131 tcg_gen_ext32u_i64(tcg_rd, tcg_rm);
4137 tcg_rm = read_cpu_reg(s, rm, sf);
4140 shift_reg_imm(tcg_rm, tcg_rm, sf, shift_type, shift_amount);
4143 tcg_rn = cpu_reg(s, rn);
4145 switch (opc | (invert << 2)) {
4148 tcg_gen_and_i64(tcg_rd, tcg_rn, tcg_rm);
4151 tcg_gen_or_i64(tcg_rd, tcg_rn, tcg_rm);
4154 tcg_gen_xor_i64(tcg_rd, tcg_rn, tcg_rm);
4158 tcg_gen_andc_i64(tcg_rd, tcg_rn, tcg_rm);
4161 tcg_gen_orc_i64(tcg_rd, tcg_rn, tcg_rm);
4164 tcg_gen_eqv_i64(tcg_rd, tcg_rn, tcg_rm);
4172 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
4176 gen_logic_CC(sf, tcg_rd);
4181 * Add/subtract (extended register)
4183 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
4184 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4185 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
4186 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4188 * sf: 0 -> 32bit, 1 -> 64bit
4189 * op: 0 -> add , 1 -> sub
4192 * option: extension type (see DecodeRegExtend)
4193 * imm3: optional shift to Rm
4195 * Rd = Rn + LSL(extend(Rm), amount)
4197 static void disas_add_sub_ext_reg(DisasContext *s, uint32_t insn)
4199 int rd = extract32(insn, 0, 5);
4200 int rn = extract32(insn, 5, 5);
4201 int imm3 = extract32(insn, 10, 3);
4202 int option = extract32(insn, 13, 3);
4203 int rm = extract32(insn, 16, 5);
4204 int opt = extract32(insn, 22, 2);
4205 bool setflags = extract32(insn, 29, 1);
4206 bool sub_op = extract32(insn, 30, 1);
4207 bool sf = extract32(insn, 31, 1);
4209 TCGv_i64 tcg_rm, tcg_rn; /* temps */
4211 TCGv_i64 tcg_result;
4213 if (imm3 > 4 || opt != 0) {
4214 unallocated_encoding(s);
4218 /* non-flag setting ops may use SP */
4220 tcg_rd = cpu_reg_sp(s, rd);
4222 tcg_rd = cpu_reg(s, rd);
4224 tcg_rn = read_cpu_reg_sp(s, rn, sf);
4226 tcg_rm = read_cpu_reg(s, rm, sf);
4227 ext_and_shift_reg(tcg_rm, tcg_rm, option, imm3);
4229 tcg_result = tcg_temp_new_i64();
4233 tcg_gen_sub_i64(tcg_result, tcg_rn, tcg_rm);
4235 tcg_gen_add_i64(tcg_result, tcg_rn, tcg_rm);
4239 gen_sub_CC(sf, tcg_result, tcg_rn, tcg_rm);
4241 gen_add_CC(sf, tcg_result, tcg_rn, tcg_rm);
4246 tcg_gen_mov_i64(tcg_rd, tcg_result);
4248 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
4251 tcg_temp_free_i64(tcg_result);
4255 * Add/subtract (shifted register)
4257 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4258 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4259 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
4260 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4262 * sf: 0 -> 32bit, 1 -> 64bit
4263 * op: 0 -> add , 1 -> sub
4265 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
4266 * imm6: Shift amount to apply to Rm before the add/sub
4268 static void disas_add_sub_reg(DisasContext *s, uint32_t insn)
4270 int rd = extract32(insn, 0, 5);
4271 int rn = extract32(insn, 5, 5);
4272 int imm6 = extract32(insn, 10, 6);
4273 int rm = extract32(insn, 16, 5);
4274 int shift_type = extract32(insn, 22, 2);
4275 bool setflags = extract32(insn, 29, 1);
4276 bool sub_op = extract32(insn, 30, 1);
4277 bool sf = extract32(insn, 31, 1);
4279 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4280 TCGv_i64 tcg_rn, tcg_rm;
4281 TCGv_i64 tcg_result;
4283 if ((shift_type == 3) || (!sf && (imm6 > 31))) {
4284 unallocated_encoding(s);
4288 tcg_rn = read_cpu_reg(s, rn, sf);
4289 tcg_rm = read_cpu_reg(s, rm, sf);
4291 shift_reg_imm(tcg_rm, tcg_rm, sf, shift_type, imm6);
4293 tcg_result = tcg_temp_new_i64();
4297 tcg_gen_sub_i64(tcg_result, tcg_rn, tcg_rm);
4299 tcg_gen_add_i64(tcg_result, tcg_rn, tcg_rm);
4303 gen_sub_CC(sf, tcg_result, tcg_rn, tcg_rm);
4305 gen_add_CC(sf, tcg_result, tcg_rn, tcg_rm);
4310 tcg_gen_mov_i64(tcg_rd, tcg_result);
4312 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
4315 tcg_temp_free_i64(tcg_result);
4318 /* Data-processing (3 source)
4320 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
4321 * +--+------+-----------+------+------+----+------+------+------+
4322 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
4323 * +--+------+-----------+------+------+----+------+------+------+
4325 static void disas_data_proc_3src(DisasContext *s, uint32_t insn)
4327 int rd = extract32(insn, 0, 5);
4328 int rn = extract32(insn, 5, 5);
4329 int ra = extract32(insn, 10, 5);
4330 int rm = extract32(insn, 16, 5);
4331 int op_id = (extract32(insn, 29, 3) << 4) |
4332 (extract32(insn, 21, 3) << 1) |
4333 extract32(insn, 15, 1);
4334 bool sf = extract32(insn, 31, 1);
4335 bool is_sub = extract32(op_id, 0, 1);
4336 bool is_high = extract32(op_id, 2, 1);
4337 bool is_signed = false;
4342 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
4344 case 0x42: /* SMADDL */
4345 case 0x43: /* SMSUBL */
4346 case 0x44: /* SMULH */
4349 case 0x0: /* MADD (32bit) */
4350 case 0x1: /* MSUB (32bit) */
4351 case 0x40: /* MADD (64bit) */
4352 case 0x41: /* MSUB (64bit) */
4353 case 0x4a: /* UMADDL */
4354 case 0x4b: /* UMSUBL */
4355 case 0x4c: /* UMULH */
4358 unallocated_encoding(s);
4363 TCGv_i64 low_bits = tcg_temp_new_i64(); /* low bits discarded */
4364 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4365 TCGv_i64 tcg_rn = cpu_reg(s, rn);
4366 TCGv_i64 tcg_rm = cpu_reg(s, rm);
4369 tcg_gen_muls2_i64(low_bits, tcg_rd, tcg_rn, tcg_rm);
4371 tcg_gen_mulu2_i64(low_bits, tcg_rd, tcg_rn, tcg_rm);
4374 tcg_temp_free_i64(low_bits);
4378 tcg_op1 = tcg_temp_new_i64();
4379 tcg_op2 = tcg_temp_new_i64();
4380 tcg_tmp = tcg_temp_new_i64();
4383 tcg_gen_mov_i64(tcg_op1, cpu_reg(s, rn));
4384 tcg_gen_mov_i64(tcg_op2, cpu_reg(s, rm));
4387 tcg_gen_ext32s_i64(tcg_op1, cpu_reg(s, rn));
4388 tcg_gen_ext32s_i64(tcg_op2, cpu_reg(s, rm));
4390 tcg_gen_ext32u_i64(tcg_op1, cpu_reg(s, rn));
4391 tcg_gen_ext32u_i64(tcg_op2, cpu_reg(s, rm));
4395 if (ra == 31 && !is_sub) {
4396 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
4397 tcg_gen_mul_i64(cpu_reg(s, rd), tcg_op1, tcg_op2);
4399 tcg_gen_mul_i64(tcg_tmp, tcg_op1, tcg_op2);
4401 tcg_gen_sub_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
4403 tcg_gen_add_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
4408 tcg_gen_ext32u_i64(cpu_reg(s, rd), cpu_reg(s, rd));
4411 tcg_temp_free_i64(tcg_op1);
4412 tcg_temp_free_i64(tcg_op2);
4413 tcg_temp_free_i64(tcg_tmp);
4416 /* Add/subtract (with carry)
4417 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
4418 * +--+--+--+------------------------+------+---------+------+-----+
4419 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
4420 * +--+--+--+------------------------+------+---------+------+-----+
4424 static void disas_adc_sbc(DisasContext *s, uint32_t insn)
4426 unsigned int sf, op, setflags, rm, rn, rd;
4427 TCGv_i64 tcg_y, tcg_rn, tcg_rd;
4429 if (extract32(insn, 10, 6) != 0) {
4430 unallocated_encoding(s);
4434 sf = extract32(insn, 31, 1);
4435 op = extract32(insn, 30, 1);
4436 setflags = extract32(insn, 29, 1);
4437 rm = extract32(insn, 16, 5);
4438 rn = extract32(insn, 5, 5);
4439 rd = extract32(insn, 0, 5);
4441 tcg_rd = cpu_reg(s, rd);
4442 tcg_rn = cpu_reg(s, rn);
4445 tcg_y = new_tmp_a64(s);
4446 tcg_gen_not_i64(tcg_y, cpu_reg(s, rm));
4448 tcg_y = cpu_reg(s, rm);
4452 gen_adc_CC(sf, tcg_rd, tcg_rn, tcg_y);
4454 gen_adc(sf, tcg_rd, tcg_rn, tcg_y);
4458 /* Conditional compare (immediate / register)
4459 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4460 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4461 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
4462 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4465 static void disas_cc(DisasContext *s, uint32_t insn)
4467 unsigned int sf, op, y, cond, rn, nzcv, is_imm;
4468 TCGv_i32 tcg_t0, tcg_t1, tcg_t2;
4469 TCGv_i64 tcg_tmp, tcg_y, tcg_rn;
4472 if (!extract32(insn, 29, 1)) {
4473 unallocated_encoding(s);
4476 if (insn & (1 << 10 | 1 << 4)) {
4477 unallocated_encoding(s);
4480 sf = extract32(insn, 31, 1);
4481 op = extract32(insn, 30, 1);
4482 is_imm = extract32(insn, 11, 1);
4483 y = extract32(insn, 16, 5); /* y = rm (reg) or imm5 (imm) */
4484 cond = extract32(insn, 12, 4);
4485 rn = extract32(insn, 5, 5);
4486 nzcv = extract32(insn, 0, 4);
4488 /* Set T0 = !COND. */
4489 tcg_t0 = tcg_temp_new_i32();
4490 arm_test_cc(&c, cond);
4491 tcg_gen_setcondi_i32(tcg_invert_cond(c.cond), tcg_t0, c.value, 0);
4494 /* Load the arguments for the new comparison. */
4496 tcg_y = new_tmp_a64(s);
4497 tcg_gen_movi_i64(tcg_y, y);
4499 tcg_y = cpu_reg(s, y);
4501 tcg_rn = cpu_reg(s, rn);
4503 /* Set the flags for the new comparison. */
4504 tcg_tmp = tcg_temp_new_i64();
4506 gen_sub_CC(sf, tcg_tmp, tcg_rn, tcg_y);
4508 gen_add_CC(sf, tcg_tmp, tcg_rn, tcg_y);
4510 tcg_temp_free_i64(tcg_tmp);
4512 /* If COND was false, force the flags to #nzcv. Compute two masks
4513 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
4514 * For tcg hosts that support ANDC, we can make do with just T1.
4515 * In either case, allow the tcg optimizer to delete any unused mask.
4517 tcg_t1 = tcg_temp_new_i32();
4518 tcg_t2 = tcg_temp_new_i32();
4519 tcg_gen_neg_i32(tcg_t1, tcg_t0);
4520 tcg_gen_subi_i32(tcg_t2, tcg_t0, 1);
4522 if (nzcv & 8) { /* N */
4523 tcg_gen_or_i32(cpu_NF, cpu_NF, tcg_t1);
4525 if (TCG_TARGET_HAS_andc_i32) {
4526 tcg_gen_andc_i32(cpu_NF, cpu_NF, tcg_t1);
4528 tcg_gen_and_i32(cpu_NF, cpu_NF, tcg_t2);
4531 if (nzcv & 4) { /* Z */
4532 if (TCG_TARGET_HAS_andc_i32) {
4533 tcg_gen_andc_i32(cpu_ZF, cpu_ZF, tcg_t1);
4535 tcg_gen_and_i32(cpu_ZF, cpu_ZF, tcg_t2);
4538 tcg_gen_or_i32(cpu_ZF, cpu_ZF, tcg_t0);
4540 if (nzcv & 2) { /* C */
4541 tcg_gen_or_i32(cpu_CF, cpu_CF, tcg_t0);
4543 if (TCG_TARGET_HAS_andc_i32) {
4544 tcg_gen_andc_i32(cpu_CF, cpu_CF, tcg_t1);
4546 tcg_gen_and_i32(cpu_CF, cpu_CF, tcg_t2);
4549 if (nzcv & 1) { /* V */
4550 tcg_gen_or_i32(cpu_VF, cpu_VF, tcg_t1);
4552 if (TCG_TARGET_HAS_andc_i32) {
4553 tcg_gen_andc_i32(cpu_VF, cpu_VF, tcg_t1);
4555 tcg_gen_and_i32(cpu_VF, cpu_VF, tcg_t2);
4558 tcg_temp_free_i32(tcg_t0);
4559 tcg_temp_free_i32(tcg_t1);
4560 tcg_temp_free_i32(tcg_t2);
4563 /* Conditional select
4564 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
4565 * +----+----+---+-----------------+------+------+-----+------+------+
4566 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
4567 * +----+----+---+-----------------+------+------+-----+------+------+
4569 static void disas_cond_select(DisasContext *s, uint32_t insn)
4571 unsigned int sf, else_inv, rm, cond, else_inc, rn, rd;
4572 TCGv_i64 tcg_rd, zero;
4575 if (extract32(insn, 29, 1) || extract32(insn, 11, 1)) {
4576 /* S == 1 or op2<1> == 1 */
4577 unallocated_encoding(s);
4580 sf = extract32(insn, 31, 1);
4581 else_inv = extract32(insn, 30, 1);
4582 rm = extract32(insn, 16, 5);
4583 cond = extract32(insn, 12, 4);
4584 else_inc = extract32(insn, 10, 1);
4585 rn = extract32(insn, 5, 5);
4586 rd = extract32(insn, 0, 5);
4588 tcg_rd = cpu_reg(s, rd);
4590 a64_test_cc(&c, cond);
4591 zero = tcg_const_i64(0);
4593 if (rn == 31 && rm == 31 && (else_inc ^ else_inv)) {
4595 tcg_gen_setcond_i64(tcg_invert_cond(c.cond), tcg_rd, c.value, zero);
4597 tcg_gen_neg_i64(tcg_rd, tcg_rd);
4600 TCGv_i64 t_true = cpu_reg(s, rn);
4601 TCGv_i64 t_false = read_cpu_reg(s, rm, 1);
4602 if (else_inv && else_inc) {
4603 tcg_gen_neg_i64(t_false, t_false);
4604 } else if (else_inv) {
4605 tcg_gen_not_i64(t_false, t_false);
4606 } else if (else_inc) {
4607 tcg_gen_addi_i64(t_false, t_false, 1);
4609 tcg_gen_movcond_i64(c.cond, tcg_rd, c.value, zero, t_true, t_false);
4612 tcg_temp_free_i64(zero);
4616 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
4620 static void handle_clz(DisasContext *s, unsigned int sf,
4621 unsigned int rn, unsigned int rd)
4623 TCGv_i64 tcg_rd, tcg_rn;
4624 tcg_rd = cpu_reg(s, rd);
4625 tcg_rn = cpu_reg(s, rn);
4628 tcg_gen_clzi_i64(tcg_rd, tcg_rn, 64);
4630 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
4631 tcg_gen_extrl_i64_i32(tcg_tmp32, tcg_rn);
4632 tcg_gen_clzi_i32(tcg_tmp32, tcg_tmp32, 32);
4633 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
4634 tcg_temp_free_i32(tcg_tmp32);
4638 static void handle_cls(DisasContext *s, unsigned int sf,
4639 unsigned int rn, unsigned int rd)
4641 TCGv_i64 tcg_rd, tcg_rn;
4642 tcg_rd = cpu_reg(s, rd);
4643 tcg_rn = cpu_reg(s, rn);
4646 tcg_gen_clrsb_i64(tcg_rd, tcg_rn);
4648 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
4649 tcg_gen_extrl_i64_i32(tcg_tmp32, tcg_rn);
4650 tcg_gen_clrsb_i32(tcg_tmp32, tcg_tmp32);
4651 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
4652 tcg_temp_free_i32(tcg_tmp32);
4656 static void handle_rbit(DisasContext *s, unsigned int sf,
4657 unsigned int rn, unsigned int rd)
4659 TCGv_i64 tcg_rd, tcg_rn;
4660 tcg_rd = cpu_reg(s, rd);
4661 tcg_rn = cpu_reg(s, rn);
4664 gen_helper_rbit64(tcg_rd, tcg_rn);
4666 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
4667 tcg_gen_extrl_i64_i32(tcg_tmp32, tcg_rn);
4668 gen_helper_rbit(tcg_tmp32, tcg_tmp32);
4669 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
4670 tcg_temp_free_i32(tcg_tmp32);
4674 /* REV with sf==1, opcode==3 ("REV64") */
4675 static void handle_rev64(DisasContext *s, unsigned int sf,
4676 unsigned int rn, unsigned int rd)
4679 unallocated_encoding(s);
4682 tcg_gen_bswap64_i64(cpu_reg(s, rd), cpu_reg(s, rn));
4685 /* REV with sf==0, opcode==2
4686 * REV32 (sf==1, opcode==2)
4688 static void handle_rev32(DisasContext *s, unsigned int sf,
4689 unsigned int rn, unsigned int rd)
4691 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4694 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
4695 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
4697 /* bswap32_i64 requires zero high word */
4698 tcg_gen_ext32u_i64(tcg_tmp, tcg_rn);
4699 tcg_gen_bswap32_i64(tcg_rd, tcg_tmp);
4700 tcg_gen_shri_i64(tcg_tmp, tcg_rn, 32);
4701 tcg_gen_bswap32_i64(tcg_tmp, tcg_tmp);
4702 tcg_gen_concat32_i64(tcg_rd, tcg_rd, tcg_tmp);
4704 tcg_temp_free_i64(tcg_tmp);
4706 tcg_gen_ext32u_i64(tcg_rd, cpu_reg(s, rn));
4707 tcg_gen_bswap32_i64(tcg_rd, tcg_rd);
4711 /* REV16 (opcode==1) */
4712 static void handle_rev16(DisasContext *s, unsigned int sf,
4713 unsigned int rn, unsigned int rd)
4715 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4716 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
4717 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
4718 TCGv_i64 mask = tcg_const_i64(sf ? 0x00ff00ff00ff00ffull : 0x00ff00ff);
4720 tcg_gen_shri_i64(tcg_tmp, tcg_rn, 8);
4721 tcg_gen_and_i64(tcg_rd, tcg_rn, mask);
4722 tcg_gen_and_i64(tcg_tmp, tcg_tmp, mask);
4723 tcg_gen_shli_i64(tcg_rd, tcg_rd, 8);
4724 tcg_gen_or_i64(tcg_rd, tcg_rd, tcg_tmp);
4726 tcg_temp_free_i64(mask);
4727 tcg_temp_free_i64(tcg_tmp);
4730 /* Data-processing (1 source)
4731 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4732 * +----+---+---+-----------------+---------+--------+------+------+
4733 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
4734 * +----+---+---+-----------------+---------+--------+------+------+
4736 static void disas_data_proc_1src(DisasContext *s, uint32_t insn)
4738 unsigned int sf, opcode, opcode2, rn, rd;
4741 if (extract32(insn, 29, 1)) {
4742 unallocated_encoding(s);
4746 sf = extract32(insn, 31, 1);
4747 opcode = extract32(insn, 10, 6);
4748 opcode2 = extract32(insn, 16, 5);
4749 rn = extract32(insn, 5, 5);
4750 rd = extract32(insn, 0, 5);
4752 #define MAP(SF, O2, O1) ((SF) | (O1 << 1) | (O2 << 7))
4754 switch (MAP(sf, opcode2, opcode)) {
4755 case MAP(0, 0x00, 0x00): /* RBIT */
4756 case MAP(1, 0x00, 0x00):
4757 handle_rbit(s, sf, rn, rd);
4759 case MAP(0, 0x00, 0x01): /* REV16 */
4760 case MAP(1, 0x00, 0x01):
4761 handle_rev16(s, sf, rn, rd);
4763 case MAP(0, 0x00, 0x02): /* REV/REV32 */
4764 case MAP(1, 0x00, 0x02):
4765 handle_rev32(s, sf, rn, rd);
4767 case MAP(1, 0x00, 0x03): /* REV64 */
4768 handle_rev64(s, sf, rn, rd);
4770 case MAP(0, 0x00, 0x04): /* CLZ */
4771 case MAP(1, 0x00, 0x04):
4772 handle_clz(s, sf, rn, rd);
4774 case MAP(0, 0x00, 0x05): /* CLS */
4775 case MAP(1, 0x00, 0x05):
4776 handle_cls(s, sf, rn, rd);
4778 case MAP(1, 0x01, 0x00): /* PACIA */
4779 if (s->pauth_active) {
4780 tcg_rd = cpu_reg(s, rd);
4781 gen_helper_pacia(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4782 } else if (!dc_isar_feature(aa64_pauth, s)) {
4783 goto do_unallocated;
4786 case MAP(1, 0x01, 0x01): /* PACIB */
4787 if (s->pauth_active) {
4788 tcg_rd = cpu_reg(s, rd);
4789 gen_helper_pacib(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4790 } else if (!dc_isar_feature(aa64_pauth, s)) {
4791 goto do_unallocated;
4794 case MAP(1, 0x01, 0x02): /* PACDA */
4795 if (s->pauth_active) {
4796 tcg_rd = cpu_reg(s, rd);
4797 gen_helper_pacda(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4798 } else if (!dc_isar_feature(aa64_pauth, s)) {
4799 goto do_unallocated;
4802 case MAP(1, 0x01, 0x03): /* PACDB */
4803 if (s->pauth_active) {
4804 tcg_rd = cpu_reg(s, rd);
4805 gen_helper_pacdb(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4806 } else if (!dc_isar_feature(aa64_pauth, s)) {
4807 goto do_unallocated;
4810 case MAP(1, 0x01, 0x04): /* AUTIA */
4811 if (s->pauth_active) {
4812 tcg_rd = cpu_reg(s, rd);
4813 gen_helper_autia(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4814 } else if (!dc_isar_feature(aa64_pauth, s)) {
4815 goto do_unallocated;
4818 case MAP(1, 0x01, 0x05): /* AUTIB */
4819 if (s->pauth_active) {
4820 tcg_rd = cpu_reg(s, rd);
4821 gen_helper_autib(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4822 } else if (!dc_isar_feature(aa64_pauth, s)) {
4823 goto do_unallocated;
4826 case MAP(1, 0x01, 0x06): /* AUTDA */
4827 if (s->pauth_active) {
4828 tcg_rd = cpu_reg(s, rd);
4829 gen_helper_autda(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4830 } else if (!dc_isar_feature(aa64_pauth, s)) {
4831 goto do_unallocated;
4834 case MAP(1, 0x01, 0x07): /* AUTDB */
4835 if (s->pauth_active) {
4836 tcg_rd = cpu_reg(s, rd);
4837 gen_helper_autdb(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4838 } else if (!dc_isar_feature(aa64_pauth, s)) {
4839 goto do_unallocated;
4842 case MAP(1, 0x01, 0x08): /* PACIZA */
4843 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4844 goto do_unallocated;
4845 } else if (s->pauth_active) {
4846 tcg_rd = cpu_reg(s, rd);
4847 gen_helper_pacia(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4850 case MAP(1, 0x01, 0x09): /* PACIZB */
4851 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4852 goto do_unallocated;
4853 } else if (s->pauth_active) {
4854 tcg_rd = cpu_reg(s, rd);
4855 gen_helper_pacib(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4858 case MAP(1, 0x01, 0x0a): /* PACDZA */
4859 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4860 goto do_unallocated;
4861 } else if (s->pauth_active) {
4862 tcg_rd = cpu_reg(s, rd);
4863 gen_helper_pacda(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4866 case MAP(1, 0x01, 0x0b): /* PACDZB */
4867 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4868 goto do_unallocated;
4869 } else if (s->pauth_active) {
4870 tcg_rd = cpu_reg(s, rd);
4871 gen_helper_pacdb(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4874 case MAP(1, 0x01, 0x0c): /* AUTIZA */
4875 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4876 goto do_unallocated;
4877 } else if (s->pauth_active) {
4878 tcg_rd = cpu_reg(s, rd);
4879 gen_helper_autia(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4882 case MAP(1, 0x01, 0x0d): /* AUTIZB */
4883 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4884 goto do_unallocated;
4885 } else if (s->pauth_active) {
4886 tcg_rd = cpu_reg(s, rd);
4887 gen_helper_autib(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4890 case MAP(1, 0x01, 0x0e): /* AUTDZA */
4891 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4892 goto do_unallocated;
4893 } else if (s->pauth_active) {
4894 tcg_rd = cpu_reg(s, rd);
4895 gen_helper_autda(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4898 case MAP(1, 0x01, 0x0f): /* AUTDZB */
4899 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4900 goto do_unallocated;
4901 } else if (s->pauth_active) {
4902 tcg_rd = cpu_reg(s, rd);
4903 gen_helper_autdb(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4906 case MAP(1, 0x01, 0x10): /* XPACI */
4907 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4908 goto do_unallocated;
4909 } else if (s->pauth_active) {
4910 tcg_rd = cpu_reg(s, rd);
4911 gen_helper_xpaci(tcg_rd, cpu_env, tcg_rd);
4914 case MAP(1, 0x01, 0x11): /* XPACD */
4915 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4916 goto do_unallocated;
4917 } else if (s->pauth_active) {
4918 tcg_rd = cpu_reg(s, rd);
4919 gen_helper_xpacd(tcg_rd, cpu_env, tcg_rd);
4924 unallocated_encoding(s);
4931 static void handle_div(DisasContext *s, bool is_signed, unsigned int sf,
4932 unsigned int rm, unsigned int rn, unsigned int rd)
4934 TCGv_i64 tcg_n, tcg_m, tcg_rd;
4935 tcg_rd = cpu_reg(s, rd);
4937 if (!sf && is_signed) {
4938 tcg_n = new_tmp_a64(s);
4939 tcg_m = new_tmp_a64(s);
4940 tcg_gen_ext32s_i64(tcg_n, cpu_reg(s, rn));
4941 tcg_gen_ext32s_i64(tcg_m, cpu_reg(s, rm));
4943 tcg_n = read_cpu_reg(s, rn, sf);
4944 tcg_m = read_cpu_reg(s, rm, sf);
4948 gen_helper_sdiv64(tcg_rd, tcg_n, tcg_m);
4950 gen_helper_udiv64(tcg_rd, tcg_n, tcg_m);
4953 if (!sf) { /* zero extend final result */
4954 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
4958 /* LSLV, LSRV, ASRV, RORV */
4959 static void handle_shift_reg(DisasContext *s,
4960 enum a64_shift_type shift_type, unsigned int sf,
4961 unsigned int rm, unsigned int rn, unsigned int rd)
4963 TCGv_i64 tcg_shift = tcg_temp_new_i64();
4964 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4965 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
4967 tcg_gen_andi_i64(tcg_shift, cpu_reg(s, rm), sf ? 63 : 31);
4968 shift_reg(tcg_rd, tcg_rn, sf, shift_type, tcg_shift);
4969 tcg_temp_free_i64(tcg_shift);
4972 /* CRC32[BHWX], CRC32C[BHWX] */
4973 static void handle_crc32(DisasContext *s,
4974 unsigned int sf, unsigned int sz, bool crc32c,
4975 unsigned int rm, unsigned int rn, unsigned int rd)
4977 TCGv_i64 tcg_acc, tcg_val;
4980 if (!dc_isar_feature(aa64_crc32, s)
4981 || (sf == 1 && sz != 3)
4982 || (sf == 0 && sz == 3)) {
4983 unallocated_encoding(s);
4988 tcg_val = cpu_reg(s, rm);
5002 g_assert_not_reached();
5004 tcg_val = new_tmp_a64(s);
5005 tcg_gen_andi_i64(tcg_val, cpu_reg(s, rm), mask);
5008 tcg_acc = cpu_reg(s, rn);
5009 tcg_bytes = tcg_const_i32(1 << sz);
5012 gen_helper_crc32c_64(cpu_reg(s, rd), tcg_acc, tcg_val, tcg_bytes);
5014 gen_helper_crc32_64(cpu_reg(s, rd), tcg_acc, tcg_val, tcg_bytes);
5017 tcg_temp_free_i32(tcg_bytes);
5020 /* Data-processing (2 source)
5021 * 31 30 29 28 21 20 16 15 10 9 5 4 0
5022 * +----+---+---+-----------------+------+--------+------+------+
5023 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
5024 * +----+---+---+-----------------+------+--------+------+------+
5026 static void disas_data_proc_2src(DisasContext *s, uint32_t insn)
5028 unsigned int sf, rm, opcode, rn, rd;
5029 sf = extract32(insn, 31, 1);
5030 rm = extract32(insn, 16, 5);
5031 opcode = extract32(insn, 10, 6);
5032 rn = extract32(insn, 5, 5);
5033 rd = extract32(insn, 0, 5);
5035 if (extract32(insn, 29, 1)) {
5036 unallocated_encoding(s);
5042 handle_div(s, false, sf, rm, rn, rd);
5045 handle_div(s, true, sf, rm, rn, rd);
5048 handle_shift_reg(s, A64_SHIFT_TYPE_LSL, sf, rm, rn, rd);
5051 handle_shift_reg(s, A64_SHIFT_TYPE_LSR, sf, rm, rn, rd);
5054 handle_shift_reg(s, A64_SHIFT_TYPE_ASR, sf, rm, rn, rd);
5057 handle_shift_reg(s, A64_SHIFT_TYPE_ROR, sf, rm, rn, rd);
5059 case 12: /* PACGA */
5060 if (sf == 0 || !dc_isar_feature(aa64_pauth, s)) {
5061 goto do_unallocated;
5063 gen_helper_pacga(cpu_reg(s, rd), cpu_env,
5064 cpu_reg(s, rn), cpu_reg_sp(s, rm));
5073 case 23: /* CRC32 */
5075 int sz = extract32(opcode, 0, 2);
5076 bool crc32c = extract32(opcode, 2, 1);
5077 handle_crc32(s, sf, sz, crc32c, rm, rn, rd);
5082 unallocated_encoding(s);
5087 /* Data processing - register */
5088 static void disas_data_proc_reg(DisasContext *s, uint32_t insn)
5090 switch (extract32(insn, 24, 5)) {
5091 case 0x0a: /* Logical (shifted register) */
5092 disas_logic_reg(s, insn);
5094 case 0x0b: /* Add/subtract */
5095 if (insn & (1 << 21)) { /* (extended register) */
5096 disas_add_sub_ext_reg(s, insn);
5098 disas_add_sub_reg(s, insn);
5101 case 0x1b: /* Data-processing (3 source) */
5102 disas_data_proc_3src(s, insn);
5105 switch (extract32(insn, 21, 3)) {
5106 case 0x0: /* Add/subtract (with carry) */
5107 disas_adc_sbc(s, insn);
5109 case 0x2: /* Conditional compare */
5110 disas_cc(s, insn); /* both imm and reg forms */
5112 case 0x4: /* Conditional select */
5113 disas_cond_select(s, insn);
5115 case 0x6: /* Data-processing */
5116 if (insn & (1 << 30)) { /* (1 source) */
5117 disas_data_proc_1src(s, insn);
5118 } else { /* (2 source) */
5119 disas_data_proc_2src(s, insn);
5123 unallocated_encoding(s);
5128 unallocated_encoding(s);
5133 static void handle_fp_compare(DisasContext *s, int size,
5134 unsigned int rn, unsigned int rm,
5135 bool cmp_with_zero, bool signal_all_nans)
5137 TCGv_i64 tcg_flags = tcg_temp_new_i64();
5138 TCGv_ptr fpst = get_fpstatus_ptr(size == MO_16);
5140 if (size == MO_64) {
5141 TCGv_i64 tcg_vn, tcg_vm;
5143 tcg_vn = read_fp_dreg(s, rn);
5144 if (cmp_with_zero) {
5145 tcg_vm = tcg_const_i64(0);
5147 tcg_vm = read_fp_dreg(s, rm);
5149 if (signal_all_nans) {
5150 gen_helper_vfp_cmped_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5152 gen_helper_vfp_cmpd_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5154 tcg_temp_free_i64(tcg_vn);
5155 tcg_temp_free_i64(tcg_vm);
5157 TCGv_i32 tcg_vn = tcg_temp_new_i32();
5158 TCGv_i32 tcg_vm = tcg_temp_new_i32();
5160 read_vec_element_i32(s, tcg_vn, rn, 0, size);
5161 if (cmp_with_zero) {
5162 tcg_gen_movi_i32(tcg_vm, 0);
5164 read_vec_element_i32(s, tcg_vm, rm, 0, size);
5169 if (signal_all_nans) {
5170 gen_helper_vfp_cmpes_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5172 gen_helper_vfp_cmps_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5176 if (signal_all_nans) {
5177 gen_helper_vfp_cmpeh_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5179 gen_helper_vfp_cmph_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5183 g_assert_not_reached();
5186 tcg_temp_free_i32(tcg_vn);
5187 tcg_temp_free_i32(tcg_vm);
5190 tcg_temp_free_ptr(fpst);
5192 gen_set_nzcv(tcg_flags);
5194 tcg_temp_free_i64(tcg_flags);
5197 /* Floating point compare
5198 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
5199 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5200 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
5201 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5203 static void disas_fp_compare(DisasContext *s, uint32_t insn)
5205 unsigned int mos, type, rm, op, rn, opc, op2r;
5208 mos = extract32(insn, 29, 3);
5209 type = extract32(insn, 22, 2);
5210 rm = extract32(insn, 16, 5);
5211 op = extract32(insn, 14, 2);
5212 rn = extract32(insn, 5, 5);
5213 opc = extract32(insn, 3, 2);
5214 op2r = extract32(insn, 0, 3);
5216 if (mos || op || op2r) {
5217 unallocated_encoding(s);
5230 if (dc_isar_feature(aa64_fp16, s)) {
5235 unallocated_encoding(s);
5239 if (!fp_access_check(s)) {
5243 handle_fp_compare(s, size, rn, rm, opc & 1, opc & 2);
5246 /* Floating point conditional compare
5247 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
5248 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5249 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
5250 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5252 static void disas_fp_ccomp(DisasContext *s, uint32_t insn)
5254 unsigned int mos, type, rm, cond, rn, op, nzcv;
5256 TCGLabel *label_continue = NULL;
5259 mos = extract32(insn, 29, 3);
5260 type = extract32(insn, 22, 2);
5261 rm = extract32(insn, 16, 5);
5262 cond = extract32(insn, 12, 4);
5263 rn = extract32(insn, 5, 5);
5264 op = extract32(insn, 4, 1);
5265 nzcv = extract32(insn, 0, 4);
5268 unallocated_encoding(s);
5281 if (dc_isar_feature(aa64_fp16, s)) {
5286 unallocated_encoding(s);
5290 if (!fp_access_check(s)) {
5294 if (cond < 0x0e) { /* not always */
5295 TCGLabel *label_match = gen_new_label();
5296 label_continue = gen_new_label();
5297 arm_gen_test_cc(cond, label_match);
5299 tcg_flags = tcg_const_i64(nzcv << 28);
5300 gen_set_nzcv(tcg_flags);
5301 tcg_temp_free_i64(tcg_flags);
5302 tcg_gen_br(label_continue);
5303 gen_set_label(label_match);
5306 handle_fp_compare(s, size, rn, rm, false, op);
5309 gen_set_label(label_continue);
5313 /* Floating point conditional select
5314 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5315 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5316 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
5317 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5319 static void disas_fp_csel(DisasContext *s, uint32_t insn)
5321 unsigned int mos, type, rm, cond, rn, rd;
5322 TCGv_i64 t_true, t_false, t_zero;
5326 mos = extract32(insn, 29, 3);
5327 type = extract32(insn, 22, 2);
5328 rm = extract32(insn, 16, 5);
5329 cond = extract32(insn, 12, 4);
5330 rn = extract32(insn, 5, 5);
5331 rd = extract32(insn, 0, 5);
5334 unallocated_encoding(s);
5347 if (dc_isar_feature(aa64_fp16, s)) {
5352 unallocated_encoding(s);
5356 if (!fp_access_check(s)) {
5360 /* Zero extend sreg & hreg inputs to 64 bits now. */
5361 t_true = tcg_temp_new_i64();
5362 t_false = tcg_temp_new_i64();
5363 read_vec_element(s, t_true, rn, 0, sz);
5364 read_vec_element(s, t_false, rm, 0, sz);
5366 a64_test_cc(&c, cond);
5367 t_zero = tcg_const_i64(0);
5368 tcg_gen_movcond_i64(c.cond, t_true, c.value, t_zero, t_true, t_false);
5369 tcg_temp_free_i64(t_zero);
5370 tcg_temp_free_i64(t_false);
5373 /* Note that sregs & hregs write back zeros to the high bits,
5374 and we've already done the zero-extension. */
5375 write_fp_dreg(s, rd, t_true);
5376 tcg_temp_free_i64(t_true);
5379 /* Floating-point data-processing (1 source) - half precision */
5380 static void handle_fp_1src_half(DisasContext *s, int opcode, int rd, int rn)
5382 TCGv_ptr fpst = NULL;
5383 TCGv_i32 tcg_op = read_fp_hreg(s, rn);
5384 TCGv_i32 tcg_res = tcg_temp_new_i32();
5387 case 0x0: /* FMOV */
5388 tcg_gen_mov_i32(tcg_res, tcg_op);
5390 case 0x1: /* FABS */
5391 tcg_gen_andi_i32(tcg_res, tcg_op, 0x7fff);
5393 case 0x2: /* FNEG */
5394 tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000);
5396 case 0x3: /* FSQRT */
5397 fpst = get_fpstatus_ptr(true);
5398 gen_helper_sqrt_f16(tcg_res, tcg_op, fpst);
5400 case 0x8: /* FRINTN */
5401 case 0x9: /* FRINTP */
5402 case 0xa: /* FRINTM */
5403 case 0xb: /* FRINTZ */
5404 case 0xc: /* FRINTA */
5406 TCGv_i32 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(opcode & 7));
5407 fpst = get_fpstatus_ptr(true);
5409 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5410 gen_helper_advsimd_rinth(tcg_res, tcg_op, fpst);
5412 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5413 tcg_temp_free_i32(tcg_rmode);
5416 case 0xe: /* FRINTX */
5417 fpst = get_fpstatus_ptr(true);
5418 gen_helper_advsimd_rinth_exact(tcg_res, tcg_op, fpst);
5420 case 0xf: /* FRINTI */
5421 fpst = get_fpstatus_ptr(true);
5422 gen_helper_advsimd_rinth(tcg_res, tcg_op, fpst);
5428 write_fp_sreg(s, rd, tcg_res);
5431 tcg_temp_free_ptr(fpst);
5433 tcg_temp_free_i32(tcg_op);
5434 tcg_temp_free_i32(tcg_res);
5437 /* Floating-point data-processing (1 source) - single precision */
5438 static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn)
5444 fpst = get_fpstatus_ptr(false);
5445 tcg_op = read_fp_sreg(s, rn);
5446 tcg_res = tcg_temp_new_i32();
5449 case 0x0: /* FMOV */
5450 tcg_gen_mov_i32(tcg_res, tcg_op);
5452 case 0x1: /* FABS */
5453 gen_helper_vfp_abss(tcg_res, tcg_op);
5455 case 0x2: /* FNEG */
5456 gen_helper_vfp_negs(tcg_res, tcg_op);
5458 case 0x3: /* FSQRT */
5459 gen_helper_vfp_sqrts(tcg_res, tcg_op, cpu_env);
5461 case 0x8: /* FRINTN */
5462 case 0x9: /* FRINTP */
5463 case 0xa: /* FRINTM */
5464 case 0xb: /* FRINTZ */
5465 case 0xc: /* FRINTA */
5467 TCGv_i32 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(opcode & 7));
5469 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5470 gen_helper_rints(tcg_res, tcg_op, fpst);
5472 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5473 tcg_temp_free_i32(tcg_rmode);
5476 case 0xe: /* FRINTX */
5477 gen_helper_rints_exact(tcg_res, tcg_op, fpst);
5479 case 0xf: /* FRINTI */
5480 gen_helper_rints(tcg_res, tcg_op, fpst);
5486 write_fp_sreg(s, rd, tcg_res);
5488 tcg_temp_free_ptr(fpst);
5489 tcg_temp_free_i32(tcg_op);
5490 tcg_temp_free_i32(tcg_res);
5493 /* Floating-point data-processing (1 source) - double precision */
5494 static void handle_fp_1src_double(DisasContext *s, int opcode, int rd, int rn)
5501 case 0x0: /* FMOV */
5502 gen_gvec_fn2(s, false, rd, rn, tcg_gen_gvec_mov, 0);
5506 fpst = get_fpstatus_ptr(false);
5507 tcg_op = read_fp_dreg(s, rn);
5508 tcg_res = tcg_temp_new_i64();
5511 case 0x1: /* FABS */
5512 gen_helper_vfp_absd(tcg_res, tcg_op);
5514 case 0x2: /* FNEG */
5515 gen_helper_vfp_negd(tcg_res, tcg_op);
5517 case 0x3: /* FSQRT */
5518 gen_helper_vfp_sqrtd(tcg_res, tcg_op, cpu_env);
5520 case 0x8: /* FRINTN */
5521 case 0x9: /* FRINTP */
5522 case 0xa: /* FRINTM */
5523 case 0xb: /* FRINTZ */
5524 case 0xc: /* FRINTA */
5526 TCGv_i32 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(opcode & 7));
5528 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5529 gen_helper_rintd(tcg_res, tcg_op, fpst);
5531 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5532 tcg_temp_free_i32(tcg_rmode);
5535 case 0xe: /* FRINTX */
5536 gen_helper_rintd_exact(tcg_res, tcg_op, fpst);
5538 case 0xf: /* FRINTI */
5539 gen_helper_rintd(tcg_res, tcg_op, fpst);
5545 write_fp_dreg(s, rd, tcg_res);
5547 tcg_temp_free_ptr(fpst);
5548 tcg_temp_free_i64(tcg_op);
5549 tcg_temp_free_i64(tcg_res);
5552 static void handle_fp_fcvt(DisasContext *s, int opcode,
5553 int rd, int rn, int dtype, int ntype)
5558 TCGv_i32 tcg_rn = read_fp_sreg(s, rn);
5560 /* Single to double */
5561 TCGv_i64 tcg_rd = tcg_temp_new_i64();
5562 gen_helper_vfp_fcvtds(tcg_rd, tcg_rn, cpu_env);
5563 write_fp_dreg(s, rd, tcg_rd);
5564 tcg_temp_free_i64(tcg_rd);
5566 /* Single to half */
5567 TCGv_i32 tcg_rd = tcg_temp_new_i32();
5568 TCGv_i32 ahp = get_ahp_flag();
5569 TCGv_ptr fpst = get_fpstatus_ptr(false);
5571 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd, tcg_rn, fpst, ahp);
5572 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5573 write_fp_sreg(s, rd, tcg_rd);
5574 tcg_temp_free_i32(tcg_rd);
5575 tcg_temp_free_i32(ahp);
5576 tcg_temp_free_ptr(fpst);
5578 tcg_temp_free_i32(tcg_rn);
5583 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
5584 TCGv_i32 tcg_rd = tcg_temp_new_i32();
5586 /* Double to single */
5587 gen_helper_vfp_fcvtsd(tcg_rd, tcg_rn, cpu_env);
5589 TCGv_ptr fpst = get_fpstatus_ptr(false);
5590 TCGv_i32 ahp = get_ahp_flag();
5591 /* Double to half */
5592 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd, tcg_rn, fpst, ahp);
5593 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5594 tcg_temp_free_ptr(fpst);
5595 tcg_temp_free_i32(ahp);
5597 write_fp_sreg(s, rd, tcg_rd);
5598 tcg_temp_free_i32(tcg_rd);
5599 tcg_temp_free_i64(tcg_rn);
5604 TCGv_i32 tcg_rn = read_fp_sreg(s, rn);
5605 TCGv_ptr tcg_fpst = get_fpstatus_ptr(false);
5606 TCGv_i32 tcg_ahp = get_ahp_flag();
5607 tcg_gen_ext16u_i32(tcg_rn, tcg_rn);
5609 /* Half to single */
5610 TCGv_i32 tcg_rd = tcg_temp_new_i32();
5611 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd, tcg_rn, tcg_fpst, tcg_ahp);
5612 write_fp_sreg(s, rd, tcg_rd);
5613 tcg_temp_free_ptr(tcg_fpst);
5614 tcg_temp_free_i32(tcg_ahp);
5615 tcg_temp_free_i32(tcg_rd);
5617 /* Half to double */
5618 TCGv_i64 tcg_rd = tcg_temp_new_i64();
5619 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd, tcg_rn, tcg_fpst, tcg_ahp);
5620 write_fp_dreg(s, rd, tcg_rd);
5621 tcg_temp_free_i64(tcg_rd);
5623 tcg_temp_free_i32(tcg_rn);
5631 /* Floating point data-processing (1 source)
5632 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
5633 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5634 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
5635 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5637 static void disas_fp_1src(DisasContext *s, uint32_t insn)
5639 int type = extract32(insn, 22, 2);
5640 int opcode = extract32(insn, 15, 6);
5641 int rn = extract32(insn, 5, 5);
5642 int rd = extract32(insn, 0, 5);
5645 case 0x4: case 0x5: case 0x7:
5647 /* FCVT between half, single and double precision */
5648 int dtype = extract32(opcode, 0, 2);
5649 if (type == 2 || dtype == type) {
5650 unallocated_encoding(s);
5653 if (!fp_access_check(s)) {
5657 handle_fp_fcvt(s, opcode, rd, rn, dtype, type);
5663 /* 32-to-32 and 64-to-64 ops */
5666 if (!fp_access_check(s)) {
5670 handle_fp_1src_single(s, opcode, rd, rn);
5673 if (!fp_access_check(s)) {
5677 handle_fp_1src_double(s, opcode, rd, rn);
5680 if (!dc_isar_feature(aa64_fp16, s)) {
5681 unallocated_encoding(s);
5685 if (!fp_access_check(s)) {
5689 handle_fp_1src_half(s, opcode, rd, rn);
5692 unallocated_encoding(s);
5696 unallocated_encoding(s);
5701 /* Floating-point data-processing (2 source) - single precision */
5702 static void handle_fp_2src_single(DisasContext *s, int opcode,
5703 int rd, int rn, int rm)
5710 tcg_res = tcg_temp_new_i32();
5711 fpst = get_fpstatus_ptr(false);
5712 tcg_op1 = read_fp_sreg(s, rn);
5713 tcg_op2 = read_fp_sreg(s, rm);
5716 case 0x0: /* FMUL */
5717 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
5719 case 0x1: /* FDIV */
5720 gen_helper_vfp_divs(tcg_res, tcg_op1, tcg_op2, fpst);
5722 case 0x2: /* FADD */
5723 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
5725 case 0x3: /* FSUB */
5726 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
5728 case 0x4: /* FMAX */
5729 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
5731 case 0x5: /* FMIN */
5732 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
5734 case 0x6: /* FMAXNM */
5735 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
5737 case 0x7: /* FMINNM */
5738 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
5740 case 0x8: /* FNMUL */
5741 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
5742 gen_helper_vfp_negs(tcg_res, tcg_res);
5746 write_fp_sreg(s, rd, tcg_res);
5748 tcg_temp_free_ptr(fpst);
5749 tcg_temp_free_i32(tcg_op1);
5750 tcg_temp_free_i32(tcg_op2);
5751 tcg_temp_free_i32(tcg_res);
5754 /* Floating-point data-processing (2 source) - double precision */
5755 static void handle_fp_2src_double(DisasContext *s, int opcode,
5756 int rd, int rn, int rm)
5763 tcg_res = tcg_temp_new_i64();
5764 fpst = get_fpstatus_ptr(false);
5765 tcg_op1 = read_fp_dreg(s, rn);
5766 tcg_op2 = read_fp_dreg(s, rm);
5769 case 0x0: /* FMUL */
5770 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
5772 case 0x1: /* FDIV */
5773 gen_helper_vfp_divd(tcg_res, tcg_op1, tcg_op2, fpst);
5775 case 0x2: /* FADD */
5776 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
5778 case 0x3: /* FSUB */
5779 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
5781 case 0x4: /* FMAX */
5782 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
5784 case 0x5: /* FMIN */
5785 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
5787 case 0x6: /* FMAXNM */
5788 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
5790 case 0x7: /* FMINNM */
5791 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
5793 case 0x8: /* FNMUL */
5794 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
5795 gen_helper_vfp_negd(tcg_res, tcg_res);
5799 write_fp_dreg(s, rd, tcg_res);
5801 tcg_temp_free_ptr(fpst);
5802 tcg_temp_free_i64(tcg_op1);
5803 tcg_temp_free_i64(tcg_op2);
5804 tcg_temp_free_i64(tcg_res);
5807 /* Floating-point data-processing (2 source) - half precision */
5808 static void handle_fp_2src_half(DisasContext *s, int opcode,
5809 int rd, int rn, int rm)
5816 tcg_res = tcg_temp_new_i32();
5817 fpst = get_fpstatus_ptr(true);
5818 tcg_op1 = read_fp_hreg(s, rn);
5819 tcg_op2 = read_fp_hreg(s, rm);
5822 case 0x0: /* FMUL */
5823 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
5825 case 0x1: /* FDIV */
5826 gen_helper_advsimd_divh(tcg_res, tcg_op1, tcg_op2, fpst);
5828 case 0x2: /* FADD */
5829 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
5831 case 0x3: /* FSUB */
5832 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
5834 case 0x4: /* FMAX */
5835 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
5837 case 0x5: /* FMIN */
5838 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
5840 case 0x6: /* FMAXNM */
5841 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
5843 case 0x7: /* FMINNM */
5844 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
5846 case 0x8: /* FNMUL */
5847 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
5848 tcg_gen_xori_i32(tcg_res, tcg_res, 0x8000);
5851 g_assert_not_reached();
5854 write_fp_sreg(s, rd, tcg_res);
5856 tcg_temp_free_ptr(fpst);
5857 tcg_temp_free_i32(tcg_op1);
5858 tcg_temp_free_i32(tcg_op2);
5859 tcg_temp_free_i32(tcg_res);
5862 /* Floating point data-processing (2 source)
5863 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5864 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5865 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
5866 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5868 static void disas_fp_2src(DisasContext *s, uint32_t insn)
5870 int type = extract32(insn, 22, 2);
5871 int rd = extract32(insn, 0, 5);
5872 int rn = extract32(insn, 5, 5);
5873 int rm = extract32(insn, 16, 5);
5874 int opcode = extract32(insn, 12, 4);
5877 unallocated_encoding(s);
5883 if (!fp_access_check(s)) {
5886 handle_fp_2src_single(s, opcode, rd, rn, rm);
5889 if (!fp_access_check(s)) {
5892 handle_fp_2src_double(s, opcode, rd, rn, rm);
5895 if (!dc_isar_feature(aa64_fp16, s)) {
5896 unallocated_encoding(s);
5899 if (!fp_access_check(s)) {
5902 handle_fp_2src_half(s, opcode, rd, rn, rm);
5905 unallocated_encoding(s);
5909 /* Floating-point data-processing (3 source) - single precision */
5910 static void handle_fp_3src_single(DisasContext *s, bool o0, bool o1,
5911 int rd, int rn, int rm, int ra)
5913 TCGv_i32 tcg_op1, tcg_op2, tcg_op3;
5914 TCGv_i32 tcg_res = tcg_temp_new_i32();
5915 TCGv_ptr fpst = get_fpstatus_ptr(false);
5917 tcg_op1 = read_fp_sreg(s, rn);
5918 tcg_op2 = read_fp_sreg(s, rm);
5919 tcg_op3 = read_fp_sreg(s, ra);
5921 /* These are fused multiply-add, and must be done as one
5922 * floating point operation with no rounding between the
5923 * multiplication and addition steps.
5924 * NB that doing the negations here as separate steps is
5925 * correct : an input NaN should come out with its sign bit
5926 * flipped if it is a negated-input.
5929 gen_helper_vfp_negs(tcg_op3, tcg_op3);
5933 gen_helper_vfp_negs(tcg_op1, tcg_op1);
5936 gen_helper_vfp_muladds(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
5938 write_fp_sreg(s, rd, tcg_res);
5940 tcg_temp_free_ptr(fpst);
5941 tcg_temp_free_i32(tcg_op1);
5942 tcg_temp_free_i32(tcg_op2);
5943 tcg_temp_free_i32(tcg_op3);
5944 tcg_temp_free_i32(tcg_res);
5947 /* Floating-point data-processing (3 source) - double precision */
5948 static void handle_fp_3src_double(DisasContext *s, bool o0, bool o1,
5949 int rd, int rn, int rm, int ra)
5951 TCGv_i64 tcg_op1, tcg_op2, tcg_op3;
5952 TCGv_i64 tcg_res = tcg_temp_new_i64();
5953 TCGv_ptr fpst = get_fpstatus_ptr(false);
5955 tcg_op1 = read_fp_dreg(s, rn);
5956 tcg_op2 = read_fp_dreg(s, rm);
5957 tcg_op3 = read_fp_dreg(s, ra);
5959 /* These are fused multiply-add, and must be done as one
5960 * floating point operation with no rounding between the
5961 * multiplication and addition steps.
5962 * NB that doing the negations here as separate steps is
5963 * correct : an input NaN should come out with its sign bit
5964 * flipped if it is a negated-input.
5967 gen_helper_vfp_negd(tcg_op3, tcg_op3);
5971 gen_helper_vfp_negd(tcg_op1, tcg_op1);
5974 gen_helper_vfp_muladdd(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
5976 write_fp_dreg(s, rd, tcg_res);
5978 tcg_temp_free_ptr(fpst);
5979 tcg_temp_free_i64(tcg_op1);
5980 tcg_temp_free_i64(tcg_op2);
5981 tcg_temp_free_i64(tcg_op3);
5982 tcg_temp_free_i64(tcg_res);
5985 /* Floating-point data-processing (3 source) - half precision */
5986 static void handle_fp_3src_half(DisasContext *s, bool o0, bool o1,
5987 int rd, int rn, int rm, int ra)
5989 TCGv_i32 tcg_op1, tcg_op2, tcg_op3;
5990 TCGv_i32 tcg_res = tcg_temp_new_i32();
5991 TCGv_ptr fpst = get_fpstatus_ptr(true);
5993 tcg_op1 = read_fp_hreg(s, rn);
5994 tcg_op2 = read_fp_hreg(s, rm);
5995 tcg_op3 = read_fp_hreg(s, ra);
5997 /* These are fused multiply-add, and must be done as one
5998 * floating point operation with no rounding between the
5999 * multiplication and addition steps.
6000 * NB that doing the negations here as separate steps is
6001 * correct : an input NaN should come out with its sign bit
6002 * flipped if it is a negated-input.
6005 tcg_gen_xori_i32(tcg_op3, tcg_op3, 0x8000);
6009 tcg_gen_xori_i32(tcg_op1, tcg_op1, 0x8000);
6012 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
6014 write_fp_sreg(s, rd, tcg_res);
6016 tcg_temp_free_ptr(fpst);
6017 tcg_temp_free_i32(tcg_op1);
6018 tcg_temp_free_i32(tcg_op2);
6019 tcg_temp_free_i32(tcg_op3);
6020 tcg_temp_free_i32(tcg_res);
6023 /* Floating point data-processing (3 source)
6024 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
6025 * +---+---+---+-----------+------+----+------+----+------+------+------+
6026 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
6027 * +---+---+---+-----------+------+----+------+----+------+------+------+
6029 static void disas_fp_3src(DisasContext *s, uint32_t insn)
6031 int type = extract32(insn, 22, 2);
6032 int rd = extract32(insn, 0, 5);
6033 int rn = extract32(insn, 5, 5);
6034 int ra = extract32(insn, 10, 5);
6035 int rm = extract32(insn, 16, 5);
6036 bool o0 = extract32(insn, 15, 1);
6037 bool o1 = extract32(insn, 21, 1);
6041 if (!fp_access_check(s)) {
6044 handle_fp_3src_single(s, o0, o1, rd, rn, rm, ra);
6047 if (!fp_access_check(s)) {
6050 handle_fp_3src_double(s, o0, o1, rd, rn, rm, ra);
6053 if (!dc_isar_feature(aa64_fp16, s)) {
6054 unallocated_encoding(s);
6057 if (!fp_access_check(s)) {
6060 handle_fp_3src_half(s, o0, o1, rd, rn, rm, ra);
6063 unallocated_encoding(s);
6067 /* The imm8 encodes the sign bit, enough bits to represent an exponent in
6068 * the range 01....1xx to 10....0xx, and the most significant 4 bits of
6069 * the mantissa; see VFPExpandImm() in the v8 ARM ARM.
6071 uint64_t vfp_expand_imm(int size, uint8_t imm8)
6077 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
6078 (extract32(imm8, 6, 1) ? 0x3fc0 : 0x4000) |
6079 extract32(imm8, 0, 6);
6083 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
6084 (extract32(imm8, 6, 1) ? 0x3e00 : 0x4000) |
6085 (extract32(imm8, 0, 6) << 3);
6089 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
6090 (extract32(imm8, 6, 1) ? 0x3000 : 0x4000) |
6091 (extract32(imm8, 0, 6) << 6);
6094 g_assert_not_reached();
6099 /* Floating point immediate
6100 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
6101 * +---+---+---+-----------+------+---+------------+-------+------+------+
6102 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
6103 * +---+---+---+-----------+------+---+------------+-------+------+------+
6105 static void disas_fp_imm(DisasContext *s, uint32_t insn)
6107 int rd = extract32(insn, 0, 5);
6108 int imm8 = extract32(insn, 13, 8);
6109 int type = extract32(insn, 22, 2);
6123 if (dc_isar_feature(aa64_fp16, s)) {
6128 unallocated_encoding(s);
6132 if (!fp_access_check(s)) {
6136 imm = vfp_expand_imm(sz, imm8);
6138 tcg_res = tcg_const_i64(imm);
6139 write_fp_dreg(s, rd, tcg_res);
6140 tcg_temp_free_i64(tcg_res);
6143 /* Handle floating point <=> fixed point conversions. Note that we can
6144 * also deal with fp <=> integer conversions as a special case (scale == 64)
6145 * OPTME: consider handling that special case specially or at least skipping
6146 * the call to scalbn in the helpers for zero shifts.
6148 static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode,
6149 bool itof, int rmode, int scale, int sf, int type)
6151 bool is_signed = !(opcode & 1);
6152 TCGv_ptr tcg_fpstatus;
6153 TCGv_i32 tcg_shift, tcg_single;
6154 TCGv_i64 tcg_double;
6156 tcg_fpstatus = get_fpstatus_ptr(type == 3);
6158 tcg_shift = tcg_const_i32(64 - scale);
6161 TCGv_i64 tcg_int = cpu_reg(s, rn);
6163 TCGv_i64 tcg_extend = new_tmp_a64(s);
6166 tcg_gen_ext32s_i64(tcg_extend, tcg_int);
6168 tcg_gen_ext32u_i64(tcg_extend, tcg_int);
6171 tcg_int = tcg_extend;
6175 case 1: /* float64 */
6176 tcg_double = tcg_temp_new_i64();
6178 gen_helper_vfp_sqtod(tcg_double, tcg_int,
6179 tcg_shift, tcg_fpstatus);
6181 gen_helper_vfp_uqtod(tcg_double, tcg_int,
6182 tcg_shift, tcg_fpstatus);
6184 write_fp_dreg(s, rd, tcg_double);
6185 tcg_temp_free_i64(tcg_double);
6188 case 0: /* float32 */
6189 tcg_single = tcg_temp_new_i32();
6191 gen_helper_vfp_sqtos(tcg_single, tcg_int,
6192 tcg_shift, tcg_fpstatus);
6194 gen_helper_vfp_uqtos(tcg_single, tcg_int,
6195 tcg_shift, tcg_fpstatus);
6197 write_fp_sreg(s, rd, tcg_single);
6198 tcg_temp_free_i32(tcg_single);
6201 case 3: /* float16 */
6202 tcg_single = tcg_temp_new_i32();
6204 gen_helper_vfp_sqtoh(tcg_single, tcg_int,
6205 tcg_shift, tcg_fpstatus);
6207 gen_helper_vfp_uqtoh(tcg_single, tcg_int,
6208 tcg_shift, tcg_fpstatus);
6210 write_fp_sreg(s, rd, tcg_single);
6211 tcg_temp_free_i32(tcg_single);
6215 g_assert_not_reached();
6218 TCGv_i64 tcg_int = cpu_reg(s, rd);
6221 if (extract32(opcode, 2, 1)) {
6222 /* There are too many rounding modes to all fit into rmode,
6223 * so FCVTA[US] is a special case.
6225 rmode = FPROUNDING_TIEAWAY;
6228 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
6230 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
6233 case 1: /* float64 */
6234 tcg_double = read_fp_dreg(s, rn);
6237 gen_helper_vfp_tosld(tcg_int, tcg_double,
6238 tcg_shift, tcg_fpstatus);
6240 gen_helper_vfp_tosqd(tcg_int, tcg_double,
6241 tcg_shift, tcg_fpstatus);
6245 gen_helper_vfp_tould(tcg_int, tcg_double,
6246 tcg_shift, tcg_fpstatus);
6248 gen_helper_vfp_touqd(tcg_int, tcg_double,
6249 tcg_shift, tcg_fpstatus);
6253 tcg_gen_ext32u_i64(tcg_int, tcg_int);
6255 tcg_temp_free_i64(tcg_double);
6258 case 0: /* float32 */
6259 tcg_single = read_fp_sreg(s, rn);
6262 gen_helper_vfp_tosqs(tcg_int, tcg_single,
6263 tcg_shift, tcg_fpstatus);
6265 gen_helper_vfp_touqs(tcg_int, tcg_single,
6266 tcg_shift, tcg_fpstatus);
6269 TCGv_i32 tcg_dest = tcg_temp_new_i32();
6271 gen_helper_vfp_tosls(tcg_dest, tcg_single,
6272 tcg_shift, tcg_fpstatus);
6274 gen_helper_vfp_touls(tcg_dest, tcg_single,
6275 tcg_shift, tcg_fpstatus);
6277 tcg_gen_extu_i32_i64(tcg_int, tcg_dest);
6278 tcg_temp_free_i32(tcg_dest);
6280 tcg_temp_free_i32(tcg_single);
6283 case 3: /* float16 */
6284 tcg_single = read_fp_sreg(s, rn);
6287 gen_helper_vfp_tosqh(tcg_int, tcg_single,
6288 tcg_shift, tcg_fpstatus);
6290 gen_helper_vfp_touqh(tcg_int, tcg_single,
6291 tcg_shift, tcg_fpstatus);
6294 TCGv_i32 tcg_dest = tcg_temp_new_i32();
6296 gen_helper_vfp_toslh(tcg_dest, tcg_single,
6297 tcg_shift, tcg_fpstatus);
6299 gen_helper_vfp_toulh(tcg_dest, tcg_single,
6300 tcg_shift, tcg_fpstatus);
6302 tcg_gen_extu_i32_i64(tcg_int, tcg_dest);
6303 tcg_temp_free_i32(tcg_dest);
6305 tcg_temp_free_i32(tcg_single);
6309 g_assert_not_reached();
6312 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
6313 tcg_temp_free_i32(tcg_rmode);
6316 tcg_temp_free_ptr(tcg_fpstatus);
6317 tcg_temp_free_i32(tcg_shift);
6320 /* Floating point <-> fixed point conversions
6321 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6322 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6323 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
6324 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6326 static void disas_fp_fixed_conv(DisasContext *s, uint32_t insn)
6328 int rd = extract32(insn, 0, 5);
6329 int rn = extract32(insn, 5, 5);
6330 int scale = extract32(insn, 10, 6);
6331 int opcode = extract32(insn, 16, 3);
6332 int rmode = extract32(insn, 19, 2);
6333 int type = extract32(insn, 22, 2);
6334 bool sbit = extract32(insn, 29, 1);
6335 bool sf = extract32(insn, 31, 1);
6338 if (sbit || (!sf && scale < 32)) {
6339 unallocated_encoding(s);
6344 case 0: /* float32 */
6345 case 1: /* float64 */
6347 case 3: /* float16 */
6348 if (dc_isar_feature(aa64_fp16, s)) {
6353 unallocated_encoding(s);
6357 switch ((rmode << 3) | opcode) {
6358 case 0x2: /* SCVTF */
6359 case 0x3: /* UCVTF */
6362 case 0x18: /* FCVTZS */
6363 case 0x19: /* FCVTZU */
6367 unallocated_encoding(s);
6371 if (!fp_access_check(s)) {
6375 handle_fpfpcvt(s, rd, rn, opcode, itof, FPROUNDING_ZERO, scale, sf, type);
6378 static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof)
6380 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
6381 * without conversion.
6385 TCGv_i64 tcg_rn = cpu_reg(s, rn);
6391 tmp = tcg_temp_new_i64();
6392 tcg_gen_ext32u_i64(tmp, tcg_rn);
6393 write_fp_dreg(s, rd, tmp);
6394 tcg_temp_free_i64(tmp);
6398 write_fp_dreg(s, rd, tcg_rn);
6401 /* 64 bit to top half. */
6402 tcg_gen_st_i64(tcg_rn, cpu_env, fp_reg_hi_offset(s, rd));
6403 clear_vec_high(s, true, rd);
6407 tmp = tcg_temp_new_i64();
6408 tcg_gen_ext16u_i64(tmp, tcg_rn);
6409 write_fp_dreg(s, rd, tmp);
6410 tcg_temp_free_i64(tmp);
6413 g_assert_not_reached();
6416 TCGv_i64 tcg_rd = cpu_reg(s, rd);
6421 tcg_gen_ld32u_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_32));
6425 tcg_gen_ld_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_64));
6428 /* 64 bits from top half */
6429 tcg_gen_ld_i64(tcg_rd, cpu_env, fp_reg_hi_offset(s, rn));
6433 tcg_gen_ld16u_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_16));
6436 g_assert_not_reached();
6441 /* Floating point <-> integer conversions
6442 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6443 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6444 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
6445 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6447 static void disas_fp_int_conv(DisasContext *s, uint32_t insn)
6449 int rd = extract32(insn, 0, 5);
6450 int rn = extract32(insn, 5, 5);
6451 int opcode = extract32(insn, 16, 3);
6452 int rmode = extract32(insn, 19, 2);
6453 int type = extract32(insn, 22, 2);
6454 bool sbit = extract32(insn, 29, 1);
6455 bool sf = extract32(insn, 31, 1);
6458 unallocated_encoding(s);
6464 bool itof = opcode & 1;
6467 unallocated_encoding(s);
6471 switch (sf << 3 | type << 1 | rmode) {
6472 case 0x0: /* 32 bit */
6473 case 0xa: /* 64 bit */
6474 case 0xd: /* 64 bit to top half of quad */
6476 case 0x6: /* 16-bit float, 32-bit int */
6477 case 0xe: /* 16-bit float, 64-bit int */
6478 if (dc_isar_feature(aa64_fp16, s)) {
6483 /* all other sf/type/rmode combinations are invalid */
6484 unallocated_encoding(s);
6488 if (!fp_access_check(s)) {
6491 handle_fmov(s, rd, rn, type, itof);
6493 /* actual FP conversions */
6494 bool itof = extract32(opcode, 1, 1);
6496 if (rmode != 0 && opcode > 1) {
6497 unallocated_encoding(s);
6501 case 0: /* float32 */
6502 case 1: /* float64 */
6504 case 3: /* float16 */
6505 if (dc_isar_feature(aa64_fp16, s)) {
6510 unallocated_encoding(s);
6514 if (!fp_access_check(s)) {
6517 handle_fpfpcvt(s, rd, rn, opcode, itof, rmode, 64, sf, type);
6521 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
6522 * 31 30 29 28 25 24 0
6523 * +---+---+---+---------+-----------------------------+
6524 * | | 0 | | 1 1 1 1 | |
6525 * +---+---+---+---------+-----------------------------+
6527 static void disas_data_proc_fp(DisasContext *s, uint32_t insn)
6529 if (extract32(insn, 24, 1)) {
6530 /* Floating point data-processing (3 source) */
6531 disas_fp_3src(s, insn);
6532 } else if (extract32(insn, 21, 1) == 0) {
6533 /* Floating point to fixed point conversions */
6534 disas_fp_fixed_conv(s, insn);
6536 switch (extract32(insn, 10, 2)) {
6538 /* Floating point conditional compare */
6539 disas_fp_ccomp(s, insn);
6542 /* Floating point data-processing (2 source) */
6543 disas_fp_2src(s, insn);
6546 /* Floating point conditional select */
6547 disas_fp_csel(s, insn);
6550 switch (ctz32(extract32(insn, 12, 4))) {
6551 case 0: /* [15:12] == xxx1 */
6552 /* Floating point immediate */
6553 disas_fp_imm(s, insn);
6555 case 1: /* [15:12] == xx10 */
6556 /* Floating point compare */
6557 disas_fp_compare(s, insn);
6559 case 2: /* [15:12] == x100 */
6560 /* Floating point data-processing (1 source) */
6561 disas_fp_1src(s, insn);
6563 case 3: /* [15:12] == 1000 */
6564 unallocated_encoding(s);
6566 default: /* [15:12] == 0000 */
6567 /* Floating point <-> integer conversions */
6568 disas_fp_int_conv(s, insn);
6576 static void do_ext64(DisasContext *s, TCGv_i64 tcg_left, TCGv_i64 tcg_right,
6579 /* Extract 64 bits from the middle of two concatenated 64 bit
6580 * vector register slices left:right. The extracted bits start
6581 * at 'pos' bits into the right (least significant) side.
6582 * We return the result in tcg_right, and guarantee not to
6585 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
6586 assert(pos > 0 && pos < 64);
6588 tcg_gen_shri_i64(tcg_right, tcg_right, pos);
6589 tcg_gen_shli_i64(tcg_tmp, tcg_left, 64 - pos);
6590 tcg_gen_or_i64(tcg_right, tcg_right, tcg_tmp);
6592 tcg_temp_free_i64(tcg_tmp);
6596 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
6597 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6598 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
6599 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6601 static void disas_simd_ext(DisasContext *s, uint32_t insn)
6603 int is_q = extract32(insn, 30, 1);
6604 int op2 = extract32(insn, 22, 2);
6605 int imm4 = extract32(insn, 11, 4);
6606 int rm = extract32(insn, 16, 5);
6607 int rn = extract32(insn, 5, 5);
6608 int rd = extract32(insn, 0, 5);
6609 int pos = imm4 << 3;
6610 TCGv_i64 tcg_resl, tcg_resh;
6612 if (op2 != 0 || (!is_q && extract32(imm4, 3, 1))) {
6613 unallocated_encoding(s);
6617 if (!fp_access_check(s)) {
6621 tcg_resh = tcg_temp_new_i64();
6622 tcg_resl = tcg_temp_new_i64();
6624 /* Vd gets bits starting at pos bits into Vm:Vn. This is
6625 * either extracting 128 bits from a 128:128 concatenation, or
6626 * extracting 64 bits from a 64:64 concatenation.
6629 read_vec_element(s, tcg_resl, rn, 0, MO_64);
6631 read_vec_element(s, tcg_resh, rm, 0, MO_64);
6632 do_ext64(s, tcg_resh, tcg_resl, pos);
6634 tcg_gen_movi_i64(tcg_resh, 0);
6641 EltPosns eltposns[] = { {rn, 0}, {rn, 1}, {rm, 0}, {rm, 1} };
6642 EltPosns *elt = eltposns;
6649 read_vec_element(s, tcg_resl, elt->reg, elt->elt, MO_64);
6651 read_vec_element(s, tcg_resh, elt->reg, elt->elt, MO_64);
6654 do_ext64(s, tcg_resh, tcg_resl, pos);
6655 tcg_hh = tcg_temp_new_i64();
6656 read_vec_element(s, tcg_hh, elt->reg, elt->elt, MO_64);
6657 do_ext64(s, tcg_hh, tcg_resh, pos);
6658 tcg_temp_free_i64(tcg_hh);
6662 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6663 tcg_temp_free_i64(tcg_resl);
6664 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6665 tcg_temp_free_i64(tcg_resh);
6669 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
6670 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6671 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
6672 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6674 static void disas_simd_tb(DisasContext *s, uint32_t insn)
6676 int op2 = extract32(insn, 22, 2);
6677 int is_q = extract32(insn, 30, 1);
6678 int rm = extract32(insn, 16, 5);
6679 int rn = extract32(insn, 5, 5);
6680 int rd = extract32(insn, 0, 5);
6681 int is_tblx = extract32(insn, 12, 1);
6682 int len = extract32(insn, 13, 2);
6683 TCGv_i64 tcg_resl, tcg_resh, tcg_idx;
6684 TCGv_i32 tcg_regno, tcg_numregs;
6687 unallocated_encoding(s);
6691 if (!fp_access_check(s)) {
6695 /* This does a table lookup: for every byte element in the input
6696 * we index into a table formed from up to four vector registers,
6697 * and then the output is the result of the lookups. Our helper
6698 * function does the lookup operation for a single 64 bit part of
6701 tcg_resl = tcg_temp_new_i64();
6702 tcg_resh = tcg_temp_new_i64();
6705 read_vec_element(s, tcg_resl, rd, 0, MO_64);
6707 tcg_gen_movi_i64(tcg_resl, 0);
6709 if (is_tblx && is_q) {
6710 read_vec_element(s, tcg_resh, rd, 1, MO_64);
6712 tcg_gen_movi_i64(tcg_resh, 0);
6715 tcg_idx = tcg_temp_new_i64();
6716 tcg_regno = tcg_const_i32(rn);
6717 tcg_numregs = tcg_const_i32(len + 1);
6718 read_vec_element(s, tcg_idx, rm, 0, MO_64);
6719 gen_helper_simd_tbl(tcg_resl, cpu_env, tcg_resl, tcg_idx,
6720 tcg_regno, tcg_numregs);
6722 read_vec_element(s, tcg_idx, rm, 1, MO_64);
6723 gen_helper_simd_tbl(tcg_resh, cpu_env, tcg_resh, tcg_idx,
6724 tcg_regno, tcg_numregs);
6726 tcg_temp_free_i64(tcg_idx);
6727 tcg_temp_free_i32(tcg_regno);
6728 tcg_temp_free_i32(tcg_numregs);
6730 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6731 tcg_temp_free_i64(tcg_resl);
6732 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6733 tcg_temp_free_i64(tcg_resh);
6737 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
6738 * +---+---+-------------+------+---+------+---+------------------+------+
6739 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
6740 * +---+---+-------------+------+---+------+---+------------------+------+
6742 static void disas_simd_zip_trn(DisasContext *s, uint32_t insn)
6744 int rd = extract32(insn, 0, 5);
6745 int rn = extract32(insn, 5, 5);
6746 int rm = extract32(insn, 16, 5);
6747 int size = extract32(insn, 22, 2);
6748 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
6749 * bit 2 indicates 1 vs 2 variant of the insn.
6751 int opcode = extract32(insn, 12, 2);
6752 bool part = extract32(insn, 14, 1);
6753 bool is_q = extract32(insn, 30, 1);
6754 int esize = 8 << size;
6756 int datasize = is_q ? 128 : 64;
6757 int elements = datasize / esize;
6758 TCGv_i64 tcg_res, tcg_resl, tcg_resh;
6760 if (opcode == 0 || (size == 3 && !is_q)) {
6761 unallocated_encoding(s);
6765 if (!fp_access_check(s)) {
6769 tcg_resl = tcg_const_i64(0);
6770 tcg_resh = tcg_const_i64(0);
6771 tcg_res = tcg_temp_new_i64();
6773 for (i = 0; i < elements; i++) {
6775 case 1: /* UZP1/2 */
6777 int midpoint = elements / 2;
6779 read_vec_element(s, tcg_res, rn, 2 * i + part, size);
6781 read_vec_element(s, tcg_res, rm,
6782 2 * (i - midpoint) + part, size);
6786 case 2: /* TRN1/2 */
6788 read_vec_element(s, tcg_res, rm, (i & ~1) + part, size);
6790 read_vec_element(s, tcg_res, rn, (i & ~1) + part, size);
6793 case 3: /* ZIP1/2 */
6795 int base = part * elements / 2;
6797 read_vec_element(s, tcg_res, rm, base + (i >> 1), size);
6799 read_vec_element(s, tcg_res, rn, base + (i >> 1), size);
6804 g_assert_not_reached();
6809 tcg_gen_shli_i64(tcg_res, tcg_res, ofs);
6810 tcg_gen_or_i64(tcg_resl, tcg_resl, tcg_res);
6812 tcg_gen_shli_i64(tcg_res, tcg_res, ofs - 64);
6813 tcg_gen_or_i64(tcg_resh, tcg_resh, tcg_res);
6817 tcg_temp_free_i64(tcg_res);
6819 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6820 tcg_temp_free_i64(tcg_resl);
6821 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6822 tcg_temp_free_i64(tcg_resh);
6826 * do_reduction_op helper
6828 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
6829 * important for correct NaN propagation that we do these
6830 * operations in exactly the order specified by the pseudocode.
6832 * This is a recursive function, TCG temps should be freed by the
6833 * calling function once it is done with the values.
6835 static TCGv_i32 do_reduction_op(DisasContext *s, int fpopcode, int rn,
6836 int esize, int size, int vmap, TCGv_ptr fpst)
6838 if (esize == size) {
6840 TCGMemOp msize = esize == 16 ? MO_16 : MO_32;
6843 /* We should have one register left here */
6844 assert(ctpop8(vmap) == 1);
6845 element = ctz32(vmap);
6846 assert(element < 8);
6848 tcg_elem = tcg_temp_new_i32();
6849 read_vec_element_i32(s, tcg_elem, rn, element, msize);
6852 int bits = size / 2;
6853 int shift = ctpop8(vmap) / 2;
6854 int vmap_lo = (vmap >> shift) & vmap;
6855 int vmap_hi = (vmap & ~vmap_lo);
6856 TCGv_i32 tcg_hi, tcg_lo, tcg_res;
6858 tcg_hi = do_reduction_op(s, fpopcode, rn, esize, bits, vmap_hi, fpst);
6859 tcg_lo = do_reduction_op(s, fpopcode, rn, esize, bits, vmap_lo, fpst);
6860 tcg_res = tcg_temp_new_i32();
6863 case 0x0c: /* fmaxnmv half-precision */
6864 gen_helper_advsimd_maxnumh(tcg_res, tcg_lo, tcg_hi, fpst);
6866 case 0x0f: /* fmaxv half-precision */
6867 gen_helper_advsimd_maxh(tcg_res, tcg_lo, tcg_hi, fpst);
6869 case 0x1c: /* fminnmv half-precision */
6870 gen_helper_advsimd_minnumh(tcg_res, tcg_lo, tcg_hi, fpst);
6872 case 0x1f: /* fminv half-precision */
6873 gen_helper_advsimd_minh(tcg_res, tcg_lo, tcg_hi, fpst);
6875 case 0x2c: /* fmaxnmv */
6876 gen_helper_vfp_maxnums(tcg_res, tcg_lo, tcg_hi, fpst);
6878 case 0x2f: /* fmaxv */
6879 gen_helper_vfp_maxs(tcg_res, tcg_lo, tcg_hi, fpst);
6881 case 0x3c: /* fminnmv */
6882 gen_helper_vfp_minnums(tcg_res, tcg_lo, tcg_hi, fpst);
6884 case 0x3f: /* fminv */
6885 gen_helper_vfp_mins(tcg_res, tcg_lo, tcg_hi, fpst);
6888 g_assert_not_reached();
6891 tcg_temp_free_i32(tcg_hi);
6892 tcg_temp_free_i32(tcg_lo);
6897 /* AdvSIMD across lanes
6898 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6899 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6900 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6901 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6903 static void disas_simd_across_lanes(DisasContext *s, uint32_t insn)
6905 int rd = extract32(insn, 0, 5);
6906 int rn = extract32(insn, 5, 5);
6907 int size = extract32(insn, 22, 2);
6908 int opcode = extract32(insn, 12, 5);
6909 bool is_q = extract32(insn, 30, 1);
6910 bool is_u = extract32(insn, 29, 1);
6912 bool is_min = false;
6916 TCGv_i64 tcg_res, tcg_elt;
6919 case 0x1b: /* ADDV */
6921 unallocated_encoding(s);
6925 case 0x3: /* SADDLV, UADDLV */
6926 case 0xa: /* SMAXV, UMAXV */
6927 case 0x1a: /* SMINV, UMINV */
6928 if (size == 3 || (size == 2 && !is_q)) {
6929 unallocated_encoding(s);
6933 case 0xc: /* FMAXNMV, FMINNMV */
6934 case 0xf: /* FMAXV, FMINV */
6935 /* Bit 1 of size field encodes min vs max and the actual size
6936 * depends on the encoding of the U bit. If not set (and FP16
6937 * enabled) then we do half-precision float instead of single
6940 is_min = extract32(size, 1, 1);
6942 if (!is_u && dc_isar_feature(aa64_fp16, s)) {
6944 } else if (!is_u || !is_q || extract32(size, 0, 1)) {
6945 unallocated_encoding(s);
6952 unallocated_encoding(s);
6956 if (!fp_access_check(s)) {
6961 elements = (is_q ? 128 : 64) / esize;
6963 tcg_res = tcg_temp_new_i64();
6964 tcg_elt = tcg_temp_new_i64();
6966 /* These instructions operate across all lanes of a vector
6967 * to produce a single result. We can guarantee that a 64
6968 * bit intermediate is sufficient:
6969 * + for [US]ADDLV the maximum element size is 32 bits, and
6970 * the result type is 64 bits
6971 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
6972 * same as the element size, which is 32 bits at most
6973 * For the integer operations we can choose to work at 64
6974 * or 32 bits and truncate at the end; for simplicity
6975 * we use 64 bits always. The floating point
6976 * ops do require 32 bit intermediates, though.
6979 read_vec_element(s, tcg_res, rn, 0, size | (is_u ? 0 : MO_SIGN));
6981 for (i = 1; i < elements; i++) {
6982 read_vec_element(s, tcg_elt, rn, i, size | (is_u ? 0 : MO_SIGN));
6985 case 0x03: /* SADDLV / UADDLV */
6986 case 0x1b: /* ADDV */
6987 tcg_gen_add_i64(tcg_res, tcg_res, tcg_elt);
6989 case 0x0a: /* SMAXV / UMAXV */
6991 tcg_gen_umax_i64(tcg_res, tcg_res, tcg_elt);
6993 tcg_gen_smax_i64(tcg_res, tcg_res, tcg_elt);
6996 case 0x1a: /* SMINV / UMINV */
6998 tcg_gen_umin_i64(tcg_res, tcg_res, tcg_elt);
7000 tcg_gen_smin_i64(tcg_res, tcg_res, tcg_elt);
7004 g_assert_not_reached();
7009 /* Floating point vector reduction ops which work across 32
7010 * bit (single) or 16 bit (half-precision) intermediates.
7011 * Note that correct NaN propagation requires that we do these
7012 * operations in exactly the order specified by the pseudocode.
7014 TCGv_ptr fpst = get_fpstatus_ptr(size == MO_16);
7015 int fpopcode = opcode | is_min << 4 | is_u << 5;
7016 int vmap = (1 << elements) - 1;
7017 TCGv_i32 tcg_res32 = do_reduction_op(s, fpopcode, rn, esize,
7018 (is_q ? 128 : 64), vmap, fpst);
7019 tcg_gen_extu_i32_i64(tcg_res, tcg_res32);
7020 tcg_temp_free_i32(tcg_res32);
7021 tcg_temp_free_ptr(fpst);
7024 tcg_temp_free_i64(tcg_elt);
7026 /* Now truncate the result to the width required for the final output */
7027 if (opcode == 0x03) {
7028 /* SADDLV, UADDLV: result is 2*esize */
7034 tcg_gen_ext8u_i64(tcg_res, tcg_res);
7037 tcg_gen_ext16u_i64(tcg_res, tcg_res);
7040 tcg_gen_ext32u_i64(tcg_res, tcg_res);
7045 g_assert_not_reached();
7048 write_fp_dreg(s, rd, tcg_res);
7049 tcg_temp_free_i64(tcg_res);
7052 /* DUP (Element, Vector)
7054 * 31 30 29 21 20 16 15 10 9 5 4 0
7055 * +---+---+-------------------+--------+-------------+------+------+
7056 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7057 * +---+---+-------------------+--------+-------------+------+------+
7059 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7061 static void handle_simd_dupe(DisasContext *s, int is_q, int rd, int rn,
7064 int size = ctz32(imm5);
7065 int index = imm5 >> (size + 1);
7067 if (size > 3 || (size == 3 && !is_q)) {
7068 unallocated_encoding(s);
7072 if (!fp_access_check(s)) {
7076 tcg_gen_gvec_dup_mem(size, vec_full_reg_offset(s, rd),
7077 vec_reg_offset(s, rn, index, size),
7078 is_q ? 16 : 8, vec_full_reg_size(s));
7081 /* DUP (element, scalar)
7082 * 31 21 20 16 15 10 9 5 4 0
7083 * +-----------------------+--------+-------------+------+------+
7084 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7085 * +-----------------------+--------+-------------+------+------+
7087 static void handle_simd_dupes(DisasContext *s, int rd, int rn,
7090 int size = ctz32(imm5);
7095 unallocated_encoding(s);
7099 if (!fp_access_check(s)) {
7103 index = imm5 >> (size + 1);
7105 /* This instruction just extracts the specified element and
7106 * zero-extends it into the bottom of the destination register.
7108 tmp = tcg_temp_new_i64();
7109 read_vec_element(s, tmp, rn, index, size);
7110 write_fp_dreg(s, rd, tmp);
7111 tcg_temp_free_i64(tmp);
7116 * 31 30 29 21 20 16 15 10 9 5 4 0
7117 * +---+---+-------------------+--------+-------------+------+------+
7118 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
7119 * +---+---+-------------------+--------+-------------+------+------+
7121 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7123 static void handle_simd_dupg(DisasContext *s, int is_q, int rd, int rn,
7126 int size = ctz32(imm5);
7127 uint32_t dofs, oprsz, maxsz;
7129 if (size > 3 || ((size == 3) && !is_q)) {
7130 unallocated_encoding(s);
7134 if (!fp_access_check(s)) {
7138 dofs = vec_full_reg_offset(s, rd);
7139 oprsz = is_q ? 16 : 8;
7140 maxsz = vec_full_reg_size(s);
7142 tcg_gen_gvec_dup_i64(size, dofs, oprsz, maxsz, cpu_reg(s, rn));
7147 * 31 21 20 16 15 14 11 10 9 5 4 0
7148 * +-----------------------+--------+------------+---+------+------+
7149 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7150 * +-----------------------+--------+------------+---+------+------+
7152 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7153 * index: encoded in imm5<4:size+1>
7155 static void handle_simd_inse(DisasContext *s, int rd, int rn,
7158 int size = ctz32(imm5);
7159 int src_index, dst_index;
7163 unallocated_encoding(s);
7167 if (!fp_access_check(s)) {
7171 dst_index = extract32(imm5, 1+size, 5);
7172 src_index = extract32(imm4, size, 4);
7174 tmp = tcg_temp_new_i64();
7176 read_vec_element(s, tmp, rn, src_index, size);
7177 write_vec_element(s, tmp, rd, dst_index, size);
7179 tcg_temp_free_i64(tmp);
7185 * 31 21 20 16 15 10 9 5 4 0
7186 * +-----------------------+--------+-------------+------+------+
7187 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
7188 * +-----------------------+--------+-------------+------+------+
7190 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7191 * index: encoded in imm5<4:size+1>
7193 static void handle_simd_insg(DisasContext *s, int rd, int rn, int imm5)
7195 int size = ctz32(imm5);
7199 unallocated_encoding(s);
7203 if (!fp_access_check(s)) {
7207 idx = extract32(imm5, 1 + size, 4 - size);
7208 write_vec_element(s, cpu_reg(s, rn), rd, idx, size);
7215 * 31 30 29 21 20 16 15 12 10 9 5 4 0
7216 * +---+---+-------------------+--------+-------------+------+------+
7217 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
7218 * +---+---+-------------------+--------+-------------+------+------+
7220 * U: unsigned when set
7221 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7223 static void handle_simd_umov_smov(DisasContext *s, int is_q, int is_signed,
7224 int rn, int rd, int imm5)
7226 int size = ctz32(imm5);
7230 /* Check for UnallocatedEncodings */
7232 if (size > 2 || (size == 2 && !is_q)) {
7233 unallocated_encoding(s);
7238 || (size < 3 && is_q)
7239 || (size == 3 && !is_q)) {
7240 unallocated_encoding(s);
7245 if (!fp_access_check(s)) {
7249 element = extract32(imm5, 1+size, 4);
7251 tcg_rd = cpu_reg(s, rd);
7252 read_vec_element(s, tcg_rd, rn, element, size | (is_signed ? MO_SIGN : 0));
7253 if (is_signed && !is_q) {
7254 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
7259 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7260 * +---+---+----+-----------------+------+---+------+---+------+------+
7261 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7262 * +---+---+----+-----------------+------+---+------+---+------+------+
7264 static void disas_simd_copy(DisasContext *s, uint32_t insn)
7266 int rd = extract32(insn, 0, 5);
7267 int rn = extract32(insn, 5, 5);
7268 int imm4 = extract32(insn, 11, 4);
7269 int op = extract32(insn, 29, 1);
7270 int is_q = extract32(insn, 30, 1);
7271 int imm5 = extract32(insn, 16, 5);
7276 handle_simd_inse(s, rd, rn, imm4, imm5);
7278 unallocated_encoding(s);
7283 /* DUP (element - vector) */
7284 handle_simd_dupe(s, is_q, rd, rn, imm5);
7288 handle_simd_dupg(s, is_q, rd, rn, imm5);
7293 handle_simd_insg(s, rd, rn, imm5);
7295 unallocated_encoding(s);
7300 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
7301 handle_simd_umov_smov(s, is_q, (imm4 == 5), rn, rd, imm5);
7304 unallocated_encoding(s);
7310 /* AdvSIMD modified immediate
7311 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
7312 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7313 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
7314 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7316 * There are a number of operations that can be carried out here:
7317 * MOVI - move (shifted) imm into register
7318 * MVNI - move inverted (shifted) imm into register
7319 * ORR - bitwise OR of (shifted) imm with register
7320 * BIC - bitwise clear of (shifted) imm with register
7321 * With ARMv8.2 we also have:
7322 * FMOV half-precision
7324 static void disas_simd_mod_imm(DisasContext *s, uint32_t insn)
7326 int rd = extract32(insn, 0, 5);
7327 int cmode = extract32(insn, 12, 4);
7328 int cmode_3_1 = extract32(cmode, 1, 3);
7329 int cmode_0 = extract32(cmode, 0, 1);
7330 int o2 = extract32(insn, 11, 1);
7331 uint64_t abcdefgh = extract32(insn, 5, 5) | (extract32(insn, 16, 3) << 5);
7332 bool is_neg = extract32(insn, 29, 1);
7333 bool is_q = extract32(insn, 30, 1);
7336 if (o2 != 0 || ((cmode == 0xf) && is_neg && !is_q)) {
7337 /* Check for FMOV (vector, immediate) - half-precision */
7338 if (!(dc_isar_feature(aa64_fp16, s) && o2 && cmode == 0xf)) {
7339 unallocated_encoding(s);
7344 if (!fp_access_check(s)) {
7348 /* See AdvSIMDExpandImm() in ARM ARM */
7349 switch (cmode_3_1) {
7350 case 0: /* Replicate(Zeros(24):imm8, 2) */
7351 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
7352 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
7353 case 3: /* Replicate(imm8:Zeros(24), 2) */
7355 int shift = cmode_3_1 * 8;
7356 imm = bitfield_replicate(abcdefgh << shift, 32);
7359 case 4: /* Replicate(Zeros(8):imm8, 4) */
7360 case 5: /* Replicate(imm8:Zeros(8), 4) */
7362 int shift = (cmode_3_1 & 0x1) * 8;
7363 imm = bitfield_replicate(abcdefgh << shift, 16);
7368 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
7369 imm = (abcdefgh << 16) | 0xffff;
7371 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
7372 imm = (abcdefgh << 8) | 0xff;
7374 imm = bitfield_replicate(imm, 32);
7377 if (!cmode_0 && !is_neg) {
7378 imm = bitfield_replicate(abcdefgh, 8);
7379 } else if (!cmode_0 && is_neg) {
7382 for (i = 0; i < 8; i++) {
7383 if ((abcdefgh) & (1 << i)) {
7384 imm |= 0xffULL << (i * 8);
7387 } else if (cmode_0) {
7389 imm = (abcdefgh & 0x3f) << 48;
7390 if (abcdefgh & 0x80) {
7391 imm |= 0x8000000000000000ULL;
7393 if (abcdefgh & 0x40) {
7394 imm |= 0x3fc0000000000000ULL;
7396 imm |= 0x4000000000000000ULL;
7400 /* FMOV (vector, immediate) - half-precision */
7401 imm = vfp_expand_imm(MO_16, abcdefgh);
7402 /* now duplicate across the lanes */
7403 imm = bitfield_replicate(imm, 16);
7405 imm = (abcdefgh & 0x3f) << 19;
7406 if (abcdefgh & 0x80) {
7409 if (abcdefgh & 0x40) {
7420 fprintf(stderr, "%s: cmode_3_1: %x\n", __func__, cmode_3_1);
7421 g_assert_not_reached();
7424 if (cmode_3_1 != 7 && is_neg) {
7428 if (!((cmode & 0x9) == 0x1 || (cmode & 0xd) == 0x9)) {
7429 /* MOVI or MVNI, with MVNI negation handled above. */
7430 tcg_gen_gvec_dup64i(vec_full_reg_offset(s, rd), is_q ? 16 : 8,
7431 vec_full_reg_size(s), imm);
7433 /* ORR or BIC, with BIC negation to AND handled above. */
7435 gen_gvec_fn2i(s, is_q, rd, rd, imm, tcg_gen_gvec_andi, MO_64);
7437 gen_gvec_fn2i(s, is_q, rd, rd, imm, tcg_gen_gvec_ori, MO_64);
7442 /* AdvSIMD scalar copy
7443 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7444 * +-----+----+-----------------+------+---+------+---+------+------+
7445 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7446 * +-----+----+-----------------+------+---+------+---+------+------+
7448 static void disas_simd_scalar_copy(DisasContext *s, uint32_t insn)
7450 int rd = extract32(insn, 0, 5);
7451 int rn = extract32(insn, 5, 5);
7452 int imm4 = extract32(insn, 11, 4);
7453 int imm5 = extract32(insn, 16, 5);
7454 int op = extract32(insn, 29, 1);
7456 if (op != 0 || imm4 != 0) {
7457 unallocated_encoding(s);
7461 /* DUP (element, scalar) */
7462 handle_simd_dupes(s, rd, rn, imm5);
7465 /* AdvSIMD scalar pairwise
7466 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7467 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7468 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7469 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7471 static void disas_simd_scalar_pairwise(DisasContext *s, uint32_t insn)
7473 int u = extract32(insn, 29, 1);
7474 int size = extract32(insn, 22, 2);
7475 int opcode = extract32(insn, 12, 5);
7476 int rn = extract32(insn, 5, 5);
7477 int rd = extract32(insn, 0, 5);
7480 /* For some ops (the FP ones), size[1] is part of the encoding.
7481 * For ADDP strictly it is not but size[1] is always 1 for valid
7484 opcode |= (extract32(size, 1, 1) << 5);
7487 case 0x3b: /* ADDP */
7488 if (u || size != 3) {
7489 unallocated_encoding(s);
7492 if (!fp_access_check(s)) {
7498 case 0xc: /* FMAXNMP */
7499 case 0xd: /* FADDP */
7500 case 0xf: /* FMAXP */
7501 case 0x2c: /* FMINNMP */
7502 case 0x2f: /* FMINP */
7503 /* FP op, size[0] is 32 or 64 bit*/
7505 if (!dc_isar_feature(aa64_fp16, s)) {
7506 unallocated_encoding(s);
7512 size = extract32(size, 0, 1) ? MO_64 : MO_32;
7515 if (!fp_access_check(s)) {
7519 fpst = get_fpstatus_ptr(size == MO_16);
7522 unallocated_encoding(s);
7526 if (size == MO_64) {
7527 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
7528 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
7529 TCGv_i64 tcg_res = tcg_temp_new_i64();
7531 read_vec_element(s, tcg_op1, rn, 0, MO_64);
7532 read_vec_element(s, tcg_op2, rn, 1, MO_64);
7535 case 0x3b: /* ADDP */
7536 tcg_gen_add_i64(tcg_res, tcg_op1, tcg_op2);
7538 case 0xc: /* FMAXNMP */
7539 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
7541 case 0xd: /* FADDP */
7542 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
7544 case 0xf: /* FMAXP */
7545 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
7547 case 0x2c: /* FMINNMP */
7548 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
7550 case 0x2f: /* FMINP */
7551 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
7554 g_assert_not_reached();
7557 write_fp_dreg(s, rd, tcg_res);
7559 tcg_temp_free_i64(tcg_op1);
7560 tcg_temp_free_i64(tcg_op2);
7561 tcg_temp_free_i64(tcg_res);
7563 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
7564 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
7565 TCGv_i32 tcg_res = tcg_temp_new_i32();
7567 read_vec_element_i32(s, tcg_op1, rn, 0, size);
7568 read_vec_element_i32(s, tcg_op2, rn, 1, size);
7570 if (size == MO_16) {
7572 case 0xc: /* FMAXNMP */
7573 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
7575 case 0xd: /* FADDP */
7576 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
7578 case 0xf: /* FMAXP */
7579 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
7581 case 0x2c: /* FMINNMP */
7582 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
7584 case 0x2f: /* FMINP */
7585 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
7588 g_assert_not_reached();
7592 case 0xc: /* FMAXNMP */
7593 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
7595 case 0xd: /* FADDP */
7596 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
7598 case 0xf: /* FMAXP */
7599 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
7601 case 0x2c: /* FMINNMP */
7602 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
7604 case 0x2f: /* FMINP */
7605 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
7608 g_assert_not_reached();
7612 write_fp_sreg(s, rd, tcg_res);
7614 tcg_temp_free_i32(tcg_op1);
7615 tcg_temp_free_i32(tcg_op2);
7616 tcg_temp_free_i32(tcg_res);
7620 tcg_temp_free_ptr(fpst);
7625 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
7627 * This code is handles the common shifting code and is used by both
7628 * the vector and scalar code.
7630 static void handle_shri_with_rndacc(TCGv_i64 tcg_res, TCGv_i64 tcg_src,
7631 TCGv_i64 tcg_rnd, bool accumulate,
7632 bool is_u, int size, int shift)
7634 bool extended_result = false;
7635 bool round = tcg_rnd != NULL;
7637 TCGv_i64 tcg_src_hi;
7639 if (round && size == 3) {
7640 extended_result = true;
7641 ext_lshift = 64 - shift;
7642 tcg_src_hi = tcg_temp_new_i64();
7643 } else if (shift == 64) {
7644 if (!accumulate && is_u) {
7645 /* result is zero */
7646 tcg_gen_movi_i64(tcg_res, 0);
7651 /* Deal with the rounding step */
7653 if (extended_result) {
7654 TCGv_i64 tcg_zero = tcg_const_i64(0);
7656 /* take care of sign extending tcg_res */
7657 tcg_gen_sari_i64(tcg_src_hi, tcg_src, 63);
7658 tcg_gen_add2_i64(tcg_src, tcg_src_hi,
7659 tcg_src, tcg_src_hi,
7662 tcg_gen_add2_i64(tcg_src, tcg_src_hi,
7666 tcg_temp_free_i64(tcg_zero);
7668 tcg_gen_add_i64(tcg_src, tcg_src, tcg_rnd);
7672 /* Now do the shift right */
7673 if (round && extended_result) {
7674 /* extended case, >64 bit precision required */
7675 if (ext_lshift == 0) {
7676 /* special case, only high bits matter */
7677 tcg_gen_mov_i64(tcg_src, tcg_src_hi);
7679 tcg_gen_shri_i64(tcg_src, tcg_src, shift);
7680 tcg_gen_shli_i64(tcg_src_hi, tcg_src_hi, ext_lshift);
7681 tcg_gen_or_i64(tcg_src, tcg_src, tcg_src_hi);
7686 /* essentially shifting in 64 zeros */
7687 tcg_gen_movi_i64(tcg_src, 0);
7689 tcg_gen_shri_i64(tcg_src, tcg_src, shift);
7693 /* effectively extending the sign-bit */
7694 tcg_gen_sari_i64(tcg_src, tcg_src, 63);
7696 tcg_gen_sari_i64(tcg_src, tcg_src, shift);
7702 tcg_gen_add_i64(tcg_res, tcg_res, tcg_src);
7704 tcg_gen_mov_i64(tcg_res, tcg_src);
7707 if (extended_result) {
7708 tcg_temp_free_i64(tcg_src_hi);
7712 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
7713 static void handle_scalar_simd_shri(DisasContext *s,
7714 bool is_u, int immh, int immb,
7715 int opcode, int rn, int rd)
7718 int immhb = immh << 3 | immb;
7719 int shift = 2 * (8 << size) - immhb;
7720 bool accumulate = false;
7722 bool insert = false;
7727 if (!extract32(immh, 3, 1)) {
7728 unallocated_encoding(s);
7732 if (!fp_access_check(s)) {
7737 case 0x02: /* SSRA / USRA (accumulate) */
7740 case 0x04: /* SRSHR / URSHR (rounding) */
7743 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7744 accumulate = round = true;
7746 case 0x08: /* SRI */
7752 uint64_t round_const = 1ULL << (shift - 1);
7753 tcg_round = tcg_const_i64(round_const);
7758 tcg_rn = read_fp_dreg(s, rn);
7759 tcg_rd = (accumulate || insert) ? read_fp_dreg(s, rd) : tcg_temp_new_i64();
7762 /* shift count same as element size is valid but does nothing;
7763 * special case to avoid potential shift by 64.
7765 int esize = 8 << size;
7766 if (shift != esize) {
7767 tcg_gen_shri_i64(tcg_rn, tcg_rn, shift);
7768 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, 0, esize - shift);
7771 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
7772 accumulate, is_u, size, shift);
7775 write_fp_dreg(s, rd, tcg_rd);
7777 tcg_temp_free_i64(tcg_rn);
7778 tcg_temp_free_i64(tcg_rd);
7780 tcg_temp_free_i64(tcg_round);
7784 /* SHL/SLI - Scalar shift left */
7785 static void handle_scalar_simd_shli(DisasContext *s, bool insert,
7786 int immh, int immb, int opcode,
7789 int size = 32 - clz32(immh) - 1;
7790 int immhb = immh << 3 | immb;
7791 int shift = immhb - (8 << size);
7792 TCGv_i64 tcg_rn = new_tmp_a64(s);
7793 TCGv_i64 tcg_rd = new_tmp_a64(s);
7795 if (!extract32(immh, 3, 1)) {
7796 unallocated_encoding(s);
7800 if (!fp_access_check(s)) {
7804 tcg_rn = read_fp_dreg(s, rn);
7805 tcg_rd = insert ? read_fp_dreg(s, rd) : tcg_temp_new_i64();
7808 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, shift, 64 - shift);
7810 tcg_gen_shli_i64(tcg_rd, tcg_rn, shift);
7813 write_fp_dreg(s, rd, tcg_rd);
7815 tcg_temp_free_i64(tcg_rn);
7816 tcg_temp_free_i64(tcg_rd);
7819 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
7820 * (signed/unsigned) narrowing */
7821 static void handle_vec_simd_sqshrn(DisasContext *s, bool is_scalar, bool is_q,
7822 bool is_u_shift, bool is_u_narrow,
7823 int immh, int immb, int opcode,
7826 int immhb = immh << 3 | immb;
7827 int size = 32 - clz32(immh) - 1;
7828 int esize = 8 << size;
7829 int shift = (2 * esize) - immhb;
7830 int elements = is_scalar ? 1 : (64 / esize);
7831 bool round = extract32(opcode, 0, 1);
7832 TCGMemOp ldop = (size + 1) | (is_u_shift ? 0 : MO_SIGN);
7833 TCGv_i64 tcg_rn, tcg_rd, tcg_round;
7834 TCGv_i32 tcg_rd_narrowed;
7837 static NeonGenNarrowEnvFn * const signed_narrow_fns[4][2] = {
7838 { gen_helper_neon_narrow_sat_s8,
7839 gen_helper_neon_unarrow_sat8 },
7840 { gen_helper_neon_narrow_sat_s16,
7841 gen_helper_neon_unarrow_sat16 },
7842 { gen_helper_neon_narrow_sat_s32,
7843 gen_helper_neon_unarrow_sat32 },
7846 static NeonGenNarrowEnvFn * const unsigned_narrow_fns[4] = {
7847 gen_helper_neon_narrow_sat_u8,
7848 gen_helper_neon_narrow_sat_u16,
7849 gen_helper_neon_narrow_sat_u32,
7852 NeonGenNarrowEnvFn *narrowfn;
7858 if (extract32(immh, 3, 1)) {
7859 unallocated_encoding(s);
7863 if (!fp_access_check(s)) {
7868 narrowfn = unsigned_narrow_fns[size];
7870 narrowfn = signed_narrow_fns[size][is_u_narrow ? 1 : 0];
7873 tcg_rn = tcg_temp_new_i64();
7874 tcg_rd = tcg_temp_new_i64();
7875 tcg_rd_narrowed = tcg_temp_new_i32();
7876 tcg_final = tcg_const_i64(0);
7879 uint64_t round_const = 1ULL << (shift - 1);
7880 tcg_round = tcg_const_i64(round_const);
7885 for (i = 0; i < elements; i++) {
7886 read_vec_element(s, tcg_rn, rn, i, ldop);
7887 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
7888 false, is_u_shift, size+1, shift);
7889 narrowfn(tcg_rd_narrowed, cpu_env, tcg_rd);
7890 tcg_gen_extu_i32_i64(tcg_rd, tcg_rd_narrowed);
7891 tcg_gen_deposit_i64(tcg_final, tcg_final, tcg_rd, esize * i, esize);
7895 write_vec_element(s, tcg_final, rd, 0, MO_64);
7897 write_vec_element(s, tcg_final, rd, 1, MO_64);
7901 tcg_temp_free_i64(tcg_round);
7903 tcg_temp_free_i64(tcg_rn);
7904 tcg_temp_free_i64(tcg_rd);
7905 tcg_temp_free_i32(tcg_rd_narrowed);
7906 tcg_temp_free_i64(tcg_final);
7908 clear_vec_high(s, is_q, rd);
7911 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
7912 static void handle_simd_qshl(DisasContext *s, bool scalar, bool is_q,
7913 bool src_unsigned, bool dst_unsigned,
7914 int immh, int immb, int rn, int rd)
7916 int immhb = immh << 3 | immb;
7917 int size = 32 - clz32(immh) - 1;
7918 int shift = immhb - (8 << size);
7922 assert(!(scalar && is_q));
7925 if (!is_q && extract32(immh, 3, 1)) {
7926 unallocated_encoding(s);
7930 /* Since we use the variable-shift helpers we must
7931 * replicate the shift count into each element of
7932 * the tcg_shift value.
7936 shift |= shift << 8;
7939 shift |= shift << 16;
7945 g_assert_not_reached();
7949 if (!fp_access_check(s)) {
7954 TCGv_i64 tcg_shift = tcg_const_i64(shift);
7955 static NeonGenTwo64OpEnvFn * const fns[2][2] = {
7956 { gen_helper_neon_qshl_s64, gen_helper_neon_qshlu_s64 },
7957 { NULL, gen_helper_neon_qshl_u64 },
7959 NeonGenTwo64OpEnvFn *genfn = fns[src_unsigned][dst_unsigned];
7960 int maxpass = is_q ? 2 : 1;
7962 for (pass = 0; pass < maxpass; pass++) {
7963 TCGv_i64 tcg_op = tcg_temp_new_i64();
7965 read_vec_element(s, tcg_op, rn, pass, MO_64);
7966 genfn(tcg_op, cpu_env, tcg_op, tcg_shift);
7967 write_vec_element(s, tcg_op, rd, pass, MO_64);
7969 tcg_temp_free_i64(tcg_op);
7971 tcg_temp_free_i64(tcg_shift);
7972 clear_vec_high(s, is_q, rd);
7974 TCGv_i32 tcg_shift = tcg_const_i32(shift);
7975 static NeonGenTwoOpEnvFn * const fns[2][2][3] = {
7977 { gen_helper_neon_qshl_s8,
7978 gen_helper_neon_qshl_s16,
7979 gen_helper_neon_qshl_s32 },
7980 { gen_helper_neon_qshlu_s8,
7981 gen_helper_neon_qshlu_s16,
7982 gen_helper_neon_qshlu_s32 }
7984 { NULL, NULL, NULL },
7985 { gen_helper_neon_qshl_u8,
7986 gen_helper_neon_qshl_u16,
7987 gen_helper_neon_qshl_u32 }
7990 NeonGenTwoOpEnvFn *genfn = fns[src_unsigned][dst_unsigned][size];
7991 TCGMemOp memop = scalar ? size : MO_32;
7992 int maxpass = scalar ? 1 : is_q ? 4 : 2;
7994 for (pass = 0; pass < maxpass; pass++) {
7995 TCGv_i32 tcg_op = tcg_temp_new_i32();
7997 read_vec_element_i32(s, tcg_op, rn, pass, memop);
7998 genfn(tcg_op, cpu_env, tcg_op, tcg_shift);
8002 tcg_gen_ext8u_i32(tcg_op, tcg_op);
8005 tcg_gen_ext16u_i32(tcg_op, tcg_op);
8010 g_assert_not_reached();
8012 write_fp_sreg(s, rd, tcg_op);
8014 write_vec_element_i32(s, tcg_op, rd, pass, MO_32);
8017 tcg_temp_free_i32(tcg_op);
8019 tcg_temp_free_i32(tcg_shift);
8022 clear_vec_high(s, is_q, rd);
8027 /* Common vector code for handling integer to FP conversion */
8028 static void handle_simd_intfp_conv(DisasContext *s, int rd, int rn,
8029 int elements, int is_signed,
8030 int fracbits, int size)
8032 TCGv_ptr tcg_fpst = get_fpstatus_ptr(size == MO_16);
8033 TCGv_i32 tcg_shift = NULL;
8035 TCGMemOp mop = size | (is_signed ? MO_SIGN : 0);
8038 if (fracbits || size == MO_64) {
8039 tcg_shift = tcg_const_i32(fracbits);
8042 if (size == MO_64) {
8043 TCGv_i64 tcg_int64 = tcg_temp_new_i64();
8044 TCGv_i64 tcg_double = tcg_temp_new_i64();
8046 for (pass = 0; pass < elements; pass++) {
8047 read_vec_element(s, tcg_int64, rn, pass, mop);
8050 gen_helper_vfp_sqtod(tcg_double, tcg_int64,
8051 tcg_shift, tcg_fpst);
8053 gen_helper_vfp_uqtod(tcg_double, tcg_int64,
8054 tcg_shift, tcg_fpst);
8056 if (elements == 1) {
8057 write_fp_dreg(s, rd, tcg_double);
8059 write_vec_element(s, tcg_double, rd, pass, MO_64);
8063 tcg_temp_free_i64(tcg_int64);
8064 tcg_temp_free_i64(tcg_double);
8067 TCGv_i32 tcg_int32 = tcg_temp_new_i32();
8068 TCGv_i32 tcg_float = tcg_temp_new_i32();
8070 for (pass = 0; pass < elements; pass++) {
8071 read_vec_element_i32(s, tcg_int32, rn, pass, mop);
8077 gen_helper_vfp_sltos(tcg_float, tcg_int32,
8078 tcg_shift, tcg_fpst);
8080 gen_helper_vfp_ultos(tcg_float, tcg_int32,
8081 tcg_shift, tcg_fpst);
8085 gen_helper_vfp_sitos(tcg_float, tcg_int32, tcg_fpst);
8087 gen_helper_vfp_uitos(tcg_float, tcg_int32, tcg_fpst);
8094 gen_helper_vfp_sltoh(tcg_float, tcg_int32,
8095 tcg_shift, tcg_fpst);
8097 gen_helper_vfp_ultoh(tcg_float, tcg_int32,
8098 tcg_shift, tcg_fpst);
8102 gen_helper_vfp_sitoh(tcg_float, tcg_int32, tcg_fpst);
8104 gen_helper_vfp_uitoh(tcg_float, tcg_int32, tcg_fpst);
8109 g_assert_not_reached();
8112 if (elements == 1) {
8113 write_fp_sreg(s, rd, tcg_float);
8115 write_vec_element_i32(s, tcg_float, rd, pass, size);
8119 tcg_temp_free_i32(tcg_int32);
8120 tcg_temp_free_i32(tcg_float);
8123 tcg_temp_free_ptr(tcg_fpst);
8125 tcg_temp_free_i32(tcg_shift);
8128 clear_vec_high(s, elements << size == 16, rd);
8131 /* UCVTF/SCVTF - Integer to FP conversion */
8132 static void handle_simd_shift_intfp_conv(DisasContext *s, bool is_scalar,
8133 bool is_q, bool is_u,
8134 int immh, int immb, int opcode,
8137 int size, elements, fracbits;
8138 int immhb = immh << 3 | immb;
8142 if (!is_scalar && !is_q) {
8143 unallocated_encoding(s);
8146 } else if (immh & 4) {
8148 } else if (immh & 2) {
8150 if (!dc_isar_feature(aa64_fp16, s)) {
8151 unallocated_encoding(s);
8155 /* immh == 0 would be a failure of the decode logic */
8156 g_assert(immh == 1);
8157 unallocated_encoding(s);
8164 elements = (8 << is_q) >> size;
8166 fracbits = (16 << size) - immhb;
8168 if (!fp_access_check(s)) {
8172 handle_simd_intfp_conv(s, rd, rn, elements, !is_u, fracbits, size);
8175 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
8176 static void handle_simd_shift_fpint_conv(DisasContext *s, bool is_scalar,
8177 bool is_q, bool is_u,
8178 int immh, int immb, int rn, int rd)
8180 int immhb = immh << 3 | immb;
8181 int pass, size, fracbits;
8182 TCGv_ptr tcg_fpstatus;
8183 TCGv_i32 tcg_rmode, tcg_shift;
8187 if (!is_scalar && !is_q) {
8188 unallocated_encoding(s);
8191 } else if (immh & 0x4) {
8193 } else if (immh & 0x2) {
8195 if (!dc_isar_feature(aa64_fp16, s)) {
8196 unallocated_encoding(s);
8200 /* Should have split out AdvSIMD modified immediate earlier. */
8202 unallocated_encoding(s);
8206 if (!fp_access_check(s)) {
8210 assert(!(is_scalar && is_q));
8212 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO));
8213 tcg_fpstatus = get_fpstatus_ptr(size == MO_16);
8214 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
8215 fracbits = (16 << size) - immhb;
8216 tcg_shift = tcg_const_i32(fracbits);
8218 if (size == MO_64) {
8219 int maxpass = is_scalar ? 1 : 2;
8221 for (pass = 0; pass < maxpass; pass++) {
8222 TCGv_i64 tcg_op = tcg_temp_new_i64();
8224 read_vec_element(s, tcg_op, rn, pass, MO_64);
8226 gen_helper_vfp_touqd(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8228 gen_helper_vfp_tosqd(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8230 write_vec_element(s, tcg_op, rd, pass, MO_64);
8231 tcg_temp_free_i64(tcg_op);
8233 clear_vec_high(s, is_q, rd);
8235 void (*fn)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_ptr);
8236 int maxpass = is_scalar ? 1 : ((8 << is_q) >> size);
8241 fn = gen_helper_vfp_touhh;
8243 fn = gen_helper_vfp_toshh;
8248 fn = gen_helper_vfp_touls;
8250 fn = gen_helper_vfp_tosls;
8254 g_assert_not_reached();
8257 for (pass = 0; pass < maxpass; pass++) {
8258 TCGv_i32 tcg_op = tcg_temp_new_i32();
8260 read_vec_element_i32(s, tcg_op, rn, pass, size);
8261 fn(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8263 write_fp_sreg(s, rd, tcg_op);
8265 write_vec_element_i32(s, tcg_op, rd, pass, size);
8267 tcg_temp_free_i32(tcg_op);
8270 clear_vec_high(s, is_q, rd);
8274 tcg_temp_free_ptr(tcg_fpstatus);
8275 tcg_temp_free_i32(tcg_shift);
8276 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
8277 tcg_temp_free_i32(tcg_rmode);
8280 /* AdvSIMD scalar shift by immediate
8281 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8282 * +-----+---+-------------+------+------+--------+---+------+------+
8283 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8284 * +-----+---+-------------+------+------+--------+---+------+------+
8286 * This is the scalar version so it works on a fixed sized registers
8288 static void disas_simd_scalar_shift_imm(DisasContext *s, uint32_t insn)
8290 int rd = extract32(insn, 0, 5);
8291 int rn = extract32(insn, 5, 5);
8292 int opcode = extract32(insn, 11, 5);
8293 int immb = extract32(insn, 16, 3);
8294 int immh = extract32(insn, 19, 4);
8295 bool is_u = extract32(insn, 29, 1);
8298 unallocated_encoding(s);
8303 case 0x08: /* SRI */
8305 unallocated_encoding(s);
8309 case 0x00: /* SSHR / USHR */
8310 case 0x02: /* SSRA / USRA */
8311 case 0x04: /* SRSHR / URSHR */
8312 case 0x06: /* SRSRA / URSRA */
8313 handle_scalar_simd_shri(s, is_u, immh, immb, opcode, rn, rd);
8315 case 0x0a: /* SHL / SLI */
8316 handle_scalar_simd_shli(s, is_u, immh, immb, opcode, rn, rd);
8318 case 0x1c: /* SCVTF, UCVTF */
8319 handle_simd_shift_intfp_conv(s, true, false, is_u, immh, immb,
8322 case 0x10: /* SQSHRUN, SQSHRUN2 */
8323 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
8325 unallocated_encoding(s);
8328 handle_vec_simd_sqshrn(s, true, false, false, true,
8329 immh, immb, opcode, rn, rd);
8331 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
8332 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
8333 handle_vec_simd_sqshrn(s, true, false, is_u, is_u,
8334 immh, immb, opcode, rn, rd);
8336 case 0xc: /* SQSHLU */
8338 unallocated_encoding(s);
8341 handle_simd_qshl(s, true, false, false, true, immh, immb, rn, rd);
8343 case 0xe: /* SQSHL, UQSHL */
8344 handle_simd_qshl(s, true, false, is_u, is_u, immh, immb, rn, rd);
8346 case 0x1f: /* FCVTZS, FCVTZU */
8347 handle_simd_shift_fpint_conv(s, true, false, is_u, immh, immb, rn, rd);
8350 unallocated_encoding(s);
8355 /* AdvSIMD scalar three different
8356 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8357 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8358 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8359 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8361 static void disas_simd_scalar_three_reg_diff(DisasContext *s, uint32_t insn)
8363 bool is_u = extract32(insn, 29, 1);
8364 int size = extract32(insn, 22, 2);
8365 int opcode = extract32(insn, 12, 4);
8366 int rm = extract32(insn, 16, 5);
8367 int rn = extract32(insn, 5, 5);
8368 int rd = extract32(insn, 0, 5);
8371 unallocated_encoding(s);
8376 case 0x9: /* SQDMLAL, SQDMLAL2 */
8377 case 0xb: /* SQDMLSL, SQDMLSL2 */
8378 case 0xd: /* SQDMULL, SQDMULL2 */
8379 if (size == 0 || size == 3) {
8380 unallocated_encoding(s);
8385 unallocated_encoding(s);
8389 if (!fp_access_check(s)) {
8394 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8395 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8396 TCGv_i64 tcg_res = tcg_temp_new_i64();
8398 read_vec_element(s, tcg_op1, rn, 0, MO_32 | MO_SIGN);
8399 read_vec_element(s, tcg_op2, rm, 0, MO_32 | MO_SIGN);
8401 tcg_gen_mul_i64(tcg_res, tcg_op1, tcg_op2);
8402 gen_helper_neon_addl_saturate_s64(tcg_res, cpu_env, tcg_res, tcg_res);
8405 case 0xd: /* SQDMULL, SQDMULL2 */
8407 case 0xb: /* SQDMLSL, SQDMLSL2 */
8408 tcg_gen_neg_i64(tcg_res, tcg_res);
8410 case 0x9: /* SQDMLAL, SQDMLAL2 */
8411 read_vec_element(s, tcg_op1, rd, 0, MO_64);
8412 gen_helper_neon_addl_saturate_s64(tcg_res, cpu_env,
8416 g_assert_not_reached();
8419 write_fp_dreg(s, rd, tcg_res);
8421 tcg_temp_free_i64(tcg_op1);
8422 tcg_temp_free_i64(tcg_op2);
8423 tcg_temp_free_i64(tcg_res);
8425 TCGv_i32 tcg_op1 = read_fp_hreg(s, rn);
8426 TCGv_i32 tcg_op2 = read_fp_hreg(s, rm);
8427 TCGv_i64 tcg_res = tcg_temp_new_i64();
8429 gen_helper_neon_mull_s16(tcg_res, tcg_op1, tcg_op2);
8430 gen_helper_neon_addl_saturate_s32(tcg_res, cpu_env, tcg_res, tcg_res);
8433 case 0xd: /* SQDMULL, SQDMULL2 */
8435 case 0xb: /* SQDMLSL, SQDMLSL2 */
8436 gen_helper_neon_negl_u32(tcg_res, tcg_res);
8438 case 0x9: /* SQDMLAL, SQDMLAL2 */
8440 TCGv_i64 tcg_op3 = tcg_temp_new_i64();
8441 read_vec_element(s, tcg_op3, rd, 0, MO_32);
8442 gen_helper_neon_addl_saturate_s32(tcg_res, cpu_env,
8444 tcg_temp_free_i64(tcg_op3);
8448 g_assert_not_reached();
8451 tcg_gen_ext32u_i64(tcg_res, tcg_res);
8452 write_fp_dreg(s, rd, tcg_res);
8454 tcg_temp_free_i32(tcg_op1);
8455 tcg_temp_free_i32(tcg_op2);
8456 tcg_temp_free_i64(tcg_res);
8460 static void handle_3same_64(DisasContext *s, int opcode, bool u,
8461 TCGv_i64 tcg_rd, TCGv_i64 tcg_rn, TCGv_i64 tcg_rm)
8463 /* Handle 64x64->64 opcodes which are shared between the scalar
8464 * and vector 3-same groups. We cover every opcode where size == 3
8465 * is valid in either the three-reg-same (integer, not pairwise)
8466 * or scalar-three-reg-same groups.
8471 case 0x1: /* SQADD */
8473 gen_helper_neon_qadd_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8475 gen_helper_neon_qadd_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8478 case 0x5: /* SQSUB */
8480 gen_helper_neon_qsub_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8482 gen_helper_neon_qsub_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8485 case 0x6: /* CMGT, CMHI */
8486 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
8487 * We implement this using setcond (test) and then negating.
8489 cond = u ? TCG_COND_GTU : TCG_COND_GT;
8491 tcg_gen_setcond_i64(cond, tcg_rd, tcg_rn, tcg_rm);
8492 tcg_gen_neg_i64(tcg_rd, tcg_rd);
8494 case 0x7: /* CMGE, CMHS */
8495 cond = u ? TCG_COND_GEU : TCG_COND_GE;
8497 case 0x11: /* CMTST, CMEQ */
8502 gen_cmtst_i64(tcg_rd, tcg_rn, tcg_rm);
8504 case 0x8: /* SSHL, USHL */
8506 gen_helper_neon_shl_u64(tcg_rd, tcg_rn, tcg_rm);
8508 gen_helper_neon_shl_s64(tcg_rd, tcg_rn, tcg_rm);
8511 case 0x9: /* SQSHL, UQSHL */
8513 gen_helper_neon_qshl_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8515 gen_helper_neon_qshl_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8518 case 0xa: /* SRSHL, URSHL */
8520 gen_helper_neon_rshl_u64(tcg_rd, tcg_rn, tcg_rm);
8522 gen_helper_neon_rshl_s64(tcg_rd, tcg_rn, tcg_rm);
8525 case 0xb: /* SQRSHL, UQRSHL */
8527 gen_helper_neon_qrshl_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8529 gen_helper_neon_qrshl_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8532 case 0x10: /* ADD, SUB */
8534 tcg_gen_sub_i64(tcg_rd, tcg_rn, tcg_rm);
8536 tcg_gen_add_i64(tcg_rd, tcg_rn, tcg_rm);
8540 g_assert_not_reached();
8544 /* Handle the 3-same-operands float operations; shared by the scalar
8545 * and vector encodings. The caller must filter out any encodings
8546 * not allocated for the encoding it is dealing with.
8548 static void handle_3same_float(DisasContext *s, int size, int elements,
8549 int fpopcode, int rd, int rn, int rm)
8552 TCGv_ptr fpst = get_fpstatus_ptr(false);
8554 for (pass = 0; pass < elements; pass++) {
8557 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8558 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8559 TCGv_i64 tcg_res = tcg_temp_new_i64();
8561 read_vec_element(s, tcg_op1, rn, pass, MO_64);
8562 read_vec_element(s, tcg_op2, rm, pass, MO_64);
8565 case 0x39: /* FMLS */
8566 /* As usual for ARM, separate negation for fused multiply-add */
8567 gen_helper_vfp_negd(tcg_op1, tcg_op1);
8569 case 0x19: /* FMLA */
8570 read_vec_element(s, tcg_res, rd, pass, MO_64);
8571 gen_helper_vfp_muladdd(tcg_res, tcg_op1, tcg_op2,
8574 case 0x18: /* FMAXNM */
8575 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
8577 case 0x1a: /* FADD */
8578 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
8580 case 0x1b: /* FMULX */
8581 gen_helper_vfp_mulxd(tcg_res, tcg_op1, tcg_op2, fpst);
8583 case 0x1c: /* FCMEQ */
8584 gen_helper_neon_ceq_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8586 case 0x1e: /* FMAX */
8587 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
8589 case 0x1f: /* FRECPS */
8590 gen_helper_recpsf_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8592 case 0x38: /* FMINNM */
8593 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
8595 case 0x3a: /* FSUB */
8596 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
8598 case 0x3e: /* FMIN */
8599 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
8601 case 0x3f: /* FRSQRTS */
8602 gen_helper_rsqrtsf_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8604 case 0x5b: /* FMUL */
8605 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
8607 case 0x5c: /* FCMGE */
8608 gen_helper_neon_cge_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8610 case 0x5d: /* FACGE */
8611 gen_helper_neon_acge_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8613 case 0x5f: /* FDIV */
8614 gen_helper_vfp_divd(tcg_res, tcg_op1, tcg_op2, fpst);
8616 case 0x7a: /* FABD */
8617 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
8618 gen_helper_vfp_absd(tcg_res, tcg_res);
8620 case 0x7c: /* FCMGT */
8621 gen_helper_neon_cgt_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8623 case 0x7d: /* FACGT */
8624 gen_helper_neon_acgt_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8627 g_assert_not_reached();
8630 write_vec_element(s, tcg_res, rd, pass, MO_64);
8632 tcg_temp_free_i64(tcg_res);
8633 tcg_temp_free_i64(tcg_op1);
8634 tcg_temp_free_i64(tcg_op2);
8637 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
8638 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
8639 TCGv_i32 tcg_res = tcg_temp_new_i32();
8641 read_vec_element_i32(s, tcg_op1, rn, pass, MO_32);
8642 read_vec_element_i32(s, tcg_op2, rm, pass, MO_32);
8645 case 0x39: /* FMLS */
8646 /* As usual for ARM, separate negation for fused multiply-add */
8647 gen_helper_vfp_negs(tcg_op1, tcg_op1);
8649 case 0x19: /* FMLA */
8650 read_vec_element_i32(s, tcg_res, rd, pass, MO_32);
8651 gen_helper_vfp_muladds(tcg_res, tcg_op1, tcg_op2,
8654 case 0x1a: /* FADD */
8655 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
8657 case 0x1b: /* FMULX */
8658 gen_helper_vfp_mulxs(tcg_res, tcg_op1, tcg_op2, fpst);
8660 case 0x1c: /* FCMEQ */
8661 gen_helper_neon_ceq_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8663 case 0x1e: /* FMAX */
8664 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
8666 case 0x1f: /* FRECPS */
8667 gen_helper_recpsf_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8669 case 0x18: /* FMAXNM */
8670 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
8672 case 0x38: /* FMINNM */
8673 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
8675 case 0x3a: /* FSUB */
8676 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
8678 case 0x3e: /* FMIN */
8679 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
8681 case 0x3f: /* FRSQRTS */
8682 gen_helper_rsqrtsf_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8684 case 0x5b: /* FMUL */
8685 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
8687 case 0x5c: /* FCMGE */
8688 gen_helper_neon_cge_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8690 case 0x5d: /* FACGE */
8691 gen_helper_neon_acge_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8693 case 0x5f: /* FDIV */
8694 gen_helper_vfp_divs(tcg_res, tcg_op1, tcg_op2, fpst);
8696 case 0x7a: /* FABD */
8697 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
8698 gen_helper_vfp_abss(tcg_res, tcg_res);
8700 case 0x7c: /* FCMGT */
8701 gen_helper_neon_cgt_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8703 case 0x7d: /* FACGT */
8704 gen_helper_neon_acgt_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8707 g_assert_not_reached();
8710 if (elements == 1) {
8711 /* scalar single so clear high part */
8712 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
8714 tcg_gen_extu_i32_i64(tcg_tmp, tcg_res);
8715 write_vec_element(s, tcg_tmp, rd, pass, MO_64);
8716 tcg_temp_free_i64(tcg_tmp);
8718 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
8721 tcg_temp_free_i32(tcg_res);
8722 tcg_temp_free_i32(tcg_op1);
8723 tcg_temp_free_i32(tcg_op2);
8727 tcg_temp_free_ptr(fpst);
8729 clear_vec_high(s, elements * (size ? 8 : 4) > 8, rd);
8732 /* AdvSIMD scalar three same
8733 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8734 * +-----+---+-----------+------+---+------+--------+---+------+------+
8735 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8736 * +-----+---+-----------+------+---+------+--------+---+------+------+
8738 static void disas_simd_scalar_three_reg_same(DisasContext *s, uint32_t insn)
8740 int rd = extract32(insn, 0, 5);
8741 int rn = extract32(insn, 5, 5);
8742 int opcode = extract32(insn, 11, 5);
8743 int rm = extract32(insn, 16, 5);
8744 int size = extract32(insn, 22, 2);
8745 bool u = extract32(insn, 29, 1);
8748 if (opcode >= 0x18) {
8749 /* Floating point: U, size[1] and opcode indicate operation */
8750 int fpopcode = opcode | (extract32(size, 1, 1) << 5) | (u << 6);
8752 case 0x1b: /* FMULX */
8753 case 0x1f: /* FRECPS */
8754 case 0x3f: /* FRSQRTS */
8755 case 0x5d: /* FACGE */
8756 case 0x7d: /* FACGT */
8757 case 0x1c: /* FCMEQ */
8758 case 0x5c: /* FCMGE */
8759 case 0x7c: /* FCMGT */
8760 case 0x7a: /* FABD */
8763 unallocated_encoding(s);
8767 if (!fp_access_check(s)) {
8771 handle_3same_float(s, extract32(size, 0, 1), 1, fpopcode, rd, rn, rm);
8776 case 0x1: /* SQADD, UQADD */
8777 case 0x5: /* SQSUB, UQSUB */
8778 case 0x9: /* SQSHL, UQSHL */
8779 case 0xb: /* SQRSHL, UQRSHL */
8781 case 0x8: /* SSHL, USHL */
8782 case 0xa: /* SRSHL, URSHL */
8783 case 0x6: /* CMGT, CMHI */
8784 case 0x7: /* CMGE, CMHS */
8785 case 0x11: /* CMTST, CMEQ */
8786 case 0x10: /* ADD, SUB (vector) */
8788 unallocated_encoding(s);
8792 case 0x16: /* SQDMULH, SQRDMULH (vector) */
8793 if (size != 1 && size != 2) {
8794 unallocated_encoding(s);
8799 unallocated_encoding(s);
8803 if (!fp_access_check(s)) {
8807 tcg_rd = tcg_temp_new_i64();
8810 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
8811 TCGv_i64 tcg_rm = read_fp_dreg(s, rm);
8813 handle_3same_64(s, opcode, u, tcg_rd, tcg_rn, tcg_rm);
8814 tcg_temp_free_i64(tcg_rn);
8815 tcg_temp_free_i64(tcg_rm);
8817 /* Do a single operation on the lowest element in the vector.
8818 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
8819 * no side effects for all these operations.
8820 * OPTME: special-purpose helpers would avoid doing some
8821 * unnecessary work in the helper for the 8 and 16 bit cases.
8823 NeonGenTwoOpEnvFn *genenvfn;
8824 TCGv_i32 tcg_rn = tcg_temp_new_i32();
8825 TCGv_i32 tcg_rm = tcg_temp_new_i32();
8826 TCGv_i32 tcg_rd32 = tcg_temp_new_i32();
8828 read_vec_element_i32(s, tcg_rn, rn, 0, size);
8829 read_vec_element_i32(s, tcg_rm, rm, 0, size);
8832 case 0x1: /* SQADD, UQADD */
8834 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8835 { gen_helper_neon_qadd_s8, gen_helper_neon_qadd_u8 },
8836 { gen_helper_neon_qadd_s16, gen_helper_neon_qadd_u16 },
8837 { gen_helper_neon_qadd_s32, gen_helper_neon_qadd_u32 },
8839 genenvfn = fns[size][u];
8842 case 0x5: /* SQSUB, UQSUB */
8844 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8845 { gen_helper_neon_qsub_s8, gen_helper_neon_qsub_u8 },
8846 { gen_helper_neon_qsub_s16, gen_helper_neon_qsub_u16 },
8847 { gen_helper_neon_qsub_s32, gen_helper_neon_qsub_u32 },
8849 genenvfn = fns[size][u];
8852 case 0x9: /* SQSHL, UQSHL */
8854 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8855 { gen_helper_neon_qshl_s8, gen_helper_neon_qshl_u8 },
8856 { gen_helper_neon_qshl_s16, gen_helper_neon_qshl_u16 },
8857 { gen_helper_neon_qshl_s32, gen_helper_neon_qshl_u32 },
8859 genenvfn = fns[size][u];
8862 case 0xb: /* SQRSHL, UQRSHL */
8864 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8865 { gen_helper_neon_qrshl_s8, gen_helper_neon_qrshl_u8 },
8866 { gen_helper_neon_qrshl_s16, gen_helper_neon_qrshl_u16 },
8867 { gen_helper_neon_qrshl_s32, gen_helper_neon_qrshl_u32 },
8869 genenvfn = fns[size][u];
8872 case 0x16: /* SQDMULH, SQRDMULH */
8874 static NeonGenTwoOpEnvFn * const fns[2][2] = {
8875 { gen_helper_neon_qdmulh_s16, gen_helper_neon_qrdmulh_s16 },
8876 { gen_helper_neon_qdmulh_s32, gen_helper_neon_qrdmulh_s32 },
8878 assert(size == 1 || size == 2);
8879 genenvfn = fns[size - 1][u];
8883 g_assert_not_reached();
8886 genenvfn(tcg_rd32, cpu_env, tcg_rn, tcg_rm);
8887 tcg_gen_extu_i32_i64(tcg_rd, tcg_rd32);
8888 tcg_temp_free_i32(tcg_rd32);
8889 tcg_temp_free_i32(tcg_rn);
8890 tcg_temp_free_i32(tcg_rm);
8893 write_fp_dreg(s, rd, tcg_rd);
8895 tcg_temp_free_i64(tcg_rd);
8898 /* AdvSIMD scalar three same FP16
8899 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
8900 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8901 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
8902 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8903 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
8904 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
8906 static void disas_simd_scalar_three_reg_same_fp16(DisasContext *s,
8909 int rd = extract32(insn, 0, 5);
8910 int rn = extract32(insn, 5, 5);
8911 int opcode = extract32(insn, 11, 3);
8912 int rm = extract32(insn, 16, 5);
8913 bool u = extract32(insn, 29, 1);
8914 bool a = extract32(insn, 23, 1);
8915 int fpopcode = opcode | (a << 3) | (u << 4);
8922 case 0x03: /* FMULX */
8923 case 0x04: /* FCMEQ (reg) */
8924 case 0x07: /* FRECPS */
8925 case 0x0f: /* FRSQRTS */
8926 case 0x14: /* FCMGE (reg) */
8927 case 0x15: /* FACGE */
8928 case 0x1a: /* FABD */
8929 case 0x1c: /* FCMGT (reg) */
8930 case 0x1d: /* FACGT */
8933 unallocated_encoding(s);
8937 if (!dc_isar_feature(aa64_fp16, s)) {
8938 unallocated_encoding(s);
8941 if (!fp_access_check(s)) {
8945 fpst = get_fpstatus_ptr(true);
8947 tcg_op1 = read_fp_hreg(s, rn);
8948 tcg_op2 = read_fp_hreg(s, rm);
8949 tcg_res = tcg_temp_new_i32();
8952 case 0x03: /* FMULX */
8953 gen_helper_advsimd_mulxh(tcg_res, tcg_op1, tcg_op2, fpst);
8955 case 0x04: /* FCMEQ (reg) */
8956 gen_helper_advsimd_ceq_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8958 case 0x07: /* FRECPS */
8959 gen_helper_recpsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8961 case 0x0f: /* FRSQRTS */
8962 gen_helper_rsqrtsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8964 case 0x14: /* FCMGE (reg) */
8965 gen_helper_advsimd_cge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8967 case 0x15: /* FACGE */
8968 gen_helper_advsimd_acge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8970 case 0x1a: /* FABD */
8971 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
8972 tcg_gen_andi_i32(tcg_res, tcg_res, 0x7fff);
8974 case 0x1c: /* FCMGT (reg) */
8975 gen_helper_advsimd_cgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8977 case 0x1d: /* FACGT */
8978 gen_helper_advsimd_acgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8981 g_assert_not_reached();
8984 write_fp_sreg(s, rd, tcg_res);
8987 tcg_temp_free_i32(tcg_res);
8988 tcg_temp_free_i32(tcg_op1);
8989 tcg_temp_free_i32(tcg_op2);
8990 tcg_temp_free_ptr(fpst);
8993 /* AdvSIMD scalar three same extra
8994 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
8995 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
8996 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
8997 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
8999 static void disas_simd_scalar_three_reg_same_extra(DisasContext *s,
9002 int rd = extract32(insn, 0, 5);
9003 int rn = extract32(insn, 5, 5);
9004 int opcode = extract32(insn, 11, 4);
9005 int rm = extract32(insn, 16, 5);
9006 int size = extract32(insn, 22, 2);
9007 bool u = extract32(insn, 29, 1);
9008 TCGv_i32 ele1, ele2, ele3;
9012 switch (u * 16 + opcode) {
9013 case 0x10: /* SQRDMLAH (vector) */
9014 case 0x11: /* SQRDMLSH (vector) */
9015 if (size != 1 && size != 2) {
9016 unallocated_encoding(s);
9019 feature = dc_isar_feature(aa64_rdm, s);
9022 unallocated_encoding(s);
9026 unallocated_encoding(s);
9029 if (!fp_access_check(s)) {
9033 /* Do a single operation on the lowest element in the vector.
9034 * We use the standard Neon helpers and rely on 0 OP 0 == 0
9035 * with no side effects for all these operations.
9036 * OPTME: special-purpose helpers would avoid doing some
9037 * unnecessary work in the helper for the 16 bit cases.
9039 ele1 = tcg_temp_new_i32();
9040 ele2 = tcg_temp_new_i32();
9041 ele3 = tcg_temp_new_i32();
9043 read_vec_element_i32(s, ele1, rn, 0, size);
9044 read_vec_element_i32(s, ele2, rm, 0, size);
9045 read_vec_element_i32(s, ele3, rd, 0, size);
9048 case 0x0: /* SQRDMLAH */
9050 gen_helper_neon_qrdmlah_s16(ele3, cpu_env, ele1, ele2, ele3);
9052 gen_helper_neon_qrdmlah_s32(ele3, cpu_env, ele1, ele2, ele3);
9055 case 0x1: /* SQRDMLSH */
9057 gen_helper_neon_qrdmlsh_s16(ele3, cpu_env, ele1, ele2, ele3);
9059 gen_helper_neon_qrdmlsh_s32(ele3, cpu_env, ele1, ele2, ele3);
9063 g_assert_not_reached();
9065 tcg_temp_free_i32(ele1);
9066 tcg_temp_free_i32(ele2);
9068 res = tcg_temp_new_i64();
9069 tcg_gen_extu_i32_i64(res, ele3);
9070 tcg_temp_free_i32(ele3);
9072 write_fp_dreg(s, rd, res);
9073 tcg_temp_free_i64(res);
9076 static void handle_2misc_64(DisasContext *s, int opcode, bool u,
9077 TCGv_i64 tcg_rd, TCGv_i64 tcg_rn,
9078 TCGv_i32 tcg_rmode, TCGv_ptr tcg_fpstatus)
9080 /* Handle 64->64 opcodes which are shared between the scalar and
9081 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
9082 * is valid in either group and also the double-precision fp ops.
9083 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
9089 case 0x4: /* CLS, CLZ */
9091 tcg_gen_clzi_i64(tcg_rd, tcg_rn, 64);
9093 tcg_gen_clrsb_i64(tcg_rd, tcg_rn);
9097 /* This opcode is shared with CNT and RBIT but we have earlier
9098 * enforced that size == 3 if and only if this is the NOT insn.
9100 tcg_gen_not_i64(tcg_rd, tcg_rn);
9102 case 0x7: /* SQABS, SQNEG */
9104 gen_helper_neon_qneg_s64(tcg_rd, cpu_env, tcg_rn);
9106 gen_helper_neon_qabs_s64(tcg_rd, cpu_env, tcg_rn);
9109 case 0xa: /* CMLT */
9110 /* 64 bit integer comparison against zero, result is
9111 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
9116 tcg_gen_setcondi_i64(cond, tcg_rd, tcg_rn, 0);
9117 tcg_gen_neg_i64(tcg_rd, tcg_rd);
9119 case 0x8: /* CMGT, CMGE */
9120 cond = u ? TCG_COND_GE : TCG_COND_GT;
9122 case 0x9: /* CMEQ, CMLE */
9123 cond = u ? TCG_COND_LE : TCG_COND_EQ;
9125 case 0xb: /* ABS, NEG */
9127 tcg_gen_neg_i64(tcg_rd, tcg_rn);
9129 TCGv_i64 tcg_zero = tcg_const_i64(0);
9130 tcg_gen_neg_i64(tcg_rd, tcg_rn);
9131 tcg_gen_movcond_i64(TCG_COND_GT, tcg_rd, tcg_rn, tcg_zero,
9133 tcg_temp_free_i64(tcg_zero);
9136 case 0x2f: /* FABS */
9137 gen_helper_vfp_absd(tcg_rd, tcg_rn);
9139 case 0x6f: /* FNEG */
9140 gen_helper_vfp_negd(tcg_rd, tcg_rn);
9142 case 0x7f: /* FSQRT */
9143 gen_helper_vfp_sqrtd(tcg_rd, tcg_rn, cpu_env);
9145 case 0x1a: /* FCVTNS */
9146 case 0x1b: /* FCVTMS */
9147 case 0x1c: /* FCVTAS */
9148 case 0x3a: /* FCVTPS */
9149 case 0x3b: /* FCVTZS */
9151 TCGv_i32 tcg_shift = tcg_const_i32(0);
9152 gen_helper_vfp_tosqd(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9153 tcg_temp_free_i32(tcg_shift);
9156 case 0x5a: /* FCVTNU */
9157 case 0x5b: /* FCVTMU */
9158 case 0x5c: /* FCVTAU */
9159 case 0x7a: /* FCVTPU */
9160 case 0x7b: /* FCVTZU */
9162 TCGv_i32 tcg_shift = tcg_const_i32(0);
9163 gen_helper_vfp_touqd(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9164 tcg_temp_free_i32(tcg_shift);
9167 case 0x18: /* FRINTN */
9168 case 0x19: /* FRINTM */
9169 case 0x38: /* FRINTP */
9170 case 0x39: /* FRINTZ */
9171 case 0x58: /* FRINTA */
9172 case 0x79: /* FRINTI */
9173 gen_helper_rintd(tcg_rd, tcg_rn, tcg_fpstatus);
9175 case 0x59: /* FRINTX */
9176 gen_helper_rintd_exact(tcg_rd, tcg_rn, tcg_fpstatus);
9179 g_assert_not_reached();
9183 static void handle_2misc_fcmp_zero(DisasContext *s, int opcode,
9184 bool is_scalar, bool is_u, bool is_q,
9185 int size, int rn, int rd)
9187 bool is_double = (size == MO_64);
9190 if (!fp_access_check(s)) {
9194 fpst = get_fpstatus_ptr(size == MO_16);
9197 TCGv_i64 tcg_op = tcg_temp_new_i64();
9198 TCGv_i64 tcg_zero = tcg_const_i64(0);
9199 TCGv_i64 tcg_res = tcg_temp_new_i64();
9200 NeonGenTwoDoubleOPFn *genfn;
9205 case 0x2e: /* FCMLT (zero) */
9208 case 0x2c: /* FCMGT (zero) */
9209 genfn = gen_helper_neon_cgt_f64;
9211 case 0x2d: /* FCMEQ (zero) */
9212 genfn = gen_helper_neon_ceq_f64;
9214 case 0x6d: /* FCMLE (zero) */
9217 case 0x6c: /* FCMGE (zero) */
9218 genfn = gen_helper_neon_cge_f64;
9221 g_assert_not_reached();
9224 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9225 read_vec_element(s, tcg_op, rn, pass, MO_64);
9227 genfn(tcg_res, tcg_zero, tcg_op, fpst);
9229 genfn(tcg_res, tcg_op, tcg_zero, fpst);
9231 write_vec_element(s, tcg_res, rd, pass, MO_64);
9233 tcg_temp_free_i64(tcg_res);
9234 tcg_temp_free_i64(tcg_zero);
9235 tcg_temp_free_i64(tcg_op);
9237 clear_vec_high(s, !is_scalar, rd);
9239 TCGv_i32 tcg_op = tcg_temp_new_i32();
9240 TCGv_i32 tcg_zero = tcg_const_i32(0);
9241 TCGv_i32 tcg_res = tcg_temp_new_i32();
9242 NeonGenTwoSingleOPFn *genfn;
9244 int pass, maxpasses;
9246 if (size == MO_16) {
9248 case 0x2e: /* FCMLT (zero) */
9251 case 0x2c: /* FCMGT (zero) */
9252 genfn = gen_helper_advsimd_cgt_f16;
9254 case 0x2d: /* FCMEQ (zero) */
9255 genfn = gen_helper_advsimd_ceq_f16;
9257 case 0x6d: /* FCMLE (zero) */
9260 case 0x6c: /* FCMGE (zero) */
9261 genfn = gen_helper_advsimd_cge_f16;
9264 g_assert_not_reached();
9268 case 0x2e: /* FCMLT (zero) */
9271 case 0x2c: /* FCMGT (zero) */
9272 genfn = gen_helper_neon_cgt_f32;
9274 case 0x2d: /* FCMEQ (zero) */
9275 genfn = gen_helper_neon_ceq_f32;
9277 case 0x6d: /* FCMLE (zero) */
9280 case 0x6c: /* FCMGE (zero) */
9281 genfn = gen_helper_neon_cge_f32;
9284 g_assert_not_reached();
9291 int vector_size = 8 << is_q;
9292 maxpasses = vector_size >> size;
9295 for (pass = 0; pass < maxpasses; pass++) {
9296 read_vec_element_i32(s, tcg_op, rn, pass, size);
9298 genfn(tcg_res, tcg_zero, tcg_op, fpst);
9300 genfn(tcg_res, tcg_op, tcg_zero, fpst);
9303 write_fp_sreg(s, rd, tcg_res);
9305 write_vec_element_i32(s, tcg_res, rd, pass, size);
9308 tcg_temp_free_i32(tcg_res);
9309 tcg_temp_free_i32(tcg_zero);
9310 tcg_temp_free_i32(tcg_op);
9312 clear_vec_high(s, is_q, rd);
9316 tcg_temp_free_ptr(fpst);
9319 static void handle_2misc_reciprocal(DisasContext *s, int opcode,
9320 bool is_scalar, bool is_u, bool is_q,
9321 int size, int rn, int rd)
9323 bool is_double = (size == 3);
9324 TCGv_ptr fpst = get_fpstatus_ptr(false);
9327 TCGv_i64 tcg_op = tcg_temp_new_i64();
9328 TCGv_i64 tcg_res = tcg_temp_new_i64();
9331 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9332 read_vec_element(s, tcg_op, rn, pass, MO_64);
9334 case 0x3d: /* FRECPE */
9335 gen_helper_recpe_f64(tcg_res, tcg_op, fpst);
9337 case 0x3f: /* FRECPX */
9338 gen_helper_frecpx_f64(tcg_res, tcg_op, fpst);
9340 case 0x7d: /* FRSQRTE */
9341 gen_helper_rsqrte_f64(tcg_res, tcg_op, fpst);
9344 g_assert_not_reached();
9346 write_vec_element(s, tcg_res, rd, pass, MO_64);
9348 tcg_temp_free_i64(tcg_res);
9349 tcg_temp_free_i64(tcg_op);
9350 clear_vec_high(s, !is_scalar, rd);
9352 TCGv_i32 tcg_op = tcg_temp_new_i32();
9353 TCGv_i32 tcg_res = tcg_temp_new_i32();
9354 int pass, maxpasses;
9359 maxpasses = is_q ? 4 : 2;
9362 for (pass = 0; pass < maxpasses; pass++) {
9363 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
9366 case 0x3c: /* URECPE */
9367 gen_helper_recpe_u32(tcg_res, tcg_op, fpst);
9369 case 0x3d: /* FRECPE */
9370 gen_helper_recpe_f32(tcg_res, tcg_op, fpst);
9372 case 0x3f: /* FRECPX */
9373 gen_helper_frecpx_f32(tcg_res, tcg_op, fpst);
9375 case 0x7d: /* FRSQRTE */
9376 gen_helper_rsqrte_f32(tcg_res, tcg_op, fpst);
9379 g_assert_not_reached();
9383 write_fp_sreg(s, rd, tcg_res);
9385 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
9388 tcg_temp_free_i32(tcg_res);
9389 tcg_temp_free_i32(tcg_op);
9391 clear_vec_high(s, is_q, rd);
9394 tcg_temp_free_ptr(fpst);
9397 static void handle_2misc_narrow(DisasContext *s, bool scalar,
9398 int opcode, bool u, bool is_q,
9399 int size, int rn, int rd)
9401 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
9402 * in the source becomes a size element in the destination).
9405 TCGv_i32 tcg_res[2];
9406 int destelt = is_q ? 2 : 0;
9407 int passes = scalar ? 1 : 2;
9410 tcg_res[1] = tcg_const_i32(0);
9413 for (pass = 0; pass < passes; pass++) {
9414 TCGv_i64 tcg_op = tcg_temp_new_i64();
9415 NeonGenNarrowFn *genfn = NULL;
9416 NeonGenNarrowEnvFn *genenvfn = NULL;
9419 read_vec_element(s, tcg_op, rn, pass, size + 1);
9421 read_vec_element(s, tcg_op, rn, pass, MO_64);
9423 tcg_res[pass] = tcg_temp_new_i32();
9426 case 0x12: /* XTN, SQXTUN */
9428 static NeonGenNarrowFn * const xtnfns[3] = {
9429 gen_helper_neon_narrow_u8,
9430 gen_helper_neon_narrow_u16,
9431 tcg_gen_extrl_i64_i32,
9433 static NeonGenNarrowEnvFn * const sqxtunfns[3] = {
9434 gen_helper_neon_unarrow_sat8,
9435 gen_helper_neon_unarrow_sat16,
9436 gen_helper_neon_unarrow_sat32,
9439 genenvfn = sqxtunfns[size];
9441 genfn = xtnfns[size];
9445 case 0x14: /* SQXTN, UQXTN */
9447 static NeonGenNarrowEnvFn * const fns[3][2] = {
9448 { gen_helper_neon_narrow_sat_s8,
9449 gen_helper_neon_narrow_sat_u8 },
9450 { gen_helper_neon_narrow_sat_s16,
9451 gen_helper_neon_narrow_sat_u16 },
9452 { gen_helper_neon_narrow_sat_s32,
9453 gen_helper_neon_narrow_sat_u32 },
9455 genenvfn = fns[size][u];
9458 case 0x16: /* FCVTN, FCVTN2 */
9459 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
9461 gen_helper_vfp_fcvtsd(tcg_res[pass], tcg_op, cpu_env);
9463 TCGv_i32 tcg_lo = tcg_temp_new_i32();
9464 TCGv_i32 tcg_hi = tcg_temp_new_i32();
9465 TCGv_ptr fpst = get_fpstatus_ptr(false);
9466 TCGv_i32 ahp = get_ahp_flag();
9468 tcg_gen_extr_i64_i32(tcg_lo, tcg_hi, tcg_op);
9469 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo, tcg_lo, fpst, ahp);
9470 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi, tcg_hi, fpst, ahp);
9471 tcg_gen_deposit_i32(tcg_res[pass], tcg_lo, tcg_hi, 16, 16);
9472 tcg_temp_free_i32(tcg_lo);
9473 tcg_temp_free_i32(tcg_hi);
9474 tcg_temp_free_ptr(fpst);
9475 tcg_temp_free_i32(ahp);
9478 case 0x56: /* FCVTXN, FCVTXN2 */
9479 /* 64 bit to 32 bit float conversion
9480 * with von Neumann rounding (round to odd)
9483 gen_helper_fcvtx_f64_to_f32(tcg_res[pass], tcg_op, cpu_env);
9486 g_assert_not_reached();
9490 genfn(tcg_res[pass], tcg_op);
9491 } else if (genenvfn) {
9492 genenvfn(tcg_res[pass], cpu_env, tcg_op);
9495 tcg_temp_free_i64(tcg_op);
9498 for (pass = 0; pass < 2; pass++) {
9499 write_vec_element_i32(s, tcg_res[pass], rd, destelt + pass, MO_32);
9500 tcg_temp_free_i32(tcg_res[pass]);
9502 clear_vec_high(s, is_q, rd);
9505 /* Remaining saturating accumulating ops */
9506 static void handle_2misc_satacc(DisasContext *s, bool is_scalar, bool is_u,
9507 bool is_q, int size, int rn, int rd)
9509 bool is_double = (size == 3);
9512 TCGv_i64 tcg_rn = tcg_temp_new_i64();
9513 TCGv_i64 tcg_rd = tcg_temp_new_i64();
9516 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9517 read_vec_element(s, tcg_rn, rn, pass, MO_64);
9518 read_vec_element(s, tcg_rd, rd, pass, MO_64);
9520 if (is_u) { /* USQADD */
9521 gen_helper_neon_uqadd_s64(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9522 } else { /* SUQADD */
9523 gen_helper_neon_sqadd_u64(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9525 write_vec_element(s, tcg_rd, rd, pass, MO_64);
9527 tcg_temp_free_i64(tcg_rd);
9528 tcg_temp_free_i64(tcg_rn);
9529 clear_vec_high(s, !is_scalar, rd);
9531 TCGv_i32 tcg_rn = tcg_temp_new_i32();
9532 TCGv_i32 tcg_rd = tcg_temp_new_i32();
9533 int pass, maxpasses;
9538 maxpasses = is_q ? 4 : 2;
9541 for (pass = 0; pass < maxpasses; pass++) {
9543 read_vec_element_i32(s, tcg_rn, rn, pass, size);
9544 read_vec_element_i32(s, tcg_rd, rd, pass, size);
9546 read_vec_element_i32(s, tcg_rn, rn, pass, MO_32);
9547 read_vec_element_i32(s, tcg_rd, rd, pass, MO_32);
9550 if (is_u) { /* USQADD */
9553 gen_helper_neon_uqadd_s8(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9556 gen_helper_neon_uqadd_s16(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9559 gen_helper_neon_uqadd_s32(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9562 g_assert_not_reached();
9564 } else { /* SUQADD */
9567 gen_helper_neon_sqadd_u8(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9570 gen_helper_neon_sqadd_u16(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9573 gen_helper_neon_sqadd_u32(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9576 g_assert_not_reached();
9581 TCGv_i64 tcg_zero = tcg_const_i64(0);
9582 write_vec_element(s, tcg_zero, rd, 0, MO_64);
9583 tcg_temp_free_i64(tcg_zero);
9585 write_vec_element_i32(s, tcg_rd, rd, pass, MO_32);
9587 tcg_temp_free_i32(tcg_rd);
9588 tcg_temp_free_i32(tcg_rn);
9589 clear_vec_high(s, is_q, rd);
9593 /* AdvSIMD scalar two reg misc
9594 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9595 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9596 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9597 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9599 static void disas_simd_scalar_two_reg_misc(DisasContext *s, uint32_t insn)
9601 int rd = extract32(insn, 0, 5);
9602 int rn = extract32(insn, 5, 5);
9603 int opcode = extract32(insn, 12, 5);
9604 int size = extract32(insn, 22, 2);
9605 bool u = extract32(insn, 29, 1);
9606 bool is_fcvt = false;
9609 TCGv_ptr tcg_fpstatus;
9612 case 0x3: /* USQADD / SUQADD*/
9613 if (!fp_access_check(s)) {
9616 handle_2misc_satacc(s, true, u, false, size, rn, rd);
9618 case 0x7: /* SQABS / SQNEG */
9620 case 0xa: /* CMLT */
9622 unallocated_encoding(s);
9626 case 0x8: /* CMGT, CMGE */
9627 case 0x9: /* CMEQ, CMLE */
9628 case 0xb: /* ABS, NEG */
9630 unallocated_encoding(s);
9634 case 0x12: /* SQXTUN */
9636 unallocated_encoding(s);
9640 case 0x14: /* SQXTN, UQXTN */
9642 unallocated_encoding(s);
9645 if (!fp_access_check(s)) {
9648 handle_2misc_narrow(s, true, opcode, u, false, size, rn, rd);
9653 /* Floating point: U, size[1] and opcode indicate operation;
9654 * size[0] indicates single or double precision.
9656 opcode |= (extract32(size, 1, 1) << 5) | (u << 6);
9657 size = extract32(size, 0, 1) ? 3 : 2;
9659 case 0x2c: /* FCMGT (zero) */
9660 case 0x2d: /* FCMEQ (zero) */
9661 case 0x2e: /* FCMLT (zero) */
9662 case 0x6c: /* FCMGE (zero) */
9663 case 0x6d: /* FCMLE (zero) */
9664 handle_2misc_fcmp_zero(s, opcode, true, u, true, size, rn, rd);
9666 case 0x1d: /* SCVTF */
9667 case 0x5d: /* UCVTF */
9669 bool is_signed = (opcode == 0x1d);
9670 if (!fp_access_check(s)) {
9673 handle_simd_intfp_conv(s, rd, rn, 1, is_signed, 0, size);
9676 case 0x3d: /* FRECPE */
9677 case 0x3f: /* FRECPX */
9678 case 0x7d: /* FRSQRTE */
9679 if (!fp_access_check(s)) {
9682 handle_2misc_reciprocal(s, opcode, true, u, true, size, rn, rd);
9684 case 0x1a: /* FCVTNS */
9685 case 0x1b: /* FCVTMS */
9686 case 0x3a: /* FCVTPS */
9687 case 0x3b: /* FCVTZS */
9688 case 0x5a: /* FCVTNU */
9689 case 0x5b: /* FCVTMU */
9690 case 0x7a: /* FCVTPU */
9691 case 0x7b: /* FCVTZU */
9693 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
9695 case 0x1c: /* FCVTAS */
9696 case 0x5c: /* FCVTAU */
9697 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
9699 rmode = FPROUNDING_TIEAWAY;
9701 case 0x56: /* FCVTXN, FCVTXN2 */
9703 unallocated_encoding(s);
9706 if (!fp_access_check(s)) {
9709 handle_2misc_narrow(s, true, opcode, u, false, size - 1, rn, rd);
9712 unallocated_encoding(s);
9717 unallocated_encoding(s);
9721 if (!fp_access_check(s)) {
9726 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
9727 tcg_fpstatus = get_fpstatus_ptr(false);
9728 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
9731 tcg_fpstatus = NULL;
9735 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
9736 TCGv_i64 tcg_rd = tcg_temp_new_i64();
9738 handle_2misc_64(s, opcode, u, tcg_rd, tcg_rn, tcg_rmode, tcg_fpstatus);
9739 write_fp_dreg(s, rd, tcg_rd);
9740 tcg_temp_free_i64(tcg_rd);
9741 tcg_temp_free_i64(tcg_rn);
9743 TCGv_i32 tcg_rn = tcg_temp_new_i32();
9744 TCGv_i32 tcg_rd = tcg_temp_new_i32();
9746 read_vec_element_i32(s, tcg_rn, rn, 0, size);
9749 case 0x7: /* SQABS, SQNEG */
9751 NeonGenOneOpEnvFn *genfn;
9752 static NeonGenOneOpEnvFn * const fns[3][2] = {
9753 { gen_helper_neon_qabs_s8, gen_helper_neon_qneg_s8 },
9754 { gen_helper_neon_qabs_s16, gen_helper_neon_qneg_s16 },
9755 { gen_helper_neon_qabs_s32, gen_helper_neon_qneg_s32 },
9757 genfn = fns[size][u];
9758 genfn(tcg_rd, cpu_env, tcg_rn);
9761 case 0x1a: /* FCVTNS */
9762 case 0x1b: /* FCVTMS */
9763 case 0x1c: /* FCVTAS */
9764 case 0x3a: /* FCVTPS */
9765 case 0x3b: /* FCVTZS */
9767 TCGv_i32 tcg_shift = tcg_const_i32(0);
9768 gen_helper_vfp_tosls(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9769 tcg_temp_free_i32(tcg_shift);
9772 case 0x5a: /* FCVTNU */
9773 case 0x5b: /* FCVTMU */
9774 case 0x5c: /* FCVTAU */
9775 case 0x7a: /* FCVTPU */
9776 case 0x7b: /* FCVTZU */
9778 TCGv_i32 tcg_shift = tcg_const_i32(0);
9779 gen_helper_vfp_touls(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9780 tcg_temp_free_i32(tcg_shift);
9784 g_assert_not_reached();
9787 write_fp_sreg(s, rd, tcg_rd);
9788 tcg_temp_free_i32(tcg_rd);
9789 tcg_temp_free_i32(tcg_rn);
9793 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
9794 tcg_temp_free_i32(tcg_rmode);
9795 tcg_temp_free_ptr(tcg_fpstatus);
9799 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
9800 static void handle_vec_simd_shri(DisasContext *s, bool is_q, bool is_u,
9801 int immh, int immb, int opcode, int rn, int rd)
9803 int size = 32 - clz32(immh) - 1;
9804 int immhb = immh << 3 | immb;
9805 int shift = 2 * (8 << size) - immhb;
9806 bool accumulate = false;
9807 int dsize = is_q ? 128 : 64;
9808 int esize = 8 << size;
9809 int elements = dsize/esize;
9810 TCGMemOp memop = size | (is_u ? 0 : MO_SIGN);
9811 TCGv_i64 tcg_rn = new_tmp_a64(s);
9812 TCGv_i64 tcg_rd = new_tmp_a64(s);
9814 uint64_t round_const;
9817 if (extract32(immh, 3, 1) && !is_q) {
9818 unallocated_encoding(s);
9821 tcg_debug_assert(size <= 3);
9823 if (!fp_access_check(s)) {
9828 case 0x02: /* SSRA / USRA (accumulate) */
9830 /* Shift count same as element size produces zero to add. */
9831 if (shift == 8 << size) {
9834 gen_gvec_op2i(s, is_q, rd, rn, shift, &usra_op[size]);
9836 /* Shift count same as element size produces all sign to add. */
9837 if (shift == 8 << size) {
9840 gen_gvec_op2i(s, is_q, rd, rn, shift, &ssra_op[size]);
9843 case 0x08: /* SRI */
9844 /* Shift count same as element size is valid but does nothing. */
9845 if (shift == 8 << size) {
9848 gen_gvec_op2i(s, is_q, rd, rn, shift, &sri_op[size]);
9851 case 0x00: /* SSHR / USHR */
9853 if (shift == 8 << size) {
9854 /* Shift count the same size as element size produces zero. */
9855 tcg_gen_gvec_dup8i(vec_full_reg_offset(s, rd),
9856 is_q ? 16 : 8, vec_full_reg_size(s), 0);
9858 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_shri, size);
9861 /* Shift count the same size as element size produces all sign. */
9862 if (shift == 8 << size) {
9865 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_sari, size);
9869 case 0x04: /* SRSHR / URSHR (rounding) */
9871 case 0x06: /* SRSRA / URSRA (accum + rounding) */
9875 g_assert_not_reached();
9878 round_const = 1ULL << (shift - 1);
9879 tcg_round = tcg_const_i64(round_const);
9881 for (i = 0; i < elements; i++) {
9882 read_vec_element(s, tcg_rn, rn, i, memop);
9884 read_vec_element(s, tcg_rd, rd, i, memop);
9887 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
9888 accumulate, is_u, size, shift);
9890 write_vec_element(s, tcg_rd, rd, i, size);
9892 tcg_temp_free_i64(tcg_round);
9895 clear_vec_high(s, is_q, rd);
9898 /* SHL/SLI - Vector shift left */
9899 static void handle_vec_simd_shli(DisasContext *s, bool is_q, bool insert,
9900 int immh, int immb, int opcode, int rn, int rd)
9902 int size = 32 - clz32(immh) - 1;
9903 int immhb = immh << 3 | immb;
9904 int shift = immhb - (8 << size);
9906 /* Range of size is limited by decode: immh is a non-zero 4 bit field */
9907 assert(size >= 0 && size <= 3);
9909 if (extract32(immh, 3, 1) && !is_q) {
9910 unallocated_encoding(s);
9914 if (!fp_access_check(s)) {
9919 gen_gvec_op2i(s, is_q, rd, rn, shift, &sli_op[size]);
9921 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_shli, size);
9925 /* USHLL/SHLL - Vector shift left with widening */
9926 static void handle_vec_simd_wshli(DisasContext *s, bool is_q, bool is_u,
9927 int immh, int immb, int opcode, int rn, int rd)
9929 int size = 32 - clz32(immh) - 1;
9930 int immhb = immh << 3 | immb;
9931 int shift = immhb - (8 << size);
9933 int esize = 8 << size;
9934 int elements = dsize/esize;
9935 TCGv_i64 tcg_rn = new_tmp_a64(s);
9936 TCGv_i64 tcg_rd = new_tmp_a64(s);
9940 unallocated_encoding(s);
9944 if (!fp_access_check(s)) {
9948 /* For the LL variants the store is larger than the load,
9949 * so if rd == rn we would overwrite parts of our input.
9950 * So load everything right now and use shifts in the main loop.
9952 read_vec_element(s, tcg_rn, rn, is_q ? 1 : 0, MO_64);
9954 for (i = 0; i < elements; i++) {
9955 tcg_gen_shri_i64(tcg_rd, tcg_rn, i * esize);
9956 ext_and_shift_reg(tcg_rd, tcg_rd, size | (!is_u << 2), 0);
9957 tcg_gen_shli_i64(tcg_rd, tcg_rd, shift);
9958 write_vec_element(s, tcg_rd, rd, i, size + 1);
9962 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
9963 static void handle_vec_simd_shrn(DisasContext *s, bool is_q,
9964 int immh, int immb, int opcode, int rn, int rd)
9966 int immhb = immh << 3 | immb;
9967 int size = 32 - clz32(immh) - 1;
9969 int esize = 8 << size;
9970 int elements = dsize/esize;
9971 int shift = (2 * esize) - immhb;
9972 bool round = extract32(opcode, 0, 1);
9973 TCGv_i64 tcg_rn, tcg_rd, tcg_final;
9977 if (extract32(immh, 3, 1)) {
9978 unallocated_encoding(s);
9982 if (!fp_access_check(s)) {
9986 tcg_rn = tcg_temp_new_i64();
9987 tcg_rd = tcg_temp_new_i64();
9988 tcg_final = tcg_temp_new_i64();
9989 read_vec_element(s, tcg_final, rd, is_q ? 1 : 0, MO_64);
9992 uint64_t round_const = 1ULL << (shift - 1);
9993 tcg_round = tcg_const_i64(round_const);
9998 for (i = 0; i < elements; i++) {
9999 read_vec_element(s, tcg_rn, rn, i, size+1);
10000 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
10001 false, true, size+1, shift);
10003 tcg_gen_deposit_i64(tcg_final, tcg_final, tcg_rd, esize * i, esize);
10007 write_vec_element(s, tcg_final, rd, 0, MO_64);
10009 write_vec_element(s, tcg_final, rd, 1, MO_64);
10012 tcg_temp_free_i64(tcg_round);
10014 tcg_temp_free_i64(tcg_rn);
10015 tcg_temp_free_i64(tcg_rd);
10016 tcg_temp_free_i64(tcg_final);
10018 clear_vec_high(s, is_q, rd);
10022 /* AdvSIMD shift by immediate
10023 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
10024 * +---+---+---+-------------+------+------+--------+---+------+------+
10025 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
10026 * +---+---+---+-------------+------+------+--------+---+------+------+
10028 static void disas_simd_shift_imm(DisasContext *s, uint32_t insn)
10030 int rd = extract32(insn, 0, 5);
10031 int rn = extract32(insn, 5, 5);
10032 int opcode = extract32(insn, 11, 5);
10033 int immb = extract32(insn, 16, 3);
10034 int immh = extract32(insn, 19, 4);
10035 bool is_u = extract32(insn, 29, 1);
10036 bool is_q = extract32(insn, 30, 1);
10039 case 0x08: /* SRI */
10041 unallocated_encoding(s);
10045 case 0x00: /* SSHR / USHR */
10046 case 0x02: /* SSRA / USRA (accumulate) */
10047 case 0x04: /* SRSHR / URSHR (rounding) */
10048 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10049 handle_vec_simd_shri(s, is_q, is_u, immh, immb, opcode, rn, rd);
10051 case 0x0a: /* SHL / SLI */
10052 handle_vec_simd_shli(s, is_q, is_u, immh, immb, opcode, rn, rd);
10054 case 0x10: /* SHRN */
10055 case 0x11: /* RSHRN / SQRSHRUN */
10057 handle_vec_simd_sqshrn(s, false, is_q, false, true, immh, immb,
10060 handle_vec_simd_shrn(s, is_q, immh, immb, opcode, rn, rd);
10063 case 0x12: /* SQSHRN / UQSHRN */
10064 case 0x13: /* SQRSHRN / UQRSHRN */
10065 handle_vec_simd_sqshrn(s, false, is_q, is_u, is_u, immh, immb,
10068 case 0x14: /* SSHLL / USHLL */
10069 handle_vec_simd_wshli(s, is_q, is_u, immh, immb, opcode, rn, rd);
10071 case 0x1c: /* SCVTF / UCVTF */
10072 handle_simd_shift_intfp_conv(s, false, is_q, is_u, immh, immb,
10075 case 0xc: /* SQSHLU */
10077 unallocated_encoding(s);
10080 handle_simd_qshl(s, false, is_q, false, true, immh, immb, rn, rd);
10082 case 0xe: /* SQSHL, UQSHL */
10083 handle_simd_qshl(s, false, is_q, is_u, is_u, immh, immb, rn, rd);
10085 case 0x1f: /* FCVTZS/ FCVTZU */
10086 handle_simd_shift_fpint_conv(s, false, is_q, is_u, immh, immb, rn, rd);
10089 unallocated_encoding(s);
10094 /* Generate code to do a "long" addition or subtraction, ie one done in
10095 * TCGv_i64 on vector lanes twice the width specified by size.
10097 static void gen_neon_addl(int size, bool is_sub, TCGv_i64 tcg_res,
10098 TCGv_i64 tcg_op1, TCGv_i64 tcg_op2)
10100 static NeonGenTwo64OpFn * const fns[3][2] = {
10101 { gen_helper_neon_addl_u16, gen_helper_neon_subl_u16 },
10102 { gen_helper_neon_addl_u32, gen_helper_neon_subl_u32 },
10103 { tcg_gen_add_i64, tcg_gen_sub_i64 },
10105 NeonGenTwo64OpFn *genfn;
10108 genfn = fns[size][is_sub];
10109 genfn(tcg_res, tcg_op1, tcg_op2);
10112 static void handle_3rd_widening(DisasContext *s, int is_q, int is_u, int size,
10113 int opcode, int rd, int rn, int rm)
10115 /* 3-reg-different widening insns: 64 x 64 -> 128 */
10116 TCGv_i64 tcg_res[2];
10119 tcg_res[0] = tcg_temp_new_i64();
10120 tcg_res[1] = tcg_temp_new_i64();
10122 /* Does this op do an adding accumulate, a subtracting accumulate,
10123 * or no accumulate at all?
10141 read_vec_element(s, tcg_res[0], rd, 0, MO_64);
10142 read_vec_element(s, tcg_res[1], rd, 1, MO_64);
10145 /* size == 2 means two 32x32->64 operations; this is worth special
10146 * casing because we can generally handle it inline.
10149 for (pass = 0; pass < 2; pass++) {
10150 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10151 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10152 TCGv_i64 tcg_passres;
10153 TCGMemOp memop = MO_32 | (is_u ? 0 : MO_SIGN);
10155 int elt = pass + is_q * 2;
10157 read_vec_element(s, tcg_op1, rn, elt, memop);
10158 read_vec_element(s, tcg_op2, rm, elt, memop);
10161 tcg_passres = tcg_res[pass];
10163 tcg_passres = tcg_temp_new_i64();
10167 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10168 tcg_gen_add_i64(tcg_passres, tcg_op1, tcg_op2);
10170 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10171 tcg_gen_sub_i64(tcg_passres, tcg_op1, tcg_op2);
10173 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10174 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10176 TCGv_i64 tcg_tmp1 = tcg_temp_new_i64();
10177 TCGv_i64 tcg_tmp2 = tcg_temp_new_i64();
10179 tcg_gen_sub_i64(tcg_tmp1, tcg_op1, tcg_op2);
10180 tcg_gen_sub_i64(tcg_tmp2, tcg_op2, tcg_op1);
10181 tcg_gen_movcond_i64(is_u ? TCG_COND_GEU : TCG_COND_GE,
10183 tcg_op1, tcg_op2, tcg_tmp1, tcg_tmp2);
10184 tcg_temp_free_i64(tcg_tmp1);
10185 tcg_temp_free_i64(tcg_tmp2);
10188 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10189 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10190 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10191 tcg_gen_mul_i64(tcg_passres, tcg_op1, tcg_op2);
10193 case 9: /* SQDMLAL, SQDMLAL2 */
10194 case 11: /* SQDMLSL, SQDMLSL2 */
10195 case 13: /* SQDMULL, SQDMULL2 */
10196 tcg_gen_mul_i64(tcg_passres, tcg_op1, tcg_op2);
10197 gen_helper_neon_addl_saturate_s64(tcg_passres, cpu_env,
10198 tcg_passres, tcg_passres);
10201 g_assert_not_reached();
10204 if (opcode == 9 || opcode == 11) {
10205 /* saturating accumulate ops */
10207 tcg_gen_neg_i64(tcg_passres, tcg_passres);
10209 gen_helper_neon_addl_saturate_s64(tcg_res[pass], cpu_env,
10210 tcg_res[pass], tcg_passres);
10211 } else if (accop > 0) {
10212 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
10213 } else if (accop < 0) {
10214 tcg_gen_sub_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
10218 tcg_temp_free_i64(tcg_passres);
10221 tcg_temp_free_i64(tcg_op1);
10222 tcg_temp_free_i64(tcg_op2);
10225 /* size 0 or 1, generally helper functions */
10226 for (pass = 0; pass < 2; pass++) {
10227 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
10228 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10229 TCGv_i64 tcg_passres;
10230 int elt = pass + is_q * 2;
10232 read_vec_element_i32(s, tcg_op1, rn, elt, MO_32);
10233 read_vec_element_i32(s, tcg_op2, rm, elt, MO_32);
10236 tcg_passres = tcg_res[pass];
10238 tcg_passres = tcg_temp_new_i64();
10242 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10243 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10245 TCGv_i64 tcg_op2_64 = tcg_temp_new_i64();
10246 static NeonGenWidenFn * const widenfns[2][2] = {
10247 { gen_helper_neon_widen_s8, gen_helper_neon_widen_u8 },
10248 { gen_helper_neon_widen_s16, gen_helper_neon_widen_u16 },
10250 NeonGenWidenFn *widenfn = widenfns[size][is_u];
10252 widenfn(tcg_op2_64, tcg_op2);
10253 widenfn(tcg_passres, tcg_op1);
10254 gen_neon_addl(size, (opcode == 2), tcg_passres,
10255 tcg_passres, tcg_op2_64);
10256 tcg_temp_free_i64(tcg_op2_64);
10259 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10260 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10263 gen_helper_neon_abdl_u16(tcg_passres, tcg_op1, tcg_op2);
10265 gen_helper_neon_abdl_s16(tcg_passres, tcg_op1, tcg_op2);
10269 gen_helper_neon_abdl_u32(tcg_passres, tcg_op1, tcg_op2);
10271 gen_helper_neon_abdl_s32(tcg_passres, tcg_op1, tcg_op2);
10275 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10276 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10277 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10280 gen_helper_neon_mull_u8(tcg_passres, tcg_op1, tcg_op2);
10282 gen_helper_neon_mull_s8(tcg_passres, tcg_op1, tcg_op2);
10286 gen_helper_neon_mull_u16(tcg_passres, tcg_op1, tcg_op2);
10288 gen_helper_neon_mull_s16(tcg_passres, tcg_op1, tcg_op2);
10292 case 9: /* SQDMLAL, SQDMLAL2 */
10293 case 11: /* SQDMLSL, SQDMLSL2 */
10294 case 13: /* SQDMULL, SQDMULL2 */
10296 gen_helper_neon_mull_s16(tcg_passres, tcg_op1, tcg_op2);
10297 gen_helper_neon_addl_saturate_s32(tcg_passres, cpu_env,
10298 tcg_passres, tcg_passres);
10300 case 14: /* PMULL */
10302 gen_helper_neon_mull_p8(tcg_passres, tcg_op1, tcg_op2);
10305 g_assert_not_reached();
10307 tcg_temp_free_i32(tcg_op1);
10308 tcg_temp_free_i32(tcg_op2);
10311 if (opcode == 9 || opcode == 11) {
10312 /* saturating accumulate ops */
10314 gen_helper_neon_negl_u32(tcg_passres, tcg_passres);
10316 gen_helper_neon_addl_saturate_s32(tcg_res[pass], cpu_env,
10320 gen_neon_addl(size, (accop < 0), tcg_res[pass],
10321 tcg_res[pass], tcg_passres);
10323 tcg_temp_free_i64(tcg_passres);
10328 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
10329 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
10330 tcg_temp_free_i64(tcg_res[0]);
10331 tcg_temp_free_i64(tcg_res[1]);
10334 static void handle_3rd_wide(DisasContext *s, int is_q, int is_u, int size,
10335 int opcode, int rd, int rn, int rm)
10337 TCGv_i64 tcg_res[2];
10338 int part = is_q ? 2 : 0;
10341 for (pass = 0; pass < 2; pass++) {
10342 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10343 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10344 TCGv_i64 tcg_op2_wide = tcg_temp_new_i64();
10345 static NeonGenWidenFn * const widenfns[3][2] = {
10346 { gen_helper_neon_widen_s8, gen_helper_neon_widen_u8 },
10347 { gen_helper_neon_widen_s16, gen_helper_neon_widen_u16 },
10348 { tcg_gen_ext_i32_i64, tcg_gen_extu_i32_i64 },
10350 NeonGenWidenFn *widenfn = widenfns[size][is_u];
10352 read_vec_element(s, tcg_op1, rn, pass, MO_64);
10353 read_vec_element_i32(s, tcg_op2, rm, part + pass, MO_32);
10354 widenfn(tcg_op2_wide, tcg_op2);
10355 tcg_temp_free_i32(tcg_op2);
10356 tcg_res[pass] = tcg_temp_new_i64();
10357 gen_neon_addl(size, (opcode == 3),
10358 tcg_res[pass], tcg_op1, tcg_op2_wide);
10359 tcg_temp_free_i64(tcg_op1);
10360 tcg_temp_free_i64(tcg_op2_wide);
10363 for (pass = 0; pass < 2; pass++) {
10364 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
10365 tcg_temp_free_i64(tcg_res[pass]);
10369 static void do_narrow_round_high_u32(TCGv_i32 res, TCGv_i64 in)
10371 tcg_gen_addi_i64(in, in, 1U << 31);
10372 tcg_gen_extrh_i64_i32(res, in);
10375 static void handle_3rd_narrowing(DisasContext *s, int is_q, int is_u, int size,
10376 int opcode, int rd, int rn, int rm)
10378 TCGv_i32 tcg_res[2];
10379 int part = is_q ? 2 : 0;
10382 for (pass = 0; pass < 2; pass++) {
10383 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10384 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10385 TCGv_i64 tcg_wideres = tcg_temp_new_i64();
10386 static NeonGenNarrowFn * const narrowfns[3][2] = {
10387 { gen_helper_neon_narrow_high_u8,
10388 gen_helper_neon_narrow_round_high_u8 },
10389 { gen_helper_neon_narrow_high_u16,
10390 gen_helper_neon_narrow_round_high_u16 },
10391 { tcg_gen_extrh_i64_i32, do_narrow_round_high_u32 },
10393 NeonGenNarrowFn *gennarrow = narrowfns[size][is_u];
10395 read_vec_element(s, tcg_op1, rn, pass, MO_64);
10396 read_vec_element(s, tcg_op2, rm, pass, MO_64);
10398 gen_neon_addl(size, (opcode == 6), tcg_wideres, tcg_op1, tcg_op2);
10400 tcg_temp_free_i64(tcg_op1);
10401 tcg_temp_free_i64(tcg_op2);
10403 tcg_res[pass] = tcg_temp_new_i32();
10404 gennarrow(tcg_res[pass], tcg_wideres);
10405 tcg_temp_free_i64(tcg_wideres);
10408 for (pass = 0; pass < 2; pass++) {
10409 write_vec_element_i32(s, tcg_res[pass], rd, pass + part, MO_32);
10410 tcg_temp_free_i32(tcg_res[pass]);
10412 clear_vec_high(s, is_q, rd);
10415 static void handle_pmull_64(DisasContext *s, int is_q, int rd, int rn, int rm)
10417 /* PMULL of 64 x 64 -> 128 is an odd special case because it
10418 * is the only three-reg-diff instruction which produces a
10419 * 128-bit wide result from a single operation. However since
10420 * it's possible to calculate the two halves more or less
10421 * separately we just use two helper calls.
10423 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10424 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10425 TCGv_i64 tcg_res = tcg_temp_new_i64();
10427 read_vec_element(s, tcg_op1, rn, is_q, MO_64);
10428 read_vec_element(s, tcg_op2, rm, is_q, MO_64);
10429 gen_helper_neon_pmull_64_lo(tcg_res, tcg_op1, tcg_op2);
10430 write_vec_element(s, tcg_res, rd, 0, MO_64);
10431 gen_helper_neon_pmull_64_hi(tcg_res, tcg_op1, tcg_op2);
10432 write_vec_element(s, tcg_res, rd, 1, MO_64);
10434 tcg_temp_free_i64(tcg_op1);
10435 tcg_temp_free_i64(tcg_op2);
10436 tcg_temp_free_i64(tcg_res);
10439 /* AdvSIMD three different
10440 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
10441 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10442 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
10443 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10445 static void disas_simd_three_reg_diff(DisasContext *s, uint32_t insn)
10447 /* Instructions in this group fall into three basic classes
10448 * (in each case with the operation working on each element in
10449 * the input vectors):
10450 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
10452 * (2) wide 64 x 128 -> 128
10453 * (3) narrowing 128 x 128 -> 64
10454 * Here we do initial decode, catch unallocated cases and
10455 * dispatch to separate functions for each class.
10457 int is_q = extract32(insn, 30, 1);
10458 int is_u = extract32(insn, 29, 1);
10459 int size = extract32(insn, 22, 2);
10460 int opcode = extract32(insn, 12, 4);
10461 int rm = extract32(insn, 16, 5);
10462 int rn = extract32(insn, 5, 5);
10463 int rd = extract32(insn, 0, 5);
10466 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
10467 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
10468 /* 64 x 128 -> 128 */
10470 unallocated_encoding(s);
10473 if (!fp_access_check(s)) {
10476 handle_3rd_wide(s, is_q, is_u, size, opcode, rd, rn, rm);
10478 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
10479 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
10480 /* 128 x 128 -> 64 */
10482 unallocated_encoding(s);
10485 if (!fp_access_check(s)) {
10488 handle_3rd_narrowing(s, is_q, is_u, size, opcode, rd, rn, rm);
10490 case 14: /* PMULL, PMULL2 */
10491 if (is_u || size == 1 || size == 2) {
10492 unallocated_encoding(s);
10496 if (!dc_isar_feature(aa64_pmull, s)) {
10497 unallocated_encoding(s);
10500 if (!fp_access_check(s)) {
10503 handle_pmull_64(s, is_q, rd, rn, rm);
10507 case 9: /* SQDMLAL, SQDMLAL2 */
10508 case 11: /* SQDMLSL, SQDMLSL2 */
10509 case 13: /* SQDMULL, SQDMULL2 */
10510 if (is_u || size == 0) {
10511 unallocated_encoding(s);
10515 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10516 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10517 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10518 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10519 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10520 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10521 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
10522 /* 64 x 64 -> 128 */
10524 unallocated_encoding(s);
10528 if (!fp_access_check(s)) {
10532 handle_3rd_widening(s, is_q, is_u, size, opcode, rd, rn, rm);
10535 /* opcode 15 not allocated */
10536 unallocated_encoding(s);
10541 /* Logic op (opcode == 3) subgroup of C3.6.16. */
10542 static void disas_simd_3same_logic(DisasContext *s, uint32_t insn)
10544 int rd = extract32(insn, 0, 5);
10545 int rn = extract32(insn, 5, 5);
10546 int rm = extract32(insn, 16, 5);
10547 int size = extract32(insn, 22, 2);
10548 bool is_u = extract32(insn, 29, 1);
10549 bool is_q = extract32(insn, 30, 1);
10551 if (!fp_access_check(s)) {
10555 switch (size + 4 * is_u) {
10557 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_and, 0);
10560 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_andc, 0);
10563 if (rn == rm) { /* MOV */
10564 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_mov, 0);
10566 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_or, 0);
10570 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_orc, 0);
10573 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_xor, 0);
10576 case 5: /* BSL bitwise select */
10577 gen_gvec_op3(s, is_q, rd, rn, rm, &bsl_op);
10579 case 6: /* BIT, bitwise insert if true */
10580 gen_gvec_op3(s, is_q, rd, rn, rm, &bit_op);
10582 case 7: /* BIF, bitwise insert if false */
10583 gen_gvec_op3(s, is_q, rd, rn, rm, &bif_op);
10587 g_assert_not_reached();
10591 /* Pairwise op subgroup of C3.6.16.
10593 * This is called directly or via the handle_3same_float for float pairwise
10594 * operations where the opcode and size are calculated differently.
10596 static void handle_simd_3same_pair(DisasContext *s, int is_q, int u, int opcode,
10597 int size, int rn, int rm, int rd)
10602 /* Floating point operations need fpst */
10603 if (opcode >= 0x58) {
10604 fpst = get_fpstatus_ptr(false);
10609 if (!fp_access_check(s)) {
10613 /* These operations work on the concatenated rm:rn, with each pair of
10614 * adjacent elements being operated on to produce an element in the result.
10617 TCGv_i64 tcg_res[2];
10619 for (pass = 0; pass < 2; pass++) {
10620 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10621 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10622 int passreg = (pass == 0) ? rn : rm;
10624 read_vec_element(s, tcg_op1, passreg, 0, MO_64);
10625 read_vec_element(s, tcg_op2, passreg, 1, MO_64);
10626 tcg_res[pass] = tcg_temp_new_i64();
10629 case 0x17: /* ADDP */
10630 tcg_gen_add_i64(tcg_res[pass], tcg_op1, tcg_op2);
10632 case 0x58: /* FMAXNMP */
10633 gen_helper_vfp_maxnumd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10635 case 0x5a: /* FADDP */
10636 gen_helper_vfp_addd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10638 case 0x5e: /* FMAXP */
10639 gen_helper_vfp_maxd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10641 case 0x78: /* FMINNMP */
10642 gen_helper_vfp_minnumd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10644 case 0x7e: /* FMINP */
10645 gen_helper_vfp_mind(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10648 g_assert_not_reached();
10651 tcg_temp_free_i64(tcg_op1);
10652 tcg_temp_free_i64(tcg_op2);
10655 for (pass = 0; pass < 2; pass++) {
10656 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
10657 tcg_temp_free_i64(tcg_res[pass]);
10660 int maxpass = is_q ? 4 : 2;
10661 TCGv_i32 tcg_res[4];
10663 for (pass = 0; pass < maxpass; pass++) {
10664 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
10665 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10666 NeonGenTwoOpFn *genfn = NULL;
10667 int passreg = pass < (maxpass / 2) ? rn : rm;
10668 int passelt = (is_q && (pass & 1)) ? 2 : 0;
10670 read_vec_element_i32(s, tcg_op1, passreg, passelt, MO_32);
10671 read_vec_element_i32(s, tcg_op2, passreg, passelt + 1, MO_32);
10672 tcg_res[pass] = tcg_temp_new_i32();
10675 case 0x17: /* ADDP */
10677 static NeonGenTwoOpFn * const fns[3] = {
10678 gen_helper_neon_padd_u8,
10679 gen_helper_neon_padd_u16,
10685 case 0x14: /* SMAXP, UMAXP */
10687 static NeonGenTwoOpFn * const fns[3][2] = {
10688 { gen_helper_neon_pmax_s8, gen_helper_neon_pmax_u8 },
10689 { gen_helper_neon_pmax_s16, gen_helper_neon_pmax_u16 },
10690 { tcg_gen_smax_i32, tcg_gen_umax_i32 },
10692 genfn = fns[size][u];
10695 case 0x15: /* SMINP, UMINP */
10697 static NeonGenTwoOpFn * const fns[3][2] = {
10698 { gen_helper_neon_pmin_s8, gen_helper_neon_pmin_u8 },
10699 { gen_helper_neon_pmin_s16, gen_helper_neon_pmin_u16 },
10700 { tcg_gen_smin_i32, tcg_gen_umin_i32 },
10702 genfn = fns[size][u];
10705 /* The FP operations are all on single floats (32 bit) */
10706 case 0x58: /* FMAXNMP */
10707 gen_helper_vfp_maxnums(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10709 case 0x5a: /* FADDP */
10710 gen_helper_vfp_adds(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10712 case 0x5e: /* FMAXP */
10713 gen_helper_vfp_maxs(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10715 case 0x78: /* FMINNMP */
10716 gen_helper_vfp_minnums(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10718 case 0x7e: /* FMINP */
10719 gen_helper_vfp_mins(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10722 g_assert_not_reached();
10725 /* FP ops called directly, otherwise call now */
10727 genfn(tcg_res[pass], tcg_op1, tcg_op2);
10730 tcg_temp_free_i32(tcg_op1);
10731 tcg_temp_free_i32(tcg_op2);
10734 for (pass = 0; pass < maxpass; pass++) {
10735 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32);
10736 tcg_temp_free_i32(tcg_res[pass]);
10738 clear_vec_high(s, is_q, rd);
10742 tcg_temp_free_ptr(fpst);
10746 /* Floating point op subgroup of C3.6.16. */
10747 static void disas_simd_3same_float(DisasContext *s, uint32_t insn)
10749 /* For floating point ops, the U, size[1] and opcode bits
10750 * together indicate the operation. size[0] indicates single
10753 int fpopcode = extract32(insn, 11, 5)
10754 | (extract32(insn, 23, 1) << 5)
10755 | (extract32(insn, 29, 1) << 6);
10756 int is_q = extract32(insn, 30, 1);
10757 int size = extract32(insn, 22, 1);
10758 int rm = extract32(insn, 16, 5);
10759 int rn = extract32(insn, 5, 5);
10760 int rd = extract32(insn, 0, 5);
10762 int datasize = is_q ? 128 : 64;
10763 int esize = 32 << size;
10764 int elements = datasize / esize;
10766 if (size == 1 && !is_q) {
10767 unallocated_encoding(s);
10771 switch (fpopcode) {
10772 case 0x58: /* FMAXNMP */
10773 case 0x5a: /* FADDP */
10774 case 0x5e: /* FMAXP */
10775 case 0x78: /* FMINNMP */
10776 case 0x7e: /* FMINP */
10777 if (size && !is_q) {
10778 unallocated_encoding(s);
10781 handle_simd_3same_pair(s, is_q, 0, fpopcode, size ? MO_64 : MO_32,
10784 case 0x1b: /* FMULX */
10785 case 0x1f: /* FRECPS */
10786 case 0x3f: /* FRSQRTS */
10787 case 0x5d: /* FACGE */
10788 case 0x7d: /* FACGT */
10789 case 0x19: /* FMLA */
10790 case 0x39: /* FMLS */
10791 case 0x18: /* FMAXNM */
10792 case 0x1a: /* FADD */
10793 case 0x1c: /* FCMEQ */
10794 case 0x1e: /* FMAX */
10795 case 0x38: /* FMINNM */
10796 case 0x3a: /* FSUB */
10797 case 0x3e: /* FMIN */
10798 case 0x5b: /* FMUL */
10799 case 0x5c: /* FCMGE */
10800 case 0x5f: /* FDIV */
10801 case 0x7a: /* FABD */
10802 case 0x7c: /* FCMGT */
10803 if (!fp_access_check(s)) {
10807 handle_3same_float(s, size, elements, fpopcode, rd, rn, rm);
10810 unallocated_encoding(s);
10815 /* Integer op subgroup of C3.6.16. */
10816 static void disas_simd_3same_int(DisasContext *s, uint32_t insn)
10818 int is_q = extract32(insn, 30, 1);
10819 int u = extract32(insn, 29, 1);
10820 int size = extract32(insn, 22, 2);
10821 int opcode = extract32(insn, 11, 5);
10822 int rm = extract32(insn, 16, 5);
10823 int rn = extract32(insn, 5, 5);
10824 int rd = extract32(insn, 0, 5);
10829 case 0x13: /* MUL, PMUL */
10830 if (u && size != 0) {
10831 unallocated_encoding(s);
10835 case 0x0: /* SHADD, UHADD */
10836 case 0x2: /* SRHADD, URHADD */
10837 case 0x4: /* SHSUB, UHSUB */
10838 case 0xc: /* SMAX, UMAX */
10839 case 0xd: /* SMIN, UMIN */
10840 case 0xe: /* SABD, UABD */
10841 case 0xf: /* SABA, UABA */
10842 case 0x12: /* MLA, MLS */
10844 unallocated_encoding(s);
10848 case 0x16: /* SQDMULH, SQRDMULH */
10849 if (size == 0 || size == 3) {
10850 unallocated_encoding(s);
10855 if (size == 3 && !is_q) {
10856 unallocated_encoding(s);
10862 if (!fp_access_check(s)) {
10867 case 0x10: /* ADD, SUB */
10869 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_sub, size);
10871 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_add, size);
10874 case 0x13: /* MUL, PMUL */
10875 if (!u) { /* MUL */
10876 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_mul, size);
10880 case 0x12: /* MLA, MLS */
10882 gen_gvec_op3(s, is_q, rd, rn, rm, &mls_op[size]);
10884 gen_gvec_op3(s, is_q, rd, rn, rm, &mla_op[size]);
10888 if (!u) { /* CMTST */
10889 gen_gvec_op3(s, is_q, rd, rn, rm, &cmtst_op[size]);
10893 cond = TCG_COND_EQ;
10895 case 0x06: /* CMGT, CMHI */
10896 cond = u ? TCG_COND_GTU : TCG_COND_GT;
10898 case 0x07: /* CMGE, CMHS */
10899 cond = u ? TCG_COND_GEU : TCG_COND_GE;
10901 tcg_gen_gvec_cmp(cond, size, vec_full_reg_offset(s, rd),
10902 vec_full_reg_offset(s, rn),
10903 vec_full_reg_offset(s, rm),
10904 is_q ? 16 : 8, vec_full_reg_size(s));
10910 for (pass = 0; pass < 2; pass++) {
10911 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10912 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10913 TCGv_i64 tcg_res = tcg_temp_new_i64();
10915 read_vec_element(s, tcg_op1, rn, pass, MO_64);
10916 read_vec_element(s, tcg_op2, rm, pass, MO_64);
10918 handle_3same_64(s, opcode, u, tcg_res, tcg_op1, tcg_op2);
10920 write_vec_element(s, tcg_res, rd, pass, MO_64);
10922 tcg_temp_free_i64(tcg_res);
10923 tcg_temp_free_i64(tcg_op1);
10924 tcg_temp_free_i64(tcg_op2);
10927 for (pass = 0; pass < (is_q ? 4 : 2); pass++) {
10928 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
10929 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10930 TCGv_i32 tcg_res = tcg_temp_new_i32();
10931 NeonGenTwoOpFn *genfn = NULL;
10932 NeonGenTwoOpEnvFn *genenvfn = NULL;
10934 read_vec_element_i32(s, tcg_op1, rn, pass, MO_32);
10935 read_vec_element_i32(s, tcg_op2, rm, pass, MO_32);
10938 case 0x0: /* SHADD, UHADD */
10940 static NeonGenTwoOpFn * const fns[3][2] = {
10941 { gen_helper_neon_hadd_s8, gen_helper_neon_hadd_u8 },
10942 { gen_helper_neon_hadd_s16, gen_helper_neon_hadd_u16 },
10943 { gen_helper_neon_hadd_s32, gen_helper_neon_hadd_u32 },
10945 genfn = fns[size][u];
10948 case 0x1: /* SQADD, UQADD */
10950 static NeonGenTwoOpEnvFn * const fns[3][2] = {
10951 { gen_helper_neon_qadd_s8, gen_helper_neon_qadd_u8 },
10952 { gen_helper_neon_qadd_s16, gen_helper_neon_qadd_u16 },
10953 { gen_helper_neon_qadd_s32, gen_helper_neon_qadd_u32 },
10955 genenvfn = fns[size][u];
10958 case 0x2: /* SRHADD, URHADD */
10960 static NeonGenTwoOpFn * const fns[3][2] = {
10961 { gen_helper_neon_rhadd_s8, gen_helper_neon_rhadd_u8 },
10962 { gen_helper_neon_rhadd_s16, gen_helper_neon_rhadd_u16 },
10963 { gen_helper_neon_rhadd_s32, gen_helper_neon_rhadd_u32 },
10965 genfn = fns[size][u];
10968 case 0x4: /* SHSUB, UHSUB */
10970 static NeonGenTwoOpFn * const fns[3][2] = {
10971 { gen_helper_neon_hsub_s8, gen_helper_neon_hsub_u8 },
10972 { gen_helper_neon_hsub_s16, gen_helper_neon_hsub_u16 },
10973 { gen_helper_neon_hsub_s32, gen_helper_neon_hsub_u32 },
10975 genfn = fns[size][u];
10978 case 0x5: /* SQSUB, UQSUB */
10980 static NeonGenTwoOpEnvFn * const fns[3][2] = {
10981 { gen_helper_neon_qsub_s8, gen_helper_neon_qsub_u8 },
10982 { gen_helper_neon_qsub_s16, gen_helper_neon_qsub_u16 },
10983 { gen_helper_neon_qsub_s32, gen_helper_neon_qsub_u32 },
10985 genenvfn = fns[size][u];
10988 case 0x8: /* SSHL, USHL */
10990 static NeonGenTwoOpFn * const fns[3][2] = {
10991 { gen_helper_neon_shl_s8, gen_helper_neon_shl_u8 },
10992 { gen_helper_neon_shl_s16, gen_helper_neon_shl_u16 },
10993 { gen_helper_neon_shl_s32, gen_helper_neon_shl_u32 },
10995 genfn = fns[size][u];
10998 case 0x9: /* SQSHL, UQSHL */
11000 static NeonGenTwoOpEnvFn * const fns[3][2] = {
11001 { gen_helper_neon_qshl_s8, gen_helper_neon_qshl_u8 },
11002 { gen_helper_neon_qshl_s16, gen_helper_neon_qshl_u16 },
11003 { gen_helper_neon_qshl_s32, gen_helper_neon_qshl_u32 },
11005 genenvfn = fns[size][u];
11008 case 0xa: /* SRSHL, URSHL */
11010 static NeonGenTwoOpFn * const fns[3][2] = {
11011 { gen_helper_neon_rshl_s8, gen_helper_neon_rshl_u8 },
11012 { gen_helper_neon_rshl_s16, gen_helper_neon_rshl_u16 },
11013 { gen_helper_neon_rshl_s32, gen_helper_neon_rshl_u32 },
11015 genfn = fns[size][u];
11018 case 0xb: /* SQRSHL, UQRSHL */
11020 static NeonGenTwoOpEnvFn * const fns[3][2] = {
11021 { gen_helper_neon_qrshl_s8, gen_helper_neon_qrshl_u8 },
11022 { gen_helper_neon_qrshl_s16, gen_helper_neon_qrshl_u16 },
11023 { gen_helper_neon_qrshl_s32, gen_helper_neon_qrshl_u32 },
11025 genenvfn = fns[size][u];
11028 case 0xc: /* SMAX, UMAX */
11030 static NeonGenTwoOpFn * const fns[3][2] = {
11031 { gen_helper_neon_max_s8, gen_helper_neon_max_u8 },
11032 { gen_helper_neon_max_s16, gen_helper_neon_max_u16 },
11033 { tcg_gen_smax_i32, tcg_gen_umax_i32 },
11035 genfn = fns[size][u];
11039 case 0xd: /* SMIN, UMIN */
11041 static NeonGenTwoOpFn * const fns[3][2] = {
11042 { gen_helper_neon_min_s8, gen_helper_neon_min_u8 },
11043 { gen_helper_neon_min_s16, gen_helper_neon_min_u16 },
11044 { tcg_gen_smin_i32, tcg_gen_umin_i32 },
11046 genfn = fns[size][u];
11049 case 0xe: /* SABD, UABD */
11050 case 0xf: /* SABA, UABA */
11052 static NeonGenTwoOpFn * const fns[3][2] = {
11053 { gen_helper_neon_abd_s8, gen_helper_neon_abd_u8 },
11054 { gen_helper_neon_abd_s16, gen_helper_neon_abd_u16 },
11055 { gen_helper_neon_abd_s32, gen_helper_neon_abd_u32 },
11057 genfn = fns[size][u];
11060 case 0x13: /* MUL, PMUL */
11061 assert(u); /* PMUL */
11063 genfn = gen_helper_neon_mul_p8;
11065 case 0x16: /* SQDMULH, SQRDMULH */
11067 static NeonGenTwoOpEnvFn * const fns[2][2] = {
11068 { gen_helper_neon_qdmulh_s16, gen_helper_neon_qrdmulh_s16 },
11069 { gen_helper_neon_qdmulh_s32, gen_helper_neon_qrdmulh_s32 },
11071 assert(size == 1 || size == 2);
11072 genenvfn = fns[size - 1][u];
11076 g_assert_not_reached();
11080 genenvfn(tcg_res, cpu_env, tcg_op1, tcg_op2);
11082 genfn(tcg_res, tcg_op1, tcg_op2);
11085 if (opcode == 0xf) {
11086 /* SABA, UABA: accumulating ops */
11087 static NeonGenTwoOpFn * const fns[3] = {
11088 gen_helper_neon_add_u8,
11089 gen_helper_neon_add_u16,
11093 read_vec_element_i32(s, tcg_op1, rd, pass, MO_32);
11094 fns[size](tcg_res, tcg_op1, tcg_res);
11097 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
11099 tcg_temp_free_i32(tcg_res);
11100 tcg_temp_free_i32(tcg_op1);
11101 tcg_temp_free_i32(tcg_op2);
11104 clear_vec_high(s, is_q, rd);
11107 /* AdvSIMD three same
11108 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11109 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11110 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11111 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11113 static void disas_simd_three_reg_same(DisasContext *s, uint32_t insn)
11115 int opcode = extract32(insn, 11, 5);
11118 case 0x3: /* logic ops */
11119 disas_simd_3same_logic(s, insn);
11121 case 0x17: /* ADDP */
11122 case 0x14: /* SMAXP, UMAXP */
11123 case 0x15: /* SMINP, UMINP */
11125 /* Pairwise operations */
11126 int is_q = extract32(insn, 30, 1);
11127 int u = extract32(insn, 29, 1);
11128 int size = extract32(insn, 22, 2);
11129 int rm = extract32(insn, 16, 5);
11130 int rn = extract32(insn, 5, 5);
11131 int rd = extract32(insn, 0, 5);
11132 if (opcode == 0x17) {
11133 if (u || (size == 3 && !is_q)) {
11134 unallocated_encoding(s);
11139 unallocated_encoding(s);
11143 handle_simd_3same_pair(s, is_q, u, opcode, size, rn, rm, rd);
11146 case 0x18 ... 0x31:
11147 /* floating point ops, sz[1] and U are part of opcode */
11148 disas_simd_3same_float(s, insn);
11151 disas_simd_3same_int(s, insn);
11157 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11159 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11160 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11161 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11162 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11164 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11165 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11168 static void disas_simd_three_reg_same_fp16(DisasContext *s, uint32_t insn)
11170 int opcode, fpopcode;
11171 int is_q, u, a, rm, rn, rd;
11172 int datasize, elements;
11175 bool pairwise = false;
11177 if (!dc_isar_feature(aa64_fp16, s)) {
11178 unallocated_encoding(s);
11182 if (!fp_access_check(s)) {
11186 /* For these floating point ops, the U, a and opcode bits
11187 * together indicate the operation.
11189 opcode = extract32(insn, 11, 3);
11190 u = extract32(insn, 29, 1);
11191 a = extract32(insn, 23, 1);
11192 is_q = extract32(insn, 30, 1);
11193 rm = extract32(insn, 16, 5);
11194 rn = extract32(insn, 5, 5);
11195 rd = extract32(insn, 0, 5);
11197 fpopcode = opcode | (a << 3) | (u << 4);
11198 datasize = is_q ? 128 : 64;
11199 elements = datasize / 16;
11201 switch (fpopcode) {
11202 case 0x10: /* FMAXNMP */
11203 case 0x12: /* FADDP */
11204 case 0x16: /* FMAXP */
11205 case 0x18: /* FMINNMP */
11206 case 0x1e: /* FMINP */
11211 fpst = get_fpstatus_ptr(true);
11214 int maxpass = is_q ? 8 : 4;
11215 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
11216 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
11217 TCGv_i32 tcg_res[8];
11219 for (pass = 0; pass < maxpass; pass++) {
11220 int passreg = pass < (maxpass / 2) ? rn : rm;
11221 int passelt = (pass << 1) & (maxpass - 1);
11223 read_vec_element_i32(s, tcg_op1, passreg, passelt, MO_16);
11224 read_vec_element_i32(s, tcg_op2, passreg, passelt + 1, MO_16);
11225 tcg_res[pass] = tcg_temp_new_i32();
11227 switch (fpopcode) {
11228 case 0x10: /* FMAXNMP */
11229 gen_helper_advsimd_maxnumh(tcg_res[pass], tcg_op1, tcg_op2,
11232 case 0x12: /* FADDP */
11233 gen_helper_advsimd_addh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11235 case 0x16: /* FMAXP */
11236 gen_helper_advsimd_maxh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11238 case 0x18: /* FMINNMP */
11239 gen_helper_advsimd_minnumh(tcg_res[pass], tcg_op1, tcg_op2,
11242 case 0x1e: /* FMINP */
11243 gen_helper_advsimd_minh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11246 g_assert_not_reached();
11250 for (pass = 0; pass < maxpass; pass++) {
11251 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_16);
11252 tcg_temp_free_i32(tcg_res[pass]);
11255 tcg_temp_free_i32(tcg_op1);
11256 tcg_temp_free_i32(tcg_op2);
11259 for (pass = 0; pass < elements; pass++) {
11260 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
11261 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
11262 TCGv_i32 tcg_res = tcg_temp_new_i32();
11264 read_vec_element_i32(s, tcg_op1, rn, pass, MO_16);
11265 read_vec_element_i32(s, tcg_op2, rm, pass, MO_16);
11267 switch (fpopcode) {
11268 case 0x0: /* FMAXNM */
11269 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
11271 case 0x1: /* FMLA */
11272 read_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11273 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_res,
11276 case 0x2: /* FADD */
11277 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
11279 case 0x3: /* FMULX */
11280 gen_helper_advsimd_mulxh(tcg_res, tcg_op1, tcg_op2, fpst);
11282 case 0x4: /* FCMEQ */
11283 gen_helper_advsimd_ceq_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11285 case 0x6: /* FMAX */
11286 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
11288 case 0x7: /* FRECPS */
11289 gen_helper_recpsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11291 case 0x8: /* FMINNM */
11292 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
11294 case 0x9: /* FMLS */
11295 /* As usual for ARM, separate negation for fused multiply-add */
11296 tcg_gen_xori_i32(tcg_op1, tcg_op1, 0x8000);
11297 read_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11298 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_res,
11301 case 0xa: /* FSUB */
11302 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
11304 case 0xe: /* FMIN */
11305 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
11307 case 0xf: /* FRSQRTS */
11308 gen_helper_rsqrtsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11310 case 0x13: /* FMUL */
11311 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
11313 case 0x14: /* FCMGE */
11314 gen_helper_advsimd_cge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11316 case 0x15: /* FACGE */
11317 gen_helper_advsimd_acge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11319 case 0x17: /* FDIV */
11320 gen_helper_advsimd_divh(tcg_res, tcg_op1, tcg_op2, fpst);
11322 case 0x1a: /* FABD */
11323 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
11324 tcg_gen_andi_i32(tcg_res, tcg_res, 0x7fff);
11326 case 0x1c: /* FCMGT */
11327 gen_helper_advsimd_cgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11329 case 0x1d: /* FACGT */
11330 gen_helper_advsimd_acgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11333 fprintf(stderr, "%s: insn %#04x, fpop %#2x @ %#" PRIx64 "\n",
11334 __func__, insn, fpopcode, s->pc);
11335 g_assert_not_reached();
11338 write_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11339 tcg_temp_free_i32(tcg_res);
11340 tcg_temp_free_i32(tcg_op1);
11341 tcg_temp_free_i32(tcg_op2);
11345 tcg_temp_free_ptr(fpst);
11347 clear_vec_high(s, is_q, rd);
11350 /* AdvSIMD three same extra
11351 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
11352 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11353 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
11354 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11356 static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
11358 int rd = extract32(insn, 0, 5);
11359 int rn = extract32(insn, 5, 5);
11360 int opcode = extract32(insn, 11, 4);
11361 int rm = extract32(insn, 16, 5);
11362 int size = extract32(insn, 22, 2);
11363 bool u = extract32(insn, 29, 1);
11364 bool is_q = extract32(insn, 30, 1);
11368 switch (u * 16 + opcode) {
11369 case 0x10: /* SQRDMLAH (vector) */
11370 case 0x11: /* SQRDMLSH (vector) */
11371 if (size != 1 && size != 2) {
11372 unallocated_encoding(s);
11375 feature = dc_isar_feature(aa64_rdm, s);
11377 case 0x02: /* SDOT (vector) */
11378 case 0x12: /* UDOT (vector) */
11379 if (size != MO_32) {
11380 unallocated_encoding(s);
11383 feature = dc_isar_feature(aa64_dp, s);
11385 case 0x18: /* FCMLA, #0 */
11386 case 0x19: /* FCMLA, #90 */
11387 case 0x1a: /* FCMLA, #180 */
11388 case 0x1b: /* FCMLA, #270 */
11389 case 0x1c: /* FCADD, #90 */
11390 case 0x1e: /* FCADD, #270 */
11392 || (size == 1 && !dc_isar_feature(aa64_fp16, s))
11393 || (size == 3 && !is_q)) {
11394 unallocated_encoding(s);
11397 feature = dc_isar_feature(aa64_fcma, s);
11400 unallocated_encoding(s);
11404 unallocated_encoding(s);
11407 if (!fp_access_check(s)) {
11412 case 0x0: /* SQRDMLAH (vector) */
11415 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s16);
11418 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s32);
11421 g_assert_not_reached();
11425 case 0x1: /* SQRDMLSH (vector) */
11428 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s16);
11431 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s32);
11434 g_assert_not_reached();
11438 case 0x2: /* SDOT / UDOT */
11439 gen_gvec_op3_ool(s, is_q, rd, rn, rm, 0,
11440 u ? gen_helper_gvec_udot_b : gen_helper_gvec_sdot_b);
11443 case 0x8: /* FCMLA, #0 */
11444 case 0x9: /* FCMLA, #90 */
11445 case 0xa: /* FCMLA, #180 */
11446 case 0xb: /* FCMLA, #270 */
11447 rot = extract32(opcode, 0, 2);
11450 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, true, rot,
11451 gen_helper_gvec_fcmlah);
11454 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
11455 gen_helper_gvec_fcmlas);
11458 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
11459 gen_helper_gvec_fcmlad);
11462 g_assert_not_reached();
11466 case 0xc: /* FCADD, #90 */
11467 case 0xe: /* FCADD, #270 */
11468 rot = extract32(opcode, 1, 1);
11471 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11472 gen_helper_gvec_fcaddh);
11475 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11476 gen_helper_gvec_fcadds);
11479 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11480 gen_helper_gvec_fcaddd);
11483 g_assert_not_reached();
11488 g_assert_not_reached();
11492 static void handle_2misc_widening(DisasContext *s, int opcode, bool is_q,
11493 int size, int rn, int rd)
11495 /* Handle 2-reg-misc ops which are widening (so each size element
11496 * in the source becomes a 2*size element in the destination.
11497 * The only instruction like this is FCVTL.
11502 /* 32 -> 64 bit fp conversion */
11503 TCGv_i64 tcg_res[2];
11504 int srcelt = is_q ? 2 : 0;
11506 for (pass = 0; pass < 2; pass++) {
11507 TCGv_i32 tcg_op = tcg_temp_new_i32();
11508 tcg_res[pass] = tcg_temp_new_i64();
11510 read_vec_element_i32(s, tcg_op, rn, srcelt + pass, MO_32);
11511 gen_helper_vfp_fcvtds(tcg_res[pass], tcg_op, cpu_env);
11512 tcg_temp_free_i32(tcg_op);
11514 for (pass = 0; pass < 2; pass++) {
11515 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11516 tcg_temp_free_i64(tcg_res[pass]);
11519 /* 16 -> 32 bit fp conversion */
11520 int srcelt = is_q ? 4 : 0;
11521 TCGv_i32 tcg_res[4];
11522 TCGv_ptr fpst = get_fpstatus_ptr(false);
11523 TCGv_i32 ahp = get_ahp_flag();
11525 for (pass = 0; pass < 4; pass++) {
11526 tcg_res[pass] = tcg_temp_new_i32();
11528 read_vec_element_i32(s, tcg_res[pass], rn, srcelt + pass, MO_16);
11529 gen_helper_vfp_fcvt_f16_to_f32(tcg_res[pass], tcg_res[pass],
11532 for (pass = 0; pass < 4; pass++) {
11533 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32);
11534 tcg_temp_free_i32(tcg_res[pass]);
11537 tcg_temp_free_ptr(fpst);
11538 tcg_temp_free_i32(ahp);
11542 static void handle_rev(DisasContext *s, int opcode, bool u,
11543 bool is_q, int size, int rn, int rd)
11545 int op = (opcode << 1) | u;
11546 int opsz = op + size;
11547 int grp_size = 3 - opsz;
11548 int dsize = is_q ? 128 : 64;
11552 unallocated_encoding(s);
11556 if (!fp_access_check(s)) {
11561 /* Special case bytes, use bswap op on each group of elements */
11562 int groups = dsize / (8 << grp_size);
11564 for (i = 0; i < groups; i++) {
11565 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
11567 read_vec_element(s, tcg_tmp, rn, i, grp_size);
11568 switch (grp_size) {
11570 tcg_gen_bswap16_i64(tcg_tmp, tcg_tmp);
11573 tcg_gen_bswap32_i64(tcg_tmp, tcg_tmp);
11576 tcg_gen_bswap64_i64(tcg_tmp, tcg_tmp);
11579 g_assert_not_reached();
11581 write_vec_element(s, tcg_tmp, rd, i, grp_size);
11582 tcg_temp_free_i64(tcg_tmp);
11584 clear_vec_high(s, is_q, rd);
11586 int revmask = (1 << grp_size) - 1;
11587 int esize = 8 << size;
11588 int elements = dsize / esize;
11589 TCGv_i64 tcg_rn = tcg_temp_new_i64();
11590 TCGv_i64 tcg_rd = tcg_const_i64(0);
11591 TCGv_i64 tcg_rd_hi = tcg_const_i64(0);
11593 for (i = 0; i < elements; i++) {
11594 int e_rev = (i & 0xf) ^ revmask;
11595 int off = e_rev * esize;
11596 read_vec_element(s, tcg_rn, rn, i, size);
11598 tcg_gen_deposit_i64(tcg_rd_hi, tcg_rd_hi,
11599 tcg_rn, off - 64, esize);
11601 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, off, esize);
11604 write_vec_element(s, tcg_rd, rd, 0, MO_64);
11605 write_vec_element(s, tcg_rd_hi, rd, 1, MO_64);
11607 tcg_temp_free_i64(tcg_rd_hi);
11608 tcg_temp_free_i64(tcg_rd);
11609 tcg_temp_free_i64(tcg_rn);
11613 static void handle_2misc_pairwise(DisasContext *s, int opcode, bool u,
11614 bool is_q, int size, int rn, int rd)
11616 /* Implement the pairwise operations from 2-misc:
11617 * SADDLP, UADDLP, SADALP, UADALP.
11618 * These all add pairs of elements in the input to produce a
11619 * double-width result element in the output (possibly accumulating).
11621 bool accum = (opcode == 0x6);
11622 int maxpass = is_q ? 2 : 1;
11624 TCGv_i64 tcg_res[2];
11627 /* 32 + 32 -> 64 op */
11628 TCGMemOp memop = size + (u ? 0 : MO_SIGN);
11630 for (pass = 0; pass < maxpass; pass++) {
11631 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
11632 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
11634 tcg_res[pass] = tcg_temp_new_i64();
11636 read_vec_element(s, tcg_op1, rn, pass * 2, memop);
11637 read_vec_element(s, tcg_op2, rn, pass * 2 + 1, memop);
11638 tcg_gen_add_i64(tcg_res[pass], tcg_op1, tcg_op2);
11640 read_vec_element(s, tcg_op1, rd, pass, MO_64);
11641 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
11644 tcg_temp_free_i64(tcg_op1);
11645 tcg_temp_free_i64(tcg_op2);
11648 for (pass = 0; pass < maxpass; pass++) {
11649 TCGv_i64 tcg_op = tcg_temp_new_i64();
11650 NeonGenOneOpFn *genfn;
11651 static NeonGenOneOpFn * const fns[2][2] = {
11652 { gen_helper_neon_addlp_s8, gen_helper_neon_addlp_u8 },
11653 { gen_helper_neon_addlp_s16, gen_helper_neon_addlp_u16 },
11656 genfn = fns[size][u];
11658 tcg_res[pass] = tcg_temp_new_i64();
11660 read_vec_element(s, tcg_op, rn, pass, MO_64);
11661 genfn(tcg_res[pass], tcg_op);
11664 read_vec_element(s, tcg_op, rd, pass, MO_64);
11666 gen_helper_neon_addl_u16(tcg_res[pass],
11667 tcg_res[pass], tcg_op);
11669 gen_helper_neon_addl_u32(tcg_res[pass],
11670 tcg_res[pass], tcg_op);
11673 tcg_temp_free_i64(tcg_op);
11677 tcg_res[1] = tcg_const_i64(0);
11679 for (pass = 0; pass < 2; pass++) {
11680 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11681 tcg_temp_free_i64(tcg_res[pass]);
11685 static void handle_shll(DisasContext *s, bool is_q, int size, int rn, int rd)
11687 /* Implement SHLL and SHLL2 */
11689 int part = is_q ? 2 : 0;
11690 TCGv_i64 tcg_res[2];
11692 for (pass = 0; pass < 2; pass++) {
11693 static NeonGenWidenFn * const widenfns[3] = {
11694 gen_helper_neon_widen_u8,
11695 gen_helper_neon_widen_u16,
11696 tcg_gen_extu_i32_i64,
11698 NeonGenWidenFn *widenfn = widenfns[size];
11699 TCGv_i32 tcg_op = tcg_temp_new_i32();
11701 read_vec_element_i32(s, tcg_op, rn, part + pass, MO_32);
11702 tcg_res[pass] = tcg_temp_new_i64();
11703 widenfn(tcg_res[pass], tcg_op);
11704 tcg_gen_shli_i64(tcg_res[pass], tcg_res[pass], 8 << size);
11706 tcg_temp_free_i32(tcg_op);
11709 for (pass = 0; pass < 2; pass++) {
11710 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11711 tcg_temp_free_i64(tcg_res[pass]);
11715 /* AdvSIMD two reg misc
11716 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
11717 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11718 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
11719 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11721 static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)
11723 int size = extract32(insn, 22, 2);
11724 int opcode = extract32(insn, 12, 5);
11725 bool u = extract32(insn, 29, 1);
11726 bool is_q = extract32(insn, 30, 1);
11727 int rn = extract32(insn, 5, 5);
11728 int rd = extract32(insn, 0, 5);
11729 bool need_fpstatus = false;
11730 bool need_rmode = false;
11732 TCGv_i32 tcg_rmode;
11733 TCGv_ptr tcg_fpstatus;
11736 case 0x0: /* REV64, REV32 */
11737 case 0x1: /* REV16 */
11738 handle_rev(s, opcode, u, is_q, size, rn, rd);
11740 case 0x5: /* CNT, NOT, RBIT */
11741 if (u && size == 0) {
11744 } else if (u && size == 1) {
11747 } else if (!u && size == 0) {
11751 unallocated_encoding(s);
11753 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
11754 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
11756 unallocated_encoding(s);
11759 if (!fp_access_check(s)) {
11763 handle_2misc_narrow(s, false, opcode, u, is_q, size, rn, rd);
11765 case 0x4: /* CLS, CLZ */
11767 unallocated_encoding(s);
11771 case 0x2: /* SADDLP, UADDLP */
11772 case 0x6: /* SADALP, UADALP */
11774 unallocated_encoding(s);
11777 if (!fp_access_check(s)) {
11780 handle_2misc_pairwise(s, opcode, u, is_q, size, rn, rd);
11782 case 0x13: /* SHLL, SHLL2 */
11783 if (u == 0 || size == 3) {
11784 unallocated_encoding(s);
11787 if (!fp_access_check(s)) {
11790 handle_shll(s, is_q, size, rn, rd);
11792 case 0xa: /* CMLT */
11794 unallocated_encoding(s);
11798 case 0x8: /* CMGT, CMGE */
11799 case 0x9: /* CMEQ, CMLE */
11800 case 0xb: /* ABS, NEG */
11801 if (size == 3 && !is_q) {
11802 unallocated_encoding(s);
11806 case 0x3: /* SUQADD, USQADD */
11807 if (size == 3 && !is_q) {
11808 unallocated_encoding(s);
11811 if (!fp_access_check(s)) {
11814 handle_2misc_satacc(s, false, u, is_q, size, rn, rd);
11816 case 0x7: /* SQABS, SQNEG */
11817 if (size == 3 && !is_q) {
11818 unallocated_encoding(s);
11823 case 0x16 ... 0x1d:
11826 /* Floating point: U, size[1] and opcode indicate operation;
11827 * size[0] indicates single or double precision.
11829 int is_double = extract32(size, 0, 1);
11830 opcode |= (extract32(size, 1, 1) << 5) | (u << 6);
11831 size = is_double ? 3 : 2;
11833 case 0x2f: /* FABS */
11834 case 0x6f: /* FNEG */
11835 if (size == 3 && !is_q) {
11836 unallocated_encoding(s);
11840 case 0x1d: /* SCVTF */
11841 case 0x5d: /* UCVTF */
11843 bool is_signed = (opcode == 0x1d) ? true : false;
11844 int elements = is_double ? 2 : is_q ? 4 : 2;
11845 if (is_double && !is_q) {
11846 unallocated_encoding(s);
11849 if (!fp_access_check(s)) {
11852 handle_simd_intfp_conv(s, rd, rn, elements, is_signed, 0, size);
11855 case 0x2c: /* FCMGT (zero) */
11856 case 0x2d: /* FCMEQ (zero) */
11857 case 0x2e: /* FCMLT (zero) */
11858 case 0x6c: /* FCMGE (zero) */
11859 case 0x6d: /* FCMLE (zero) */
11860 if (size == 3 && !is_q) {
11861 unallocated_encoding(s);
11864 handle_2misc_fcmp_zero(s, opcode, false, u, is_q, size, rn, rd);
11866 case 0x7f: /* FSQRT */
11867 if (size == 3 && !is_q) {
11868 unallocated_encoding(s);
11872 case 0x1a: /* FCVTNS */
11873 case 0x1b: /* FCVTMS */
11874 case 0x3a: /* FCVTPS */
11875 case 0x3b: /* FCVTZS */
11876 case 0x5a: /* FCVTNU */
11877 case 0x5b: /* FCVTMU */
11878 case 0x7a: /* FCVTPU */
11879 case 0x7b: /* FCVTZU */
11880 need_fpstatus = true;
11882 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
11883 if (size == 3 && !is_q) {
11884 unallocated_encoding(s);
11888 case 0x5c: /* FCVTAU */
11889 case 0x1c: /* FCVTAS */
11890 need_fpstatus = true;
11892 rmode = FPROUNDING_TIEAWAY;
11893 if (size == 3 && !is_q) {
11894 unallocated_encoding(s);
11898 case 0x3c: /* URECPE */
11900 unallocated_encoding(s);
11904 case 0x3d: /* FRECPE */
11905 case 0x7d: /* FRSQRTE */
11906 if (size == 3 && !is_q) {
11907 unallocated_encoding(s);
11910 if (!fp_access_check(s)) {
11913 handle_2misc_reciprocal(s, opcode, false, u, is_q, size, rn, rd);
11915 case 0x56: /* FCVTXN, FCVTXN2 */
11917 unallocated_encoding(s);
11921 case 0x16: /* FCVTN, FCVTN2 */
11922 /* handle_2misc_narrow does a 2*size -> size operation, but these
11923 * instructions encode the source size rather than dest size.
11925 if (!fp_access_check(s)) {
11928 handle_2misc_narrow(s, false, opcode, 0, is_q, size - 1, rn, rd);
11930 case 0x17: /* FCVTL, FCVTL2 */
11931 if (!fp_access_check(s)) {
11934 handle_2misc_widening(s, opcode, is_q, size, rn, rd);
11936 case 0x18: /* FRINTN */
11937 case 0x19: /* FRINTM */
11938 case 0x38: /* FRINTP */
11939 case 0x39: /* FRINTZ */
11941 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
11943 case 0x59: /* FRINTX */
11944 case 0x79: /* FRINTI */
11945 need_fpstatus = true;
11946 if (size == 3 && !is_q) {
11947 unallocated_encoding(s);
11951 case 0x58: /* FRINTA */
11953 rmode = FPROUNDING_TIEAWAY;
11954 need_fpstatus = true;
11955 if (size == 3 && !is_q) {
11956 unallocated_encoding(s);
11960 case 0x7c: /* URSQRTE */
11962 unallocated_encoding(s);
11965 need_fpstatus = true;
11968 unallocated_encoding(s);
11974 unallocated_encoding(s);
11978 if (!fp_access_check(s)) {
11982 if (need_fpstatus || need_rmode) {
11983 tcg_fpstatus = get_fpstatus_ptr(false);
11985 tcg_fpstatus = NULL;
11988 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
11989 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
11996 if (u && size == 0) { /* NOT */
11997 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_not, 0);
12003 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_neg, size);
12010 /* All 64-bit element operations can be shared with scalar 2misc */
12013 /* Coverity claims (size == 3 && !is_q) has been eliminated
12014 * from all paths leading to here.
12016 tcg_debug_assert(is_q);
12017 for (pass = 0; pass < 2; pass++) {
12018 TCGv_i64 tcg_op = tcg_temp_new_i64();
12019 TCGv_i64 tcg_res = tcg_temp_new_i64();
12021 read_vec_element(s, tcg_op, rn, pass, MO_64);
12023 handle_2misc_64(s, opcode, u, tcg_res, tcg_op,
12024 tcg_rmode, tcg_fpstatus);
12026 write_vec_element(s, tcg_res, rd, pass, MO_64);
12028 tcg_temp_free_i64(tcg_res);
12029 tcg_temp_free_i64(tcg_op);
12034 for (pass = 0; pass < (is_q ? 4 : 2); pass++) {
12035 TCGv_i32 tcg_op = tcg_temp_new_i32();
12036 TCGv_i32 tcg_res = tcg_temp_new_i32();
12039 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
12042 /* Special cases for 32 bit elements */
12044 case 0xa: /* CMLT */
12045 /* 32 bit integer comparison against zero, result is
12046 * test ? (2^32 - 1) : 0. We implement via setcond(test)
12049 cond = TCG_COND_LT;
12051 tcg_gen_setcondi_i32(cond, tcg_res, tcg_op, 0);
12052 tcg_gen_neg_i32(tcg_res, tcg_res);
12054 case 0x8: /* CMGT, CMGE */
12055 cond = u ? TCG_COND_GE : TCG_COND_GT;
12057 case 0x9: /* CMEQ, CMLE */
12058 cond = u ? TCG_COND_LE : TCG_COND_EQ;
12060 case 0x4: /* CLS */
12062 tcg_gen_clzi_i32(tcg_res, tcg_op, 32);
12064 tcg_gen_clrsb_i32(tcg_res, tcg_op);
12067 case 0x7: /* SQABS, SQNEG */
12069 gen_helper_neon_qneg_s32(tcg_res, cpu_env, tcg_op);
12071 gen_helper_neon_qabs_s32(tcg_res, cpu_env, tcg_op);
12074 case 0xb: /* ABS, NEG */
12076 tcg_gen_neg_i32(tcg_res, tcg_op);
12078 TCGv_i32 tcg_zero = tcg_const_i32(0);
12079 tcg_gen_neg_i32(tcg_res, tcg_op);
12080 tcg_gen_movcond_i32(TCG_COND_GT, tcg_res, tcg_op,
12081 tcg_zero, tcg_op, tcg_res);
12082 tcg_temp_free_i32(tcg_zero);
12085 case 0x2f: /* FABS */
12086 gen_helper_vfp_abss(tcg_res, tcg_op);
12088 case 0x6f: /* FNEG */
12089 gen_helper_vfp_negs(tcg_res, tcg_op);
12091 case 0x7f: /* FSQRT */
12092 gen_helper_vfp_sqrts(tcg_res, tcg_op, cpu_env);
12094 case 0x1a: /* FCVTNS */
12095 case 0x1b: /* FCVTMS */
12096 case 0x1c: /* FCVTAS */
12097 case 0x3a: /* FCVTPS */
12098 case 0x3b: /* FCVTZS */
12100 TCGv_i32 tcg_shift = tcg_const_i32(0);
12101 gen_helper_vfp_tosls(tcg_res, tcg_op,
12102 tcg_shift, tcg_fpstatus);
12103 tcg_temp_free_i32(tcg_shift);
12106 case 0x5a: /* FCVTNU */
12107 case 0x5b: /* FCVTMU */
12108 case 0x5c: /* FCVTAU */
12109 case 0x7a: /* FCVTPU */
12110 case 0x7b: /* FCVTZU */
12112 TCGv_i32 tcg_shift = tcg_const_i32(0);
12113 gen_helper_vfp_touls(tcg_res, tcg_op,
12114 tcg_shift, tcg_fpstatus);
12115 tcg_temp_free_i32(tcg_shift);
12118 case 0x18: /* FRINTN */
12119 case 0x19: /* FRINTM */
12120 case 0x38: /* FRINTP */
12121 case 0x39: /* FRINTZ */
12122 case 0x58: /* FRINTA */
12123 case 0x79: /* FRINTI */
12124 gen_helper_rints(tcg_res, tcg_op, tcg_fpstatus);
12126 case 0x59: /* FRINTX */
12127 gen_helper_rints_exact(tcg_res, tcg_op, tcg_fpstatus);
12129 case 0x7c: /* URSQRTE */
12130 gen_helper_rsqrte_u32(tcg_res, tcg_op, tcg_fpstatus);
12133 g_assert_not_reached();
12136 /* Use helpers for 8 and 16 bit elements */
12138 case 0x5: /* CNT, RBIT */
12139 /* For these two insns size is part of the opcode specifier
12140 * (handled earlier); they always operate on byte elements.
12143 gen_helper_neon_rbit_u8(tcg_res, tcg_op);
12145 gen_helper_neon_cnt_u8(tcg_res, tcg_op);
12148 case 0x7: /* SQABS, SQNEG */
12150 NeonGenOneOpEnvFn *genfn;
12151 static NeonGenOneOpEnvFn * const fns[2][2] = {
12152 { gen_helper_neon_qabs_s8, gen_helper_neon_qneg_s8 },
12153 { gen_helper_neon_qabs_s16, gen_helper_neon_qneg_s16 },
12155 genfn = fns[size][u];
12156 genfn(tcg_res, cpu_env, tcg_op);
12159 case 0x8: /* CMGT, CMGE */
12160 case 0x9: /* CMEQ, CMLE */
12161 case 0xa: /* CMLT */
12163 static NeonGenTwoOpFn * const fns[3][2] = {
12164 { gen_helper_neon_cgt_s8, gen_helper_neon_cgt_s16 },
12165 { gen_helper_neon_cge_s8, gen_helper_neon_cge_s16 },
12166 { gen_helper_neon_ceq_u8, gen_helper_neon_ceq_u16 },
12168 NeonGenTwoOpFn *genfn;
12171 TCGv_i32 tcg_zero = tcg_const_i32(0);
12173 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
12174 comp = (opcode - 0x8) * 2 + u;
12175 /* ...but LE, LT are implemented as reverse GE, GT */
12176 reverse = (comp > 2);
12180 genfn = fns[comp][size];
12182 genfn(tcg_res, tcg_zero, tcg_op);
12184 genfn(tcg_res, tcg_op, tcg_zero);
12186 tcg_temp_free_i32(tcg_zero);
12189 case 0xb: /* ABS, NEG */
12191 TCGv_i32 tcg_zero = tcg_const_i32(0);
12193 gen_helper_neon_sub_u16(tcg_res, tcg_zero, tcg_op);
12195 gen_helper_neon_sub_u8(tcg_res, tcg_zero, tcg_op);
12197 tcg_temp_free_i32(tcg_zero);
12200 gen_helper_neon_abs_s16(tcg_res, tcg_op);
12202 gen_helper_neon_abs_s8(tcg_res, tcg_op);
12206 case 0x4: /* CLS, CLZ */
12209 gen_helper_neon_clz_u8(tcg_res, tcg_op);
12211 gen_helper_neon_clz_u16(tcg_res, tcg_op);
12215 gen_helper_neon_cls_s8(tcg_res, tcg_op);
12217 gen_helper_neon_cls_s16(tcg_res, tcg_op);
12222 g_assert_not_reached();
12226 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
12228 tcg_temp_free_i32(tcg_res);
12229 tcg_temp_free_i32(tcg_op);
12232 clear_vec_high(s, is_q, rd);
12235 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12236 tcg_temp_free_i32(tcg_rmode);
12238 if (need_fpstatus) {
12239 tcg_temp_free_ptr(tcg_fpstatus);
12243 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12245 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12246 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12247 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12248 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12249 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12250 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12252 * This actually covers two groups where scalar access is governed by
12253 * bit 28. A bunch of the instructions (float to integral) only exist
12254 * in the vector form and are un-allocated for the scalar decode. Also
12255 * in the scalar decode Q is always 1.
12257 static void disas_simd_two_reg_misc_fp16(DisasContext *s, uint32_t insn)
12259 int fpop, opcode, a, u;
12263 bool only_in_vector = false;
12266 TCGv_i32 tcg_rmode = NULL;
12267 TCGv_ptr tcg_fpstatus = NULL;
12268 bool need_rmode = false;
12269 bool need_fpst = true;
12272 if (!dc_isar_feature(aa64_fp16, s)) {
12273 unallocated_encoding(s);
12277 rd = extract32(insn, 0, 5);
12278 rn = extract32(insn, 5, 5);
12280 a = extract32(insn, 23, 1);
12281 u = extract32(insn, 29, 1);
12282 is_scalar = extract32(insn, 28, 1);
12283 is_q = extract32(insn, 30, 1);
12285 opcode = extract32(insn, 12, 5);
12286 fpop = deposit32(opcode, 5, 1, a);
12287 fpop = deposit32(fpop, 6, 1, u);
12289 rd = extract32(insn, 0, 5);
12290 rn = extract32(insn, 5, 5);
12293 case 0x1d: /* SCVTF */
12294 case 0x5d: /* UCVTF */
12301 elements = (is_q ? 8 : 4);
12304 if (!fp_access_check(s)) {
12307 handle_simd_intfp_conv(s, rd, rn, elements, !u, 0, MO_16);
12311 case 0x2c: /* FCMGT (zero) */
12312 case 0x2d: /* FCMEQ (zero) */
12313 case 0x2e: /* FCMLT (zero) */
12314 case 0x6c: /* FCMGE (zero) */
12315 case 0x6d: /* FCMLE (zero) */
12316 handle_2misc_fcmp_zero(s, fpop, is_scalar, 0, is_q, MO_16, rn, rd);
12318 case 0x3d: /* FRECPE */
12319 case 0x3f: /* FRECPX */
12321 case 0x18: /* FRINTN */
12323 only_in_vector = true;
12324 rmode = FPROUNDING_TIEEVEN;
12326 case 0x19: /* FRINTM */
12328 only_in_vector = true;
12329 rmode = FPROUNDING_NEGINF;
12331 case 0x38: /* FRINTP */
12333 only_in_vector = true;
12334 rmode = FPROUNDING_POSINF;
12336 case 0x39: /* FRINTZ */
12338 only_in_vector = true;
12339 rmode = FPROUNDING_ZERO;
12341 case 0x58: /* FRINTA */
12343 only_in_vector = true;
12344 rmode = FPROUNDING_TIEAWAY;
12346 case 0x59: /* FRINTX */
12347 case 0x79: /* FRINTI */
12348 only_in_vector = true;
12349 /* current rounding mode */
12351 case 0x1a: /* FCVTNS */
12353 rmode = FPROUNDING_TIEEVEN;
12355 case 0x1b: /* FCVTMS */
12357 rmode = FPROUNDING_NEGINF;
12359 case 0x1c: /* FCVTAS */
12361 rmode = FPROUNDING_TIEAWAY;
12363 case 0x3a: /* FCVTPS */
12365 rmode = FPROUNDING_POSINF;
12367 case 0x3b: /* FCVTZS */
12369 rmode = FPROUNDING_ZERO;
12371 case 0x5a: /* FCVTNU */
12373 rmode = FPROUNDING_TIEEVEN;
12375 case 0x5b: /* FCVTMU */
12377 rmode = FPROUNDING_NEGINF;
12379 case 0x5c: /* FCVTAU */
12381 rmode = FPROUNDING_TIEAWAY;
12383 case 0x7a: /* FCVTPU */
12385 rmode = FPROUNDING_POSINF;
12387 case 0x7b: /* FCVTZU */
12389 rmode = FPROUNDING_ZERO;
12391 case 0x2f: /* FABS */
12392 case 0x6f: /* FNEG */
12395 case 0x7d: /* FRSQRTE */
12396 case 0x7f: /* FSQRT (vector) */
12399 fprintf(stderr, "%s: insn %#04x fpop %#2x\n", __func__, insn, fpop);
12400 g_assert_not_reached();
12404 /* Check additional constraints for the scalar encoding */
12407 unallocated_encoding(s);
12410 /* FRINTxx is only in the vector form */
12411 if (only_in_vector) {
12412 unallocated_encoding(s);
12417 if (!fp_access_check(s)) {
12421 if (need_rmode || need_fpst) {
12422 tcg_fpstatus = get_fpstatus_ptr(true);
12426 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
12427 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12431 TCGv_i32 tcg_op = read_fp_hreg(s, rn);
12432 TCGv_i32 tcg_res = tcg_temp_new_i32();
12435 case 0x1a: /* FCVTNS */
12436 case 0x1b: /* FCVTMS */
12437 case 0x1c: /* FCVTAS */
12438 case 0x3a: /* FCVTPS */
12439 case 0x3b: /* FCVTZS */
12440 gen_helper_advsimd_f16tosinth(tcg_res, tcg_op, tcg_fpstatus);
12442 case 0x3d: /* FRECPE */
12443 gen_helper_recpe_f16(tcg_res, tcg_op, tcg_fpstatus);
12445 case 0x3f: /* FRECPX */
12446 gen_helper_frecpx_f16(tcg_res, tcg_op, tcg_fpstatus);
12448 case 0x5a: /* FCVTNU */
12449 case 0x5b: /* FCVTMU */
12450 case 0x5c: /* FCVTAU */
12451 case 0x7a: /* FCVTPU */
12452 case 0x7b: /* FCVTZU */
12453 gen_helper_advsimd_f16touinth(tcg_res, tcg_op, tcg_fpstatus);
12455 case 0x6f: /* FNEG */
12456 tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000);
12458 case 0x7d: /* FRSQRTE */
12459 gen_helper_rsqrte_f16(tcg_res, tcg_op, tcg_fpstatus);
12462 g_assert_not_reached();
12465 /* limit any sign extension going on */
12466 tcg_gen_andi_i32(tcg_res, tcg_res, 0xffff);
12467 write_fp_sreg(s, rd, tcg_res);
12469 tcg_temp_free_i32(tcg_res);
12470 tcg_temp_free_i32(tcg_op);
12472 for (pass = 0; pass < (is_q ? 8 : 4); pass++) {
12473 TCGv_i32 tcg_op = tcg_temp_new_i32();
12474 TCGv_i32 tcg_res = tcg_temp_new_i32();
12476 read_vec_element_i32(s, tcg_op, rn, pass, MO_16);
12479 case 0x1a: /* FCVTNS */
12480 case 0x1b: /* FCVTMS */
12481 case 0x1c: /* FCVTAS */
12482 case 0x3a: /* FCVTPS */
12483 case 0x3b: /* FCVTZS */
12484 gen_helper_advsimd_f16tosinth(tcg_res, tcg_op, tcg_fpstatus);
12486 case 0x3d: /* FRECPE */
12487 gen_helper_recpe_f16(tcg_res, tcg_op, tcg_fpstatus);
12489 case 0x5a: /* FCVTNU */
12490 case 0x5b: /* FCVTMU */
12491 case 0x5c: /* FCVTAU */
12492 case 0x7a: /* FCVTPU */
12493 case 0x7b: /* FCVTZU */
12494 gen_helper_advsimd_f16touinth(tcg_res, tcg_op, tcg_fpstatus);
12496 case 0x18: /* FRINTN */
12497 case 0x19: /* FRINTM */
12498 case 0x38: /* FRINTP */
12499 case 0x39: /* FRINTZ */
12500 case 0x58: /* FRINTA */
12501 case 0x79: /* FRINTI */
12502 gen_helper_advsimd_rinth(tcg_res, tcg_op, tcg_fpstatus);
12504 case 0x59: /* FRINTX */
12505 gen_helper_advsimd_rinth_exact(tcg_res, tcg_op, tcg_fpstatus);
12507 case 0x2f: /* FABS */
12508 tcg_gen_andi_i32(tcg_res, tcg_op, 0x7fff);
12510 case 0x6f: /* FNEG */
12511 tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000);
12513 case 0x7d: /* FRSQRTE */
12514 gen_helper_rsqrte_f16(tcg_res, tcg_op, tcg_fpstatus);
12516 case 0x7f: /* FSQRT */
12517 gen_helper_sqrt_f16(tcg_res, tcg_op, tcg_fpstatus);
12520 g_assert_not_reached();
12523 write_vec_element_i32(s, tcg_res, rd, pass, MO_16);
12525 tcg_temp_free_i32(tcg_res);
12526 tcg_temp_free_i32(tcg_op);
12529 clear_vec_high(s, is_q, rd);
12533 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12534 tcg_temp_free_i32(tcg_rmode);
12537 if (tcg_fpstatus) {
12538 tcg_temp_free_ptr(tcg_fpstatus);
12542 /* AdvSIMD scalar x indexed element
12543 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12544 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12545 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12546 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12547 * AdvSIMD vector x indexed element
12548 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12549 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12550 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12551 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12553 static void disas_simd_indexed(DisasContext *s, uint32_t insn)
12555 /* This encoding has two kinds of instruction:
12556 * normal, where we perform elt x idxelt => elt for each
12557 * element in the vector
12558 * long, where we perform elt x idxelt and generate a result of
12559 * double the width of the input element
12560 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
12562 bool is_scalar = extract32(insn, 28, 1);
12563 bool is_q = extract32(insn, 30, 1);
12564 bool u = extract32(insn, 29, 1);
12565 int size = extract32(insn, 22, 2);
12566 int l = extract32(insn, 21, 1);
12567 int m = extract32(insn, 20, 1);
12568 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
12569 int rm = extract32(insn, 16, 4);
12570 int opcode = extract32(insn, 12, 4);
12571 int h = extract32(insn, 11, 1);
12572 int rn = extract32(insn, 5, 5);
12573 int rd = extract32(insn, 0, 5);
12574 bool is_long = false;
12576 bool is_fp16 = false;
12580 switch (16 * u + opcode) {
12581 case 0x08: /* MUL */
12582 case 0x10: /* MLA */
12583 case 0x14: /* MLS */
12585 unallocated_encoding(s);
12589 case 0x02: /* SMLAL, SMLAL2 */
12590 case 0x12: /* UMLAL, UMLAL2 */
12591 case 0x06: /* SMLSL, SMLSL2 */
12592 case 0x16: /* UMLSL, UMLSL2 */
12593 case 0x0a: /* SMULL, SMULL2 */
12594 case 0x1a: /* UMULL, UMULL2 */
12596 unallocated_encoding(s);
12601 case 0x03: /* SQDMLAL, SQDMLAL2 */
12602 case 0x07: /* SQDMLSL, SQDMLSL2 */
12603 case 0x0b: /* SQDMULL, SQDMULL2 */
12606 case 0x0c: /* SQDMULH */
12607 case 0x0d: /* SQRDMULH */
12609 case 0x01: /* FMLA */
12610 case 0x05: /* FMLS */
12611 case 0x09: /* FMUL */
12612 case 0x19: /* FMULX */
12615 case 0x1d: /* SQRDMLAH */
12616 case 0x1f: /* SQRDMLSH */
12617 if (!dc_isar_feature(aa64_rdm, s)) {
12618 unallocated_encoding(s);
12622 case 0x0e: /* SDOT */
12623 case 0x1e: /* UDOT */
12624 if (size != MO_32 || !dc_isar_feature(aa64_dp, s)) {
12625 unallocated_encoding(s);
12629 case 0x11: /* FCMLA #0 */
12630 case 0x13: /* FCMLA #90 */
12631 case 0x15: /* FCMLA #180 */
12632 case 0x17: /* FCMLA #270 */
12633 if (!dc_isar_feature(aa64_fcma, s)) {
12634 unallocated_encoding(s);
12640 unallocated_encoding(s);
12645 case 1: /* normal fp */
12646 /* convert insn encoded size to TCGMemOp size */
12648 case 0: /* half-precision */
12652 case MO_32: /* single precision */
12653 case MO_64: /* double precision */
12656 unallocated_encoding(s);
12661 case 2: /* complex fp */
12662 /* Each indexable element is a complex pair. */
12667 unallocated_encoding(s);
12675 unallocated_encoding(s);
12680 default: /* integer */
12684 unallocated_encoding(s);
12689 if (is_fp16 && !dc_isar_feature(aa64_fp16, s)) {
12690 unallocated_encoding(s);
12694 /* Given TCGMemOp size, adjust register and indexing. */
12697 index = h << 2 | l << 1 | m;
12700 index = h << 1 | l;
12705 unallocated_encoding(s);
12712 g_assert_not_reached();
12715 if (!fp_access_check(s)) {
12720 fpst = get_fpstatus_ptr(is_fp16);
12725 switch (16 * u + opcode) {
12726 case 0x0e: /* SDOT */
12727 case 0x1e: /* UDOT */
12728 gen_gvec_op3_ool(s, is_q, rd, rn, rm, index,
12729 u ? gen_helper_gvec_udot_idx_b
12730 : gen_helper_gvec_sdot_idx_b);
12732 case 0x11: /* FCMLA #0 */
12733 case 0x13: /* FCMLA #90 */
12734 case 0x15: /* FCMLA #180 */
12735 case 0x17: /* FCMLA #270 */
12737 int rot = extract32(insn, 13, 2);
12738 int data = (index << 2) | rot;
12739 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
12740 vec_full_reg_offset(s, rn),
12741 vec_full_reg_offset(s, rm), fpst,
12742 is_q ? 16 : 8, vec_full_reg_size(s), data,
12744 ? gen_helper_gvec_fcmlas_idx
12745 : gen_helper_gvec_fcmlah_idx);
12746 tcg_temp_free_ptr(fpst);
12752 TCGv_i64 tcg_idx = tcg_temp_new_i64();
12755 assert(is_fp && is_q && !is_long);
12757 read_vec_element(s, tcg_idx, rm, index, MO_64);
12759 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
12760 TCGv_i64 tcg_op = tcg_temp_new_i64();
12761 TCGv_i64 tcg_res = tcg_temp_new_i64();
12763 read_vec_element(s, tcg_op, rn, pass, MO_64);
12765 switch (16 * u + opcode) {
12766 case 0x05: /* FMLS */
12767 /* As usual for ARM, separate negation for fused multiply-add */
12768 gen_helper_vfp_negd(tcg_op, tcg_op);
12770 case 0x01: /* FMLA */
12771 read_vec_element(s, tcg_res, rd, pass, MO_64);
12772 gen_helper_vfp_muladdd(tcg_res, tcg_op, tcg_idx, tcg_res, fpst);
12774 case 0x09: /* FMUL */
12775 gen_helper_vfp_muld(tcg_res, tcg_op, tcg_idx, fpst);
12777 case 0x19: /* FMULX */
12778 gen_helper_vfp_mulxd(tcg_res, tcg_op, tcg_idx, fpst);
12781 g_assert_not_reached();
12784 write_vec_element(s, tcg_res, rd, pass, MO_64);
12785 tcg_temp_free_i64(tcg_op);
12786 tcg_temp_free_i64(tcg_res);
12789 tcg_temp_free_i64(tcg_idx);
12790 clear_vec_high(s, !is_scalar, rd);
12791 } else if (!is_long) {
12792 /* 32 bit floating point, or 16 or 32 bit integer.
12793 * For the 16 bit scalar case we use the usual Neon helpers and
12794 * rely on the fact that 0 op 0 == 0 with no side effects.
12796 TCGv_i32 tcg_idx = tcg_temp_new_i32();
12797 int pass, maxpasses;
12802 maxpasses = is_q ? 4 : 2;
12805 read_vec_element_i32(s, tcg_idx, rm, index, size);
12807 if (size == 1 && !is_scalar) {
12808 /* The simplest way to handle the 16x16 indexed ops is to duplicate
12809 * the index into both halves of the 32 bit tcg_idx and then use
12810 * the usual Neon helpers.
12812 tcg_gen_deposit_i32(tcg_idx, tcg_idx, tcg_idx, 16, 16);
12815 for (pass = 0; pass < maxpasses; pass++) {
12816 TCGv_i32 tcg_op = tcg_temp_new_i32();
12817 TCGv_i32 tcg_res = tcg_temp_new_i32();
12819 read_vec_element_i32(s, tcg_op, rn, pass, is_scalar ? size : MO_32);
12821 switch (16 * u + opcode) {
12822 case 0x08: /* MUL */
12823 case 0x10: /* MLA */
12824 case 0x14: /* MLS */
12826 static NeonGenTwoOpFn * const fns[2][2] = {
12827 { gen_helper_neon_add_u16, gen_helper_neon_sub_u16 },
12828 { tcg_gen_add_i32, tcg_gen_sub_i32 },
12830 NeonGenTwoOpFn *genfn;
12831 bool is_sub = opcode == 0x4;
12834 gen_helper_neon_mul_u16(tcg_res, tcg_op, tcg_idx);
12836 tcg_gen_mul_i32(tcg_res, tcg_op, tcg_idx);
12838 if (opcode == 0x8) {
12841 read_vec_element_i32(s, tcg_op, rd, pass, MO_32);
12842 genfn = fns[size - 1][is_sub];
12843 genfn(tcg_res, tcg_op, tcg_res);
12846 case 0x05: /* FMLS */
12847 case 0x01: /* FMLA */
12848 read_vec_element_i32(s, tcg_res, rd, pass,
12849 is_scalar ? size : MO_32);
12852 if (opcode == 0x5) {
12853 /* As usual for ARM, separate negation for fused
12855 tcg_gen_xori_i32(tcg_op, tcg_op, 0x80008000);
12858 gen_helper_advsimd_muladdh(tcg_res, tcg_op, tcg_idx,
12861 gen_helper_advsimd_muladd2h(tcg_res, tcg_op, tcg_idx,
12866 if (opcode == 0x5) {
12867 /* As usual for ARM, separate negation for
12868 * fused multiply-add */
12869 tcg_gen_xori_i32(tcg_op, tcg_op, 0x80000000);
12871 gen_helper_vfp_muladds(tcg_res, tcg_op, tcg_idx,
12875 g_assert_not_reached();
12878 case 0x09: /* FMUL */
12882 gen_helper_advsimd_mulh(tcg_res, tcg_op,
12885 gen_helper_advsimd_mul2h(tcg_res, tcg_op,
12890 gen_helper_vfp_muls(tcg_res, tcg_op, tcg_idx, fpst);
12893 g_assert_not_reached();
12896 case 0x19: /* FMULX */
12900 gen_helper_advsimd_mulxh(tcg_res, tcg_op,
12903 gen_helper_advsimd_mulx2h(tcg_res, tcg_op,
12908 gen_helper_vfp_mulxs(tcg_res, tcg_op, tcg_idx, fpst);
12911 g_assert_not_reached();
12914 case 0x0c: /* SQDMULH */
12916 gen_helper_neon_qdmulh_s16(tcg_res, cpu_env,
12919 gen_helper_neon_qdmulh_s32(tcg_res, cpu_env,
12923 case 0x0d: /* SQRDMULH */
12925 gen_helper_neon_qrdmulh_s16(tcg_res, cpu_env,
12928 gen_helper_neon_qrdmulh_s32(tcg_res, cpu_env,
12932 case 0x1d: /* SQRDMLAH */
12933 read_vec_element_i32(s, tcg_res, rd, pass,
12934 is_scalar ? size : MO_32);
12936 gen_helper_neon_qrdmlah_s16(tcg_res, cpu_env,
12937 tcg_op, tcg_idx, tcg_res);
12939 gen_helper_neon_qrdmlah_s32(tcg_res, cpu_env,
12940 tcg_op, tcg_idx, tcg_res);
12943 case 0x1f: /* SQRDMLSH */
12944 read_vec_element_i32(s, tcg_res, rd, pass,
12945 is_scalar ? size : MO_32);
12947 gen_helper_neon_qrdmlsh_s16(tcg_res, cpu_env,
12948 tcg_op, tcg_idx, tcg_res);
12950 gen_helper_neon_qrdmlsh_s32(tcg_res, cpu_env,
12951 tcg_op, tcg_idx, tcg_res);
12955 g_assert_not_reached();
12959 write_fp_sreg(s, rd, tcg_res);
12961 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
12964 tcg_temp_free_i32(tcg_op);
12965 tcg_temp_free_i32(tcg_res);
12968 tcg_temp_free_i32(tcg_idx);
12969 clear_vec_high(s, is_q, rd);
12971 /* long ops: 16x16->32 or 32x32->64 */
12972 TCGv_i64 tcg_res[2];
12974 bool satop = extract32(opcode, 0, 1);
12975 TCGMemOp memop = MO_32;
12982 TCGv_i64 tcg_idx = tcg_temp_new_i64();
12984 read_vec_element(s, tcg_idx, rm, index, memop);
12986 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
12987 TCGv_i64 tcg_op = tcg_temp_new_i64();
12988 TCGv_i64 tcg_passres;
12994 passelt = pass + (is_q * 2);
12997 read_vec_element(s, tcg_op, rn, passelt, memop);
12999 tcg_res[pass] = tcg_temp_new_i64();
13001 if (opcode == 0xa || opcode == 0xb) {
13002 /* Non-accumulating ops */
13003 tcg_passres = tcg_res[pass];
13005 tcg_passres = tcg_temp_new_i64();
13008 tcg_gen_mul_i64(tcg_passres, tcg_op, tcg_idx);
13009 tcg_temp_free_i64(tcg_op);
13012 /* saturating, doubling */
13013 gen_helper_neon_addl_saturate_s64(tcg_passres, cpu_env,
13014 tcg_passres, tcg_passres);
13017 if (opcode == 0xa || opcode == 0xb) {
13021 /* Accumulating op: handle accumulate step */
13022 read_vec_element(s, tcg_res[pass], rd, pass, MO_64);
13025 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13026 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
13028 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13029 tcg_gen_sub_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
13031 case 0x7: /* SQDMLSL, SQDMLSL2 */
13032 tcg_gen_neg_i64(tcg_passres, tcg_passres);
13034 case 0x3: /* SQDMLAL, SQDMLAL2 */
13035 gen_helper_neon_addl_saturate_s64(tcg_res[pass], cpu_env,
13040 g_assert_not_reached();
13042 tcg_temp_free_i64(tcg_passres);
13044 tcg_temp_free_i64(tcg_idx);
13046 clear_vec_high(s, !is_scalar, rd);
13048 TCGv_i32 tcg_idx = tcg_temp_new_i32();
13051 read_vec_element_i32(s, tcg_idx, rm, index, size);
13054 /* The simplest way to handle the 16x16 indexed ops is to
13055 * duplicate the index into both halves of the 32 bit tcg_idx
13056 * and then use the usual Neon helpers.
13058 tcg_gen_deposit_i32(tcg_idx, tcg_idx, tcg_idx, 16, 16);
13061 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
13062 TCGv_i32 tcg_op = tcg_temp_new_i32();
13063 TCGv_i64 tcg_passres;
13066 read_vec_element_i32(s, tcg_op, rn, pass, size);
13068 read_vec_element_i32(s, tcg_op, rn,
13069 pass + (is_q * 2), MO_32);
13072 tcg_res[pass] = tcg_temp_new_i64();
13074 if (opcode == 0xa || opcode == 0xb) {
13075 /* Non-accumulating ops */
13076 tcg_passres = tcg_res[pass];
13078 tcg_passres = tcg_temp_new_i64();
13081 if (memop & MO_SIGN) {
13082 gen_helper_neon_mull_s16(tcg_passres, tcg_op, tcg_idx);
13084 gen_helper_neon_mull_u16(tcg_passres, tcg_op, tcg_idx);
13087 gen_helper_neon_addl_saturate_s32(tcg_passres, cpu_env,
13088 tcg_passres, tcg_passres);
13090 tcg_temp_free_i32(tcg_op);
13092 if (opcode == 0xa || opcode == 0xb) {
13096 /* Accumulating op: handle accumulate step */
13097 read_vec_element(s, tcg_res[pass], rd, pass, MO_64);
13100 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13101 gen_helper_neon_addl_u32(tcg_res[pass], tcg_res[pass],
13104 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13105 gen_helper_neon_subl_u32(tcg_res[pass], tcg_res[pass],
13108 case 0x7: /* SQDMLSL, SQDMLSL2 */
13109 gen_helper_neon_negl_u32(tcg_passres, tcg_passres);
13111 case 0x3: /* SQDMLAL, SQDMLAL2 */
13112 gen_helper_neon_addl_saturate_s32(tcg_res[pass], cpu_env,
13117 g_assert_not_reached();
13119 tcg_temp_free_i64(tcg_passres);
13121 tcg_temp_free_i32(tcg_idx);
13124 tcg_gen_ext32u_i64(tcg_res[0], tcg_res[0]);
13129 tcg_res[1] = tcg_const_i64(0);
13132 for (pass = 0; pass < 2; pass++) {
13133 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
13134 tcg_temp_free_i64(tcg_res[pass]);
13139 tcg_temp_free_ptr(fpst);
13144 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13145 * +-----------------+------+-----------+--------+-----+------+------+
13146 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13147 * +-----------------+------+-----------+--------+-----+------+------+
13149 static void disas_crypto_aes(DisasContext *s, uint32_t insn)
13151 int size = extract32(insn, 22, 2);
13152 int opcode = extract32(insn, 12, 5);
13153 int rn = extract32(insn, 5, 5);
13154 int rd = extract32(insn, 0, 5);
13156 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
13157 TCGv_i32 tcg_decrypt;
13158 CryptoThreeOpIntFn *genfn;
13160 if (!dc_isar_feature(aa64_aes, s) || size != 0) {
13161 unallocated_encoding(s);
13166 case 0x4: /* AESE */
13168 genfn = gen_helper_crypto_aese;
13170 case 0x6: /* AESMC */
13172 genfn = gen_helper_crypto_aesmc;
13174 case 0x5: /* AESD */
13176 genfn = gen_helper_crypto_aese;
13178 case 0x7: /* AESIMC */
13180 genfn = gen_helper_crypto_aesmc;
13183 unallocated_encoding(s);
13187 if (!fp_access_check(s)) {
13191 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13192 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13193 tcg_decrypt = tcg_const_i32(decrypt);
13195 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_decrypt);
13197 tcg_temp_free_ptr(tcg_rd_ptr);
13198 tcg_temp_free_ptr(tcg_rn_ptr);
13199 tcg_temp_free_i32(tcg_decrypt);
13202 /* Crypto three-reg SHA
13203 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
13204 * +-----------------+------+---+------+---+--------+-----+------+------+
13205 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
13206 * +-----------------+------+---+------+---+--------+-----+------+------+
13208 static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn)
13210 int size = extract32(insn, 22, 2);
13211 int opcode = extract32(insn, 12, 3);
13212 int rm = extract32(insn, 16, 5);
13213 int rn = extract32(insn, 5, 5);
13214 int rd = extract32(insn, 0, 5);
13215 CryptoThreeOpFn *genfn;
13216 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13220 unallocated_encoding(s);
13225 case 0: /* SHA1C */
13226 case 1: /* SHA1P */
13227 case 2: /* SHA1M */
13228 case 3: /* SHA1SU0 */
13230 feature = dc_isar_feature(aa64_sha1, s);
13232 case 4: /* SHA256H */
13233 genfn = gen_helper_crypto_sha256h;
13234 feature = dc_isar_feature(aa64_sha256, s);
13236 case 5: /* SHA256H2 */
13237 genfn = gen_helper_crypto_sha256h2;
13238 feature = dc_isar_feature(aa64_sha256, s);
13240 case 6: /* SHA256SU1 */
13241 genfn = gen_helper_crypto_sha256su1;
13242 feature = dc_isar_feature(aa64_sha256, s);
13245 unallocated_encoding(s);
13250 unallocated_encoding(s);
13254 if (!fp_access_check(s)) {
13258 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13259 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13260 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13263 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr);
13265 TCGv_i32 tcg_opcode = tcg_const_i32(opcode);
13267 gen_helper_crypto_sha1_3reg(tcg_rd_ptr, tcg_rn_ptr,
13268 tcg_rm_ptr, tcg_opcode);
13269 tcg_temp_free_i32(tcg_opcode);
13272 tcg_temp_free_ptr(tcg_rd_ptr);
13273 tcg_temp_free_ptr(tcg_rn_ptr);
13274 tcg_temp_free_ptr(tcg_rm_ptr);
13277 /* Crypto two-reg SHA
13278 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13279 * +-----------------+------+-----------+--------+-----+------+------+
13280 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13281 * +-----------------+------+-----------+--------+-----+------+------+
13283 static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn)
13285 int size = extract32(insn, 22, 2);
13286 int opcode = extract32(insn, 12, 5);
13287 int rn = extract32(insn, 5, 5);
13288 int rd = extract32(insn, 0, 5);
13289 CryptoTwoOpFn *genfn;
13291 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
13294 unallocated_encoding(s);
13299 case 0: /* SHA1H */
13300 feature = dc_isar_feature(aa64_sha1, s);
13301 genfn = gen_helper_crypto_sha1h;
13303 case 1: /* SHA1SU1 */
13304 feature = dc_isar_feature(aa64_sha1, s);
13305 genfn = gen_helper_crypto_sha1su1;
13307 case 2: /* SHA256SU0 */
13308 feature = dc_isar_feature(aa64_sha256, s);
13309 genfn = gen_helper_crypto_sha256su0;
13312 unallocated_encoding(s);
13317 unallocated_encoding(s);
13321 if (!fp_access_check(s)) {
13325 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13326 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13328 genfn(tcg_rd_ptr, tcg_rn_ptr);
13330 tcg_temp_free_ptr(tcg_rd_ptr);
13331 tcg_temp_free_ptr(tcg_rn_ptr);
13334 /* Crypto three-reg SHA512
13335 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13336 * +-----------------------+------+---+---+-----+--------+------+------+
13337 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
13338 * +-----------------------+------+---+---+-----+--------+------+------+
13340 static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn)
13342 int opcode = extract32(insn, 10, 2);
13343 int o = extract32(insn, 14, 1);
13344 int rm = extract32(insn, 16, 5);
13345 int rn = extract32(insn, 5, 5);
13346 int rd = extract32(insn, 0, 5);
13348 CryptoThreeOpFn *genfn;
13352 case 0: /* SHA512H */
13353 feature = dc_isar_feature(aa64_sha512, s);
13354 genfn = gen_helper_crypto_sha512h;
13356 case 1: /* SHA512H2 */
13357 feature = dc_isar_feature(aa64_sha512, s);
13358 genfn = gen_helper_crypto_sha512h2;
13360 case 2: /* SHA512SU1 */
13361 feature = dc_isar_feature(aa64_sha512, s);
13362 genfn = gen_helper_crypto_sha512su1;
13365 feature = dc_isar_feature(aa64_sha3, s);
13371 case 0: /* SM3PARTW1 */
13372 feature = dc_isar_feature(aa64_sm3, s);
13373 genfn = gen_helper_crypto_sm3partw1;
13375 case 1: /* SM3PARTW2 */
13376 feature = dc_isar_feature(aa64_sm3, s);
13377 genfn = gen_helper_crypto_sm3partw2;
13379 case 2: /* SM4EKEY */
13380 feature = dc_isar_feature(aa64_sm4, s);
13381 genfn = gen_helper_crypto_sm4ekey;
13384 unallocated_encoding(s);
13390 unallocated_encoding(s);
13394 if (!fp_access_check(s)) {
13399 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13401 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13402 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13403 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13405 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr);
13407 tcg_temp_free_ptr(tcg_rd_ptr);
13408 tcg_temp_free_ptr(tcg_rn_ptr);
13409 tcg_temp_free_ptr(tcg_rm_ptr);
13411 TCGv_i64 tcg_op1, tcg_op2, tcg_res[2];
13414 tcg_op1 = tcg_temp_new_i64();
13415 tcg_op2 = tcg_temp_new_i64();
13416 tcg_res[0] = tcg_temp_new_i64();
13417 tcg_res[1] = tcg_temp_new_i64();
13419 for (pass = 0; pass < 2; pass++) {
13420 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13421 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13423 tcg_gen_rotli_i64(tcg_res[pass], tcg_op2, 1);
13424 tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
13426 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13427 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13429 tcg_temp_free_i64(tcg_op1);
13430 tcg_temp_free_i64(tcg_op2);
13431 tcg_temp_free_i64(tcg_res[0]);
13432 tcg_temp_free_i64(tcg_res[1]);
13436 /* Crypto two-reg SHA512
13437 * 31 12 11 10 9 5 4 0
13438 * +-----------------------------------------+--------+------+------+
13439 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
13440 * +-----------------------------------------+--------+------+------+
13442 static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn)
13444 int opcode = extract32(insn, 10, 2);
13445 int rn = extract32(insn, 5, 5);
13446 int rd = extract32(insn, 0, 5);
13447 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
13449 CryptoTwoOpFn *genfn;
13452 case 0: /* SHA512SU0 */
13453 feature = dc_isar_feature(aa64_sha512, s);
13454 genfn = gen_helper_crypto_sha512su0;
13457 feature = dc_isar_feature(aa64_sm4, s);
13458 genfn = gen_helper_crypto_sm4e;
13461 unallocated_encoding(s);
13466 unallocated_encoding(s);
13470 if (!fp_access_check(s)) {
13474 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13475 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13477 genfn(tcg_rd_ptr, tcg_rn_ptr);
13479 tcg_temp_free_ptr(tcg_rd_ptr);
13480 tcg_temp_free_ptr(tcg_rn_ptr);
13483 /* Crypto four-register
13484 * 31 23 22 21 20 16 15 14 10 9 5 4 0
13485 * +-------------------+-----+------+---+------+------+------+
13486 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
13487 * +-------------------+-----+------+---+------+------+------+
13489 static void disas_crypto_four_reg(DisasContext *s, uint32_t insn)
13491 int op0 = extract32(insn, 21, 2);
13492 int rm = extract32(insn, 16, 5);
13493 int ra = extract32(insn, 10, 5);
13494 int rn = extract32(insn, 5, 5);
13495 int rd = extract32(insn, 0, 5);
13501 feature = dc_isar_feature(aa64_sha3, s);
13503 case 2: /* SM3SS1 */
13504 feature = dc_isar_feature(aa64_sm3, s);
13507 unallocated_encoding(s);
13512 unallocated_encoding(s);
13516 if (!fp_access_check(s)) {
13521 TCGv_i64 tcg_op1, tcg_op2, tcg_op3, tcg_res[2];
13524 tcg_op1 = tcg_temp_new_i64();
13525 tcg_op2 = tcg_temp_new_i64();
13526 tcg_op3 = tcg_temp_new_i64();
13527 tcg_res[0] = tcg_temp_new_i64();
13528 tcg_res[1] = tcg_temp_new_i64();
13530 for (pass = 0; pass < 2; pass++) {
13531 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13532 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13533 read_vec_element(s, tcg_op3, ra, pass, MO_64);
13537 tcg_gen_xor_i64(tcg_res[pass], tcg_op2, tcg_op3);
13540 tcg_gen_andc_i64(tcg_res[pass], tcg_op2, tcg_op3);
13542 tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
13544 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13545 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13547 tcg_temp_free_i64(tcg_op1);
13548 tcg_temp_free_i64(tcg_op2);
13549 tcg_temp_free_i64(tcg_op3);
13550 tcg_temp_free_i64(tcg_res[0]);
13551 tcg_temp_free_i64(tcg_res[1]);
13553 TCGv_i32 tcg_op1, tcg_op2, tcg_op3, tcg_res, tcg_zero;
13555 tcg_op1 = tcg_temp_new_i32();
13556 tcg_op2 = tcg_temp_new_i32();
13557 tcg_op3 = tcg_temp_new_i32();
13558 tcg_res = tcg_temp_new_i32();
13559 tcg_zero = tcg_const_i32(0);
13561 read_vec_element_i32(s, tcg_op1, rn, 3, MO_32);
13562 read_vec_element_i32(s, tcg_op2, rm, 3, MO_32);
13563 read_vec_element_i32(s, tcg_op3, ra, 3, MO_32);
13565 tcg_gen_rotri_i32(tcg_res, tcg_op1, 20);
13566 tcg_gen_add_i32(tcg_res, tcg_res, tcg_op2);
13567 tcg_gen_add_i32(tcg_res, tcg_res, tcg_op3);
13568 tcg_gen_rotri_i32(tcg_res, tcg_res, 25);
13570 write_vec_element_i32(s, tcg_zero, rd, 0, MO_32);
13571 write_vec_element_i32(s, tcg_zero, rd, 1, MO_32);
13572 write_vec_element_i32(s, tcg_zero, rd, 2, MO_32);
13573 write_vec_element_i32(s, tcg_res, rd, 3, MO_32);
13575 tcg_temp_free_i32(tcg_op1);
13576 tcg_temp_free_i32(tcg_op2);
13577 tcg_temp_free_i32(tcg_op3);
13578 tcg_temp_free_i32(tcg_res);
13579 tcg_temp_free_i32(tcg_zero);
13584 * 31 21 20 16 15 10 9 5 4 0
13585 * +-----------------------+------+--------+------+------+
13586 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
13587 * +-----------------------+------+--------+------+------+
13589 static void disas_crypto_xar(DisasContext *s, uint32_t insn)
13591 int rm = extract32(insn, 16, 5);
13592 int imm6 = extract32(insn, 10, 6);
13593 int rn = extract32(insn, 5, 5);
13594 int rd = extract32(insn, 0, 5);
13595 TCGv_i64 tcg_op1, tcg_op2, tcg_res[2];
13598 if (!dc_isar_feature(aa64_sha3, s)) {
13599 unallocated_encoding(s);
13603 if (!fp_access_check(s)) {
13607 tcg_op1 = tcg_temp_new_i64();
13608 tcg_op2 = tcg_temp_new_i64();
13609 tcg_res[0] = tcg_temp_new_i64();
13610 tcg_res[1] = tcg_temp_new_i64();
13612 for (pass = 0; pass < 2; pass++) {
13613 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13614 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13616 tcg_gen_xor_i64(tcg_res[pass], tcg_op1, tcg_op2);
13617 tcg_gen_rotri_i64(tcg_res[pass], tcg_res[pass], imm6);
13619 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13620 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13622 tcg_temp_free_i64(tcg_op1);
13623 tcg_temp_free_i64(tcg_op2);
13624 tcg_temp_free_i64(tcg_res[0]);
13625 tcg_temp_free_i64(tcg_res[1]);
13628 /* Crypto three-reg imm2
13629 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13630 * +-----------------------+------+-----+------+--------+------+------+
13631 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
13632 * +-----------------------+------+-----+------+--------+------+------+
13634 static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn)
13636 int opcode = extract32(insn, 10, 2);
13637 int imm2 = extract32(insn, 12, 2);
13638 int rm = extract32(insn, 16, 5);
13639 int rn = extract32(insn, 5, 5);
13640 int rd = extract32(insn, 0, 5);
13641 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13642 TCGv_i32 tcg_imm2, tcg_opcode;
13644 if (!dc_isar_feature(aa64_sm3, s)) {
13645 unallocated_encoding(s);
13649 if (!fp_access_check(s)) {
13653 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13654 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13655 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13656 tcg_imm2 = tcg_const_i32(imm2);
13657 tcg_opcode = tcg_const_i32(opcode);
13659 gen_helper_crypto_sm3tt(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr, tcg_imm2,
13662 tcg_temp_free_ptr(tcg_rd_ptr);
13663 tcg_temp_free_ptr(tcg_rn_ptr);
13664 tcg_temp_free_ptr(tcg_rm_ptr);
13665 tcg_temp_free_i32(tcg_imm2);
13666 tcg_temp_free_i32(tcg_opcode);
13669 /* C3.6 Data processing - SIMD, inc Crypto
13671 * As the decode gets a little complex we are using a table based
13672 * approach for this part of the decode.
13674 static const AArch64DecodeTable data_proc_simd[] = {
13675 /* pattern , mask , fn */
13676 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same },
13677 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra },
13678 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff },
13679 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc },
13680 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes },
13681 { 0x0e000400, 0x9fe08400, disas_simd_copy },
13682 { 0x0f000000, 0x9f000400, disas_simd_indexed }, /* vector indexed */
13683 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
13684 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm },
13685 { 0x0f000400, 0x9f800400, disas_simd_shift_imm },
13686 { 0x0e000000, 0xbf208c00, disas_simd_tb },
13687 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn },
13688 { 0x2e000000, 0xbf208400, disas_simd_ext },
13689 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same },
13690 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra },
13691 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff },
13692 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc },
13693 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise },
13694 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy },
13695 { 0x5f000000, 0xdf000400, disas_simd_indexed }, /* scalar indexed */
13696 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm },
13697 { 0x4e280800, 0xff3e0c00, disas_crypto_aes },
13698 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha },
13699 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha },
13700 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 },
13701 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 },
13702 { 0xce000000, 0xff808000, disas_crypto_four_reg },
13703 { 0xce800000, 0xffe00000, disas_crypto_xar },
13704 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2 },
13705 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16 },
13706 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16 },
13707 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16 },
13708 { 0x00000000, 0x00000000, NULL }
13711 static void disas_data_proc_simd(DisasContext *s, uint32_t insn)
13713 /* Note that this is called with all non-FP cases from
13714 * table C3-6 so it must UNDEF for entries not specifically
13715 * allocated to instructions in that table.
13717 AArch64DecodeFn *fn = lookup_disas_fn(&data_proc_simd[0], insn);
13721 unallocated_encoding(s);
13725 /* C3.6 Data processing - SIMD and floating point */
13726 static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn)
13728 if (extract32(insn, 28, 1) == 1 && extract32(insn, 30, 1) == 0) {
13729 disas_data_proc_fp(s, insn);
13731 /* SIMD, including crypto */
13732 disas_data_proc_simd(s, insn);
13736 /* C3.1 A64 instruction index by encoding */
13737 static void disas_a64_insn(CPUARMState *env, DisasContext *s)
13741 insn = arm_ldl_code(env, s->pc, s->sctlr_b);
13745 s->fp_access_checked = false;
13747 switch (extract32(insn, 25, 4)) {
13748 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
13749 unallocated_encoding(s);
13752 if (!dc_isar_feature(aa64_sve, s) || !disas_sve(s, insn)) {
13753 unallocated_encoding(s);
13756 case 0x8: case 0x9: /* Data processing - immediate */
13757 disas_data_proc_imm(s, insn);
13759 case 0xa: case 0xb: /* Branch, exception generation and system insns */
13760 disas_b_exc_sys(s, insn);
13765 case 0xe: /* Loads and stores */
13766 disas_ldst(s, insn);
13769 case 0xd: /* Data processing - register */
13770 disas_data_proc_reg(s, insn);
13773 case 0xf: /* Data processing - SIMD and floating point */
13774 disas_data_proc_simd_fp(s, insn);
13777 assert(FALSE); /* all 15 cases should be handled above */
13781 /* if we allocated any temporaries, free them here */
13785 static void aarch64_tr_init_disas_context(DisasContextBase *dcbase,
13788 DisasContext *dc = container_of(dcbase, DisasContext, base);
13789 CPUARMState *env = cpu->env_ptr;
13790 ARMCPU *arm_cpu = arm_env_get_cpu(env);
13791 uint32_t tb_flags = dc->base.tb->flags;
13792 int bound, core_mmu_idx;
13794 dc->isar = &arm_cpu->isar;
13795 dc->pc = dc->base.pc_first;
13799 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
13800 * there is no secure EL1, so we route exceptions to EL3.
13802 dc->secure_routed_to_el3 = arm_feature(env, ARM_FEATURE_EL3) &&
13803 !arm_el_is_aa64(env, 3);
13806 dc->be_data = FIELD_EX32(tb_flags, TBFLAG_ANY, BE_DATA) ? MO_BE : MO_LE;
13807 dc->condexec_mask = 0;
13808 dc->condexec_cond = 0;
13809 core_mmu_idx = FIELD_EX32(tb_flags, TBFLAG_ANY, MMUIDX);
13810 dc->mmu_idx = core_to_arm_mmu_idx(env, core_mmu_idx);
13811 dc->tbii = FIELD_EX32(tb_flags, TBFLAG_A64, TBII);
13812 dc->current_el = arm_mmu_idx_to_el(dc->mmu_idx);
13813 #if !defined(CONFIG_USER_ONLY)
13814 dc->user = (dc->current_el == 0);
13816 dc->fp_excp_el = FIELD_EX32(tb_flags, TBFLAG_ANY, FPEXC_EL);
13817 dc->sve_excp_el = FIELD_EX32(tb_flags, TBFLAG_A64, SVEEXC_EL);
13818 dc->sve_len = (FIELD_EX32(tb_flags, TBFLAG_A64, ZCR_LEN) + 1) * 16;
13819 dc->pauth_active = FIELD_EX32(tb_flags, TBFLAG_A64, PAUTH_ACTIVE);
13821 dc->vec_stride = 0;
13822 dc->cp_regs = arm_cpu->cp_regs;
13823 dc->features = env->features;
13825 /* Single step state. The code-generation logic here is:
13827 * generate code with no special handling for single-stepping (except
13828 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
13829 * this happens anyway because those changes are all system register or
13831 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
13832 * emit code for one insn
13833 * emit code to clear PSTATE.SS
13834 * emit code to generate software step exception for completed step
13835 * end TB (as usual for having generated an exception)
13836 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
13837 * emit code to generate a software step exception
13840 dc->ss_active = FIELD_EX32(tb_flags, TBFLAG_ANY, SS_ACTIVE);
13841 dc->pstate_ss = FIELD_EX32(tb_flags, TBFLAG_ANY, PSTATE_SS);
13842 dc->is_ldex = false;
13843 dc->ss_same_el = (arm_debug_target_el(env) == dc->current_el);
13845 /* Bound the number of insns to execute to those left on the page. */
13846 bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
13848 /* If architectural single step active, limit to 1. */
13849 if (dc->ss_active) {
13852 dc->base.max_insns = MIN(dc->base.max_insns, bound);
13854 init_tmp_a64_array(dc);
13857 static void aarch64_tr_tb_start(DisasContextBase *db, CPUState *cpu)
13861 static void aarch64_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
13863 DisasContext *dc = container_of(dcbase, DisasContext, base);
13865 tcg_gen_insn_start(dc->pc, 0, 0);
13866 dc->insn_start = tcg_last_op();
13869 static bool aarch64_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu,
13870 const CPUBreakpoint *bp)
13872 DisasContext *dc = container_of(dcbase, DisasContext, base);
13874 if (bp->flags & BP_CPU) {
13875 gen_a64_set_pc_im(dc->pc);
13876 gen_helper_check_breakpoints(cpu_env);
13877 /* End the TB early; it likely won't be executed */
13878 dc->base.is_jmp = DISAS_TOO_MANY;
13880 gen_exception_internal_insn(dc, 0, EXCP_DEBUG);
13881 /* The address covered by the breakpoint must be
13882 included in [tb->pc, tb->pc + tb->size) in order
13883 to for it to be properly cleared -- thus we
13884 increment the PC here so that the logic setting
13885 tb->size below does the right thing. */
13887 dc->base.is_jmp = DISAS_NORETURN;
13893 static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
13895 DisasContext *dc = container_of(dcbase, DisasContext, base);
13896 CPUARMState *env = cpu->env_ptr;
13898 if (dc->ss_active && !dc->pstate_ss) {
13899 /* Singlestep state is Active-pending.
13900 * If we're in this state at the start of a TB then either
13901 * a) we just took an exception to an EL which is being debugged
13902 * and this is the first insn in the exception handler
13903 * b) debug exceptions were masked and we just unmasked them
13904 * without changing EL (eg by clearing PSTATE.D)
13905 * In either case we're going to take a swstep exception in the
13906 * "did not step an insn" case, and so the syndrome ISV and EX
13907 * bits should be zero.
13909 assert(dc->base.num_insns == 1);
13910 gen_exception(EXCP_UDEF, syn_swstep(dc->ss_same_el, 0, 0),
13911 default_exception_el(dc));
13912 dc->base.is_jmp = DISAS_NORETURN;
13914 disas_a64_insn(env, dc);
13917 dc->base.pc_next = dc->pc;
13918 translator_loop_temp_check(&dc->base);
13921 static void aarch64_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
13923 DisasContext *dc = container_of(dcbase, DisasContext, base);
13925 if (unlikely(dc->base.singlestep_enabled || dc->ss_active)) {
13926 /* Note that this means single stepping WFI doesn't halt the CPU.
13927 * For conditional branch insns this is harmless unreachable code as
13928 * gen_goto_tb() has already handled emitting the debug exception
13929 * (and thus a tb-jump is not possible when singlestepping).
13931 switch (dc->base.is_jmp) {
13933 gen_a64_set_pc_im(dc->pc);
13937 if (dc->base.singlestep_enabled) {
13938 gen_exception_internal(EXCP_DEBUG);
13940 gen_step_complete_exception(dc);
13943 case DISAS_NORETURN:
13947 switch (dc->base.is_jmp) {
13949 case DISAS_TOO_MANY:
13950 gen_goto_tb(dc, 1, dc->pc);
13954 gen_a64_set_pc_im(dc->pc);
13957 tcg_gen_exit_tb(NULL, 0);
13960 tcg_gen_lookup_and_goto_ptr();
13962 case DISAS_NORETURN:
13966 gen_a64_set_pc_im(dc->pc);
13967 gen_helper_wfe(cpu_env);
13970 gen_a64_set_pc_im(dc->pc);
13971 gen_helper_yield(cpu_env);
13975 /* This is a special case because we don't want to just halt the CPU
13976 * if trying to debug across a WFI.
13978 TCGv_i32 tmp = tcg_const_i32(4);
13980 gen_a64_set_pc_im(dc->pc);
13981 gen_helper_wfi(cpu_env, tmp);
13982 tcg_temp_free_i32(tmp);
13983 /* The helper doesn't necessarily throw an exception, but we
13984 * must go back to the main loop to check for interrupts anyway.
13986 tcg_gen_exit_tb(NULL, 0);
13992 /* Functions above can change dc->pc, so re-align db->pc_next */
13993 dc->base.pc_next = dc->pc;
13996 static void aarch64_tr_disas_log(const DisasContextBase *dcbase,
13999 DisasContext *dc = container_of(dcbase, DisasContext, base);
14001 qemu_log("IN: %s\n", lookup_symbol(dc->base.pc_first));
14002 log_target_disas(cpu, dc->base.pc_first, dc->base.tb->size);
14005 const TranslatorOps aarch64_translator_ops = {
14006 .init_disas_context = aarch64_tr_init_disas_context,
14007 .tb_start = aarch64_tr_tb_start,
14008 .insn_start = aarch64_tr_insn_start,
14009 .breakpoint_check = aarch64_tr_breakpoint_check,
14010 .translate_insn = aarch64_tr_translate_insn,
14011 .tb_stop = aarch64_tr_tb_stop,
14012 .disas_log = aarch64_tr_disas_log,