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 & ~1) != 2) {
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 mos = extract32(insn, 29, 3);
5640 int type = extract32(insn, 22, 2);
5641 int opcode = extract32(insn, 15, 6);
5642 int rn = extract32(insn, 5, 5);
5643 int rd = extract32(insn, 0, 5);
5646 unallocated_encoding(s);
5651 case 0x4: case 0x5: case 0x7:
5653 /* FCVT between half, single and double precision */
5654 int dtype = extract32(opcode, 0, 2);
5655 if (type == 2 || dtype == type) {
5656 unallocated_encoding(s);
5659 if (!fp_access_check(s)) {
5663 handle_fp_fcvt(s, opcode, rd, rn, dtype, type);
5669 /* 32-to-32 and 64-to-64 ops */
5672 if (!fp_access_check(s)) {
5676 handle_fp_1src_single(s, opcode, rd, rn);
5679 if (!fp_access_check(s)) {
5683 handle_fp_1src_double(s, opcode, rd, rn);
5686 if (!dc_isar_feature(aa64_fp16, s)) {
5687 unallocated_encoding(s);
5691 if (!fp_access_check(s)) {
5695 handle_fp_1src_half(s, opcode, rd, rn);
5698 unallocated_encoding(s);
5702 unallocated_encoding(s);
5707 /* Floating-point data-processing (2 source) - single precision */
5708 static void handle_fp_2src_single(DisasContext *s, int opcode,
5709 int rd, int rn, int rm)
5716 tcg_res = tcg_temp_new_i32();
5717 fpst = get_fpstatus_ptr(false);
5718 tcg_op1 = read_fp_sreg(s, rn);
5719 tcg_op2 = read_fp_sreg(s, rm);
5722 case 0x0: /* FMUL */
5723 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
5725 case 0x1: /* FDIV */
5726 gen_helper_vfp_divs(tcg_res, tcg_op1, tcg_op2, fpst);
5728 case 0x2: /* FADD */
5729 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
5731 case 0x3: /* FSUB */
5732 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
5734 case 0x4: /* FMAX */
5735 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
5737 case 0x5: /* FMIN */
5738 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
5740 case 0x6: /* FMAXNM */
5741 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
5743 case 0x7: /* FMINNM */
5744 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
5746 case 0x8: /* FNMUL */
5747 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
5748 gen_helper_vfp_negs(tcg_res, tcg_res);
5752 write_fp_sreg(s, rd, tcg_res);
5754 tcg_temp_free_ptr(fpst);
5755 tcg_temp_free_i32(tcg_op1);
5756 tcg_temp_free_i32(tcg_op2);
5757 tcg_temp_free_i32(tcg_res);
5760 /* Floating-point data-processing (2 source) - double precision */
5761 static void handle_fp_2src_double(DisasContext *s, int opcode,
5762 int rd, int rn, int rm)
5769 tcg_res = tcg_temp_new_i64();
5770 fpst = get_fpstatus_ptr(false);
5771 tcg_op1 = read_fp_dreg(s, rn);
5772 tcg_op2 = read_fp_dreg(s, rm);
5775 case 0x0: /* FMUL */
5776 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
5778 case 0x1: /* FDIV */
5779 gen_helper_vfp_divd(tcg_res, tcg_op1, tcg_op2, fpst);
5781 case 0x2: /* FADD */
5782 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
5784 case 0x3: /* FSUB */
5785 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
5787 case 0x4: /* FMAX */
5788 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
5790 case 0x5: /* FMIN */
5791 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
5793 case 0x6: /* FMAXNM */
5794 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
5796 case 0x7: /* FMINNM */
5797 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
5799 case 0x8: /* FNMUL */
5800 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
5801 gen_helper_vfp_negd(tcg_res, tcg_res);
5805 write_fp_dreg(s, rd, tcg_res);
5807 tcg_temp_free_ptr(fpst);
5808 tcg_temp_free_i64(tcg_op1);
5809 tcg_temp_free_i64(tcg_op2);
5810 tcg_temp_free_i64(tcg_res);
5813 /* Floating-point data-processing (2 source) - half precision */
5814 static void handle_fp_2src_half(DisasContext *s, int opcode,
5815 int rd, int rn, int rm)
5822 tcg_res = tcg_temp_new_i32();
5823 fpst = get_fpstatus_ptr(true);
5824 tcg_op1 = read_fp_hreg(s, rn);
5825 tcg_op2 = read_fp_hreg(s, rm);
5828 case 0x0: /* FMUL */
5829 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
5831 case 0x1: /* FDIV */
5832 gen_helper_advsimd_divh(tcg_res, tcg_op1, tcg_op2, fpst);
5834 case 0x2: /* FADD */
5835 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
5837 case 0x3: /* FSUB */
5838 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
5840 case 0x4: /* FMAX */
5841 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
5843 case 0x5: /* FMIN */
5844 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
5846 case 0x6: /* FMAXNM */
5847 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
5849 case 0x7: /* FMINNM */
5850 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
5852 case 0x8: /* FNMUL */
5853 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
5854 tcg_gen_xori_i32(tcg_res, tcg_res, 0x8000);
5857 g_assert_not_reached();
5860 write_fp_sreg(s, rd, tcg_res);
5862 tcg_temp_free_ptr(fpst);
5863 tcg_temp_free_i32(tcg_op1);
5864 tcg_temp_free_i32(tcg_op2);
5865 tcg_temp_free_i32(tcg_res);
5868 /* Floating point data-processing (2 source)
5869 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5870 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5871 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
5872 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5874 static void disas_fp_2src(DisasContext *s, uint32_t insn)
5876 int mos = extract32(insn, 29, 3);
5877 int type = extract32(insn, 22, 2);
5878 int rd = extract32(insn, 0, 5);
5879 int rn = extract32(insn, 5, 5);
5880 int rm = extract32(insn, 16, 5);
5881 int opcode = extract32(insn, 12, 4);
5883 if (opcode > 8 || mos) {
5884 unallocated_encoding(s);
5890 if (!fp_access_check(s)) {
5893 handle_fp_2src_single(s, opcode, rd, rn, rm);
5896 if (!fp_access_check(s)) {
5899 handle_fp_2src_double(s, opcode, rd, rn, rm);
5902 if (!dc_isar_feature(aa64_fp16, s)) {
5903 unallocated_encoding(s);
5906 if (!fp_access_check(s)) {
5909 handle_fp_2src_half(s, opcode, rd, rn, rm);
5912 unallocated_encoding(s);
5916 /* Floating-point data-processing (3 source) - single precision */
5917 static void handle_fp_3src_single(DisasContext *s, bool o0, bool o1,
5918 int rd, int rn, int rm, int ra)
5920 TCGv_i32 tcg_op1, tcg_op2, tcg_op3;
5921 TCGv_i32 tcg_res = tcg_temp_new_i32();
5922 TCGv_ptr fpst = get_fpstatus_ptr(false);
5924 tcg_op1 = read_fp_sreg(s, rn);
5925 tcg_op2 = read_fp_sreg(s, rm);
5926 tcg_op3 = read_fp_sreg(s, ra);
5928 /* These are fused multiply-add, and must be done as one
5929 * floating point operation with no rounding between the
5930 * multiplication and addition steps.
5931 * NB that doing the negations here as separate steps is
5932 * correct : an input NaN should come out with its sign bit
5933 * flipped if it is a negated-input.
5936 gen_helper_vfp_negs(tcg_op3, tcg_op3);
5940 gen_helper_vfp_negs(tcg_op1, tcg_op1);
5943 gen_helper_vfp_muladds(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
5945 write_fp_sreg(s, rd, tcg_res);
5947 tcg_temp_free_ptr(fpst);
5948 tcg_temp_free_i32(tcg_op1);
5949 tcg_temp_free_i32(tcg_op2);
5950 tcg_temp_free_i32(tcg_op3);
5951 tcg_temp_free_i32(tcg_res);
5954 /* Floating-point data-processing (3 source) - double precision */
5955 static void handle_fp_3src_double(DisasContext *s, bool o0, bool o1,
5956 int rd, int rn, int rm, int ra)
5958 TCGv_i64 tcg_op1, tcg_op2, tcg_op3;
5959 TCGv_i64 tcg_res = tcg_temp_new_i64();
5960 TCGv_ptr fpst = get_fpstatus_ptr(false);
5962 tcg_op1 = read_fp_dreg(s, rn);
5963 tcg_op2 = read_fp_dreg(s, rm);
5964 tcg_op3 = read_fp_dreg(s, ra);
5966 /* These are fused multiply-add, and must be done as one
5967 * floating point operation with no rounding between the
5968 * multiplication and addition steps.
5969 * NB that doing the negations here as separate steps is
5970 * correct : an input NaN should come out with its sign bit
5971 * flipped if it is a negated-input.
5974 gen_helper_vfp_negd(tcg_op3, tcg_op3);
5978 gen_helper_vfp_negd(tcg_op1, tcg_op1);
5981 gen_helper_vfp_muladdd(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
5983 write_fp_dreg(s, rd, tcg_res);
5985 tcg_temp_free_ptr(fpst);
5986 tcg_temp_free_i64(tcg_op1);
5987 tcg_temp_free_i64(tcg_op2);
5988 tcg_temp_free_i64(tcg_op3);
5989 tcg_temp_free_i64(tcg_res);
5992 /* Floating-point data-processing (3 source) - half precision */
5993 static void handle_fp_3src_half(DisasContext *s, bool o0, bool o1,
5994 int rd, int rn, int rm, int ra)
5996 TCGv_i32 tcg_op1, tcg_op2, tcg_op3;
5997 TCGv_i32 tcg_res = tcg_temp_new_i32();
5998 TCGv_ptr fpst = get_fpstatus_ptr(true);
6000 tcg_op1 = read_fp_hreg(s, rn);
6001 tcg_op2 = read_fp_hreg(s, rm);
6002 tcg_op3 = read_fp_hreg(s, ra);
6004 /* These are fused multiply-add, and must be done as one
6005 * floating point operation with no rounding between the
6006 * multiplication and addition steps.
6007 * NB that doing the negations here as separate steps is
6008 * correct : an input NaN should come out with its sign bit
6009 * flipped if it is a negated-input.
6012 tcg_gen_xori_i32(tcg_op3, tcg_op3, 0x8000);
6016 tcg_gen_xori_i32(tcg_op1, tcg_op1, 0x8000);
6019 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
6021 write_fp_sreg(s, rd, tcg_res);
6023 tcg_temp_free_ptr(fpst);
6024 tcg_temp_free_i32(tcg_op1);
6025 tcg_temp_free_i32(tcg_op2);
6026 tcg_temp_free_i32(tcg_op3);
6027 tcg_temp_free_i32(tcg_res);
6030 /* Floating point data-processing (3 source)
6031 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
6032 * +---+---+---+-----------+------+----+------+----+------+------+------+
6033 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
6034 * +---+---+---+-----------+------+----+------+----+------+------+------+
6036 static void disas_fp_3src(DisasContext *s, uint32_t insn)
6038 int mos = extract32(insn, 29, 3);
6039 int type = extract32(insn, 22, 2);
6040 int rd = extract32(insn, 0, 5);
6041 int rn = extract32(insn, 5, 5);
6042 int ra = extract32(insn, 10, 5);
6043 int rm = extract32(insn, 16, 5);
6044 bool o0 = extract32(insn, 15, 1);
6045 bool o1 = extract32(insn, 21, 1);
6048 unallocated_encoding(s);
6054 if (!fp_access_check(s)) {
6057 handle_fp_3src_single(s, o0, o1, rd, rn, rm, ra);
6060 if (!fp_access_check(s)) {
6063 handle_fp_3src_double(s, o0, o1, rd, rn, rm, ra);
6066 if (!dc_isar_feature(aa64_fp16, s)) {
6067 unallocated_encoding(s);
6070 if (!fp_access_check(s)) {
6073 handle_fp_3src_half(s, o0, o1, rd, rn, rm, ra);
6076 unallocated_encoding(s);
6080 /* The imm8 encodes the sign bit, enough bits to represent an exponent in
6081 * the range 01....1xx to 10....0xx, and the most significant 4 bits of
6082 * the mantissa; see VFPExpandImm() in the v8 ARM ARM.
6084 uint64_t vfp_expand_imm(int size, uint8_t imm8)
6090 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
6091 (extract32(imm8, 6, 1) ? 0x3fc0 : 0x4000) |
6092 extract32(imm8, 0, 6);
6096 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
6097 (extract32(imm8, 6, 1) ? 0x3e00 : 0x4000) |
6098 (extract32(imm8, 0, 6) << 3);
6102 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
6103 (extract32(imm8, 6, 1) ? 0x3000 : 0x4000) |
6104 (extract32(imm8, 0, 6) << 6);
6107 g_assert_not_reached();
6112 /* Floating point immediate
6113 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
6114 * +---+---+---+-----------+------+---+------------+-------+------+------+
6115 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
6116 * +---+---+---+-----------+------+---+------------+-------+------+------+
6118 static void disas_fp_imm(DisasContext *s, uint32_t insn)
6120 int rd = extract32(insn, 0, 5);
6121 int imm5 = extract32(insn, 5, 5);
6122 int imm8 = extract32(insn, 13, 8);
6123 int type = extract32(insn, 22, 2);
6124 int mos = extract32(insn, 29, 3);
6130 unallocated_encoding(s);
6143 if (dc_isar_feature(aa64_fp16, s)) {
6148 unallocated_encoding(s);
6152 if (!fp_access_check(s)) {
6156 imm = vfp_expand_imm(sz, imm8);
6158 tcg_res = tcg_const_i64(imm);
6159 write_fp_dreg(s, rd, tcg_res);
6160 tcg_temp_free_i64(tcg_res);
6163 /* Handle floating point <=> fixed point conversions. Note that we can
6164 * also deal with fp <=> integer conversions as a special case (scale == 64)
6165 * OPTME: consider handling that special case specially or at least skipping
6166 * the call to scalbn in the helpers for zero shifts.
6168 static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode,
6169 bool itof, int rmode, int scale, int sf, int type)
6171 bool is_signed = !(opcode & 1);
6172 TCGv_ptr tcg_fpstatus;
6173 TCGv_i32 tcg_shift, tcg_single;
6174 TCGv_i64 tcg_double;
6176 tcg_fpstatus = get_fpstatus_ptr(type == 3);
6178 tcg_shift = tcg_const_i32(64 - scale);
6181 TCGv_i64 tcg_int = cpu_reg(s, rn);
6183 TCGv_i64 tcg_extend = new_tmp_a64(s);
6186 tcg_gen_ext32s_i64(tcg_extend, tcg_int);
6188 tcg_gen_ext32u_i64(tcg_extend, tcg_int);
6191 tcg_int = tcg_extend;
6195 case 1: /* float64 */
6196 tcg_double = tcg_temp_new_i64();
6198 gen_helper_vfp_sqtod(tcg_double, tcg_int,
6199 tcg_shift, tcg_fpstatus);
6201 gen_helper_vfp_uqtod(tcg_double, tcg_int,
6202 tcg_shift, tcg_fpstatus);
6204 write_fp_dreg(s, rd, tcg_double);
6205 tcg_temp_free_i64(tcg_double);
6208 case 0: /* float32 */
6209 tcg_single = tcg_temp_new_i32();
6211 gen_helper_vfp_sqtos(tcg_single, tcg_int,
6212 tcg_shift, tcg_fpstatus);
6214 gen_helper_vfp_uqtos(tcg_single, tcg_int,
6215 tcg_shift, tcg_fpstatus);
6217 write_fp_sreg(s, rd, tcg_single);
6218 tcg_temp_free_i32(tcg_single);
6221 case 3: /* float16 */
6222 tcg_single = tcg_temp_new_i32();
6224 gen_helper_vfp_sqtoh(tcg_single, tcg_int,
6225 tcg_shift, tcg_fpstatus);
6227 gen_helper_vfp_uqtoh(tcg_single, tcg_int,
6228 tcg_shift, tcg_fpstatus);
6230 write_fp_sreg(s, rd, tcg_single);
6231 tcg_temp_free_i32(tcg_single);
6235 g_assert_not_reached();
6238 TCGv_i64 tcg_int = cpu_reg(s, rd);
6241 if (extract32(opcode, 2, 1)) {
6242 /* There are too many rounding modes to all fit into rmode,
6243 * so FCVTA[US] is a special case.
6245 rmode = FPROUNDING_TIEAWAY;
6248 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
6250 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
6253 case 1: /* float64 */
6254 tcg_double = read_fp_dreg(s, rn);
6257 gen_helper_vfp_tosld(tcg_int, tcg_double,
6258 tcg_shift, tcg_fpstatus);
6260 gen_helper_vfp_tosqd(tcg_int, tcg_double,
6261 tcg_shift, tcg_fpstatus);
6265 gen_helper_vfp_tould(tcg_int, tcg_double,
6266 tcg_shift, tcg_fpstatus);
6268 gen_helper_vfp_touqd(tcg_int, tcg_double,
6269 tcg_shift, tcg_fpstatus);
6273 tcg_gen_ext32u_i64(tcg_int, tcg_int);
6275 tcg_temp_free_i64(tcg_double);
6278 case 0: /* float32 */
6279 tcg_single = read_fp_sreg(s, rn);
6282 gen_helper_vfp_tosqs(tcg_int, tcg_single,
6283 tcg_shift, tcg_fpstatus);
6285 gen_helper_vfp_touqs(tcg_int, tcg_single,
6286 tcg_shift, tcg_fpstatus);
6289 TCGv_i32 tcg_dest = tcg_temp_new_i32();
6291 gen_helper_vfp_tosls(tcg_dest, tcg_single,
6292 tcg_shift, tcg_fpstatus);
6294 gen_helper_vfp_touls(tcg_dest, tcg_single,
6295 tcg_shift, tcg_fpstatus);
6297 tcg_gen_extu_i32_i64(tcg_int, tcg_dest);
6298 tcg_temp_free_i32(tcg_dest);
6300 tcg_temp_free_i32(tcg_single);
6303 case 3: /* float16 */
6304 tcg_single = read_fp_sreg(s, rn);
6307 gen_helper_vfp_tosqh(tcg_int, tcg_single,
6308 tcg_shift, tcg_fpstatus);
6310 gen_helper_vfp_touqh(tcg_int, tcg_single,
6311 tcg_shift, tcg_fpstatus);
6314 TCGv_i32 tcg_dest = tcg_temp_new_i32();
6316 gen_helper_vfp_toslh(tcg_dest, tcg_single,
6317 tcg_shift, tcg_fpstatus);
6319 gen_helper_vfp_toulh(tcg_dest, tcg_single,
6320 tcg_shift, tcg_fpstatus);
6322 tcg_gen_extu_i32_i64(tcg_int, tcg_dest);
6323 tcg_temp_free_i32(tcg_dest);
6325 tcg_temp_free_i32(tcg_single);
6329 g_assert_not_reached();
6332 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
6333 tcg_temp_free_i32(tcg_rmode);
6336 tcg_temp_free_ptr(tcg_fpstatus);
6337 tcg_temp_free_i32(tcg_shift);
6340 /* Floating point <-> fixed point conversions
6341 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6342 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6343 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
6344 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6346 static void disas_fp_fixed_conv(DisasContext *s, uint32_t insn)
6348 int rd = extract32(insn, 0, 5);
6349 int rn = extract32(insn, 5, 5);
6350 int scale = extract32(insn, 10, 6);
6351 int opcode = extract32(insn, 16, 3);
6352 int rmode = extract32(insn, 19, 2);
6353 int type = extract32(insn, 22, 2);
6354 bool sbit = extract32(insn, 29, 1);
6355 bool sf = extract32(insn, 31, 1);
6358 if (sbit || (!sf && scale < 32)) {
6359 unallocated_encoding(s);
6364 case 0: /* float32 */
6365 case 1: /* float64 */
6367 case 3: /* float16 */
6368 if (dc_isar_feature(aa64_fp16, s)) {
6373 unallocated_encoding(s);
6377 switch ((rmode << 3) | opcode) {
6378 case 0x2: /* SCVTF */
6379 case 0x3: /* UCVTF */
6382 case 0x18: /* FCVTZS */
6383 case 0x19: /* FCVTZU */
6387 unallocated_encoding(s);
6391 if (!fp_access_check(s)) {
6395 handle_fpfpcvt(s, rd, rn, opcode, itof, FPROUNDING_ZERO, scale, sf, type);
6398 static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof)
6400 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
6401 * without conversion.
6405 TCGv_i64 tcg_rn = cpu_reg(s, rn);
6411 tmp = tcg_temp_new_i64();
6412 tcg_gen_ext32u_i64(tmp, tcg_rn);
6413 write_fp_dreg(s, rd, tmp);
6414 tcg_temp_free_i64(tmp);
6418 write_fp_dreg(s, rd, tcg_rn);
6421 /* 64 bit to top half. */
6422 tcg_gen_st_i64(tcg_rn, cpu_env, fp_reg_hi_offset(s, rd));
6423 clear_vec_high(s, true, rd);
6427 tmp = tcg_temp_new_i64();
6428 tcg_gen_ext16u_i64(tmp, tcg_rn);
6429 write_fp_dreg(s, rd, tmp);
6430 tcg_temp_free_i64(tmp);
6433 g_assert_not_reached();
6436 TCGv_i64 tcg_rd = cpu_reg(s, rd);
6441 tcg_gen_ld32u_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_32));
6445 tcg_gen_ld_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_64));
6448 /* 64 bits from top half */
6449 tcg_gen_ld_i64(tcg_rd, cpu_env, fp_reg_hi_offset(s, rn));
6453 tcg_gen_ld16u_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_16));
6456 g_assert_not_reached();
6461 /* Floating point <-> integer conversions
6462 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6463 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6464 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
6465 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6467 static void disas_fp_int_conv(DisasContext *s, uint32_t insn)
6469 int rd = extract32(insn, 0, 5);
6470 int rn = extract32(insn, 5, 5);
6471 int opcode = extract32(insn, 16, 3);
6472 int rmode = extract32(insn, 19, 2);
6473 int type = extract32(insn, 22, 2);
6474 bool sbit = extract32(insn, 29, 1);
6475 bool sf = extract32(insn, 31, 1);
6478 unallocated_encoding(s);
6484 bool itof = opcode & 1;
6487 unallocated_encoding(s);
6491 switch (sf << 3 | type << 1 | rmode) {
6492 case 0x0: /* 32 bit */
6493 case 0xa: /* 64 bit */
6494 case 0xd: /* 64 bit to top half of quad */
6496 case 0x6: /* 16-bit float, 32-bit int */
6497 case 0xe: /* 16-bit float, 64-bit int */
6498 if (dc_isar_feature(aa64_fp16, s)) {
6503 /* all other sf/type/rmode combinations are invalid */
6504 unallocated_encoding(s);
6508 if (!fp_access_check(s)) {
6511 handle_fmov(s, rd, rn, type, itof);
6513 /* actual FP conversions */
6514 bool itof = extract32(opcode, 1, 1);
6516 if (rmode != 0 && opcode > 1) {
6517 unallocated_encoding(s);
6521 case 0: /* float32 */
6522 case 1: /* float64 */
6524 case 3: /* float16 */
6525 if (dc_isar_feature(aa64_fp16, s)) {
6530 unallocated_encoding(s);
6534 if (!fp_access_check(s)) {
6537 handle_fpfpcvt(s, rd, rn, opcode, itof, rmode, 64, sf, type);
6541 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
6542 * 31 30 29 28 25 24 0
6543 * +---+---+---+---------+-----------------------------+
6544 * | | 0 | | 1 1 1 1 | |
6545 * +---+---+---+---------+-----------------------------+
6547 static void disas_data_proc_fp(DisasContext *s, uint32_t insn)
6549 if (extract32(insn, 24, 1)) {
6550 /* Floating point data-processing (3 source) */
6551 disas_fp_3src(s, insn);
6552 } else if (extract32(insn, 21, 1) == 0) {
6553 /* Floating point to fixed point conversions */
6554 disas_fp_fixed_conv(s, insn);
6556 switch (extract32(insn, 10, 2)) {
6558 /* Floating point conditional compare */
6559 disas_fp_ccomp(s, insn);
6562 /* Floating point data-processing (2 source) */
6563 disas_fp_2src(s, insn);
6566 /* Floating point conditional select */
6567 disas_fp_csel(s, insn);
6570 switch (ctz32(extract32(insn, 12, 4))) {
6571 case 0: /* [15:12] == xxx1 */
6572 /* Floating point immediate */
6573 disas_fp_imm(s, insn);
6575 case 1: /* [15:12] == xx10 */
6576 /* Floating point compare */
6577 disas_fp_compare(s, insn);
6579 case 2: /* [15:12] == x100 */
6580 /* Floating point data-processing (1 source) */
6581 disas_fp_1src(s, insn);
6583 case 3: /* [15:12] == 1000 */
6584 unallocated_encoding(s);
6586 default: /* [15:12] == 0000 */
6587 /* Floating point <-> integer conversions */
6588 disas_fp_int_conv(s, insn);
6596 static void do_ext64(DisasContext *s, TCGv_i64 tcg_left, TCGv_i64 tcg_right,
6599 /* Extract 64 bits from the middle of two concatenated 64 bit
6600 * vector register slices left:right. The extracted bits start
6601 * at 'pos' bits into the right (least significant) side.
6602 * We return the result in tcg_right, and guarantee not to
6605 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
6606 assert(pos > 0 && pos < 64);
6608 tcg_gen_shri_i64(tcg_right, tcg_right, pos);
6609 tcg_gen_shli_i64(tcg_tmp, tcg_left, 64 - pos);
6610 tcg_gen_or_i64(tcg_right, tcg_right, tcg_tmp);
6612 tcg_temp_free_i64(tcg_tmp);
6616 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
6617 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6618 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
6619 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6621 static void disas_simd_ext(DisasContext *s, uint32_t insn)
6623 int is_q = extract32(insn, 30, 1);
6624 int op2 = extract32(insn, 22, 2);
6625 int imm4 = extract32(insn, 11, 4);
6626 int rm = extract32(insn, 16, 5);
6627 int rn = extract32(insn, 5, 5);
6628 int rd = extract32(insn, 0, 5);
6629 int pos = imm4 << 3;
6630 TCGv_i64 tcg_resl, tcg_resh;
6632 if (op2 != 0 || (!is_q && extract32(imm4, 3, 1))) {
6633 unallocated_encoding(s);
6637 if (!fp_access_check(s)) {
6641 tcg_resh = tcg_temp_new_i64();
6642 tcg_resl = tcg_temp_new_i64();
6644 /* Vd gets bits starting at pos bits into Vm:Vn. This is
6645 * either extracting 128 bits from a 128:128 concatenation, or
6646 * extracting 64 bits from a 64:64 concatenation.
6649 read_vec_element(s, tcg_resl, rn, 0, MO_64);
6651 read_vec_element(s, tcg_resh, rm, 0, MO_64);
6652 do_ext64(s, tcg_resh, tcg_resl, pos);
6654 tcg_gen_movi_i64(tcg_resh, 0);
6661 EltPosns eltposns[] = { {rn, 0}, {rn, 1}, {rm, 0}, {rm, 1} };
6662 EltPosns *elt = eltposns;
6669 read_vec_element(s, tcg_resl, elt->reg, elt->elt, MO_64);
6671 read_vec_element(s, tcg_resh, elt->reg, elt->elt, MO_64);
6674 do_ext64(s, tcg_resh, tcg_resl, pos);
6675 tcg_hh = tcg_temp_new_i64();
6676 read_vec_element(s, tcg_hh, elt->reg, elt->elt, MO_64);
6677 do_ext64(s, tcg_hh, tcg_resh, pos);
6678 tcg_temp_free_i64(tcg_hh);
6682 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6683 tcg_temp_free_i64(tcg_resl);
6684 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6685 tcg_temp_free_i64(tcg_resh);
6689 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
6690 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6691 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
6692 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6694 static void disas_simd_tb(DisasContext *s, uint32_t insn)
6696 int op2 = extract32(insn, 22, 2);
6697 int is_q = extract32(insn, 30, 1);
6698 int rm = extract32(insn, 16, 5);
6699 int rn = extract32(insn, 5, 5);
6700 int rd = extract32(insn, 0, 5);
6701 int is_tblx = extract32(insn, 12, 1);
6702 int len = extract32(insn, 13, 2);
6703 TCGv_i64 tcg_resl, tcg_resh, tcg_idx;
6704 TCGv_i32 tcg_regno, tcg_numregs;
6707 unallocated_encoding(s);
6711 if (!fp_access_check(s)) {
6715 /* This does a table lookup: for every byte element in the input
6716 * we index into a table formed from up to four vector registers,
6717 * and then the output is the result of the lookups. Our helper
6718 * function does the lookup operation for a single 64 bit part of
6721 tcg_resl = tcg_temp_new_i64();
6722 tcg_resh = tcg_temp_new_i64();
6725 read_vec_element(s, tcg_resl, rd, 0, MO_64);
6727 tcg_gen_movi_i64(tcg_resl, 0);
6729 if (is_tblx && is_q) {
6730 read_vec_element(s, tcg_resh, rd, 1, MO_64);
6732 tcg_gen_movi_i64(tcg_resh, 0);
6735 tcg_idx = tcg_temp_new_i64();
6736 tcg_regno = tcg_const_i32(rn);
6737 tcg_numregs = tcg_const_i32(len + 1);
6738 read_vec_element(s, tcg_idx, rm, 0, MO_64);
6739 gen_helper_simd_tbl(tcg_resl, cpu_env, tcg_resl, tcg_idx,
6740 tcg_regno, tcg_numregs);
6742 read_vec_element(s, tcg_idx, rm, 1, MO_64);
6743 gen_helper_simd_tbl(tcg_resh, cpu_env, tcg_resh, tcg_idx,
6744 tcg_regno, tcg_numregs);
6746 tcg_temp_free_i64(tcg_idx);
6747 tcg_temp_free_i32(tcg_regno);
6748 tcg_temp_free_i32(tcg_numregs);
6750 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6751 tcg_temp_free_i64(tcg_resl);
6752 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6753 tcg_temp_free_i64(tcg_resh);
6757 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
6758 * +---+---+-------------+------+---+------+---+------------------+------+
6759 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
6760 * +---+---+-------------+------+---+------+---+------------------+------+
6762 static void disas_simd_zip_trn(DisasContext *s, uint32_t insn)
6764 int rd = extract32(insn, 0, 5);
6765 int rn = extract32(insn, 5, 5);
6766 int rm = extract32(insn, 16, 5);
6767 int size = extract32(insn, 22, 2);
6768 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
6769 * bit 2 indicates 1 vs 2 variant of the insn.
6771 int opcode = extract32(insn, 12, 2);
6772 bool part = extract32(insn, 14, 1);
6773 bool is_q = extract32(insn, 30, 1);
6774 int esize = 8 << size;
6776 int datasize = is_q ? 128 : 64;
6777 int elements = datasize / esize;
6778 TCGv_i64 tcg_res, tcg_resl, tcg_resh;
6780 if (opcode == 0 || (size == 3 && !is_q)) {
6781 unallocated_encoding(s);
6785 if (!fp_access_check(s)) {
6789 tcg_resl = tcg_const_i64(0);
6790 tcg_resh = tcg_const_i64(0);
6791 tcg_res = tcg_temp_new_i64();
6793 for (i = 0; i < elements; i++) {
6795 case 1: /* UZP1/2 */
6797 int midpoint = elements / 2;
6799 read_vec_element(s, tcg_res, rn, 2 * i + part, size);
6801 read_vec_element(s, tcg_res, rm,
6802 2 * (i - midpoint) + part, size);
6806 case 2: /* TRN1/2 */
6808 read_vec_element(s, tcg_res, rm, (i & ~1) + part, size);
6810 read_vec_element(s, tcg_res, rn, (i & ~1) + part, size);
6813 case 3: /* ZIP1/2 */
6815 int base = part * elements / 2;
6817 read_vec_element(s, tcg_res, rm, base + (i >> 1), size);
6819 read_vec_element(s, tcg_res, rn, base + (i >> 1), size);
6824 g_assert_not_reached();
6829 tcg_gen_shli_i64(tcg_res, tcg_res, ofs);
6830 tcg_gen_or_i64(tcg_resl, tcg_resl, tcg_res);
6832 tcg_gen_shli_i64(tcg_res, tcg_res, ofs - 64);
6833 tcg_gen_or_i64(tcg_resh, tcg_resh, tcg_res);
6837 tcg_temp_free_i64(tcg_res);
6839 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6840 tcg_temp_free_i64(tcg_resl);
6841 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6842 tcg_temp_free_i64(tcg_resh);
6846 * do_reduction_op helper
6848 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
6849 * important for correct NaN propagation that we do these
6850 * operations in exactly the order specified by the pseudocode.
6852 * This is a recursive function, TCG temps should be freed by the
6853 * calling function once it is done with the values.
6855 static TCGv_i32 do_reduction_op(DisasContext *s, int fpopcode, int rn,
6856 int esize, int size, int vmap, TCGv_ptr fpst)
6858 if (esize == size) {
6860 TCGMemOp msize = esize == 16 ? MO_16 : MO_32;
6863 /* We should have one register left here */
6864 assert(ctpop8(vmap) == 1);
6865 element = ctz32(vmap);
6866 assert(element < 8);
6868 tcg_elem = tcg_temp_new_i32();
6869 read_vec_element_i32(s, tcg_elem, rn, element, msize);
6872 int bits = size / 2;
6873 int shift = ctpop8(vmap) / 2;
6874 int vmap_lo = (vmap >> shift) & vmap;
6875 int vmap_hi = (vmap & ~vmap_lo);
6876 TCGv_i32 tcg_hi, tcg_lo, tcg_res;
6878 tcg_hi = do_reduction_op(s, fpopcode, rn, esize, bits, vmap_hi, fpst);
6879 tcg_lo = do_reduction_op(s, fpopcode, rn, esize, bits, vmap_lo, fpst);
6880 tcg_res = tcg_temp_new_i32();
6883 case 0x0c: /* fmaxnmv half-precision */
6884 gen_helper_advsimd_maxnumh(tcg_res, tcg_lo, tcg_hi, fpst);
6886 case 0x0f: /* fmaxv half-precision */
6887 gen_helper_advsimd_maxh(tcg_res, tcg_lo, tcg_hi, fpst);
6889 case 0x1c: /* fminnmv half-precision */
6890 gen_helper_advsimd_minnumh(tcg_res, tcg_lo, tcg_hi, fpst);
6892 case 0x1f: /* fminv half-precision */
6893 gen_helper_advsimd_minh(tcg_res, tcg_lo, tcg_hi, fpst);
6895 case 0x2c: /* fmaxnmv */
6896 gen_helper_vfp_maxnums(tcg_res, tcg_lo, tcg_hi, fpst);
6898 case 0x2f: /* fmaxv */
6899 gen_helper_vfp_maxs(tcg_res, tcg_lo, tcg_hi, fpst);
6901 case 0x3c: /* fminnmv */
6902 gen_helper_vfp_minnums(tcg_res, tcg_lo, tcg_hi, fpst);
6904 case 0x3f: /* fminv */
6905 gen_helper_vfp_mins(tcg_res, tcg_lo, tcg_hi, fpst);
6908 g_assert_not_reached();
6911 tcg_temp_free_i32(tcg_hi);
6912 tcg_temp_free_i32(tcg_lo);
6917 /* AdvSIMD across lanes
6918 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6919 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6920 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6921 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6923 static void disas_simd_across_lanes(DisasContext *s, uint32_t insn)
6925 int rd = extract32(insn, 0, 5);
6926 int rn = extract32(insn, 5, 5);
6927 int size = extract32(insn, 22, 2);
6928 int opcode = extract32(insn, 12, 5);
6929 bool is_q = extract32(insn, 30, 1);
6930 bool is_u = extract32(insn, 29, 1);
6932 bool is_min = false;
6936 TCGv_i64 tcg_res, tcg_elt;
6939 case 0x1b: /* ADDV */
6941 unallocated_encoding(s);
6945 case 0x3: /* SADDLV, UADDLV */
6946 case 0xa: /* SMAXV, UMAXV */
6947 case 0x1a: /* SMINV, UMINV */
6948 if (size == 3 || (size == 2 && !is_q)) {
6949 unallocated_encoding(s);
6953 case 0xc: /* FMAXNMV, FMINNMV */
6954 case 0xf: /* FMAXV, FMINV */
6955 /* Bit 1 of size field encodes min vs max and the actual size
6956 * depends on the encoding of the U bit. If not set (and FP16
6957 * enabled) then we do half-precision float instead of single
6960 is_min = extract32(size, 1, 1);
6962 if (!is_u && dc_isar_feature(aa64_fp16, s)) {
6964 } else if (!is_u || !is_q || extract32(size, 0, 1)) {
6965 unallocated_encoding(s);
6972 unallocated_encoding(s);
6976 if (!fp_access_check(s)) {
6981 elements = (is_q ? 128 : 64) / esize;
6983 tcg_res = tcg_temp_new_i64();
6984 tcg_elt = tcg_temp_new_i64();
6986 /* These instructions operate across all lanes of a vector
6987 * to produce a single result. We can guarantee that a 64
6988 * bit intermediate is sufficient:
6989 * + for [US]ADDLV the maximum element size is 32 bits, and
6990 * the result type is 64 bits
6991 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
6992 * same as the element size, which is 32 bits at most
6993 * For the integer operations we can choose to work at 64
6994 * or 32 bits and truncate at the end; for simplicity
6995 * we use 64 bits always. The floating point
6996 * ops do require 32 bit intermediates, though.
6999 read_vec_element(s, tcg_res, rn, 0, size | (is_u ? 0 : MO_SIGN));
7001 for (i = 1; i < elements; i++) {
7002 read_vec_element(s, tcg_elt, rn, i, size | (is_u ? 0 : MO_SIGN));
7005 case 0x03: /* SADDLV / UADDLV */
7006 case 0x1b: /* ADDV */
7007 tcg_gen_add_i64(tcg_res, tcg_res, tcg_elt);
7009 case 0x0a: /* SMAXV / UMAXV */
7011 tcg_gen_umax_i64(tcg_res, tcg_res, tcg_elt);
7013 tcg_gen_smax_i64(tcg_res, tcg_res, tcg_elt);
7016 case 0x1a: /* SMINV / UMINV */
7018 tcg_gen_umin_i64(tcg_res, tcg_res, tcg_elt);
7020 tcg_gen_smin_i64(tcg_res, tcg_res, tcg_elt);
7024 g_assert_not_reached();
7029 /* Floating point vector reduction ops which work across 32
7030 * bit (single) or 16 bit (half-precision) intermediates.
7031 * Note that correct NaN propagation requires that we do these
7032 * operations in exactly the order specified by the pseudocode.
7034 TCGv_ptr fpst = get_fpstatus_ptr(size == MO_16);
7035 int fpopcode = opcode | is_min << 4 | is_u << 5;
7036 int vmap = (1 << elements) - 1;
7037 TCGv_i32 tcg_res32 = do_reduction_op(s, fpopcode, rn, esize,
7038 (is_q ? 128 : 64), vmap, fpst);
7039 tcg_gen_extu_i32_i64(tcg_res, tcg_res32);
7040 tcg_temp_free_i32(tcg_res32);
7041 tcg_temp_free_ptr(fpst);
7044 tcg_temp_free_i64(tcg_elt);
7046 /* Now truncate the result to the width required for the final output */
7047 if (opcode == 0x03) {
7048 /* SADDLV, UADDLV: result is 2*esize */
7054 tcg_gen_ext8u_i64(tcg_res, tcg_res);
7057 tcg_gen_ext16u_i64(tcg_res, tcg_res);
7060 tcg_gen_ext32u_i64(tcg_res, tcg_res);
7065 g_assert_not_reached();
7068 write_fp_dreg(s, rd, tcg_res);
7069 tcg_temp_free_i64(tcg_res);
7072 /* DUP (Element, Vector)
7074 * 31 30 29 21 20 16 15 10 9 5 4 0
7075 * +---+---+-------------------+--------+-------------+------+------+
7076 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7077 * +---+---+-------------------+--------+-------------+------+------+
7079 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7081 static void handle_simd_dupe(DisasContext *s, int is_q, int rd, int rn,
7084 int size = ctz32(imm5);
7085 int index = imm5 >> (size + 1);
7087 if (size > 3 || (size == 3 && !is_q)) {
7088 unallocated_encoding(s);
7092 if (!fp_access_check(s)) {
7096 tcg_gen_gvec_dup_mem(size, vec_full_reg_offset(s, rd),
7097 vec_reg_offset(s, rn, index, size),
7098 is_q ? 16 : 8, vec_full_reg_size(s));
7101 /* DUP (element, scalar)
7102 * 31 21 20 16 15 10 9 5 4 0
7103 * +-----------------------+--------+-------------+------+------+
7104 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7105 * +-----------------------+--------+-------------+------+------+
7107 static void handle_simd_dupes(DisasContext *s, int rd, int rn,
7110 int size = ctz32(imm5);
7115 unallocated_encoding(s);
7119 if (!fp_access_check(s)) {
7123 index = imm5 >> (size + 1);
7125 /* This instruction just extracts the specified element and
7126 * zero-extends it into the bottom of the destination register.
7128 tmp = tcg_temp_new_i64();
7129 read_vec_element(s, tmp, rn, index, size);
7130 write_fp_dreg(s, rd, tmp);
7131 tcg_temp_free_i64(tmp);
7136 * 31 30 29 21 20 16 15 10 9 5 4 0
7137 * +---+---+-------------------+--------+-------------+------+------+
7138 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
7139 * +---+---+-------------------+--------+-------------+------+------+
7141 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7143 static void handle_simd_dupg(DisasContext *s, int is_q, int rd, int rn,
7146 int size = ctz32(imm5);
7147 uint32_t dofs, oprsz, maxsz;
7149 if (size > 3 || ((size == 3) && !is_q)) {
7150 unallocated_encoding(s);
7154 if (!fp_access_check(s)) {
7158 dofs = vec_full_reg_offset(s, rd);
7159 oprsz = is_q ? 16 : 8;
7160 maxsz = vec_full_reg_size(s);
7162 tcg_gen_gvec_dup_i64(size, dofs, oprsz, maxsz, cpu_reg(s, rn));
7167 * 31 21 20 16 15 14 11 10 9 5 4 0
7168 * +-----------------------+--------+------------+---+------+------+
7169 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7170 * +-----------------------+--------+------------+---+------+------+
7172 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7173 * index: encoded in imm5<4:size+1>
7175 static void handle_simd_inse(DisasContext *s, int rd, int rn,
7178 int size = ctz32(imm5);
7179 int src_index, dst_index;
7183 unallocated_encoding(s);
7187 if (!fp_access_check(s)) {
7191 dst_index = extract32(imm5, 1+size, 5);
7192 src_index = extract32(imm4, size, 4);
7194 tmp = tcg_temp_new_i64();
7196 read_vec_element(s, tmp, rn, src_index, size);
7197 write_vec_element(s, tmp, rd, dst_index, size);
7199 tcg_temp_free_i64(tmp);
7205 * 31 21 20 16 15 10 9 5 4 0
7206 * +-----------------------+--------+-------------+------+------+
7207 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
7208 * +-----------------------+--------+-------------+------+------+
7210 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7211 * index: encoded in imm5<4:size+1>
7213 static void handle_simd_insg(DisasContext *s, int rd, int rn, int imm5)
7215 int size = ctz32(imm5);
7219 unallocated_encoding(s);
7223 if (!fp_access_check(s)) {
7227 idx = extract32(imm5, 1 + size, 4 - size);
7228 write_vec_element(s, cpu_reg(s, rn), rd, idx, size);
7235 * 31 30 29 21 20 16 15 12 10 9 5 4 0
7236 * +---+---+-------------------+--------+-------------+------+------+
7237 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
7238 * +---+---+-------------------+--------+-------------+------+------+
7240 * U: unsigned when set
7241 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7243 static void handle_simd_umov_smov(DisasContext *s, int is_q, int is_signed,
7244 int rn, int rd, int imm5)
7246 int size = ctz32(imm5);
7250 /* Check for UnallocatedEncodings */
7252 if (size > 2 || (size == 2 && !is_q)) {
7253 unallocated_encoding(s);
7258 || (size < 3 && is_q)
7259 || (size == 3 && !is_q)) {
7260 unallocated_encoding(s);
7265 if (!fp_access_check(s)) {
7269 element = extract32(imm5, 1+size, 4);
7271 tcg_rd = cpu_reg(s, rd);
7272 read_vec_element(s, tcg_rd, rn, element, size | (is_signed ? MO_SIGN : 0));
7273 if (is_signed && !is_q) {
7274 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
7279 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7280 * +---+---+----+-----------------+------+---+------+---+------+------+
7281 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7282 * +---+---+----+-----------------+------+---+------+---+------+------+
7284 static void disas_simd_copy(DisasContext *s, uint32_t insn)
7286 int rd = extract32(insn, 0, 5);
7287 int rn = extract32(insn, 5, 5);
7288 int imm4 = extract32(insn, 11, 4);
7289 int op = extract32(insn, 29, 1);
7290 int is_q = extract32(insn, 30, 1);
7291 int imm5 = extract32(insn, 16, 5);
7296 handle_simd_inse(s, rd, rn, imm4, imm5);
7298 unallocated_encoding(s);
7303 /* DUP (element - vector) */
7304 handle_simd_dupe(s, is_q, rd, rn, imm5);
7308 handle_simd_dupg(s, is_q, rd, rn, imm5);
7313 handle_simd_insg(s, rd, rn, imm5);
7315 unallocated_encoding(s);
7320 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
7321 handle_simd_umov_smov(s, is_q, (imm4 == 5), rn, rd, imm5);
7324 unallocated_encoding(s);
7330 /* AdvSIMD modified immediate
7331 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
7332 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7333 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
7334 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7336 * There are a number of operations that can be carried out here:
7337 * MOVI - move (shifted) imm into register
7338 * MVNI - move inverted (shifted) imm into register
7339 * ORR - bitwise OR of (shifted) imm with register
7340 * BIC - bitwise clear of (shifted) imm with register
7341 * With ARMv8.2 we also have:
7342 * FMOV half-precision
7344 static void disas_simd_mod_imm(DisasContext *s, uint32_t insn)
7346 int rd = extract32(insn, 0, 5);
7347 int cmode = extract32(insn, 12, 4);
7348 int cmode_3_1 = extract32(cmode, 1, 3);
7349 int cmode_0 = extract32(cmode, 0, 1);
7350 int o2 = extract32(insn, 11, 1);
7351 uint64_t abcdefgh = extract32(insn, 5, 5) | (extract32(insn, 16, 3) << 5);
7352 bool is_neg = extract32(insn, 29, 1);
7353 bool is_q = extract32(insn, 30, 1);
7356 if (o2 != 0 || ((cmode == 0xf) && is_neg && !is_q)) {
7357 /* Check for FMOV (vector, immediate) - half-precision */
7358 if (!(dc_isar_feature(aa64_fp16, s) && o2 && cmode == 0xf)) {
7359 unallocated_encoding(s);
7364 if (!fp_access_check(s)) {
7368 /* See AdvSIMDExpandImm() in ARM ARM */
7369 switch (cmode_3_1) {
7370 case 0: /* Replicate(Zeros(24):imm8, 2) */
7371 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
7372 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
7373 case 3: /* Replicate(imm8:Zeros(24), 2) */
7375 int shift = cmode_3_1 * 8;
7376 imm = bitfield_replicate(abcdefgh << shift, 32);
7379 case 4: /* Replicate(Zeros(8):imm8, 4) */
7380 case 5: /* Replicate(imm8:Zeros(8), 4) */
7382 int shift = (cmode_3_1 & 0x1) * 8;
7383 imm = bitfield_replicate(abcdefgh << shift, 16);
7388 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
7389 imm = (abcdefgh << 16) | 0xffff;
7391 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
7392 imm = (abcdefgh << 8) | 0xff;
7394 imm = bitfield_replicate(imm, 32);
7397 if (!cmode_0 && !is_neg) {
7398 imm = bitfield_replicate(abcdefgh, 8);
7399 } else if (!cmode_0 && is_neg) {
7402 for (i = 0; i < 8; i++) {
7403 if ((abcdefgh) & (1 << i)) {
7404 imm |= 0xffULL << (i * 8);
7407 } else if (cmode_0) {
7409 imm = (abcdefgh & 0x3f) << 48;
7410 if (abcdefgh & 0x80) {
7411 imm |= 0x8000000000000000ULL;
7413 if (abcdefgh & 0x40) {
7414 imm |= 0x3fc0000000000000ULL;
7416 imm |= 0x4000000000000000ULL;
7420 /* FMOV (vector, immediate) - half-precision */
7421 imm = vfp_expand_imm(MO_16, abcdefgh);
7422 /* now duplicate across the lanes */
7423 imm = bitfield_replicate(imm, 16);
7425 imm = (abcdefgh & 0x3f) << 19;
7426 if (abcdefgh & 0x80) {
7429 if (abcdefgh & 0x40) {
7440 fprintf(stderr, "%s: cmode_3_1: %x\n", __func__, cmode_3_1);
7441 g_assert_not_reached();
7444 if (cmode_3_1 != 7 && is_neg) {
7448 if (!((cmode & 0x9) == 0x1 || (cmode & 0xd) == 0x9)) {
7449 /* MOVI or MVNI, with MVNI negation handled above. */
7450 tcg_gen_gvec_dup64i(vec_full_reg_offset(s, rd), is_q ? 16 : 8,
7451 vec_full_reg_size(s), imm);
7453 /* ORR or BIC, with BIC negation to AND handled above. */
7455 gen_gvec_fn2i(s, is_q, rd, rd, imm, tcg_gen_gvec_andi, MO_64);
7457 gen_gvec_fn2i(s, is_q, rd, rd, imm, tcg_gen_gvec_ori, MO_64);
7462 /* AdvSIMD scalar copy
7463 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7464 * +-----+----+-----------------+------+---+------+---+------+------+
7465 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7466 * +-----+----+-----------------+------+---+------+---+------+------+
7468 static void disas_simd_scalar_copy(DisasContext *s, uint32_t insn)
7470 int rd = extract32(insn, 0, 5);
7471 int rn = extract32(insn, 5, 5);
7472 int imm4 = extract32(insn, 11, 4);
7473 int imm5 = extract32(insn, 16, 5);
7474 int op = extract32(insn, 29, 1);
7476 if (op != 0 || imm4 != 0) {
7477 unallocated_encoding(s);
7481 /* DUP (element, scalar) */
7482 handle_simd_dupes(s, rd, rn, imm5);
7485 /* AdvSIMD scalar pairwise
7486 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7487 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7488 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7489 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7491 static void disas_simd_scalar_pairwise(DisasContext *s, uint32_t insn)
7493 int u = extract32(insn, 29, 1);
7494 int size = extract32(insn, 22, 2);
7495 int opcode = extract32(insn, 12, 5);
7496 int rn = extract32(insn, 5, 5);
7497 int rd = extract32(insn, 0, 5);
7500 /* For some ops (the FP ones), size[1] is part of the encoding.
7501 * For ADDP strictly it is not but size[1] is always 1 for valid
7504 opcode |= (extract32(size, 1, 1) << 5);
7507 case 0x3b: /* ADDP */
7508 if (u || size != 3) {
7509 unallocated_encoding(s);
7512 if (!fp_access_check(s)) {
7518 case 0xc: /* FMAXNMP */
7519 case 0xd: /* FADDP */
7520 case 0xf: /* FMAXP */
7521 case 0x2c: /* FMINNMP */
7522 case 0x2f: /* FMINP */
7523 /* FP op, size[0] is 32 or 64 bit*/
7525 if (!dc_isar_feature(aa64_fp16, s)) {
7526 unallocated_encoding(s);
7532 size = extract32(size, 0, 1) ? MO_64 : MO_32;
7535 if (!fp_access_check(s)) {
7539 fpst = get_fpstatus_ptr(size == MO_16);
7542 unallocated_encoding(s);
7546 if (size == MO_64) {
7547 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
7548 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
7549 TCGv_i64 tcg_res = tcg_temp_new_i64();
7551 read_vec_element(s, tcg_op1, rn, 0, MO_64);
7552 read_vec_element(s, tcg_op2, rn, 1, MO_64);
7555 case 0x3b: /* ADDP */
7556 tcg_gen_add_i64(tcg_res, tcg_op1, tcg_op2);
7558 case 0xc: /* FMAXNMP */
7559 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
7561 case 0xd: /* FADDP */
7562 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
7564 case 0xf: /* FMAXP */
7565 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
7567 case 0x2c: /* FMINNMP */
7568 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
7570 case 0x2f: /* FMINP */
7571 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
7574 g_assert_not_reached();
7577 write_fp_dreg(s, rd, tcg_res);
7579 tcg_temp_free_i64(tcg_op1);
7580 tcg_temp_free_i64(tcg_op2);
7581 tcg_temp_free_i64(tcg_res);
7583 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
7584 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
7585 TCGv_i32 tcg_res = tcg_temp_new_i32();
7587 read_vec_element_i32(s, tcg_op1, rn, 0, size);
7588 read_vec_element_i32(s, tcg_op2, rn, 1, size);
7590 if (size == MO_16) {
7592 case 0xc: /* FMAXNMP */
7593 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
7595 case 0xd: /* FADDP */
7596 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
7598 case 0xf: /* FMAXP */
7599 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
7601 case 0x2c: /* FMINNMP */
7602 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
7604 case 0x2f: /* FMINP */
7605 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
7608 g_assert_not_reached();
7612 case 0xc: /* FMAXNMP */
7613 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
7615 case 0xd: /* FADDP */
7616 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
7618 case 0xf: /* FMAXP */
7619 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
7621 case 0x2c: /* FMINNMP */
7622 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
7624 case 0x2f: /* FMINP */
7625 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
7628 g_assert_not_reached();
7632 write_fp_sreg(s, rd, tcg_res);
7634 tcg_temp_free_i32(tcg_op1);
7635 tcg_temp_free_i32(tcg_op2);
7636 tcg_temp_free_i32(tcg_res);
7640 tcg_temp_free_ptr(fpst);
7645 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
7647 * This code is handles the common shifting code and is used by both
7648 * the vector and scalar code.
7650 static void handle_shri_with_rndacc(TCGv_i64 tcg_res, TCGv_i64 tcg_src,
7651 TCGv_i64 tcg_rnd, bool accumulate,
7652 bool is_u, int size, int shift)
7654 bool extended_result = false;
7655 bool round = tcg_rnd != NULL;
7657 TCGv_i64 tcg_src_hi;
7659 if (round && size == 3) {
7660 extended_result = true;
7661 ext_lshift = 64 - shift;
7662 tcg_src_hi = tcg_temp_new_i64();
7663 } else if (shift == 64) {
7664 if (!accumulate && is_u) {
7665 /* result is zero */
7666 tcg_gen_movi_i64(tcg_res, 0);
7671 /* Deal with the rounding step */
7673 if (extended_result) {
7674 TCGv_i64 tcg_zero = tcg_const_i64(0);
7676 /* take care of sign extending tcg_res */
7677 tcg_gen_sari_i64(tcg_src_hi, tcg_src, 63);
7678 tcg_gen_add2_i64(tcg_src, tcg_src_hi,
7679 tcg_src, tcg_src_hi,
7682 tcg_gen_add2_i64(tcg_src, tcg_src_hi,
7686 tcg_temp_free_i64(tcg_zero);
7688 tcg_gen_add_i64(tcg_src, tcg_src, tcg_rnd);
7692 /* Now do the shift right */
7693 if (round && extended_result) {
7694 /* extended case, >64 bit precision required */
7695 if (ext_lshift == 0) {
7696 /* special case, only high bits matter */
7697 tcg_gen_mov_i64(tcg_src, tcg_src_hi);
7699 tcg_gen_shri_i64(tcg_src, tcg_src, shift);
7700 tcg_gen_shli_i64(tcg_src_hi, tcg_src_hi, ext_lshift);
7701 tcg_gen_or_i64(tcg_src, tcg_src, tcg_src_hi);
7706 /* essentially shifting in 64 zeros */
7707 tcg_gen_movi_i64(tcg_src, 0);
7709 tcg_gen_shri_i64(tcg_src, tcg_src, shift);
7713 /* effectively extending the sign-bit */
7714 tcg_gen_sari_i64(tcg_src, tcg_src, 63);
7716 tcg_gen_sari_i64(tcg_src, tcg_src, shift);
7722 tcg_gen_add_i64(tcg_res, tcg_res, tcg_src);
7724 tcg_gen_mov_i64(tcg_res, tcg_src);
7727 if (extended_result) {
7728 tcg_temp_free_i64(tcg_src_hi);
7732 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
7733 static void handle_scalar_simd_shri(DisasContext *s,
7734 bool is_u, int immh, int immb,
7735 int opcode, int rn, int rd)
7738 int immhb = immh << 3 | immb;
7739 int shift = 2 * (8 << size) - immhb;
7740 bool accumulate = false;
7742 bool insert = false;
7747 if (!extract32(immh, 3, 1)) {
7748 unallocated_encoding(s);
7752 if (!fp_access_check(s)) {
7757 case 0x02: /* SSRA / USRA (accumulate) */
7760 case 0x04: /* SRSHR / URSHR (rounding) */
7763 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7764 accumulate = round = true;
7766 case 0x08: /* SRI */
7772 uint64_t round_const = 1ULL << (shift - 1);
7773 tcg_round = tcg_const_i64(round_const);
7778 tcg_rn = read_fp_dreg(s, rn);
7779 tcg_rd = (accumulate || insert) ? read_fp_dreg(s, rd) : tcg_temp_new_i64();
7782 /* shift count same as element size is valid but does nothing;
7783 * special case to avoid potential shift by 64.
7785 int esize = 8 << size;
7786 if (shift != esize) {
7787 tcg_gen_shri_i64(tcg_rn, tcg_rn, shift);
7788 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, 0, esize - shift);
7791 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
7792 accumulate, is_u, size, shift);
7795 write_fp_dreg(s, rd, tcg_rd);
7797 tcg_temp_free_i64(tcg_rn);
7798 tcg_temp_free_i64(tcg_rd);
7800 tcg_temp_free_i64(tcg_round);
7804 /* SHL/SLI - Scalar shift left */
7805 static void handle_scalar_simd_shli(DisasContext *s, bool insert,
7806 int immh, int immb, int opcode,
7809 int size = 32 - clz32(immh) - 1;
7810 int immhb = immh << 3 | immb;
7811 int shift = immhb - (8 << size);
7812 TCGv_i64 tcg_rn = new_tmp_a64(s);
7813 TCGv_i64 tcg_rd = new_tmp_a64(s);
7815 if (!extract32(immh, 3, 1)) {
7816 unallocated_encoding(s);
7820 if (!fp_access_check(s)) {
7824 tcg_rn = read_fp_dreg(s, rn);
7825 tcg_rd = insert ? read_fp_dreg(s, rd) : tcg_temp_new_i64();
7828 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, shift, 64 - shift);
7830 tcg_gen_shli_i64(tcg_rd, tcg_rn, shift);
7833 write_fp_dreg(s, rd, tcg_rd);
7835 tcg_temp_free_i64(tcg_rn);
7836 tcg_temp_free_i64(tcg_rd);
7839 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
7840 * (signed/unsigned) narrowing */
7841 static void handle_vec_simd_sqshrn(DisasContext *s, bool is_scalar, bool is_q,
7842 bool is_u_shift, bool is_u_narrow,
7843 int immh, int immb, int opcode,
7846 int immhb = immh << 3 | immb;
7847 int size = 32 - clz32(immh) - 1;
7848 int esize = 8 << size;
7849 int shift = (2 * esize) - immhb;
7850 int elements = is_scalar ? 1 : (64 / esize);
7851 bool round = extract32(opcode, 0, 1);
7852 TCGMemOp ldop = (size + 1) | (is_u_shift ? 0 : MO_SIGN);
7853 TCGv_i64 tcg_rn, tcg_rd, tcg_round;
7854 TCGv_i32 tcg_rd_narrowed;
7857 static NeonGenNarrowEnvFn * const signed_narrow_fns[4][2] = {
7858 { gen_helper_neon_narrow_sat_s8,
7859 gen_helper_neon_unarrow_sat8 },
7860 { gen_helper_neon_narrow_sat_s16,
7861 gen_helper_neon_unarrow_sat16 },
7862 { gen_helper_neon_narrow_sat_s32,
7863 gen_helper_neon_unarrow_sat32 },
7866 static NeonGenNarrowEnvFn * const unsigned_narrow_fns[4] = {
7867 gen_helper_neon_narrow_sat_u8,
7868 gen_helper_neon_narrow_sat_u16,
7869 gen_helper_neon_narrow_sat_u32,
7872 NeonGenNarrowEnvFn *narrowfn;
7878 if (extract32(immh, 3, 1)) {
7879 unallocated_encoding(s);
7883 if (!fp_access_check(s)) {
7888 narrowfn = unsigned_narrow_fns[size];
7890 narrowfn = signed_narrow_fns[size][is_u_narrow ? 1 : 0];
7893 tcg_rn = tcg_temp_new_i64();
7894 tcg_rd = tcg_temp_new_i64();
7895 tcg_rd_narrowed = tcg_temp_new_i32();
7896 tcg_final = tcg_const_i64(0);
7899 uint64_t round_const = 1ULL << (shift - 1);
7900 tcg_round = tcg_const_i64(round_const);
7905 for (i = 0; i < elements; i++) {
7906 read_vec_element(s, tcg_rn, rn, i, ldop);
7907 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
7908 false, is_u_shift, size+1, shift);
7909 narrowfn(tcg_rd_narrowed, cpu_env, tcg_rd);
7910 tcg_gen_extu_i32_i64(tcg_rd, tcg_rd_narrowed);
7911 tcg_gen_deposit_i64(tcg_final, tcg_final, tcg_rd, esize * i, esize);
7915 write_vec_element(s, tcg_final, rd, 0, MO_64);
7917 write_vec_element(s, tcg_final, rd, 1, MO_64);
7921 tcg_temp_free_i64(tcg_round);
7923 tcg_temp_free_i64(tcg_rn);
7924 tcg_temp_free_i64(tcg_rd);
7925 tcg_temp_free_i32(tcg_rd_narrowed);
7926 tcg_temp_free_i64(tcg_final);
7928 clear_vec_high(s, is_q, rd);
7931 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
7932 static void handle_simd_qshl(DisasContext *s, bool scalar, bool is_q,
7933 bool src_unsigned, bool dst_unsigned,
7934 int immh, int immb, int rn, int rd)
7936 int immhb = immh << 3 | immb;
7937 int size = 32 - clz32(immh) - 1;
7938 int shift = immhb - (8 << size);
7942 assert(!(scalar && is_q));
7945 if (!is_q && extract32(immh, 3, 1)) {
7946 unallocated_encoding(s);
7950 /* Since we use the variable-shift helpers we must
7951 * replicate the shift count into each element of
7952 * the tcg_shift value.
7956 shift |= shift << 8;
7959 shift |= shift << 16;
7965 g_assert_not_reached();
7969 if (!fp_access_check(s)) {
7974 TCGv_i64 tcg_shift = tcg_const_i64(shift);
7975 static NeonGenTwo64OpEnvFn * const fns[2][2] = {
7976 { gen_helper_neon_qshl_s64, gen_helper_neon_qshlu_s64 },
7977 { NULL, gen_helper_neon_qshl_u64 },
7979 NeonGenTwo64OpEnvFn *genfn = fns[src_unsigned][dst_unsigned];
7980 int maxpass = is_q ? 2 : 1;
7982 for (pass = 0; pass < maxpass; pass++) {
7983 TCGv_i64 tcg_op = tcg_temp_new_i64();
7985 read_vec_element(s, tcg_op, rn, pass, MO_64);
7986 genfn(tcg_op, cpu_env, tcg_op, tcg_shift);
7987 write_vec_element(s, tcg_op, rd, pass, MO_64);
7989 tcg_temp_free_i64(tcg_op);
7991 tcg_temp_free_i64(tcg_shift);
7992 clear_vec_high(s, is_q, rd);
7994 TCGv_i32 tcg_shift = tcg_const_i32(shift);
7995 static NeonGenTwoOpEnvFn * const fns[2][2][3] = {
7997 { gen_helper_neon_qshl_s8,
7998 gen_helper_neon_qshl_s16,
7999 gen_helper_neon_qshl_s32 },
8000 { gen_helper_neon_qshlu_s8,
8001 gen_helper_neon_qshlu_s16,
8002 gen_helper_neon_qshlu_s32 }
8004 { NULL, NULL, NULL },
8005 { gen_helper_neon_qshl_u8,
8006 gen_helper_neon_qshl_u16,
8007 gen_helper_neon_qshl_u32 }
8010 NeonGenTwoOpEnvFn *genfn = fns[src_unsigned][dst_unsigned][size];
8011 TCGMemOp memop = scalar ? size : MO_32;
8012 int maxpass = scalar ? 1 : is_q ? 4 : 2;
8014 for (pass = 0; pass < maxpass; pass++) {
8015 TCGv_i32 tcg_op = tcg_temp_new_i32();
8017 read_vec_element_i32(s, tcg_op, rn, pass, memop);
8018 genfn(tcg_op, cpu_env, tcg_op, tcg_shift);
8022 tcg_gen_ext8u_i32(tcg_op, tcg_op);
8025 tcg_gen_ext16u_i32(tcg_op, tcg_op);
8030 g_assert_not_reached();
8032 write_fp_sreg(s, rd, tcg_op);
8034 write_vec_element_i32(s, tcg_op, rd, pass, MO_32);
8037 tcg_temp_free_i32(tcg_op);
8039 tcg_temp_free_i32(tcg_shift);
8042 clear_vec_high(s, is_q, rd);
8047 /* Common vector code for handling integer to FP conversion */
8048 static void handle_simd_intfp_conv(DisasContext *s, int rd, int rn,
8049 int elements, int is_signed,
8050 int fracbits, int size)
8052 TCGv_ptr tcg_fpst = get_fpstatus_ptr(size == MO_16);
8053 TCGv_i32 tcg_shift = NULL;
8055 TCGMemOp mop = size | (is_signed ? MO_SIGN : 0);
8058 if (fracbits || size == MO_64) {
8059 tcg_shift = tcg_const_i32(fracbits);
8062 if (size == MO_64) {
8063 TCGv_i64 tcg_int64 = tcg_temp_new_i64();
8064 TCGv_i64 tcg_double = tcg_temp_new_i64();
8066 for (pass = 0; pass < elements; pass++) {
8067 read_vec_element(s, tcg_int64, rn, pass, mop);
8070 gen_helper_vfp_sqtod(tcg_double, tcg_int64,
8071 tcg_shift, tcg_fpst);
8073 gen_helper_vfp_uqtod(tcg_double, tcg_int64,
8074 tcg_shift, tcg_fpst);
8076 if (elements == 1) {
8077 write_fp_dreg(s, rd, tcg_double);
8079 write_vec_element(s, tcg_double, rd, pass, MO_64);
8083 tcg_temp_free_i64(tcg_int64);
8084 tcg_temp_free_i64(tcg_double);
8087 TCGv_i32 tcg_int32 = tcg_temp_new_i32();
8088 TCGv_i32 tcg_float = tcg_temp_new_i32();
8090 for (pass = 0; pass < elements; pass++) {
8091 read_vec_element_i32(s, tcg_int32, rn, pass, mop);
8097 gen_helper_vfp_sltos(tcg_float, tcg_int32,
8098 tcg_shift, tcg_fpst);
8100 gen_helper_vfp_ultos(tcg_float, tcg_int32,
8101 tcg_shift, tcg_fpst);
8105 gen_helper_vfp_sitos(tcg_float, tcg_int32, tcg_fpst);
8107 gen_helper_vfp_uitos(tcg_float, tcg_int32, tcg_fpst);
8114 gen_helper_vfp_sltoh(tcg_float, tcg_int32,
8115 tcg_shift, tcg_fpst);
8117 gen_helper_vfp_ultoh(tcg_float, tcg_int32,
8118 tcg_shift, tcg_fpst);
8122 gen_helper_vfp_sitoh(tcg_float, tcg_int32, tcg_fpst);
8124 gen_helper_vfp_uitoh(tcg_float, tcg_int32, tcg_fpst);
8129 g_assert_not_reached();
8132 if (elements == 1) {
8133 write_fp_sreg(s, rd, tcg_float);
8135 write_vec_element_i32(s, tcg_float, rd, pass, size);
8139 tcg_temp_free_i32(tcg_int32);
8140 tcg_temp_free_i32(tcg_float);
8143 tcg_temp_free_ptr(tcg_fpst);
8145 tcg_temp_free_i32(tcg_shift);
8148 clear_vec_high(s, elements << size == 16, rd);
8151 /* UCVTF/SCVTF - Integer to FP conversion */
8152 static void handle_simd_shift_intfp_conv(DisasContext *s, bool is_scalar,
8153 bool is_q, bool is_u,
8154 int immh, int immb, int opcode,
8157 int size, elements, fracbits;
8158 int immhb = immh << 3 | immb;
8162 if (!is_scalar && !is_q) {
8163 unallocated_encoding(s);
8166 } else if (immh & 4) {
8168 } else if (immh & 2) {
8170 if (!dc_isar_feature(aa64_fp16, s)) {
8171 unallocated_encoding(s);
8175 /* immh == 0 would be a failure of the decode logic */
8176 g_assert(immh == 1);
8177 unallocated_encoding(s);
8184 elements = (8 << is_q) >> size;
8186 fracbits = (16 << size) - immhb;
8188 if (!fp_access_check(s)) {
8192 handle_simd_intfp_conv(s, rd, rn, elements, !is_u, fracbits, size);
8195 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
8196 static void handle_simd_shift_fpint_conv(DisasContext *s, bool is_scalar,
8197 bool is_q, bool is_u,
8198 int immh, int immb, int rn, int rd)
8200 int immhb = immh << 3 | immb;
8201 int pass, size, fracbits;
8202 TCGv_ptr tcg_fpstatus;
8203 TCGv_i32 tcg_rmode, tcg_shift;
8207 if (!is_scalar && !is_q) {
8208 unallocated_encoding(s);
8211 } else if (immh & 0x4) {
8213 } else if (immh & 0x2) {
8215 if (!dc_isar_feature(aa64_fp16, s)) {
8216 unallocated_encoding(s);
8220 /* Should have split out AdvSIMD modified immediate earlier. */
8222 unallocated_encoding(s);
8226 if (!fp_access_check(s)) {
8230 assert(!(is_scalar && is_q));
8232 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO));
8233 tcg_fpstatus = get_fpstatus_ptr(size == MO_16);
8234 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
8235 fracbits = (16 << size) - immhb;
8236 tcg_shift = tcg_const_i32(fracbits);
8238 if (size == MO_64) {
8239 int maxpass = is_scalar ? 1 : 2;
8241 for (pass = 0; pass < maxpass; pass++) {
8242 TCGv_i64 tcg_op = tcg_temp_new_i64();
8244 read_vec_element(s, tcg_op, rn, pass, MO_64);
8246 gen_helper_vfp_touqd(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8248 gen_helper_vfp_tosqd(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8250 write_vec_element(s, tcg_op, rd, pass, MO_64);
8251 tcg_temp_free_i64(tcg_op);
8253 clear_vec_high(s, is_q, rd);
8255 void (*fn)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_ptr);
8256 int maxpass = is_scalar ? 1 : ((8 << is_q) >> size);
8261 fn = gen_helper_vfp_touhh;
8263 fn = gen_helper_vfp_toshh;
8268 fn = gen_helper_vfp_touls;
8270 fn = gen_helper_vfp_tosls;
8274 g_assert_not_reached();
8277 for (pass = 0; pass < maxpass; pass++) {
8278 TCGv_i32 tcg_op = tcg_temp_new_i32();
8280 read_vec_element_i32(s, tcg_op, rn, pass, size);
8281 fn(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8283 write_fp_sreg(s, rd, tcg_op);
8285 write_vec_element_i32(s, tcg_op, rd, pass, size);
8287 tcg_temp_free_i32(tcg_op);
8290 clear_vec_high(s, is_q, rd);
8294 tcg_temp_free_ptr(tcg_fpstatus);
8295 tcg_temp_free_i32(tcg_shift);
8296 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
8297 tcg_temp_free_i32(tcg_rmode);
8300 /* AdvSIMD scalar shift by immediate
8301 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8302 * +-----+---+-------------+------+------+--------+---+------+------+
8303 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8304 * +-----+---+-------------+------+------+--------+---+------+------+
8306 * This is the scalar version so it works on a fixed sized registers
8308 static void disas_simd_scalar_shift_imm(DisasContext *s, uint32_t insn)
8310 int rd = extract32(insn, 0, 5);
8311 int rn = extract32(insn, 5, 5);
8312 int opcode = extract32(insn, 11, 5);
8313 int immb = extract32(insn, 16, 3);
8314 int immh = extract32(insn, 19, 4);
8315 bool is_u = extract32(insn, 29, 1);
8318 unallocated_encoding(s);
8323 case 0x08: /* SRI */
8325 unallocated_encoding(s);
8329 case 0x00: /* SSHR / USHR */
8330 case 0x02: /* SSRA / USRA */
8331 case 0x04: /* SRSHR / URSHR */
8332 case 0x06: /* SRSRA / URSRA */
8333 handle_scalar_simd_shri(s, is_u, immh, immb, opcode, rn, rd);
8335 case 0x0a: /* SHL / SLI */
8336 handle_scalar_simd_shli(s, is_u, immh, immb, opcode, rn, rd);
8338 case 0x1c: /* SCVTF, UCVTF */
8339 handle_simd_shift_intfp_conv(s, true, false, is_u, immh, immb,
8342 case 0x10: /* SQSHRUN, SQSHRUN2 */
8343 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
8345 unallocated_encoding(s);
8348 handle_vec_simd_sqshrn(s, true, false, false, true,
8349 immh, immb, opcode, rn, rd);
8351 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
8352 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
8353 handle_vec_simd_sqshrn(s, true, false, is_u, is_u,
8354 immh, immb, opcode, rn, rd);
8356 case 0xc: /* SQSHLU */
8358 unallocated_encoding(s);
8361 handle_simd_qshl(s, true, false, false, true, immh, immb, rn, rd);
8363 case 0xe: /* SQSHL, UQSHL */
8364 handle_simd_qshl(s, true, false, is_u, is_u, immh, immb, rn, rd);
8366 case 0x1f: /* FCVTZS, FCVTZU */
8367 handle_simd_shift_fpint_conv(s, true, false, is_u, immh, immb, rn, rd);
8370 unallocated_encoding(s);
8375 /* AdvSIMD scalar three different
8376 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8377 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8378 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8379 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8381 static void disas_simd_scalar_three_reg_diff(DisasContext *s, uint32_t insn)
8383 bool is_u = extract32(insn, 29, 1);
8384 int size = extract32(insn, 22, 2);
8385 int opcode = extract32(insn, 12, 4);
8386 int rm = extract32(insn, 16, 5);
8387 int rn = extract32(insn, 5, 5);
8388 int rd = extract32(insn, 0, 5);
8391 unallocated_encoding(s);
8396 case 0x9: /* SQDMLAL, SQDMLAL2 */
8397 case 0xb: /* SQDMLSL, SQDMLSL2 */
8398 case 0xd: /* SQDMULL, SQDMULL2 */
8399 if (size == 0 || size == 3) {
8400 unallocated_encoding(s);
8405 unallocated_encoding(s);
8409 if (!fp_access_check(s)) {
8414 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8415 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8416 TCGv_i64 tcg_res = tcg_temp_new_i64();
8418 read_vec_element(s, tcg_op1, rn, 0, MO_32 | MO_SIGN);
8419 read_vec_element(s, tcg_op2, rm, 0, MO_32 | MO_SIGN);
8421 tcg_gen_mul_i64(tcg_res, tcg_op1, tcg_op2);
8422 gen_helper_neon_addl_saturate_s64(tcg_res, cpu_env, tcg_res, tcg_res);
8425 case 0xd: /* SQDMULL, SQDMULL2 */
8427 case 0xb: /* SQDMLSL, SQDMLSL2 */
8428 tcg_gen_neg_i64(tcg_res, tcg_res);
8430 case 0x9: /* SQDMLAL, SQDMLAL2 */
8431 read_vec_element(s, tcg_op1, rd, 0, MO_64);
8432 gen_helper_neon_addl_saturate_s64(tcg_res, cpu_env,
8436 g_assert_not_reached();
8439 write_fp_dreg(s, rd, tcg_res);
8441 tcg_temp_free_i64(tcg_op1);
8442 tcg_temp_free_i64(tcg_op2);
8443 tcg_temp_free_i64(tcg_res);
8445 TCGv_i32 tcg_op1 = read_fp_hreg(s, rn);
8446 TCGv_i32 tcg_op2 = read_fp_hreg(s, rm);
8447 TCGv_i64 tcg_res = tcg_temp_new_i64();
8449 gen_helper_neon_mull_s16(tcg_res, tcg_op1, tcg_op2);
8450 gen_helper_neon_addl_saturate_s32(tcg_res, cpu_env, tcg_res, tcg_res);
8453 case 0xd: /* SQDMULL, SQDMULL2 */
8455 case 0xb: /* SQDMLSL, SQDMLSL2 */
8456 gen_helper_neon_negl_u32(tcg_res, tcg_res);
8458 case 0x9: /* SQDMLAL, SQDMLAL2 */
8460 TCGv_i64 tcg_op3 = tcg_temp_new_i64();
8461 read_vec_element(s, tcg_op3, rd, 0, MO_32);
8462 gen_helper_neon_addl_saturate_s32(tcg_res, cpu_env,
8464 tcg_temp_free_i64(tcg_op3);
8468 g_assert_not_reached();
8471 tcg_gen_ext32u_i64(tcg_res, tcg_res);
8472 write_fp_dreg(s, rd, tcg_res);
8474 tcg_temp_free_i32(tcg_op1);
8475 tcg_temp_free_i32(tcg_op2);
8476 tcg_temp_free_i64(tcg_res);
8480 static void handle_3same_64(DisasContext *s, int opcode, bool u,
8481 TCGv_i64 tcg_rd, TCGv_i64 tcg_rn, TCGv_i64 tcg_rm)
8483 /* Handle 64x64->64 opcodes which are shared between the scalar
8484 * and vector 3-same groups. We cover every opcode where size == 3
8485 * is valid in either the three-reg-same (integer, not pairwise)
8486 * or scalar-three-reg-same groups.
8491 case 0x1: /* SQADD */
8493 gen_helper_neon_qadd_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8495 gen_helper_neon_qadd_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8498 case 0x5: /* SQSUB */
8500 gen_helper_neon_qsub_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8502 gen_helper_neon_qsub_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8505 case 0x6: /* CMGT, CMHI */
8506 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
8507 * We implement this using setcond (test) and then negating.
8509 cond = u ? TCG_COND_GTU : TCG_COND_GT;
8511 tcg_gen_setcond_i64(cond, tcg_rd, tcg_rn, tcg_rm);
8512 tcg_gen_neg_i64(tcg_rd, tcg_rd);
8514 case 0x7: /* CMGE, CMHS */
8515 cond = u ? TCG_COND_GEU : TCG_COND_GE;
8517 case 0x11: /* CMTST, CMEQ */
8522 gen_cmtst_i64(tcg_rd, tcg_rn, tcg_rm);
8524 case 0x8: /* SSHL, USHL */
8526 gen_helper_neon_shl_u64(tcg_rd, tcg_rn, tcg_rm);
8528 gen_helper_neon_shl_s64(tcg_rd, tcg_rn, tcg_rm);
8531 case 0x9: /* SQSHL, UQSHL */
8533 gen_helper_neon_qshl_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8535 gen_helper_neon_qshl_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8538 case 0xa: /* SRSHL, URSHL */
8540 gen_helper_neon_rshl_u64(tcg_rd, tcg_rn, tcg_rm);
8542 gen_helper_neon_rshl_s64(tcg_rd, tcg_rn, tcg_rm);
8545 case 0xb: /* SQRSHL, UQRSHL */
8547 gen_helper_neon_qrshl_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8549 gen_helper_neon_qrshl_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8552 case 0x10: /* ADD, SUB */
8554 tcg_gen_sub_i64(tcg_rd, tcg_rn, tcg_rm);
8556 tcg_gen_add_i64(tcg_rd, tcg_rn, tcg_rm);
8560 g_assert_not_reached();
8564 /* Handle the 3-same-operands float operations; shared by the scalar
8565 * and vector encodings. The caller must filter out any encodings
8566 * not allocated for the encoding it is dealing with.
8568 static void handle_3same_float(DisasContext *s, int size, int elements,
8569 int fpopcode, int rd, int rn, int rm)
8572 TCGv_ptr fpst = get_fpstatus_ptr(false);
8574 for (pass = 0; pass < elements; pass++) {
8577 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8578 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8579 TCGv_i64 tcg_res = tcg_temp_new_i64();
8581 read_vec_element(s, tcg_op1, rn, pass, MO_64);
8582 read_vec_element(s, tcg_op2, rm, pass, MO_64);
8585 case 0x39: /* FMLS */
8586 /* As usual for ARM, separate negation for fused multiply-add */
8587 gen_helper_vfp_negd(tcg_op1, tcg_op1);
8589 case 0x19: /* FMLA */
8590 read_vec_element(s, tcg_res, rd, pass, MO_64);
8591 gen_helper_vfp_muladdd(tcg_res, tcg_op1, tcg_op2,
8594 case 0x18: /* FMAXNM */
8595 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
8597 case 0x1a: /* FADD */
8598 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
8600 case 0x1b: /* FMULX */
8601 gen_helper_vfp_mulxd(tcg_res, tcg_op1, tcg_op2, fpst);
8603 case 0x1c: /* FCMEQ */
8604 gen_helper_neon_ceq_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8606 case 0x1e: /* FMAX */
8607 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
8609 case 0x1f: /* FRECPS */
8610 gen_helper_recpsf_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8612 case 0x38: /* FMINNM */
8613 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
8615 case 0x3a: /* FSUB */
8616 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
8618 case 0x3e: /* FMIN */
8619 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
8621 case 0x3f: /* FRSQRTS */
8622 gen_helper_rsqrtsf_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8624 case 0x5b: /* FMUL */
8625 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
8627 case 0x5c: /* FCMGE */
8628 gen_helper_neon_cge_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8630 case 0x5d: /* FACGE */
8631 gen_helper_neon_acge_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8633 case 0x5f: /* FDIV */
8634 gen_helper_vfp_divd(tcg_res, tcg_op1, tcg_op2, fpst);
8636 case 0x7a: /* FABD */
8637 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
8638 gen_helper_vfp_absd(tcg_res, tcg_res);
8640 case 0x7c: /* FCMGT */
8641 gen_helper_neon_cgt_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8643 case 0x7d: /* FACGT */
8644 gen_helper_neon_acgt_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8647 g_assert_not_reached();
8650 write_vec_element(s, tcg_res, rd, pass, MO_64);
8652 tcg_temp_free_i64(tcg_res);
8653 tcg_temp_free_i64(tcg_op1);
8654 tcg_temp_free_i64(tcg_op2);
8657 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
8658 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
8659 TCGv_i32 tcg_res = tcg_temp_new_i32();
8661 read_vec_element_i32(s, tcg_op1, rn, pass, MO_32);
8662 read_vec_element_i32(s, tcg_op2, rm, pass, MO_32);
8665 case 0x39: /* FMLS */
8666 /* As usual for ARM, separate negation for fused multiply-add */
8667 gen_helper_vfp_negs(tcg_op1, tcg_op1);
8669 case 0x19: /* FMLA */
8670 read_vec_element_i32(s, tcg_res, rd, pass, MO_32);
8671 gen_helper_vfp_muladds(tcg_res, tcg_op1, tcg_op2,
8674 case 0x1a: /* FADD */
8675 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
8677 case 0x1b: /* FMULX */
8678 gen_helper_vfp_mulxs(tcg_res, tcg_op1, tcg_op2, fpst);
8680 case 0x1c: /* FCMEQ */
8681 gen_helper_neon_ceq_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8683 case 0x1e: /* FMAX */
8684 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
8686 case 0x1f: /* FRECPS */
8687 gen_helper_recpsf_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8689 case 0x18: /* FMAXNM */
8690 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
8692 case 0x38: /* FMINNM */
8693 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
8695 case 0x3a: /* FSUB */
8696 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
8698 case 0x3e: /* FMIN */
8699 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
8701 case 0x3f: /* FRSQRTS */
8702 gen_helper_rsqrtsf_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8704 case 0x5b: /* FMUL */
8705 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
8707 case 0x5c: /* FCMGE */
8708 gen_helper_neon_cge_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8710 case 0x5d: /* FACGE */
8711 gen_helper_neon_acge_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8713 case 0x5f: /* FDIV */
8714 gen_helper_vfp_divs(tcg_res, tcg_op1, tcg_op2, fpst);
8716 case 0x7a: /* FABD */
8717 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
8718 gen_helper_vfp_abss(tcg_res, tcg_res);
8720 case 0x7c: /* FCMGT */
8721 gen_helper_neon_cgt_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8723 case 0x7d: /* FACGT */
8724 gen_helper_neon_acgt_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8727 g_assert_not_reached();
8730 if (elements == 1) {
8731 /* scalar single so clear high part */
8732 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
8734 tcg_gen_extu_i32_i64(tcg_tmp, tcg_res);
8735 write_vec_element(s, tcg_tmp, rd, pass, MO_64);
8736 tcg_temp_free_i64(tcg_tmp);
8738 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
8741 tcg_temp_free_i32(tcg_res);
8742 tcg_temp_free_i32(tcg_op1);
8743 tcg_temp_free_i32(tcg_op2);
8747 tcg_temp_free_ptr(fpst);
8749 clear_vec_high(s, elements * (size ? 8 : 4) > 8, rd);
8752 /* AdvSIMD scalar three same
8753 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8754 * +-----+---+-----------+------+---+------+--------+---+------+------+
8755 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8756 * +-----+---+-----------+------+---+------+--------+---+------+------+
8758 static void disas_simd_scalar_three_reg_same(DisasContext *s, uint32_t insn)
8760 int rd = extract32(insn, 0, 5);
8761 int rn = extract32(insn, 5, 5);
8762 int opcode = extract32(insn, 11, 5);
8763 int rm = extract32(insn, 16, 5);
8764 int size = extract32(insn, 22, 2);
8765 bool u = extract32(insn, 29, 1);
8768 if (opcode >= 0x18) {
8769 /* Floating point: U, size[1] and opcode indicate operation */
8770 int fpopcode = opcode | (extract32(size, 1, 1) << 5) | (u << 6);
8772 case 0x1b: /* FMULX */
8773 case 0x1f: /* FRECPS */
8774 case 0x3f: /* FRSQRTS */
8775 case 0x5d: /* FACGE */
8776 case 0x7d: /* FACGT */
8777 case 0x1c: /* FCMEQ */
8778 case 0x5c: /* FCMGE */
8779 case 0x7c: /* FCMGT */
8780 case 0x7a: /* FABD */
8783 unallocated_encoding(s);
8787 if (!fp_access_check(s)) {
8791 handle_3same_float(s, extract32(size, 0, 1), 1, fpopcode, rd, rn, rm);
8796 case 0x1: /* SQADD, UQADD */
8797 case 0x5: /* SQSUB, UQSUB */
8798 case 0x9: /* SQSHL, UQSHL */
8799 case 0xb: /* SQRSHL, UQRSHL */
8801 case 0x8: /* SSHL, USHL */
8802 case 0xa: /* SRSHL, URSHL */
8803 case 0x6: /* CMGT, CMHI */
8804 case 0x7: /* CMGE, CMHS */
8805 case 0x11: /* CMTST, CMEQ */
8806 case 0x10: /* ADD, SUB (vector) */
8808 unallocated_encoding(s);
8812 case 0x16: /* SQDMULH, SQRDMULH (vector) */
8813 if (size != 1 && size != 2) {
8814 unallocated_encoding(s);
8819 unallocated_encoding(s);
8823 if (!fp_access_check(s)) {
8827 tcg_rd = tcg_temp_new_i64();
8830 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
8831 TCGv_i64 tcg_rm = read_fp_dreg(s, rm);
8833 handle_3same_64(s, opcode, u, tcg_rd, tcg_rn, tcg_rm);
8834 tcg_temp_free_i64(tcg_rn);
8835 tcg_temp_free_i64(tcg_rm);
8837 /* Do a single operation on the lowest element in the vector.
8838 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
8839 * no side effects for all these operations.
8840 * OPTME: special-purpose helpers would avoid doing some
8841 * unnecessary work in the helper for the 8 and 16 bit cases.
8843 NeonGenTwoOpEnvFn *genenvfn;
8844 TCGv_i32 tcg_rn = tcg_temp_new_i32();
8845 TCGv_i32 tcg_rm = tcg_temp_new_i32();
8846 TCGv_i32 tcg_rd32 = tcg_temp_new_i32();
8848 read_vec_element_i32(s, tcg_rn, rn, 0, size);
8849 read_vec_element_i32(s, tcg_rm, rm, 0, size);
8852 case 0x1: /* SQADD, UQADD */
8854 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8855 { gen_helper_neon_qadd_s8, gen_helper_neon_qadd_u8 },
8856 { gen_helper_neon_qadd_s16, gen_helper_neon_qadd_u16 },
8857 { gen_helper_neon_qadd_s32, gen_helper_neon_qadd_u32 },
8859 genenvfn = fns[size][u];
8862 case 0x5: /* SQSUB, UQSUB */
8864 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8865 { gen_helper_neon_qsub_s8, gen_helper_neon_qsub_u8 },
8866 { gen_helper_neon_qsub_s16, gen_helper_neon_qsub_u16 },
8867 { gen_helper_neon_qsub_s32, gen_helper_neon_qsub_u32 },
8869 genenvfn = fns[size][u];
8872 case 0x9: /* SQSHL, UQSHL */
8874 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8875 { gen_helper_neon_qshl_s8, gen_helper_neon_qshl_u8 },
8876 { gen_helper_neon_qshl_s16, gen_helper_neon_qshl_u16 },
8877 { gen_helper_neon_qshl_s32, gen_helper_neon_qshl_u32 },
8879 genenvfn = fns[size][u];
8882 case 0xb: /* SQRSHL, UQRSHL */
8884 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8885 { gen_helper_neon_qrshl_s8, gen_helper_neon_qrshl_u8 },
8886 { gen_helper_neon_qrshl_s16, gen_helper_neon_qrshl_u16 },
8887 { gen_helper_neon_qrshl_s32, gen_helper_neon_qrshl_u32 },
8889 genenvfn = fns[size][u];
8892 case 0x16: /* SQDMULH, SQRDMULH */
8894 static NeonGenTwoOpEnvFn * const fns[2][2] = {
8895 { gen_helper_neon_qdmulh_s16, gen_helper_neon_qrdmulh_s16 },
8896 { gen_helper_neon_qdmulh_s32, gen_helper_neon_qrdmulh_s32 },
8898 assert(size == 1 || size == 2);
8899 genenvfn = fns[size - 1][u];
8903 g_assert_not_reached();
8906 genenvfn(tcg_rd32, cpu_env, tcg_rn, tcg_rm);
8907 tcg_gen_extu_i32_i64(tcg_rd, tcg_rd32);
8908 tcg_temp_free_i32(tcg_rd32);
8909 tcg_temp_free_i32(tcg_rn);
8910 tcg_temp_free_i32(tcg_rm);
8913 write_fp_dreg(s, rd, tcg_rd);
8915 tcg_temp_free_i64(tcg_rd);
8918 /* AdvSIMD scalar three same FP16
8919 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
8920 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8921 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
8922 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8923 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
8924 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
8926 static void disas_simd_scalar_three_reg_same_fp16(DisasContext *s,
8929 int rd = extract32(insn, 0, 5);
8930 int rn = extract32(insn, 5, 5);
8931 int opcode = extract32(insn, 11, 3);
8932 int rm = extract32(insn, 16, 5);
8933 bool u = extract32(insn, 29, 1);
8934 bool a = extract32(insn, 23, 1);
8935 int fpopcode = opcode | (a << 3) | (u << 4);
8942 case 0x03: /* FMULX */
8943 case 0x04: /* FCMEQ (reg) */
8944 case 0x07: /* FRECPS */
8945 case 0x0f: /* FRSQRTS */
8946 case 0x14: /* FCMGE (reg) */
8947 case 0x15: /* FACGE */
8948 case 0x1a: /* FABD */
8949 case 0x1c: /* FCMGT (reg) */
8950 case 0x1d: /* FACGT */
8953 unallocated_encoding(s);
8957 if (!dc_isar_feature(aa64_fp16, s)) {
8958 unallocated_encoding(s);
8961 if (!fp_access_check(s)) {
8965 fpst = get_fpstatus_ptr(true);
8967 tcg_op1 = read_fp_hreg(s, rn);
8968 tcg_op2 = read_fp_hreg(s, rm);
8969 tcg_res = tcg_temp_new_i32();
8972 case 0x03: /* FMULX */
8973 gen_helper_advsimd_mulxh(tcg_res, tcg_op1, tcg_op2, fpst);
8975 case 0x04: /* FCMEQ (reg) */
8976 gen_helper_advsimd_ceq_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8978 case 0x07: /* FRECPS */
8979 gen_helper_recpsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8981 case 0x0f: /* FRSQRTS */
8982 gen_helper_rsqrtsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8984 case 0x14: /* FCMGE (reg) */
8985 gen_helper_advsimd_cge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8987 case 0x15: /* FACGE */
8988 gen_helper_advsimd_acge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8990 case 0x1a: /* FABD */
8991 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
8992 tcg_gen_andi_i32(tcg_res, tcg_res, 0x7fff);
8994 case 0x1c: /* FCMGT (reg) */
8995 gen_helper_advsimd_cgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8997 case 0x1d: /* FACGT */
8998 gen_helper_advsimd_acgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
9001 g_assert_not_reached();
9004 write_fp_sreg(s, rd, tcg_res);
9007 tcg_temp_free_i32(tcg_res);
9008 tcg_temp_free_i32(tcg_op1);
9009 tcg_temp_free_i32(tcg_op2);
9010 tcg_temp_free_ptr(fpst);
9013 /* AdvSIMD scalar three same extra
9014 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
9015 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9016 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
9017 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9019 static void disas_simd_scalar_three_reg_same_extra(DisasContext *s,
9022 int rd = extract32(insn, 0, 5);
9023 int rn = extract32(insn, 5, 5);
9024 int opcode = extract32(insn, 11, 4);
9025 int rm = extract32(insn, 16, 5);
9026 int size = extract32(insn, 22, 2);
9027 bool u = extract32(insn, 29, 1);
9028 TCGv_i32 ele1, ele2, ele3;
9032 switch (u * 16 + opcode) {
9033 case 0x10: /* SQRDMLAH (vector) */
9034 case 0x11: /* SQRDMLSH (vector) */
9035 if (size != 1 && size != 2) {
9036 unallocated_encoding(s);
9039 feature = dc_isar_feature(aa64_rdm, s);
9042 unallocated_encoding(s);
9046 unallocated_encoding(s);
9049 if (!fp_access_check(s)) {
9053 /* Do a single operation on the lowest element in the vector.
9054 * We use the standard Neon helpers and rely on 0 OP 0 == 0
9055 * with no side effects for all these operations.
9056 * OPTME: special-purpose helpers would avoid doing some
9057 * unnecessary work in the helper for the 16 bit cases.
9059 ele1 = tcg_temp_new_i32();
9060 ele2 = tcg_temp_new_i32();
9061 ele3 = tcg_temp_new_i32();
9063 read_vec_element_i32(s, ele1, rn, 0, size);
9064 read_vec_element_i32(s, ele2, rm, 0, size);
9065 read_vec_element_i32(s, ele3, rd, 0, size);
9068 case 0x0: /* SQRDMLAH */
9070 gen_helper_neon_qrdmlah_s16(ele3, cpu_env, ele1, ele2, ele3);
9072 gen_helper_neon_qrdmlah_s32(ele3, cpu_env, ele1, ele2, ele3);
9075 case 0x1: /* SQRDMLSH */
9077 gen_helper_neon_qrdmlsh_s16(ele3, cpu_env, ele1, ele2, ele3);
9079 gen_helper_neon_qrdmlsh_s32(ele3, cpu_env, ele1, ele2, ele3);
9083 g_assert_not_reached();
9085 tcg_temp_free_i32(ele1);
9086 tcg_temp_free_i32(ele2);
9088 res = tcg_temp_new_i64();
9089 tcg_gen_extu_i32_i64(res, ele3);
9090 tcg_temp_free_i32(ele3);
9092 write_fp_dreg(s, rd, res);
9093 tcg_temp_free_i64(res);
9096 static void handle_2misc_64(DisasContext *s, int opcode, bool u,
9097 TCGv_i64 tcg_rd, TCGv_i64 tcg_rn,
9098 TCGv_i32 tcg_rmode, TCGv_ptr tcg_fpstatus)
9100 /* Handle 64->64 opcodes which are shared between the scalar and
9101 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
9102 * is valid in either group and also the double-precision fp ops.
9103 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
9109 case 0x4: /* CLS, CLZ */
9111 tcg_gen_clzi_i64(tcg_rd, tcg_rn, 64);
9113 tcg_gen_clrsb_i64(tcg_rd, tcg_rn);
9117 /* This opcode is shared with CNT and RBIT but we have earlier
9118 * enforced that size == 3 if and only if this is the NOT insn.
9120 tcg_gen_not_i64(tcg_rd, tcg_rn);
9122 case 0x7: /* SQABS, SQNEG */
9124 gen_helper_neon_qneg_s64(tcg_rd, cpu_env, tcg_rn);
9126 gen_helper_neon_qabs_s64(tcg_rd, cpu_env, tcg_rn);
9129 case 0xa: /* CMLT */
9130 /* 64 bit integer comparison against zero, result is
9131 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
9136 tcg_gen_setcondi_i64(cond, tcg_rd, tcg_rn, 0);
9137 tcg_gen_neg_i64(tcg_rd, tcg_rd);
9139 case 0x8: /* CMGT, CMGE */
9140 cond = u ? TCG_COND_GE : TCG_COND_GT;
9142 case 0x9: /* CMEQ, CMLE */
9143 cond = u ? TCG_COND_LE : TCG_COND_EQ;
9145 case 0xb: /* ABS, NEG */
9147 tcg_gen_neg_i64(tcg_rd, tcg_rn);
9149 TCGv_i64 tcg_zero = tcg_const_i64(0);
9150 tcg_gen_neg_i64(tcg_rd, tcg_rn);
9151 tcg_gen_movcond_i64(TCG_COND_GT, tcg_rd, tcg_rn, tcg_zero,
9153 tcg_temp_free_i64(tcg_zero);
9156 case 0x2f: /* FABS */
9157 gen_helper_vfp_absd(tcg_rd, tcg_rn);
9159 case 0x6f: /* FNEG */
9160 gen_helper_vfp_negd(tcg_rd, tcg_rn);
9162 case 0x7f: /* FSQRT */
9163 gen_helper_vfp_sqrtd(tcg_rd, tcg_rn, cpu_env);
9165 case 0x1a: /* FCVTNS */
9166 case 0x1b: /* FCVTMS */
9167 case 0x1c: /* FCVTAS */
9168 case 0x3a: /* FCVTPS */
9169 case 0x3b: /* FCVTZS */
9171 TCGv_i32 tcg_shift = tcg_const_i32(0);
9172 gen_helper_vfp_tosqd(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9173 tcg_temp_free_i32(tcg_shift);
9176 case 0x5a: /* FCVTNU */
9177 case 0x5b: /* FCVTMU */
9178 case 0x5c: /* FCVTAU */
9179 case 0x7a: /* FCVTPU */
9180 case 0x7b: /* FCVTZU */
9182 TCGv_i32 tcg_shift = tcg_const_i32(0);
9183 gen_helper_vfp_touqd(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9184 tcg_temp_free_i32(tcg_shift);
9187 case 0x18: /* FRINTN */
9188 case 0x19: /* FRINTM */
9189 case 0x38: /* FRINTP */
9190 case 0x39: /* FRINTZ */
9191 case 0x58: /* FRINTA */
9192 case 0x79: /* FRINTI */
9193 gen_helper_rintd(tcg_rd, tcg_rn, tcg_fpstatus);
9195 case 0x59: /* FRINTX */
9196 gen_helper_rintd_exact(tcg_rd, tcg_rn, tcg_fpstatus);
9199 g_assert_not_reached();
9203 static void handle_2misc_fcmp_zero(DisasContext *s, int opcode,
9204 bool is_scalar, bool is_u, bool is_q,
9205 int size, int rn, int rd)
9207 bool is_double = (size == MO_64);
9210 if (!fp_access_check(s)) {
9214 fpst = get_fpstatus_ptr(size == MO_16);
9217 TCGv_i64 tcg_op = tcg_temp_new_i64();
9218 TCGv_i64 tcg_zero = tcg_const_i64(0);
9219 TCGv_i64 tcg_res = tcg_temp_new_i64();
9220 NeonGenTwoDoubleOPFn *genfn;
9225 case 0x2e: /* FCMLT (zero) */
9228 case 0x2c: /* FCMGT (zero) */
9229 genfn = gen_helper_neon_cgt_f64;
9231 case 0x2d: /* FCMEQ (zero) */
9232 genfn = gen_helper_neon_ceq_f64;
9234 case 0x6d: /* FCMLE (zero) */
9237 case 0x6c: /* FCMGE (zero) */
9238 genfn = gen_helper_neon_cge_f64;
9241 g_assert_not_reached();
9244 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9245 read_vec_element(s, tcg_op, rn, pass, MO_64);
9247 genfn(tcg_res, tcg_zero, tcg_op, fpst);
9249 genfn(tcg_res, tcg_op, tcg_zero, fpst);
9251 write_vec_element(s, tcg_res, rd, pass, MO_64);
9253 tcg_temp_free_i64(tcg_res);
9254 tcg_temp_free_i64(tcg_zero);
9255 tcg_temp_free_i64(tcg_op);
9257 clear_vec_high(s, !is_scalar, rd);
9259 TCGv_i32 tcg_op = tcg_temp_new_i32();
9260 TCGv_i32 tcg_zero = tcg_const_i32(0);
9261 TCGv_i32 tcg_res = tcg_temp_new_i32();
9262 NeonGenTwoSingleOPFn *genfn;
9264 int pass, maxpasses;
9266 if (size == MO_16) {
9268 case 0x2e: /* FCMLT (zero) */
9271 case 0x2c: /* FCMGT (zero) */
9272 genfn = gen_helper_advsimd_cgt_f16;
9274 case 0x2d: /* FCMEQ (zero) */
9275 genfn = gen_helper_advsimd_ceq_f16;
9277 case 0x6d: /* FCMLE (zero) */
9280 case 0x6c: /* FCMGE (zero) */
9281 genfn = gen_helper_advsimd_cge_f16;
9284 g_assert_not_reached();
9288 case 0x2e: /* FCMLT (zero) */
9291 case 0x2c: /* FCMGT (zero) */
9292 genfn = gen_helper_neon_cgt_f32;
9294 case 0x2d: /* FCMEQ (zero) */
9295 genfn = gen_helper_neon_ceq_f32;
9297 case 0x6d: /* FCMLE (zero) */
9300 case 0x6c: /* FCMGE (zero) */
9301 genfn = gen_helper_neon_cge_f32;
9304 g_assert_not_reached();
9311 int vector_size = 8 << is_q;
9312 maxpasses = vector_size >> size;
9315 for (pass = 0; pass < maxpasses; pass++) {
9316 read_vec_element_i32(s, tcg_op, rn, pass, size);
9318 genfn(tcg_res, tcg_zero, tcg_op, fpst);
9320 genfn(tcg_res, tcg_op, tcg_zero, fpst);
9323 write_fp_sreg(s, rd, tcg_res);
9325 write_vec_element_i32(s, tcg_res, rd, pass, size);
9328 tcg_temp_free_i32(tcg_res);
9329 tcg_temp_free_i32(tcg_zero);
9330 tcg_temp_free_i32(tcg_op);
9332 clear_vec_high(s, is_q, rd);
9336 tcg_temp_free_ptr(fpst);
9339 static void handle_2misc_reciprocal(DisasContext *s, int opcode,
9340 bool is_scalar, bool is_u, bool is_q,
9341 int size, int rn, int rd)
9343 bool is_double = (size == 3);
9344 TCGv_ptr fpst = get_fpstatus_ptr(false);
9347 TCGv_i64 tcg_op = tcg_temp_new_i64();
9348 TCGv_i64 tcg_res = tcg_temp_new_i64();
9351 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9352 read_vec_element(s, tcg_op, rn, pass, MO_64);
9354 case 0x3d: /* FRECPE */
9355 gen_helper_recpe_f64(tcg_res, tcg_op, fpst);
9357 case 0x3f: /* FRECPX */
9358 gen_helper_frecpx_f64(tcg_res, tcg_op, fpst);
9360 case 0x7d: /* FRSQRTE */
9361 gen_helper_rsqrte_f64(tcg_res, tcg_op, fpst);
9364 g_assert_not_reached();
9366 write_vec_element(s, tcg_res, rd, pass, MO_64);
9368 tcg_temp_free_i64(tcg_res);
9369 tcg_temp_free_i64(tcg_op);
9370 clear_vec_high(s, !is_scalar, rd);
9372 TCGv_i32 tcg_op = tcg_temp_new_i32();
9373 TCGv_i32 tcg_res = tcg_temp_new_i32();
9374 int pass, maxpasses;
9379 maxpasses = is_q ? 4 : 2;
9382 for (pass = 0; pass < maxpasses; pass++) {
9383 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
9386 case 0x3c: /* URECPE */
9387 gen_helper_recpe_u32(tcg_res, tcg_op, fpst);
9389 case 0x3d: /* FRECPE */
9390 gen_helper_recpe_f32(tcg_res, tcg_op, fpst);
9392 case 0x3f: /* FRECPX */
9393 gen_helper_frecpx_f32(tcg_res, tcg_op, fpst);
9395 case 0x7d: /* FRSQRTE */
9396 gen_helper_rsqrte_f32(tcg_res, tcg_op, fpst);
9399 g_assert_not_reached();
9403 write_fp_sreg(s, rd, tcg_res);
9405 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
9408 tcg_temp_free_i32(tcg_res);
9409 tcg_temp_free_i32(tcg_op);
9411 clear_vec_high(s, is_q, rd);
9414 tcg_temp_free_ptr(fpst);
9417 static void handle_2misc_narrow(DisasContext *s, bool scalar,
9418 int opcode, bool u, bool is_q,
9419 int size, int rn, int rd)
9421 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
9422 * in the source becomes a size element in the destination).
9425 TCGv_i32 tcg_res[2];
9426 int destelt = is_q ? 2 : 0;
9427 int passes = scalar ? 1 : 2;
9430 tcg_res[1] = tcg_const_i32(0);
9433 for (pass = 0; pass < passes; pass++) {
9434 TCGv_i64 tcg_op = tcg_temp_new_i64();
9435 NeonGenNarrowFn *genfn = NULL;
9436 NeonGenNarrowEnvFn *genenvfn = NULL;
9439 read_vec_element(s, tcg_op, rn, pass, size + 1);
9441 read_vec_element(s, tcg_op, rn, pass, MO_64);
9443 tcg_res[pass] = tcg_temp_new_i32();
9446 case 0x12: /* XTN, SQXTUN */
9448 static NeonGenNarrowFn * const xtnfns[3] = {
9449 gen_helper_neon_narrow_u8,
9450 gen_helper_neon_narrow_u16,
9451 tcg_gen_extrl_i64_i32,
9453 static NeonGenNarrowEnvFn * const sqxtunfns[3] = {
9454 gen_helper_neon_unarrow_sat8,
9455 gen_helper_neon_unarrow_sat16,
9456 gen_helper_neon_unarrow_sat32,
9459 genenvfn = sqxtunfns[size];
9461 genfn = xtnfns[size];
9465 case 0x14: /* SQXTN, UQXTN */
9467 static NeonGenNarrowEnvFn * const fns[3][2] = {
9468 { gen_helper_neon_narrow_sat_s8,
9469 gen_helper_neon_narrow_sat_u8 },
9470 { gen_helper_neon_narrow_sat_s16,
9471 gen_helper_neon_narrow_sat_u16 },
9472 { gen_helper_neon_narrow_sat_s32,
9473 gen_helper_neon_narrow_sat_u32 },
9475 genenvfn = fns[size][u];
9478 case 0x16: /* FCVTN, FCVTN2 */
9479 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
9481 gen_helper_vfp_fcvtsd(tcg_res[pass], tcg_op, cpu_env);
9483 TCGv_i32 tcg_lo = tcg_temp_new_i32();
9484 TCGv_i32 tcg_hi = tcg_temp_new_i32();
9485 TCGv_ptr fpst = get_fpstatus_ptr(false);
9486 TCGv_i32 ahp = get_ahp_flag();
9488 tcg_gen_extr_i64_i32(tcg_lo, tcg_hi, tcg_op);
9489 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo, tcg_lo, fpst, ahp);
9490 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi, tcg_hi, fpst, ahp);
9491 tcg_gen_deposit_i32(tcg_res[pass], tcg_lo, tcg_hi, 16, 16);
9492 tcg_temp_free_i32(tcg_lo);
9493 tcg_temp_free_i32(tcg_hi);
9494 tcg_temp_free_ptr(fpst);
9495 tcg_temp_free_i32(ahp);
9498 case 0x56: /* FCVTXN, FCVTXN2 */
9499 /* 64 bit to 32 bit float conversion
9500 * with von Neumann rounding (round to odd)
9503 gen_helper_fcvtx_f64_to_f32(tcg_res[pass], tcg_op, cpu_env);
9506 g_assert_not_reached();
9510 genfn(tcg_res[pass], tcg_op);
9511 } else if (genenvfn) {
9512 genenvfn(tcg_res[pass], cpu_env, tcg_op);
9515 tcg_temp_free_i64(tcg_op);
9518 for (pass = 0; pass < 2; pass++) {
9519 write_vec_element_i32(s, tcg_res[pass], rd, destelt + pass, MO_32);
9520 tcg_temp_free_i32(tcg_res[pass]);
9522 clear_vec_high(s, is_q, rd);
9525 /* Remaining saturating accumulating ops */
9526 static void handle_2misc_satacc(DisasContext *s, bool is_scalar, bool is_u,
9527 bool is_q, int size, int rn, int rd)
9529 bool is_double = (size == 3);
9532 TCGv_i64 tcg_rn = tcg_temp_new_i64();
9533 TCGv_i64 tcg_rd = tcg_temp_new_i64();
9536 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9537 read_vec_element(s, tcg_rn, rn, pass, MO_64);
9538 read_vec_element(s, tcg_rd, rd, pass, MO_64);
9540 if (is_u) { /* USQADD */
9541 gen_helper_neon_uqadd_s64(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9542 } else { /* SUQADD */
9543 gen_helper_neon_sqadd_u64(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9545 write_vec_element(s, tcg_rd, rd, pass, MO_64);
9547 tcg_temp_free_i64(tcg_rd);
9548 tcg_temp_free_i64(tcg_rn);
9549 clear_vec_high(s, !is_scalar, rd);
9551 TCGv_i32 tcg_rn = tcg_temp_new_i32();
9552 TCGv_i32 tcg_rd = tcg_temp_new_i32();
9553 int pass, maxpasses;
9558 maxpasses = is_q ? 4 : 2;
9561 for (pass = 0; pass < maxpasses; pass++) {
9563 read_vec_element_i32(s, tcg_rn, rn, pass, size);
9564 read_vec_element_i32(s, tcg_rd, rd, pass, size);
9566 read_vec_element_i32(s, tcg_rn, rn, pass, MO_32);
9567 read_vec_element_i32(s, tcg_rd, rd, pass, MO_32);
9570 if (is_u) { /* USQADD */
9573 gen_helper_neon_uqadd_s8(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9576 gen_helper_neon_uqadd_s16(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9579 gen_helper_neon_uqadd_s32(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9582 g_assert_not_reached();
9584 } else { /* SUQADD */
9587 gen_helper_neon_sqadd_u8(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9590 gen_helper_neon_sqadd_u16(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9593 gen_helper_neon_sqadd_u32(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9596 g_assert_not_reached();
9601 TCGv_i64 tcg_zero = tcg_const_i64(0);
9602 write_vec_element(s, tcg_zero, rd, 0, MO_64);
9603 tcg_temp_free_i64(tcg_zero);
9605 write_vec_element_i32(s, tcg_rd, rd, pass, MO_32);
9607 tcg_temp_free_i32(tcg_rd);
9608 tcg_temp_free_i32(tcg_rn);
9609 clear_vec_high(s, is_q, rd);
9613 /* AdvSIMD scalar two reg misc
9614 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9615 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9616 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9617 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9619 static void disas_simd_scalar_two_reg_misc(DisasContext *s, uint32_t insn)
9621 int rd = extract32(insn, 0, 5);
9622 int rn = extract32(insn, 5, 5);
9623 int opcode = extract32(insn, 12, 5);
9624 int size = extract32(insn, 22, 2);
9625 bool u = extract32(insn, 29, 1);
9626 bool is_fcvt = false;
9629 TCGv_ptr tcg_fpstatus;
9632 case 0x3: /* USQADD / SUQADD*/
9633 if (!fp_access_check(s)) {
9636 handle_2misc_satacc(s, true, u, false, size, rn, rd);
9638 case 0x7: /* SQABS / SQNEG */
9640 case 0xa: /* CMLT */
9642 unallocated_encoding(s);
9646 case 0x8: /* CMGT, CMGE */
9647 case 0x9: /* CMEQ, CMLE */
9648 case 0xb: /* ABS, NEG */
9650 unallocated_encoding(s);
9654 case 0x12: /* SQXTUN */
9656 unallocated_encoding(s);
9660 case 0x14: /* SQXTN, UQXTN */
9662 unallocated_encoding(s);
9665 if (!fp_access_check(s)) {
9668 handle_2misc_narrow(s, true, opcode, u, false, size, rn, rd);
9673 /* Floating point: U, size[1] and opcode indicate operation;
9674 * size[0] indicates single or double precision.
9676 opcode |= (extract32(size, 1, 1) << 5) | (u << 6);
9677 size = extract32(size, 0, 1) ? 3 : 2;
9679 case 0x2c: /* FCMGT (zero) */
9680 case 0x2d: /* FCMEQ (zero) */
9681 case 0x2e: /* FCMLT (zero) */
9682 case 0x6c: /* FCMGE (zero) */
9683 case 0x6d: /* FCMLE (zero) */
9684 handle_2misc_fcmp_zero(s, opcode, true, u, true, size, rn, rd);
9686 case 0x1d: /* SCVTF */
9687 case 0x5d: /* UCVTF */
9689 bool is_signed = (opcode == 0x1d);
9690 if (!fp_access_check(s)) {
9693 handle_simd_intfp_conv(s, rd, rn, 1, is_signed, 0, size);
9696 case 0x3d: /* FRECPE */
9697 case 0x3f: /* FRECPX */
9698 case 0x7d: /* FRSQRTE */
9699 if (!fp_access_check(s)) {
9702 handle_2misc_reciprocal(s, opcode, true, u, true, size, rn, rd);
9704 case 0x1a: /* FCVTNS */
9705 case 0x1b: /* FCVTMS */
9706 case 0x3a: /* FCVTPS */
9707 case 0x3b: /* FCVTZS */
9708 case 0x5a: /* FCVTNU */
9709 case 0x5b: /* FCVTMU */
9710 case 0x7a: /* FCVTPU */
9711 case 0x7b: /* FCVTZU */
9713 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
9715 case 0x1c: /* FCVTAS */
9716 case 0x5c: /* FCVTAU */
9717 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
9719 rmode = FPROUNDING_TIEAWAY;
9721 case 0x56: /* FCVTXN, FCVTXN2 */
9723 unallocated_encoding(s);
9726 if (!fp_access_check(s)) {
9729 handle_2misc_narrow(s, true, opcode, u, false, size - 1, rn, rd);
9732 unallocated_encoding(s);
9737 unallocated_encoding(s);
9741 if (!fp_access_check(s)) {
9746 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
9747 tcg_fpstatus = get_fpstatus_ptr(false);
9748 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
9751 tcg_fpstatus = NULL;
9755 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
9756 TCGv_i64 tcg_rd = tcg_temp_new_i64();
9758 handle_2misc_64(s, opcode, u, tcg_rd, tcg_rn, tcg_rmode, tcg_fpstatus);
9759 write_fp_dreg(s, rd, tcg_rd);
9760 tcg_temp_free_i64(tcg_rd);
9761 tcg_temp_free_i64(tcg_rn);
9763 TCGv_i32 tcg_rn = tcg_temp_new_i32();
9764 TCGv_i32 tcg_rd = tcg_temp_new_i32();
9766 read_vec_element_i32(s, tcg_rn, rn, 0, size);
9769 case 0x7: /* SQABS, SQNEG */
9771 NeonGenOneOpEnvFn *genfn;
9772 static NeonGenOneOpEnvFn * const fns[3][2] = {
9773 { gen_helper_neon_qabs_s8, gen_helper_neon_qneg_s8 },
9774 { gen_helper_neon_qabs_s16, gen_helper_neon_qneg_s16 },
9775 { gen_helper_neon_qabs_s32, gen_helper_neon_qneg_s32 },
9777 genfn = fns[size][u];
9778 genfn(tcg_rd, cpu_env, tcg_rn);
9781 case 0x1a: /* FCVTNS */
9782 case 0x1b: /* FCVTMS */
9783 case 0x1c: /* FCVTAS */
9784 case 0x3a: /* FCVTPS */
9785 case 0x3b: /* FCVTZS */
9787 TCGv_i32 tcg_shift = tcg_const_i32(0);
9788 gen_helper_vfp_tosls(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9789 tcg_temp_free_i32(tcg_shift);
9792 case 0x5a: /* FCVTNU */
9793 case 0x5b: /* FCVTMU */
9794 case 0x5c: /* FCVTAU */
9795 case 0x7a: /* FCVTPU */
9796 case 0x7b: /* FCVTZU */
9798 TCGv_i32 tcg_shift = tcg_const_i32(0);
9799 gen_helper_vfp_touls(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9800 tcg_temp_free_i32(tcg_shift);
9804 g_assert_not_reached();
9807 write_fp_sreg(s, rd, tcg_rd);
9808 tcg_temp_free_i32(tcg_rd);
9809 tcg_temp_free_i32(tcg_rn);
9813 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
9814 tcg_temp_free_i32(tcg_rmode);
9815 tcg_temp_free_ptr(tcg_fpstatus);
9819 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
9820 static void handle_vec_simd_shri(DisasContext *s, bool is_q, bool is_u,
9821 int immh, int immb, int opcode, int rn, int rd)
9823 int size = 32 - clz32(immh) - 1;
9824 int immhb = immh << 3 | immb;
9825 int shift = 2 * (8 << size) - immhb;
9826 bool accumulate = false;
9827 int dsize = is_q ? 128 : 64;
9828 int esize = 8 << size;
9829 int elements = dsize/esize;
9830 TCGMemOp memop = size | (is_u ? 0 : MO_SIGN);
9831 TCGv_i64 tcg_rn = new_tmp_a64(s);
9832 TCGv_i64 tcg_rd = new_tmp_a64(s);
9834 uint64_t round_const;
9837 if (extract32(immh, 3, 1) && !is_q) {
9838 unallocated_encoding(s);
9841 tcg_debug_assert(size <= 3);
9843 if (!fp_access_check(s)) {
9848 case 0x02: /* SSRA / USRA (accumulate) */
9850 /* Shift count same as element size produces zero to add. */
9851 if (shift == 8 << size) {
9854 gen_gvec_op2i(s, is_q, rd, rn, shift, &usra_op[size]);
9856 /* Shift count same as element size produces all sign to add. */
9857 if (shift == 8 << size) {
9860 gen_gvec_op2i(s, is_q, rd, rn, shift, &ssra_op[size]);
9863 case 0x08: /* SRI */
9864 /* Shift count same as element size is valid but does nothing. */
9865 if (shift == 8 << size) {
9868 gen_gvec_op2i(s, is_q, rd, rn, shift, &sri_op[size]);
9871 case 0x00: /* SSHR / USHR */
9873 if (shift == 8 << size) {
9874 /* Shift count the same size as element size produces zero. */
9875 tcg_gen_gvec_dup8i(vec_full_reg_offset(s, rd),
9876 is_q ? 16 : 8, vec_full_reg_size(s), 0);
9878 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_shri, size);
9881 /* Shift count the same size as element size produces all sign. */
9882 if (shift == 8 << size) {
9885 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_sari, size);
9889 case 0x04: /* SRSHR / URSHR (rounding) */
9891 case 0x06: /* SRSRA / URSRA (accum + rounding) */
9895 g_assert_not_reached();
9898 round_const = 1ULL << (shift - 1);
9899 tcg_round = tcg_const_i64(round_const);
9901 for (i = 0; i < elements; i++) {
9902 read_vec_element(s, tcg_rn, rn, i, memop);
9904 read_vec_element(s, tcg_rd, rd, i, memop);
9907 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
9908 accumulate, is_u, size, shift);
9910 write_vec_element(s, tcg_rd, rd, i, size);
9912 tcg_temp_free_i64(tcg_round);
9915 clear_vec_high(s, is_q, rd);
9918 /* SHL/SLI - Vector shift left */
9919 static void handle_vec_simd_shli(DisasContext *s, bool is_q, bool insert,
9920 int immh, int immb, int opcode, int rn, int rd)
9922 int size = 32 - clz32(immh) - 1;
9923 int immhb = immh << 3 | immb;
9924 int shift = immhb - (8 << size);
9926 /* Range of size is limited by decode: immh is a non-zero 4 bit field */
9927 assert(size >= 0 && size <= 3);
9929 if (extract32(immh, 3, 1) && !is_q) {
9930 unallocated_encoding(s);
9934 if (!fp_access_check(s)) {
9939 gen_gvec_op2i(s, is_q, rd, rn, shift, &sli_op[size]);
9941 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_shli, size);
9945 /* USHLL/SHLL - Vector shift left with widening */
9946 static void handle_vec_simd_wshli(DisasContext *s, bool is_q, bool is_u,
9947 int immh, int immb, int opcode, int rn, int rd)
9949 int size = 32 - clz32(immh) - 1;
9950 int immhb = immh << 3 | immb;
9951 int shift = immhb - (8 << size);
9953 int esize = 8 << size;
9954 int elements = dsize/esize;
9955 TCGv_i64 tcg_rn = new_tmp_a64(s);
9956 TCGv_i64 tcg_rd = new_tmp_a64(s);
9960 unallocated_encoding(s);
9964 if (!fp_access_check(s)) {
9968 /* For the LL variants the store is larger than the load,
9969 * so if rd == rn we would overwrite parts of our input.
9970 * So load everything right now and use shifts in the main loop.
9972 read_vec_element(s, tcg_rn, rn, is_q ? 1 : 0, MO_64);
9974 for (i = 0; i < elements; i++) {
9975 tcg_gen_shri_i64(tcg_rd, tcg_rn, i * esize);
9976 ext_and_shift_reg(tcg_rd, tcg_rd, size | (!is_u << 2), 0);
9977 tcg_gen_shli_i64(tcg_rd, tcg_rd, shift);
9978 write_vec_element(s, tcg_rd, rd, i, size + 1);
9982 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
9983 static void handle_vec_simd_shrn(DisasContext *s, bool is_q,
9984 int immh, int immb, int opcode, int rn, int rd)
9986 int immhb = immh << 3 | immb;
9987 int size = 32 - clz32(immh) - 1;
9989 int esize = 8 << size;
9990 int elements = dsize/esize;
9991 int shift = (2 * esize) - immhb;
9992 bool round = extract32(opcode, 0, 1);
9993 TCGv_i64 tcg_rn, tcg_rd, tcg_final;
9997 if (extract32(immh, 3, 1)) {
9998 unallocated_encoding(s);
10002 if (!fp_access_check(s)) {
10006 tcg_rn = tcg_temp_new_i64();
10007 tcg_rd = tcg_temp_new_i64();
10008 tcg_final = tcg_temp_new_i64();
10009 read_vec_element(s, tcg_final, rd, is_q ? 1 : 0, MO_64);
10012 uint64_t round_const = 1ULL << (shift - 1);
10013 tcg_round = tcg_const_i64(round_const);
10018 for (i = 0; i < elements; i++) {
10019 read_vec_element(s, tcg_rn, rn, i, size+1);
10020 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
10021 false, true, size+1, shift);
10023 tcg_gen_deposit_i64(tcg_final, tcg_final, tcg_rd, esize * i, esize);
10027 write_vec_element(s, tcg_final, rd, 0, MO_64);
10029 write_vec_element(s, tcg_final, rd, 1, MO_64);
10032 tcg_temp_free_i64(tcg_round);
10034 tcg_temp_free_i64(tcg_rn);
10035 tcg_temp_free_i64(tcg_rd);
10036 tcg_temp_free_i64(tcg_final);
10038 clear_vec_high(s, is_q, rd);
10042 /* AdvSIMD shift by immediate
10043 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
10044 * +---+---+---+-------------+------+------+--------+---+------+------+
10045 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
10046 * +---+---+---+-------------+------+------+--------+---+------+------+
10048 static void disas_simd_shift_imm(DisasContext *s, uint32_t insn)
10050 int rd = extract32(insn, 0, 5);
10051 int rn = extract32(insn, 5, 5);
10052 int opcode = extract32(insn, 11, 5);
10053 int immb = extract32(insn, 16, 3);
10054 int immh = extract32(insn, 19, 4);
10055 bool is_u = extract32(insn, 29, 1);
10056 bool is_q = extract32(insn, 30, 1);
10059 case 0x08: /* SRI */
10061 unallocated_encoding(s);
10065 case 0x00: /* SSHR / USHR */
10066 case 0x02: /* SSRA / USRA (accumulate) */
10067 case 0x04: /* SRSHR / URSHR (rounding) */
10068 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10069 handle_vec_simd_shri(s, is_q, is_u, immh, immb, opcode, rn, rd);
10071 case 0x0a: /* SHL / SLI */
10072 handle_vec_simd_shli(s, is_q, is_u, immh, immb, opcode, rn, rd);
10074 case 0x10: /* SHRN */
10075 case 0x11: /* RSHRN / SQRSHRUN */
10077 handle_vec_simd_sqshrn(s, false, is_q, false, true, immh, immb,
10080 handle_vec_simd_shrn(s, is_q, immh, immb, opcode, rn, rd);
10083 case 0x12: /* SQSHRN / UQSHRN */
10084 case 0x13: /* SQRSHRN / UQRSHRN */
10085 handle_vec_simd_sqshrn(s, false, is_q, is_u, is_u, immh, immb,
10088 case 0x14: /* SSHLL / USHLL */
10089 handle_vec_simd_wshli(s, is_q, is_u, immh, immb, opcode, rn, rd);
10091 case 0x1c: /* SCVTF / UCVTF */
10092 handle_simd_shift_intfp_conv(s, false, is_q, is_u, immh, immb,
10095 case 0xc: /* SQSHLU */
10097 unallocated_encoding(s);
10100 handle_simd_qshl(s, false, is_q, false, true, immh, immb, rn, rd);
10102 case 0xe: /* SQSHL, UQSHL */
10103 handle_simd_qshl(s, false, is_q, is_u, is_u, immh, immb, rn, rd);
10105 case 0x1f: /* FCVTZS/ FCVTZU */
10106 handle_simd_shift_fpint_conv(s, false, is_q, is_u, immh, immb, rn, rd);
10109 unallocated_encoding(s);
10114 /* Generate code to do a "long" addition or subtraction, ie one done in
10115 * TCGv_i64 on vector lanes twice the width specified by size.
10117 static void gen_neon_addl(int size, bool is_sub, TCGv_i64 tcg_res,
10118 TCGv_i64 tcg_op1, TCGv_i64 tcg_op2)
10120 static NeonGenTwo64OpFn * const fns[3][2] = {
10121 { gen_helper_neon_addl_u16, gen_helper_neon_subl_u16 },
10122 { gen_helper_neon_addl_u32, gen_helper_neon_subl_u32 },
10123 { tcg_gen_add_i64, tcg_gen_sub_i64 },
10125 NeonGenTwo64OpFn *genfn;
10128 genfn = fns[size][is_sub];
10129 genfn(tcg_res, tcg_op1, tcg_op2);
10132 static void handle_3rd_widening(DisasContext *s, int is_q, int is_u, int size,
10133 int opcode, int rd, int rn, int rm)
10135 /* 3-reg-different widening insns: 64 x 64 -> 128 */
10136 TCGv_i64 tcg_res[2];
10139 tcg_res[0] = tcg_temp_new_i64();
10140 tcg_res[1] = tcg_temp_new_i64();
10142 /* Does this op do an adding accumulate, a subtracting accumulate,
10143 * or no accumulate at all?
10161 read_vec_element(s, tcg_res[0], rd, 0, MO_64);
10162 read_vec_element(s, tcg_res[1], rd, 1, MO_64);
10165 /* size == 2 means two 32x32->64 operations; this is worth special
10166 * casing because we can generally handle it inline.
10169 for (pass = 0; pass < 2; pass++) {
10170 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10171 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10172 TCGv_i64 tcg_passres;
10173 TCGMemOp memop = MO_32 | (is_u ? 0 : MO_SIGN);
10175 int elt = pass + is_q * 2;
10177 read_vec_element(s, tcg_op1, rn, elt, memop);
10178 read_vec_element(s, tcg_op2, rm, elt, memop);
10181 tcg_passres = tcg_res[pass];
10183 tcg_passres = tcg_temp_new_i64();
10187 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10188 tcg_gen_add_i64(tcg_passres, tcg_op1, tcg_op2);
10190 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10191 tcg_gen_sub_i64(tcg_passres, tcg_op1, tcg_op2);
10193 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10194 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10196 TCGv_i64 tcg_tmp1 = tcg_temp_new_i64();
10197 TCGv_i64 tcg_tmp2 = tcg_temp_new_i64();
10199 tcg_gen_sub_i64(tcg_tmp1, tcg_op1, tcg_op2);
10200 tcg_gen_sub_i64(tcg_tmp2, tcg_op2, tcg_op1);
10201 tcg_gen_movcond_i64(is_u ? TCG_COND_GEU : TCG_COND_GE,
10203 tcg_op1, tcg_op2, tcg_tmp1, tcg_tmp2);
10204 tcg_temp_free_i64(tcg_tmp1);
10205 tcg_temp_free_i64(tcg_tmp2);
10208 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10209 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10210 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10211 tcg_gen_mul_i64(tcg_passres, tcg_op1, tcg_op2);
10213 case 9: /* SQDMLAL, SQDMLAL2 */
10214 case 11: /* SQDMLSL, SQDMLSL2 */
10215 case 13: /* SQDMULL, SQDMULL2 */
10216 tcg_gen_mul_i64(tcg_passres, tcg_op1, tcg_op2);
10217 gen_helper_neon_addl_saturate_s64(tcg_passres, cpu_env,
10218 tcg_passres, tcg_passres);
10221 g_assert_not_reached();
10224 if (opcode == 9 || opcode == 11) {
10225 /* saturating accumulate ops */
10227 tcg_gen_neg_i64(tcg_passres, tcg_passres);
10229 gen_helper_neon_addl_saturate_s64(tcg_res[pass], cpu_env,
10230 tcg_res[pass], tcg_passres);
10231 } else if (accop > 0) {
10232 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
10233 } else if (accop < 0) {
10234 tcg_gen_sub_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
10238 tcg_temp_free_i64(tcg_passres);
10241 tcg_temp_free_i64(tcg_op1);
10242 tcg_temp_free_i64(tcg_op2);
10245 /* size 0 or 1, generally helper functions */
10246 for (pass = 0; pass < 2; pass++) {
10247 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
10248 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10249 TCGv_i64 tcg_passres;
10250 int elt = pass + is_q * 2;
10252 read_vec_element_i32(s, tcg_op1, rn, elt, MO_32);
10253 read_vec_element_i32(s, tcg_op2, rm, elt, MO_32);
10256 tcg_passres = tcg_res[pass];
10258 tcg_passres = tcg_temp_new_i64();
10262 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10263 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10265 TCGv_i64 tcg_op2_64 = tcg_temp_new_i64();
10266 static NeonGenWidenFn * const widenfns[2][2] = {
10267 { gen_helper_neon_widen_s8, gen_helper_neon_widen_u8 },
10268 { gen_helper_neon_widen_s16, gen_helper_neon_widen_u16 },
10270 NeonGenWidenFn *widenfn = widenfns[size][is_u];
10272 widenfn(tcg_op2_64, tcg_op2);
10273 widenfn(tcg_passres, tcg_op1);
10274 gen_neon_addl(size, (opcode == 2), tcg_passres,
10275 tcg_passres, tcg_op2_64);
10276 tcg_temp_free_i64(tcg_op2_64);
10279 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10280 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10283 gen_helper_neon_abdl_u16(tcg_passres, tcg_op1, tcg_op2);
10285 gen_helper_neon_abdl_s16(tcg_passres, tcg_op1, tcg_op2);
10289 gen_helper_neon_abdl_u32(tcg_passres, tcg_op1, tcg_op2);
10291 gen_helper_neon_abdl_s32(tcg_passres, tcg_op1, tcg_op2);
10295 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10296 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10297 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10300 gen_helper_neon_mull_u8(tcg_passres, tcg_op1, tcg_op2);
10302 gen_helper_neon_mull_s8(tcg_passres, tcg_op1, tcg_op2);
10306 gen_helper_neon_mull_u16(tcg_passres, tcg_op1, tcg_op2);
10308 gen_helper_neon_mull_s16(tcg_passres, tcg_op1, tcg_op2);
10312 case 9: /* SQDMLAL, SQDMLAL2 */
10313 case 11: /* SQDMLSL, SQDMLSL2 */
10314 case 13: /* SQDMULL, SQDMULL2 */
10316 gen_helper_neon_mull_s16(tcg_passres, tcg_op1, tcg_op2);
10317 gen_helper_neon_addl_saturate_s32(tcg_passres, cpu_env,
10318 tcg_passres, tcg_passres);
10320 case 14: /* PMULL */
10322 gen_helper_neon_mull_p8(tcg_passres, tcg_op1, tcg_op2);
10325 g_assert_not_reached();
10327 tcg_temp_free_i32(tcg_op1);
10328 tcg_temp_free_i32(tcg_op2);
10331 if (opcode == 9 || opcode == 11) {
10332 /* saturating accumulate ops */
10334 gen_helper_neon_negl_u32(tcg_passres, tcg_passres);
10336 gen_helper_neon_addl_saturate_s32(tcg_res[pass], cpu_env,
10340 gen_neon_addl(size, (accop < 0), tcg_res[pass],
10341 tcg_res[pass], tcg_passres);
10343 tcg_temp_free_i64(tcg_passres);
10348 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
10349 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
10350 tcg_temp_free_i64(tcg_res[0]);
10351 tcg_temp_free_i64(tcg_res[1]);
10354 static void handle_3rd_wide(DisasContext *s, int is_q, int is_u, int size,
10355 int opcode, int rd, int rn, int rm)
10357 TCGv_i64 tcg_res[2];
10358 int part = is_q ? 2 : 0;
10361 for (pass = 0; pass < 2; pass++) {
10362 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10363 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10364 TCGv_i64 tcg_op2_wide = tcg_temp_new_i64();
10365 static NeonGenWidenFn * const widenfns[3][2] = {
10366 { gen_helper_neon_widen_s8, gen_helper_neon_widen_u8 },
10367 { gen_helper_neon_widen_s16, gen_helper_neon_widen_u16 },
10368 { tcg_gen_ext_i32_i64, tcg_gen_extu_i32_i64 },
10370 NeonGenWidenFn *widenfn = widenfns[size][is_u];
10372 read_vec_element(s, tcg_op1, rn, pass, MO_64);
10373 read_vec_element_i32(s, tcg_op2, rm, part + pass, MO_32);
10374 widenfn(tcg_op2_wide, tcg_op2);
10375 tcg_temp_free_i32(tcg_op2);
10376 tcg_res[pass] = tcg_temp_new_i64();
10377 gen_neon_addl(size, (opcode == 3),
10378 tcg_res[pass], tcg_op1, tcg_op2_wide);
10379 tcg_temp_free_i64(tcg_op1);
10380 tcg_temp_free_i64(tcg_op2_wide);
10383 for (pass = 0; pass < 2; pass++) {
10384 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
10385 tcg_temp_free_i64(tcg_res[pass]);
10389 static void do_narrow_round_high_u32(TCGv_i32 res, TCGv_i64 in)
10391 tcg_gen_addi_i64(in, in, 1U << 31);
10392 tcg_gen_extrh_i64_i32(res, in);
10395 static void handle_3rd_narrowing(DisasContext *s, int is_q, int is_u, int size,
10396 int opcode, int rd, int rn, int rm)
10398 TCGv_i32 tcg_res[2];
10399 int part = is_q ? 2 : 0;
10402 for (pass = 0; pass < 2; pass++) {
10403 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10404 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10405 TCGv_i64 tcg_wideres = tcg_temp_new_i64();
10406 static NeonGenNarrowFn * const narrowfns[3][2] = {
10407 { gen_helper_neon_narrow_high_u8,
10408 gen_helper_neon_narrow_round_high_u8 },
10409 { gen_helper_neon_narrow_high_u16,
10410 gen_helper_neon_narrow_round_high_u16 },
10411 { tcg_gen_extrh_i64_i32, do_narrow_round_high_u32 },
10413 NeonGenNarrowFn *gennarrow = narrowfns[size][is_u];
10415 read_vec_element(s, tcg_op1, rn, pass, MO_64);
10416 read_vec_element(s, tcg_op2, rm, pass, MO_64);
10418 gen_neon_addl(size, (opcode == 6), tcg_wideres, tcg_op1, tcg_op2);
10420 tcg_temp_free_i64(tcg_op1);
10421 tcg_temp_free_i64(tcg_op2);
10423 tcg_res[pass] = tcg_temp_new_i32();
10424 gennarrow(tcg_res[pass], tcg_wideres);
10425 tcg_temp_free_i64(tcg_wideres);
10428 for (pass = 0; pass < 2; pass++) {
10429 write_vec_element_i32(s, tcg_res[pass], rd, pass + part, MO_32);
10430 tcg_temp_free_i32(tcg_res[pass]);
10432 clear_vec_high(s, is_q, rd);
10435 static void handle_pmull_64(DisasContext *s, int is_q, int rd, int rn, int rm)
10437 /* PMULL of 64 x 64 -> 128 is an odd special case because it
10438 * is the only three-reg-diff instruction which produces a
10439 * 128-bit wide result from a single operation. However since
10440 * it's possible to calculate the two halves more or less
10441 * separately we just use two helper calls.
10443 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10444 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10445 TCGv_i64 tcg_res = tcg_temp_new_i64();
10447 read_vec_element(s, tcg_op1, rn, is_q, MO_64);
10448 read_vec_element(s, tcg_op2, rm, is_q, MO_64);
10449 gen_helper_neon_pmull_64_lo(tcg_res, tcg_op1, tcg_op2);
10450 write_vec_element(s, tcg_res, rd, 0, MO_64);
10451 gen_helper_neon_pmull_64_hi(tcg_res, tcg_op1, tcg_op2);
10452 write_vec_element(s, tcg_res, rd, 1, MO_64);
10454 tcg_temp_free_i64(tcg_op1);
10455 tcg_temp_free_i64(tcg_op2);
10456 tcg_temp_free_i64(tcg_res);
10459 /* AdvSIMD three different
10460 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
10461 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10462 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
10463 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10465 static void disas_simd_three_reg_diff(DisasContext *s, uint32_t insn)
10467 /* Instructions in this group fall into three basic classes
10468 * (in each case with the operation working on each element in
10469 * the input vectors):
10470 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
10472 * (2) wide 64 x 128 -> 128
10473 * (3) narrowing 128 x 128 -> 64
10474 * Here we do initial decode, catch unallocated cases and
10475 * dispatch to separate functions for each class.
10477 int is_q = extract32(insn, 30, 1);
10478 int is_u = extract32(insn, 29, 1);
10479 int size = extract32(insn, 22, 2);
10480 int opcode = extract32(insn, 12, 4);
10481 int rm = extract32(insn, 16, 5);
10482 int rn = extract32(insn, 5, 5);
10483 int rd = extract32(insn, 0, 5);
10486 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
10487 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
10488 /* 64 x 128 -> 128 */
10490 unallocated_encoding(s);
10493 if (!fp_access_check(s)) {
10496 handle_3rd_wide(s, is_q, is_u, size, opcode, rd, rn, rm);
10498 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
10499 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
10500 /* 128 x 128 -> 64 */
10502 unallocated_encoding(s);
10505 if (!fp_access_check(s)) {
10508 handle_3rd_narrowing(s, is_q, is_u, size, opcode, rd, rn, rm);
10510 case 14: /* PMULL, PMULL2 */
10511 if (is_u || size == 1 || size == 2) {
10512 unallocated_encoding(s);
10516 if (!dc_isar_feature(aa64_pmull, s)) {
10517 unallocated_encoding(s);
10520 if (!fp_access_check(s)) {
10523 handle_pmull_64(s, is_q, rd, rn, rm);
10527 case 9: /* SQDMLAL, SQDMLAL2 */
10528 case 11: /* SQDMLSL, SQDMLSL2 */
10529 case 13: /* SQDMULL, SQDMULL2 */
10530 if (is_u || size == 0) {
10531 unallocated_encoding(s);
10535 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10536 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10537 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10538 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10539 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10540 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10541 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
10542 /* 64 x 64 -> 128 */
10544 unallocated_encoding(s);
10548 if (!fp_access_check(s)) {
10552 handle_3rd_widening(s, is_q, is_u, size, opcode, rd, rn, rm);
10555 /* opcode 15 not allocated */
10556 unallocated_encoding(s);
10561 /* Logic op (opcode == 3) subgroup of C3.6.16. */
10562 static void disas_simd_3same_logic(DisasContext *s, uint32_t insn)
10564 int rd = extract32(insn, 0, 5);
10565 int rn = extract32(insn, 5, 5);
10566 int rm = extract32(insn, 16, 5);
10567 int size = extract32(insn, 22, 2);
10568 bool is_u = extract32(insn, 29, 1);
10569 bool is_q = extract32(insn, 30, 1);
10571 if (!fp_access_check(s)) {
10575 switch (size + 4 * is_u) {
10577 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_and, 0);
10580 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_andc, 0);
10583 if (rn == rm) { /* MOV */
10584 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_mov, 0);
10586 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_or, 0);
10590 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_orc, 0);
10593 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_xor, 0);
10596 case 5: /* BSL bitwise select */
10597 gen_gvec_op3(s, is_q, rd, rn, rm, &bsl_op);
10599 case 6: /* BIT, bitwise insert if true */
10600 gen_gvec_op3(s, is_q, rd, rn, rm, &bit_op);
10602 case 7: /* BIF, bitwise insert if false */
10603 gen_gvec_op3(s, is_q, rd, rn, rm, &bif_op);
10607 g_assert_not_reached();
10611 /* Pairwise op subgroup of C3.6.16.
10613 * This is called directly or via the handle_3same_float for float pairwise
10614 * operations where the opcode and size are calculated differently.
10616 static void handle_simd_3same_pair(DisasContext *s, int is_q, int u, int opcode,
10617 int size, int rn, int rm, int rd)
10622 /* Floating point operations need fpst */
10623 if (opcode >= 0x58) {
10624 fpst = get_fpstatus_ptr(false);
10629 if (!fp_access_check(s)) {
10633 /* These operations work on the concatenated rm:rn, with each pair of
10634 * adjacent elements being operated on to produce an element in the result.
10637 TCGv_i64 tcg_res[2];
10639 for (pass = 0; pass < 2; pass++) {
10640 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10641 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10642 int passreg = (pass == 0) ? rn : rm;
10644 read_vec_element(s, tcg_op1, passreg, 0, MO_64);
10645 read_vec_element(s, tcg_op2, passreg, 1, MO_64);
10646 tcg_res[pass] = tcg_temp_new_i64();
10649 case 0x17: /* ADDP */
10650 tcg_gen_add_i64(tcg_res[pass], tcg_op1, tcg_op2);
10652 case 0x58: /* FMAXNMP */
10653 gen_helper_vfp_maxnumd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10655 case 0x5a: /* FADDP */
10656 gen_helper_vfp_addd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10658 case 0x5e: /* FMAXP */
10659 gen_helper_vfp_maxd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10661 case 0x78: /* FMINNMP */
10662 gen_helper_vfp_minnumd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10664 case 0x7e: /* FMINP */
10665 gen_helper_vfp_mind(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10668 g_assert_not_reached();
10671 tcg_temp_free_i64(tcg_op1);
10672 tcg_temp_free_i64(tcg_op2);
10675 for (pass = 0; pass < 2; pass++) {
10676 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
10677 tcg_temp_free_i64(tcg_res[pass]);
10680 int maxpass = is_q ? 4 : 2;
10681 TCGv_i32 tcg_res[4];
10683 for (pass = 0; pass < maxpass; pass++) {
10684 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
10685 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10686 NeonGenTwoOpFn *genfn = NULL;
10687 int passreg = pass < (maxpass / 2) ? rn : rm;
10688 int passelt = (is_q && (pass & 1)) ? 2 : 0;
10690 read_vec_element_i32(s, tcg_op1, passreg, passelt, MO_32);
10691 read_vec_element_i32(s, tcg_op2, passreg, passelt + 1, MO_32);
10692 tcg_res[pass] = tcg_temp_new_i32();
10695 case 0x17: /* ADDP */
10697 static NeonGenTwoOpFn * const fns[3] = {
10698 gen_helper_neon_padd_u8,
10699 gen_helper_neon_padd_u16,
10705 case 0x14: /* SMAXP, UMAXP */
10707 static NeonGenTwoOpFn * const fns[3][2] = {
10708 { gen_helper_neon_pmax_s8, gen_helper_neon_pmax_u8 },
10709 { gen_helper_neon_pmax_s16, gen_helper_neon_pmax_u16 },
10710 { tcg_gen_smax_i32, tcg_gen_umax_i32 },
10712 genfn = fns[size][u];
10715 case 0x15: /* SMINP, UMINP */
10717 static NeonGenTwoOpFn * const fns[3][2] = {
10718 { gen_helper_neon_pmin_s8, gen_helper_neon_pmin_u8 },
10719 { gen_helper_neon_pmin_s16, gen_helper_neon_pmin_u16 },
10720 { tcg_gen_smin_i32, tcg_gen_umin_i32 },
10722 genfn = fns[size][u];
10725 /* The FP operations are all on single floats (32 bit) */
10726 case 0x58: /* FMAXNMP */
10727 gen_helper_vfp_maxnums(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10729 case 0x5a: /* FADDP */
10730 gen_helper_vfp_adds(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10732 case 0x5e: /* FMAXP */
10733 gen_helper_vfp_maxs(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10735 case 0x78: /* FMINNMP */
10736 gen_helper_vfp_minnums(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10738 case 0x7e: /* FMINP */
10739 gen_helper_vfp_mins(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10742 g_assert_not_reached();
10745 /* FP ops called directly, otherwise call now */
10747 genfn(tcg_res[pass], tcg_op1, tcg_op2);
10750 tcg_temp_free_i32(tcg_op1);
10751 tcg_temp_free_i32(tcg_op2);
10754 for (pass = 0; pass < maxpass; pass++) {
10755 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32);
10756 tcg_temp_free_i32(tcg_res[pass]);
10758 clear_vec_high(s, is_q, rd);
10762 tcg_temp_free_ptr(fpst);
10766 /* Floating point op subgroup of C3.6.16. */
10767 static void disas_simd_3same_float(DisasContext *s, uint32_t insn)
10769 /* For floating point ops, the U, size[1] and opcode bits
10770 * together indicate the operation. size[0] indicates single
10773 int fpopcode = extract32(insn, 11, 5)
10774 | (extract32(insn, 23, 1) << 5)
10775 | (extract32(insn, 29, 1) << 6);
10776 int is_q = extract32(insn, 30, 1);
10777 int size = extract32(insn, 22, 1);
10778 int rm = extract32(insn, 16, 5);
10779 int rn = extract32(insn, 5, 5);
10780 int rd = extract32(insn, 0, 5);
10782 int datasize = is_q ? 128 : 64;
10783 int esize = 32 << size;
10784 int elements = datasize / esize;
10786 if (size == 1 && !is_q) {
10787 unallocated_encoding(s);
10791 switch (fpopcode) {
10792 case 0x58: /* FMAXNMP */
10793 case 0x5a: /* FADDP */
10794 case 0x5e: /* FMAXP */
10795 case 0x78: /* FMINNMP */
10796 case 0x7e: /* FMINP */
10797 if (size && !is_q) {
10798 unallocated_encoding(s);
10801 handle_simd_3same_pair(s, is_q, 0, fpopcode, size ? MO_64 : MO_32,
10804 case 0x1b: /* FMULX */
10805 case 0x1f: /* FRECPS */
10806 case 0x3f: /* FRSQRTS */
10807 case 0x5d: /* FACGE */
10808 case 0x7d: /* FACGT */
10809 case 0x19: /* FMLA */
10810 case 0x39: /* FMLS */
10811 case 0x18: /* FMAXNM */
10812 case 0x1a: /* FADD */
10813 case 0x1c: /* FCMEQ */
10814 case 0x1e: /* FMAX */
10815 case 0x38: /* FMINNM */
10816 case 0x3a: /* FSUB */
10817 case 0x3e: /* FMIN */
10818 case 0x5b: /* FMUL */
10819 case 0x5c: /* FCMGE */
10820 case 0x5f: /* FDIV */
10821 case 0x7a: /* FABD */
10822 case 0x7c: /* FCMGT */
10823 if (!fp_access_check(s)) {
10827 handle_3same_float(s, size, elements, fpopcode, rd, rn, rm);
10830 unallocated_encoding(s);
10835 /* Integer op subgroup of C3.6.16. */
10836 static void disas_simd_3same_int(DisasContext *s, uint32_t insn)
10838 int is_q = extract32(insn, 30, 1);
10839 int u = extract32(insn, 29, 1);
10840 int size = extract32(insn, 22, 2);
10841 int opcode = extract32(insn, 11, 5);
10842 int rm = extract32(insn, 16, 5);
10843 int rn = extract32(insn, 5, 5);
10844 int rd = extract32(insn, 0, 5);
10849 case 0x13: /* MUL, PMUL */
10850 if (u && size != 0) {
10851 unallocated_encoding(s);
10855 case 0x0: /* SHADD, UHADD */
10856 case 0x2: /* SRHADD, URHADD */
10857 case 0x4: /* SHSUB, UHSUB */
10858 case 0xc: /* SMAX, UMAX */
10859 case 0xd: /* SMIN, UMIN */
10860 case 0xe: /* SABD, UABD */
10861 case 0xf: /* SABA, UABA */
10862 case 0x12: /* MLA, MLS */
10864 unallocated_encoding(s);
10868 case 0x16: /* SQDMULH, SQRDMULH */
10869 if (size == 0 || size == 3) {
10870 unallocated_encoding(s);
10875 if (size == 3 && !is_q) {
10876 unallocated_encoding(s);
10882 if (!fp_access_check(s)) {
10887 case 0x10: /* ADD, SUB */
10889 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_sub, size);
10891 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_add, size);
10894 case 0x13: /* MUL, PMUL */
10895 if (!u) { /* MUL */
10896 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_mul, size);
10900 case 0x12: /* MLA, MLS */
10902 gen_gvec_op3(s, is_q, rd, rn, rm, &mls_op[size]);
10904 gen_gvec_op3(s, is_q, rd, rn, rm, &mla_op[size]);
10908 if (!u) { /* CMTST */
10909 gen_gvec_op3(s, is_q, rd, rn, rm, &cmtst_op[size]);
10913 cond = TCG_COND_EQ;
10915 case 0x06: /* CMGT, CMHI */
10916 cond = u ? TCG_COND_GTU : TCG_COND_GT;
10918 case 0x07: /* CMGE, CMHS */
10919 cond = u ? TCG_COND_GEU : TCG_COND_GE;
10921 tcg_gen_gvec_cmp(cond, size, vec_full_reg_offset(s, rd),
10922 vec_full_reg_offset(s, rn),
10923 vec_full_reg_offset(s, rm),
10924 is_q ? 16 : 8, vec_full_reg_size(s));
10930 for (pass = 0; pass < 2; pass++) {
10931 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10932 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10933 TCGv_i64 tcg_res = tcg_temp_new_i64();
10935 read_vec_element(s, tcg_op1, rn, pass, MO_64);
10936 read_vec_element(s, tcg_op2, rm, pass, MO_64);
10938 handle_3same_64(s, opcode, u, tcg_res, tcg_op1, tcg_op2);
10940 write_vec_element(s, tcg_res, rd, pass, MO_64);
10942 tcg_temp_free_i64(tcg_res);
10943 tcg_temp_free_i64(tcg_op1);
10944 tcg_temp_free_i64(tcg_op2);
10947 for (pass = 0; pass < (is_q ? 4 : 2); pass++) {
10948 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
10949 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10950 TCGv_i32 tcg_res = tcg_temp_new_i32();
10951 NeonGenTwoOpFn *genfn = NULL;
10952 NeonGenTwoOpEnvFn *genenvfn = NULL;
10954 read_vec_element_i32(s, tcg_op1, rn, pass, MO_32);
10955 read_vec_element_i32(s, tcg_op2, rm, pass, MO_32);
10958 case 0x0: /* SHADD, UHADD */
10960 static NeonGenTwoOpFn * const fns[3][2] = {
10961 { gen_helper_neon_hadd_s8, gen_helper_neon_hadd_u8 },
10962 { gen_helper_neon_hadd_s16, gen_helper_neon_hadd_u16 },
10963 { gen_helper_neon_hadd_s32, gen_helper_neon_hadd_u32 },
10965 genfn = fns[size][u];
10968 case 0x1: /* SQADD, UQADD */
10970 static NeonGenTwoOpEnvFn * const fns[3][2] = {
10971 { gen_helper_neon_qadd_s8, gen_helper_neon_qadd_u8 },
10972 { gen_helper_neon_qadd_s16, gen_helper_neon_qadd_u16 },
10973 { gen_helper_neon_qadd_s32, gen_helper_neon_qadd_u32 },
10975 genenvfn = fns[size][u];
10978 case 0x2: /* SRHADD, URHADD */
10980 static NeonGenTwoOpFn * const fns[3][2] = {
10981 { gen_helper_neon_rhadd_s8, gen_helper_neon_rhadd_u8 },
10982 { gen_helper_neon_rhadd_s16, gen_helper_neon_rhadd_u16 },
10983 { gen_helper_neon_rhadd_s32, gen_helper_neon_rhadd_u32 },
10985 genfn = fns[size][u];
10988 case 0x4: /* SHSUB, UHSUB */
10990 static NeonGenTwoOpFn * const fns[3][2] = {
10991 { gen_helper_neon_hsub_s8, gen_helper_neon_hsub_u8 },
10992 { gen_helper_neon_hsub_s16, gen_helper_neon_hsub_u16 },
10993 { gen_helper_neon_hsub_s32, gen_helper_neon_hsub_u32 },
10995 genfn = fns[size][u];
10998 case 0x5: /* SQSUB, UQSUB */
11000 static NeonGenTwoOpEnvFn * const fns[3][2] = {
11001 { gen_helper_neon_qsub_s8, gen_helper_neon_qsub_u8 },
11002 { gen_helper_neon_qsub_s16, gen_helper_neon_qsub_u16 },
11003 { gen_helper_neon_qsub_s32, gen_helper_neon_qsub_u32 },
11005 genenvfn = fns[size][u];
11008 case 0x8: /* SSHL, USHL */
11010 static NeonGenTwoOpFn * const fns[3][2] = {
11011 { gen_helper_neon_shl_s8, gen_helper_neon_shl_u8 },
11012 { gen_helper_neon_shl_s16, gen_helper_neon_shl_u16 },
11013 { gen_helper_neon_shl_s32, gen_helper_neon_shl_u32 },
11015 genfn = fns[size][u];
11018 case 0x9: /* SQSHL, UQSHL */
11020 static NeonGenTwoOpEnvFn * const fns[3][2] = {
11021 { gen_helper_neon_qshl_s8, gen_helper_neon_qshl_u8 },
11022 { gen_helper_neon_qshl_s16, gen_helper_neon_qshl_u16 },
11023 { gen_helper_neon_qshl_s32, gen_helper_neon_qshl_u32 },
11025 genenvfn = fns[size][u];
11028 case 0xa: /* SRSHL, URSHL */
11030 static NeonGenTwoOpFn * const fns[3][2] = {
11031 { gen_helper_neon_rshl_s8, gen_helper_neon_rshl_u8 },
11032 { gen_helper_neon_rshl_s16, gen_helper_neon_rshl_u16 },
11033 { gen_helper_neon_rshl_s32, gen_helper_neon_rshl_u32 },
11035 genfn = fns[size][u];
11038 case 0xb: /* SQRSHL, UQRSHL */
11040 static NeonGenTwoOpEnvFn * const fns[3][2] = {
11041 { gen_helper_neon_qrshl_s8, gen_helper_neon_qrshl_u8 },
11042 { gen_helper_neon_qrshl_s16, gen_helper_neon_qrshl_u16 },
11043 { gen_helper_neon_qrshl_s32, gen_helper_neon_qrshl_u32 },
11045 genenvfn = fns[size][u];
11048 case 0xc: /* SMAX, UMAX */
11050 static NeonGenTwoOpFn * const fns[3][2] = {
11051 { gen_helper_neon_max_s8, gen_helper_neon_max_u8 },
11052 { gen_helper_neon_max_s16, gen_helper_neon_max_u16 },
11053 { tcg_gen_smax_i32, tcg_gen_umax_i32 },
11055 genfn = fns[size][u];
11059 case 0xd: /* SMIN, UMIN */
11061 static NeonGenTwoOpFn * const fns[3][2] = {
11062 { gen_helper_neon_min_s8, gen_helper_neon_min_u8 },
11063 { gen_helper_neon_min_s16, gen_helper_neon_min_u16 },
11064 { tcg_gen_smin_i32, tcg_gen_umin_i32 },
11066 genfn = fns[size][u];
11069 case 0xe: /* SABD, UABD */
11070 case 0xf: /* SABA, UABA */
11072 static NeonGenTwoOpFn * const fns[3][2] = {
11073 { gen_helper_neon_abd_s8, gen_helper_neon_abd_u8 },
11074 { gen_helper_neon_abd_s16, gen_helper_neon_abd_u16 },
11075 { gen_helper_neon_abd_s32, gen_helper_neon_abd_u32 },
11077 genfn = fns[size][u];
11080 case 0x13: /* MUL, PMUL */
11081 assert(u); /* PMUL */
11083 genfn = gen_helper_neon_mul_p8;
11085 case 0x16: /* SQDMULH, SQRDMULH */
11087 static NeonGenTwoOpEnvFn * const fns[2][2] = {
11088 { gen_helper_neon_qdmulh_s16, gen_helper_neon_qrdmulh_s16 },
11089 { gen_helper_neon_qdmulh_s32, gen_helper_neon_qrdmulh_s32 },
11091 assert(size == 1 || size == 2);
11092 genenvfn = fns[size - 1][u];
11096 g_assert_not_reached();
11100 genenvfn(tcg_res, cpu_env, tcg_op1, tcg_op2);
11102 genfn(tcg_res, tcg_op1, tcg_op2);
11105 if (opcode == 0xf) {
11106 /* SABA, UABA: accumulating ops */
11107 static NeonGenTwoOpFn * const fns[3] = {
11108 gen_helper_neon_add_u8,
11109 gen_helper_neon_add_u16,
11113 read_vec_element_i32(s, tcg_op1, rd, pass, MO_32);
11114 fns[size](tcg_res, tcg_op1, tcg_res);
11117 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
11119 tcg_temp_free_i32(tcg_res);
11120 tcg_temp_free_i32(tcg_op1);
11121 tcg_temp_free_i32(tcg_op2);
11124 clear_vec_high(s, is_q, rd);
11127 /* AdvSIMD three same
11128 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11129 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11130 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11131 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11133 static void disas_simd_three_reg_same(DisasContext *s, uint32_t insn)
11135 int opcode = extract32(insn, 11, 5);
11138 case 0x3: /* logic ops */
11139 disas_simd_3same_logic(s, insn);
11141 case 0x17: /* ADDP */
11142 case 0x14: /* SMAXP, UMAXP */
11143 case 0x15: /* SMINP, UMINP */
11145 /* Pairwise operations */
11146 int is_q = extract32(insn, 30, 1);
11147 int u = extract32(insn, 29, 1);
11148 int size = extract32(insn, 22, 2);
11149 int rm = extract32(insn, 16, 5);
11150 int rn = extract32(insn, 5, 5);
11151 int rd = extract32(insn, 0, 5);
11152 if (opcode == 0x17) {
11153 if (u || (size == 3 && !is_q)) {
11154 unallocated_encoding(s);
11159 unallocated_encoding(s);
11163 handle_simd_3same_pair(s, is_q, u, opcode, size, rn, rm, rd);
11166 case 0x18 ... 0x31:
11167 /* floating point ops, sz[1] and U are part of opcode */
11168 disas_simd_3same_float(s, insn);
11171 disas_simd_3same_int(s, insn);
11177 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11179 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11180 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11181 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11182 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11184 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11185 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11188 static void disas_simd_three_reg_same_fp16(DisasContext *s, uint32_t insn)
11190 int opcode, fpopcode;
11191 int is_q, u, a, rm, rn, rd;
11192 int datasize, elements;
11195 bool pairwise = false;
11197 if (!dc_isar_feature(aa64_fp16, s)) {
11198 unallocated_encoding(s);
11202 if (!fp_access_check(s)) {
11206 /* For these floating point ops, the U, a and opcode bits
11207 * together indicate the operation.
11209 opcode = extract32(insn, 11, 3);
11210 u = extract32(insn, 29, 1);
11211 a = extract32(insn, 23, 1);
11212 is_q = extract32(insn, 30, 1);
11213 rm = extract32(insn, 16, 5);
11214 rn = extract32(insn, 5, 5);
11215 rd = extract32(insn, 0, 5);
11217 fpopcode = opcode | (a << 3) | (u << 4);
11218 datasize = is_q ? 128 : 64;
11219 elements = datasize / 16;
11221 switch (fpopcode) {
11222 case 0x10: /* FMAXNMP */
11223 case 0x12: /* FADDP */
11224 case 0x16: /* FMAXP */
11225 case 0x18: /* FMINNMP */
11226 case 0x1e: /* FMINP */
11231 fpst = get_fpstatus_ptr(true);
11234 int maxpass = is_q ? 8 : 4;
11235 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
11236 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
11237 TCGv_i32 tcg_res[8];
11239 for (pass = 0; pass < maxpass; pass++) {
11240 int passreg = pass < (maxpass / 2) ? rn : rm;
11241 int passelt = (pass << 1) & (maxpass - 1);
11243 read_vec_element_i32(s, tcg_op1, passreg, passelt, MO_16);
11244 read_vec_element_i32(s, tcg_op2, passreg, passelt + 1, MO_16);
11245 tcg_res[pass] = tcg_temp_new_i32();
11247 switch (fpopcode) {
11248 case 0x10: /* FMAXNMP */
11249 gen_helper_advsimd_maxnumh(tcg_res[pass], tcg_op1, tcg_op2,
11252 case 0x12: /* FADDP */
11253 gen_helper_advsimd_addh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11255 case 0x16: /* FMAXP */
11256 gen_helper_advsimd_maxh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11258 case 0x18: /* FMINNMP */
11259 gen_helper_advsimd_minnumh(tcg_res[pass], tcg_op1, tcg_op2,
11262 case 0x1e: /* FMINP */
11263 gen_helper_advsimd_minh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11266 g_assert_not_reached();
11270 for (pass = 0; pass < maxpass; pass++) {
11271 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_16);
11272 tcg_temp_free_i32(tcg_res[pass]);
11275 tcg_temp_free_i32(tcg_op1);
11276 tcg_temp_free_i32(tcg_op2);
11279 for (pass = 0; pass < elements; pass++) {
11280 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
11281 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
11282 TCGv_i32 tcg_res = tcg_temp_new_i32();
11284 read_vec_element_i32(s, tcg_op1, rn, pass, MO_16);
11285 read_vec_element_i32(s, tcg_op2, rm, pass, MO_16);
11287 switch (fpopcode) {
11288 case 0x0: /* FMAXNM */
11289 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
11291 case 0x1: /* FMLA */
11292 read_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11293 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_res,
11296 case 0x2: /* FADD */
11297 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
11299 case 0x3: /* FMULX */
11300 gen_helper_advsimd_mulxh(tcg_res, tcg_op1, tcg_op2, fpst);
11302 case 0x4: /* FCMEQ */
11303 gen_helper_advsimd_ceq_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11305 case 0x6: /* FMAX */
11306 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
11308 case 0x7: /* FRECPS */
11309 gen_helper_recpsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11311 case 0x8: /* FMINNM */
11312 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
11314 case 0x9: /* FMLS */
11315 /* As usual for ARM, separate negation for fused multiply-add */
11316 tcg_gen_xori_i32(tcg_op1, tcg_op1, 0x8000);
11317 read_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11318 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_res,
11321 case 0xa: /* FSUB */
11322 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
11324 case 0xe: /* FMIN */
11325 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
11327 case 0xf: /* FRSQRTS */
11328 gen_helper_rsqrtsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11330 case 0x13: /* FMUL */
11331 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
11333 case 0x14: /* FCMGE */
11334 gen_helper_advsimd_cge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11336 case 0x15: /* FACGE */
11337 gen_helper_advsimd_acge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11339 case 0x17: /* FDIV */
11340 gen_helper_advsimd_divh(tcg_res, tcg_op1, tcg_op2, fpst);
11342 case 0x1a: /* FABD */
11343 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
11344 tcg_gen_andi_i32(tcg_res, tcg_res, 0x7fff);
11346 case 0x1c: /* FCMGT */
11347 gen_helper_advsimd_cgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11349 case 0x1d: /* FACGT */
11350 gen_helper_advsimd_acgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11353 fprintf(stderr, "%s: insn %#04x, fpop %#2x @ %#" PRIx64 "\n",
11354 __func__, insn, fpopcode, s->pc);
11355 g_assert_not_reached();
11358 write_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11359 tcg_temp_free_i32(tcg_res);
11360 tcg_temp_free_i32(tcg_op1);
11361 tcg_temp_free_i32(tcg_op2);
11365 tcg_temp_free_ptr(fpst);
11367 clear_vec_high(s, is_q, rd);
11370 /* AdvSIMD three same extra
11371 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
11372 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11373 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
11374 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11376 static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
11378 int rd = extract32(insn, 0, 5);
11379 int rn = extract32(insn, 5, 5);
11380 int opcode = extract32(insn, 11, 4);
11381 int rm = extract32(insn, 16, 5);
11382 int size = extract32(insn, 22, 2);
11383 bool u = extract32(insn, 29, 1);
11384 bool is_q = extract32(insn, 30, 1);
11388 switch (u * 16 + opcode) {
11389 case 0x10: /* SQRDMLAH (vector) */
11390 case 0x11: /* SQRDMLSH (vector) */
11391 if (size != 1 && size != 2) {
11392 unallocated_encoding(s);
11395 feature = dc_isar_feature(aa64_rdm, s);
11397 case 0x02: /* SDOT (vector) */
11398 case 0x12: /* UDOT (vector) */
11399 if (size != MO_32) {
11400 unallocated_encoding(s);
11403 feature = dc_isar_feature(aa64_dp, s);
11405 case 0x18: /* FCMLA, #0 */
11406 case 0x19: /* FCMLA, #90 */
11407 case 0x1a: /* FCMLA, #180 */
11408 case 0x1b: /* FCMLA, #270 */
11409 case 0x1c: /* FCADD, #90 */
11410 case 0x1e: /* FCADD, #270 */
11412 || (size == 1 && !dc_isar_feature(aa64_fp16, s))
11413 || (size == 3 && !is_q)) {
11414 unallocated_encoding(s);
11417 feature = dc_isar_feature(aa64_fcma, s);
11420 unallocated_encoding(s);
11424 unallocated_encoding(s);
11427 if (!fp_access_check(s)) {
11432 case 0x0: /* SQRDMLAH (vector) */
11435 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s16);
11438 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s32);
11441 g_assert_not_reached();
11445 case 0x1: /* SQRDMLSH (vector) */
11448 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s16);
11451 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s32);
11454 g_assert_not_reached();
11458 case 0x2: /* SDOT / UDOT */
11459 gen_gvec_op3_ool(s, is_q, rd, rn, rm, 0,
11460 u ? gen_helper_gvec_udot_b : gen_helper_gvec_sdot_b);
11463 case 0x8: /* FCMLA, #0 */
11464 case 0x9: /* FCMLA, #90 */
11465 case 0xa: /* FCMLA, #180 */
11466 case 0xb: /* FCMLA, #270 */
11467 rot = extract32(opcode, 0, 2);
11470 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, true, rot,
11471 gen_helper_gvec_fcmlah);
11474 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
11475 gen_helper_gvec_fcmlas);
11478 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
11479 gen_helper_gvec_fcmlad);
11482 g_assert_not_reached();
11486 case 0xc: /* FCADD, #90 */
11487 case 0xe: /* FCADD, #270 */
11488 rot = extract32(opcode, 1, 1);
11491 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11492 gen_helper_gvec_fcaddh);
11495 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11496 gen_helper_gvec_fcadds);
11499 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11500 gen_helper_gvec_fcaddd);
11503 g_assert_not_reached();
11508 g_assert_not_reached();
11512 static void handle_2misc_widening(DisasContext *s, int opcode, bool is_q,
11513 int size, int rn, int rd)
11515 /* Handle 2-reg-misc ops which are widening (so each size element
11516 * in the source becomes a 2*size element in the destination.
11517 * The only instruction like this is FCVTL.
11522 /* 32 -> 64 bit fp conversion */
11523 TCGv_i64 tcg_res[2];
11524 int srcelt = is_q ? 2 : 0;
11526 for (pass = 0; pass < 2; pass++) {
11527 TCGv_i32 tcg_op = tcg_temp_new_i32();
11528 tcg_res[pass] = tcg_temp_new_i64();
11530 read_vec_element_i32(s, tcg_op, rn, srcelt + pass, MO_32);
11531 gen_helper_vfp_fcvtds(tcg_res[pass], tcg_op, cpu_env);
11532 tcg_temp_free_i32(tcg_op);
11534 for (pass = 0; pass < 2; pass++) {
11535 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11536 tcg_temp_free_i64(tcg_res[pass]);
11539 /* 16 -> 32 bit fp conversion */
11540 int srcelt = is_q ? 4 : 0;
11541 TCGv_i32 tcg_res[4];
11542 TCGv_ptr fpst = get_fpstatus_ptr(false);
11543 TCGv_i32 ahp = get_ahp_flag();
11545 for (pass = 0; pass < 4; pass++) {
11546 tcg_res[pass] = tcg_temp_new_i32();
11548 read_vec_element_i32(s, tcg_res[pass], rn, srcelt + pass, MO_16);
11549 gen_helper_vfp_fcvt_f16_to_f32(tcg_res[pass], tcg_res[pass],
11552 for (pass = 0; pass < 4; pass++) {
11553 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32);
11554 tcg_temp_free_i32(tcg_res[pass]);
11557 tcg_temp_free_ptr(fpst);
11558 tcg_temp_free_i32(ahp);
11562 static void handle_rev(DisasContext *s, int opcode, bool u,
11563 bool is_q, int size, int rn, int rd)
11565 int op = (opcode << 1) | u;
11566 int opsz = op + size;
11567 int grp_size = 3 - opsz;
11568 int dsize = is_q ? 128 : 64;
11572 unallocated_encoding(s);
11576 if (!fp_access_check(s)) {
11581 /* Special case bytes, use bswap op on each group of elements */
11582 int groups = dsize / (8 << grp_size);
11584 for (i = 0; i < groups; i++) {
11585 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
11587 read_vec_element(s, tcg_tmp, rn, i, grp_size);
11588 switch (grp_size) {
11590 tcg_gen_bswap16_i64(tcg_tmp, tcg_tmp);
11593 tcg_gen_bswap32_i64(tcg_tmp, tcg_tmp);
11596 tcg_gen_bswap64_i64(tcg_tmp, tcg_tmp);
11599 g_assert_not_reached();
11601 write_vec_element(s, tcg_tmp, rd, i, grp_size);
11602 tcg_temp_free_i64(tcg_tmp);
11604 clear_vec_high(s, is_q, rd);
11606 int revmask = (1 << grp_size) - 1;
11607 int esize = 8 << size;
11608 int elements = dsize / esize;
11609 TCGv_i64 tcg_rn = tcg_temp_new_i64();
11610 TCGv_i64 tcg_rd = tcg_const_i64(0);
11611 TCGv_i64 tcg_rd_hi = tcg_const_i64(0);
11613 for (i = 0; i < elements; i++) {
11614 int e_rev = (i & 0xf) ^ revmask;
11615 int off = e_rev * esize;
11616 read_vec_element(s, tcg_rn, rn, i, size);
11618 tcg_gen_deposit_i64(tcg_rd_hi, tcg_rd_hi,
11619 tcg_rn, off - 64, esize);
11621 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, off, esize);
11624 write_vec_element(s, tcg_rd, rd, 0, MO_64);
11625 write_vec_element(s, tcg_rd_hi, rd, 1, MO_64);
11627 tcg_temp_free_i64(tcg_rd_hi);
11628 tcg_temp_free_i64(tcg_rd);
11629 tcg_temp_free_i64(tcg_rn);
11633 static void handle_2misc_pairwise(DisasContext *s, int opcode, bool u,
11634 bool is_q, int size, int rn, int rd)
11636 /* Implement the pairwise operations from 2-misc:
11637 * SADDLP, UADDLP, SADALP, UADALP.
11638 * These all add pairs of elements in the input to produce a
11639 * double-width result element in the output (possibly accumulating).
11641 bool accum = (opcode == 0x6);
11642 int maxpass = is_q ? 2 : 1;
11644 TCGv_i64 tcg_res[2];
11647 /* 32 + 32 -> 64 op */
11648 TCGMemOp memop = size + (u ? 0 : MO_SIGN);
11650 for (pass = 0; pass < maxpass; pass++) {
11651 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
11652 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
11654 tcg_res[pass] = tcg_temp_new_i64();
11656 read_vec_element(s, tcg_op1, rn, pass * 2, memop);
11657 read_vec_element(s, tcg_op2, rn, pass * 2 + 1, memop);
11658 tcg_gen_add_i64(tcg_res[pass], tcg_op1, tcg_op2);
11660 read_vec_element(s, tcg_op1, rd, pass, MO_64);
11661 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
11664 tcg_temp_free_i64(tcg_op1);
11665 tcg_temp_free_i64(tcg_op2);
11668 for (pass = 0; pass < maxpass; pass++) {
11669 TCGv_i64 tcg_op = tcg_temp_new_i64();
11670 NeonGenOneOpFn *genfn;
11671 static NeonGenOneOpFn * const fns[2][2] = {
11672 { gen_helper_neon_addlp_s8, gen_helper_neon_addlp_u8 },
11673 { gen_helper_neon_addlp_s16, gen_helper_neon_addlp_u16 },
11676 genfn = fns[size][u];
11678 tcg_res[pass] = tcg_temp_new_i64();
11680 read_vec_element(s, tcg_op, rn, pass, MO_64);
11681 genfn(tcg_res[pass], tcg_op);
11684 read_vec_element(s, tcg_op, rd, pass, MO_64);
11686 gen_helper_neon_addl_u16(tcg_res[pass],
11687 tcg_res[pass], tcg_op);
11689 gen_helper_neon_addl_u32(tcg_res[pass],
11690 tcg_res[pass], tcg_op);
11693 tcg_temp_free_i64(tcg_op);
11697 tcg_res[1] = tcg_const_i64(0);
11699 for (pass = 0; pass < 2; pass++) {
11700 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11701 tcg_temp_free_i64(tcg_res[pass]);
11705 static void handle_shll(DisasContext *s, bool is_q, int size, int rn, int rd)
11707 /* Implement SHLL and SHLL2 */
11709 int part = is_q ? 2 : 0;
11710 TCGv_i64 tcg_res[2];
11712 for (pass = 0; pass < 2; pass++) {
11713 static NeonGenWidenFn * const widenfns[3] = {
11714 gen_helper_neon_widen_u8,
11715 gen_helper_neon_widen_u16,
11716 tcg_gen_extu_i32_i64,
11718 NeonGenWidenFn *widenfn = widenfns[size];
11719 TCGv_i32 tcg_op = tcg_temp_new_i32();
11721 read_vec_element_i32(s, tcg_op, rn, part + pass, MO_32);
11722 tcg_res[pass] = tcg_temp_new_i64();
11723 widenfn(tcg_res[pass], tcg_op);
11724 tcg_gen_shli_i64(tcg_res[pass], tcg_res[pass], 8 << size);
11726 tcg_temp_free_i32(tcg_op);
11729 for (pass = 0; pass < 2; pass++) {
11730 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11731 tcg_temp_free_i64(tcg_res[pass]);
11735 /* AdvSIMD two reg misc
11736 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
11737 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11738 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
11739 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11741 static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)
11743 int size = extract32(insn, 22, 2);
11744 int opcode = extract32(insn, 12, 5);
11745 bool u = extract32(insn, 29, 1);
11746 bool is_q = extract32(insn, 30, 1);
11747 int rn = extract32(insn, 5, 5);
11748 int rd = extract32(insn, 0, 5);
11749 bool need_fpstatus = false;
11750 bool need_rmode = false;
11752 TCGv_i32 tcg_rmode;
11753 TCGv_ptr tcg_fpstatus;
11756 case 0x0: /* REV64, REV32 */
11757 case 0x1: /* REV16 */
11758 handle_rev(s, opcode, u, is_q, size, rn, rd);
11760 case 0x5: /* CNT, NOT, RBIT */
11761 if (u && size == 0) {
11764 } else if (u && size == 1) {
11767 } else if (!u && size == 0) {
11771 unallocated_encoding(s);
11773 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
11774 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
11776 unallocated_encoding(s);
11779 if (!fp_access_check(s)) {
11783 handle_2misc_narrow(s, false, opcode, u, is_q, size, rn, rd);
11785 case 0x4: /* CLS, CLZ */
11787 unallocated_encoding(s);
11791 case 0x2: /* SADDLP, UADDLP */
11792 case 0x6: /* SADALP, UADALP */
11794 unallocated_encoding(s);
11797 if (!fp_access_check(s)) {
11800 handle_2misc_pairwise(s, opcode, u, is_q, size, rn, rd);
11802 case 0x13: /* SHLL, SHLL2 */
11803 if (u == 0 || size == 3) {
11804 unallocated_encoding(s);
11807 if (!fp_access_check(s)) {
11810 handle_shll(s, is_q, size, rn, rd);
11812 case 0xa: /* CMLT */
11814 unallocated_encoding(s);
11818 case 0x8: /* CMGT, CMGE */
11819 case 0x9: /* CMEQ, CMLE */
11820 case 0xb: /* ABS, NEG */
11821 if (size == 3 && !is_q) {
11822 unallocated_encoding(s);
11826 case 0x3: /* SUQADD, USQADD */
11827 if (size == 3 && !is_q) {
11828 unallocated_encoding(s);
11831 if (!fp_access_check(s)) {
11834 handle_2misc_satacc(s, false, u, is_q, size, rn, rd);
11836 case 0x7: /* SQABS, SQNEG */
11837 if (size == 3 && !is_q) {
11838 unallocated_encoding(s);
11843 case 0x16 ... 0x1d:
11846 /* Floating point: U, size[1] and opcode indicate operation;
11847 * size[0] indicates single or double precision.
11849 int is_double = extract32(size, 0, 1);
11850 opcode |= (extract32(size, 1, 1) << 5) | (u << 6);
11851 size = is_double ? 3 : 2;
11853 case 0x2f: /* FABS */
11854 case 0x6f: /* FNEG */
11855 if (size == 3 && !is_q) {
11856 unallocated_encoding(s);
11860 case 0x1d: /* SCVTF */
11861 case 0x5d: /* UCVTF */
11863 bool is_signed = (opcode == 0x1d) ? true : false;
11864 int elements = is_double ? 2 : is_q ? 4 : 2;
11865 if (is_double && !is_q) {
11866 unallocated_encoding(s);
11869 if (!fp_access_check(s)) {
11872 handle_simd_intfp_conv(s, rd, rn, elements, is_signed, 0, size);
11875 case 0x2c: /* FCMGT (zero) */
11876 case 0x2d: /* FCMEQ (zero) */
11877 case 0x2e: /* FCMLT (zero) */
11878 case 0x6c: /* FCMGE (zero) */
11879 case 0x6d: /* FCMLE (zero) */
11880 if (size == 3 && !is_q) {
11881 unallocated_encoding(s);
11884 handle_2misc_fcmp_zero(s, opcode, false, u, is_q, size, rn, rd);
11886 case 0x7f: /* FSQRT */
11887 if (size == 3 && !is_q) {
11888 unallocated_encoding(s);
11892 case 0x1a: /* FCVTNS */
11893 case 0x1b: /* FCVTMS */
11894 case 0x3a: /* FCVTPS */
11895 case 0x3b: /* FCVTZS */
11896 case 0x5a: /* FCVTNU */
11897 case 0x5b: /* FCVTMU */
11898 case 0x7a: /* FCVTPU */
11899 case 0x7b: /* FCVTZU */
11900 need_fpstatus = true;
11902 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
11903 if (size == 3 && !is_q) {
11904 unallocated_encoding(s);
11908 case 0x5c: /* FCVTAU */
11909 case 0x1c: /* FCVTAS */
11910 need_fpstatus = true;
11912 rmode = FPROUNDING_TIEAWAY;
11913 if (size == 3 && !is_q) {
11914 unallocated_encoding(s);
11918 case 0x3c: /* URECPE */
11920 unallocated_encoding(s);
11924 case 0x3d: /* FRECPE */
11925 case 0x7d: /* FRSQRTE */
11926 if (size == 3 && !is_q) {
11927 unallocated_encoding(s);
11930 if (!fp_access_check(s)) {
11933 handle_2misc_reciprocal(s, opcode, false, u, is_q, size, rn, rd);
11935 case 0x56: /* FCVTXN, FCVTXN2 */
11937 unallocated_encoding(s);
11941 case 0x16: /* FCVTN, FCVTN2 */
11942 /* handle_2misc_narrow does a 2*size -> size operation, but these
11943 * instructions encode the source size rather than dest size.
11945 if (!fp_access_check(s)) {
11948 handle_2misc_narrow(s, false, opcode, 0, is_q, size - 1, rn, rd);
11950 case 0x17: /* FCVTL, FCVTL2 */
11951 if (!fp_access_check(s)) {
11954 handle_2misc_widening(s, opcode, is_q, size, rn, rd);
11956 case 0x18: /* FRINTN */
11957 case 0x19: /* FRINTM */
11958 case 0x38: /* FRINTP */
11959 case 0x39: /* FRINTZ */
11961 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
11963 case 0x59: /* FRINTX */
11964 case 0x79: /* FRINTI */
11965 need_fpstatus = true;
11966 if (size == 3 && !is_q) {
11967 unallocated_encoding(s);
11971 case 0x58: /* FRINTA */
11973 rmode = FPROUNDING_TIEAWAY;
11974 need_fpstatus = true;
11975 if (size == 3 && !is_q) {
11976 unallocated_encoding(s);
11980 case 0x7c: /* URSQRTE */
11982 unallocated_encoding(s);
11985 need_fpstatus = true;
11988 unallocated_encoding(s);
11994 unallocated_encoding(s);
11998 if (!fp_access_check(s)) {
12002 if (need_fpstatus || need_rmode) {
12003 tcg_fpstatus = get_fpstatus_ptr(false);
12005 tcg_fpstatus = NULL;
12008 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
12009 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12016 if (u && size == 0) { /* NOT */
12017 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_not, 0);
12023 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_neg, size);
12030 /* All 64-bit element operations can be shared with scalar 2misc */
12033 /* Coverity claims (size == 3 && !is_q) has been eliminated
12034 * from all paths leading to here.
12036 tcg_debug_assert(is_q);
12037 for (pass = 0; pass < 2; pass++) {
12038 TCGv_i64 tcg_op = tcg_temp_new_i64();
12039 TCGv_i64 tcg_res = tcg_temp_new_i64();
12041 read_vec_element(s, tcg_op, rn, pass, MO_64);
12043 handle_2misc_64(s, opcode, u, tcg_res, tcg_op,
12044 tcg_rmode, tcg_fpstatus);
12046 write_vec_element(s, tcg_res, rd, pass, MO_64);
12048 tcg_temp_free_i64(tcg_res);
12049 tcg_temp_free_i64(tcg_op);
12054 for (pass = 0; pass < (is_q ? 4 : 2); pass++) {
12055 TCGv_i32 tcg_op = tcg_temp_new_i32();
12056 TCGv_i32 tcg_res = tcg_temp_new_i32();
12059 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
12062 /* Special cases for 32 bit elements */
12064 case 0xa: /* CMLT */
12065 /* 32 bit integer comparison against zero, result is
12066 * test ? (2^32 - 1) : 0. We implement via setcond(test)
12069 cond = TCG_COND_LT;
12071 tcg_gen_setcondi_i32(cond, tcg_res, tcg_op, 0);
12072 tcg_gen_neg_i32(tcg_res, tcg_res);
12074 case 0x8: /* CMGT, CMGE */
12075 cond = u ? TCG_COND_GE : TCG_COND_GT;
12077 case 0x9: /* CMEQ, CMLE */
12078 cond = u ? TCG_COND_LE : TCG_COND_EQ;
12080 case 0x4: /* CLS */
12082 tcg_gen_clzi_i32(tcg_res, tcg_op, 32);
12084 tcg_gen_clrsb_i32(tcg_res, tcg_op);
12087 case 0x7: /* SQABS, SQNEG */
12089 gen_helper_neon_qneg_s32(tcg_res, cpu_env, tcg_op);
12091 gen_helper_neon_qabs_s32(tcg_res, cpu_env, tcg_op);
12094 case 0xb: /* ABS, NEG */
12096 tcg_gen_neg_i32(tcg_res, tcg_op);
12098 TCGv_i32 tcg_zero = tcg_const_i32(0);
12099 tcg_gen_neg_i32(tcg_res, tcg_op);
12100 tcg_gen_movcond_i32(TCG_COND_GT, tcg_res, tcg_op,
12101 tcg_zero, tcg_op, tcg_res);
12102 tcg_temp_free_i32(tcg_zero);
12105 case 0x2f: /* FABS */
12106 gen_helper_vfp_abss(tcg_res, tcg_op);
12108 case 0x6f: /* FNEG */
12109 gen_helper_vfp_negs(tcg_res, tcg_op);
12111 case 0x7f: /* FSQRT */
12112 gen_helper_vfp_sqrts(tcg_res, tcg_op, cpu_env);
12114 case 0x1a: /* FCVTNS */
12115 case 0x1b: /* FCVTMS */
12116 case 0x1c: /* FCVTAS */
12117 case 0x3a: /* FCVTPS */
12118 case 0x3b: /* FCVTZS */
12120 TCGv_i32 tcg_shift = tcg_const_i32(0);
12121 gen_helper_vfp_tosls(tcg_res, tcg_op,
12122 tcg_shift, tcg_fpstatus);
12123 tcg_temp_free_i32(tcg_shift);
12126 case 0x5a: /* FCVTNU */
12127 case 0x5b: /* FCVTMU */
12128 case 0x5c: /* FCVTAU */
12129 case 0x7a: /* FCVTPU */
12130 case 0x7b: /* FCVTZU */
12132 TCGv_i32 tcg_shift = tcg_const_i32(0);
12133 gen_helper_vfp_touls(tcg_res, tcg_op,
12134 tcg_shift, tcg_fpstatus);
12135 tcg_temp_free_i32(tcg_shift);
12138 case 0x18: /* FRINTN */
12139 case 0x19: /* FRINTM */
12140 case 0x38: /* FRINTP */
12141 case 0x39: /* FRINTZ */
12142 case 0x58: /* FRINTA */
12143 case 0x79: /* FRINTI */
12144 gen_helper_rints(tcg_res, tcg_op, tcg_fpstatus);
12146 case 0x59: /* FRINTX */
12147 gen_helper_rints_exact(tcg_res, tcg_op, tcg_fpstatus);
12149 case 0x7c: /* URSQRTE */
12150 gen_helper_rsqrte_u32(tcg_res, tcg_op, tcg_fpstatus);
12153 g_assert_not_reached();
12156 /* Use helpers for 8 and 16 bit elements */
12158 case 0x5: /* CNT, RBIT */
12159 /* For these two insns size is part of the opcode specifier
12160 * (handled earlier); they always operate on byte elements.
12163 gen_helper_neon_rbit_u8(tcg_res, tcg_op);
12165 gen_helper_neon_cnt_u8(tcg_res, tcg_op);
12168 case 0x7: /* SQABS, SQNEG */
12170 NeonGenOneOpEnvFn *genfn;
12171 static NeonGenOneOpEnvFn * const fns[2][2] = {
12172 { gen_helper_neon_qabs_s8, gen_helper_neon_qneg_s8 },
12173 { gen_helper_neon_qabs_s16, gen_helper_neon_qneg_s16 },
12175 genfn = fns[size][u];
12176 genfn(tcg_res, cpu_env, tcg_op);
12179 case 0x8: /* CMGT, CMGE */
12180 case 0x9: /* CMEQ, CMLE */
12181 case 0xa: /* CMLT */
12183 static NeonGenTwoOpFn * const fns[3][2] = {
12184 { gen_helper_neon_cgt_s8, gen_helper_neon_cgt_s16 },
12185 { gen_helper_neon_cge_s8, gen_helper_neon_cge_s16 },
12186 { gen_helper_neon_ceq_u8, gen_helper_neon_ceq_u16 },
12188 NeonGenTwoOpFn *genfn;
12191 TCGv_i32 tcg_zero = tcg_const_i32(0);
12193 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
12194 comp = (opcode - 0x8) * 2 + u;
12195 /* ...but LE, LT are implemented as reverse GE, GT */
12196 reverse = (comp > 2);
12200 genfn = fns[comp][size];
12202 genfn(tcg_res, tcg_zero, tcg_op);
12204 genfn(tcg_res, tcg_op, tcg_zero);
12206 tcg_temp_free_i32(tcg_zero);
12209 case 0xb: /* ABS, NEG */
12211 TCGv_i32 tcg_zero = tcg_const_i32(0);
12213 gen_helper_neon_sub_u16(tcg_res, tcg_zero, tcg_op);
12215 gen_helper_neon_sub_u8(tcg_res, tcg_zero, tcg_op);
12217 tcg_temp_free_i32(tcg_zero);
12220 gen_helper_neon_abs_s16(tcg_res, tcg_op);
12222 gen_helper_neon_abs_s8(tcg_res, tcg_op);
12226 case 0x4: /* CLS, CLZ */
12229 gen_helper_neon_clz_u8(tcg_res, tcg_op);
12231 gen_helper_neon_clz_u16(tcg_res, tcg_op);
12235 gen_helper_neon_cls_s8(tcg_res, tcg_op);
12237 gen_helper_neon_cls_s16(tcg_res, tcg_op);
12242 g_assert_not_reached();
12246 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
12248 tcg_temp_free_i32(tcg_res);
12249 tcg_temp_free_i32(tcg_op);
12252 clear_vec_high(s, is_q, rd);
12255 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12256 tcg_temp_free_i32(tcg_rmode);
12258 if (need_fpstatus) {
12259 tcg_temp_free_ptr(tcg_fpstatus);
12263 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12265 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12266 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12267 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12268 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12269 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12270 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12272 * This actually covers two groups where scalar access is governed by
12273 * bit 28. A bunch of the instructions (float to integral) only exist
12274 * in the vector form and are un-allocated for the scalar decode. Also
12275 * in the scalar decode Q is always 1.
12277 static void disas_simd_two_reg_misc_fp16(DisasContext *s, uint32_t insn)
12279 int fpop, opcode, a, u;
12283 bool only_in_vector = false;
12286 TCGv_i32 tcg_rmode = NULL;
12287 TCGv_ptr tcg_fpstatus = NULL;
12288 bool need_rmode = false;
12289 bool need_fpst = true;
12292 if (!dc_isar_feature(aa64_fp16, s)) {
12293 unallocated_encoding(s);
12297 rd = extract32(insn, 0, 5);
12298 rn = extract32(insn, 5, 5);
12300 a = extract32(insn, 23, 1);
12301 u = extract32(insn, 29, 1);
12302 is_scalar = extract32(insn, 28, 1);
12303 is_q = extract32(insn, 30, 1);
12305 opcode = extract32(insn, 12, 5);
12306 fpop = deposit32(opcode, 5, 1, a);
12307 fpop = deposit32(fpop, 6, 1, u);
12309 rd = extract32(insn, 0, 5);
12310 rn = extract32(insn, 5, 5);
12313 case 0x1d: /* SCVTF */
12314 case 0x5d: /* UCVTF */
12321 elements = (is_q ? 8 : 4);
12324 if (!fp_access_check(s)) {
12327 handle_simd_intfp_conv(s, rd, rn, elements, !u, 0, MO_16);
12331 case 0x2c: /* FCMGT (zero) */
12332 case 0x2d: /* FCMEQ (zero) */
12333 case 0x2e: /* FCMLT (zero) */
12334 case 0x6c: /* FCMGE (zero) */
12335 case 0x6d: /* FCMLE (zero) */
12336 handle_2misc_fcmp_zero(s, fpop, is_scalar, 0, is_q, MO_16, rn, rd);
12338 case 0x3d: /* FRECPE */
12339 case 0x3f: /* FRECPX */
12341 case 0x18: /* FRINTN */
12343 only_in_vector = true;
12344 rmode = FPROUNDING_TIEEVEN;
12346 case 0x19: /* FRINTM */
12348 only_in_vector = true;
12349 rmode = FPROUNDING_NEGINF;
12351 case 0x38: /* FRINTP */
12353 only_in_vector = true;
12354 rmode = FPROUNDING_POSINF;
12356 case 0x39: /* FRINTZ */
12358 only_in_vector = true;
12359 rmode = FPROUNDING_ZERO;
12361 case 0x58: /* FRINTA */
12363 only_in_vector = true;
12364 rmode = FPROUNDING_TIEAWAY;
12366 case 0x59: /* FRINTX */
12367 case 0x79: /* FRINTI */
12368 only_in_vector = true;
12369 /* current rounding mode */
12371 case 0x1a: /* FCVTNS */
12373 rmode = FPROUNDING_TIEEVEN;
12375 case 0x1b: /* FCVTMS */
12377 rmode = FPROUNDING_NEGINF;
12379 case 0x1c: /* FCVTAS */
12381 rmode = FPROUNDING_TIEAWAY;
12383 case 0x3a: /* FCVTPS */
12385 rmode = FPROUNDING_POSINF;
12387 case 0x3b: /* FCVTZS */
12389 rmode = FPROUNDING_ZERO;
12391 case 0x5a: /* FCVTNU */
12393 rmode = FPROUNDING_TIEEVEN;
12395 case 0x5b: /* FCVTMU */
12397 rmode = FPROUNDING_NEGINF;
12399 case 0x5c: /* FCVTAU */
12401 rmode = FPROUNDING_TIEAWAY;
12403 case 0x7a: /* FCVTPU */
12405 rmode = FPROUNDING_POSINF;
12407 case 0x7b: /* FCVTZU */
12409 rmode = FPROUNDING_ZERO;
12411 case 0x2f: /* FABS */
12412 case 0x6f: /* FNEG */
12415 case 0x7d: /* FRSQRTE */
12416 case 0x7f: /* FSQRT (vector) */
12419 fprintf(stderr, "%s: insn %#04x fpop %#2x\n", __func__, insn, fpop);
12420 g_assert_not_reached();
12424 /* Check additional constraints for the scalar encoding */
12427 unallocated_encoding(s);
12430 /* FRINTxx is only in the vector form */
12431 if (only_in_vector) {
12432 unallocated_encoding(s);
12437 if (!fp_access_check(s)) {
12441 if (need_rmode || need_fpst) {
12442 tcg_fpstatus = get_fpstatus_ptr(true);
12446 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
12447 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12451 TCGv_i32 tcg_op = read_fp_hreg(s, rn);
12452 TCGv_i32 tcg_res = tcg_temp_new_i32();
12455 case 0x1a: /* FCVTNS */
12456 case 0x1b: /* FCVTMS */
12457 case 0x1c: /* FCVTAS */
12458 case 0x3a: /* FCVTPS */
12459 case 0x3b: /* FCVTZS */
12460 gen_helper_advsimd_f16tosinth(tcg_res, tcg_op, tcg_fpstatus);
12462 case 0x3d: /* FRECPE */
12463 gen_helper_recpe_f16(tcg_res, tcg_op, tcg_fpstatus);
12465 case 0x3f: /* FRECPX */
12466 gen_helper_frecpx_f16(tcg_res, tcg_op, tcg_fpstatus);
12468 case 0x5a: /* FCVTNU */
12469 case 0x5b: /* FCVTMU */
12470 case 0x5c: /* FCVTAU */
12471 case 0x7a: /* FCVTPU */
12472 case 0x7b: /* FCVTZU */
12473 gen_helper_advsimd_f16touinth(tcg_res, tcg_op, tcg_fpstatus);
12475 case 0x6f: /* FNEG */
12476 tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000);
12478 case 0x7d: /* FRSQRTE */
12479 gen_helper_rsqrte_f16(tcg_res, tcg_op, tcg_fpstatus);
12482 g_assert_not_reached();
12485 /* limit any sign extension going on */
12486 tcg_gen_andi_i32(tcg_res, tcg_res, 0xffff);
12487 write_fp_sreg(s, rd, tcg_res);
12489 tcg_temp_free_i32(tcg_res);
12490 tcg_temp_free_i32(tcg_op);
12492 for (pass = 0; pass < (is_q ? 8 : 4); pass++) {
12493 TCGv_i32 tcg_op = tcg_temp_new_i32();
12494 TCGv_i32 tcg_res = tcg_temp_new_i32();
12496 read_vec_element_i32(s, tcg_op, rn, pass, MO_16);
12499 case 0x1a: /* FCVTNS */
12500 case 0x1b: /* FCVTMS */
12501 case 0x1c: /* FCVTAS */
12502 case 0x3a: /* FCVTPS */
12503 case 0x3b: /* FCVTZS */
12504 gen_helper_advsimd_f16tosinth(tcg_res, tcg_op, tcg_fpstatus);
12506 case 0x3d: /* FRECPE */
12507 gen_helper_recpe_f16(tcg_res, tcg_op, tcg_fpstatus);
12509 case 0x5a: /* FCVTNU */
12510 case 0x5b: /* FCVTMU */
12511 case 0x5c: /* FCVTAU */
12512 case 0x7a: /* FCVTPU */
12513 case 0x7b: /* FCVTZU */
12514 gen_helper_advsimd_f16touinth(tcg_res, tcg_op, tcg_fpstatus);
12516 case 0x18: /* FRINTN */
12517 case 0x19: /* FRINTM */
12518 case 0x38: /* FRINTP */
12519 case 0x39: /* FRINTZ */
12520 case 0x58: /* FRINTA */
12521 case 0x79: /* FRINTI */
12522 gen_helper_advsimd_rinth(tcg_res, tcg_op, tcg_fpstatus);
12524 case 0x59: /* FRINTX */
12525 gen_helper_advsimd_rinth_exact(tcg_res, tcg_op, tcg_fpstatus);
12527 case 0x2f: /* FABS */
12528 tcg_gen_andi_i32(tcg_res, tcg_op, 0x7fff);
12530 case 0x6f: /* FNEG */
12531 tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000);
12533 case 0x7d: /* FRSQRTE */
12534 gen_helper_rsqrte_f16(tcg_res, tcg_op, tcg_fpstatus);
12536 case 0x7f: /* FSQRT */
12537 gen_helper_sqrt_f16(tcg_res, tcg_op, tcg_fpstatus);
12540 g_assert_not_reached();
12543 write_vec_element_i32(s, tcg_res, rd, pass, MO_16);
12545 tcg_temp_free_i32(tcg_res);
12546 tcg_temp_free_i32(tcg_op);
12549 clear_vec_high(s, is_q, rd);
12553 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12554 tcg_temp_free_i32(tcg_rmode);
12557 if (tcg_fpstatus) {
12558 tcg_temp_free_ptr(tcg_fpstatus);
12562 /* AdvSIMD scalar x indexed element
12563 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12564 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12565 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12566 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12567 * AdvSIMD vector x indexed element
12568 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12569 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12570 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12571 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12573 static void disas_simd_indexed(DisasContext *s, uint32_t insn)
12575 /* This encoding has two kinds of instruction:
12576 * normal, where we perform elt x idxelt => elt for each
12577 * element in the vector
12578 * long, where we perform elt x idxelt and generate a result of
12579 * double the width of the input element
12580 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
12582 bool is_scalar = extract32(insn, 28, 1);
12583 bool is_q = extract32(insn, 30, 1);
12584 bool u = extract32(insn, 29, 1);
12585 int size = extract32(insn, 22, 2);
12586 int l = extract32(insn, 21, 1);
12587 int m = extract32(insn, 20, 1);
12588 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
12589 int rm = extract32(insn, 16, 4);
12590 int opcode = extract32(insn, 12, 4);
12591 int h = extract32(insn, 11, 1);
12592 int rn = extract32(insn, 5, 5);
12593 int rd = extract32(insn, 0, 5);
12594 bool is_long = false;
12596 bool is_fp16 = false;
12600 switch (16 * u + opcode) {
12601 case 0x08: /* MUL */
12602 case 0x10: /* MLA */
12603 case 0x14: /* MLS */
12605 unallocated_encoding(s);
12609 case 0x02: /* SMLAL, SMLAL2 */
12610 case 0x12: /* UMLAL, UMLAL2 */
12611 case 0x06: /* SMLSL, SMLSL2 */
12612 case 0x16: /* UMLSL, UMLSL2 */
12613 case 0x0a: /* SMULL, SMULL2 */
12614 case 0x1a: /* UMULL, UMULL2 */
12616 unallocated_encoding(s);
12621 case 0x03: /* SQDMLAL, SQDMLAL2 */
12622 case 0x07: /* SQDMLSL, SQDMLSL2 */
12623 case 0x0b: /* SQDMULL, SQDMULL2 */
12626 case 0x0c: /* SQDMULH */
12627 case 0x0d: /* SQRDMULH */
12629 case 0x01: /* FMLA */
12630 case 0x05: /* FMLS */
12631 case 0x09: /* FMUL */
12632 case 0x19: /* FMULX */
12635 case 0x1d: /* SQRDMLAH */
12636 case 0x1f: /* SQRDMLSH */
12637 if (!dc_isar_feature(aa64_rdm, s)) {
12638 unallocated_encoding(s);
12642 case 0x0e: /* SDOT */
12643 case 0x1e: /* UDOT */
12644 if (is_scalar || size != MO_32 || !dc_isar_feature(aa64_dp, s)) {
12645 unallocated_encoding(s);
12649 case 0x11: /* FCMLA #0 */
12650 case 0x13: /* FCMLA #90 */
12651 case 0x15: /* FCMLA #180 */
12652 case 0x17: /* FCMLA #270 */
12653 if (is_scalar || !dc_isar_feature(aa64_fcma, s)) {
12654 unallocated_encoding(s);
12660 unallocated_encoding(s);
12665 case 1: /* normal fp */
12666 /* convert insn encoded size to TCGMemOp size */
12668 case 0: /* half-precision */
12672 case MO_32: /* single precision */
12673 case MO_64: /* double precision */
12676 unallocated_encoding(s);
12681 case 2: /* complex fp */
12682 /* Each indexable element is a complex pair. */
12687 unallocated_encoding(s);
12695 unallocated_encoding(s);
12700 default: /* integer */
12704 unallocated_encoding(s);
12709 if (is_fp16 && !dc_isar_feature(aa64_fp16, s)) {
12710 unallocated_encoding(s);
12714 /* Given TCGMemOp size, adjust register and indexing. */
12717 index = h << 2 | l << 1 | m;
12720 index = h << 1 | l;
12725 unallocated_encoding(s);
12732 g_assert_not_reached();
12735 if (!fp_access_check(s)) {
12740 fpst = get_fpstatus_ptr(is_fp16);
12745 switch (16 * u + opcode) {
12746 case 0x0e: /* SDOT */
12747 case 0x1e: /* UDOT */
12748 gen_gvec_op3_ool(s, is_q, rd, rn, rm, index,
12749 u ? gen_helper_gvec_udot_idx_b
12750 : gen_helper_gvec_sdot_idx_b);
12752 case 0x11: /* FCMLA #0 */
12753 case 0x13: /* FCMLA #90 */
12754 case 0x15: /* FCMLA #180 */
12755 case 0x17: /* FCMLA #270 */
12757 int rot = extract32(insn, 13, 2);
12758 int data = (index << 2) | rot;
12759 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
12760 vec_full_reg_offset(s, rn),
12761 vec_full_reg_offset(s, rm), fpst,
12762 is_q ? 16 : 8, vec_full_reg_size(s), data,
12764 ? gen_helper_gvec_fcmlas_idx
12765 : gen_helper_gvec_fcmlah_idx);
12766 tcg_temp_free_ptr(fpst);
12772 TCGv_i64 tcg_idx = tcg_temp_new_i64();
12775 assert(is_fp && is_q && !is_long);
12777 read_vec_element(s, tcg_idx, rm, index, MO_64);
12779 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
12780 TCGv_i64 tcg_op = tcg_temp_new_i64();
12781 TCGv_i64 tcg_res = tcg_temp_new_i64();
12783 read_vec_element(s, tcg_op, rn, pass, MO_64);
12785 switch (16 * u + opcode) {
12786 case 0x05: /* FMLS */
12787 /* As usual for ARM, separate negation for fused multiply-add */
12788 gen_helper_vfp_negd(tcg_op, tcg_op);
12790 case 0x01: /* FMLA */
12791 read_vec_element(s, tcg_res, rd, pass, MO_64);
12792 gen_helper_vfp_muladdd(tcg_res, tcg_op, tcg_idx, tcg_res, fpst);
12794 case 0x09: /* FMUL */
12795 gen_helper_vfp_muld(tcg_res, tcg_op, tcg_idx, fpst);
12797 case 0x19: /* FMULX */
12798 gen_helper_vfp_mulxd(tcg_res, tcg_op, tcg_idx, fpst);
12801 g_assert_not_reached();
12804 write_vec_element(s, tcg_res, rd, pass, MO_64);
12805 tcg_temp_free_i64(tcg_op);
12806 tcg_temp_free_i64(tcg_res);
12809 tcg_temp_free_i64(tcg_idx);
12810 clear_vec_high(s, !is_scalar, rd);
12811 } else if (!is_long) {
12812 /* 32 bit floating point, or 16 or 32 bit integer.
12813 * For the 16 bit scalar case we use the usual Neon helpers and
12814 * rely on the fact that 0 op 0 == 0 with no side effects.
12816 TCGv_i32 tcg_idx = tcg_temp_new_i32();
12817 int pass, maxpasses;
12822 maxpasses = is_q ? 4 : 2;
12825 read_vec_element_i32(s, tcg_idx, rm, index, size);
12827 if (size == 1 && !is_scalar) {
12828 /* The simplest way to handle the 16x16 indexed ops is to duplicate
12829 * the index into both halves of the 32 bit tcg_idx and then use
12830 * the usual Neon helpers.
12832 tcg_gen_deposit_i32(tcg_idx, tcg_idx, tcg_idx, 16, 16);
12835 for (pass = 0; pass < maxpasses; pass++) {
12836 TCGv_i32 tcg_op = tcg_temp_new_i32();
12837 TCGv_i32 tcg_res = tcg_temp_new_i32();
12839 read_vec_element_i32(s, tcg_op, rn, pass, is_scalar ? size : MO_32);
12841 switch (16 * u + opcode) {
12842 case 0x08: /* MUL */
12843 case 0x10: /* MLA */
12844 case 0x14: /* MLS */
12846 static NeonGenTwoOpFn * const fns[2][2] = {
12847 { gen_helper_neon_add_u16, gen_helper_neon_sub_u16 },
12848 { tcg_gen_add_i32, tcg_gen_sub_i32 },
12850 NeonGenTwoOpFn *genfn;
12851 bool is_sub = opcode == 0x4;
12854 gen_helper_neon_mul_u16(tcg_res, tcg_op, tcg_idx);
12856 tcg_gen_mul_i32(tcg_res, tcg_op, tcg_idx);
12858 if (opcode == 0x8) {
12861 read_vec_element_i32(s, tcg_op, rd, pass, MO_32);
12862 genfn = fns[size - 1][is_sub];
12863 genfn(tcg_res, tcg_op, tcg_res);
12866 case 0x05: /* FMLS */
12867 case 0x01: /* FMLA */
12868 read_vec_element_i32(s, tcg_res, rd, pass,
12869 is_scalar ? size : MO_32);
12872 if (opcode == 0x5) {
12873 /* As usual for ARM, separate negation for fused
12875 tcg_gen_xori_i32(tcg_op, tcg_op, 0x80008000);
12878 gen_helper_advsimd_muladdh(tcg_res, tcg_op, tcg_idx,
12881 gen_helper_advsimd_muladd2h(tcg_res, tcg_op, tcg_idx,
12886 if (opcode == 0x5) {
12887 /* As usual for ARM, separate negation for
12888 * fused multiply-add */
12889 tcg_gen_xori_i32(tcg_op, tcg_op, 0x80000000);
12891 gen_helper_vfp_muladds(tcg_res, tcg_op, tcg_idx,
12895 g_assert_not_reached();
12898 case 0x09: /* FMUL */
12902 gen_helper_advsimd_mulh(tcg_res, tcg_op,
12905 gen_helper_advsimd_mul2h(tcg_res, tcg_op,
12910 gen_helper_vfp_muls(tcg_res, tcg_op, tcg_idx, fpst);
12913 g_assert_not_reached();
12916 case 0x19: /* FMULX */
12920 gen_helper_advsimd_mulxh(tcg_res, tcg_op,
12923 gen_helper_advsimd_mulx2h(tcg_res, tcg_op,
12928 gen_helper_vfp_mulxs(tcg_res, tcg_op, tcg_idx, fpst);
12931 g_assert_not_reached();
12934 case 0x0c: /* SQDMULH */
12936 gen_helper_neon_qdmulh_s16(tcg_res, cpu_env,
12939 gen_helper_neon_qdmulh_s32(tcg_res, cpu_env,
12943 case 0x0d: /* SQRDMULH */
12945 gen_helper_neon_qrdmulh_s16(tcg_res, cpu_env,
12948 gen_helper_neon_qrdmulh_s32(tcg_res, cpu_env,
12952 case 0x1d: /* SQRDMLAH */
12953 read_vec_element_i32(s, tcg_res, rd, pass,
12954 is_scalar ? size : MO_32);
12956 gen_helper_neon_qrdmlah_s16(tcg_res, cpu_env,
12957 tcg_op, tcg_idx, tcg_res);
12959 gen_helper_neon_qrdmlah_s32(tcg_res, cpu_env,
12960 tcg_op, tcg_idx, tcg_res);
12963 case 0x1f: /* SQRDMLSH */
12964 read_vec_element_i32(s, tcg_res, rd, pass,
12965 is_scalar ? size : MO_32);
12967 gen_helper_neon_qrdmlsh_s16(tcg_res, cpu_env,
12968 tcg_op, tcg_idx, tcg_res);
12970 gen_helper_neon_qrdmlsh_s32(tcg_res, cpu_env,
12971 tcg_op, tcg_idx, tcg_res);
12975 g_assert_not_reached();
12979 write_fp_sreg(s, rd, tcg_res);
12981 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
12984 tcg_temp_free_i32(tcg_op);
12985 tcg_temp_free_i32(tcg_res);
12988 tcg_temp_free_i32(tcg_idx);
12989 clear_vec_high(s, is_q, rd);
12991 /* long ops: 16x16->32 or 32x32->64 */
12992 TCGv_i64 tcg_res[2];
12994 bool satop = extract32(opcode, 0, 1);
12995 TCGMemOp memop = MO_32;
13002 TCGv_i64 tcg_idx = tcg_temp_new_i64();
13004 read_vec_element(s, tcg_idx, rm, index, memop);
13006 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
13007 TCGv_i64 tcg_op = tcg_temp_new_i64();
13008 TCGv_i64 tcg_passres;
13014 passelt = pass + (is_q * 2);
13017 read_vec_element(s, tcg_op, rn, passelt, memop);
13019 tcg_res[pass] = tcg_temp_new_i64();
13021 if (opcode == 0xa || opcode == 0xb) {
13022 /* Non-accumulating ops */
13023 tcg_passres = tcg_res[pass];
13025 tcg_passres = tcg_temp_new_i64();
13028 tcg_gen_mul_i64(tcg_passres, tcg_op, tcg_idx);
13029 tcg_temp_free_i64(tcg_op);
13032 /* saturating, doubling */
13033 gen_helper_neon_addl_saturate_s64(tcg_passres, cpu_env,
13034 tcg_passres, tcg_passres);
13037 if (opcode == 0xa || opcode == 0xb) {
13041 /* Accumulating op: handle accumulate step */
13042 read_vec_element(s, tcg_res[pass], rd, pass, MO_64);
13045 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13046 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
13048 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13049 tcg_gen_sub_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
13051 case 0x7: /* SQDMLSL, SQDMLSL2 */
13052 tcg_gen_neg_i64(tcg_passres, tcg_passres);
13054 case 0x3: /* SQDMLAL, SQDMLAL2 */
13055 gen_helper_neon_addl_saturate_s64(tcg_res[pass], cpu_env,
13060 g_assert_not_reached();
13062 tcg_temp_free_i64(tcg_passres);
13064 tcg_temp_free_i64(tcg_idx);
13066 clear_vec_high(s, !is_scalar, rd);
13068 TCGv_i32 tcg_idx = tcg_temp_new_i32();
13071 read_vec_element_i32(s, tcg_idx, rm, index, size);
13074 /* The simplest way to handle the 16x16 indexed ops is to
13075 * duplicate the index into both halves of the 32 bit tcg_idx
13076 * and then use the usual Neon helpers.
13078 tcg_gen_deposit_i32(tcg_idx, tcg_idx, tcg_idx, 16, 16);
13081 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
13082 TCGv_i32 tcg_op = tcg_temp_new_i32();
13083 TCGv_i64 tcg_passres;
13086 read_vec_element_i32(s, tcg_op, rn, pass, size);
13088 read_vec_element_i32(s, tcg_op, rn,
13089 pass + (is_q * 2), MO_32);
13092 tcg_res[pass] = tcg_temp_new_i64();
13094 if (opcode == 0xa || opcode == 0xb) {
13095 /* Non-accumulating ops */
13096 tcg_passres = tcg_res[pass];
13098 tcg_passres = tcg_temp_new_i64();
13101 if (memop & MO_SIGN) {
13102 gen_helper_neon_mull_s16(tcg_passres, tcg_op, tcg_idx);
13104 gen_helper_neon_mull_u16(tcg_passres, tcg_op, tcg_idx);
13107 gen_helper_neon_addl_saturate_s32(tcg_passres, cpu_env,
13108 tcg_passres, tcg_passres);
13110 tcg_temp_free_i32(tcg_op);
13112 if (opcode == 0xa || opcode == 0xb) {
13116 /* Accumulating op: handle accumulate step */
13117 read_vec_element(s, tcg_res[pass], rd, pass, MO_64);
13120 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13121 gen_helper_neon_addl_u32(tcg_res[pass], tcg_res[pass],
13124 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13125 gen_helper_neon_subl_u32(tcg_res[pass], tcg_res[pass],
13128 case 0x7: /* SQDMLSL, SQDMLSL2 */
13129 gen_helper_neon_negl_u32(tcg_passres, tcg_passres);
13131 case 0x3: /* SQDMLAL, SQDMLAL2 */
13132 gen_helper_neon_addl_saturate_s32(tcg_res[pass], cpu_env,
13137 g_assert_not_reached();
13139 tcg_temp_free_i64(tcg_passres);
13141 tcg_temp_free_i32(tcg_idx);
13144 tcg_gen_ext32u_i64(tcg_res[0], tcg_res[0]);
13149 tcg_res[1] = tcg_const_i64(0);
13152 for (pass = 0; pass < 2; pass++) {
13153 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
13154 tcg_temp_free_i64(tcg_res[pass]);
13159 tcg_temp_free_ptr(fpst);
13164 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13165 * +-----------------+------+-----------+--------+-----+------+------+
13166 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13167 * +-----------------+------+-----------+--------+-----+------+------+
13169 static void disas_crypto_aes(DisasContext *s, uint32_t insn)
13171 int size = extract32(insn, 22, 2);
13172 int opcode = extract32(insn, 12, 5);
13173 int rn = extract32(insn, 5, 5);
13174 int rd = extract32(insn, 0, 5);
13176 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
13177 TCGv_i32 tcg_decrypt;
13178 CryptoThreeOpIntFn *genfn;
13180 if (!dc_isar_feature(aa64_aes, s) || size != 0) {
13181 unallocated_encoding(s);
13186 case 0x4: /* AESE */
13188 genfn = gen_helper_crypto_aese;
13190 case 0x6: /* AESMC */
13192 genfn = gen_helper_crypto_aesmc;
13194 case 0x5: /* AESD */
13196 genfn = gen_helper_crypto_aese;
13198 case 0x7: /* AESIMC */
13200 genfn = gen_helper_crypto_aesmc;
13203 unallocated_encoding(s);
13207 if (!fp_access_check(s)) {
13211 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13212 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13213 tcg_decrypt = tcg_const_i32(decrypt);
13215 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_decrypt);
13217 tcg_temp_free_ptr(tcg_rd_ptr);
13218 tcg_temp_free_ptr(tcg_rn_ptr);
13219 tcg_temp_free_i32(tcg_decrypt);
13222 /* Crypto three-reg SHA
13223 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
13224 * +-----------------+------+---+------+---+--------+-----+------+------+
13225 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
13226 * +-----------------+------+---+------+---+--------+-----+------+------+
13228 static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn)
13230 int size = extract32(insn, 22, 2);
13231 int opcode = extract32(insn, 12, 3);
13232 int rm = extract32(insn, 16, 5);
13233 int rn = extract32(insn, 5, 5);
13234 int rd = extract32(insn, 0, 5);
13235 CryptoThreeOpFn *genfn;
13236 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13240 unallocated_encoding(s);
13245 case 0: /* SHA1C */
13246 case 1: /* SHA1P */
13247 case 2: /* SHA1M */
13248 case 3: /* SHA1SU0 */
13250 feature = dc_isar_feature(aa64_sha1, s);
13252 case 4: /* SHA256H */
13253 genfn = gen_helper_crypto_sha256h;
13254 feature = dc_isar_feature(aa64_sha256, s);
13256 case 5: /* SHA256H2 */
13257 genfn = gen_helper_crypto_sha256h2;
13258 feature = dc_isar_feature(aa64_sha256, s);
13260 case 6: /* SHA256SU1 */
13261 genfn = gen_helper_crypto_sha256su1;
13262 feature = dc_isar_feature(aa64_sha256, s);
13265 unallocated_encoding(s);
13270 unallocated_encoding(s);
13274 if (!fp_access_check(s)) {
13278 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13279 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13280 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13283 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr);
13285 TCGv_i32 tcg_opcode = tcg_const_i32(opcode);
13287 gen_helper_crypto_sha1_3reg(tcg_rd_ptr, tcg_rn_ptr,
13288 tcg_rm_ptr, tcg_opcode);
13289 tcg_temp_free_i32(tcg_opcode);
13292 tcg_temp_free_ptr(tcg_rd_ptr);
13293 tcg_temp_free_ptr(tcg_rn_ptr);
13294 tcg_temp_free_ptr(tcg_rm_ptr);
13297 /* Crypto two-reg SHA
13298 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13299 * +-----------------+------+-----------+--------+-----+------+------+
13300 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13301 * +-----------------+------+-----------+--------+-----+------+------+
13303 static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn)
13305 int size = extract32(insn, 22, 2);
13306 int opcode = extract32(insn, 12, 5);
13307 int rn = extract32(insn, 5, 5);
13308 int rd = extract32(insn, 0, 5);
13309 CryptoTwoOpFn *genfn;
13311 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
13314 unallocated_encoding(s);
13319 case 0: /* SHA1H */
13320 feature = dc_isar_feature(aa64_sha1, s);
13321 genfn = gen_helper_crypto_sha1h;
13323 case 1: /* SHA1SU1 */
13324 feature = dc_isar_feature(aa64_sha1, s);
13325 genfn = gen_helper_crypto_sha1su1;
13327 case 2: /* SHA256SU0 */
13328 feature = dc_isar_feature(aa64_sha256, s);
13329 genfn = gen_helper_crypto_sha256su0;
13332 unallocated_encoding(s);
13337 unallocated_encoding(s);
13341 if (!fp_access_check(s)) {
13345 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13346 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13348 genfn(tcg_rd_ptr, tcg_rn_ptr);
13350 tcg_temp_free_ptr(tcg_rd_ptr);
13351 tcg_temp_free_ptr(tcg_rn_ptr);
13354 /* Crypto three-reg SHA512
13355 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13356 * +-----------------------+------+---+---+-----+--------+------+------+
13357 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
13358 * +-----------------------+------+---+---+-----+--------+------+------+
13360 static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn)
13362 int opcode = extract32(insn, 10, 2);
13363 int o = extract32(insn, 14, 1);
13364 int rm = extract32(insn, 16, 5);
13365 int rn = extract32(insn, 5, 5);
13366 int rd = extract32(insn, 0, 5);
13368 CryptoThreeOpFn *genfn;
13372 case 0: /* SHA512H */
13373 feature = dc_isar_feature(aa64_sha512, s);
13374 genfn = gen_helper_crypto_sha512h;
13376 case 1: /* SHA512H2 */
13377 feature = dc_isar_feature(aa64_sha512, s);
13378 genfn = gen_helper_crypto_sha512h2;
13380 case 2: /* SHA512SU1 */
13381 feature = dc_isar_feature(aa64_sha512, s);
13382 genfn = gen_helper_crypto_sha512su1;
13385 feature = dc_isar_feature(aa64_sha3, s);
13391 case 0: /* SM3PARTW1 */
13392 feature = dc_isar_feature(aa64_sm3, s);
13393 genfn = gen_helper_crypto_sm3partw1;
13395 case 1: /* SM3PARTW2 */
13396 feature = dc_isar_feature(aa64_sm3, s);
13397 genfn = gen_helper_crypto_sm3partw2;
13399 case 2: /* SM4EKEY */
13400 feature = dc_isar_feature(aa64_sm4, s);
13401 genfn = gen_helper_crypto_sm4ekey;
13404 unallocated_encoding(s);
13410 unallocated_encoding(s);
13414 if (!fp_access_check(s)) {
13419 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13421 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13422 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13423 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13425 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr);
13427 tcg_temp_free_ptr(tcg_rd_ptr);
13428 tcg_temp_free_ptr(tcg_rn_ptr);
13429 tcg_temp_free_ptr(tcg_rm_ptr);
13431 TCGv_i64 tcg_op1, tcg_op2, tcg_res[2];
13434 tcg_op1 = tcg_temp_new_i64();
13435 tcg_op2 = tcg_temp_new_i64();
13436 tcg_res[0] = tcg_temp_new_i64();
13437 tcg_res[1] = tcg_temp_new_i64();
13439 for (pass = 0; pass < 2; pass++) {
13440 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13441 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13443 tcg_gen_rotli_i64(tcg_res[pass], tcg_op2, 1);
13444 tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
13446 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13447 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13449 tcg_temp_free_i64(tcg_op1);
13450 tcg_temp_free_i64(tcg_op2);
13451 tcg_temp_free_i64(tcg_res[0]);
13452 tcg_temp_free_i64(tcg_res[1]);
13456 /* Crypto two-reg SHA512
13457 * 31 12 11 10 9 5 4 0
13458 * +-----------------------------------------+--------+------+------+
13459 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
13460 * +-----------------------------------------+--------+------+------+
13462 static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn)
13464 int opcode = extract32(insn, 10, 2);
13465 int rn = extract32(insn, 5, 5);
13466 int rd = extract32(insn, 0, 5);
13467 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
13469 CryptoTwoOpFn *genfn;
13472 case 0: /* SHA512SU0 */
13473 feature = dc_isar_feature(aa64_sha512, s);
13474 genfn = gen_helper_crypto_sha512su0;
13477 feature = dc_isar_feature(aa64_sm4, s);
13478 genfn = gen_helper_crypto_sm4e;
13481 unallocated_encoding(s);
13486 unallocated_encoding(s);
13490 if (!fp_access_check(s)) {
13494 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13495 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13497 genfn(tcg_rd_ptr, tcg_rn_ptr);
13499 tcg_temp_free_ptr(tcg_rd_ptr);
13500 tcg_temp_free_ptr(tcg_rn_ptr);
13503 /* Crypto four-register
13504 * 31 23 22 21 20 16 15 14 10 9 5 4 0
13505 * +-------------------+-----+------+---+------+------+------+
13506 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
13507 * +-------------------+-----+------+---+------+------+------+
13509 static void disas_crypto_four_reg(DisasContext *s, uint32_t insn)
13511 int op0 = extract32(insn, 21, 2);
13512 int rm = extract32(insn, 16, 5);
13513 int ra = extract32(insn, 10, 5);
13514 int rn = extract32(insn, 5, 5);
13515 int rd = extract32(insn, 0, 5);
13521 feature = dc_isar_feature(aa64_sha3, s);
13523 case 2: /* SM3SS1 */
13524 feature = dc_isar_feature(aa64_sm3, s);
13527 unallocated_encoding(s);
13532 unallocated_encoding(s);
13536 if (!fp_access_check(s)) {
13541 TCGv_i64 tcg_op1, tcg_op2, tcg_op3, tcg_res[2];
13544 tcg_op1 = tcg_temp_new_i64();
13545 tcg_op2 = tcg_temp_new_i64();
13546 tcg_op3 = tcg_temp_new_i64();
13547 tcg_res[0] = tcg_temp_new_i64();
13548 tcg_res[1] = tcg_temp_new_i64();
13550 for (pass = 0; pass < 2; pass++) {
13551 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13552 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13553 read_vec_element(s, tcg_op3, ra, pass, MO_64);
13557 tcg_gen_xor_i64(tcg_res[pass], tcg_op2, tcg_op3);
13560 tcg_gen_andc_i64(tcg_res[pass], tcg_op2, tcg_op3);
13562 tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
13564 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13565 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13567 tcg_temp_free_i64(tcg_op1);
13568 tcg_temp_free_i64(tcg_op2);
13569 tcg_temp_free_i64(tcg_op3);
13570 tcg_temp_free_i64(tcg_res[0]);
13571 tcg_temp_free_i64(tcg_res[1]);
13573 TCGv_i32 tcg_op1, tcg_op2, tcg_op3, tcg_res, tcg_zero;
13575 tcg_op1 = tcg_temp_new_i32();
13576 tcg_op2 = tcg_temp_new_i32();
13577 tcg_op3 = tcg_temp_new_i32();
13578 tcg_res = tcg_temp_new_i32();
13579 tcg_zero = tcg_const_i32(0);
13581 read_vec_element_i32(s, tcg_op1, rn, 3, MO_32);
13582 read_vec_element_i32(s, tcg_op2, rm, 3, MO_32);
13583 read_vec_element_i32(s, tcg_op3, ra, 3, MO_32);
13585 tcg_gen_rotri_i32(tcg_res, tcg_op1, 20);
13586 tcg_gen_add_i32(tcg_res, tcg_res, tcg_op2);
13587 tcg_gen_add_i32(tcg_res, tcg_res, tcg_op3);
13588 tcg_gen_rotri_i32(tcg_res, tcg_res, 25);
13590 write_vec_element_i32(s, tcg_zero, rd, 0, MO_32);
13591 write_vec_element_i32(s, tcg_zero, rd, 1, MO_32);
13592 write_vec_element_i32(s, tcg_zero, rd, 2, MO_32);
13593 write_vec_element_i32(s, tcg_res, rd, 3, MO_32);
13595 tcg_temp_free_i32(tcg_op1);
13596 tcg_temp_free_i32(tcg_op2);
13597 tcg_temp_free_i32(tcg_op3);
13598 tcg_temp_free_i32(tcg_res);
13599 tcg_temp_free_i32(tcg_zero);
13604 * 31 21 20 16 15 10 9 5 4 0
13605 * +-----------------------+------+--------+------+------+
13606 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
13607 * +-----------------------+------+--------+------+------+
13609 static void disas_crypto_xar(DisasContext *s, uint32_t insn)
13611 int rm = extract32(insn, 16, 5);
13612 int imm6 = extract32(insn, 10, 6);
13613 int rn = extract32(insn, 5, 5);
13614 int rd = extract32(insn, 0, 5);
13615 TCGv_i64 tcg_op1, tcg_op2, tcg_res[2];
13618 if (!dc_isar_feature(aa64_sha3, s)) {
13619 unallocated_encoding(s);
13623 if (!fp_access_check(s)) {
13627 tcg_op1 = tcg_temp_new_i64();
13628 tcg_op2 = tcg_temp_new_i64();
13629 tcg_res[0] = tcg_temp_new_i64();
13630 tcg_res[1] = tcg_temp_new_i64();
13632 for (pass = 0; pass < 2; pass++) {
13633 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13634 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13636 tcg_gen_xor_i64(tcg_res[pass], tcg_op1, tcg_op2);
13637 tcg_gen_rotri_i64(tcg_res[pass], tcg_res[pass], imm6);
13639 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13640 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13642 tcg_temp_free_i64(tcg_op1);
13643 tcg_temp_free_i64(tcg_op2);
13644 tcg_temp_free_i64(tcg_res[0]);
13645 tcg_temp_free_i64(tcg_res[1]);
13648 /* Crypto three-reg imm2
13649 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13650 * +-----------------------+------+-----+------+--------+------+------+
13651 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
13652 * +-----------------------+------+-----+------+--------+------+------+
13654 static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn)
13656 int opcode = extract32(insn, 10, 2);
13657 int imm2 = extract32(insn, 12, 2);
13658 int rm = extract32(insn, 16, 5);
13659 int rn = extract32(insn, 5, 5);
13660 int rd = extract32(insn, 0, 5);
13661 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13662 TCGv_i32 tcg_imm2, tcg_opcode;
13664 if (!dc_isar_feature(aa64_sm3, s)) {
13665 unallocated_encoding(s);
13669 if (!fp_access_check(s)) {
13673 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13674 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13675 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13676 tcg_imm2 = tcg_const_i32(imm2);
13677 tcg_opcode = tcg_const_i32(opcode);
13679 gen_helper_crypto_sm3tt(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr, tcg_imm2,
13682 tcg_temp_free_ptr(tcg_rd_ptr);
13683 tcg_temp_free_ptr(tcg_rn_ptr);
13684 tcg_temp_free_ptr(tcg_rm_ptr);
13685 tcg_temp_free_i32(tcg_imm2);
13686 tcg_temp_free_i32(tcg_opcode);
13689 /* C3.6 Data processing - SIMD, inc Crypto
13691 * As the decode gets a little complex we are using a table based
13692 * approach for this part of the decode.
13694 static const AArch64DecodeTable data_proc_simd[] = {
13695 /* pattern , mask , fn */
13696 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same },
13697 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra },
13698 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff },
13699 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc },
13700 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes },
13701 { 0x0e000400, 0x9fe08400, disas_simd_copy },
13702 { 0x0f000000, 0x9f000400, disas_simd_indexed }, /* vector indexed */
13703 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
13704 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm },
13705 { 0x0f000400, 0x9f800400, disas_simd_shift_imm },
13706 { 0x0e000000, 0xbf208c00, disas_simd_tb },
13707 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn },
13708 { 0x2e000000, 0xbf208400, disas_simd_ext },
13709 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same },
13710 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra },
13711 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff },
13712 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc },
13713 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise },
13714 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy },
13715 { 0x5f000000, 0xdf000400, disas_simd_indexed }, /* scalar indexed */
13716 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm },
13717 { 0x4e280800, 0xff3e0c00, disas_crypto_aes },
13718 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha },
13719 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha },
13720 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 },
13721 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 },
13722 { 0xce000000, 0xff808000, disas_crypto_four_reg },
13723 { 0xce800000, 0xffe00000, disas_crypto_xar },
13724 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2 },
13725 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16 },
13726 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16 },
13727 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16 },
13728 { 0x00000000, 0x00000000, NULL }
13731 static void disas_data_proc_simd(DisasContext *s, uint32_t insn)
13733 /* Note that this is called with all non-FP cases from
13734 * table C3-6 so it must UNDEF for entries not specifically
13735 * allocated to instructions in that table.
13737 AArch64DecodeFn *fn = lookup_disas_fn(&data_proc_simd[0], insn);
13741 unallocated_encoding(s);
13745 /* C3.6 Data processing - SIMD and floating point */
13746 static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn)
13748 if (extract32(insn, 28, 1) == 1 && extract32(insn, 30, 1) == 0) {
13749 disas_data_proc_fp(s, insn);
13751 /* SIMD, including crypto */
13752 disas_data_proc_simd(s, insn);
13756 /* C3.1 A64 instruction index by encoding */
13757 static void disas_a64_insn(CPUARMState *env, DisasContext *s)
13761 insn = arm_ldl_code(env, s->pc, s->sctlr_b);
13765 s->fp_access_checked = false;
13767 switch (extract32(insn, 25, 4)) {
13768 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
13769 unallocated_encoding(s);
13772 if (!dc_isar_feature(aa64_sve, s) || !disas_sve(s, insn)) {
13773 unallocated_encoding(s);
13776 case 0x8: case 0x9: /* Data processing - immediate */
13777 disas_data_proc_imm(s, insn);
13779 case 0xa: case 0xb: /* Branch, exception generation and system insns */
13780 disas_b_exc_sys(s, insn);
13785 case 0xe: /* Loads and stores */
13786 disas_ldst(s, insn);
13789 case 0xd: /* Data processing - register */
13790 disas_data_proc_reg(s, insn);
13793 case 0xf: /* Data processing - SIMD and floating point */
13794 disas_data_proc_simd_fp(s, insn);
13797 assert(FALSE); /* all 15 cases should be handled above */
13801 /* if we allocated any temporaries, free them here */
13805 static void aarch64_tr_init_disas_context(DisasContextBase *dcbase,
13808 DisasContext *dc = container_of(dcbase, DisasContext, base);
13809 CPUARMState *env = cpu->env_ptr;
13810 ARMCPU *arm_cpu = arm_env_get_cpu(env);
13811 uint32_t tb_flags = dc->base.tb->flags;
13812 int bound, core_mmu_idx;
13814 dc->isar = &arm_cpu->isar;
13815 dc->pc = dc->base.pc_first;
13819 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
13820 * there is no secure EL1, so we route exceptions to EL3.
13822 dc->secure_routed_to_el3 = arm_feature(env, ARM_FEATURE_EL3) &&
13823 !arm_el_is_aa64(env, 3);
13826 dc->be_data = FIELD_EX32(tb_flags, TBFLAG_ANY, BE_DATA) ? MO_BE : MO_LE;
13827 dc->condexec_mask = 0;
13828 dc->condexec_cond = 0;
13829 core_mmu_idx = FIELD_EX32(tb_flags, TBFLAG_ANY, MMUIDX);
13830 dc->mmu_idx = core_to_arm_mmu_idx(env, core_mmu_idx);
13831 dc->tbii = FIELD_EX32(tb_flags, TBFLAG_A64, TBII);
13832 dc->current_el = arm_mmu_idx_to_el(dc->mmu_idx);
13833 #if !defined(CONFIG_USER_ONLY)
13834 dc->user = (dc->current_el == 0);
13836 dc->fp_excp_el = FIELD_EX32(tb_flags, TBFLAG_ANY, FPEXC_EL);
13837 dc->sve_excp_el = FIELD_EX32(tb_flags, TBFLAG_A64, SVEEXC_EL);
13838 dc->sve_len = (FIELD_EX32(tb_flags, TBFLAG_A64, ZCR_LEN) + 1) * 16;
13839 dc->pauth_active = FIELD_EX32(tb_flags, TBFLAG_A64, PAUTH_ACTIVE);
13841 dc->vec_stride = 0;
13842 dc->cp_regs = arm_cpu->cp_regs;
13843 dc->features = env->features;
13845 /* Single step state. The code-generation logic here is:
13847 * generate code with no special handling for single-stepping (except
13848 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
13849 * this happens anyway because those changes are all system register or
13851 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
13852 * emit code for one insn
13853 * emit code to clear PSTATE.SS
13854 * emit code to generate software step exception for completed step
13855 * end TB (as usual for having generated an exception)
13856 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
13857 * emit code to generate a software step exception
13860 dc->ss_active = FIELD_EX32(tb_flags, TBFLAG_ANY, SS_ACTIVE);
13861 dc->pstate_ss = FIELD_EX32(tb_flags, TBFLAG_ANY, PSTATE_SS);
13862 dc->is_ldex = false;
13863 dc->ss_same_el = (arm_debug_target_el(env) == dc->current_el);
13865 /* Bound the number of insns to execute to those left on the page. */
13866 bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
13868 /* If architectural single step active, limit to 1. */
13869 if (dc->ss_active) {
13872 dc->base.max_insns = MIN(dc->base.max_insns, bound);
13874 init_tmp_a64_array(dc);
13877 static void aarch64_tr_tb_start(DisasContextBase *db, CPUState *cpu)
13881 static void aarch64_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
13883 DisasContext *dc = container_of(dcbase, DisasContext, base);
13885 tcg_gen_insn_start(dc->pc, 0, 0);
13886 dc->insn_start = tcg_last_op();
13889 static bool aarch64_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu,
13890 const CPUBreakpoint *bp)
13892 DisasContext *dc = container_of(dcbase, DisasContext, base);
13894 if (bp->flags & BP_CPU) {
13895 gen_a64_set_pc_im(dc->pc);
13896 gen_helper_check_breakpoints(cpu_env);
13897 /* End the TB early; it likely won't be executed */
13898 dc->base.is_jmp = DISAS_TOO_MANY;
13900 gen_exception_internal_insn(dc, 0, EXCP_DEBUG);
13901 /* The address covered by the breakpoint must be
13902 included in [tb->pc, tb->pc + tb->size) in order
13903 to for it to be properly cleared -- thus we
13904 increment the PC here so that the logic setting
13905 tb->size below does the right thing. */
13907 dc->base.is_jmp = DISAS_NORETURN;
13913 static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
13915 DisasContext *dc = container_of(dcbase, DisasContext, base);
13916 CPUARMState *env = cpu->env_ptr;
13918 if (dc->ss_active && !dc->pstate_ss) {
13919 /* Singlestep state is Active-pending.
13920 * If we're in this state at the start of a TB then either
13921 * a) we just took an exception to an EL which is being debugged
13922 * and this is the first insn in the exception handler
13923 * b) debug exceptions were masked and we just unmasked them
13924 * without changing EL (eg by clearing PSTATE.D)
13925 * In either case we're going to take a swstep exception in the
13926 * "did not step an insn" case, and so the syndrome ISV and EX
13927 * bits should be zero.
13929 assert(dc->base.num_insns == 1);
13930 gen_exception(EXCP_UDEF, syn_swstep(dc->ss_same_el, 0, 0),
13931 default_exception_el(dc));
13932 dc->base.is_jmp = DISAS_NORETURN;
13934 disas_a64_insn(env, dc);
13937 dc->base.pc_next = dc->pc;
13938 translator_loop_temp_check(&dc->base);
13941 static void aarch64_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
13943 DisasContext *dc = container_of(dcbase, DisasContext, base);
13945 if (unlikely(dc->base.singlestep_enabled || dc->ss_active)) {
13946 /* Note that this means single stepping WFI doesn't halt the CPU.
13947 * For conditional branch insns this is harmless unreachable code as
13948 * gen_goto_tb() has already handled emitting the debug exception
13949 * (and thus a tb-jump is not possible when singlestepping).
13951 switch (dc->base.is_jmp) {
13953 gen_a64_set_pc_im(dc->pc);
13957 if (dc->base.singlestep_enabled) {
13958 gen_exception_internal(EXCP_DEBUG);
13960 gen_step_complete_exception(dc);
13963 case DISAS_NORETURN:
13967 switch (dc->base.is_jmp) {
13969 case DISAS_TOO_MANY:
13970 gen_goto_tb(dc, 1, dc->pc);
13974 gen_a64_set_pc_im(dc->pc);
13977 tcg_gen_exit_tb(NULL, 0);
13980 tcg_gen_lookup_and_goto_ptr();
13982 case DISAS_NORETURN:
13986 gen_a64_set_pc_im(dc->pc);
13987 gen_helper_wfe(cpu_env);
13990 gen_a64_set_pc_im(dc->pc);
13991 gen_helper_yield(cpu_env);
13995 /* This is a special case because we don't want to just halt the CPU
13996 * if trying to debug across a WFI.
13998 TCGv_i32 tmp = tcg_const_i32(4);
14000 gen_a64_set_pc_im(dc->pc);
14001 gen_helper_wfi(cpu_env, tmp);
14002 tcg_temp_free_i32(tmp);
14003 /* The helper doesn't necessarily throw an exception, but we
14004 * must go back to the main loop to check for interrupts anyway.
14006 tcg_gen_exit_tb(NULL, 0);
14012 /* Functions above can change dc->pc, so re-align db->pc_next */
14013 dc->base.pc_next = dc->pc;
14016 static void aarch64_tr_disas_log(const DisasContextBase *dcbase,
14019 DisasContext *dc = container_of(dcbase, DisasContext, base);
14021 qemu_log("IN: %s\n", lookup_symbol(dc->base.pc_first));
14022 log_target_disas(cpu, dc->base.pc_first, dc->base.tb->size);
14025 const TranslatorOps aarch64_translator_ops = {
14026 .init_disas_context = aarch64_tr_init_disas_context,
14027 .tb_start = aarch64_tr_tb_start,
14028 .insn_start = aarch64_tr_insn_start,
14029 .breakpoint_check = aarch64_tr_breakpoint_check,
14030 .translate_insn = aarch64_tr_translate_insn,
14031 .tb_stop = aarch64_tr_tb_stop,
14032 .disas_log = aarch64_tr_disas_log,