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 the 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)
280 if (s->current_el <= 1) {
281 /* Test if NEITHER or BOTH TBI values are set. If so, no need to
282 * examine bit 55 of address, can just generate code.
283 * If mixed, then test via generated code
285 if (s->tbi0 && s->tbi1) {
286 TCGv_i64 tmp_reg = tcg_temp_new_i64();
287 /* Both bits set, sign extension from bit 55 into [63:56] will
290 tcg_gen_shli_i64(tmp_reg, src, 8);
291 tcg_gen_sari_i64(cpu_pc, tmp_reg, 8);
292 tcg_temp_free_i64(tmp_reg);
293 } else if (!s->tbi0 && !s->tbi1) {
294 /* Neither bit set, just load it as-is */
295 tcg_gen_mov_i64(cpu_pc, src);
297 TCGv_i64 tcg_tmpval = tcg_temp_new_i64();
298 TCGv_i64 tcg_bit55 = tcg_temp_new_i64();
299 TCGv_i64 tcg_zero = tcg_const_i64(0);
301 tcg_gen_andi_i64(tcg_bit55, src, (1ull << 55));
304 /* tbi0==1, tbi1==0, so 0-fill upper byte if bit 55 = 0 */
305 tcg_gen_andi_i64(tcg_tmpval, src,
306 0x00FFFFFFFFFFFFFFull);
307 tcg_gen_movcond_i64(TCG_COND_EQ, cpu_pc, tcg_bit55, tcg_zero,
310 /* tbi0==0, tbi1==1, so 1-fill upper byte if bit 55 = 1 */
311 tcg_gen_ori_i64(tcg_tmpval, src,
312 0xFF00000000000000ull);
313 tcg_gen_movcond_i64(TCG_COND_NE, cpu_pc, tcg_bit55, tcg_zero,
316 tcg_temp_free_i64(tcg_zero);
317 tcg_temp_free_i64(tcg_bit55);
318 tcg_temp_free_i64(tcg_tmpval);
320 } else { /* EL > 1 */
322 /* Force tag byte to all zero */
323 tcg_gen_andi_i64(cpu_pc, src, 0x00FFFFFFFFFFFFFFull);
325 /* Load unmodified address */
326 tcg_gen_mov_i64(cpu_pc, src);
331 typedef struct DisasCompare64 {
336 static void a64_test_cc(DisasCompare64 *c64, int cc)
340 arm_test_cc(&c32, cc);
342 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
343 * properly. The NE/EQ comparisons are also fine with this choice. */
344 c64->cond = c32.cond;
345 c64->value = tcg_temp_new_i64();
346 tcg_gen_ext_i32_i64(c64->value, c32.value);
351 static void a64_free_cc(DisasCompare64 *c64)
353 tcg_temp_free_i64(c64->value);
356 static void gen_exception_internal(int excp)
358 TCGv_i32 tcg_excp = tcg_const_i32(excp);
360 assert(excp_is_internal(excp));
361 gen_helper_exception_internal(cpu_env, tcg_excp);
362 tcg_temp_free_i32(tcg_excp);
365 static void gen_exception(int excp, uint32_t syndrome, uint32_t target_el)
367 TCGv_i32 tcg_excp = tcg_const_i32(excp);
368 TCGv_i32 tcg_syn = tcg_const_i32(syndrome);
369 TCGv_i32 tcg_el = tcg_const_i32(target_el);
371 gen_helper_exception_with_syndrome(cpu_env, tcg_excp,
373 tcg_temp_free_i32(tcg_el);
374 tcg_temp_free_i32(tcg_syn);
375 tcg_temp_free_i32(tcg_excp);
378 static void gen_exception_internal_insn(DisasContext *s, int offset, int excp)
380 gen_a64_set_pc_im(s->pc - offset);
381 gen_exception_internal(excp);
382 s->base.is_jmp = DISAS_NORETURN;
385 static void gen_exception_insn(DisasContext *s, int offset, int excp,
386 uint32_t syndrome, uint32_t target_el)
388 gen_a64_set_pc_im(s->pc - offset);
389 gen_exception(excp, syndrome, target_el);
390 s->base.is_jmp = DISAS_NORETURN;
393 static void gen_exception_bkpt_insn(DisasContext *s, int offset,
398 gen_a64_set_pc_im(s->pc - offset);
399 tcg_syn = tcg_const_i32(syndrome);
400 gen_helper_exception_bkpt_insn(cpu_env, tcg_syn);
401 tcg_temp_free_i32(tcg_syn);
402 s->base.is_jmp = DISAS_NORETURN;
405 static void gen_ss_advance(DisasContext *s)
407 /* If the singlestep state is Active-not-pending, advance to
412 gen_helper_clear_pstate_ss(cpu_env);
416 static void gen_step_complete_exception(DisasContext *s)
418 /* We just completed step of an insn. Move from Active-not-pending
419 * to Active-pending, and then also take the swstep exception.
420 * This corresponds to making the (IMPDEF) choice to prioritize
421 * swstep exceptions over asynchronous exceptions taken to an exception
422 * level where debug is disabled. This choice has the advantage that
423 * we do not need to maintain internal state corresponding to the
424 * ISV/EX syndrome bits between completion of the step and generation
425 * of the exception, and our syndrome information is always correct.
428 gen_exception(EXCP_UDEF, syn_swstep(s->ss_same_el, 1, s->is_ldex),
429 default_exception_el(s));
430 s->base.is_jmp = DISAS_NORETURN;
433 static inline bool use_goto_tb(DisasContext *s, int n, uint64_t dest)
435 /* No direct tb linking with singlestep (either QEMU's or the ARM
436 * debug architecture kind) or deterministic io
438 if (s->base.singlestep_enabled || s->ss_active ||
439 (tb_cflags(s->base.tb) & CF_LAST_IO)) {
443 #ifndef CONFIG_USER_ONLY
444 /* Only link tbs from inside the same guest page */
445 if ((s->base.tb->pc & TARGET_PAGE_MASK) != (dest & TARGET_PAGE_MASK)) {
453 static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)
455 TranslationBlock *tb;
458 if (use_goto_tb(s, n, dest)) {
460 gen_a64_set_pc_im(dest);
461 tcg_gen_exit_tb(tb, n);
462 s->base.is_jmp = DISAS_NORETURN;
464 gen_a64_set_pc_im(dest);
466 gen_step_complete_exception(s);
467 } else if (s->base.singlestep_enabled) {
468 gen_exception_internal(EXCP_DEBUG);
470 tcg_gen_lookup_and_goto_ptr();
471 s->base.is_jmp = DISAS_NORETURN;
476 void unallocated_encoding(DisasContext *s)
478 /* Unallocated and reserved encodings are uncategorized */
479 gen_exception_insn(s, 4, EXCP_UDEF, syn_uncategorized(),
480 default_exception_el(s));
483 static void init_tmp_a64_array(DisasContext *s)
485 #ifdef CONFIG_DEBUG_TCG
486 memset(s->tmp_a64, 0, sizeof(s->tmp_a64));
488 s->tmp_a64_count = 0;
491 static void free_tmp_a64(DisasContext *s)
494 for (i = 0; i < s->tmp_a64_count; i++) {
495 tcg_temp_free_i64(s->tmp_a64[i]);
497 init_tmp_a64_array(s);
500 TCGv_i64 new_tmp_a64(DisasContext *s)
502 assert(s->tmp_a64_count < TMP_A64_MAX);
503 return s->tmp_a64[s->tmp_a64_count++] = tcg_temp_new_i64();
506 TCGv_i64 new_tmp_a64_zero(DisasContext *s)
508 TCGv_i64 t = new_tmp_a64(s);
509 tcg_gen_movi_i64(t, 0);
514 * Register access functions
516 * These functions are used for directly accessing a register in where
517 * changes to the final register value are likely to be made. If you
518 * need to use a register for temporary calculation (e.g. index type
519 * operations) use the read_* form.
521 * B1.2.1 Register mappings
523 * In instruction register encoding 31 can refer to ZR (zero register) or
524 * the SP (stack pointer) depending on context. In QEMU's case we map SP
525 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
526 * This is the point of the _sp forms.
528 TCGv_i64 cpu_reg(DisasContext *s, int reg)
531 return new_tmp_a64_zero(s);
537 /* register access for when 31 == SP */
538 TCGv_i64 cpu_reg_sp(DisasContext *s, int reg)
543 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
544 * representing the register contents. This TCGv is an auto-freed
545 * temporary so it need not be explicitly freed, and may be modified.
547 TCGv_i64 read_cpu_reg(DisasContext *s, int reg, int sf)
549 TCGv_i64 v = new_tmp_a64(s);
552 tcg_gen_mov_i64(v, cpu_X[reg]);
554 tcg_gen_ext32u_i64(v, cpu_X[reg]);
557 tcg_gen_movi_i64(v, 0);
562 TCGv_i64 read_cpu_reg_sp(DisasContext *s, int reg, int sf)
564 TCGv_i64 v = new_tmp_a64(s);
566 tcg_gen_mov_i64(v, cpu_X[reg]);
568 tcg_gen_ext32u_i64(v, cpu_X[reg]);
573 /* Return the offset into CPUARMState of a slice (from
574 * the least significant end) of FP register Qn (ie
576 * (Note that this is not the same mapping as for A32; see cpu.h)
578 static inline int fp_reg_offset(DisasContext *s, int regno, TCGMemOp size)
580 return vec_reg_offset(s, regno, 0, size);
583 /* Offset of the high half of the 128 bit vector Qn */
584 static inline int fp_reg_hi_offset(DisasContext *s, int regno)
586 return vec_reg_offset(s, regno, 1, MO_64);
589 /* Convenience accessors for reading and writing single and double
590 * FP registers. Writing clears the upper parts of the associated
591 * 128 bit vector register, as required by the architecture.
592 * Note that unlike the GP register accessors, the values returned
593 * by the read functions must be manually freed.
595 static TCGv_i64 read_fp_dreg(DisasContext *s, int reg)
597 TCGv_i64 v = tcg_temp_new_i64();
599 tcg_gen_ld_i64(v, cpu_env, fp_reg_offset(s, reg, MO_64));
603 static TCGv_i32 read_fp_sreg(DisasContext *s, int reg)
605 TCGv_i32 v = tcg_temp_new_i32();
607 tcg_gen_ld_i32(v, cpu_env, fp_reg_offset(s, reg, MO_32));
611 static TCGv_i32 read_fp_hreg(DisasContext *s, int reg)
613 TCGv_i32 v = tcg_temp_new_i32();
615 tcg_gen_ld16u_i32(v, cpu_env, fp_reg_offset(s, reg, MO_16));
619 /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64).
620 * If SVE is not enabled, then there are only 128 bits in the vector.
622 static void clear_vec_high(DisasContext *s, bool is_q, int rd)
624 unsigned ofs = fp_reg_offset(s, rd, MO_64);
625 unsigned vsz = vec_full_reg_size(s);
628 TCGv_i64 tcg_zero = tcg_const_i64(0);
629 tcg_gen_st_i64(tcg_zero, cpu_env, ofs + 8);
630 tcg_temp_free_i64(tcg_zero);
633 tcg_gen_gvec_dup8i(ofs + 16, vsz - 16, vsz - 16, 0);
637 void write_fp_dreg(DisasContext *s, int reg, TCGv_i64 v)
639 unsigned ofs = fp_reg_offset(s, reg, MO_64);
641 tcg_gen_st_i64(v, cpu_env, ofs);
642 clear_vec_high(s, false, reg);
645 static void write_fp_sreg(DisasContext *s, int reg, TCGv_i32 v)
647 TCGv_i64 tmp = tcg_temp_new_i64();
649 tcg_gen_extu_i32_i64(tmp, v);
650 write_fp_dreg(s, reg, tmp);
651 tcg_temp_free_i64(tmp);
654 TCGv_ptr get_fpstatus_ptr(bool is_f16)
656 TCGv_ptr statusptr = tcg_temp_new_ptr();
659 /* In A64 all instructions (both FP and Neon) use the FPCR; there
660 * is no equivalent of the A32 Neon "standard FPSCR value".
661 * However half-precision operations operate under a different
662 * FZ16 flag and use vfp.fp_status_f16 instead of vfp.fp_status.
665 offset = offsetof(CPUARMState, vfp.fp_status_f16);
667 offset = offsetof(CPUARMState, vfp.fp_status);
669 tcg_gen_addi_ptr(statusptr, cpu_env, offset);
673 /* Expand a 2-operand AdvSIMD vector operation using an expander function. */
674 static void gen_gvec_fn2(DisasContext *s, bool is_q, int rd, int rn,
675 GVecGen2Fn *gvec_fn, int vece)
677 gvec_fn(vece, vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
678 is_q ? 16 : 8, vec_full_reg_size(s));
681 /* Expand a 2-operand + immediate AdvSIMD vector operation using
682 * an expander function.
684 static void gen_gvec_fn2i(DisasContext *s, bool is_q, int rd, int rn,
685 int64_t imm, GVecGen2iFn *gvec_fn, int vece)
687 gvec_fn(vece, vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
688 imm, is_q ? 16 : 8, vec_full_reg_size(s));
691 /* Expand a 3-operand AdvSIMD vector operation using an expander function. */
692 static void gen_gvec_fn3(DisasContext *s, bool is_q, int rd, int rn, int rm,
693 GVecGen3Fn *gvec_fn, int vece)
695 gvec_fn(vece, vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
696 vec_full_reg_offset(s, rm), is_q ? 16 : 8, vec_full_reg_size(s));
699 /* Expand a 2-operand + immediate AdvSIMD vector operation using
702 static void gen_gvec_op2i(DisasContext *s, bool is_q, int rd,
703 int rn, int64_t imm, const GVecGen2i *gvec_op)
705 tcg_gen_gvec_2i(vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
706 is_q ? 16 : 8, vec_full_reg_size(s), imm, gvec_op);
709 /* Expand a 3-operand AdvSIMD vector operation using an op descriptor. */
710 static void gen_gvec_op3(DisasContext *s, bool is_q, int rd,
711 int rn, int rm, const GVecGen3 *gvec_op)
713 tcg_gen_gvec_3(vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn),
714 vec_full_reg_offset(s, rm), is_q ? 16 : 8,
715 vec_full_reg_size(s), gvec_op);
718 /* Expand a 3-operand operation using an out-of-line helper. */
719 static void gen_gvec_op3_ool(DisasContext *s, bool is_q, int rd,
720 int rn, int rm, int data, gen_helper_gvec_3 *fn)
722 tcg_gen_gvec_3_ool(vec_full_reg_offset(s, rd),
723 vec_full_reg_offset(s, rn),
724 vec_full_reg_offset(s, rm),
725 is_q ? 16 : 8, vec_full_reg_size(s), data, fn);
728 /* Expand a 3-operand + env pointer operation using
729 * an out-of-line helper.
731 static void gen_gvec_op3_env(DisasContext *s, bool is_q, int rd,
732 int rn, int rm, gen_helper_gvec_3_ptr *fn)
734 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
735 vec_full_reg_offset(s, rn),
736 vec_full_reg_offset(s, rm), cpu_env,
737 is_q ? 16 : 8, vec_full_reg_size(s), 0, fn);
740 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
741 * an out-of-line helper.
743 static void gen_gvec_op3_fpst(DisasContext *s, bool is_q, int rd, int rn,
744 int rm, bool is_fp16, int data,
745 gen_helper_gvec_3_ptr *fn)
747 TCGv_ptr fpst = get_fpstatus_ptr(is_fp16);
748 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
749 vec_full_reg_offset(s, rn),
750 vec_full_reg_offset(s, rm), fpst,
751 is_q ? 16 : 8, vec_full_reg_size(s), data, fn);
752 tcg_temp_free_ptr(fpst);
755 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
756 * than the 32 bit equivalent.
758 static inline void gen_set_NZ64(TCGv_i64 result)
760 tcg_gen_extr_i64_i32(cpu_ZF, cpu_NF, result);
761 tcg_gen_or_i32(cpu_ZF, cpu_ZF, cpu_NF);
764 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
765 static inline void gen_logic_CC(int sf, TCGv_i64 result)
768 gen_set_NZ64(result);
770 tcg_gen_extrl_i64_i32(cpu_ZF, result);
771 tcg_gen_mov_i32(cpu_NF, cpu_ZF);
773 tcg_gen_movi_i32(cpu_CF, 0);
774 tcg_gen_movi_i32(cpu_VF, 0);
777 /* dest = T0 + T1; compute C, N, V and Z flags */
778 static void gen_add_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
781 TCGv_i64 result, flag, tmp;
782 result = tcg_temp_new_i64();
783 flag = tcg_temp_new_i64();
784 tmp = tcg_temp_new_i64();
786 tcg_gen_movi_i64(tmp, 0);
787 tcg_gen_add2_i64(result, flag, t0, tmp, t1, tmp);
789 tcg_gen_extrl_i64_i32(cpu_CF, flag);
791 gen_set_NZ64(result);
793 tcg_gen_xor_i64(flag, result, t0);
794 tcg_gen_xor_i64(tmp, t0, t1);
795 tcg_gen_andc_i64(flag, flag, tmp);
796 tcg_temp_free_i64(tmp);
797 tcg_gen_extrh_i64_i32(cpu_VF, flag);
799 tcg_gen_mov_i64(dest, result);
800 tcg_temp_free_i64(result);
801 tcg_temp_free_i64(flag);
803 /* 32 bit arithmetic */
804 TCGv_i32 t0_32 = tcg_temp_new_i32();
805 TCGv_i32 t1_32 = tcg_temp_new_i32();
806 TCGv_i32 tmp = tcg_temp_new_i32();
808 tcg_gen_movi_i32(tmp, 0);
809 tcg_gen_extrl_i64_i32(t0_32, t0);
810 tcg_gen_extrl_i64_i32(t1_32, t1);
811 tcg_gen_add2_i32(cpu_NF, cpu_CF, t0_32, tmp, t1_32, tmp);
812 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
813 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
814 tcg_gen_xor_i32(tmp, t0_32, t1_32);
815 tcg_gen_andc_i32(cpu_VF, cpu_VF, tmp);
816 tcg_gen_extu_i32_i64(dest, cpu_NF);
818 tcg_temp_free_i32(tmp);
819 tcg_temp_free_i32(t0_32);
820 tcg_temp_free_i32(t1_32);
824 /* dest = T0 - T1; compute C, N, V and Z flags */
825 static void gen_sub_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
828 /* 64 bit arithmetic */
829 TCGv_i64 result, flag, tmp;
831 result = tcg_temp_new_i64();
832 flag = tcg_temp_new_i64();
833 tcg_gen_sub_i64(result, t0, t1);
835 gen_set_NZ64(result);
837 tcg_gen_setcond_i64(TCG_COND_GEU, flag, t0, t1);
838 tcg_gen_extrl_i64_i32(cpu_CF, flag);
840 tcg_gen_xor_i64(flag, result, t0);
841 tmp = tcg_temp_new_i64();
842 tcg_gen_xor_i64(tmp, t0, t1);
843 tcg_gen_and_i64(flag, flag, tmp);
844 tcg_temp_free_i64(tmp);
845 tcg_gen_extrh_i64_i32(cpu_VF, flag);
846 tcg_gen_mov_i64(dest, result);
847 tcg_temp_free_i64(flag);
848 tcg_temp_free_i64(result);
850 /* 32 bit arithmetic */
851 TCGv_i32 t0_32 = tcg_temp_new_i32();
852 TCGv_i32 t1_32 = tcg_temp_new_i32();
855 tcg_gen_extrl_i64_i32(t0_32, t0);
856 tcg_gen_extrl_i64_i32(t1_32, t1);
857 tcg_gen_sub_i32(cpu_NF, t0_32, t1_32);
858 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
859 tcg_gen_setcond_i32(TCG_COND_GEU, cpu_CF, t0_32, t1_32);
860 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
861 tmp = tcg_temp_new_i32();
862 tcg_gen_xor_i32(tmp, t0_32, t1_32);
863 tcg_temp_free_i32(t0_32);
864 tcg_temp_free_i32(t1_32);
865 tcg_gen_and_i32(cpu_VF, cpu_VF, tmp);
866 tcg_temp_free_i32(tmp);
867 tcg_gen_extu_i32_i64(dest, cpu_NF);
871 /* dest = T0 + T1 + CF; do not compute flags. */
872 static void gen_adc(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
874 TCGv_i64 flag = tcg_temp_new_i64();
875 tcg_gen_extu_i32_i64(flag, cpu_CF);
876 tcg_gen_add_i64(dest, t0, t1);
877 tcg_gen_add_i64(dest, dest, flag);
878 tcg_temp_free_i64(flag);
881 tcg_gen_ext32u_i64(dest, dest);
885 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
886 static void gen_adc_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
889 TCGv_i64 result, cf_64, vf_64, tmp;
890 result = tcg_temp_new_i64();
891 cf_64 = tcg_temp_new_i64();
892 vf_64 = tcg_temp_new_i64();
893 tmp = tcg_const_i64(0);
895 tcg_gen_extu_i32_i64(cf_64, cpu_CF);
896 tcg_gen_add2_i64(result, cf_64, t0, tmp, cf_64, tmp);
897 tcg_gen_add2_i64(result, cf_64, result, cf_64, t1, tmp);
898 tcg_gen_extrl_i64_i32(cpu_CF, cf_64);
899 gen_set_NZ64(result);
901 tcg_gen_xor_i64(vf_64, result, t0);
902 tcg_gen_xor_i64(tmp, t0, t1);
903 tcg_gen_andc_i64(vf_64, vf_64, tmp);
904 tcg_gen_extrh_i64_i32(cpu_VF, vf_64);
906 tcg_gen_mov_i64(dest, result);
908 tcg_temp_free_i64(tmp);
909 tcg_temp_free_i64(vf_64);
910 tcg_temp_free_i64(cf_64);
911 tcg_temp_free_i64(result);
913 TCGv_i32 t0_32, t1_32, tmp;
914 t0_32 = tcg_temp_new_i32();
915 t1_32 = tcg_temp_new_i32();
916 tmp = tcg_const_i32(0);
918 tcg_gen_extrl_i64_i32(t0_32, t0);
919 tcg_gen_extrl_i64_i32(t1_32, t1);
920 tcg_gen_add2_i32(cpu_NF, cpu_CF, t0_32, tmp, cpu_CF, tmp);
921 tcg_gen_add2_i32(cpu_NF, cpu_CF, cpu_NF, cpu_CF, t1_32, tmp);
923 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
924 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
925 tcg_gen_xor_i32(tmp, t0_32, t1_32);
926 tcg_gen_andc_i32(cpu_VF, cpu_VF, tmp);
927 tcg_gen_extu_i32_i64(dest, cpu_NF);
929 tcg_temp_free_i32(tmp);
930 tcg_temp_free_i32(t1_32);
931 tcg_temp_free_i32(t0_32);
936 * Load/Store generators
940 * Store from GPR register to memory.
942 static void do_gpr_st_memidx(DisasContext *s, TCGv_i64 source,
943 TCGv_i64 tcg_addr, int size, int memidx,
945 unsigned int iss_srt,
946 bool iss_sf, bool iss_ar)
949 tcg_gen_qemu_st_i64(source, tcg_addr, memidx, s->be_data + size);
954 syn = syn_data_abort_with_iss(0,
960 0, 0, 0, 0, 0, false);
961 disas_set_insn_syndrome(s, syn);
965 static void do_gpr_st(DisasContext *s, TCGv_i64 source,
966 TCGv_i64 tcg_addr, int size,
968 unsigned int iss_srt,
969 bool iss_sf, bool iss_ar)
971 do_gpr_st_memidx(s, source, tcg_addr, size, get_mem_index(s),
972 iss_valid, iss_srt, iss_sf, iss_ar);
976 * Load from memory to GPR register
978 static void do_gpr_ld_memidx(DisasContext *s,
979 TCGv_i64 dest, TCGv_i64 tcg_addr,
980 int size, bool is_signed,
981 bool extend, int memidx,
982 bool iss_valid, unsigned int iss_srt,
983 bool iss_sf, bool iss_ar)
985 TCGMemOp memop = s->be_data + size;
993 tcg_gen_qemu_ld_i64(dest, tcg_addr, memidx, memop);
995 if (extend && is_signed) {
997 tcg_gen_ext32u_i64(dest, dest);
1003 syn = syn_data_abort_with_iss(0,
1009 0, 0, 0, 0, 0, false);
1010 disas_set_insn_syndrome(s, syn);
1014 static void do_gpr_ld(DisasContext *s,
1015 TCGv_i64 dest, TCGv_i64 tcg_addr,
1016 int size, bool is_signed, bool extend,
1017 bool iss_valid, unsigned int iss_srt,
1018 bool iss_sf, bool iss_ar)
1020 do_gpr_ld_memidx(s, dest, tcg_addr, size, is_signed, extend,
1022 iss_valid, iss_srt, iss_sf, iss_ar);
1026 * Store from FP register to memory
1028 static void do_fp_st(DisasContext *s, int srcidx, TCGv_i64 tcg_addr, int size)
1030 /* This writes the bottom N bits of a 128 bit wide vector to memory */
1031 TCGv_i64 tmp = tcg_temp_new_i64();
1032 tcg_gen_ld_i64(tmp, cpu_env, fp_reg_offset(s, srcidx, MO_64));
1034 tcg_gen_qemu_st_i64(tmp, tcg_addr, get_mem_index(s),
1037 bool be = s->be_data == MO_BE;
1038 TCGv_i64 tcg_hiaddr = tcg_temp_new_i64();
1040 tcg_gen_addi_i64(tcg_hiaddr, tcg_addr, 8);
1041 tcg_gen_qemu_st_i64(tmp, be ? tcg_hiaddr : tcg_addr, get_mem_index(s),
1043 tcg_gen_ld_i64(tmp, cpu_env, fp_reg_hi_offset(s, srcidx));
1044 tcg_gen_qemu_st_i64(tmp, be ? tcg_addr : tcg_hiaddr, get_mem_index(s),
1046 tcg_temp_free_i64(tcg_hiaddr);
1049 tcg_temp_free_i64(tmp);
1053 * Load from memory to FP register
1055 static void do_fp_ld(DisasContext *s, int destidx, TCGv_i64 tcg_addr, int size)
1057 /* This always zero-extends and writes to a full 128 bit wide vector */
1058 TCGv_i64 tmplo = tcg_temp_new_i64();
1062 TCGMemOp memop = s->be_data + size;
1063 tmphi = tcg_const_i64(0);
1064 tcg_gen_qemu_ld_i64(tmplo, tcg_addr, get_mem_index(s), memop);
1066 bool be = s->be_data == MO_BE;
1067 TCGv_i64 tcg_hiaddr;
1069 tmphi = tcg_temp_new_i64();
1070 tcg_hiaddr = tcg_temp_new_i64();
1072 tcg_gen_addi_i64(tcg_hiaddr, tcg_addr, 8);
1073 tcg_gen_qemu_ld_i64(tmplo, be ? tcg_hiaddr : tcg_addr, get_mem_index(s),
1075 tcg_gen_qemu_ld_i64(tmphi, be ? tcg_addr : tcg_hiaddr, get_mem_index(s),
1077 tcg_temp_free_i64(tcg_hiaddr);
1080 tcg_gen_st_i64(tmplo, cpu_env, fp_reg_offset(s, destidx, MO_64));
1081 tcg_gen_st_i64(tmphi, cpu_env, fp_reg_hi_offset(s, destidx));
1083 tcg_temp_free_i64(tmplo);
1084 tcg_temp_free_i64(tmphi);
1086 clear_vec_high(s, true, destidx);
1090 * Vector load/store helpers.
1092 * The principal difference between this and a FP load is that we don't
1093 * zero extend as we are filling a partial chunk of the vector register.
1094 * These functions don't support 128 bit loads/stores, which would be
1095 * normal load/store operations.
1097 * The _i32 versions are useful when operating on 32 bit quantities
1098 * (eg for floating point single or using Neon helper functions).
1101 /* Get value of an element within a vector register */
1102 static void read_vec_element(DisasContext *s, TCGv_i64 tcg_dest, int srcidx,
1103 int element, TCGMemOp memop)
1105 int vect_off = vec_reg_offset(s, srcidx, element, memop & MO_SIZE);
1108 tcg_gen_ld8u_i64(tcg_dest, cpu_env, vect_off);
1111 tcg_gen_ld16u_i64(tcg_dest, cpu_env, vect_off);
1114 tcg_gen_ld32u_i64(tcg_dest, cpu_env, vect_off);
1117 tcg_gen_ld8s_i64(tcg_dest, cpu_env, vect_off);
1120 tcg_gen_ld16s_i64(tcg_dest, cpu_env, vect_off);
1123 tcg_gen_ld32s_i64(tcg_dest, cpu_env, vect_off);
1127 tcg_gen_ld_i64(tcg_dest, cpu_env, vect_off);
1130 g_assert_not_reached();
1134 static void read_vec_element_i32(DisasContext *s, TCGv_i32 tcg_dest, int srcidx,
1135 int element, TCGMemOp memop)
1137 int vect_off = vec_reg_offset(s, srcidx, element, memop & MO_SIZE);
1140 tcg_gen_ld8u_i32(tcg_dest, cpu_env, vect_off);
1143 tcg_gen_ld16u_i32(tcg_dest, cpu_env, vect_off);
1146 tcg_gen_ld8s_i32(tcg_dest, cpu_env, vect_off);
1149 tcg_gen_ld16s_i32(tcg_dest, cpu_env, vect_off);
1153 tcg_gen_ld_i32(tcg_dest, cpu_env, vect_off);
1156 g_assert_not_reached();
1160 /* Set value of an element within a vector register */
1161 static void write_vec_element(DisasContext *s, TCGv_i64 tcg_src, int destidx,
1162 int element, TCGMemOp memop)
1164 int vect_off = vec_reg_offset(s, destidx, element, memop & MO_SIZE);
1167 tcg_gen_st8_i64(tcg_src, cpu_env, vect_off);
1170 tcg_gen_st16_i64(tcg_src, cpu_env, vect_off);
1173 tcg_gen_st32_i64(tcg_src, cpu_env, vect_off);
1176 tcg_gen_st_i64(tcg_src, cpu_env, vect_off);
1179 g_assert_not_reached();
1183 static void write_vec_element_i32(DisasContext *s, TCGv_i32 tcg_src,
1184 int destidx, int element, TCGMemOp memop)
1186 int vect_off = vec_reg_offset(s, destidx, element, memop & MO_SIZE);
1189 tcg_gen_st8_i32(tcg_src, cpu_env, vect_off);
1192 tcg_gen_st16_i32(tcg_src, cpu_env, vect_off);
1195 tcg_gen_st_i32(tcg_src, cpu_env, vect_off);
1198 g_assert_not_reached();
1202 /* Store from vector register to memory */
1203 static void do_vec_st(DisasContext *s, int srcidx, int element,
1204 TCGv_i64 tcg_addr, int size, TCGMemOp endian)
1206 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
1208 read_vec_element(s, tcg_tmp, srcidx, element, size);
1209 tcg_gen_qemu_st_i64(tcg_tmp, tcg_addr, get_mem_index(s), endian | size);
1211 tcg_temp_free_i64(tcg_tmp);
1214 /* Load from memory to vector register */
1215 static void do_vec_ld(DisasContext *s, int destidx, int element,
1216 TCGv_i64 tcg_addr, int size, TCGMemOp endian)
1218 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
1220 tcg_gen_qemu_ld_i64(tcg_tmp, tcg_addr, get_mem_index(s), endian | size);
1221 write_vec_element(s, tcg_tmp, destidx, element, size);
1223 tcg_temp_free_i64(tcg_tmp);
1226 /* Check that FP/Neon access is enabled. If it is, return
1227 * true. If not, emit code to generate an appropriate exception,
1228 * and return false; the caller should not emit any code for
1229 * the instruction. Note that this check must happen after all
1230 * unallocated-encoding checks (otherwise the syndrome information
1231 * for the resulting exception will be incorrect).
1233 static inline bool fp_access_check(DisasContext *s)
1235 assert(!s->fp_access_checked);
1236 s->fp_access_checked = true;
1238 if (!s->fp_excp_el) {
1242 gen_exception_insn(s, 4, EXCP_UDEF, syn_fp_access_trap(1, 0xe, false),
1247 /* Check that SVE access is enabled. If it is, return true.
1248 * If not, emit code to generate an appropriate exception and return false.
1250 bool sve_access_check(DisasContext *s)
1252 if (s->sve_excp_el) {
1253 gen_exception_insn(s, 4, EXCP_UDEF, syn_sve_access_trap(),
1257 return fp_access_check(s);
1261 * This utility function is for doing register extension with an
1262 * optional shift. You will likely want to pass a temporary for the
1263 * destination register. See DecodeRegExtend() in the ARM ARM.
1265 static void ext_and_shift_reg(TCGv_i64 tcg_out, TCGv_i64 tcg_in,
1266 int option, unsigned int shift)
1268 int extsize = extract32(option, 0, 2);
1269 bool is_signed = extract32(option, 2, 1);
1274 tcg_gen_ext8s_i64(tcg_out, tcg_in);
1277 tcg_gen_ext16s_i64(tcg_out, tcg_in);
1280 tcg_gen_ext32s_i64(tcg_out, tcg_in);
1283 tcg_gen_mov_i64(tcg_out, tcg_in);
1289 tcg_gen_ext8u_i64(tcg_out, tcg_in);
1292 tcg_gen_ext16u_i64(tcg_out, tcg_in);
1295 tcg_gen_ext32u_i64(tcg_out, tcg_in);
1298 tcg_gen_mov_i64(tcg_out, tcg_in);
1304 tcg_gen_shli_i64(tcg_out, tcg_out, shift);
1308 static inline void gen_check_sp_alignment(DisasContext *s)
1310 /* The AArch64 architecture mandates that (if enabled via PSTATE
1311 * or SCTLR bits) there is a check that SP is 16-aligned on every
1312 * SP-relative load or store (with an exception generated if it is not).
1313 * In line with general QEMU practice regarding misaligned accesses,
1314 * we omit these checks for the sake of guest program performance.
1315 * This function is provided as a hook so we can more easily add these
1316 * checks in future (possibly as a "favour catching guest program bugs
1317 * over speed" user selectable option).
1322 * This provides a simple table based table lookup decoder. It is
1323 * intended to be used when the relevant bits for decode are too
1324 * awkwardly placed and switch/if based logic would be confusing and
1325 * deeply nested. Since it's a linear search through the table, tables
1326 * should be kept small.
1328 * It returns the first handler where insn & mask == pattern, or
1329 * NULL if there is no match.
1330 * The table is terminated by an empty mask (i.e. 0)
1332 static inline AArch64DecodeFn *lookup_disas_fn(const AArch64DecodeTable *table,
1335 const AArch64DecodeTable *tptr = table;
1337 while (tptr->mask) {
1338 if ((insn & tptr->mask) == tptr->pattern) {
1339 return tptr->disas_fn;
1347 * The instruction disassembly implemented here matches
1348 * the instruction encoding classifications in chapter C4
1349 * of the ARM Architecture Reference Manual (DDI0487B_a);
1350 * classification names and decode diagrams here should generally
1351 * match up with those in the manual.
1354 /* Unconditional branch (immediate)
1356 * +----+-----------+-------------------------------------+
1357 * | op | 0 0 1 0 1 | imm26 |
1358 * +----+-----------+-------------------------------------+
1360 static void disas_uncond_b_imm(DisasContext *s, uint32_t insn)
1362 uint64_t addr = s->pc + sextract32(insn, 0, 26) * 4 - 4;
1364 if (insn & (1U << 31)) {
1365 /* BL Branch with link */
1366 tcg_gen_movi_i64(cpu_reg(s, 30), s->pc);
1369 /* B Branch / BL Branch with link */
1370 gen_goto_tb(s, 0, addr);
1373 /* Compare and branch (immediate)
1374 * 31 30 25 24 23 5 4 0
1375 * +----+-------------+----+---------------------+--------+
1376 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1377 * +----+-------------+----+---------------------+--------+
1379 static void disas_comp_b_imm(DisasContext *s, uint32_t insn)
1381 unsigned int sf, op, rt;
1383 TCGLabel *label_match;
1386 sf = extract32(insn, 31, 1);
1387 op = extract32(insn, 24, 1); /* 0: CBZ; 1: CBNZ */
1388 rt = extract32(insn, 0, 5);
1389 addr = s->pc + sextract32(insn, 5, 19) * 4 - 4;
1391 tcg_cmp = read_cpu_reg(s, rt, sf);
1392 label_match = gen_new_label();
1394 tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ,
1395 tcg_cmp, 0, label_match);
1397 gen_goto_tb(s, 0, s->pc);
1398 gen_set_label(label_match);
1399 gen_goto_tb(s, 1, addr);
1402 /* Test and branch (immediate)
1403 * 31 30 25 24 23 19 18 5 4 0
1404 * +----+-------------+----+-------+-------------+------+
1405 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1406 * +----+-------------+----+-------+-------------+------+
1408 static void disas_test_b_imm(DisasContext *s, uint32_t insn)
1410 unsigned int bit_pos, op, rt;
1412 TCGLabel *label_match;
1415 bit_pos = (extract32(insn, 31, 1) << 5) | extract32(insn, 19, 5);
1416 op = extract32(insn, 24, 1); /* 0: TBZ; 1: TBNZ */
1417 addr = s->pc + sextract32(insn, 5, 14) * 4 - 4;
1418 rt = extract32(insn, 0, 5);
1420 tcg_cmp = tcg_temp_new_i64();
1421 tcg_gen_andi_i64(tcg_cmp, cpu_reg(s, rt), (1ULL << bit_pos));
1422 label_match = gen_new_label();
1423 tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ,
1424 tcg_cmp, 0, label_match);
1425 tcg_temp_free_i64(tcg_cmp);
1426 gen_goto_tb(s, 0, s->pc);
1427 gen_set_label(label_match);
1428 gen_goto_tb(s, 1, addr);
1431 /* Conditional branch (immediate)
1432 * 31 25 24 23 5 4 3 0
1433 * +---------------+----+---------------------+----+------+
1434 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1435 * +---------------+----+---------------------+----+------+
1437 static void disas_cond_b_imm(DisasContext *s, uint32_t insn)
1442 if ((insn & (1 << 4)) || (insn & (1 << 24))) {
1443 unallocated_encoding(s);
1446 addr = s->pc + sextract32(insn, 5, 19) * 4 - 4;
1447 cond = extract32(insn, 0, 4);
1450 /* genuinely conditional branches */
1451 TCGLabel *label_match = gen_new_label();
1452 arm_gen_test_cc(cond, label_match);
1453 gen_goto_tb(s, 0, s->pc);
1454 gen_set_label(label_match);
1455 gen_goto_tb(s, 1, addr);
1457 /* 0xe and 0xf are both "always" conditions */
1458 gen_goto_tb(s, 0, addr);
1462 /* HINT instruction group, including various allocated HINTs */
1463 static void handle_hint(DisasContext *s, uint32_t insn,
1464 unsigned int op1, unsigned int op2, unsigned int crm)
1466 unsigned int selector = crm << 3 | op2;
1469 unallocated_encoding(s);
1474 case 0b00000: /* NOP */
1476 case 0b00011: /* WFI */
1477 s->base.is_jmp = DISAS_WFI;
1479 case 0b00001: /* YIELD */
1480 /* When running in MTTCG we don't generate jumps to the yield and
1481 * WFE helpers as it won't affect the scheduling of other vCPUs.
1482 * If we wanted to more completely model WFE/SEV so we don't busy
1483 * spin unnecessarily we would need to do something more involved.
1485 if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) {
1486 s->base.is_jmp = DISAS_YIELD;
1489 case 0b00010: /* WFE */
1490 if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) {
1491 s->base.is_jmp = DISAS_WFE;
1494 case 0b00100: /* SEV */
1495 case 0b00101: /* SEVL */
1496 /* we treat all as NOP at least for now */
1498 case 0b00111: /* XPACLRI */
1499 if (s->pauth_active) {
1500 gen_helper_xpaci(cpu_X[30], cpu_env, cpu_X[30]);
1503 case 0b01000: /* PACIA1716 */
1504 if (s->pauth_active) {
1505 gen_helper_pacia(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1508 case 0b01010: /* PACIB1716 */
1509 if (s->pauth_active) {
1510 gen_helper_pacib(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1513 case 0b01100: /* AUTIA1716 */
1514 if (s->pauth_active) {
1515 gen_helper_autia(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1518 case 0b01110: /* AUTIB1716 */
1519 if (s->pauth_active) {
1520 gen_helper_autib(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]);
1523 case 0b11000: /* PACIAZ */
1524 if (s->pauth_active) {
1525 gen_helper_pacia(cpu_X[30], cpu_env, cpu_X[30],
1526 new_tmp_a64_zero(s));
1529 case 0b11001: /* PACIASP */
1530 if (s->pauth_active) {
1531 gen_helper_pacia(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1534 case 0b11010: /* PACIBZ */
1535 if (s->pauth_active) {
1536 gen_helper_pacib(cpu_X[30], cpu_env, cpu_X[30],
1537 new_tmp_a64_zero(s));
1540 case 0b11011: /* PACIBSP */
1541 if (s->pauth_active) {
1542 gen_helper_pacib(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1545 case 0b11100: /* AUTIAZ */
1546 if (s->pauth_active) {
1547 gen_helper_autia(cpu_X[30], cpu_env, cpu_X[30],
1548 new_tmp_a64_zero(s));
1551 case 0b11101: /* AUTIASP */
1552 if (s->pauth_active) {
1553 gen_helper_autia(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1556 case 0b11110: /* AUTIBZ */
1557 if (s->pauth_active) {
1558 gen_helper_autib(cpu_X[30], cpu_env, cpu_X[30],
1559 new_tmp_a64_zero(s));
1562 case 0b11111: /* AUTIBSP */
1563 if (s->pauth_active) {
1564 gen_helper_autib(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]);
1568 /* default specified as NOP equivalent */
1573 static void gen_clrex(DisasContext *s, uint32_t insn)
1575 tcg_gen_movi_i64(cpu_exclusive_addr, -1);
1578 /* CLREX, DSB, DMB, ISB */
1579 static void handle_sync(DisasContext *s, uint32_t insn,
1580 unsigned int op1, unsigned int op2, unsigned int crm)
1585 unallocated_encoding(s);
1596 case 1: /* MBReqTypes_Reads */
1597 bar = TCG_BAR_SC | TCG_MO_LD_LD | TCG_MO_LD_ST;
1599 case 2: /* MBReqTypes_Writes */
1600 bar = TCG_BAR_SC | TCG_MO_ST_ST;
1602 default: /* MBReqTypes_All */
1603 bar = TCG_BAR_SC | TCG_MO_ALL;
1609 /* We need to break the TB after this insn to execute
1610 * a self-modified code correctly and also to take
1611 * any pending interrupts immediately.
1613 gen_goto_tb(s, 0, s->pc);
1616 unallocated_encoding(s);
1621 /* MSR (immediate) - move immediate to processor state field */
1622 static void handle_msr_i(DisasContext *s, uint32_t insn,
1623 unsigned int op1, unsigned int op2, unsigned int crm)
1625 int op = op1 << 3 | op2;
1627 case 0x05: /* SPSel */
1628 if (s->current_el == 0) {
1629 unallocated_encoding(s);
1633 case 0x1e: /* DAIFSet */
1634 case 0x1f: /* DAIFClear */
1636 TCGv_i32 tcg_imm = tcg_const_i32(crm);
1637 TCGv_i32 tcg_op = tcg_const_i32(op);
1638 gen_a64_set_pc_im(s->pc - 4);
1639 gen_helper_msr_i_pstate(cpu_env, tcg_op, tcg_imm);
1640 tcg_temp_free_i32(tcg_imm);
1641 tcg_temp_free_i32(tcg_op);
1642 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1643 gen_a64_set_pc_im(s->pc);
1644 s->base.is_jmp = (op == 0x1f ? DISAS_EXIT : DISAS_JUMP);
1648 unallocated_encoding(s);
1653 static void gen_get_nzcv(TCGv_i64 tcg_rt)
1655 TCGv_i32 tmp = tcg_temp_new_i32();
1656 TCGv_i32 nzcv = tcg_temp_new_i32();
1658 /* build bit 31, N */
1659 tcg_gen_andi_i32(nzcv, cpu_NF, (1U << 31));
1660 /* build bit 30, Z */
1661 tcg_gen_setcondi_i32(TCG_COND_EQ, tmp, cpu_ZF, 0);
1662 tcg_gen_deposit_i32(nzcv, nzcv, tmp, 30, 1);
1663 /* build bit 29, C */
1664 tcg_gen_deposit_i32(nzcv, nzcv, cpu_CF, 29, 1);
1665 /* build bit 28, V */
1666 tcg_gen_shri_i32(tmp, cpu_VF, 31);
1667 tcg_gen_deposit_i32(nzcv, nzcv, tmp, 28, 1);
1668 /* generate result */
1669 tcg_gen_extu_i32_i64(tcg_rt, nzcv);
1671 tcg_temp_free_i32(nzcv);
1672 tcg_temp_free_i32(tmp);
1675 static void gen_set_nzcv(TCGv_i64 tcg_rt)
1678 TCGv_i32 nzcv = tcg_temp_new_i32();
1680 /* take NZCV from R[t] */
1681 tcg_gen_extrl_i64_i32(nzcv, tcg_rt);
1684 tcg_gen_andi_i32(cpu_NF, nzcv, (1U << 31));
1686 tcg_gen_andi_i32(cpu_ZF, nzcv, (1 << 30));
1687 tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_ZF, cpu_ZF, 0);
1689 tcg_gen_andi_i32(cpu_CF, nzcv, (1 << 29));
1690 tcg_gen_shri_i32(cpu_CF, cpu_CF, 29);
1692 tcg_gen_andi_i32(cpu_VF, nzcv, (1 << 28));
1693 tcg_gen_shli_i32(cpu_VF, cpu_VF, 3);
1694 tcg_temp_free_i32(nzcv);
1697 /* MRS - move from system register
1698 * MSR (register) - move to system register
1701 * These are all essentially the same insn in 'read' and 'write'
1702 * versions, with varying op0 fields.
1704 static void handle_sys(DisasContext *s, uint32_t insn, bool isread,
1705 unsigned int op0, unsigned int op1, unsigned int op2,
1706 unsigned int crn, unsigned int crm, unsigned int rt)
1708 const ARMCPRegInfo *ri;
1711 ri = get_arm_cp_reginfo(s->cp_regs,
1712 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP,
1713 crn, crm, op0, op1, op2));
1716 /* Unknown register; this might be a guest error or a QEMU
1717 * unimplemented feature.
1719 qemu_log_mask(LOG_UNIMP, "%s access to unsupported AArch64 "
1720 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1721 isread ? "read" : "write", op0, op1, crn, crm, op2);
1722 unallocated_encoding(s);
1726 /* Check access permissions */
1727 if (!cp_access_ok(s->current_el, ri, isread)) {
1728 unallocated_encoding(s);
1733 /* Emit code to perform further access permissions checks at
1734 * runtime; this may result in an exception.
1737 TCGv_i32 tcg_syn, tcg_isread;
1740 gen_a64_set_pc_im(s->pc - 4);
1741 tmpptr = tcg_const_ptr(ri);
1742 syndrome = syn_aa64_sysregtrap(op0, op1, op2, crn, crm, rt, isread);
1743 tcg_syn = tcg_const_i32(syndrome);
1744 tcg_isread = tcg_const_i32(isread);
1745 gen_helper_access_check_cp_reg(cpu_env, tmpptr, tcg_syn, tcg_isread);
1746 tcg_temp_free_ptr(tmpptr);
1747 tcg_temp_free_i32(tcg_syn);
1748 tcg_temp_free_i32(tcg_isread);
1751 /* Handle special cases first */
1752 switch (ri->type & ~(ARM_CP_FLAG_MASK & ~ARM_CP_SPECIAL)) {
1756 tcg_rt = cpu_reg(s, rt);
1758 gen_get_nzcv(tcg_rt);
1760 gen_set_nzcv(tcg_rt);
1763 case ARM_CP_CURRENTEL:
1764 /* Reads as current EL value from pstate, which is
1765 * guaranteed to be constant by the tb flags.
1767 tcg_rt = cpu_reg(s, rt);
1768 tcg_gen_movi_i64(tcg_rt, s->current_el << 2);
1771 /* Writes clear the aligned block of memory which rt points into. */
1772 tcg_rt = cpu_reg(s, rt);
1773 gen_helper_dc_zva(cpu_env, tcg_rt);
1778 if ((ri->type & ARM_CP_FPU) && !fp_access_check(s)) {
1780 } else if ((ri->type & ARM_CP_SVE) && !sve_access_check(s)) {
1784 if ((tb_cflags(s->base.tb) & CF_USE_ICOUNT) && (ri->type & ARM_CP_IO)) {
1788 tcg_rt = cpu_reg(s, rt);
1791 if (ri->type & ARM_CP_CONST) {
1792 tcg_gen_movi_i64(tcg_rt, ri->resetvalue);
1793 } else if (ri->readfn) {
1795 tmpptr = tcg_const_ptr(ri);
1796 gen_helper_get_cp_reg64(tcg_rt, cpu_env, tmpptr);
1797 tcg_temp_free_ptr(tmpptr);
1799 tcg_gen_ld_i64(tcg_rt, cpu_env, ri->fieldoffset);
1802 if (ri->type & ARM_CP_CONST) {
1803 /* If not forbidden by access permissions, treat as WI */
1805 } else if (ri->writefn) {
1807 tmpptr = tcg_const_ptr(ri);
1808 gen_helper_set_cp_reg64(cpu_env, tmpptr, tcg_rt);
1809 tcg_temp_free_ptr(tmpptr);
1811 tcg_gen_st_i64(tcg_rt, cpu_env, ri->fieldoffset);
1815 if ((tb_cflags(s->base.tb) & CF_USE_ICOUNT) && (ri->type & ARM_CP_IO)) {
1816 /* I/O operations must end the TB here (whether read or write) */
1818 s->base.is_jmp = DISAS_UPDATE;
1819 } else if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) {
1820 /* We default to ending the TB on a coprocessor register write,
1821 * but allow this to be suppressed by the register definition
1822 * (usually only necessary to work around guest bugs).
1824 s->base.is_jmp = DISAS_UPDATE;
1829 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1830 * +---------------------+---+-----+-----+-------+-------+-----+------+
1831 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1832 * +---------------------+---+-----+-----+-------+-------+-----+------+
1834 static void disas_system(DisasContext *s, uint32_t insn)
1836 unsigned int l, op0, op1, crn, crm, op2, rt;
1837 l = extract32(insn, 21, 1);
1838 op0 = extract32(insn, 19, 2);
1839 op1 = extract32(insn, 16, 3);
1840 crn = extract32(insn, 12, 4);
1841 crm = extract32(insn, 8, 4);
1842 op2 = extract32(insn, 5, 3);
1843 rt = extract32(insn, 0, 5);
1846 if (l || rt != 31) {
1847 unallocated_encoding(s);
1851 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
1852 handle_hint(s, insn, op1, op2, crm);
1854 case 3: /* CLREX, DSB, DMB, ISB */
1855 handle_sync(s, insn, op1, op2, crm);
1857 case 4: /* MSR (immediate) */
1858 handle_msr_i(s, insn, op1, op2, crm);
1861 unallocated_encoding(s);
1866 handle_sys(s, insn, l, op0, op1, op2, crn, crm, rt);
1869 /* Exception generation
1871 * 31 24 23 21 20 5 4 2 1 0
1872 * +-----------------+-----+------------------------+-----+----+
1873 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1874 * +-----------------------+------------------------+----------+
1876 static void disas_exc(DisasContext *s, uint32_t insn)
1878 int opc = extract32(insn, 21, 3);
1879 int op2_ll = extract32(insn, 0, 5);
1880 int imm16 = extract32(insn, 5, 16);
1885 /* For SVC, HVC and SMC we advance the single-step state
1886 * machine before taking the exception. This is architecturally
1887 * mandated, to ensure that single-stepping a system call
1888 * instruction works properly.
1893 gen_exception_insn(s, 0, EXCP_SWI, syn_aa64_svc(imm16),
1894 default_exception_el(s));
1897 if (s->current_el == 0) {
1898 unallocated_encoding(s);
1901 /* The pre HVC helper handles cases when HVC gets trapped
1902 * as an undefined insn by runtime configuration.
1904 gen_a64_set_pc_im(s->pc - 4);
1905 gen_helper_pre_hvc(cpu_env);
1907 gen_exception_insn(s, 0, EXCP_HVC, syn_aa64_hvc(imm16), 2);
1910 if (s->current_el == 0) {
1911 unallocated_encoding(s);
1914 gen_a64_set_pc_im(s->pc - 4);
1915 tmp = tcg_const_i32(syn_aa64_smc(imm16));
1916 gen_helper_pre_smc(cpu_env, tmp);
1917 tcg_temp_free_i32(tmp);
1919 gen_exception_insn(s, 0, EXCP_SMC, syn_aa64_smc(imm16), 3);
1922 unallocated_encoding(s);
1928 unallocated_encoding(s);
1932 gen_exception_bkpt_insn(s, 4, syn_aa64_bkpt(imm16));
1936 unallocated_encoding(s);
1939 /* HLT. This has two purposes.
1940 * Architecturally, it is an external halting debug instruction.
1941 * Since QEMU doesn't implement external debug, we treat this as
1942 * it is required for halting debug disabled: it will UNDEF.
1943 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1945 if (semihosting_enabled() && imm16 == 0xf000) {
1946 #ifndef CONFIG_USER_ONLY
1947 /* In system mode, don't allow userspace access to semihosting,
1948 * to provide some semblance of security (and for consistency
1949 * with our 32-bit semihosting).
1951 if (s->current_el == 0) {
1952 unsupported_encoding(s, insn);
1956 gen_exception_internal_insn(s, 0, EXCP_SEMIHOST);
1958 unsupported_encoding(s, insn);
1962 if (op2_ll < 1 || op2_ll > 3) {
1963 unallocated_encoding(s);
1966 /* DCPS1, DCPS2, DCPS3 */
1967 unsupported_encoding(s, insn);
1970 unallocated_encoding(s);
1975 /* Unconditional branch (register)
1976 * 31 25 24 21 20 16 15 10 9 5 4 0
1977 * +---------------+-------+-------+-------+------+-------+
1978 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1979 * +---------------+-------+-------+-------+------+-------+
1981 static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)
1983 unsigned int opc, op2, op3, rn, op4;
1986 opc = extract32(insn, 21, 4);
1987 op2 = extract32(insn, 16, 5);
1988 op3 = extract32(insn, 10, 6);
1989 rn = extract32(insn, 5, 5);
1990 op4 = extract32(insn, 0, 5);
1992 if (op4 != 0x0 || op3 != 0x0 || op2 != 0x1f) {
1993 unallocated_encoding(s);
2001 gen_a64_set_pc(s, cpu_reg(s, rn));
2002 /* BLR also needs to load return address */
2004 tcg_gen_movi_i64(cpu_reg(s, 30), s->pc);
2008 if (s->current_el == 0) {
2009 unallocated_encoding(s);
2012 if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) {
2015 dst = tcg_temp_new_i64();
2016 tcg_gen_ld_i64(dst, cpu_env,
2017 offsetof(CPUARMState, elr_el[s->current_el]));
2018 gen_helper_exception_return(cpu_env, dst);
2019 tcg_temp_free_i64(dst);
2020 if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) {
2023 /* Must exit loop to check un-masked IRQs */
2024 s->base.is_jmp = DISAS_EXIT;
2028 unallocated_encoding(s);
2030 unsupported_encoding(s, insn);
2034 unallocated_encoding(s);
2038 s->base.is_jmp = DISAS_JUMP;
2041 /* Branches, exception generating and system instructions */
2042 static void disas_b_exc_sys(DisasContext *s, uint32_t insn)
2044 switch (extract32(insn, 25, 7)) {
2045 case 0x0a: case 0x0b:
2046 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
2047 disas_uncond_b_imm(s, insn);
2049 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
2050 disas_comp_b_imm(s, insn);
2052 case 0x1b: case 0x5b: /* Test & branch (immediate) */
2053 disas_test_b_imm(s, insn);
2055 case 0x2a: /* Conditional branch (immediate) */
2056 disas_cond_b_imm(s, insn);
2058 case 0x6a: /* Exception generation / System */
2059 if (insn & (1 << 24)) {
2060 disas_system(s, insn);
2065 case 0x6b: /* Unconditional branch (register) */
2066 disas_uncond_b_reg(s, insn);
2069 unallocated_encoding(s);
2075 * Load/Store exclusive instructions are implemented by remembering
2076 * the value/address loaded, and seeing if these are the same
2077 * when the store is performed. This is not actually the architecturally
2078 * mandated semantics, but it works for typical guest code sequences
2079 * and avoids having to monitor regular stores.
2081 * The store exclusive uses the atomic cmpxchg primitives to avoid
2082 * races in multi-threaded linux-user and when MTTCG softmmu is
2085 static void gen_load_exclusive(DisasContext *s, int rt, int rt2,
2086 TCGv_i64 addr, int size, bool is_pair)
2088 int idx = get_mem_index(s);
2089 TCGMemOp memop = s->be_data;
2091 g_assert(size <= 3);
2093 g_assert(size >= 2);
2095 /* The pair must be single-copy atomic for the doubleword. */
2096 memop |= MO_64 | MO_ALIGN;
2097 tcg_gen_qemu_ld_i64(cpu_exclusive_val, addr, idx, memop);
2098 if (s->be_data == MO_LE) {
2099 tcg_gen_extract_i64(cpu_reg(s, rt), cpu_exclusive_val, 0, 32);
2100 tcg_gen_extract_i64(cpu_reg(s, rt2), cpu_exclusive_val, 32, 32);
2102 tcg_gen_extract_i64(cpu_reg(s, rt), cpu_exclusive_val, 32, 32);
2103 tcg_gen_extract_i64(cpu_reg(s, rt2), cpu_exclusive_val, 0, 32);
2106 /* The pair must be single-copy atomic for *each* doubleword, not
2107 the entire quadword, however it must be quadword aligned. */
2109 tcg_gen_qemu_ld_i64(cpu_exclusive_val, addr, idx,
2110 memop | MO_ALIGN_16);
2112 TCGv_i64 addr2 = tcg_temp_new_i64();
2113 tcg_gen_addi_i64(addr2, addr, 8);
2114 tcg_gen_qemu_ld_i64(cpu_exclusive_high, addr2, idx, memop);
2115 tcg_temp_free_i64(addr2);
2117 tcg_gen_mov_i64(cpu_reg(s, rt), cpu_exclusive_val);
2118 tcg_gen_mov_i64(cpu_reg(s, rt2), cpu_exclusive_high);
2121 memop |= size | MO_ALIGN;
2122 tcg_gen_qemu_ld_i64(cpu_exclusive_val, addr, idx, memop);
2123 tcg_gen_mov_i64(cpu_reg(s, rt), cpu_exclusive_val);
2125 tcg_gen_mov_i64(cpu_exclusive_addr, addr);
2128 static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,
2129 TCGv_i64 addr, int size, int is_pair)
2131 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
2132 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
2135 * [addr + datasize] = {Rt2};
2141 * env->exclusive_addr = -1;
2143 TCGLabel *fail_label = gen_new_label();
2144 TCGLabel *done_label = gen_new_label();
2147 tcg_gen_brcond_i64(TCG_COND_NE, addr, cpu_exclusive_addr, fail_label);
2149 tmp = tcg_temp_new_i64();
2152 if (s->be_data == MO_LE) {
2153 tcg_gen_concat32_i64(tmp, cpu_reg(s, rt), cpu_reg(s, rt2));
2155 tcg_gen_concat32_i64(tmp, cpu_reg(s, rt2), cpu_reg(s, rt));
2157 tcg_gen_atomic_cmpxchg_i64(tmp, cpu_exclusive_addr,
2158 cpu_exclusive_val, tmp,
2160 MO_64 | MO_ALIGN | s->be_data);
2161 tcg_gen_setcond_i64(TCG_COND_NE, tmp, tmp, cpu_exclusive_val);
2162 } else if (tb_cflags(s->base.tb) & CF_PARALLEL) {
2163 if (!HAVE_CMPXCHG128) {
2164 gen_helper_exit_atomic(cpu_env);
2165 s->base.is_jmp = DISAS_NORETURN;
2166 } else if (s->be_data == MO_LE) {
2167 gen_helper_paired_cmpxchg64_le_parallel(tmp, cpu_env,
2172 gen_helper_paired_cmpxchg64_be_parallel(tmp, cpu_env,
2177 } else if (s->be_data == MO_LE) {
2178 gen_helper_paired_cmpxchg64_le(tmp, cpu_env, cpu_exclusive_addr,
2179 cpu_reg(s, rt), cpu_reg(s, rt2));
2181 gen_helper_paired_cmpxchg64_be(tmp, cpu_env, cpu_exclusive_addr,
2182 cpu_reg(s, rt), cpu_reg(s, rt2));
2185 tcg_gen_atomic_cmpxchg_i64(tmp, cpu_exclusive_addr, cpu_exclusive_val,
2186 cpu_reg(s, rt), get_mem_index(s),
2187 size | MO_ALIGN | s->be_data);
2188 tcg_gen_setcond_i64(TCG_COND_NE, tmp, tmp, cpu_exclusive_val);
2190 tcg_gen_mov_i64(cpu_reg(s, rd), tmp);
2191 tcg_temp_free_i64(tmp);
2192 tcg_gen_br(done_label);
2194 gen_set_label(fail_label);
2195 tcg_gen_movi_i64(cpu_reg(s, rd), 1);
2196 gen_set_label(done_label);
2197 tcg_gen_movi_i64(cpu_exclusive_addr, -1);
2200 static void gen_compare_and_swap(DisasContext *s, int rs, int rt,
2203 TCGv_i64 tcg_rs = cpu_reg(s, rs);
2204 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2205 int memidx = get_mem_index(s);
2206 TCGv_i64 addr = cpu_reg_sp(s, rn);
2209 gen_check_sp_alignment(s);
2211 tcg_gen_atomic_cmpxchg_i64(tcg_rs, addr, tcg_rs, tcg_rt, memidx,
2212 size | MO_ALIGN | s->be_data);
2215 static void gen_compare_and_swap_pair(DisasContext *s, int rs, int rt,
2218 TCGv_i64 s1 = cpu_reg(s, rs);
2219 TCGv_i64 s2 = cpu_reg(s, rs + 1);
2220 TCGv_i64 t1 = cpu_reg(s, rt);
2221 TCGv_i64 t2 = cpu_reg(s, rt + 1);
2222 TCGv_i64 addr = cpu_reg_sp(s, rn);
2223 int memidx = get_mem_index(s);
2226 gen_check_sp_alignment(s);
2230 TCGv_i64 cmp = tcg_temp_new_i64();
2231 TCGv_i64 val = tcg_temp_new_i64();
2233 if (s->be_data == MO_LE) {
2234 tcg_gen_concat32_i64(val, t1, t2);
2235 tcg_gen_concat32_i64(cmp, s1, s2);
2237 tcg_gen_concat32_i64(val, t2, t1);
2238 tcg_gen_concat32_i64(cmp, s2, s1);
2241 tcg_gen_atomic_cmpxchg_i64(cmp, addr, cmp, val, memidx,
2242 MO_64 | MO_ALIGN | s->be_data);
2243 tcg_temp_free_i64(val);
2245 if (s->be_data == MO_LE) {
2246 tcg_gen_extr32_i64(s1, s2, cmp);
2248 tcg_gen_extr32_i64(s2, s1, cmp);
2250 tcg_temp_free_i64(cmp);
2251 } else if (tb_cflags(s->base.tb) & CF_PARALLEL) {
2252 if (HAVE_CMPXCHG128) {
2253 TCGv_i32 tcg_rs = tcg_const_i32(rs);
2254 if (s->be_data == MO_LE) {
2255 gen_helper_casp_le_parallel(cpu_env, tcg_rs, addr, t1, t2);
2257 gen_helper_casp_be_parallel(cpu_env, tcg_rs, addr, t1, t2);
2259 tcg_temp_free_i32(tcg_rs);
2261 gen_helper_exit_atomic(cpu_env);
2262 s->base.is_jmp = DISAS_NORETURN;
2265 TCGv_i64 d1 = tcg_temp_new_i64();
2266 TCGv_i64 d2 = tcg_temp_new_i64();
2267 TCGv_i64 a2 = tcg_temp_new_i64();
2268 TCGv_i64 c1 = tcg_temp_new_i64();
2269 TCGv_i64 c2 = tcg_temp_new_i64();
2270 TCGv_i64 zero = tcg_const_i64(0);
2272 /* Load the two words, in memory order. */
2273 tcg_gen_qemu_ld_i64(d1, addr, memidx,
2274 MO_64 | MO_ALIGN_16 | s->be_data);
2275 tcg_gen_addi_i64(a2, addr, 8);
2276 tcg_gen_qemu_ld_i64(d2, addr, memidx, MO_64 | s->be_data);
2278 /* Compare the two words, also in memory order. */
2279 tcg_gen_setcond_i64(TCG_COND_EQ, c1, d1, s1);
2280 tcg_gen_setcond_i64(TCG_COND_EQ, c2, d2, s2);
2281 tcg_gen_and_i64(c2, c2, c1);
2283 /* If compare equal, write back new data, else write back old data. */
2284 tcg_gen_movcond_i64(TCG_COND_NE, c1, c2, zero, t1, d1);
2285 tcg_gen_movcond_i64(TCG_COND_NE, c2, c2, zero, t2, d2);
2286 tcg_gen_qemu_st_i64(c1, addr, memidx, MO_64 | s->be_data);
2287 tcg_gen_qemu_st_i64(c2, a2, memidx, MO_64 | s->be_data);
2288 tcg_temp_free_i64(a2);
2289 tcg_temp_free_i64(c1);
2290 tcg_temp_free_i64(c2);
2291 tcg_temp_free_i64(zero);
2293 /* Write back the data from memory to Rs. */
2294 tcg_gen_mov_i64(s1, d1);
2295 tcg_gen_mov_i64(s2, d2);
2296 tcg_temp_free_i64(d1);
2297 tcg_temp_free_i64(d2);
2301 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2302 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2304 static bool disas_ldst_compute_iss_sf(int size, bool is_signed, int opc)
2306 int opc0 = extract32(opc, 0, 1);
2310 regsize = opc0 ? 32 : 64;
2312 regsize = size == 3 ? 64 : 32;
2314 return regsize == 64;
2317 /* Load/store exclusive
2319 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2320 * +-----+-------------+----+---+----+------+----+-------+------+------+
2321 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2322 * +-----+-------------+----+---+----+------+----+-------+------+------+
2324 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2325 * L: 0 -> store, 1 -> load
2326 * o2: 0 -> exclusive, 1 -> not
2327 * o1: 0 -> single register, 1 -> register pair
2328 * o0: 1 -> load-acquire/store-release, 0 -> not
2330 static void disas_ldst_excl(DisasContext *s, uint32_t insn)
2332 int rt = extract32(insn, 0, 5);
2333 int rn = extract32(insn, 5, 5);
2334 int rt2 = extract32(insn, 10, 5);
2335 int rs = extract32(insn, 16, 5);
2336 int is_lasr = extract32(insn, 15, 1);
2337 int o2_L_o1_o0 = extract32(insn, 21, 3) * 2 | is_lasr;
2338 int size = extract32(insn, 30, 2);
2341 switch (o2_L_o1_o0) {
2342 case 0x0: /* STXR */
2343 case 0x1: /* STLXR */
2345 gen_check_sp_alignment(s);
2348 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
2350 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2351 gen_store_exclusive(s, rs, rt, rt2, tcg_addr, size, false);
2354 case 0x4: /* LDXR */
2355 case 0x5: /* LDAXR */
2357 gen_check_sp_alignment(s);
2359 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2361 gen_load_exclusive(s, rt, rt2, tcg_addr, size, false);
2363 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
2367 case 0x8: /* STLLR */
2368 if (!dc_isar_feature(aa64_lor, s)) {
2371 /* StoreLORelease is the same as Store-Release for QEMU. */
2373 case 0x9: /* STLR */
2374 /* Generate ISS for non-exclusive accesses including LASR. */
2376 gen_check_sp_alignment(s);
2378 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
2379 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2380 do_gpr_st(s, cpu_reg(s, rt), tcg_addr, size, true, rt,
2381 disas_ldst_compute_iss_sf(size, false, 0), is_lasr);
2384 case 0xc: /* LDLAR */
2385 if (!dc_isar_feature(aa64_lor, s)) {
2388 /* LoadLOAcquire is the same as Load-Acquire for QEMU. */
2390 case 0xd: /* LDAR */
2391 /* Generate ISS for non-exclusive accesses including LASR. */
2393 gen_check_sp_alignment(s);
2395 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2396 do_gpr_ld(s, cpu_reg(s, rt), tcg_addr, size, false, false, true, rt,
2397 disas_ldst_compute_iss_sf(size, false, 0), is_lasr);
2398 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
2401 case 0x2: case 0x3: /* CASP / STXP */
2402 if (size & 2) { /* STXP / STLXP */
2404 gen_check_sp_alignment(s);
2407 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL);
2409 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2410 gen_store_exclusive(s, rs, rt, rt2, tcg_addr, size, true);
2414 && ((rt | rs) & 1) == 0
2415 && dc_isar_feature(aa64_atomics, s)) {
2417 gen_compare_and_swap_pair(s, rs, rt, rn, size | 2);
2422 case 0x6: case 0x7: /* CASPA / LDXP */
2423 if (size & 2) { /* LDXP / LDAXP */
2425 gen_check_sp_alignment(s);
2427 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2429 gen_load_exclusive(s, rt, rt2, tcg_addr, size, true);
2431 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ);
2436 && ((rt | rs) & 1) == 0
2437 && dc_isar_feature(aa64_atomics, s)) {
2438 /* CASPA / CASPAL */
2439 gen_compare_and_swap_pair(s, rs, rt, rn, size | 2);
2445 case 0xb: /* CASL */
2446 case 0xe: /* CASA */
2447 case 0xf: /* CASAL */
2448 if (rt2 == 31 && dc_isar_feature(aa64_atomics, s)) {
2449 gen_compare_and_swap(s, rs, rt, rn, size);
2454 unallocated_encoding(s);
2458 * Load register (literal)
2460 * 31 30 29 27 26 25 24 23 5 4 0
2461 * +-----+-------+---+-----+-------------------+-------+
2462 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2463 * +-----+-------+---+-----+-------------------+-------+
2465 * V: 1 -> vector (simd/fp)
2466 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2467 * 10-> 32 bit signed, 11 -> prefetch
2468 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2470 static void disas_ld_lit(DisasContext *s, uint32_t insn)
2472 int rt = extract32(insn, 0, 5);
2473 int64_t imm = sextract32(insn, 5, 19) << 2;
2474 bool is_vector = extract32(insn, 26, 1);
2475 int opc = extract32(insn, 30, 2);
2476 bool is_signed = false;
2478 TCGv_i64 tcg_rt, tcg_addr;
2482 unallocated_encoding(s);
2486 if (!fp_access_check(s)) {
2491 /* PRFM (literal) : prefetch */
2494 size = 2 + extract32(opc, 0, 1);
2495 is_signed = extract32(opc, 1, 1);
2498 tcg_rt = cpu_reg(s, rt);
2500 tcg_addr = tcg_const_i64((s->pc - 4) + imm);
2502 do_fp_ld(s, rt, tcg_addr, size);
2504 /* Only unsigned 32bit loads target 32bit registers. */
2505 bool iss_sf = opc != 0;
2507 do_gpr_ld(s, tcg_rt, tcg_addr, size, is_signed, false,
2508 true, rt, iss_sf, false);
2510 tcg_temp_free_i64(tcg_addr);
2514 * LDNP (Load Pair - non-temporal hint)
2515 * LDP (Load Pair - non vector)
2516 * LDPSW (Load Pair Signed Word - non vector)
2517 * STNP (Store Pair - non-temporal hint)
2518 * STP (Store Pair - non vector)
2519 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2520 * LDP (Load Pair of SIMD&FP)
2521 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2522 * STP (Store Pair of SIMD&FP)
2524 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2525 * +-----+-------+---+---+-------+---+-----------------------------+
2526 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2527 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2529 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2531 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2532 * V: 0 -> GPR, 1 -> Vector
2533 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2534 * 10 -> signed offset, 11 -> pre-index
2535 * L: 0 -> Store 1 -> Load
2537 * Rt, Rt2 = GPR or SIMD registers to be stored
2538 * Rn = general purpose register containing address
2539 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2541 static void disas_ldst_pair(DisasContext *s, uint32_t insn)
2543 int rt = extract32(insn, 0, 5);
2544 int rn = extract32(insn, 5, 5);
2545 int rt2 = extract32(insn, 10, 5);
2546 uint64_t offset = sextract64(insn, 15, 7);
2547 int index = extract32(insn, 23, 2);
2548 bool is_vector = extract32(insn, 26, 1);
2549 bool is_load = extract32(insn, 22, 1);
2550 int opc = extract32(insn, 30, 2);
2552 bool is_signed = false;
2553 bool postindex = false;
2556 TCGv_i64 tcg_addr; /* calculated address */
2560 unallocated_encoding(s);
2567 size = 2 + extract32(opc, 1, 1);
2568 is_signed = extract32(opc, 0, 1);
2569 if (!is_load && is_signed) {
2570 unallocated_encoding(s);
2576 case 1: /* post-index */
2581 /* signed offset with "non-temporal" hint. Since we don't emulate
2582 * caches we don't care about hints to the cache system about
2583 * data access patterns, and handle this identically to plain
2587 /* There is no non-temporal-hint version of LDPSW */
2588 unallocated_encoding(s);
2593 case 2: /* signed offset, rn not updated */
2596 case 3: /* pre-index */
2602 if (is_vector && !fp_access_check(s)) {
2609 gen_check_sp_alignment(s);
2612 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2615 tcg_gen_addi_i64(tcg_addr, tcg_addr, offset);
2620 do_fp_ld(s, rt, tcg_addr, size);
2622 do_fp_st(s, rt, tcg_addr, size);
2624 tcg_gen_addi_i64(tcg_addr, tcg_addr, 1 << size);
2626 do_fp_ld(s, rt2, tcg_addr, size);
2628 do_fp_st(s, rt2, tcg_addr, size);
2631 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2632 TCGv_i64 tcg_rt2 = cpu_reg(s, rt2);
2635 TCGv_i64 tmp = tcg_temp_new_i64();
2637 /* Do not modify tcg_rt before recognizing any exception
2638 * from the second load.
2640 do_gpr_ld(s, tmp, tcg_addr, size, is_signed, false,
2641 false, 0, false, false);
2642 tcg_gen_addi_i64(tcg_addr, tcg_addr, 1 << size);
2643 do_gpr_ld(s, tcg_rt2, tcg_addr, size, is_signed, false,
2644 false, 0, false, false);
2646 tcg_gen_mov_i64(tcg_rt, tmp);
2647 tcg_temp_free_i64(tmp);
2649 do_gpr_st(s, tcg_rt, tcg_addr, size,
2650 false, 0, false, false);
2651 tcg_gen_addi_i64(tcg_addr, tcg_addr, 1 << size);
2652 do_gpr_st(s, tcg_rt2, tcg_addr, size,
2653 false, 0, false, false);
2659 tcg_gen_addi_i64(tcg_addr, tcg_addr, offset - (1 << size));
2661 tcg_gen_subi_i64(tcg_addr, tcg_addr, 1 << size);
2663 tcg_gen_mov_i64(cpu_reg_sp(s, rn), tcg_addr);
2668 * Load/store (immediate post-indexed)
2669 * Load/store (immediate pre-indexed)
2670 * Load/store (unscaled immediate)
2672 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2673 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2674 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2675 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2677 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2679 * V = 0 -> non-vector
2680 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2681 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2683 static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn,
2689 int rn = extract32(insn, 5, 5);
2690 int imm9 = sextract32(insn, 12, 9);
2691 int idx = extract32(insn, 10, 2);
2692 bool is_signed = false;
2693 bool is_store = false;
2694 bool is_extended = false;
2695 bool is_unpriv = (idx == 2);
2696 bool iss_valid = !is_vector;
2703 size |= (opc & 2) << 1;
2704 if (size > 4 || is_unpriv) {
2705 unallocated_encoding(s);
2708 is_store = ((opc & 1) == 0);
2709 if (!fp_access_check(s)) {
2713 if (size == 3 && opc == 2) {
2714 /* PRFM - prefetch */
2716 unallocated_encoding(s);
2721 if (opc == 3 && size > 1) {
2722 unallocated_encoding(s);
2725 is_store = (opc == 0);
2726 is_signed = extract32(opc, 1, 1);
2727 is_extended = (size < 3) && extract32(opc, 0, 1);
2745 g_assert_not_reached();
2749 gen_check_sp_alignment(s);
2751 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2754 tcg_gen_addi_i64(tcg_addr, tcg_addr, imm9);
2759 do_fp_st(s, rt, tcg_addr, size);
2761 do_fp_ld(s, rt, tcg_addr, size);
2764 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2765 int memidx = is_unpriv ? get_a64_user_mem_index(s) : get_mem_index(s);
2766 bool iss_sf = disas_ldst_compute_iss_sf(size, is_signed, opc);
2769 do_gpr_st_memidx(s, tcg_rt, tcg_addr, size, memidx,
2770 iss_valid, rt, iss_sf, false);
2772 do_gpr_ld_memidx(s, tcg_rt, tcg_addr, size,
2773 is_signed, is_extended, memidx,
2774 iss_valid, rt, iss_sf, false);
2779 TCGv_i64 tcg_rn = cpu_reg_sp(s, rn);
2781 tcg_gen_addi_i64(tcg_addr, tcg_addr, imm9);
2783 tcg_gen_mov_i64(tcg_rn, tcg_addr);
2788 * Load/store (register offset)
2790 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2791 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2792 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2793 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2796 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2797 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2799 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2800 * opc<0>: 0 -> store, 1 -> load
2801 * V: 1 -> vector/simd
2802 * opt: extend encoding (see DecodeRegExtend)
2803 * S: if S=1 then scale (essentially index by sizeof(size))
2804 * Rt: register to transfer into/out of
2805 * Rn: address register or SP for base
2806 * Rm: offset register or ZR for offset
2808 static void disas_ldst_reg_roffset(DisasContext *s, uint32_t insn,
2814 int rn = extract32(insn, 5, 5);
2815 int shift = extract32(insn, 12, 1);
2816 int rm = extract32(insn, 16, 5);
2817 int opt = extract32(insn, 13, 3);
2818 bool is_signed = false;
2819 bool is_store = false;
2820 bool is_extended = false;
2825 if (extract32(opt, 1, 1) == 0) {
2826 unallocated_encoding(s);
2831 size |= (opc & 2) << 1;
2833 unallocated_encoding(s);
2836 is_store = !extract32(opc, 0, 1);
2837 if (!fp_access_check(s)) {
2841 if (size == 3 && opc == 2) {
2842 /* PRFM - prefetch */
2845 if (opc == 3 && size > 1) {
2846 unallocated_encoding(s);
2849 is_store = (opc == 0);
2850 is_signed = extract32(opc, 1, 1);
2851 is_extended = (size < 3) && extract32(opc, 0, 1);
2855 gen_check_sp_alignment(s);
2857 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2859 tcg_rm = read_cpu_reg(s, rm, 1);
2860 ext_and_shift_reg(tcg_rm, tcg_rm, opt, shift ? size : 0);
2862 tcg_gen_add_i64(tcg_addr, tcg_addr, tcg_rm);
2866 do_fp_st(s, rt, tcg_addr, size);
2868 do_fp_ld(s, rt, tcg_addr, size);
2871 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2872 bool iss_sf = disas_ldst_compute_iss_sf(size, is_signed, opc);
2874 do_gpr_st(s, tcg_rt, tcg_addr, size,
2875 true, rt, iss_sf, false);
2877 do_gpr_ld(s, tcg_rt, tcg_addr, size,
2878 is_signed, is_extended,
2879 true, rt, iss_sf, false);
2885 * Load/store (unsigned immediate)
2887 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2888 * +----+-------+---+-----+-----+------------+-------+------+
2889 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2890 * +----+-------+---+-----+-----+------------+-------+------+
2893 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2894 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2896 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2897 * opc<0>: 0 -> store, 1 -> load
2898 * Rn: base address register (inc SP)
2899 * Rt: target register
2901 static void disas_ldst_reg_unsigned_imm(DisasContext *s, uint32_t insn,
2907 int rn = extract32(insn, 5, 5);
2908 unsigned int imm12 = extract32(insn, 10, 12);
2909 unsigned int offset;
2914 bool is_signed = false;
2915 bool is_extended = false;
2918 size |= (opc & 2) << 1;
2920 unallocated_encoding(s);
2923 is_store = !extract32(opc, 0, 1);
2924 if (!fp_access_check(s)) {
2928 if (size == 3 && opc == 2) {
2929 /* PRFM - prefetch */
2932 if (opc == 3 && size > 1) {
2933 unallocated_encoding(s);
2936 is_store = (opc == 0);
2937 is_signed = extract32(opc, 1, 1);
2938 is_extended = (size < 3) && extract32(opc, 0, 1);
2942 gen_check_sp_alignment(s);
2944 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2945 offset = imm12 << size;
2946 tcg_gen_addi_i64(tcg_addr, tcg_addr, offset);
2950 do_fp_st(s, rt, tcg_addr, size);
2952 do_fp_ld(s, rt, tcg_addr, size);
2955 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2956 bool iss_sf = disas_ldst_compute_iss_sf(size, is_signed, opc);
2958 do_gpr_st(s, tcg_rt, tcg_addr, size,
2959 true, rt, iss_sf, false);
2961 do_gpr_ld(s, tcg_rt, tcg_addr, size, is_signed, is_extended,
2962 true, rt, iss_sf, false);
2967 /* Atomic memory operations
2969 * 31 30 27 26 24 22 21 16 15 12 10 5 0
2970 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
2971 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
2972 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
2974 * Rt: the result register
2975 * Rn: base address or SP
2976 * Rs: the source register for the operation
2977 * V: vector flag (always 0 as of v8.3)
2981 static void disas_ldst_atomic(DisasContext *s, uint32_t insn,
2982 int size, int rt, bool is_vector)
2984 int rs = extract32(insn, 16, 5);
2985 int rn = extract32(insn, 5, 5);
2986 int o3_opc = extract32(insn, 12, 4);
2987 TCGv_i64 tcg_rn, tcg_rs;
2988 AtomicThreeOpFn *fn;
2990 if (is_vector || !dc_isar_feature(aa64_atomics, s)) {
2991 unallocated_encoding(s);
2995 case 000: /* LDADD */
2996 fn = tcg_gen_atomic_fetch_add_i64;
2998 case 001: /* LDCLR */
2999 fn = tcg_gen_atomic_fetch_and_i64;
3001 case 002: /* LDEOR */
3002 fn = tcg_gen_atomic_fetch_xor_i64;
3004 case 003: /* LDSET */
3005 fn = tcg_gen_atomic_fetch_or_i64;
3007 case 004: /* LDSMAX */
3008 fn = tcg_gen_atomic_fetch_smax_i64;
3010 case 005: /* LDSMIN */
3011 fn = tcg_gen_atomic_fetch_smin_i64;
3013 case 006: /* LDUMAX */
3014 fn = tcg_gen_atomic_fetch_umax_i64;
3016 case 007: /* LDUMIN */
3017 fn = tcg_gen_atomic_fetch_umin_i64;
3020 fn = tcg_gen_atomic_xchg_i64;
3023 unallocated_encoding(s);
3028 gen_check_sp_alignment(s);
3030 tcg_rn = cpu_reg_sp(s, rn);
3031 tcg_rs = read_cpu_reg(s, rs, true);
3033 if (o3_opc == 1) { /* LDCLR */
3034 tcg_gen_not_i64(tcg_rs, tcg_rs);
3037 /* The tcg atomic primitives are all full barriers. Therefore we
3038 * can ignore the Acquire and Release bits of this instruction.
3040 fn(cpu_reg(s, rt), tcg_rn, tcg_rs, get_mem_index(s),
3041 s->be_data | size | MO_ALIGN);
3044 /* Load/store register (all forms) */
3045 static void disas_ldst_reg(DisasContext *s, uint32_t insn)
3047 int rt = extract32(insn, 0, 5);
3048 int opc = extract32(insn, 22, 2);
3049 bool is_vector = extract32(insn, 26, 1);
3050 int size = extract32(insn, 30, 2);
3052 switch (extract32(insn, 24, 2)) {
3054 if (extract32(insn, 21, 1) == 0) {
3055 /* Load/store register (unscaled immediate)
3056 * Load/store immediate pre/post-indexed
3057 * Load/store register unprivileged
3059 disas_ldst_reg_imm9(s, insn, opc, size, rt, is_vector);
3062 switch (extract32(insn, 10, 2)) {
3064 disas_ldst_atomic(s, insn, size, rt, is_vector);
3067 disas_ldst_reg_roffset(s, insn, opc, size, rt, is_vector);
3072 disas_ldst_reg_unsigned_imm(s, insn, opc, size, rt, is_vector);
3075 unallocated_encoding(s);
3078 /* AdvSIMD load/store multiple structures
3080 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
3081 * +---+---+---------------+---+-------------+--------+------+------+------+
3082 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
3083 * +---+---+---------------+---+-------------+--------+------+------+------+
3085 * AdvSIMD load/store multiple structures (post-indexed)
3087 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
3088 * +---+---+---------------+---+---+---------+--------+------+------+------+
3089 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
3090 * +---+---+---------------+---+---+---------+--------+------+------+------+
3092 * Rt: first (or only) SIMD&FP register to be transferred
3093 * Rn: base address or SP
3094 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3096 static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)
3098 int rt = extract32(insn, 0, 5);
3099 int rn = extract32(insn, 5, 5);
3100 int size = extract32(insn, 10, 2);
3101 int opcode = extract32(insn, 12, 4);
3102 bool is_store = !extract32(insn, 22, 1);
3103 bool is_postidx = extract32(insn, 23, 1);
3104 bool is_q = extract32(insn, 30, 1);
3105 TCGv_i64 tcg_addr, tcg_rn, tcg_ebytes;
3106 TCGMemOp endian = s->be_data;
3108 int ebytes; /* bytes per element */
3109 int elements; /* elements per vector */
3110 int rpt; /* num iterations */
3111 int selem; /* structure elements */
3114 if (extract32(insn, 31, 1) || extract32(insn, 21, 1)) {
3115 unallocated_encoding(s);
3119 /* From the shared decode logic */
3150 unallocated_encoding(s);
3154 if (size == 3 && !is_q && selem != 1) {
3156 unallocated_encoding(s);
3160 if (!fp_access_check(s)) {
3165 gen_check_sp_alignment(s);
3168 /* For our purposes, bytes are always little-endian. */
3173 /* Consecutive little-endian elements from a single register
3174 * can be promoted to a larger little-endian operation.
3176 if (selem == 1 && endian == MO_LE) {
3180 elements = (is_q ? 16 : 8) / ebytes;
3182 tcg_rn = cpu_reg_sp(s, rn);
3183 tcg_addr = tcg_temp_new_i64();
3184 tcg_gen_mov_i64(tcg_addr, tcg_rn);
3185 tcg_ebytes = tcg_const_i64(ebytes);
3187 for (r = 0; r < rpt; r++) {
3189 for (e = 0; e < elements; e++) {
3191 for (xs = 0; xs < selem; xs++) {
3192 int tt = (rt + r + xs) % 32;
3194 do_vec_st(s, tt, e, tcg_addr, size, endian);
3196 do_vec_ld(s, tt, e, tcg_addr, size, endian);
3198 tcg_gen_add_i64(tcg_addr, tcg_addr, tcg_ebytes);
3204 /* For non-quad operations, setting a slice of the low
3205 * 64 bits of the register clears the high 64 bits (in
3206 * the ARM ARM pseudocode this is implicit in the fact
3207 * that 'rval' is a 64 bit wide variable).
3208 * For quad operations, we might still need to zero the
3211 for (r = 0; r < rpt * selem; r++) {
3212 int tt = (rt + r) % 32;
3213 clear_vec_high(s, is_q, tt);
3218 int rm = extract32(insn, 16, 5);
3220 tcg_gen_mov_i64(tcg_rn, tcg_addr);
3222 tcg_gen_add_i64(tcg_rn, tcg_rn, cpu_reg(s, rm));
3225 tcg_temp_free_i64(tcg_ebytes);
3226 tcg_temp_free_i64(tcg_addr);
3229 /* AdvSIMD load/store single structure
3231 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3232 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3233 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3234 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3236 * AdvSIMD load/store single structure (post-indexed)
3238 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3239 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3240 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3241 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3243 * Rt: first (or only) SIMD&FP register to be transferred
3244 * Rn: base address or SP
3245 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3246 * index = encoded in Q:S:size dependent on size
3248 * lane_size = encoded in R, opc
3249 * transfer width = encoded in opc, S, size
3251 static void disas_ldst_single_struct(DisasContext *s, uint32_t insn)
3253 int rt = extract32(insn, 0, 5);
3254 int rn = extract32(insn, 5, 5);
3255 int size = extract32(insn, 10, 2);
3256 int S = extract32(insn, 12, 1);
3257 int opc = extract32(insn, 13, 3);
3258 int R = extract32(insn, 21, 1);
3259 int is_load = extract32(insn, 22, 1);
3260 int is_postidx = extract32(insn, 23, 1);
3261 int is_q = extract32(insn, 30, 1);
3263 int scale = extract32(opc, 1, 2);
3264 int selem = (extract32(opc, 0, 1) << 1 | R) + 1;
3265 bool replicate = false;
3266 int index = is_q << 3 | S << 2 | size;
3268 TCGv_i64 tcg_addr, tcg_rn, tcg_ebytes;
3272 if (!is_load || S) {
3273 unallocated_encoding(s);
3282 if (extract32(size, 0, 1)) {
3283 unallocated_encoding(s);
3289 if (extract32(size, 1, 1)) {
3290 unallocated_encoding(s);
3293 if (!extract32(size, 0, 1)) {
3297 unallocated_encoding(s);
3305 g_assert_not_reached();
3308 if (!fp_access_check(s)) {
3312 ebytes = 1 << scale;
3315 gen_check_sp_alignment(s);
3318 tcg_rn = cpu_reg_sp(s, rn);
3319 tcg_addr = tcg_temp_new_i64();
3320 tcg_gen_mov_i64(tcg_addr, tcg_rn);
3321 tcg_ebytes = tcg_const_i64(ebytes);
3323 for (xs = 0; xs < selem; xs++) {
3325 /* Load and replicate to all elements */
3326 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
3328 tcg_gen_qemu_ld_i64(tcg_tmp, tcg_addr,
3329 get_mem_index(s), s->be_data + scale);
3330 tcg_gen_gvec_dup_i64(scale, vec_full_reg_offset(s, rt),
3331 (is_q + 1) * 8, vec_full_reg_size(s),
3333 tcg_temp_free_i64(tcg_tmp);
3335 /* Load/store one element per register */
3337 do_vec_ld(s, rt, index, tcg_addr, scale, s->be_data);
3339 do_vec_st(s, rt, index, tcg_addr, scale, s->be_data);
3342 tcg_gen_add_i64(tcg_addr, tcg_addr, tcg_ebytes);
3347 int rm = extract32(insn, 16, 5);
3349 tcg_gen_mov_i64(tcg_rn, tcg_addr);
3351 tcg_gen_add_i64(tcg_rn, tcg_rn, cpu_reg(s, rm));
3354 tcg_temp_free_i64(tcg_ebytes);
3355 tcg_temp_free_i64(tcg_addr);
3358 /* Loads and stores */
3359 static void disas_ldst(DisasContext *s, uint32_t insn)
3361 switch (extract32(insn, 24, 6)) {
3362 case 0x08: /* Load/store exclusive */
3363 disas_ldst_excl(s, insn);
3365 case 0x18: case 0x1c: /* Load register (literal) */
3366 disas_ld_lit(s, insn);
3368 case 0x28: case 0x29:
3369 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
3370 disas_ldst_pair(s, insn);
3372 case 0x38: case 0x39:
3373 case 0x3c: case 0x3d: /* Load/store register (all forms) */
3374 disas_ldst_reg(s, insn);
3376 case 0x0c: /* AdvSIMD load/store multiple structures */
3377 disas_ldst_multiple_struct(s, insn);
3379 case 0x0d: /* AdvSIMD load/store single structure */
3380 disas_ldst_single_struct(s, insn);
3383 unallocated_encoding(s);
3388 /* PC-rel. addressing
3389 * 31 30 29 28 24 23 5 4 0
3390 * +----+-------+-----------+-------------------+------+
3391 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
3392 * +----+-------+-----------+-------------------+------+
3394 static void disas_pc_rel_adr(DisasContext *s, uint32_t insn)
3396 unsigned int page, rd;
3400 page = extract32(insn, 31, 1);
3401 /* SignExtend(immhi:immlo) -> offset */
3402 offset = sextract64(insn, 5, 19);
3403 offset = offset << 2 | extract32(insn, 29, 2);
3404 rd = extract32(insn, 0, 5);
3408 /* ADRP (page based) */
3413 tcg_gen_movi_i64(cpu_reg(s, rd), base + offset);
3417 * Add/subtract (immediate)
3419 * 31 30 29 28 24 23 22 21 10 9 5 4 0
3420 * +--+--+--+-----------+-----+-------------+-----+-----+
3421 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
3422 * +--+--+--+-----------+-----+-------------+-----+-----+
3424 * sf: 0 -> 32bit, 1 -> 64bit
3425 * op: 0 -> add , 1 -> sub
3427 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
3429 static void disas_add_sub_imm(DisasContext *s, uint32_t insn)
3431 int rd = extract32(insn, 0, 5);
3432 int rn = extract32(insn, 5, 5);
3433 uint64_t imm = extract32(insn, 10, 12);
3434 int shift = extract32(insn, 22, 2);
3435 bool setflags = extract32(insn, 29, 1);
3436 bool sub_op = extract32(insn, 30, 1);
3437 bool is_64bit = extract32(insn, 31, 1);
3439 TCGv_i64 tcg_rn = cpu_reg_sp(s, rn);
3440 TCGv_i64 tcg_rd = setflags ? cpu_reg(s, rd) : cpu_reg_sp(s, rd);
3441 TCGv_i64 tcg_result;
3450 unallocated_encoding(s);
3454 tcg_result = tcg_temp_new_i64();
3457 tcg_gen_subi_i64(tcg_result, tcg_rn, imm);
3459 tcg_gen_addi_i64(tcg_result, tcg_rn, imm);
3462 TCGv_i64 tcg_imm = tcg_const_i64(imm);
3464 gen_sub_CC(is_64bit, tcg_result, tcg_rn, tcg_imm);
3466 gen_add_CC(is_64bit, tcg_result, tcg_rn, tcg_imm);
3468 tcg_temp_free_i64(tcg_imm);
3472 tcg_gen_mov_i64(tcg_rd, tcg_result);
3474 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
3477 tcg_temp_free_i64(tcg_result);
3480 /* The input should be a value in the bottom e bits (with higher
3481 * bits zero); returns that value replicated into every element
3482 * of size e in a 64 bit integer.
3484 static uint64_t bitfield_replicate(uint64_t mask, unsigned int e)
3494 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
3495 static inline uint64_t bitmask64(unsigned int length)
3497 assert(length > 0 && length <= 64);
3498 return ~0ULL >> (64 - length);
3501 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
3502 * only require the wmask. Returns false if the imms/immr/immn are a reserved
3503 * value (ie should cause a guest UNDEF exception), and true if they are
3504 * valid, in which case the decoded bit pattern is written to result.
3506 bool logic_imm_decode_wmask(uint64_t *result, unsigned int immn,
3507 unsigned int imms, unsigned int immr)
3510 unsigned e, levels, s, r;
3513 assert(immn < 2 && imms < 64 && immr < 64);
3515 /* The bit patterns we create here are 64 bit patterns which
3516 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
3517 * 64 bits each. Each element contains the same value: a run
3518 * of between 1 and e-1 non-zero bits, rotated within the
3519 * element by between 0 and e-1 bits.
3521 * The element size and run length are encoded into immn (1 bit)
3522 * and imms (6 bits) as follows:
3523 * 64 bit elements: immn = 1, imms = <length of run - 1>
3524 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
3525 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
3526 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
3527 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
3528 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
3529 * Notice that immn = 0, imms = 11111x is the only combination
3530 * not covered by one of the above options; this is reserved.
3531 * Further, <length of run - 1> all-ones is a reserved pattern.
3533 * In all cases the rotation is by immr % e (and immr is 6 bits).
3536 /* First determine the element size */
3537 len = 31 - clz32((immn << 6) | (~imms & 0x3f));
3539 /* This is the immn == 0, imms == 0x11111x case */
3549 /* <length of run - 1> mustn't be all-ones. */
3553 /* Create the value of one element: s+1 set bits rotated
3554 * by r within the element (which is e bits wide)...
3556 mask = bitmask64(s + 1);
3558 mask = (mask >> r) | (mask << (e - r));
3559 mask &= bitmask64(e);
3561 /* ...then replicate the element over the whole 64 bit value */
3562 mask = bitfield_replicate(mask, e);
3567 /* Logical (immediate)
3568 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3569 * +----+-----+-------------+---+------+------+------+------+
3570 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
3571 * +----+-----+-------------+---+------+------+------+------+
3573 static void disas_logic_imm(DisasContext *s, uint32_t insn)
3575 unsigned int sf, opc, is_n, immr, imms, rn, rd;
3576 TCGv_i64 tcg_rd, tcg_rn;
3578 bool is_and = false;
3580 sf = extract32(insn, 31, 1);
3581 opc = extract32(insn, 29, 2);
3582 is_n = extract32(insn, 22, 1);
3583 immr = extract32(insn, 16, 6);
3584 imms = extract32(insn, 10, 6);
3585 rn = extract32(insn, 5, 5);
3586 rd = extract32(insn, 0, 5);
3589 unallocated_encoding(s);
3593 if (opc == 0x3) { /* ANDS */
3594 tcg_rd = cpu_reg(s, rd);
3596 tcg_rd = cpu_reg_sp(s, rd);
3598 tcg_rn = cpu_reg(s, rn);
3600 if (!logic_imm_decode_wmask(&wmask, is_n, imms, immr)) {
3601 /* some immediate field values are reserved */
3602 unallocated_encoding(s);
3607 wmask &= 0xffffffff;
3611 case 0x3: /* ANDS */
3613 tcg_gen_andi_i64(tcg_rd, tcg_rn, wmask);
3617 tcg_gen_ori_i64(tcg_rd, tcg_rn, wmask);
3620 tcg_gen_xori_i64(tcg_rd, tcg_rn, wmask);
3623 assert(FALSE); /* must handle all above */
3627 if (!sf && !is_and) {
3628 /* zero extend final result; we know we can skip this for AND
3629 * since the immediate had the high 32 bits clear.
3631 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3634 if (opc == 3) { /* ANDS */
3635 gen_logic_CC(sf, tcg_rd);
3640 * Move wide (immediate)
3642 * 31 30 29 28 23 22 21 20 5 4 0
3643 * +--+-----+-------------+-----+----------------+------+
3644 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
3645 * +--+-----+-------------+-----+----------------+------+
3647 * sf: 0 -> 32 bit, 1 -> 64 bit
3648 * opc: 00 -> N, 10 -> Z, 11 -> K
3649 * hw: shift/16 (0,16, and sf only 32, 48)
3651 static void disas_movw_imm(DisasContext *s, uint32_t insn)
3653 int rd = extract32(insn, 0, 5);
3654 uint64_t imm = extract32(insn, 5, 16);
3655 int sf = extract32(insn, 31, 1);
3656 int opc = extract32(insn, 29, 2);
3657 int pos = extract32(insn, 21, 2) << 4;
3658 TCGv_i64 tcg_rd = cpu_reg(s, rd);
3661 if (!sf && (pos >= 32)) {
3662 unallocated_encoding(s);
3676 tcg_gen_movi_i64(tcg_rd, imm);
3679 tcg_imm = tcg_const_i64(imm);
3680 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_imm, pos, 16);
3681 tcg_temp_free_i64(tcg_imm);
3683 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3687 unallocated_encoding(s);
3693 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3694 * +----+-----+-------------+---+------+------+------+------+
3695 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3696 * +----+-----+-------------+---+------+------+------+------+
3698 static void disas_bitfield(DisasContext *s, uint32_t insn)
3700 unsigned int sf, n, opc, ri, si, rn, rd, bitsize, pos, len;
3701 TCGv_i64 tcg_rd, tcg_tmp;
3703 sf = extract32(insn, 31, 1);
3704 opc = extract32(insn, 29, 2);
3705 n = extract32(insn, 22, 1);
3706 ri = extract32(insn, 16, 6);
3707 si = extract32(insn, 10, 6);
3708 rn = extract32(insn, 5, 5);
3709 rd = extract32(insn, 0, 5);
3710 bitsize = sf ? 64 : 32;
3712 if (sf != n || ri >= bitsize || si >= bitsize || opc > 2) {
3713 unallocated_encoding(s);
3717 tcg_rd = cpu_reg(s, rd);
3719 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3720 to be smaller than bitsize, we'll never reference data outside the
3721 low 32-bits anyway. */
3722 tcg_tmp = read_cpu_reg(s, rn, 1);
3724 /* Recognize simple(r) extractions. */
3726 /* Wd<s-r:0> = Wn<s:r> */
3727 len = (si - ri) + 1;
3728 if (opc == 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
3729 tcg_gen_sextract_i64(tcg_rd, tcg_tmp, ri, len);
3731 } else if (opc == 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
3732 tcg_gen_extract_i64(tcg_rd, tcg_tmp, ri, len);
3735 /* opc == 1, BXFIL fall through to deposit */
3736 tcg_gen_extract_i64(tcg_tmp, tcg_tmp, ri, len);
3739 /* Handle the ri > si case with a deposit
3740 * Wd<32+s-r,32-r> = Wn<s:0>
3743 pos = (bitsize - ri) & (bitsize - 1);
3746 if (opc == 0 && len < ri) {
3747 /* SBFM: sign extend the destination field from len to fill
3748 the balance of the word. Let the deposit below insert all
3749 of those sign bits. */
3750 tcg_gen_sextract_i64(tcg_tmp, tcg_tmp, 0, len);
3754 if (opc == 1) { /* BFM, BXFIL */
3755 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_tmp, pos, len);
3757 /* SBFM or UBFM: We start with zero, and we haven't modified
3758 any bits outside bitsize, therefore the zero-extension
3759 below is unneeded. */
3760 tcg_gen_deposit_z_i64(tcg_rd, tcg_tmp, pos, len);
3765 if (!sf) { /* zero extend final result */
3766 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3771 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3772 * +----+------+-------------+---+----+------+--------+------+------+
3773 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3774 * +----+------+-------------+---+----+------+--------+------+------+
3776 static void disas_extract(DisasContext *s, uint32_t insn)
3778 unsigned int sf, n, rm, imm, rn, rd, bitsize, op21, op0;
3780 sf = extract32(insn, 31, 1);
3781 n = extract32(insn, 22, 1);
3782 rm = extract32(insn, 16, 5);
3783 imm = extract32(insn, 10, 6);
3784 rn = extract32(insn, 5, 5);
3785 rd = extract32(insn, 0, 5);
3786 op21 = extract32(insn, 29, 2);
3787 op0 = extract32(insn, 21, 1);
3788 bitsize = sf ? 64 : 32;
3790 if (sf != n || op21 || op0 || imm >= bitsize) {
3791 unallocated_encoding(s);
3793 TCGv_i64 tcg_rd, tcg_rm, tcg_rn;
3795 tcg_rd = cpu_reg(s, rd);
3797 if (unlikely(imm == 0)) {
3798 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3799 * so an extract from bit 0 is a special case.
3802 tcg_gen_mov_i64(tcg_rd, cpu_reg(s, rm));
3804 tcg_gen_ext32u_i64(tcg_rd, cpu_reg(s, rm));
3806 } else if (rm == rn) { /* ROR */
3807 tcg_rm = cpu_reg(s, rm);
3809 tcg_gen_rotri_i64(tcg_rd, tcg_rm, imm);
3811 TCGv_i32 tmp = tcg_temp_new_i32();
3812 tcg_gen_extrl_i64_i32(tmp, tcg_rm);
3813 tcg_gen_rotri_i32(tmp, tmp, imm);
3814 tcg_gen_extu_i32_i64(tcg_rd, tmp);
3815 tcg_temp_free_i32(tmp);
3818 tcg_rm = read_cpu_reg(s, rm, sf);
3819 tcg_rn = read_cpu_reg(s, rn, sf);
3820 tcg_gen_shri_i64(tcg_rm, tcg_rm, imm);
3821 tcg_gen_shli_i64(tcg_rn, tcg_rn, bitsize - imm);
3822 tcg_gen_or_i64(tcg_rd, tcg_rm, tcg_rn);
3824 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3830 /* Data processing - immediate */
3831 static void disas_data_proc_imm(DisasContext *s, uint32_t insn)
3833 switch (extract32(insn, 23, 6)) {
3834 case 0x20: case 0x21: /* PC-rel. addressing */
3835 disas_pc_rel_adr(s, insn);
3837 case 0x22: case 0x23: /* Add/subtract (immediate) */
3838 disas_add_sub_imm(s, insn);
3840 case 0x24: /* Logical (immediate) */
3841 disas_logic_imm(s, insn);
3843 case 0x25: /* Move wide (immediate) */
3844 disas_movw_imm(s, insn);
3846 case 0x26: /* Bitfield */
3847 disas_bitfield(s, insn);
3849 case 0x27: /* Extract */
3850 disas_extract(s, insn);
3853 unallocated_encoding(s);
3858 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3859 * Note that it is the caller's responsibility to ensure that the
3860 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3861 * mandated semantics for out of range shifts.
3863 static void shift_reg(TCGv_i64 dst, TCGv_i64 src, int sf,
3864 enum a64_shift_type shift_type, TCGv_i64 shift_amount)
3866 switch (shift_type) {
3867 case A64_SHIFT_TYPE_LSL:
3868 tcg_gen_shl_i64(dst, src, shift_amount);
3870 case A64_SHIFT_TYPE_LSR:
3871 tcg_gen_shr_i64(dst, src, shift_amount);
3873 case A64_SHIFT_TYPE_ASR:
3875 tcg_gen_ext32s_i64(dst, src);
3877 tcg_gen_sar_i64(dst, sf ? src : dst, shift_amount);
3879 case A64_SHIFT_TYPE_ROR:
3881 tcg_gen_rotr_i64(dst, src, shift_amount);
3884 t0 = tcg_temp_new_i32();
3885 t1 = tcg_temp_new_i32();
3886 tcg_gen_extrl_i64_i32(t0, src);
3887 tcg_gen_extrl_i64_i32(t1, shift_amount);
3888 tcg_gen_rotr_i32(t0, t0, t1);
3889 tcg_gen_extu_i32_i64(dst, t0);
3890 tcg_temp_free_i32(t0);
3891 tcg_temp_free_i32(t1);
3895 assert(FALSE); /* all shift types should be handled */
3899 if (!sf) { /* zero extend final result */
3900 tcg_gen_ext32u_i64(dst, dst);
3904 /* Shift a TCGv src by immediate, put result in dst.
3905 * The shift amount must be in range (this should always be true as the
3906 * relevant instructions will UNDEF on bad shift immediates).
3908 static void shift_reg_imm(TCGv_i64 dst, TCGv_i64 src, int sf,
3909 enum a64_shift_type shift_type, unsigned int shift_i)
3911 assert(shift_i < (sf ? 64 : 32));
3914 tcg_gen_mov_i64(dst, src);
3916 TCGv_i64 shift_const;
3918 shift_const = tcg_const_i64(shift_i);
3919 shift_reg(dst, src, sf, shift_type, shift_const);
3920 tcg_temp_free_i64(shift_const);
3924 /* Logical (shifted register)
3925 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3926 * +----+-----+-----------+-------+---+------+--------+------+------+
3927 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3928 * +----+-----+-----------+-------+---+------+--------+------+------+
3930 static void disas_logic_reg(DisasContext *s, uint32_t insn)
3932 TCGv_i64 tcg_rd, tcg_rn, tcg_rm;
3933 unsigned int sf, opc, shift_type, invert, rm, shift_amount, rn, rd;
3935 sf = extract32(insn, 31, 1);
3936 opc = extract32(insn, 29, 2);
3937 shift_type = extract32(insn, 22, 2);
3938 invert = extract32(insn, 21, 1);
3939 rm = extract32(insn, 16, 5);
3940 shift_amount = extract32(insn, 10, 6);
3941 rn = extract32(insn, 5, 5);
3942 rd = extract32(insn, 0, 5);
3944 if (!sf && (shift_amount & (1 << 5))) {
3945 unallocated_encoding(s);
3949 tcg_rd = cpu_reg(s, rd);
3951 if (opc == 1 && shift_amount == 0 && shift_type == 0 && rn == 31) {
3952 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3953 * register-register MOV and MVN, so it is worth special casing.
3955 tcg_rm = cpu_reg(s, rm);
3957 tcg_gen_not_i64(tcg_rd, tcg_rm);
3959 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3963 tcg_gen_mov_i64(tcg_rd, tcg_rm);
3965 tcg_gen_ext32u_i64(tcg_rd, tcg_rm);
3971 tcg_rm = read_cpu_reg(s, rm, sf);
3974 shift_reg_imm(tcg_rm, tcg_rm, sf, shift_type, shift_amount);
3977 tcg_rn = cpu_reg(s, rn);
3979 switch (opc | (invert << 2)) {
3982 tcg_gen_and_i64(tcg_rd, tcg_rn, tcg_rm);
3985 tcg_gen_or_i64(tcg_rd, tcg_rn, tcg_rm);
3988 tcg_gen_xor_i64(tcg_rd, tcg_rn, tcg_rm);
3992 tcg_gen_andc_i64(tcg_rd, tcg_rn, tcg_rm);
3995 tcg_gen_orc_i64(tcg_rd, tcg_rn, tcg_rm);
3998 tcg_gen_eqv_i64(tcg_rd, tcg_rn, tcg_rm);
4006 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
4010 gen_logic_CC(sf, tcg_rd);
4015 * Add/subtract (extended register)
4017 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
4018 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4019 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
4020 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4022 * sf: 0 -> 32bit, 1 -> 64bit
4023 * op: 0 -> add , 1 -> sub
4026 * option: extension type (see DecodeRegExtend)
4027 * imm3: optional shift to Rm
4029 * Rd = Rn + LSL(extend(Rm), amount)
4031 static void disas_add_sub_ext_reg(DisasContext *s, uint32_t insn)
4033 int rd = extract32(insn, 0, 5);
4034 int rn = extract32(insn, 5, 5);
4035 int imm3 = extract32(insn, 10, 3);
4036 int option = extract32(insn, 13, 3);
4037 int rm = extract32(insn, 16, 5);
4038 bool setflags = extract32(insn, 29, 1);
4039 bool sub_op = extract32(insn, 30, 1);
4040 bool sf = extract32(insn, 31, 1);
4042 TCGv_i64 tcg_rm, tcg_rn; /* temps */
4044 TCGv_i64 tcg_result;
4047 unallocated_encoding(s);
4051 /* non-flag setting ops may use SP */
4053 tcg_rd = cpu_reg_sp(s, rd);
4055 tcg_rd = cpu_reg(s, rd);
4057 tcg_rn = read_cpu_reg_sp(s, rn, sf);
4059 tcg_rm = read_cpu_reg(s, rm, sf);
4060 ext_and_shift_reg(tcg_rm, tcg_rm, option, imm3);
4062 tcg_result = tcg_temp_new_i64();
4066 tcg_gen_sub_i64(tcg_result, tcg_rn, tcg_rm);
4068 tcg_gen_add_i64(tcg_result, tcg_rn, tcg_rm);
4072 gen_sub_CC(sf, tcg_result, tcg_rn, tcg_rm);
4074 gen_add_CC(sf, tcg_result, tcg_rn, tcg_rm);
4079 tcg_gen_mov_i64(tcg_rd, tcg_result);
4081 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
4084 tcg_temp_free_i64(tcg_result);
4088 * Add/subtract (shifted register)
4090 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4091 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4092 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
4093 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4095 * sf: 0 -> 32bit, 1 -> 64bit
4096 * op: 0 -> add , 1 -> sub
4098 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
4099 * imm6: Shift amount to apply to Rm before the add/sub
4101 static void disas_add_sub_reg(DisasContext *s, uint32_t insn)
4103 int rd = extract32(insn, 0, 5);
4104 int rn = extract32(insn, 5, 5);
4105 int imm6 = extract32(insn, 10, 6);
4106 int rm = extract32(insn, 16, 5);
4107 int shift_type = extract32(insn, 22, 2);
4108 bool setflags = extract32(insn, 29, 1);
4109 bool sub_op = extract32(insn, 30, 1);
4110 bool sf = extract32(insn, 31, 1);
4112 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4113 TCGv_i64 tcg_rn, tcg_rm;
4114 TCGv_i64 tcg_result;
4116 if ((shift_type == 3) || (!sf && (imm6 > 31))) {
4117 unallocated_encoding(s);
4121 tcg_rn = read_cpu_reg(s, rn, sf);
4122 tcg_rm = read_cpu_reg(s, rm, sf);
4124 shift_reg_imm(tcg_rm, tcg_rm, sf, shift_type, imm6);
4126 tcg_result = tcg_temp_new_i64();
4130 tcg_gen_sub_i64(tcg_result, tcg_rn, tcg_rm);
4132 tcg_gen_add_i64(tcg_result, tcg_rn, tcg_rm);
4136 gen_sub_CC(sf, tcg_result, tcg_rn, tcg_rm);
4138 gen_add_CC(sf, tcg_result, tcg_rn, tcg_rm);
4143 tcg_gen_mov_i64(tcg_rd, tcg_result);
4145 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
4148 tcg_temp_free_i64(tcg_result);
4151 /* Data-processing (3 source)
4153 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
4154 * +--+------+-----------+------+------+----+------+------+------+
4155 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
4156 * +--+------+-----------+------+------+----+------+------+------+
4158 static void disas_data_proc_3src(DisasContext *s, uint32_t insn)
4160 int rd = extract32(insn, 0, 5);
4161 int rn = extract32(insn, 5, 5);
4162 int ra = extract32(insn, 10, 5);
4163 int rm = extract32(insn, 16, 5);
4164 int op_id = (extract32(insn, 29, 3) << 4) |
4165 (extract32(insn, 21, 3) << 1) |
4166 extract32(insn, 15, 1);
4167 bool sf = extract32(insn, 31, 1);
4168 bool is_sub = extract32(op_id, 0, 1);
4169 bool is_high = extract32(op_id, 2, 1);
4170 bool is_signed = false;
4175 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
4177 case 0x42: /* SMADDL */
4178 case 0x43: /* SMSUBL */
4179 case 0x44: /* SMULH */
4182 case 0x0: /* MADD (32bit) */
4183 case 0x1: /* MSUB (32bit) */
4184 case 0x40: /* MADD (64bit) */
4185 case 0x41: /* MSUB (64bit) */
4186 case 0x4a: /* UMADDL */
4187 case 0x4b: /* UMSUBL */
4188 case 0x4c: /* UMULH */
4191 unallocated_encoding(s);
4196 TCGv_i64 low_bits = tcg_temp_new_i64(); /* low bits discarded */
4197 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4198 TCGv_i64 tcg_rn = cpu_reg(s, rn);
4199 TCGv_i64 tcg_rm = cpu_reg(s, rm);
4202 tcg_gen_muls2_i64(low_bits, tcg_rd, tcg_rn, tcg_rm);
4204 tcg_gen_mulu2_i64(low_bits, tcg_rd, tcg_rn, tcg_rm);
4207 tcg_temp_free_i64(low_bits);
4211 tcg_op1 = tcg_temp_new_i64();
4212 tcg_op2 = tcg_temp_new_i64();
4213 tcg_tmp = tcg_temp_new_i64();
4216 tcg_gen_mov_i64(tcg_op1, cpu_reg(s, rn));
4217 tcg_gen_mov_i64(tcg_op2, cpu_reg(s, rm));
4220 tcg_gen_ext32s_i64(tcg_op1, cpu_reg(s, rn));
4221 tcg_gen_ext32s_i64(tcg_op2, cpu_reg(s, rm));
4223 tcg_gen_ext32u_i64(tcg_op1, cpu_reg(s, rn));
4224 tcg_gen_ext32u_i64(tcg_op2, cpu_reg(s, rm));
4228 if (ra == 31 && !is_sub) {
4229 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
4230 tcg_gen_mul_i64(cpu_reg(s, rd), tcg_op1, tcg_op2);
4232 tcg_gen_mul_i64(tcg_tmp, tcg_op1, tcg_op2);
4234 tcg_gen_sub_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
4236 tcg_gen_add_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
4241 tcg_gen_ext32u_i64(cpu_reg(s, rd), cpu_reg(s, rd));
4244 tcg_temp_free_i64(tcg_op1);
4245 tcg_temp_free_i64(tcg_op2);
4246 tcg_temp_free_i64(tcg_tmp);
4249 /* Add/subtract (with carry)
4250 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
4251 * +--+--+--+------------------------+------+---------+------+-----+
4252 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
4253 * +--+--+--+------------------------+------+---------+------+-----+
4257 static void disas_adc_sbc(DisasContext *s, uint32_t insn)
4259 unsigned int sf, op, setflags, rm, rn, rd;
4260 TCGv_i64 tcg_y, tcg_rn, tcg_rd;
4262 if (extract32(insn, 10, 6) != 0) {
4263 unallocated_encoding(s);
4267 sf = extract32(insn, 31, 1);
4268 op = extract32(insn, 30, 1);
4269 setflags = extract32(insn, 29, 1);
4270 rm = extract32(insn, 16, 5);
4271 rn = extract32(insn, 5, 5);
4272 rd = extract32(insn, 0, 5);
4274 tcg_rd = cpu_reg(s, rd);
4275 tcg_rn = cpu_reg(s, rn);
4278 tcg_y = new_tmp_a64(s);
4279 tcg_gen_not_i64(tcg_y, cpu_reg(s, rm));
4281 tcg_y = cpu_reg(s, rm);
4285 gen_adc_CC(sf, tcg_rd, tcg_rn, tcg_y);
4287 gen_adc(sf, tcg_rd, tcg_rn, tcg_y);
4291 /* Conditional compare (immediate / register)
4292 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4293 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4294 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
4295 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4298 static void disas_cc(DisasContext *s, uint32_t insn)
4300 unsigned int sf, op, y, cond, rn, nzcv, is_imm;
4301 TCGv_i32 tcg_t0, tcg_t1, tcg_t2;
4302 TCGv_i64 tcg_tmp, tcg_y, tcg_rn;
4305 if (!extract32(insn, 29, 1)) {
4306 unallocated_encoding(s);
4309 if (insn & (1 << 10 | 1 << 4)) {
4310 unallocated_encoding(s);
4313 sf = extract32(insn, 31, 1);
4314 op = extract32(insn, 30, 1);
4315 is_imm = extract32(insn, 11, 1);
4316 y = extract32(insn, 16, 5); /* y = rm (reg) or imm5 (imm) */
4317 cond = extract32(insn, 12, 4);
4318 rn = extract32(insn, 5, 5);
4319 nzcv = extract32(insn, 0, 4);
4321 /* Set T0 = !COND. */
4322 tcg_t0 = tcg_temp_new_i32();
4323 arm_test_cc(&c, cond);
4324 tcg_gen_setcondi_i32(tcg_invert_cond(c.cond), tcg_t0, c.value, 0);
4327 /* Load the arguments for the new comparison. */
4329 tcg_y = new_tmp_a64(s);
4330 tcg_gen_movi_i64(tcg_y, y);
4332 tcg_y = cpu_reg(s, y);
4334 tcg_rn = cpu_reg(s, rn);
4336 /* Set the flags for the new comparison. */
4337 tcg_tmp = tcg_temp_new_i64();
4339 gen_sub_CC(sf, tcg_tmp, tcg_rn, tcg_y);
4341 gen_add_CC(sf, tcg_tmp, tcg_rn, tcg_y);
4343 tcg_temp_free_i64(tcg_tmp);
4345 /* If COND was false, force the flags to #nzcv. Compute two masks
4346 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
4347 * For tcg hosts that support ANDC, we can make do with just T1.
4348 * In either case, allow the tcg optimizer to delete any unused mask.
4350 tcg_t1 = tcg_temp_new_i32();
4351 tcg_t2 = tcg_temp_new_i32();
4352 tcg_gen_neg_i32(tcg_t1, tcg_t0);
4353 tcg_gen_subi_i32(tcg_t2, tcg_t0, 1);
4355 if (nzcv & 8) { /* N */
4356 tcg_gen_or_i32(cpu_NF, cpu_NF, tcg_t1);
4358 if (TCG_TARGET_HAS_andc_i32) {
4359 tcg_gen_andc_i32(cpu_NF, cpu_NF, tcg_t1);
4361 tcg_gen_and_i32(cpu_NF, cpu_NF, tcg_t2);
4364 if (nzcv & 4) { /* Z */
4365 if (TCG_TARGET_HAS_andc_i32) {
4366 tcg_gen_andc_i32(cpu_ZF, cpu_ZF, tcg_t1);
4368 tcg_gen_and_i32(cpu_ZF, cpu_ZF, tcg_t2);
4371 tcg_gen_or_i32(cpu_ZF, cpu_ZF, tcg_t0);
4373 if (nzcv & 2) { /* C */
4374 tcg_gen_or_i32(cpu_CF, cpu_CF, tcg_t0);
4376 if (TCG_TARGET_HAS_andc_i32) {
4377 tcg_gen_andc_i32(cpu_CF, cpu_CF, tcg_t1);
4379 tcg_gen_and_i32(cpu_CF, cpu_CF, tcg_t2);
4382 if (nzcv & 1) { /* V */
4383 tcg_gen_or_i32(cpu_VF, cpu_VF, tcg_t1);
4385 if (TCG_TARGET_HAS_andc_i32) {
4386 tcg_gen_andc_i32(cpu_VF, cpu_VF, tcg_t1);
4388 tcg_gen_and_i32(cpu_VF, cpu_VF, tcg_t2);
4391 tcg_temp_free_i32(tcg_t0);
4392 tcg_temp_free_i32(tcg_t1);
4393 tcg_temp_free_i32(tcg_t2);
4396 /* Conditional select
4397 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
4398 * +----+----+---+-----------------+------+------+-----+------+------+
4399 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
4400 * +----+----+---+-----------------+------+------+-----+------+------+
4402 static void disas_cond_select(DisasContext *s, uint32_t insn)
4404 unsigned int sf, else_inv, rm, cond, else_inc, rn, rd;
4405 TCGv_i64 tcg_rd, zero;
4408 if (extract32(insn, 29, 1) || extract32(insn, 11, 1)) {
4409 /* S == 1 or op2<1> == 1 */
4410 unallocated_encoding(s);
4413 sf = extract32(insn, 31, 1);
4414 else_inv = extract32(insn, 30, 1);
4415 rm = extract32(insn, 16, 5);
4416 cond = extract32(insn, 12, 4);
4417 else_inc = extract32(insn, 10, 1);
4418 rn = extract32(insn, 5, 5);
4419 rd = extract32(insn, 0, 5);
4421 tcg_rd = cpu_reg(s, rd);
4423 a64_test_cc(&c, cond);
4424 zero = tcg_const_i64(0);
4426 if (rn == 31 && rm == 31 && (else_inc ^ else_inv)) {
4428 tcg_gen_setcond_i64(tcg_invert_cond(c.cond), tcg_rd, c.value, zero);
4430 tcg_gen_neg_i64(tcg_rd, tcg_rd);
4433 TCGv_i64 t_true = cpu_reg(s, rn);
4434 TCGv_i64 t_false = read_cpu_reg(s, rm, 1);
4435 if (else_inv && else_inc) {
4436 tcg_gen_neg_i64(t_false, t_false);
4437 } else if (else_inv) {
4438 tcg_gen_not_i64(t_false, t_false);
4439 } else if (else_inc) {
4440 tcg_gen_addi_i64(t_false, t_false, 1);
4442 tcg_gen_movcond_i64(c.cond, tcg_rd, c.value, zero, t_true, t_false);
4445 tcg_temp_free_i64(zero);
4449 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
4453 static void handle_clz(DisasContext *s, unsigned int sf,
4454 unsigned int rn, unsigned int rd)
4456 TCGv_i64 tcg_rd, tcg_rn;
4457 tcg_rd = cpu_reg(s, rd);
4458 tcg_rn = cpu_reg(s, rn);
4461 tcg_gen_clzi_i64(tcg_rd, tcg_rn, 64);
4463 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
4464 tcg_gen_extrl_i64_i32(tcg_tmp32, tcg_rn);
4465 tcg_gen_clzi_i32(tcg_tmp32, tcg_tmp32, 32);
4466 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
4467 tcg_temp_free_i32(tcg_tmp32);
4471 static void handle_cls(DisasContext *s, unsigned int sf,
4472 unsigned int rn, unsigned int rd)
4474 TCGv_i64 tcg_rd, tcg_rn;
4475 tcg_rd = cpu_reg(s, rd);
4476 tcg_rn = cpu_reg(s, rn);
4479 tcg_gen_clrsb_i64(tcg_rd, tcg_rn);
4481 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
4482 tcg_gen_extrl_i64_i32(tcg_tmp32, tcg_rn);
4483 tcg_gen_clrsb_i32(tcg_tmp32, tcg_tmp32);
4484 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
4485 tcg_temp_free_i32(tcg_tmp32);
4489 static void handle_rbit(DisasContext *s, unsigned int sf,
4490 unsigned int rn, unsigned int rd)
4492 TCGv_i64 tcg_rd, tcg_rn;
4493 tcg_rd = cpu_reg(s, rd);
4494 tcg_rn = cpu_reg(s, rn);
4497 gen_helper_rbit64(tcg_rd, tcg_rn);
4499 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
4500 tcg_gen_extrl_i64_i32(tcg_tmp32, tcg_rn);
4501 gen_helper_rbit(tcg_tmp32, tcg_tmp32);
4502 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
4503 tcg_temp_free_i32(tcg_tmp32);
4507 /* REV with sf==1, opcode==3 ("REV64") */
4508 static void handle_rev64(DisasContext *s, unsigned int sf,
4509 unsigned int rn, unsigned int rd)
4512 unallocated_encoding(s);
4515 tcg_gen_bswap64_i64(cpu_reg(s, rd), cpu_reg(s, rn));
4518 /* REV with sf==0, opcode==2
4519 * REV32 (sf==1, opcode==2)
4521 static void handle_rev32(DisasContext *s, unsigned int sf,
4522 unsigned int rn, unsigned int rd)
4524 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4527 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
4528 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
4530 /* bswap32_i64 requires zero high word */
4531 tcg_gen_ext32u_i64(tcg_tmp, tcg_rn);
4532 tcg_gen_bswap32_i64(tcg_rd, tcg_tmp);
4533 tcg_gen_shri_i64(tcg_tmp, tcg_rn, 32);
4534 tcg_gen_bswap32_i64(tcg_tmp, tcg_tmp);
4535 tcg_gen_concat32_i64(tcg_rd, tcg_rd, tcg_tmp);
4537 tcg_temp_free_i64(tcg_tmp);
4539 tcg_gen_ext32u_i64(tcg_rd, cpu_reg(s, rn));
4540 tcg_gen_bswap32_i64(tcg_rd, tcg_rd);
4544 /* REV16 (opcode==1) */
4545 static void handle_rev16(DisasContext *s, unsigned int sf,
4546 unsigned int rn, unsigned int rd)
4548 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4549 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
4550 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
4551 TCGv_i64 mask = tcg_const_i64(sf ? 0x00ff00ff00ff00ffull : 0x00ff00ff);
4553 tcg_gen_shri_i64(tcg_tmp, tcg_rn, 8);
4554 tcg_gen_and_i64(tcg_rd, tcg_rn, mask);
4555 tcg_gen_and_i64(tcg_tmp, tcg_tmp, mask);
4556 tcg_gen_shli_i64(tcg_rd, tcg_rd, 8);
4557 tcg_gen_or_i64(tcg_rd, tcg_rd, tcg_tmp);
4559 tcg_temp_free_i64(mask);
4560 tcg_temp_free_i64(tcg_tmp);
4563 /* Data-processing (1 source)
4564 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4565 * +----+---+---+-----------------+---------+--------+------+------+
4566 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
4567 * +----+---+---+-----------------+---------+--------+------+------+
4569 static void disas_data_proc_1src(DisasContext *s, uint32_t insn)
4571 unsigned int sf, opcode, opcode2, rn, rd;
4574 if (extract32(insn, 29, 1)) {
4575 unallocated_encoding(s);
4579 sf = extract32(insn, 31, 1);
4580 opcode = extract32(insn, 10, 6);
4581 opcode2 = extract32(insn, 16, 5);
4582 rn = extract32(insn, 5, 5);
4583 rd = extract32(insn, 0, 5);
4585 #define MAP(SF, O2, O1) ((SF) | (O1 << 1) | (O2 << 7))
4587 switch (MAP(sf, opcode2, opcode)) {
4588 case MAP(0, 0x00, 0x00): /* RBIT */
4589 case MAP(1, 0x00, 0x00):
4590 handle_rbit(s, sf, rn, rd);
4592 case MAP(0, 0x00, 0x01): /* REV16 */
4593 case MAP(1, 0x00, 0x01):
4594 handle_rev16(s, sf, rn, rd);
4596 case MAP(0, 0x00, 0x02): /* REV/REV32 */
4597 case MAP(1, 0x00, 0x02):
4598 handle_rev32(s, sf, rn, rd);
4600 case MAP(1, 0x00, 0x03): /* REV64 */
4601 handle_rev64(s, sf, rn, rd);
4603 case MAP(0, 0x00, 0x04): /* CLZ */
4604 case MAP(1, 0x00, 0x04):
4605 handle_clz(s, sf, rn, rd);
4607 case MAP(0, 0x00, 0x05): /* CLS */
4608 case MAP(1, 0x00, 0x05):
4609 handle_cls(s, sf, rn, rd);
4611 case MAP(1, 0x01, 0x00): /* PACIA */
4612 if (s->pauth_active) {
4613 tcg_rd = cpu_reg(s, rd);
4614 gen_helper_pacia(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4615 } else if (!dc_isar_feature(aa64_pauth, s)) {
4616 goto do_unallocated;
4619 case MAP(1, 0x01, 0x01): /* PACIB */
4620 if (s->pauth_active) {
4621 tcg_rd = cpu_reg(s, rd);
4622 gen_helper_pacib(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4623 } else if (!dc_isar_feature(aa64_pauth, s)) {
4624 goto do_unallocated;
4627 case MAP(1, 0x01, 0x02): /* PACDA */
4628 if (s->pauth_active) {
4629 tcg_rd = cpu_reg(s, rd);
4630 gen_helper_pacda(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4631 } else if (!dc_isar_feature(aa64_pauth, s)) {
4632 goto do_unallocated;
4635 case MAP(1, 0x01, 0x03): /* PACDB */
4636 if (s->pauth_active) {
4637 tcg_rd = cpu_reg(s, rd);
4638 gen_helper_pacdb(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4639 } else if (!dc_isar_feature(aa64_pauth, s)) {
4640 goto do_unallocated;
4643 case MAP(1, 0x01, 0x04): /* AUTIA */
4644 if (s->pauth_active) {
4645 tcg_rd = cpu_reg(s, rd);
4646 gen_helper_autia(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4647 } else if (!dc_isar_feature(aa64_pauth, s)) {
4648 goto do_unallocated;
4651 case MAP(1, 0x01, 0x05): /* AUTIB */
4652 if (s->pauth_active) {
4653 tcg_rd = cpu_reg(s, rd);
4654 gen_helper_autib(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4655 } else if (!dc_isar_feature(aa64_pauth, s)) {
4656 goto do_unallocated;
4659 case MAP(1, 0x01, 0x06): /* AUTDA */
4660 if (s->pauth_active) {
4661 tcg_rd = cpu_reg(s, rd);
4662 gen_helper_autda(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4663 } else if (!dc_isar_feature(aa64_pauth, s)) {
4664 goto do_unallocated;
4667 case MAP(1, 0x01, 0x07): /* AUTDB */
4668 if (s->pauth_active) {
4669 tcg_rd = cpu_reg(s, rd);
4670 gen_helper_autdb(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn));
4671 } else if (!dc_isar_feature(aa64_pauth, s)) {
4672 goto do_unallocated;
4675 case MAP(1, 0x01, 0x08): /* PACIZA */
4676 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4677 goto do_unallocated;
4678 } else if (s->pauth_active) {
4679 tcg_rd = cpu_reg(s, rd);
4680 gen_helper_pacia(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4683 case MAP(1, 0x01, 0x09): /* PACIZB */
4684 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4685 goto do_unallocated;
4686 } else if (s->pauth_active) {
4687 tcg_rd = cpu_reg(s, rd);
4688 gen_helper_pacib(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4691 case MAP(1, 0x01, 0x0a): /* PACDZA */
4692 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4693 goto do_unallocated;
4694 } else if (s->pauth_active) {
4695 tcg_rd = cpu_reg(s, rd);
4696 gen_helper_pacda(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4699 case MAP(1, 0x01, 0x0b): /* PACDZB */
4700 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4701 goto do_unallocated;
4702 } else if (s->pauth_active) {
4703 tcg_rd = cpu_reg(s, rd);
4704 gen_helper_pacdb(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4707 case MAP(1, 0x01, 0x0c): /* AUTIZA */
4708 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4709 goto do_unallocated;
4710 } else if (s->pauth_active) {
4711 tcg_rd = cpu_reg(s, rd);
4712 gen_helper_autia(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4715 case MAP(1, 0x01, 0x0d): /* AUTIZB */
4716 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4717 goto do_unallocated;
4718 } else if (s->pauth_active) {
4719 tcg_rd = cpu_reg(s, rd);
4720 gen_helper_autib(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4723 case MAP(1, 0x01, 0x0e): /* AUTDZA */
4724 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4725 goto do_unallocated;
4726 } else if (s->pauth_active) {
4727 tcg_rd = cpu_reg(s, rd);
4728 gen_helper_autda(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4731 case MAP(1, 0x01, 0x0f): /* AUTDZB */
4732 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4733 goto do_unallocated;
4734 } else if (s->pauth_active) {
4735 tcg_rd = cpu_reg(s, rd);
4736 gen_helper_autdb(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s));
4739 case MAP(1, 0x01, 0x10): /* XPACI */
4740 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4741 goto do_unallocated;
4742 } else if (s->pauth_active) {
4743 tcg_rd = cpu_reg(s, rd);
4744 gen_helper_xpaci(tcg_rd, cpu_env, tcg_rd);
4747 case MAP(1, 0x01, 0x11): /* XPACD */
4748 if (!dc_isar_feature(aa64_pauth, s) || rn != 31) {
4749 goto do_unallocated;
4750 } else if (s->pauth_active) {
4751 tcg_rd = cpu_reg(s, rd);
4752 gen_helper_xpacd(tcg_rd, cpu_env, tcg_rd);
4757 unallocated_encoding(s);
4764 static void handle_div(DisasContext *s, bool is_signed, unsigned int sf,
4765 unsigned int rm, unsigned int rn, unsigned int rd)
4767 TCGv_i64 tcg_n, tcg_m, tcg_rd;
4768 tcg_rd = cpu_reg(s, rd);
4770 if (!sf && is_signed) {
4771 tcg_n = new_tmp_a64(s);
4772 tcg_m = new_tmp_a64(s);
4773 tcg_gen_ext32s_i64(tcg_n, cpu_reg(s, rn));
4774 tcg_gen_ext32s_i64(tcg_m, cpu_reg(s, rm));
4776 tcg_n = read_cpu_reg(s, rn, sf);
4777 tcg_m = read_cpu_reg(s, rm, sf);
4781 gen_helper_sdiv64(tcg_rd, tcg_n, tcg_m);
4783 gen_helper_udiv64(tcg_rd, tcg_n, tcg_m);
4786 if (!sf) { /* zero extend final result */
4787 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
4791 /* LSLV, LSRV, ASRV, RORV */
4792 static void handle_shift_reg(DisasContext *s,
4793 enum a64_shift_type shift_type, unsigned int sf,
4794 unsigned int rm, unsigned int rn, unsigned int rd)
4796 TCGv_i64 tcg_shift = tcg_temp_new_i64();
4797 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4798 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
4800 tcg_gen_andi_i64(tcg_shift, cpu_reg(s, rm), sf ? 63 : 31);
4801 shift_reg(tcg_rd, tcg_rn, sf, shift_type, tcg_shift);
4802 tcg_temp_free_i64(tcg_shift);
4805 /* CRC32[BHWX], CRC32C[BHWX] */
4806 static void handle_crc32(DisasContext *s,
4807 unsigned int sf, unsigned int sz, bool crc32c,
4808 unsigned int rm, unsigned int rn, unsigned int rd)
4810 TCGv_i64 tcg_acc, tcg_val;
4813 if (!dc_isar_feature(aa64_crc32, s)
4814 || (sf == 1 && sz != 3)
4815 || (sf == 0 && sz == 3)) {
4816 unallocated_encoding(s);
4821 tcg_val = cpu_reg(s, rm);
4835 g_assert_not_reached();
4837 tcg_val = new_tmp_a64(s);
4838 tcg_gen_andi_i64(tcg_val, cpu_reg(s, rm), mask);
4841 tcg_acc = cpu_reg(s, rn);
4842 tcg_bytes = tcg_const_i32(1 << sz);
4845 gen_helper_crc32c_64(cpu_reg(s, rd), tcg_acc, tcg_val, tcg_bytes);
4847 gen_helper_crc32_64(cpu_reg(s, rd), tcg_acc, tcg_val, tcg_bytes);
4850 tcg_temp_free_i32(tcg_bytes);
4853 /* Data-processing (2 source)
4854 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4855 * +----+---+---+-----------------+------+--------+------+------+
4856 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
4857 * +----+---+---+-----------------+------+--------+------+------+
4859 static void disas_data_proc_2src(DisasContext *s, uint32_t insn)
4861 unsigned int sf, rm, opcode, rn, rd;
4862 sf = extract32(insn, 31, 1);
4863 rm = extract32(insn, 16, 5);
4864 opcode = extract32(insn, 10, 6);
4865 rn = extract32(insn, 5, 5);
4866 rd = extract32(insn, 0, 5);
4868 if (extract32(insn, 29, 1)) {
4869 unallocated_encoding(s);
4875 handle_div(s, false, sf, rm, rn, rd);
4878 handle_div(s, true, sf, rm, rn, rd);
4881 handle_shift_reg(s, A64_SHIFT_TYPE_LSL, sf, rm, rn, rd);
4884 handle_shift_reg(s, A64_SHIFT_TYPE_LSR, sf, rm, rn, rd);
4887 handle_shift_reg(s, A64_SHIFT_TYPE_ASR, sf, rm, rn, rd);
4890 handle_shift_reg(s, A64_SHIFT_TYPE_ROR, sf, rm, rn, rd);
4892 case 12: /* PACGA */
4893 if (sf == 0 || !dc_isar_feature(aa64_pauth, s)) {
4894 goto do_unallocated;
4896 gen_helper_pacga(cpu_reg(s, rd), cpu_env,
4897 cpu_reg(s, rn), cpu_reg_sp(s, rm));
4906 case 23: /* CRC32 */
4908 int sz = extract32(opcode, 0, 2);
4909 bool crc32c = extract32(opcode, 2, 1);
4910 handle_crc32(s, sf, sz, crc32c, rm, rn, rd);
4915 unallocated_encoding(s);
4920 /* Data processing - register */
4921 static void disas_data_proc_reg(DisasContext *s, uint32_t insn)
4923 switch (extract32(insn, 24, 5)) {
4924 case 0x0a: /* Logical (shifted register) */
4925 disas_logic_reg(s, insn);
4927 case 0x0b: /* Add/subtract */
4928 if (insn & (1 << 21)) { /* (extended register) */
4929 disas_add_sub_ext_reg(s, insn);
4931 disas_add_sub_reg(s, insn);
4934 case 0x1b: /* Data-processing (3 source) */
4935 disas_data_proc_3src(s, insn);
4938 switch (extract32(insn, 21, 3)) {
4939 case 0x0: /* Add/subtract (with carry) */
4940 disas_adc_sbc(s, insn);
4942 case 0x2: /* Conditional compare */
4943 disas_cc(s, insn); /* both imm and reg forms */
4945 case 0x4: /* Conditional select */
4946 disas_cond_select(s, insn);
4948 case 0x6: /* Data-processing */
4949 if (insn & (1 << 30)) { /* (1 source) */
4950 disas_data_proc_1src(s, insn);
4951 } else { /* (2 source) */
4952 disas_data_proc_2src(s, insn);
4956 unallocated_encoding(s);
4961 unallocated_encoding(s);
4966 static void handle_fp_compare(DisasContext *s, int size,
4967 unsigned int rn, unsigned int rm,
4968 bool cmp_with_zero, bool signal_all_nans)
4970 TCGv_i64 tcg_flags = tcg_temp_new_i64();
4971 TCGv_ptr fpst = get_fpstatus_ptr(size == MO_16);
4973 if (size == MO_64) {
4974 TCGv_i64 tcg_vn, tcg_vm;
4976 tcg_vn = read_fp_dreg(s, rn);
4977 if (cmp_with_zero) {
4978 tcg_vm = tcg_const_i64(0);
4980 tcg_vm = read_fp_dreg(s, rm);
4982 if (signal_all_nans) {
4983 gen_helper_vfp_cmped_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
4985 gen_helper_vfp_cmpd_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
4987 tcg_temp_free_i64(tcg_vn);
4988 tcg_temp_free_i64(tcg_vm);
4990 TCGv_i32 tcg_vn = tcg_temp_new_i32();
4991 TCGv_i32 tcg_vm = tcg_temp_new_i32();
4993 read_vec_element_i32(s, tcg_vn, rn, 0, size);
4994 if (cmp_with_zero) {
4995 tcg_gen_movi_i32(tcg_vm, 0);
4997 read_vec_element_i32(s, tcg_vm, rm, 0, size);
5002 if (signal_all_nans) {
5003 gen_helper_vfp_cmpes_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5005 gen_helper_vfp_cmps_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5009 if (signal_all_nans) {
5010 gen_helper_vfp_cmpeh_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5012 gen_helper_vfp_cmph_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
5016 g_assert_not_reached();
5019 tcg_temp_free_i32(tcg_vn);
5020 tcg_temp_free_i32(tcg_vm);
5023 tcg_temp_free_ptr(fpst);
5025 gen_set_nzcv(tcg_flags);
5027 tcg_temp_free_i64(tcg_flags);
5030 /* Floating point compare
5031 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
5032 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5033 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
5034 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5036 static void disas_fp_compare(DisasContext *s, uint32_t insn)
5038 unsigned int mos, type, rm, op, rn, opc, op2r;
5041 mos = extract32(insn, 29, 3);
5042 type = extract32(insn, 22, 2);
5043 rm = extract32(insn, 16, 5);
5044 op = extract32(insn, 14, 2);
5045 rn = extract32(insn, 5, 5);
5046 opc = extract32(insn, 3, 2);
5047 op2r = extract32(insn, 0, 3);
5049 if (mos || op || op2r) {
5050 unallocated_encoding(s);
5063 if (dc_isar_feature(aa64_fp16, s)) {
5068 unallocated_encoding(s);
5072 if (!fp_access_check(s)) {
5076 handle_fp_compare(s, size, rn, rm, opc & 1, opc & 2);
5079 /* Floating point conditional compare
5080 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
5081 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5082 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
5083 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5085 static void disas_fp_ccomp(DisasContext *s, uint32_t insn)
5087 unsigned int mos, type, rm, cond, rn, op, nzcv;
5089 TCGLabel *label_continue = NULL;
5092 mos = extract32(insn, 29, 3);
5093 type = extract32(insn, 22, 2);
5094 rm = extract32(insn, 16, 5);
5095 cond = extract32(insn, 12, 4);
5096 rn = extract32(insn, 5, 5);
5097 op = extract32(insn, 4, 1);
5098 nzcv = extract32(insn, 0, 4);
5101 unallocated_encoding(s);
5114 if (dc_isar_feature(aa64_fp16, s)) {
5119 unallocated_encoding(s);
5123 if (!fp_access_check(s)) {
5127 if (cond < 0x0e) { /* not always */
5128 TCGLabel *label_match = gen_new_label();
5129 label_continue = gen_new_label();
5130 arm_gen_test_cc(cond, label_match);
5132 tcg_flags = tcg_const_i64(nzcv << 28);
5133 gen_set_nzcv(tcg_flags);
5134 tcg_temp_free_i64(tcg_flags);
5135 tcg_gen_br(label_continue);
5136 gen_set_label(label_match);
5139 handle_fp_compare(s, size, rn, rm, false, op);
5142 gen_set_label(label_continue);
5146 /* Floating point conditional select
5147 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5148 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5149 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
5150 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5152 static void disas_fp_csel(DisasContext *s, uint32_t insn)
5154 unsigned int mos, type, rm, cond, rn, rd;
5155 TCGv_i64 t_true, t_false, t_zero;
5159 mos = extract32(insn, 29, 3);
5160 type = extract32(insn, 22, 2);
5161 rm = extract32(insn, 16, 5);
5162 cond = extract32(insn, 12, 4);
5163 rn = extract32(insn, 5, 5);
5164 rd = extract32(insn, 0, 5);
5167 unallocated_encoding(s);
5180 if (dc_isar_feature(aa64_fp16, s)) {
5185 unallocated_encoding(s);
5189 if (!fp_access_check(s)) {
5193 /* Zero extend sreg & hreg inputs to 64 bits now. */
5194 t_true = tcg_temp_new_i64();
5195 t_false = tcg_temp_new_i64();
5196 read_vec_element(s, t_true, rn, 0, sz);
5197 read_vec_element(s, t_false, rm, 0, sz);
5199 a64_test_cc(&c, cond);
5200 t_zero = tcg_const_i64(0);
5201 tcg_gen_movcond_i64(c.cond, t_true, c.value, t_zero, t_true, t_false);
5202 tcg_temp_free_i64(t_zero);
5203 tcg_temp_free_i64(t_false);
5206 /* Note that sregs & hregs write back zeros to the high bits,
5207 and we've already done the zero-extension. */
5208 write_fp_dreg(s, rd, t_true);
5209 tcg_temp_free_i64(t_true);
5212 /* Floating-point data-processing (1 source) - half precision */
5213 static void handle_fp_1src_half(DisasContext *s, int opcode, int rd, int rn)
5215 TCGv_ptr fpst = NULL;
5216 TCGv_i32 tcg_op = read_fp_hreg(s, rn);
5217 TCGv_i32 tcg_res = tcg_temp_new_i32();
5220 case 0x0: /* FMOV */
5221 tcg_gen_mov_i32(tcg_res, tcg_op);
5223 case 0x1: /* FABS */
5224 tcg_gen_andi_i32(tcg_res, tcg_op, 0x7fff);
5226 case 0x2: /* FNEG */
5227 tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000);
5229 case 0x3: /* FSQRT */
5230 fpst = get_fpstatus_ptr(true);
5231 gen_helper_sqrt_f16(tcg_res, tcg_op, fpst);
5233 case 0x8: /* FRINTN */
5234 case 0x9: /* FRINTP */
5235 case 0xa: /* FRINTM */
5236 case 0xb: /* FRINTZ */
5237 case 0xc: /* FRINTA */
5239 TCGv_i32 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(opcode & 7));
5240 fpst = get_fpstatus_ptr(true);
5242 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5243 gen_helper_advsimd_rinth(tcg_res, tcg_op, fpst);
5245 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5246 tcg_temp_free_i32(tcg_rmode);
5249 case 0xe: /* FRINTX */
5250 fpst = get_fpstatus_ptr(true);
5251 gen_helper_advsimd_rinth_exact(tcg_res, tcg_op, fpst);
5253 case 0xf: /* FRINTI */
5254 fpst = get_fpstatus_ptr(true);
5255 gen_helper_advsimd_rinth(tcg_res, tcg_op, fpst);
5261 write_fp_sreg(s, rd, tcg_res);
5264 tcg_temp_free_ptr(fpst);
5266 tcg_temp_free_i32(tcg_op);
5267 tcg_temp_free_i32(tcg_res);
5270 /* Floating-point data-processing (1 source) - single precision */
5271 static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn)
5277 fpst = get_fpstatus_ptr(false);
5278 tcg_op = read_fp_sreg(s, rn);
5279 tcg_res = tcg_temp_new_i32();
5282 case 0x0: /* FMOV */
5283 tcg_gen_mov_i32(tcg_res, tcg_op);
5285 case 0x1: /* FABS */
5286 gen_helper_vfp_abss(tcg_res, tcg_op);
5288 case 0x2: /* FNEG */
5289 gen_helper_vfp_negs(tcg_res, tcg_op);
5291 case 0x3: /* FSQRT */
5292 gen_helper_vfp_sqrts(tcg_res, tcg_op, cpu_env);
5294 case 0x8: /* FRINTN */
5295 case 0x9: /* FRINTP */
5296 case 0xa: /* FRINTM */
5297 case 0xb: /* FRINTZ */
5298 case 0xc: /* FRINTA */
5300 TCGv_i32 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(opcode & 7));
5302 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5303 gen_helper_rints(tcg_res, tcg_op, fpst);
5305 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5306 tcg_temp_free_i32(tcg_rmode);
5309 case 0xe: /* FRINTX */
5310 gen_helper_rints_exact(tcg_res, tcg_op, fpst);
5312 case 0xf: /* FRINTI */
5313 gen_helper_rints(tcg_res, tcg_op, fpst);
5319 write_fp_sreg(s, rd, tcg_res);
5321 tcg_temp_free_ptr(fpst);
5322 tcg_temp_free_i32(tcg_op);
5323 tcg_temp_free_i32(tcg_res);
5326 /* Floating-point data-processing (1 source) - double precision */
5327 static void handle_fp_1src_double(DisasContext *s, int opcode, int rd, int rn)
5334 case 0x0: /* FMOV */
5335 gen_gvec_fn2(s, false, rd, rn, tcg_gen_gvec_mov, 0);
5339 fpst = get_fpstatus_ptr(false);
5340 tcg_op = read_fp_dreg(s, rn);
5341 tcg_res = tcg_temp_new_i64();
5344 case 0x1: /* FABS */
5345 gen_helper_vfp_absd(tcg_res, tcg_op);
5347 case 0x2: /* FNEG */
5348 gen_helper_vfp_negd(tcg_res, tcg_op);
5350 case 0x3: /* FSQRT */
5351 gen_helper_vfp_sqrtd(tcg_res, tcg_op, cpu_env);
5353 case 0x8: /* FRINTN */
5354 case 0x9: /* FRINTP */
5355 case 0xa: /* FRINTM */
5356 case 0xb: /* FRINTZ */
5357 case 0xc: /* FRINTA */
5359 TCGv_i32 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(opcode & 7));
5361 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5362 gen_helper_rintd(tcg_res, tcg_op, fpst);
5364 gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst);
5365 tcg_temp_free_i32(tcg_rmode);
5368 case 0xe: /* FRINTX */
5369 gen_helper_rintd_exact(tcg_res, tcg_op, fpst);
5371 case 0xf: /* FRINTI */
5372 gen_helper_rintd(tcg_res, tcg_op, fpst);
5378 write_fp_dreg(s, rd, tcg_res);
5380 tcg_temp_free_ptr(fpst);
5381 tcg_temp_free_i64(tcg_op);
5382 tcg_temp_free_i64(tcg_res);
5385 static void handle_fp_fcvt(DisasContext *s, int opcode,
5386 int rd, int rn, int dtype, int ntype)
5391 TCGv_i32 tcg_rn = read_fp_sreg(s, rn);
5393 /* Single to double */
5394 TCGv_i64 tcg_rd = tcg_temp_new_i64();
5395 gen_helper_vfp_fcvtds(tcg_rd, tcg_rn, cpu_env);
5396 write_fp_dreg(s, rd, tcg_rd);
5397 tcg_temp_free_i64(tcg_rd);
5399 /* Single to half */
5400 TCGv_i32 tcg_rd = tcg_temp_new_i32();
5401 TCGv_i32 ahp = get_ahp_flag();
5402 TCGv_ptr fpst = get_fpstatus_ptr(false);
5404 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd, tcg_rn, fpst, ahp);
5405 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5406 write_fp_sreg(s, rd, tcg_rd);
5407 tcg_temp_free_i32(tcg_rd);
5408 tcg_temp_free_i32(ahp);
5409 tcg_temp_free_ptr(fpst);
5411 tcg_temp_free_i32(tcg_rn);
5416 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
5417 TCGv_i32 tcg_rd = tcg_temp_new_i32();
5419 /* Double to single */
5420 gen_helper_vfp_fcvtsd(tcg_rd, tcg_rn, cpu_env);
5422 TCGv_ptr fpst = get_fpstatus_ptr(false);
5423 TCGv_i32 ahp = get_ahp_flag();
5424 /* Double to half */
5425 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd, tcg_rn, fpst, ahp);
5426 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5427 tcg_temp_free_ptr(fpst);
5428 tcg_temp_free_i32(ahp);
5430 write_fp_sreg(s, rd, tcg_rd);
5431 tcg_temp_free_i32(tcg_rd);
5432 tcg_temp_free_i64(tcg_rn);
5437 TCGv_i32 tcg_rn = read_fp_sreg(s, rn);
5438 TCGv_ptr tcg_fpst = get_fpstatus_ptr(false);
5439 TCGv_i32 tcg_ahp = get_ahp_flag();
5440 tcg_gen_ext16u_i32(tcg_rn, tcg_rn);
5442 /* Half to single */
5443 TCGv_i32 tcg_rd = tcg_temp_new_i32();
5444 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd, tcg_rn, tcg_fpst, tcg_ahp);
5445 write_fp_sreg(s, rd, tcg_rd);
5446 tcg_temp_free_ptr(tcg_fpst);
5447 tcg_temp_free_i32(tcg_ahp);
5448 tcg_temp_free_i32(tcg_rd);
5450 /* Half to double */
5451 TCGv_i64 tcg_rd = tcg_temp_new_i64();
5452 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd, tcg_rn, tcg_fpst, tcg_ahp);
5453 write_fp_dreg(s, rd, tcg_rd);
5454 tcg_temp_free_i64(tcg_rd);
5456 tcg_temp_free_i32(tcg_rn);
5464 /* Floating point data-processing (1 source)
5465 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
5466 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5467 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
5468 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5470 static void disas_fp_1src(DisasContext *s, uint32_t insn)
5472 int type = extract32(insn, 22, 2);
5473 int opcode = extract32(insn, 15, 6);
5474 int rn = extract32(insn, 5, 5);
5475 int rd = extract32(insn, 0, 5);
5478 case 0x4: case 0x5: case 0x7:
5480 /* FCVT between half, single and double precision */
5481 int dtype = extract32(opcode, 0, 2);
5482 if (type == 2 || dtype == type) {
5483 unallocated_encoding(s);
5486 if (!fp_access_check(s)) {
5490 handle_fp_fcvt(s, opcode, rd, rn, dtype, type);
5496 /* 32-to-32 and 64-to-64 ops */
5499 if (!fp_access_check(s)) {
5503 handle_fp_1src_single(s, opcode, rd, rn);
5506 if (!fp_access_check(s)) {
5510 handle_fp_1src_double(s, opcode, rd, rn);
5513 if (!dc_isar_feature(aa64_fp16, s)) {
5514 unallocated_encoding(s);
5518 if (!fp_access_check(s)) {
5522 handle_fp_1src_half(s, opcode, rd, rn);
5525 unallocated_encoding(s);
5529 unallocated_encoding(s);
5534 /* Floating-point data-processing (2 source) - single precision */
5535 static void handle_fp_2src_single(DisasContext *s, int opcode,
5536 int rd, int rn, int rm)
5543 tcg_res = tcg_temp_new_i32();
5544 fpst = get_fpstatus_ptr(false);
5545 tcg_op1 = read_fp_sreg(s, rn);
5546 tcg_op2 = read_fp_sreg(s, rm);
5549 case 0x0: /* FMUL */
5550 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
5552 case 0x1: /* FDIV */
5553 gen_helper_vfp_divs(tcg_res, tcg_op1, tcg_op2, fpst);
5555 case 0x2: /* FADD */
5556 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
5558 case 0x3: /* FSUB */
5559 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
5561 case 0x4: /* FMAX */
5562 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
5564 case 0x5: /* FMIN */
5565 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
5567 case 0x6: /* FMAXNM */
5568 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
5570 case 0x7: /* FMINNM */
5571 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
5573 case 0x8: /* FNMUL */
5574 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
5575 gen_helper_vfp_negs(tcg_res, tcg_res);
5579 write_fp_sreg(s, rd, tcg_res);
5581 tcg_temp_free_ptr(fpst);
5582 tcg_temp_free_i32(tcg_op1);
5583 tcg_temp_free_i32(tcg_op2);
5584 tcg_temp_free_i32(tcg_res);
5587 /* Floating-point data-processing (2 source) - double precision */
5588 static void handle_fp_2src_double(DisasContext *s, int opcode,
5589 int rd, int rn, int rm)
5596 tcg_res = tcg_temp_new_i64();
5597 fpst = get_fpstatus_ptr(false);
5598 tcg_op1 = read_fp_dreg(s, rn);
5599 tcg_op2 = read_fp_dreg(s, rm);
5602 case 0x0: /* FMUL */
5603 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
5605 case 0x1: /* FDIV */
5606 gen_helper_vfp_divd(tcg_res, tcg_op1, tcg_op2, fpst);
5608 case 0x2: /* FADD */
5609 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
5611 case 0x3: /* FSUB */
5612 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
5614 case 0x4: /* FMAX */
5615 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
5617 case 0x5: /* FMIN */
5618 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
5620 case 0x6: /* FMAXNM */
5621 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
5623 case 0x7: /* FMINNM */
5624 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
5626 case 0x8: /* FNMUL */
5627 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
5628 gen_helper_vfp_negd(tcg_res, tcg_res);
5632 write_fp_dreg(s, rd, tcg_res);
5634 tcg_temp_free_ptr(fpst);
5635 tcg_temp_free_i64(tcg_op1);
5636 tcg_temp_free_i64(tcg_op2);
5637 tcg_temp_free_i64(tcg_res);
5640 /* Floating-point data-processing (2 source) - half precision */
5641 static void handle_fp_2src_half(DisasContext *s, int opcode,
5642 int rd, int rn, int rm)
5649 tcg_res = tcg_temp_new_i32();
5650 fpst = get_fpstatus_ptr(true);
5651 tcg_op1 = read_fp_hreg(s, rn);
5652 tcg_op2 = read_fp_hreg(s, rm);
5655 case 0x0: /* FMUL */
5656 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
5658 case 0x1: /* FDIV */
5659 gen_helper_advsimd_divh(tcg_res, tcg_op1, tcg_op2, fpst);
5661 case 0x2: /* FADD */
5662 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
5664 case 0x3: /* FSUB */
5665 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
5667 case 0x4: /* FMAX */
5668 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
5670 case 0x5: /* FMIN */
5671 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
5673 case 0x6: /* FMAXNM */
5674 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
5676 case 0x7: /* FMINNM */
5677 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
5679 case 0x8: /* FNMUL */
5680 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
5681 tcg_gen_xori_i32(tcg_res, tcg_res, 0x8000);
5684 g_assert_not_reached();
5687 write_fp_sreg(s, rd, tcg_res);
5689 tcg_temp_free_ptr(fpst);
5690 tcg_temp_free_i32(tcg_op1);
5691 tcg_temp_free_i32(tcg_op2);
5692 tcg_temp_free_i32(tcg_res);
5695 /* Floating point data-processing (2 source)
5696 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5697 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5698 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
5699 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5701 static void disas_fp_2src(DisasContext *s, uint32_t insn)
5703 int type = extract32(insn, 22, 2);
5704 int rd = extract32(insn, 0, 5);
5705 int rn = extract32(insn, 5, 5);
5706 int rm = extract32(insn, 16, 5);
5707 int opcode = extract32(insn, 12, 4);
5710 unallocated_encoding(s);
5716 if (!fp_access_check(s)) {
5719 handle_fp_2src_single(s, opcode, rd, rn, rm);
5722 if (!fp_access_check(s)) {
5725 handle_fp_2src_double(s, opcode, rd, rn, rm);
5728 if (!dc_isar_feature(aa64_fp16, s)) {
5729 unallocated_encoding(s);
5732 if (!fp_access_check(s)) {
5735 handle_fp_2src_half(s, opcode, rd, rn, rm);
5738 unallocated_encoding(s);
5742 /* Floating-point data-processing (3 source) - single precision */
5743 static void handle_fp_3src_single(DisasContext *s, bool o0, bool o1,
5744 int rd, int rn, int rm, int ra)
5746 TCGv_i32 tcg_op1, tcg_op2, tcg_op3;
5747 TCGv_i32 tcg_res = tcg_temp_new_i32();
5748 TCGv_ptr fpst = get_fpstatus_ptr(false);
5750 tcg_op1 = read_fp_sreg(s, rn);
5751 tcg_op2 = read_fp_sreg(s, rm);
5752 tcg_op3 = read_fp_sreg(s, ra);
5754 /* These are fused multiply-add, and must be done as one
5755 * floating point operation with no rounding between the
5756 * multiplication and addition steps.
5757 * NB that doing the negations here as separate steps is
5758 * correct : an input NaN should come out with its sign bit
5759 * flipped if it is a negated-input.
5762 gen_helper_vfp_negs(tcg_op3, tcg_op3);
5766 gen_helper_vfp_negs(tcg_op1, tcg_op1);
5769 gen_helper_vfp_muladds(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
5771 write_fp_sreg(s, rd, tcg_res);
5773 tcg_temp_free_ptr(fpst);
5774 tcg_temp_free_i32(tcg_op1);
5775 tcg_temp_free_i32(tcg_op2);
5776 tcg_temp_free_i32(tcg_op3);
5777 tcg_temp_free_i32(tcg_res);
5780 /* Floating-point data-processing (3 source) - double precision */
5781 static void handle_fp_3src_double(DisasContext *s, bool o0, bool o1,
5782 int rd, int rn, int rm, int ra)
5784 TCGv_i64 tcg_op1, tcg_op2, tcg_op3;
5785 TCGv_i64 tcg_res = tcg_temp_new_i64();
5786 TCGv_ptr fpst = get_fpstatus_ptr(false);
5788 tcg_op1 = read_fp_dreg(s, rn);
5789 tcg_op2 = read_fp_dreg(s, rm);
5790 tcg_op3 = read_fp_dreg(s, ra);
5792 /* These are fused multiply-add, and must be done as one
5793 * floating point operation with no rounding between the
5794 * multiplication and addition steps.
5795 * NB that doing the negations here as separate steps is
5796 * correct : an input NaN should come out with its sign bit
5797 * flipped if it is a negated-input.
5800 gen_helper_vfp_negd(tcg_op3, tcg_op3);
5804 gen_helper_vfp_negd(tcg_op1, tcg_op1);
5807 gen_helper_vfp_muladdd(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
5809 write_fp_dreg(s, rd, tcg_res);
5811 tcg_temp_free_ptr(fpst);
5812 tcg_temp_free_i64(tcg_op1);
5813 tcg_temp_free_i64(tcg_op2);
5814 tcg_temp_free_i64(tcg_op3);
5815 tcg_temp_free_i64(tcg_res);
5818 /* Floating-point data-processing (3 source) - half precision */
5819 static void handle_fp_3src_half(DisasContext *s, bool o0, bool o1,
5820 int rd, int rn, int rm, int ra)
5822 TCGv_i32 tcg_op1, tcg_op2, tcg_op3;
5823 TCGv_i32 tcg_res = tcg_temp_new_i32();
5824 TCGv_ptr fpst = get_fpstatus_ptr(true);
5826 tcg_op1 = read_fp_hreg(s, rn);
5827 tcg_op2 = read_fp_hreg(s, rm);
5828 tcg_op3 = read_fp_hreg(s, ra);
5830 /* These are fused multiply-add, and must be done as one
5831 * floating point operation with no rounding between the
5832 * multiplication and addition steps.
5833 * NB that doing the negations here as separate steps is
5834 * correct : an input NaN should come out with its sign bit
5835 * flipped if it is a negated-input.
5838 tcg_gen_xori_i32(tcg_op3, tcg_op3, 0x8000);
5842 tcg_gen_xori_i32(tcg_op1, tcg_op1, 0x8000);
5845 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
5847 write_fp_sreg(s, rd, tcg_res);
5849 tcg_temp_free_ptr(fpst);
5850 tcg_temp_free_i32(tcg_op1);
5851 tcg_temp_free_i32(tcg_op2);
5852 tcg_temp_free_i32(tcg_op3);
5853 tcg_temp_free_i32(tcg_res);
5856 /* Floating point data-processing (3 source)
5857 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
5858 * +---+---+---+-----------+------+----+------+----+------+------+------+
5859 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
5860 * +---+---+---+-----------+------+----+------+----+------+------+------+
5862 static void disas_fp_3src(DisasContext *s, uint32_t insn)
5864 int type = extract32(insn, 22, 2);
5865 int rd = extract32(insn, 0, 5);
5866 int rn = extract32(insn, 5, 5);
5867 int ra = extract32(insn, 10, 5);
5868 int rm = extract32(insn, 16, 5);
5869 bool o0 = extract32(insn, 15, 1);
5870 bool o1 = extract32(insn, 21, 1);
5874 if (!fp_access_check(s)) {
5877 handle_fp_3src_single(s, o0, o1, rd, rn, rm, ra);
5880 if (!fp_access_check(s)) {
5883 handle_fp_3src_double(s, o0, o1, rd, rn, rm, ra);
5886 if (!dc_isar_feature(aa64_fp16, s)) {
5887 unallocated_encoding(s);
5890 if (!fp_access_check(s)) {
5893 handle_fp_3src_half(s, o0, o1, rd, rn, rm, ra);
5896 unallocated_encoding(s);
5900 /* The imm8 encodes the sign bit, enough bits to represent an exponent in
5901 * the range 01....1xx to 10....0xx, and the most significant 4 bits of
5902 * the mantissa; see VFPExpandImm() in the v8 ARM ARM.
5904 uint64_t vfp_expand_imm(int size, uint8_t imm8)
5910 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
5911 (extract32(imm8, 6, 1) ? 0x3fc0 : 0x4000) |
5912 extract32(imm8, 0, 6);
5916 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
5917 (extract32(imm8, 6, 1) ? 0x3e00 : 0x4000) |
5918 (extract32(imm8, 0, 6) << 3);
5922 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
5923 (extract32(imm8, 6, 1) ? 0x3000 : 0x4000) |
5924 (extract32(imm8, 0, 6) << 6);
5927 g_assert_not_reached();
5932 /* Floating point immediate
5933 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
5934 * +---+---+---+-----------+------+---+------------+-------+------+------+
5935 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
5936 * +---+---+---+-----------+------+---+------------+-------+------+------+
5938 static void disas_fp_imm(DisasContext *s, uint32_t insn)
5940 int rd = extract32(insn, 0, 5);
5941 int imm8 = extract32(insn, 13, 8);
5942 int type = extract32(insn, 22, 2);
5956 if (dc_isar_feature(aa64_fp16, s)) {
5961 unallocated_encoding(s);
5965 if (!fp_access_check(s)) {
5969 imm = vfp_expand_imm(sz, imm8);
5971 tcg_res = tcg_const_i64(imm);
5972 write_fp_dreg(s, rd, tcg_res);
5973 tcg_temp_free_i64(tcg_res);
5976 /* Handle floating point <=> fixed point conversions. Note that we can
5977 * also deal with fp <=> integer conversions as a special case (scale == 64)
5978 * OPTME: consider handling that special case specially or at least skipping
5979 * the call to scalbn in the helpers for zero shifts.
5981 static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode,
5982 bool itof, int rmode, int scale, int sf, int type)
5984 bool is_signed = !(opcode & 1);
5985 TCGv_ptr tcg_fpstatus;
5986 TCGv_i32 tcg_shift, tcg_single;
5987 TCGv_i64 tcg_double;
5989 tcg_fpstatus = get_fpstatus_ptr(type == 3);
5991 tcg_shift = tcg_const_i32(64 - scale);
5994 TCGv_i64 tcg_int = cpu_reg(s, rn);
5996 TCGv_i64 tcg_extend = new_tmp_a64(s);
5999 tcg_gen_ext32s_i64(tcg_extend, tcg_int);
6001 tcg_gen_ext32u_i64(tcg_extend, tcg_int);
6004 tcg_int = tcg_extend;
6008 case 1: /* float64 */
6009 tcg_double = tcg_temp_new_i64();
6011 gen_helper_vfp_sqtod(tcg_double, tcg_int,
6012 tcg_shift, tcg_fpstatus);
6014 gen_helper_vfp_uqtod(tcg_double, tcg_int,
6015 tcg_shift, tcg_fpstatus);
6017 write_fp_dreg(s, rd, tcg_double);
6018 tcg_temp_free_i64(tcg_double);
6021 case 0: /* float32 */
6022 tcg_single = tcg_temp_new_i32();
6024 gen_helper_vfp_sqtos(tcg_single, tcg_int,
6025 tcg_shift, tcg_fpstatus);
6027 gen_helper_vfp_uqtos(tcg_single, tcg_int,
6028 tcg_shift, tcg_fpstatus);
6030 write_fp_sreg(s, rd, tcg_single);
6031 tcg_temp_free_i32(tcg_single);
6034 case 3: /* float16 */
6035 tcg_single = tcg_temp_new_i32();
6037 gen_helper_vfp_sqtoh(tcg_single, tcg_int,
6038 tcg_shift, tcg_fpstatus);
6040 gen_helper_vfp_uqtoh(tcg_single, tcg_int,
6041 tcg_shift, tcg_fpstatus);
6043 write_fp_sreg(s, rd, tcg_single);
6044 tcg_temp_free_i32(tcg_single);
6048 g_assert_not_reached();
6051 TCGv_i64 tcg_int = cpu_reg(s, rd);
6054 if (extract32(opcode, 2, 1)) {
6055 /* There are too many rounding modes to all fit into rmode,
6056 * so FCVTA[US] is a special case.
6058 rmode = FPROUNDING_TIEAWAY;
6061 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
6063 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
6066 case 1: /* float64 */
6067 tcg_double = read_fp_dreg(s, rn);
6070 gen_helper_vfp_tosld(tcg_int, tcg_double,
6071 tcg_shift, tcg_fpstatus);
6073 gen_helper_vfp_tosqd(tcg_int, tcg_double,
6074 tcg_shift, tcg_fpstatus);
6078 gen_helper_vfp_tould(tcg_int, tcg_double,
6079 tcg_shift, tcg_fpstatus);
6081 gen_helper_vfp_touqd(tcg_int, tcg_double,
6082 tcg_shift, tcg_fpstatus);
6086 tcg_gen_ext32u_i64(tcg_int, tcg_int);
6088 tcg_temp_free_i64(tcg_double);
6091 case 0: /* float32 */
6092 tcg_single = read_fp_sreg(s, rn);
6095 gen_helper_vfp_tosqs(tcg_int, tcg_single,
6096 tcg_shift, tcg_fpstatus);
6098 gen_helper_vfp_touqs(tcg_int, tcg_single,
6099 tcg_shift, tcg_fpstatus);
6102 TCGv_i32 tcg_dest = tcg_temp_new_i32();
6104 gen_helper_vfp_tosls(tcg_dest, tcg_single,
6105 tcg_shift, tcg_fpstatus);
6107 gen_helper_vfp_touls(tcg_dest, tcg_single,
6108 tcg_shift, tcg_fpstatus);
6110 tcg_gen_extu_i32_i64(tcg_int, tcg_dest);
6111 tcg_temp_free_i32(tcg_dest);
6113 tcg_temp_free_i32(tcg_single);
6116 case 3: /* float16 */
6117 tcg_single = read_fp_sreg(s, rn);
6120 gen_helper_vfp_tosqh(tcg_int, tcg_single,
6121 tcg_shift, tcg_fpstatus);
6123 gen_helper_vfp_touqh(tcg_int, tcg_single,
6124 tcg_shift, tcg_fpstatus);
6127 TCGv_i32 tcg_dest = tcg_temp_new_i32();
6129 gen_helper_vfp_toslh(tcg_dest, tcg_single,
6130 tcg_shift, tcg_fpstatus);
6132 gen_helper_vfp_toulh(tcg_dest, tcg_single,
6133 tcg_shift, tcg_fpstatus);
6135 tcg_gen_extu_i32_i64(tcg_int, tcg_dest);
6136 tcg_temp_free_i32(tcg_dest);
6138 tcg_temp_free_i32(tcg_single);
6142 g_assert_not_reached();
6145 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
6146 tcg_temp_free_i32(tcg_rmode);
6149 tcg_temp_free_ptr(tcg_fpstatus);
6150 tcg_temp_free_i32(tcg_shift);
6153 /* Floating point <-> fixed point conversions
6154 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6155 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6156 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
6157 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6159 static void disas_fp_fixed_conv(DisasContext *s, uint32_t insn)
6161 int rd = extract32(insn, 0, 5);
6162 int rn = extract32(insn, 5, 5);
6163 int scale = extract32(insn, 10, 6);
6164 int opcode = extract32(insn, 16, 3);
6165 int rmode = extract32(insn, 19, 2);
6166 int type = extract32(insn, 22, 2);
6167 bool sbit = extract32(insn, 29, 1);
6168 bool sf = extract32(insn, 31, 1);
6171 if (sbit || (!sf && scale < 32)) {
6172 unallocated_encoding(s);
6177 case 0: /* float32 */
6178 case 1: /* float64 */
6180 case 3: /* float16 */
6181 if (dc_isar_feature(aa64_fp16, s)) {
6186 unallocated_encoding(s);
6190 switch ((rmode << 3) | opcode) {
6191 case 0x2: /* SCVTF */
6192 case 0x3: /* UCVTF */
6195 case 0x18: /* FCVTZS */
6196 case 0x19: /* FCVTZU */
6200 unallocated_encoding(s);
6204 if (!fp_access_check(s)) {
6208 handle_fpfpcvt(s, rd, rn, opcode, itof, FPROUNDING_ZERO, scale, sf, type);
6211 static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof)
6213 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
6214 * without conversion.
6218 TCGv_i64 tcg_rn = cpu_reg(s, rn);
6224 tmp = tcg_temp_new_i64();
6225 tcg_gen_ext32u_i64(tmp, tcg_rn);
6226 write_fp_dreg(s, rd, tmp);
6227 tcg_temp_free_i64(tmp);
6231 write_fp_dreg(s, rd, tcg_rn);
6234 /* 64 bit to top half. */
6235 tcg_gen_st_i64(tcg_rn, cpu_env, fp_reg_hi_offset(s, rd));
6236 clear_vec_high(s, true, rd);
6240 tmp = tcg_temp_new_i64();
6241 tcg_gen_ext16u_i64(tmp, tcg_rn);
6242 write_fp_dreg(s, rd, tmp);
6243 tcg_temp_free_i64(tmp);
6246 g_assert_not_reached();
6249 TCGv_i64 tcg_rd = cpu_reg(s, rd);
6254 tcg_gen_ld32u_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_32));
6258 tcg_gen_ld_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_64));
6261 /* 64 bits from top half */
6262 tcg_gen_ld_i64(tcg_rd, cpu_env, fp_reg_hi_offset(s, rn));
6266 tcg_gen_ld16u_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_16));
6269 g_assert_not_reached();
6274 /* Floating point <-> integer conversions
6275 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6276 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6277 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
6278 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6280 static void disas_fp_int_conv(DisasContext *s, uint32_t insn)
6282 int rd = extract32(insn, 0, 5);
6283 int rn = extract32(insn, 5, 5);
6284 int opcode = extract32(insn, 16, 3);
6285 int rmode = extract32(insn, 19, 2);
6286 int type = extract32(insn, 22, 2);
6287 bool sbit = extract32(insn, 29, 1);
6288 bool sf = extract32(insn, 31, 1);
6291 unallocated_encoding(s);
6297 bool itof = opcode & 1;
6300 unallocated_encoding(s);
6304 switch (sf << 3 | type << 1 | rmode) {
6305 case 0x0: /* 32 bit */
6306 case 0xa: /* 64 bit */
6307 case 0xd: /* 64 bit to top half of quad */
6309 case 0x6: /* 16-bit float, 32-bit int */
6310 case 0xe: /* 16-bit float, 64-bit int */
6311 if (dc_isar_feature(aa64_fp16, s)) {
6316 /* all other sf/type/rmode combinations are invalid */
6317 unallocated_encoding(s);
6321 if (!fp_access_check(s)) {
6324 handle_fmov(s, rd, rn, type, itof);
6326 /* actual FP conversions */
6327 bool itof = extract32(opcode, 1, 1);
6329 if (rmode != 0 && opcode > 1) {
6330 unallocated_encoding(s);
6334 case 0: /* float32 */
6335 case 1: /* float64 */
6337 case 3: /* float16 */
6338 if (dc_isar_feature(aa64_fp16, s)) {
6343 unallocated_encoding(s);
6347 if (!fp_access_check(s)) {
6350 handle_fpfpcvt(s, rd, rn, opcode, itof, rmode, 64, sf, type);
6354 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
6355 * 31 30 29 28 25 24 0
6356 * +---+---+---+---------+-----------------------------+
6357 * | | 0 | | 1 1 1 1 | |
6358 * +---+---+---+---------+-----------------------------+
6360 static void disas_data_proc_fp(DisasContext *s, uint32_t insn)
6362 if (extract32(insn, 24, 1)) {
6363 /* Floating point data-processing (3 source) */
6364 disas_fp_3src(s, insn);
6365 } else if (extract32(insn, 21, 1) == 0) {
6366 /* Floating point to fixed point conversions */
6367 disas_fp_fixed_conv(s, insn);
6369 switch (extract32(insn, 10, 2)) {
6371 /* Floating point conditional compare */
6372 disas_fp_ccomp(s, insn);
6375 /* Floating point data-processing (2 source) */
6376 disas_fp_2src(s, insn);
6379 /* Floating point conditional select */
6380 disas_fp_csel(s, insn);
6383 switch (ctz32(extract32(insn, 12, 4))) {
6384 case 0: /* [15:12] == xxx1 */
6385 /* Floating point immediate */
6386 disas_fp_imm(s, insn);
6388 case 1: /* [15:12] == xx10 */
6389 /* Floating point compare */
6390 disas_fp_compare(s, insn);
6392 case 2: /* [15:12] == x100 */
6393 /* Floating point data-processing (1 source) */
6394 disas_fp_1src(s, insn);
6396 case 3: /* [15:12] == 1000 */
6397 unallocated_encoding(s);
6399 default: /* [15:12] == 0000 */
6400 /* Floating point <-> integer conversions */
6401 disas_fp_int_conv(s, insn);
6409 static void do_ext64(DisasContext *s, TCGv_i64 tcg_left, TCGv_i64 tcg_right,
6412 /* Extract 64 bits from the middle of two concatenated 64 bit
6413 * vector register slices left:right. The extracted bits start
6414 * at 'pos' bits into the right (least significant) side.
6415 * We return the result in tcg_right, and guarantee not to
6418 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
6419 assert(pos > 0 && pos < 64);
6421 tcg_gen_shri_i64(tcg_right, tcg_right, pos);
6422 tcg_gen_shli_i64(tcg_tmp, tcg_left, 64 - pos);
6423 tcg_gen_or_i64(tcg_right, tcg_right, tcg_tmp);
6425 tcg_temp_free_i64(tcg_tmp);
6429 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
6430 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6431 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
6432 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6434 static void disas_simd_ext(DisasContext *s, uint32_t insn)
6436 int is_q = extract32(insn, 30, 1);
6437 int op2 = extract32(insn, 22, 2);
6438 int imm4 = extract32(insn, 11, 4);
6439 int rm = extract32(insn, 16, 5);
6440 int rn = extract32(insn, 5, 5);
6441 int rd = extract32(insn, 0, 5);
6442 int pos = imm4 << 3;
6443 TCGv_i64 tcg_resl, tcg_resh;
6445 if (op2 != 0 || (!is_q && extract32(imm4, 3, 1))) {
6446 unallocated_encoding(s);
6450 if (!fp_access_check(s)) {
6454 tcg_resh = tcg_temp_new_i64();
6455 tcg_resl = tcg_temp_new_i64();
6457 /* Vd gets bits starting at pos bits into Vm:Vn. This is
6458 * either extracting 128 bits from a 128:128 concatenation, or
6459 * extracting 64 bits from a 64:64 concatenation.
6462 read_vec_element(s, tcg_resl, rn, 0, MO_64);
6464 read_vec_element(s, tcg_resh, rm, 0, MO_64);
6465 do_ext64(s, tcg_resh, tcg_resl, pos);
6467 tcg_gen_movi_i64(tcg_resh, 0);
6474 EltPosns eltposns[] = { {rn, 0}, {rn, 1}, {rm, 0}, {rm, 1} };
6475 EltPosns *elt = eltposns;
6482 read_vec_element(s, tcg_resl, elt->reg, elt->elt, MO_64);
6484 read_vec_element(s, tcg_resh, elt->reg, elt->elt, MO_64);
6487 do_ext64(s, tcg_resh, tcg_resl, pos);
6488 tcg_hh = tcg_temp_new_i64();
6489 read_vec_element(s, tcg_hh, elt->reg, elt->elt, MO_64);
6490 do_ext64(s, tcg_hh, tcg_resh, pos);
6491 tcg_temp_free_i64(tcg_hh);
6495 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6496 tcg_temp_free_i64(tcg_resl);
6497 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6498 tcg_temp_free_i64(tcg_resh);
6502 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
6503 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6504 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
6505 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6507 static void disas_simd_tb(DisasContext *s, uint32_t insn)
6509 int op2 = extract32(insn, 22, 2);
6510 int is_q = extract32(insn, 30, 1);
6511 int rm = extract32(insn, 16, 5);
6512 int rn = extract32(insn, 5, 5);
6513 int rd = extract32(insn, 0, 5);
6514 int is_tblx = extract32(insn, 12, 1);
6515 int len = extract32(insn, 13, 2);
6516 TCGv_i64 tcg_resl, tcg_resh, tcg_idx;
6517 TCGv_i32 tcg_regno, tcg_numregs;
6520 unallocated_encoding(s);
6524 if (!fp_access_check(s)) {
6528 /* This does a table lookup: for every byte element in the input
6529 * we index into a table formed from up to four vector registers,
6530 * and then the output is the result of the lookups. Our helper
6531 * function does the lookup operation for a single 64 bit part of
6534 tcg_resl = tcg_temp_new_i64();
6535 tcg_resh = tcg_temp_new_i64();
6538 read_vec_element(s, tcg_resl, rd, 0, MO_64);
6540 tcg_gen_movi_i64(tcg_resl, 0);
6542 if (is_tblx && is_q) {
6543 read_vec_element(s, tcg_resh, rd, 1, MO_64);
6545 tcg_gen_movi_i64(tcg_resh, 0);
6548 tcg_idx = tcg_temp_new_i64();
6549 tcg_regno = tcg_const_i32(rn);
6550 tcg_numregs = tcg_const_i32(len + 1);
6551 read_vec_element(s, tcg_idx, rm, 0, MO_64);
6552 gen_helper_simd_tbl(tcg_resl, cpu_env, tcg_resl, tcg_idx,
6553 tcg_regno, tcg_numregs);
6555 read_vec_element(s, tcg_idx, rm, 1, MO_64);
6556 gen_helper_simd_tbl(tcg_resh, cpu_env, tcg_resh, tcg_idx,
6557 tcg_regno, tcg_numregs);
6559 tcg_temp_free_i64(tcg_idx);
6560 tcg_temp_free_i32(tcg_regno);
6561 tcg_temp_free_i32(tcg_numregs);
6563 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6564 tcg_temp_free_i64(tcg_resl);
6565 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6566 tcg_temp_free_i64(tcg_resh);
6570 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
6571 * +---+---+-------------+------+---+------+---+------------------+------+
6572 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
6573 * +---+---+-------------+------+---+------+---+------------------+------+
6575 static void disas_simd_zip_trn(DisasContext *s, uint32_t insn)
6577 int rd = extract32(insn, 0, 5);
6578 int rn = extract32(insn, 5, 5);
6579 int rm = extract32(insn, 16, 5);
6580 int size = extract32(insn, 22, 2);
6581 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
6582 * bit 2 indicates 1 vs 2 variant of the insn.
6584 int opcode = extract32(insn, 12, 2);
6585 bool part = extract32(insn, 14, 1);
6586 bool is_q = extract32(insn, 30, 1);
6587 int esize = 8 << size;
6589 int datasize = is_q ? 128 : 64;
6590 int elements = datasize / esize;
6591 TCGv_i64 tcg_res, tcg_resl, tcg_resh;
6593 if (opcode == 0 || (size == 3 && !is_q)) {
6594 unallocated_encoding(s);
6598 if (!fp_access_check(s)) {
6602 tcg_resl = tcg_const_i64(0);
6603 tcg_resh = tcg_const_i64(0);
6604 tcg_res = tcg_temp_new_i64();
6606 for (i = 0; i < elements; i++) {
6608 case 1: /* UZP1/2 */
6610 int midpoint = elements / 2;
6612 read_vec_element(s, tcg_res, rn, 2 * i + part, size);
6614 read_vec_element(s, tcg_res, rm,
6615 2 * (i - midpoint) + part, size);
6619 case 2: /* TRN1/2 */
6621 read_vec_element(s, tcg_res, rm, (i & ~1) + part, size);
6623 read_vec_element(s, tcg_res, rn, (i & ~1) + part, size);
6626 case 3: /* ZIP1/2 */
6628 int base = part * elements / 2;
6630 read_vec_element(s, tcg_res, rm, base + (i >> 1), size);
6632 read_vec_element(s, tcg_res, rn, base + (i >> 1), size);
6637 g_assert_not_reached();
6642 tcg_gen_shli_i64(tcg_res, tcg_res, ofs);
6643 tcg_gen_or_i64(tcg_resl, tcg_resl, tcg_res);
6645 tcg_gen_shli_i64(tcg_res, tcg_res, ofs - 64);
6646 tcg_gen_or_i64(tcg_resh, tcg_resh, tcg_res);
6650 tcg_temp_free_i64(tcg_res);
6652 write_vec_element(s, tcg_resl, rd, 0, MO_64);
6653 tcg_temp_free_i64(tcg_resl);
6654 write_vec_element(s, tcg_resh, rd, 1, MO_64);
6655 tcg_temp_free_i64(tcg_resh);
6659 * do_reduction_op helper
6661 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
6662 * important for correct NaN propagation that we do these
6663 * operations in exactly the order specified by the pseudocode.
6665 * This is a recursive function, TCG temps should be freed by the
6666 * calling function once it is done with the values.
6668 static TCGv_i32 do_reduction_op(DisasContext *s, int fpopcode, int rn,
6669 int esize, int size, int vmap, TCGv_ptr fpst)
6671 if (esize == size) {
6673 TCGMemOp msize = esize == 16 ? MO_16 : MO_32;
6676 /* We should have one register left here */
6677 assert(ctpop8(vmap) == 1);
6678 element = ctz32(vmap);
6679 assert(element < 8);
6681 tcg_elem = tcg_temp_new_i32();
6682 read_vec_element_i32(s, tcg_elem, rn, element, msize);
6685 int bits = size / 2;
6686 int shift = ctpop8(vmap) / 2;
6687 int vmap_lo = (vmap >> shift) & vmap;
6688 int vmap_hi = (vmap & ~vmap_lo);
6689 TCGv_i32 tcg_hi, tcg_lo, tcg_res;
6691 tcg_hi = do_reduction_op(s, fpopcode, rn, esize, bits, vmap_hi, fpst);
6692 tcg_lo = do_reduction_op(s, fpopcode, rn, esize, bits, vmap_lo, fpst);
6693 tcg_res = tcg_temp_new_i32();
6696 case 0x0c: /* fmaxnmv half-precision */
6697 gen_helper_advsimd_maxnumh(tcg_res, tcg_lo, tcg_hi, fpst);
6699 case 0x0f: /* fmaxv half-precision */
6700 gen_helper_advsimd_maxh(tcg_res, tcg_lo, tcg_hi, fpst);
6702 case 0x1c: /* fminnmv half-precision */
6703 gen_helper_advsimd_minnumh(tcg_res, tcg_lo, tcg_hi, fpst);
6705 case 0x1f: /* fminv half-precision */
6706 gen_helper_advsimd_minh(tcg_res, tcg_lo, tcg_hi, fpst);
6708 case 0x2c: /* fmaxnmv */
6709 gen_helper_vfp_maxnums(tcg_res, tcg_lo, tcg_hi, fpst);
6711 case 0x2f: /* fmaxv */
6712 gen_helper_vfp_maxs(tcg_res, tcg_lo, tcg_hi, fpst);
6714 case 0x3c: /* fminnmv */
6715 gen_helper_vfp_minnums(tcg_res, tcg_lo, tcg_hi, fpst);
6717 case 0x3f: /* fminv */
6718 gen_helper_vfp_mins(tcg_res, tcg_lo, tcg_hi, fpst);
6721 g_assert_not_reached();
6724 tcg_temp_free_i32(tcg_hi);
6725 tcg_temp_free_i32(tcg_lo);
6730 /* AdvSIMD across lanes
6731 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6732 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6733 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6734 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6736 static void disas_simd_across_lanes(DisasContext *s, uint32_t insn)
6738 int rd = extract32(insn, 0, 5);
6739 int rn = extract32(insn, 5, 5);
6740 int size = extract32(insn, 22, 2);
6741 int opcode = extract32(insn, 12, 5);
6742 bool is_q = extract32(insn, 30, 1);
6743 bool is_u = extract32(insn, 29, 1);
6745 bool is_min = false;
6749 TCGv_i64 tcg_res, tcg_elt;
6752 case 0x1b: /* ADDV */
6754 unallocated_encoding(s);
6758 case 0x3: /* SADDLV, UADDLV */
6759 case 0xa: /* SMAXV, UMAXV */
6760 case 0x1a: /* SMINV, UMINV */
6761 if (size == 3 || (size == 2 && !is_q)) {
6762 unallocated_encoding(s);
6766 case 0xc: /* FMAXNMV, FMINNMV */
6767 case 0xf: /* FMAXV, FMINV */
6768 /* Bit 1 of size field encodes min vs max and the actual size
6769 * depends on the encoding of the U bit. If not set (and FP16
6770 * enabled) then we do half-precision float instead of single
6773 is_min = extract32(size, 1, 1);
6775 if (!is_u && dc_isar_feature(aa64_fp16, s)) {
6777 } else if (!is_u || !is_q || extract32(size, 0, 1)) {
6778 unallocated_encoding(s);
6785 unallocated_encoding(s);
6789 if (!fp_access_check(s)) {
6794 elements = (is_q ? 128 : 64) / esize;
6796 tcg_res = tcg_temp_new_i64();
6797 tcg_elt = tcg_temp_new_i64();
6799 /* These instructions operate across all lanes of a vector
6800 * to produce a single result. We can guarantee that a 64
6801 * bit intermediate is sufficient:
6802 * + for [US]ADDLV the maximum element size is 32 bits, and
6803 * the result type is 64 bits
6804 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
6805 * same as the element size, which is 32 bits at most
6806 * For the integer operations we can choose to work at 64
6807 * or 32 bits and truncate at the end; for simplicity
6808 * we use 64 bits always. The floating point
6809 * ops do require 32 bit intermediates, though.
6812 read_vec_element(s, tcg_res, rn, 0, size | (is_u ? 0 : MO_SIGN));
6814 for (i = 1; i < elements; i++) {
6815 read_vec_element(s, tcg_elt, rn, i, size | (is_u ? 0 : MO_SIGN));
6818 case 0x03: /* SADDLV / UADDLV */
6819 case 0x1b: /* ADDV */
6820 tcg_gen_add_i64(tcg_res, tcg_res, tcg_elt);
6822 case 0x0a: /* SMAXV / UMAXV */
6824 tcg_gen_umax_i64(tcg_res, tcg_res, tcg_elt);
6826 tcg_gen_smax_i64(tcg_res, tcg_res, tcg_elt);
6829 case 0x1a: /* SMINV / UMINV */
6831 tcg_gen_umin_i64(tcg_res, tcg_res, tcg_elt);
6833 tcg_gen_smin_i64(tcg_res, tcg_res, tcg_elt);
6837 g_assert_not_reached();
6842 /* Floating point vector reduction ops which work across 32
6843 * bit (single) or 16 bit (half-precision) intermediates.
6844 * Note that correct NaN propagation requires that we do these
6845 * operations in exactly the order specified by the pseudocode.
6847 TCGv_ptr fpst = get_fpstatus_ptr(size == MO_16);
6848 int fpopcode = opcode | is_min << 4 | is_u << 5;
6849 int vmap = (1 << elements) - 1;
6850 TCGv_i32 tcg_res32 = do_reduction_op(s, fpopcode, rn, esize,
6851 (is_q ? 128 : 64), vmap, fpst);
6852 tcg_gen_extu_i32_i64(tcg_res, tcg_res32);
6853 tcg_temp_free_i32(tcg_res32);
6854 tcg_temp_free_ptr(fpst);
6857 tcg_temp_free_i64(tcg_elt);
6859 /* Now truncate the result to the width required for the final output */
6860 if (opcode == 0x03) {
6861 /* SADDLV, UADDLV: result is 2*esize */
6867 tcg_gen_ext8u_i64(tcg_res, tcg_res);
6870 tcg_gen_ext16u_i64(tcg_res, tcg_res);
6873 tcg_gen_ext32u_i64(tcg_res, tcg_res);
6878 g_assert_not_reached();
6881 write_fp_dreg(s, rd, tcg_res);
6882 tcg_temp_free_i64(tcg_res);
6885 /* DUP (Element, Vector)
6887 * 31 30 29 21 20 16 15 10 9 5 4 0
6888 * +---+---+-------------------+--------+-------------+------+------+
6889 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
6890 * +---+---+-------------------+--------+-------------+------+------+
6892 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6894 static void handle_simd_dupe(DisasContext *s, int is_q, int rd, int rn,
6897 int size = ctz32(imm5);
6898 int index = imm5 >> (size + 1);
6900 if (size > 3 || (size == 3 && !is_q)) {
6901 unallocated_encoding(s);
6905 if (!fp_access_check(s)) {
6909 tcg_gen_gvec_dup_mem(size, vec_full_reg_offset(s, rd),
6910 vec_reg_offset(s, rn, index, size),
6911 is_q ? 16 : 8, vec_full_reg_size(s));
6914 /* DUP (element, scalar)
6915 * 31 21 20 16 15 10 9 5 4 0
6916 * +-----------------------+--------+-------------+------+------+
6917 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
6918 * +-----------------------+--------+-------------+------+------+
6920 static void handle_simd_dupes(DisasContext *s, int rd, int rn,
6923 int size = ctz32(imm5);
6928 unallocated_encoding(s);
6932 if (!fp_access_check(s)) {
6936 index = imm5 >> (size + 1);
6938 /* This instruction just extracts the specified element and
6939 * zero-extends it into the bottom of the destination register.
6941 tmp = tcg_temp_new_i64();
6942 read_vec_element(s, tmp, rn, index, size);
6943 write_fp_dreg(s, rd, tmp);
6944 tcg_temp_free_i64(tmp);
6949 * 31 30 29 21 20 16 15 10 9 5 4 0
6950 * +---+---+-------------------+--------+-------------+------+------+
6951 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
6952 * +---+---+-------------------+--------+-------------+------+------+
6954 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6956 static void handle_simd_dupg(DisasContext *s, int is_q, int rd, int rn,
6959 int size = ctz32(imm5);
6960 uint32_t dofs, oprsz, maxsz;
6962 if (size > 3 || ((size == 3) && !is_q)) {
6963 unallocated_encoding(s);
6967 if (!fp_access_check(s)) {
6971 dofs = vec_full_reg_offset(s, rd);
6972 oprsz = is_q ? 16 : 8;
6973 maxsz = vec_full_reg_size(s);
6975 tcg_gen_gvec_dup_i64(size, dofs, oprsz, maxsz, cpu_reg(s, rn));
6980 * 31 21 20 16 15 14 11 10 9 5 4 0
6981 * +-----------------------+--------+------------+---+------+------+
6982 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6983 * +-----------------------+--------+------------+---+------+------+
6985 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6986 * index: encoded in imm5<4:size+1>
6988 static void handle_simd_inse(DisasContext *s, int rd, int rn,
6991 int size = ctz32(imm5);
6992 int src_index, dst_index;
6996 unallocated_encoding(s);
7000 if (!fp_access_check(s)) {
7004 dst_index = extract32(imm5, 1+size, 5);
7005 src_index = extract32(imm4, size, 4);
7007 tmp = tcg_temp_new_i64();
7009 read_vec_element(s, tmp, rn, src_index, size);
7010 write_vec_element(s, tmp, rd, dst_index, size);
7012 tcg_temp_free_i64(tmp);
7018 * 31 21 20 16 15 10 9 5 4 0
7019 * +-----------------------+--------+-------------+------+------+
7020 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
7021 * +-----------------------+--------+-------------+------+------+
7023 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7024 * index: encoded in imm5<4:size+1>
7026 static void handle_simd_insg(DisasContext *s, int rd, int rn, int imm5)
7028 int size = ctz32(imm5);
7032 unallocated_encoding(s);
7036 if (!fp_access_check(s)) {
7040 idx = extract32(imm5, 1 + size, 4 - size);
7041 write_vec_element(s, cpu_reg(s, rn), rd, idx, size);
7048 * 31 30 29 21 20 16 15 12 10 9 5 4 0
7049 * +---+---+-------------------+--------+-------------+------+------+
7050 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
7051 * +---+---+-------------------+--------+-------------+------+------+
7053 * U: unsigned when set
7054 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7056 static void handle_simd_umov_smov(DisasContext *s, int is_q, int is_signed,
7057 int rn, int rd, int imm5)
7059 int size = ctz32(imm5);
7063 /* Check for UnallocatedEncodings */
7065 if (size > 2 || (size == 2 && !is_q)) {
7066 unallocated_encoding(s);
7071 || (size < 3 && is_q)
7072 || (size == 3 && !is_q)) {
7073 unallocated_encoding(s);
7078 if (!fp_access_check(s)) {
7082 element = extract32(imm5, 1+size, 4);
7084 tcg_rd = cpu_reg(s, rd);
7085 read_vec_element(s, tcg_rd, rn, element, size | (is_signed ? MO_SIGN : 0));
7086 if (is_signed && !is_q) {
7087 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
7092 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7093 * +---+---+----+-----------------+------+---+------+---+------+------+
7094 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7095 * +---+---+----+-----------------+------+---+------+---+------+------+
7097 static void disas_simd_copy(DisasContext *s, uint32_t insn)
7099 int rd = extract32(insn, 0, 5);
7100 int rn = extract32(insn, 5, 5);
7101 int imm4 = extract32(insn, 11, 4);
7102 int op = extract32(insn, 29, 1);
7103 int is_q = extract32(insn, 30, 1);
7104 int imm5 = extract32(insn, 16, 5);
7109 handle_simd_inse(s, rd, rn, imm4, imm5);
7111 unallocated_encoding(s);
7116 /* DUP (element - vector) */
7117 handle_simd_dupe(s, is_q, rd, rn, imm5);
7121 handle_simd_dupg(s, is_q, rd, rn, imm5);
7126 handle_simd_insg(s, rd, rn, imm5);
7128 unallocated_encoding(s);
7133 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
7134 handle_simd_umov_smov(s, is_q, (imm4 == 5), rn, rd, imm5);
7137 unallocated_encoding(s);
7143 /* AdvSIMD modified immediate
7144 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
7145 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7146 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
7147 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7149 * There are a number of operations that can be carried out here:
7150 * MOVI - move (shifted) imm into register
7151 * MVNI - move inverted (shifted) imm into register
7152 * ORR - bitwise OR of (shifted) imm with register
7153 * BIC - bitwise clear of (shifted) imm with register
7154 * With ARMv8.2 we also have:
7155 * FMOV half-precision
7157 static void disas_simd_mod_imm(DisasContext *s, uint32_t insn)
7159 int rd = extract32(insn, 0, 5);
7160 int cmode = extract32(insn, 12, 4);
7161 int cmode_3_1 = extract32(cmode, 1, 3);
7162 int cmode_0 = extract32(cmode, 0, 1);
7163 int o2 = extract32(insn, 11, 1);
7164 uint64_t abcdefgh = extract32(insn, 5, 5) | (extract32(insn, 16, 3) << 5);
7165 bool is_neg = extract32(insn, 29, 1);
7166 bool is_q = extract32(insn, 30, 1);
7169 if (o2 != 0 || ((cmode == 0xf) && is_neg && !is_q)) {
7170 /* Check for FMOV (vector, immediate) - half-precision */
7171 if (!(dc_isar_feature(aa64_fp16, s) && o2 && cmode == 0xf)) {
7172 unallocated_encoding(s);
7177 if (!fp_access_check(s)) {
7181 /* See AdvSIMDExpandImm() in ARM ARM */
7182 switch (cmode_3_1) {
7183 case 0: /* Replicate(Zeros(24):imm8, 2) */
7184 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
7185 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
7186 case 3: /* Replicate(imm8:Zeros(24), 2) */
7188 int shift = cmode_3_1 * 8;
7189 imm = bitfield_replicate(abcdefgh << shift, 32);
7192 case 4: /* Replicate(Zeros(8):imm8, 4) */
7193 case 5: /* Replicate(imm8:Zeros(8), 4) */
7195 int shift = (cmode_3_1 & 0x1) * 8;
7196 imm = bitfield_replicate(abcdefgh << shift, 16);
7201 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
7202 imm = (abcdefgh << 16) | 0xffff;
7204 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
7205 imm = (abcdefgh << 8) | 0xff;
7207 imm = bitfield_replicate(imm, 32);
7210 if (!cmode_0 && !is_neg) {
7211 imm = bitfield_replicate(abcdefgh, 8);
7212 } else if (!cmode_0 && is_neg) {
7215 for (i = 0; i < 8; i++) {
7216 if ((abcdefgh) & (1 << i)) {
7217 imm |= 0xffULL << (i * 8);
7220 } else if (cmode_0) {
7222 imm = (abcdefgh & 0x3f) << 48;
7223 if (abcdefgh & 0x80) {
7224 imm |= 0x8000000000000000ULL;
7226 if (abcdefgh & 0x40) {
7227 imm |= 0x3fc0000000000000ULL;
7229 imm |= 0x4000000000000000ULL;
7233 /* FMOV (vector, immediate) - half-precision */
7234 imm = vfp_expand_imm(MO_16, abcdefgh);
7235 /* now duplicate across the lanes */
7236 imm = bitfield_replicate(imm, 16);
7238 imm = (abcdefgh & 0x3f) << 19;
7239 if (abcdefgh & 0x80) {
7242 if (abcdefgh & 0x40) {
7253 fprintf(stderr, "%s: cmode_3_1: %x\n", __func__, cmode_3_1);
7254 g_assert_not_reached();
7257 if (cmode_3_1 != 7 && is_neg) {
7261 if (!((cmode & 0x9) == 0x1 || (cmode & 0xd) == 0x9)) {
7262 /* MOVI or MVNI, with MVNI negation handled above. */
7263 tcg_gen_gvec_dup64i(vec_full_reg_offset(s, rd), is_q ? 16 : 8,
7264 vec_full_reg_size(s), imm);
7266 /* ORR or BIC, with BIC negation to AND handled above. */
7268 gen_gvec_fn2i(s, is_q, rd, rd, imm, tcg_gen_gvec_andi, MO_64);
7270 gen_gvec_fn2i(s, is_q, rd, rd, imm, tcg_gen_gvec_ori, MO_64);
7275 /* AdvSIMD scalar copy
7276 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7277 * +-----+----+-----------------+------+---+------+---+------+------+
7278 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7279 * +-----+----+-----------------+------+---+------+---+------+------+
7281 static void disas_simd_scalar_copy(DisasContext *s, uint32_t insn)
7283 int rd = extract32(insn, 0, 5);
7284 int rn = extract32(insn, 5, 5);
7285 int imm4 = extract32(insn, 11, 4);
7286 int imm5 = extract32(insn, 16, 5);
7287 int op = extract32(insn, 29, 1);
7289 if (op != 0 || imm4 != 0) {
7290 unallocated_encoding(s);
7294 /* DUP (element, scalar) */
7295 handle_simd_dupes(s, rd, rn, imm5);
7298 /* AdvSIMD scalar pairwise
7299 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7300 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7301 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7302 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7304 static void disas_simd_scalar_pairwise(DisasContext *s, uint32_t insn)
7306 int u = extract32(insn, 29, 1);
7307 int size = extract32(insn, 22, 2);
7308 int opcode = extract32(insn, 12, 5);
7309 int rn = extract32(insn, 5, 5);
7310 int rd = extract32(insn, 0, 5);
7313 /* For some ops (the FP ones), size[1] is part of the encoding.
7314 * For ADDP strictly it is not but size[1] is always 1 for valid
7317 opcode |= (extract32(size, 1, 1) << 5);
7320 case 0x3b: /* ADDP */
7321 if (u || size != 3) {
7322 unallocated_encoding(s);
7325 if (!fp_access_check(s)) {
7331 case 0xc: /* FMAXNMP */
7332 case 0xd: /* FADDP */
7333 case 0xf: /* FMAXP */
7334 case 0x2c: /* FMINNMP */
7335 case 0x2f: /* FMINP */
7336 /* FP op, size[0] is 32 or 64 bit*/
7338 if (!dc_isar_feature(aa64_fp16, s)) {
7339 unallocated_encoding(s);
7345 size = extract32(size, 0, 1) ? MO_64 : MO_32;
7348 if (!fp_access_check(s)) {
7352 fpst = get_fpstatus_ptr(size == MO_16);
7355 unallocated_encoding(s);
7359 if (size == MO_64) {
7360 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
7361 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
7362 TCGv_i64 tcg_res = tcg_temp_new_i64();
7364 read_vec_element(s, tcg_op1, rn, 0, MO_64);
7365 read_vec_element(s, tcg_op2, rn, 1, MO_64);
7368 case 0x3b: /* ADDP */
7369 tcg_gen_add_i64(tcg_res, tcg_op1, tcg_op2);
7371 case 0xc: /* FMAXNMP */
7372 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
7374 case 0xd: /* FADDP */
7375 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
7377 case 0xf: /* FMAXP */
7378 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
7380 case 0x2c: /* FMINNMP */
7381 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
7383 case 0x2f: /* FMINP */
7384 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
7387 g_assert_not_reached();
7390 write_fp_dreg(s, rd, tcg_res);
7392 tcg_temp_free_i64(tcg_op1);
7393 tcg_temp_free_i64(tcg_op2);
7394 tcg_temp_free_i64(tcg_res);
7396 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
7397 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
7398 TCGv_i32 tcg_res = tcg_temp_new_i32();
7400 read_vec_element_i32(s, tcg_op1, rn, 0, size);
7401 read_vec_element_i32(s, tcg_op2, rn, 1, size);
7403 if (size == MO_16) {
7405 case 0xc: /* FMAXNMP */
7406 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
7408 case 0xd: /* FADDP */
7409 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
7411 case 0xf: /* FMAXP */
7412 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
7414 case 0x2c: /* FMINNMP */
7415 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
7417 case 0x2f: /* FMINP */
7418 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
7421 g_assert_not_reached();
7425 case 0xc: /* FMAXNMP */
7426 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
7428 case 0xd: /* FADDP */
7429 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
7431 case 0xf: /* FMAXP */
7432 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
7434 case 0x2c: /* FMINNMP */
7435 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
7437 case 0x2f: /* FMINP */
7438 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
7441 g_assert_not_reached();
7445 write_fp_sreg(s, rd, tcg_res);
7447 tcg_temp_free_i32(tcg_op1);
7448 tcg_temp_free_i32(tcg_op2);
7449 tcg_temp_free_i32(tcg_res);
7453 tcg_temp_free_ptr(fpst);
7458 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
7460 * This code is handles the common shifting code and is used by both
7461 * the vector and scalar code.
7463 static void handle_shri_with_rndacc(TCGv_i64 tcg_res, TCGv_i64 tcg_src,
7464 TCGv_i64 tcg_rnd, bool accumulate,
7465 bool is_u, int size, int shift)
7467 bool extended_result = false;
7468 bool round = tcg_rnd != NULL;
7470 TCGv_i64 tcg_src_hi;
7472 if (round && size == 3) {
7473 extended_result = true;
7474 ext_lshift = 64 - shift;
7475 tcg_src_hi = tcg_temp_new_i64();
7476 } else if (shift == 64) {
7477 if (!accumulate && is_u) {
7478 /* result is zero */
7479 tcg_gen_movi_i64(tcg_res, 0);
7484 /* Deal with the rounding step */
7486 if (extended_result) {
7487 TCGv_i64 tcg_zero = tcg_const_i64(0);
7489 /* take care of sign extending tcg_res */
7490 tcg_gen_sari_i64(tcg_src_hi, tcg_src, 63);
7491 tcg_gen_add2_i64(tcg_src, tcg_src_hi,
7492 tcg_src, tcg_src_hi,
7495 tcg_gen_add2_i64(tcg_src, tcg_src_hi,
7499 tcg_temp_free_i64(tcg_zero);
7501 tcg_gen_add_i64(tcg_src, tcg_src, tcg_rnd);
7505 /* Now do the shift right */
7506 if (round && extended_result) {
7507 /* extended case, >64 bit precision required */
7508 if (ext_lshift == 0) {
7509 /* special case, only high bits matter */
7510 tcg_gen_mov_i64(tcg_src, tcg_src_hi);
7512 tcg_gen_shri_i64(tcg_src, tcg_src, shift);
7513 tcg_gen_shli_i64(tcg_src_hi, tcg_src_hi, ext_lshift);
7514 tcg_gen_or_i64(tcg_src, tcg_src, tcg_src_hi);
7519 /* essentially shifting in 64 zeros */
7520 tcg_gen_movi_i64(tcg_src, 0);
7522 tcg_gen_shri_i64(tcg_src, tcg_src, shift);
7526 /* effectively extending the sign-bit */
7527 tcg_gen_sari_i64(tcg_src, tcg_src, 63);
7529 tcg_gen_sari_i64(tcg_src, tcg_src, shift);
7535 tcg_gen_add_i64(tcg_res, tcg_res, tcg_src);
7537 tcg_gen_mov_i64(tcg_res, tcg_src);
7540 if (extended_result) {
7541 tcg_temp_free_i64(tcg_src_hi);
7545 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
7546 static void handle_scalar_simd_shri(DisasContext *s,
7547 bool is_u, int immh, int immb,
7548 int opcode, int rn, int rd)
7551 int immhb = immh << 3 | immb;
7552 int shift = 2 * (8 << size) - immhb;
7553 bool accumulate = false;
7555 bool insert = false;
7560 if (!extract32(immh, 3, 1)) {
7561 unallocated_encoding(s);
7565 if (!fp_access_check(s)) {
7570 case 0x02: /* SSRA / USRA (accumulate) */
7573 case 0x04: /* SRSHR / URSHR (rounding) */
7576 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7577 accumulate = round = true;
7579 case 0x08: /* SRI */
7585 uint64_t round_const = 1ULL << (shift - 1);
7586 tcg_round = tcg_const_i64(round_const);
7591 tcg_rn = read_fp_dreg(s, rn);
7592 tcg_rd = (accumulate || insert) ? read_fp_dreg(s, rd) : tcg_temp_new_i64();
7595 /* shift count same as element size is valid but does nothing;
7596 * special case to avoid potential shift by 64.
7598 int esize = 8 << size;
7599 if (shift != esize) {
7600 tcg_gen_shri_i64(tcg_rn, tcg_rn, shift);
7601 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, 0, esize - shift);
7604 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
7605 accumulate, is_u, size, shift);
7608 write_fp_dreg(s, rd, tcg_rd);
7610 tcg_temp_free_i64(tcg_rn);
7611 tcg_temp_free_i64(tcg_rd);
7613 tcg_temp_free_i64(tcg_round);
7617 /* SHL/SLI - Scalar shift left */
7618 static void handle_scalar_simd_shli(DisasContext *s, bool insert,
7619 int immh, int immb, int opcode,
7622 int size = 32 - clz32(immh) - 1;
7623 int immhb = immh << 3 | immb;
7624 int shift = immhb - (8 << size);
7625 TCGv_i64 tcg_rn = new_tmp_a64(s);
7626 TCGv_i64 tcg_rd = new_tmp_a64(s);
7628 if (!extract32(immh, 3, 1)) {
7629 unallocated_encoding(s);
7633 if (!fp_access_check(s)) {
7637 tcg_rn = read_fp_dreg(s, rn);
7638 tcg_rd = insert ? read_fp_dreg(s, rd) : tcg_temp_new_i64();
7641 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, shift, 64 - shift);
7643 tcg_gen_shli_i64(tcg_rd, tcg_rn, shift);
7646 write_fp_dreg(s, rd, tcg_rd);
7648 tcg_temp_free_i64(tcg_rn);
7649 tcg_temp_free_i64(tcg_rd);
7652 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
7653 * (signed/unsigned) narrowing */
7654 static void handle_vec_simd_sqshrn(DisasContext *s, bool is_scalar, bool is_q,
7655 bool is_u_shift, bool is_u_narrow,
7656 int immh, int immb, int opcode,
7659 int immhb = immh << 3 | immb;
7660 int size = 32 - clz32(immh) - 1;
7661 int esize = 8 << size;
7662 int shift = (2 * esize) - immhb;
7663 int elements = is_scalar ? 1 : (64 / esize);
7664 bool round = extract32(opcode, 0, 1);
7665 TCGMemOp ldop = (size + 1) | (is_u_shift ? 0 : MO_SIGN);
7666 TCGv_i64 tcg_rn, tcg_rd, tcg_round;
7667 TCGv_i32 tcg_rd_narrowed;
7670 static NeonGenNarrowEnvFn * const signed_narrow_fns[4][2] = {
7671 { gen_helper_neon_narrow_sat_s8,
7672 gen_helper_neon_unarrow_sat8 },
7673 { gen_helper_neon_narrow_sat_s16,
7674 gen_helper_neon_unarrow_sat16 },
7675 { gen_helper_neon_narrow_sat_s32,
7676 gen_helper_neon_unarrow_sat32 },
7679 static NeonGenNarrowEnvFn * const unsigned_narrow_fns[4] = {
7680 gen_helper_neon_narrow_sat_u8,
7681 gen_helper_neon_narrow_sat_u16,
7682 gen_helper_neon_narrow_sat_u32,
7685 NeonGenNarrowEnvFn *narrowfn;
7691 if (extract32(immh, 3, 1)) {
7692 unallocated_encoding(s);
7696 if (!fp_access_check(s)) {
7701 narrowfn = unsigned_narrow_fns[size];
7703 narrowfn = signed_narrow_fns[size][is_u_narrow ? 1 : 0];
7706 tcg_rn = tcg_temp_new_i64();
7707 tcg_rd = tcg_temp_new_i64();
7708 tcg_rd_narrowed = tcg_temp_new_i32();
7709 tcg_final = tcg_const_i64(0);
7712 uint64_t round_const = 1ULL << (shift - 1);
7713 tcg_round = tcg_const_i64(round_const);
7718 for (i = 0; i < elements; i++) {
7719 read_vec_element(s, tcg_rn, rn, i, ldop);
7720 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
7721 false, is_u_shift, size+1, shift);
7722 narrowfn(tcg_rd_narrowed, cpu_env, tcg_rd);
7723 tcg_gen_extu_i32_i64(tcg_rd, tcg_rd_narrowed);
7724 tcg_gen_deposit_i64(tcg_final, tcg_final, tcg_rd, esize * i, esize);
7728 write_vec_element(s, tcg_final, rd, 0, MO_64);
7730 write_vec_element(s, tcg_final, rd, 1, MO_64);
7734 tcg_temp_free_i64(tcg_round);
7736 tcg_temp_free_i64(tcg_rn);
7737 tcg_temp_free_i64(tcg_rd);
7738 tcg_temp_free_i32(tcg_rd_narrowed);
7739 tcg_temp_free_i64(tcg_final);
7741 clear_vec_high(s, is_q, rd);
7744 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
7745 static void handle_simd_qshl(DisasContext *s, bool scalar, bool is_q,
7746 bool src_unsigned, bool dst_unsigned,
7747 int immh, int immb, int rn, int rd)
7749 int immhb = immh << 3 | immb;
7750 int size = 32 - clz32(immh) - 1;
7751 int shift = immhb - (8 << size);
7755 assert(!(scalar && is_q));
7758 if (!is_q && extract32(immh, 3, 1)) {
7759 unallocated_encoding(s);
7763 /* Since we use the variable-shift helpers we must
7764 * replicate the shift count into each element of
7765 * the tcg_shift value.
7769 shift |= shift << 8;
7772 shift |= shift << 16;
7778 g_assert_not_reached();
7782 if (!fp_access_check(s)) {
7787 TCGv_i64 tcg_shift = tcg_const_i64(shift);
7788 static NeonGenTwo64OpEnvFn * const fns[2][2] = {
7789 { gen_helper_neon_qshl_s64, gen_helper_neon_qshlu_s64 },
7790 { NULL, gen_helper_neon_qshl_u64 },
7792 NeonGenTwo64OpEnvFn *genfn = fns[src_unsigned][dst_unsigned];
7793 int maxpass = is_q ? 2 : 1;
7795 for (pass = 0; pass < maxpass; pass++) {
7796 TCGv_i64 tcg_op = tcg_temp_new_i64();
7798 read_vec_element(s, tcg_op, rn, pass, MO_64);
7799 genfn(tcg_op, cpu_env, tcg_op, tcg_shift);
7800 write_vec_element(s, tcg_op, rd, pass, MO_64);
7802 tcg_temp_free_i64(tcg_op);
7804 tcg_temp_free_i64(tcg_shift);
7805 clear_vec_high(s, is_q, rd);
7807 TCGv_i32 tcg_shift = tcg_const_i32(shift);
7808 static NeonGenTwoOpEnvFn * const fns[2][2][3] = {
7810 { gen_helper_neon_qshl_s8,
7811 gen_helper_neon_qshl_s16,
7812 gen_helper_neon_qshl_s32 },
7813 { gen_helper_neon_qshlu_s8,
7814 gen_helper_neon_qshlu_s16,
7815 gen_helper_neon_qshlu_s32 }
7817 { NULL, NULL, NULL },
7818 { gen_helper_neon_qshl_u8,
7819 gen_helper_neon_qshl_u16,
7820 gen_helper_neon_qshl_u32 }
7823 NeonGenTwoOpEnvFn *genfn = fns[src_unsigned][dst_unsigned][size];
7824 TCGMemOp memop = scalar ? size : MO_32;
7825 int maxpass = scalar ? 1 : is_q ? 4 : 2;
7827 for (pass = 0; pass < maxpass; pass++) {
7828 TCGv_i32 tcg_op = tcg_temp_new_i32();
7830 read_vec_element_i32(s, tcg_op, rn, pass, memop);
7831 genfn(tcg_op, cpu_env, tcg_op, tcg_shift);
7835 tcg_gen_ext8u_i32(tcg_op, tcg_op);
7838 tcg_gen_ext16u_i32(tcg_op, tcg_op);
7843 g_assert_not_reached();
7845 write_fp_sreg(s, rd, tcg_op);
7847 write_vec_element_i32(s, tcg_op, rd, pass, MO_32);
7850 tcg_temp_free_i32(tcg_op);
7852 tcg_temp_free_i32(tcg_shift);
7855 clear_vec_high(s, is_q, rd);
7860 /* Common vector code for handling integer to FP conversion */
7861 static void handle_simd_intfp_conv(DisasContext *s, int rd, int rn,
7862 int elements, int is_signed,
7863 int fracbits, int size)
7865 TCGv_ptr tcg_fpst = get_fpstatus_ptr(size == MO_16);
7866 TCGv_i32 tcg_shift = NULL;
7868 TCGMemOp mop = size | (is_signed ? MO_SIGN : 0);
7871 if (fracbits || size == MO_64) {
7872 tcg_shift = tcg_const_i32(fracbits);
7875 if (size == MO_64) {
7876 TCGv_i64 tcg_int64 = tcg_temp_new_i64();
7877 TCGv_i64 tcg_double = tcg_temp_new_i64();
7879 for (pass = 0; pass < elements; pass++) {
7880 read_vec_element(s, tcg_int64, rn, pass, mop);
7883 gen_helper_vfp_sqtod(tcg_double, tcg_int64,
7884 tcg_shift, tcg_fpst);
7886 gen_helper_vfp_uqtod(tcg_double, tcg_int64,
7887 tcg_shift, tcg_fpst);
7889 if (elements == 1) {
7890 write_fp_dreg(s, rd, tcg_double);
7892 write_vec_element(s, tcg_double, rd, pass, MO_64);
7896 tcg_temp_free_i64(tcg_int64);
7897 tcg_temp_free_i64(tcg_double);
7900 TCGv_i32 tcg_int32 = tcg_temp_new_i32();
7901 TCGv_i32 tcg_float = tcg_temp_new_i32();
7903 for (pass = 0; pass < elements; pass++) {
7904 read_vec_element_i32(s, tcg_int32, rn, pass, mop);
7910 gen_helper_vfp_sltos(tcg_float, tcg_int32,
7911 tcg_shift, tcg_fpst);
7913 gen_helper_vfp_ultos(tcg_float, tcg_int32,
7914 tcg_shift, tcg_fpst);
7918 gen_helper_vfp_sitos(tcg_float, tcg_int32, tcg_fpst);
7920 gen_helper_vfp_uitos(tcg_float, tcg_int32, tcg_fpst);
7927 gen_helper_vfp_sltoh(tcg_float, tcg_int32,
7928 tcg_shift, tcg_fpst);
7930 gen_helper_vfp_ultoh(tcg_float, tcg_int32,
7931 tcg_shift, tcg_fpst);
7935 gen_helper_vfp_sitoh(tcg_float, tcg_int32, tcg_fpst);
7937 gen_helper_vfp_uitoh(tcg_float, tcg_int32, tcg_fpst);
7942 g_assert_not_reached();
7945 if (elements == 1) {
7946 write_fp_sreg(s, rd, tcg_float);
7948 write_vec_element_i32(s, tcg_float, rd, pass, size);
7952 tcg_temp_free_i32(tcg_int32);
7953 tcg_temp_free_i32(tcg_float);
7956 tcg_temp_free_ptr(tcg_fpst);
7958 tcg_temp_free_i32(tcg_shift);
7961 clear_vec_high(s, elements << size == 16, rd);
7964 /* UCVTF/SCVTF - Integer to FP conversion */
7965 static void handle_simd_shift_intfp_conv(DisasContext *s, bool is_scalar,
7966 bool is_q, bool is_u,
7967 int immh, int immb, int opcode,
7970 int size, elements, fracbits;
7971 int immhb = immh << 3 | immb;
7975 if (!is_scalar && !is_q) {
7976 unallocated_encoding(s);
7979 } else if (immh & 4) {
7981 } else if (immh & 2) {
7983 if (!dc_isar_feature(aa64_fp16, s)) {
7984 unallocated_encoding(s);
7988 /* immh == 0 would be a failure of the decode logic */
7989 g_assert(immh == 1);
7990 unallocated_encoding(s);
7997 elements = (8 << is_q) >> size;
7999 fracbits = (16 << size) - immhb;
8001 if (!fp_access_check(s)) {
8005 handle_simd_intfp_conv(s, rd, rn, elements, !is_u, fracbits, size);
8008 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
8009 static void handle_simd_shift_fpint_conv(DisasContext *s, bool is_scalar,
8010 bool is_q, bool is_u,
8011 int immh, int immb, int rn, int rd)
8013 int immhb = immh << 3 | immb;
8014 int pass, size, fracbits;
8015 TCGv_ptr tcg_fpstatus;
8016 TCGv_i32 tcg_rmode, tcg_shift;
8020 if (!is_scalar && !is_q) {
8021 unallocated_encoding(s);
8024 } else if (immh & 0x4) {
8026 } else if (immh & 0x2) {
8028 if (!dc_isar_feature(aa64_fp16, s)) {
8029 unallocated_encoding(s);
8033 /* Should have split out AdvSIMD modified immediate earlier. */
8035 unallocated_encoding(s);
8039 if (!fp_access_check(s)) {
8043 assert(!(is_scalar && is_q));
8045 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO));
8046 tcg_fpstatus = get_fpstatus_ptr(size == MO_16);
8047 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
8048 fracbits = (16 << size) - immhb;
8049 tcg_shift = tcg_const_i32(fracbits);
8051 if (size == MO_64) {
8052 int maxpass = is_scalar ? 1 : 2;
8054 for (pass = 0; pass < maxpass; pass++) {
8055 TCGv_i64 tcg_op = tcg_temp_new_i64();
8057 read_vec_element(s, tcg_op, rn, pass, MO_64);
8059 gen_helper_vfp_touqd(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8061 gen_helper_vfp_tosqd(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8063 write_vec_element(s, tcg_op, rd, pass, MO_64);
8064 tcg_temp_free_i64(tcg_op);
8066 clear_vec_high(s, is_q, rd);
8068 void (*fn)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_ptr);
8069 int maxpass = is_scalar ? 1 : ((8 << is_q) >> size);
8074 fn = gen_helper_vfp_touhh;
8076 fn = gen_helper_vfp_toshh;
8081 fn = gen_helper_vfp_touls;
8083 fn = gen_helper_vfp_tosls;
8087 g_assert_not_reached();
8090 for (pass = 0; pass < maxpass; pass++) {
8091 TCGv_i32 tcg_op = tcg_temp_new_i32();
8093 read_vec_element_i32(s, tcg_op, rn, pass, size);
8094 fn(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
8096 write_fp_sreg(s, rd, tcg_op);
8098 write_vec_element_i32(s, tcg_op, rd, pass, size);
8100 tcg_temp_free_i32(tcg_op);
8103 clear_vec_high(s, is_q, rd);
8107 tcg_temp_free_ptr(tcg_fpstatus);
8108 tcg_temp_free_i32(tcg_shift);
8109 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
8110 tcg_temp_free_i32(tcg_rmode);
8113 /* AdvSIMD scalar shift by immediate
8114 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8115 * +-----+---+-------------+------+------+--------+---+------+------+
8116 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8117 * +-----+---+-------------+------+------+--------+---+------+------+
8119 * This is the scalar version so it works on a fixed sized registers
8121 static void disas_simd_scalar_shift_imm(DisasContext *s, uint32_t insn)
8123 int rd = extract32(insn, 0, 5);
8124 int rn = extract32(insn, 5, 5);
8125 int opcode = extract32(insn, 11, 5);
8126 int immb = extract32(insn, 16, 3);
8127 int immh = extract32(insn, 19, 4);
8128 bool is_u = extract32(insn, 29, 1);
8131 unallocated_encoding(s);
8136 case 0x08: /* SRI */
8138 unallocated_encoding(s);
8142 case 0x00: /* SSHR / USHR */
8143 case 0x02: /* SSRA / USRA */
8144 case 0x04: /* SRSHR / URSHR */
8145 case 0x06: /* SRSRA / URSRA */
8146 handle_scalar_simd_shri(s, is_u, immh, immb, opcode, rn, rd);
8148 case 0x0a: /* SHL / SLI */
8149 handle_scalar_simd_shli(s, is_u, immh, immb, opcode, rn, rd);
8151 case 0x1c: /* SCVTF, UCVTF */
8152 handle_simd_shift_intfp_conv(s, true, false, is_u, immh, immb,
8155 case 0x10: /* SQSHRUN, SQSHRUN2 */
8156 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
8158 unallocated_encoding(s);
8161 handle_vec_simd_sqshrn(s, true, false, false, true,
8162 immh, immb, opcode, rn, rd);
8164 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
8165 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
8166 handle_vec_simd_sqshrn(s, true, false, is_u, is_u,
8167 immh, immb, opcode, rn, rd);
8169 case 0xc: /* SQSHLU */
8171 unallocated_encoding(s);
8174 handle_simd_qshl(s, true, false, false, true, immh, immb, rn, rd);
8176 case 0xe: /* SQSHL, UQSHL */
8177 handle_simd_qshl(s, true, false, is_u, is_u, immh, immb, rn, rd);
8179 case 0x1f: /* FCVTZS, FCVTZU */
8180 handle_simd_shift_fpint_conv(s, true, false, is_u, immh, immb, rn, rd);
8183 unallocated_encoding(s);
8188 /* AdvSIMD scalar three different
8189 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8190 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8191 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8192 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8194 static void disas_simd_scalar_three_reg_diff(DisasContext *s, uint32_t insn)
8196 bool is_u = extract32(insn, 29, 1);
8197 int size = extract32(insn, 22, 2);
8198 int opcode = extract32(insn, 12, 4);
8199 int rm = extract32(insn, 16, 5);
8200 int rn = extract32(insn, 5, 5);
8201 int rd = extract32(insn, 0, 5);
8204 unallocated_encoding(s);
8209 case 0x9: /* SQDMLAL, SQDMLAL2 */
8210 case 0xb: /* SQDMLSL, SQDMLSL2 */
8211 case 0xd: /* SQDMULL, SQDMULL2 */
8212 if (size == 0 || size == 3) {
8213 unallocated_encoding(s);
8218 unallocated_encoding(s);
8222 if (!fp_access_check(s)) {
8227 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8228 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8229 TCGv_i64 tcg_res = tcg_temp_new_i64();
8231 read_vec_element(s, tcg_op1, rn, 0, MO_32 | MO_SIGN);
8232 read_vec_element(s, tcg_op2, rm, 0, MO_32 | MO_SIGN);
8234 tcg_gen_mul_i64(tcg_res, tcg_op1, tcg_op2);
8235 gen_helper_neon_addl_saturate_s64(tcg_res, cpu_env, tcg_res, tcg_res);
8238 case 0xd: /* SQDMULL, SQDMULL2 */
8240 case 0xb: /* SQDMLSL, SQDMLSL2 */
8241 tcg_gen_neg_i64(tcg_res, tcg_res);
8243 case 0x9: /* SQDMLAL, SQDMLAL2 */
8244 read_vec_element(s, tcg_op1, rd, 0, MO_64);
8245 gen_helper_neon_addl_saturate_s64(tcg_res, cpu_env,
8249 g_assert_not_reached();
8252 write_fp_dreg(s, rd, tcg_res);
8254 tcg_temp_free_i64(tcg_op1);
8255 tcg_temp_free_i64(tcg_op2);
8256 tcg_temp_free_i64(tcg_res);
8258 TCGv_i32 tcg_op1 = read_fp_hreg(s, rn);
8259 TCGv_i32 tcg_op2 = read_fp_hreg(s, rm);
8260 TCGv_i64 tcg_res = tcg_temp_new_i64();
8262 gen_helper_neon_mull_s16(tcg_res, tcg_op1, tcg_op2);
8263 gen_helper_neon_addl_saturate_s32(tcg_res, cpu_env, tcg_res, tcg_res);
8266 case 0xd: /* SQDMULL, SQDMULL2 */
8268 case 0xb: /* SQDMLSL, SQDMLSL2 */
8269 gen_helper_neon_negl_u32(tcg_res, tcg_res);
8271 case 0x9: /* SQDMLAL, SQDMLAL2 */
8273 TCGv_i64 tcg_op3 = tcg_temp_new_i64();
8274 read_vec_element(s, tcg_op3, rd, 0, MO_32);
8275 gen_helper_neon_addl_saturate_s32(tcg_res, cpu_env,
8277 tcg_temp_free_i64(tcg_op3);
8281 g_assert_not_reached();
8284 tcg_gen_ext32u_i64(tcg_res, tcg_res);
8285 write_fp_dreg(s, rd, tcg_res);
8287 tcg_temp_free_i32(tcg_op1);
8288 tcg_temp_free_i32(tcg_op2);
8289 tcg_temp_free_i64(tcg_res);
8293 static void handle_3same_64(DisasContext *s, int opcode, bool u,
8294 TCGv_i64 tcg_rd, TCGv_i64 tcg_rn, TCGv_i64 tcg_rm)
8296 /* Handle 64x64->64 opcodes which are shared between the scalar
8297 * and vector 3-same groups. We cover every opcode where size == 3
8298 * is valid in either the three-reg-same (integer, not pairwise)
8299 * or scalar-three-reg-same groups.
8304 case 0x1: /* SQADD */
8306 gen_helper_neon_qadd_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8308 gen_helper_neon_qadd_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8311 case 0x5: /* SQSUB */
8313 gen_helper_neon_qsub_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8315 gen_helper_neon_qsub_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8318 case 0x6: /* CMGT, CMHI */
8319 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
8320 * We implement this using setcond (test) and then negating.
8322 cond = u ? TCG_COND_GTU : TCG_COND_GT;
8324 tcg_gen_setcond_i64(cond, tcg_rd, tcg_rn, tcg_rm);
8325 tcg_gen_neg_i64(tcg_rd, tcg_rd);
8327 case 0x7: /* CMGE, CMHS */
8328 cond = u ? TCG_COND_GEU : TCG_COND_GE;
8330 case 0x11: /* CMTST, CMEQ */
8335 gen_cmtst_i64(tcg_rd, tcg_rn, tcg_rm);
8337 case 0x8: /* SSHL, USHL */
8339 gen_helper_neon_shl_u64(tcg_rd, tcg_rn, tcg_rm);
8341 gen_helper_neon_shl_s64(tcg_rd, tcg_rn, tcg_rm);
8344 case 0x9: /* SQSHL, UQSHL */
8346 gen_helper_neon_qshl_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8348 gen_helper_neon_qshl_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8351 case 0xa: /* SRSHL, URSHL */
8353 gen_helper_neon_rshl_u64(tcg_rd, tcg_rn, tcg_rm);
8355 gen_helper_neon_rshl_s64(tcg_rd, tcg_rn, tcg_rm);
8358 case 0xb: /* SQRSHL, UQRSHL */
8360 gen_helper_neon_qrshl_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8362 gen_helper_neon_qrshl_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
8365 case 0x10: /* ADD, SUB */
8367 tcg_gen_sub_i64(tcg_rd, tcg_rn, tcg_rm);
8369 tcg_gen_add_i64(tcg_rd, tcg_rn, tcg_rm);
8373 g_assert_not_reached();
8377 /* Handle the 3-same-operands float operations; shared by the scalar
8378 * and vector encodings. The caller must filter out any encodings
8379 * not allocated for the encoding it is dealing with.
8381 static void handle_3same_float(DisasContext *s, int size, int elements,
8382 int fpopcode, int rd, int rn, int rm)
8385 TCGv_ptr fpst = get_fpstatus_ptr(false);
8387 for (pass = 0; pass < elements; pass++) {
8390 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8391 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8392 TCGv_i64 tcg_res = tcg_temp_new_i64();
8394 read_vec_element(s, tcg_op1, rn, pass, MO_64);
8395 read_vec_element(s, tcg_op2, rm, pass, MO_64);
8398 case 0x39: /* FMLS */
8399 /* As usual for ARM, separate negation for fused multiply-add */
8400 gen_helper_vfp_negd(tcg_op1, tcg_op1);
8402 case 0x19: /* FMLA */
8403 read_vec_element(s, tcg_res, rd, pass, MO_64);
8404 gen_helper_vfp_muladdd(tcg_res, tcg_op1, tcg_op2,
8407 case 0x18: /* FMAXNM */
8408 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
8410 case 0x1a: /* FADD */
8411 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
8413 case 0x1b: /* FMULX */
8414 gen_helper_vfp_mulxd(tcg_res, tcg_op1, tcg_op2, fpst);
8416 case 0x1c: /* FCMEQ */
8417 gen_helper_neon_ceq_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8419 case 0x1e: /* FMAX */
8420 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
8422 case 0x1f: /* FRECPS */
8423 gen_helper_recpsf_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8425 case 0x38: /* FMINNM */
8426 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
8428 case 0x3a: /* FSUB */
8429 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
8431 case 0x3e: /* FMIN */
8432 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
8434 case 0x3f: /* FRSQRTS */
8435 gen_helper_rsqrtsf_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8437 case 0x5b: /* FMUL */
8438 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
8440 case 0x5c: /* FCMGE */
8441 gen_helper_neon_cge_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8443 case 0x5d: /* FACGE */
8444 gen_helper_neon_acge_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8446 case 0x5f: /* FDIV */
8447 gen_helper_vfp_divd(tcg_res, tcg_op1, tcg_op2, fpst);
8449 case 0x7a: /* FABD */
8450 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
8451 gen_helper_vfp_absd(tcg_res, tcg_res);
8453 case 0x7c: /* FCMGT */
8454 gen_helper_neon_cgt_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8456 case 0x7d: /* FACGT */
8457 gen_helper_neon_acgt_f64(tcg_res, tcg_op1, tcg_op2, fpst);
8460 g_assert_not_reached();
8463 write_vec_element(s, tcg_res, rd, pass, MO_64);
8465 tcg_temp_free_i64(tcg_res);
8466 tcg_temp_free_i64(tcg_op1);
8467 tcg_temp_free_i64(tcg_op2);
8470 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
8471 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
8472 TCGv_i32 tcg_res = tcg_temp_new_i32();
8474 read_vec_element_i32(s, tcg_op1, rn, pass, MO_32);
8475 read_vec_element_i32(s, tcg_op2, rm, pass, MO_32);
8478 case 0x39: /* FMLS */
8479 /* As usual for ARM, separate negation for fused multiply-add */
8480 gen_helper_vfp_negs(tcg_op1, tcg_op1);
8482 case 0x19: /* FMLA */
8483 read_vec_element_i32(s, tcg_res, rd, pass, MO_32);
8484 gen_helper_vfp_muladds(tcg_res, tcg_op1, tcg_op2,
8487 case 0x1a: /* FADD */
8488 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
8490 case 0x1b: /* FMULX */
8491 gen_helper_vfp_mulxs(tcg_res, tcg_op1, tcg_op2, fpst);
8493 case 0x1c: /* FCMEQ */
8494 gen_helper_neon_ceq_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8496 case 0x1e: /* FMAX */
8497 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
8499 case 0x1f: /* FRECPS */
8500 gen_helper_recpsf_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8502 case 0x18: /* FMAXNM */
8503 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
8505 case 0x38: /* FMINNM */
8506 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
8508 case 0x3a: /* FSUB */
8509 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
8511 case 0x3e: /* FMIN */
8512 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
8514 case 0x3f: /* FRSQRTS */
8515 gen_helper_rsqrtsf_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8517 case 0x5b: /* FMUL */
8518 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
8520 case 0x5c: /* FCMGE */
8521 gen_helper_neon_cge_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8523 case 0x5d: /* FACGE */
8524 gen_helper_neon_acge_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8526 case 0x5f: /* FDIV */
8527 gen_helper_vfp_divs(tcg_res, tcg_op1, tcg_op2, fpst);
8529 case 0x7a: /* FABD */
8530 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
8531 gen_helper_vfp_abss(tcg_res, tcg_res);
8533 case 0x7c: /* FCMGT */
8534 gen_helper_neon_cgt_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8536 case 0x7d: /* FACGT */
8537 gen_helper_neon_acgt_f32(tcg_res, tcg_op1, tcg_op2, fpst);
8540 g_assert_not_reached();
8543 if (elements == 1) {
8544 /* scalar single so clear high part */
8545 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
8547 tcg_gen_extu_i32_i64(tcg_tmp, tcg_res);
8548 write_vec_element(s, tcg_tmp, rd, pass, MO_64);
8549 tcg_temp_free_i64(tcg_tmp);
8551 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
8554 tcg_temp_free_i32(tcg_res);
8555 tcg_temp_free_i32(tcg_op1);
8556 tcg_temp_free_i32(tcg_op2);
8560 tcg_temp_free_ptr(fpst);
8562 clear_vec_high(s, elements * (size ? 8 : 4) > 8, rd);
8565 /* AdvSIMD scalar three same
8566 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8567 * +-----+---+-----------+------+---+------+--------+---+------+------+
8568 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8569 * +-----+---+-----------+------+---+------+--------+---+------+------+
8571 static void disas_simd_scalar_three_reg_same(DisasContext *s, uint32_t insn)
8573 int rd = extract32(insn, 0, 5);
8574 int rn = extract32(insn, 5, 5);
8575 int opcode = extract32(insn, 11, 5);
8576 int rm = extract32(insn, 16, 5);
8577 int size = extract32(insn, 22, 2);
8578 bool u = extract32(insn, 29, 1);
8581 if (opcode >= 0x18) {
8582 /* Floating point: U, size[1] and opcode indicate operation */
8583 int fpopcode = opcode | (extract32(size, 1, 1) << 5) | (u << 6);
8585 case 0x1b: /* FMULX */
8586 case 0x1f: /* FRECPS */
8587 case 0x3f: /* FRSQRTS */
8588 case 0x5d: /* FACGE */
8589 case 0x7d: /* FACGT */
8590 case 0x1c: /* FCMEQ */
8591 case 0x5c: /* FCMGE */
8592 case 0x7c: /* FCMGT */
8593 case 0x7a: /* FABD */
8596 unallocated_encoding(s);
8600 if (!fp_access_check(s)) {
8604 handle_3same_float(s, extract32(size, 0, 1), 1, fpopcode, rd, rn, rm);
8609 case 0x1: /* SQADD, UQADD */
8610 case 0x5: /* SQSUB, UQSUB */
8611 case 0x9: /* SQSHL, UQSHL */
8612 case 0xb: /* SQRSHL, UQRSHL */
8614 case 0x8: /* SSHL, USHL */
8615 case 0xa: /* SRSHL, URSHL */
8616 case 0x6: /* CMGT, CMHI */
8617 case 0x7: /* CMGE, CMHS */
8618 case 0x11: /* CMTST, CMEQ */
8619 case 0x10: /* ADD, SUB (vector) */
8621 unallocated_encoding(s);
8625 case 0x16: /* SQDMULH, SQRDMULH (vector) */
8626 if (size != 1 && size != 2) {
8627 unallocated_encoding(s);
8632 unallocated_encoding(s);
8636 if (!fp_access_check(s)) {
8640 tcg_rd = tcg_temp_new_i64();
8643 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
8644 TCGv_i64 tcg_rm = read_fp_dreg(s, rm);
8646 handle_3same_64(s, opcode, u, tcg_rd, tcg_rn, tcg_rm);
8647 tcg_temp_free_i64(tcg_rn);
8648 tcg_temp_free_i64(tcg_rm);
8650 /* Do a single operation on the lowest element in the vector.
8651 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
8652 * no side effects for all these operations.
8653 * OPTME: special-purpose helpers would avoid doing some
8654 * unnecessary work in the helper for the 8 and 16 bit cases.
8656 NeonGenTwoOpEnvFn *genenvfn;
8657 TCGv_i32 tcg_rn = tcg_temp_new_i32();
8658 TCGv_i32 tcg_rm = tcg_temp_new_i32();
8659 TCGv_i32 tcg_rd32 = tcg_temp_new_i32();
8661 read_vec_element_i32(s, tcg_rn, rn, 0, size);
8662 read_vec_element_i32(s, tcg_rm, rm, 0, size);
8665 case 0x1: /* SQADD, UQADD */
8667 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8668 { gen_helper_neon_qadd_s8, gen_helper_neon_qadd_u8 },
8669 { gen_helper_neon_qadd_s16, gen_helper_neon_qadd_u16 },
8670 { gen_helper_neon_qadd_s32, gen_helper_neon_qadd_u32 },
8672 genenvfn = fns[size][u];
8675 case 0x5: /* SQSUB, UQSUB */
8677 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8678 { gen_helper_neon_qsub_s8, gen_helper_neon_qsub_u8 },
8679 { gen_helper_neon_qsub_s16, gen_helper_neon_qsub_u16 },
8680 { gen_helper_neon_qsub_s32, gen_helper_neon_qsub_u32 },
8682 genenvfn = fns[size][u];
8685 case 0x9: /* SQSHL, UQSHL */
8687 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8688 { gen_helper_neon_qshl_s8, gen_helper_neon_qshl_u8 },
8689 { gen_helper_neon_qshl_s16, gen_helper_neon_qshl_u16 },
8690 { gen_helper_neon_qshl_s32, gen_helper_neon_qshl_u32 },
8692 genenvfn = fns[size][u];
8695 case 0xb: /* SQRSHL, UQRSHL */
8697 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8698 { gen_helper_neon_qrshl_s8, gen_helper_neon_qrshl_u8 },
8699 { gen_helper_neon_qrshl_s16, gen_helper_neon_qrshl_u16 },
8700 { gen_helper_neon_qrshl_s32, gen_helper_neon_qrshl_u32 },
8702 genenvfn = fns[size][u];
8705 case 0x16: /* SQDMULH, SQRDMULH */
8707 static NeonGenTwoOpEnvFn * const fns[2][2] = {
8708 { gen_helper_neon_qdmulh_s16, gen_helper_neon_qrdmulh_s16 },
8709 { gen_helper_neon_qdmulh_s32, gen_helper_neon_qrdmulh_s32 },
8711 assert(size == 1 || size == 2);
8712 genenvfn = fns[size - 1][u];
8716 g_assert_not_reached();
8719 genenvfn(tcg_rd32, cpu_env, tcg_rn, tcg_rm);
8720 tcg_gen_extu_i32_i64(tcg_rd, tcg_rd32);
8721 tcg_temp_free_i32(tcg_rd32);
8722 tcg_temp_free_i32(tcg_rn);
8723 tcg_temp_free_i32(tcg_rm);
8726 write_fp_dreg(s, rd, tcg_rd);
8728 tcg_temp_free_i64(tcg_rd);
8731 /* AdvSIMD scalar three same FP16
8732 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
8733 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8734 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
8735 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8736 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
8737 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
8739 static void disas_simd_scalar_three_reg_same_fp16(DisasContext *s,
8742 int rd = extract32(insn, 0, 5);
8743 int rn = extract32(insn, 5, 5);
8744 int opcode = extract32(insn, 11, 3);
8745 int rm = extract32(insn, 16, 5);
8746 bool u = extract32(insn, 29, 1);
8747 bool a = extract32(insn, 23, 1);
8748 int fpopcode = opcode | (a << 3) | (u << 4);
8755 case 0x03: /* FMULX */
8756 case 0x04: /* FCMEQ (reg) */
8757 case 0x07: /* FRECPS */
8758 case 0x0f: /* FRSQRTS */
8759 case 0x14: /* FCMGE (reg) */
8760 case 0x15: /* FACGE */
8761 case 0x1a: /* FABD */
8762 case 0x1c: /* FCMGT (reg) */
8763 case 0x1d: /* FACGT */
8766 unallocated_encoding(s);
8770 if (!dc_isar_feature(aa64_fp16, s)) {
8771 unallocated_encoding(s);
8774 if (!fp_access_check(s)) {
8778 fpst = get_fpstatus_ptr(true);
8780 tcg_op1 = read_fp_hreg(s, rn);
8781 tcg_op2 = read_fp_hreg(s, rm);
8782 tcg_res = tcg_temp_new_i32();
8785 case 0x03: /* FMULX */
8786 gen_helper_advsimd_mulxh(tcg_res, tcg_op1, tcg_op2, fpst);
8788 case 0x04: /* FCMEQ (reg) */
8789 gen_helper_advsimd_ceq_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8791 case 0x07: /* FRECPS */
8792 gen_helper_recpsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8794 case 0x0f: /* FRSQRTS */
8795 gen_helper_rsqrtsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8797 case 0x14: /* FCMGE (reg) */
8798 gen_helper_advsimd_cge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8800 case 0x15: /* FACGE */
8801 gen_helper_advsimd_acge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8803 case 0x1a: /* FABD */
8804 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
8805 tcg_gen_andi_i32(tcg_res, tcg_res, 0x7fff);
8807 case 0x1c: /* FCMGT (reg) */
8808 gen_helper_advsimd_cgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8810 case 0x1d: /* FACGT */
8811 gen_helper_advsimd_acgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
8814 g_assert_not_reached();
8817 write_fp_sreg(s, rd, tcg_res);
8820 tcg_temp_free_i32(tcg_res);
8821 tcg_temp_free_i32(tcg_op1);
8822 tcg_temp_free_i32(tcg_op2);
8823 tcg_temp_free_ptr(fpst);
8826 /* AdvSIMD scalar three same extra
8827 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
8828 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
8829 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
8830 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
8832 static void disas_simd_scalar_three_reg_same_extra(DisasContext *s,
8835 int rd = extract32(insn, 0, 5);
8836 int rn = extract32(insn, 5, 5);
8837 int opcode = extract32(insn, 11, 4);
8838 int rm = extract32(insn, 16, 5);
8839 int size = extract32(insn, 22, 2);
8840 bool u = extract32(insn, 29, 1);
8841 TCGv_i32 ele1, ele2, ele3;
8845 switch (u * 16 + opcode) {
8846 case 0x10: /* SQRDMLAH (vector) */
8847 case 0x11: /* SQRDMLSH (vector) */
8848 if (size != 1 && size != 2) {
8849 unallocated_encoding(s);
8852 feature = dc_isar_feature(aa64_rdm, s);
8855 unallocated_encoding(s);
8859 unallocated_encoding(s);
8862 if (!fp_access_check(s)) {
8866 /* Do a single operation on the lowest element in the vector.
8867 * We use the standard Neon helpers and rely on 0 OP 0 == 0
8868 * with no side effects for all these operations.
8869 * OPTME: special-purpose helpers would avoid doing some
8870 * unnecessary work in the helper for the 16 bit cases.
8872 ele1 = tcg_temp_new_i32();
8873 ele2 = tcg_temp_new_i32();
8874 ele3 = tcg_temp_new_i32();
8876 read_vec_element_i32(s, ele1, rn, 0, size);
8877 read_vec_element_i32(s, ele2, rm, 0, size);
8878 read_vec_element_i32(s, ele3, rd, 0, size);
8881 case 0x0: /* SQRDMLAH */
8883 gen_helper_neon_qrdmlah_s16(ele3, cpu_env, ele1, ele2, ele3);
8885 gen_helper_neon_qrdmlah_s32(ele3, cpu_env, ele1, ele2, ele3);
8888 case 0x1: /* SQRDMLSH */
8890 gen_helper_neon_qrdmlsh_s16(ele3, cpu_env, ele1, ele2, ele3);
8892 gen_helper_neon_qrdmlsh_s32(ele3, cpu_env, ele1, ele2, ele3);
8896 g_assert_not_reached();
8898 tcg_temp_free_i32(ele1);
8899 tcg_temp_free_i32(ele2);
8901 res = tcg_temp_new_i64();
8902 tcg_gen_extu_i32_i64(res, ele3);
8903 tcg_temp_free_i32(ele3);
8905 write_fp_dreg(s, rd, res);
8906 tcg_temp_free_i64(res);
8909 static void handle_2misc_64(DisasContext *s, int opcode, bool u,
8910 TCGv_i64 tcg_rd, TCGv_i64 tcg_rn,
8911 TCGv_i32 tcg_rmode, TCGv_ptr tcg_fpstatus)
8913 /* Handle 64->64 opcodes which are shared between the scalar and
8914 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
8915 * is valid in either group and also the double-precision fp ops.
8916 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
8922 case 0x4: /* CLS, CLZ */
8924 tcg_gen_clzi_i64(tcg_rd, tcg_rn, 64);
8926 tcg_gen_clrsb_i64(tcg_rd, tcg_rn);
8930 /* This opcode is shared with CNT and RBIT but we have earlier
8931 * enforced that size == 3 if and only if this is the NOT insn.
8933 tcg_gen_not_i64(tcg_rd, tcg_rn);
8935 case 0x7: /* SQABS, SQNEG */
8937 gen_helper_neon_qneg_s64(tcg_rd, cpu_env, tcg_rn);
8939 gen_helper_neon_qabs_s64(tcg_rd, cpu_env, tcg_rn);
8942 case 0xa: /* CMLT */
8943 /* 64 bit integer comparison against zero, result is
8944 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
8949 tcg_gen_setcondi_i64(cond, tcg_rd, tcg_rn, 0);
8950 tcg_gen_neg_i64(tcg_rd, tcg_rd);
8952 case 0x8: /* CMGT, CMGE */
8953 cond = u ? TCG_COND_GE : TCG_COND_GT;
8955 case 0x9: /* CMEQ, CMLE */
8956 cond = u ? TCG_COND_LE : TCG_COND_EQ;
8958 case 0xb: /* ABS, NEG */
8960 tcg_gen_neg_i64(tcg_rd, tcg_rn);
8962 TCGv_i64 tcg_zero = tcg_const_i64(0);
8963 tcg_gen_neg_i64(tcg_rd, tcg_rn);
8964 tcg_gen_movcond_i64(TCG_COND_GT, tcg_rd, tcg_rn, tcg_zero,
8966 tcg_temp_free_i64(tcg_zero);
8969 case 0x2f: /* FABS */
8970 gen_helper_vfp_absd(tcg_rd, tcg_rn);
8972 case 0x6f: /* FNEG */
8973 gen_helper_vfp_negd(tcg_rd, tcg_rn);
8975 case 0x7f: /* FSQRT */
8976 gen_helper_vfp_sqrtd(tcg_rd, tcg_rn, cpu_env);
8978 case 0x1a: /* FCVTNS */
8979 case 0x1b: /* FCVTMS */
8980 case 0x1c: /* FCVTAS */
8981 case 0x3a: /* FCVTPS */
8982 case 0x3b: /* FCVTZS */
8984 TCGv_i32 tcg_shift = tcg_const_i32(0);
8985 gen_helper_vfp_tosqd(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
8986 tcg_temp_free_i32(tcg_shift);
8989 case 0x5a: /* FCVTNU */
8990 case 0x5b: /* FCVTMU */
8991 case 0x5c: /* FCVTAU */
8992 case 0x7a: /* FCVTPU */
8993 case 0x7b: /* FCVTZU */
8995 TCGv_i32 tcg_shift = tcg_const_i32(0);
8996 gen_helper_vfp_touqd(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
8997 tcg_temp_free_i32(tcg_shift);
9000 case 0x18: /* FRINTN */
9001 case 0x19: /* FRINTM */
9002 case 0x38: /* FRINTP */
9003 case 0x39: /* FRINTZ */
9004 case 0x58: /* FRINTA */
9005 case 0x79: /* FRINTI */
9006 gen_helper_rintd(tcg_rd, tcg_rn, tcg_fpstatus);
9008 case 0x59: /* FRINTX */
9009 gen_helper_rintd_exact(tcg_rd, tcg_rn, tcg_fpstatus);
9012 g_assert_not_reached();
9016 static void handle_2misc_fcmp_zero(DisasContext *s, int opcode,
9017 bool is_scalar, bool is_u, bool is_q,
9018 int size, int rn, int rd)
9020 bool is_double = (size == MO_64);
9023 if (!fp_access_check(s)) {
9027 fpst = get_fpstatus_ptr(size == MO_16);
9030 TCGv_i64 tcg_op = tcg_temp_new_i64();
9031 TCGv_i64 tcg_zero = tcg_const_i64(0);
9032 TCGv_i64 tcg_res = tcg_temp_new_i64();
9033 NeonGenTwoDoubleOPFn *genfn;
9038 case 0x2e: /* FCMLT (zero) */
9041 case 0x2c: /* FCMGT (zero) */
9042 genfn = gen_helper_neon_cgt_f64;
9044 case 0x2d: /* FCMEQ (zero) */
9045 genfn = gen_helper_neon_ceq_f64;
9047 case 0x6d: /* FCMLE (zero) */
9050 case 0x6c: /* FCMGE (zero) */
9051 genfn = gen_helper_neon_cge_f64;
9054 g_assert_not_reached();
9057 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9058 read_vec_element(s, tcg_op, rn, pass, MO_64);
9060 genfn(tcg_res, tcg_zero, tcg_op, fpst);
9062 genfn(tcg_res, tcg_op, tcg_zero, fpst);
9064 write_vec_element(s, tcg_res, rd, pass, MO_64);
9066 tcg_temp_free_i64(tcg_res);
9067 tcg_temp_free_i64(tcg_zero);
9068 tcg_temp_free_i64(tcg_op);
9070 clear_vec_high(s, !is_scalar, rd);
9072 TCGv_i32 tcg_op = tcg_temp_new_i32();
9073 TCGv_i32 tcg_zero = tcg_const_i32(0);
9074 TCGv_i32 tcg_res = tcg_temp_new_i32();
9075 NeonGenTwoSingleOPFn *genfn;
9077 int pass, maxpasses;
9079 if (size == MO_16) {
9081 case 0x2e: /* FCMLT (zero) */
9084 case 0x2c: /* FCMGT (zero) */
9085 genfn = gen_helper_advsimd_cgt_f16;
9087 case 0x2d: /* FCMEQ (zero) */
9088 genfn = gen_helper_advsimd_ceq_f16;
9090 case 0x6d: /* FCMLE (zero) */
9093 case 0x6c: /* FCMGE (zero) */
9094 genfn = gen_helper_advsimd_cge_f16;
9097 g_assert_not_reached();
9101 case 0x2e: /* FCMLT (zero) */
9104 case 0x2c: /* FCMGT (zero) */
9105 genfn = gen_helper_neon_cgt_f32;
9107 case 0x2d: /* FCMEQ (zero) */
9108 genfn = gen_helper_neon_ceq_f32;
9110 case 0x6d: /* FCMLE (zero) */
9113 case 0x6c: /* FCMGE (zero) */
9114 genfn = gen_helper_neon_cge_f32;
9117 g_assert_not_reached();
9124 int vector_size = 8 << is_q;
9125 maxpasses = vector_size >> size;
9128 for (pass = 0; pass < maxpasses; pass++) {
9129 read_vec_element_i32(s, tcg_op, rn, pass, size);
9131 genfn(tcg_res, tcg_zero, tcg_op, fpst);
9133 genfn(tcg_res, tcg_op, tcg_zero, fpst);
9136 write_fp_sreg(s, rd, tcg_res);
9138 write_vec_element_i32(s, tcg_res, rd, pass, size);
9141 tcg_temp_free_i32(tcg_res);
9142 tcg_temp_free_i32(tcg_zero);
9143 tcg_temp_free_i32(tcg_op);
9145 clear_vec_high(s, is_q, rd);
9149 tcg_temp_free_ptr(fpst);
9152 static void handle_2misc_reciprocal(DisasContext *s, int opcode,
9153 bool is_scalar, bool is_u, bool is_q,
9154 int size, int rn, int rd)
9156 bool is_double = (size == 3);
9157 TCGv_ptr fpst = get_fpstatus_ptr(false);
9160 TCGv_i64 tcg_op = tcg_temp_new_i64();
9161 TCGv_i64 tcg_res = tcg_temp_new_i64();
9164 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9165 read_vec_element(s, tcg_op, rn, pass, MO_64);
9167 case 0x3d: /* FRECPE */
9168 gen_helper_recpe_f64(tcg_res, tcg_op, fpst);
9170 case 0x3f: /* FRECPX */
9171 gen_helper_frecpx_f64(tcg_res, tcg_op, fpst);
9173 case 0x7d: /* FRSQRTE */
9174 gen_helper_rsqrte_f64(tcg_res, tcg_op, fpst);
9177 g_assert_not_reached();
9179 write_vec_element(s, tcg_res, rd, pass, MO_64);
9181 tcg_temp_free_i64(tcg_res);
9182 tcg_temp_free_i64(tcg_op);
9183 clear_vec_high(s, !is_scalar, rd);
9185 TCGv_i32 tcg_op = tcg_temp_new_i32();
9186 TCGv_i32 tcg_res = tcg_temp_new_i32();
9187 int pass, maxpasses;
9192 maxpasses = is_q ? 4 : 2;
9195 for (pass = 0; pass < maxpasses; pass++) {
9196 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
9199 case 0x3c: /* URECPE */
9200 gen_helper_recpe_u32(tcg_res, tcg_op, fpst);
9202 case 0x3d: /* FRECPE */
9203 gen_helper_recpe_f32(tcg_res, tcg_op, fpst);
9205 case 0x3f: /* FRECPX */
9206 gen_helper_frecpx_f32(tcg_res, tcg_op, fpst);
9208 case 0x7d: /* FRSQRTE */
9209 gen_helper_rsqrte_f32(tcg_res, tcg_op, fpst);
9212 g_assert_not_reached();
9216 write_fp_sreg(s, rd, tcg_res);
9218 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
9221 tcg_temp_free_i32(tcg_res);
9222 tcg_temp_free_i32(tcg_op);
9224 clear_vec_high(s, is_q, rd);
9227 tcg_temp_free_ptr(fpst);
9230 static void handle_2misc_narrow(DisasContext *s, bool scalar,
9231 int opcode, bool u, bool is_q,
9232 int size, int rn, int rd)
9234 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
9235 * in the source becomes a size element in the destination).
9238 TCGv_i32 tcg_res[2];
9239 int destelt = is_q ? 2 : 0;
9240 int passes = scalar ? 1 : 2;
9243 tcg_res[1] = tcg_const_i32(0);
9246 for (pass = 0; pass < passes; pass++) {
9247 TCGv_i64 tcg_op = tcg_temp_new_i64();
9248 NeonGenNarrowFn *genfn = NULL;
9249 NeonGenNarrowEnvFn *genenvfn = NULL;
9252 read_vec_element(s, tcg_op, rn, pass, size + 1);
9254 read_vec_element(s, tcg_op, rn, pass, MO_64);
9256 tcg_res[pass] = tcg_temp_new_i32();
9259 case 0x12: /* XTN, SQXTUN */
9261 static NeonGenNarrowFn * const xtnfns[3] = {
9262 gen_helper_neon_narrow_u8,
9263 gen_helper_neon_narrow_u16,
9264 tcg_gen_extrl_i64_i32,
9266 static NeonGenNarrowEnvFn * const sqxtunfns[3] = {
9267 gen_helper_neon_unarrow_sat8,
9268 gen_helper_neon_unarrow_sat16,
9269 gen_helper_neon_unarrow_sat32,
9272 genenvfn = sqxtunfns[size];
9274 genfn = xtnfns[size];
9278 case 0x14: /* SQXTN, UQXTN */
9280 static NeonGenNarrowEnvFn * const fns[3][2] = {
9281 { gen_helper_neon_narrow_sat_s8,
9282 gen_helper_neon_narrow_sat_u8 },
9283 { gen_helper_neon_narrow_sat_s16,
9284 gen_helper_neon_narrow_sat_u16 },
9285 { gen_helper_neon_narrow_sat_s32,
9286 gen_helper_neon_narrow_sat_u32 },
9288 genenvfn = fns[size][u];
9291 case 0x16: /* FCVTN, FCVTN2 */
9292 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
9294 gen_helper_vfp_fcvtsd(tcg_res[pass], tcg_op, cpu_env);
9296 TCGv_i32 tcg_lo = tcg_temp_new_i32();
9297 TCGv_i32 tcg_hi = tcg_temp_new_i32();
9298 TCGv_ptr fpst = get_fpstatus_ptr(false);
9299 TCGv_i32 ahp = get_ahp_flag();
9301 tcg_gen_extr_i64_i32(tcg_lo, tcg_hi, tcg_op);
9302 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo, tcg_lo, fpst, ahp);
9303 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi, tcg_hi, fpst, ahp);
9304 tcg_gen_deposit_i32(tcg_res[pass], tcg_lo, tcg_hi, 16, 16);
9305 tcg_temp_free_i32(tcg_lo);
9306 tcg_temp_free_i32(tcg_hi);
9307 tcg_temp_free_ptr(fpst);
9308 tcg_temp_free_i32(ahp);
9311 case 0x56: /* FCVTXN, FCVTXN2 */
9312 /* 64 bit to 32 bit float conversion
9313 * with von Neumann rounding (round to odd)
9316 gen_helper_fcvtx_f64_to_f32(tcg_res[pass], tcg_op, cpu_env);
9319 g_assert_not_reached();
9323 genfn(tcg_res[pass], tcg_op);
9324 } else if (genenvfn) {
9325 genenvfn(tcg_res[pass], cpu_env, tcg_op);
9328 tcg_temp_free_i64(tcg_op);
9331 for (pass = 0; pass < 2; pass++) {
9332 write_vec_element_i32(s, tcg_res[pass], rd, destelt + pass, MO_32);
9333 tcg_temp_free_i32(tcg_res[pass]);
9335 clear_vec_high(s, is_q, rd);
9338 /* Remaining saturating accumulating ops */
9339 static void handle_2misc_satacc(DisasContext *s, bool is_scalar, bool is_u,
9340 bool is_q, int size, int rn, int rd)
9342 bool is_double = (size == 3);
9345 TCGv_i64 tcg_rn = tcg_temp_new_i64();
9346 TCGv_i64 tcg_rd = tcg_temp_new_i64();
9349 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9350 read_vec_element(s, tcg_rn, rn, pass, MO_64);
9351 read_vec_element(s, tcg_rd, rd, pass, MO_64);
9353 if (is_u) { /* USQADD */
9354 gen_helper_neon_uqadd_s64(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9355 } else { /* SUQADD */
9356 gen_helper_neon_sqadd_u64(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9358 write_vec_element(s, tcg_rd, rd, pass, MO_64);
9360 tcg_temp_free_i64(tcg_rd);
9361 tcg_temp_free_i64(tcg_rn);
9362 clear_vec_high(s, !is_scalar, rd);
9364 TCGv_i32 tcg_rn = tcg_temp_new_i32();
9365 TCGv_i32 tcg_rd = tcg_temp_new_i32();
9366 int pass, maxpasses;
9371 maxpasses = is_q ? 4 : 2;
9374 for (pass = 0; pass < maxpasses; pass++) {
9376 read_vec_element_i32(s, tcg_rn, rn, pass, size);
9377 read_vec_element_i32(s, tcg_rd, rd, pass, size);
9379 read_vec_element_i32(s, tcg_rn, rn, pass, MO_32);
9380 read_vec_element_i32(s, tcg_rd, rd, pass, MO_32);
9383 if (is_u) { /* USQADD */
9386 gen_helper_neon_uqadd_s8(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9389 gen_helper_neon_uqadd_s16(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9392 gen_helper_neon_uqadd_s32(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9395 g_assert_not_reached();
9397 } else { /* SUQADD */
9400 gen_helper_neon_sqadd_u8(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9403 gen_helper_neon_sqadd_u16(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9406 gen_helper_neon_sqadd_u32(tcg_rd, cpu_env, tcg_rn, tcg_rd);
9409 g_assert_not_reached();
9414 TCGv_i64 tcg_zero = tcg_const_i64(0);
9415 write_vec_element(s, tcg_zero, rd, 0, MO_64);
9416 tcg_temp_free_i64(tcg_zero);
9418 write_vec_element_i32(s, tcg_rd, rd, pass, MO_32);
9420 tcg_temp_free_i32(tcg_rd);
9421 tcg_temp_free_i32(tcg_rn);
9422 clear_vec_high(s, is_q, rd);
9426 /* AdvSIMD scalar two reg misc
9427 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9428 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9429 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9430 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9432 static void disas_simd_scalar_two_reg_misc(DisasContext *s, uint32_t insn)
9434 int rd = extract32(insn, 0, 5);
9435 int rn = extract32(insn, 5, 5);
9436 int opcode = extract32(insn, 12, 5);
9437 int size = extract32(insn, 22, 2);
9438 bool u = extract32(insn, 29, 1);
9439 bool is_fcvt = false;
9442 TCGv_ptr tcg_fpstatus;
9445 case 0x3: /* USQADD / SUQADD*/
9446 if (!fp_access_check(s)) {
9449 handle_2misc_satacc(s, true, u, false, size, rn, rd);
9451 case 0x7: /* SQABS / SQNEG */
9453 case 0xa: /* CMLT */
9455 unallocated_encoding(s);
9459 case 0x8: /* CMGT, CMGE */
9460 case 0x9: /* CMEQ, CMLE */
9461 case 0xb: /* ABS, NEG */
9463 unallocated_encoding(s);
9467 case 0x12: /* SQXTUN */
9469 unallocated_encoding(s);
9473 case 0x14: /* SQXTN, UQXTN */
9475 unallocated_encoding(s);
9478 if (!fp_access_check(s)) {
9481 handle_2misc_narrow(s, true, opcode, u, false, size, rn, rd);
9486 /* Floating point: U, size[1] and opcode indicate operation;
9487 * size[0] indicates single or double precision.
9489 opcode |= (extract32(size, 1, 1) << 5) | (u << 6);
9490 size = extract32(size, 0, 1) ? 3 : 2;
9492 case 0x2c: /* FCMGT (zero) */
9493 case 0x2d: /* FCMEQ (zero) */
9494 case 0x2e: /* FCMLT (zero) */
9495 case 0x6c: /* FCMGE (zero) */
9496 case 0x6d: /* FCMLE (zero) */
9497 handle_2misc_fcmp_zero(s, opcode, true, u, true, size, rn, rd);
9499 case 0x1d: /* SCVTF */
9500 case 0x5d: /* UCVTF */
9502 bool is_signed = (opcode == 0x1d);
9503 if (!fp_access_check(s)) {
9506 handle_simd_intfp_conv(s, rd, rn, 1, is_signed, 0, size);
9509 case 0x3d: /* FRECPE */
9510 case 0x3f: /* FRECPX */
9511 case 0x7d: /* FRSQRTE */
9512 if (!fp_access_check(s)) {
9515 handle_2misc_reciprocal(s, opcode, true, u, true, size, rn, rd);
9517 case 0x1a: /* FCVTNS */
9518 case 0x1b: /* FCVTMS */
9519 case 0x3a: /* FCVTPS */
9520 case 0x3b: /* FCVTZS */
9521 case 0x5a: /* FCVTNU */
9522 case 0x5b: /* FCVTMU */
9523 case 0x7a: /* FCVTPU */
9524 case 0x7b: /* FCVTZU */
9526 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
9528 case 0x1c: /* FCVTAS */
9529 case 0x5c: /* FCVTAU */
9530 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
9532 rmode = FPROUNDING_TIEAWAY;
9534 case 0x56: /* FCVTXN, FCVTXN2 */
9536 unallocated_encoding(s);
9539 if (!fp_access_check(s)) {
9542 handle_2misc_narrow(s, true, opcode, u, false, size - 1, rn, rd);
9545 unallocated_encoding(s);
9550 unallocated_encoding(s);
9554 if (!fp_access_check(s)) {
9559 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
9560 tcg_fpstatus = get_fpstatus_ptr(false);
9561 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
9564 tcg_fpstatus = NULL;
9568 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
9569 TCGv_i64 tcg_rd = tcg_temp_new_i64();
9571 handle_2misc_64(s, opcode, u, tcg_rd, tcg_rn, tcg_rmode, tcg_fpstatus);
9572 write_fp_dreg(s, rd, tcg_rd);
9573 tcg_temp_free_i64(tcg_rd);
9574 tcg_temp_free_i64(tcg_rn);
9576 TCGv_i32 tcg_rn = tcg_temp_new_i32();
9577 TCGv_i32 tcg_rd = tcg_temp_new_i32();
9579 read_vec_element_i32(s, tcg_rn, rn, 0, size);
9582 case 0x7: /* SQABS, SQNEG */
9584 NeonGenOneOpEnvFn *genfn;
9585 static NeonGenOneOpEnvFn * const fns[3][2] = {
9586 { gen_helper_neon_qabs_s8, gen_helper_neon_qneg_s8 },
9587 { gen_helper_neon_qabs_s16, gen_helper_neon_qneg_s16 },
9588 { gen_helper_neon_qabs_s32, gen_helper_neon_qneg_s32 },
9590 genfn = fns[size][u];
9591 genfn(tcg_rd, cpu_env, tcg_rn);
9594 case 0x1a: /* FCVTNS */
9595 case 0x1b: /* FCVTMS */
9596 case 0x1c: /* FCVTAS */
9597 case 0x3a: /* FCVTPS */
9598 case 0x3b: /* FCVTZS */
9600 TCGv_i32 tcg_shift = tcg_const_i32(0);
9601 gen_helper_vfp_tosls(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9602 tcg_temp_free_i32(tcg_shift);
9605 case 0x5a: /* FCVTNU */
9606 case 0x5b: /* FCVTMU */
9607 case 0x5c: /* FCVTAU */
9608 case 0x7a: /* FCVTPU */
9609 case 0x7b: /* FCVTZU */
9611 TCGv_i32 tcg_shift = tcg_const_i32(0);
9612 gen_helper_vfp_touls(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
9613 tcg_temp_free_i32(tcg_shift);
9617 g_assert_not_reached();
9620 write_fp_sreg(s, rd, tcg_rd);
9621 tcg_temp_free_i32(tcg_rd);
9622 tcg_temp_free_i32(tcg_rn);
9626 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
9627 tcg_temp_free_i32(tcg_rmode);
9628 tcg_temp_free_ptr(tcg_fpstatus);
9632 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
9633 static void handle_vec_simd_shri(DisasContext *s, bool is_q, bool is_u,
9634 int immh, int immb, int opcode, int rn, int rd)
9636 int size = 32 - clz32(immh) - 1;
9637 int immhb = immh << 3 | immb;
9638 int shift = 2 * (8 << size) - immhb;
9639 bool accumulate = false;
9640 int dsize = is_q ? 128 : 64;
9641 int esize = 8 << size;
9642 int elements = dsize/esize;
9643 TCGMemOp memop = size | (is_u ? 0 : MO_SIGN);
9644 TCGv_i64 tcg_rn = new_tmp_a64(s);
9645 TCGv_i64 tcg_rd = new_tmp_a64(s);
9647 uint64_t round_const;
9650 if (extract32(immh, 3, 1) && !is_q) {
9651 unallocated_encoding(s);
9654 tcg_debug_assert(size <= 3);
9656 if (!fp_access_check(s)) {
9661 case 0x02: /* SSRA / USRA (accumulate) */
9663 /* Shift count same as element size produces zero to add. */
9664 if (shift == 8 << size) {
9667 gen_gvec_op2i(s, is_q, rd, rn, shift, &usra_op[size]);
9669 /* Shift count same as element size produces all sign to add. */
9670 if (shift == 8 << size) {
9673 gen_gvec_op2i(s, is_q, rd, rn, shift, &ssra_op[size]);
9676 case 0x08: /* SRI */
9677 /* Shift count same as element size is valid but does nothing. */
9678 if (shift == 8 << size) {
9681 gen_gvec_op2i(s, is_q, rd, rn, shift, &sri_op[size]);
9684 case 0x00: /* SSHR / USHR */
9686 if (shift == 8 << size) {
9687 /* Shift count the same size as element size produces zero. */
9688 tcg_gen_gvec_dup8i(vec_full_reg_offset(s, rd),
9689 is_q ? 16 : 8, vec_full_reg_size(s), 0);
9691 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_shri, size);
9694 /* Shift count the same size as element size produces all sign. */
9695 if (shift == 8 << size) {
9698 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_sari, size);
9702 case 0x04: /* SRSHR / URSHR (rounding) */
9704 case 0x06: /* SRSRA / URSRA (accum + rounding) */
9708 g_assert_not_reached();
9711 round_const = 1ULL << (shift - 1);
9712 tcg_round = tcg_const_i64(round_const);
9714 for (i = 0; i < elements; i++) {
9715 read_vec_element(s, tcg_rn, rn, i, memop);
9717 read_vec_element(s, tcg_rd, rd, i, memop);
9720 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
9721 accumulate, is_u, size, shift);
9723 write_vec_element(s, tcg_rd, rd, i, size);
9725 tcg_temp_free_i64(tcg_round);
9728 clear_vec_high(s, is_q, rd);
9731 /* SHL/SLI - Vector shift left */
9732 static void handle_vec_simd_shli(DisasContext *s, bool is_q, bool insert,
9733 int immh, int immb, int opcode, int rn, int rd)
9735 int size = 32 - clz32(immh) - 1;
9736 int immhb = immh << 3 | immb;
9737 int shift = immhb - (8 << size);
9739 /* Range of size is limited by decode: immh is a non-zero 4 bit field */
9740 assert(size >= 0 && size <= 3);
9742 if (extract32(immh, 3, 1) && !is_q) {
9743 unallocated_encoding(s);
9747 if (!fp_access_check(s)) {
9752 gen_gvec_op2i(s, is_q, rd, rn, shift, &sli_op[size]);
9754 gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_shli, size);
9758 /* USHLL/SHLL - Vector shift left with widening */
9759 static void handle_vec_simd_wshli(DisasContext *s, bool is_q, bool is_u,
9760 int immh, int immb, int opcode, int rn, int rd)
9762 int size = 32 - clz32(immh) - 1;
9763 int immhb = immh << 3 | immb;
9764 int shift = immhb - (8 << size);
9766 int esize = 8 << size;
9767 int elements = dsize/esize;
9768 TCGv_i64 tcg_rn = new_tmp_a64(s);
9769 TCGv_i64 tcg_rd = new_tmp_a64(s);
9773 unallocated_encoding(s);
9777 if (!fp_access_check(s)) {
9781 /* For the LL variants the store is larger than the load,
9782 * so if rd == rn we would overwrite parts of our input.
9783 * So load everything right now and use shifts in the main loop.
9785 read_vec_element(s, tcg_rn, rn, is_q ? 1 : 0, MO_64);
9787 for (i = 0; i < elements; i++) {
9788 tcg_gen_shri_i64(tcg_rd, tcg_rn, i * esize);
9789 ext_and_shift_reg(tcg_rd, tcg_rd, size | (!is_u << 2), 0);
9790 tcg_gen_shli_i64(tcg_rd, tcg_rd, shift);
9791 write_vec_element(s, tcg_rd, rd, i, size + 1);
9795 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
9796 static void handle_vec_simd_shrn(DisasContext *s, bool is_q,
9797 int immh, int immb, int opcode, int rn, int rd)
9799 int immhb = immh << 3 | immb;
9800 int size = 32 - clz32(immh) - 1;
9802 int esize = 8 << size;
9803 int elements = dsize/esize;
9804 int shift = (2 * esize) - immhb;
9805 bool round = extract32(opcode, 0, 1);
9806 TCGv_i64 tcg_rn, tcg_rd, tcg_final;
9810 if (extract32(immh, 3, 1)) {
9811 unallocated_encoding(s);
9815 if (!fp_access_check(s)) {
9819 tcg_rn = tcg_temp_new_i64();
9820 tcg_rd = tcg_temp_new_i64();
9821 tcg_final = tcg_temp_new_i64();
9822 read_vec_element(s, tcg_final, rd, is_q ? 1 : 0, MO_64);
9825 uint64_t round_const = 1ULL << (shift - 1);
9826 tcg_round = tcg_const_i64(round_const);
9831 for (i = 0; i < elements; i++) {
9832 read_vec_element(s, tcg_rn, rn, i, size+1);
9833 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
9834 false, true, size+1, shift);
9836 tcg_gen_deposit_i64(tcg_final, tcg_final, tcg_rd, esize * i, esize);
9840 write_vec_element(s, tcg_final, rd, 0, MO_64);
9842 write_vec_element(s, tcg_final, rd, 1, MO_64);
9845 tcg_temp_free_i64(tcg_round);
9847 tcg_temp_free_i64(tcg_rn);
9848 tcg_temp_free_i64(tcg_rd);
9849 tcg_temp_free_i64(tcg_final);
9851 clear_vec_high(s, is_q, rd);
9855 /* AdvSIMD shift by immediate
9856 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
9857 * +---+---+---+-------------+------+------+--------+---+------+------+
9858 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
9859 * +---+---+---+-------------+------+------+--------+---+------+------+
9861 static void disas_simd_shift_imm(DisasContext *s, uint32_t insn)
9863 int rd = extract32(insn, 0, 5);
9864 int rn = extract32(insn, 5, 5);
9865 int opcode = extract32(insn, 11, 5);
9866 int immb = extract32(insn, 16, 3);
9867 int immh = extract32(insn, 19, 4);
9868 bool is_u = extract32(insn, 29, 1);
9869 bool is_q = extract32(insn, 30, 1);
9872 case 0x08: /* SRI */
9874 unallocated_encoding(s);
9878 case 0x00: /* SSHR / USHR */
9879 case 0x02: /* SSRA / USRA (accumulate) */
9880 case 0x04: /* SRSHR / URSHR (rounding) */
9881 case 0x06: /* SRSRA / URSRA (accum + rounding) */
9882 handle_vec_simd_shri(s, is_q, is_u, immh, immb, opcode, rn, rd);
9884 case 0x0a: /* SHL / SLI */
9885 handle_vec_simd_shli(s, is_q, is_u, immh, immb, opcode, rn, rd);
9887 case 0x10: /* SHRN */
9888 case 0x11: /* RSHRN / SQRSHRUN */
9890 handle_vec_simd_sqshrn(s, false, is_q, false, true, immh, immb,
9893 handle_vec_simd_shrn(s, is_q, immh, immb, opcode, rn, rd);
9896 case 0x12: /* SQSHRN / UQSHRN */
9897 case 0x13: /* SQRSHRN / UQRSHRN */
9898 handle_vec_simd_sqshrn(s, false, is_q, is_u, is_u, immh, immb,
9901 case 0x14: /* SSHLL / USHLL */
9902 handle_vec_simd_wshli(s, is_q, is_u, immh, immb, opcode, rn, rd);
9904 case 0x1c: /* SCVTF / UCVTF */
9905 handle_simd_shift_intfp_conv(s, false, is_q, is_u, immh, immb,
9908 case 0xc: /* SQSHLU */
9910 unallocated_encoding(s);
9913 handle_simd_qshl(s, false, is_q, false, true, immh, immb, rn, rd);
9915 case 0xe: /* SQSHL, UQSHL */
9916 handle_simd_qshl(s, false, is_q, is_u, is_u, immh, immb, rn, rd);
9918 case 0x1f: /* FCVTZS/ FCVTZU */
9919 handle_simd_shift_fpint_conv(s, false, is_q, is_u, immh, immb, rn, rd);
9922 unallocated_encoding(s);
9927 /* Generate code to do a "long" addition or subtraction, ie one done in
9928 * TCGv_i64 on vector lanes twice the width specified by size.
9930 static void gen_neon_addl(int size, bool is_sub, TCGv_i64 tcg_res,
9931 TCGv_i64 tcg_op1, TCGv_i64 tcg_op2)
9933 static NeonGenTwo64OpFn * const fns[3][2] = {
9934 { gen_helper_neon_addl_u16, gen_helper_neon_subl_u16 },
9935 { gen_helper_neon_addl_u32, gen_helper_neon_subl_u32 },
9936 { tcg_gen_add_i64, tcg_gen_sub_i64 },
9938 NeonGenTwo64OpFn *genfn;
9941 genfn = fns[size][is_sub];
9942 genfn(tcg_res, tcg_op1, tcg_op2);
9945 static void handle_3rd_widening(DisasContext *s, int is_q, int is_u, int size,
9946 int opcode, int rd, int rn, int rm)
9948 /* 3-reg-different widening insns: 64 x 64 -> 128 */
9949 TCGv_i64 tcg_res[2];
9952 tcg_res[0] = tcg_temp_new_i64();
9953 tcg_res[1] = tcg_temp_new_i64();
9955 /* Does this op do an adding accumulate, a subtracting accumulate,
9956 * or no accumulate at all?
9974 read_vec_element(s, tcg_res[0], rd, 0, MO_64);
9975 read_vec_element(s, tcg_res[1], rd, 1, MO_64);
9978 /* size == 2 means two 32x32->64 operations; this is worth special
9979 * casing because we can generally handle it inline.
9982 for (pass = 0; pass < 2; pass++) {
9983 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
9984 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
9985 TCGv_i64 tcg_passres;
9986 TCGMemOp memop = MO_32 | (is_u ? 0 : MO_SIGN);
9988 int elt = pass + is_q * 2;
9990 read_vec_element(s, tcg_op1, rn, elt, memop);
9991 read_vec_element(s, tcg_op2, rm, elt, memop);
9994 tcg_passres = tcg_res[pass];
9996 tcg_passres = tcg_temp_new_i64();
10000 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10001 tcg_gen_add_i64(tcg_passres, tcg_op1, tcg_op2);
10003 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10004 tcg_gen_sub_i64(tcg_passres, tcg_op1, tcg_op2);
10006 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10007 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10009 TCGv_i64 tcg_tmp1 = tcg_temp_new_i64();
10010 TCGv_i64 tcg_tmp2 = tcg_temp_new_i64();
10012 tcg_gen_sub_i64(tcg_tmp1, tcg_op1, tcg_op2);
10013 tcg_gen_sub_i64(tcg_tmp2, tcg_op2, tcg_op1);
10014 tcg_gen_movcond_i64(is_u ? TCG_COND_GEU : TCG_COND_GE,
10016 tcg_op1, tcg_op2, tcg_tmp1, tcg_tmp2);
10017 tcg_temp_free_i64(tcg_tmp1);
10018 tcg_temp_free_i64(tcg_tmp2);
10021 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10022 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10023 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10024 tcg_gen_mul_i64(tcg_passres, tcg_op1, tcg_op2);
10026 case 9: /* SQDMLAL, SQDMLAL2 */
10027 case 11: /* SQDMLSL, SQDMLSL2 */
10028 case 13: /* SQDMULL, SQDMULL2 */
10029 tcg_gen_mul_i64(tcg_passres, tcg_op1, tcg_op2);
10030 gen_helper_neon_addl_saturate_s64(tcg_passres, cpu_env,
10031 tcg_passres, tcg_passres);
10034 g_assert_not_reached();
10037 if (opcode == 9 || opcode == 11) {
10038 /* saturating accumulate ops */
10040 tcg_gen_neg_i64(tcg_passres, tcg_passres);
10042 gen_helper_neon_addl_saturate_s64(tcg_res[pass], cpu_env,
10043 tcg_res[pass], tcg_passres);
10044 } else if (accop > 0) {
10045 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
10046 } else if (accop < 0) {
10047 tcg_gen_sub_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
10051 tcg_temp_free_i64(tcg_passres);
10054 tcg_temp_free_i64(tcg_op1);
10055 tcg_temp_free_i64(tcg_op2);
10058 /* size 0 or 1, generally helper functions */
10059 for (pass = 0; pass < 2; pass++) {
10060 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
10061 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10062 TCGv_i64 tcg_passres;
10063 int elt = pass + is_q * 2;
10065 read_vec_element_i32(s, tcg_op1, rn, elt, MO_32);
10066 read_vec_element_i32(s, tcg_op2, rm, elt, MO_32);
10069 tcg_passres = tcg_res[pass];
10071 tcg_passres = tcg_temp_new_i64();
10075 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10076 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10078 TCGv_i64 tcg_op2_64 = tcg_temp_new_i64();
10079 static NeonGenWidenFn * const widenfns[2][2] = {
10080 { gen_helper_neon_widen_s8, gen_helper_neon_widen_u8 },
10081 { gen_helper_neon_widen_s16, gen_helper_neon_widen_u16 },
10083 NeonGenWidenFn *widenfn = widenfns[size][is_u];
10085 widenfn(tcg_op2_64, tcg_op2);
10086 widenfn(tcg_passres, tcg_op1);
10087 gen_neon_addl(size, (opcode == 2), tcg_passres,
10088 tcg_passres, tcg_op2_64);
10089 tcg_temp_free_i64(tcg_op2_64);
10092 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10093 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10096 gen_helper_neon_abdl_u16(tcg_passres, tcg_op1, tcg_op2);
10098 gen_helper_neon_abdl_s16(tcg_passres, tcg_op1, tcg_op2);
10102 gen_helper_neon_abdl_u32(tcg_passres, tcg_op1, tcg_op2);
10104 gen_helper_neon_abdl_s32(tcg_passres, tcg_op1, tcg_op2);
10108 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10109 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10110 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10113 gen_helper_neon_mull_u8(tcg_passres, tcg_op1, tcg_op2);
10115 gen_helper_neon_mull_s8(tcg_passres, tcg_op1, tcg_op2);
10119 gen_helper_neon_mull_u16(tcg_passres, tcg_op1, tcg_op2);
10121 gen_helper_neon_mull_s16(tcg_passres, tcg_op1, tcg_op2);
10125 case 9: /* SQDMLAL, SQDMLAL2 */
10126 case 11: /* SQDMLSL, SQDMLSL2 */
10127 case 13: /* SQDMULL, SQDMULL2 */
10129 gen_helper_neon_mull_s16(tcg_passres, tcg_op1, tcg_op2);
10130 gen_helper_neon_addl_saturate_s32(tcg_passres, cpu_env,
10131 tcg_passres, tcg_passres);
10133 case 14: /* PMULL */
10135 gen_helper_neon_mull_p8(tcg_passres, tcg_op1, tcg_op2);
10138 g_assert_not_reached();
10140 tcg_temp_free_i32(tcg_op1);
10141 tcg_temp_free_i32(tcg_op2);
10144 if (opcode == 9 || opcode == 11) {
10145 /* saturating accumulate ops */
10147 gen_helper_neon_negl_u32(tcg_passres, tcg_passres);
10149 gen_helper_neon_addl_saturate_s32(tcg_res[pass], cpu_env,
10153 gen_neon_addl(size, (accop < 0), tcg_res[pass],
10154 tcg_res[pass], tcg_passres);
10156 tcg_temp_free_i64(tcg_passres);
10161 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
10162 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
10163 tcg_temp_free_i64(tcg_res[0]);
10164 tcg_temp_free_i64(tcg_res[1]);
10167 static void handle_3rd_wide(DisasContext *s, int is_q, int is_u, int size,
10168 int opcode, int rd, int rn, int rm)
10170 TCGv_i64 tcg_res[2];
10171 int part = is_q ? 2 : 0;
10174 for (pass = 0; pass < 2; pass++) {
10175 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10176 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10177 TCGv_i64 tcg_op2_wide = tcg_temp_new_i64();
10178 static NeonGenWidenFn * const widenfns[3][2] = {
10179 { gen_helper_neon_widen_s8, gen_helper_neon_widen_u8 },
10180 { gen_helper_neon_widen_s16, gen_helper_neon_widen_u16 },
10181 { tcg_gen_ext_i32_i64, tcg_gen_extu_i32_i64 },
10183 NeonGenWidenFn *widenfn = widenfns[size][is_u];
10185 read_vec_element(s, tcg_op1, rn, pass, MO_64);
10186 read_vec_element_i32(s, tcg_op2, rm, part + pass, MO_32);
10187 widenfn(tcg_op2_wide, tcg_op2);
10188 tcg_temp_free_i32(tcg_op2);
10189 tcg_res[pass] = tcg_temp_new_i64();
10190 gen_neon_addl(size, (opcode == 3),
10191 tcg_res[pass], tcg_op1, tcg_op2_wide);
10192 tcg_temp_free_i64(tcg_op1);
10193 tcg_temp_free_i64(tcg_op2_wide);
10196 for (pass = 0; pass < 2; pass++) {
10197 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
10198 tcg_temp_free_i64(tcg_res[pass]);
10202 static void do_narrow_round_high_u32(TCGv_i32 res, TCGv_i64 in)
10204 tcg_gen_addi_i64(in, in, 1U << 31);
10205 tcg_gen_extrh_i64_i32(res, in);
10208 static void handle_3rd_narrowing(DisasContext *s, int is_q, int is_u, int size,
10209 int opcode, int rd, int rn, int rm)
10211 TCGv_i32 tcg_res[2];
10212 int part = is_q ? 2 : 0;
10215 for (pass = 0; pass < 2; pass++) {
10216 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10217 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10218 TCGv_i64 tcg_wideres = tcg_temp_new_i64();
10219 static NeonGenNarrowFn * const narrowfns[3][2] = {
10220 { gen_helper_neon_narrow_high_u8,
10221 gen_helper_neon_narrow_round_high_u8 },
10222 { gen_helper_neon_narrow_high_u16,
10223 gen_helper_neon_narrow_round_high_u16 },
10224 { tcg_gen_extrh_i64_i32, do_narrow_round_high_u32 },
10226 NeonGenNarrowFn *gennarrow = narrowfns[size][is_u];
10228 read_vec_element(s, tcg_op1, rn, pass, MO_64);
10229 read_vec_element(s, tcg_op2, rm, pass, MO_64);
10231 gen_neon_addl(size, (opcode == 6), tcg_wideres, tcg_op1, tcg_op2);
10233 tcg_temp_free_i64(tcg_op1);
10234 tcg_temp_free_i64(tcg_op2);
10236 tcg_res[pass] = tcg_temp_new_i32();
10237 gennarrow(tcg_res[pass], tcg_wideres);
10238 tcg_temp_free_i64(tcg_wideres);
10241 for (pass = 0; pass < 2; pass++) {
10242 write_vec_element_i32(s, tcg_res[pass], rd, pass + part, MO_32);
10243 tcg_temp_free_i32(tcg_res[pass]);
10245 clear_vec_high(s, is_q, rd);
10248 static void handle_pmull_64(DisasContext *s, int is_q, int rd, int rn, int rm)
10250 /* PMULL of 64 x 64 -> 128 is an odd special case because it
10251 * is the only three-reg-diff instruction which produces a
10252 * 128-bit wide result from a single operation. However since
10253 * it's possible to calculate the two halves more or less
10254 * separately we just use two helper calls.
10256 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10257 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10258 TCGv_i64 tcg_res = tcg_temp_new_i64();
10260 read_vec_element(s, tcg_op1, rn, is_q, MO_64);
10261 read_vec_element(s, tcg_op2, rm, is_q, MO_64);
10262 gen_helper_neon_pmull_64_lo(tcg_res, tcg_op1, tcg_op2);
10263 write_vec_element(s, tcg_res, rd, 0, MO_64);
10264 gen_helper_neon_pmull_64_hi(tcg_res, tcg_op1, tcg_op2);
10265 write_vec_element(s, tcg_res, rd, 1, MO_64);
10267 tcg_temp_free_i64(tcg_op1);
10268 tcg_temp_free_i64(tcg_op2);
10269 tcg_temp_free_i64(tcg_res);
10272 /* AdvSIMD three different
10273 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
10274 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10275 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
10276 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10278 static void disas_simd_three_reg_diff(DisasContext *s, uint32_t insn)
10280 /* Instructions in this group fall into three basic classes
10281 * (in each case with the operation working on each element in
10282 * the input vectors):
10283 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
10285 * (2) wide 64 x 128 -> 128
10286 * (3) narrowing 128 x 128 -> 64
10287 * Here we do initial decode, catch unallocated cases and
10288 * dispatch to separate functions for each class.
10290 int is_q = extract32(insn, 30, 1);
10291 int is_u = extract32(insn, 29, 1);
10292 int size = extract32(insn, 22, 2);
10293 int opcode = extract32(insn, 12, 4);
10294 int rm = extract32(insn, 16, 5);
10295 int rn = extract32(insn, 5, 5);
10296 int rd = extract32(insn, 0, 5);
10299 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
10300 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
10301 /* 64 x 128 -> 128 */
10303 unallocated_encoding(s);
10306 if (!fp_access_check(s)) {
10309 handle_3rd_wide(s, is_q, is_u, size, opcode, rd, rn, rm);
10311 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
10312 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
10313 /* 128 x 128 -> 64 */
10315 unallocated_encoding(s);
10318 if (!fp_access_check(s)) {
10321 handle_3rd_narrowing(s, is_q, is_u, size, opcode, rd, rn, rm);
10323 case 14: /* PMULL, PMULL2 */
10324 if (is_u || size == 1 || size == 2) {
10325 unallocated_encoding(s);
10329 if (!dc_isar_feature(aa64_pmull, s)) {
10330 unallocated_encoding(s);
10333 if (!fp_access_check(s)) {
10336 handle_pmull_64(s, is_q, rd, rn, rm);
10340 case 9: /* SQDMLAL, SQDMLAL2 */
10341 case 11: /* SQDMLSL, SQDMLSL2 */
10342 case 13: /* SQDMULL, SQDMULL2 */
10343 if (is_u || size == 0) {
10344 unallocated_encoding(s);
10348 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10349 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10350 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10351 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10352 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10353 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10354 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
10355 /* 64 x 64 -> 128 */
10357 unallocated_encoding(s);
10361 if (!fp_access_check(s)) {
10365 handle_3rd_widening(s, is_q, is_u, size, opcode, rd, rn, rm);
10368 /* opcode 15 not allocated */
10369 unallocated_encoding(s);
10374 /* Logic op (opcode == 3) subgroup of C3.6.16. */
10375 static void disas_simd_3same_logic(DisasContext *s, uint32_t insn)
10377 int rd = extract32(insn, 0, 5);
10378 int rn = extract32(insn, 5, 5);
10379 int rm = extract32(insn, 16, 5);
10380 int size = extract32(insn, 22, 2);
10381 bool is_u = extract32(insn, 29, 1);
10382 bool is_q = extract32(insn, 30, 1);
10384 if (!fp_access_check(s)) {
10388 switch (size + 4 * is_u) {
10390 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_and, 0);
10393 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_andc, 0);
10396 if (rn == rm) { /* MOV */
10397 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_mov, 0);
10399 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_or, 0);
10403 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_orc, 0);
10406 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_xor, 0);
10409 case 5: /* BSL bitwise select */
10410 gen_gvec_op3(s, is_q, rd, rn, rm, &bsl_op);
10412 case 6: /* BIT, bitwise insert if true */
10413 gen_gvec_op3(s, is_q, rd, rn, rm, &bit_op);
10415 case 7: /* BIF, bitwise insert if false */
10416 gen_gvec_op3(s, is_q, rd, rn, rm, &bif_op);
10420 g_assert_not_reached();
10424 /* Pairwise op subgroup of C3.6.16.
10426 * This is called directly or via the handle_3same_float for float pairwise
10427 * operations where the opcode and size are calculated differently.
10429 static void handle_simd_3same_pair(DisasContext *s, int is_q, int u, int opcode,
10430 int size, int rn, int rm, int rd)
10435 /* Floating point operations need fpst */
10436 if (opcode >= 0x58) {
10437 fpst = get_fpstatus_ptr(false);
10442 if (!fp_access_check(s)) {
10446 /* These operations work on the concatenated rm:rn, with each pair of
10447 * adjacent elements being operated on to produce an element in the result.
10450 TCGv_i64 tcg_res[2];
10452 for (pass = 0; pass < 2; pass++) {
10453 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10454 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10455 int passreg = (pass == 0) ? rn : rm;
10457 read_vec_element(s, tcg_op1, passreg, 0, MO_64);
10458 read_vec_element(s, tcg_op2, passreg, 1, MO_64);
10459 tcg_res[pass] = tcg_temp_new_i64();
10462 case 0x17: /* ADDP */
10463 tcg_gen_add_i64(tcg_res[pass], tcg_op1, tcg_op2);
10465 case 0x58: /* FMAXNMP */
10466 gen_helper_vfp_maxnumd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10468 case 0x5a: /* FADDP */
10469 gen_helper_vfp_addd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10471 case 0x5e: /* FMAXP */
10472 gen_helper_vfp_maxd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10474 case 0x78: /* FMINNMP */
10475 gen_helper_vfp_minnumd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10477 case 0x7e: /* FMINP */
10478 gen_helper_vfp_mind(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10481 g_assert_not_reached();
10484 tcg_temp_free_i64(tcg_op1);
10485 tcg_temp_free_i64(tcg_op2);
10488 for (pass = 0; pass < 2; pass++) {
10489 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
10490 tcg_temp_free_i64(tcg_res[pass]);
10493 int maxpass = is_q ? 4 : 2;
10494 TCGv_i32 tcg_res[4];
10496 for (pass = 0; pass < maxpass; pass++) {
10497 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
10498 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10499 NeonGenTwoOpFn *genfn = NULL;
10500 int passreg = pass < (maxpass / 2) ? rn : rm;
10501 int passelt = (is_q && (pass & 1)) ? 2 : 0;
10503 read_vec_element_i32(s, tcg_op1, passreg, passelt, MO_32);
10504 read_vec_element_i32(s, tcg_op2, passreg, passelt + 1, MO_32);
10505 tcg_res[pass] = tcg_temp_new_i32();
10508 case 0x17: /* ADDP */
10510 static NeonGenTwoOpFn * const fns[3] = {
10511 gen_helper_neon_padd_u8,
10512 gen_helper_neon_padd_u16,
10518 case 0x14: /* SMAXP, UMAXP */
10520 static NeonGenTwoOpFn * const fns[3][2] = {
10521 { gen_helper_neon_pmax_s8, gen_helper_neon_pmax_u8 },
10522 { gen_helper_neon_pmax_s16, gen_helper_neon_pmax_u16 },
10523 { tcg_gen_smax_i32, tcg_gen_umax_i32 },
10525 genfn = fns[size][u];
10528 case 0x15: /* SMINP, UMINP */
10530 static NeonGenTwoOpFn * const fns[3][2] = {
10531 { gen_helper_neon_pmin_s8, gen_helper_neon_pmin_u8 },
10532 { gen_helper_neon_pmin_s16, gen_helper_neon_pmin_u16 },
10533 { tcg_gen_smin_i32, tcg_gen_umin_i32 },
10535 genfn = fns[size][u];
10538 /* The FP operations are all on single floats (32 bit) */
10539 case 0x58: /* FMAXNMP */
10540 gen_helper_vfp_maxnums(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10542 case 0x5a: /* FADDP */
10543 gen_helper_vfp_adds(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10545 case 0x5e: /* FMAXP */
10546 gen_helper_vfp_maxs(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10548 case 0x78: /* FMINNMP */
10549 gen_helper_vfp_minnums(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10551 case 0x7e: /* FMINP */
10552 gen_helper_vfp_mins(tcg_res[pass], tcg_op1, tcg_op2, fpst);
10555 g_assert_not_reached();
10558 /* FP ops called directly, otherwise call now */
10560 genfn(tcg_res[pass], tcg_op1, tcg_op2);
10563 tcg_temp_free_i32(tcg_op1);
10564 tcg_temp_free_i32(tcg_op2);
10567 for (pass = 0; pass < maxpass; pass++) {
10568 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32);
10569 tcg_temp_free_i32(tcg_res[pass]);
10571 clear_vec_high(s, is_q, rd);
10575 tcg_temp_free_ptr(fpst);
10579 /* Floating point op subgroup of C3.6.16. */
10580 static void disas_simd_3same_float(DisasContext *s, uint32_t insn)
10582 /* For floating point ops, the U, size[1] and opcode bits
10583 * together indicate the operation. size[0] indicates single
10586 int fpopcode = extract32(insn, 11, 5)
10587 | (extract32(insn, 23, 1) << 5)
10588 | (extract32(insn, 29, 1) << 6);
10589 int is_q = extract32(insn, 30, 1);
10590 int size = extract32(insn, 22, 1);
10591 int rm = extract32(insn, 16, 5);
10592 int rn = extract32(insn, 5, 5);
10593 int rd = extract32(insn, 0, 5);
10595 int datasize = is_q ? 128 : 64;
10596 int esize = 32 << size;
10597 int elements = datasize / esize;
10599 if (size == 1 && !is_q) {
10600 unallocated_encoding(s);
10604 switch (fpopcode) {
10605 case 0x58: /* FMAXNMP */
10606 case 0x5a: /* FADDP */
10607 case 0x5e: /* FMAXP */
10608 case 0x78: /* FMINNMP */
10609 case 0x7e: /* FMINP */
10610 if (size && !is_q) {
10611 unallocated_encoding(s);
10614 handle_simd_3same_pair(s, is_q, 0, fpopcode, size ? MO_64 : MO_32,
10617 case 0x1b: /* FMULX */
10618 case 0x1f: /* FRECPS */
10619 case 0x3f: /* FRSQRTS */
10620 case 0x5d: /* FACGE */
10621 case 0x7d: /* FACGT */
10622 case 0x19: /* FMLA */
10623 case 0x39: /* FMLS */
10624 case 0x18: /* FMAXNM */
10625 case 0x1a: /* FADD */
10626 case 0x1c: /* FCMEQ */
10627 case 0x1e: /* FMAX */
10628 case 0x38: /* FMINNM */
10629 case 0x3a: /* FSUB */
10630 case 0x3e: /* FMIN */
10631 case 0x5b: /* FMUL */
10632 case 0x5c: /* FCMGE */
10633 case 0x5f: /* FDIV */
10634 case 0x7a: /* FABD */
10635 case 0x7c: /* FCMGT */
10636 if (!fp_access_check(s)) {
10640 handle_3same_float(s, size, elements, fpopcode, rd, rn, rm);
10643 unallocated_encoding(s);
10648 /* Integer op subgroup of C3.6.16. */
10649 static void disas_simd_3same_int(DisasContext *s, uint32_t insn)
10651 int is_q = extract32(insn, 30, 1);
10652 int u = extract32(insn, 29, 1);
10653 int size = extract32(insn, 22, 2);
10654 int opcode = extract32(insn, 11, 5);
10655 int rm = extract32(insn, 16, 5);
10656 int rn = extract32(insn, 5, 5);
10657 int rd = extract32(insn, 0, 5);
10662 case 0x13: /* MUL, PMUL */
10663 if (u && size != 0) {
10664 unallocated_encoding(s);
10668 case 0x0: /* SHADD, UHADD */
10669 case 0x2: /* SRHADD, URHADD */
10670 case 0x4: /* SHSUB, UHSUB */
10671 case 0xc: /* SMAX, UMAX */
10672 case 0xd: /* SMIN, UMIN */
10673 case 0xe: /* SABD, UABD */
10674 case 0xf: /* SABA, UABA */
10675 case 0x12: /* MLA, MLS */
10677 unallocated_encoding(s);
10681 case 0x16: /* SQDMULH, SQRDMULH */
10682 if (size == 0 || size == 3) {
10683 unallocated_encoding(s);
10688 if (size == 3 && !is_q) {
10689 unallocated_encoding(s);
10695 if (!fp_access_check(s)) {
10700 case 0x10: /* ADD, SUB */
10702 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_sub, size);
10704 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_add, size);
10707 case 0x13: /* MUL, PMUL */
10708 if (!u) { /* MUL */
10709 gen_gvec_fn3(s, is_q, rd, rn, rm, tcg_gen_gvec_mul, size);
10713 case 0x12: /* MLA, MLS */
10715 gen_gvec_op3(s, is_q, rd, rn, rm, &mls_op[size]);
10717 gen_gvec_op3(s, is_q, rd, rn, rm, &mla_op[size]);
10721 if (!u) { /* CMTST */
10722 gen_gvec_op3(s, is_q, rd, rn, rm, &cmtst_op[size]);
10726 cond = TCG_COND_EQ;
10728 case 0x06: /* CMGT, CMHI */
10729 cond = u ? TCG_COND_GTU : TCG_COND_GT;
10731 case 0x07: /* CMGE, CMHS */
10732 cond = u ? TCG_COND_GEU : TCG_COND_GE;
10734 tcg_gen_gvec_cmp(cond, size, vec_full_reg_offset(s, rd),
10735 vec_full_reg_offset(s, rn),
10736 vec_full_reg_offset(s, rm),
10737 is_q ? 16 : 8, vec_full_reg_size(s));
10743 for (pass = 0; pass < 2; pass++) {
10744 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
10745 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
10746 TCGv_i64 tcg_res = tcg_temp_new_i64();
10748 read_vec_element(s, tcg_op1, rn, pass, MO_64);
10749 read_vec_element(s, tcg_op2, rm, pass, MO_64);
10751 handle_3same_64(s, opcode, u, tcg_res, tcg_op1, tcg_op2);
10753 write_vec_element(s, tcg_res, rd, pass, MO_64);
10755 tcg_temp_free_i64(tcg_res);
10756 tcg_temp_free_i64(tcg_op1);
10757 tcg_temp_free_i64(tcg_op2);
10760 for (pass = 0; pass < (is_q ? 4 : 2); pass++) {
10761 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
10762 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
10763 TCGv_i32 tcg_res = tcg_temp_new_i32();
10764 NeonGenTwoOpFn *genfn = NULL;
10765 NeonGenTwoOpEnvFn *genenvfn = NULL;
10767 read_vec_element_i32(s, tcg_op1, rn, pass, MO_32);
10768 read_vec_element_i32(s, tcg_op2, rm, pass, MO_32);
10771 case 0x0: /* SHADD, UHADD */
10773 static NeonGenTwoOpFn * const fns[3][2] = {
10774 { gen_helper_neon_hadd_s8, gen_helper_neon_hadd_u8 },
10775 { gen_helper_neon_hadd_s16, gen_helper_neon_hadd_u16 },
10776 { gen_helper_neon_hadd_s32, gen_helper_neon_hadd_u32 },
10778 genfn = fns[size][u];
10781 case 0x1: /* SQADD, UQADD */
10783 static NeonGenTwoOpEnvFn * const fns[3][2] = {
10784 { gen_helper_neon_qadd_s8, gen_helper_neon_qadd_u8 },
10785 { gen_helper_neon_qadd_s16, gen_helper_neon_qadd_u16 },
10786 { gen_helper_neon_qadd_s32, gen_helper_neon_qadd_u32 },
10788 genenvfn = fns[size][u];
10791 case 0x2: /* SRHADD, URHADD */
10793 static NeonGenTwoOpFn * const fns[3][2] = {
10794 { gen_helper_neon_rhadd_s8, gen_helper_neon_rhadd_u8 },
10795 { gen_helper_neon_rhadd_s16, gen_helper_neon_rhadd_u16 },
10796 { gen_helper_neon_rhadd_s32, gen_helper_neon_rhadd_u32 },
10798 genfn = fns[size][u];
10801 case 0x4: /* SHSUB, UHSUB */
10803 static NeonGenTwoOpFn * const fns[3][2] = {
10804 { gen_helper_neon_hsub_s8, gen_helper_neon_hsub_u8 },
10805 { gen_helper_neon_hsub_s16, gen_helper_neon_hsub_u16 },
10806 { gen_helper_neon_hsub_s32, gen_helper_neon_hsub_u32 },
10808 genfn = fns[size][u];
10811 case 0x5: /* SQSUB, UQSUB */
10813 static NeonGenTwoOpEnvFn * const fns[3][2] = {
10814 { gen_helper_neon_qsub_s8, gen_helper_neon_qsub_u8 },
10815 { gen_helper_neon_qsub_s16, gen_helper_neon_qsub_u16 },
10816 { gen_helper_neon_qsub_s32, gen_helper_neon_qsub_u32 },
10818 genenvfn = fns[size][u];
10821 case 0x8: /* SSHL, USHL */
10823 static NeonGenTwoOpFn * const fns[3][2] = {
10824 { gen_helper_neon_shl_s8, gen_helper_neon_shl_u8 },
10825 { gen_helper_neon_shl_s16, gen_helper_neon_shl_u16 },
10826 { gen_helper_neon_shl_s32, gen_helper_neon_shl_u32 },
10828 genfn = fns[size][u];
10831 case 0x9: /* SQSHL, UQSHL */
10833 static NeonGenTwoOpEnvFn * const fns[3][2] = {
10834 { gen_helper_neon_qshl_s8, gen_helper_neon_qshl_u8 },
10835 { gen_helper_neon_qshl_s16, gen_helper_neon_qshl_u16 },
10836 { gen_helper_neon_qshl_s32, gen_helper_neon_qshl_u32 },
10838 genenvfn = fns[size][u];
10841 case 0xa: /* SRSHL, URSHL */
10843 static NeonGenTwoOpFn * const fns[3][2] = {
10844 { gen_helper_neon_rshl_s8, gen_helper_neon_rshl_u8 },
10845 { gen_helper_neon_rshl_s16, gen_helper_neon_rshl_u16 },
10846 { gen_helper_neon_rshl_s32, gen_helper_neon_rshl_u32 },
10848 genfn = fns[size][u];
10851 case 0xb: /* SQRSHL, UQRSHL */
10853 static NeonGenTwoOpEnvFn * const fns[3][2] = {
10854 { gen_helper_neon_qrshl_s8, gen_helper_neon_qrshl_u8 },
10855 { gen_helper_neon_qrshl_s16, gen_helper_neon_qrshl_u16 },
10856 { gen_helper_neon_qrshl_s32, gen_helper_neon_qrshl_u32 },
10858 genenvfn = fns[size][u];
10861 case 0xc: /* SMAX, UMAX */
10863 static NeonGenTwoOpFn * const fns[3][2] = {
10864 { gen_helper_neon_max_s8, gen_helper_neon_max_u8 },
10865 { gen_helper_neon_max_s16, gen_helper_neon_max_u16 },
10866 { tcg_gen_smax_i32, tcg_gen_umax_i32 },
10868 genfn = fns[size][u];
10872 case 0xd: /* SMIN, UMIN */
10874 static NeonGenTwoOpFn * const fns[3][2] = {
10875 { gen_helper_neon_min_s8, gen_helper_neon_min_u8 },
10876 { gen_helper_neon_min_s16, gen_helper_neon_min_u16 },
10877 { tcg_gen_smin_i32, tcg_gen_umin_i32 },
10879 genfn = fns[size][u];
10882 case 0xe: /* SABD, UABD */
10883 case 0xf: /* SABA, UABA */
10885 static NeonGenTwoOpFn * const fns[3][2] = {
10886 { gen_helper_neon_abd_s8, gen_helper_neon_abd_u8 },
10887 { gen_helper_neon_abd_s16, gen_helper_neon_abd_u16 },
10888 { gen_helper_neon_abd_s32, gen_helper_neon_abd_u32 },
10890 genfn = fns[size][u];
10893 case 0x13: /* MUL, PMUL */
10894 assert(u); /* PMUL */
10896 genfn = gen_helper_neon_mul_p8;
10898 case 0x16: /* SQDMULH, SQRDMULH */
10900 static NeonGenTwoOpEnvFn * const fns[2][2] = {
10901 { gen_helper_neon_qdmulh_s16, gen_helper_neon_qrdmulh_s16 },
10902 { gen_helper_neon_qdmulh_s32, gen_helper_neon_qrdmulh_s32 },
10904 assert(size == 1 || size == 2);
10905 genenvfn = fns[size - 1][u];
10909 g_assert_not_reached();
10913 genenvfn(tcg_res, cpu_env, tcg_op1, tcg_op2);
10915 genfn(tcg_res, tcg_op1, tcg_op2);
10918 if (opcode == 0xf) {
10919 /* SABA, UABA: accumulating ops */
10920 static NeonGenTwoOpFn * const fns[3] = {
10921 gen_helper_neon_add_u8,
10922 gen_helper_neon_add_u16,
10926 read_vec_element_i32(s, tcg_op1, rd, pass, MO_32);
10927 fns[size](tcg_res, tcg_op1, tcg_res);
10930 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
10932 tcg_temp_free_i32(tcg_res);
10933 tcg_temp_free_i32(tcg_op1);
10934 tcg_temp_free_i32(tcg_op2);
10937 clear_vec_high(s, is_q, rd);
10940 /* AdvSIMD three same
10941 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
10942 * +---+---+---+-----------+------+---+------+--------+---+------+------+
10943 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
10944 * +---+---+---+-----------+------+---+------+--------+---+------+------+
10946 static void disas_simd_three_reg_same(DisasContext *s, uint32_t insn)
10948 int opcode = extract32(insn, 11, 5);
10951 case 0x3: /* logic ops */
10952 disas_simd_3same_logic(s, insn);
10954 case 0x17: /* ADDP */
10955 case 0x14: /* SMAXP, UMAXP */
10956 case 0x15: /* SMINP, UMINP */
10958 /* Pairwise operations */
10959 int is_q = extract32(insn, 30, 1);
10960 int u = extract32(insn, 29, 1);
10961 int size = extract32(insn, 22, 2);
10962 int rm = extract32(insn, 16, 5);
10963 int rn = extract32(insn, 5, 5);
10964 int rd = extract32(insn, 0, 5);
10965 if (opcode == 0x17) {
10966 if (u || (size == 3 && !is_q)) {
10967 unallocated_encoding(s);
10972 unallocated_encoding(s);
10976 handle_simd_3same_pair(s, is_q, u, opcode, size, rn, rm, rd);
10979 case 0x18 ... 0x31:
10980 /* floating point ops, sz[1] and U are part of opcode */
10981 disas_simd_3same_float(s, insn);
10984 disas_simd_3same_int(s, insn);
10990 * Advanced SIMD three same (ARMv8.2 FP16 variants)
10992 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
10993 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
10994 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
10995 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
10997 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
10998 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11001 static void disas_simd_three_reg_same_fp16(DisasContext *s, uint32_t insn)
11003 int opcode, fpopcode;
11004 int is_q, u, a, rm, rn, rd;
11005 int datasize, elements;
11008 bool pairwise = false;
11010 if (!dc_isar_feature(aa64_fp16, s)) {
11011 unallocated_encoding(s);
11015 if (!fp_access_check(s)) {
11019 /* For these floating point ops, the U, a and opcode bits
11020 * together indicate the operation.
11022 opcode = extract32(insn, 11, 3);
11023 u = extract32(insn, 29, 1);
11024 a = extract32(insn, 23, 1);
11025 is_q = extract32(insn, 30, 1);
11026 rm = extract32(insn, 16, 5);
11027 rn = extract32(insn, 5, 5);
11028 rd = extract32(insn, 0, 5);
11030 fpopcode = opcode | (a << 3) | (u << 4);
11031 datasize = is_q ? 128 : 64;
11032 elements = datasize / 16;
11034 switch (fpopcode) {
11035 case 0x10: /* FMAXNMP */
11036 case 0x12: /* FADDP */
11037 case 0x16: /* FMAXP */
11038 case 0x18: /* FMINNMP */
11039 case 0x1e: /* FMINP */
11044 fpst = get_fpstatus_ptr(true);
11047 int maxpass = is_q ? 8 : 4;
11048 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
11049 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
11050 TCGv_i32 tcg_res[8];
11052 for (pass = 0; pass < maxpass; pass++) {
11053 int passreg = pass < (maxpass / 2) ? rn : rm;
11054 int passelt = (pass << 1) & (maxpass - 1);
11056 read_vec_element_i32(s, tcg_op1, passreg, passelt, MO_16);
11057 read_vec_element_i32(s, tcg_op2, passreg, passelt + 1, MO_16);
11058 tcg_res[pass] = tcg_temp_new_i32();
11060 switch (fpopcode) {
11061 case 0x10: /* FMAXNMP */
11062 gen_helper_advsimd_maxnumh(tcg_res[pass], tcg_op1, tcg_op2,
11065 case 0x12: /* FADDP */
11066 gen_helper_advsimd_addh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11068 case 0x16: /* FMAXP */
11069 gen_helper_advsimd_maxh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11071 case 0x18: /* FMINNMP */
11072 gen_helper_advsimd_minnumh(tcg_res[pass], tcg_op1, tcg_op2,
11075 case 0x1e: /* FMINP */
11076 gen_helper_advsimd_minh(tcg_res[pass], tcg_op1, tcg_op2, fpst);
11079 g_assert_not_reached();
11083 for (pass = 0; pass < maxpass; pass++) {
11084 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_16);
11085 tcg_temp_free_i32(tcg_res[pass]);
11088 tcg_temp_free_i32(tcg_op1);
11089 tcg_temp_free_i32(tcg_op2);
11092 for (pass = 0; pass < elements; pass++) {
11093 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
11094 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
11095 TCGv_i32 tcg_res = tcg_temp_new_i32();
11097 read_vec_element_i32(s, tcg_op1, rn, pass, MO_16);
11098 read_vec_element_i32(s, tcg_op2, rm, pass, MO_16);
11100 switch (fpopcode) {
11101 case 0x0: /* FMAXNM */
11102 gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst);
11104 case 0x1: /* FMLA */
11105 read_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11106 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_res,
11109 case 0x2: /* FADD */
11110 gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst);
11112 case 0x3: /* FMULX */
11113 gen_helper_advsimd_mulxh(tcg_res, tcg_op1, tcg_op2, fpst);
11115 case 0x4: /* FCMEQ */
11116 gen_helper_advsimd_ceq_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11118 case 0x6: /* FMAX */
11119 gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst);
11121 case 0x7: /* FRECPS */
11122 gen_helper_recpsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11124 case 0x8: /* FMINNM */
11125 gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst);
11127 case 0x9: /* FMLS */
11128 /* As usual for ARM, separate negation for fused multiply-add */
11129 tcg_gen_xori_i32(tcg_op1, tcg_op1, 0x8000);
11130 read_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11131 gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_res,
11134 case 0xa: /* FSUB */
11135 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
11137 case 0xe: /* FMIN */
11138 gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst);
11140 case 0xf: /* FRSQRTS */
11141 gen_helper_rsqrtsf_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11143 case 0x13: /* FMUL */
11144 gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst);
11146 case 0x14: /* FCMGE */
11147 gen_helper_advsimd_cge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11149 case 0x15: /* FACGE */
11150 gen_helper_advsimd_acge_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11152 case 0x17: /* FDIV */
11153 gen_helper_advsimd_divh(tcg_res, tcg_op1, tcg_op2, fpst);
11155 case 0x1a: /* FABD */
11156 gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst);
11157 tcg_gen_andi_i32(tcg_res, tcg_res, 0x7fff);
11159 case 0x1c: /* FCMGT */
11160 gen_helper_advsimd_cgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11162 case 0x1d: /* FACGT */
11163 gen_helper_advsimd_acgt_f16(tcg_res, tcg_op1, tcg_op2, fpst);
11166 fprintf(stderr, "%s: insn %#04x, fpop %#2x @ %#" PRIx64 "\n",
11167 __func__, insn, fpopcode, s->pc);
11168 g_assert_not_reached();
11171 write_vec_element_i32(s, tcg_res, rd, pass, MO_16);
11172 tcg_temp_free_i32(tcg_res);
11173 tcg_temp_free_i32(tcg_op1);
11174 tcg_temp_free_i32(tcg_op2);
11178 tcg_temp_free_ptr(fpst);
11180 clear_vec_high(s, is_q, rd);
11183 /* AdvSIMD three same extra
11184 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
11185 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11186 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
11187 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11189 static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn)
11191 int rd = extract32(insn, 0, 5);
11192 int rn = extract32(insn, 5, 5);
11193 int opcode = extract32(insn, 11, 4);
11194 int rm = extract32(insn, 16, 5);
11195 int size = extract32(insn, 22, 2);
11196 bool u = extract32(insn, 29, 1);
11197 bool is_q = extract32(insn, 30, 1);
11201 switch (u * 16 + opcode) {
11202 case 0x10: /* SQRDMLAH (vector) */
11203 case 0x11: /* SQRDMLSH (vector) */
11204 if (size != 1 && size != 2) {
11205 unallocated_encoding(s);
11208 feature = dc_isar_feature(aa64_rdm, s);
11210 case 0x02: /* SDOT (vector) */
11211 case 0x12: /* UDOT (vector) */
11212 if (size != MO_32) {
11213 unallocated_encoding(s);
11216 feature = dc_isar_feature(aa64_dp, s);
11218 case 0x18: /* FCMLA, #0 */
11219 case 0x19: /* FCMLA, #90 */
11220 case 0x1a: /* FCMLA, #180 */
11221 case 0x1b: /* FCMLA, #270 */
11222 case 0x1c: /* FCADD, #90 */
11223 case 0x1e: /* FCADD, #270 */
11225 || (size == 1 && !dc_isar_feature(aa64_fp16, s))
11226 || (size == 3 && !is_q)) {
11227 unallocated_encoding(s);
11230 feature = dc_isar_feature(aa64_fcma, s);
11233 unallocated_encoding(s);
11237 unallocated_encoding(s);
11240 if (!fp_access_check(s)) {
11245 case 0x0: /* SQRDMLAH (vector) */
11248 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s16);
11251 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlah_s32);
11254 g_assert_not_reached();
11258 case 0x1: /* SQRDMLSH (vector) */
11261 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s16);
11264 gen_gvec_op3_env(s, is_q, rd, rn, rm, gen_helper_gvec_qrdmlsh_s32);
11267 g_assert_not_reached();
11271 case 0x2: /* SDOT / UDOT */
11272 gen_gvec_op3_ool(s, is_q, rd, rn, rm, 0,
11273 u ? gen_helper_gvec_udot_b : gen_helper_gvec_sdot_b);
11276 case 0x8: /* FCMLA, #0 */
11277 case 0x9: /* FCMLA, #90 */
11278 case 0xa: /* FCMLA, #180 */
11279 case 0xb: /* FCMLA, #270 */
11280 rot = extract32(opcode, 0, 2);
11283 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, true, rot,
11284 gen_helper_gvec_fcmlah);
11287 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
11288 gen_helper_gvec_fcmlas);
11291 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, false, rot,
11292 gen_helper_gvec_fcmlad);
11295 g_assert_not_reached();
11299 case 0xc: /* FCADD, #90 */
11300 case 0xe: /* FCADD, #270 */
11301 rot = extract32(opcode, 1, 1);
11304 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11305 gen_helper_gvec_fcaddh);
11308 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11309 gen_helper_gvec_fcadds);
11312 gen_gvec_op3_fpst(s, is_q, rd, rn, rm, size == 1, rot,
11313 gen_helper_gvec_fcaddd);
11316 g_assert_not_reached();
11321 g_assert_not_reached();
11325 static void handle_2misc_widening(DisasContext *s, int opcode, bool is_q,
11326 int size, int rn, int rd)
11328 /* Handle 2-reg-misc ops which are widening (so each size element
11329 * in the source becomes a 2*size element in the destination.
11330 * The only instruction like this is FCVTL.
11335 /* 32 -> 64 bit fp conversion */
11336 TCGv_i64 tcg_res[2];
11337 int srcelt = is_q ? 2 : 0;
11339 for (pass = 0; pass < 2; pass++) {
11340 TCGv_i32 tcg_op = tcg_temp_new_i32();
11341 tcg_res[pass] = tcg_temp_new_i64();
11343 read_vec_element_i32(s, tcg_op, rn, srcelt + pass, MO_32);
11344 gen_helper_vfp_fcvtds(tcg_res[pass], tcg_op, cpu_env);
11345 tcg_temp_free_i32(tcg_op);
11347 for (pass = 0; pass < 2; pass++) {
11348 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11349 tcg_temp_free_i64(tcg_res[pass]);
11352 /* 16 -> 32 bit fp conversion */
11353 int srcelt = is_q ? 4 : 0;
11354 TCGv_i32 tcg_res[4];
11355 TCGv_ptr fpst = get_fpstatus_ptr(false);
11356 TCGv_i32 ahp = get_ahp_flag();
11358 for (pass = 0; pass < 4; pass++) {
11359 tcg_res[pass] = tcg_temp_new_i32();
11361 read_vec_element_i32(s, tcg_res[pass], rn, srcelt + pass, MO_16);
11362 gen_helper_vfp_fcvt_f16_to_f32(tcg_res[pass], tcg_res[pass],
11365 for (pass = 0; pass < 4; pass++) {
11366 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32);
11367 tcg_temp_free_i32(tcg_res[pass]);
11370 tcg_temp_free_ptr(fpst);
11371 tcg_temp_free_i32(ahp);
11375 static void handle_rev(DisasContext *s, int opcode, bool u,
11376 bool is_q, int size, int rn, int rd)
11378 int op = (opcode << 1) | u;
11379 int opsz = op + size;
11380 int grp_size = 3 - opsz;
11381 int dsize = is_q ? 128 : 64;
11385 unallocated_encoding(s);
11389 if (!fp_access_check(s)) {
11394 /* Special case bytes, use bswap op on each group of elements */
11395 int groups = dsize / (8 << grp_size);
11397 for (i = 0; i < groups; i++) {
11398 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
11400 read_vec_element(s, tcg_tmp, rn, i, grp_size);
11401 switch (grp_size) {
11403 tcg_gen_bswap16_i64(tcg_tmp, tcg_tmp);
11406 tcg_gen_bswap32_i64(tcg_tmp, tcg_tmp);
11409 tcg_gen_bswap64_i64(tcg_tmp, tcg_tmp);
11412 g_assert_not_reached();
11414 write_vec_element(s, tcg_tmp, rd, i, grp_size);
11415 tcg_temp_free_i64(tcg_tmp);
11417 clear_vec_high(s, is_q, rd);
11419 int revmask = (1 << grp_size) - 1;
11420 int esize = 8 << size;
11421 int elements = dsize / esize;
11422 TCGv_i64 tcg_rn = tcg_temp_new_i64();
11423 TCGv_i64 tcg_rd = tcg_const_i64(0);
11424 TCGv_i64 tcg_rd_hi = tcg_const_i64(0);
11426 for (i = 0; i < elements; i++) {
11427 int e_rev = (i & 0xf) ^ revmask;
11428 int off = e_rev * esize;
11429 read_vec_element(s, tcg_rn, rn, i, size);
11431 tcg_gen_deposit_i64(tcg_rd_hi, tcg_rd_hi,
11432 tcg_rn, off - 64, esize);
11434 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, off, esize);
11437 write_vec_element(s, tcg_rd, rd, 0, MO_64);
11438 write_vec_element(s, tcg_rd_hi, rd, 1, MO_64);
11440 tcg_temp_free_i64(tcg_rd_hi);
11441 tcg_temp_free_i64(tcg_rd);
11442 tcg_temp_free_i64(tcg_rn);
11446 static void handle_2misc_pairwise(DisasContext *s, int opcode, bool u,
11447 bool is_q, int size, int rn, int rd)
11449 /* Implement the pairwise operations from 2-misc:
11450 * SADDLP, UADDLP, SADALP, UADALP.
11451 * These all add pairs of elements in the input to produce a
11452 * double-width result element in the output (possibly accumulating).
11454 bool accum = (opcode == 0x6);
11455 int maxpass = is_q ? 2 : 1;
11457 TCGv_i64 tcg_res[2];
11460 /* 32 + 32 -> 64 op */
11461 TCGMemOp memop = size + (u ? 0 : MO_SIGN);
11463 for (pass = 0; pass < maxpass; pass++) {
11464 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
11465 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
11467 tcg_res[pass] = tcg_temp_new_i64();
11469 read_vec_element(s, tcg_op1, rn, pass * 2, memop);
11470 read_vec_element(s, tcg_op2, rn, pass * 2 + 1, memop);
11471 tcg_gen_add_i64(tcg_res[pass], tcg_op1, tcg_op2);
11473 read_vec_element(s, tcg_op1, rd, pass, MO_64);
11474 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
11477 tcg_temp_free_i64(tcg_op1);
11478 tcg_temp_free_i64(tcg_op2);
11481 for (pass = 0; pass < maxpass; pass++) {
11482 TCGv_i64 tcg_op = tcg_temp_new_i64();
11483 NeonGenOneOpFn *genfn;
11484 static NeonGenOneOpFn * const fns[2][2] = {
11485 { gen_helper_neon_addlp_s8, gen_helper_neon_addlp_u8 },
11486 { gen_helper_neon_addlp_s16, gen_helper_neon_addlp_u16 },
11489 genfn = fns[size][u];
11491 tcg_res[pass] = tcg_temp_new_i64();
11493 read_vec_element(s, tcg_op, rn, pass, MO_64);
11494 genfn(tcg_res[pass], tcg_op);
11497 read_vec_element(s, tcg_op, rd, pass, MO_64);
11499 gen_helper_neon_addl_u16(tcg_res[pass],
11500 tcg_res[pass], tcg_op);
11502 gen_helper_neon_addl_u32(tcg_res[pass],
11503 tcg_res[pass], tcg_op);
11506 tcg_temp_free_i64(tcg_op);
11510 tcg_res[1] = tcg_const_i64(0);
11512 for (pass = 0; pass < 2; pass++) {
11513 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11514 tcg_temp_free_i64(tcg_res[pass]);
11518 static void handle_shll(DisasContext *s, bool is_q, int size, int rn, int rd)
11520 /* Implement SHLL and SHLL2 */
11522 int part = is_q ? 2 : 0;
11523 TCGv_i64 tcg_res[2];
11525 for (pass = 0; pass < 2; pass++) {
11526 static NeonGenWidenFn * const widenfns[3] = {
11527 gen_helper_neon_widen_u8,
11528 gen_helper_neon_widen_u16,
11529 tcg_gen_extu_i32_i64,
11531 NeonGenWidenFn *widenfn = widenfns[size];
11532 TCGv_i32 tcg_op = tcg_temp_new_i32();
11534 read_vec_element_i32(s, tcg_op, rn, part + pass, MO_32);
11535 tcg_res[pass] = tcg_temp_new_i64();
11536 widenfn(tcg_res[pass], tcg_op);
11537 tcg_gen_shli_i64(tcg_res[pass], tcg_res[pass], 8 << size);
11539 tcg_temp_free_i32(tcg_op);
11542 for (pass = 0; pass < 2; pass++) {
11543 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
11544 tcg_temp_free_i64(tcg_res[pass]);
11548 /* AdvSIMD two reg misc
11549 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
11550 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11551 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
11552 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11554 static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)
11556 int size = extract32(insn, 22, 2);
11557 int opcode = extract32(insn, 12, 5);
11558 bool u = extract32(insn, 29, 1);
11559 bool is_q = extract32(insn, 30, 1);
11560 int rn = extract32(insn, 5, 5);
11561 int rd = extract32(insn, 0, 5);
11562 bool need_fpstatus = false;
11563 bool need_rmode = false;
11565 TCGv_i32 tcg_rmode;
11566 TCGv_ptr tcg_fpstatus;
11569 case 0x0: /* REV64, REV32 */
11570 case 0x1: /* REV16 */
11571 handle_rev(s, opcode, u, is_q, size, rn, rd);
11573 case 0x5: /* CNT, NOT, RBIT */
11574 if (u && size == 0) {
11577 } else if (u && size == 1) {
11580 } else if (!u && size == 0) {
11584 unallocated_encoding(s);
11586 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
11587 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
11589 unallocated_encoding(s);
11592 if (!fp_access_check(s)) {
11596 handle_2misc_narrow(s, false, opcode, u, is_q, size, rn, rd);
11598 case 0x4: /* CLS, CLZ */
11600 unallocated_encoding(s);
11604 case 0x2: /* SADDLP, UADDLP */
11605 case 0x6: /* SADALP, UADALP */
11607 unallocated_encoding(s);
11610 if (!fp_access_check(s)) {
11613 handle_2misc_pairwise(s, opcode, u, is_q, size, rn, rd);
11615 case 0x13: /* SHLL, SHLL2 */
11616 if (u == 0 || size == 3) {
11617 unallocated_encoding(s);
11620 if (!fp_access_check(s)) {
11623 handle_shll(s, is_q, size, rn, rd);
11625 case 0xa: /* CMLT */
11627 unallocated_encoding(s);
11631 case 0x8: /* CMGT, CMGE */
11632 case 0x9: /* CMEQ, CMLE */
11633 case 0xb: /* ABS, NEG */
11634 if (size == 3 && !is_q) {
11635 unallocated_encoding(s);
11639 case 0x3: /* SUQADD, USQADD */
11640 if (size == 3 && !is_q) {
11641 unallocated_encoding(s);
11644 if (!fp_access_check(s)) {
11647 handle_2misc_satacc(s, false, u, is_q, size, rn, rd);
11649 case 0x7: /* SQABS, SQNEG */
11650 if (size == 3 && !is_q) {
11651 unallocated_encoding(s);
11656 case 0x16 ... 0x1d:
11659 /* Floating point: U, size[1] and opcode indicate operation;
11660 * size[0] indicates single or double precision.
11662 int is_double = extract32(size, 0, 1);
11663 opcode |= (extract32(size, 1, 1) << 5) | (u << 6);
11664 size = is_double ? 3 : 2;
11666 case 0x2f: /* FABS */
11667 case 0x6f: /* FNEG */
11668 if (size == 3 && !is_q) {
11669 unallocated_encoding(s);
11673 case 0x1d: /* SCVTF */
11674 case 0x5d: /* UCVTF */
11676 bool is_signed = (opcode == 0x1d) ? true : false;
11677 int elements = is_double ? 2 : is_q ? 4 : 2;
11678 if (is_double && !is_q) {
11679 unallocated_encoding(s);
11682 if (!fp_access_check(s)) {
11685 handle_simd_intfp_conv(s, rd, rn, elements, is_signed, 0, size);
11688 case 0x2c: /* FCMGT (zero) */
11689 case 0x2d: /* FCMEQ (zero) */
11690 case 0x2e: /* FCMLT (zero) */
11691 case 0x6c: /* FCMGE (zero) */
11692 case 0x6d: /* FCMLE (zero) */
11693 if (size == 3 && !is_q) {
11694 unallocated_encoding(s);
11697 handle_2misc_fcmp_zero(s, opcode, false, u, is_q, size, rn, rd);
11699 case 0x7f: /* FSQRT */
11700 if (size == 3 && !is_q) {
11701 unallocated_encoding(s);
11705 case 0x1a: /* FCVTNS */
11706 case 0x1b: /* FCVTMS */
11707 case 0x3a: /* FCVTPS */
11708 case 0x3b: /* FCVTZS */
11709 case 0x5a: /* FCVTNU */
11710 case 0x5b: /* FCVTMU */
11711 case 0x7a: /* FCVTPU */
11712 case 0x7b: /* FCVTZU */
11713 need_fpstatus = true;
11715 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
11716 if (size == 3 && !is_q) {
11717 unallocated_encoding(s);
11721 case 0x5c: /* FCVTAU */
11722 case 0x1c: /* FCVTAS */
11723 need_fpstatus = true;
11725 rmode = FPROUNDING_TIEAWAY;
11726 if (size == 3 && !is_q) {
11727 unallocated_encoding(s);
11731 case 0x3c: /* URECPE */
11733 unallocated_encoding(s);
11737 case 0x3d: /* FRECPE */
11738 case 0x7d: /* FRSQRTE */
11739 if (size == 3 && !is_q) {
11740 unallocated_encoding(s);
11743 if (!fp_access_check(s)) {
11746 handle_2misc_reciprocal(s, opcode, false, u, is_q, size, rn, rd);
11748 case 0x56: /* FCVTXN, FCVTXN2 */
11750 unallocated_encoding(s);
11754 case 0x16: /* FCVTN, FCVTN2 */
11755 /* handle_2misc_narrow does a 2*size -> size operation, but these
11756 * instructions encode the source size rather than dest size.
11758 if (!fp_access_check(s)) {
11761 handle_2misc_narrow(s, false, opcode, 0, is_q, size - 1, rn, rd);
11763 case 0x17: /* FCVTL, FCVTL2 */
11764 if (!fp_access_check(s)) {
11767 handle_2misc_widening(s, opcode, is_q, size, rn, rd);
11769 case 0x18: /* FRINTN */
11770 case 0x19: /* FRINTM */
11771 case 0x38: /* FRINTP */
11772 case 0x39: /* FRINTZ */
11774 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
11776 case 0x59: /* FRINTX */
11777 case 0x79: /* FRINTI */
11778 need_fpstatus = true;
11779 if (size == 3 && !is_q) {
11780 unallocated_encoding(s);
11784 case 0x58: /* FRINTA */
11786 rmode = FPROUNDING_TIEAWAY;
11787 need_fpstatus = true;
11788 if (size == 3 && !is_q) {
11789 unallocated_encoding(s);
11793 case 0x7c: /* URSQRTE */
11795 unallocated_encoding(s);
11798 need_fpstatus = true;
11801 unallocated_encoding(s);
11807 unallocated_encoding(s);
11811 if (!fp_access_check(s)) {
11815 if (need_fpstatus || need_rmode) {
11816 tcg_fpstatus = get_fpstatus_ptr(false);
11818 tcg_fpstatus = NULL;
11821 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
11822 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
11829 if (u && size == 0) { /* NOT */
11830 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_not, 0);
11836 gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_neg, size);
11843 /* All 64-bit element operations can be shared with scalar 2misc */
11846 /* Coverity claims (size == 3 && !is_q) has been eliminated
11847 * from all paths leading to here.
11849 tcg_debug_assert(is_q);
11850 for (pass = 0; pass < 2; pass++) {
11851 TCGv_i64 tcg_op = tcg_temp_new_i64();
11852 TCGv_i64 tcg_res = tcg_temp_new_i64();
11854 read_vec_element(s, tcg_op, rn, pass, MO_64);
11856 handle_2misc_64(s, opcode, u, tcg_res, tcg_op,
11857 tcg_rmode, tcg_fpstatus);
11859 write_vec_element(s, tcg_res, rd, pass, MO_64);
11861 tcg_temp_free_i64(tcg_res);
11862 tcg_temp_free_i64(tcg_op);
11867 for (pass = 0; pass < (is_q ? 4 : 2); pass++) {
11868 TCGv_i32 tcg_op = tcg_temp_new_i32();
11869 TCGv_i32 tcg_res = tcg_temp_new_i32();
11872 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
11875 /* Special cases for 32 bit elements */
11877 case 0xa: /* CMLT */
11878 /* 32 bit integer comparison against zero, result is
11879 * test ? (2^32 - 1) : 0. We implement via setcond(test)
11882 cond = TCG_COND_LT;
11884 tcg_gen_setcondi_i32(cond, tcg_res, tcg_op, 0);
11885 tcg_gen_neg_i32(tcg_res, tcg_res);
11887 case 0x8: /* CMGT, CMGE */
11888 cond = u ? TCG_COND_GE : TCG_COND_GT;
11890 case 0x9: /* CMEQ, CMLE */
11891 cond = u ? TCG_COND_LE : TCG_COND_EQ;
11893 case 0x4: /* CLS */
11895 tcg_gen_clzi_i32(tcg_res, tcg_op, 32);
11897 tcg_gen_clrsb_i32(tcg_res, tcg_op);
11900 case 0x7: /* SQABS, SQNEG */
11902 gen_helper_neon_qneg_s32(tcg_res, cpu_env, tcg_op);
11904 gen_helper_neon_qabs_s32(tcg_res, cpu_env, tcg_op);
11907 case 0xb: /* ABS, NEG */
11909 tcg_gen_neg_i32(tcg_res, tcg_op);
11911 TCGv_i32 tcg_zero = tcg_const_i32(0);
11912 tcg_gen_neg_i32(tcg_res, tcg_op);
11913 tcg_gen_movcond_i32(TCG_COND_GT, tcg_res, tcg_op,
11914 tcg_zero, tcg_op, tcg_res);
11915 tcg_temp_free_i32(tcg_zero);
11918 case 0x2f: /* FABS */
11919 gen_helper_vfp_abss(tcg_res, tcg_op);
11921 case 0x6f: /* FNEG */
11922 gen_helper_vfp_negs(tcg_res, tcg_op);
11924 case 0x7f: /* FSQRT */
11925 gen_helper_vfp_sqrts(tcg_res, tcg_op, cpu_env);
11927 case 0x1a: /* FCVTNS */
11928 case 0x1b: /* FCVTMS */
11929 case 0x1c: /* FCVTAS */
11930 case 0x3a: /* FCVTPS */
11931 case 0x3b: /* FCVTZS */
11933 TCGv_i32 tcg_shift = tcg_const_i32(0);
11934 gen_helper_vfp_tosls(tcg_res, tcg_op,
11935 tcg_shift, tcg_fpstatus);
11936 tcg_temp_free_i32(tcg_shift);
11939 case 0x5a: /* FCVTNU */
11940 case 0x5b: /* FCVTMU */
11941 case 0x5c: /* FCVTAU */
11942 case 0x7a: /* FCVTPU */
11943 case 0x7b: /* FCVTZU */
11945 TCGv_i32 tcg_shift = tcg_const_i32(0);
11946 gen_helper_vfp_touls(tcg_res, tcg_op,
11947 tcg_shift, tcg_fpstatus);
11948 tcg_temp_free_i32(tcg_shift);
11951 case 0x18: /* FRINTN */
11952 case 0x19: /* FRINTM */
11953 case 0x38: /* FRINTP */
11954 case 0x39: /* FRINTZ */
11955 case 0x58: /* FRINTA */
11956 case 0x79: /* FRINTI */
11957 gen_helper_rints(tcg_res, tcg_op, tcg_fpstatus);
11959 case 0x59: /* FRINTX */
11960 gen_helper_rints_exact(tcg_res, tcg_op, tcg_fpstatus);
11962 case 0x7c: /* URSQRTE */
11963 gen_helper_rsqrte_u32(tcg_res, tcg_op, tcg_fpstatus);
11966 g_assert_not_reached();
11969 /* Use helpers for 8 and 16 bit elements */
11971 case 0x5: /* CNT, RBIT */
11972 /* For these two insns size is part of the opcode specifier
11973 * (handled earlier); they always operate on byte elements.
11976 gen_helper_neon_rbit_u8(tcg_res, tcg_op);
11978 gen_helper_neon_cnt_u8(tcg_res, tcg_op);
11981 case 0x7: /* SQABS, SQNEG */
11983 NeonGenOneOpEnvFn *genfn;
11984 static NeonGenOneOpEnvFn * const fns[2][2] = {
11985 { gen_helper_neon_qabs_s8, gen_helper_neon_qneg_s8 },
11986 { gen_helper_neon_qabs_s16, gen_helper_neon_qneg_s16 },
11988 genfn = fns[size][u];
11989 genfn(tcg_res, cpu_env, tcg_op);
11992 case 0x8: /* CMGT, CMGE */
11993 case 0x9: /* CMEQ, CMLE */
11994 case 0xa: /* CMLT */
11996 static NeonGenTwoOpFn * const fns[3][2] = {
11997 { gen_helper_neon_cgt_s8, gen_helper_neon_cgt_s16 },
11998 { gen_helper_neon_cge_s8, gen_helper_neon_cge_s16 },
11999 { gen_helper_neon_ceq_u8, gen_helper_neon_ceq_u16 },
12001 NeonGenTwoOpFn *genfn;
12004 TCGv_i32 tcg_zero = tcg_const_i32(0);
12006 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
12007 comp = (opcode - 0x8) * 2 + u;
12008 /* ...but LE, LT are implemented as reverse GE, GT */
12009 reverse = (comp > 2);
12013 genfn = fns[comp][size];
12015 genfn(tcg_res, tcg_zero, tcg_op);
12017 genfn(tcg_res, tcg_op, tcg_zero);
12019 tcg_temp_free_i32(tcg_zero);
12022 case 0xb: /* ABS, NEG */
12024 TCGv_i32 tcg_zero = tcg_const_i32(0);
12026 gen_helper_neon_sub_u16(tcg_res, tcg_zero, tcg_op);
12028 gen_helper_neon_sub_u8(tcg_res, tcg_zero, tcg_op);
12030 tcg_temp_free_i32(tcg_zero);
12033 gen_helper_neon_abs_s16(tcg_res, tcg_op);
12035 gen_helper_neon_abs_s8(tcg_res, tcg_op);
12039 case 0x4: /* CLS, CLZ */
12042 gen_helper_neon_clz_u8(tcg_res, tcg_op);
12044 gen_helper_neon_clz_u16(tcg_res, tcg_op);
12048 gen_helper_neon_cls_s8(tcg_res, tcg_op);
12050 gen_helper_neon_cls_s16(tcg_res, tcg_op);
12055 g_assert_not_reached();
12059 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
12061 tcg_temp_free_i32(tcg_res);
12062 tcg_temp_free_i32(tcg_op);
12065 clear_vec_high(s, is_q, rd);
12068 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12069 tcg_temp_free_i32(tcg_rmode);
12071 if (need_fpstatus) {
12072 tcg_temp_free_ptr(tcg_fpstatus);
12076 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12078 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12079 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12080 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12081 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12082 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12083 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12085 * This actually covers two groups where scalar access is governed by
12086 * bit 28. A bunch of the instructions (float to integral) only exist
12087 * in the vector form and are un-allocated for the scalar decode. Also
12088 * in the scalar decode Q is always 1.
12090 static void disas_simd_two_reg_misc_fp16(DisasContext *s, uint32_t insn)
12092 int fpop, opcode, a, u;
12096 bool only_in_vector = false;
12099 TCGv_i32 tcg_rmode = NULL;
12100 TCGv_ptr tcg_fpstatus = NULL;
12101 bool need_rmode = false;
12102 bool need_fpst = true;
12105 if (!dc_isar_feature(aa64_fp16, s)) {
12106 unallocated_encoding(s);
12110 rd = extract32(insn, 0, 5);
12111 rn = extract32(insn, 5, 5);
12113 a = extract32(insn, 23, 1);
12114 u = extract32(insn, 29, 1);
12115 is_scalar = extract32(insn, 28, 1);
12116 is_q = extract32(insn, 30, 1);
12118 opcode = extract32(insn, 12, 5);
12119 fpop = deposit32(opcode, 5, 1, a);
12120 fpop = deposit32(fpop, 6, 1, u);
12122 rd = extract32(insn, 0, 5);
12123 rn = extract32(insn, 5, 5);
12126 case 0x1d: /* SCVTF */
12127 case 0x5d: /* UCVTF */
12134 elements = (is_q ? 8 : 4);
12137 if (!fp_access_check(s)) {
12140 handle_simd_intfp_conv(s, rd, rn, elements, !u, 0, MO_16);
12144 case 0x2c: /* FCMGT (zero) */
12145 case 0x2d: /* FCMEQ (zero) */
12146 case 0x2e: /* FCMLT (zero) */
12147 case 0x6c: /* FCMGE (zero) */
12148 case 0x6d: /* FCMLE (zero) */
12149 handle_2misc_fcmp_zero(s, fpop, is_scalar, 0, is_q, MO_16, rn, rd);
12151 case 0x3d: /* FRECPE */
12152 case 0x3f: /* FRECPX */
12154 case 0x18: /* FRINTN */
12156 only_in_vector = true;
12157 rmode = FPROUNDING_TIEEVEN;
12159 case 0x19: /* FRINTM */
12161 only_in_vector = true;
12162 rmode = FPROUNDING_NEGINF;
12164 case 0x38: /* FRINTP */
12166 only_in_vector = true;
12167 rmode = FPROUNDING_POSINF;
12169 case 0x39: /* FRINTZ */
12171 only_in_vector = true;
12172 rmode = FPROUNDING_ZERO;
12174 case 0x58: /* FRINTA */
12176 only_in_vector = true;
12177 rmode = FPROUNDING_TIEAWAY;
12179 case 0x59: /* FRINTX */
12180 case 0x79: /* FRINTI */
12181 only_in_vector = true;
12182 /* current rounding mode */
12184 case 0x1a: /* FCVTNS */
12186 rmode = FPROUNDING_TIEEVEN;
12188 case 0x1b: /* FCVTMS */
12190 rmode = FPROUNDING_NEGINF;
12192 case 0x1c: /* FCVTAS */
12194 rmode = FPROUNDING_TIEAWAY;
12196 case 0x3a: /* FCVTPS */
12198 rmode = FPROUNDING_POSINF;
12200 case 0x3b: /* FCVTZS */
12202 rmode = FPROUNDING_ZERO;
12204 case 0x5a: /* FCVTNU */
12206 rmode = FPROUNDING_TIEEVEN;
12208 case 0x5b: /* FCVTMU */
12210 rmode = FPROUNDING_NEGINF;
12212 case 0x5c: /* FCVTAU */
12214 rmode = FPROUNDING_TIEAWAY;
12216 case 0x7a: /* FCVTPU */
12218 rmode = FPROUNDING_POSINF;
12220 case 0x7b: /* FCVTZU */
12222 rmode = FPROUNDING_ZERO;
12224 case 0x2f: /* FABS */
12225 case 0x6f: /* FNEG */
12228 case 0x7d: /* FRSQRTE */
12229 case 0x7f: /* FSQRT (vector) */
12232 fprintf(stderr, "%s: insn %#04x fpop %#2x\n", __func__, insn, fpop);
12233 g_assert_not_reached();
12237 /* Check additional constraints for the scalar encoding */
12240 unallocated_encoding(s);
12243 /* FRINTxx is only in the vector form */
12244 if (only_in_vector) {
12245 unallocated_encoding(s);
12250 if (!fp_access_check(s)) {
12254 if (need_rmode || need_fpst) {
12255 tcg_fpstatus = get_fpstatus_ptr(true);
12259 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
12260 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12264 TCGv_i32 tcg_op = read_fp_hreg(s, rn);
12265 TCGv_i32 tcg_res = tcg_temp_new_i32();
12268 case 0x1a: /* FCVTNS */
12269 case 0x1b: /* FCVTMS */
12270 case 0x1c: /* FCVTAS */
12271 case 0x3a: /* FCVTPS */
12272 case 0x3b: /* FCVTZS */
12273 gen_helper_advsimd_f16tosinth(tcg_res, tcg_op, tcg_fpstatus);
12275 case 0x3d: /* FRECPE */
12276 gen_helper_recpe_f16(tcg_res, tcg_op, tcg_fpstatus);
12278 case 0x3f: /* FRECPX */
12279 gen_helper_frecpx_f16(tcg_res, tcg_op, tcg_fpstatus);
12281 case 0x5a: /* FCVTNU */
12282 case 0x5b: /* FCVTMU */
12283 case 0x5c: /* FCVTAU */
12284 case 0x7a: /* FCVTPU */
12285 case 0x7b: /* FCVTZU */
12286 gen_helper_advsimd_f16touinth(tcg_res, tcg_op, tcg_fpstatus);
12288 case 0x6f: /* FNEG */
12289 tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000);
12291 case 0x7d: /* FRSQRTE */
12292 gen_helper_rsqrte_f16(tcg_res, tcg_op, tcg_fpstatus);
12295 g_assert_not_reached();
12298 /* limit any sign extension going on */
12299 tcg_gen_andi_i32(tcg_res, tcg_res, 0xffff);
12300 write_fp_sreg(s, rd, tcg_res);
12302 tcg_temp_free_i32(tcg_res);
12303 tcg_temp_free_i32(tcg_op);
12305 for (pass = 0; pass < (is_q ? 8 : 4); pass++) {
12306 TCGv_i32 tcg_op = tcg_temp_new_i32();
12307 TCGv_i32 tcg_res = tcg_temp_new_i32();
12309 read_vec_element_i32(s, tcg_op, rn, pass, MO_16);
12312 case 0x1a: /* FCVTNS */
12313 case 0x1b: /* FCVTMS */
12314 case 0x1c: /* FCVTAS */
12315 case 0x3a: /* FCVTPS */
12316 case 0x3b: /* FCVTZS */
12317 gen_helper_advsimd_f16tosinth(tcg_res, tcg_op, tcg_fpstatus);
12319 case 0x3d: /* FRECPE */
12320 gen_helper_recpe_f16(tcg_res, tcg_op, tcg_fpstatus);
12322 case 0x5a: /* FCVTNU */
12323 case 0x5b: /* FCVTMU */
12324 case 0x5c: /* FCVTAU */
12325 case 0x7a: /* FCVTPU */
12326 case 0x7b: /* FCVTZU */
12327 gen_helper_advsimd_f16touinth(tcg_res, tcg_op, tcg_fpstatus);
12329 case 0x18: /* FRINTN */
12330 case 0x19: /* FRINTM */
12331 case 0x38: /* FRINTP */
12332 case 0x39: /* FRINTZ */
12333 case 0x58: /* FRINTA */
12334 case 0x79: /* FRINTI */
12335 gen_helper_advsimd_rinth(tcg_res, tcg_op, tcg_fpstatus);
12337 case 0x59: /* FRINTX */
12338 gen_helper_advsimd_rinth_exact(tcg_res, tcg_op, tcg_fpstatus);
12340 case 0x2f: /* FABS */
12341 tcg_gen_andi_i32(tcg_res, tcg_op, 0x7fff);
12343 case 0x6f: /* FNEG */
12344 tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000);
12346 case 0x7d: /* FRSQRTE */
12347 gen_helper_rsqrte_f16(tcg_res, tcg_op, tcg_fpstatus);
12349 case 0x7f: /* FSQRT */
12350 gen_helper_sqrt_f16(tcg_res, tcg_op, tcg_fpstatus);
12353 g_assert_not_reached();
12356 write_vec_element_i32(s, tcg_res, rd, pass, MO_16);
12358 tcg_temp_free_i32(tcg_res);
12359 tcg_temp_free_i32(tcg_op);
12362 clear_vec_high(s, is_q, rd);
12366 gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus);
12367 tcg_temp_free_i32(tcg_rmode);
12370 if (tcg_fpstatus) {
12371 tcg_temp_free_ptr(tcg_fpstatus);
12375 /* AdvSIMD scalar x indexed element
12376 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12377 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12378 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12379 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12380 * AdvSIMD vector x indexed element
12381 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12382 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12383 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12384 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12386 static void disas_simd_indexed(DisasContext *s, uint32_t insn)
12388 /* This encoding has two kinds of instruction:
12389 * normal, where we perform elt x idxelt => elt for each
12390 * element in the vector
12391 * long, where we perform elt x idxelt and generate a result of
12392 * double the width of the input element
12393 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
12395 bool is_scalar = extract32(insn, 28, 1);
12396 bool is_q = extract32(insn, 30, 1);
12397 bool u = extract32(insn, 29, 1);
12398 int size = extract32(insn, 22, 2);
12399 int l = extract32(insn, 21, 1);
12400 int m = extract32(insn, 20, 1);
12401 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
12402 int rm = extract32(insn, 16, 4);
12403 int opcode = extract32(insn, 12, 4);
12404 int h = extract32(insn, 11, 1);
12405 int rn = extract32(insn, 5, 5);
12406 int rd = extract32(insn, 0, 5);
12407 bool is_long = false;
12409 bool is_fp16 = false;
12413 switch (16 * u + opcode) {
12414 case 0x08: /* MUL */
12415 case 0x10: /* MLA */
12416 case 0x14: /* MLS */
12418 unallocated_encoding(s);
12422 case 0x02: /* SMLAL, SMLAL2 */
12423 case 0x12: /* UMLAL, UMLAL2 */
12424 case 0x06: /* SMLSL, SMLSL2 */
12425 case 0x16: /* UMLSL, UMLSL2 */
12426 case 0x0a: /* SMULL, SMULL2 */
12427 case 0x1a: /* UMULL, UMULL2 */
12429 unallocated_encoding(s);
12434 case 0x03: /* SQDMLAL, SQDMLAL2 */
12435 case 0x07: /* SQDMLSL, SQDMLSL2 */
12436 case 0x0b: /* SQDMULL, SQDMULL2 */
12439 case 0x0c: /* SQDMULH */
12440 case 0x0d: /* SQRDMULH */
12442 case 0x01: /* FMLA */
12443 case 0x05: /* FMLS */
12444 case 0x09: /* FMUL */
12445 case 0x19: /* FMULX */
12448 case 0x1d: /* SQRDMLAH */
12449 case 0x1f: /* SQRDMLSH */
12450 if (!dc_isar_feature(aa64_rdm, s)) {
12451 unallocated_encoding(s);
12455 case 0x0e: /* SDOT */
12456 case 0x1e: /* UDOT */
12457 if (size != MO_32 || !dc_isar_feature(aa64_dp, s)) {
12458 unallocated_encoding(s);
12462 case 0x11: /* FCMLA #0 */
12463 case 0x13: /* FCMLA #90 */
12464 case 0x15: /* FCMLA #180 */
12465 case 0x17: /* FCMLA #270 */
12466 if (!dc_isar_feature(aa64_fcma, s)) {
12467 unallocated_encoding(s);
12473 unallocated_encoding(s);
12478 case 1: /* normal fp */
12479 /* convert insn encoded size to TCGMemOp size */
12481 case 0: /* half-precision */
12485 case MO_32: /* single precision */
12486 case MO_64: /* double precision */
12489 unallocated_encoding(s);
12494 case 2: /* complex fp */
12495 /* Each indexable element is a complex pair. */
12500 unallocated_encoding(s);
12508 unallocated_encoding(s);
12513 default: /* integer */
12517 unallocated_encoding(s);
12522 if (is_fp16 && !dc_isar_feature(aa64_fp16, s)) {
12523 unallocated_encoding(s);
12527 /* Given TCGMemOp size, adjust register and indexing. */
12530 index = h << 2 | l << 1 | m;
12533 index = h << 1 | l;
12538 unallocated_encoding(s);
12545 g_assert_not_reached();
12548 if (!fp_access_check(s)) {
12553 fpst = get_fpstatus_ptr(is_fp16);
12558 switch (16 * u + opcode) {
12559 case 0x0e: /* SDOT */
12560 case 0x1e: /* UDOT */
12561 gen_gvec_op3_ool(s, is_q, rd, rn, rm, index,
12562 u ? gen_helper_gvec_udot_idx_b
12563 : gen_helper_gvec_sdot_idx_b);
12565 case 0x11: /* FCMLA #0 */
12566 case 0x13: /* FCMLA #90 */
12567 case 0x15: /* FCMLA #180 */
12568 case 0x17: /* FCMLA #270 */
12570 int rot = extract32(insn, 13, 2);
12571 int data = (index << 2) | rot;
12572 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
12573 vec_full_reg_offset(s, rn),
12574 vec_full_reg_offset(s, rm), fpst,
12575 is_q ? 16 : 8, vec_full_reg_size(s), data,
12577 ? gen_helper_gvec_fcmlas_idx
12578 : gen_helper_gvec_fcmlah_idx);
12579 tcg_temp_free_ptr(fpst);
12585 TCGv_i64 tcg_idx = tcg_temp_new_i64();
12588 assert(is_fp && is_q && !is_long);
12590 read_vec_element(s, tcg_idx, rm, index, MO_64);
12592 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
12593 TCGv_i64 tcg_op = tcg_temp_new_i64();
12594 TCGv_i64 tcg_res = tcg_temp_new_i64();
12596 read_vec_element(s, tcg_op, rn, pass, MO_64);
12598 switch (16 * u + opcode) {
12599 case 0x05: /* FMLS */
12600 /* As usual for ARM, separate negation for fused multiply-add */
12601 gen_helper_vfp_negd(tcg_op, tcg_op);
12603 case 0x01: /* FMLA */
12604 read_vec_element(s, tcg_res, rd, pass, MO_64);
12605 gen_helper_vfp_muladdd(tcg_res, tcg_op, tcg_idx, tcg_res, fpst);
12607 case 0x09: /* FMUL */
12608 gen_helper_vfp_muld(tcg_res, tcg_op, tcg_idx, fpst);
12610 case 0x19: /* FMULX */
12611 gen_helper_vfp_mulxd(tcg_res, tcg_op, tcg_idx, fpst);
12614 g_assert_not_reached();
12617 write_vec_element(s, tcg_res, rd, pass, MO_64);
12618 tcg_temp_free_i64(tcg_op);
12619 tcg_temp_free_i64(tcg_res);
12622 tcg_temp_free_i64(tcg_idx);
12623 clear_vec_high(s, !is_scalar, rd);
12624 } else if (!is_long) {
12625 /* 32 bit floating point, or 16 or 32 bit integer.
12626 * For the 16 bit scalar case we use the usual Neon helpers and
12627 * rely on the fact that 0 op 0 == 0 with no side effects.
12629 TCGv_i32 tcg_idx = tcg_temp_new_i32();
12630 int pass, maxpasses;
12635 maxpasses = is_q ? 4 : 2;
12638 read_vec_element_i32(s, tcg_idx, rm, index, size);
12640 if (size == 1 && !is_scalar) {
12641 /* The simplest way to handle the 16x16 indexed ops is to duplicate
12642 * the index into both halves of the 32 bit tcg_idx and then use
12643 * the usual Neon helpers.
12645 tcg_gen_deposit_i32(tcg_idx, tcg_idx, tcg_idx, 16, 16);
12648 for (pass = 0; pass < maxpasses; pass++) {
12649 TCGv_i32 tcg_op = tcg_temp_new_i32();
12650 TCGv_i32 tcg_res = tcg_temp_new_i32();
12652 read_vec_element_i32(s, tcg_op, rn, pass, is_scalar ? size : MO_32);
12654 switch (16 * u + opcode) {
12655 case 0x08: /* MUL */
12656 case 0x10: /* MLA */
12657 case 0x14: /* MLS */
12659 static NeonGenTwoOpFn * const fns[2][2] = {
12660 { gen_helper_neon_add_u16, gen_helper_neon_sub_u16 },
12661 { tcg_gen_add_i32, tcg_gen_sub_i32 },
12663 NeonGenTwoOpFn *genfn;
12664 bool is_sub = opcode == 0x4;
12667 gen_helper_neon_mul_u16(tcg_res, tcg_op, tcg_idx);
12669 tcg_gen_mul_i32(tcg_res, tcg_op, tcg_idx);
12671 if (opcode == 0x8) {
12674 read_vec_element_i32(s, tcg_op, rd, pass, MO_32);
12675 genfn = fns[size - 1][is_sub];
12676 genfn(tcg_res, tcg_op, tcg_res);
12679 case 0x05: /* FMLS */
12680 case 0x01: /* FMLA */
12681 read_vec_element_i32(s, tcg_res, rd, pass,
12682 is_scalar ? size : MO_32);
12685 if (opcode == 0x5) {
12686 /* As usual for ARM, separate negation for fused
12688 tcg_gen_xori_i32(tcg_op, tcg_op, 0x80008000);
12691 gen_helper_advsimd_muladdh(tcg_res, tcg_op, tcg_idx,
12694 gen_helper_advsimd_muladd2h(tcg_res, tcg_op, tcg_idx,
12699 if (opcode == 0x5) {
12700 /* As usual for ARM, separate negation for
12701 * fused multiply-add */
12702 tcg_gen_xori_i32(tcg_op, tcg_op, 0x80000000);
12704 gen_helper_vfp_muladds(tcg_res, tcg_op, tcg_idx,
12708 g_assert_not_reached();
12711 case 0x09: /* FMUL */
12715 gen_helper_advsimd_mulh(tcg_res, tcg_op,
12718 gen_helper_advsimd_mul2h(tcg_res, tcg_op,
12723 gen_helper_vfp_muls(tcg_res, tcg_op, tcg_idx, fpst);
12726 g_assert_not_reached();
12729 case 0x19: /* FMULX */
12733 gen_helper_advsimd_mulxh(tcg_res, tcg_op,
12736 gen_helper_advsimd_mulx2h(tcg_res, tcg_op,
12741 gen_helper_vfp_mulxs(tcg_res, tcg_op, tcg_idx, fpst);
12744 g_assert_not_reached();
12747 case 0x0c: /* SQDMULH */
12749 gen_helper_neon_qdmulh_s16(tcg_res, cpu_env,
12752 gen_helper_neon_qdmulh_s32(tcg_res, cpu_env,
12756 case 0x0d: /* SQRDMULH */
12758 gen_helper_neon_qrdmulh_s16(tcg_res, cpu_env,
12761 gen_helper_neon_qrdmulh_s32(tcg_res, cpu_env,
12765 case 0x1d: /* SQRDMLAH */
12766 read_vec_element_i32(s, tcg_res, rd, pass,
12767 is_scalar ? size : MO_32);
12769 gen_helper_neon_qrdmlah_s16(tcg_res, cpu_env,
12770 tcg_op, tcg_idx, tcg_res);
12772 gen_helper_neon_qrdmlah_s32(tcg_res, cpu_env,
12773 tcg_op, tcg_idx, tcg_res);
12776 case 0x1f: /* SQRDMLSH */
12777 read_vec_element_i32(s, tcg_res, rd, pass,
12778 is_scalar ? size : MO_32);
12780 gen_helper_neon_qrdmlsh_s16(tcg_res, cpu_env,
12781 tcg_op, tcg_idx, tcg_res);
12783 gen_helper_neon_qrdmlsh_s32(tcg_res, cpu_env,
12784 tcg_op, tcg_idx, tcg_res);
12788 g_assert_not_reached();
12792 write_fp_sreg(s, rd, tcg_res);
12794 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
12797 tcg_temp_free_i32(tcg_op);
12798 tcg_temp_free_i32(tcg_res);
12801 tcg_temp_free_i32(tcg_idx);
12802 clear_vec_high(s, is_q, rd);
12804 /* long ops: 16x16->32 or 32x32->64 */
12805 TCGv_i64 tcg_res[2];
12807 bool satop = extract32(opcode, 0, 1);
12808 TCGMemOp memop = MO_32;
12815 TCGv_i64 tcg_idx = tcg_temp_new_i64();
12817 read_vec_element(s, tcg_idx, rm, index, memop);
12819 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
12820 TCGv_i64 tcg_op = tcg_temp_new_i64();
12821 TCGv_i64 tcg_passres;
12827 passelt = pass + (is_q * 2);
12830 read_vec_element(s, tcg_op, rn, passelt, memop);
12832 tcg_res[pass] = tcg_temp_new_i64();
12834 if (opcode == 0xa || opcode == 0xb) {
12835 /* Non-accumulating ops */
12836 tcg_passres = tcg_res[pass];
12838 tcg_passres = tcg_temp_new_i64();
12841 tcg_gen_mul_i64(tcg_passres, tcg_op, tcg_idx);
12842 tcg_temp_free_i64(tcg_op);
12845 /* saturating, doubling */
12846 gen_helper_neon_addl_saturate_s64(tcg_passres, cpu_env,
12847 tcg_passres, tcg_passres);
12850 if (opcode == 0xa || opcode == 0xb) {
12854 /* Accumulating op: handle accumulate step */
12855 read_vec_element(s, tcg_res[pass], rd, pass, MO_64);
12858 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
12859 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
12861 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
12862 tcg_gen_sub_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
12864 case 0x7: /* SQDMLSL, SQDMLSL2 */
12865 tcg_gen_neg_i64(tcg_passres, tcg_passres);
12867 case 0x3: /* SQDMLAL, SQDMLAL2 */
12868 gen_helper_neon_addl_saturate_s64(tcg_res[pass], cpu_env,
12873 g_assert_not_reached();
12875 tcg_temp_free_i64(tcg_passres);
12877 tcg_temp_free_i64(tcg_idx);
12879 clear_vec_high(s, !is_scalar, rd);
12881 TCGv_i32 tcg_idx = tcg_temp_new_i32();
12884 read_vec_element_i32(s, tcg_idx, rm, index, size);
12887 /* The simplest way to handle the 16x16 indexed ops is to
12888 * duplicate the index into both halves of the 32 bit tcg_idx
12889 * and then use the usual Neon helpers.
12891 tcg_gen_deposit_i32(tcg_idx, tcg_idx, tcg_idx, 16, 16);
12894 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
12895 TCGv_i32 tcg_op = tcg_temp_new_i32();
12896 TCGv_i64 tcg_passres;
12899 read_vec_element_i32(s, tcg_op, rn, pass, size);
12901 read_vec_element_i32(s, tcg_op, rn,
12902 pass + (is_q * 2), MO_32);
12905 tcg_res[pass] = tcg_temp_new_i64();
12907 if (opcode == 0xa || opcode == 0xb) {
12908 /* Non-accumulating ops */
12909 tcg_passres = tcg_res[pass];
12911 tcg_passres = tcg_temp_new_i64();
12914 if (memop & MO_SIGN) {
12915 gen_helper_neon_mull_s16(tcg_passres, tcg_op, tcg_idx);
12917 gen_helper_neon_mull_u16(tcg_passres, tcg_op, tcg_idx);
12920 gen_helper_neon_addl_saturate_s32(tcg_passres, cpu_env,
12921 tcg_passres, tcg_passres);
12923 tcg_temp_free_i32(tcg_op);
12925 if (opcode == 0xa || opcode == 0xb) {
12929 /* Accumulating op: handle accumulate step */
12930 read_vec_element(s, tcg_res[pass], rd, pass, MO_64);
12933 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
12934 gen_helper_neon_addl_u32(tcg_res[pass], tcg_res[pass],
12937 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
12938 gen_helper_neon_subl_u32(tcg_res[pass], tcg_res[pass],
12941 case 0x7: /* SQDMLSL, SQDMLSL2 */
12942 gen_helper_neon_negl_u32(tcg_passres, tcg_passres);
12944 case 0x3: /* SQDMLAL, SQDMLAL2 */
12945 gen_helper_neon_addl_saturate_s32(tcg_res[pass], cpu_env,
12950 g_assert_not_reached();
12952 tcg_temp_free_i64(tcg_passres);
12954 tcg_temp_free_i32(tcg_idx);
12957 tcg_gen_ext32u_i64(tcg_res[0], tcg_res[0]);
12962 tcg_res[1] = tcg_const_i64(0);
12965 for (pass = 0; pass < 2; pass++) {
12966 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
12967 tcg_temp_free_i64(tcg_res[pass]);
12972 tcg_temp_free_ptr(fpst);
12977 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
12978 * +-----------------+------+-----------+--------+-----+------+------+
12979 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
12980 * +-----------------+------+-----------+--------+-----+------+------+
12982 static void disas_crypto_aes(DisasContext *s, uint32_t insn)
12984 int size = extract32(insn, 22, 2);
12985 int opcode = extract32(insn, 12, 5);
12986 int rn = extract32(insn, 5, 5);
12987 int rd = extract32(insn, 0, 5);
12989 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
12990 TCGv_i32 tcg_decrypt;
12991 CryptoThreeOpIntFn *genfn;
12993 if (!dc_isar_feature(aa64_aes, s) || size != 0) {
12994 unallocated_encoding(s);
12999 case 0x4: /* AESE */
13001 genfn = gen_helper_crypto_aese;
13003 case 0x6: /* AESMC */
13005 genfn = gen_helper_crypto_aesmc;
13007 case 0x5: /* AESD */
13009 genfn = gen_helper_crypto_aese;
13011 case 0x7: /* AESIMC */
13013 genfn = gen_helper_crypto_aesmc;
13016 unallocated_encoding(s);
13020 if (!fp_access_check(s)) {
13024 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13025 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13026 tcg_decrypt = tcg_const_i32(decrypt);
13028 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_decrypt);
13030 tcg_temp_free_ptr(tcg_rd_ptr);
13031 tcg_temp_free_ptr(tcg_rn_ptr);
13032 tcg_temp_free_i32(tcg_decrypt);
13035 /* Crypto three-reg SHA
13036 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
13037 * +-----------------+------+---+------+---+--------+-----+------+------+
13038 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
13039 * +-----------------+------+---+------+---+--------+-----+------+------+
13041 static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn)
13043 int size = extract32(insn, 22, 2);
13044 int opcode = extract32(insn, 12, 3);
13045 int rm = extract32(insn, 16, 5);
13046 int rn = extract32(insn, 5, 5);
13047 int rd = extract32(insn, 0, 5);
13048 CryptoThreeOpFn *genfn;
13049 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13053 unallocated_encoding(s);
13058 case 0: /* SHA1C */
13059 case 1: /* SHA1P */
13060 case 2: /* SHA1M */
13061 case 3: /* SHA1SU0 */
13063 feature = dc_isar_feature(aa64_sha1, s);
13065 case 4: /* SHA256H */
13066 genfn = gen_helper_crypto_sha256h;
13067 feature = dc_isar_feature(aa64_sha256, s);
13069 case 5: /* SHA256H2 */
13070 genfn = gen_helper_crypto_sha256h2;
13071 feature = dc_isar_feature(aa64_sha256, s);
13073 case 6: /* SHA256SU1 */
13074 genfn = gen_helper_crypto_sha256su1;
13075 feature = dc_isar_feature(aa64_sha256, s);
13078 unallocated_encoding(s);
13083 unallocated_encoding(s);
13087 if (!fp_access_check(s)) {
13091 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13092 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13093 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13096 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr);
13098 TCGv_i32 tcg_opcode = tcg_const_i32(opcode);
13100 gen_helper_crypto_sha1_3reg(tcg_rd_ptr, tcg_rn_ptr,
13101 tcg_rm_ptr, tcg_opcode);
13102 tcg_temp_free_i32(tcg_opcode);
13105 tcg_temp_free_ptr(tcg_rd_ptr);
13106 tcg_temp_free_ptr(tcg_rn_ptr);
13107 tcg_temp_free_ptr(tcg_rm_ptr);
13110 /* Crypto two-reg SHA
13111 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13112 * +-----------------+------+-----------+--------+-----+------+------+
13113 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13114 * +-----------------+------+-----------+--------+-----+------+------+
13116 static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn)
13118 int size = extract32(insn, 22, 2);
13119 int opcode = extract32(insn, 12, 5);
13120 int rn = extract32(insn, 5, 5);
13121 int rd = extract32(insn, 0, 5);
13122 CryptoTwoOpFn *genfn;
13124 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
13127 unallocated_encoding(s);
13132 case 0: /* SHA1H */
13133 feature = dc_isar_feature(aa64_sha1, s);
13134 genfn = gen_helper_crypto_sha1h;
13136 case 1: /* SHA1SU1 */
13137 feature = dc_isar_feature(aa64_sha1, s);
13138 genfn = gen_helper_crypto_sha1su1;
13140 case 2: /* SHA256SU0 */
13141 feature = dc_isar_feature(aa64_sha256, s);
13142 genfn = gen_helper_crypto_sha256su0;
13145 unallocated_encoding(s);
13150 unallocated_encoding(s);
13154 if (!fp_access_check(s)) {
13158 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13159 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13161 genfn(tcg_rd_ptr, tcg_rn_ptr);
13163 tcg_temp_free_ptr(tcg_rd_ptr);
13164 tcg_temp_free_ptr(tcg_rn_ptr);
13167 /* Crypto three-reg SHA512
13168 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13169 * +-----------------------+------+---+---+-----+--------+------+------+
13170 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
13171 * +-----------------------+------+---+---+-----+--------+------+------+
13173 static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn)
13175 int opcode = extract32(insn, 10, 2);
13176 int o = extract32(insn, 14, 1);
13177 int rm = extract32(insn, 16, 5);
13178 int rn = extract32(insn, 5, 5);
13179 int rd = extract32(insn, 0, 5);
13181 CryptoThreeOpFn *genfn;
13185 case 0: /* SHA512H */
13186 feature = dc_isar_feature(aa64_sha512, s);
13187 genfn = gen_helper_crypto_sha512h;
13189 case 1: /* SHA512H2 */
13190 feature = dc_isar_feature(aa64_sha512, s);
13191 genfn = gen_helper_crypto_sha512h2;
13193 case 2: /* SHA512SU1 */
13194 feature = dc_isar_feature(aa64_sha512, s);
13195 genfn = gen_helper_crypto_sha512su1;
13198 feature = dc_isar_feature(aa64_sha3, s);
13204 case 0: /* SM3PARTW1 */
13205 feature = dc_isar_feature(aa64_sm3, s);
13206 genfn = gen_helper_crypto_sm3partw1;
13208 case 1: /* SM3PARTW2 */
13209 feature = dc_isar_feature(aa64_sm3, s);
13210 genfn = gen_helper_crypto_sm3partw2;
13212 case 2: /* SM4EKEY */
13213 feature = dc_isar_feature(aa64_sm4, s);
13214 genfn = gen_helper_crypto_sm4ekey;
13217 unallocated_encoding(s);
13223 unallocated_encoding(s);
13227 if (!fp_access_check(s)) {
13232 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13234 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13235 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13236 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13238 genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr);
13240 tcg_temp_free_ptr(tcg_rd_ptr);
13241 tcg_temp_free_ptr(tcg_rn_ptr);
13242 tcg_temp_free_ptr(tcg_rm_ptr);
13244 TCGv_i64 tcg_op1, tcg_op2, tcg_res[2];
13247 tcg_op1 = tcg_temp_new_i64();
13248 tcg_op2 = tcg_temp_new_i64();
13249 tcg_res[0] = tcg_temp_new_i64();
13250 tcg_res[1] = tcg_temp_new_i64();
13252 for (pass = 0; pass < 2; pass++) {
13253 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13254 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13256 tcg_gen_rotli_i64(tcg_res[pass], tcg_op2, 1);
13257 tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
13259 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13260 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13262 tcg_temp_free_i64(tcg_op1);
13263 tcg_temp_free_i64(tcg_op2);
13264 tcg_temp_free_i64(tcg_res[0]);
13265 tcg_temp_free_i64(tcg_res[1]);
13269 /* Crypto two-reg SHA512
13270 * 31 12 11 10 9 5 4 0
13271 * +-----------------------------------------+--------+------+------+
13272 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
13273 * +-----------------------------------------+--------+------+------+
13275 static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn)
13277 int opcode = extract32(insn, 10, 2);
13278 int rn = extract32(insn, 5, 5);
13279 int rd = extract32(insn, 0, 5);
13280 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr;
13282 CryptoTwoOpFn *genfn;
13285 case 0: /* SHA512SU0 */
13286 feature = dc_isar_feature(aa64_sha512, s);
13287 genfn = gen_helper_crypto_sha512su0;
13290 feature = dc_isar_feature(aa64_sm4, s);
13291 genfn = gen_helper_crypto_sm4e;
13294 unallocated_encoding(s);
13299 unallocated_encoding(s);
13303 if (!fp_access_check(s)) {
13307 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13308 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13310 genfn(tcg_rd_ptr, tcg_rn_ptr);
13312 tcg_temp_free_ptr(tcg_rd_ptr);
13313 tcg_temp_free_ptr(tcg_rn_ptr);
13316 /* Crypto four-register
13317 * 31 23 22 21 20 16 15 14 10 9 5 4 0
13318 * +-------------------+-----+------+---+------+------+------+
13319 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
13320 * +-------------------+-----+------+---+------+------+------+
13322 static void disas_crypto_four_reg(DisasContext *s, uint32_t insn)
13324 int op0 = extract32(insn, 21, 2);
13325 int rm = extract32(insn, 16, 5);
13326 int ra = extract32(insn, 10, 5);
13327 int rn = extract32(insn, 5, 5);
13328 int rd = extract32(insn, 0, 5);
13334 feature = dc_isar_feature(aa64_sha3, s);
13336 case 2: /* SM3SS1 */
13337 feature = dc_isar_feature(aa64_sm3, s);
13340 unallocated_encoding(s);
13345 unallocated_encoding(s);
13349 if (!fp_access_check(s)) {
13354 TCGv_i64 tcg_op1, tcg_op2, tcg_op3, tcg_res[2];
13357 tcg_op1 = tcg_temp_new_i64();
13358 tcg_op2 = tcg_temp_new_i64();
13359 tcg_op3 = tcg_temp_new_i64();
13360 tcg_res[0] = tcg_temp_new_i64();
13361 tcg_res[1] = tcg_temp_new_i64();
13363 for (pass = 0; pass < 2; pass++) {
13364 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13365 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13366 read_vec_element(s, tcg_op3, ra, pass, MO_64);
13370 tcg_gen_xor_i64(tcg_res[pass], tcg_op2, tcg_op3);
13373 tcg_gen_andc_i64(tcg_res[pass], tcg_op2, tcg_op3);
13375 tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
13377 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13378 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13380 tcg_temp_free_i64(tcg_op1);
13381 tcg_temp_free_i64(tcg_op2);
13382 tcg_temp_free_i64(tcg_op3);
13383 tcg_temp_free_i64(tcg_res[0]);
13384 tcg_temp_free_i64(tcg_res[1]);
13386 TCGv_i32 tcg_op1, tcg_op2, tcg_op3, tcg_res, tcg_zero;
13388 tcg_op1 = tcg_temp_new_i32();
13389 tcg_op2 = tcg_temp_new_i32();
13390 tcg_op3 = tcg_temp_new_i32();
13391 tcg_res = tcg_temp_new_i32();
13392 tcg_zero = tcg_const_i32(0);
13394 read_vec_element_i32(s, tcg_op1, rn, 3, MO_32);
13395 read_vec_element_i32(s, tcg_op2, rm, 3, MO_32);
13396 read_vec_element_i32(s, tcg_op3, ra, 3, MO_32);
13398 tcg_gen_rotri_i32(tcg_res, tcg_op1, 20);
13399 tcg_gen_add_i32(tcg_res, tcg_res, tcg_op2);
13400 tcg_gen_add_i32(tcg_res, tcg_res, tcg_op3);
13401 tcg_gen_rotri_i32(tcg_res, tcg_res, 25);
13403 write_vec_element_i32(s, tcg_zero, rd, 0, MO_32);
13404 write_vec_element_i32(s, tcg_zero, rd, 1, MO_32);
13405 write_vec_element_i32(s, tcg_zero, rd, 2, MO_32);
13406 write_vec_element_i32(s, tcg_res, rd, 3, MO_32);
13408 tcg_temp_free_i32(tcg_op1);
13409 tcg_temp_free_i32(tcg_op2);
13410 tcg_temp_free_i32(tcg_op3);
13411 tcg_temp_free_i32(tcg_res);
13412 tcg_temp_free_i32(tcg_zero);
13417 * 31 21 20 16 15 10 9 5 4 0
13418 * +-----------------------+------+--------+------+------+
13419 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
13420 * +-----------------------+------+--------+------+------+
13422 static void disas_crypto_xar(DisasContext *s, uint32_t insn)
13424 int rm = extract32(insn, 16, 5);
13425 int imm6 = extract32(insn, 10, 6);
13426 int rn = extract32(insn, 5, 5);
13427 int rd = extract32(insn, 0, 5);
13428 TCGv_i64 tcg_op1, tcg_op2, tcg_res[2];
13431 if (!dc_isar_feature(aa64_sha3, s)) {
13432 unallocated_encoding(s);
13436 if (!fp_access_check(s)) {
13440 tcg_op1 = tcg_temp_new_i64();
13441 tcg_op2 = tcg_temp_new_i64();
13442 tcg_res[0] = tcg_temp_new_i64();
13443 tcg_res[1] = tcg_temp_new_i64();
13445 for (pass = 0; pass < 2; pass++) {
13446 read_vec_element(s, tcg_op1, rn, pass, MO_64);
13447 read_vec_element(s, tcg_op2, rm, pass, MO_64);
13449 tcg_gen_xor_i64(tcg_res[pass], tcg_op1, tcg_op2);
13450 tcg_gen_rotri_i64(tcg_res[pass], tcg_res[pass], imm6);
13452 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
13453 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
13455 tcg_temp_free_i64(tcg_op1);
13456 tcg_temp_free_i64(tcg_op2);
13457 tcg_temp_free_i64(tcg_res[0]);
13458 tcg_temp_free_i64(tcg_res[1]);
13461 /* Crypto three-reg imm2
13462 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13463 * +-----------------------+------+-----+------+--------+------+------+
13464 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
13465 * +-----------------------+------+-----+------+--------+------+------+
13467 static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn)
13469 int opcode = extract32(insn, 10, 2);
13470 int imm2 = extract32(insn, 12, 2);
13471 int rm = extract32(insn, 16, 5);
13472 int rn = extract32(insn, 5, 5);
13473 int rd = extract32(insn, 0, 5);
13474 TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr;
13475 TCGv_i32 tcg_imm2, tcg_opcode;
13477 if (!dc_isar_feature(aa64_sm3, s)) {
13478 unallocated_encoding(s);
13482 if (!fp_access_check(s)) {
13486 tcg_rd_ptr = vec_full_reg_ptr(s, rd);
13487 tcg_rn_ptr = vec_full_reg_ptr(s, rn);
13488 tcg_rm_ptr = vec_full_reg_ptr(s, rm);
13489 tcg_imm2 = tcg_const_i32(imm2);
13490 tcg_opcode = tcg_const_i32(opcode);
13492 gen_helper_crypto_sm3tt(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr, tcg_imm2,
13495 tcg_temp_free_ptr(tcg_rd_ptr);
13496 tcg_temp_free_ptr(tcg_rn_ptr);
13497 tcg_temp_free_ptr(tcg_rm_ptr);
13498 tcg_temp_free_i32(tcg_imm2);
13499 tcg_temp_free_i32(tcg_opcode);
13502 /* C3.6 Data processing - SIMD, inc Crypto
13504 * As the decode gets a little complex we are using a table based
13505 * approach for this part of the decode.
13507 static const AArch64DecodeTable data_proc_simd[] = {
13508 /* pattern , mask , fn */
13509 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same },
13510 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra },
13511 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff },
13512 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc },
13513 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes },
13514 { 0x0e000400, 0x9fe08400, disas_simd_copy },
13515 { 0x0f000000, 0x9f000400, disas_simd_indexed }, /* vector indexed */
13516 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
13517 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm },
13518 { 0x0f000400, 0x9f800400, disas_simd_shift_imm },
13519 { 0x0e000000, 0xbf208c00, disas_simd_tb },
13520 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn },
13521 { 0x2e000000, 0xbf208400, disas_simd_ext },
13522 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same },
13523 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra },
13524 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff },
13525 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc },
13526 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise },
13527 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy },
13528 { 0x5f000000, 0xdf000400, disas_simd_indexed }, /* scalar indexed */
13529 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm },
13530 { 0x4e280800, 0xff3e0c00, disas_crypto_aes },
13531 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha },
13532 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha },
13533 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 },
13534 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 },
13535 { 0xce000000, 0xff808000, disas_crypto_four_reg },
13536 { 0xce800000, 0xffe00000, disas_crypto_xar },
13537 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2 },
13538 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16 },
13539 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16 },
13540 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16 },
13541 { 0x00000000, 0x00000000, NULL }
13544 static void disas_data_proc_simd(DisasContext *s, uint32_t insn)
13546 /* Note that this is called with all non-FP cases from
13547 * table C3-6 so it must UNDEF for entries not specifically
13548 * allocated to instructions in that table.
13550 AArch64DecodeFn *fn = lookup_disas_fn(&data_proc_simd[0], insn);
13554 unallocated_encoding(s);
13558 /* C3.6 Data processing - SIMD and floating point */
13559 static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn)
13561 if (extract32(insn, 28, 1) == 1 && extract32(insn, 30, 1) == 0) {
13562 disas_data_proc_fp(s, insn);
13564 /* SIMD, including crypto */
13565 disas_data_proc_simd(s, insn);
13569 /* C3.1 A64 instruction index by encoding */
13570 static void disas_a64_insn(CPUARMState *env, DisasContext *s)
13574 insn = arm_ldl_code(env, s->pc, s->sctlr_b);
13578 s->fp_access_checked = false;
13580 switch (extract32(insn, 25, 4)) {
13581 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
13582 unallocated_encoding(s);
13585 if (!dc_isar_feature(aa64_sve, s) || !disas_sve(s, insn)) {
13586 unallocated_encoding(s);
13589 case 0x8: case 0x9: /* Data processing - immediate */
13590 disas_data_proc_imm(s, insn);
13592 case 0xa: case 0xb: /* Branch, exception generation and system insns */
13593 disas_b_exc_sys(s, insn);
13598 case 0xe: /* Loads and stores */
13599 disas_ldst(s, insn);
13602 case 0xd: /* Data processing - register */
13603 disas_data_proc_reg(s, insn);
13606 case 0xf: /* Data processing - SIMD and floating point */
13607 disas_data_proc_simd_fp(s, insn);
13610 assert(FALSE); /* all 15 cases should be handled above */
13614 /* if we allocated any temporaries, free them here */
13618 static void aarch64_tr_init_disas_context(DisasContextBase *dcbase,
13621 DisasContext *dc = container_of(dcbase, DisasContext, base);
13622 CPUARMState *env = cpu->env_ptr;
13623 ARMCPU *arm_cpu = arm_env_get_cpu(env);
13624 uint32_t tb_flags = dc->base.tb->flags;
13625 int bound, core_mmu_idx;
13627 dc->isar = &arm_cpu->isar;
13628 dc->pc = dc->base.pc_first;
13632 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
13633 * there is no secure EL1, so we route exceptions to EL3.
13635 dc->secure_routed_to_el3 = arm_feature(env, ARM_FEATURE_EL3) &&
13636 !arm_el_is_aa64(env, 3);
13639 dc->be_data = FIELD_EX32(tb_flags, TBFLAG_ANY, BE_DATA) ? MO_BE : MO_LE;
13640 dc->condexec_mask = 0;
13641 dc->condexec_cond = 0;
13642 core_mmu_idx = FIELD_EX32(tb_flags, TBFLAG_ANY, MMUIDX);
13643 dc->mmu_idx = core_to_arm_mmu_idx(env, core_mmu_idx);
13644 dc->tbi0 = FIELD_EX32(tb_flags, TBFLAG_A64, TBI0);
13645 dc->tbi1 = FIELD_EX32(tb_flags, TBFLAG_A64, TBI1);
13646 dc->current_el = arm_mmu_idx_to_el(dc->mmu_idx);
13647 #if !defined(CONFIG_USER_ONLY)
13648 dc->user = (dc->current_el == 0);
13650 dc->fp_excp_el = FIELD_EX32(tb_flags, TBFLAG_ANY, FPEXC_EL);
13651 dc->sve_excp_el = FIELD_EX32(tb_flags, TBFLAG_A64, SVEEXC_EL);
13652 dc->sve_len = (FIELD_EX32(tb_flags, TBFLAG_A64, ZCR_LEN) + 1) * 16;
13653 dc->pauth_active = FIELD_EX32(tb_flags, TBFLAG_A64, PAUTH_ACTIVE);
13655 dc->vec_stride = 0;
13656 dc->cp_regs = arm_cpu->cp_regs;
13657 dc->features = env->features;
13659 /* Single step state. The code-generation logic here is:
13661 * generate code with no special handling for single-stepping (except
13662 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
13663 * this happens anyway because those changes are all system register or
13665 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
13666 * emit code for one insn
13667 * emit code to clear PSTATE.SS
13668 * emit code to generate software step exception for completed step
13669 * end TB (as usual for having generated an exception)
13670 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
13671 * emit code to generate a software step exception
13674 dc->ss_active = FIELD_EX32(tb_flags, TBFLAG_ANY, SS_ACTIVE);
13675 dc->pstate_ss = FIELD_EX32(tb_flags, TBFLAG_ANY, PSTATE_SS);
13676 dc->is_ldex = false;
13677 dc->ss_same_el = (arm_debug_target_el(env) == dc->current_el);
13679 /* Bound the number of insns to execute to those left on the page. */
13680 bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
13682 /* If architectural single step active, limit to 1. */
13683 if (dc->ss_active) {
13686 dc->base.max_insns = MIN(dc->base.max_insns, bound);
13688 init_tmp_a64_array(dc);
13691 static void aarch64_tr_tb_start(DisasContextBase *db, CPUState *cpu)
13695 static void aarch64_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
13697 DisasContext *dc = container_of(dcbase, DisasContext, base);
13699 tcg_gen_insn_start(dc->pc, 0, 0);
13700 dc->insn_start = tcg_last_op();
13703 static bool aarch64_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cpu,
13704 const CPUBreakpoint *bp)
13706 DisasContext *dc = container_of(dcbase, DisasContext, base);
13708 if (bp->flags & BP_CPU) {
13709 gen_a64_set_pc_im(dc->pc);
13710 gen_helper_check_breakpoints(cpu_env);
13711 /* End the TB early; it likely won't be executed */
13712 dc->base.is_jmp = DISAS_TOO_MANY;
13714 gen_exception_internal_insn(dc, 0, EXCP_DEBUG);
13715 /* The address covered by the breakpoint must be
13716 included in [tb->pc, tb->pc + tb->size) in order
13717 to for it to be properly cleared -- thus we
13718 increment the PC here so that the logic setting
13719 tb->size below does the right thing. */
13721 dc->base.is_jmp = DISAS_NORETURN;
13727 static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
13729 DisasContext *dc = container_of(dcbase, DisasContext, base);
13730 CPUARMState *env = cpu->env_ptr;
13732 if (dc->ss_active && !dc->pstate_ss) {
13733 /* Singlestep state is Active-pending.
13734 * If we're in this state at the start of a TB then either
13735 * a) we just took an exception to an EL which is being debugged
13736 * and this is the first insn in the exception handler
13737 * b) debug exceptions were masked and we just unmasked them
13738 * without changing EL (eg by clearing PSTATE.D)
13739 * In either case we're going to take a swstep exception in the
13740 * "did not step an insn" case, and so the syndrome ISV and EX
13741 * bits should be zero.
13743 assert(dc->base.num_insns == 1);
13744 gen_exception(EXCP_UDEF, syn_swstep(dc->ss_same_el, 0, 0),
13745 default_exception_el(dc));
13746 dc->base.is_jmp = DISAS_NORETURN;
13748 disas_a64_insn(env, dc);
13751 dc->base.pc_next = dc->pc;
13752 translator_loop_temp_check(&dc->base);
13755 static void aarch64_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
13757 DisasContext *dc = container_of(dcbase, DisasContext, base);
13759 if (unlikely(dc->base.singlestep_enabled || dc->ss_active)) {
13760 /* Note that this means single stepping WFI doesn't halt the CPU.
13761 * For conditional branch insns this is harmless unreachable code as
13762 * gen_goto_tb() has already handled emitting the debug exception
13763 * (and thus a tb-jump is not possible when singlestepping).
13765 switch (dc->base.is_jmp) {
13767 gen_a64_set_pc_im(dc->pc);
13771 if (dc->base.singlestep_enabled) {
13772 gen_exception_internal(EXCP_DEBUG);
13774 gen_step_complete_exception(dc);
13777 case DISAS_NORETURN:
13781 switch (dc->base.is_jmp) {
13783 case DISAS_TOO_MANY:
13784 gen_goto_tb(dc, 1, dc->pc);
13788 gen_a64_set_pc_im(dc->pc);
13791 tcg_gen_exit_tb(NULL, 0);
13794 tcg_gen_lookup_and_goto_ptr();
13796 case DISAS_NORETURN:
13800 gen_a64_set_pc_im(dc->pc);
13801 gen_helper_wfe(cpu_env);
13804 gen_a64_set_pc_im(dc->pc);
13805 gen_helper_yield(cpu_env);
13809 /* This is a special case because we don't want to just halt the CPU
13810 * if trying to debug across a WFI.
13812 TCGv_i32 tmp = tcg_const_i32(4);
13814 gen_a64_set_pc_im(dc->pc);
13815 gen_helper_wfi(cpu_env, tmp);
13816 tcg_temp_free_i32(tmp);
13817 /* The helper doesn't necessarily throw an exception, but we
13818 * must go back to the main loop to check for interrupts anyway.
13820 tcg_gen_exit_tb(NULL, 0);
13826 /* Functions above can change dc->pc, so re-align db->pc_next */
13827 dc->base.pc_next = dc->pc;
13830 static void aarch64_tr_disas_log(const DisasContextBase *dcbase,
13833 DisasContext *dc = container_of(dcbase, DisasContext, base);
13835 qemu_log("IN: %s\n", lookup_symbol(dc->base.pc_first));
13836 log_target_disas(cpu, dc->base.pc_first, dc->base.tb->size);
13839 const TranslatorOps aarch64_translator_ops = {
13840 .init_disas_context = aarch64_tr_init_disas_context,
13841 .tb_start = aarch64_tr_tb_start,
13842 .insn_start = aarch64_tr_insn_start,
13843 .breakpoint_check = aarch64_tr_breakpoint_check,
13844 .translate_insn = aarch64_tr_translate_insn,
13845 .tb_stop = aarch64_tr_tb_stop,
13846 .disas_log = aarch64_tr_disas_log,