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/>.
28 #include "translate.h"
29 #include "internals.h"
30 #include "qemu/host-utils.h"
32 #include "exec/gen-icount.h"
38 static TCGv_i64 cpu_X[32];
39 static TCGv_i64 cpu_pc;
40 static TCGv_i32 cpu_NF, cpu_ZF, cpu_CF, cpu_VF;
42 /* Load/store exclusive handling */
43 static TCGv_i64 cpu_exclusive_addr;
44 static TCGv_i64 cpu_exclusive_val;
45 static TCGv_i64 cpu_exclusive_high;
46 #ifdef CONFIG_USER_ONLY
47 static TCGv_i64 cpu_exclusive_test;
48 static TCGv_i32 cpu_exclusive_info;
51 static const char *regnames[] = {
52 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
53 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
54 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
55 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
59 A64_SHIFT_TYPE_LSL = 0,
60 A64_SHIFT_TYPE_LSR = 1,
61 A64_SHIFT_TYPE_ASR = 2,
62 A64_SHIFT_TYPE_ROR = 3
65 /* Table based decoder typedefs - used when the relevant bits for decode
66 * are too awkwardly scattered across the instruction (eg SIMD).
68 typedef void AArch64DecodeFn(DisasContext *s, uint32_t insn);
70 typedef struct AArch64DecodeTable {
73 AArch64DecodeFn *disas_fn;
76 /* Function prototype for gen_ functions for calling Neon helpers */
77 typedef void NeonGenOneOpEnvFn(TCGv_i32, TCGv_ptr, TCGv_i32);
78 typedef void NeonGenTwoOpFn(TCGv_i32, TCGv_i32, TCGv_i32);
79 typedef void NeonGenTwoOpEnvFn(TCGv_i32, TCGv_ptr, TCGv_i32, TCGv_i32);
80 typedef void NeonGenTwo64OpFn(TCGv_i64, TCGv_i64, TCGv_i64);
81 typedef void NeonGenTwo64OpEnvFn(TCGv_i64, TCGv_ptr, TCGv_i64, TCGv_i64);
82 typedef void NeonGenNarrowFn(TCGv_i32, TCGv_i64);
83 typedef void NeonGenNarrowEnvFn(TCGv_i32, TCGv_ptr, TCGv_i64);
84 typedef void NeonGenWidenFn(TCGv_i64, TCGv_i32);
85 typedef void NeonGenTwoSingleOPFn(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_ptr);
86 typedef void NeonGenTwoDoubleOPFn(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_ptr);
87 typedef void NeonGenOneOpFn(TCGv_i64, TCGv_i64);
89 /* initialize TCG globals. */
90 void a64_translate_init(void)
94 cpu_pc = tcg_global_mem_new_i64(TCG_AREG0,
95 offsetof(CPUARMState, pc),
97 for (i = 0; i < 32; i++) {
98 cpu_X[i] = tcg_global_mem_new_i64(TCG_AREG0,
99 offsetof(CPUARMState, xregs[i]),
103 cpu_NF = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUARMState, NF), "NF");
104 cpu_ZF = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUARMState, ZF), "ZF");
105 cpu_CF = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUARMState, CF), "CF");
106 cpu_VF = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUARMState, VF), "VF");
108 cpu_exclusive_addr = tcg_global_mem_new_i64(TCG_AREG0,
109 offsetof(CPUARMState, exclusive_addr), "exclusive_addr");
110 cpu_exclusive_val = tcg_global_mem_new_i64(TCG_AREG0,
111 offsetof(CPUARMState, exclusive_val), "exclusive_val");
112 cpu_exclusive_high = tcg_global_mem_new_i64(TCG_AREG0,
113 offsetof(CPUARMState, exclusive_high), "exclusive_high");
114 #ifdef CONFIG_USER_ONLY
115 cpu_exclusive_test = tcg_global_mem_new_i64(TCG_AREG0,
116 offsetof(CPUARMState, exclusive_test), "exclusive_test");
117 cpu_exclusive_info = tcg_global_mem_new_i32(TCG_AREG0,
118 offsetof(CPUARMState, exclusive_info), "exclusive_info");
122 void aarch64_cpu_dump_state(CPUState *cs, FILE *f,
123 fprintf_function cpu_fprintf, int flags)
125 ARMCPU *cpu = ARM_CPU(cs);
126 CPUARMState *env = &cpu->env;
127 uint32_t psr = pstate_read(env);
130 cpu_fprintf(f, "PC=%016"PRIx64" SP=%016"PRIx64"\n",
131 env->pc, env->xregs[31]);
132 for (i = 0; i < 31; i++) {
133 cpu_fprintf(f, "X%02d=%016"PRIx64, i, env->xregs[i]);
135 cpu_fprintf(f, "\n");
140 cpu_fprintf(f, "PSTATE=%08x (flags %c%c%c%c)\n",
142 psr & PSTATE_N ? 'N' : '-',
143 psr & PSTATE_Z ? 'Z' : '-',
144 psr & PSTATE_C ? 'C' : '-',
145 psr & PSTATE_V ? 'V' : '-');
146 cpu_fprintf(f, "\n");
148 if (flags & CPU_DUMP_FPU) {
150 for (i = 0; i < numvfpregs; i += 2) {
151 uint64_t vlo = float64_val(env->vfp.regs[i * 2]);
152 uint64_t vhi = float64_val(env->vfp.regs[(i * 2) + 1]);
153 cpu_fprintf(f, "q%02d=%016" PRIx64 ":%016" PRIx64 " ",
155 vlo = float64_val(env->vfp.regs[(i + 1) * 2]);
156 vhi = float64_val(env->vfp.regs[((i + 1) * 2) + 1]);
157 cpu_fprintf(f, "q%02d=%016" PRIx64 ":%016" PRIx64 "\n",
160 cpu_fprintf(f, "FPCR: %08x FPSR: %08x\n",
161 vfp_get_fpcr(env), vfp_get_fpsr(env));
165 static int get_mem_index(DisasContext *s)
167 #ifdef CONFIG_USER_ONLY
174 void gen_a64_set_pc_im(uint64_t val)
176 tcg_gen_movi_i64(cpu_pc, val);
179 static void gen_exception(int excp)
181 TCGv_i32 tmp = tcg_temp_new_i32();
182 tcg_gen_movi_i32(tmp, excp);
183 gen_helper_exception(cpu_env, tmp);
184 tcg_temp_free_i32(tmp);
187 static void gen_exception_insn(DisasContext *s, int offset, int excp)
189 gen_a64_set_pc_im(s->pc - offset);
191 s->is_jmp = DISAS_EXC;
194 static inline bool use_goto_tb(DisasContext *s, int n, uint64_t dest)
196 /* No direct tb linking with singlestep or deterministic io */
197 if (s->singlestep_enabled || (s->tb->cflags & CF_LAST_IO)) {
201 /* Only link tbs from inside the same guest page */
202 if ((s->tb->pc & TARGET_PAGE_MASK) != (dest & TARGET_PAGE_MASK)) {
209 static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)
211 TranslationBlock *tb;
214 if (use_goto_tb(s, n, dest)) {
216 gen_a64_set_pc_im(dest);
217 tcg_gen_exit_tb((intptr_t)tb + n);
218 s->is_jmp = DISAS_TB_JUMP;
220 gen_a64_set_pc_im(dest);
221 if (s->singlestep_enabled) {
222 gen_exception(EXCP_DEBUG);
225 s->is_jmp = DISAS_JUMP;
229 static void unallocated_encoding(DisasContext *s)
231 gen_exception_insn(s, 4, EXCP_UDEF);
234 #define unsupported_encoding(s, insn) \
236 qemu_log_mask(LOG_UNIMP, \
237 "%s:%d: unsupported instruction encoding 0x%08x " \
238 "at pc=%016" PRIx64 "\n", \
239 __FILE__, __LINE__, insn, s->pc - 4); \
240 unallocated_encoding(s); \
243 static void init_tmp_a64_array(DisasContext *s)
245 #ifdef CONFIG_DEBUG_TCG
247 for (i = 0; i < ARRAY_SIZE(s->tmp_a64); i++) {
248 TCGV_UNUSED_I64(s->tmp_a64[i]);
251 s->tmp_a64_count = 0;
254 static void free_tmp_a64(DisasContext *s)
257 for (i = 0; i < s->tmp_a64_count; i++) {
258 tcg_temp_free_i64(s->tmp_a64[i]);
260 init_tmp_a64_array(s);
263 static TCGv_i64 new_tmp_a64(DisasContext *s)
265 assert(s->tmp_a64_count < TMP_A64_MAX);
266 return s->tmp_a64[s->tmp_a64_count++] = tcg_temp_new_i64();
269 static TCGv_i64 new_tmp_a64_zero(DisasContext *s)
271 TCGv_i64 t = new_tmp_a64(s);
272 tcg_gen_movi_i64(t, 0);
277 * Register access functions
279 * These functions are used for directly accessing a register in where
280 * changes to the final register value are likely to be made. If you
281 * need to use a register for temporary calculation (e.g. index type
282 * operations) use the read_* form.
284 * B1.2.1 Register mappings
286 * In instruction register encoding 31 can refer to ZR (zero register) or
287 * the SP (stack pointer) depending on context. In QEMU's case we map SP
288 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
289 * This is the point of the _sp forms.
291 static TCGv_i64 cpu_reg(DisasContext *s, int reg)
294 return new_tmp_a64_zero(s);
300 /* register access for when 31 == SP */
301 static TCGv_i64 cpu_reg_sp(DisasContext *s, int reg)
306 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
307 * representing the register contents. This TCGv is an auto-freed
308 * temporary so it need not be explicitly freed, and may be modified.
310 static TCGv_i64 read_cpu_reg(DisasContext *s, int reg, int sf)
312 TCGv_i64 v = new_tmp_a64(s);
315 tcg_gen_mov_i64(v, cpu_X[reg]);
317 tcg_gen_ext32u_i64(v, cpu_X[reg]);
320 tcg_gen_movi_i64(v, 0);
325 static TCGv_i64 read_cpu_reg_sp(DisasContext *s, int reg, int sf)
327 TCGv_i64 v = new_tmp_a64(s);
329 tcg_gen_mov_i64(v, cpu_X[reg]);
331 tcg_gen_ext32u_i64(v, cpu_X[reg]);
336 /* Return the offset into CPUARMState of an element of specified
337 * size, 'element' places in from the least significant end of
338 * the FP/vector register Qn.
340 static inline int vec_reg_offset(int regno, int element, TCGMemOp size)
342 int offs = offsetof(CPUARMState, vfp.regs[regno * 2]);
343 #ifdef HOST_WORDS_BIGENDIAN
344 /* This is complicated slightly because vfp.regs[2n] is
345 * still the low half and vfp.regs[2n+1] the high half
346 * of the 128 bit vector, even on big endian systems.
347 * Calculate the offset assuming a fully bigendian 128 bits,
348 * then XOR to account for the order of the two 64 bit halves.
350 offs += (16 - ((element + 1) * (1 << size)));
353 offs += element * (1 << size);
358 /* Return the offset into CPUARMState of a slice (from
359 * the least significant end) of FP register Qn (ie
361 * (Note that this is not the same mapping as for A32; see cpu.h)
363 static inline int fp_reg_offset(int regno, TCGMemOp size)
365 int offs = offsetof(CPUARMState, vfp.regs[regno * 2]);
366 #ifdef HOST_WORDS_BIGENDIAN
367 offs += (8 - (1 << size));
372 /* Offset of the high half of the 128 bit vector Qn */
373 static inline int fp_reg_hi_offset(int regno)
375 return offsetof(CPUARMState, vfp.regs[regno * 2 + 1]);
378 /* Convenience accessors for reading and writing single and double
379 * FP registers. Writing clears the upper parts of the associated
380 * 128 bit vector register, as required by the architecture.
381 * Note that unlike the GP register accessors, the values returned
382 * by the read functions must be manually freed.
384 static TCGv_i64 read_fp_dreg(DisasContext *s, int reg)
386 TCGv_i64 v = tcg_temp_new_i64();
388 tcg_gen_ld_i64(v, cpu_env, fp_reg_offset(reg, MO_64));
392 static TCGv_i32 read_fp_sreg(DisasContext *s, int reg)
394 TCGv_i32 v = tcg_temp_new_i32();
396 tcg_gen_ld_i32(v, cpu_env, fp_reg_offset(reg, MO_32));
400 static void write_fp_dreg(DisasContext *s, int reg, TCGv_i64 v)
402 TCGv_i64 tcg_zero = tcg_const_i64(0);
404 tcg_gen_st_i64(v, cpu_env, fp_reg_offset(reg, MO_64));
405 tcg_gen_st_i64(tcg_zero, cpu_env, fp_reg_hi_offset(reg));
406 tcg_temp_free_i64(tcg_zero);
409 static void write_fp_sreg(DisasContext *s, int reg, TCGv_i32 v)
411 TCGv_i64 tmp = tcg_temp_new_i64();
413 tcg_gen_extu_i32_i64(tmp, v);
414 write_fp_dreg(s, reg, tmp);
415 tcg_temp_free_i64(tmp);
418 static TCGv_ptr get_fpstatus_ptr(void)
420 TCGv_ptr statusptr = tcg_temp_new_ptr();
423 /* In A64 all instructions (both FP and Neon) use the FPCR;
424 * there is no equivalent of the A32 Neon "standard FPSCR value"
425 * and all operations use vfp.fp_status.
427 offset = offsetof(CPUARMState, vfp.fp_status);
428 tcg_gen_addi_ptr(statusptr, cpu_env, offset);
432 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
433 * than the 32 bit equivalent.
435 static inline void gen_set_NZ64(TCGv_i64 result)
437 TCGv_i64 flag = tcg_temp_new_i64();
439 tcg_gen_setcondi_i64(TCG_COND_NE, flag, result, 0);
440 tcg_gen_trunc_i64_i32(cpu_ZF, flag);
441 tcg_gen_shri_i64(flag, result, 32);
442 tcg_gen_trunc_i64_i32(cpu_NF, flag);
443 tcg_temp_free_i64(flag);
446 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
447 static inline void gen_logic_CC(int sf, TCGv_i64 result)
450 gen_set_NZ64(result);
452 tcg_gen_trunc_i64_i32(cpu_ZF, result);
453 tcg_gen_trunc_i64_i32(cpu_NF, result);
455 tcg_gen_movi_i32(cpu_CF, 0);
456 tcg_gen_movi_i32(cpu_VF, 0);
459 /* dest = T0 + T1; compute C, N, V and Z flags */
460 static void gen_add_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
463 TCGv_i64 result, flag, tmp;
464 result = tcg_temp_new_i64();
465 flag = tcg_temp_new_i64();
466 tmp = tcg_temp_new_i64();
468 tcg_gen_movi_i64(tmp, 0);
469 tcg_gen_add2_i64(result, flag, t0, tmp, t1, tmp);
471 tcg_gen_trunc_i64_i32(cpu_CF, flag);
473 gen_set_NZ64(result);
475 tcg_gen_xor_i64(flag, result, t0);
476 tcg_gen_xor_i64(tmp, t0, t1);
477 tcg_gen_andc_i64(flag, flag, tmp);
478 tcg_temp_free_i64(tmp);
479 tcg_gen_shri_i64(flag, flag, 32);
480 tcg_gen_trunc_i64_i32(cpu_VF, flag);
482 tcg_gen_mov_i64(dest, result);
483 tcg_temp_free_i64(result);
484 tcg_temp_free_i64(flag);
486 /* 32 bit arithmetic */
487 TCGv_i32 t0_32 = tcg_temp_new_i32();
488 TCGv_i32 t1_32 = tcg_temp_new_i32();
489 TCGv_i32 tmp = tcg_temp_new_i32();
491 tcg_gen_movi_i32(tmp, 0);
492 tcg_gen_trunc_i64_i32(t0_32, t0);
493 tcg_gen_trunc_i64_i32(t1_32, t1);
494 tcg_gen_add2_i32(cpu_NF, cpu_CF, t0_32, tmp, t1_32, tmp);
495 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
496 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
497 tcg_gen_xor_i32(tmp, t0_32, t1_32);
498 tcg_gen_andc_i32(cpu_VF, cpu_VF, tmp);
499 tcg_gen_extu_i32_i64(dest, cpu_NF);
501 tcg_temp_free_i32(tmp);
502 tcg_temp_free_i32(t0_32);
503 tcg_temp_free_i32(t1_32);
507 /* dest = T0 - T1; compute C, N, V and Z flags */
508 static void gen_sub_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
511 /* 64 bit arithmetic */
512 TCGv_i64 result, flag, tmp;
514 result = tcg_temp_new_i64();
515 flag = tcg_temp_new_i64();
516 tcg_gen_sub_i64(result, t0, t1);
518 gen_set_NZ64(result);
520 tcg_gen_setcond_i64(TCG_COND_GEU, flag, t0, t1);
521 tcg_gen_trunc_i64_i32(cpu_CF, flag);
523 tcg_gen_xor_i64(flag, result, t0);
524 tmp = tcg_temp_new_i64();
525 tcg_gen_xor_i64(tmp, t0, t1);
526 tcg_gen_and_i64(flag, flag, tmp);
527 tcg_temp_free_i64(tmp);
528 tcg_gen_shri_i64(flag, flag, 32);
529 tcg_gen_trunc_i64_i32(cpu_VF, flag);
530 tcg_gen_mov_i64(dest, result);
531 tcg_temp_free_i64(flag);
532 tcg_temp_free_i64(result);
534 /* 32 bit arithmetic */
535 TCGv_i32 t0_32 = tcg_temp_new_i32();
536 TCGv_i32 t1_32 = tcg_temp_new_i32();
539 tcg_gen_trunc_i64_i32(t0_32, t0);
540 tcg_gen_trunc_i64_i32(t1_32, t1);
541 tcg_gen_sub_i32(cpu_NF, t0_32, t1_32);
542 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
543 tcg_gen_setcond_i32(TCG_COND_GEU, cpu_CF, t0_32, t1_32);
544 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
545 tmp = tcg_temp_new_i32();
546 tcg_gen_xor_i32(tmp, t0_32, t1_32);
547 tcg_temp_free_i32(t0_32);
548 tcg_temp_free_i32(t1_32);
549 tcg_gen_and_i32(cpu_VF, cpu_VF, tmp);
550 tcg_temp_free_i32(tmp);
551 tcg_gen_extu_i32_i64(dest, cpu_NF);
555 /* dest = T0 + T1 + CF; do not compute flags. */
556 static void gen_adc(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
558 TCGv_i64 flag = tcg_temp_new_i64();
559 tcg_gen_extu_i32_i64(flag, cpu_CF);
560 tcg_gen_add_i64(dest, t0, t1);
561 tcg_gen_add_i64(dest, dest, flag);
562 tcg_temp_free_i64(flag);
565 tcg_gen_ext32u_i64(dest, dest);
569 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
570 static void gen_adc_CC(int sf, TCGv_i64 dest, TCGv_i64 t0, TCGv_i64 t1)
573 TCGv_i64 result, cf_64, vf_64, tmp;
574 result = tcg_temp_new_i64();
575 cf_64 = tcg_temp_new_i64();
576 vf_64 = tcg_temp_new_i64();
577 tmp = tcg_const_i64(0);
579 tcg_gen_extu_i32_i64(cf_64, cpu_CF);
580 tcg_gen_add2_i64(result, cf_64, t0, tmp, cf_64, tmp);
581 tcg_gen_add2_i64(result, cf_64, result, cf_64, t1, tmp);
582 tcg_gen_trunc_i64_i32(cpu_CF, cf_64);
583 gen_set_NZ64(result);
585 tcg_gen_xor_i64(vf_64, result, t0);
586 tcg_gen_xor_i64(tmp, t0, t1);
587 tcg_gen_andc_i64(vf_64, vf_64, tmp);
588 tcg_gen_shri_i64(vf_64, vf_64, 32);
589 tcg_gen_trunc_i64_i32(cpu_VF, vf_64);
591 tcg_gen_mov_i64(dest, result);
593 tcg_temp_free_i64(tmp);
594 tcg_temp_free_i64(vf_64);
595 tcg_temp_free_i64(cf_64);
596 tcg_temp_free_i64(result);
598 TCGv_i32 t0_32, t1_32, tmp;
599 t0_32 = tcg_temp_new_i32();
600 t1_32 = tcg_temp_new_i32();
601 tmp = tcg_const_i32(0);
603 tcg_gen_trunc_i64_i32(t0_32, t0);
604 tcg_gen_trunc_i64_i32(t1_32, t1);
605 tcg_gen_add2_i32(cpu_NF, cpu_CF, t0_32, tmp, cpu_CF, tmp);
606 tcg_gen_add2_i32(cpu_NF, cpu_CF, cpu_NF, cpu_CF, t1_32, tmp);
608 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
609 tcg_gen_xor_i32(cpu_VF, cpu_NF, t0_32);
610 tcg_gen_xor_i32(tmp, t0_32, t1_32);
611 tcg_gen_andc_i32(cpu_VF, cpu_VF, tmp);
612 tcg_gen_extu_i32_i64(dest, cpu_NF);
614 tcg_temp_free_i32(tmp);
615 tcg_temp_free_i32(t1_32);
616 tcg_temp_free_i32(t0_32);
621 * Load/Store generators
625 * Store from GPR register to memory.
627 static void do_gpr_st_memidx(DisasContext *s, TCGv_i64 source,
628 TCGv_i64 tcg_addr, int size, int memidx)
631 tcg_gen_qemu_st_i64(source, tcg_addr, memidx, MO_TE + size);
634 static void do_gpr_st(DisasContext *s, TCGv_i64 source,
635 TCGv_i64 tcg_addr, int size)
637 do_gpr_st_memidx(s, source, tcg_addr, size, get_mem_index(s));
641 * Load from memory to GPR register
643 static void do_gpr_ld_memidx(DisasContext *s, TCGv_i64 dest, TCGv_i64 tcg_addr,
644 int size, bool is_signed, bool extend, int memidx)
646 TCGMemOp memop = MO_TE + size;
654 tcg_gen_qemu_ld_i64(dest, tcg_addr, memidx, memop);
656 if (extend && is_signed) {
658 tcg_gen_ext32u_i64(dest, dest);
662 static void do_gpr_ld(DisasContext *s, TCGv_i64 dest, TCGv_i64 tcg_addr,
663 int size, bool is_signed, bool extend)
665 do_gpr_ld_memidx(s, dest, tcg_addr, size, is_signed, extend,
670 * Store from FP register to memory
672 static void do_fp_st(DisasContext *s, int srcidx, TCGv_i64 tcg_addr, int size)
674 /* This writes the bottom N bits of a 128 bit wide vector to memory */
675 TCGv_i64 tmp = tcg_temp_new_i64();
676 tcg_gen_ld_i64(tmp, cpu_env, fp_reg_offset(srcidx, MO_64));
678 tcg_gen_qemu_st_i64(tmp, tcg_addr, get_mem_index(s), MO_TE + size);
680 TCGv_i64 tcg_hiaddr = tcg_temp_new_i64();
681 tcg_gen_qemu_st_i64(tmp, tcg_addr, get_mem_index(s), MO_TEQ);
682 tcg_gen_qemu_st64(tmp, tcg_addr, get_mem_index(s));
683 tcg_gen_ld_i64(tmp, cpu_env, fp_reg_hi_offset(srcidx));
684 tcg_gen_addi_i64(tcg_hiaddr, tcg_addr, 8);
685 tcg_gen_qemu_st_i64(tmp, tcg_hiaddr, get_mem_index(s), MO_TEQ);
686 tcg_temp_free_i64(tcg_hiaddr);
689 tcg_temp_free_i64(tmp);
693 * Load from memory to FP register
695 static void do_fp_ld(DisasContext *s, int destidx, TCGv_i64 tcg_addr, int size)
697 /* This always zero-extends and writes to a full 128 bit wide vector */
698 TCGv_i64 tmplo = tcg_temp_new_i64();
702 TCGMemOp memop = MO_TE + size;
703 tmphi = tcg_const_i64(0);
704 tcg_gen_qemu_ld_i64(tmplo, tcg_addr, get_mem_index(s), memop);
707 tmphi = tcg_temp_new_i64();
708 tcg_hiaddr = tcg_temp_new_i64();
710 tcg_gen_qemu_ld_i64(tmplo, tcg_addr, get_mem_index(s), MO_TEQ);
711 tcg_gen_addi_i64(tcg_hiaddr, tcg_addr, 8);
712 tcg_gen_qemu_ld_i64(tmphi, tcg_hiaddr, get_mem_index(s), MO_TEQ);
713 tcg_temp_free_i64(tcg_hiaddr);
716 tcg_gen_st_i64(tmplo, cpu_env, fp_reg_offset(destidx, MO_64));
717 tcg_gen_st_i64(tmphi, cpu_env, fp_reg_hi_offset(destidx));
719 tcg_temp_free_i64(tmplo);
720 tcg_temp_free_i64(tmphi);
724 * Vector load/store helpers.
726 * The principal difference between this and a FP load is that we don't
727 * zero extend as we are filling a partial chunk of the vector register.
728 * These functions don't support 128 bit loads/stores, which would be
729 * normal load/store operations.
731 * The _i32 versions are useful when operating on 32 bit quantities
732 * (eg for floating point single or using Neon helper functions).
735 /* Get value of an element within a vector register */
736 static void read_vec_element(DisasContext *s, TCGv_i64 tcg_dest, int srcidx,
737 int element, TCGMemOp memop)
739 int vect_off = vec_reg_offset(srcidx, element, memop & MO_SIZE);
742 tcg_gen_ld8u_i64(tcg_dest, cpu_env, vect_off);
745 tcg_gen_ld16u_i64(tcg_dest, cpu_env, vect_off);
748 tcg_gen_ld32u_i64(tcg_dest, cpu_env, vect_off);
751 tcg_gen_ld8s_i64(tcg_dest, cpu_env, vect_off);
754 tcg_gen_ld16s_i64(tcg_dest, cpu_env, vect_off);
757 tcg_gen_ld32s_i64(tcg_dest, cpu_env, vect_off);
761 tcg_gen_ld_i64(tcg_dest, cpu_env, vect_off);
764 g_assert_not_reached();
768 static void read_vec_element_i32(DisasContext *s, TCGv_i32 tcg_dest, int srcidx,
769 int element, TCGMemOp memop)
771 int vect_off = vec_reg_offset(srcidx, element, memop & MO_SIZE);
774 tcg_gen_ld8u_i32(tcg_dest, cpu_env, vect_off);
777 tcg_gen_ld16u_i32(tcg_dest, cpu_env, vect_off);
780 tcg_gen_ld8s_i32(tcg_dest, cpu_env, vect_off);
783 tcg_gen_ld16s_i32(tcg_dest, cpu_env, vect_off);
787 tcg_gen_ld_i32(tcg_dest, cpu_env, vect_off);
790 g_assert_not_reached();
794 /* Set value of an element within a vector register */
795 static void write_vec_element(DisasContext *s, TCGv_i64 tcg_src, int destidx,
796 int element, TCGMemOp memop)
798 int vect_off = vec_reg_offset(destidx, element, memop & MO_SIZE);
801 tcg_gen_st8_i64(tcg_src, cpu_env, vect_off);
804 tcg_gen_st16_i64(tcg_src, cpu_env, vect_off);
807 tcg_gen_st32_i64(tcg_src, cpu_env, vect_off);
810 tcg_gen_st_i64(tcg_src, cpu_env, vect_off);
813 g_assert_not_reached();
817 static void write_vec_element_i32(DisasContext *s, TCGv_i32 tcg_src,
818 int destidx, int element, TCGMemOp memop)
820 int vect_off = vec_reg_offset(destidx, element, memop & MO_SIZE);
823 tcg_gen_st8_i32(tcg_src, cpu_env, vect_off);
826 tcg_gen_st16_i32(tcg_src, cpu_env, vect_off);
829 tcg_gen_st_i32(tcg_src, cpu_env, vect_off);
832 g_assert_not_reached();
836 /* Clear the high 64 bits of a 128 bit vector (in general non-quad
837 * vector ops all need to do this).
839 static void clear_vec_high(DisasContext *s, int rd)
841 TCGv_i64 tcg_zero = tcg_const_i64(0);
843 write_vec_element(s, tcg_zero, rd, 1, MO_64);
844 tcg_temp_free_i64(tcg_zero);
847 /* Store from vector register to memory */
848 static void do_vec_st(DisasContext *s, int srcidx, int element,
849 TCGv_i64 tcg_addr, int size)
851 TCGMemOp memop = MO_TE + size;
852 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
854 read_vec_element(s, tcg_tmp, srcidx, element, size);
855 tcg_gen_qemu_st_i64(tcg_tmp, tcg_addr, get_mem_index(s), memop);
857 tcg_temp_free_i64(tcg_tmp);
860 /* Load from memory to vector register */
861 static void do_vec_ld(DisasContext *s, int destidx, int element,
862 TCGv_i64 tcg_addr, int size)
864 TCGMemOp memop = MO_TE + size;
865 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
867 tcg_gen_qemu_ld_i64(tcg_tmp, tcg_addr, get_mem_index(s), memop);
868 write_vec_element(s, tcg_tmp, destidx, element, size);
870 tcg_temp_free_i64(tcg_tmp);
874 * This utility function is for doing register extension with an
875 * optional shift. You will likely want to pass a temporary for the
876 * destination register. See DecodeRegExtend() in the ARM ARM.
878 static void ext_and_shift_reg(TCGv_i64 tcg_out, TCGv_i64 tcg_in,
879 int option, unsigned int shift)
881 int extsize = extract32(option, 0, 2);
882 bool is_signed = extract32(option, 2, 1);
887 tcg_gen_ext8s_i64(tcg_out, tcg_in);
890 tcg_gen_ext16s_i64(tcg_out, tcg_in);
893 tcg_gen_ext32s_i64(tcg_out, tcg_in);
896 tcg_gen_mov_i64(tcg_out, tcg_in);
902 tcg_gen_ext8u_i64(tcg_out, tcg_in);
905 tcg_gen_ext16u_i64(tcg_out, tcg_in);
908 tcg_gen_ext32u_i64(tcg_out, tcg_in);
911 tcg_gen_mov_i64(tcg_out, tcg_in);
917 tcg_gen_shli_i64(tcg_out, tcg_out, shift);
921 static inline void gen_check_sp_alignment(DisasContext *s)
923 /* The AArch64 architecture mandates that (if enabled via PSTATE
924 * or SCTLR bits) there is a check that SP is 16-aligned on every
925 * SP-relative load or store (with an exception generated if it is not).
926 * In line with general QEMU practice regarding misaligned accesses,
927 * we omit these checks for the sake of guest program performance.
928 * This function is provided as a hook so we can more easily add these
929 * checks in future (possibly as a "favour catching guest program bugs
930 * over speed" user selectable option).
935 * This provides a simple table based table lookup decoder. It is
936 * intended to be used when the relevant bits for decode are too
937 * awkwardly placed and switch/if based logic would be confusing and
938 * deeply nested. Since it's a linear search through the table, tables
939 * should be kept small.
941 * It returns the first handler where insn & mask == pattern, or
942 * NULL if there is no match.
943 * The table is terminated by an empty mask (i.e. 0)
945 static inline AArch64DecodeFn *lookup_disas_fn(const AArch64DecodeTable *table,
948 const AArch64DecodeTable *tptr = table;
951 if ((insn & tptr->mask) == tptr->pattern) {
952 return tptr->disas_fn;
960 * the instruction disassembly implemented here matches
961 * the instruction encoding classifications in chapter 3 (C3)
962 * of the ARM Architecture Reference Manual (DDI0487A_a)
965 /* C3.2.7 Unconditional branch (immediate)
967 * +----+-----------+-------------------------------------+
968 * | op | 0 0 1 0 1 | imm26 |
969 * +----+-----------+-------------------------------------+
971 static void disas_uncond_b_imm(DisasContext *s, uint32_t insn)
973 uint64_t addr = s->pc + sextract32(insn, 0, 26) * 4 - 4;
975 if (insn & (1 << 31)) {
976 /* C5.6.26 BL Branch with link */
977 tcg_gen_movi_i64(cpu_reg(s, 30), s->pc);
980 /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
981 gen_goto_tb(s, 0, addr);
984 /* C3.2.1 Compare & branch (immediate)
985 * 31 30 25 24 23 5 4 0
986 * +----+-------------+----+---------------------+--------+
987 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
988 * +----+-------------+----+---------------------+--------+
990 static void disas_comp_b_imm(DisasContext *s, uint32_t insn)
992 unsigned int sf, op, rt;
997 sf = extract32(insn, 31, 1);
998 op = extract32(insn, 24, 1); /* 0: CBZ; 1: CBNZ */
999 rt = extract32(insn, 0, 5);
1000 addr = s->pc + sextract32(insn, 5, 19) * 4 - 4;
1002 tcg_cmp = read_cpu_reg(s, rt, sf);
1003 label_match = gen_new_label();
1005 tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ,
1006 tcg_cmp, 0, label_match);
1008 gen_goto_tb(s, 0, s->pc);
1009 gen_set_label(label_match);
1010 gen_goto_tb(s, 1, addr);
1013 /* C3.2.5 Test & branch (immediate)
1014 * 31 30 25 24 23 19 18 5 4 0
1015 * +----+-------------+----+-------+-------------+------+
1016 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1017 * +----+-------------+----+-------+-------------+------+
1019 static void disas_test_b_imm(DisasContext *s, uint32_t insn)
1021 unsigned int bit_pos, op, rt;
1026 bit_pos = (extract32(insn, 31, 1) << 5) | extract32(insn, 19, 5);
1027 op = extract32(insn, 24, 1); /* 0: TBZ; 1: TBNZ */
1028 addr = s->pc + sextract32(insn, 5, 14) * 4 - 4;
1029 rt = extract32(insn, 0, 5);
1031 tcg_cmp = tcg_temp_new_i64();
1032 tcg_gen_andi_i64(tcg_cmp, cpu_reg(s, rt), (1ULL << bit_pos));
1033 label_match = gen_new_label();
1034 tcg_gen_brcondi_i64(op ? TCG_COND_NE : TCG_COND_EQ,
1035 tcg_cmp, 0, label_match);
1036 tcg_temp_free_i64(tcg_cmp);
1037 gen_goto_tb(s, 0, s->pc);
1038 gen_set_label(label_match);
1039 gen_goto_tb(s, 1, addr);
1042 /* C3.2.2 / C5.6.19 Conditional branch (immediate)
1043 * 31 25 24 23 5 4 3 0
1044 * +---------------+----+---------------------+----+------+
1045 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1046 * +---------------+----+---------------------+----+------+
1048 static void disas_cond_b_imm(DisasContext *s, uint32_t insn)
1053 if ((insn & (1 << 4)) || (insn & (1 << 24))) {
1054 unallocated_encoding(s);
1057 addr = s->pc + sextract32(insn, 5, 19) * 4 - 4;
1058 cond = extract32(insn, 0, 4);
1061 /* genuinely conditional branches */
1062 int label_match = gen_new_label();
1063 arm_gen_test_cc(cond, label_match);
1064 gen_goto_tb(s, 0, s->pc);
1065 gen_set_label(label_match);
1066 gen_goto_tb(s, 1, addr);
1068 /* 0xe and 0xf are both "always" conditions */
1069 gen_goto_tb(s, 0, addr);
1074 static void handle_hint(DisasContext *s, uint32_t insn,
1075 unsigned int op1, unsigned int op2, unsigned int crm)
1077 unsigned int selector = crm << 3 | op2;
1080 unallocated_encoding(s);
1088 s->is_jmp = DISAS_WFI;
1094 /* we treat all as NOP at least for now */
1097 /* default specified as NOP equivalent */
1102 static void gen_clrex(DisasContext *s, uint32_t insn)
1104 tcg_gen_movi_i64(cpu_exclusive_addr, -1);
1107 /* CLREX, DSB, DMB, ISB */
1108 static void handle_sync(DisasContext *s, uint32_t insn,
1109 unsigned int op1, unsigned int op2, unsigned int crm)
1112 unallocated_encoding(s);
1123 /* We don't emulate caches so barriers are no-ops */
1126 unallocated_encoding(s);
1131 /* C5.6.130 MSR (immediate) - move immediate to processor state field */
1132 static void handle_msr_i(DisasContext *s, uint32_t insn,
1133 unsigned int op1, unsigned int op2, unsigned int crm)
1135 int op = op1 << 3 | op2;
1137 case 0x05: /* SPSel */
1138 if (s->current_pl == 0) {
1139 unallocated_encoding(s);
1143 case 0x1e: /* DAIFSet */
1144 case 0x1f: /* DAIFClear */
1146 TCGv_i32 tcg_imm = tcg_const_i32(crm);
1147 TCGv_i32 tcg_op = tcg_const_i32(op);
1148 gen_a64_set_pc_im(s->pc - 4);
1149 gen_helper_msr_i_pstate(cpu_env, tcg_op, tcg_imm);
1150 tcg_temp_free_i32(tcg_imm);
1151 tcg_temp_free_i32(tcg_op);
1152 s->is_jmp = DISAS_UPDATE;
1156 unallocated_encoding(s);
1161 static void gen_get_nzcv(TCGv_i64 tcg_rt)
1163 TCGv_i32 tmp = tcg_temp_new_i32();
1164 TCGv_i32 nzcv = tcg_temp_new_i32();
1166 /* build bit 31, N */
1167 tcg_gen_andi_i32(nzcv, cpu_NF, (1 << 31));
1168 /* build bit 30, Z */
1169 tcg_gen_setcondi_i32(TCG_COND_EQ, tmp, cpu_ZF, 0);
1170 tcg_gen_deposit_i32(nzcv, nzcv, tmp, 30, 1);
1171 /* build bit 29, C */
1172 tcg_gen_deposit_i32(nzcv, nzcv, cpu_CF, 29, 1);
1173 /* build bit 28, V */
1174 tcg_gen_shri_i32(tmp, cpu_VF, 31);
1175 tcg_gen_deposit_i32(nzcv, nzcv, tmp, 28, 1);
1176 /* generate result */
1177 tcg_gen_extu_i32_i64(tcg_rt, nzcv);
1179 tcg_temp_free_i32(nzcv);
1180 tcg_temp_free_i32(tmp);
1183 static void gen_set_nzcv(TCGv_i64 tcg_rt)
1186 TCGv_i32 nzcv = tcg_temp_new_i32();
1188 /* take NZCV from R[t] */
1189 tcg_gen_trunc_i64_i32(nzcv, tcg_rt);
1192 tcg_gen_andi_i32(cpu_NF, nzcv, (1 << 31));
1194 tcg_gen_andi_i32(cpu_ZF, nzcv, (1 << 30));
1195 tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_ZF, cpu_ZF, 0);
1197 tcg_gen_andi_i32(cpu_CF, nzcv, (1 << 29));
1198 tcg_gen_shri_i32(cpu_CF, cpu_CF, 29);
1200 tcg_gen_andi_i32(cpu_VF, nzcv, (1 << 28));
1201 tcg_gen_shli_i32(cpu_VF, cpu_VF, 3);
1202 tcg_temp_free_i32(nzcv);
1205 /* C5.6.129 MRS - move from system register
1206 * C5.6.131 MSR (register) - move to system register
1209 * These are all essentially the same insn in 'read' and 'write'
1210 * versions, with varying op0 fields.
1212 static void handle_sys(DisasContext *s, uint32_t insn, bool isread,
1213 unsigned int op0, unsigned int op1, unsigned int op2,
1214 unsigned int crn, unsigned int crm, unsigned int rt)
1216 const ARMCPRegInfo *ri;
1219 ri = get_arm_cp_reginfo(s->cp_regs,
1220 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP,
1221 crn, crm, op0, op1, op2));
1224 /* Unknown register; this might be a guest error or a QEMU
1225 * unimplemented feature.
1227 qemu_log_mask(LOG_UNIMP, "%s access to unsupported AArch64 "
1228 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1229 isread ? "read" : "write", op0, op1, crn, crm, op2);
1230 unallocated_encoding(s);
1234 /* Check access permissions */
1235 if (!cp_access_ok(s->current_pl, ri, isread)) {
1236 unallocated_encoding(s);
1241 /* Emit code to perform further access permissions checks at
1242 * runtime; this may result in an exception.
1245 gen_a64_set_pc_im(s->pc - 4);
1246 tmpptr = tcg_const_ptr(ri);
1247 gen_helper_access_check_cp_reg(cpu_env, tmpptr);
1248 tcg_temp_free_ptr(tmpptr);
1251 /* Handle special cases first */
1252 switch (ri->type & ~(ARM_CP_FLAG_MASK & ~ARM_CP_SPECIAL)) {
1256 tcg_rt = cpu_reg(s, rt);
1258 gen_get_nzcv(tcg_rt);
1260 gen_set_nzcv(tcg_rt);
1263 case ARM_CP_CURRENTEL:
1264 /* Reads as current EL value from pstate, which is
1265 * guaranteed to be constant by the tb flags.
1267 tcg_rt = cpu_reg(s, rt);
1268 tcg_gen_movi_i64(tcg_rt, s->current_pl << 2);
1274 if (use_icount && (ri->type & ARM_CP_IO)) {
1278 tcg_rt = cpu_reg(s, rt);
1281 if (ri->type & ARM_CP_CONST) {
1282 tcg_gen_movi_i64(tcg_rt, ri->resetvalue);
1283 } else if (ri->readfn) {
1285 tmpptr = tcg_const_ptr(ri);
1286 gen_helper_get_cp_reg64(tcg_rt, cpu_env, tmpptr);
1287 tcg_temp_free_ptr(tmpptr);
1289 tcg_gen_ld_i64(tcg_rt, cpu_env, ri->fieldoffset);
1292 if (ri->type & ARM_CP_CONST) {
1293 /* If not forbidden by access permissions, treat as WI */
1295 } else if (ri->writefn) {
1297 tmpptr = tcg_const_ptr(ri);
1298 gen_helper_set_cp_reg64(cpu_env, tmpptr, tcg_rt);
1299 tcg_temp_free_ptr(tmpptr);
1301 tcg_gen_st_i64(tcg_rt, cpu_env, ri->fieldoffset);
1305 if (use_icount && (ri->type & ARM_CP_IO)) {
1306 /* I/O operations must end the TB here (whether read or write) */
1308 s->is_jmp = DISAS_UPDATE;
1309 } else if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) {
1310 /* We default to ending the TB on a coprocessor register write,
1311 * but allow this to be suppressed by the register definition
1312 * (usually only necessary to work around guest bugs).
1314 s->is_jmp = DISAS_UPDATE;
1319 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1320 * +---------------------+---+-----+-----+-------+-------+-----+------+
1321 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1322 * +---------------------+---+-----+-----+-------+-------+-----+------+
1324 static void disas_system(DisasContext *s, uint32_t insn)
1326 unsigned int l, op0, op1, crn, crm, op2, rt;
1327 l = extract32(insn, 21, 1);
1328 op0 = extract32(insn, 19, 2);
1329 op1 = extract32(insn, 16, 3);
1330 crn = extract32(insn, 12, 4);
1331 crm = extract32(insn, 8, 4);
1332 op2 = extract32(insn, 5, 3);
1333 rt = extract32(insn, 0, 5);
1336 if (l || rt != 31) {
1337 unallocated_encoding(s);
1341 case 2: /* C5.6.68 HINT */
1342 handle_hint(s, insn, op1, op2, crm);
1344 case 3: /* CLREX, DSB, DMB, ISB */
1345 handle_sync(s, insn, op1, op2, crm);
1347 case 4: /* C5.6.130 MSR (immediate) */
1348 handle_msr_i(s, insn, op1, op2, crm);
1351 unallocated_encoding(s);
1356 handle_sys(s, insn, l, op0, op1, op2, crn, crm, rt);
1359 /* C3.2.3 Exception generation
1361 * 31 24 23 21 20 5 4 2 1 0
1362 * +-----------------+-----+------------------------+-----+----+
1363 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1364 * +-----------------------+------------------------+----------+
1366 static void disas_exc(DisasContext *s, uint32_t insn)
1368 int opc = extract32(insn, 21, 3);
1369 int op2_ll = extract32(insn, 0, 5);
1373 /* SVC, HVC, SMC; since we don't support the Virtualization
1374 * or TrustZone extensions these all UNDEF except SVC.
1377 unallocated_encoding(s);
1380 gen_exception_insn(s, 0, EXCP_SWI);
1384 unallocated_encoding(s);
1388 gen_exception_insn(s, 0, EXCP_BKPT);
1392 unallocated_encoding(s);
1396 unsupported_encoding(s, insn);
1399 if (op2_ll < 1 || op2_ll > 3) {
1400 unallocated_encoding(s);
1403 /* DCPS1, DCPS2, DCPS3 */
1404 unsupported_encoding(s, insn);
1407 unallocated_encoding(s);
1412 /* C3.2.7 Unconditional branch (register)
1413 * 31 25 24 21 20 16 15 10 9 5 4 0
1414 * +---------------+-------+-------+-------+------+-------+
1415 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1416 * +---------------+-------+-------+-------+------+-------+
1418 static void disas_uncond_b_reg(DisasContext *s, uint32_t insn)
1420 unsigned int opc, op2, op3, rn, op4;
1422 opc = extract32(insn, 21, 4);
1423 op2 = extract32(insn, 16, 5);
1424 op3 = extract32(insn, 10, 6);
1425 rn = extract32(insn, 5, 5);
1426 op4 = extract32(insn, 0, 5);
1428 if (op4 != 0x0 || op3 != 0x0 || op2 != 0x1f) {
1429 unallocated_encoding(s);
1438 tcg_gen_movi_i64(cpu_reg(s, 30), s->pc);
1443 unallocated_encoding(s);
1445 unsupported_encoding(s, insn);
1449 unallocated_encoding(s);
1453 tcg_gen_mov_i64(cpu_pc, cpu_reg(s, rn));
1454 s->is_jmp = DISAS_JUMP;
1457 /* C3.2 Branches, exception generating and system instructions */
1458 static void disas_b_exc_sys(DisasContext *s, uint32_t insn)
1460 switch (extract32(insn, 25, 7)) {
1461 case 0x0a: case 0x0b:
1462 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1463 disas_uncond_b_imm(s, insn);
1465 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1466 disas_comp_b_imm(s, insn);
1468 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1469 disas_test_b_imm(s, insn);
1471 case 0x2a: /* Conditional branch (immediate) */
1472 disas_cond_b_imm(s, insn);
1474 case 0x6a: /* Exception generation / System */
1475 if (insn & (1 << 24)) {
1476 disas_system(s, insn);
1481 case 0x6b: /* Unconditional branch (register) */
1482 disas_uncond_b_reg(s, insn);
1485 unallocated_encoding(s);
1491 * Load/Store exclusive instructions are implemented by remembering
1492 * the value/address loaded, and seeing if these are the same
1493 * when the store is performed. This is not actually the architecturally
1494 * mandated semantics, but it works for typical guest code sequences
1495 * and avoids having to monitor regular stores.
1497 * In system emulation mode only one CPU will be running at once, so
1498 * this sequence is effectively atomic. In user emulation mode we
1499 * throw an exception and handle the atomic operation elsewhere.
1501 static void gen_load_exclusive(DisasContext *s, int rt, int rt2,
1502 TCGv_i64 addr, int size, bool is_pair)
1504 TCGv_i64 tmp = tcg_temp_new_i64();
1505 TCGMemOp memop = MO_TE + size;
1507 g_assert(size <= 3);
1508 tcg_gen_qemu_ld_i64(tmp, addr, get_mem_index(s), memop);
1511 TCGv_i64 addr2 = tcg_temp_new_i64();
1512 TCGv_i64 hitmp = tcg_temp_new_i64();
1514 g_assert(size >= 2);
1515 tcg_gen_addi_i64(addr2, addr, 1 << size);
1516 tcg_gen_qemu_ld_i64(hitmp, addr2, get_mem_index(s), memop);
1517 tcg_temp_free_i64(addr2);
1518 tcg_gen_mov_i64(cpu_exclusive_high, hitmp);
1519 tcg_gen_mov_i64(cpu_reg(s, rt2), hitmp);
1520 tcg_temp_free_i64(hitmp);
1523 tcg_gen_mov_i64(cpu_exclusive_val, tmp);
1524 tcg_gen_mov_i64(cpu_reg(s, rt), tmp);
1526 tcg_temp_free_i64(tmp);
1527 tcg_gen_mov_i64(cpu_exclusive_addr, addr);
1530 #ifdef CONFIG_USER_ONLY
1531 static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,
1532 TCGv_i64 addr, int size, int is_pair)
1534 tcg_gen_mov_i64(cpu_exclusive_test, addr);
1535 tcg_gen_movi_i32(cpu_exclusive_info,
1536 size | is_pair << 2 | (rd << 4) | (rt << 9) | (rt2 << 14));
1537 gen_exception_insn(s, 4, EXCP_STREX);
1540 static void gen_store_exclusive(DisasContext *s, int rd, int rt, int rt2,
1541 TCGv_i64 inaddr, int size, int is_pair)
1543 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1544 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1547 * [addr + datasize] = {Rt2};
1553 * env->exclusive_addr = -1;
1555 int fail_label = gen_new_label();
1556 int done_label = gen_new_label();
1557 TCGv_i64 addr = tcg_temp_local_new_i64();
1560 /* Copy input into a local temp so it is not trashed when the
1561 * basic block ends at the branch insn.
1563 tcg_gen_mov_i64(addr, inaddr);
1564 tcg_gen_brcond_i64(TCG_COND_NE, addr, cpu_exclusive_addr, fail_label);
1566 tmp = tcg_temp_new_i64();
1567 tcg_gen_qemu_ld_i64(tmp, addr, get_mem_index(s), MO_TE + size);
1568 tcg_gen_brcond_i64(TCG_COND_NE, tmp, cpu_exclusive_val, fail_label);
1569 tcg_temp_free_i64(tmp);
1572 TCGv_i64 addrhi = tcg_temp_new_i64();
1573 TCGv_i64 tmphi = tcg_temp_new_i64();
1575 tcg_gen_addi_i64(addrhi, addr, 1 << size);
1576 tcg_gen_qemu_ld_i64(tmphi, addrhi, get_mem_index(s), MO_TE + size);
1577 tcg_gen_brcond_i64(TCG_COND_NE, tmphi, cpu_exclusive_high, fail_label);
1579 tcg_temp_free_i64(tmphi);
1580 tcg_temp_free_i64(addrhi);
1583 /* We seem to still have the exclusive monitor, so do the store */
1584 tcg_gen_qemu_st_i64(cpu_reg(s, rt), addr, get_mem_index(s), MO_TE + size);
1586 TCGv_i64 addrhi = tcg_temp_new_i64();
1588 tcg_gen_addi_i64(addrhi, addr, 1 << size);
1589 tcg_gen_qemu_st_i64(cpu_reg(s, rt2), addrhi,
1590 get_mem_index(s), MO_TE + size);
1591 tcg_temp_free_i64(addrhi);
1594 tcg_temp_free_i64(addr);
1596 tcg_gen_movi_i64(cpu_reg(s, rd), 0);
1597 tcg_gen_br(done_label);
1598 gen_set_label(fail_label);
1599 tcg_gen_movi_i64(cpu_reg(s, rd), 1);
1600 gen_set_label(done_label);
1601 tcg_gen_movi_i64(cpu_exclusive_addr, -1);
1606 /* C3.3.6 Load/store exclusive
1608 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
1609 * +-----+-------------+----+---+----+------+----+-------+------+------+
1610 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
1611 * +-----+-------------+----+---+----+------+----+-------+------+------+
1613 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
1614 * L: 0 -> store, 1 -> load
1615 * o2: 0 -> exclusive, 1 -> not
1616 * o1: 0 -> single register, 1 -> register pair
1617 * o0: 1 -> load-acquire/store-release, 0 -> not
1619 * o0 == 0 AND o2 == 1 is un-allocated
1620 * o1 == 1 is un-allocated except for 32 and 64 bit sizes
1622 static void disas_ldst_excl(DisasContext *s, uint32_t insn)
1624 int rt = extract32(insn, 0, 5);
1625 int rn = extract32(insn, 5, 5);
1626 int rt2 = extract32(insn, 10, 5);
1627 int is_lasr = extract32(insn, 15, 1);
1628 int rs = extract32(insn, 16, 5);
1629 int is_pair = extract32(insn, 21, 1);
1630 int is_store = !extract32(insn, 22, 1);
1631 int is_excl = !extract32(insn, 23, 1);
1632 int size = extract32(insn, 30, 2);
1635 if ((!is_excl && !is_lasr) ||
1636 (is_pair && size < 2)) {
1637 unallocated_encoding(s);
1642 gen_check_sp_alignment(s);
1644 tcg_addr = read_cpu_reg_sp(s, rn, 1);
1646 /* Note that since TCG is single threaded load-acquire/store-release
1647 * semantics require no extra if (is_lasr) { ... } handling.
1652 gen_load_exclusive(s, rt, rt2, tcg_addr, size, is_pair);
1654 gen_store_exclusive(s, rs, rt, rt2, tcg_addr, size, is_pair);
1657 TCGv_i64 tcg_rt = cpu_reg(s, rt);
1659 do_gpr_st(s, tcg_rt, tcg_addr, size);
1661 do_gpr_ld(s, tcg_rt, tcg_addr, size, false, false);
1664 TCGv_i64 tcg_rt2 = cpu_reg(s, rt);
1665 tcg_gen_addi_i64(tcg_addr, tcg_addr, 1 << size);
1667 do_gpr_st(s, tcg_rt2, tcg_addr, size);
1669 do_gpr_ld(s, tcg_rt2, tcg_addr, size, false, false);
1676 * C3.3.5 Load register (literal)
1678 * 31 30 29 27 26 25 24 23 5 4 0
1679 * +-----+-------+---+-----+-------------------+-------+
1680 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
1681 * +-----+-------+---+-----+-------------------+-------+
1683 * V: 1 -> vector (simd/fp)
1684 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
1685 * 10-> 32 bit signed, 11 -> prefetch
1686 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
1688 static void disas_ld_lit(DisasContext *s, uint32_t insn)
1690 int rt = extract32(insn, 0, 5);
1691 int64_t imm = sextract32(insn, 5, 19) << 2;
1692 bool is_vector = extract32(insn, 26, 1);
1693 int opc = extract32(insn, 30, 2);
1694 bool is_signed = false;
1696 TCGv_i64 tcg_rt, tcg_addr;
1700 unallocated_encoding(s);
1706 /* PRFM (literal) : prefetch */
1709 size = 2 + extract32(opc, 0, 1);
1710 is_signed = extract32(opc, 1, 1);
1713 tcg_rt = cpu_reg(s, rt);
1715 tcg_addr = tcg_const_i64((s->pc - 4) + imm);
1717 do_fp_ld(s, rt, tcg_addr, size);
1719 do_gpr_ld(s, tcg_rt, tcg_addr, size, is_signed, false);
1721 tcg_temp_free_i64(tcg_addr);
1725 * C5.6.80 LDNP (Load Pair - non-temporal hint)
1726 * C5.6.81 LDP (Load Pair - non vector)
1727 * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
1728 * C5.6.176 STNP (Store Pair - non-temporal hint)
1729 * C5.6.177 STP (Store Pair - non vector)
1730 * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
1731 * C6.3.165 LDP (Load Pair of SIMD&FP)
1732 * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
1733 * C6.3.284 STP (Store Pair of SIMD&FP)
1735 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
1736 * +-----+-------+---+---+-------+---+-----------------------------+
1737 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
1738 * +-----+-------+---+---+-------+---+-------+-------+------+------+
1740 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
1742 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
1743 * V: 0 -> GPR, 1 -> Vector
1744 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
1745 * 10 -> signed offset, 11 -> pre-index
1746 * L: 0 -> Store 1 -> Load
1748 * Rt, Rt2 = GPR or SIMD registers to be stored
1749 * Rn = general purpose register containing address
1750 * imm7 = signed offset (multiple of 4 or 8 depending on size)
1752 static void disas_ldst_pair(DisasContext *s, uint32_t insn)
1754 int rt = extract32(insn, 0, 5);
1755 int rn = extract32(insn, 5, 5);
1756 int rt2 = extract32(insn, 10, 5);
1757 int64_t offset = sextract32(insn, 15, 7);
1758 int index = extract32(insn, 23, 2);
1759 bool is_vector = extract32(insn, 26, 1);
1760 bool is_load = extract32(insn, 22, 1);
1761 int opc = extract32(insn, 30, 2);
1763 bool is_signed = false;
1764 bool postindex = false;
1767 TCGv_i64 tcg_addr; /* calculated address */
1771 unallocated_encoding(s);
1778 size = 2 + extract32(opc, 1, 1);
1779 is_signed = extract32(opc, 0, 1);
1780 if (!is_load && is_signed) {
1781 unallocated_encoding(s);
1787 case 1: /* post-index */
1792 /* signed offset with "non-temporal" hint. Since we don't emulate
1793 * caches we don't care about hints to the cache system about
1794 * data access patterns, and handle this identically to plain
1798 /* There is no non-temporal-hint version of LDPSW */
1799 unallocated_encoding(s);
1804 case 2: /* signed offset, rn not updated */
1807 case 3: /* pre-index */
1816 gen_check_sp_alignment(s);
1819 tcg_addr = read_cpu_reg_sp(s, rn, 1);
1822 tcg_gen_addi_i64(tcg_addr, tcg_addr, offset);
1827 do_fp_ld(s, rt, tcg_addr, size);
1829 do_fp_st(s, rt, tcg_addr, size);
1832 TCGv_i64 tcg_rt = cpu_reg(s, rt);
1834 do_gpr_ld(s, tcg_rt, tcg_addr, size, is_signed, false);
1836 do_gpr_st(s, tcg_rt, tcg_addr, size);
1839 tcg_gen_addi_i64(tcg_addr, tcg_addr, 1 << size);
1842 do_fp_ld(s, rt2, tcg_addr, size);
1844 do_fp_st(s, rt2, tcg_addr, size);
1847 TCGv_i64 tcg_rt2 = cpu_reg(s, rt2);
1849 do_gpr_ld(s, tcg_rt2, tcg_addr, size, is_signed, false);
1851 do_gpr_st(s, tcg_rt2, tcg_addr, size);
1857 tcg_gen_addi_i64(tcg_addr, tcg_addr, offset - (1 << size));
1859 tcg_gen_subi_i64(tcg_addr, tcg_addr, 1 << size);
1861 tcg_gen_mov_i64(cpu_reg_sp(s, rn), tcg_addr);
1866 * C3.3.8 Load/store (immediate post-indexed)
1867 * C3.3.9 Load/store (immediate pre-indexed)
1868 * C3.3.12 Load/store (unscaled immediate)
1870 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
1871 * +----+-------+---+-----+-----+---+--------+-----+------+------+
1872 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
1873 * +----+-------+---+-----+-----+---+--------+-----+------+------+
1875 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
1877 * V = 0 -> non-vector
1878 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
1879 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
1881 static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn)
1883 int rt = extract32(insn, 0, 5);
1884 int rn = extract32(insn, 5, 5);
1885 int imm9 = sextract32(insn, 12, 9);
1886 int opc = extract32(insn, 22, 2);
1887 int size = extract32(insn, 30, 2);
1888 int idx = extract32(insn, 10, 2);
1889 bool is_signed = false;
1890 bool is_store = false;
1891 bool is_extended = false;
1892 bool is_unpriv = (idx == 2);
1893 bool is_vector = extract32(insn, 26, 1);
1900 size |= (opc & 2) << 1;
1901 if (size > 4 || is_unpriv) {
1902 unallocated_encoding(s);
1905 is_store = ((opc & 1) == 0);
1907 if (size == 3 && opc == 2) {
1908 /* PRFM - prefetch */
1910 unallocated_encoding(s);
1915 if (opc == 3 && size > 1) {
1916 unallocated_encoding(s);
1919 is_store = (opc == 0);
1920 is_signed = opc & (1<<1);
1921 is_extended = (size < 3) && (opc & 1);
1941 gen_check_sp_alignment(s);
1943 tcg_addr = read_cpu_reg_sp(s, rn, 1);
1946 tcg_gen_addi_i64(tcg_addr, tcg_addr, imm9);
1951 do_fp_st(s, rt, tcg_addr, size);
1953 do_fp_ld(s, rt, tcg_addr, size);
1956 TCGv_i64 tcg_rt = cpu_reg(s, rt);
1957 int memidx = is_unpriv ? 1 : get_mem_index(s);
1960 do_gpr_st_memidx(s, tcg_rt, tcg_addr, size, memidx);
1962 do_gpr_ld_memidx(s, tcg_rt, tcg_addr, size,
1963 is_signed, is_extended, memidx);
1968 TCGv_i64 tcg_rn = cpu_reg_sp(s, rn);
1970 tcg_gen_addi_i64(tcg_addr, tcg_addr, imm9);
1972 tcg_gen_mov_i64(tcg_rn, tcg_addr);
1977 * C3.3.10 Load/store (register offset)
1979 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
1980 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
1981 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
1982 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
1985 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
1986 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
1988 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
1989 * opc<0>: 0 -> store, 1 -> load
1990 * V: 1 -> vector/simd
1991 * opt: extend encoding (see DecodeRegExtend)
1992 * S: if S=1 then scale (essentially index by sizeof(size))
1993 * Rt: register to transfer into/out of
1994 * Rn: address register or SP for base
1995 * Rm: offset register or ZR for offset
1997 static void disas_ldst_reg_roffset(DisasContext *s, uint32_t insn)
1999 int rt = extract32(insn, 0, 5);
2000 int rn = extract32(insn, 5, 5);
2001 int shift = extract32(insn, 12, 1);
2002 int rm = extract32(insn, 16, 5);
2003 int opc = extract32(insn, 22, 2);
2004 int opt = extract32(insn, 13, 3);
2005 int size = extract32(insn, 30, 2);
2006 bool is_signed = false;
2007 bool is_store = false;
2008 bool is_extended = false;
2009 bool is_vector = extract32(insn, 26, 1);
2014 if (extract32(opt, 1, 1) == 0) {
2015 unallocated_encoding(s);
2020 size |= (opc & 2) << 1;
2022 unallocated_encoding(s);
2025 is_store = !extract32(opc, 0, 1);
2027 if (size == 3 && opc == 2) {
2028 /* PRFM - prefetch */
2031 if (opc == 3 && size > 1) {
2032 unallocated_encoding(s);
2035 is_store = (opc == 0);
2036 is_signed = extract32(opc, 1, 1);
2037 is_extended = (size < 3) && extract32(opc, 0, 1);
2041 gen_check_sp_alignment(s);
2043 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2045 tcg_rm = read_cpu_reg(s, rm, 1);
2046 ext_and_shift_reg(tcg_rm, tcg_rm, opt, shift ? size : 0);
2048 tcg_gen_add_i64(tcg_addr, tcg_addr, tcg_rm);
2052 do_fp_st(s, rt, tcg_addr, size);
2054 do_fp_ld(s, rt, tcg_addr, size);
2057 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2059 do_gpr_st(s, tcg_rt, tcg_addr, size);
2061 do_gpr_ld(s, tcg_rt, tcg_addr, size, is_signed, is_extended);
2067 * C3.3.13 Load/store (unsigned immediate)
2069 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2070 * +----+-------+---+-----+-----+------------+-------+------+
2071 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2072 * +----+-------+---+-----+-----+------------+-------+------+
2075 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2076 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2078 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2079 * opc<0>: 0 -> store, 1 -> load
2080 * Rn: base address register (inc SP)
2081 * Rt: target register
2083 static void disas_ldst_reg_unsigned_imm(DisasContext *s, uint32_t insn)
2085 int rt = extract32(insn, 0, 5);
2086 int rn = extract32(insn, 5, 5);
2087 unsigned int imm12 = extract32(insn, 10, 12);
2088 bool is_vector = extract32(insn, 26, 1);
2089 int size = extract32(insn, 30, 2);
2090 int opc = extract32(insn, 22, 2);
2091 unsigned int offset;
2096 bool is_signed = false;
2097 bool is_extended = false;
2100 size |= (opc & 2) << 1;
2102 unallocated_encoding(s);
2105 is_store = !extract32(opc, 0, 1);
2107 if (size == 3 && opc == 2) {
2108 /* PRFM - prefetch */
2111 if (opc == 3 && size > 1) {
2112 unallocated_encoding(s);
2115 is_store = (opc == 0);
2116 is_signed = extract32(opc, 1, 1);
2117 is_extended = (size < 3) && extract32(opc, 0, 1);
2121 gen_check_sp_alignment(s);
2123 tcg_addr = read_cpu_reg_sp(s, rn, 1);
2124 offset = imm12 << size;
2125 tcg_gen_addi_i64(tcg_addr, tcg_addr, offset);
2129 do_fp_st(s, rt, tcg_addr, size);
2131 do_fp_ld(s, rt, tcg_addr, size);
2134 TCGv_i64 tcg_rt = cpu_reg(s, rt);
2136 do_gpr_st(s, tcg_rt, tcg_addr, size);
2138 do_gpr_ld(s, tcg_rt, tcg_addr, size, is_signed, is_extended);
2143 /* Load/store register (all forms) */
2144 static void disas_ldst_reg(DisasContext *s, uint32_t insn)
2146 switch (extract32(insn, 24, 2)) {
2148 if (extract32(insn, 21, 1) == 1 && extract32(insn, 10, 2) == 2) {
2149 disas_ldst_reg_roffset(s, insn);
2151 /* Load/store register (unscaled immediate)
2152 * Load/store immediate pre/post-indexed
2153 * Load/store register unprivileged
2155 disas_ldst_reg_imm9(s, insn);
2159 disas_ldst_reg_unsigned_imm(s, insn);
2162 unallocated_encoding(s);
2167 /* C3.3.1 AdvSIMD load/store multiple structures
2169 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2170 * +---+---+---------------+---+-------------+--------+------+------+------+
2171 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2172 * +---+---+---------------+---+-------------+--------+------+------+------+
2174 * C3.3.2 AdvSIMD load/store multiple structures (post-indexed)
2176 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2177 * +---+---+---------------+---+---+---------+--------+------+------+------+
2178 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2179 * +---+---+---------------+---+---+---------+--------+------+------+------+
2181 * Rt: first (or only) SIMD&FP register to be transferred
2182 * Rn: base address or SP
2183 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2185 static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn)
2187 int rt = extract32(insn, 0, 5);
2188 int rn = extract32(insn, 5, 5);
2189 int size = extract32(insn, 10, 2);
2190 int opcode = extract32(insn, 12, 4);
2191 bool is_store = !extract32(insn, 22, 1);
2192 bool is_postidx = extract32(insn, 23, 1);
2193 bool is_q = extract32(insn, 30, 1);
2194 TCGv_i64 tcg_addr, tcg_rn;
2196 int ebytes = 1 << size;
2197 int elements = (is_q ? 128 : 64) / (8 << size);
2198 int rpt; /* num iterations */
2199 int selem; /* structure elements */
2202 if (extract32(insn, 31, 1) || extract32(insn, 21, 1)) {
2203 unallocated_encoding(s);
2207 /* From the shared decode logic */
2238 unallocated_encoding(s);
2242 if (size == 3 && !is_q && selem != 1) {
2244 unallocated_encoding(s);
2249 gen_check_sp_alignment(s);
2252 tcg_rn = cpu_reg_sp(s, rn);
2253 tcg_addr = tcg_temp_new_i64();
2254 tcg_gen_mov_i64(tcg_addr, tcg_rn);
2256 for (r = 0; r < rpt; r++) {
2258 for (e = 0; e < elements; e++) {
2259 int tt = (rt + r) % 32;
2261 for (xs = 0; xs < selem; xs++) {
2263 do_vec_st(s, tt, e, tcg_addr, size);
2265 do_vec_ld(s, tt, e, tcg_addr, size);
2267 /* For non-quad operations, setting a slice of the low
2268 * 64 bits of the register clears the high 64 bits (in
2269 * the ARM ARM pseudocode this is implicit in the fact
2270 * that 'rval' is a 64 bit wide variable). We optimize
2271 * by noticing that we only need to do this the first
2272 * time we touch a register.
2274 if (!is_q && e == 0 && (r == 0 || xs == selem - 1)) {
2275 clear_vec_high(s, tt);
2278 tcg_gen_addi_i64(tcg_addr, tcg_addr, ebytes);
2285 int rm = extract32(insn, 16, 5);
2287 tcg_gen_mov_i64(tcg_rn, tcg_addr);
2289 tcg_gen_add_i64(tcg_rn, tcg_rn, cpu_reg(s, rm));
2292 tcg_temp_free_i64(tcg_addr);
2295 /* C3.3.3 AdvSIMD load/store single structure
2297 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2298 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2299 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
2300 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2302 * C3.3.4 AdvSIMD load/store single structure (post-indexed)
2304 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2305 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2306 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
2307 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2309 * Rt: first (or only) SIMD&FP register to be transferred
2310 * Rn: base address or SP
2311 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2312 * index = encoded in Q:S:size dependent on size
2314 * lane_size = encoded in R, opc
2315 * transfer width = encoded in opc, S, size
2317 static void disas_ldst_single_struct(DisasContext *s, uint32_t insn)
2319 int rt = extract32(insn, 0, 5);
2320 int rn = extract32(insn, 5, 5);
2321 int size = extract32(insn, 10, 2);
2322 int S = extract32(insn, 12, 1);
2323 int opc = extract32(insn, 13, 3);
2324 int R = extract32(insn, 21, 1);
2325 int is_load = extract32(insn, 22, 1);
2326 int is_postidx = extract32(insn, 23, 1);
2327 int is_q = extract32(insn, 30, 1);
2329 int scale = extract32(opc, 1, 2);
2330 int selem = (extract32(opc, 0, 1) << 1 | R) + 1;
2331 bool replicate = false;
2332 int index = is_q << 3 | S << 2 | size;
2334 TCGv_i64 tcg_addr, tcg_rn;
2338 if (!is_load || S) {
2339 unallocated_encoding(s);
2348 if (extract32(size, 0, 1)) {
2349 unallocated_encoding(s);
2355 if (extract32(size, 1, 1)) {
2356 unallocated_encoding(s);
2359 if (!extract32(size, 0, 1)) {
2363 unallocated_encoding(s);
2371 g_assert_not_reached();
2374 ebytes = 1 << scale;
2377 gen_check_sp_alignment(s);
2380 tcg_rn = cpu_reg_sp(s, rn);
2381 tcg_addr = tcg_temp_new_i64();
2382 tcg_gen_mov_i64(tcg_addr, tcg_rn);
2384 for (xs = 0; xs < selem; xs++) {
2386 /* Load and replicate to all elements */
2388 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
2390 tcg_gen_qemu_ld_i64(tcg_tmp, tcg_addr,
2391 get_mem_index(s), MO_TE + scale);
2394 mulconst = 0x0101010101010101ULL;
2397 mulconst = 0x0001000100010001ULL;
2400 mulconst = 0x0000000100000001ULL;
2406 g_assert_not_reached();
2409 tcg_gen_muli_i64(tcg_tmp, tcg_tmp, mulconst);
2411 write_vec_element(s, tcg_tmp, rt, 0, MO_64);
2413 write_vec_element(s, tcg_tmp, rt, 1, MO_64);
2415 clear_vec_high(s, rt);
2417 tcg_temp_free_i64(tcg_tmp);
2419 /* Load/store one element per register */
2421 do_vec_ld(s, rt, index, tcg_addr, MO_TE + scale);
2423 do_vec_st(s, rt, index, tcg_addr, MO_TE + scale);
2426 tcg_gen_addi_i64(tcg_addr, tcg_addr, ebytes);
2431 int rm = extract32(insn, 16, 5);
2433 tcg_gen_mov_i64(tcg_rn, tcg_addr);
2435 tcg_gen_add_i64(tcg_rn, tcg_rn, cpu_reg(s, rm));
2438 tcg_temp_free_i64(tcg_addr);
2441 /* C3.3 Loads and stores */
2442 static void disas_ldst(DisasContext *s, uint32_t insn)
2444 switch (extract32(insn, 24, 6)) {
2445 case 0x08: /* Load/store exclusive */
2446 disas_ldst_excl(s, insn);
2448 case 0x18: case 0x1c: /* Load register (literal) */
2449 disas_ld_lit(s, insn);
2451 case 0x28: case 0x29:
2452 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
2453 disas_ldst_pair(s, insn);
2455 case 0x38: case 0x39:
2456 case 0x3c: case 0x3d: /* Load/store register (all forms) */
2457 disas_ldst_reg(s, insn);
2459 case 0x0c: /* AdvSIMD load/store multiple structures */
2460 disas_ldst_multiple_struct(s, insn);
2462 case 0x0d: /* AdvSIMD load/store single structure */
2463 disas_ldst_single_struct(s, insn);
2466 unallocated_encoding(s);
2471 /* C3.4.6 PC-rel. addressing
2472 * 31 30 29 28 24 23 5 4 0
2473 * +----+-------+-----------+-------------------+------+
2474 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
2475 * +----+-------+-----------+-------------------+------+
2477 static void disas_pc_rel_adr(DisasContext *s, uint32_t insn)
2479 unsigned int page, rd;
2483 page = extract32(insn, 31, 1);
2484 /* SignExtend(immhi:immlo) -> offset */
2485 offset = ((int64_t)sextract32(insn, 5, 19) << 2) | extract32(insn, 29, 2);
2486 rd = extract32(insn, 0, 5);
2490 /* ADRP (page based) */
2495 tcg_gen_movi_i64(cpu_reg(s, rd), base + offset);
2499 * C3.4.1 Add/subtract (immediate)
2501 * 31 30 29 28 24 23 22 21 10 9 5 4 0
2502 * +--+--+--+-----------+-----+-------------+-----+-----+
2503 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
2504 * +--+--+--+-----------+-----+-------------+-----+-----+
2506 * sf: 0 -> 32bit, 1 -> 64bit
2507 * op: 0 -> add , 1 -> sub
2509 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
2511 static void disas_add_sub_imm(DisasContext *s, uint32_t insn)
2513 int rd = extract32(insn, 0, 5);
2514 int rn = extract32(insn, 5, 5);
2515 uint64_t imm = extract32(insn, 10, 12);
2516 int shift = extract32(insn, 22, 2);
2517 bool setflags = extract32(insn, 29, 1);
2518 bool sub_op = extract32(insn, 30, 1);
2519 bool is_64bit = extract32(insn, 31, 1);
2521 TCGv_i64 tcg_rn = cpu_reg_sp(s, rn);
2522 TCGv_i64 tcg_rd = setflags ? cpu_reg(s, rd) : cpu_reg_sp(s, rd);
2523 TCGv_i64 tcg_result;
2532 unallocated_encoding(s);
2536 tcg_result = tcg_temp_new_i64();
2539 tcg_gen_subi_i64(tcg_result, tcg_rn, imm);
2541 tcg_gen_addi_i64(tcg_result, tcg_rn, imm);
2544 TCGv_i64 tcg_imm = tcg_const_i64(imm);
2546 gen_sub_CC(is_64bit, tcg_result, tcg_rn, tcg_imm);
2548 gen_add_CC(is_64bit, tcg_result, tcg_rn, tcg_imm);
2550 tcg_temp_free_i64(tcg_imm);
2554 tcg_gen_mov_i64(tcg_rd, tcg_result);
2556 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
2559 tcg_temp_free_i64(tcg_result);
2562 /* The input should be a value in the bottom e bits (with higher
2563 * bits zero); returns that value replicated into every element
2564 * of size e in a 64 bit integer.
2566 static uint64_t bitfield_replicate(uint64_t mask, unsigned int e)
2576 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
2577 static inline uint64_t bitmask64(unsigned int length)
2579 assert(length > 0 && length <= 64);
2580 return ~0ULL >> (64 - length);
2583 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
2584 * only require the wmask. Returns false if the imms/immr/immn are a reserved
2585 * value (ie should cause a guest UNDEF exception), and true if they are
2586 * valid, in which case the decoded bit pattern is written to result.
2588 static bool logic_imm_decode_wmask(uint64_t *result, unsigned int immn,
2589 unsigned int imms, unsigned int immr)
2592 unsigned e, levels, s, r;
2595 assert(immn < 2 && imms < 64 && immr < 64);
2597 /* The bit patterns we create here are 64 bit patterns which
2598 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
2599 * 64 bits each. Each element contains the same value: a run
2600 * of between 1 and e-1 non-zero bits, rotated within the
2601 * element by between 0 and e-1 bits.
2603 * The element size and run length are encoded into immn (1 bit)
2604 * and imms (6 bits) as follows:
2605 * 64 bit elements: immn = 1, imms = <length of run - 1>
2606 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
2607 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
2608 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
2609 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
2610 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
2611 * Notice that immn = 0, imms = 11111x is the only combination
2612 * not covered by one of the above options; this is reserved.
2613 * Further, <length of run - 1> all-ones is a reserved pattern.
2615 * In all cases the rotation is by immr % e (and immr is 6 bits).
2618 /* First determine the element size */
2619 len = 31 - clz32((immn << 6) | (~imms & 0x3f));
2621 /* This is the immn == 0, imms == 0x11111x case */
2631 /* <length of run - 1> mustn't be all-ones. */
2635 /* Create the value of one element: s+1 set bits rotated
2636 * by r within the element (which is e bits wide)...
2638 mask = bitmask64(s + 1);
2639 mask = (mask >> r) | (mask << (e - r));
2640 /* ...then replicate the element over the whole 64 bit value */
2641 mask = bitfield_replicate(mask, e);
2646 /* C3.4.4 Logical (immediate)
2647 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2648 * +----+-----+-------------+---+------+------+------+------+
2649 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
2650 * +----+-----+-------------+---+------+------+------+------+
2652 static void disas_logic_imm(DisasContext *s, uint32_t insn)
2654 unsigned int sf, opc, is_n, immr, imms, rn, rd;
2655 TCGv_i64 tcg_rd, tcg_rn;
2657 bool is_and = false;
2659 sf = extract32(insn, 31, 1);
2660 opc = extract32(insn, 29, 2);
2661 is_n = extract32(insn, 22, 1);
2662 immr = extract32(insn, 16, 6);
2663 imms = extract32(insn, 10, 6);
2664 rn = extract32(insn, 5, 5);
2665 rd = extract32(insn, 0, 5);
2668 unallocated_encoding(s);
2672 if (opc == 0x3) { /* ANDS */
2673 tcg_rd = cpu_reg(s, rd);
2675 tcg_rd = cpu_reg_sp(s, rd);
2677 tcg_rn = cpu_reg(s, rn);
2679 if (!logic_imm_decode_wmask(&wmask, is_n, imms, immr)) {
2680 /* some immediate field values are reserved */
2681 unallocated_encoding(s);
2686 wmask &= 0xffffffff;
2690 case 0x3: /* ANDS */
2692 tcg_gen_andi_i64(tcg_rd, tcg_rn, wmask);
2696 tcg_gen_ori_i64(tcg_rd, tcg_rn, wmask);
2699 tcg_gen_xori_i64(tcg_rd, tcg_rn, wmask);
2702 assert(FALSE); /* must handle all above */
2706 if (!sf && !is_and) {
2707 /* zero extend final result; we know we can skip this for AND
2708 * since the immediate had the high 32 bits clear.
2710 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
2713 if (opc == 3) { /* ANDS */
2714 gen_logic_CC(sf, tcg_rd);
2719 * C3.4.5 Move wide (immediate)
2721 * 31 30 29 28 23 22 21 20 5 4 0
2722 * +--+-----+-------------+-----+----------------+------+
2723 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
2724 * +--+-----+-------------+-----+----------------+------+
2726 * sf: 0 -> 32 bit, 1 -> 64 bit
2727 * opc: 00 -> N, 10 -> Z, 11 -> K
2728 * hw: shift/16 (0,16, and sf only 32, 48)
2730 static void disas_movw_imm(DisasContext *s, uint32_t insn)
2732 int rd = extract32(insn, 0, 5);
2733 uint64_t imm = extract32(insn, 5, 16);
2734 int sf = extract32(insn, 31, 1);
2735 int opc = extract32(insn, 29, 2);
2736 int pos = extract32(insn, 21, 2) << 4;
2737 TCGv_i64 tcg_rd = cpu_reg(s, rd);
2740 if (!sf && (pos >= 32)) {
2741 unallocated_encoding(s);
2755 tcg_gen_movi_i64(tcg_rd, imm);
2758 tcg_imm = tcg_const_i64(imm);
2759 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_imm, pos, 16);
2760 tcg_temp_free_i64(tcg_imm);
2762 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
2766 unallocated_encoding(s);
2772 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2773 * +----+-----+-------------+---+------+------+------+------+
2774 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
2775 * +----+-----+-------------+---+------+------+------+------+
2777 static void disas_bitfield(DisasContext *s, uint32_t insn)
2779 unsigned int sf, n, opc, ri, si, rn, rd, bitsize, pos, len;
2780 TCGv_i64 tcg_rd, tcg_tmp;
2782 sf = extract32(insn, 31, 1);
2783 opc = extract32(insn, 29, 2);
2784 n = extract32(insn, 22, 1);
2785 ri = extract32(insn, 16, 6);
2786 si = extract32(insn, 10, 6);
2787 rn = extract32(insn, 5, 5);
2788 rd = extract32(insn, 0, 5);
2789 bitsize = sf ? 64 : 32;
2791 if (sf != n || ri >= bitsize || si >= bitsize || opc > 2) {
2792 unallocated_encoding(s);
2796 tcg_rd = cpu_reg(s, rd);
2797 tcg_tmp = read_cpu_reg(s, rn, sf);
2799 /* OPTME: probably worth recognizing common cases of ext{8,16,32}{u,s} */
2801 if (opc != 1) { /* SBFM or UBFM */
2802 tcg_gen_movi_i64(tcg_rd, 0);
2805 /* do the bit move operation */
2807 /* Wd<s-r:0> = Wn<s:r> */
2808 tcg_gen_shri_i64(tcg_tmp, tcg_tmp, ri);
2810 len = (si - ri) + 1;
2812 /* Wd<32+s-r,32-r> = Wn<s:0> */
2817 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_tmp, pos, len);
2819 if (opc == 0) { /* SBFM - sign extend the destination field */
2820 tcg_gen_shli_i64(tcg_rd, tcg_rd, 64 - (pos + len));
2821 tcg_gen_sari_i64(tcg_rd, tcg_rd, 64 - (pos + len));
2824 if (!sf) { /* zero extend final result */
2825 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
2830 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
2831 * +----+------+-------------+---+----+------+--------+------+------+
2832 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
2833 * +----+------+-------------+---+----+------+--------+------+------+
2835 static void disas_extract(DisasContext *s, uint32_t insn)
2837 unsigned int sf, n, rm, imm, rn, rd, bitsize, op21, op0;
2839 sf = extract32(insn, 31, 1);
2840 n = extract32(insn, 22, 1);
2841 rm = extract32(insn, 16, 5);
2842 imm = extract32(insn, 10, 6);
2843 rn = extract32(insn, 5, 5);
2844 rd = extract32(insn, 0, 5);
2845 op21 = extract32(insn, 29, 2);
2846 op0 = extract32(insn, 21, 1);
2847 bitsize = sf ? 64 : 32;
2849 if (sf != n || op21 || op0 || imm >= bitsize) {
2850 unallocated_encoding(s);
2852 TCGv_i64 tcg_rd, tcg_rm, tcg_rn;
2854 tcg_rd = cpu_reg(s, rd);
2857 /* OPTME: we can special case rm==rn as a rotate */
2858 tcg_rm = read_cpu_reg(s, rm, sf);
2859 tcg_rn = read_cpu_reg(s, rn, sf);
2860 tcg_gen_shri_i64(tcg_rm, tcg_rm, imm);
2861 tcg_gen_shli_i64(tcg_rn, tcg_rn, bitsize - imm);
2862 tcg_gen_or_i64(tcg_rd, tcg_rm, tcg_rn);
2864 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
2867 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
2868 * so an extract from bit 0 is a special case.
2871 tcg_gen_mov_i64(tcg_rd, cpu_reg(s, rm));
2873 tcg_gen_ext32u_i64(tcg_rd, cpu_reg(s, rm));
2880 /* C3.4 Data processing - immediate */
2881 static void disas_data_proc_imm(DisasContext *s, uint32_t insn)
2883 switch (extract32(insn, 23, 6)) {
2884 case 0x20: case 0x21: /* PC-rel. addressing */
2885 disas_pc_rel_adr(s, insn);
2887 case 0x22: case 0x23: /* Add/subtract (immediate) */
2888 disas_add_sub_imm(s, insn);
2890 case 0x24: /* Logical (immediate) */
2891 disas_logic_imm(s, insn);
2893 case 0x25: /* Move wide (immediate) */
2894 disas_movw_imm(s, insn);
2896 case 0x26: /* Bitfield */
2897 disas_bitfield(s, insn);
2899 case 0x27: /* Extract */
2900 disas_extract(s, insn);
2903 unallocated_encoding(s);
2908 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
2909 * Note that it is the caller's responsibility to ensure that the
2910 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
2911 * mandated semantics for out of range shifts.
2913 static void shift_reg(TCGv_i64 dst, TCGv_i64 src, int sf,
2914 enum a64_shift_type shift_type, TCGv_i64 shift_amount)
2916 switch (shift_type) {
2917 case A64_SHIFT_TYPE_LSL:
2918 tcg_gen_shl_i64(dst, src, shift_amount);
2920 case A64_SHIFT_TYPE_LSR:
2921 tcg_gen_shr_i64(dst, src, shift_amount);
2923 case A64_SHIFT_TYPE_ASR:
2925 tcg_gen_ext32s_i64(dst, src);
2927 tcg_gen_sar_i64(dst, sf ? src : dst, shift_amount);
2929 case A64_SHIFT_TYPE_ROR:
2931 tcg_gen_rotr_i64(dst, src, shift_amount);
2934 t0 = tcg_temp_new_i32();
2935 t1 = tcg_temp_new_i32();
2936 tcg_gen_trunc_i64_i32(t0, src);
2937 tcg_gen_trunc_i64_i32(t1, shift_amount);
2938 tcg_gen_rotr_i32(t0, t0, t1);
2939 tcg_gen_extu_i32_i64(dst, t0);
2940 tcg_temp_free_i32(t0);
2941 tcg_temp_free_i32(t1);
2945 assert(FALSE); /* all shift types should be handled */
2949 if (!sf) { /* zero extend final result */
2950 tcg_gen_ext32u_i64(dst, dst);
2954 /* Shift a TCGv src by immediate, put result in dst.
2955 * The shift amount must be in range (this should always be true as the
2956 * relevant instructions will UNDEF on bad shift immediates).
2958 static void shift_reg_imm(TCGv_i64 dst, TCGv_i64 src, int sf,
2959 enum a64_shift_type shift_type, unsigned int shift_i)
2961 assert(shift_i < (sf ? 64 : 32));
2964 tcg_gen_mov_i64(dst, src);
2966 TCGv_i64 shift_const;
2968 shift_const = tcg_const_i64(shift_i);
2969 shift_reg(dst, src, sf, shift_type, shift_const);
2970 tcg_temp_free_i64(shift_const);
2974 /* C3.5.10 Logical (shifted register)
2975 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
2976 * +----+-----+-----------+-------+---+------+--------+------+------+
2977 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
2978 * +----+-----+-----------+-------+---+------+--------+------+------+
2980 static void disas_logic_reg(DisasContext *s, uint32_t insn)
2982 TCGv_i64 tcg_rd, tcg_rn, tcg_rm;
2983 unsigned int sf, opc, shift_type, invert, rm, shift_amount, rn, rd;
2985 sf = extract32(insn, 31, 1);
2986 opc = extract32(insn, 29, 2);
2987 shift_type = extract32(insn, 22, 2);
2988 invert = extract32(insn, 21, 1);
2989 rm = extract32(insn, 16, 5);
2990 shift_amount = extract32(insn, 10, 6);
2991 rn = extract32(insn, 5, 5);
2992 rd = extract32(insn, 0, 5);
2994 if (!sf && (shift_amount & (1 << 5))) {
2995 unallocated_encoding(s);
2999 tcg_rd = cpu_reg(s, rd);
3001 if (opc == 1 && shift_amount == 0 && shift_type == 0 && rn == 31) {
3002 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3003 * register-register MOV and MVN, so it is worth special casing.
3005 tcg_rm = cpu_reg(s, rm);
3007 tcg_gen_not_i64(tcg_rd, tcg_rm);
3009 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3013 tcg_gen_mov_i64(tcg_rd, tcg_rm);
3015 tcg_gen_ext32u_i64(tcg_rd, tcg_rm);
3021 tcg_rm = read_cpu_reg(s, rm, sf);
3024 shift_reg_imm(tcg_rm, tcg_rm, sf, shift_type, shift_amount);
3027 tcg_rn = cpu_reg(s, rn);
3029 switch (opc | (invert << 2)) {
3032 tcg_gen_and_i64(tcg_rd, tcg_rn, tcg_rm);
3035 tcg_gen_or_i64(tcg_rd, tcg_rn, tcg_rm);
3038 tcg_gen_xor_i64(tcg_rd, tcg_rn, tcg_rm);
3042 tcg_gen_andc_i64(tcg_rd, tcg_rn, tcg_rm);
3045 tcg_gen_orc_i64(tcg_rd, tcg_rn, tcg_rm);
3048 tcg_gen_eqv_i64(tcg_rd, tcg_rn, tcg_rm);
3056 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3060 gen_logic_CC(sf, tcg_rd);
3065 * C3.5.1 Add/subtract (extended register)
3067 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3068 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3069 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3070 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3072 * sf: 0 -> 32bit, 1 -> 64bit
3073 * op: 0 -> add , 1 -> sub
3076 * option: extension type (see DecodeRegExtend)
3077 * imm3: optional shift to Rm
3079 * Rd = Rn + LSL(extend(Rm), amount)
3081 static void disas_add_sub_ext_reg(DisasContext *s, uint32_t insn)
3083 int rd = extract32(insn, 0, 5);
3084 int rn = extract32(insn, 5, 5);
3085 int imm3 = extract32(insn, 10, 3);
3086 int option = extract32(insn, 13, 3);
3087 int rm = extract32(insn, 16, 5);
3088 bool setflags = extract32(insn, 29, 1);
3089 bool sub_op = extract32(insn, 30, 1);
3090 bool sf = extract32(insn, 31, 1);
3092 TCGv_i64 tcg_rm, tcg_rn; /* temps */
3094 TCGv_i64 tcg_result;
3097 unallocated_encoding(s);
3101 /* non-flag setting ops may use SP */
3103 tcg_rd = cpu_reg_sp(s, rd);
3105 tcg_rd = cpu_reg(s, rd);
3107 tcg_rn = read_cpu_reg_sp(s, rn, sf);
3109 tcg_rm = read_cpu_reg(s, rm, sf);
3110 ext_and_shift_reg(tcg_rm, tcg_rm, option, imm3);
3112 tcg_result = tcg_temp_new_i64();
3116 tcg_gen_sub_i64(tcg_result, tcg_rn, tcg_rm);
3118 tcg_gen_add_i64(tcg_result, tcg_rn, tcg_rm);
3122 gen_sub_CC(sf, tcg_result, tcg_rn, tcg_rm);
3124 gen_add_CC(sf, tcg_result, tcg_rn, tcg_rm);
3129 tcg_gen_mov_i64(tcg_rd, tcg_result);
3131 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
3134 tcg_temp_free_i64(tcg_result);
3138 * C3.5.2 Add/subtract (shifted register)
3140 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3141 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3142 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3143 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3145 * sf: 0 -> 32bit, 1 -> 64bit
3146 * op: 0 -> add , 1 -> sub
3148 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3149 * imm6: Shift amount to apply to Rm before the add/sub
3151 static void disas_add_sub_reg(DisasContext *s, uint32_t insn)
3153 int rd = extract32(insn, 0, 5);
3154 int rn = extract32(insn, 5, 5);
3155 int imm6 = extract32(insn, 10, 6);
3156 int rm = extract32(insn, 16, 5);
3157 int shift_type = extract32(insn, 22, 2);
3158 bool setflags = extract32(insn, 29, 1);
3159 bool sub_op = extract32(insn, 30, 1);
3160 bool sf = extract32(insn, 31, 1);
3162 TCGv_i64 tcg_rd = cpu_reg(s, rd);
3163 TCGv_i64 tcg_rn, tcg_rm;
3164 TCGv_i64 tcg_result;
3166 if ((shift_type == 3) || (!sf && (imm6 > 31))) {
3167 unallocated_encoding(s);
3171 tcg_rn = read_cpu_reg(s, rn, sf);
3172 tcg_rm = read_cpu_reg(s, rm, sf);
3174 shift_reg_imm(tcg_rm, tcg_rm, sf, shift_type, imm6);
3176 tcg_result = tcg_temp_new_i64();
3180 tcg_gen_sub_i64(tcg_result, tcg_rn, tcg_rm);
3182 tcg_gen_add_i64(tcg_result, tcg_rn, tcg_rm);
3186 gen_sub_CC(sf, tcg_result, tcg_rn, tcg_rm);
3188 gen_add_CC(sf, tcg_result, tcg_rn, tcg_rm);
3193 tcg_gen_mov_i64(tcg_rd, tcg_result);
3195 tcg_gen_ext32u_i64(tcg_rd, tcg_result);
3198 tcg_temp_free_i64(tcg_result);
3201 /* C3.5.9 Data-processing (3 source)
3203 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3204 +--+------+-----------+------+------+----+------+------+------+
3205 |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3206 +--+------+-----------+------+------+----+------+------+------+
3209 static void disas_data_proc_3src(DisasContext *s, uint32_t insn)
3211 int rd = extract32(insn, 0, 5);
3212 int rn = extract32(insn, 5, 5);
3213 int ra = extract32(insn, 10, 5);
3214 int rm = extract32(insn, 16, 5);
3215 int op_id = (extract32(insn, 29, 3) << 4) |
3216 (extract32(insn, 21, 3) << 1) |
3217 extract32(insn, 15, 1);
3218 bool sf = extract32(insn, 31, 1);
3219 bool is_sub = extract32(op_id, 0, 1);
3220 bool is_high = extract32(op_id, 2, 1);
3221 bool is_signed = false;
3226 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
3228 case 0x42: /* SMADDL */
3229 case 0x43: /* SMSUBL */
3230 case 0x44: /* SMULH */
3233 case 0x0: /* MADD (32bit) */
3234 case 0x1: /* MSUB (32bit) */
3235 case 0x40: /* MADD (64bit) */
3236 case 0x41: /* MSUB (64bit) */
3237 case 0x4a: /* UMADDL */
3238 case 0x4b: /* UMSUBL */
3239 case 0x4c: /* UMULH */
3242 unallocated_encoding(s);
3247 TCGv_i64 low_bits = tcg_temp_new_i64(); /* low bits discarded */
3248 TCGv_i64 tcg_rd = cpu_reg(s, rd);
3249 TCGv_i64 tcg_rn = cpu_reg(s, rn);
3250 TCGv_i64 tcg_rm = cpu_reg(s, rm);
3253 tcg_gen_muls2_i64(low_bits, tcg_rd, tcg_rn, tcg_rm);
3255 tcg_gen_mulu2_i64(low_bits, tcg_rd, tcg_rn, tcg_rm);
3258 tcg_temp_free_i64(low_bits);
3262 tcg_op1 = tcg_temp_new_i64();
3263 tcg_op2 = tcg_temp_new_i64();
3264 tcg_tmp = tcg_temp_new_i64();
3267 tcg_gen_mov_i64(tcg_op1, cpu_reg(s, rn));
3268 tcg_gen_mov_i64(tcg_op2, cpu_reg(s, rm));
3271 tcg_gen_ext32s_i64(tcg_op1, cpu_reg(s, rn));
3272 tcg_gen_ext32s_i64(tcg_op2, cpu_reg(s, rm));
3274 tcg_gen_ext32u_i64(tcg_op1, cpu_reg(s, rn));
3275 tcg_gen_ext32u_i64(tcg_op2, cpu_reg(s, rm));
3279 if (ra == 31 && !is_sub) {
3280 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
3281 tcg_gen_mul_i64(cpu_reg(s, rd), tcg_op1, tcg_op2);
3283 tcg_gen_mul_i64(tcg_tmp, tcg_op1, tcg_op2);
3285 tcg_gen_sub_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
3287 tcg_gen_add_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
3292 tcg_gen_ext32u_i64(cpu_reg(s, rd), cpu_reg(s, rd));
3295 tcg_temp_free_i64(tcg_op1);
3296 tcg_temp_free_i64(tcg_op2);
3297 tcg_temp_free_i64(tcg_tmp);
3300 /* C3.5.3 - Add/subtract (with carry)
3301 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
3302 * +--+--+--+------------------------+------+---------+------+-----+
3303 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
3304 * +--+--+--+------------------------+------+---------+------+-----+
3308 static void disas_adc_sbc(DisasContext *s, uint32_t insn)
3310 unsigned int sf, op, setflags, rm, rn, rd;
3311 TCGv_i64 tcg_y, tcg_rn, tcg_rd;
3313 if (extract32(insn, 10, 6) != 0) {
3314 unallocated_encoding(s);
3318 sf = extract32(insn, 31, 1);
3319 op = extract32(insn, 30, 1);
3320 setflags = extract32(insn, 29, 1);
3321 rm = extract32(insn, 16, 5);
3322 rn = extract32(insn, 5, 5);
3323 rd = extract32(insn, 0, 5);
3325 tcg_rd = cpu_reg(s, rd);
3326 tcg_rn = cpu_reg(s, rn);
3329 tcg_y = new_tmp_a64(s);
3330 tcg_gen_not_i64(tcg_y, cpu_reg(s, rm));
3332 tcg_y = cpu_reg(s, rm);
3336 gen_adc_CC(sf, tcg_rd, tcg_rn, tcg_y);
3338 gen_adc(sf, tcg_rd, tcg_rn, tcg_y);
3342 /* C3.5.4 - C3.5.5 Conditional compare (immediate / register)
3343 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3344 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3345 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
3346 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3349 static void disas_cc(DisasContext *s, uint32_t insn)
3351 unsigned int sf, op, y, cond, rn, nzcv, is_imm;
3352 int label_continue = -1;
3353 TCGv_i64 tcg_tmp, tcg_y, tcg_rn;
3355 if (!extract32(insn, 29, 1)) {
3356 unallocated_encoding(s);
3359 if (insn & (1 << 10 | 1 << 4)) {
3360 unallocated_encoding(s);
3363 sf = extract32(insn, 31, 1);
3364 op = extract32(insn, 30, 1);
3365 is_imm = extract32(insn, 11, 1);
3366 y = extract32(insn, 16, 5); /* y = rm (reg) or imm5 (imm) */
3367 cond = extract32(insn, 12, 4);
3368 rn = extract32(insn, 5, 5);
3369 nzcv = extract32(insn, 0, 4);
3371 if (cond < 0x0e) { /* not always */
3372 int label_match = gen_new_label();
3373 label_continue = gen_new_label();
3374 arm_gen_test_cc(cond, label_match);
3376 tcg_tmp = tcg_temp_new_i64();
3377 tcg_gen_movi_i64(tcg_tmp, nzcv << 28);
3378 gen_set_nzcv(tcg_tmp);
3379 tcg_temp_free_i64(tcg_tmp);
3380 tcg_gen_br(label_continue);
3381 gen_set_label(label_match);
3383 /* match, or condition is always */
3385 tcg_y = new_tmp_a64(s);
3386 tcg_gen_movi_i64(tcg_y, y);
3388 tcg_y = cpu_reg(s, y);
3390 tcg_rn = cpu_reg(s, rn);
3392 tcg_tmp = tcg_temp_new_i64();
3394 gen_sub_CC(sf, tcg_tmp, tcg_rn, tcg_y);
3396 gen_add_CC(sf, tcg_tmp, tcg_rn, tcg_y);
3398 tcg_temp_free_i64(tcg_tmp);
3400 if (cond < 0x0e) { /* continue */
3401 gen_set_label(label_continue);
3405 /* C3.5.6 Conditional select
3406 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
3407 * +----+----+---+-----------------+------+------+-----+------+------+
3408 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
3409 * +----+----+---+-----------------+------+------+-----+------+------+
3411 static void disas_cond_select(DisasContext *s, uint32_t insn)
3413 unsigned int sf, else_inv, rm, cond, else_inc, rn, rd;
3414 TCGv_i64 tcg_rd, tcg_src;
3416 if (extract32(insn, 29, 1) || extract32(insn, 11, 1)) {
3417 /* S == 1 or op2<1> == 1 */
3418 unallocated_encoding(s);
3421 sf = extract32(insn, 31, 1);
3422 else_inv = extract32(insn, 30, 1);
3423 rm = extract32(insn, 16, 5);
3424 cond = extract32(insn, 12, 4);
3425 else_inc = extract32(insn, 10, 1);
3426 rn = extract32(insn, 5, 5);
3427 rd = extract32(insn, 0, 5);
3430 /* silly no-op write; until we use movcond we must special-case
3431 * this to avoid a dead temporary across basic blocks.
3436 tcg_rd = cpu_reg(s, rd);
3438 if (cond >= 0x0e) { /* condition "always" */
3439 tcg_src = read_cpu_reg(s, rn, sf);
3440 tcg_gen_mov_i64(tcg_rd, tcg_src);
3442 /* OPTME: we could use movcond here, at the cost of duplicating
3443 * a lot of the arm_gen_test_cc() logic.
3445 int label_match = gen_new_label();
3446 int label_continue = gen_new_label();
3448 arm_gen_test_cc(cond, label_match);
3450 tcg_src = cpu_reg(s, rm);
3452 if (else_inv && else_inc) {
3453 tcg_gen_neg_i64(tcg_rd, tcg_src);
3454 } else if (else_inv) {
3455 tcg_gen_not_i64(tcg_rd, tcg_src);
3456 } else if (else_inc) {
3457 tcg_gen_addi_i64(tcg_rd, tcg_src, 1);
3459 tcg_gen_mov_i64(tcg_rd, tcg_src);
3462 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3464 tcg_gen_br(label_continue);
3466 gen_set_label(label_match);
3467 tcg_src = read_cpu_reg(s, rn, sf);
3468 tcg_gen_mov_i64(tcg_rd, tcg_src);
3470 gen_set_label(label_continue);
3474 static void handle_clz(DisasContext *s, unsigned int sf,
3475 unsigned int rn, unsigned int rd)
3477 TCGv_i64 tcg_rd, tcg_rn;
3478 tcg_rd = cpu_reg(s, rd);
3479 tcg_rn = cpu_reg(s, rn);
3482 gen_helper_clz64(tcg_rd, tcg_rn);
3484 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
3485 tcg_gen_trunc_i64_i32(tcg_tmp32, tcg_rn);
3486 gen_helper_clz(tcg_tmp32, tcg_tmp32);
3487 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
3488 tcg_temp_free_i32(tcg_tmp32);
3492 static void handle_cls(DisasContext *s, unsigned int sf,
3493 unsigned int rn, unsigned int rd)
3495 TCGv_i64 tcg_rd, tcg_rn;
3496 tcg_rd = cpu_reg(s, rd);
3497 tcg_rn = cpu_reg(s, rn);
3500 gen_helper_cls64(tcg_rd, tcg_rn);
3502 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
3503 tcg_gen_trunc_i64_i32(tcg_tmp32, tcg_rn);
3504 gen_helper_cls32(tcg_tmp32, tcg_tmp32);
3505 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
3506 tcg_temp_free_i32(tcg_tmp32);
3510 static void handle_rbit(DisasContext *s, unsigned int sf,
3511 unsigned int rn, unsigned int rd)
3513 TCGv_i64 tcg_rd, tcg_rn;
3514 tcg_rd = cpu_reg(s, rd);
3515 tcg_rn = cpu_reg(s, rn);
3518 gen_helper_rbit64(tcg_rd, tcg_rn);
3520 TCGv_i32 tcg_tmp32 = tcg_temp_new_i32();
3521 tcg_gen_trunc_i64_i32(tcg_tmp32, tcg_rn);
3522 gen_helper_rbit(tcg_tmp32, tcg_tmp32);
3523 tcg_gen_extu_i32_i64(tcg_rd, tcg_tmp32);
3524 tcg_temp_free_i32(tcg_tmp32);
3528 /* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
3529 static void handle_rev64(DisasContext *s, unsigned int sf,
3530 unsigned int rn, unsigned int rd)
3533 unallocated_encoding(s);
3536 tcg_gen_bswap64_i64(cpu_reg(s, rd), cpu_reg(s, rn));
3539 /* C5.6.149 REV with sf==0, opcode==2
3540 * C5.6.151 REV32 (sf==1, opcode==2)
3542 static void handle_rev32(DisasContext *s, unsigned int sf,
3543 unsigned int rn, unsigned int rd)
3545 TCGv_i64 tcg_rd = cpu_reg(s, rd);
3548 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
3549 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
3551 /* bswap32_i64 requires zero high word */
3552 tcg_gen_ext32u_i64(tcg_tmp, tcg_rn);
3553 tcg_gen_bswap32_i64(tcg_rd, tcg_tmp);
3554 tcg_gen_shri_i64(tcg_tmp, tcg_rn, 32);
3555 tcg_gen_bswap32_i64(tcg_tmp, tcg_tmp);
3556 tcg_gen_concat32_i64(tcg_rd, tcg_rd, tcg_tmp);
3558 tcg_temp_free_i64(tcg_tmp);
3560 tcg_gen_ext32u_i64(tcg_rd, cpu_reg(s, rn));
3561 tcg_gen_bswap32_i64(tcg_rd, tcg_rd);
3565 /* C5.6.150 REV16 (opcode==1) */
3566 static void handle_rev16(DisasContext *s, unsigned int sf,
3567 unsigned int rn, unsigned int rd)
3569 TCGv_i64 tcg_rd = cpu_reg(s, rd);
3570 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
3571 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
3573 tcg_gen_andi_i64(tcg_tmp, tcg_rn, 0xffff);
3574 tcg_gen_bswap16_i64(tcg_rd, tcg_tmp);
3576 tcg_gen_shri_i64(tcg_tmp, tcg_rn, 16);
3577 tcg_gen_andi_i64(tcg_tmp, tcg_tmp, 0xffff);
3578 tcg_gen_bswap16_i64(tcg_tmp, tcg_tmp);
3579 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_tmp, 16, 16);
3582 tcg_gen_shri_i64(tcg_tmp, tcg_rn, 32);
3583 tcg_gen_andi_i64(tcg_tmp, tcg_tmp, 0xffff);
3584 tcg_gen_bswap16_i64(tcg_tmp, tcg_tmp);
3585 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_tmp, 32, 16);
3587 tcg_gen_shri_i64(tcg_tmp, tcg_rn, 48);
3588 tcg_gen_bswap16_i64(tcg_tmp, tcg_tmp);
3589 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_tmp, 48, 16);
3592 tcg_temp_free_i64(tcg_tmp);
3595 /* C3.5.7 Data-processing (1 source)
3596 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3597 * +----+---+---+-----------------+---------+--------+------+------+
3598 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
3599 * +----+---+---+-----------------+---------+--------+------+------+
3601 static void disas_data_proc_1src(DisasContext *s, uint32_t insn)
3603 unsigned int sf, opcode, rn, rd;
3605 if (extract32(insn, 29, 1) || extract32(insn, 16, 5)) {
3606 unallocated_encoding(s);
3610 sf = extract32(insn, 31, 1);
3611 opcode = extract32(insn, 10, 6);
3612 rn = extract32(insn, 5, 5);
3613 rd = extract32(insn, 0, 5);
3617 handle_rbit(s, sf, rn, rd);
3620 handle_rev16(s, sf, rn, rd);
3623 handle_rev32(s, sf, rn, rd);
3626 handle_rev64(s, sf, rn, rd);
3629 handle_clz(s, sf, rn, rd);
3632 handle_cls(s, sf, rn, rd);
3637 static void handle_div(DisasContext *s, bool is_signed, unsigned int sf,
3638 unsigned int rm, unsigned int rn, unsigned int rd)
3640 TCGv_i64 tcg_n, tcg_m, tcg_rd;
3641 tcg_rd = cpu_reg(s, rd);
3643 if (!sf && is_signed) {
3644 tcg_n = new_tmp_a64(s);
3645 tcg_m = new_tmp_a64(s);
3646 tcg_gen_ext32s_i64(tcg_n, cpu_reg(s, rn));
3647 tcg_gen_ext32s_i64(tcg_m, cpu_reg(s, rm));
3649 tcg_n = read_cpu_reg(s, rn, sf);
3650 tcg_m = read_cpu_reg(s, rm, sf);
3654 gen_helper_sdiv64(tcg_rd, tcg_n, tcg_m);
3656 gen_helper_udiv64(tcg_rd, tcg_n, tcg_m);
3659 if (!sf) { /* zero extend final result */
3660 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
3664 /* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
3665 static void handle_shift_reg(DisasContext *s,
3666 enum a64_shift_type shift_type, unsigned int sf,
3667 unsigned int rm, unsigned int rn, unsigned int rd)
3669 TCGv_i64 tcg_shift = tcg_temp_new_i64();
3670 TCGv_i64 tcg_rd = cpu_reg(s, rd);
3671 TCGv_i64 tcg_rn = read_cpu_reg(s, rn, sf);
3673 tcg_gen_andi_i64(tcg_shift, cpu_reg(s, rm), sf ? 63 : 31);
3674 shift_reg(tcg_rd, tcg_rn, sf, shift_type, tcg_shift);
3675 tcg_temp_free_i64(tcg_shift);
3678 /* C3.5.8 Data-processing (2 source)
3679 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3680 * +----+---+---+-----------------+------+--------+------+------+
3681 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
3682 * +----+---+---+-----------------+------+--------+------+------+
3684 static void disas_data_proc_2src(DisasContext *s, uint32_t insn)
3686 unsigned int sf, rm, opcode, rn, rd;
3687 sf = extract32(insn, 31, 1);
3688 rm = extract32(insn, 16, 5);
3689 opcode = extract32(insn, 10, 6);
3690 rn = extract32(insn, 5, 5);
3691 rd = extract32(insn, 0, 5);
3693 if (extract32(insn, 29, 1)) {
3694 unallocated_encoding(s);
3700 handle_div(s, false, sf, rm, rn, rd);
3703 handle_div(s, true, sf, rm, rn, rd);
3706 handle_shift_reg(s, A64_SHIFT_TYPE_LSL, sf, rm, rn, rd);
3709 handle_shift_reg(s, A64_SHIFT_TYPE_LSR, sf, rm, rn, rd);
3712 handle_shift_reg(s, A64_SHIFT_TYPE_ASR, sf, rm, rn, rd);
3715 handle_shift_reg(s, A64_SHIFT_TYPE_ROR, sf, rm, rn, rd);
3724 case 23: /* CRC32 */
3725 unsupported_encoding(s, insn);
3728 unallocated_encoding(s);
3733 /* C3.5 Data processing - register */
3734 static void disas_data_proc_reg(DisasContext *s, uint32_t insn)
3736 switch (extract32(insn, 24, 5)) {
3737 case 0x0a: /* Logical (shifted register) */
3738 disas_logic_reg(s, insn);
3740 case 0x0b: /* Add/subtract */
3741 if (insn & (1 << 21)) { /* (extended register) */
3742 disas_add_sub_ext_reg(s, insn);
3744 disas_add_sub_reg(s, insn);
3747 case 0x1b: /* Data-processing (3 source) */
3748 disas_data_proc_3src(s, insn);
3751 switch (extract32(insn, 21, 3)) {
3752 case 0x0: /* Add/subtract (with carry) */
3753 disas_adc_sbc(s, insn);
3755 case 0x2: /* Conditional compare */
3756 disas_cc(s, insn); /* both imm and reg forms */
3758 case 0x4: /* Conditional select */
3759 disas_cond_select(s, insn);
3761 case 0x6: /* Data-processing */
3762 if (insn & (1 << 30)) { /* (1 source) */
3763 disas_data_proc_1src(s, insn);
3764 } else { /* (2 source) */
3765 disas_data_proc_2src(s, insn);
3769 unallocated_encoding(s);
3774 unallocated_encoding(s);
3779 static void handle_fp_compare(DisasContext *s, bool is_double,
3780 unsigned int rn, unsigned int rm,
3781 bool cmp_with_zero, bool signal_all_nans)
3783 TCGv_i64 tcg_flags = tcg_temp_new_i64();
3784 TCGv_ptr fpst = get_fpstatus_ptr();
3787 TCGv_i64 tcg_vn, tcg_vm;
3789 tcg_vn = read_fp_dreg(s, rn);
3790 if (cmp_with_zero) {
3791 tcg_vm = tcg_const_i64(0);
3793 tcg_vm = read_fp_dreg(s, rm);
3795 if (signal_all_nans) {
3796 gen_helper_vfp_cmped_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
3798 gen_helper_vfp_cmpd_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
3800 tcg_temp_free_i64(tcg_vn);
3801 tcg_temp_free_i64(tcg_vm);
3803 TCGv_i32 tcg_vn, tcg_vm;
3805 tcg_vn = read_fp_sreg(s, rn);
3806 if (cmp_with_zero) {
3807 tcg_vm = tcg_const_i32(0);
3809 tcg_vm = read_fp_sreg(s, rm);
3811 if (signal_all_nans) {
3812 gen_helper_vfp_cmpes_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
3814 gen_helper_vfp_cmps_a64(tcg_flags, tcg_vn, tcg_vm, fpst);
3816 tcg_temp_free_i32(tcg_vn);
3817 tcg_temp_free_i32(tcg_vm);
3820 tcg_temp_free_ptr(fpst);
3822 gen_set_nzcv(tcg_flags);
3824 tcg_temp_free_i64(tcg_flags);
3827 /* C3.6.22 Floating point compare
3828 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
3829 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
3830 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
3831 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
3833 static void disas_fp_compare(DisasContext *s, uint32_t insn)
3835 unsigned int mos, type, rm, op, rn, opc, op2r;
3837 mos = extract32(insn, 29, 3);
3838 type = extract32(insn, 22, 2); /* 0 = single, 1 = double */
3839 rm = extract32(insn, 16, 5);
3840 op = extract32(insn, 14, 2);
3841 rn = extract32(insn, 5, 5);
3842 opc = extract32(insn, 3, 2);
3843 op2r = extract32(insn, 0, 3);
3845 if (mos || op || op2r || type > 1) {
3846 unallocated_encoding(s);
3850 handle_fp_compare(s, type, rn, rm, opc & 1, opc & 2);
3853 /* C3.6.23 Floating point conditional compare
3854 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3855 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
3856 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
3857 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
3859 static void disas_fp_ccomp(DisasContext *s, uint32_t insn)
3861 unsigned int mos, type, rm, cond, rn, op, nzcv;
3863 int label_continue = -1;
3865 mos = extract32(insn, 29, 3);
3866 type = extract32(insn, 22, 2); /* 0 = single, 1 = double */
3867 rm = extract32(insn, 16, 5);
3868 cond = extract32(insn, 12, 4);
3869 rn = extract32(insn, 5, 5);
3870 op = extract32(insn, 4, 1);
3871 nzcv = extract32(insn, 0, 4);
3873 if (mos || type > 1) {
3874 unallocated_encoding(s);
3878 if (cond < 0x0e) { /* not always */
3879 int label_match = gen_new_label();
3880 label_continue = gen_new_label();
3881 arm_gen_test_cc(cond, label_match);
3883 tcg_flags = tcg_const_i64(nzcv << 28);
3884 gen_set_nzcv(tcg_flags);
3885 tcg_temp_free_i64(tcg_flags);
3886 tcg_gen_br(label_continue);
3887 gen_set_label(label_match);
3890 handle_fp_compare(s, type, rn, rm, false, op);
3893 gen_set_label(label_continue);
3897 /* copy src FP register to dst FP register; type specifies single or double */
3898 static void gen_mov_fp2fp(DisasContext *s, int type, int dst, int src)
3901 TCGv_i64 v = read_fp_dreg(s, src);
3902 write_fp_dreg(s, dst, v);
3903 tcg_temp_free_i64(v);
3905 TCGv_i32 v = read_fp_sreg(s, src);
3906 write_fp_sreg(s, dst, v);
3907 tcg_temp_free_i32(v);
3911 /* C3.6.24 Floating point conditional select
3912 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
3913 * +---+---+---+-----------+------+---+------+------+-----+------+------+
3914 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
3915 * +---+---+---+-----------+------+---+------+------+-----+------+------+
3917 static void disas_fp_csel(DisasContext *s, uint32_t insn)
3919 unsigned int mos, type, rm, cond, rn, rd;
3920 int label_continue = -1;
3922 mos = extract32(insn, 29, 3);
3923 type = extract32(insn, 22, 2); /* 0 = single, 1 = double */
3924 rm = extract32(insn, 16, 5);
3925 cond = extract32(insn, 12, 4);
3926 rn = extract32(insn, 5, 5);
3927 rd = extract32(insn, 0, 5);
3929 if (mos || type > 1) {
3930 unallocated_encoding(s);
3934 if (cond < 0x0e) { /* not always */
3935 int label_match = gen_new_label();
3936 label_continue = gen_new_label();
3937 arm_gen_test_cc(cond, label_match);
3939 gen_mov_fp2fp(s, type, rd, rm);
3940 tcg_gen_br(label_continue);
3941 gen_set_label(label_match);
3944 gen_mov_fp2fp(s, type, rd, rn);
3946 if (cond < 0x0e) { /* continue */
3947 gen_set_label(label_continue);
3951 /* C3.6.25 Floating-point data-processing (1 source) - single precision */
3952 static void handle_fp_1src_single(DisasContext *s, int opcode, int rd, int rn)
3958 fpst = get_fpstatus_ptr();
3959 tcg_op = read_fp_sreg(s, rn);
3960 tcg_res = tcg_temp_new_i32();
3963 case 0x0: /* FMOV */
3964 tcg_gen_mov_i32(tcg_res, tcg_op);
3966 case 0x1: /* FABS */
3967 gen_helper_vfp_abss(tcg_res, tcg_op);
3969 case 0x2: /* FNEG */
3970 gen_helper_vfp_negs(tcg_res, tcg_op);
3972 case 0x3: /* FSQRT */
3973 gen_helper_vfp_sqrts(tcg_res, tcg_op, cpu_env);
3975 case 0x8: /* FRINTN */
3976 case 0x9: /* FRINTP */
3977 case 0xa: /* FRINTM */
3978 case 0xb: /* FRINTZ */
3979 case 0xc: /* FRINTA */
3981 TCGv_i32 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(opcode & 7));
3983 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
3984 gen_helper_rints(tcg_res, tcg_op, fpst);
3986 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
3987 tcg_temp_free_i32(tcg_rmode);
3990 case 0xe: /* FRINTX */
3991 gen_helper_rints_exact(tcg_res, tcg_op, fpst);
3993 case 0xf: /* FRINTI */
3994 gen_helper_rints(tcg_res, tcg_op, fpst);
4000 write_fp_sreg(s, rd, tcg_res);
4002 tcg_temp_free_ptr(fpst);
4003 tcg_temp_free_i32(tcg_op);
4004 tcg_temp_free_i32(tcg_res);
4007 /* C3.6.25 Floating-point data-processing (1 source) - double precision */
4008 static void handle_fp_1src_double(DisasContext *s, int opcode, int rd, int rn)
4014 fpst = get_fpstatus_ptr();
4015 tcg_op = read_fp_dreg(s, rn);
4016 tcg_res = tcg_temp_new_i64();
4019 case 0x0: /* FMOV */
4020 tcg_gen_mov_i64(tcg_res, tcg_op);
4022 case 0x1: /* FABS */
4023 gen_helper_vfp_absd(tcg_res, tcg_op);
4025 case 0x2: /* FNEG */
4026 gen_helper_vfp_negd(tcg_res, tcg_op);
4028 case 0x3: /* FSQRT */
4029 gen_helper_vfp_sqrtd(tcg_res, tcg_op, cpu_env);
4031 case 0x8: /* FRINTN */
4032 case 0x9: /* FRINTP */
4033 case 0xa: /* FRINTM */
4034 case 0xb: /* FRINTZ */
4035 case 0xc: /* FRINTA */
4037 TCGv_i32 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(opcode & 7));
4039 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
4040 gen_helper_rintd(tcg_res, tcg_op, fpst);
4042 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
4043 tcg_temp_free_i32(tcg_rmode);
4046 case 0xe: /* FRINTX */
4047 gen_helper_rintd_exact(tcg_res, tcg_op, fpst);
4049 case 0xf: /* FRINTI */
4050 gen_helper_rintd(tcg_res, tcg_op, fpst);
4056 write_fp_dreg(s, rd, tcg_res);
4058 tcg_temp_free_ptr(fpst);
4059 tcg_temp_free_i64(tcg_op);
4060 tcg_temp_free_i64(tcg_res);
4063 static void handle_fp_fcvt(DisasContext *s, int opcode,
4064 int rd, int rn, int dtype, int ntype)
4069 TCGv_i32 tcg_rn = read_fp_sreg(s, rn);
4071 /* Single to double */
4072 TCGv_i64 tcg_rd = tcg_temp_new_i64();
4073 gen_helper_vfp_fcvtds(tcg_rd, tcg_rn, cpu_env);
4074 write_fp_dreg(s, rd, tcg_rd);
4075 tcg_temp_free_i64(tcg_rd);
4077 /* Single to half */
4078 TCGv_i32 tcg_rd = tcg_temp_new_i32();
4079 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd, tcg_rn, cpu_env);
4080 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4081 write_fp_sreg(s, rd, tcg_rd);
4082 tcg_temp_free_i32(tcg_rd);
4084 tcg_temp_free_i32(tcg_rn);
4089 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
4090 TCGv_i32 tcg_rd = tcg_temp_new_i32();
4092 /* Double to single */
4093 gen_helper_vfp_fcvtsd(tcg_rd, tcg_rn, cpu_env);
4095 /* Double to half */
4096 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd, tcg_rn, cpu_env);
4097 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4099 write_fp_sreg(s, rd, tcg_rd);
4100 tcg_temp_free_i32(tcg_rd);
4101 tcg_temp_free_i64(tcg_rn);
4106 TCGv_i32 tcg_rn = read_fp_sreg(s, rn);
4107 tcg_gen_ext16u_i32(tcg_rn, tcg_rn);
4109 /* Half to single */
4110 TCGv_i32 tcg_rd = tcg_temp_new_i32();
4111 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd, tcg_rn, cpu_env);
4112 write_fp_sreg(s, rd, tcg_rd);
4113 tcg_temp_free_i32(tcg_rd);
4115 /* Half to double */
4116 TCGv_i64 tcg_rd = tcg_temp_new_i64();
4117 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd, tcg_rn, cpu_env);
4118 write_fp_dreg(s, rd, tcg_rd);
4119 tcg_temp_free_i64(tcg_rd);
4121 tcg_temp_free_i32(tcg_rn);
4129 /* C3.6.25 Floating point data-processing (1 source)
4130 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
4131 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4132 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
4133 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4135 static void disas_fp_1src(DisasContext *s, uint32_t insn)
4137 int type = extract32(insn, 22, 2);
4138 int opcode = extract32(insn, 15, 6);
4139 int rn = extract32(insn, 5, 5);
4140 int rd = extract32(insn, 0, 5);
4143 case 0x4: case 0x5: case 0x7:
4145 /* FCVT between half, single and double precision */
4146 int dtype = extract32(opcode, 0, 2);
4147 if (type == 2 || dtype == type) {
4148 unallocated_encoding(s);
4151 handle_fp_fcvt(s, opcode, rd, rn, dtype, type);
4157 /* 32-to-32 and 64-to-64 ops */
4160 handle_fp_1src_single(s, opcode, rd, rn);
4163 handle_fp_1src_double(s, opcode, rd, rn);
4166 unallocated_encoding(s);
4170 unallocated_encoding(s);
4175 /* C3.6.26 Floating-point data-processing (2 source) - single precision */
4176 static void handle_fp_2src_single(DisasContext *s, int opcode,
4177 int rd, int rn, int rm)
4184 tcg_res = tcg_temp_new_i32();
4185 fpst = get_fpstatus_ptr();
4186 tcg_op1 = read_fp_sreg(s, rn);
4187 tcg_op2 = read_fp_sreg(s, rm);
4190 case 0x0: /* FMUL */
4191 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
4193 case 0x1: /* FDIV */
4194 gen_helper_vfp_divs(tcg_res, tcg_op1, tcg_op2, fpst);
4196 case 0x2: /* FADD */
4197 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
4199 case 0x3: /* FSUB */
4200 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
4202 case 0x4: /* FMAX */
4203 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
4205 case 0x5: /* FMIN */
4206 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
4208 case 0x6: /* FMAXNM */
4209 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
4211 case 0x7: /* FMINNM */
4212 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
4214 case 0x8: /* FNMUL */
4215 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
4216 gen_helper_vfp_negs(tcg_res, tcg_res);
4220 write_fp_sreg(s, rd, tcg_res);
4222 tcg_temp_free_ptr(fpst);
4223 tcg_temp_free_i32(tcg_op1);
4224 tcg_temp_free_i32(tcg_op2);
4225 tcg_temp_free_i32(tcg_res);
4228 /* C3.6.26 Floating-point data-processing (2 source) - double precision */
4229 static void handle_fp_2src_double(DisasContext *s, int opcode,
4230 int rd, int rn, int rm)
4237 tcg_res = tcg_temp_new_i64();
4238 fpst = get_fpstatus_ptr();
4239 tcg_op1 = read_fp_dreg(s, rn);
4240 tcg_op2 = read_fp_dreg(s, rm);
4243 case 0x0: /* FMUL */
4244 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
4246 case 0x1: /* FDIV */
4247 gen_helper_vfp_divd(tcg_res, tcg_op1, tcg_op2, fpst);
4249 case 0x2: /* FADD */
4250 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
4252 case 0x3: /* FSUB */
4253 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
4255 case 0x4: /* FMAX */
4256 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
4258 case 0x5: /* FMIN */
4259 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
4261 case 0x6: /* FMAXNM */
4262 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
4264 case 0x7: /* FMINNM */
4265 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
4267 case 0x8: /* FNMUL */
4268 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
4269 gen_helper_vfp_negd(tcg_res, tcg_res);
4273 write_fp_dreg(s, rd, tcg_res);
4275 tcg_temp_free_ptr(fpst);
4276 tcg_temp_free_i64(tcg_op1);
4277 tcg_temp_free_i64(tcg_op2);
4278 tcg_temp_free_i64(tcg_res);
4281 /* C3.6.26 Floating point data-processing (2 source)
4282 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4283 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4284 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
4285 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4287 static void disas_fp_2src(DisasContext *s, uint32_t insn)
4289 int type = extract32(insn, 22, 2);
4290 int rd = extract32(insn, 0, 5);
4291 int rn = extract32(insn, 5, 5);
4292 int rm = extract32(insn, 16, 5);
4293 int opcode = extract32(insn, 12, 4);
4296 unallocated_encoding(s);
4302 handle_fp_2src_single(s, opcode, rd, rn, rm);
4305 handle_fp_2src_double(s, opcode, rd, rn, rm);
4308 unallocated_encoding(s);
4312 /* C3.6.27 Floating-point data-processing (3 source) - single precision */
4313 static void handle_fp_3src_single(DisasContext *s, bool o0, bool o1,
4314 int rd, int rn, int rm, int ra)
4316 TCGv_i32 tcg_op1, tcg_op2, tcg_op3;
4317 TCGv_i32 tcg_res = tcg_temp_new_i32();
4318 TCGv_ptr fpst = get_fpstatus_ptr();
4320 tcg_op1 = read_fp_sreg(s, rn);
4321 tcg_op2 = read_fp_sreg(s, rm);
4322 tcg_op3 = read_fp_sreg(s, ra);
4324 /* These are fused multiply-add, and must be done as one
4325 * floating point operation with no rounding between the
4326 * multiplication and addition steps.
4327 * NB that doing the negations here as separate steps is
4328 * correct : an input NaN should come out with its sign bit
4329 * flipped if it is a negated-input.
4332 gen_helper_vfp_negs(tcg_op3, tcg_op3);
4336 gen_helper_vfp_negs(tcg_op1, tcg_op1);
4339 gen_helper_vfp_muladds(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
4341 write_fp_sreg(s, rd, tcg_res);
4343 tcg_temp_free_ptr(fpst);
4344 tcg_temp_free_i32(tcg_op1);
4345 tcg_temp_free_i32(tcg_op2);
4346 tcg_temp_free_i32(tcg_op3);
4347 tcg_temp_free_i32(tcg_res);
4350 /* C3.6.27 Floating-point data-processing (3 source) - double precision */
4351 static void handle_fp_3src_double(DisasContext *s, bool o0, bool o1,
4352 int rd, int rn, int rm, int ra)
4354 TCGv_i64 tcg_op1, tcg_op2, tcg_op3;
4355 TCGv_i64 tcg_res = tcg_temp_new_i64();
4356 TCGv_ptr fpst = get_fpstatus_ptr();
4358 tcg_op1 = read_fp_dreg(s, rn);
4359 tcg_op2 = read_fp_dreg(s, rm);
4360 tcg_op3 = read_fp_dreg(s, ra);
4362 /* These are fused multiply-add, and must be done as one
4363 * floating point operation with no rounding between the
4364 * multiplication and addition steps.
4365 * NB that doing the negations here as separate steps is
4366 * correct : an input NaN should come out with its sign bit
4367 * flipped if it is a negated-input.
4370 gen_helper_vfp_negd(tcg_op3, tcg_op3);
4374 gen_helper_vfp_negd(tcg_op1, tcg_op1);
4377 gen_helper_vfp_muladdd(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst);
4379 write_fp_dreg(s, rd, tcg_res);
4381 tcg_temp_free_ptr(fpst);
4382 tcg_temp_free_i64(tcg_op1);
4383 tcg_temp_free_i64(tcg_op2);
4384 tcg_temp_free_i64(tcg_op3);
4385 tcg_temp_free_i64(tcg_res);
4388 /* C3.6.27 Floating point data-processing (3 source)
4389 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
4390 * +---+---+---+-----------+------+----+------+----+------+------+------+
4391 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
4392 * +---+---+---+-----------+------+----+------+----+------+------+------+
4394 static void disas_fp_3src(DisasContext *s, uint32_t insn)
4396 int type = extract32(insn, 22, 2);
4397 int rd = extract32(insn, 0, 5);
4398 int rn = extract32(insn, 5, 5);
4399 int ra = extract32(insn, 10, 5);
4400 int rm = extract32(insn, 16, 5);
4401 bool o0 = extract32(insn, 15, 1);
4402 bool o1 = extract32(insn, 21, 1);
4406 handle_fp_3src_single(s, o0, o1, rd, rn, rm, ra);
4409 handle_fp_3src_double(s, o0, o1, rd, rn, rm, ra);
4412 unallocated_encoding(s);
4416 /* C3.6.28 Floating point immediate
4417 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
4418 * +---+---+---+-----------+------+---+------------+-------+------+------+
4419 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
4420 * +---+---+---+-----------+------+---+------------+-------+------+------+
4422 static void disas_fp_imm(DisasContext *s, uint32_t insn)
4424 int rd = extract32(insn, 0, 5);
4425 int imm8 = extract32(insn, 13, 8);
4426 int is_double = extract32(insn, 22, 2);
4430 if (is_double > 1) {
4431 unallocated_encoding(s);
4435 /* The imm8 encodes the sign bit, enough bits to represent
4436 * an exponent in the range 01....1xx to 10....0xx,
4437 * and the most significant 4 bits of the mantissa; see
4438 * VFPExpandImm() in the v8 ARM ARM.
4441 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
4442 (extract32(imm8, 6, 1) ? 0x3fc0 : 0x4000) |
4443 extract32(imm8, 0, 6);
4446 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
4447 (extract32(imm8, 6, 1) ? 0x3e00 : 0x4000) |
4448 (extract32(imm8, 0, 6) << 3);
4452 tcg_res = tcg_const_i64(imm);
4453 write_fp_dreg(s, rd, tcg_res);
4454 tcg_temp_free_i64(tcg_res);
4457 /* Handle floating point <=> fixed point conversions. Note that we can
4458 * also deal with fp <=> integer conversions as a special case (scale == 64)
4459 * OPTME: consider handling that special case specially or at least skipping
4460 * the call to scalbn in the helpers for zero shifts.
4462 static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode,
4463 bool itof, int rmode, int scale, int sf, int type)
4465 bool is_signed = !(opcode & 1);
4466 bool is_double = type;
4467 TCGv_ptr tcg_fpstatus;
4470 tcg_fpstatus = get_fpstatus_ptr();
4472 tcg_shift = tcg_const_i32(64 - scale);
4475 TCGv_i64 tcg_int = cpu_reg(s, rn);
4477 TCGv_i64 tcg_extend = new_tmp_a64(s);
4480 tcg_gen_ext32s_i64(tcg_extend, tcg_int);
4482 tcg_gen_ext32u_i64(tcg_extend, tcg_int);
4485 tcg_int = tcg_extend;
4489 TCGv_i64 tcg_double = tcg_temp_new_i64();
4491 gen_helper_vfp_sqtod(tcg_double, tcg_int,
4492 tcg_shift, tcg_fpstatus);
4494 gen_helper_vfp_uqtod(tcg_double, tcg_int,
4495 tcg_shift, tcg_fpstatus);
4497 write_fp_dreg(s, rd, tcg_double);
4498 tcg_temp_free_i64(tcg_double);
4500 TCGv_i32 tcg_single = tcg_temp_new_i32();
4502 gen_helper_vfp_sqtos(tcg_single, tcg_int,
4503 tcg_shift, tcg_fpstatus);
4505 gen_helper_vfp_uqtos(tcg_single, tcg_int,
4506 tcg_shift, tcg_fpstatus);
4508 write_fp_sreg(s, rd, tcg_single);
4509 tcg_temp_free_i32(tcg_single);
4512 TCGv_i64 tcg_int = cpu_reg(s, rd);
4515 if (extract32(opcode, 2, 1)) {
4516 /* There are too many rounding modes to all fit into rmode,
4517 * so FCVTA[US] is a special case.
4519 rmode = FPROUNDING_TIEAWAY;
4522 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
4524 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
4527 TCGv_i64 tcg_double = read_fp_dreg(s, rn);
4530 gen_helper_vfp_tosld(tcg_int, tcg_double,
4531 tcg_shift, tcg_fpstatus);
4533 gen_helper_vfp_tosqd(tcg_int, tcg_double,
4534 tcg_shift, tcg_fpstatus);
4538 gen_helper_vfp_tould(tcg_int, tcg_double,
4539 tcg_shift, tcg_fpstatus);
4541 gen_helper_vfp_touqd(tcg_int, tcg_double,
4542 tcg_shift, tcg_fpstatus);
4545 tcg_temp_free_i64(tcg_double);
4547 TCGv_i32 tcg_single = read_fp_sreg(s, rn);
4550 gen_helper_vfp_tosqs(tcg_int, tcg_single,
4551 tcg_shift, tcg_fpstatus);
4553 gen_helper_vfp_touqs(tcg_int, tcg_single,
4554 tcg_shift, tcg_fpstatus);
4557 TCGv_i32 tcg_dest = tcg_temp_new_i32();
4559 gen_helper_vfp_tosls(tcg_dest, tcg_single,
4560 tcg_shift, tcg_fpstatus);
4562 gen_helper_vfp_touls(tcg_dest, tcg_single,
4563 tcg_shift, tcg_fpstatus);
4565 tcg_gen_extu_i32_i64(tcg_int, tcg_dest);
4566 tcg_temp_free_i32(tcg_dest);
4568 tcg_temp_free_i32(tcg_single);
4571 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
4572 tcg_temp_free_i32(tcg_rmode);
4575 tcg_gen_ext32u_i64(tcg_int, tcg_int);
4579 tcg_temp_free_ptr(tcg_fpstatus);
4580 tcg_temp_free_i32(tcg_shift);
4583 /* C3.6.29 Floating point <-> fixed point conversions
4584 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4585 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4586 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
4587 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4589 static void disas_fp_fixed_conv(DisasContext *s, uint32_t insn)
4591 int rd = extract32(insn, 0, 5);
4592 int rn = extract32(insn, 5, 5);
4593 int scale = extract32(insn, 10, 6);
4594 int opcode = extract32(insn, 16, 3);
4595 int rmode = extract32(insn, 19, 2);
4596 int type = extract32(insn, 22, 2);
4597 bool sbit = extract32(insn, 29, 1);
4598 bool sf = extract32(insn, 31, 1);
4601 if (sbit || (type > 1)
4602 || (!sf && scale < 32)) {
4603 unallocated_encoding(s);
4607 switch ((rmode << 3) | opcode) {
4608 case 0x2: /* SCVTF */
4609 case 0x3: /* UCVTF */
4612 case 0x18: /* FCVTZS */
4613 case 0x19: /* FCVTZU */
4617 unallocated_encoding(s);
4621 handle_fpfpcvt(s, rd, rn, opcode, itof, FPROUNDING_ZERO, scale, sf, type);
4624 static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof)
4626 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
4627 * without conversion.
4631 TCGv_i64 tcg_rn = cpu_reg(s, rn);
4637 TCGv_i64 tmp = tcg_temp_new_i64();
4638 tcg_gen_ext32u_i64(tmp, tcg_rn);
4639 tcg_gen_st_i64(tmp, cpu_env, fp_reg_offset(rd, MO_64));
4640 tcg_gen_movi_i64(tmp, 0);
4641 tcg_gen_st_i64(tmp, cpu_env, fp_reg_hi_offset(rd));
4642 tcg_temp_free_i64(tmp);
4648 TCGv_i64 tmp = tcg_const_i64(0);
4649 tcg_gen_st_i64(tcg_rn, cpu_env, fp_reg_offset(rd, MO_64));
4650 tcg_gen_st_i64(tmp, cpu_env, fp_reg_hi_offset(rd));
4651 tcg_temp_free_i64(tmp);
4655 /* 64 bit to top half. */
4656 tcg_gen_st_i64(tcg_rn, cpu_env, fp_reg_hi_offset(rd));
4660 TCGv_i64 tcg_rd = cpu_reg(s, rd);
4665 tcg_gen_ld32u_i64(tcg_rd, cpu_env, fp_reg_offset(rn, MO_32));
4669 tcg_gen_ld_i64(tcg_rd, cpu_env, fp_reg_offset(rn, MO_64));
4672 /* 64 bits from top half */
4673 tcg_gen_ld_i64(tcg_rd, cpu_env, fp_reg_hi_offset(rn));
4679 /* C3.6.30 Floating point <-> integer conversions
4680 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4681 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4682 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
4683 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4685 static void disas_fp_int_conv(DisasContext *s, uint32_t insn)
4687 int rd = extract32(insn, 0, 5);
4688 int rn = extract32(insn, 5, 5);
4689 int opcode = extract32(insn, 16, 3);
4690 int rmode = extract32(insn, 19, 2);
4691 int type = extract32(insn, 22, 2);
4692 bool sbit = extract32(insn, 29, 1);
4693 bool sf = extract32(insn, 31, 1);
4696 unallocated_encoding(s);
4702 bool itof = opcode & 1;
4705 unallocated_encoding(s);
4709 switch (sf << 3 | type << 1 | rmode) {
4710 case 0x0: /* 32 bit */
4711 case 0xa: /* 64 bit */
4712 case 0xd: /* 64 bit to top half of quad */
4715 /* all other sf/type/rmode combinations are invalid */
4716 unallocated_encoding(s);
4720 handle_fmov(s, rd, rn, type, itof);
4722 /* actual FP conversions */
4723 bool itof = extract32(opcode, 1, 1);
4725 if (type > 1 || (rmode != 0 && opcode > 1)) {
4726 unallocated_encoding(s);
4730 handle_fpfpcvt(s, rd, rn, opcode, itof, rmode, 64, sf, type);
4734 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
4735 * 31 30 29 28 25 24 0
4736 * +---+---+---+---------+-----------------------------+
4737 * | | 0 | | 1 1 1 1 | |
4738 * +---+---+---+---------+-----------------------------+
4740 static void disas_data_proc_fp(DisasContext *s, uint32_t insn)
4742 if (extract32(insn, 24, 1)) {
4743 /* Floating point data-processing (3 source) */
4744 disas_fp_3src(s, insn);
4745 } else if (extract32(insn, 21, 1) == 0) {
4746 /* Floating point to fixed point conversions */
4747 disas_fp_fixed_conv(s, insn);
4749 switch (extract32(insn, 10, 2)) {
4751 /* Floating point conditional compare */
4752 disas_fp_ccomp(s, insn);
4755 /* Floating point data-processing (2 source) */
4756 disas_fp_2src(s, insn);
4759 /* Floating point conditional select */
4760 disas_fp_csel(s, insn);
4763 switch (ctz32(extract32(insn, 12, 4))) {
4764 case 0: /* [15:12] == xxx1 */
4765 /* Floating point immediate */
4766 disas_fp_imm(s, insn);
4768 case 1: /* [15:12] == xx10 */
4769 /* Floating point compare */
4770 disas_fp_compare(s, insn);
4772 case 2: /* [15:12] == x100 */
4773 /* Floating point data-processing (1 source) */
4774 disas_fp_1src(s, insn);
4776 case 3: /* [15:12] == 1000 */
4777 unallocated_encoding(s);
4779 default: /* [15:12] == 0000 */
4780 /* Floating point <-> integer conversions */
4781 disas_fp_int_conv(s, insn);
4789 static void do_ext64(DisasContext *s, TCGv_i64 tcg_left, TCGv_i64 tcg_right,
4792 /* Extract 64 bits from the middle of two concatenated 64 bit
4793 * vector register slices left:right. The extracted bits start
4794 * at 'pos' bits into the right (least significant) side.
4795 * We return the result in tcg_right, and guarantee not to
4798 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
4799 assert(pos > 0 && pos < 64);
4801 tcg_gen_shri_i64(tcg_right, tcg_right, pos);
4802 tcg_gen_shli_i64(tcg_tmp, tcg_left, 64 - pos);
4803 tcg_gen_or_i64(tcg_right, tcg_right, tcg_tmp);
4805 tcg_temp_free_i64(tcg_tmp);
4809 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
4810 * +---+---+-------------+-----+---+------+---+------+---+------+------+
4811 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
4812 * +---+---+-------------+-----+---+------+---+------+---+------+------+
4814 static void disas_simd_ext(DisasContext *s, uint32_t insn)
4816 int is_q = extract32(insn, 30, 1);
4817 int op2 = extract32(insn, 22, 2);
4818 int imm4 = extract32(insn, 11, 4);
4819 int rm = extract32(insn, 16, 5);
4820 int rn = extract32(insn, 5, 5);
4821 int rd = extract32(insn, 0, 5);
4822 int pos = imm4 << 3;
4823 TCGv_i64 tcg_resl, tcg_resh;
4825 if (op2 != 0 || (!is_q && extract32(imm4, 3, 1))) {
4826 unallocated_encoding(s);
4830 tcg_resh = tcg_temp_new_i64();
4831 tcg_resl = tcg_temp_new_i64();
4833 /* Vd gets bits starting at pos bits into Vm:Vn. This is
4834 * either extracting 128 bits from a 128:128 concatenation, or
4835 * extracting 64 bits from a 64:64 concatenation.
4838 read_vec_element(s, tcg_resl, rn, 0, MO_64);
4840 read_vec_element(s, tcg_resh, rm, 0, MO_64);
4841 do_ext64(s, tcg_resh, tcg_resl, pos);
4843 tcg_gen_movi_i64(tcg_resh, 0);
4850 EltPosns eltposns[] = { {rn, 0}, {rn, 1}, {rm, 0}, {rm, 1} };
4851 EltPosns *elt = eltposns;
4858 read_vec_element(s, tcg_resl, elt->reg, elt->elt, MO_64);
4860 read_vec_element(s, tcg_resh, elt->reg, elt->elt, MO_64);
4863 do_ext64(s, tcg_resh, tcg_resl, pos);
4864 tcg_hh = tcg_temp_new_i64();
4865 read_vec_element(s, tcg_hh, elt->reg, elt->elt, MO_64);
4866 do_ext64(s, tcg_hh, tcg_resh, pos);
4867 tcg_temp_free_i64(tcg_hh);
4871 write_vec_element(s, tcg_resl, rd, 0, MO_64);
4872 tcg_temp_free_i64(tcg_resl);
4873 write_vec_element(s, tcg_resh, rd, 1, MO_64);
4874 tcg_temp_free_i64(tcg_resh);
4878 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
4879 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
4880 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
4881 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
4883 static void disas_simd_tb(DisasContext *s, uint32_t insn)
4885 int op2 = extract32(insn, 22, 2);
4886 int is_q = extract32(insn, 30, 1);
4887 int rm = extract32(insn, 16, 5);
4888 int rn = extract32(insn, 5, 5);
4889 int rd = extract32(insn, 0, 5);
4890 int is_tblx = extract32(insn, 12, 1);
4891 int len = extract32(insn, 13, 2);
4892 TCGv_i64 tcg_resl, tcg_resh, tcg_idx;
4893 TCGv_i32 tcg_regno, tcg_numregs;
4896 unallocated_encoding(s);
4900 /* This does a table lookup: for every byte element in the input
4901 * we index into a table formed from up to four vector registers,
4902 * and then the output is the result of the lookups. Our helper
4903 * function does the lookup operation for a single 64 bit part of
4906 tcg_resl = tcg_temp_new_i64();
4907 tcg_resh = tcg_temp_new_i64();
4910 read_vec_element(s, tcg_resl, rd, 0, MO_64);
4912 tcg_gen_movi_i64(tcg_resl, 0);
4914 if (is_tblx && is_q) {
4915 read_vec_element(s, tcg_resh, rd, 1, MO_64);
4917 tcg_gen_movi_i64(tcg_resh, 0);
4920 tcg_idx = tcg_temp_new_i64();
4921 tcg_regno = tcg_const_i32(rn);
4922 tcg_numregs = tcg_const_i32(len + 1);
4923 read_vec_element(s, tcg_idx, rm, 0, MO_64);
4924 gen_helper_simd_tbl(tcg_resl, cpu_env, tcg_resl, tcg_idx,
4925 tcg_regno, tcg_numregs);
4927 read_vec_element(s, tcg_idx, rm, 1, MO_64);
4928 gen_helper_simd_tbl(tcg_resh, cpu_env, tcg_resh, tcg_idx,
4929 tcg_regno, tcg_numregs);
4931 tcg_temp_free_i64(tcg_idx);
4932 tcg_temp_free_i32(tcg_regno);
4933 tcg_temp_free_i32(tcg_numregs);
4935 write_vec_element(s, tcg_resl, rd, 0, MO_64);
4936 tcg_temp_free_i64(tcg_resl);
4937 write_vec_element(s, tcg_resh, rd, 1, MO_64);
4938 tcg_temp_free_i64(tcg_resh);
4941 /* C3.6.3 ZIP/UZP/TRN
4942 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
4943 * +---+---+-------------+------+---+------+---+------------------+------+
4944 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
4945 * +---+---+-------------+------+---+------+---+------------------+------+
4947 static void disas_simd_zip_trn(DisasContext *s, uint32_t insn)
4949 int rd = extract32(insn, 0, 5);
4950 int rn = extract32(insn, 5, 5);
4951 int rm = extract32(insn, 16, 5);
4952 int size = extract32(insn, 22, 2);
4953 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
4954 * bit 2 indicates 1 vs 2 variant of the insn.
4956 int opcode = extract32(insn, 12, 2);
4957 bool part = extract32(insn, 14, 1);
4958 bool is_q = extract32(insn, 30, 1);
4959 int esize = 8 << size;
4961 int datasize = is_q ? 128 : 64;
4962 int elements = datasize / esize;
4963 TCGv_i64 tcg_res, tcg_resl, tcg_resh;
4965 if (opcode == 0 || (size == 3 && !is_q)) {
4966 unallocated_encoding(s);
4970 tcg_resl = tcg_const_i64(0);
4971 tcg_resh = tcg_const_i64(0);
4972 tcg_res = tcg_temp_new_i64();
4974 for (i = 0; i < elements; i++) {
4976 case 1: /* UZP1/2 */
4978 int midpoint = elements / 2;
4980 read_vec_element(s, tcg_res, rn, 2 * i + part, size);
4982 read_vec_element(s, tcg_res, rm,
4983 2 * (i - midpoint) + part, size);
4987 case 2: /* TRN1/2 */
4989 read_vec_element(s, tcg_res, rm, (i & ~1) + part, size);
4991 read_vec_element(s, tcg_res, rn, (i & ~1) + part, size);
4994 case 3: /* ZIP1/2 */
4996 int base = part * elements / 2;
4998 read_vec_element(s, tcg_res, rm, base + (i >> 1), size);
5000 read_vec_element(s, tcg_res, rn, base + (i >> 1), size);
5005 g_assert_not_reached();
5010 tcg_gen_shli_i64(tcg_res, tcg_res, ofs);
5011 tcg_gen_or_i64(tcg_resl, tcg_resl, tcg_res);
5013 tcg_gen_shli_i64(tcg_res, tcg_res, ofs - 64);
5014 tcg_gen_or_i64(tcg_resh, tcg_resh, tcg_res);
5018 tcg_temp_free_i64(tcg_res);
5020 write_vec_element(s, tcg_resl, rd, 0, MO_64);
5021 tcg_temp_free_i64(tcg_resl);
5022 write_vec_element(s, tcg_resh, rd, 1, MO_64);
5023 tcg_temp_free_i64(tcg_resh);
5026 static void do_minmaxop(DisasContext *s, TCGv_i32 tcg_elt1, TCGv_i32 tcg_elt2,
5027 int opc, bool is_min, TCGv_ptr fpst)
5029 /* Helper function for disas_simd_across_lanes: do a single precision
5030 * min/max operation on the specified two inputs,
5031 * and return the result in tcg_elt1.
5035 gen_helper_vfp_minnums(tcg_elt1, tcg_elt1, tcg_elt2, fpst);
5037 gen_helper_vfp_maxnums(tcg_elt1, tcg_elt1, tcg_elt2, fpst);
5042 gen_helper_vfp_mins(tcg_elt1, tcg_elt1, tcg_elt2, fpst);
5044 gen_helper_vfp_maxs(tcg_elt1, tcg_elt1, tcg_elt2, fpst);
5049 /* C3.6.4 AdvSIMD across lanes
5050 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5051 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5052 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5053 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5055 static void disas_simd_across_lanes(DisasContext *s, uint32_t insn)
5057 int rd = extract32(insn, 0, 5);
5058 int rn = extract32(insn, 5, 5);
5059 int size = extract32(insn, 22, 2);
5060 int opcode = extract32(insn, 12, 5);
5061 bool is_q = extract32(insn, 30, 1);
5062 bool is_u = extract32(insn, 29, 1);
5064 bool is_min = false;
5068 TCGv_i64 tcg_res, tcg_elt;
5071 case 0x1b: /* ADDV */
5073 unallocated_encoding(s);
5077 case 0x3: /* SADDLV, UADDLV */
5078 case 0xa: /* SMAXV, UMAXV */
5079 case 0x1a: /* SMINV, UMINV */
5080 if (size == 3 || (size == 2 && !is_q)) {
5081 unallocated_encoding(s);
5085 case 0xc: /* FMAXNMV, FMINNMV */
5086 case 0xf: /* FMAXV, FMINV */
5087 if (!is_u || !is_q || extract32(size, 0, 1)) {
5088 unallocated_encoding(s);
5091 /* Bit 1 of size field encodes min vs max, and actual size is always
5092 * 32 bits: adjust the size variable so following code can rely on it
5094 is_min = extract32(size, 1, 1);
5099 unallocated_encoding(s);
5104 elements = (is_q ? 128 : 64) / esize;
5106 tcg_res = tcg_temp_new_i64();
5107 tcg_elt = tcg_temp_new_i64();
5109 /* These instructions operate across all lanes of a vector
5110 * to produce a single result. We can guarantee that a 64
5111 * bit intermediate is sufficient:
5112 * + for [US]ADDLV the maximum element size is 32 bits, and
5113 * the result type is 64 bits
5114 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
5115 * same as the element size, which is 32 bits at most
5116 * For the integer operations we can choose to work at 64
5117 * or 32 bits and truncate at the end; for simplicity
5118 * we use 64 bits always. The floating point
5119 * ops do require 32 bit intermediates, though.
5122 read_vec_element(s, tcg_res, rn, 0, size | (is_u ? 0 : MO_SIGN));
5124 for (i = 1; i < elements; i++) {
5125 read_vec_element(s, tcg_elt, rn, i, size | (is_u ? 0 : MO_SIGN));
5128 case 0x03: /* SADDLV / UADDLV */
5129 case 0x1b: /* ADDV */
5130 tcg_gen_add_i64(tcg_res, tcg_res, tcg_elt);
5132 case 0x0a: /* SMAXV / UMAXV */
5133 tcg_gen_movcond_i64(is_u ? TCG_COND_GEU : TCG_COND_GE,
5135 tcg_res, tcg_elt, tcg_res, tcg_elt);
5137 case 0x1a: /* SMINV / UMINV */
5138 tcg_gen_movcond_i64(is_u ? TCG_COND_LEU : TCG_COND_LE,
5140 tcg_res, tcg_elt, tcg_res, tcg_elt);
5144 g_assert_not_reached();
5149 /* Floating point ops which work on 32 bit (single) intermediates.
5150 * Note that correct NaN propagation requires that we do these
5151 * operations in exactly the order specified by the pseudocode.
5153 TCGv_i32 tcg_elt1 = tcg_temp_new_i32();
5154 TCGv_i32 tcg_elt2 = tcg_temp_new_i32();
5155 TCGv_i32 tcg_elt3 = tcg_temp_new_i32();
5156 TCGv_ptr fpst = get_fpstatus_ptr();
5158 assert(esize == 32);
5159 assert(elements == 4);
5161 read_vec_element(s, tcg_elt, rn, 0, MO_32);
5162 tcg_gen_trunc_i64_i32(tcg_elt1, tcg_elt);
5163 read_vec_element(s, tcg_elt, rn, 1, MO_32);
5164 tcg_gen_trunc_i64_i32(tcg_elt2, tcg_elt);
5166 do_minmaxop(s, tcg_elt1, tcg_elt2, opcode, is_min, fpst);
5168 read_vec_element(s, tcg_elt, rn, 2, MO_32);
5169 tcg_gen_trunc_i64_i32(tcg_elt2, tcg_elt);
5170 read_vec_element(s, tcg_elt, rn, 3, MO_32);
5171 tcg_gen_trunc_i64_i32(tcg_elt3, tcg_elt);
5173 do_minmaxop(s, tcg_elt2, tcg_elt3, opcode, is_min, fpst);
5175 do_minmaxop(s, tcg_elt1, tcg_elt2, opcode, is_min, fpst);
5177 tcg_gen_extu_i32_i64(tcg_res, tcg_elt1);
5178 tcg_temp_free_i32(tcg_elt1);
5179 tcg_temp_free_i32(tcg_elt2);
5180 tcg_temp_free_i32(tcg_elt3);
5181 tcg_temp_free_ptr(fpst);
5184 tcg_temp_free_i64(tcg_elt);
5186 /* Now truncate the result to the width required for the final output */
5187 if (opcode == 0x03) {
5188 /* SADDLV, UADDLV: result is 2*esize */
5194 tcg_gen_ext8u_i64(tcg_res, tcg_res);
5197 tcg_gen_ext16u_i64(tcg_res, tcg_res);
5200 tcg_gen_ext32u_i64(tcg_res, tcg_res);
5205 g_assert_not_reached();
5208 write_fp_dreg(s, rd, tcg_res);
5209 tcg_temp_free_i64(tcg_res);
5212 /* C6.3.31 DUP (Element, Vector)
5214 * 31 30 29 21 20 16 15 10 9 5 4 0
5215 * +---+---+-------------------+--------+-------------+------+------+
5216 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5217 * +---+---+-------------------+--------+-------------+------+------+
5219 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5221 static void handle_simd_dupe(DisasContext *s, int is_q, int rd, int rn,
5224 int size = ctz32(imm5);
5225 int esize = 8 << size;
5226 int elements = (is_q ? 128 : 64) / esize;
5230 if (size > 3 || (size == 3 && !is_q)) {
5231 unallocated_encoding(s);
5235 index = imm5 >> (size + 1);
5237 tmp = tcg_temp_new_i64();
5238 read_vec_element(s, tmp, rn, index, size);
5240 for (i = 0; i < elements; i++) {
5241 write_vec_element(s, tmp, rd, i, size);
5245 clear_vec_high(s, rd);
5248 tcg_temp_free_i64(tmp);
5251 /* C6.3.31 DUP (element, scalar)
5252 * 31 21 20 16 15 10 9 5 4 0
5253 * +-----------------------+--------+-------------+------+------+
5254 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5255 * +-----------------------+--------+-------------+------+------+
5257 static void handle_simd_dupes(DisasContext *s, int rd, int rn,
5260 int size = ctz32(imm5);
5265 unallocated_encoding(s);
5269 index = imm5 >> (size + 1);
5271 /* This instruction just extracts the specified element and
5272 * zero-extends it into the bottom of the destination register.
5274 tmp = tcg_temp_new_i64();
5275 read_vec_element(s, tmp, rn, index, size);
5276 write_fp_dreg(s, rd, tmp);
5277 tcg_temp_free_i64(tmp);
5280 /* C6.3.32 DUP (General)
5282 * 31 30 29 21 20 16 15 10 9 5 4 0
5283 * +---+---+-------------------+--------+-------------+------+------+
5284 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
5285 * +---+---+-------------------+--------+-------------+------+------+
5287 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5289 static void handle_simd_dupg(DisasContext *s, int is_q, int rd, int rn,
5292 int size = ctz32(imm5);
5293 int esize = 8 << size;
5294 int elements = (is_q ? 128 : 64)/esize;
5297 if (size > 3 || ((size == 3) && !is_q)) {
5298 unallocated_encoding(s);
5301 for (i = 0; i < elements; i++) {
5302 write_vec_element(s, cpu_reg(s, rn), rd, i, size);
5305 clear_vec_high(s, rd);
5309 /* C6.3.150 INS (Element)
5311 * 31 21 20 16 15 14 11 10 9 5 4 0
5312 * +-----------------------+--------+------------+---+------+------+
5313 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5314 * +-----------------------+--------+------------+---+------+------+
5316 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5317 * index: encoded in imm5<4:size+1>
5319 static void handle_simd_inse(DisasContext *s, int rd, int rn,
5322 int size = ctz32(imm5);
5323 int src_index, dst_index;
5327 unallocated_encoding(s);
5330 dst_index = extract32(imm5, 1+size, 5);
5331 src_index = extract32(imm4, size, 4);
5333 tmp = tcg_temp_new_i64();
5335 read_vec_element(s, tmp, rn, src_index, size);
5336 write_vec_element(s, tmp, rd, dst_index, size);
5338 tcg_temp_free_i64(tmp);
5342 /* C6.3.151 INS (General)
5344 * 31 21 20 16 15 10 9 5 4 0
5345 * +-----------------------+--------+-------------+------+------+
5346 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
5347 * +-----------------------+--------+-------------+------+------+
5349 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5350 * index: encoded in imm5<4:size+1>
5352 static void handle_simd_insg(DisasContext *s, int rd, int rn, int imm5)
5354 int size = ctz32(imm5);
5358 unallocated_encoding(s);
5362 idx = extract32(imm5, 1 + size, 4 - size);
5363 write_vec_element(s, cpu_reg(s, rn), rd, idx, size);
5367 * C6.3.321 UMOV (General)
5368 * C6.3.237 SMOV (General)
5370 * 31 30 29 21 20 16 15 12 10 9 5 4 0
5371 * +---+---+-------------------+--------+-------------+------+------+
5372 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
5373 * +---+---+-------------------+--------+-------------+------+------+
5375 * U: unsigned when set
5376 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5378 static void handle_simd_umov_smov(DisasContext *s, int is_q, int is_signed,
5379 int rn, int rd, int imm5)
5381 int size = ctz32(imm5);
5385 /* Check for UnallocatedEncodings */
5387 if (size > 2 || (size == 2 && !is_q)) {
5388 unallocated_encoding(s);
5393 || (size < 3 && is_q)
5394 || (size == 3 && !is_q)) {
5395 unallocated_encoding(s);
5399 element = extract32(imm5, 1+size, 4);
5401 tcg_rd = cpu_reg(s, rd);
5402 read_vec_element(s, tcg_rd, rn, element, size | (is_signed ? MO_SIGN : 0));
5403 if (is_signed && !is_q) {
5404 tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
5408 /* C3.6.5 AdvSIMD copy
5409 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5410 * +---+---+----+-----------------+------+---+------+---+------+------+
5411 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5412 * +---+---+----+-----------------+------+---+------+---+------+------+
5414 static void disas_simd_copy(DisasContext *s, uint32_t insn)
5416 int rd = extract32(insn, 0, 5);
5417 int rn = extract32(insn, 5, 5);
5418 int imm4 = extract32(insn, 11, 4);
5419 int op = extract32(insn, 29, 1);
5420 int is_q = extract32(insn, 30, 1);
5421 int imm5 = extract32(insn, 16, 5);
5426 handle_simd_inse(s, rd, rn, imm4, imm5);
5428 unallocated_encoding(s);
5433 /* DUP (element - vector) */
5434 handle_simd_dupe(s, is_q, rd, rn, imm5);
5438 handle_simd_dupg(s, is_q, rd, rn, imm5);
5443 handle_simd_insg(s, rd, rn, imm5);
5445 unallocated_encoding(s);
5450 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
5451 handle_simd_umov_smov(s, is_q, (imm4 == 5), rn, rd, imm5);
5454 unallocated_encoding(s);
5460 /* C3.6.6 AdvSIMD modified immediate
5461 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
5462 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5463 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
5464 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5466 * There are a number of operations that can be carried out here:
5467 * MOVI - move (shifted) imm into register
5468 * MVNI - move inverted (shifted) imm into register
5469 * ORR - bitwise OR of (shifted) imm with register
5470 * BIC - bitwise clear of (shifted) imm with register
5472 static void disas_simd_mod_imm(DisasContext *s, uint32_t insn)
5474 int rd = extract32(insn, 0, 5);
5475 int cmode = extract32(insn, 12, 4);
5476 int cmode_3_1 = extract32(cmode, 1, 3);
5477 int cmode_0 = extract32(cmode, 0, 1);
5478 int o2 = extract32(insn, 11, 1);
5479 uint64_t abcdefgh = extract32(insn, 5, 5) | (extract32(insn, 16, 3) << 5);
5480 bool is_neg = extract32(insn, 29, 1);
5481 bool is_q = extract32(insn, 30, 1);
5483 TCGv_i64 tcg_rd, tcg_imm;
5486 if (o2 != 0 || ((cmode == 0xf) && is_neg && !is_q)) {
5487 unallocated_encoding(s);
5491 /* See AdvSIMDExpandImm() in ARM ARM */
5492 switch (cmode_3_1) {
5493 case 0: /* Replicate(Zeros(24):imm8, 2) */
5494 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
5495 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
5496 case 3: /* Replicate(imm8:Zeros(24), 2) */
5498 int shift = cmode_3_1 * 8;
5499 imm = bitfield_replicate(abcdefgh << shift, 32);
5502 case 4: /* Replicate(Zeros(8):imm8, 4) */
5503 case 5: /* Replicate(imm8:Zeros(8), 4) */
5505 int shift = (cmode_3_1 & 0x1) * 8;
5506 imm = bitfield_replicate(abcdefgh << shift, 16);
5511 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
5512 imm = (abcdefgh << 16) | 0xffff;
5514 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
5515 imm = (abcdefgh << 8) | 0xff;
5517 imm = bitfield_replicate(imm, 32);
5520 if (!cmode_0 && !is_neg) {
5521 imm = bitfield_replicate(abcdefgh, 8);
5522 } else if (!cmode_0 && is_neg) {
5525 for (i = 0; i < 8; i++) {
5526 if ((abcdefgh) & (1 << i)) {
5527 imm |= 0xffULL << (i * 8);
5530 } else if (cmode_0) {
5532 imm = (abcdefgh & 0x3f) << 48;
5533 if (abcdefgh & 0x80) {
5534 imm |= 0x8000000000000000ULL;
5536 if (abcdefgh & 0x40) {
5537 imm |= 0x3fc0000000000000ULL;
5539 imm |= 0x4000000000000000ULL;
5542 imm = (abcdefgh & 0x3f) << 19;
5543 if (abcdefgh & 0x80) {
5546 if (abcdefgh & 0x40) {
5557 if (cmode_3_1 != 7 && is_neg) {
5561 tcg_imm = tcg_const_i64(imm);
5562 tcg_rd = new_tmp_a64(s);
5564 for (i = 0; i < 2; i++) {
5565 int foffs = i ? fp_reg_hi_offset(rd) : fp_reg_offset(rd, MO_64);
5567 if (i == 1 && !is_q) {
5568 /* non-quad ops clear high half of vector */
5569 tcg_gen_movi_i64(tcg_rd, 0);
5570 } else if ((cmode & 0x9) == 0x1 || (cmode & 0xd) == 0x9) {
5571 tcg_gen_ld_i64(tcg_rd, cpu_env, foffs);
5574 tcg_gen_and_i64(tcg_rd, tcg_rd, tcg_imm);
5577 tcg_gen_or_i64(tcg_rd, tcg_rd, tcg_imm);
5581 tcg_gen_mov_i64(tcg_rd, tcg_imm);
5583 tcg_gen_st_i64(tcg_rd, cpu_env, foffs);
5586 tcg_temp_free_i64(tcg_imm);
5589 /* C3.6.7 AdvSIMD scalar copy
5590 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5591 * +-----+----+-----------------+------+---+------+---+------+------+
5592 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5593 * +-----+----+-----------------+------+---+------+---+------+------+
5595 static void disas_simd_scalar_copy(DisasContext *s, uint32_t insn)
5597 int rd = extract32(insn, 0, 5);
5598 int rn = extract32(insn, 5, 5);
5599 int imm4 = extract32(insn, 11, 4);
5600 int imm5 = extract32(insn, 16, 5);
5601 int op = extract32(insn, 29, 1);
5603 if (op != 0 || imm4 != 0) {
5604 unallocated_encoding(s);
5608 /* DUP (element, scalar) */
5609 handle_simd_dupes(s, rd, rn, imm5);
5612 /* C3.6.8 AdvSIMD scalar pairwise
5613 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5614 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5615 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5616 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5618 static void disas_simd_scalar_pairwise(DisasContext *s, uint32_t insn)
5620 int u = extract32(insn, 29, 1);
5621 int size = extract32(insn, 22, 2);
5622 int opcode = extract32(insn, 12, 5);
5623 int rn = extract32(insn, 5, 5);
5624 int rd = extract32(insn, 0, 5);
5627 /* For some ops (the FP ones), size[1] is part of the encoding.
5628 * For ADDP strictly it is not but size[1] is always 1 for valid
5631 opcode |= (extract32(size, 1, 1) << 5);
5634 case 0x3b: /* ADDP */
5635 if (u || size != 3) {
5636 unallocated_encoding(s);
5639 TCGV_UNUSED_PTR(fpst);
5641 case 0xc: /* FMAXNMP */
5642 case 0xd: /* FADDP */
5643 case 0xf: /* FMAXP */
5644 case 0x2c: /* FMINNMP */
5645 case 0x2f: /* FMINP */
5646 /* FP op, size[0] is 32 or 64 bit */
5648 unallocated_encoding(s);
5651 size = extract32(size, 0, 1) ? 3 : 2;
5652 fpst = get_fpstatus_ptr();
5655 unallocated_encoding(s);
5660 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
5661 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
5662 TCGv_i64 tcg_res = tcg_temp_new_i64();
5664 read_vec_element(s, tcg_op1, rn, 0, MO_64);
5665 read_vec_element(s, tcg_op2, rn, 1, MO_64);
5668 case 0x3b: /* ADDP */
5669 tcg_gen_add_i64(tcg_res, tcg_op1, tcg_op2);
5671 case 0xc: /* FMAXNMP */
5672 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
5674 case 0xd: /* FADDP */
5675 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
5677 case 0xf: /* FMAXP */
5678 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
5680 case 0x2c: /* FMINNMP */
5681 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
5683 case 0x2f: /* FMINP */
5684 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
5687 g_assert_not_reached();
5690 write_fp_dreg(s, rd, tcg_res);
5692 tcg_temp_free_i64(tcg_op1);
5693 tcg_temp_free_i64(tcg_op2);
5694 tcg_temp_free_i64(tcg_res);
5696 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
5697 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
5698 TCGv_i32 tcg_res = tcg_temp_new_i32();
5700 read_vec_element_i32(s, tcg_op1, rn, 0, MO_32);
5701 read_vec_element_i32(s, tcg_op2, rn, 1, MO_32);
5704 case 0xc: /* FMAXNMP */
5705 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
5707 case 0xd: /* FADDP */
5708 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
5710 case 0xf: /* FMAXP */
5711 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
5713 case 0x2c: /* FMINNMP */
5714 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
5716 case 0x2f: /* FMINP */
5717 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
5720 g_assert_not_reached();
5723 write_fp_sreg(s, rd, tcg_res);
5725 tcg_temp_free_i32(tcg_op1);
5726 tcg_temp_free_i32(tcg_op2);
5727 tcg_temp_free_i32(tcg_res);
5730 if (!TCGV_IS_UNUSED_PTR(fpst)) {
5731 tcg_temp_free_ptr(fpst);
5736 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
5738 * This code is handles the common shifting code and is used by both
5739 * the vector and scalar code.
5741 static void handle_shri_with_rndacc(TCGv_i64 tcg_res, TCGv_i64 tcg_src,
5742 TCGv_i64 tcg_rnd, bool accumulate,
5743 bool is_u, int size, int shift)
5745 bool extended_result = false;
5746 bool round = !TCGV_IS_UNUSED_I64(tcg_rnd);
5748 TCGv_i64 tcg_src_hi;
5750 if (round && size == 3) {
5751 extended_result = true;
5752 ext_lshift = 64 - shift;
5753 tcg_src_hi = tcg_temp_new_i64();
5754 } else if (shift == 64) {
5755 if (!accumulate && is_u) {
5756 /* result is zero */
5757 tcg_gen_movi_i64(tcg_res, 0);
5762 /* Deal with the rounding step */
5764 if (extended_result) {
5765 TCGv_i64 tcg_zero = tcg_const_i64(0);
5767 /* take care of sign extending tcg_res */
5768 tcg_gen_sari_i64(tcg_src_hi, tcg_src, 63);
5769 tcg_gen_add2_i64(tcg_src, tcg_src_hi,
5770 tcg_src, tcg_src_hi,
5773 tcg_gen_add2_i64(tcg_src, tcg_src_hi,
5777 tcg_temp_free_i64(tcg_zero);
5779 tcg_gen_add_i64(tcg_src, tcg_src, tcg_rnd);
5783 /* Now do the shift right */
5784 if (round && extended_result) {
5785 /* extended case, >64 bit precision required */
5786 if (ext_lshift == 0) {
5787 /* special case, only high bits matter */
5788 tcg_gen_mov_i64(tcg_src, tcg_src_hi);
5790 tcg_gen_shri_i64(tcg_src, tcg_src, shift);
5791 tcg_gen_shli_i64(tcg_src_hi, tcg_src_hi, ext_lshift);
5792 tcg_gen_or_i64(tcg_src, tcg_src, tcg_src_hi);
5797 /* essentially shifting in 64 zeros */
5798 tcg_gen_movi_i64(tcg_src, 0);
5800 tcg_gen_shri_i64(tcg_src, tcg_src, shift);
5804 /* effectively extending the sign-bit */
5805 tcg_gen_sari_i64(tcg_src, tcg_src, 63);
5807 tcg_gen_sari_i64(tcg_src, tcg_src, shift);
5813 tcg_gen_add_i64(tcg_res, tcg_res, tcg_src);
5815 tcg_gen_mov_i64(tcg_res, tcg_src);
5818 if (extended_result) {
5819 tcg_temp_free_i64(tcg_src_hi);
5823 /* Common SHL/SLI - Shift left with an optional insert */
5824 static void handle_shli_with_ins(TCGv_i64 tcg_res, TCGv_i64 tcg_src,
5825 bool insert, int shift)
5827 if (insert) { /* SLI */
5828 tcg_gen_deposit_i64(tcg_res, tcg_res, tcg_src, shift, 64 - shift);
5830 tcg_gen_shli_i64(tcg_res, tcg_src, shift);
5834 /* SRI: shift right with insert */
5835 static void handle_shri_with_ins(TCGv_i64 tcg_res, TCGv_i64 tcg_src,
5836 int size, int shift)
5838 int esize = 8 << size;
5840 /* shift count same as element size is valid but does nothing;
5841 * special case to avoid potential shift by 64.
5843 if (shift != esize) {
5844 tcg_gen_shri_i64(tcg_src, tcg_src, shift);
5845 tcg_gen_deposit_i64(tcg_res, tcg_res, tcg_src, 0, esize - shift);
5849 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
5850 static void handle_scalar_simd_shri(DisasContext *s,
5851 bool is_u, int immh, int immb,
5852 int opcode, int rn, int rd)
5855 int immhb = immh << 3 | immb;
5856 int shift = 2 * (8 << size) - immhb;
5857 bool accumulate = false;
5859 bool insert = false;
5864 if (!extract32(immh, 3, 1)) {
5865 unallocated_encoding(s);
5870 case 0x02: /* SSRA / USRA (accumulate) */
5873 case 0x04: /* SRSHR / URSHR (rounding) */
5876 case 0x06: /* SRSRA / URSRA (accum + rounding) */
5877 accumulate = round = true;
5879 case 0x08: /* SRI */
5885 uint64_t round_const = 1ULL << (shift - 1);
5886 tcg_round = tcg_const_i64(round_const);
5888 TCGV_UNUSED_I64(tcg_round);
5891 tcg_rn = read_fp_dreg(s, rn);
5892 tcg_rd = (accumulate || insert) ? read_fp_dreg(s, rd) : tcg_temp_new_i64();
5895 handle_shri_with_ins(tcg_rd, tcg_rn, size, shift);
5897 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
5898 accumulate, is_u, size, shift);
5901 write_fp_dreg(s, rd, tcg_rd);
5903 tcg_temp_free_i64(tcg_rn);
5904 tcg_temp_free_i64(tcg_rd);
5906 tcg_temp_free_i64(tcg_round);
5910 /* SHL/SLI - Scalar shift left */
5911 static void handle_scalar_simd_shli(DisasContext *s, bool insert,
5912 int immh, int immb, int opcode,
5915 int size = 32 - clz32(immh) - 1;
5916 int immhb = immh << 3 | immb;
5917 int shift = immhb - (8 << size);
5918 TCGv_i64 tcg_rn = new_tmp_a64(s);
5919 TCGv_i64 tcg_rd = new_tmp_a64(s);
5921 if (!extract32(immh, 3, 1)) {
5922 unallocated_encoding(s);
5926 tcg_rn = read_fp_dreg(s, rn);
5927 tcg_rd = insert ? read_fp_dreg(s, rd) : tcg_temp_new_i64();
5929 handle_shli_with_ins(tcg_rd, tcg_rn, insert, shift);
5931 write_fp_dreg(s, rd, tcg_rd);
5933 tcg_temp_free_i64(tcg_rn);
5934 tcg_temp_free_i64(tcg_rd);
5937 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
5938 * (signed/unsigned) narrowing */
5939 static void handle_vec_simd_sqshrn(DisasContext *s, bool is_scalar, bool is_q,
5940 bool is_u_shift, bool is_u_narrow,
5941 int immh, int immb, int opcode,
5944 int immhb = immh << 3 | immb;
5945 int size = 32 - clz32(immh) - 1;
5946 int esize = 8 << size;
5947 int shift = (2 * esize) - immhb;
5948 int elements = is_scalar ? 1 : (64 / esize);
5949 bool round = extract32(opcode, 0, 1);
5950 TCGMemOp ldop = (size + 1) | (is_u_shift ? 0 : MO_SIGN);
5951 TCGv_i64 tcg_rn, tcg_rd, tcg_round;
5952 TCGv_i32 tcg_rd_narrowed;
5955 static NeonGenNarrowEnvFn * const signed_narrow_fns[4][2] = {
5956 { gen_helper_neon_narrow_sat_s8,
5957 gen_helper_neon_unarrow_sat8 },
5958 { gen_helper_neon_narrow_sat_s16,
5959 gen_helper_neon_unarrow_sat16 },
5960 { gen_helper_neon_narrow_sat_s32,
5961 gen_helper_neon_unarrow_sat32 },
5964 static NeonGenNarrowEnvFn * const unsigned_narrow_fns[4] = {
5965 gen_helper_neon_narrow_sat_u8,
5966 gen_helper_neon_narrow_sat_u16,
5967 gen_helper_neon_narrow_sat_u32,
5970 NeonGenNarrowEnvFn *narrowfn;
5976 if (extract32(immh, 3, 1)) {
5977 unallocated_encoding(s);
5982 narrowfn = unsigned_narrow_fns[size];
5984 narrowfn = signed_narrow_fns[size][is_u_narrow ? 1 : 0];
5987 tcg_rn = tcg_temp_new_i64();
5988 tcg_rd = tcg_temp_new_i64();
5989 tcg_rd_narrowed = tcg_temp_new_i32();
5990 tcg_final = tcg_const_i64(0);
5993 uint64_t round_const = 1ULL << (shift - 1);
5994 tcg_round = tcg_const_i64(round_const);
5996 TCGV_UNUSED_I64(tcg_round);
5999 for (i = 0; i < elements; i++) {
6000 read_vec_element(s, tcg_rn, rn, i, ldop);
6001 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
6002 false, is_u_shift, size+1, shift);
6003 narrowfn(tcg_rd_narrowed, cpu_env, tcg_rd);
6004 tcg_gen_extu_i32_i64(tcg_rd, tcg_rd_narrowed);
6005 tcg_gen_deposit_i64(tcg_final, tcg_final, tcg_rd, esize * i, esize);
6009 clear_vec_high(s, rd);
6010 write_vec_element(s, tcg_final, rd, 0, MO_64);
6012 write_vec_element(s, tcg_final, rd, 1, MO_64);
6016 tcg_temp_free_i64(tcg_round);
6018 tcg_temp_free_i64(tcg_rn);
6019 tcg_temp_free_i64(tcg_rd);
6020 tcg_temp_free_i32(tcg_rd_narrowed);
6021 tcg_temp_free_i64(tcg_final);
6025 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
6026 static void handle_simd_qshl(DisasContext *s, bool scalar, bool is_q,
6027 bool src_unsigned, bool dst_unsigned,
6028 int immh, int immb, int rn, int rd)
6030 int immhb = immh << 3 | immb;
6031 int size = 32 - clz32(immh) - 1;
6032 int shift = immhb - (8 << size);
6036 assert(!(scalar && is_q));
6039 if (!is_q && extract32(immh, 3, 1)) {
6040 unallocated_encoding(s);
6044 /* Since we use the variable-shift helpers we must
6045 * replicate the shift count into each element of
6046 * the tcg_shift value.
6050 shift |= shift << 8;
6053 shift |= shift << 16;
6059 g_assert_not_reached();
6064 TCGv_i64 tcg_shift = tcg_const_i64(shift);
6065 static NeonGenTwo64OpEnvFn * const fns[2][2] = {
6066 { gen_helper_neon_qshl_s64, gen_helper_neon_qshlu_s64 },
6067 { NULL, gen_helper_neon_qshl_u64 },
6069 NeonGenTwo64OpEnvFn *genfn = fns[src_unsigned][dst_unsigned];
6070 int maxpass = is_q ? 2 : 1;
6072 for (pass = 0; pass < maxpass; pass++) {
6073 TCGv_i64 tcg_op = tcg_temp_new_i64();
6075 read_vec_element(s, tcg_op, rn, pass, MO_64);
6076 genfn(tcg_op, cpu_env, tcg_op, tcg_shift);
6077 write_vec_element(s, tcg_op, rd, pass, MO_64);
6079 tcg_temp_free_i64(tcg_op);
6081 tcg_temp_free_i64(tcg_shift);
6084 clear_vec_high(s, rd);
6087 TCGv_i32 tcg_shift = tcg_const_i32(shift);
6088 static NeonGenTwoOpEnvFn * const fns[2][2][3] = {
6090 { gen_helper_neon_qshl_s8,
6091 gen_helper_neon_qshl_s16,
6092 gen_helper_neon_qshl_s32 },
6093 { gen_helper_neon_qshlu_s8,
6094 gen_helper_neon_qshlu_s16,
6095 gen_helper_neon_qshlu_s32 }
6097 { NULL, NULL, NULL },
6098 { gen_helper_neon_qshl_u8,
6099 gen_helper_neon_qshl_u16,
6100 gen_helper_neon_qshl_u32 }
6103 NeonGenTwoOpEnvFn *genfn = fns[src_unsigned][dst_unsigned][size];
6104 TCGMemOp memop = scalar ? size : MO_32;
6105 int maxpass = scalar ? 1 : is_q ? 4 : 2;
6107 for (pass = 0; pass < maxpass; pass++) {
6108 TCGv_i32 tcg_op = tcg_temp_new_i32();
6110 read_vec_element_i32(s, tcg_op, rn, pass, memop);
6111 genfn(tcg_op, cpu_env, tcg_op, tcg_shift);
6115 tcg_gen_ext8u_i32(tcg_op, tcg_op);
6118 tcg_gen_ext16u_i32(tcg_op, tcg_op);
6123 g_assert_not_reached();
6125 write_fp_sreg(s, rd, tcg_op);
6127 write_vec_element_i32(s, tcg_op, rd, pass, MO_32);
6130 tcg_temp_free_i32(tcg_op);
6132 tcg_temp_free_i32(tcg_shift);
6134 if (!is_q && !scalar) {
6135 clear_vec_high(s, rd);
6140 /* Common vector code for handling integer to FP conversion */
6141 static void handle_simd_intfp_conv(DisasContext *s, int rd, int rn,
6142 int elements, int is_signed,
6143 int fracbits, int size)
6145 bool is_double = size == 3 ? true : false;
6146 TCGv_ptr tcg_fpst = get_fpstatus_ptr();
6147 TCGv_i32 tcg_shift = tcg_const_i32(fracbits);
6148 TCGv_i64 tcg_int = tcg_temp_new_i64();
6149 TCGMemOp mop = size | (is_signed ? MO_SIGN : 0);
6152 for (pass = 0; pass < elements; pass++) {
6153 read_vec_element(s, tcg_int, rn, pass, mop);
6156 TCGv_i64 tcg_double = tcg_temp_new_i64();
6158 gen_helper_vfp_sqtod(tcg_double, tcg_int,
6159 tcg_shift, tcg_fpst);
6161 gen_helper_vfp_uqtod(tcg_double, tcg_int,
6162 tcg_shift, tcg_fpst);
6164 if (elements == 1) {
6165 write_fp_dreg(s, rd, tcg_double);
6167 write_vec_element(s, tcg_double, rd, pass, MO_64);
6169 tcg_temp_free_i64(tcg_double);
6171 TCGv_i32 tcg_single = tcg_temp_new_i32();
6173 gen_helper_vfp_sqtos(tcg_single, tcg_int,
6174 tcg_shift, tcg_fpst);
6176 gen_helper_vfp_uqtos(tcg_single, tcg_int,
6177 tcg_shift, tcg_fpst);
6179 if (elements == 1) {
6180 write_fp_sreg(s, rd, tcg_single);
6182 write_vec_element_i32(s, tcg_single, rd, pass, MO_32);
6184 tcg_temp_free_i32(tcg_single);
6188 if (!is_double && elements == 2) {
6189 clear_vec_high(s, rd);
6192 tcg_temp_free_i64(tcg_int);
6193 tcg_temp_free_ptr(tcg_fpst);
6194 tcg_temp_free_i32(tcg_shift);
6197 /* UCVTF/SCVTF - Integer to FP conversion */
6198 static void handle_simd_shift_intfp_conv(DisasContext *s, bool is_scalar,
6199 bool is_q, bool is_u,
6200 int immh, int immb, int opcode,
6203 bool is_double = extract32(immh, 3, 1);
6204 int size = is_double ? MO_64 : MO_32;
6206 int immhb = immh << 3 | immb;
6207 int fracbits = (is_double ? 128 : 64) - immhb;
6209 if (!extract32(immh, 2, 2)) {
6210 unallocated_encoding(s);
6217 elements = is_double ? 2 : is_q ? 4 : 2;
6218 if (is_double && !is_q) {
6219 unallocated_encoding(s);
6223 /* immh == 0 would be a failure of the decode logic */
6226 handle_simd_intfp_conv(s, rd, rn, elements, !is_u, fracbits, size);
6229 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
6230 static void handle_simd_shift_fpint_conv(DisasContext *s, bool is_scalar,
6231 bool is_q, bool is_u,
6232 int immh, int immb, int rn, int rd)
6234 bool is_double = extract32(immh, 3, 1);
6235 int immhb = immh << 3 | immb;
6236 int fracbits = (is_double ? 128 : 64) - immhb;
6238 TCGv_ptr tcg_fpstatus;
6239 TCGv_i32 tcg_rmode, tcg_shift;
6241 if (!extract32(immh, 2, 2)) {
6242 unallocated_encoding(s);
6246 if (!is_scalar && !is_q && is_double) {
6247 unallocated_encoding(s);
6251 assert(!(is_scalar && is_q));
6253 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO));
6254 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
6255 tcg_fpstatus = get_fpstatus_ptr();
6256 tcg_shift = tcg_const_i32(fracbits);
6259 int maxpass = is_scalar ? 1 : is_q ? 2 : 1;
6261 for (pass = 0; pass < maxpass; pass++) {
6262 TCGv_i64 tcg_op = tcg_temp_new_i64();
6264 read_vec_element(s, tcg_op, rn, pass, MO_64);
6266 gen_helper_vfp_touqd(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
6268 gen_helper_vfp_tosqd(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
6270 write_vec_element(s, tcg_op, rd, pass, MO_64);
6271 tcg_temp_free_i64(tcg_op);
6274 clear_vec_high(s, rd);
6277 int maxpass = is_scalar ? 1 : is_q ? 4 : 2;
6278 for (pass = 0; pass < maxpass; pass++) {
6279 TCGv_i32 tcg_op = tcg_temp_new_i32();
6281 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
6283 gen_helper_vfp_touls(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
6285 gen_helper_vfp_tosls(tcg_op, tcg_op, tcg_shift, tcg_fpstatus);
6288 write_fp_sreg(s, rd, tcg_op);
6290 write_vec_element_i32(s, tcg_op, rd, pass, MO_32);
6292 tcg_temp_free_i32(tcg_op);
6294 if (!is_q && !is_scalar) {
6295 clear_vec_high(s, rd);
6299 tcg_temp_free_ptr(tcg_fpstatus);
6300 tcg_temp_free_i32(tcg_shift);
6301 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
6302 tcg_temp_free_i32(tcg_rmode);
6305 /* C3.6.9 AdvSIMD scalar shift by immediate
6306 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
6307 * +-----+---+-------------+------+------+--------+---+------+------+
6308 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
6309 * +-----+---+-------------+------+------+--------+---+------+------+
6311 * This is the scalar version so it works on a fixed sized registers
6313 static void disas_simd_scalar_shift_imm(DisasContext *s, uint32_t insn)
6315 int rd = extract32(insn, 0, 5);
6316 int rn = extract32(insn, 5, 5);
6317 int opcode = extract32(insn, 11, 5);
6318 int immb = extract32(insn, 16, 3);
6319 int immh = extract32(insn, 19, 4);
6320 bool is_u = extract32(insn, 29, 1);
6323 unallocated_encoding(s);
6328 case 0x08: /* SRI */
6330 unallocated_encoding(s);
6334 case 0x00: /* SSHR / USHR */
6335 case 0x02: /* SSRA / USRA */
6336 case 0x04: /* SRSHR / URSHR */
6337 case 0x06: /* SRSRA / URSRA */
6338 handle_scalar_simd_shri(s, is_u, immh, immb, opcode, rn, rd);
6340 case 0x0a: /* SHL / SLI */
6341 handle_scalar_simd_shli(s, is_u, immh, immb, opcode, rn, rd);
6343 case 0x1c: /* SCVTF, UCVTF */
6344 handle_simd_shift_intfp_conv(s, true, false, is_u, immh, immb,
6347 case 0x10: /* SQSHRUN, SQSHRUN2 */
6348 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
6350 unallocated_encoding(s);
6353 handle_vec_simd_sqshrn(s, true, false, false, true,
6354 immh, immb, opcode, rn, rd);
6356 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
6357 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
6358 handle_vec_simd_sqshrn(s, true, false, is_u, is_u,
6359 immh, immb, opcode, rn, rd);
6361 case 0xc: /* SQSHLU */
6363 unallocated_encoding(s);
6366 handle_simd_qshl(s, true, false, false, true, immh, immb, rn, rd);
6368 case 0xe: /* SQSHL, UQSHL */
6369 handle_simd_qshl(s, true, false, is_u, is_u, immh, immb, rn, rd);
6371 case 0x1f: /* FCVTZS, FCVTZU */
6372 handle_simd_shift_fpint_conv(s, true, false, is_u, immh, immb, rn, rd);
6375 unallocated_encoding(s);
6380 /* C3.6.10 AdvSIMD scalar three different
6381 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6382 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6383 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
6384 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6386 static void disas_simd_scalar_three_reg_diff(DisasContext *s, uint32_t insn)
6388 bool is_u = extract32(insn, 29, 1);
6389 int size = extract32(insn, 22, 2);
6390 int opcode = extract32(insn, 12, 4);
6391 int rm = extract32(insn, 16, 5);
6392 int rn = extract32(insn, 5, 5);
6393 int rd = extract32(insn, 0, 5);
6396 unallocated_encoding(s);
6401 case 0x9: /* SQDMLAL, SQDMLAL2 */
6402 case 0xb: /* SQDMLSL, SQDMLSL2 */
6403 case 0xd: /* SQDMULL, SQDMULL2 */
6404 if (size == 0 || size == 3) {
6405 unallocated_encoding(s);
6410 unallocated_encoding(s);
6415 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
6416 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
6417 TCGv_i64 tcg_res = tcg_temp_new_i64();
6419 read_vec_element(s, tcg_op1, rn, 0, MO_32 | MO_SIGN);
6420 read_vec_element(s, tcg_op2, rm, 0, MO_32 | MO_SIGN);
6422 tcg_gen_mul_i64(tcg_res, tcg_op1, tcg_op2);
6423 gen_helper_neon_addl_saturate_s64(tcg_res, cpu_env, tcg_res, tcg_res);
6426 case 0xd: /* SQDMULL, SQDMULL2 */
6428 case 0xb: /* SQDMLSL, SQDMLSL2 */
6429 tcg_gen_neg_i64(tcg_res, tcg_res);
6431 case 0x9: /* SQDMLAL, SQDMLAL2 */
6432 read_vec_element(s, tcg_op1, rd, 0, MO_64);
6433 gen_helper_neon_addl_saturate_s64(tcg_res, cpu_env,
6437 g_assert_not_reached();
6440 write_fp_dreg(s, rd, tcg_res);
6442 tcg_temp_free_i64(tcg_op1);
6443 tcg_temp_free_i64(tcg_op2);
6444 tcg_temp_free_i64(tcg_res);
6446 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
6447 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
6448 TCGv_i64 tcg_res = tcg_temp_new_i64();
6450 read_vec_element_i32(s, tcg_op1, rn, 0, MO_16);
6451 read_vec_element_i32(s, tcg_op2, rm, 0, MO_16);
6453 gen_helper_neon_mull_s16(tcg_res, tcg_op1, tcg_op2);
6454 gen_helper_neon_addl_saturate_s32(tcg_res, cpu_env, tcg_res, tcg_res);
6457 case 0xd: /* SQDMULL, SQDMULL2 */
6459 case 0xb: /* SQDMLSL, SQDMLSL2 */
6460 gen_helper_neon_negl_u32(tcg_res, tcg_res);
6462 case 0x9: /* SQDMLAL, SQDMLAL2 */
6464 TCGv_i64 tcg_op3 = tcg_temp_new_i64();
6465 read_vec_element(s, tcg_op3, rd, 0, MO_32);
6466 gen_helper_neon_addl_saturate_s32(tcg_res, cpu_env,
6468 tcg_temp_free_i64(tcg_op3);
6472 g_assert_not_reached();
6475 tcg_gen_ext32u_i64(tcg_res, tcg_res);
6476 write_fp_dreg(s, rd, tcg_res);
6478 tcg_temp_free_i32(tcg_op1);
6479 tcg_temp_free_i32(tcg_op2);
6480 tcg_temp_free_i64(tcg_res);
6484 static void handle_3same_64(DisasContext *s, int opcode, bool u,
6485 TCGv_i64 tcg_rd, TCGv_i64 tcg_rn, TCGv_i64 tcg_rm)
6487 /* Handle 64x64->64 opcodes which are shared between the scalar
6488 * and vector 3-same groups. We cover every opcode where size == 3
6489 * is valid in either the three-reg-same (integer, not pairwise)
6490 * or scalar-three-reg-same groups. (Some opcodes are not yet
6496 case 0x1: /* SQADD */
6498 gen_helper_neon_qadd_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
6500 gen_helper_neon_qadd_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
6503 case 0x5: /* SQSUB */
6505 gen_helper_neon_qsub_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
6507 gen_helper_neon_qsub_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
6510 case 0x6: /* CMGT, CMHI */
6511 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
6512 * We implement this using setcond (test) and then negating.
6514 cond = u ? TCG_COND_GTU : TCG_COND_GT;
6516 tcg_gen_setcond_i64(cond, tcg_rd, tcg_rn, tcg_rm);
6517 tcg_gen_neg_i64(tcg_rd, tcg_rd);
6519 case 0x7: /* CMGE, CMHS */
6520 cond = u ? TCG_COND_GEU : TCG_COND_GE;
6522 case 0x11: /* CMTST, CMEQ */
6527 /* CMTST : test is "if (X & Y != 0)". */
6528 tcg_gen_and_i64(tcg_rd, tcg_rn, tcg_rm);
6529 tcg_gen_setcondi_i64(TCG_COND_NE, tcg_rd, tcg_rd, 0);
6530 tcg_gen_neg_i64(tcg_rd, tcg_rd);
6532 case 0x8: /* SSHL, USHL */
6534 gen_helper_neon_shl_u64(tcg_rd, tcg_rn, tcg_rm);
6536 gen_helper_neon_shl_s64(tcg_rd, tcg_rn, tcg_rm);
6539 case 0x9: /* SQSHL, UQSHL */
6541 gen_helper_neon_qshl_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
6543 gen_helper_neon_qshl_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
6546 case 0xa: /* SRSHL, URSHL */
6548 gen_helper_neon_rshl_u64(tcg_rd, tcg_rn, tcg_rm);
6550 gen_helper_neon_rshl_s64(tcg_rd, tcg_rn, tcg_rm);
6553 case 0xb: /* SQRSHL, UQRSHL */
6555 gen_helper_neon_qrshl_u64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
6557 gen_helper_neon_qrshl_s64(tcg_rd, cpu_env, tcg_rn, tcg_rm);
6560 case 0x10: /* ADD, SUB */
6562 tcg_gen_sub_i64(tcg_rd, tcg_rn, tcg_rm);
6564 tcg_gen_add_i64(tcg_rd, tcg_rn, tcg_rm);
6568 g_assert_not_reached();
6572 /* Handle the 3-same-operands float operations; shared by the scalar
6573 * and vector encodings. The caller must filter out any encodings
6574 * not allocated for the encoding it is dealing with.
6576 static void handle_3same_float(DisasContext *s, int size, int elements,
6577 int fpopcode, int rd, int rn, int rm)
6580 TCGv_ptr fpst = get_fpstatus_ptr();
6582 for (pass = 0; pass < elements; pass++) {
6585 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
6586 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
6587 TCGv_i64 tcg_res = tcg_temp_new_i64();
6589 read_vec_element(s, tcg_op1, rn, pass, MO_64);
6590 read_vec_element(s, tcg_op2, rm, pass, MO_64);
6593 case 0x39: /* FMLS */
6594 /* As usual for ARM, separate negation for fused multiply-add */
6595 gen_helper_vfp_negd(tcg_op1, tcg_op1);
6597 case 0x19: /* FMLA */
6598 read_vec_element(s, tcg_res, rd, pass, MO_64);
6599 gen_helper_vfp_muladdd(tcg_res, tcg_op1, tcg_op2,
6602 case 0x18: /* FMAXNM */
6603 gen_helper_vfp_maxnumd(tcg_res, tcg_op1, tcg_op2, fpst);
6605 case 0x1a: /* FADD */
6606 gen_helper_vfp_addd(tcg_res, tcg_op1, tcg_op2, fpst);
6608 case 0x1b: /* FMULX */
6609 gen_helper_vfp_mulxd(tcg_res, tcg_op1, tcg_op2, fpst);
6611 case 0x1c: /* FCMEQ */
6612 gen_helper_neon_ceq_f64(tcg_res, tcg_op1, tcg_op2, fpst);
6614 case 0x1e: /* FMAX */
6615 gen_helper_vfp_maxd(tcg_res, tcg_op1, tcg_op2, fpst);
6617 case 0x1f: /* FRECPS */
6618 gen_helper_recpsf_f64(tcg_res, tcg_op1, tcg_op2, fpst);
6620 case 0x38: /* FMINNM */
6621 gen_helper_vfp_minnumd(tcg_res, tcg_op1, tcg_op2, fpst);
6623 case 0x3a: /* FSUB */
6624 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
6626 case 0x3e: /* FMIN */
6627 gen_helper_vfp_mind(tcg_res, tcg_op1, tcg_op2, fpst);
6629 case 0x3f: /* FRSQRTS */
6630 gen_helper_rsqrtsf_f64(tcg_res, tcg_op1, tcg_op2, fpst);
6632 case 0x5b: /* FMUL */
6633 gen_helper_vfp_muld(tcg_res, tcg_op1, tcg_op2, fpst);
6635 case 0x5c: /* FCMGE */
6636 gen_helper_neon_cge_f64(tcg_res, tcg_op1, tcg_op2, fpst);
6638 case 0x5d: /* FACGE */
6639 gen_helper_neon_acge_f64(tcg_res, tcg_op1, tcg_op2, fpst);
6641 case 0x5f: /* FDIV */
6642 gen_helper_vfp_divd(tcg_res, tcg_op1, tcg_op2, fpst);
6644 case 0x7a: /* FABD */
6645 gen_helper_vfp_subd(tcg_res, tcg_op1, tcg_op2, fpst);
6646 gen_helper_vfp_absd(tcg_res, tcg_res);
6648 case 0x7c: /* FCMGT */
6649 gen_helper_neon_cgt_f64(tcg_res, tcg_op1, tcg_op2, fpst);
6651 case 0x7d: /* FACGT */
6652 gen_helper_neon_acgt_f64(tcg_res, tcg_op1, tcg_op2, fpst);
6655 g_assert_not_reached();
6658 write_vec_element(s, tcg_res, rd, pass, MO_64);
6660 tcg_temp_free_i64(tcg_res);
6661 tcg_temp_free_i64(tcg_op1);
6662 tcg_temp_free_i64(tcg_op2);
6665 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
6666 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
6667 TCGv_i32 tcg_res = tcg_temp_new_i32();
6669 read_vec_element_i32(s, tcg_op1, rn, pass, MO_32);
6670 read_vec_element_i32(s, tcg_op2, rm, pass, MO_32);
6673 case 0x39: /* FMLS */
6674 /* As usual for ARM, separate negation for fused multiply-add */
6675 gen_helper_vfp_negs(tcg_op1, tcg_op1);
6677 case 0x19: /* FMLA */
6678 read_vec_element_i32(s, tcg_res, rd, pass, MO_32);
6679 gen_helper_vfp_muladds(tcg_res, tcg_op1, tcg_op2,
6682 case 0x1a: /* FADD */
6683 gen_helper_vfp_adds(tcg_res, tcg_op1, tcg_op2, fpst);
6685 case 0x1b: /* FMULX */
6686 gen_helper_vfp_mulxs(tcg_res, tcg_op1, tcg_op2, fpst);
6688 case 0x1c: /* FCMEQ */
6689 gen_helper_neon_ceq_f32(tcg_res, tcg_op1, tcg_op2, fpst);
6691 case 0x1e: /* FMAX */
6692 gen_helper_vfp_maxs(tcg_res, tcg_op1, tcg_op2, fpst);
6694 case 0x1f: /* FRECPS */
6695 gen_helper_recpsf_f32(tcg_res, tcg_op1, tcg_op2, fpst);
6697 case 0x18: /* FMAXNM */
6698 gen_helper_vfp_maxnums(tcg_res, tcg_op1, tcg_op2, fpst);
6700 case 0x38: /* FMINNM */
6701 gen_helper_vfp_minnums(tcg_res, tcg_op1, tcg_op2, fpst);
6703 case 0x3a: /* FSUB */
6704 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
6706 case 0x3e: /* FMIN */
6707 gen_helper_vfp_mins(tcg_res, tcg_op1, tcg_op2, fpst);
6709 case 0x3f: /* FRSQRTS */
6710 gen_helper_rsqrtsf_f32(tcg_res, tcg_op1, tcg_op2, fpst);
6712 case 0x5b: /* FMUL */
6713 gen_helper_vfp_muls(tcg_res, tcg_op1, tcg_op2, fpst);
6715 case 0x5c: /* FCMGE */
6716 gen_helper_neon_cge_f32(tcg_res, tcg_op1, tcg_op2, fpst);
6718 case 0x5d: /* FACGE */
6719 gen_helper_neon_acge_f32(tcg_res, tcg_op1, tcg_op2, fpst);
6721 case 0x5f: /* FDIV */
6722 gen_helper_vfp_divs(tcg_res, tcg_op1, tcg_op2, fpst);
6724 case 0x7a: /* FABD */
6725 gen_helper_vfp_subs(tcg_res, tcg_op1, tcg_op2, fpst);
6726 gen_helper_vfp_abss(tcg_res, tcg_res);
6728 case 0x7c: /* FCMGT */
6729 gen_helper_neon_cgt_f32(tcg_res, tcg_op1, tcg_op2, fpst);
6731 case 0x7d: /* FACGT */
6732 gen_helper_neon_acgt_f32(tcg_res, tcg_op1, tcg_op2, fpst);
6735 g_assert_not_reached();
6738 if (elements == 1) {
6739 /* scalar single so clear high part */
6740 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
6742 tcg_gen_extu_i32_i64(tcg_tmp, tcg_res);
6743 write_vec_element(s, tcg_tmp, rd, pass, MO_64);
6744 tcg_temp_free_i64(tcg_tmp);
6746 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
6749 tcg_temp_free_i32(tcg_res);
6750 tcg_temp_free_i32(tcg_op1);
6751 tcg_temp_free_i32(tcg_op2);
6755 tcg_temp_free_ptr(fpst);
6757 if ((elements << size) < 4) {
6758 /* scalar, or non-quad vector op */
6759 clear_vec_high(s, rd);
6763 /* C3.6.11 AdvSIMD scalar three same
6764 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
6765 * +-----+---+-----------+------+---+------+--------+---+------+------+
6766 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
6767 * +-----+---+-----------+------+---+------+--------+---+------+------+
6769 static void disas_simd_scalar_three_reg_same(DisasContext *s, uint32_t insn)
6771 int rd = extract32(insn, 0, 5);
6772 int rn = extract32(insn, 5, 5);
6773 int opcode = extract32(insn, 11, 5);
6774 int rm = extract32(insn, 16, 5);
6775 int size = extract32(insn, 22, 2);
6776 bool u = extract32(insn, 29, 1);
6779 if (opcode >= 0x18) {
6780 /* Floating point: U, size[1] and opcode indicate operation */
6781 int fpopcode = opcode | (extract32(size, 1, 1) << 5) | (u << 6);
6783 case 0x1b: /* FMULX */
6784 case 0x1f: /* FRECPS */
6785 case 0x3f: /* FRSQRTS */
6786 case 0x5d: /* FACGE */
6787 case 0x7d: /* FACGT */
6788 case 0x1c: /* FCMEQ */
6789 case 0x5c: /* FCMGE */
6790 case 0x7c: /* FCMGT */
6791 case 0x7a: /* FABD */
6794 unallocated_encoding(s);
6798 handle_3same_float(s, extract32(size, 0, 1), 1, fpopcode, rd, rn, rm);
6803 case 0x1: /* SQADD, UQADD */
6804 case 0x5: /* SQSUB, UQSUB */
6805 case 0x9: /* SQSHL, UQSHL */
6806 case 0xb: /* SQRSHL, UQRSHL */
6808 case 0x8: /* SSHL, USHL */
6809 case 0xa: /* SRSHL, URSHL */
6810 case 0x6: /* CMGT, CMHI */
6811 case 0x7: /* CMGE, CMHS */
6812 case 0x11: /* CMTST, CMEQ */
6813 case 0x10: /* ADD, SUB (vector) */
6815 unallocated_encoding(s);
6819 case 0x16: /* SQDMULH, SQRDMULH (vector) */
6820 if (size != 1 && size != 2) {
6821 unallocated_encoding(s);
6826 unallocated_encoding(s);
6830 tcg_rd = tcg_temp_new_i64();
6833 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
6834 TCGv_i64 tcg_rm = read_fp_dreg(s, rm);
6836 handle_3same_64(s, opcode, u, tcg_rd, tcg_rn, tcg_rm);
6837 tcg_temp_free_i64(tcg_rn);
6838 tcg_temp_free_i64(tcg_rm);
6840 /* Do a single operation on the lowest element in the vector.
6841 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
6842 * no side effects for all these operations.
6843 * OPTME: special-purpose helpers would avoid doing some
6844 * unnecessary work in the helper for the 8 and 16 bit cases.
6846 NeonGenTwoOpEnvFn *genenvfn;
6847 TCGv_i32 tcg_rn = tcg_temp_new_i32();
6848 TCGv_i32 tcg_rm = tcg_temp_new_i32();
6849 TCGv_i32 tcg_rd32 = tcg_temp_new_i32();
6851 read_vec_element_i32(s, tcg_rn, rn, 0, size);
6852 read_vec_element_i32(s, tcg_rm, rm, 0, size);
6855 case 0x1: /* SQADD, UQADD */
6857 static NeonGenTwoOpEnvFn * const fns[3][2] = {
6858 { gen_helper_neon_qadd_s8, gen_helper_neon_qadd_u8 },
6859 { gen_helper_neon_qadd_s16, gen_helper_neon_qadd_u16 },
6860 { gen_helper_neon_qadd_s32, gen_helper_neon_qadd_u32 },
6862 genenvfn = fns[size][u];
6865 case 0x5: /* SQSUB, UQSUB */
6867 static NeonGenTwoOpEnvFn * const fns[3][2] = {
6868 { gen_helper_neon_qsub_s8, gen_helper_neon_qsub_u8 },
6869 { gen_helper_neon_qsub_s16, gen_helper_neon_qsub_u16 },
6870 { gen_helper_neon_qsub_s32, gen_helper_neon_qsub_u32 },
6872 genenvfn = fns[size][u];
6875 case 0x9: /* SQSHL, UQSHL */
6877 static NeonGenTwoOpEnvFn * const fns[3][2] = {
6878 { gen_helper_neon_qshl_s8, gen_helper_neon_qshl_u8 },
6879 { gen_helper_neon_qshl_s16, gen_helper_neon_qshl_u16 },
6880 { gen_helper_neon_qshl_s32, gen_helper_neon_qshl_u32 },
6882 genenvfn = fns[size][u];
6885 case 0xb: /* SQRSHL, UQRSHL */
6887 static NeonGenTwoOpEnvFn * const fns[3][2] = {
6888 { gen_helper_neon_qrshl_s8, gen_helper_neon_qrshl_u8 },
6889 { gen_helper_neon_qrshl_s16, gen_helper_neon_qrshl_u16 },
6890 { gen_helper_neon_qrshl_s32, gen_helper_neon_qrshl_u32 },
6892 genenvfn = fns[size][u];
6895 case 0x16: /* SQDMULH, SQRDMULH */
6897 static NeonGenTwoOpEnvFn * const fns[2][2] = {
6898 { gen_helper_neon_qdmulh_s16, gen_helper_neon_qrdmulh_s16 },
6899 { gen_helper_neon_qdmulh_s32, gen_helper_neon_qrdmulh_s32 },
6901 assert(size == 1 || size == 2);
6902 genenvfn = fns[size - 1][u];
6906 g_assert_not_reached();
6909 genenvfn(tcg_rd32, cpu_env, tcg_rn, tcg_rm);
6910 tcg_gen_extu_i32_i64(tcg_rd, tcg_rd32);
6911 tcg_temp_free_i32(tcg_rd32);
6912 tcg_temp_free_i32(tcg_rn);
6913 tcg_temp_free_i32(tcg_rm);
6916 write_fp_dreg(s, rd, tcg_rd);
6918 tcg_temp_free_i64(tcg_rd);
6921 static void handle_2misc_64(DisasContext *s, int opcode, bool u,
6922 TCGv_i64 tcg_rd, TCGv_i64 tcg_rn,
6923 TCGv_i32 tcg_rmode, TCGv_ptr tcg_fpstatus)
6925 /* Handle 64->64 opcodes which are shared between the scalar and
6926 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
6927 * is valid in either group and also the double-precision fp ops.
6928 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
6934 case 0x4: /* CLS, CLZ */
6936 gen_helper_clz64(tcg_rd, tcg_rn);
6938 gen_helper_cls64(tcg_rd, tcg_rn);
6942 /* This opcode is shared with CNT and RBIT but we have earlier
6943 * enforced that size == 3 if and only if this is the NOT insn.
6945 tcg_gen_not_i64(tcg_rd, tcg_rn);
6947 case 0x7: /* SQABS, SQNEG */
6949 gen_helper_neon_qneg_s64(tcg_rd, cpu_env, tcg_rn);
6951 gen_helper_neon_qabs_s64(tcg_rd, cpu_env, tcg_rn);
6954 case 0xa: /* CMLT */
6955 /* 64 bit integer comparison against zero, result is
6956 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
6961 tcg_gen_setcondi_i64(cond, tcg_rd, tcg_rn, 0);
6962 tcg_gen_neg_i64(tcg_rd, tcg_rd);
6964 case 0x8: /* CMGT, CMGE */
6965 cond = u ? TCG_COND_GE : TCG_COND_GT;
6967 case 0x9: /* CMEQ, CMLE */
6968 cond = u ? TCG_COND_LE : TCG_COND_EQ;
6970 case 0xb: /* ABS, NEG */
6972 tcg_gen_neg_i64(tcg_rd, tcg_rn);
6974 TCGv_i64 tcg_zero = tcg_const_i64(0);
6975 tcg_gen_neg_i64(tcg_rd, tcg_rn);
6976 tcg_gen_movcond_i64(TCG_COND_GT, tcg_rd, tcg_rn, tcg_zero,
6978 tcg_temp_free_i64(tcg_zero);
6981 case 0x2f: /* FABS */
6982 gen_helper_vfp_absd(tcg_rd, tcg_rn);
6984 case 0x6f: /* FNEG */
6985 gen_helper_vfp_negd(tcg_rd, tcg_rn);
6987 case 0x7f: /* FSQRT */
6988 gen_helper_vfp_sqrtd(tcg_rd, tcg_rn, cpu_env);
6990 case 0x1a: /* FCVTNS */
6991 case 0x1b: /* FCVTMS */
6992 case 0x1c: /* FCVTAS */
6993 case 0x3a: /* FCVTPS */
6994 case 0x3b: /* FCVTZS */
6996 TCGv_i32 tcg_shift = tcg_const_i32(0);
6997 gen_helper_vfp_tosqd(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
6998 tcg_temp_free_i32(tcg_shift);
7001 case 0x5a: /* FCVTNU */
7002 case 0x5b: /* FCVTMU */
7003 case 0x5c: /* FCVTAU */
7004 case 0x7a: /* FCVTPU */
7005 case 0x7b: /* FCVTZU */
7007 TCGv_i32 tcg_shift = tcg_const_i32(0);
7008 gen_helper_vfp_touqd(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
7009 tcg_temp_free_i32(tcg_shift);
7012 case 0x18: /* FRINTN */
7013 case 0x19: /* FRINTM */
7014 case 0x38: /* FRINTP */
7015 case 0x39: /* FRINTZ */
7016 case 0x58: /* FRINTA */
7017 case 0x79: /* FRINTI */
7018 gen_helper_rintd(tcg_rd, tcg_rn, tcg_fpstatus);
7020 case 0x59: /* FRINTX */
7021 gen_helper_rintd_exact(tcg_rd, tcg_rn, tcg_fpstatus);
7024 g_assert_not_reached();
7028 static void handle_2misc_fcmp_zero(DisasContext *s, int opcode,
7029 bool is_scalar, bool is_u, bool is_q,
7030 int size, int rn, int rd)
7032 bool is_double = (size == 3);
7033 TCGv_ptr fpst = get_fpstatus_ptr();
7036 TCGv_i64 tcg_op = tcg_temp_new_i64();
7037 TCGv_i64 tcg_zero = tcg_const_i64(0);
7038 TCGv_i64 tcg_res = tcg_temp_new_i64();
7039 NeonGenTwoDoubleOPFn *genfn;
7044 case 0x2e: /* FCMLT (zero) */
7047 case 0x2c: /* FCMGT (zero) */
7048 genfn = gen_helper_neon_cgt_f64;
7050 case 0x2d: /* FCMEQ (zero) */
7051 genfn = gen_helper_neon_ceq_f64;
7053 case 0x6d: /* FCMLE (zero) */
7056 case 0x6c: /* FCMGE (zero) */
7057 genfn = gen_helper_neon_cge_f64;
7060 g_assert_not_reached();
7063 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
7064 read_vec_element(s, tcg_op, rn, pass, MO_64);
7066 genfn(tcg_res, tcg_zero, tcg_op, fpst);
7068 genfn(tcg_res, tcg_op, tcg_zero, fpst);
7070 write_vec_element(s, tcg_res, rd, pass, MO_64);
7073 clear_vec_high(s, rd);
7076 tcg_temp_free_i64(tcg_res);
7077 tcg_temp_free_i64(tcg_zero);
7078 tcg_temp_free_i64(tcg_op);
7080 TCGv_i32 tcg_op = tcg_temp_new_i32();
7081 TCGv_i32 tcg_zero = tcg_const_i32(0);
7082 TCGv_i32 tcg_res = tcg_temp_new_i32();
7083 NeonGenTwoSingleOPFn *genfn;
7085 int pass, maxpasses;
7088 case 0x2e: /* FCMLT (zero) */
7091 case 0x2c: /* FCMGT (zero) */
7092 genfn = gen_helper_neon_cgt_f32;
7094 case 0x2d: /* FCMEQ (zero) */
7095 genfn = gen_helper_neon_ceq_f32;
7097 case 0x6d: /* FCMLE (zero) */
7100 case 0x6c: /* FCMGE (zero) */
7101 genfn = gen_helper_neon_cge_f32;
7104 g_assert_not_reached();
7110 maxpasses = is_q ? 4 : 2;
7113 for (pass = 0; pass < maxpasses; pass++) {
7114 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
7116 genfn(tcg_res, tcg_zero, tcg_op, fpst);
7118 genfn(tcg_res, tcg_op, tcg_zero, fpst);
7121 write_fp_sreg(s, rd, tcg_res);
7123 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
7126 tcg_temp_free_i32(tcg_res);
7127 tcg_temp_free_i32(tcg_zero);
7128 tcg_temp_free_i32(tcg_op);
7129 if (!is_q && !is_scalar) {
7130 clear_vec_high(s, rd);
7134 tcg_temp_free_ptr(fpst);
7137 static void handle_2misc_reciprocal(DisasContext *s, int opcode,
7138 bool is_scalar, bool is_u, bool is_q,
7139 int size, int rn, int rd)
7141 bool is_double = (size == 3);
7142 TCGv_ptr fpst = get_fpstatus_ptr();
7145 TCGv_i64 tcg_op = tcg_temp_new_i64();
7146 TCGv_i64 tcg_res = tcg_temp_new_i64();
7149 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
7150 read_vec_element(s, tcg_op, rn, pass, MO_64);
7152 case 0x3d: /* FRECPE */
7153 gen_helper_recpe_f64(tcg_res, tcg_op, fpst);
7155 case 0x3f: /* FRECPX */
7156 gen_helper_frecpx_f64(tcg_res, tcg_op, fpst);
7158 case 0x7d: /* FRSQRTE */
7159 gen_helper_rsqrte_f64(tcg_res, tcg_op, fpst);
7162 g_assert_not_reached();
7164 write_vec_element(s, tcg_res, rd, pass, MO_64);
7167 clear_vec_high(s, rd);
7170 tcg_temp_free_i64(tcg_res);
7171 tcg_temp_free_i64(tcg_op);
7173 TCGv_i32 tcg_op = tcg_temp_new_i32();
7174 TCGv_i32 tcg_res = tcg_temp_new_i32();
7175 int pass, maxpasses;
7180 maxpasses = is_q ? 4 : 2;
7183 for (pass = 0; pass < maxpasses; pass++) {
7184 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
7187 case 0x3c: /* URECPE */
7188 gen_helper_recpe_u32(tcg_res, tcg_op, fpst);
7190 case 0x3d: /* FRECPE */
7191 gen_helper_recpe_f32(tcg_res, tcg_op, fpst);
7193 case 0x3f: /* FRECPX */
7194 gen_helper_frecpx_f32(tcg_res, tcg_op, fpst);
7196 case 0x7d: /* FRSQRTE */
7197 gen_helper_rsqrte_f32(tcg_res, tcg_op, fpst);
7200 g_assert_not_reached();
7204 write_fp_sreg(s, rd, tcg_res);
7206 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
7209 tcg_temp_free_i32(tcg_res);
7210 tcg_temp_free_i32(tcg_op);
7211 if (!is_q && !is_scalar) {
7212 clear_vec_high(s, rd);
7215 tcg_temp_free_ptr(fpst);
7218 static void handle_2misc_narrow(DisasContext *s, bool scalar,
7219 int opcode, bool u, bool is_q,
7220 int size, int rn, int rd)
7222 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
7223 * in the source becomes a size element in the destination).
7226 TCGv_i32 tcg_res[2];
7227 int destelt = is_q ? 2 : 0;
7228 int passes = scalar ? 1 : 2;
7231 tcg_res[1] = tcg_const_i32(0);
7234 for (pass = 0; pass < passes; pass++) {
7235 TCGv_i64 tcg_op = tcg_temp_new_i64();
7236 NeonGenNarrowFn *genfn = NULL;
7237 NeonGenNarrowEnvFn *genenvfn = NULL;
7240 read_vec_element(s, tcg_op, rn, pass, size + 1);
7242 read_vec_element(s, tcg_op, rn, pass, MO_64);
7244 tcg_res[pass] = tcg_temp_new_i32();
7247 case 0x12: /* XTN, SQXTUN */
7249 static NeonGenNarrowFn * const xtnfns[3] = {
7250 gen_helper_neon_narrow_u8,
7251 gen_helper_neon_narrow_u16,
7252 tcg_gen_trunc_i64_i32,
7254 static NeonGenNarrowEnvFn * const sqxtunfns[3] = {
7255 gen_helper_neon_unarrow_sat8,
7256 gen_helper_neon_unarrow_sat16,
7257 gen_helper_neon_unarrow_sat32,
7260 genenvfn = sqxtunfns[size];
7262 genfn = xtnfns[size];
7266 case 0x14: /* SQXTN, UQXTN */
7268 static NeonGenNarrowEnvFn * const fns[3][2] = {
7269 { gen_helper_neon_narrow_sat_s8,
7270 gen_helper_neon_narrow_sat_u8 },
7271 { gen_helper_neon_narrow_sat_s16,
7272 gen_helper_neon_narrow_sat_u16 },
7273 { gen_helper_neon_narrow_sat_s32,
7274 gen_helper_neon_narrow_sat_u32 },
7276 genenvfn = fns[size][u];
7279 case 0x16: /* FCVTN, FCVTN2 */
7280 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
7282 gen_helper_vfp_fcvtsd(tcg_res[pass], tcg_op, cpu_env);
7284 TCGv_i32 tcg_lo = tcg_temp_new_i32();
7285 TCGv_i32 tcg_hi = tcg_temp_new_i32();
7286 tcg_gen_trunc_i64_i32(tcg_lo, tcg_op);
7287 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo, tcg_lo, cpu_env);
7288 tcg_gen_shri_i64(tcg_op, tcg_op, 32);
7289 tcg_gen_trunc_i64_i32(tcg_hi, tcg_op);
7290 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi, tcg_hi, cpu_env);
7291 tcg_gen_deposit_i32(tcg_res[pass], tcg_lo, tcg_hi, 16, 16);
7292 tcg_temp_free_i32(tcg_lo);
7293 tcg_temp_free_i32(tcg_hi);
7296 case 0x56: /* FCVTXN, FCVTXN2 */
7297 /* 64 bit to 32 bit float conversion
7298 * with von Neumann rounding (round to odd)
7301 gen_helper_fcvtx_f64_to_f32(tcg_res[pass], tcg_op, cpu_env);
7304 g_assert_not_reached();
7308 genfn(tcg_res[pass], tcg_op);
7309 } else if (genenvfn) {
7310 genenvfn(tcg_res[pass], cpu_env, tcg_op);
7313 tcg_temp_free_i64(tcg_op);
7316 for (pass = 0; pass < 2; pass++) {
7317 write_vec_element_i32(s, tcg_res[pass], rd, destelt + pass, MO_32);
7318 tcg_temp_free_i32(tcg_res[pass]);
7321 clear_vec_high(s, rd);
7325 /* Remaining saturating accumulating ops */
7326 static void handle_2misc_satacc(DisasContext *s, bool is_scalar, bool is_u,
7327 bool is_q, int size, int rn, int rd)
7329 bool is_double = (size == 3);
7332 TCGv_i64 tcg_rn = tcg_temp_new_i64();
7333 TCGv_i64 tcg_rd = tcg_temp_new_i64();
7336 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
7337 read_vec_element(s, tcg_rn, rn, pass, MO_64);
7338 read_vec_element(s, tcg_rd, rd, pass, MO_64);
7340 if (is_u) { /* USQADD */
7341 gen_helper_neon_uqadd_s64(tcg_rd, cpu_env, tcg_rn, tcg_rd);
7342 } else { /* SUQADD */
7343 gen_helper_neon_sqadd_u64(tcg_rd, cpu_env, tcg_rn, tcg_rd);
7345 write_vec_element(s, tcg_rd, rd, pass, MO_64);
7348 clear_vec_high(s, rd);
7351 tcg_temp_free_i64(tcg_rd);
7352 tcg_temp_free_i64(tcg_rn);
7354 TCGv_i32 tcg_rn = tcg_temp_new_i32();
7355 TCGv_i32 tcg_rd = tcg_temp_new_i32();
7356 int pass, maxpasses;
7361 maxpasses = is_q ? 4 : 2;
7364 for (pass = 0; pass < maxpasses; pass++) {
7366 read_vec_element_i32(s, tcg_rn, rn, pass, size);
7367 read_vec_element_i32(s, tcg_rd, rd, pass, size);
7369 read_vec_element_i32(s, tcg_rn, rn, pass, MO_32);
7370 read_vec_element_i32(s, tcg_rd, rd, pass, MO_32);
7373 if (is_u) { /* USQADD */
7376 gen_helper_neon_uqadd_s8(tcg_rd, cpu_env, tcg_rn, tcg_rd);
7379 gen_helper_neon_uqadd_s16(tcg_rd, cpu_env, tcg_rn, tcg_rd);
7382 gen_helper_neon_uqadd_s32(tcg_rd, cpu_env, tcg_rn, tcg_rd);
7385 g_assert_not_reached();
7387 } else { /* SUQADD */
7390 gen_helper_neon_sqadd_u8(tcg_rd, cpu_env, tcg_rn, tcg_rd);
7393 gen_helper_neon_sqadd_u16(tcg_rd, cpu_env, tcg_rn, tcg_rd);
7396 gen_helper_neon_sqadd_u32(tcg_rd, cpu_env, tcg_rn, tcg_rd);
7399 g_assert_not_reached();
7404 TCGv_i64 tcg_zero = tcg_const_i64(0);
7405 write_vec_element(s, tcg_zero, rd, 0, MO_64);
7406 tcg_temp_free_i64(tcg_zero);
7408 write_vec_element_i32(s, tcg_rd, rd, pass, MO_32);
7412 clear_vec_high(s, rd);
7415 tcg_temp_free_i32(tcg_rd);
7416 tcg_temp_free_i32(tcg_rn);
7420 /* C3.6.12 AdvSIMD scalar two reg misc
7421 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7422 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7423 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
7424 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7426 static void disas_simd_scalar_two_reg_misc(DisasContext *s, uint32_t insn)
7428 int rd = extract32(insn, 0, 5);
7429 int rn = extract32(insn, 5, 5);
7430 int opcode = extract32(insn, 12, 5);
7431 int size = extract32(insn, 22, 2);
7432 bool u = extract32(insn, 29, 1);
7433 bool is_fcvt = false;
7436 TCGv_ptr tcg_fpstatus;
7439 case 0x3: /* USQADD / SUQADD*/
7440 handle_2misc_satacc(s, true, u, false, size, rn, rd);
7442 case 0x7: /* SQABS / SQNEG */
7444 case 0xa: /* CMLT */
7446 unallocated_encoding(s);
7450 case 0x8: /* CMGT, CMGE */
7451 case 0x9: /* CMEQ, CMLE */
7452 case 0xb: /* ABS, NEG */
7454 unallocated_encoding(s);
7458 case 0x12: /* SQXTUN */
7460 unallocated_encoding(s);
7464 case 0x14: /* SQXTN, UQXTN */
7466 unallocated_encoding(s);
7469 handle_2misc_narrow(s, true, opcode, u, false, size, rn, rd);
7474 /* Floating point: U, size[1] and opcode indicate operation;
7475 * size[0] indicates single or double precision.
7477 opcode |= (extract32(size, 1, 1) << 5) | (u << 6);
7478 size = extract32(size, 0, 1) ? 3 : 2;
7480 case 0x2c: /* FCMGT (zero) */
7481 case 0x2d: /* FCMEQ (zero) */
7482 case 0x2e: /* FCMLT (zero) */
7483 case 0x6c: /* FCMGE (zero) */
7484 case 0x6d: /* FCMLE (zero) */
7485 handle_2misc_fcmp_zero(s, opcode, true, u, true, size, rn, rd);
7487 case 0x1d: /* SCVTF */
7488 case 0x5d: /* UCVTF */
7490 bool is_signed = (opcode == 0x1d);
7491 handle_simd_intfp_conv(s, rd, rn, 1, is_signed, 0, size);
7494 case 0x3d: /* FRECPE */
7495 case 0x3f: /* FRECPX */
7496 case 0x7d: /* FRSQRTE */
7497 handle_2misc_reciprocal(s, opcode, true, u, true, size, rn, rd);
7499 case 0x1a: /* FCVTNS */
7500 case 0x1b: /* FCVTMS */
7501 case 0x3a: /* FCVTPS */
7502 case 0x3b: /* FCVTZS */
7503 case 0x5a: /* FCVTNU */
7504 case 0x5b: /* FCVTMU */
7505 case 0x7a: /* FCVTPU */
7506 case 0x7b: /* FCVTZU */
7508 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
7510 case 0x1c: /* FCVTAS */
7511 case 0x5c: /* FCVTAU */
7512 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
7514 rmode = FPROUNDING_TIEAWAY;
7516 case 0x56: /* FCVTXN, FCVTXN2 */
7518 unallocated_encoding(s);
7521 handle_2misc_narrow(s, true, opcode, u, false, size - 1, rn, rd);
7524 unallocated_encoding(s);
7529 unallocated_encoding(s);
7534 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
7535 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
7536 tcg_fpstatus = get_fpstatus_ptr();
7538 TCGV_UNUSED_I32(tcg_rmode);
7539 TCGV_UNUSED_PTR(tcg_fpstatus);
7543 TCGv_i64 tcg_rn = read_fp_dreg(s, rn);
7544 TCGv_i64 tcg_rd = tcg_temp_new_i64();
7546 handle_2misc_64(s, opcode, u, tcg_rd, tcg_rn, tcg_rmode, tcg_fpstatus);
7547 write_fp_dreg(s, rd, tcg_rd);
7548 tcg_temp_free_i64(tcg_rd);
7549 tcg_temp_free_i64(tcg_rn);
7551 TCGv_i32 tcg_rn = tcg_temp_new_i32();
7552 TCGv_i32 tcg_rd = tcg_temp_new_i32();
7554 read_vec_element_i32(s, tcg_rn, rn, 0, size);
7557 case 0x7: /* SQABS, SQNEG */
7559 NeonGenOneOpEnvFn *genfn;
7560 static NeonGenOneOpEnvFn * const fns[3][2] = {
7561 { gen_helper_neon_qabs_s8, gen_helper_neon_qneg_s8 },
7562 { gen_helper_neon_qabs_s16, gen_helper_neon_qneg_s16 },
7563 { gen_helper_neon_qabs_s32, gen_helper_neon_qneg_s32 },
7565 genfn = fns[size][u];
7566 genfn(tcg_rd, cpu_env, tcg_rn);
7569 case 0x1a: /* FCVTNS */
7570 case 0x1b: /* FCVTMS */
7571 case 0x1c: /* FCVTAS */
7572 case 0x3a: /* FCVTPS */
7573 case 0x3b: /* FCVTZS */
7575 TCGv_i32 tcg_shift = tcg_const_i32(0);
7576 gen_helper_vfp_tosls(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
7577 tcg_temp_free_i32(tcg_shift);
7580 case 0x5a: /* FCVTNU */
7581 case 0x5b: /* FCVTMU */
7582 case 0x5c: /* FCVTAU */
7583 case 0x7a: /* FCVTPU */
7584 case 0x7b: /* FCVTZU */
7586 TCGv_i32 tcg_shift = tcg_const_i32(0);
7587 gen_helper_vfp_touls(tcg_rd, tcg_rn, tcg_shift, tcg_fpstatus);
7588 tcg_temp_free_i32(tcg_shift);
7592 g_assert_not_reached();
7595 write_fp_sreg(s, rd, tcg_rd);
7596 tcg_temp_free_i32(tcg_rd);
7597 tcg_temp_free_i32(tcg_rn);
7601 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
7602 tcg_temp_free_i32(tcg_rmode);
7603 tcg_temp_free_ptr(tcg_fpstatus);
7607 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
7608 static void handle_vec_simd_shri(DisasContext *s, bool is_q, bool is_u,
7609 int immh, int immb, int opcode, int rn, int rd)
7611 int size = 32 - clz32(immh) - 1;
7612 int immhb = immh << 3 | immb;
7613 int shift = 2 * (8 << size) - immhb;
7614 bool accumulate = false;
7616 bool insert = false;
7617 int dsize = is_q ? 128 : 64;
7618 int esize = 8 << size;
7619 int elements = dsize/esize;
7620 TCGMemOp memop = size | (is_u ? 0 : MO_SIGN);
7621 TCGv_i64 tcg_rn = new_tmp_a64(s);
7622 TCGv_i64 tcg_rd = new_tmp_a64(s);
7626 if (extract32(immh, 3, 1) && !is_q) {
7627 unallocated_encoding(s);
7631 if (size > 3 && !is_q) {
7632 unallocated_encoding(s);
7637 case 0x02: /* SSRA / USRA (accumulate) */
7640 case 0x04: /* SRSHR / URSHR (rounding) */
7643 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7644 accumulate = round = true;
7646 case 0x08: /* SRI */
7652 uint64_t round_const = 1ULL << (shift - 1);
7653 tcg_round = tcg_const_i64(round_const);
7655 TCGV_UNUSED_I64(tcg_round);
7658 for (i = 0; i < elements; i++) {
7659 read_vec_element(s, tcg_rn, rn, i, memop);
7660 if (accumulate || insert) {
7661 read_vec_element(s, tcg_rd, rd, i, memop);
7665 handle_shri_with_ins(tcg_rd, tcg_rn, size, shift);
7667 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
7668 accumulate, is_u, size, shift);
7671 write_vec_element(s, tcg_rd, rd, i, size);
7675 clear_vec_high(s, rd);
7679 tcg_temp_free_i64(tcg_round);
7683 /* SHL/SLI - Vector shift left */
7684 static void handle_vec_simd_shli(DisasContext *s, bool is_q, bool insert,
7685 int immh, int immb, int opcode, int rn, int rd)
7687 int size = 32 - clz32(immh) - 1;
7688 int immhb = immh << 3 | immb;
7689 int shift = immhb - (8 << size);
7690 int dsize = is_q ? 128 : 64;
7691 int esize = 8 << size;
7692 int elements = dsize/esize;
7693 TCGv_i64 tcg_rn = new_tmp_a64(s);
7694 TCGv_i64 tcg_rd = new_tmp_a64(s);
7697 if (extract32(immh, 3, 1) && !is_q) {
7698 unallocated_encoding(s);
7702 if (size > 3 && !is_q) {
7703 unallocated_encoding(s);
7707 for (i = 0; i < elements; i++) {
7708 read_vec_element(s, tcg_rn, rn, i, size);
7710 read_vec_element(s, tcg_rd, rd, i, size);
7713 handle_shli_with_ins(tcg_rd, tcg_rn, insert, shift);
7715 write_vec_element(s, tcg_rd, rd, i, size);
7719 clear_vec_high(s, rd);
7723 /* USHLL/SHLL - Vector shift left with widening */
7724 static void handle_vec_simd_wshli(DisasContext *s, bool is_q, bool is_u,
7725 int immh, int immb, int opcode, int rn, int rd)
7727 int size = 32 - clz32(immh) - 1;
7728 int immhb = immh << 3 | immb;
7729 int shift = immhb - (8 << size);
7731 int esize = 8 << size;
7732 int elements = dsize/esize;
7733 TCGv_i64 tcg_rn = new_tmp_a64(s);
7734 TCGv_i64 tcg_rd = new_tmp_a64(s);
7738 unallocated_encoding(s);
7742 /* For the LL variants the store is larger than the load,
7743 * so if rd == rn we would overwrite parts of our input.
7744 * So load everything right now and use shifts in the main loop.
7746 read_vec_element(s, tcg_rn, rn, is_q ? 1 : 0, MO_64);
7748 for (i = 0; i < elements; i++) {
7749 tcg_gen_shri_i64(tcg_rd, tcg_rn, i * esize);
7750 ext_and_shift_reg(tcg_rd, tcg_rd, size | (!is_u << 2), 0);
7751 tcg_gen_shli_i64(tcg_rd, tcg_rd, shift);
7752 write_vec_element(s, tcg_rd, rd, i, size + 1);
7756 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
7757 static void handle_vec_simd_shrn(DisasContext *s, bool is_q,
7758 int immh, int immb, int opcode, int rn, int rd)
7760 int immhb = immh << 3 | immb;
7761 int size = 32 - clz32(immh) - 1;
7763 int esize = 8 << size;
7764 int elements = dsize/esize;
7765 int shift = (2 * esize) - immhb;
7766 bool round = extract32(opcode, 0, 1);
7767 TCGv_i64 tcg_rn, tcg_rd, tcg_final;
7771 if (extract32(immh, 3, 1)) {
7772 unallocated_encoding(s);
7776 tcg_rn = tcg_temp_new_i64();
7777 tcg_rd = tcg_temp_new_i64();
7778 tcg_final = tcg_temp_new_i64();
7779 read_vec_element(s, tcg_final, rd, is_q ? 1 : 0, MO_64);
7782 uint64_t round_const = 1ULL << (shift - 1);
7783 tcg_round = tcg_const_i64(round_const);
7785 TCGV_UNUSED_I64(tcg_round);
7788 for (i = 0; i < elements; i++) {
7789 read_vec_element(s, tcg_rn, rn, i, size+1);
7790 handle_shri_with_rndacc(tcg_rd, tcg_rn, tcg_round,
7791 false, true, size+1, shift);
7793 tcg_gen_deposit_i64(tcg_final, tcg_final, tcg_rd, esize * i, esize);
7797 clear_vec_high(s, rd);
7798 write_vec_element(s, tcg_final, rd, 0, MO_64);
7800 write_vec_element(s, tcg_final, rd, 1, MO_64);
7804 tcg_temp_free_i64(tcg_round);
7806 tcg_temp_free_i64(tcg_rn);
7807 tcg_temp_free_i64(tcg_rd);
7808 tcg_temp_free_i64(tcg_final);
7813 /* C3.6.14 AdvSIMD shift by immediate
7814 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
7815 * +---+---+---+-------------+------+------+--------+---+------+------+
7816 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
7817 * +---+---+---+-------------+------+------+--------+---+------+------+
7819 static void disas_simd_shift_imm(DisasContext *s, uint32_t insn)
7821 int rd = extract32(insn, 0, 5);
7822 int rn = extract32(insn, 5, 5);
7823 int opcode = extract32(insn, 11, 5);
7824 int immb = extract32(insn, 16, 3);
7825 int immh = extract32(insn, 19, 4);
7826 bool is_u = extract32(insn, 29, 1);
7827 bool is_q = extract32(insn, 30, 1);
7830 case 0x08: /* SRI */
7832 unallocated_encoding(s);
7836 case 0x00: /* SSHR / USHR */
7837 case 0x02: /* SSRA / USRA (accumulate) */
7838 case 0x04: /* SRSHR / URSHR (rounding) */
7839 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7840 handle_vec_simd_shri(s, is_q, is_u, immh, immb, opcode, rn, rd);
7842 case 0x0a: /* SHL / SLI */
7843 handle_vec_simd_shli(s, is_q, is_u, immh, immb, opcode, rn, rd);
7845 case 0x10: /* SHRN */
7846 case 0x11: /* RSHRN / SQRSHRUN */
7848 handle_vec_simd_sqshrn(s, false, is_q, false, true, immh, immb,
7851 handle_vec_simd_shrn(s, is_q, immh, immb, opcode, rn, rd);
7854 case 0x12: /* SQSHRN / UQSHRN */
7855 case 0x13: /* SQRSHRN / UQRSHRN */
7856 handle_vec_simd_sqshrn(s, false, is_q, is_u, is_u, immh, immb,
7859 case 0x14: /* SSHLL / USHLL */
7860 handle_vec_simd_wshli(s, is_q, is_u, immh, immb, opcode, rn, rd);
7862 case 0x1c: /* SCVTF / UCVTF */
7863 handle_simd_shift_intfp_conv(s, false, is_q, is_u, immh, immb,
7866 case 0xc: /* SQSHLU */
7868 unallocated_encoding(s);
7871 handle_simd_qshl(s, false, is_q, false, true, immh, immb, rn, rd);
7873 case 0xe: /* SQSHL, UQSHL */
7874 handle_simd_qshl(s, false, is_q, is_u, is_u, immh, immb, rn, rd);
7876 case 0x1f: /* FCVTZS/ FCVTZU */
7877 handle_simd_shift_fpint_conv(s, false, is_q, is_u, immh, immb, rn, rd);
7880 unallocated_encoding(s);
7885 /* Generate code to do a "long" addition or subtraction, ie one done in
7886 * TCGv_i64 on vector lanes twice the width specified by size.
7888 static void gen_neon_addl(int size, bool is_sub, TCGv_i64 tcg_res,
7889 TCGv_i64 tcg_op1, TCGv_i64 tcg_op2)
7891 static NeonGenTwo64OpFn * const fns[3][2] = {
7892 { gen_helper_neon_addl_u16, gen_helper_neon_subl_u16 },
7893 { gen_helper_neon_addl_u32, gen_helper_neon_subl_u32 },
7894 { tcg_gen_add_i64, tcg_gen_sub_i64 },
7896 NeonGenTwo64OpFn *genfn;
7899 genfn = fns[size][is_sub];
7900 genfn(tcg_res, tcg_op1, tcg_op2);
7903 static void handle_3rd_widening(DisasContext *s, int is_q, int is_u, int size,
7904 int opcode, int rd, int rn, int rm)
7906 /* 3-reg-different widening insns: 64 x 64 -> 128 */
7907 TCGv_i64 tcg_res[2];
7910 tcg_res[0] = tcg_temp_new_i64();
7911 tcg_res[1] = tcg_temp_new_i64();
7913 /* Does this op do an adding accumulate, a subtracting accumulate,
7914 * or no accumulate at all?
7932 read_vec_element(s, tcg_res[0], rd, 0, MO_64);
7933 read_vec_element(s, tcg_res[1], rd, 1, MO_64);
7936 /* size == 2 means two 32x32->64 operations; this is worth special
7937 * casing because we can generally handle it inline.
7940 for (pass = 0; pass < 2; pass++) {
7941 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
7942 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
7943 TCGv_i64 tcg_passres;
7944 TCGMemOp memop = MO_32 | (is_u ? 0 : MO_SIGN);
7946 int elt = pass + is_q * 2;
7948 read_vec_element(s, tcg_op1, rn, elt, memop);
7949 read_vec_element(s, tcg_op2, rm, elt, memop);
7952 tcg_passres = tcg_res[pass];
7954 tcg_passres = tcg_temp_new_i64();
7958 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
7959 tcg_gen_add_i64(tcg_passres, tcg_op1, tcg_op2);
7961 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
7962 tcg_gen_sub_i64(tcg_passres, tcg_op1, tcg_op2);
7964 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
7965 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
7967 TCGv_i64 tcg_tmp1 = tcg_temp_new_i64();
7968 TCGv_i64 tcg_tmp2 = tcg_temp_new_i64();
7970 tcg_gen_sub_i64(tcg_tmp1, tcg_op1, tcg_op2);
7971 tcg_gen_sub_i64(tcg_tmp2, tcg_op2, tcg_op1);
7972 tcg_gen_movcond_i64(is_u ? TCG_COND_GEU : TCG_COND_GE,
7974 tcg_op1, tcg_op2, tcg_tmp1, tcg_tmp2);
7975 tcg_temp_free_i64(tcg_tmp1);
7976 tcg_temp_free_i64(tcg_tmp2);
7979 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
7980 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
7981 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
7982 tcg_gen_mul_i64(tcg_passres, tcg_op1, tcg_op2);
7984 case 9: /* SQDMLAL, SQDMLAL2 */
7985 case 11: /* SQDMLSL, SQDMLSL2 */
7986 case 13: /* SQDMULL, SQDMULL2 */
7987 tcg_gen_mul_i64(tcg_passres, tcg_op1, tcg_op2);
7988 gen_helper_neon_addl_saturate_s64(tcg_passres, cpu_env,
7989 tcg_passres, tcg_passres);
7992 g_assert_not_reached();
7995 if (opcode == 9 || opcode == 11) {
7996 /* saturating accumulate ops */
7998 tcg_gen_neg_i64(tcg_passres, tcg_passres);
8000 gen_helper_neon_addl_saturate_s64(tcg_res[pass], cpu_env,
8001 tcg_res[pass], tcg_passres);
8002 } else if (accop > 0) {
8003 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
8004 } else if (accop < 0) {
8005 tcg_gen_sub_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
8009 tcg_temp_free_i64(tcg_passres);
8012 tcg_temp_free_i64(tcg_op1);
8013 tcg_temp_free_i64(tcg_op2);
8016 /* size 0 or 1, generally helper functions */
8017 for (pass = 0; pass < 2; pass++) {
8018 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
8019 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
8020 TCGv_i64 tcg_passres;
8021 int elt = pass + is_q * 2;
8023 read_vec_element_i32(s, tcg_op1, rn, elt, MO_32);
8024 read_vec_element_i32(s, tcg_op2, rm, elt, MO_32);
8027 tcg_passres = tcg_res[pass];
8029 tcg_passres = tcg_temp_new_i64();
8033 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8034 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8036 TCGv_i64 tcg_op2_64 = tcg_temp_new_i64();
8037 static NeonGenWidenFn * const widenfns[2][2] = {
8038 { gen_helper_neon_widen_s8, gen_helper_neon_widen_u8 },
8039 { gen_helper_neon_widen_s16, gen_helper_neon_widen_u16 },
8041 NeonGenWidenFn *widenfn = widenfns[size][is_u];
8043 widenfn(tcg_op2_64, tcg_op2);
8044 widenfn(tcg_passres, tcg_op1);
8045 gen_neon_addl(size, (opcode == 2), tcg_passres,
8046 tcg_passres, tcg_op2_64);
8047 tcg_temp_free_i64(tcg_op2_64);
8050 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8051 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8054 gen_helper_neon_abdl_u16(tcg_passres, tcg_op1, tcg_op2);
8056 gen_helper_neon_abdl_s16(tcg_passres, tcg_op1, tcg_op2);
8060 gen_helper_neon_abdl_u32(tcg_passres, tcg_op1, tcg_op2);
8062 gen_helper_neon_abdl_s32(tcg_passres, tcg_op1, tcg_op2);
8066 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8067 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8068 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8071 gen_helper_neon_mull_u8(tcg_passres, tcg_op1, tcg_op2);
8073 gen_helper_neon_mull_s8(tcg_passres, tcg_op1, tcg_op2);
8077 gen_helper_neon_mull_u16(tcg_passres, tcg_op1, tcg_op2);
8079 gen_helper_neon_mull_s16(tcg_passres, tcg_op1, tcg_op2);
8083 case 9: /* SQDMLAL, SQDMLAL2 */
8084 case 11: /* SQDMLSL, SQDMLSL2 */
8085 case 13: /* SQDMULL, SQDMULL2 */
8087 gen_helper_neon_mull_s16(tcg_passres, tcg_op1, tcg_op2);
8088 gen_helper_neon_addl_saturate_s32(tcg_passres, cpu_env,
8089 tcg_passres, tcg_passres);
8091 case 14: /* PMULL */
8093 gen_helper_neon_mull_p8(tcg_passres, tcg_op1, tcg_op2);
8096 g_assert_not_reached();
8098 tcg_temp_free_i32(tcg_op1);
8099 tcg_temp_free_i32(tcg_op2);
8102 if (opcode == 9 || opcode == 11) {
8103 /* saturating accumulate ops */
8105 gen_helper_neon_negl_u32(tcg_passres, tcg_passres);
8107 gen_helper_neon_addl_saturate_s32(tcg_res[pass], cpu_env,
8111 gen_neon_addl(size, (accop < 0), tcg_res[pass],
8112 tcg_res[pass], tcg_passres);
8114 tcg_temp_free_i64(tcg_passres);
8119 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
8120 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
8121 tcg_temp_free_i64(tcg_res[0]);
8122 tcg_temp_free_i64(tcg_res[1]);
8125 static void handle_3rd_wide(DisasContext *s, int is_q, int is_u, int size,
8126 int opcode, int rd, int rn, int rm)
8128 TCGv_i64 tcg_res[2];
8129 int part = is_q ? 2 : 0;
8132 for (pass = 0; pass < 2; pass++) {
8133 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8134 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
8135 TCGv_i64 tcg_op2_wide = tcg_temp_new_i64();
8136 static NeonGenWidenFn * const widenfns[3][2] = {
8137 { gen_helper_neon_widen_s8, gen_helper_neon_widen_u8 },
8138 { gen_helper_neon_widen_s16, gen_helper_neon_widen_u16 },
8139 { tcg_gen_ext_i32_i64, tcg_gen_extu_i32_i64 },
8141 NeonGenWidenFn *widenfn = widenfns[size][is_u];
8143 read_vec_element(s, tcg_op1, rn, pass, MO_64);
8144 read_vec_element_i32(s, tcg_op2, rm, part + pass, MO_32);
8145 widenfn(tcg_op2_wide, tcg_op2);
8146 tcg_temp_free_i32(tcg_op2);
8147 tcg_res[pass] = tcg_temp_new_i64();
8148 gen_neon_addl(size, (opcode == 3),
8149 tcg_res[pass], tcg_op1, tcg_op2_wide);
8150 tcg_temp_free_i64(tcg_op1);
8151 tcg_temp_free_i64(tcg_op2_wide);
8154 for (pass = 0; pass < 2; pass++) {
8155 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
8156 tcg_temp_free_i64(tcg_res[pass]);
8160 static void do_narrow_high_u32(TCGv_i32 res, TCGv_i64 in)
8162 tcg_gen_shri_i64(in, in, 32);
8163 tcg_gen_trunc_i64_i32(res, in);
8166 static void do_narrow_round_high_u32(TCGv_i32 res, TCGv_i64 in)
8168 tcg_gen_addi_i64(in, in, 1U << 31);
8169 do_narrow_high_u32(res, in);
8172 static void handle_3rd_narrowing(DisasContext *s, int is_q, int is_u, int size,
8173 int opcode, int rd, int rn, int rm)
8175 TCGv_i32 tcg_res[2];
8176 int part = is_q ? 2 : 0;
8179 for (pass = 0; pass < 2; pass++) {
8180 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8181 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8182 TCGv_i64 tcg_wideres = tcg_temp_new_i64();
8183 static NeonGenNarrowFn * const narrowfns[3][2] = {
8184 { gen_helper_neon_narrow_high_u8,
8185 gen_helper_neon_narrow_round_high_u8 },
8186 { gen_helper_neon_narrow_high_u16,
8187 gen_helper_neon_narrow_round_high_u16 },
8188 { do_narrow_high_u32, do_narrow_round_high_u32 },
8190 NeonGenNarrowFn *gennarrow = narrowfns[size][is_u];
8192 read_vec_element(s, tcg_op1, rn, pass, MO_64);
8193 read_vec_element(s, tcg_op2, rm, pass, MO_64);
8195 gen_neon_addl(size, (opcode == 6), tcg_wideres, tcg_op1, tcg_op2);
8197 tcg_temp_free_i64(tcg_op1);
8198 tcg_temp_free_i64(tcg_op2);
8200 tcg_res[pass] = tcg_temp_new_i32();
8201 gennarrow(tcg_res[pass], tcg_wideres);
8202 tcg_temp_free_i64(tcg_wideres);
8205 for (pass = 0; pass < 2; pass++) {
8206 write_vec_element_i32(s, tcg_res[pass], rd, pass + part, MO_32);
8207 tcg_temp_free_i32(tcg_res[pass]);
8210 clear_vec_high(s, rd);
8214 static void handle_pmull_64(DisasContext *s, int is_q, int rd, int rn, int rm)
8216 /* PMULL of 64 x 64 -> 128 is an odd special case because it
8217 * is the only three-reg-diff instruction which produces a
8218 * 128-bit wide result from a single operation. However since
8219 * it's possible to calculate the two halves more or less
8220 * separately we just use two helper calls.
8222 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8223 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8224 TCGv_i64 tcg_res = tcg_temp_new_i64();
8226 read_vec_element(s, tcg_op1, rn, is_q, MO_64);
8227 read_vec_element(s, tcg_op2, rm, is_q, MO_64);
8228 gen_helper_neon_pmull_64_lo(tcg_res, tcg_op1, tcg_op2);
8229 write_vec_element(s, tcg_res, rd, 0, MO_64);
8230 gen_helper_neon_pmull_64_hi(tcg_res, tcg_op1, tcg_op2);
8231 write_vec_element(s, tcg_res, rd, 1, MO_64);
8233 tcg_temp_free_i64(tcg_op1);
8234 tcg_temp_free_i64(tcg_op2);
8235 tcg_temp_free_i64(tcg_res);
8238 /* C3.6.15 AdvSIMD three different
8239 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8240 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8241 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8242 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8244 static void disas_simd_three_reg_diff(DisasContext *s, uint32_t insn)
8246 /* Instructions in this group fall into three basic classes
8247 * (in each case with the operation working on each element in
8248 * the input vectors):
8249 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
8251 * (2) wide 64 x 128 -> 128
8252 * (3) narrowing 128 x 128 -> 64
8253 * Here we do initial decode, catch unallocated cases and
8254 * dispatch to separate functions for each class.
8256 int is_q = extract32(insn, 30, 1);
8257 int is_u = extract32(insn, 29, 1);
8258 int size = extract32(insn, 22, 2);
8259 int opcode = extract32(insn, 12, 4);
8260 int rm = extract32(insn, 16, 5);
8261 int rn = extract32(insn, 5, 5);
8262 int rd = extract32(insn, 0, 5);
8265 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
8266 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
8267 /* 64 x 128 -> 128 */
8269 unallocated_encoding(s);
8272 handle_3rd_wide(s, is_q, is_u, size, opcode, rd, rn, rm);
8274 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
8275 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
8276 /* 128 x 128 -> 64 */
8278 unallocated_encoding(s);
8281 handle_3rd_narrowing(s, is_q, is_u, size, opcode, rd, rn, rm);
8283 case 14: /* PMULL, PMULL2 */
8284 if (is_u || size == 1 || size == 2) {
8285 unallocated_encoding(s);
8289 if (!arm_dc_feature(s, ARM_FEATURE_V8_AES)) {
8290 unallocated_encoding(s);
8293 handle_pmull_64(s, is_q, rd, rn, rm);
8297 case 9: /* SQDMLAL, SQDMLAL2 */
8298 case 11: /* SQDMLSL, SQDMLSL2 */
8299 case 13: /* SQDMULL, SQDMULL2 */
8300 if (is_u || size == 0) {
8301 unallocated_encoding(s);
8305 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8306 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8307 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8308 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8309 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8310 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8311 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
8312 /* 64 x 64 -> 128 */
8314 unallocated_encoding(s);
8318 handle_3rd_widening(s, is_q, is_u, size, opcode, rd, rn, rm);
8321 /* opcode 15 not allocated */
8322 unallocated_encoding(s);
8327 /* Logic op (opcode == 3) subgroup of C3.6.16. */
8328 static void disas_simd_3same_logic(DisasContext *s, uint32_t insn)
8330 int rd = extract32(insn, 0, 5);
8331 int rn = extract32(insn, 5, 5);
8332 int rm = extract32(insn, 16, 5);
8333 int size = extract32(insn, 22, 2);
8334 bool is_u = extract32(insn, 29, 1);
8335 bool is_q = extract32(insn, 30, 1);
8336 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8337 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8338 TCGv_i64 tcg_res[2];
8341 tcg_res[0] = tcg_temp_new_i64();
8342 tcg_res[1] = tcg_temp_new_i64();
8344 for (pass = 0; pass < (is_q ? 2 : 1); pass++) {
8345 read_vec_element(s, tcg_op1, rn, pass, MO_64);
8346 read_vec_element(s, tcg_op2, rm, pass, MO_64);
8351 tcg_gen_and_i64(tcg_res[pass], tcg_op1, tcg_op2);
8354 tcg_gen_andc_i64(tcg_res[pass], tcg_op1, tcg_op2);
8357 tcg_gen_or_i64(tcg_res[pass], tcg_op1, tcg_op2);
8360 tcg_gen_orc_i64(tcg_res[pass], tcg_op1, tcg_op2);
8365 /* B* ops need res loaded to operate on */
8366 read_vec_element(s, tcg_res[pass], rd, pass, MO_64);
8371 tcg_gen_xor_i64(tcg_res[pass], tcg_op1, tcg_op2);
8373 case 1: /* BSL bitwise select */
8374 tcg_gen_xor_i64(tcg_op1, tcg_op1, tcg_op2);
8375 tcg_gen_and_i64(tcg_op1, tcg_op1, tcg_res[pass]);
8376 tcg_gen_xor_i64(tcg_res[pass], tcg_op2, tcg_op1);
8378 case 2: /* BIT, bitwise insert if true */
8379 tcg_gen_xor_i64(tcg_op1, tcg_op1, tcg_res[pass]);
8380 tcg_gen_and_i64(tcg_op1, tcg_op1, tcg_op2);
8381 tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
8383 case 3: /* BIF, bitwise insert if false */
8384 tcg_gen_xor_i64(tcg_op1, tcg_op1, tcg_res[pass]);
8385 tcg_gen_andc_i64(tcg_op1, tcg_op1, tcg_op2);
8386 tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
8392 write_vec_element(s, tcg_res[0], rd, 0, MO_64);
8394 tcg_gen_movi_i64(tcg_res[1], 0);
8396 write_vec_element(s, tcg_res[1], rd, 1, MO_64);
8398 tcg_temp_free_i64(tcg_op1);
8399 tcg_temp_free_i64(tcg_op2);
8400 tcg_temp_free_i64(tcg_res[0]);
8401 tcg_temp_free_i64(tcg_res[1]);
8404 /* Helper functions for 32 bit comparisons */
8405 static void gen_max_s32(TCGv_i32 res, TCGv_i32 op1, TCGv_i32 op2)
8407 tcg_gen_movcond_i32(TCG_COND_GE, res, op1, op2, op1, op2);
8410 static void gen_max_u32(TCGv_i32 res, TCGv_i32 op1, TCGv_i32 op2)
8412 tcg_gen_movcond_i32(TCG_COND_GEU, res, op1, op2, op1, op2);
8415 static void gen_min_s32(TCGv_i32 res, TCGv_i32 op1, TCGv_i32 op2)
8417 tcg_gen_movcond_i32(TCG_COND_LE, res, op1, op2, op1, op2);
8420 static void gen_min_u32(TCGv_i32 res, TCGv_i32 op1, TCGv_i32 op2)
8422 tcg_gen_movcond_i32(TCG_COND_LEU, res, op1, op2, op1, op2);
8425 /* Pairwise op subgroup of C3.6.16.
8427 * This is called directly or via the handle_3same_float for float pairwise
8428 * operations where the opcode and size are calculated differently.
8430 static void handle_simd_3same_pair(DisasContext *s, int is_q, int u, int opcode,
8431 int size, int rn, int rm, int rd)
8436 /* Floating point operations need fpst */
8437 if (opcode >= 0x58) {
8438 fpst = get_fpstatus_ptr();
8440 TCGV_UNUSED_PTR(fpst);
8443 /* These operations work on the concatenated rm:rn, with each pair of
8444 * adjacent elements being operated on to produce an element in the result.
8447 TCGv_i64 tcg_res[2];
8449 for (pass = 0; pass < 2; pass++) {
8450 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8451 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8452 int passreg = (pass == 0) ? rn : rm;
8454 read_vec_element(s, tcg_op1, passreg, 0, MO_64);
8455 read_vec_element(s, tcg_op2, passreg, 1, MO_64);
8456 tcg_res[pass] = tcg_temp_new_i64();
8459 case 0x17: /* ADDP */
8460 tcg_gen_add_i64(tcg_res[pass], tcg_op1, tcg_op2);
8462 case 0x58: /* FMAXNMP */
8463 gen_helper_vfp_maxnumd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
8465 case 0x5a: /* FADDP */
8466 gen_helper_vfp_addd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
8468 case 0x5e: /* FMAXP */
8469 gen_helper_vfp_maxd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
8471 case 0x78: /* FMINNMP */
8472 gen_helper_vfp_minnumd(tcg_res[pass], tcg_op1, tcg_op2, fpst);
8474 case 0x7e: /* FMINP */
8475 gen_helper_vfp_mind(tcg_res[pass], tcg_op1, tcg_op2, fpst);
8478 g_assert_not_reached();
8481 tcg_temp_free_i64(tcg_op1);
8482 tcg_temp_free_i64(tcg_op2);
8485 for (pass = 0; pass < 2; pass++) {
8486 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
8487 tcg_temp_free_i64(tcg_res[pass]);
8490 int maxpass = is_q ? 4 : 2;
8491 TCGv_i32 tcg_res[4];
8493 for (pass = 0; pass < maxpass; pass++) {
8494 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
8495 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
8496 NeonGenTwoOpFn *genfn = NULL;
8497 int passreg = pass < (maxpass / 2) ? rn : rm;
8498 int passelt = (is_q && (pass & 1)) ? 2 : 0;
8500 read_vec_element_i32(s, tcg_op1, passreg, passelt, MO_32);
8501 read_vec_element_i32(s, tcg_op2, passreg, passelt + 1, MO_32);
8502 tcg_res[pass] = tcg_temp_new_i32();
8505 case 0x17: /* ADDP */
8507 static NeonGenTwoOpFn * const fns[3] = {
8508 gen_helper_neon_padd_u8,
8509 gen_helper_neon_padd_u16,
8515 case 0x14: /* SMAXP, UMAXP */
8517 static NeonGenTwoOpFn * const fns[3][2] = {
8518 { gen_helper_neon_pmax_s8, gen_helper_neon_pmax_u8 },
8519 { gen_helper_neon_pmax_s16, gen_helper_neon_pmax_u16 },
8520 { gen_max_s32, gen_max_u32 },
8522 genfn = fns[size][u];
8525 case 0x15: /* SMINP, UMINP */
8527 static NeonGenTwoOpFn * const fns[3][2] = {
8528 { gen_helper_neon_pmin_s8, gen_helper_neon_pmin_u8 },
8529 { gen_helper_neon_pmin_s16, gen_helper_neon_pmin_u16 },
8530 { gen_min_s32, gen_min_u32 },
8532 genfn = fns[size][u];
8535 /* The FP operations are all on single floats (32 bit) */
8536 case 0x58: /* FMAXNMP */
8537 gen_helper_vfp_maxnums(tcg_res[pass], tcg_op1, tcg_op2, fpst);
8539 case 0x5a: /* FADDP */
8540 gen_helper_vfp_adds(tcg_res[pass], tcg_op1, tcg_op2, fpst);
8542 case 0x5e: /* FMAXP */
8543 gen_helper_vfp_maxs(tcg_res[pass], tcg_op1, tcg_op2, fpst);
8545 case 0x78: /* FMINNMP */
8546 gen_helper_vfp_minnums(tcg_res[pass], tcg_op1, tcg_op2, fpst);
8548 case 0x7e: /* FMINP */
8549 gen_helper_vfp_mins(tcg_res[pass], tcg_op1, tcg_op2, fpst);
8552 g_assert_not_reached();
8555 /* FP ops called directly, otherwise call now */
8557 genfn(tcg_res[pass], tcg_op1, tcg_op2);
8560 tcg_temp_free_i32(tcg_op1);
8561 tcg_temp_free_i32(tcg_op2);
8564 for (pass = 0; pass < maxpass; pass++) {
8565 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32);
8566 tcg_temp_free_i32(tcg_res[pass]);
8569 clear_vec_high(s, rd);
8573 if (!TCGV_IS_UNUSED_PTR(fpst)) {
8574 tcg_temp_free_ptr(fpst);
8578 /* Floating point op subgroup of C3.6.16. */
8579 static void disas_simd_3same_float(DisasContext *s, uint32_t insn)
8581 /* For floating point ops, the U, size[1] and opcode bits
8582 * together indicate the operation. size[0] indicates single
8585 int fpopcode = extract32(insn, 11, 5)
8586 | (extract32(insn, 23, 1) << 5)
8587 | (extract32(insn, 29, 1) << 6);
8588 int is_q = extract32(insn, 30, 1);
8589 int size = extract32(insn, 22, 1);
8590 int rm = extract32(insn, 16, 5);
8591 int rn = extract32(insn, 5, 5);
8592 int rd = extract32(insn, 0, 5);
8594 int datasize = is_q ? 128 : 64;
8595 int esize = 32 << size;
8596 int elements = datasize / esize;
8598 if (size == 1 && !is_q) {
8599 unallocated_encoding(s);
8604 case 0x58: /* FMAXNMP */
8605 case 0x5a: /* FADDP */
8606 case 0x5e: /* FMAXP */
8607 case 0x78: /* FMINNMP */
8608 case 0x7e: /* FMINP */
8609 if (size && !is_q) {
8610 unallocated_encoding(s);
8613 handle_simd_3same_pair(s, is_q, 0, fpopcode, size ? MO_64 : MO_32,
8616 case 0x1b: /* FMULX */
8617 case 0x1f: /* FRECPS */
8618 case 0x3f: /* FRSQRTS */
8619 case 0x5d: /* FACGE */
8620 case 0x7d: /* FACGT */
8621 case 0x19: /* FMLA */
8622 case 0x39: /* FMLS */
8623 case 0x18: /* FMAXNM */
8624 case 0x1a: /* FADD */
8625 case 0x1c: /* FCMEQ */
8626 case 0x1e: /* FMAX */
8627 case 0x38: /* FMINNM */
8628 case 0x3a: /* FSUB */
8629 case 0x3e: /* FMIN */
8630 case 0x5b: /* FMUL */
8631 case 0x5c: /* FCMGE */
8632 case 0x5f: /* FDIV */
8633 case 0x7a: /* FABD */
8634 case 0x7c: /* FCMGT */
8635 handle_3same_float(s, size, elements, fpopcode, rd, rn, rm);
8638 unallocated_encoding(s);
8643 /* Integer op subgroup of C3.6.16. */
8644 static void disas_simd_3same_int(DisasContext *s, uint32_t insn)
8646 int is_q = extract32(insn, 30, 1);
8647 int u = extract32(insn, 29, 1);
8648 int size = extract32(insn, 22, 2);
8649 int opcode = extract32(insn, 11, 5);
8650 int rm = extract32(insn, 16, 5);
8651 int rn = extract32(insn, 5, 5);
8652 int rd = extract32(insn, 0, 5);
8656 case 0x13: /* MUL, PMUL */
8657 if (u && size != 0) {
8658 unallocated_encoding(s);
8662 case 0x0: /* SHADD, UHADD */
8663 case 0x2: /* SRHADD, URHADD */
8664 case 0x4: /* SHSUB, UHSUB */
8665 case 0xc: /* SMAX, UMAX */
8666 case 0xd: /* SMIN, UMIN */
8667 case 0xe: /* SABD, UABD */
8668 case 0xf: /* SABA, UABA */
8669 case 0x12: /* MLA, MLS */
8671 unallocated_encoding(s);
8675 case 0x16: /* SQDMULH, SQRDMULH */
8676 if (size == 0 || size == 3) {
8677 unallocated_encoding(s);
8682 if (size == 3 && !is_q) {
8683 unallocated_encoding(s);
8690 for (pass = 0; pass < (is_q ? 2 : 1); pass++) {
8691 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
8692 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
8693 TCGv_i64 tcg_res = tcg_temp_new_i64();
8695 read_vec_element(s, tcg_op1, rn, pass, MO_64);
8696 read_vec_element(s, tcg_op2, rm, pass, MO_64);
8698 handle_3same_64(s, opcode, u, tcg_res, tcg_op1, tcg_op2);
8700 write_vec_element(s, tcg_res, rd, pass, MO_64);
8702 tcg_temp_free_i64(tcg_res);
8703 tcg_temp_free_i64(tcg_op1);
8704 tcg_temp_free_i64(tcg_op2);
8707 for (pass = 0; pass < (is_q ? 4 : 2); pass++) {
8708 TCGv_i32 tcg_op1 = tcg_temp_new_i32();
8709 TCGv_i32 tcg_op2 = tcg_temp_new_i32();
8710 TCGv_i32 tcg_res = tcg_temp_new_i32();
8711 NeonGenTwoOpFn *genfn = NULL;
8712 NeonGenTwoOpEnvFn *genenvfn = NULL;
8714 read_vec_element_i32(s, tcg_op1, rn, pass, MO_32);
8715 read_vec_element_i32(s, tcg_op2, rm, pass, MO_32);
8718 case 0x0: /* SHADD, UHADD */
8720 static NeonGenTwoOpFn * const fns[3][2] = {
8721 { gen_helper_neon_hadd_s8, gen_helper_neon_hadd_u8 },
8722 { gen_helper_neon_hadd_s16, gen_helper_neon_hadd_u16 },
8723 { gen_helper_neon_hadd_s32, gen_helper_neon_hadd_u32 },
8725 genfn = fns[size][u];
8728 case 0x1: /* SQADD, UQADD */
8730 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8731 { gen_helper_neon_qadd_s8, gen_helper_neon_qadd_u8 },
8732 { gen_helper_neon_qadd_s16, gen_helper_neon_qadd_u16 },
8733 { gen_helper_neon_qadd_s32, gen_helper_neon_qadd_u32 },
8735 genenvfn = fns[size][u];
8738 case 0x2: /* SRHADD, URHADD */
8740 static NeonGenTwoOpFn * const fns[3][2] = {
8741 { gen_helper_neon_rhadd_s8, gen_helper_neon_rhadd_u8 },
8742 { gen_helper_neon_rhadd_s16, gen_helper_neon_rhadd_u16 },
8743 { gen_helper_neon_rhadd_s32, gen_helper_neon_rhadd_u32 },
8745 genfn = fns[size][u];
8748 case 0x4: /* SHSUB, UHSUB */
8750 static NeonGenTwoOpFn * const fns[3][2] = {
8751 { gen_helper_neon_hsub_s8, gen_helper_neon_hsub_u8 },
8752 { gen_helper_neon_hsub_s16, gen_helper_neon_hsub_u16 },
8753 { gen_helper_neon_hsub_s32, gen_helper_neon_hsub_u32 },
8755 genfn = fns[size][u];
8758 case 0x5: /* SQSUB, UQSUB */
8760 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8761 { gen_helper_neon_qsub_s8, gen_helper_neon_qsub_u8 },
8762 { gen_helper_neon_qsub_s16, gen_helper_neon_qsub_u16 },
8763 { gen_helper_neon_qsub_s32, gen_helper_neon_qsub_u32 },
8765 genenvfn = fns[size][u];
8768 case 0x6: /* CMGT, CMHI */
8770 static NeonGenTwoOpFn * const fns[3][2] = {
8771 { gen_helper_neon_cgt_s8, gen_helper_neon_cgt_u8 },
8772 { gen_helper_neon_cgt_s16, gen_helper_neon_cgt_u16 },
8773 { gen_helper_neon_cgt_s32, gen_helper_neon_cgt_u32 },
8775 genfn = fns[size][u];
8778 case 0x7: /* CMGE, CMHS */
8780 static NeonGenTwoOpFn * const fns[3][2] = {
8781 { gen_helper_neon_cge_s8, gen_helper_neon_cge_u8 },
8782 { gen_helper_neon_cge_s16, gen_helper_neon_cge_u16 },
8783 { gen_helper_neon_cge_s32, gen_helper_neon_cge_u32 },
8785 genfn = fns[size][u];
8788 case 0x8: /* SSHL, USHL */
8790 static NeonGenTwoOpFn * const fns[3][2] = {
8791 { gen_helper_neon_shl_s8, gen_helper_neon_shl_u8 },
8792 { gen_helper_neon_shl_s16, gen_helper_neon_shl_u16 },
8793 { gen_helper_neon_shl_s32, gen_helper_neon_shl_u32 },
8795 genfn = fns[size][u];
8798 case 0x9: /* SQSHL, UQSHL */
8800 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8801 { gen_helper_neon_qshl_s8, gen_helper_neon_qshl_u8 },
8802 { gen_helper_neon_qshl_s16, gen_helper_neon_qshl_u16 },
8803 { gen_helper_neon_qshl_s32, gen_helper_neon_qshl_u32 },
8805 genenvfn = fns[size][u];
8808 case 0xa: /* SRSHL, URSHL */
8810 static NeonGenTwoOpFn * const fns[3][2] = {
8811 { gen_helper_neon_rshl_s8, gen_helper_neon_rshl_u8 },
8812 { gen_helper_neon_rshl_s16, gen_helper_neon_rshl_u16 },
8813 { gen_helper_neon_rshl_s32, gen_helper_neon_rshl_u32 },
8815 genfn = fns[size][u];
8818 case 0xb: /* SQRSHL, UQRSHL */
8820 static NeonGenTwoOpEnvFn * const fns[3][2] = {
8821 { gen_helper_neon_qrshl_s8, gen_helper_neon_qrshl_u8 },
8822 { gen_helper_neon_qrshl_s16, gen_helper_neon_qrshl_u16 },
8823 { gen_helper_neon_qrshl_s32, gen_helper_neon_qrshl_u32 },
8825 genenvfn = fns[size][u];
8828 case 0xc: /* SMAX, UMAX */
8830 static NeonGenTwoOpFn * const fns[3][2] = {
8831 { gen_helper_neon_max_s8, gen_helper_neon_max_u8 },
8832 { gen_helper_neon_max_s16, gen_helper_neon_max_u16 },
8833 { gen_max_s32, gen_max_u32 },
8835 genfn = fns[size][u];
8839 case 0xd: /* SMIN, UMIN */
8841 static NeonGenTwoOpFn * const fns[3][2] = {
8842 { gen_helper_neon_min_s8, gen_helper_neon_min_u8 },
8843 { gen_helper_neon_min_s16, gen_helper_neon_min_u16 },
8844 { gen_min_s32, gen_min_u32 },
8846 genfn = fns[size][u];
8849 case 0xe: /* SABD, UABD */
8850 case 0xf: /* SABA, UABA */
8852 static NeonGenTwoOpFn * const fns[3][2] = {
8853 { gen_helper_neon_abd_s8, gen_helper_neon_abd_u8 },
8854 { gen_helper_neon_abd_s16, gen_helper_neon_abd_u16 },
8855 { gen_helper_neon_abd_s32, gen_helper_neon_abd_u32 },
8857 genfn = fns[size][u];
8860 case 0x10: /* ADD, SUB */
8862 static NeonGenTwoOpFn * const fns[3][2] = {
8863 { gen_helper_neon_add_u8, gen_helper_neon_sub_u8 },
8864 { gen_helper_neon_add_u16, gen_helper_neon_sub_u16 },
8865 { tcg_gen_add_i32, tcg_gen_sub_i32 },
8867 genfn = fns[size][u];
8870 case 0x11: /* CMTST, CMEQ */
8872 static NeonGenTwoOpFn * const fns[3][2] = {
8873 { gen_helper_neon_tst_u8, gen_helper_neon_ceq_u8 },
8874 { gen_helper_neon_tst_u16, gen_helper_neon_ceq_u16 },
8875 { gen_helper_neon_tst_u32, gen_helper_neon_ceq_u32 },
8877 genfn = fns[size][u];
8880 case 0x13: /* MUL, PMUL */
8884 genfn = gen_helper_neon_mul_p8;
8887 /* fall through : MUL */
8888 case 0x12: /* MLA, MLS */
8890 static NeonGenTwoOpFn * const fns[3] = {
8891 gen_helper_neon_mul_u8,
8892 gen_helper_neon_mul_u16,
8898 case 0x16: /* SQDMULH, SQRDMULH */
8900 static NeonGenTwoOpEnvFn * const fns[2][2] = {
8901 { gen_helper_neon_qdmulh_s16, gen_helper_neon_qrdmulh_s16 },
8902 { gen_helper_neon_qdmulh_s32, gen_helper_neon_qrdmulh_s32 },
8904 assert(size == 1 || size == 2);
8905 genenvfn = fns[size - 1][u];
8909 g_assert_not_reached();
8913 genenvfn(tcg_res, cpu_env, tcg_op1, tcg_op2);
8915 genfn(tcg_res, tcg_op1, tcg_op2);
8918 if (opcode == 0xf || opcode == 0x12) {
8919 /* SABA, UABA, MLA, MLS: accumulating ops */
8920 static NeonGenTwoOpFn * const fns[3][2] = {
8921 { gen_helper_neon_add_u8, gen_helper_neon_sub_u8 },
8922 { gen_helper_neon_add_u16, gen_helper_neon_sub_u16 },
8923 { tcg_gen_add_i32, tcg_gen_sub_i32 },
8925 bool is_sub = (opcode == 0x12 && u); /* MLS */
8927 genfn = fns[size][is_sub];
8928 read_vec_element_i32(s, tcg_op1, rd, pass, MO_32);
8929 genfn(tcg_res, tcg_op1, tcg_res);
8932 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
8934 tcg_temp_free_i32(tcg_res);
8935 tcg_temp_free_i32(tcg_op1);
8936 tcg_temp_free_i32(tcg_op2);
8941 clear_vec_high(s, rd);
8945 /* C3.6.16 AdvSIMD three same
8946 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8947 * +---+---+---+-----------+------+---+------+--------+---+------+------+
8948 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8949 * +---+---+---+-----------+------+---+------+--------+---+------+------+
8951 static void disas_simd_three_reg_same(DisasContext *s, uint32_t insn)
8953 int opcode = extract32(insn, 11, 5);
8956 case 0x3: /* logic ops */
8957 disas_simd_3same_logic(s, insn);
8959 case 0x17: /* ADDP */
8960 case 0x14: /* SMAXP, UMAXP */
8961 case 0x15: /* SMINP, UMINP */
8963 /* Pairwise operations */
8964 int is_q = extract32(insn, 30, 1);
8965 int u = extract32(insn, 29, 1);
8966 int size = extract32(insn, 22, 2);
8967 int rm = extract32(insn, 16, 5);
8968 int rn = extract32(insn, 5, 5);
8969 int rd = extract32(insn, 0, 5);
8970 if (opcode == 0x17) {
8971 if (u || (size == 3 && !is_q)) {
8972 unallocated_encoding(s);
8977 unallocated_encoding(s);
8981 handle_simd_3same_pair(s, is_q, u, opcode, size, rn, rm, rd);
8985 /* floating point ops, sz[1] and U are part of opcode */
8986 disas_simd_3same_float(s, insn);
8989 disas_simd_3same_int(s, insn);
8994 static void handle_2misc_widening(DisasContext *s, int opcode, bool is_q,
8995 int size, int rn, int rd)
8997 /* Handle 2-reg-misc ops which are widening (so each size element
8998 * in the source becomes a 2*size element in the destination.
8999 * The only instruction like this is FCVTL.
9004 /* 32 -> 64 bit fp conversion */
9005 TCGv_i64 tcg_res[2];
9006 int srcelt = is_q ? 2 : 0;
9008 for (pass = 0; pass < 2; pass++) {
9009 TCGv_i32 tcg_op = tcg_temp_new_i32();
9010 tcg_res[pass] = tcg_temp_new_i64();
9012 read_vec_element_i32(s, tcg_op, rn, srcelt + pass, MO_32);
9013 gen_helper_vfp_fcvtds(tcg_res[pass], tcg_op, cpu_env);
9014 tcg_temp_free_i32(tcg_op);
9016 for (pass = 0; pass < 2; pass++) {
9017 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
9018 tcg_temp_free_i64(tcg_res[pass]);
9021 /* 16 -> 32 bit fp conversion */
9022 int srcelt = is_q ? 4 : 0;
9023 TCGv_i32 tcg_res[4];
9025 for (pass = 0; pass < 4; pass++) {
9026 tcg_res[pass] = tcg_temp_new_i32();
9028 read_vec_element_i32(s, tcg_res[pass], rn, srcelt + pass, MO_16);
9029 gen_helper_vfp_fcvt_f16_to_f32(tcg_res[pass], tcg_res[pass],
9032 for (pass = 0; pass < 4; pass++) {
9033 write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32);
9034 tcg_temp_free_i32(tcg_res[pass]);
9039 static void handle_rev(DisasContext *s, int opcode, bool u,
9040 bool is_q, int size, int rn, int rd)
9042 int op = (opcode << 1) | u;
9043 int opsz = op + size;
9044 int grp_size = 3 - opsz;
9045 int dsize = is_q ? 128 : 64;
9049 unallocated_encoding(s);
9054 /* Special case bytes, use bswap op on each group of elements */
9055 int groups = dsize / (8 << grp_size);
9057 for (i = 0; i < groups; i++) {
9058 TCGv_i64 tcg_tmp = tcg_temp_new_i64();
9060 read_vec_element(s, tcg_tmp, rn, i, grp_size);
9063 tcg_gen_bswap16_i64(tcg_tmp, tcg_tmp);
9066 tcg_gen_bswap32_i64(tcg_tmp, tcg_tmp);
9069 tcg_gen_bswap64_i64(tcg_tmp, tcg_tmp);
9072 g_assert_not_reached();
9074 write_vec_element(s, tcg_tmp, rd, i, grp_size);
9075 tcg_temp_free_i64(tcg_tmp);
9078 clear_vec_high(s, rd);
9081 int revmask = (1 << grp_size) - 1;
9082 int esize = 8 << size;
9083 int elements = dsize / esize;
9084 TCGv_i64 tcg_rn = tcg_temp_new_i64();
9085 TCGv_i64 tcg_rd = tcg_const_i64(0);
9086 TCGv_i64 tcg_rd_hi = tcg_const_i64(0);
9088 for (i = 0; i < elements; i++) {
9089 int e_rev = (i & 0xf) ^ revmask;
9090 int off = e_rev * esize;
9091 read_vec_element(s, tcg_rn, rn, i, size);
9093 tcg_gen_deposit_i64(tcg_rd_hi, tcg_rd_hi,
9094 tcg_rn, off - 64, esize);
9096 tcg_gen_deposit_i64(tcg_rd, tcg_rd, tcg_rn, off, esize);
9099 write_vec_element(s, tcg_rd, rd, 0, MO_64);
9100 write_vec_element(s, tcg_rd_hi, rd, 1, MO_64);
9102 tcg_temp_free_i64(tcg_rd_hi);
9103 tcg_temp_free_i64(tcg_rd);
9104 tcg_temp_free_i64(tcg_rn);
9108 static void handle_2misc_pairwise(DisasContext *s, int opcode, bool u,
9109 bool is_q, int size, int rn, int rd)
9111 /* Implement the pairwise operations from 2-misc:
9112 * SADDLP, UADDLP, SADALP, UADALP.
9113 * These all add pairs of elements in the input to produce a
9114 * double-width result element in the output (possibly accumulating).
9116 bool accum = (opcode == 0x6);
9117 int maxpass = is_q ? 2 : 1;
9119 TCGv_i64 tcg_res[2];
9122 /* 32 + 32 -> 64 op */
9123 TCGMemOp memop = size + (u ? 0 : MO_SIGN);
9125 for (pass = 0; pass < maxpass; pass++) {
9126 TCGv_i64 tcg_op1 = tcg_temp_new_i64();
9127 TCGv_i64 tcg_op2 = tcg_temp_new_i64();
9129 tcg_res[pass] = tcg_temp_new_i64();
9131 read_vec_element(s, tcg_op1, rn, pass * 2, memop);
9132 read_vec_element(s, tcg_op2, rn, pass * 2 + 1, memop);
9133 tcg_gen_add_i64(tcg_res[pass], tcg_op1, tcg_op2);
9135 read_vec_element(s, tcg_op1, rd, pass, MO_64);
9136 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_op1);
9139 tcg_temp_free_i64(tcg_op1);
9140 tcg_temp_free_i64(tcg_op2);
9143 for (pass = 0; pass < maxpass; pass++) {
9144 TCGv_i64 tcg_op = tcg_temp_new_i64();
9145 NeonGenOneOpFn *genfn;
9146 static NeonGenOneOpFn * const fns[2][2] = {
9147 { gen_helper_neon_addlp_s8, gen_helper_neon_addlp_u8 },
9148 { gen_helper_neon_addlp_s16, gen_helper_neon_addlp_u16 },
9151 genfn = fns[size][u];
9153 tcg_res[pass] = tcg_temp_new_i64();
9155 read_vec_element(s, tcg_op, rn, pass, MO_64);
9156 genfn(tcg_res[pass], tcg_op);
9159 read_vec_element(s, tcg_op, rd, pass, MO_64);
9161 gen_helper_neon_addl_u16(tcg_res[pass],
9162 tcg_res[pass], tcg_op);
9164 gen_helper_neon_addl_u32(tcg_res[pass],
9165 tcg_res[pass], tcg_op);
9168 tcg_temp_free_i64(tcg_op);
9172 tcg_res[1] = tcg_const_i64(0);
9174 for (pass = 0; pass < 2; pass++) {
9175 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
9176 tcg_temp_free_i64(tcg_res[pass]);
9180 static void handle_shll(DisasContext *s, bool is_q, int size, int rn, int rd)
9182 /* Implement SHLL and SHLL2 */
9184 int part = is_q ? 2 : 0;
9185 TCGv_i64 tcg_res[2];
9187 for (pass = 0; pass < 2; pass++) {
9188 static NeonGenWidenFn * const widenfns[3] = {
9189 gen_helper_neon_widen_u8,
9190 gen_helper_neon_widen_u16,
9191 tcg_gen_extu_i32_i64,
9193 NeonGenWidenFn *widenfn = widenfns[size];
9194 TCGv_i32 tcg_op = tcg_temp_new_i32();
9196 read_vec_element_i32(s, tcg_op, rn, part + pass, MO_32);
9197 tcg_res[pass] = tcg_temp_new_i64();
9198 widenfn(tcg_res[pass], tcg_op);
9199 tcg_gen_shli_i64(tcg_res[pass], tcg_res[pass], 8 << size);
9201 tcg_temp_free_i32(tcg_op);
9204 for (pass = 0; pass < 2; pass++) {
9205 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
9206 tcg_temp_free_i64(tcg_res[pass]);
9210 /* C3.6.17 AdvSIMD two reg misc
9211 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9212 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9213 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9214 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9216 static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn)
9218 int size = extract32(insn, 22, 2);
9219 int opcode = extract32(insn, 12, 5);
9220 bool u = extract32(insn, 29, 1);
9221 bool is_q = extract32(insn, 30, 1);
9222 int rn = extract32(insn, 5, 5);
9223 int rd = extract32(insn, 0, 5);
9224 bool need_fpstatus = false;
9225 bool need_rmode = false;
9228 TCGv_ptr tcg_fpstatus;
9231 case 0x0: /* REV64, REV32 */
9232 case 0x1: /* REV16 */
9233 handle_rev(s, opcode, u, is_q, size, rn, rd);
9235 case 0x5: /* CNT, NOT, RBIT */
9236 if (u && size == 0) {
9237 /* NOT: adjust size so we can use the 64-bits-at-a-time loop. */
9240 } else if (u && size == 1) {
9243 } else if (!u && size == 0) {
9247 unallocated_encoding(s);
9249 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
9250 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
9252 unallocated_encoding(s);
9255 handle_2misc_narrow(s, false, opcode, u, is_q, size, rn, rd);
9257 case 0x4: /* CLS, CLZ */
9259 unallocated_encoding(s);
9263 case 0x2: /* SADDLP, UADDLP */
9264 case 0x6: /* SADALP, UADALP */
9266 unallocated_encoding(s);
9269 handle_2misc_pairwise(s, opcode, u, is_q, size, rn, rd);
9271 case 0x13: /* SHLL, SHLL2 */
9272 if (u == 0 || size == 3) {
9273 unallocated_encoding(s);
9276 handle_shll(s, is_q, size, rn, rd);
9278 case 0xa: /* CMLT */
9280 unallocated_encoding(s);
9284 case 0x8: /* CMGT, CMGE */
9285 case 0x9: /* CMEQ, CMLE */
9286 case 0xb: /* ABS, NEG */
9287 if (size == 3 && !is_q) {
9288 unallocated_encoding(s);
9292 case 0x3: /* SUQADD, USQADD */
9293 if (size == 3 && !is_q) {
9294 unallocated_encoding(s);
9297 handle_2misc_satacc(s, false, u, is_q, size, rn, rd);
9299 case 0x7: /* SQABS, SQNEG */
9300 if (size == 3 && !is_q) {
9301 unallocated_encoding(s);
9309 /* Floating point: U, size[1] and opcode indicate operation;
9310 * size[0] indicates single or double precision.
9312 int is_double = extract32(size, 0, 1);
9313 opcode |= (extract32(size, 1, 1) << 5) | (u << 6);
9314 size = is_double ? 3 : 2;
9316 case 0x2f: /* FABS */
9317 case 0x6f: /* FNEG */
9318 if (size == 3 && !is_q) {
9319 unallocated_encoding(s);
9323 case 0x1d: /* SCVTF */
9324 case 0x5d: /* UCVTF */
9326 bool is_signed = (opcode == 0x1d) ? true : false;
9327 int elements = is_double ? 2 : is_q ? 4 : 2;
9328 if (is_double && !is_q) {
9329 unallocated_encoding(s);
9332 handle_simd_intfp_conv(s, rd, rn, elements, is_signed, 0, size);
9335 case 0x2c: /* FCMGT (zero) */
9336 case 0x2d: /* FCMEQ (zero) */
9337 case 0x2e: /* FCMLT (zero) */
9338 case 0x6c: /* FCMGE (zero) */
9339 case 0x6d: /* FCMLE (zero) */
9340 if (size == 3 && !is_q) {
9341 unallocated_encoding(s);
9344 handle_2misc_fcmp_zero(s, opcode, false, u, is_q, size, rn, rd);
9346 case 0x7f: /* FSQRT */
9347 if (size == 3 && !is_q) {
9348 unallocated_encoding(s);
9352 case 0x1a: /* FCVTNS */
9353 case 0x1b: /* FCVTMS */
9354 case 0x3a: /* FCVTPS */
9355 case 0x3b: /* FCVTZS */
9356 case 0x5a: /* FCVTNU */
9357 case 0x5b: /* FCVTMU */
9358 case 0x7a: /* FCVTPU */
9359 case 0x7b: /* FCVTZU */
9360 need_fpstatus = true;
9362 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
9363 if (size == 3 && !is_q) {
9364 unallocated_encoding(s);
9368 case 0x5c: /* FCVTAU */
9369 case 0x1c: /* FCVTAS */
9370 need_fpstatus = true;
9372 rmode = FPROUNDING_TIEAWAY;
9373 if (size == 3 && !is_q) {
9374 unallocated_encoding(s);
9378 case 0x3c: /* URECPE */
9380 unallocated_encoding(s);
9384 case 0x3d: /* FRECPE */
9385 case 0x7d: /* FRSQRTE */
9386 if (size == 3 && !is_q) {
9387 unallocated_encoding(s);
9390 handle_2misc_reciprocal(s, opcode, false, u, is_q, size, rn, rd);
9392 case 0x56: /* FCVTXN, FCVTXN2 */
9394 unallocated_encoding(s);
9398 case 0x16: /* FCVTN, FCVTN2 */
9399 /* handle_2misc_narrow does a 2*size -> size operation, but these
9400 * instructions encode the source size rather than dest size.
9402 handle_2misc_narrow(s, false, opcode, 0, is_q, size - 1, rn, rd);
9404 case 0x17: /* FCVTL, FCVTL2 */
9405 handle_2misc_widening(s, opcode, is_q, size, rn, rd);
9407 case 0x18: /* FRINTN */
9408 case 0x19: /* FRINTM */
9409 case 0x38: /* FRINTP */
9410 case 0x39: /* FRINTZ */
9412 rmode = extract32(opcode, 5, 1) | (extract32(opcode, 0, 1) << 1);
9414 case 0x59: /* FRINTX */
9415 case 0x79: /* FRINTI */
9416 need_fpstatus = true;
9417 if (size == 3 && !is_q) {
9418 unallocated_encoding(s);
9422 case 0x58: /* FRINTA */
9424 rmode = FPROUNDING_TIEAWAY;
9425 need_fpstatus = true;
9426 if (size == 3 && !is_q) {
9427 unallocated_encoding(s);
9431 case 0x7c: /* URSQRTE */
9433 unallocated_encoding(s);
9436 need_fpstatus = true;
9439 unallocated_encoding(s);
9445 unallocated_encoding(s);
9449 if (need_fpstatus) {
9450 tcg_fpstatus = get_fpstatus_ptr();
9452 TCGV_UNUSED_PTR(tcg_fpstatus);
9455 tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode));
9456 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
9458 TCGV_UNUSED_I32(tcg_rmode);
9462 /* All 64-bit element operations can be shared with scalar 2misc */
9465 for (pass = 0; pass < (is_q ? 2 : 1); pass++) {
9466 TCGv_i64 tcg_op = tcg_temp_new_i64();
9467 TCGv_i64 tcg_res = tcg_temp_new_i64();
9469 read_vec_element(s, tcg_op, rn, pass, MO_64);
9471 handle_2misc_64(s, opcode, u, tcg_res, tcg_op,
9472 tcg_rmode, tcg_fpstatus);
9474 write_vec_element(s, tcg_res, rd, pass, MO_64);
9476 tcg_temp_free_i64(tcg_res);
9477 tcg_temp_free_i64(tcg_op);
9482 for (pass = 0; pass < (is_q ? 4 : 2); pass++) {
9483 TCGv_i32 tcg_op = tcg_temp_new_i32();
9484 TCGv_i32 tcg_res = tcg_temp_new_i32();
9487 read_vec_element_i32(s, tcg_op, rn, pass, MO_32);
9490 /* Special cases for 32 bit elements */
9492 case 0xa: /* CMLT */
9493 /* 32 bit integer comparison against zero, result is
9494 * test ? (2^32 - 1) : 0. We implement via setcond(test)
9499 tcg_gen_setcondi_i32(cond, tcg_res, tcg_op, 0);
9500 tcg_gen_neg_i32(tcg_res, tcg_res);
9502 case 0x8: /* CMGT, CMGE */
9503 cond = u ? TCG_COND_GE : TCG_COND_GT;
9505 case 0x9: /* CMEQ, CMLE */
9506 cond = u ? TCG_COND_LE : TCG_COND_EQ;
9510 gen_helper_clz32(tcg_res, tcg_op);
9512 gen_helper_cls32(tcg_res, tcg_op);
9515 case 0x7: /* SQABS, SQNEG */
9517 gen_helper_neon_qneg_s32(tcg_res, cpu_env, tcg_op);
9519 gen_helper_neon_qabs_s32(tcg_res, cpu_env, tcg_op);
9522 case 0xb: /* ABS, NEG */
9524 tcg_gen_neg_i32(tcg_res, tcg_op);
9526 TCGv_i32 tcg_zero = tcg_const_i32(0);
9527 tcg_gen_neg_i32(tcg_res, tcg_op);
9528 tcg_gen_movcond_i32(TCG_COND_GT, tcg_res, tcg_op,
9529 tcg_zero, tcg_op, tcg_res);
9530 tcg_temp_free_i32(tcg_zero);
9533 case 0x2f: /* FABS */
9534 gen_helper_vfp_abss(tcg_res, tcg_op);
9536 case 0x6f: /* FNEG */
9537 gen_helper_vfp_negs(tcg_res, tcg_op);
9539 case 0x7f: /* FSQRT */
9540 gen_helper_vfp_sqrts(tcg_res, tcg_op, cpu_env);
9542 case 0x1a: /* FCVTNS */
9543 case 0x1b: /* FCVTMS */
9544 case 0x1c: /* FCVTAS */
9545 case 0x3a: /* FCVTPS */
9546 case 0x3b: /* FCVTZS */
9548 TCGv_i32 tcg_shift = tcg_const_i32(0);
9549 gen_helper_vfp_tosls(tcg_res, tcg_op,
9550 tcg_shift, tcg_fpstatus);
9551 tcg_temp_free_i32(tcg_shift);
9554 case 0x5a: /* FCVTNU */
9555 case 0x5b: /* FCVTMU */
9556 case 0x5c: /* FCVTAU */
9557 case 0x7a: /* FCVTPU */
9558 case 0x7b: /* FCVTZU */
9560 TCGv_i32 tcg_shift = tcg_const_i32(0);
9561 gen_helper_vfp_touls(tcg_res, tcg_op,
9562 tcg_shift, tcg_fpstatus);
9563 tcg_temp_free_i32(tcg_shift);
9566 case 0x18: /* FRINTN */
9567 case 0x19: /* FRINTM */
9568 case 0x38: /* FRINTP */
9569 case 0x39: /* FRINTZ */
9570 case 0x58: /* FRINTA */
9571 case 0x79: /* FRINTI */
9572 gen_helper_rints(tcg_res, tcg_op, tcg_fpstatus);
9574 case 0x59: /* FRINTX */
9575 gen_helper_rints_exact(tcg_res, tcg_op, tcg_fpstatus);
9577 case 0x7c: /* URSQRTE */
9578 gen_helper_rsqrte_u32(tcg_res, tcg_op, tcg_fpstatus);
9581 g_assert_not_reached();
9584 /* Use helpers for 8 and 16 bit elements */
9586 case 0x5: /* CNT, RBIT */
9587 /* For these two insns size is part of the opcode specifier
9588 * (handled earlier); they always operate on byte elements.
9591 gen_helper_neon_rbit_u8(tcg_res, tcg_op);
9593 gen_helper_neon_cnt_u8(tcg_res, tcg_op);
9596 case 0x7: /* SQABS, SQNEG */
9598 NeonGenOneOpEnvFn *genfn;
9599 static NeonGenOneOpEnvFn * const fns[2][2] = {
9600 { gen_helper_neon_qabs_s8, gen_helper_neon_qneg_s8 },
9601 { gen_helper_neon_qabs_s16, gen_helper_neon_qneg_s16 },
9603 genfn = fns[size][u];
9604 genfn(tcg_res, cpu_env, tcg_op);
9607 case 0x8: /* CMGT, CMGE */
9608 case 0x9: /* CMEQ, CMLE */
9609 case 0xa: /* CMLT */
9611 static NeonGenTwoOpFn * const fns[3][2] = {
9612 { gen_helper_neon_cgt_s8, gen_helper_neon_cgt_s16 },
9613 { gen_helper_neon_cge_s8, gen_helper_neon_cge_s16 },
9614 { gen_helper_neon_ceq_u8, gen_helper_neon_ceq_u16 },
9616 NeonGenTwoOpFn *genfn;
9619 TCGv_i32 tcg_zero = tcg_const_i32(0);
9621 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
9622 comp = (opcode - 0x8) * 2 + u;
9623 /* ...but LE, LT are implemented as reverse GE, GT */
9624 reverse = (comp > 2);
9628 genfn = fns[comp][size];
9630 genfn(tcg_res, tcg_zero, tcg_op);
9632 genfn(tcg_res, tcg_op, tcg_zero);
9634 tcg_temp_free_i32(tcg_zero);
9637 case 0xb: /* ABS, NEG */
9639 TCGv_i32 tcg_zero = tcg_const_i32(0);
9641 gen_helper_neon_sub_u16(tcg_res, tcg_zero, tcg_op);
9643 gen_helper_neon_sub_u8(tcg_res, tcg_zero, tcg_op);
9645 tcg_temp_free_i32(tcg_zero);
9648 gen_helper_neon_abs_s16(tcg_res, tcg_op);
9650 gen_helper_neon_abs_s8(tcg_res, tcg_op);
9654 case 0x4: /* CLS, CLZ */
9657 gen_helper_neon_clz_u8(tcg_res, tcg_op);
9659 gen_helper_neon_clz_u16(tcg_res, tcg_op);
9663 gen_helper_neon_cls_s8(tcg_res, tcg_op);
9665 gen_helper_neon_cls_s16(tcg_res, tcg_op);
9670 g_assert_not_reached();
9674 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
9676 tcg_temp_free_i32(tcg_res);
9677 tcg_temp_free_i32(tcg_op);
9681 clear_vec_high(s, rd);
9685 gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env);
9686 tcg_temp_free_i32(tcg_rmode);
9688 if (need_fpstatus) {
9689 tcg_temp_free_ptr(tcg_fpstatus);
9693 /* C3.6.13 AdvSIMD scalar x indexed element
9694 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
9695 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
9696 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
9697 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
9698 * C3.6.18 AdvSIMD vector x indexed element
9699 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
9700 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
9701 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
9702 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
9704 static void disas_simd_indexed(DisasContext *s, uint32_t insn)
9706 /* This encoding has two kinds of instruction:
9707 * normal, where we perform elt x idxelt => elt for each
9708 * element in the vector
9709 * long, where we perform elt x idxelt and generate a result of
9710 * double the width of the input element
9711 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
9713 bool is_scalar = extract32(insn, 28, 1);
9714 bool is_q = extract32(insn, 30, 1);
9715 bool u = extract32(insn, 29, 1);
9716 int size = extract32(insn, 22, 2);
9717 int l = extract32(insn, 21, 1);
9718 int m = extract32(insn, 20, 1);
9719 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
9720 int rm = extract32(insn, 16, 4);
9721 int opcode = extract32(insn, 12, 4);
9722 int h = extract32(insn, 11, 1);
9723 int rn = extract32(insn, 5, 5);
9724 int rd = extract32(insn, 0, 5);
9725 bool is_long = false;
9733 if (!u || is_scalar) {
9734 unallocated_encoding(s);
9738 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
9739 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
9740 case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
9742 unallocated_encoding(s);
9747 case 0x3: /* SQDMLAL, SQDMLAL2 */
9748 case 0x7: /* SQDMLSL, SQDMLSL2 */
9749 case 0xb: /* SQDMULL, SQDMULL2 */
9752 case 0xc: /* SQDMULH */
9753 case 0xd: /* SQRDMULH */
9755 unallocated_encoding(s);
9760 if (u || is_scalar) {
9761 unallocated_encoding(s);
9765 case 0x1: /* FMLA */
9766 case 0x5: /* FMLS */
9768 unallocated_encoding(s);
9772 case 0x9: /* FMUL, FMULX */
9773 if (!extract32(size, 1, 1)) {
9774 unallocated_encoding(s);
9780 unallocated_encoding(s);
9785 /* low bit of size indicates single/double */
9786 size = extract32(size, 0, 1) ? 3 : 2;
9791 unallocated_encoding(s);
9800 index = h << 2 | l << 1 | m;
9807 unallocated_encoding(s);
9813 fpst = get_fpstatus_ptr();
9815 TCGV_UNUSED_PTR(fpst);
9819 TCGv_i64 tcg_idx = tcg_temp_new_i64();
9822 assert(is_fp && is_q && !is_long);
9824 read_vec_element(s, tcg_idx, rm, index, MO_64);
9826 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9827 TCGv_i64 tcg_op = tcg_temp_new_i64();
9828 TCGv_i64 tcg_res = tcg_temp_new_i64();
9830 read_vec_element(s, tcg_op, rn, pass, MO_64);
9833 case 0x5: /* FMLS */
9834 /* As usual for ARM, separate negation for fused multiply-add */
9835 gen_helper_vfp_negd(tcg_op, tcg_op);
9837 case 0x1: /* FMLA */
9838 read_vec_element(s, tcg_res, rd, pass, MO_64);
9839 gen_helper_vfp_muladdd(tcg_res, tcg_op, tcg_idx, tcg_res, fpst);
9841 case 0x9: /* FMUL, FMULX */
9843 gen_helper_vfp_mulxd(tcg_res, tcg_op, tcg_idx, fpst);
9845 gen_helper_vfp_muld(tcg_res, tcg_op, tcg_idx, fpst);
9849 g_assert_not_reached();
9852 write_vec_element(s, tcg_res, rd, pass, MO_64);
9853 tcg_temp_free_i64(tcg_op);
9854 tcg_temp_free_i64(tcg_res);
9858 clear_vec_high(s, rd);
9861 tcg_temp_free_i64(tcg_idx);
9862 } else if (!is_long) {
9863 /* 32 bit floating point, or 16 or 32 bit integer.
9864 * For the 16 bit scalar case we use the usual Neon helpers and
9865 * rely on the fact that 0 op 0 == 0 with no side effects.
9867 TCGv_i32 tcg_idx = tcg_temp_new_i32();
9868 int pass, maxpasses;
9873 maxpasses = is_q ? 4 : 2;
9876 read_vec_element_i32(s, tcg_idx, rm, index, size);
9878 if (size == 1 && !is_scalar) {
9879 /* The simplest way to handle the 16x16 indexed ops is to duplicate
9880 * the index into both halves of the 32 bit tcg_idx and then use
9881 * the usual Neon helpers.
9883 tcg_gen_deposit_i32(tcg_idx, tcg_idx, tcg_idx, 16, 16);
9886 for (pass = 0; pass < maxpasses; pass++) {
9887 TCGv_i32 tcg_op = tcg_temp_new_i32();
9888 TCGv_i32 tcg_res = tcg_temp_new_i32();
9890 read_vec_element_i32(s, tcg_op, rn, pass, is_scalar ? size : MO_32);
9897 static NeonGenTwoOpFn * const fns[2][2] = {
9898 { gen_helper_neon_add_u16, gen_helper_neon_sub_u16 },
9899 { tcg_gen_add_i32, tcg_gen_sub_i32 },
9901 NeonGenTwoOpFn *genfn;
9902 bool is_sub = opcode == 0x4;
9905 gen_helper_neon_mul_u16(tcg_res, tcg_op, tcg_idx);
9907 tcg_gen_mul_i32(tcg_res, tcg_op, tcg_idx);
9909 if (opcode == 0x8) {
9912 read_vec_element_i32(s, tcg_op, rd, pass, MO_32);
9913 genfn = fns[size - 1][is_sub];
9914 genfn(tcg_res, tcg_op, tcg_res);
9917 case 0x5: /* FMLS */
9918 /* As usual for ARM, separate negation for fused multiply-add */
9919 gen_helper_vfp_negs(tcg_op, tcg_op);
9921 case 0x1: /* FMLA */
9922 read_vec_element_i32(s, tcg_res, rd, pass, MO_32);
9923 gen_helper_vfp_muladds(tcg_res, tcg_op, tcg_idx, tcg_res, fpst);
9925 case 0x9: /* FMUL, FMULX */
9927 gen_helper_vfp_mulxs(tcg_res, tcg_op, tcg_idx, fpst);
9929 gen_helper_vfp_muls(tcg_res, tcg_op, tcg_idx, fpst);
9932 case 0xc: /* SQDMULH */
9934 gen_helper_neon_qdmulh_s16(tcg_res, cpu_env,
9937 gen_helper_neon_qdmulh_s32(tcg_res, cpu_env,
9941 case 0xd: /* SQRDMULH */
9943 gen_helper_neon_qrdmulh_s16(tcg_res, cpu_env,
9946 gen_helper_neon_qrdmulh_s32(tcg_res, cpu_env,
9951 g_assert_not_reached();
9955 write_fp_sreg(s, rd, tcg_res);
9957 write_vec_element_i32(s, tcg_res, rd, pass, MO_32);
9960 tcg_temp_free_i32(tcg_op);
9961 tcg_temp_free_i32(tcg_res);
9964 tcg_temp_free_i32(tcg_idx);
9967 clear_vec_high(s, rd);
9970 /* long ops: 16x16->32 or 32x32->64 */
9971 TCGv_i64 tcg_res[2];
9973 bool satop = extract32(opcode, 0, 1);
9974 TCGMemOp memop = MO_32;
9981 TCGv_i64 tcg_idx = tcg_temp_new_i64();
9983 read_vec_element(s, tcg_idx, rm, index, memop);
9985 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
9986 TCGv_i64 tcg_op = tcg_temp_new_i64();
9987 TCGv_i64 tcg_passres;
9993 passelt = pass + (is_q * 2);
9996 read_vec_element(s, tcg_op, rn, passelt, memop);
9998 tcg_res[pass] = tcg_temp_new_i64();
10000 if (opcode == 0xa || opcode == 0xb) {
10001 /* Non-accumulating ops */
10002 tcg_passres = tcg_res[pass];
10004 tcg_passres = tcg_temp_new_i64();
10007 tcg_gen_mul_i64(tcg_passres, tcg_op, tcg_idx);
10008 tcg_temp_free_i64(tcg_op);
10011 /* saturating, doubling */
10012 gen_helper_neon_addl_saturate_s64(tcg_passres, cpu_env,
10013 tcg_passres, tcg_passres);
10016 if (opcode == 0xa || opcode == 0xb) {
10020 /* Accumulating op: handle accumulate step */
10021 read_vec_element(s, tcg_res[pass], rd, pass, MO_64);
10024 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10025 tcg_gen_add_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
10027 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10028 tcg_gen_sub_i64(tcg_res[pass], tcg_res[pass], tcg_passres);
10030 case 0x7: /* SQDMLSL, SQDMLSL2 */
10031 tcg_gen_neg_i64(tcg_passres, tcg_passres);
10033 case 0x3: /* SQDMLAL, SQDMLAL2 */
10034 gen_helper_neon_addl_saturate_s64(tcg_res[pass], cpu_env,
10039 g_assert_not_reached();
10041 tcg_temp_free_i64(tcg_passres);
10043 tcg_temp_free_i64(tcg_idx);
10046 clear_vec_high(s, rd);
10049 TCGv_i32 tcg_idx = tcg_temp_new_i32();
10052 read_vec_element_i32(s, tcg_idx, rm, index, size);
10055 /* The simplest way to handle the 16x16 indexed ops is to
10056 * duplicate the index into both halves of the 32 bit tcg_idx
10057 * and then use the usual Neon helpers.
10059 tcg_gen_deposit_i32(tcg_idx, tcg_idx, tcg_idx, 16, 16);
10062 for (pass = 0; pass < (is_scalar ? 1 : 2); pass++) {
10063 TCGv_i32 tcg_op = tcg_temp_new_i32();
10064 TCGv_i64 tcg_passres;
10067 read_vec_element_i32(s, tcg_op, rn, pass, size);
10069 read_vec_element_i32(s, tcg_op, rn,
10070 pass + (is_q * 2), MO_32);
10073 tcg_res[pass] = tcg_temp_new_i64();
10075 if (opcode == 0xa || opcode == 0xb) {
10076 /* Non-accumulating ops */
10077 tcg_passres = tcg_res[pass];
10079 tcg_passres = tcg_temp_new_i64();
10082 if (memop & MO_SIGN) {
10083 gen_helper_neon_mull_s16(tcg_passres, tcg_op, tcg_idx);
10085 gen_helper_neon_mull_u16(tcg_passres, tcg_op, tcg_idx);
10088 gen_helper_neon_addl_saturate_s32(tcg_passres, cpu_env,
10089 tcg_passres, tcg_passres);
10091 tcg_temp_free_i32(tcg_op);
10093 if (opcode == 0xa || opcode == 0xb) {
10097 /* Accumulating op: handle accumulate step */
10098 read_vec_element(s, tcg_res[pass], rd, pass, MO_64);
10101 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10102 gen_helper_neon_addl_u32(tcg_res[pass], tcg_res[pass],
10105 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10106 gen_helper_neon_subl_u32(tcg_res[pass], tcg_res[pass],
10109 case 0x7: /* SQDMLSL, SQDMLSL2 */
10110 gen_helper_neon_negl_u32(tcg_passres, tcg_passres);
10112 case 0x3: /* SQDMLAL, SQDMLAL2 */
10113 gen_helper_neon_addl_saturate_s32(tcg_res[pass], cpu_env,
10118 g_assert_not_reached();
10120 tcg_temp_free_i64(tcg_passres);
10122 tcg_temp_free_i32(tcg_idx);
10125 tcg_gen_ext32u_i64(tcg_res[0], tcg_res[0]);
10130 tcg_res[1] = tcg_const_i64(0);
10133 for (pass = 0; pass < 2; pass++) {
10134 write_vec_element(s, tcg_res[pass], rd, pass, MO_64);
10135 tcg_temp_free_i64(tcg_res[pass]);
10139 if (!TCGV_IS_UNUSED_PTR(fpst)) {
10140 tcg_temp_free_ptr(fpst);
10144 /* C3.6.19 Crypto AES
10145 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10146 * +-----------------+------+-----------+--------+-----+------+------+
10147 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10148 * +-----------------+------+-----------+--------+-----+------+------+
10150 static void disas_crypto_aes(DisasContext *s, uint32_t insn)
10152 unsupported_encoding(s, insn);
10155 /* C3.6.20 Crypto three-reg SHA
10156 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
10157 * +-----------------+------+---+------+---+--------+-----+------+------+
10158 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
10159 * +-----------------+------+---+------+---+--------+-----+------+------+
10161 static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn)
10163 unsupported_encoding(s, insn);
10166 /* C3.6.21 Crypto two-reg SHA
10167 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10168 * +-----------------+------+-----------+--------+-----+------+------+
10169 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10170 * +-----------------+------+-----------+--------+-----+------+------+
10172 static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn)
10174 unsupported_encoding(s, insn);
10177 /* C3.6 Data processing - SIMD, inc Crypto
10179 * As the decode gets a little complex we are using a table based
10180 * approach for this part of the decode.
10182 static const AArch64DecodeTable data_proc_simd[] = {
10183 /* pattern , mask , fn */
10184 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same },
10185 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff },
10186 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc },
10187 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes },
10188 { 0x0e000400, 0x9fe08400, disas_simd_copy },
10189 { 0x0f000000, 0x9f000400, disas_simd_indexed }, /* vector indexed */
10190 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
10191 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm },
10192 { 0x0f000400, 0x9f800400, disas_simd_shift_imm },
10193 { 0x0e000000, 0xbf208c00, disas_simd_tb },
10194 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn },
10195 { 0x2e000000, 0xbf208400, disas_simd_ext },
10196 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same },
10197 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff },
10198 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc },
10199 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise },
10200 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy },
10201 { 0x5f000000, 0xdf000400, disas_simd_indexed }, /* scalar indexed */
10202 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm },
10203 { 0x4e280800, 0xff3e0c00, disas_crypto_aes },
10204 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha },
10205 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha },
10206 { 0x00000000, 0x00000000, NULL }
10209 static void disas_data_proc_simd(DisasContext *s, uint32_t insn)
10211 /* Note that this is called with all non-FP cases from
10212 * table C3-6 so it must UNDEF for entries not specifically
10213 * allocated to instructions in that table.
10215 AArch64DecodeFn *fn = lookup_disas_fn(&data_proc_simd[0], insn);
10219 unallocated_encoding(s);
10223 /* C3.6 Data processing - SIMD and floating point */
10224 static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn)
10226 if (extract32(insn, 28, 1) == 1 && extract32(insn, 30, 1) == 0) {
10227 disas_data_proc_fp(s, insn);
10229 /* SIMD, including crypto */
10230 disas_data_proc_simd(s, insn);
10234 /* C3.1 A64 instruction index by encoding */
10235 static void disas_a64_insn(CPUARMState *env, DisasContext *s)
10239 insn = arm_ldl_code(env, s->pc, s->bswap_code);
10243 switch (extract32(insn, 25, 4)) {
10244 case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
10245 unallocated_encoding(s);
10247 case 0x8: case 0x9: /* Data processing - immediate */
10248 disas_data_proc_imm(s, insn);
10250 case 0xa: case 0xb: /* Branch, exception generation and system insns */
10251 disas_b_exc_sys(s, insn);
10256 case 0xe: /* Loads and stores */
10257 disas_ldst(s, insn);
10260 case 0xd: /* Data processing - register */
10261 disas_data_proc_reg(s, insn);
10264 case 0xf: /* Data processing - SIMD and floating point */
10265 disas_data_proc_simd_fp(s, insn);
10268 assert(FALSE); /* all 15 cases should be handled above */
10272 /* if we allocated any temporaries, free them here */
10276 void gen_intermediate_code_internal_a64(ARMCPU *cpu,
10277 TranslationBlock *tb,
10280 CPUState *cs = CPU(cpu);
10281 CPUARMState *env = &cpu->env;
10282 DisasContext dc1, *dc = &dc1;
10284 uint16_t *gen_opc_end;
10286 target_ulong pc_start;
10287 target_ulong next_page_start;
10295 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
10297 dc->is_jmp = DISAS_NEXT;
10299 dc->singlestep_enabled = cs->singlestep_enabled;
10304 dc->bswap_code = 0;
10305 dc->condexec_mask = 0;
10306 dc->condexec_cond = 0;
10307 #if !defined(CONFIG_USER_ONLY)
10308 dc->user = (ARM_TBFLAG_AA64_EL(tb->flags) == 0);
10310 dc->vfp_enabled = 0;
10312 dc->vec_stride = 0;
10313 dc->cp_regs = cpu->cp_regs;
10314 dc->current_pl = arm_current_pl(env);
10315 dc->features = env->features;
10317 init_tmp_a64_array(dc);
10319 next_page_start = (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
10322 max_insns = tb->cflags & CF_COUNT_MASK;
10323 if (max_insns == 0) {
10324 max_insns = CF_COUNT_MASK;
10329 tcg_clear_temp_count();
10332 if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) {
10333 QTAILQ_FOREACH(bp, &cs->breakpoints, entry) {
10334 if (bp->pc == dc->pc) {
10335 gen_exception_insn(dc, 0, EXCP_DEBUG);
10336 /* Advance PC so that clearing the breakpoint will
10337 invalidate this TB. */
10339 goto done_generating;
10345 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
10349 tcg_ctx.gen_opc_instr_start[lj++] = 0;
10352 tcg_ctx.gen_opc_pc[lj] = dc->pc;
10353 tcg_ctx.gen_opc_instr_start[lj] = 1;
10354 tcg_ctx.gen_opc_icount[lj] = num_insns;
10357 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) {
10361 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
10362 tcg_gen_debug_insn_start(dc->pc);
10365 disas_a64_insn(env, dc);
10367 if (tcg_check_temp_count()) {
10368 fprintf(stderr, "TCG temporary leak before "TARGET_FMT_lx"\n",
10372 /* Translation stops when a conditional branch is encountered.
10373 * Otherwise the subsequent code could get translated several times.
10374 * Also stop translation when a page boundary is reached. This
10375 * ensures prefetch aborts occur at the right place.
10378 } while (!dc->is_jmp && tcg_ctx.gen_opc_ptr < gen_opc_end &&
10379 !cs->singlestep_enabled &&
10381 dc->pc < next_page_start &&
10382 num_insns < max_insns);
10384 if (tb->cflags & CF_LAST_IO) {
10388 if (unlikely(cs->singlestep_enabled) && dc->is_jmp != DISAS_EXC) {
10389 /* Note that this means single stepping WFI doesn't halt the CPU.
10390 * For conditional branch insns this is harmless unreachable code as
10391 * gen_goto_tb() has already handled emitting the debug exception
10392 * (and thus a tb-jump is not possible when singlestepping).
10394 assert(dc->is_jmp != DISAS_TB_JUMP);
10395 if (dc->is_jmp != DISAS_JUMP) {
10396 gen_a64_set_pc_im(dc->pc);
10398 gen_exception(EXCP_DEBUG);
10400 switch (dc->is_jmp) {
10402 gen_goto_tb(dc, 1, dc->pc);
10406 gen_a64_set_pc_im(dc->pc);
10409 /* indicate that the hash table must be used to find the next TB */
10410 tcg_gen_exit_tb(0);
10412 case DISAS_TB_JUMP:
10417 /* This is a special case because we don't want to just halt the CPU
10418 * if trying to debug across a WFI.
10420 gen_a64_set_pc_im(dc->pc);
10421 gen_helper_wfi(cpu_env);
10427 gen_tb_end(tb, num_insns);
10428 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
10431 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
10432 qemu_log("----------------\n");
10433 qemu_log("IN: %s\n", lookup_symbol(pc_start));
10434 log_target_disas(env, pc_start, dc->pc - pc_start,
10435 4 | (dc->bswap_code << 1));
10440 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
10443 tcg_ctx.gen_opc_instr_start[lj++] = 0;
10446 tb->size = dc->pc - pc_start;
10447 tb->icount = num_insns;