4 * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
22 #include "exec/exec-all.h"
26 #include "translate.h"
27 #include "internals.h"
28 #include "qemu/host-utils.h"
30 #include "exec/semihost.h"
31 #include "exec/gen-icount.h"
33 #include "exec/helper-proto.h"
34 #include "exec/helper-gen.h"
37 #include "trace-tcg.h"
39 static TCGv_i64 cpu_X
[32];
40 static TCGv_i64 cpu_pc
;
42 /* Load/store exclusive handling */
43 static TCGv_i64 cpu_exclusive_high
;
44 static TCGv_i64
cpu_reg(DisasContext
*s
, int reg
);
46 static const char *regnames
[] = {
47 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
48 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
49 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
50 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
54 A64_SHIFT_TYPE_LSL
= 0,
55 A64_SHIFT_TYPE_LSR
= 1,
56 A64_SHIFT_TYPE_ASR
= 2,
57 A64_SHIFT_TYPE_ROR
= 3
60 /* Table based decoder typedefs - used when the relevant bits for decode
61 * are too awkwardly scattered across the instruction (eg SIMD).
63 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
65 typedef struct AArch64DecodeTable
{
68 AArch64DecodeFn
*disas_fn
;
71 /* Function prototype for gen_ functions for calling Neon helpers */
72 typedef void NeonGenOneOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
);
73 typedef void NeonGenTwoOpFn(TCGv_i32
, TCGv_i32
, TCGv_i32
);
74 typedef void NeonGenTwoOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
, TCGv_i32
);
75 typedef void NeonGenTwo64OpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
);
76 typedef void NeonGenTwo64OpEnvFn(TCGv_i64
, TCGv_ptr
, TCGv_i64
, TCGv_i64
);
77 typedef void NeonGenNarrowFn(TCGv_i32
, TCGv_i64
);
78 typedef void NeonGenNarrowEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i64
);
79 typedef void NeonGenWidenFn(TCGv_i64
, TCGv_i32
);
80 typedef void NeonGenTwoSingleOPFn(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
81 typedef void NeonGenTwoDoubleOPFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGv_ptr
);
82 typedef void NeonGenOneOpFn(TCGv_i64
, TCGv_i64
);
83 typedef void CryptoTwoOpEnvFn(TCGv_ptr
, TCGv_i32
, TCGv_i32
);
84 typedef void CryptoThreeOpEnvFn(TCGv_ptr
, TCGv_i32
, TCGv_i32
, TCGv_i32
);
86 /* initialize TCG globals. */
87 void a64_translate_init(void)
91 cpu_pc
= tcg_global_mem_new_i64(cpu_env
,
92 offsetof(CPUARMState
, pc
),
94 for (i
= 0; i
< 32; i
++) {
95 cpu_X
[i
] = tcg_global_mem_new_i64(cpu_env
,
96 offsetof(CPUARMState
, xregs
[i
]),
100 cpu_exclusive_high
= tcg_global_mem_new_i64(cpu_env
,
101 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
104 static inline ARMMMUIdx
get_a64_user_mem_index(DisasContext
*s
)
106 /* Return the mmu_idx to use for A64 "unprivileged load/store" insns:
107 * if EL1, access as if EL0; otherwise access at current EL
109 switch (s
->mmu_idx
) {
110 case ARMMMUIdx_S12NSE1
:
111 return ARMMMUIdx_S12NSE0
;
112 case ARMMMUIdx_S1SE1
:
113 return ARMMMUIdx_S1SE0
;
115 g_assert_not_reached();
121 void aarch64_cpu_dump_state(CPUState
*cs
, FILE *f
,
122 fprintf_function cpu_fprintf
, int flags
)
124 ARMCPU
*cpu
= ARM_CPU(cs
);
125 CPUARMState
*env
= &cpu
->env
;
126 uint32_t psr
= pstate_read(env
);
128 int el
= arm_current_el(env
);
129 const char *ns_status
;
131 cpu_fprintf(f
, "PC=%016"PRIx64
" SP=%016"PRIx64
"\n",
132 env
->pc
, env
->xregs
[31]);
133 for (i
= 0; i
< 31; i
++) {
134 cpu_fprintf(f
, "X%02d=%016"PRIx64
, i
, env
->xregs
[i
]);
136 cpu_fprintf(f
, "\n");
142 if (arm_feature(env
, ARM_FEATURE_EL3
) && el
!= 3) {
143 ns_status
= env
->cp15
.scr_el3
& SCR_NS
? "NS " : "S ";
148 cpu_fprintf(f
, "\nPSTATE=%08x %c%c%c%c %sEL%d%c\n",
150 psr
& PSTATE_N
? 'N' : '-',
151 psr
& PSTATE_Z
? 'Z' : '-',
152 psr
& PSTATE_C
? 'C' : '-',
153 psr
& PSTATE_V
? 'V' : '-',
156 psr
& PSTATE_SP
? 'h' : 't');
158 if (flags
& CPU_DUMP_FPU
) {
160 for (i
= 0; i
< numvfpregs
; i
+= 2) {
161 uint64_t vlo
= float64_val(env
->vfp
.regs
[i
* 2]);
162 uint64_t vhi
= float64_val(env
->vfp
.regs
[(i
* 2) + 1]);
163 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
" ",
165 vlo
= float64_val(env
->vfp
.regs
[(i
+ 1) * 2]);
166 vhi
= float64_val(env
->vfp
.regs
[((i
+ 1) * 2) + 1]);
167 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
"\n",
170 cpu_fprintf(f
, "FPCR: %08x FPSR: %08x\n",
171 vfp_get_fpcr(env
), vfp_get_fpsr(env
));
175 void gen_a64_set_pc_im(uint64_t val
)
177 tcg_gen_movi_i64(cpu_pc
, val
);
180 /* Load the PC from a generic TCG variable.
182 * If address tagging is enabled via the TCR TBI bits, then loading
183 * an address into the PC will clear out any tag in the it:
184 * + for EL2 and EL3 there is only one TBI bit, and if it is set
185 * then the address is zero-extended, clearing bits [63:56]
186 * + for EL0 and EL1, TBI0 controls addresses with bit 55 == 0
187 * and TBI1 controls addressses with bit 55 == 1.
188 * If the appropriate TBI bit is set for the address then
189 * the address is sign-extended from bit 55 into bits [63:56]
191 * We can avoid doing this for relative-branches, because the
192 * PC + offset can never overflow into the tag bits (assuming
193 * that virtual addresses are less than 56 bits wide, as they
194 * are currently), but we must handle it for branch-to-register.
196 static void gen_a64_set_pc(DisasContext
*s
, TCGv_i64 src
)
199 if (s
->current_el
<= 1) {
200 /* Test if NEITHER or BOTH TBI values are set. If so, no need to
201 * examine bit 55 of address, can just generate code.
202 * If mixed, then test via generated code
204 if (s
->tbi0
&& s
->tbi1
) {
205 TCGv_i64 tmp_reg
= tcg_temp_new_i64();
206 /* Both bits set, sign extension from bit 55 into [63:56] will
209 tcg_gen_shli_i64(tmp_reg
, src
, 8);
210 tcg_gen_sari_i64(cpu_pc
, tmp_reg
, 8);
211 tcg_temp_free_i64(tmp_reg
);
212 } else if (!s
->tbi0
&& !s
->tbi1
) {
213 /* Neither bit set, just load it as-is */
214 tcg_gen_mov_i64(cpu_pc
, src
);
216 TCGv_i64 tcg_tmpval
= tcg_temp_new_i64();
217 TCGv_i64 tcg_bit55
= tcg_temp_new_i64();
218 TCGv_i64 tcg_zero
= tcg_const_i64(0);
220 tcg_gen_andi_i64(tcg_bit55
, src
, (1ull << 55));
223 /* tbi0==1, tbi1==0, so 0-fill upper byte if bit 55 = 0 */
224 tcg_gen_andi_i64(tcg_tmpval
, src
,
225 0x00FFFFFFFFFFFFFFull
);
226 tcg_gen_movcond_i64(TCG_COND_EQ
, cpu_pc
, tcg_bit55
, tcg_zero
,
229 /* tbi0==0, tbi1==1, so 1-fill upper byte if bit 55 = 1 */
230 tcg_gen_ori_i64(tcg_tmpval
, src
,
231 0xFF00000000000000ull
);
232 tcg_gen_movcond_i64(TCG_COND_NE
, cpu_pc
, tcg_bit55
, tcg_zero
,
235 tcg_temp_free_i64(tcg_zero
);
236 tcg_temp_free_i64(tcg_bit55
);
237 tcg_temp_free_i64(tcg_tmpval
);
239 } else { /* EL > 1 */
241 /* Force tag byte to all zero */
242 tcg_gen_andi_i64(cpu_pc
, src
, 0x00FFFFFFFFFFFFFFull
);
244 /* Load unmodified address */
245 tcg_gen_mov_i64(cpu_pc
, src
);
250 typedef struct DisasCompare64
{
255 static void a64_test_cc(DisasCompare64
*c64
, int cc
)
259 arm_test_cc(&c32
, cc
);
261 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
262 * properly. The NE/EQ comparisons are also fine with this choice. */
263 c64
->cond
= c32
.cond
;
264 c64
->value
= tcg_temp_new_i64();
265 tcg_gen_ext_i32_i64(c64
->value
, c32
.value
);
270 static void a64_free_cc(DisasCompare64
*c64
)
272 tcg_temp_free_i64(c64
->value
);
275 static void gen_exception_internal(int excp
)
277 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
279 assert(excp_is_internal(excp
));
280 gen_helper_exception_internal(cpu_env
, tcg_excp
);
281 tcg_temp_free_i32(tcg_excp
);
284 static void gen_exception(int excp
, uint32_t syndrome
, uint32_t target_el
)
286 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
287 TCGv_i32 tcg_syn
= tcg_const_i32(syndrome
);
288 TCGv_i32 tcg_el
= tcg_const_i32(target_el
);
290 gen_helper_exception_with_syndrome(cpu_env
, tcg_excp
,
292 tcg_temp_free_i32(tcg_el
);
293 tcg_temp_free_i32(tcg_syn
);
294 tcg_temp_free_i32(tcg_excp
);
297 static void gen_exception_internal_insn(DisasContext
*s
, int offset
, int excp
)
299 gen_a64_set_pc_im(s
->pc
- offset
);
300 gen_exception_internal(excp
);
301 s
->is_jmp
= DISAS_EXC
;
304 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
,
305 uint32_t syndrome
, uint32_t target_el
)
307 gen_a64_set_pc_im(s
->pc
- offset
);
308 gen_exception(excp
, syndrome
, target_el
);
309 s
->is_jmp
= DISAS_EXC
;
312 static void gen_ss_advance(DisasContext
*s
)
314 /* If the singlestep state is Active-not-pending, advance to
319 gen_helper_clear_pstate_ss(cpu_env
);
323 static void gen_step_complete_exception(DisasContext
*s
)
325 /* We just completed step of an insn. Move from Active-not-pending
326 * to Active-pending, and then also take the swstep exception.
327 * This corresponds to making the (IMPDEF) choice to prioritize
328 * swstep exceptions over asynchronous exceptions taken to an exception
329 * level where debug is disabled. This choice has the advantage that
330 * we do not need to maintain internal state corresponding to the
331 * ISV/EX syndrome bits between completion of the step and generation
332 * of the exception, and our syndrome information is always correct.
335 gen_exception(EXCP_UDEF
, syn_swstep(s
->ss_same_el
, 1, s
->is_ldex
),
336 default_exception_el(s
));
337 s
->is_jmp
= DISAS_EXC
;
340 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
342 /* No direct tb linking with singlestep (either QEMU's or the ARM
343 * debug architecture kind) or deterministic io
345 if (s
->singlestep_enabled
|| s
->ss_active
|| (s
->tb
->cflags
& CF_LAST_IO
)) {
349 #ifndef CONFIG_USER_ONLY
350 /* Only link tbs from inside the same guest page */
351 if ((s
->tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
359 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
361 TranslationBlock
*tb
;
364 if (use_goto_tb(s
, n
, dest
)) {
366 gen_a64_set_pc_im(dest
);
367 tcg_gen_exit_tb((intptr_t)tb
+ n
);
368 s
->is_jmp
= DISAS_TB_JUMP
;
370 gen_a64_set_pc_im(dest
);
372 gen_step_complete_exception(s
);
373 } else if (s
->singlestep_enabled
) {
374 gen_exception_internal(EXCP_DEBUG
);
377 s
->is_jmp
= DISAS_TB_JUMP
;
382 static void unallocated_encoding(DisasContext
*s
)
384 /* Unallocated and reserved encodings are uncategorized */
385 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized(),
386 default_exception_el(s
));
389 #define unsupported_encoding(s, insn) \
391 qemu_log_mask(LOG_UNIMP, \
392 "%s:%d: unsupported instruction encoding 0x%08x " \
393 "at pc=%016" PRIx64 "\n", \
394 __FILE__, __LINE__, insn, s->pc - 4); \
395 unallocated_encoding(s); \
398 static void init_tmp_a64_array(DisasContext
*s
)
400 #ifdef CONFIG_DEBUG_TCG
402 for (i
= 0; i
< ARRAY_SIZE(s
->tmp_a64
); i
++) {
403 TCGV_UNUSED_I64(s
->tmp_a64
[i
]);
406 s
->tmp_a64_count
= 0;
409 static void free_tmp_a64(DisasContext
*s
)
412 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
413 tcg_temp_free_i64(s
->tmp_a64
[i
]);
415 init_tmp_a64_array(s
);
418 static TCGv_i64
new_tmp_a64(DisasContext
*s
)
420 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
421 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
424 static TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
426 TCGv_i64 t
= new_tmp_a64(s
);
427 tcg_gen_movi_i64(t
, 0);
432 * Register access functions
434 * These functions are used for directly accessing a register in where
435 * changes to the final register value are likely to be made. If you
436 * need to use a register for temporary calculation (e.g. index type
437 * operations) use the read_* form.
439 * B1.2.1 Register mappings
441 * In instruction register encoding 31 can refer to ZR (zero register) or
442 * the SP (stack pointer) depending on context. In QEMU's case we map SP
443 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
444 * This is the point of the _sp forms.
446 static TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
449 return new_tmp_a64_zero(s
);
455 /* register access for when 31 == SP */
456 static TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
461 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
462 * representing the register contents. This TCGv is an auto-freed
463 * temporary so it need not be explicitly freed, and may be modified.
465 static TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
467 TCGv_i64 v
= new_tmp_a64(s
);
470 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
472 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
475 tcg_gen_movi_i64(v
, 0);
480 static TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
482 TCGv_i64 v
= new_tmp_a64(s
);
484 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
486 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
491 /* We should have at some point before trying to access an FP register
492 * done the necessary access check, so assert that
493 * (a) we did the check and
494 * (b) we didn't then just plough ahead anyway if it failed.
495 * Print the instruction pattern in the abort message so we can figure
496 * out what we need to fix if a user encounters this problem in the wild.
498 static inline void assert_fp_access_checked(DisasContext
*s
)
500 #ifdef CONFIG_DEBUG_TCG
501 if (unlikely(!s
->fp_access_checked
|| s
->fp_excp_el
)) {
502 fprintf(stderr
, "target-arm: FP access check missing for "
503 "instruction 0x%08x\n", s
->insn
);
509 /* Return the offset into CPUARMState of an element of specified
510 * size, 'element' places in from the least significant end of
511 * the FP/vector register Qn.
513 static inline int vec_reg_offset(DisasContext
*s
, int regno
,
514 int element
, TCGMemOp size
)
517 #ifdef HOST_WORDS_BIGENDIAN
518 /* This is complicated slightly because vfp.regs[2n] is
519 * still the low half and vfp.regs[2n+1] the high half
520 * of the 128 bit vector, even on big endian systems.
521 * Calculate the offset assuming a fully bigendian 128 bits,
522 * then XOR to account for the order of the two 64 bit halves.
524 offs
+= (16 - ((element
+ 1) * (1 << size
)));
527 offs
+= element
* (1 << size
);
529 offs
+= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
530 assert_fp_access_checked(s
);
534 /* Return the offset into CPUARMState of a slice (from
535 * the least significant end) of FP register Qn (ie
537 * (Note that this is not the same mapping as for A32; see cpu.h)
539 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
541 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
542 #ifdef HOST_WORDS_BIGENDIAN
543 offs
+= (8 - (1 << size
));
545 assert_fp_access_checked(s
);
549 /* Offset of the high half of the 128 bit vector Qn */
550 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
552 assert_fp_access_checked(s
);
553 return offsetof(CPUARMState
, vfp
.regs
[regno
* 2 + 1]);
556 /* Convenience accessors for reading and writing single and double
557 * FP registers. Writing clears the upper parts of the associated
558 * 128 bit vector register, as required by the architecture.
559 * Note that unlike the GP register accessors, the values returned
560 * by the read functions must be manually freed.
562 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
564 TCGv_i64 v
= tcg_temp_new_i64();
566 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
570 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
572 TCGv_i32 v
= tcg_temp_new_i32();
574 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
578 static void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
580 TCGv_i64 tcg_zero
= tcg_const_i64(0);
582 tcg_gen_st_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
583 tcg_gen_st_i64(tcg_zero
, cpu_env
, fp_reg_hi_offset(s
, reg
));
584 tcg_temp_free_i64(tcg_zero
);
587 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
589 TCGv_i64 tmp
= tcg_temp_new_i64();
591 tcg_gen_extu_i32_i64(tmp
, v
);
592 write_fp_dreg(s
, reg
, tmp
);
593 tcg_temp_free_i64(tmp
);
596 static TCGv_ptr
get_fpstatus_ptr(void)
598 TCGv_ptr statusptr
= tcg_temp_new_ptr();
601 /* In A64 all instructions (both FP and Neon) use the FPCR;
602 * there is no equivalent of the A32 Neon "standard FPSCR value"
603 * and all operations use vfp.fp_status.
605 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
606 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
610 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
611 * than the 32 bit equivalent.
613 static inline void gen_set_NZ64(TCGv_i64 result
)
615 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
616 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
619 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
620 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
623 gen_set_NZ64(result
);
625 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
626 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
628 tcg_gen_movi_i32(cpu_CF
, 0);
629 tcg_gen_movi_i32(cpu_VF
, 0);
632 /* dest = T0 + T1; compute C, N, V and Z flags */
633 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
636 TCGv_i64 result
, flag
, tmp
;
637 result
= tcg_temp_new_i64();
638 flag
= tcg_temp_new_i64();
639 tmp
= tcg_temp_new_i64();
641 tcg_gen_movi_i64(tmp
, 0);
642 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
644 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
646 gen_set_NZ64(result
);
648 tcg_gen_xor_i64(flag
, result
, t0
);
649 tcg_gen_xor_i64(tmp
, t0
, t1
);
650 tcg_gen_andc_i64(flag
, flag
, tmp
);
651 tcg_temp_free_i64(tmp
);
652 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
654 tcg_gen_mov_i64(dest
, result
);
655 tcg_temp_free_i64(result
);
656 tcg_temp_free_i64(flag
);
658 /* 32 bit arithmetic */
659 TCGv_i32 t0_32
= tcg_temp_new_i32();
660 TCGv_i32 t1_32
= tcg_temp_new_i32();
661 TCGv_i32 tmp
= tcg_temp_new_i32();
663 tcg_gen_movi_i32(tmp
, 0);
664 tcg_gen_extrl_i64_i32(t0_32
, t0
);
665 tcg_gen_extrl_i64_i32(t1_32
, t1
);
666 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
667 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
668 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
669 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
670 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
671 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
673 tcg_temp_free_i32(tmp
);
674 tcg_temp_free_i32(t0_32
);
675 tcg_temp_free_i32(t1_32
);
679 /* dest = T0 - T1; compute C, N, V and Z flags */
680 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
683 /* 64 bit arithmetic */
684 TCGv_i64 result
, flag
, tmp
;
686 result
= tcg_temp_new_i64();
687 flag
= tcg_temp_new_i64();
688 tcg_gen_sub_i64(result
, t0
, t1
);
690 gen_set_NZ64(result
);
692 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
693 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
695 tcg_gen_xor_i64(flag
, result
, t0
);
696 tmp
= tcg_temp_new_i64();
697 tcg_gen_xor_i64(tmp
, t0
, t1
);
698 tcg_gen_and_i64(flag
, flag
, tmp
);
699 tcg_temp_free_i64(tmp
);
700 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
701 tcg_gen_mov_i64(dest
, result
);
702 tcg_temp_free_i64(flag
);
703 tcg_temp_free_i64(result
);
705 /* 32 bit arithmetic */
706 TCGv_i32 t0_32
= tcg_temp_new_i32();
707 TCGv_i32 t1_32
= tcg_temp_new_i32();
710 tcg_gen_extrl_i64_i32(t0_32
, t0
);
711 tcg_gen_extrl_i64_i32(t1_32
, t1
);
712 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
713 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
714 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
715 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
716 tmp
= tcg_temp_new_i32();
717 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
718 tcg_temp_free_i32(t0_32
);
719 tcg_temp_free_i32(t1_32
);
720 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
721 tcg_temp_free_i32(tmp
);
722 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
726 /* dest = T0 + T1 + CF; do not compute flags. */
727 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
729 TCGv_i64 flag
= tcg_temp_new_i64();
730 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
731 tcg_gen_add_i64(dest
, t0
, t1
);
732 tcg_gen_add_i64(dest
, dest
, flag
);
733 tcg_temp_free_i64(flag
);
736 tcg_gen_ext32u_i64(dest
, dest
);
740 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
741 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
744 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
745 result
= tcg_temp_new_i64();
746 cf_64
= tcg_temp_new_i64();
747 vf_64
= tcg_temp_new_i64();
748 tmp
= tcg_const_i64(0);
750 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
751 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
752 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
753 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
754 gen_set_NZ64(result
);
756 tcg_gen_xor_i64(vf_64
, result
, t0
);
757 tcg_gen_xor_i64(tmp
, t0
, t1
);
758 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
759 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
761 tcg_gen_mov_i64(dest
, result
);
763 tcg_temp_free_i64(tmp
);
764 tcg_temp_free_i64(vf_64
);
765 tcg_temp_free_i64(cf_64
);
766 tcg_temp_free_i64(result
);
768 TCGv_i32 t0_32
, t1_32
, tmp
;
769 t0_32
= tcg_temp_new_i32();
770 t1_32
= tcg_temp_new_i32();
771 tmp
= tcg_const_i32(0);
773 tcg_gen_extrl_i64_i32(t0_32
, t0
);
774 tcg_gen_extrl_i64_i32(t1_32
, t1
);
775 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
776 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
778 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
779 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
780 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
781 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
782 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
784 tcg_temp_free_i32(tmp
);
785 tcg_temp_free_i32(t1_32
);
786 tcg_temp_free_i32(t0_32
);
791 * Load/Store generators
795 * Store from GPR register to memory.
797 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
798 TCGv_i64 tcg_addr
, int size
, int memidx
,
800 unsigned int iss_srt
,
801 bool iss_sf
, bool iss_ar
)
804 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, s
->be_data
+ size
);
809 syn
= syn_data_abort_with_iss(0,
815 0, 0, 0, 0, 0, false);
816 disas_set_insn_syndrome(s
, syn
);
820 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
821 TCGv_i64 tcg_addr
, int size
,
823 unsigned int iss_srt
,
824 bool iss_sf
, bool iss_ar
)
826 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
),
827 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
831 * Load from memory to GPR register
833 static void do_gpr_ld_memidx(DisasContext
*s
,
834 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
835 int size
, bool is_signed
,
836 bool extend
, int memidx
,
837 bool iss_valid
, unsigned int iss_srt
,
838 bool iss_sf
, bool iss_ar
)
840 TCGMemOp memop
= s
->be_data
+ size
;
848 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
850 if (extend
&& is_signed
) {
852 tcg_gen_ext32u_i64(dest
, dest
);
858 syn
= syn_data_abort_with_iss(0,
864 0, 0, 0, 0, 0, false);
865 disas_set_insn_syndrome(s
, syn
);
869 static void do_gpr_ld(DisasContext
*s
,
870 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
871 int size
, bool is_signed
, bool extend
,
872 bool iss_valid
, unsigned int iss_srt
,
873 bool iss_sf
, bool iss_ar
)
875 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
877 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
881 * Store from FP register to memory
883 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
885 /* This writes the bottom N bits of a 128 bit wide vector to memory */
886 TCGv_i64 tmp
= tcg_temp_new_i64();
887 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
889 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
),
892 bool be
= s
->be_data
== MO_BE
;
893 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
895 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
896 tcg_gen_qemu_st_i64(tmp
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
898 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
899 tcg_gen_qemu_st_i64(tmp
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
901 tcg_temp_free_i64(tcg_hiaddr
);
904 tcg_temp_free_i64(tmp
);
908 * Load from memory to FP register
910 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
912 /* This always zero-extends and writes to a full 128 bit wide vector */
913 TCGv_i64 tmplo
= tcg_temp_new_i64();
917 TCGMemOp memop
= s
->be_data
+ size
;
918 tmphi
= tcg_const_i64(0);
919 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
921 bool be
= s
->be_data
== MO_BE
;
924 tmphi
= tcg_temp_new_i64();
925 tcg_hiaddr
= tcg_temp_new_i64();
927 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
928 tcg_gen_qemu_ld_i64(tmplo
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
930 tcg_gen_qemu_ld_i64(tmphi
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
932 tcg_temp_free_i64(tcg_hiaddr
);
935 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
936 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
938 tcg_temp_free_i64(tmplo
);
939 tcg_temp_free_i64(tmphi
);
943 * Vector load/store helpers.
945 * The principal difference between this and a FP load is that we don't
946 * zero extend as we are filling a partial chunk of the vector register.
947 * These functions don't support 128 bit loads/stores, which would be
948 * normal load/store operations.
950 * The _i32 versions are useful when operating on 32 bit quantities
951 * (eg for floating point single or using Neon helper functions).
954 /* Get value of an element within a vector register */
955 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
956 int element
, TCGMemOp memop
)
958 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
961 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
964 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
967 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
970 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
973 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
976 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
980 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
983 g_assert_not_reached();
987 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
988 int element
, TCGMemOp memop
)
990 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
993 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
996 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
999 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
1002 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
1006 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
1009 g_assert_not_reached();
1013 /* Set value of an element within a vector register */
1014 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
1015 int element
, TCGMemOp memop
)
1017 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1020 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
1023 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
1026 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
1029 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
1032 g_assert_not_reached();
1036 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
1037 int destidx
, int element
, TCGMemOp memop
)
1039 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1042 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
1045 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
1048 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
1051 g_assert_not_reached();
1055 /* Clear the high 64 bits of a 128 bit vector (in general non-quad
1056 * vector ops all need to do this).
1058 static void clear_vec_high(DisasContext
*s
, int rd
)
1060 TCGv_i64 tcg_zero
= tcg_const_i64(0);
1062 write_vec_element(s
, tcg_zero
, rd
, 1, MO_64
);
1063 tcg_temp_free_i64(tcg_zero
);
1066 /* Store from vector register to memory */
1067 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
1068 TCGv_i64 tcg_addr
, int size
)
1070 TCGMemOp memop
= s
->be_data
+ size
;
1071 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1073 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
1074 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
1076 tcg_temp_free_i64(tcg_tmp
);
1079 /* Load from memory to vector register */
1080 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
1081 TCGv_i64 tcg_addr
, int size
)
1083 TCGMemOp memop
= s
->be_data
+ size
;
1084 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1086 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
1087 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
1089 tcg_temp_free_i64(tcg_tmp
);
1092 /* Check that FP/Neon access is enabled. If it is, return
1093 * true. If not, emit code to generate an appropriate exception,
1094 * and return false; the caller should not emit any code for
1095 * the instruction. Note that this check must happen after all
1096 * unallocated-encoding checks (otherwise the syndrome information
1097 * for the resulting exception will be incorrect).
1099 static inline bool fp_access_check(DisasContext
*s
)
1101 assert(!s
->fp_access_checked
);
1102 s
->fp_access_checked
= true;
1104 if (!s
->fp_excp_el
) {
1108 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false),
1114 * This utility function is for doing register extension with an
1115 * optional shift. You will likely want to pass a temporary for the
1116 * destination register. See DecodeRegExtend() in the ARM ARM.
1118 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1119 int option
, unsigned int shift
)
1121 int extsize
= extract32(option
, 0, 2);
1122 bool is_signed
= extract32(option
, 2, 1);
1127 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1130 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1133 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1136 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1142 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1145 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1148 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1151 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1157 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1161 static inline void gen_check_sp_alignment(DisasContext
*s
)
1163 /* The AArch64 architecture mandates that (if enabled via PSTATE
1164 * or SCTLR bits) there is a check that SP is 16-aligned on every
1165 * SP-relative load or store (with an exception generated if it is not).
1166 * In line with general QEMU practice regarding misaligned accesses,
1167 * we omit these checks for the sake of guest program performance.
1168 * This function is provided as a hook so we can more easily add these
1169 * checks in future (possibly as a "favour catching guest program bugs
1170 * over speed" user selectable option).
1175 * This provides a simple table based table lookup decoder. It is
1176 * intended to be used when the relevant bits for decode are too
1177 * awkwardly placed and switch/if based logic would be confusing and
1178 * deeply nested. Since it's a linear search through the table, tables
1179 * should be kept small.
1181 * It returns the first handler where insn & mask == pattern, or
1182 * NULL if there is no match.
1183 * The table is terminated by an empty mask (i.e. 0)
1185 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1188 const AArch64DecodeTable
*tptr
= table
;
1190 while (tptr
->mask
) {
1191 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1192 return tptr
->disas_fn
;
1200 * the instruction disassembly implemented here matches
1201 * the instruction encoding classifications in chapter 3 (C3)
1202 * of the ARM Architecture Reference Manual (DDI0487A_a)
1205 /* C3.2.7 Unconditional branch (immediate)
1207 * +----+-----------+-------------------------------------+
1208 * | op | 0 0 1 0 1 | imm26 |
1209 * +----+-----------+-------------------------------------+
1211 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1213 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1215 if (insn
& (1U << 31)) {
1216 /* C5.6.26 BL Branch with link */
1217 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1220 /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
1221 gen_goto_tb(s
, 0, addr
);
1224 /* C3.2.1 Compare & branch (immediate)
1225 * 31 30 25 24 23 5 4 0
1226 * +----+-------------+----+---------------------+--------+
1227 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1228 * +----+-------------+----+---------------------+--------+
1230 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1232 unsigned int sf
, op
, rt
;
1234 TCGLabel
*label_match
;
1237 sf
= extract32(insn
, 31, 1);
1238 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1239 rt
= extract32(insn
, 0, 5);
1240 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1242 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1243 label_match
= gen_new_label();
1245 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1246 tcg_cmp
, 0, label_match
);
1248 gen_goto_tb(s
, 0, s
->pc
);
1249 gen_set_label(label_match
);
1250 gen_goto_tb(s
, 1, addr
);
1253 /* C3.2.5 Test & branch (immediate)
1254 * 31 30 25 24 23 19 18 5 4 0
1255 * +----+-------------+----+-------+-------------+------+
1256 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1257 * +----+-------------+----+-------+-------------+------+
1259 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1261 unsigned int bit_pos
, op
, rt
;
1263 TCGLabel
*label_match
;
1266 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1267 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1268 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1269 rt
= extract32(insn
, 0, 5);
1271 tcg_cmp
= tcg_temp_new_i64();
1272 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1273 label_match
= gen_new_label();
1274 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1275 tcg_cmp
, 0, label_match
);
1276 tcg_temp_free_i64(tcg_cmp
);
1277 gen_goto_tb(s
, 0, s
->pc
);
1278 gen_set_label(label_match
);
1279 gen_goto_tb(s
, 1, addr
);
1282 /* C3.2.2 / C5.6.19 Conditional branch (immediate)
1283 * 31 25 24 23 5 4 3 0
1284 * +---------------+----+---------------------+----+------+
1285 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1286 * +---------------+----+---------------------+----+------+
1288 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1293 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1294 unallocated_encoding(s
);
1297 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1298 cond
= extract32(insn
, 0, 4);
1301 /* genuinely conditional branches */
1302 TCGLabel
*label_match
= gen_new_label();
1303 arm_gen_test_cc(cond
, label_match
);
1304 gen_goto_tb(s
, 0, s
->pc
);
1305 gen_set_label(label_match
);
1306 gen_goto_tb(s
, 1, addr
);
1308 /* 0xe and 0xf are both "always" conditions */
1309 gen_goto_tb(s
, 0, addr
);
1314 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1315 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1317 unsigned int selector
= crm
<< 3 | op2
;
1320 unallocated_encoding(s
);
1328 s
->is_jmp
= DISAS_WFI
;
1331 if (!parallel_cpus
) {
1332 s
->is_jmp
= DISAS_YIELD
;
1336 if (!parallel_cpus
) {
1337 s
->is_jmp
= DISAS_WFE
;
1342 /* we treat all as NOP at least for now */
1345 /* default specified as NOP equivalent */
1350 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1352 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1355 /* CLREX, DSB, DMB, ISB */
1356 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1357 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1362 unallocated_encoding(s
);
1373 case 1: /* MBReqTypes_Reads */
1374 bar
= TCG_BAR_SC
| TCG_MO_LD_LD
| TCG_MO_LD_ST
;
1376 case 2: /* MBReqTypes_Writes */
1377 bar
= TCG_BAR_SC
| TCG_MO_ST_ST
;
1379 default: /* MBReqTypes_All */
1380 bar
= TCG_BAR_SC
| TCG_MO_ALL
;
1386 /* We need to break the TB after this insn to execute
1387 * a self-modified code correctly and also to take
1388 * any pending interrupts immediately.
1390 s
->is_jmp
= DISAS_UPDATE
;
1393 unallocated_encoding(s
);
1398 /* C5.6.130 MSR (immediate) - move immediate to processor state field */
1399 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1400 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1402 int op
= op1
<< 3 | op2
;
1404 case 0x05: /* SPSel */
1405 if (s
->current_el
== 0) {
1406 unallocated_encoding(s
);
1410 case 0x1e: /* DAIFSet */
1411 case 0x1f: /* DAIFClear */
1413 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1414 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1415 gen_a64_set_pc_im(s
->pc
- 4);
1416 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1417 tcg_temp_free_i32(tcg_imm
);
1418 tcg_temp_free_i32(tcg_op
);
1419 s
->is_jmp
= DISAS_UPDATE
;
1423 unallocated_encoding(s
);
1428 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1430 TCGv_i32 tmp
= tcg_temp_new_i32();
1431 TCGv_i32 nzcv
= tcg_temp_new_i32();
1433 /* build bit 31, N */
1434 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1435 /* build bit 30, Z */
1436 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1437 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1438 /* build bit 29, C */
1439 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1440 /* build bit 28, V */
1441 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1442 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1443 /* generate result */
1444 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1446 tcg_temp_free_i32(nzcv
);
1447 tcg_temp_free_i32(tmp
);
1450 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1453 TCGv_i32 nzcv
= tcg_temp_new_i32();
1455 /* take NZCV from R[t] */
1456 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1459 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1461 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1462 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1464 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1465 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1467 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1468 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1469 tcg_temp_free_i32(nzcv
);
1472 /* C5.6.129 MRS - move from system register
1473 * C5.6.131 MSR (register) - move to system register
1476 * These are all essentially the same insn in 'read' and 'write'
1477 * versions, with varying op0 fields.
1479 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1480 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1481 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1483 const ARMCPRegInfo
*ri
;
1486 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1487 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1488 crn
, crm
, op0
, op1
, op2
));
1491 /* Unknown register; this might be a guest error or a QEMU
1492 * unimplemented feature.
1494 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1495 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1496 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1497 unallocated_encoding(s
);
1501 /* Check access permissions */
1502 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1503 unallocated_encoding(s
);
1508 /* Emit code to perform further access permissions checks at
1509 * runtime; this may result in an exception.
1512 TCGv_i32 tcg_syn
, tcg_isread
;
1515 gen_a64_set_pc_im(s
->pc
- 4);
1516 tmpptr
= tcg_const_ptr(ri
);
1517 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1518 tcg_syn
= tcg_const_i32(syndrome
);
1519 tcg_isread
= tcg_const_i32(isread
);
1520 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
, tcg_isread
);
1521 tcg_temp_free_ptr(tmpptr
);
1522 tcg_temp_free_i32(tcg_syn
);
1523 tcg_temp_free_i32(tcg_isread
);
1526 /* Handle special cases first */
1527 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1531 tcg_rt
= cpu_reg(s
, rt
);
1533 gen_get_nzcv(tcg_rt
);
1535 gen_set_nzcv(tcg_rt
);
1538 case ARM_CP_CURRENTEL
:
1539 /* Reads as current EL value from pstate, which is
1540 * guaranteed to be constant by the tb flags.
1542 tcg_rt
= cpu_reg(s
, rt
);
1543 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1546 /* Writes clear the aligned block of memory which rt points into. */
1547 tcg_rt
= cpu_reg(s
, rt
);
1548 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1554 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1558 tcg_rt
= cpu_reg(s
, rt
);
1561 if (ri
->type
& ARM_CP_CONST
) {
1562 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1563 } else if (ri
->readfn
) {
1565 tmpptr
= tcg_const_ptr(ri
);
1566 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1567 tcg_temp_free_ptr(tmpptr
);
1569 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1572 if (ri
->type
& ARM_CP_CONST
) {
1573 /* If not forbidden by access permissions, treat as WI */
1575 } else if (ri
->writefn
) {
1577 tmpptr
= tcg_const_ptr(ri
);
1578 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1579 tcg_temp_free_ptr(tmpptr
);
1581 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1585 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1586 /* I/O operations must end the TB here (whether read or write) */
1588 s
->is_jmp
= DISAS_UPDATE
;
1589 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1590 /* We default to ending the TB on a coprocessor register write,
1591 * but allow this to be suppressed by the register definition
1592 * (usually only necessary to work around guest bugs).
1594 s
->is_jmp
= DISAS_UPDATE
;
1599 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1600 * +---------------------+---+-----+-----+-------+-------+-----+------+
1601 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1602 * +---------------------+---+-----+-----+-------+-------+-----+------+
1604 static void disas_system(DisasContext
*s
, uint32_t insn
)
1606 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1607 l
= extract32(insn
, 21, 1);
1608 op0
= extract32(insn
, 19, 2);
1609 op1
= extract32(insn
, 16, 3);
1610 crn
= extract32(insn
, 12, 4);
1611 crm
= extract32(insn
, 8, 4);
1612 op2
= extract32(insn
, 5, 3);
1613 rt
= extract32(insn
, 0, 5);
1616 if (l
|| rt
!= 31) {
1617 unallocated_encoding(s
);
1621 case 2: /* C5.6.68 HINT */
1622 handle_hint(s
, insn
, op1
, op2
, crm
);
1624 case 3: /* CLREX, DSB, DMB, ISB */
1625 handle_sync(s
, insn
, op1
, op2
, crm
);
1627 case 4: /* C5.6.130 MSR (immediate) */
1628 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1631 unallocated_encoding(s
);
1636 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1639 /* C3.2.3 Exception generation
1641 * 31 24 23 21 20 5 4 2 1 0
1642 * +-----------------+-----+------------------------+-----+----+
1643 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1644 * +-----------------------+------------------------+----------+
1646 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1648 int opc
= extract32(insn
, 21, 3);
1649 int op2_ll
= extract32(insn
, 0, 5);
1650 int imm16
= extract32(insn
, 5, 16);
1655 /* For SVC, HVC and SMC we advance the single-step state
1656 * machine before taking the exception. This is architecturally
1657 * mandated, to ensure that single-stepping a system call
1658 * instruction works properly.
1663 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
),
1664 default_exception_el(s
));
1667 if (s
->current_el
== 0) {
1668 unallocated_encoding(s
);
1671 /* The pre HVC helper handles cases when HVC gets trapped
1672 * as an undefined insn by runtime configuration.
1674 gen_a64_set_pc_im(s
->pc
- 4);
1675 gen_helper_pre_hvc(cpu_env
);
1677 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
), 2);
1680 if (s
->current_el
== 0) {
1681 unallocated_encoding(s
);
1684 gen_a64_set_pc_im(s
->pc
- 4);
1685 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1686 gen_helper_pre_smc(cpu_env
, tmp
);
1687 tcg_temp_free_i32(tmp
);
1689 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
), 3);
1692 unallocated_encoding(s
);
1698 unallocated_encoding(s
);
1702 gen_exception_insn(s
, 4, EXCP_BKPT
, syn_aa64_bkpt(imm16
),
1703 default_exception_el(s
));
1707 unallocated_encoding(s
);
1710 /* HLT. This has two purposes.
1711 * Architecturally, it is an external halting debug instruction.
1712 * Since QEMU doesn't implement external debug, we treat this as
1713 * it is required for halting debug disabled: it will UNDEF.
1714 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1716 if (semihosting_enabled() && imm16
== 0xf000) {
1717 #ifndef CONFIG_USER_ONLY
1718 /* In system mode, don't allow userspace access to semihosting,
1719 * to provide some semblance of security (and for consistency
1720 * with our 32-bit semihosting).
1722 if (s
->current_el
== 0) {
1723 unsupported_encoding(s
, insn
);
1727 gen_exception_internal_insn(s
, 0, EXCP_SEMIHOST
);
1729 unsupported_encoding(s
, insn
);
1733 if (op2_ll
< 1 || op2_ll
> 3) {
1734 unallocated_encoding(s
);
1737 /* DCPS1, DCPS2, DCPS3 */
1738 unsupported_encoding(s
, insn
);
1741 unallocated_encoding(s
);
1746 /* C3.2.7 Unconditional branch (register)
1747 * 31 25 24 21 20 16 15 10 9 5 4 0
1748 * +---------------+-------+-------+-------+------+-------+
1749 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1750 * +---------------+-------+-------+-------+------+-------+
1752 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1754 unsigned int opc
, op2
, op3
, rn
, op4
;
1756 opc
= extract32(insn
, 21, 4);
1757 op2
= extract32(insn
, 16, 5);
1758 op3
= extract32(insn
, 10, 6);
1759 rn
= extract32(insn
, 5, 5);
1760 op4
= extract32(insn
, 0, 5);
1762 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1763 unallocated_encoding(s
);
1771 gen_a64_set_pc(s
, cpu_reg(s
, rn
));
1772 /* BLR also needs to load return address */
1774 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1778 if (s
->current_el
== 0) {
1779 unallocated_encoding(s
);
1782 gen_helper_exception_return(cpu_env
);
1783 s
->is_jmp
= DISAS_JUMP
;
1787 unallocated_encoding(s
);
1789 unsupported_encoding(s
, insn
);
1793 unallocated_encoding(s
);
1797 s
->is_jmp
= DISAS_JUMP
;
1800 /* C3.2 Branches, exception generating and system instructions */
1801 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1803 switch (extract32(insn
, 25, 7)) {
1804 case 0x0a: case 0x0b:
1805 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1806 disas_uncond_b_imm(s
, insn
);
1808 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1809 disas_comp_b_imm(s
, insn
);
1811 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1812 disas_test_b_imm(s
, insn
);
1814 case 0x2a: /* Conditional branch (immediate) */
1815 disas_cond_b_imm(s
, insn
);
1817 case 0x6a: /* Exception generation / System */
1818 if (insn
& (1 << 24)) {
1819 disas_system(s
, insn
);
1824 case 0x6b: /* Unconditional branch (register) */
1825 disas_uncond_b_reg(s
, insn
);
1828 unallocated_encoding(s
);
1834 * Load/Store exclusive instructions are implemented by remembering
1835 * the value/address loaded, and seeing if these are the same
1836 * when the store is performed. This is not actually the architecturally
1837 * mandated semantics, but it works for typical guest code sequences
1838 * and avoids having to monitor regular stores.
1840 * The store exclusive uses the atomic cmpxchg primitives to avoid
1841 * races in multi-threaded linux-user and when MTTCG softmmu is
1844 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
1845 TCGv_i64 addr
, int size
, bool is_pair
)
1847 TCGv_i64 tmp
= tcg_temp_new_i64();
1848 TCGMemOp memop
= s
->be_data
+ size
;
1850 g_assert(size
<= 3);
1851 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), memop
);
1854 TCGv_i64 addr2
= tcg_temp_new_i64();
1855 TCGv_i64 hitmp
= tcg_temp_new_i64();
1857 g_assert(size
>= 2);
1858 tcg_gen_addi_i64(addr2
, addr
, 1 << size
);
1859 tcg_gen_qemu_ld_i64(hitmp
, addr2
, get_mem_index(s
), memop
);
1860 tcg_temp_free_i64(addr2
);
1861 tcg_gen_mov_i64(cpu_exclusive_high
, hitmp
);
1862 tcg_gen_mov_i64(cpu_reg(s
, rt2
), hitmp
);
1863 tcg_temp_free_i64(hitmp
);
1866 tcg_gen_mov_i64(cpu_exclusive_val
, tmp
);
1867 tcg_gen_mov_i64(cpu_reg(s
, rt
), tmp
);
1869 tcg_temp_free_i64(tmp
);
1870 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
1873 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1874 TCGv_i64 inaddr
, int size
, int is_pair
)
1876 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1877 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1880 * [addr + datasize] = {Rt2};
1886 * env->exclusive_addr = -1;
1888 TCGLabel
*fail_label
= gen_new_label();
1889 TCGLabel
*done_label
= gen_new_label();
1890 TCGv_i64 addr
= tcg_temp_local_new_i64();
1893 /* Copy input into a local temp so it is not trashed when the
1894 * basic block ends at the branch insn.
1896 tcg_gen_mov_i64(addr
, inaddr
);
1897 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
1899 tmp
= tcg_temp_new_i64();
1902 TCGv_i64 val
= tcg_temp_new_i64();
1903 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
1904 tcg_gen_concat32_i64(val
, cpu_exclusive_val
, cpu_exclusive_high
);
1905 tcg_gen_atomic_cmpxchg_i64(tmp
, addr
, val
, tmp
,
1907 size
| MO_ALIGN
| s
->be_data
);
1908 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, val
);
1909 tcg_temp_free_i64(val
);
1910 } else if (s
->be_data
== MO_LE
) {
1911 gen_helper_paired_cmpxchg64_le(tmp
, cpu_env
, addr
, cpu_reg(s
, rt
),
1914 gen_helper_paired_cmpxchg64_be(tmp
, cpu_env
, addr
, cpu_reg(s
, rt
),
1918 TCGv_i64 val
= cpu_reg(s
, rt
);
1919 tcg_gen_atomic_cmpxchg_i64(tmp
, addr
, cpu_exclusive_val
, val
,
1921 size
| MO_ALIGN
| s
->be_data
);
1922 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
1925 tcg_temp_free_i64(addr
);
1927 tcg_gen_mov_i64(cpu_reg(s
, rd
), tmp
);
1928 tcg_temp_free_i64(tmp
);
1929 tcg_gen_br(done_label
);
1931 gen_set_label(fail_label
);
1932 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
1933 gen_set_label(done_label
);
1934 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1937 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
1938 * from the ARMv8 specs for LDR (Shared decode for all encodings).
1940 static bool disas_ldst_compute_iss_sf(int size
, bool is_signed
, int opc
)
1942 int opc0
= extract32(opc
, 0, 1);
1946 regsize
= opc0
? 32 : 64;
1948 regsize
= size
== 3 ? 64 : 32;
1950 return regsize
== 64;
1953 /* C3.3.6 Load/store exclusive
1955 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
1956 * +-----+-------------+----+---+----+------+----+-------+------+------+
1957 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
1958 * +-----+-------------+----+---+----+------+----+-------+------+------+
1960 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
1961 * L: 0 -> store, 1 -> load
1962 * o2: 0 -> exclusive, 1 -> not
1963 * o1: 0 -> single register, 1 -> register pair
1964 * o0: 1 -> load-acquire/store-release, 0 -> not
1966 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
1968 int rt
= extract32(insn
, 0, 5);
1969 int rn
= extract32(insn
, 5, 5);
1970 int rt2
= extract32(insn
, 10, 5);
1971 int is_lasr
= extract32(insn
, 15, 1);
1972 int rs
= extract32(insn
, 16, 5);
1973 int is_pair
= extract32(insn
, 21, 1);
1974 int is_store
= !extract32(insn
, 22, 1);
1975 int is_excl
= !extract32(insn
, 23, 1);
1976 int size
= extract32(insn
, 30, 2);
1979 if ((!is_excl
&& !is_pair
&& !is_lasr
) ||
1980 (!is_excl
&& is_pair
) ||
1981 (is_pair
&& size
< 2)) {
1982 unallocated_encoding(s
);
1987 gen_check_sp_alignment(s
);
1989 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1991 /* Note that since TCG is single threaded load-acquire/store-release
1992 * semantics require no extra if (is_lasr) { ... } handling.
1998 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, is_pair
);
2000 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2004 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2006 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, is_pair
);
2009 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2010 bool iss_sf
= disas_ldst_compute_iss_sf(size
, false, 0);
2012 /* Generate ISS for non-exclusive accesses including LASR. */
2015 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2017 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2018 true, rt
, iss_sf
, is_lasr
);
2020 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, false, false,
2021 true, rt
, iss_sf
, is_lasr
);
2023 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2030 * C3.3.5 Load register (literal)
2032 * 31 30 29 27 26 25 24 23 5 4 0
2033 * +-----+-------+---+-----+-------------------+-------+
2034 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2035 * +-----+-------+---+-----+-------------------+-------+
2037 * V: 1 -> vector (simd/fp)
2038 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2039 * 10-> 32 bit signed, 11 -> prefetch
2040 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2042 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
2044 int rt
= extract32(insn
, 0, 5);
2045 int64_t imm
= sextract32(insn
, 5, 19) << 2;
2046 bool is_vector
= extract32(insn
, 26, 1);
2047 int opc
= extract32(insn
, 30, 2);
2048 bool is_signed
= false;
2050 TCGv_i64 tcg_rt
, tcg_addr
;
2054 unallocated_encoding(s
);
2058 if (!fp_access_check(s
)) {
2063 /* PRFM (literal) : prefetch */
2066 size
= 2 + extract32(opc
, 0, 1);
2067 is_signed
= extract32(opc
, 1, 1);
2070 tcg_rt
= cpu_reg(s
, rt
);
2072 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
2074 do_fp_ld(s
, rt
, tcg_addr
, size
);
2076 /* Only unsigned 32bit loads target 32bit registers. */
2077 bool iss_sf
= opc
!= 0;
2079 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false,
2080 true, rt
, iss_sf
, false);
2082 tcg_temp_free_i64(tcg_addr
);
2086 * C5.6.80 LDNP (Load Pair - non-temporal hint)
2087 * C5.6.81 LDP (Load Pair - non vector)
2088 * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
2089 * C5.6.176 STNP (Store Pair - non-temporal hint)
2090 * C5.6.177 STP (Store Pair - non vector)
2091 * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
2092 * C6.3.165 LDP (Load Pair of SIMD&FP)
2093 * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
2094 * C6.3.284 STP (Store Pair of SIMD&FP)
2096 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2097 * +-----+-------+---+---+-------+---+-----------------------------+
2098 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2099 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2101 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2103 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2104 * V: 0 -> GPR, 1 -> Vector
2105 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2106 * 10 -> signed offset, 11 -> pre-index
2107 * L: 0 -> Store 1 -> Load
2109 * Rt, Rt2 = GPR or SIMD registers to be stored
2110 * Rn = general purpose register containing address
2111 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2113 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
2115 int rt
= extract32(insn
, 0, 5);
2116 int rn
= extract32(insn
, 5, 5);
2117 int rt2
= extract32(insn
, 10, 5);
2118 uint64_t offset
= sextract64(insn
, 15, 7);
2119 int index
= extract32(insn
, 23, 2);
2120 bool is_vector
= extract32(insn
, 26, 1);
2121 bool is_load
= extract32(insn
, 22, 1);
2122 int opc
= extract32(insn
, 30, 2);
2124 bool is_signed
= false;
2125 bool postindex
= false;
2128 TCGv_i64 tcg_addr
; /* calculated address */
2132 unallocated_encoding(s
);
2139 size
= 2 + extract32(opc
, 1, 1);
2140 is_signed
= extract32(opc
, 0, 1);
2141 if (!is_load
&& is_signed
) {
2142 unallocated_encoding(s
);
2148 case 1: /* post-index */
2153 /* signed offset with "non-temporal" hint. Since we don't emulate
2154 * caches we don't care about hints to the cache system about
2155 * data access patterns, and handle this identically to plain
2159 /* There is no non-temporal-hint version of LDPSW */
2160 unallocated_encoding(s
);
2165 case 2: /* signed offset, rn not updated */
2168 case 3: /* pre-index */
2174 if (is_vector
&& !fp_access_check(s
)) {
2181 gen_check_sp_alignment(s
);
2184 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2187 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2192 do_fp_ld(s
, rt
, tcg_addr
, size
);
2194 do_fp_st(s
, rt
, tcg_addr
, size
);
2197 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2199 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false,
2200 false, 0, false, false);
2202 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2203 false, 0, false, false);
2206 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2209 do_fp_ld(s
, rt2
, tcg_addr
, size
);
2211 do_fp_st(s
, rt2
, tcg_addr
, size
);
2214 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2216 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false,
2217 false, 0, false, false);
2219 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
,
2220 false, 0, false, false);
2226 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
2228 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2230 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
2235 * C3.3.8 Load/store (immediate post-indexed)
2236 * C3.3.9 Load/store (immediate pre-indexed)
2237 * C3.3.12 Load/store (unscaled immediate)
2239 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2240 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2241 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2242 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2244 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2246 * V = 0 -> non-vector
2247 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2248 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2250 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
2256 int rn
= extract32(insn
, 5, 5);
2257 int imm9
= sextract32(insn
, 12, 9);
2258 int idx
= extract32(insn
, 10, 2);
2259 bool is_signed
= false;
2260 bool is_store
= false;
2261 bool is_extended
= false;
2262 bool is_unpriv
= (idx
== 2);
2263 bool iss_valid
= !is_vector
;
2270 size
|= (opc
& 2) << 1;
2271 if (size
> 4 || is_unpriv
) {
2272 unallocated_encoding(s
);
2275 is_store
= ((opc
& 1) == 0);
2276 if (!fp_access_check(s
)) {
2280 if (size
== 3 && opc
== 2) {
2281 /* PRFM - prefetch */
2283 unallocated_encoding(s
);
2288 if (opc
== 3 && size
> 1) {
2289 unallocated_encoding(s
);
2292 is_store
= (opc
== 0);
2293 is_signed
= extract32(opc
, 1, 1);
2294 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2314 gen_check_sp_alignment(s
);
2316 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2319 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2324 do_fp_st(s
, rt
, tcg_addr
, size
);
2326 do_fp_ld(s
, rt
, tcg_addr
, size
);
2329 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2330 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2331 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2334 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
,
2335 iss_valid
, rt
, iss_sf
, false);
2337 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
2338 is_signed
, is_extended
, memidx
,
2339 iss_valid
, rt
, iss_sf
, false);
2344 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2346 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2348 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2353 * C3.3.10 Load/store (register offset)
2355 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2356 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2357 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2358 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2361 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2362 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2364 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2365 * opc<0>: 0 -> store, 1 -> load
2366 * V: 1 -> vector/simd
2367 * opt: extend encoding (see DecodeRegExtend)
2368 * S: if S=1 then scale (essentially index by sizeof(size))
2369 * Rt: register to transfer into/out of
2370 * Rn: address register or SP for base
2371 * Rm: offset register or ZR for offset
2373 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
2379 int rn
= extract32(insn
, 5, 5);
2380 int shift
= extract32(insn
, 12, 1);
2381 int rm
= extract32(insn
, 16, 5);
2382 int opt
= extract32(insn
, 13, 3);
2383 bool is_signed
= false;
2384 bool is_store
= false;
2385 bool is_extended
= false;
2390 if (extract32(opt
, 1, 1) == 0) {
2391 unallocated_encoding(s
);
2396 size
|= (opc
& 2) << 1;
2398 unallocated_encoding(s
);
2401 is_store
= !extract32(opc
, 0, 1);
2402 if (!fp_access_check(s
)) {
2406 if (size
== 3 && opc
== 2) {
2407 /* PRFM - prefetch */
2410 if (opc
== 3 && size
> 1) {
2411 unallocated_encoding(s
);
2414 is_store
= (opc
== 0);
2415 is_signed
= extract32(opc
, 1, 1);
2416 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2420 gen_check_sp_alignment(s
);
2422 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2424 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2425 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2427 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2431 do_fp_st(s
, rt
, tcg_addr
, size
);
2433 do_fp_ld(s
, rt
, tcg_addr
, size
);
2436 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2437 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2439 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2440 true, rt
, iss_sf
, false);
2442 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
,
2443 is_signed
, is_extended
,
2444 true, rt
, iss_sf
, false);
2450 * C3.3.13 Load/store (unsigned immediate)
2452 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2453 * +----+-------+---+-----+-----+------------+-------+------+
2454 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2455 * +----+-------+---+-----+-----+------------+-------+------+
2458 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2459 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2461 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2462 * opc<0>: 0 -> store, 1 -> load
2463 * Rn: base address register (inc SP)
2464 * Rt: target register
2466 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
2472 int rn
= extract32(insn
, 5, 5);
2473 unsigned int imm12
= extract32(insn
, 10, 12);
2474 unsigned int offset
;
2479 bool is_signed
= false;
2480 bool is_extended
= false;
2483 size
|= (opc
& 2) << 1;
2485 unallocated_encoding(s
);
2488 is_store
= !extract32(opc
, 0, 1);
2489 if (!fp_access_check(s
)) {
2493 if (size
== 3 && opc
== 2) {
2494 /* PRFM - prefetch */
2497 if (opc
== 3 && size
> 1) {
2498 unallocated_encoding(s
);
2501 is_store
= (opc
== 0);
2502 is_signed
= extract32(opc
, 1, 1);
2503 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2507 gen_check_sp_alignment(s
);
2509 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2510 offset
= imm12
<< size
;
2511 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2515 do_fp_st(s
, rt
, tcg_addr
, size
);
2517 do_fp_ld(s
, rt
, tcg_addr
, size
);
2520 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2521 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2523 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2524 true, rt
, iss_sf
, false);
2526 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
,
2527 true, rt
, iss_sf
, false);
2532 /* Load/store register (all forms) */
2533 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2535 int rt
= extract32(insn
, 0, 5);
2536 int opc
= extract32(insn
, 22, 2);
2537 bool is_vector
= extract32(insn
, 26, 1);
2538 int size
= extract32(insn
, 30, 2);
2540 switch (extract32(insn
, 24, 2)) {
2542 if (extract32(insn
, 21, 1) == 1 && extract32(insn
, 10, 2) == 2) {
2543 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
2545 /* Load/store register (unscaled immediate)
2546 * Load/store immediate pre/post-indexed
2547 * Load/store register unprivileged
2549 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
2553 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
2556 unallocated_encoding(s
);
2561 /* C3.3.1 AdvSIMD load/store multiple structures
2563 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2564 * +---+---+---------------+---+-------------+--------+------+------+------+
2565 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2566 * +---+---+---------------+---+-------------+--------+------+------+------+
2568 * C3.3.2 AdvSIMD load/store multiple structures (post-indexed)
2570 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2571 * +---+---+---------------+---+---+---------+--------+------+------+------+
2572 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2573 * +---+---+---------------+---+---+---------+--------+------+------+------+
2575 * Rt: first (or only) SIMD&FP register to be transferred
2576 * Rn: base address or SP
2577 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2579 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
2581 int rt
= extract32(insn
, 0, 5);
2582 int rn
= extract32(insn
, 5, 5);
2583 int size
= extract32(insn
, 10, 2);
2584 int opcode
= extract32(insn
, 12, 4);
2585 bool is_store
= !extract32(insn
, 22, 1);
2586 bool is_postidx
= extract32(insn
, 23, 1);
2587 bool is_q
= extract32(insn
, 30, 1);
2588 TCGv_i64 tcg_addr
, tcg_rn
;
2590 int ebytes
= 1 << size
;
2591 int elements
= (is_q
? 128 : 64) / (8 << size
);
2592 int rpt
; /* num iterations */
2593 int selem
; /* structure elements */
2596 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
2597 unallocated_encoding(s
);
2601 /* From the shared decode logic */
2632 unallocated_encoding(s
);
2636 if (size
== 3 && !is_q
&& selem
!= 1) {
2638 unallocated_encoding(s
);
2642 if (!fp_access_check(s
)) {
2647 gen_check_sp_alignment(s
);
2650 tcg_rn
= cpu_reg_sp(s
, rn
);
2651 tcg_addr
= tcg_temp_new_i64();
2652 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2654 for (r
= 0; r
< rpt
; r
++) {
2656 for (e
= 0; e
< elements
; e
++) {
2657 int tt
= (rt
+ r
) % 32;
2659 for (xs
= 0; xs
< selem
; xs
++) {
2661 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
2663 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
2665 /* For non-quad operations, setting a slice of the low
2666 * 64 bits of the register clears the high 64 bits (in
2667 * the ARM ARM pseudocode this is implicit in the fact
2668 * that 'rval' is a 64 bit wide variable). We optimize
2669 * by noticing that we only need to do this the first
2670 * time we touch a register.
2672 if (!is_q
&& e
== 0 && (r
== 0 || xs
== selem
- 1)) {
2673 clear_vec_high(s
, tt
);
2676 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2683 int rm
= extract32(insn
, 16, 5);
2685 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2687 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2690 tcg_temp_free_i64(tcg_addr
);
2693 /* C3.3.3 AdvSIMD load/store single structure
2695 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2696 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2697 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
2698 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2700 * C3.3.4 AdvSIMD load/store single structure (post-indexed)
2702 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2703 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2704 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
2705 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2707 * Rt: first (or only) SIMD&FP register to be transferred
2708 * Rn: base address or SP
2709 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2710 * index = encoded in Q:S:size dependent on size
2712 * lane_size = encoded in R, opc
2713 * transfer width = encoded in opc, S, size
2715 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
2717 int rt
= extract32(insn
, 0, 5);
2718 int rn
= extract32(insn
, 5, 5);
2719 int size
= extract32(insn
, 10, 2);
2720 int S
= extract32(insn
, 12, 1);
2721 int opc
= extract32(insn
, 13, 3);
2722 int R
= extract32(insn
, 21, 1);
2723 int is_load
= extract32(insn
, 22, 1);
2724 int is_postidx
= extract32(insn
, 23, 1);
2725 int is_q
= extract32(insn
, 30, 1);
2727 int scale
= extract32(opc
, 1, 2);
2728 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
2729 bool replicate
= false;
2730 int index
= is_q
<< 3 | S
<< 2 | size
;
2732 TCGv_i64 tcg_addr
, tcg_rn
;
2736 if (!is_load
|| S
) {
2737 unallocated_encoding(s
);
2746 if (extract32(size
, 0, 1)) {
2747 unallocated_encoding(s
);
2753 if (extract32(size
, 1, 1)) {
2754 unallocated_encoding(s
);
2757 if (!extract32(size
, 0, 1)) {
2761 unallocated_encoding(s
);
2769 g_assert_not_reached();
2772 if (!fp_access_check(s
)) {
2776 ebytes
= 1 << scale
;
2779 gen_check_sp_alignment(s
);
2782 tcg_rn
= cpu_reg_sp(s
, rn
);
2783 tcg_addr
= tcg_temp_new_i64();
2784 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2786 for (xs
= 0; xs
< selem
; xs
++) {
2788 /* Load and replicate to all elements */
2790 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
2792 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
2793 get_mem_index(s
), s
->be_data
+ scale
);
2796 mulconst
= 0x0101010101010101ULL
;
2799 mulconst
= 0x0001000100010001ULL
;
2802 mulconst
= 0x0000000100000001ULL
;
2808 g_assert_not_reached();
2811 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
2813 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
2815 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
2817 clear_vec_high(s
, rt
);
2819 tcg_temp_free_i64(tcg_tmp
);
2821 /* Load/store one element per register */
2823 do_vec_ld(s
, rt
, index
, tcg_addr
, scale
);
2825 do_vec_st(s
, rt
, index
, tcg_addr
, scale
);
2828 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2833 int rm
= extract32(insn
, 16, 5);
2835 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2837 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2840 tcg_temp_free_i64(tcg_addr
);
2843 /* C3.3 Loads and stores */
2844 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
2846 switch (extract32(insn
, 24, 6)) {
2847 case 0x08: /* Load/store exclusive */
2848 disas_ldst_excl(s
, insn
);
2850 case 0x18: case 0x1c: /* Load register (literal) */
2851 disas_ld_lit(s
, insn
);
2853 case 0x28: case 0x29:
2854 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
2855 disas_ldst_pair(s
, insn
);
2857 case 0x38: case 0x39:
2858 case 0x3c: case 0x3d: /* Load/store register (all forms) */
2859 disas_ldst_reg(s
, insn
);
2861 case 0x0c: /* AdvSIMD load/store multiple structures */
2862 disas_ldst_multiple_struct(s
, insn
);
2864 case 0x0d: /* AdvSIMD load/store single structure */
2865 disas_ldst_single_struct(s
, insn
);
2868 unallocated_encoding(s
);
2873 /* C3.4.6 PC-rel. addressing
2874 * 31 30 29 28 24 23 5 4 0
2875 * +----+-------+-----------+-------------------+------+
2876 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
2877 * +----+-------+-----------+-------------------+------+
2879 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
2881 unsigned int page
, rd
;
2885 page
= extract32(insn
, 31, 1);
2886 /* SignExtend(immhi:immlo) -> offset */
2887 offset
= sextract64(insn
, 5, 19);
2888 offset
= offset
<< 2 | extract32(insn
, 29, 2);
2889 rd
= extract32(insn
, 0, 5);
2893 /* ADRP (page based) */
2898 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
2902 * C3.4.1 Add/subtract (immediate)
2904 * 31 30 29 28 24 23 22 21 10 9 5 4 0
2905 * +--+--+--+-----------+-----+-------------+-----+-----+
2906 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
2907 * +--+--+--+-----------+-----+-------------+-----+-----+
2909 * sf: 0 -> 32bit, 1 -> 64bit
2910 * op: 0 -> add , 1 -> sub
2912 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
2914 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
2916 int rd
= extract32(insn
, 0, 5);
2917 int rn
= extract32(insn
, 5, 5);
2918 uint64_t imm
= extract32(insn
, 10, 12);
2919 int shift
= extract32(insn
, 22, 2);
2920 bool setflags
= extract32(insn
, 29, 1);
2921 bool sub_op
= extract32(insn
, 30, 1);
2922 bool is_64bit
= extract32(insn
, 31, 1);
2924 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2925 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
2926 TCGv_i64 tcg_result
;
2935 unallocated_encoding(s
);
2939 tcg_result
= tcg_temp_new_i64();
2942 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
2944 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
2947 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
2949 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2951 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2953 tcg_temp_free_i64(tcg_imm
);
2957 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
2959 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
2962 tcg_temp_free_i64(tcg_result
);
2965 /* The input should be a value in the bottom e bits (with higher
2966 * bits zero); returns that value replicated into every element
2967 * of size e in a 64 bit integer.
2969 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
2979 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
2980 static inline uint64_t bitmask64(unsigned int length
)
2982 assert(length
> 0 && length
<= 64);
2983 return ~0ULL >> (64 - length
);
2986 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
2987 * only require the wmask. Returns false if the imms/immr/immn are a reserved
2988 * value (ie should cause a guest UNDEF exception), and true if they are
2989 * valid, in which case the decoded bit pattern is written to result.
2991 static bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
2992 unsigned int imms
, unsigned int immr
)
2995 unsigned e
, levels
, s
, r
;
2998 assert(immn
< 2 && imms
< 64 && immr
< 64);
3000 /* The bit patterns we create here are 64 bit patterns which
3001 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
3002 * 64 bits each. Each element contains the same value: a run
3003 * of between 1 and e-1 non-zero bits, rotated within the
3004 * element by between 0 and e-1 bits.
3006 * The element size and run length are encoded into immn (1 bit)
3007 * and imms (6 bits) as follows:
3008 * 64 bit elements: immn = 1, imms = <length of run - 1>
3009 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
3010 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
3011 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
3012 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
3013 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
3014 * Notice that immn = 0, imms = 11111x is the only combination
3015 * not covered by one of the above options; this is reserved.
3016 * Further, <length of run - 1> all-ones is a reserved pattern.
3018 * In all cases the rotation is by immr % e (and immr is 6 bits).
3021 /* First determine the element size */
3022 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
3024 /* This is the immn == 0, imms == 0x11111x case */
3034 /* <length of run - 1> mustn't be all-ones. */
3038 /* Create the value of one element: s+1 set bits rotated
3039 * by r within the element (which is e bits wide)...
3041 mask
= bitmask64(s
+ 1);
3043 mask
= (mask
>> r
) | (mask
<< (e
- r
));
3044 mask
&= bitmask64(e
);
3046 /* ...then replicate the element over the whole 64 bit value */
3047 mask
= bitfield_replicate(mask
, e
);
3052 /* C3.4.4 Logical (immediate)
3053 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3054 * +----+-----+-------------+---+------+------+------+------+
3055 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
3056 * +----+-----+-------------+---+------+------+------+------+
3058 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
3060 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
3061 TCGv_i64 tcg_rd
, tcg_rn
;
3063 bool is_and
= false;
3065 sf
= extract32(insn
, 31, 1);
3066 opc
= extract32(insn
, 29, 2);
3067 is_n
= extract32(insn
, 22, 1);
3068 immr
= extract32(insn
, 16, 6);
3069 imms
= extract32(insn
, 10, 6);
3070 rn
= extract32(insn
, 5, 5);
3071 rd
= extract32(insn
, 0, 5);
3074 unallocated_encoding(s
);
3078 if (opc
== 0x3) { /* ANDS */
3079 tcg_rd
= cpu_reg(s
, rd
);
3081 tcg_rd
= cpu_reg_sp(s
, rd
);
3083 tcg_rn
= cpu_reg(s
, rn
);
3085 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
3086 /* some immediate field values are reserved */
3087 unallocated_encoding(s
);
3092 wmask
&= 0xffffffff;
3096 case 0x3: /* ANDS */
3098 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
3102 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
3105 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
3108 assert(FALSE
); /* must handle all above */
3112 if (!sf
&& !is_and
) {
3113 /* zero extend final result; we know we can skip this for AND
3114 * since the immediate had the high 32 bits clear.
3116 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3119 if (opc
== 3) { /* ANDS */
3120 gen_logic_CC(sf
, tcg_rd
);
3125 * C3.4.5 Move wide (immediate)
3127 * 31 30 29 28 23 22 21 20 5 4 0
3128 * +--+-----+-------------+-----+----------------+------+
3129 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
3130 * +--+-----+-------------+-----+----------------+------+
3132 * sf: 0 -> 32 bit, 1 -> 64 bit
3133 * opc: 00 -> N, 10 -> Z, 11 -> K
3134 * hw: shift/16 (0,16, and sf only 32, 48)
3136 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
3138 int rd
= extract32(insn
, 0, 5);
3139 uint64_t imm
= extract32(insn
, 5, 16);
3140 int sf
= extract32(insn
, 31, 1);
3141 int opc
= extract32(insn
, 29, 2);
3142 int pos
= extract32(insn
, 21, 2) << 4;
3143 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3146 if (!sf
&& (pos
>= 32)) {
3147 unallocated_encoding(s
);
3161 tcg_gen_movi_i64(tcg_rd
, imm
);
3164 tcg_imm
= tcg_const_i64(imm
);
3165 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
3166 tcg_temp_free_i64(tcg_imm
);
3168 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3172 unallocated_encoding(s
);
3178 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3179 * +----+-----+-------------+---+------+------+------+------+
3180 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3181 * +----+-----+-------------+---+------+------+------+------+
3183 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
3185 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
3186 TCGv_i64 tcg_rd
, tcg_tmp
;
3188 sf
= extract32(insn
, 31, 1);
3189 opc
= extract32(insn
, 29, 2);
3190 n
= extract32(insn
, 22, 1);
3191 ri
= extract32(insn
, 16, 6);
3192 si
= extract32(insn
, 10, 6);
3193 rn
= extract32(insn
, 5, 5);
3194 rd
= extract32(insn
, 0, 5);
3195 bitsize
= sf
? 64 : 32;
3197 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
3198 unallocated_encoding(s
);
3202 tcg_rd
= cpu_reg(s
, rd
);
3204 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3205 to be smaller than bitsize, we'll never reference data outside the
3206 low 32-bits anyway. */
3207 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
3209 /* Recognize simple(r) extractions. */
3211 /* Wd<s-r:0> = Wn<s:r> */
3212 len
= (si
- ri
) + 1;
3213 if (opc
== 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
3214 tcg_gen_sextract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3216 } else if (opc
== 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
3217 tcg_gen_extract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3220 /* opc == 1, BXFIL fall through to deposit */
3221 tcg_gen_extract_i64(tcg_tmp
, tcg_tmp
, ri
, len
);
3224 /* Handle the ri > si case with a deposit
3225 * Wd<32+s-r,32-r> = Wn<s:0>
3228 pos
= (bitsize
- ri
) & (bitsize
- 1);
3231 if (opc
== 0 && len
< ri
) {
3232 /* SBFM: sign extend the destination field from len to fill
3233 the balance of the word. Let the deposit below insert all
3234 of those sign bits. */
3235 tcg_gen_sextract_i64(tcg_tmp
, tcg_tmp
, 0, len
);
3239 if (opc
== 1) { /* BFM, BXFIL */
3240 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
3242 /* SBFM or UBFM: We start with zero, and we haven't modified
3243 any bits outside bitsize, therefore the zero-extension
3244 below is unneeded. */
3245 tcg_gen_deposit_z_i64(tcg_rd
, tcg_tmp
, pos
, len
);
3250 if (!sf
) { /* zero extend final result */
3251 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3256 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3257 * +----+------+-------------+---+----+------+--------+------+------+
3258 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3259 * +----+------+-------------+---+----+------+--------+------+------+
3261 static void disas_extract(DisasContext
*s
, uint32_t insn
)
3263 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
3265 sf
= extract32(insn
, 31, 1);
3266 n
= extract32(insn
, 22, 1);
3267 rm
= extract32(insn
, 16, 5);
3268 imm
= extract32(insn
, 10, 6);
3269 rn
= extract32(insn
, 5, 5);
3270 rd
= extract32(insn
, 0, 5);
3271 op21
= extract32(insn
, 29, 2);
3272 op0
= extract32(insn
, 21, 1);
3273 bitsize
= sf
? 64 : 32;
3275 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
3276 unallocated_encoding(s
);
3278 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
3280 tcg_rd
= cpu_reg(s
, rd
);
3282 if (unlikely(imm
== 0)) {
3283 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3284 * so an extract from bit 0 is a special case.
3287 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
3289 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
3291 } else if (rm
== rn
) { /* ROR */
3292 tcg_rm
= cpu_reg(s
, rm
);
3294 tcg_gen_rotri_i64(tcg_rd
, tcg_rm
, imm
);
3296 TCGv_i32 tmp
= tcg_temp_new_i32();
3297 tcg_gen_extrl_i64_i32(tmp
, tcg_rm
);
3298 tcg_gen_rotri_i32(tmp
, tmp
, imm
);
3299 tcg_gen_extu_i32_i64(tcg_rd
, tmp
);
3300 tcg_temp_free_i32(tmp
);
3303 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3304 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3305 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
3306 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
3307 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
3309 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3315 /* C3.4 Data processing - immediate */
3316 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
3318 switch (extract32(insn
, 23, 6)) {
3319 case 0x20: case 0x21: /* PC-rel. addressing */
3320 disas_pc_rel_adr(s
, insn
);
3322 case 0x22: case 0x23: /* Add/subtract (immediate) */
3323 disas_add_sub_imm(s
, insn
);
3325 case 0x24: /* Logical (immediate) */
3326 disas_logic_imm(s
, insn
);
3328 case 0x25: /* Move wide (immediate) */
3329 disas_movw_imm(s
, insn
);
3331 case 0x26: /* Bitfield */
3332 disas_bitfield(s
, insn
);
3334 case 0x27: /* Extract */
3335 disas_extract(s
, insn
);
3338 unallocated_encoding(s
);
3343 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3344 * Note that it is the caller's responsibility to ensure that the
3345 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3346 * mandated semantics for out of range shifts.
3348 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3349 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
3351 switch (shift_type
) {
3352 case A64_SHIFT_TYPE_LSL
:
3353 tcg_gen_shl_i64(dst
, src
, shift_amount
);
3355 case A64_SHIFT_TYPE_LSR
:
3356 tcg_gen_shr_i64(dst
, src
, shift_amount
);
3358 case A64_SHIFT_TYPE_ASR
:
3360 tcg_gen_ext32s_i64(dst
, src
);
3362 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
3364 case A64_SHIFT_TYPE_ROR
:
3366 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
3369 t0
= tcg_temp_new_i32();
3370 t1
= tcg_temp_new_i32();
3371 tcg_gen_extrl_i64_i32(t0
, src
);
3372 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
3373 tcg_gen_rotr_i32(t0
, t0
, t1
);
3374 tcg_gen_extu_i32_i64(dst
, t0
);
3375 tcg_temp_free_i32(t0
);
3376 tcg_temp_free_i32(t1
);
3380 assert(FALSE
); /* all shift types should be handled */
3384 if (!sf
) { /* zero extend final result */
3385 tcg_gen_ext32u_i64(dst
, dst
);
3389 /* Shift a TCGv src by immediate, put result in dst.
3390 * The shift amount must be in range (this should always be true as the
3391 * relevant instructions will UNDEF on bad shift immediates).
3393 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3394 enum a64_shift_type shift_type
, unsigned int shift_i
)
3396 assert(shift_i
< (sf
? 64 : 32));
3399 tcg_gen_mov_i64(dst
, src
);
3401 TCGv_i64 shift_const
;
3403 shift_const
= tcg_const_i64(shift_i
);
3404 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
3405 tcg_temp_free_i64(shift_const
);
3409 /* C3.5.10 Logical (shifted register)
3410 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3411 * +----+-----+-----------+-------+---+------+--------+------+------+
3412 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3413 * +----+-----+-----------+-------+---+------+--------+------+------+
3415 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
3417 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
3418 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
3420 sf
= extract32(insn
, 31, 1);
3421 opc
= extract32(insn
, 29, 2);
3422 shift_type
= extract32(insn
, 22, 2);
3423 invert
= extract32(insn
, 21, 1);
3424 rm
= extract32(insn
, 16, 5);
3425 shift_amount
= extract32(insn
, 10, 6);
3426 rn
= extract32(insn
, 5, 5);
3427 rd
= extract32(insn
, 0, 5);
3429 if (!sf
&& (shift_amount
& (1 << 5))) {
3430 unallocated_encoding(s
);
3434 tcg_rd
= cpu_reg(s
, rd
);
3436 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3437 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3438 * register-register MOV and MVN, so it is worth special casing.
3440 tcg_rm
= cpu_reg(s
, rm
);
3442 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3444 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3448 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3450 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3456 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3459 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3462 tcg_rn
= cpu_reg(s
, rn
);
3464 switch (opc
| (invert
<< 2)) {
3467 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3470 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3473 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3477 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3480 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3483 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3491 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3495 gen_logic_CC(sf
, tcg_rd
);
3500 * C3.5.1 Add/subtract (extended register)
3502 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3503 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3504 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3505 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3507 * sf: 0 -> 32bit, 1 -> 64bit
3508 * op: 0 -> add , 1 -> sub
3511 * option: extension type (see DecodeRegExtend)
3512 * imm3: optional shift to Rm
3514 * Rd = Rn + LSL(extend(Rm), amount)
3516 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3518 int rd
= extract32(insn
, 0, 5);
3519 int rn
= extract32(insn
, 5, 5);
3520 int imm3
= extract32(insn
, 10, 3);
3521 int option
= extract32(insn
, 13, 3);
3522 int rm
= extract32(insn
, 16, 5);
3523 bool setflags
= extract32(insn
, 29, 1);
3524 bool sub_op
= extract32(insn
, 30, 1);
3525 bool sf
= extract32(insn
, 31, 1);
3527 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3529 TCGv_i64 tcg_result
;
3532 unallocated_encoding(s
);
3536 /* non-flag setting ops may use SP */
3538 tcg_rd
= cpu_reg_sp(s
, rd
);
3540 tcg_rd
= cpu_reg(s
, rd
);
3542 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3544 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3545 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3547 tcg_result
= tcg_temp_new_i64();
3551 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3553 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3557 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3559 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3564 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3566 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3569 tcg_temp_free_i64(tcg_result
);
3573 * C3.5.2 Add/subtract (shifted register)
3575 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3576 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3577 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3578 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3580 * sf: 0 -> 32bit, 1 -> 64bit
3581 * op: 0 -> add , 1 -> sub
3583 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3584 * imm6: Shift amount to apply to Rm before the add/sub
3586 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
3588 int rd
= extract32(insn
, 0, 5);
3589 int rn
= extract32(insn
, 5, 5);
3590 int imm6
= extract32(insn
, 10, 6);
3591 int rm
= extract32(insn
, 16, 5);
3592 int shift_type
= extract32(insn
, 22, 2);
3593 bool setflags
= extract32(insn
, 29, 1);
3594 bool sub_op
= extract32(insn
, 30, 1);
3595 bool sf
= extract32(insn
, 31, 1);
3597 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3598 TCGv_i64 tcg_rn
, tcg_rm
;
3599 TCGv_i64 tcg_result
;
3601 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
3602 unallocated_encoding(s
);
3606 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3607 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3609 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
3611 tcg_result
= tcg_temp_new_i64();
3615 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3617 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3621 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3623 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3628 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3630 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3633 tcg_temp_free_i64(tcg_result
);
3636 /* C3.5.9 Data-processing (3 source)
3638 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3639 +--+------+-----------+------+------+----+------+------+------+
3640 |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3641 +--+------+-----------+------+------+----+------+------+------+
3644 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
3646 int rd
= extract32(insn
, 0, 5);
3647 int rn
= extract32(insn
, 5, 5);
3648 int ra
= extract32(insn
, 10, 5);
3649 int rm
= extract32(insn
, 16, 5);
3650 int op_id
= (extract32(insn
, 29, 3) << 4) |
3651 (extract32(insn
, 21, 3) << 1) |
3652 extract32(insn
, 15, 1);
3653 bool sf
= extract32(insn
, 31, 1);
3654 bool is_sub
= extract32(op_id
, 0, 1);
3655 bool is_high
= extract32(op_id
, 2, 1);
3656 bool is_signed
= false;
3661 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
3663 case 0x42: /* SMADDL */
3664 case 0x43: /* SMSUBL */
3665 case 0x44: /* SMULH */
3668 case 0x0: /* MADD (32bit) */
3669 case 0x1: /* MSUB (32bit) */
3670 case 0x40: /* MADD (64bit) */
3671 case 0x41: /* MSUB (64bit) */
3672 case 0x4a: /* UMADDL */
3673 case 0x4b: /* UMSUBL */
3674 case 0x4c: /* UMULH */
3677 unallocated_encoding(s
);
3682 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
3683 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3684 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
3685 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
3688 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3690 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3693 tcg_temp_free_i64(low_bits
);
3697 tcg_op1
= tcg_temp_new_i64();
3698 tcg_op2
= tcg_temp_new_i64();
3699 tcg_tmp
= tcg_temp_new_i64();
3702 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
3703 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
3706 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
3707 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
3709 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
3710 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
3714 if (ra
== 31 && !is_sub
) {
3715 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
3716 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
3718 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
3720 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3722 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3727 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
3730 tcg_temp_free_i64(tcg_op1
);
3731 tcg_temp_free_i64(tcg_op2
);
3732 tcg_temp_free_i64(tcg_tmp
);
3735 /* C3.5.3 - Add/subtract (with carry)
3736 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
3737 * +--+--+--+------------------------+------+---------+------+-----+
3738 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
3739 * +--+--+--+------------------------+------+---------+------+-----+
3743 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
3745 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
3746 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
3748 if (extract32(insn
, 10, 6) != 0) {
3749 unallocated_encoding(s
);
3753 sf
= extract32(insn
, 31, 1);
3754 op
= extract32(insn
, 30, 1);
3755 setflags
= extract32(insn
, 29, 1);
3756 rm
= extract32(insn
, 16, 5);
3757 rn
= extract32(insn
, 5, 5);
3758 rd
= extract32(insn
, 0, 5);
3760 tcg_rd
= cpu_reg(s
, rd
);
3761 tcg_rn
= cpu_reg(s
, rn
);
3764 tcg_y
= new_tmp_a64(s
);
3765 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
3767 tcg_y
= cpu_reg(s
, rm
);
3771 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3773 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3777 /* C3.5.4 - C3.5.5 Conditional compare (immediate / register)
3778 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3779 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3780 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
3781 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3784 static void disas_cc(DisasContext
*s
, uint32_t insn
)
3786 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
3787 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
3788 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
3791 if (!extract32(insn
, 29, 1)) {
3792 unallocated_encoding(s
);
3795 if (insn
& (1 << 10 | 1 << 4)) {
3796 unallocated_encoding(s
);
3799 sf
= extract32(insn
, 31, 1);
3800 op
= extract32(insn
, 30, 1);
3801 is_imm
= extract32(insn
, 11, 1);
3802 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
3803 cond
= extract32(insn
, 12, 4);
3804 rn
= extract32(insn
, 5, 5);
3805 nzcv
= extract32(insn
, 0, 4);
3807 /* Set T0 = !COND. */
3808 tcg_t0
= tcg_temp_new_i32();
3809 arm_test_cc(&c
, cond
);
3810 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
3813 /* Load the arguments for the new comparison. */
3815 tcg_y
= new_tmp_a64(s
);
3816 tcg_gen_movi_i64(tcg_y
, y
);
3818 tcg_y
= cpu_reg(s
, y
);
3820 tcg_rn
= cpu_reg(s
, rn
);
3822 /* Set the flags for the new comparison. */
3823 tcg_tmp
= tcg_temp_new_i64();
3825 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3827 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3829 tcg_temp_free_i64(tcg_tmp
);
3831 /* If COND was false, force the flags to #nzcv. Compute two masks
3832 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
3833 * For tcg hosts that support ANDC, we can make do with just T1.
3834 * In either case, allow the tcg optimizer to delete any unused mask.
3836 tcg_t1
= tcg_temp_new_i32();
3837 tcg_t2
= tcg_temp_new_i32();
3838 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
3839 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
3841 if (nzcv
& 8) { /* N */
3842 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
3844 if (TCG_TARGET_HAS_andc_i32
) {
3845 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
3847 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
3850 if (nzcv
& 4) { /* Z */
3851 if (TCG_TARGET_HAS_andc_i32
) {
3852 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
3854 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
3857 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
3859 if (nzcv
& 2) { /* C */
3860 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
3862 if (TCG_TARGET_HAS_andc_i32
) {
3863 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
3865 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
3868 if (nzcv
& 1) { /* V */
3869 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
3871 if (TCG_TARGET_HAS_andc_i32
) {
3872 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
3874 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
3877 tcg_temp_free_i32(tcg_t0
);
3878 tcg_temp_free_i32(tcg_t1
);
3879 tcg_temp_free_i32(tcg_t2
);
3882 /* C3.5.6 Conditional select
3883 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
3884 * +----+----+---+-----------------+------+------+-----+------+------+
3885 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
3886 * +----+----+---+-----------------+------+------+-----+------+------+
3888 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
3890 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
3891 TCGv_i64 tcg_rd
, zero
;
3894 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
3895 /* S == 1 or op2<1> == 1 */
3896 unallocated_encoding(s
);
3899 sf
= extract32(insn
, 31, 1);
3900 else_inv
= extract32(insn
, 30, 1);
3901 rm
= extract32(insn
, 16, 5);
3902 cond
= extract32(insn
, 12, 4);
3903 else_inc
= extract32(insn
, 10, 1);
3904 rn
= extract32(insn
, 5, 5);
3905 rd
= extract32(insn
, 0, 5);
3907 tcg_rd
= cpu_reg(s
, rd
);
3909 a64_test_cc(&c
, cond
);
3910 zero
= tcg_const_i64(0);
3912 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
3914 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
3916 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
3919 TCGv_i64 t_true
= cpu_reg(s
, rn
);
3920 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
3921 if (else_inv
&& else_inc
) {
3922 tcg_gen_neg_i64(t_false
, t_false
);
3923 } else if (else_inv
) {
3924 tcg_gen_not_i64(t_false
, t_false
);
3925 } else if (else_inc
) {
3926 tcg_gen_addi_i64(t_false
, t_false
, 1);
3928 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
3931 tcg_temp_free_i64(zero
);
3935 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3939 static void handle_clz(DisasContext
*s
, unsigned int sf
,
3940 unsigned int rn
, unsigned int rd
)
3942 TCGv_i64 tcg_rd
, tcg_rn
;
3943 tcg_rd
= cpu_reg(s
, rd
);
3944 tcg_rn
= cpu_reg(s
, rn
);
3947 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
3949 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3950 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3951 tcg_gen_clzi_i32(tcg_tmp32
, tcg_tmp32
, 32);
3952 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3953 tcg_temp_free_i32(tcg_tmp32
);
3957 static void handle_cls(DisasContext
*s
, unsigned int sf
,
3958 unsigned int rn
, unsigned int rd
)
3960 TCGv_i64 tcg_rd
, tcg_rn
;
3961 tcg_rd
= cpu_reg(s
, rd
);
3962 tcg_rn
= cpu_reg(s
, rn
);
3965 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
3967 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3968 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3969 tcg_gen_clrsb_i32(tcg_tmp32
, tcg_tmp32
);
3970 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3971 tcg_temp_free_i32(tcg_tmp32
);
3975 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
3976 unsigned int rn
, unsigned int rd
)
3978 TCGv_i64 tcg_rd
, tcg_rn
;
3979 tcg_rd
= cpu_reg(s
, rd
);
3980 tcg_rn
= cpu_reg(s
, rn
);
3983 gen_helper_rbit64(tcg_rd
, tcg_rn
);
3985 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3986 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3987 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
3988 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3989 tcg_temp_free_i32(tcg_tmp32
);
3993 /* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
3994 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
3995 unsigned int rn
, unsigned int rd
)
3998 unallocated_encoding(s
);
4001 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
4004 /* C5.6.149 REV with sf==0, opcode==2
4005 * C5.6.151 REV32 (sf==1, opcode==2)
4007 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
4008 unsigned int rn
, unsigned int rd
)
4010 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4013 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4014 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4016 /* bswap32_i64 requires zero high word */
4017 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
4018 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
4019 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
4020 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
4021 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4023 tcg_temp_free_i64(tcg_tmp
);
4025 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
4026 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
4030 /* C5.6.150 REV16 (opcode==1) */
4031 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
4032 unsigned int rn
, unsigned int rd
)
4034 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4035 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4036 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4038 tcg_gen_andi_i64(tcg_tmp
, tcg_rn
, 0xffff);
4039 tcg_gen_bswap16_i64(tcg_rd
, tcg_tmp
);
4041 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 16);
4042 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
4043 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
4044 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 16, 16);
4047 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
4048 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
4049 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
4050 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 32, 16);
4052 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 48);
4053 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
4054 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 48, 16);
4057 tcg_temp_free_i64(tcg_tmp
);
4060 /* C3.5.7 Data-processing (1 source)
4061 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4062 * +----+---+---+-----------------+---------+--------+------+------+
4063 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
4064 * +----+---+---+-----------------+---------+--------+------+------+
4066 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
4068 unsigned int sf
, opcode
, rn
, rd
;
4070 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
4071 unallocated_encoding(s
);
4075 sf
= extract32(insn
, 31, 1);
4076 opcode
= extract32(insn
, 10, 6);
4077 rn
= extract32(insn
, 5, 5);
4078 rd
= extract32(insn
, 0, 5);
4082 handle_rbit(s
, sf
, rn
, rd
);
4085 handle_rev16(s
, sf
, rn
, rd
);
4088 handle_rev32(s
, sf
, rn
, rd
);
4091 handle_rev64(s
, sf
, rn
, rd
);
4094 handle_clz(s
, sf
, rn
, rd
);
4097 handle_cls(s
, sf
, rn
, rd
);
4102 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
4103 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4105 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
4106 tcg_rd
= cpu_reg(s
, rd
);
4108 if (!sf
&& is_signed
) {
4109 tcg_n
= new_tmp_a64(s
);
4110 tcg_m
= new_tmp_a64(s
);
4111 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
4112 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
4114 tcg_n
= read_cpu_reg(s
, rn
, sf
);
4115 tcg_m
= read_cpu_reg(s
, rm
, sf
);
4119 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
4121 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
4124 if (!sf
) { /* zero extend final result */
4125 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4129 /* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
4130 static void handle_shift_reg(DisasContext
*s
,
4131 enum a64_shift_type shift_type
, unsigned int sf
,
4132 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4134 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
4135 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4136 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4138 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
4139 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
4140 tcg_temp_free_i64(tcg_shift
);
4143 /* CRC32[BHWX], CRC32C[BHWX] */
4144 static void handle_crc32(DisasContext
*s
,
4145 unsigned int sf
, unsigned int sz
, bool crc32c
,
4146 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4148 TCGv_i64 tcg_acc
, tcg_val
;
4151 if (!arm_dc_feature(s
, ARM_FEATURE_CRC
)
4152 || (sf
== 1 && sz
!= 3)
4153 || (sf
== 0 && sz
== 3)) {
4154 unallocated_encoding(s
);
4159 tcg_val
= cpu_reg(s
, rm
);
4173 g_assert_not_reached();
4175 tcg_val
= new_tmp_a64(s
);
4176 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
4179 tcg_acc
= cpu_reg(s
, rn
);
4180 tcg_bytes
= tcg_const_i32(1 << sz
);
4183 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4185 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4188 tcg_temp_free_i32(tcg_bytes
);
4191 /* C3.5.8 Data-processing (2 source)
4192 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4193 * +----+---+---+-----------------+------+--------+------+------+
4194 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
4195 * +----+---+---+-----------------+------+--------+------+------+
4197 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
4199 unsigned int sf
, rm
, opcode
, rn
, rd
;
4200 sf
= extract32(insn
, 31, 1);
4201 rm
= extract32(insn
, 16, 5);
4202 opcode
= extract32(insn
, 10, 6);
4203 rn
= extract32(insn
, 5, 5);
4204 rd
= extract32(insn
, 0, 5);
4206 if (extract32(insn
, 29, 1)) {
4207 unallocated_encoding(s
);
4213 handle_div(s
, false, sf
, rm
, rn
, rd
);
4216 handle_div(s
, true, sf
, rm
, rn
, rd
);
4219 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
4222 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
4225 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
4228 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
4237 case 23: /* CRC32 */
4239 int sz
= extract32(opcode
, 0, 2);
4240 bool crc32c
= extract32(opcode
, 2, 1);
4241 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
4245 unallocated_encoding(s
);
4250 /* C3.5 Data processing - register */
4251 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
4253 switch (extract32(insn
, 24, 5)) {
4254 case 0x0a: /* Logical (shifted register) */
4255 disas_logic_reg(s
, insn
);
4257 case 0x0b: /* Add/subtract */
4258 if (insn
& (1 << 21)) { /* (extended register) */
4259 disas_add_sub_ext_reg(s
, insn
);
4261 disas_add_sub_reg(s
, insn
);
4264 case 0x1b: /* Data-processing (3 source) */
4265 disas_data_proc_3src(s
, insn
);
4268 switch (extract32(insn
, 21, 3)) {
4269 case 0x0: /* Add/subtract (with carry) */
4270 disas_adc_sbc(s
, insn
);
4272 case 0x2: /* Conditional compare */
4273 disas_cc(s
, insn
); /* both imm and reg forms */
4275 case 0x4: /* Conditional select */
4276 disas_cond_select(s
, insn
);
4278 case 0x6: /* Data-processing */
4279 if (insn
& (1 << 30)) { /* (1 source) */
4280 disas_data_proc_1src(s
, insn
);
4281 } else { /* (2 source) */
4282 disas_data_proc_2src(s
, insn
);
4286 unallocated_encoding(s
);
4291 unallocated_encoding(s
);
4296 static void handle_fp_compare(DisasContext
*s
, bool is_double
,
4297 unsigned int rn
, unsigned int rm
,
4298 bool cmp_with_zero
, bool signal_all_nans
)
4300 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
4301 TCGv_ptr fpst
= get_fpstatus_ptr();
4304 TCGv_i64 tcg_vn
, tcg_vm
;
4306 tcg_vn
= read_fp_dreg(s
, rn
);
4307 if (cmp_with_zero
) {
4308 tcg_vm
= tcg_const_i64(0);
4310 tcg_vm
= read_fp_dreg(s
, rm
);
4312 if (signal_all_nans
) {
4313 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4315 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4317 tcg_temp_free_i64(tcg_vn
);
4318 tcg_temp_free_i64(tcg_vm
);
4320 TCGv_i32 tcg_vn
, tcg_vm
;
4322 tcg_vn
= read_fp_sreg(s
, rn
);
4323 if (cmp_with_zero
) {
4324 tcg_vm
= tcg_const_i32(0);
4326 tcg_vm
= read_fp_sreg(s
, rm
);
4328 if (signal_all_nans
) {
4329 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4331 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4333 tcg_temp_free_i32(tcg_vn
);
4334 tcg_temp_free_i32(tcg_vm
);
4337 tcg_temp_free_ptr(fpst
);
4339 gen_set_nzcv(tcg_flags
);
4341 tcg_temp_free_i64(tcg_flags
);
4344 /* C3.6.22 Floating point compare
4345 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
4346 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4347 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
4348 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4350 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
4352 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
4354 mos
= extract32(insn
, 29, 3);
4355 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4356 rm
= extract32(insn
, 16, 5);
4357 op
= extract32(insn
, 14, 2);
4358 rn
= extract32(insn
, 5, 5);
4359 opc
= extract32(insn
, 3, 2);
4360 op2r
= extract32(insn
, 0, 3);
4362 if (mos
|| op
|| op2r
|| type
> 1) {
4363 unallocated_encoding(s
);
4367 if (!fp_access_check(s
)) {
4371 handle_fp_compare(s
, type
, rn
, rm
, opc
& 1, opc
& 2);
4374 /* C3.6.23 Floating point conditional compare
4375 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4376 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4377 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
4378 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4380 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
4382 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
4384 TCGLabel
*label_continue
= NULL
;
4386 mos
= extract32(insn
, 29, 3);
4387 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4388 rm
= extract32(insn
, 16, 5);
4389 cond
= extract32(insn
, 12, 4);
4390 rn
= extract32(insn
, 5, 5);
4391 op
= extract32(insn
, 4, 1);
4392 nzcv
= extract32(insn
, 0, 4);
4394 if (mos
|| type
> 1) {
4395 unallocated_encoding(s
);
4399 if (!fp_access_check(s
)) {
4403 if (cond
< 0x0e) { /* not always */
4404 TCGLabel
*label_match
= gen_new_label();
4405 label_continue
= gen_new_label();
4406 arm_gen_test_cc(cond
, label_match
);
4408 tcg_flags
= tcg_const_i64(nzcv
<< 28);
4409 gen_set_nzcv(tcg_flags
);
4410 tcg_temp_free_i64(tcg_flags
);
4411 tcg_gen_br(label_continue
);
4412 gen_set_label(label_match
);
4415 handle_fp_compare(s
, type
, rn
, rm
, false, op
);
4418 gen_set_label(label_continue
);
4422 /* C3.6.24 Floating point conditional select
4423 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4424 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4425 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
4426 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4428 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
4430 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
4431 TCGv_i64 t_true
, t_false
, t_zero
;
4434 mos
= extract32(insn
, 29, 3);
4435 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4436 rm
= extract32(insn
, 16, 5);
4437 cond
= extract32(insn
, 12, 4);
4438 rn
= extract32(insn
, 5, 5);
4439 rd
= extract32(insn
, 0, 5);
4441 if (mos
|| type
> 1) {
4442 unallocated_encoding(s
);
4446 if (!fp_access_check(s
)) {
4450 /* Zero extend sreg inputs to 64 bits now. */
4451 t_true
= tcg_temp_new_i64();
4452 t_false
= tcg_temp_new_i64();
4453 read_vec_element(s
, t_true
, rn
, 0, type
? MO_64
: MO_32
);
4454 read_vec_element(s
, t_false
, rm
, 0, type
? MO_64
: MO_32
);
4456 a64_test_cc(&c
, cond
);
4457 t_zero
= tcg_const_i64(0);
4458 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, t_zero
, t_true
, t_false
);
4459 tcg_temp_free_i64(t_zero
);
4460 tcg_temp_free_i64(t_false
);
4463 /* Note that sregs write back zeros to the high bits,
4464 and we've already done the zero-extension. */
4465 write_fp_dreg(s
, rd
, t_true
);
4466 tcg_temp_free_i64(t_true
);
4469 /* C3.6.25 Floating-point data-processing (1 source) - single precision */
4470 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
4476 fpst
= get_fpstatus_ptr();
4477 tcg_op
= read_fp_sreg(s
, rn
);
4478 tcg_res
= tcg_temp_new_i32();
4481 case 0x0: /* FMOV */
4482 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4484 case 0x1: /* FABS */
4485 gen_helper_vfp_abss(tcg_res
, tcg_op
);
4487 case 0x2: /* FNEG */
4488 gen_helper_vfp_negs(tcg_res
, tcg_op
);
4490 case 0x3: /* FSQRT */
4491 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
4493 case 0x8: /* FRINTN */
4494 case 0x9: /* FRINTP */
4495 case 0xa: /* FRINTM */
4496 case 0xb: /* FRINTZ */
4497 case 0xc: /* FRINTA */
4499 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4501 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4502 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4504 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4505 tcg_temp_free_i32(tcg_rmode
);
4508 case 0xe: /* FRINTX */
4509 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
4511 case 0xf: /* FRINTI */
4512 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4518 write_fp_sreg(s
, rd
, tcg_res
);
4520 tcg_temp_free_ptr(fpst
);
4521 tcg_temp_free_i32(tcg_op
);
4522 tcg_temp_free_i32(tcg_res
);
4525 /* C3.6.25 Floating-point data-processing (1 source) - double precision */
4526 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
4532 fpst
= get_fpstatus_ptr();
4533 tcg_op
= read_fp_dreg(s
, rn
);
4534 tcg_res
= tcg_temp_new_i64();
4537 case 0x0: /* FMOV */
4538 tcg_gen_mov_i64(tcg_res
, tcg_op
);
4540 case 0x1: /* FABS */
4541 gen_helper_vfp_absd(tcg_res
, tcg_op
);
4543 case 0x2: /* FNEG */
4544 gen_helper_vfp_negd(tcg_res
, tcg_op
);
4546 case 0x3: /* FSQRT */
4547 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
4549 case 0x8: /* FRINTN */
4550 case 0x9: /* FRINTP */
4551 case 0xa: /* FRINTM */
4552 case 0xb: /* FRINTZ */
4553 case 0xc: /* FRINTA */
4555 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4557 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4558 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4560 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4561 tcg_temp_free_i32(tcg_rmode
);
4564 case 0xe: /* FRINTX */
4565 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
4567 case 0xf: /* FRINTI */
4568 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4574 write_fp_dreg(s
, rd
, tcg_res
);
4576 tcg_temp_free_ptr(fpst
);
4577 tcg_temp_free_i64(tcg_op
);
4578 tcg_temp_free_i64(tcg_res
);
4581 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
4582 int rd
, int rn
, int dtype
, int ntype
)
4587 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4589 /* Single to double */
4590 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4591 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
4592 write_fp_dreg(s
, rd
, tcg_rd
);
4593 tcg_temp_free_i64(tcg_rd
);
4595 /* Single to half */
4596 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4597 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4598 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4599 write_fp_sreg(s
, rd
, tcg_rd
);
4600 tcg_temp_free_i32(tcg_rd
);
4602 tcg_temp_free_i32(tcg_rn
);
4607 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
4608 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4610 /* Double to single */
4611 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
4613 /* Double to half */
4614 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4615 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4617 write_fp_sreg(s
, rd
, tcg_rd
);
4618 tcg_temp_free_i32(tcg_rd
);
4619 tcg_temp_free_i64(tcg_rn
);
4624 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4625 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
4627 /* Half to single */
4628 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4629 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, cpu_env
);
4630 write_fp_sreg(s
, rd
, tcg_rd
);
4631 tcg_temp_free_i32(tcg_rd
);
4633 /* Half to double */
4634 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4635 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, cpu_env
);
4636 write_fp_dreg(s
, rd
, tcg_rd
);
4637 tcg_temp_free_i64(tcg_rd
);
4639 tcg_temp_free_i32(tcg_rn
);
4647 /* C3.6.25 Floating point data-processing (1 source)
4648 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
4649 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4650 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
4651 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4653 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
4655 int type
= extract32(insn
, 22, 2);
4656 int opcode
= extract32(insn
, 15, 6);
4657 int rn
= extract32(insn
, 5, 5);
4658 int rd
= extract32(insn
, 0, 5);
4661 case 0x4: case 0x5: case 0x7:
4663 /* FCVT between half, single and double precision */
4664 int dtype
= extract32(opcode
, 0, 2);
4665 if (type
== 2 || dtype
== type
) {
4666 unallocated_encoding(s
);
4669 if (!fp_access_check(s
)) {
4673 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
4679 /* 32-to-32 and 64-to-64 ops */
4682 if (!fp_access_check(s
)) {
4686 handle_fp_1src_single(s
, opcode
, rd
, rn
);
4689 if (!fp_access_check(s
)) {
4693 handle_fp_1src_double(s
, opcode
, rd
, rn
);
4696 unallocated_encoding(s
);
4700 unallocated_encoding(s
);
4705 /* C3.6.26 Floating-point data-processing (2 source) - single precision */
4706 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
4707 int rd
, int rn
, int rm
)
4714 tcg_res
= tcg_temp_new_i32();
4715 fpst
= get_fpstatus_ptr();
4716 tcg_op1
= read_fp_sreg(s
, rn
);
4717 tcg_op2
= read_fp_sreg(s
, rm
);
4720 case 0x0: /* FMUL */
4721 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4723 case 0x1: /* FDIV */
4724 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4726 case 0x2: /* FADD */
4727 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4729 case 0x3: /* FSUB */
4730 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4732 case 0x4: /* FMAX */
4733 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4735 case 0x5: /* FMIN */
4736 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4738 case 0x6: /* FMAXNM */
4739 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4741 case 0x7: /* FMINNM */
4742 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4744 case 0x8: /* FNMUL */
4745 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4746 gen_helper_vfp_negs(tcg_res
, tcg_res
);
4750 write_fp_sreg(s
, rd
, tcg_res
);
4752 tcg_temp_free_ptr(fpst
);
4753 tcg_temp_free_i32(tcg_op1
);
4754 tcg_temp_free_i32(tcg_op2
);
4755 tcg_temp_free_i32(tcg_res
);
4758 /* C3.6.26 Floating-point data-processing (2 source) - double precision */
4759 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
4760 int rd
, int rn
, int rm
)
4767 tcg_res
= tcg_temp_new_i64();
4768 fpst
= get_fpstatus_ptr();
4769 tcg_op1
= read_fp_dreg(s
, rn
);
4770 tcg_op2
= read_fp_dreg(s
, rm
);
4773 case 0x0: /* FMUL */
4774 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4776 case 0x1: /* FDIV */
4777 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4779 case 0x2: /* FADD */
4780 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4782 case 0x3: /* FSUB */
4783 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4785 case 0x4: /* FMAX */
4786 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4788 case 0x5: /* FMIN */
4789 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4791 case 0x6: /* FMAXNM */
4792 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4794 case 0x7: /* FMINNM */
4795 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4797 case 0x8: /* FNMUL */
4798 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4799 gen_helper_vfp_negd(tcg_res
, tcg_res
);
4803 write_fp_dreg(s
, rd
, tcg_res
);
4805 tcg_temp_free_ptr(fpst
);
4806 tcg_temp_free_i64(tcg_op1
);
4807 tcg_temp_free_i64(tcg_op2
);
4808 tcg_temp_free_i64(tcg_res
);
4811 /* C3.6.26 Floating point data-processing (2 source)
4812 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4813 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4814 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
4815 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4817 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
4819 int type
= extract32(insn
, 22, 2);
4820 int rd
= extract32(insn
, 0, 5);
4821 int rn
= extract32(insn
, 5, 5);
4822 int rm
= extract32(insn
, 16, 5);
4823 int opcode
= extract32(insn
, 12, 4);
4826 unallocated_encoding(s
);
4832 if (!fp_access_check(s
)) {
4835 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
4838 if (!fp_access_check(s
)) {
4841 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
4844 unallocated_encoding(s
);
4848 /* C3.6.27 Floating-point data-processing (3 source) - single precision */
4849 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
4850 int rd
, int rn
, int rm
, int ra
)
4852 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
4853 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4854 TCGv_ptr fpst
= get_fpstatus_ptr();
4856 tcg_op1
= read_fp_sreg(s
, rn
);
4857 tcg_op2
= read_fp_sreg(s
, rm
);
4858 tcg_op3
= read_fp_sreg(s
, ra
);
4860 /* These are fused multiply-add, and must be done as one
4861 * floating point operation with no rounding between the
4862 * multiplication and addition steps.
4863 * NB that doing the negations here as separate steps is
4864 * correct : an input NaN should come out with its sign bit
4865 * flipped if it is a negated-input.
4868 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
4872 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
4875 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4877 write_fp_sreg(s
, rd
, tcg_res
);
4879 tcg_temp_free_ptr(fpst
);
4880 tcg_temp_free_i32(tcg_op1
);
4881 tcg_temp_free_i32(tcg_op2
);
4882 tcg_temp_free_i32(tcg_op3
);
4883 tcg_temp_free_i32(tcg_res
);
4886 /* C3.6.27 Floating-point data-processing (3 source) - double precision */
4887 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
4888 int rd
, int rn
, int rm
, int ra
)
4890 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
4891 TCGv_i64 tcg_res
= tcg_temp_new_i64();
4892 TCGv_ptr fpst
= get_fpstatus_ptr();
4894 tcg_op1
= read_fp_dreg(s
, rn
);
4895 tcg_op2
= read_fp_dreg(s
, rm
);
4896 tcg_op3
= read_fp_dreg(s
, ra
);
4898 /* These are fused multiply-add, and must be done as one
4899 * floating point operation with no rounding between the
4900 * multiplication and addition steps.
4901 * NB that doing the negations here as separate steps is
4902 * correct : an input NaN should come out with its sign bit
4903 * flipped if it is a negated-input.
4906 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
4910 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
4913 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4915 write_fp_dreg(s
, rd
, tcg_res
);
4917 tcg_temp_free_ptr(fpst
);
4918 tcg_temp_free_i64(tcg_op1
);
4919 tcg_temp_free_i64(tcg_op2
);
4920 tcg_temp_free_i64(tcg_op3
);
4921 tcg_temp_free_i64(tcg_res
);
4924 /* C3.6.27 Floating point data-processing (3 source)
4925 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
4926 * +---+---+---+-----------+------+----+------+----+------+------+------+
4927 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
4928 * +---+---+---+-----------+------+----+------+----+------+------+------+
4930 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
4932 int type
= extract32(insn
, 22, 2);
4933 int rd
= extract32(insn
, 0, 5);
4934 int rn
= extract32(insn
, 5, 5);
4935 int ra
= extract32(insn
, 10, 5);
4936 int rm
= extract32(insn
, 16, 5);
4937 bool o0
= extract32(insn
, 15, 1);
4938 bool o1
= extract32(insn
, 21, 1);
4942 if (!fp_access_check(s
)) {
4945 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4948 if (!fp_access_check(s
)) {
4951 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4954 unallocated_encoding(s
);
4958 /* C3.6.28 Floating point immediate
4959 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
4960 * +---+---+---+-----------+------+---+------------+-------+------+------+
4961 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
4962 * +---+---+---+-----------+------+---+------------+-------+------+------+
4964 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
4966 int rd
= extract32(insn
, 0, 5);
4967 int imm8
= extract32(insn
, 13, 8);
4968 int is_double
= extract32(insn
, 22, 2);
4972 if (is_double
> 1) {
4973 unallocated_encoding(s
);
4977 if (!fp_access_check(s
)) {
4981 /* The imm8 encodes the sign bit, enough bits to represent
4982 * an exponent in the range 01....1xx to 10....0xx,
4983 * and the most significant 4 bits of the mantissa; see
4984 * VFPExpandImm() in the v8 ARM ARM.
4987 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4988 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
4989 extract32(imm8
, 0, 6);
4992 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4993 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
4994 (extract32(imm8
, 0, 6) << 3);
4998 tcg_res
= tcg_const_i64(imm
);
4999 write_fp_dreg(s
, rd
, tcg_res
);
5000 tcg_temp_free_i64(tcg_res
);
5003 /* Handle floating point <=> fixed point conversions. Note that we can
5004 * also deal with fp <=> integer conversions as a special case (scale == 64)
5005 * OPTME: consider handling that special case specially or at least skipping
5006 * the call to scalbn in the helpers for zero shifts.
5008 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
5009 bool itof
, int rmode
, int scale
, int sf
, int type
)
5011 bool is_signed
= !(opcode
& 1);
5012 bool is_double
= type
;
5013 TCGv_ptr tcg_fpstatus
;
5016 tcg_fpstatus
= get_fpstatus_ptr();
5018 tcg_shift
= tcg_const_i32(64 - scale
);
5021 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
5023 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
5026 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
5028 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
5031 tcg_int
= tcg_extend
;
5035 TCGv_i64 tcg_double
= tcg_temp_new_i64();
5037 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
5038 tcg_shift
, tcg_fpstatus
);
5040 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
5041 tcg_shift
, tcg_fpstatus
);
5043 write_fp_dreg(s
, rd
, tcg_double
);
5044 tcg_temp_free_i64(tcg_double
);
5046 TCGv_i32 tcg_single
= tcg_temp_new_i32();
5048 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
5049 tcg_shift
, tcg_fpstatus
);
5051 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
5052 tcg_shift
, tcg_fpstatus
);
5054 write_fp_sreg(s
, rd
, tcg_single
);
5055 tcg_temp_free_i32(tcg_single
);
5058 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
5061 if (extract32(opcode
, 2, 1)) {
5062 /* There are too many rounding modes to all fit into rmode,
5063 * so FCVTA[US] is a special case.
5065 rmode
= FPROUNDING_TIEAWAY
;
5068 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
5070 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
5073 TCGv_i64 tcg_double
= read_fp_dreg(s
, rn
);
5076 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
5077 tcg_shift
, tcg_fpstatus
);
5079 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
5080 tcg_shift
, tcg_fpstatus
);
5084 gen_helper_vfp_tould(tcg_int
, tcg_double
,
5085 tcg_shift
, tcg_fpstatus
);
5087 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
5088 tcg_shift
, tcg_fpstatus
);
5091 tcg_temp_free_i64(tcg_double
);
5093 TCGv_i32 tcg_single
= read_fp_sreg(s
, rn
);
5096 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
5097 tcg_shift
, tcg_fpstatus
);
5099 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
5100 tcg_shift
, tcg_fpstatus
);
5103 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
5105 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
5106 tcg_shift
, tcg_fpstatus
);
5108 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
5109 tcg_shift
, tcg_fpstatus
);
5111 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
5112 tcg_temp_free_i32(tcg_dest
);
5114 tcg_temp_free_i32(tcg_single
);
5117 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
5118 tcg_temp_free_i32(tcg_rmode
);
5121 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
5125 tcg_temp_free_ptr(tcg_fpstatus
);
5126 tcg_temp_free_i32(tcg_shift
);
5129 /* C3.6.29 Floating point <-> fixed point conversions
5130 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
5131 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
5132 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
5133 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
5135 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
5137 int rd
= extract32(insn
, 0, 5);
5138 int rn
= extract32(insn
, 5, 5);
5139 int scale
= extract32(insn
, 10, 6);
5140 int opcode
= extract32(insn
, 16, 3);
5141 int rmode
= extract32(insn
, 19, 2);
5142 int type
= extract32(insn
, 22, 2);
5143 bool sbit
= extract32(insn
, 29, 1);
5144 bool sf
= extract32(insn
, 31, 1);
5147 if (sbit
|| (type
> 1)
5148 || (!sf
&& scale
< 32)) {
5149 unallocated_encoding(s
);
5153 switch ((rmode
<< 3) | opcode
) {
5154 case 0x2: /* SCVTF */
5155 case 0x3: /* UCVTF */
5158 case 0x18: /* FCVTZS */
5159 case 0x19: /* FCVTZU */
5163 unallocated_encoding(s
);
5167 if (!fp_access_check(s
)) {
5171 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
5174 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
5176 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
5177 * without conversion.
5181 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
5187 TCGv_i64 tmp
= tcg_temp_new_i64();
5188 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
5189 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
5190 tcg_gen_movi_i64(tmp
, 0);
5191 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5192 tcg_temp_free_i64(tmp
);
5198 TCGv_i64 tmp
= tcg_const_i64(0);
5199 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
5200 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5201 tcg_temp_free_i64(tmp
);
5205 /* 64 bit to top half. */
5206 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5210 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5215 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
5219 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
5222 /* 64 bits from top half */
5223 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
5229 /* C3.6.30 Floating point <-> integer conversions
5230 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
5231 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5232 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
5233 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5235 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
5237 int rd
= extract32(insn
, 0, 5);
5238 int rn
= extract32(insn
, 5, 5);
5239 int opcode
= extract32(insn
, 16, 3);
5240 int rmode
= extract32(insn
, 19, 2);
5241 int type
= extract32(insn
, 22, 2);
5242 bool sbit
= extract32(insn
, 29, 1);
5243 bool sf
= extract32(insn
, 31, 1);
5246 unallocated_encoding(s
);
5252 bool itof
= opcode
& 1;
5255 unallocated_encoding(s
);
5259 switch (sf
<< 3 | type
<< 1 | rmode
) {
5260 case 0x0: /* 32 bit */
5261 case 0xa: /* 64 bit */
5262 case 0xd: /* 64 bit to top half of quad */
5265 /* all other sf/type/rmode combinations are invalid */
5266 unallocated_encoding(s
);
5270 if (!fp_access_check(s
)) {
5273 handle_fmov(s
, rd
, rn
, type
, itof
);
5275 /* actual FP conversions */
5276 bool itof
= extract32(opcode
, 1, 1);
5278 if (type
> 1 || (rmode
!= 0 && opcode
> 1)) {
5279 unallocated_encoding(s
);
5283 if (!fp_access_check(s
)) {
5286 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
5290 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
5291 * 31 30 29 28 25 24 0
5292 * +---+---+---+---------+-----------------------------+
5293 * | | 0 | | 1 1 1 1 | |
5294 * +---+---+---+---------+-----------------------------+
5296 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
5298 if (extract32(insn
, 24, 1)) {
5299 /* Floating point data-processing (3 source) */
5300 disas_fp_3src(s
, insn
);
5301 } else if (extract32(insn
, 21, 1) == 0) {
5302 /* Floating point to fixed point conversions */
5303 disas_fp_fixed_conv(s
, insn
);
5305 switch (extract32(insn
, 10, 2)) {
5307 /* Floating point conditional compare */
5308 disas_fp_ccomp(s
, insn
);
5311 /* Floating point data-processing (2 source) */
5312 disas_fp_2src(s
, insn
);
5315 /* Floating point conditional select */
5316 disas_fp_csel(s
, insn
);
5319 switch (ctz32(extract32(insn
, 12, 4))) {
5320 case 0: /* [15:12] == xxx1 */
5321 /* Floating point immediate */
5322 disas_fp_imm(s
, insn
);
5324 case 1: /* [15:12] == xx10 */
5325 /* Floating point compare */
5326 disas_fp_compare(s
, insn
);
5328 case 2: /* [15:12] == x100 */
5329 /* Floating point data-processing (1 source) */
5330 disas_fp_1src(s
, insn
);
5332 case 3: /* [15:12] == 1000 */
5333 unallocated_encoding(s
);
5335 default: /* [15:12] == 0000 */
5336 /* Floating point <-> integer conversions */
5337 disas_fp_int_conv(s
, insn
);
5345 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
5348 /* Extract 64 bits from the middle of two concatenated 64 bit
5349 * vector register slices left:right. The extracted bits start
5350 * at 'pos' bits into the right (least significant) side.
5351 * We return the result in tcg_right, and guarantee not to
5354 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5355 assert(pos
> 0 && pos
< 64);
5357 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
5358 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
5359 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
5361 tcg_temp_free_i64(tcg_tmp
);
5365 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
5366 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5367 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
5368 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5370 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
5372 int is_q
= extract32(insn
, 30, 1);
5373 int op2
= extract32(insn
, 22, 2);
5374 int imm4
= extract32(insn
, 11, 4);
5375 int rm
= extract32(insn
, 16, 5);
5376 int rn
= extract32(insn
, 5, 5);
5377 int rd
= extract32(insn
, 0, 5);
5378 int pos
= imm4
<< 3;
5379 TCGv_i64 tcg_resl
, tcg_resh
;
5381 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
5382 unallocated_encoding(s
);
5386 if (!fp_access_check(s
)) {
5390 tcg_resh
= tcg_temp_new_i64();
5391 tcg_resl
= tcg_temp_new_i64();
5393 /* Vd gets bits starting at pos bits into Vm:Vn. This is
5394 * either extracting 128 bits from a 128:128 concatenation, or
5395 * extracting 64 bits from a 64:64 concatenation.
5398 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
5400 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
5401 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5403 tcg_gen_movi_i64(tcg_resh
, 0);
5410 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
5411 EltPosns
*elt
= eltposns
;
5418 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
5420 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
5423 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5424 tcg_hh
= tcg_temp_new_i64();
5425 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
5426 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
5427 tcg_temp_free_i64(tcg_hh
);
5431 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5432 tcg_temp_free_i64(tcg_resl
);
5433 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5434 tcg_temp_free_i64(tcg_resh
);
5438 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
5439 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5440 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
5441 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5443 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
5445 int op2
= extract32(insn
, 22, 2);
5446 int is_q
= extract32(insn
, 30, 1);
5447 int rm
= extract32(insn
, 16, 5);
5448 int rn
= extract32(insn
, 5, 5);
5449 int rd
= extract32(insn
, 0, 5);
5450 int is_tblx
= extract32(insn
, 12, 1);
5451 int len
= extract32(insn
, 13, 2);
5452 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
5453 TCGv_i32 tcg_regno
, tcg_numregs
;
5456 unallocated_encoding(s
);
5460 if (!fp_access_check(s
)) {
5464 /* This does a table lookup: for every byte element in the input
5465 * we index into a table formed from up to four vector registers,
5466 * and then the output is the result of the lookups. Our helper
5467 * function does the lookup operation for a single 64 bit part of
5470 tcg_resl
= tcg_temp_new_i64();
5471 tcg_resh
= tcg_temp_new_i64();
5474 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5476 tcg_gen_movi_i64(tcg_resl
, 0);
5478 if (is_tblx
&& is_q
) {
5479 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5481 tcg_gen_movi_i64(tcg_resh
, 0);
5484 tcg_idx
= tcg_temp_new_i64();
5485 tcg_regno
= tcg_const_i32(rn
);
5486 tcg_numregs
= tcg_const_i32(len
+ 1);
5487 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
5488 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
5489 tcg_regno
, tcg_numregs
);
5491 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
5492 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
5493 tcg_regno
, tcg_numregs
);
5495 tcg_temp_free_i64(tcg_idx
);
5496 tcg_temp_free_i32(tcg_regno
);
5497 tcg_temp_free_i32(tcg_numregs
);
5499 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5500 tcg_temp_free_i64(tcg_resl
);
5501 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5502 tcg_temp_free_i64(tcg_resh
);
5505 /* C3.6.3 ZIP/UZP/TRN
5506 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
5507 * +---+---+-------------+------+---+------+---+------------------+------+
5508 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
5509 * +---+---+-------------+------+---+------+---+------------------+------+
5511 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
5513 int rd
= extract32(insn
, 0, 5);
5514 int rn
= extract32(insn
, 5, 5);
5515 int rm
= extract32(insn
, 16, 5);
5516 int size
= extract32(insn
, 22, 2);
5517 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
5518 * bit 2 indicates 1 vs 2 variant of the insn.
5520 int opcode
= extract32(insn
, 12, 2);
5521 bool part
= extract32(insn
, 14, 1);
5522 bool is_q
= extract32(insn
, 30, 1);
5523 int esize
= 8 << size
;
5525 int datasize
= is_q
? 128 : 64;
5526 int elements
= datasize
/ esize
;
5527 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
5529 if (opcode
== 0 || (size
== 3 && !is_q
)) {
5530 unallocated_encoding(s
);
5534 if (!fp_access_check(s
)) {
5538 tcg_resl
= tcg_const_i64(0);
5539 tcg_resh
= tcg_const_i64(0);
5540 tcg_res
= tcg_temp_new_i64();
5542 for (i
= 0; i
< elements
; i
++) {
5544 case 1: /* UZP1/2 */
5546 int midpoint
= elements
/ 2;
5548 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
5550 read_vec_element(s
, tcg_res
, rm
,
5551 2 * (i
- midpoint
) + part
, size
);
5555 case 2: /* TRN1/2 */
5557 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
5559 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
5562 case 3: /* ZIP1/2 */
5564 int base
= part
* elements
/ 2;
5566 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
5568 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
5573 g_assert_not_reached();
5578 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
5579 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
5581 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
5582 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
5586 tcg_temp_free_i64(tcg_res
);
5588 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5589 tcg_temp_free_i64(tcg_resl
);
5590 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5591 tcg_temp_free_i64(tcg_resh
);
5594 static void do_minmaxop(DisasContext
*s
, TCGv_i32 tcg_elt1
, TCGv_i32 tcg_elt2
,
5595 int opc
, bool is_min
, TCGv_ptr fpst
)
5597 /* Helper function for disas_simd_across_lanes: do a single precision
5598 * min/max operation on the specified two inputs,
5599 * and return the result in tcg_elt1.
5603 gen_helper_vfp_minnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5605 gen_helper_vfp_maxnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5610 gen_helper_vfp_mins(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5612 gen_helper_vfp_maxs(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5617 /* C3.6.4 AdvSIMD across lanes
5618 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5619 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5620 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5621 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5623 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
5625 int rd
= extract32(insn
, 0, 5);
5626 int rn
= extract32(insn
, 5, 5);
5627 int size
= extract32(insn
, 22, 2);
5628 int opcode
= extract32(insn
, 12, 5);
5629 bool is_q
= extract32(insn
, 30, 1);
5630 bool is_u
= extract32(insn
, 29, 1);
5632 bool is_min
= false;
5636 TCGv_i64 tcg_res
, tcg_elt
;
5639 case 0x1b: /* ADDV */
5641 unallocated_encoding(s
);
5645 case 0x3: /* SADDLV, UADDLV */
5646 case 0xa: /* SMAXV, UMAXV */
5647 case 0x1a: /* SMINV, UMINV */
5648 if (size
== 3 || (size
== 2 && !is_q
)) {
5649 unallocated_encoding(s
);
5653 case 0xc: /* FMAXNMV, FMINNMV */
5654 case 0xf: /* FMAXV, FMINV */
5655 if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
5656 unallocated_encoding(s
);
5659 /* Bit 1 of size field encodes min vs max, and actual size is always
5660 * 32 bits: adjust the size variable so following code can rely on it
5662 is_min
= extract32(size
, 1, 1);
5667 unallocated_encoding(s
);
5671 if (!fp_access_check(s
)) {
5676 elements
= (is_q
? 128 : 64) / esize
;
5678 tcg_res
= tcg_temp_new_i64();
5679 tcg_elt
= tcg_temp_new_i64();
5681 /* These instructions operate across all lanes of a vector
5682 * to produce a single result. We can guarantee that a 64
5683 * bit intermediate is sufficient:
5684 * + for [US]ADDLV the maximum element size is 32 bits, and
5685 * the result type is 64 bits
5686 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
5687 * same as the element size, which is 32 bits at most
5688 * For the integer operations we can choose to work at 64
5689 * or 32 bits and truncate at the end; for simplicity
5690 * we use 64 bits always. The floating point
5691 * ops do require 32 bit intermediates, though.
5694 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
5696 for (i
= 1; i
< elements
; i
++) {
5697 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
5700 case 0x03: /* SADDLV / UADDLV */
5701 case 0x1b: /* ADDV */
5702 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
5704 case 0x0a: /* SMAXV / UMAXV */
5705 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
5707 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5709 case 0x1a: /* SMINV / UMINV */
5710 tcg_gen_movcond_i64(is_u
? TCG_COND_LEU
: TCG_COND_LE
,
5712 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5716 g_assert_not_reached();
5721 /* Floating point ops which work on 32 bit (single) intermediates.
5722 * Note that correct NaN propagation requires that we do these
5723 * operations in exactly the order specified by the pseudocode.
5725 TCGv_i32 tcg_elt1
= tcg_temp_new_i32();
5726 TCGv_i32 tcg_elt2
= tcg_temp_new_i32();
5727 TCGv_i32 tcg_elt3
= tcg_temp_new_i32();
5728 TCGv_ptr fpst
= get_fpstatus_ptr();
5730 assert(esize
== 32);
5731 assert(elements
== 4);
5733 read_vec_element(s
, tcg_elt
, rn
, 0, MO_32
);
5734 tcg_gen_extrl_i64_i32(tcg_elt1
, tcg_elt
);
5735 read_vec_element(s
, tcg_elt
, rn
, 1, MO_32
);
5736 tcg_gen_extrl_i64_i32(tcg_elt2
, tcg_elt
);
5738 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5740 read_vec_element(s
, tcg_elt
, rn
, 2, MO_32
);
5741 tcg_gen_extrl_i64_i32(tcg_elt2
, tcg_elt
);
5742 read_vec_element(s
, tcg_elt
, rn
, 3, MO_32
);
5743 tcg_gen_extrl_i64_i32(tcg_elt3
, tcg_elt
);
5745 do_minmaxop(s
, tcg_elt2
, tcg_elt3
, opcode
, is_min
, fpst
);
5747 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5749 tcg_gen_extu_i32_i64(tcg_res
, tcg_elt1
);
5750 tcg_temp_free_i32(tcg_elt1
);
5751 tcg_temp_free_i32(tcg_elt2
);
5752 tcg_temp_free_i32(tcg_elt3
);
5753 tcg_temp_free_ptr(fpst
);
5756 tcg_temp_free_i64(tcg_elt
);
5758 /* Now truncate the result to the width required for the final output */
5759 if (opcode
== 0x03) {
5760 /* SADDLV, UADDLV: result is 2*esize */
5766 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
5769 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
5772 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
5777 g_assert_not_reached();
5780 write_fp_dreg(s
, rd
, tcg_res
);
5781 tcg_temp_free_i64(tcg_res
);
5784 /* C6.3.31 DUP (Element, Vector)
5786 * 31 30 29 21 20 16 15 10 9 5 4 0
5787 * +---+---+-------------------+--------+-------------+------+------+
5788 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5789 * +---+---+-------------------+--------+-------------+------+------+
5791 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5793 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
5796 int size
= ctz32(imm5
);
5797 int esize
= 8 << size
;
5798 int elements
= (is_q
? 128 : 64) / esize
;
5802 if (size
> 3 || (size
== 3 && !is_q
)) {
5803 unallocated_encoding(s
);
5807 if (!fp_access_check(s
)) {
5811 index
= imm5
>> (size
+ 1);
5813 tmp
= tcg_temp_new_i64();
5814 read_vec_element(s
, tmp
, rn
, index
, size
);
5816 for (i
= 0; i
< elements
; i
++) {
5817 write_vec_element(s
, tmp
, rd
, i
, size
);
5821 clear_vec_high(s
, rd
);
5824 tcg_temp_free_i64(tmp
);
5827 /* C6.3.31 DUP (element, scalar)
5828 * 31 21 20 16 15 10 9 5 4 0
5829 * +-----------------------+--------+-------------+------+------+
5830 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5831 * +-----------------------+--------+-------------+------+------+
5833 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
5836 int size
= ctz32(imm5
);
5841 unallocated_encoding(s
);
5845 if (!fp_access_check(s
)) {
5849 index
= imm5
>> (size
+ 1);
5851 /* This instruction just extracts the specified element and
5852 * zero-extends it into the bottom of the destination register.
5854 tmp
= tcg_temp_new_i64();
5855 read_vec_element(s
, tmp
, rn
, index
, size
);
5856 write_fp_dreg(s
, rd
, tmp
);
5857 tcg_temp_free_i64(tmp
);
5860 /* C6.3.32 DUP (General)
5862 * 31 30 29 21 20 16 15 10 9 5 4 0
5863 * +---+---+-------------------+--------+-------------+------+------+
5864 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
5865 * +---+---+-------------------+--------+-------------+------+------+
5867 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5869 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
5872 int size
= ctz32(imm5
);
5873 int esize
= 8 << size
;
5874 int elements
= (is_q
? 128 : 64)/esize
;
5877 if (size
> 3 || ((size
== 3) && !is_q
)) {
5878 unallocated_encoding(s
);
5882 if (!fp_access_check(s
)) {
5886 for (i
= 0; i
< elements
; i
++) {
5887 write_vec_element(s
, cpu_reg(s
, rn
), rd
, i
, size
);
5890 clear_vec_high(s
, rd
);
5894 /* C6.3.150 INS (Element)
5896 * 31 21 20 16 15 14 11 10 9 5 4 0
5897 * +-----------------------+--------+------------+---+------+------+
5898 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5899 * +-----------------------+--------+------------+---+------+------+
5901 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5902 * index: encoded in imm5<4:size+1>
5904 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
5907 int size
= ctz32(imm5
);
5908 int src_index
, dst_index
;
5912 unallocated_encoding(s
);
5916 if (!fp_access_check(s
)) {
5920 dst_index
= extract32(imm5
, 1+size
, 5);
5921 src_index
= extract32(imm4
, size
, 4);
5923 tmp
= tcg_temp_new_i64();
5925 read_vec_element(s
, tmp
, rn
, src_index
, size
);
5926 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
5928 tcg_temp_free_i64(tmp
);
5932 /* C6.3.151 INS (General)
5934 * 31 21 20 16 15 10 9 5 4 0
5935 * +-----------------------+--------+-------------+------+------+
5936 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
5937 * +-----------------------+--------+-------------+------+------+
5939 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5940 * index: encoded in imm5<4:size+1>
5942 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
5944 int size
= ctz32(imm5
);
5948 unallocated_encoding(s
);
5952 if (!fp_access_check(s
)) {
5956 idx
= extract32(imm5
, 1 + size
, 4 - size
);
5957 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
5961 * C6.3.321 UMOV (General)
5962 * C6.3.237 SMOV (General)
5964 * 31 30 29 21 20 16 15 12 10 9 5 4 0
5965 * +---+---+-------------------+--------+-------------+------+------+
5966 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
5967 * +---+---+-------------------+--------+-------------+------+------+
5969 * U: unsigned when set
5970 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5972 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
5973 int rn
, int rd
, int imm5
)
5975 int size
= ctz32(imm5
);
5979 /* Check for UnallocatedEncodings */
5981 if (size
> 2 || (size
== 2 && !is_q
)) {
5982 unallocated_encoding(s
);
5987 || (size
< 3 && is_q
)
5988 || (size
== 3 && !is_q
)) {
5989 unallocated_encoding(s
);
5994 if (!fp_access_check(s
)) {
5998 element
= extract32(imm5
, 1+size
, 4);
6000 tcg_rd
= cpu_reg(s
, rd
);
6001 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
6002 if (is_signed
&& !is_q
) {
6003 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
6007 /* C3.6.5 AdvSIMD copy
6008 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
6009 * +---+---+----+-----------------+------+---+------+---+------+------+
6010 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6011 * +---+---+----+-----------------+------+---+------+---+------+------+
6013 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
6015 int rd
= extract32(insn
, 0, 5);
6016 int rn
= extract32(insn
, 5, 5);
6017 int imm4
= extract32(insn
, 11, 4);
6018 int op
= extract32(insn
, 29, 1);
6019 int is_q
= extract32(insn
, 30, 1);
6020 int imm5
= extract32(insn
, 16, 5);
6025 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
6027 unallocated_encoding(s
);
6032 /* DUP (element - vector) */
6033 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
6037 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
6042 handle_simd_insg(s
, rd
, rn
, imm5
);
6044 unallocated_encoding(s
);
6049 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
6050 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
6053 unallocated_encoding(s
);
6059 /* C3.6.6 AdvSIMD modified immediate
6060 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
6061 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
6062 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
6063 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
6065 * There are a number of operations that can be carried out here:
6066 * MOVI - move (shifted) imm into register
6067 * MVNI - move inverted (shifted) imm into register
6068 * ORR - bitwise OR of (shifted) imm with register
6069 * BIC - bitwise clear of (shifted) imm with register
6071 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
6073 int rd
= extract32(insn
, 0, 5);
6074 int cmode
= extract32(insn
, 12, 4);
6075 int cmode_3_1
= extract32(cmode
, 1, 3);
6076 int cmode_0
= extract32(cmode
, 0, 1);
6077 int o2
= extract32(insn
, 11, 1);
6078 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
6079 bool is_neg
= extract32(insn
, 29, 1);
6080 bool is_q
= extract32(insn
, 30, 1);
6082 TCGv_i64 tcg_rd
, tcg_imm
;
6085 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
6086 unallocated_encoding(s
);
6090 if (!fp_access_check(s
)) {
6094 /* See AdvSIMDExpandImm() in ARM ARM */
6095 switch (cmode_3_1
) {
6096 case 0: /* Replicate(Zeros(24):imm8, 2) */
6097 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
6098 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
6099 case 3: /* Replicate(imm8:Zeros(24), 2) */
6101 int shift
= cmode_3_1
* 8;
6102 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
6105 case 4: /* Replicate(Zeros(8):imm8, 4) */
6106 case 5: /* Replicate(imm8:Zeros(8), 4) */
6108 int shift
= (cmode_3_1
& 0x1) * 8;
6109 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
6114 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
6115 imm
= (abcdefgh
<< 16) | 0xffff;
6117 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
6118 imm
= (abcdefgh
<< 8) | 0xff;
6120 imm
= bitfield_replicate(imm
, 32);
6123 if (!cmode_0
&& !is_neg
) {
6124 imm
= bitfield_replicate(abcdefgh
, 8);
6125 } else if (!cmode_0
&& is_neg
) {
6128 for (i
= 0; i
< 8; i
++) {
6129 if ((abcdefgh
) & (1 << i
)) {
6130 imm
|= 0xffULL
<< (i
* 8);
6133 } else if (cmode_0
) {
6135 imm
= (abcdefgh
& 0x3f) << 48;
6136 if (abcdefgh
& 0x80) {
6137 imm
|= 0x8000000000000000ULL
;
6139 if (abcdefgh
& 0x40) {
6140 imm
|= 0x3fc0000000000000ULL
;
6142 imm
|= 0x4000000000000000ULL
;
6145 imm
= (abcdefgh
& 0x3f) << 19;
6146 if (abcdefgh
& 0x80) {
6149 if (abcdefgh
& 0x40) {
6160 if (cmode_3_1
!= 7 && is_neg
) {
6164 tcg_imm
= tcg_const_i64(imm
);
6165 tcg_rd
= new_tmp_a64(s
);
6167 for (i
= 0; i
< 2; i
++) {
6168 int foffs
= i
? fp_reg_hi_offset(s
, rd
) : fp_reg_offset(s
, rd
, MO_64
);
6170 if (i
== 1 && !is_q
) {
6171 /* non-quad ops clear high half of vector */
6172 tcg_gen_movi_i64(tcg_rd
, 0);
6173 } else if ((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9) {
6174 tcg_gen_ld_i64(tcg_rd
, cpu_env
, foffs
);
6177 tcg_gen_and_i64(tcg_rd
, tcg_rd
, tcg_imm
);
6180 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_imm
);
6184 tcg_gen_mov_i64(tcg_rd
, tcg_imm
);
6186 tcg_gen_st_i64(tcg_rd
, cpu_env
, foffs
);
6189 tcg_temp_free_i64(tcg_imm
);
6192 /* C3.6.7 AdvSIMD scalar copy
6193 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
6194 * +-----+----+-----------------+------+---+------+---+------+------+
6195 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6196 * +-----+----+-----------------+------+---+------+---+------+------+
6198 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
6200 int rd
= extract32(insn
, 0, 5);
6201 int rn
= extract32(insn
, 5, 5);
6202 int imm4
= extract32(insn
, 11, 4);
6203 int imm5
= extract32(insn
, 16, 5);
6204 int op
= extract32(insn
, 29, 1);
6206 if (op
!= 0 || imm4
!= 0) {
6207 unallocated_encoding(s
);
6211 /* DUP (element, scalar) */
6212 handle_simd_dupes(s
, rd
, rn
, imm5
);
6215 /* C3.6.8 AdvSIMD scalar pairwise
6216 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6217 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6218 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6219 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6221 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
6223 int u
= extract32(insn
, 29, 1);
6224 int size
= extract32(insn
, 22, 2);
6225 int opcode
= extract32(insn
, 12, 5);
6226 int rn
= extract32(insn
, 5, 5);
6227 int rd
= extract32(insn
, 0, 5);
6230 /* For some ops (the FP ones), size[1] is part of the encoding.
6231 * For ADDP strictly it is not but size[1] is always 1 for valid
6234 opcode
|= (extract32(size
, 1, 1) << 5);
6237 case 0x3b: /* ADDP */
6238 if (u
|| size
!= 3) {
6239 unallocated_encoding(s
);
6242 if (!fp_access_check(s
)) {
6246 TCGV_UNUSED_PTR(fpst
);
6248 case 0xc: /* FMAXNMP */
6249 case 0xd: /* FADDP */
6250 case 0xf: /* FMAXP */
6251 case 0x2c: /* FMINNMP */
6252 case 0x2f: /* FMINP */
6253 /* FP op, size[0] is 32 or 64 bit */
6255 unallocated_encoding(s
);
6258 if (!fp_access_check(s
)) {
6262 size
= extract32(size
, 0, 1) ? 3 : 2;
6263 fpst
= get_fpstatus_ptr();
6266 unallocated_encoding(s
);
6271 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6272 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6273 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6275 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
6276 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
6279 case 0x3b: /* ADDP */
6280 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
6282 case 0xc: /* FMAXNMP */
6283 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6285 case 0xd: /* FADDP */
6286 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6288 case 0xf: /* FMAXP */
6289 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6291 case 0x2c: /* FMINNMP */
6292 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6294 case 0x2f: /* FMINP */
6295 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6298 g_assert_not_reached();
6301 write_fp_dreg(s
, rd
, tcg_res
);
6303 tcg_temp_free_i64(tcg_op1
);
6304 tcg_temp_free_i64(tcg_op2
);
6305 tcg_temp_free_i64(tcg_res
);
6307 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6308 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6309 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6311 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_32
);
6312 read_vec_element_i32(s
, tcg_op2
, rn
, 1, MO_32
);
6315 case 0xc: /* FMAXNMP */
6316 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6318 case 0xd: /* FADDP */
6319 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6321 case 0xf: /* FMAXP */
6322 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6324 case 0x2c: /* FMINNMP */
6325 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6327 case 0x2f: /* FMINP */
6328 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6331 g_assert_not_reached();
6334 write_fp_sreg(s
, rd
, tcg_res
);
6336 tcg_temp_free_i32(tcg_op1
);
6337 tcg_temp_free_i32(tcg_op2
);
6338 tcg_temp_free_i32(tcg_res
);
6341 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
6342 tcg_temp_free_ptr(fpst
);
6347 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
6349 * This code is handles the common shifting code and is used by both
6350 * the vector and scalar code.
6352 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6353 TCGv_i64 tcg_rnd
, bool accumulate
,
6354 bool is_u
, int size
, int shift
)
6356 bool extended_result
= false;
6357 bool round
= !TCGV_IS_UNUSED_I64(tcg_rnd
);
6359 TCGv_i64 tcg_src_hi
;
6361 if (round
&& size
== 3) {
6362 extended_result
= true;
6363 ext_lshift
= 64 - shift
;
6364 tcg_src_hi
= tcg_temp_new_i64();
6365 } else if (shift
== 64) {
6366 if (!accumulate
&& is_u
) {
6367 /* result is zero */
6368 tcg_gen_movi_i64(tcg_res
, 0);
6373 /* Deal with the rounding step */
6375 if (extended_result
) {
6376 TCGv_i64 tcg_zero
= tcg_const_i64(0);
6378 /* take care of sign extending tcg_res */
6379 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
6380 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6381 tcg_src
, tcg_src_hi
,
6384 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6388 tcg_temp_free_i64(tcg_zero
);
6390 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
6394 /* Now do the shift right */
6395 if (round
&& extended_result
) {
6396 /* extended case, >64 bit precision required */
6397 if (ext_lshift
== 0) {
6398 /* special case, only high bits matter */
6399 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
6401 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6402 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
6403 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
6408 /* essentially shifting in 64 zeros */
6409 tcg_gen_movi_i64(tcg_src
, 0);
6411 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6415 /* effectively extending the sign-bit */
6416 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
6418 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
6424 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
6426 tcg_gen_mov_i64(tcg_res
, tcg_src
);
6429 if (extended_result
) {
6430 tcg_temp_free_i64(tcg_src_hi
);
6434 /* Common SHL/SLI - Shift left with an optional insert */
6435 static void handle_shli_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6436 bool insert
, int shift
)
6438 if (insert
) { /* SLI */
6439 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, shift
, 64 - shift
);
6441 tcg_gen_shli_i64(tcg_res
, tcg_src
, shift
);
6445 /* SRI: shift right with insert */
6446 static void handle_shri_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6447 int size
, int shift
)
6449 int esize
= 8 << size
;
6451 /* shift count same as element size is valid but does nothing;
6452 * special case to avoid potential shift by 64.
6454 if (shift
!= esize
) {
6455 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6456 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, 0, esize
- shift
);
6460 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
6461 static void handle_scalar_simd_shri(DisasContext
*s
,
6462 bool is_u
, int immh
, int immb
,
6463 int opcode
, int rn
, int rd
)
6466 int immhb
= immh
<< 3 | immb
;
6467 int shift
= 2 * (8 << size
) - immhb
;
6468 bool accumulate
= false;
6470 bool insert
= false;
6475 if (!extract32(immh
, 3, 1)) {
6476 unallocated_encoding(s
);
6480 if (!fp_access_check(s
)) {
6485 case 0x02: /* SSRA / USRA (accumulate) */
6488 case 0x04: /* SRSHR / URSHR (rounding) */
6491 case 0x06: /* SRSRA / URSRA (accum + rounding) */
6492 accumulate
= round
= true;
6494 case 0x08: /* SRI */
6500 uint64_t round_const
= 1ULL << (shift
- 1);
6501 tcg_round
= tcg_const_i64(round_const
);
6503 TCGV_UNUSED_I64(tcg_round
);
6506 tcg_rn
= read_fp_dreg(s
, rn
);
6507 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6510 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
6512 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6513 accumulate
, is_u
, size
, shift
);
6516 write_fp_dreg(s
, rd
, tcg_rd
);
6518 tcg_temp_free_i64(tcg_rn
);
6519 tcg_temp_free_i64(tcg_rd
);
6521 tcg_temp_free_i64(tcg_round
);
6525 /* SHL/SLI - Scalar shift left */
6526 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
6527 int immh
, int immb
, int opcode
,
6530 int size
= 32 - clz32(immh
) - 1;
6531 int immhb
= immh
<< 3 | immb
;
6532 int shift
= immhb
- (8 << size
);
6533 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
6534 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
6536 if (!extract32(immh
, 3, 1)) {
6537 unallocated_encoding(s
);
6541 if (!fp_access_check(s
)) {
6545 tcg_rn
= read_fp_dreg(s
, rn
);
6546 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6548 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
6550 write_fp_dreg(s
, rd
, tcg_rd
);
6552 tcg_temp_free_i64(tcg_rn
);
6553 tcg_temp_free_i64(tcg_rd
);
6556 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
6557 * (signed/unsigned) narrowing */
6558 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
6559 bool is_u_shift
, bool is_u_narrow
,
6560 int immh
, int immb
, int opcode
,
6563 int immhb
= immh
<< 3 | immb
;
6564 int size
= 32 - clz32(immh
) - 1;
6565 int esize
= 8 << size
;
6566 int shift
= (2 * esize
) - immhb
;
6567 int elements
= is_scalar
? 1 : (64 / esize
);
6568 bool round
= extract32(opcode
, 0, 1);
6569 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
6570 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
6571 TCGv_i32 tcg_rd_narrowed
;
6574 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
6575 { gen_helper_neon_narrow_sat_s8
,
6576 gen_helper_neon_unarrow_sat8
},
6577 { gen_helper_neon_narrow_sat_s16
,
6578 gen_helper_neon_unarrow_sat16
},
6579 { gen_helper_neon_narrow_sat_s32
,
6580 gen_helper_neon_unarrow_sat32
},
6583 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
6584 gen_helper_neon_narrow_sat_u8
,
6585 gen_helper_neon_narrow_sat_u16
,
6586 gen_helper_neon_narrow_sat_u32
,
6589 NeonGenNarrowEnvFn
*narrowfn
;
6595 if (extract32(immh
, 3, 1)) {
6596 unallocated_encoding(s
);
6600 if (!fp_access_check(s
)) {
6605 narrowfn
= unsigned_narrow_fns
[size
];
6607 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
6610 tcg_rn
= tcg_temp_new_i64();
6611 tcg_rd
= tcg_temp_new_i64();
6612 tcg_rd_narrowed
= tcg_temp_new_i32();
6613 tcg_final
= tcg_const_i64(0);
6616 uint64_t round_const
= 1ULL << (shift
- 1);
6617 tcg_round
= tcg_const_i64(round_const
);
6619 TCGV_UNUSED_I64(tcg_round
);
6622 for (i
= 0; i
< elements
; i
++) {
6623 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
6624 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6625 false, is_u_shift
, size
+1, shift
);
6626 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
6627 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
6628 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
6632 clear_vec_high(s
, rd
);
6633 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
6635 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
6639 tcg_temp_free_i64(tcg_round
);
6641 tcg_temp_free_i64(tcg_rn
);
6642 tcg_temp_free_i64(tcg_rd
);
6643 tcg_temp_free_i32(tcg_rd_narrowed
);
6644 tcg_temp_free_i64(tcg_final
);
6648 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
6649 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
6650 bool src_unsigned
, bool dst_unsigned
,
6651 int immh
, int immb
, int rn
, int rd
)
6653 int immhb
= immh
<< 3 | immb
;
6654 int size
= 32 - clz32(immh
) - 1;
6655 int shift
= immhb
- (8 << size
);
6659 assert(!(scalar
&& is_q
));
6662 if (!is_q
&& extract32(immh
, 3, 1)) {
6663 unallocated_encoding(s
);
6667 /* Since we use the variable-shift helpers we must
6668 * replicate the shift count into each element of
6669 * the tcg_shift value.
6673 shift
|= shift
<< 8;
6676 shift
|= shift
<< 16;
6682 g_assert_not_reached();
6686 if (!fp_access_check(s
)) {
6691 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
6692 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
6693 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
6694 { NULL
, gen_helper_neon_qshl_u64
},
6696 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
6697 int maxpass
= is_q
? 2 : 1;
6699 for (pass
= 0; pass
< maxpass
; pass
++) {
6700 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6702 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6703 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6704 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6706 tcg_temp_free_i64(tcg_op
);
6708 tcg_temp_free_i64(tcg_shift
);
6711 clear_vec_high(s
, rd
);
6714 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
6715 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
6717 { gen_helper_neon_qshl_s8
,
6718 gen_helper_neon_qshl_s16
,
6719 gen_helper_neon_qshl_s32
},
6720 { gen_helper_neon_qshlu_s8
,
6721 gen_helper_neon_qshlu_s16
,
6722 gen_helper_neon_qshlu_s32
}
6724 { NULL
, NULL
, NULL
},
6725 { gen_helper_neon_qshl_u8
,
6726 gen_helper_neon_qshl_u16
,
6727 gen_helper_neon_qshl_u32
}
6730 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
6731 TCGMemOp memop
= scalar
? size
: MO_32
;
6732 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
6734 for (pass
= 0; pass
< maxpass
; pass
++) {
6735 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6737 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
6738 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6742 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
6745 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
6750 g_assert_not_reached();
6752 write_fp_sreg(s
, rd
, tcg_op
);
6754 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6757 tcg_temp_free_i32(tcg_op
);
6759 tcg_temp_free_i32(tcg_shift
);
6761 if (!is_q
&& !scalar
) {
6762 clear_vec_high(s
, rd
);
6767 /* Common vector code for handling integer to FP conversion */
6768 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
6769 int elements
, int is_signed
,
6770 int fracbits
, int size
)
6772 bool is_double
= size
== 3 ? true : false;
6773 TCGv_ptr tcg_fpst
= get_fpstatus_ptr();
6774 TCGv_i32 tcg_shift
= tcg_const_i32(fracbits
);
6775 TCGv_i64 tcg_int
= tcg_temp_new_i64();
6776 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
6779 for (pass
= 0; pass
< elements
; pass
++) {
6780 read_vec_element(s
, tcg_int
, rn
, pass
, mop
);
6783 TCGv_i64 tcg_double
= tcg_temp_new_i64();
6785 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6786 tcg_shift
, tcg_fpst
);
6788 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6789 tcg_shift
, tcg_fpst
);
6791 if (elements
== 1) {
6792 write_fp_dreg(s
, rd
, tcg_double
);
6794 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
6796 tcg_temp_free_i64(tcg_double
);
6798 TCGv_i32 tcg_single
= tcg_temp_new_i32();
6800 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6801 tcg_shift
, tcg_fpst
);
6803 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6804 tcg_shift
, tcg_fpst
);
6806 if (elements
== 1) {
6807 write_fp_sreg(s
, rd
, tcg_single
);
6809 write_vec_element_i32(s
, tcg_single
, rd
, pass
, MO_32
);
6811 tcg_temp_free_i32(tcg_single
);
6815 if (!is_double
&& elements
== 2) {
6816 clear_vec_high(s
, rd
);
6819 tcg_temp_free_i64(tcg_int
);
6820 tcg_temp_free_ptr(tcg_fpst
);
6821 tcg_temp_free_i32(tcg_shift
);
6824 /* UCVTF/SCVTF - Integer to FP conversion */
6825 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
6826 bool is_q
, bool is_u
,
6827 int immh
, int immb
, int opcode
,
6830 bool is_double
= extract32(immh
, 3, 1);
6831 int size
= is_double
? MO_64
: MO_32
;
6833 int immhb
= immh
<< 3 | immb
;
6834 int fracbits
= (is_double
? 128 : 64) - immhb
;
6836 if (!extract32(immh
, 2, 2)) {
6837 unallocated_encoding(s
);
6844 elements
= is_double
? 2 : is_q
? 4 : 2;
6845 if (is_double
&& !is_q
) {
6846 unallocated_encoding(s
);
6851 if (!fp_access_check(s
)) {
6855 /* immh == 0 would be a failure of the decode logic */
6858 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
6861 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
6862 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
6863 bool is_q
, bool is_u
,
6864 int immh
, int immb
, int rn
, int rd
)
6866 bool is_double
= extract32(immh
, 3, 1);
6867 int immhb
= immh
<< 3 | immb
;
6868 int fracbits
= (is_double
? 128 : 64) - immhb
;
6870 TCGv_ptr tcg_fpstatus
;
6871 TCGv_i32 tcg_rmode
, tcg_shift
;
6873 if (!extract32(immh
, 2, 2)) {
6874 unallocated_encoding(s
);
6878 if (!is_scalar
&& !is_q
&& is_double
) {
6879 unallocated_encoding(s
);
6883 if (!fp_access_check(s
)) {
6887 assert(!(is_scalar
&& is_q
));
6889 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
6890 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6891 tcg_fpstatus
= get_fpstatus_ptr();
6892 tcg_shift
= tcg_const_i32(fracbits
);
6895 int maxpass
= is_scalar
? 1 : 2;
6897 for (pass
= 0; pass
< maxpass
; pass
++) {
6898 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6900 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6902 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6904 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6906 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6907 tcg_temp_free_i64(tcg_op
);
6910 clear_vec_high(s
, rd
);
6913 int maxpass
= is_scalar
? 1 : is_q
? 4 : 2;
6914 for (pass
= 0; pass
< maxpass
; pass
++) {
6915 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6917 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
6919 gen_helper_vfp_touls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6921 gen_helper_vfp_tosls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6924 write_fp_sreg(s
, rd
, tcg_op
);
6926 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6928 tcg_temp_free_i32(tcg_op
);
6930 if (!is_q
&& !is_scalar
) {
6931 clear_vec_high(s
, rd
);
6935 tcg_temp_free_ptr(tcg_fpstatus
);
6936 tcg_temp_free_i32(tcg_shift
);
6937 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6938 tcg_temp_free_i32(tcg_rmode
);
6941 /* C3.6.9 AdvSIMD scalar shift by immediate
6942 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
6943 * +-----+---+-------------+------+------+--------+---+------+------+
6944 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
6945 * +-----+---+-------------+------+------+--------+---+------+------+
6947 * This is the scalar version so it works on a fixed sized registers
6949 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
6951 int rd
= extract32(insn
, 0, 5);
6952 int rn
= extract32(insn
, 5, 5);
6953 int opcode
= extract32(insn
, 11, 5);
6954 int immb
= extract32(insn
, 16, 3);
6955 int immh
= extract32(insn
, 19, 4);
6956 bool is_u
= extract32(insn
, 29, 1);
6959 unallocated_encoding(s
);
6964 case 0x08: /* SRI */
6966 unallocated_encoding(s
);
6970 case 0x00: /* SSHR / USHR */
6971 case 0x02: /* SSRA / USRA */
6972 case 0x04: /* SRSHR / URSHR */
6973 case 0x06: /* SRSRA / URSRA */
6974 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6976 case 0x0a: /* SHL / SLI */
6977 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6979 case 0x1c: /* SCVTF, UCVTF */
6980 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
6983 case 0x10: /* SQSHRUN, SQSHRUN2 */
6984 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
6986 unallocated_encoding(s
);
6989 handle_vec_simd_sqshrn(s
, true, false, false, true,
6990 immh
, immb
, opcode
, rn
, rd
);
6992 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
6993 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
6994 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
6995 immh
, immb
, opcode
, rn
, rd
);
6997 case 0xc: /* SQSHLU */
6999 unallocated_encoding(s
);
7002 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
7004 case 0xe: /* SQSHL, UQSHL */
7005 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
7007 case 0x1f: /* FCVTZS, FCVTZU */
7008 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
7011 unallocated_encoding(s
);
7016 /* C3.6.10 AdvSIMD scalar three different
7017 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
7018 * +-----+---+-----------+------+---+------+--------+-----+------+------+
7019 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
7020 * +-----+---+-----------+------+---+------+--------+-----+------+------+
7022 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
7024 bool is_u
= extract32(insn
, 29, 1);
7025 int size
= extract32(insn
, 22, 2);
7026 int opcode
= extract32(insn
, 12, 4);
7027 int rm
= extract32(insn
, 16, 5);
7028 int rn
= extract32(insn
, 5, 5);
7029 int rd
= extract32(insn
, 0, 5);
7032 unallocated_encoding(s
);
7037 case 0x9: /* SQDMLAL, SQDMLAL2 */
7038 case 0xb: /* SQDMLSL, SQDMLSL2 */
7039 case 0xd: /* SQDMULL, SQDMULL2 */
7040 if (size
== 0 || size
== 3) {
7041 unallocated_encoding(s
);
7046 unallocated_encoding(s
);
7050 if (!fp_access_check(s
)) {
7055 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7056 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7057 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7059 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
7060 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
7062 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
7063 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
7066 case 0xd: /* SQDMULL, SQDMULL2 */
7068 case 0xb: /* SQDMLSL, SQDMLSL2 */
7069 tcg_gen_neg_i64(tcg_res
, tcg_res
);
7071 case 0x9: /* SQDMLAL, SQDMLAL2 */
7072 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
7073 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
7077 g_assert_not_reached();
7080 write_fp_dreg(s
, rd
, tcg_res
);
7082 tcg_temp_free_i64(tcg_op1
);
7083 tcg_temp_free_i64(tcg_op2
);
7084 tcg_temp_free_i64(tcg_res
);
7086 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7087 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7088 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7090 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_16
);
7091 read_vec_element_i32(s
, tcg_op2
, rm
, 0, MO_16
);
7093 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
7094 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
7097 case 0xd: /* SQDMULL, SQDMULL2 */
7099 case 0xb: /* SQDMLSL, SQDMLSL2 */
7100 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
7102 case 0x9: /* SQDMLAL, SQDMLAL2 */
7104 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
7105 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
7106 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
7108 tcg_temp_free_i64(tcg_op3
);
7112 g_assert_not_reached();
7115 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
7116 write_fp_dreg(s
, rd
, tcg_res
);
7118 tcg_temp_free_i32(tcg_op1
);
7119 tcg_temp_free_i32(tcg_op2
);
7120 tcg_temp_free_i64(tcg_res
);
7124 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
7125 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
7127 /* Handle 64x64->64 opcodes which are shared between the scalar
7128 * and vector 3-same groups. We cover every opcode where size == 3
7129 * is valid in either the three-reg-same (integer, not pairwise)
7130 * or scalar-three-reg-same groups. (Some opcodes are not yet
7136 case 0x1: /* SQADD */
7138 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7140 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7143 case 0x5: /* SQSUB */
7145 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7147 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7150 case 0x6: /* CMGT, CMHI */
7151 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
7152 * We implement this using setcond (test) and then negating.
7154 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
7156 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
7157 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7159 case 0x7: /* CMGE, CMHS */
7160 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
7162 case 0x11: /* CMTST, CMEQ */
7167 /* CMTST : test is "if (X & Y != 0)". */
7168 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
7169 tcg_gen_setcondi_i64(TCG_COND_NE
, tcg_rd
, tcg_rd
, 0);
7170 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7172 case 0x8: /* SSHL, USHL */
7174 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
7176 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
7179 case 0x9: /* SQSHL, UQSHL */
7181 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7183 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7186 case 0xa: /* SRSHL, URSHL */
7188 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
7190 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
7193 case 0xb: /* SQRSHL, UQRSHL */
7195 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7197 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7200 case 0x10: /* ADD, SUB */
7202 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
7204 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
7208 g_assert_not_reached();
7212 /* Handle the 3-same-operands float operations; shared by the scalar
7213 * and vector encodings. The caller must filter out any encodings
7214 * not allocated for the encoding it is dealing with.
7216 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
7217 int fpopcode
, int rd
, int rn
, int rm
)
7220 TCGv_ptr fpst
= get_fpstatus_ptr();
7222 for (pass
= 0; pass
< elements
; pass
++) {
7225 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7226 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7227 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7229 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
7230 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
7233 case 0x39: /* FMLS */
7234 /* As usual for ARM, separate negation for fused multiply-add */
7235 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
7237 case 0x19: /* FMLA */
7238 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7239 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
7242 case 0x18: /* FMAXNM */
7243 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7245 case 0x1a: /* FADD */
7246 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7248 case 0x1b: /* FMULX */
7249 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7251 case 0x1c: /* FCMEQ */
7252 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7254 case 0x1e: /* FMAX */
7255 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7257 case 0x1f: /* FRECPS */
7258 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7260 case 0x38: /* FMINNM */
7261 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7263 case 0x3a: /* FSUB */
7264 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7266 case 0x3e: /* FMIN */
7267 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7269 case 0x3f: /* FRSQRTS */
7270 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7272 case 0x5b: /* FMUL */
7273 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7275 case 0x5c: /* FCMGE */
7276 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7278 case 0x5d: /* FACGE */
7279 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7281 case 0x5f: /* FDIV */
7282 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7284 case 0x7a: /* FABD */
7285 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7286 gen_helper_vfp_absd(tcg_res
, tcg_res
);
7288 case 0x7c: /* FCMGT */
7289 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7291 case 0x7d: /* FACGT */
7292 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7295 g_assert_not_reached();
7298 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7300 tcg_temp_free_i64(tcg_res
);
7301 tcg_temp_free_i64(tcg_op1
);
7302 tcg_temp_free_i64(tcg_op2
);
7305 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7306 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7307 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7309 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
7310 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
7313 case 0x39: /* FMLS */
7314 /* As usual for ARM, separate negation for fused multiply-add */
7315 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
7317 case 0x19: /* FMLA */
7318 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7319 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
7322 case 0x1a: /* FADD */
7323 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7325 case 0x1b: /* FMULX */
7326 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7328 case 0x1c: /* FCMEQ */
7329 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7331 case 0x1e: /* FMAX */
7332 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7334 case 0x1f: /* FRECPS */
7335 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7337 case 0x18: /* FMAXNM */
7338 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7340 case 0x38: /* FMINNM */
7341 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7343 case 0x3a: /* FSUB */
7344 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7346 case 0x3e: /* FMIN */
7347 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7349 case 0x3f: /* FRSQRTS */
7350 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7352 case 0x5b: /* FMUL */
7353 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7355 case 0x5c: /* FCMGE */
7356 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7358 case 0x5d: /* FACGE */
7359 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7361 case 0x5f: /* FDIV */
7362 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7364 case 0x7a: /* FABD */
7365 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7366 gen_helper_vfp_abss(tcg_res
, tcg_res
);
7368 case 0x7c: /* FCMGT */
7369 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7371 case 0x7d: /* FACGT */
7372 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7375 g_assert_not_reached();
7378 if (elements
== 1) {
7379 /* scalar single so clear high part */
7380 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
7382 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
7383 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
7384 tcg_temp_free_i64(tcg_tmp
);
7386 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7389 tcg_temp_free_i32(tcg_res
);
7390 tcg_temp_free_i32(tcg_op1
);
7391 tcg_temp_free_i32(tcg_op2
);
7395 tcg_temp_free_ptr(fpst
);
7397 if ((elements
<< size
) < 4) {
7398 /* scalar, or non-quad vector op */
7399 clear_vec_high(s
, rd
);
7403 /* C3.6.11 AdvSIMD scalar three same
7404 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
7405 * +-----+---+-----------+------+---+------+--------+---+------+------+
7406 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
7407 * +-----+---+-----------+------+---+------+--------+---+------+------+
7409 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
7411 int rd
= extract32(insn
, 0, 5);
7412 int rn
= extract32(insn
, 5, 5);
7413 int opcode
= extract32(insn
, 11, 5);
7414 int rm
= extract32(insn
, 16, 5);
7415 int size
= extract32(insn
, 22, 2);
7416 bool u
= extract32(insn
, 29, 1);
7419 if (opcode
>= 0x18) {
7420 /* Floating point: U, size[1] and opcode indicate operation */
7421 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
7423 case 0x1b: /* FMULX */
7424 case 0x1f: /* FRECPS */
7425 case 0x3f: /* FRSQRTS */
7426 case 0x5d: /* FACGE */
7427 case 0x7d: /* FACGT */
7428 case 0x1c: /* FCMEQ */
7429 case 0x5c: /* FCMGE */
7430 case 0x7c: /* FCMGT */
7431 case 0x7a: /* FABD */
7434 unallocated_encoding(s
);
7438 if (!fp_access_check(s
)) {
7442 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
7447 case 0x1: /* SQADD, UQADD */
7448 case 0x5: /* SQSUB, UQSUB */
7449 case 0x9: /* SQSHL, UQSHL */
7450 case 0xb: /* SQRSHL, UQRSHL */
7452 case 0x8: /* SSHL, USHL */
7453 case 0xa: /* SRSHL, URSHL */
7454 case 0x6: /* CMGT, CMHI */
7455 case 0x7: /* CMGE, CMHS */
7456 case 0x11: /* CMTST, CMEQ */
7457 case 0x10: /* ADD, SUB (vector) */
7459 unallocated_encoding(s
);
7463 case 0x16: /* SQDMULH, SQRDMULH (vector) */
7464 if (size
!= 1 && size
!= 2) {
7465 unallocated_encoding(s
);
7470 unallocated_encoding(s
);
7474 if (!fp_access_check(s
)) {
7478 tcg_rd
= tcg_temp_new_i64();
7481 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7482 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
7484 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
7485 tcg_temp_free_i64(tcg_rn
);
7486 tcg_temp_free_i64(tcg_rm
);
7488 /* Do a single operation on the lowest element in the vector.
7489 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
7490 * no side effects for all these operations.
7491 * OPTME: special-purpose helpers would avoid doing some
7492 * unnecessary work in the helper for the 8 and 16 bit cases.
7494 NeonGenTwoOpEnvFn
*genenvfn
;
7495 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7496 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
7497 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
7499 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7500 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
7503 case 0x1: /* SQADD, UQADD */
7505 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7506 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
7507 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
7508 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
7510 genenvfn
= fns
[size
][u
];
7513 case 0x5: /* SQSUB, UQSUB */
7515 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7516 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
7517 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
7518 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
7520 genenvfn
= fns
[size
][u
];
7523 case 0x9: /* SQSHL, UQSHL */
7525 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7526 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
7527 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
7528 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
7530 genenvfn
= fns
[size
][u
];
7533 case 0xb: /* SQRSHL, UQRSHL */
7535 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7536 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
7537 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
7538 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
7540 genenvfn
= fns
[size
][u
];
7543 case 0x16: /* SQDMULH, SQRDMULH */
7545 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
7546 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
7547 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
7549 assert(size
== 1 || size
== 2);
7550 genenvfn
= fns
[size
- 1][u
];
7554 g_assert_not_reached();
7557 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
7558 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
7559 tcg_temp_free_i32(tcg_rd32
);
7560 tcg_temp_free_i32(tcg_rn
);
7561 tcg_temp_free_i32(tcg_rm
);
7564 write_fp_dreg(s
, rd
, tcg_rd
);
7566 tcg_temp_free_i64(tcg_rd
);
7569 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
7570 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
7571 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
7573 /* Handle 64->64 opcodes which are shared between the scalar and
7574 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
7575 * is valid in either group and also the double-precision fp ops.
7576 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
7582 case 0x4: /* CLS, CLZ */
7584 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
7586 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
7590 /* This opcode is shared with CNT and RBIT but we have earlier
7591 * enforced that size == 3 if and only if this is the NOT insn.
7593 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
7595 case 0x7: /* SQABS, SQNEG */
7597 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
7599 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
7602 case 0xa: /* CMLT */
7603 /* 64 bit integer comparison against zero, result is
7604 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
7609 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
7610 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7612 case 0x8: /* CMGT, CMGE */
7613 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
7615 case 0x9: /* CMEQ, CMLE */
7616 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
7618 case 0xb: /* ABS, NEG */
7620 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7622 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7623 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7624 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
7626 tcg_temp_free_i64(tcg_zero
);
7629 case 0x2f: /* FABS */
7630 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
7632 case 0x6f: /* FNEG */
7633 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
7635 case 0x7f: /* FSQRT */
7636 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
7638 case 0x1a: /* FCVTNS */
7639 case 0x1b: /* FCVTMS */
7640 case 0x1c: /* FCVTAS */
7641 case 0x3a: /* FCVTPS */
7642 case 0x3b: /* FCVTZS */
7644 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7645 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7646 tcg_temp_free_i32(tcg_shift
);
7649 case 0x5a: /* FCVTNU */
7650 case 0x5b: /* FCVTMU */
7651 case 0x5c: /* FCVTAU */
7652 case 0x7a: /* FCVTPU */
7653 case 0x7b: /* FCVTZU */
7655 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7656 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7657 tcg_temp_free_i32(tcg_shift
);
7660 case 0x18: /* FRINTN */
7661 case 0x19: /* FRINTM */
7662 case 0x38: /* FRINTP */
7663 case 0x39: /* FRINTZ */
7664 case 0x58: /* FRINTA */
7665 case 0x79: /* FRINTI */
7666 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7668 case 0x59: /* FRINTX */
7669 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7672 g_assert_not_reached();
7676 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
7677 bool is_scalar
, bool is_u
, bool is_q
,
7678 int size
, int rn
, int rd
)
7680 bool is_double
= (size
== 3);
7683 if (!fp_access_check(s
)) {
7687 fpst
= get_fpstatus_ptr();
7690 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7691 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7692 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7693 NeonGenTwoDoubleOPFn
*genfn
;
7698 case 0x2e: /* FCMLT (zero) */
7701 case 0x2c: /* FCMGT (zero) */
7702 genfn
= gen_helper_neon_cgt_f64
;
7704 case 0x2d: /* FCMEQ (zero) */
7705 genfn
= gen_helper_neon_ceq_f64
;
7707 case 0x6d: /* FCMLE (zero) */
7710 case 0x6c: /* FCMGE (zero) */
7711 genfn
= gen_helper_neon_cge_f64
;
7714 g_assert_not_reached();
7717 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7718 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7720 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7722 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7724 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7727 clear_vec_high(s
, rd
);
7730 tcg_temp_free_i64(tcg_res
);
7731 tcg_temp_free_i64(tcg_zero
);
7732 tcg_temp_free_i64(tcg_op
);
7734 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7735 TCGv_i32 tcg_zero
= tcg_const_i32(0);
7736 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7737 NeonGenTwoSingleOPFn
*genfn
;
7739 int pass
, maxpasses
;
7742 case 0x2e: /* FCMLT (zero) */
7745 case 0x2c: /* FCMGT (zero) */
7746 genfn
= gen_helper_neon_cgt_f32
;
7748 case 0x2d: /* FCMEQ (zero) */
7749 genfn
= gen_helper_neon_ceq_f32
;
7751 case 0x6d: /* FCMLE (zero) */
7754 case 0x6c: /* FCMGE (zero) */
7755 genfn
= gen_helper_neon_cge_f32
;
7758 g_assert_not_reached();
7764 maxpasses
= is_q
? 4 : 2;
7767 for (pass
= 0; pass
< maxpasses
; pass
++) {
7768 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7770 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7772 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7775 write_fp_sreg(s
, rd
, tcg_res
);
7777 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7780 tcg_temp_free_i32(tcg_res
);
7781 tcg_temp_free_i32(tcg_zero
);
7782 tcg_temp_free_i32(tcg_op
);
7783 if (!is_q
&& !is_scalar
) {
7784 clear_vec_high(s
, rd
);
7788 tcg_temp_free_ptr(fpst
);
7791 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
7792 bool is_scalar
, bool is_u
, bool is_q
,
7793 int size
, int rn
, int rd
)
7795 bool is_double
= (size
== 3);
7796 TCGv_ptr fpst
= get_fpstatus_ptr();
7799 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7800 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7803 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7804 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7806 case 0x3d: /* FRECPE */
7807 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
7809 case 0x3f: /* FRECPX */
7810 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
7812 case 0x7d: /* FRSQRTE */
7813 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
7816 g_assert_not_reached();
7818 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7821 clear_vec_high(s
, rd
);
7824 tcg_temp_free_i64(tcg_res
);
7825 tcg_temp_free_i64(tcg_op
);
7827 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7828 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7829 int pass
, maxpasses
;
7834 maxpasses
= is_q
? 4 : 2;
7837 for (pass
= 0; pass
< maxpasses
; pass
++) {
7838 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7841 case 0x3c: /* URECPE */
7842 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
7844 case 0x3d: /* FRECPE */
7845 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
7847 case 0x3f: /* FRECPX */
7848 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
7850 case 0x7d: /* FRSQRTE */
7851 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
7854 g_assert_not_reached();
7858 write_fp_sreg(s
, rd
, tcg_res
);
7860 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7863 tcg_temp_free_i32(tcg_res
);
7864 tcg_temp_free_i32(tcg_op
);
7865 if (!is_q
&& !is_scalar
) {
7866 clear_vec_high(s
, rd
);
7869 tcg_temp_free_ptr(fpst
);
7872 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
7873 int opcode
, bool u
, bool is_q
,
7874 int size
, int rn
, int rd
)
7876 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
7877 * in the source becomes a size element in the destination).
7880 TCGv_i32 tcg_res
[2];
7881 int destelt
= is_q
? 2 : 0;
7882 int passes
= scalar
? 1 : 2;
7885 tcg_res
[1] = tcg_const_i32(0);
7888 for (pass
= 0; pass
< passes
; pass
++) {
7889 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7890 NeonGenNarrowFn
*genfn
= NULL
;
7891 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
7894 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
7896 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7898 tcg_res
[pass
] = tcg_temp_new_i32();
7901 case 0x12: /* XTN, SQXTUN */
7903 static NeonGenNarrowFn
* const xtnfns
[3] = {
7904 gen_helper_neon_narrow_u8
,
7905 gen_helper_neon_narrow_u16
,
7906 tcg_gen_extrl_i64_i32
,
7908 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
7909 gen_helper_neon_unarrow_sat8
,
7910 gen_helper_neon_unarrow_sat16
,
7911 gen_helper_neon_unarrow_sat32
,
7914 genenvfn
= sqxtunfns
[size
];
7916 genfn
= xtnfns
[size
];
7920 case 0x14: /* SQXTN, UQXTN */
7922 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
7923 { gen_helper_neon_narrow_sat_s8
,
7924 gen_helper_neon_narrow_sat_u8
},
7925 { gen_helper_neon_narrow_sat_s16
,
7926 gen_helper_neon_narrow_sat_u16
},
7927 { gen_helper_neon_narrow_sat_s32
,
7928 gen_helper_neon_narrow_sat_u32
},
7930 genenvfn
= fns
[size
][u
];
7933 case 0x16: /* FCVTN, FCVTN2 */
7934 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
7936 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
7938 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
7939 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
7940 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
7941 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, cpu_env
);
7942 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, cpu_env
);
7943 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
7944 tcg_temp_free_i32(tcg_lo
);
7945 tcg_temp_free_i32(tcg_hi
);
7948 case 0x56: /* FCVTXN, FCVTXN2 */
7949 /* 64 bit to 32 bit float conversion
7950 * with von Neumann rounding (round to odd)
7953 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
7956 g_assert_not_reached();
7960 genfn(tcg_res
[pass
], tcg_op
);
7961 } else if (genenvfn
) {
7962 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
7965 tcg_temp_free_i64(tcg_op
);
7968 for (pass
= 0; pass
< 2; pass
++) {
7969 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
7970 tcg_temp_free_i32(tcg_res
[pass
]);
7973 clear_vec_high(s
, rd
);
7977 /* Remaining saturating accumulating ops */
7978 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
7979 bool is_q
, int size
, int rn
, int rd
)
7981 bool is_double
= (size
== 3);
7984 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
7985 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7988 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7989 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
7990 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7992 if (is_u
) { /* USQADD */
7993 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7994 } else { /* SUQADD */
7995 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7997 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
8000 clear_vec_high(s
, rd
);
8003 tcg_temp_free_i64(tcg_rd
);
8004 tcg_temp_free_i64(tcg_rn
);
8006 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
8007 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
8008 int pass
, maxpasses
;
8013 maxpasses
= is_q
? 4 : 2;
8016 for (pass
= 0; pass
< maxpasses
; pass
++) {
8018 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
8019 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
8021 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
8022 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
8025 if (is_u
) { /* USQADD */
8028 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8031 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8034 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8037 g_assert_not_reached();
8039 } else { /* SUQADD */
8042 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8045 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8048 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8051 g_assert_not_reached();
8056 TCGv_i64 tcg_zero
= tcg_const_i64(0);
8057 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
8058 tcg_temp_free_i64(tcg_zero
);
8060 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
8064 clear_vec_high(s
, rd
);
8067 tcg_temp_free_i32(tcg_rd
);
8068 tcg_temp_free_i32(tcg_rn
);
8072 /* C3.6.12 AdvSIMD scalar two reg misc
8073 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
8074 * +-----+---+-----------+------+-----------+--------+-----+------+------+
8075 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
8076 * +-----+---+-----------+------+-----------+--------+-----+------+------+
8078 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
8080 int rd
= extract32(insn
, 0, 5);
8081 int rn
= extract32(insn
, 5, 5);
8082 int opcode
= extract32(insn
, 12, 5);
8083 int size
= extract32(insn
, 22, 2);
8084 bool u
= extract32(insn
, 29, 1);
8085 bool is_fcvt
= false;
8088 TCGv_ptr tcg_fpstatus
;
8091 case 0x3: /* USQADD / SUQADD*/
8092 if (!fp_access_check(s
)) {
8095 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
8097 case 0x7: /* SQABS / SQNEG */
8099 case 0xa: /* CMLT */
8101 unallocated_encoding(s
);
8105 case 0x8: /* CMGT, CMGE */
8106 case 0x9: /* CMEQ, CMLE */
8107 case 0xb: /* ABS, NEG */
8109 unallocated_encoding(s
);
8113 case 0x12: /* SQXTUN */
8115 unallocated_encoding(s
);
8119 case 0x14: /* SQXTN, UQXTN */
8121 unallocated_encoding(s
);
8124 if (!fp_access_check(s
)) {
8127 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
8132 /* Floating point: U, size[1] and opcode indicate operation;
8133 * size[0] indicates single or double precision.
8135 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
8136 size
= extract32(size
, 0, 1) ? 3 : 2;
8138 case 0x2c: /* FCMGT (zero) */
8139 case 0x2d: /* FCMEQ (zero) */
8140 case 0x2e: /* FCMLT (zero) */
8141 case 0x6c: /* FCMGE (zero) */
8142 case 0x6d: /* FCMLE (zero) */
8143 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
8145 case 0x1d: /* SCVTF */
8146 case 0x5d: /* UCVTF */
8148 bool is_signed
= (opcode
== 0x1d);
8149 if (!fp_access_check(s
)) {
8152 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
8155 case 0x3d: /* FRECPE */
8156 case 0x3f: /* FRECPX */
8157 case 0x7d: /* FRSQRTE */
8158 if (!fp_access_check(s
)) {
8161 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
8163 case 0x1a: /* FCVTNS */
8164 case 0x1b: /* FCVTMS */
8165 case 0x3a: /* FCVTPS */
8166 case 0x3b: /* FCVTZS */
8167 case 0x5a: /* FCVTNU */
8168 case 0x5b: /* FCVTMU */
8169 case 0x7a: /* FCVTPU */
8170 case 0x7b: /* FCVTZU */
8172 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
8174 case 0x1c: /* FCVTAS */
8175 case 0x5c: /* FCVTAU */
8176 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
8178 rmode
= FPROUNDING_TIEAWAY
;
8180 case 0x56: /* FCVTXN, FCVTXN2 */
8182 unallocated_encoding(s
);
8185 if (!fp_access_check(s
)) {
8188 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
8191 unallocated_encoding(s
);
8196 unallocated_encoding(s
);
8200 if (!fp_access_check(s
)) {
8205 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
8206 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
8207 tcg_fpstatus
= get_fpstatus_ptr();
8209 TCGV_UNUSED_I32(tcg_rmode
);
8210 TCGV_UNUSED_PTR(tcg_fpstatus
);
8214 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
8215 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
8217 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
8218 write_fp_dreg(s
, rd
, tcg_rd
);
8219 tcg_temp_free_i64(tcg_rd
);
8220 tcg_temp_free_i64(tcg_rn
);
8222 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
8223 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
8225 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
8228 case 0x7: /* SQABS, SQNEG */
8230 NeonGenOneOpEnvFn
*genfn
;
8231 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
8232 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
8233 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
8234 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
8236 genfn
= fns
[size
][u
];
8237 genfn(tcg_rd
, cpu_env
, tcg_rn
);
8240 case 0x1a: /* FCVTNS */
8241 case 0x1b: /* FCVTMS */
8242 case 0x1c: /* FCVTAS */
8243 case 0x3a: /* FCVTPS */
8244 case 0x3b: /* FCVTZS */
8246 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8247 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8248 tcg_temp_free_i32(tcg_shift
);
8251 case 0x5a: /* FCVTNU */
8252 case 0x5b: /* FCVTMU */
8253 case 0x5c: /* FCVTAU */
8254 case 0x7a: /* FCVTPU */
8255 case 0x7b: /* FCVTZU */
8257 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8258 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8259 tcg_temp_free_i32(tcg_shift
);
8263 g_assert_not_reached();
8266 write_fp_sreg(s
, rd
, tcg_rd
);
8267 tcg_temp_free_i32(tcg_rd
);
8268 tcg_temp_free_i32(tcg_rn
);
8272 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
8273 tcg_temp_free_i32(tcg_rmode
);
8274 tcg_temp_free_ptr(tcg_fpstatus
);
8278 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
8279 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
8280 int immh
, int immb
, int opcode
, int rn
, int rd
)
8282 int size
= 32 - clz32(immh
) - 1;
8283 int immhb
= immh
<< 3 | immb
;
8284 int shift
= 2 * (8 << size
) - immhb
;
8285 bool accumulate
= false;
8287 bool insert
= false;
8288 int dsize
= is_q
? 128 : 64;
8289 int esize
= 8 << size
;
8290 int elements
= dsize
/esize
;
8291 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
8292 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8293 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8297 if (extract32(immh
, 3, 1) && !is_q
) {
8298 unallocated_encoding(s
);
8302 if (size
> 3 && !is_q
) {
8303 unallocated_encoding(s
);
8307 if (!fp_access_check(s
)) {
8312 case 0x02: /* SSRA / USRA (accumulate) */
8315 case 0x04: /* SRSHR / URSHR (rounding) */
8318 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8319 accumulate
= round
= true;
8321 case 0x08: /* SRI */
8327 uint64_t round_const
= 1ULL << (shift
- 1);
8328 tcg_round
= tcg_const_i64(round_const
);
8330 TCGV_UNUSED_I64(tcg_round
);
8333 for (i
= 0; i
< elements
; i
++) {
8334 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
8335 if (accumulate
|| insert
) {
8336 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
8340 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
8342 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8343 accumulate
, is_u
, size
, shift
);
8346 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8350 clear_vec_high(s
, rd
);
8354 tcg_temp_free_i64(tcg_round
);
8358 /* SHL/SLI - Vector shift left */
8359 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
8360 int immh
, int immb
, int opcode
, int rn
, int rd
)
8362 int size
= 32 - clz32(immh
) - 1;
8363 int immhb
= immh
<< 3 | immb
;
8364 int shift
= immhb
- (8 << size
);
8365 int dsize
= is_q
? 128 : 64;
8366 int esize
= 8 << size
;
8367 int elements
= dsize
/esize
;
8368 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8369 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8372 if (extract32(immh
, 3, 1) && !is_q
) {
8373 unallocated_encoding(s
);
8377 if (size
> 3 && !is_q
) {
8378 unallocated_encoding(s
);
8382 if (!fp_access_check(s
)) {
8386 for (i
= 0; i
< elements
; i
++) {
8387 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
8389 read_vec_element(s
, tcg_rd
, rd
, i
, size
);
8392 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
8394 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8398 clear_vec_high(s
, rd
);
8402 /* USHLL/SHLL - Vector shift left with widening */
8403 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
8404 int immh
, int immb
, int opcode
, int rn
, int rd
)
8406 int size
= 32 - clz32(immh
) - 1;
8407 int immhb
= immh
<< 3 | immb
;
8408 int shift
= immhb
- (8 << size
);
8410 int esize
= 8 << size
;
8411 int elements
= dsize
/esize
;
8412 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8413 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8417 unallocated_encoding(s
);
8421 if (!fp_access_check(s
)) {
8425 /* For the LL variants the store is larger than the load,
8426 * so if rd == rn we would overwrite parts of our input.
8427 * So load everything right now and use shifts in the main loop.
8429 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
8431 for (i
= 0; i
< elements
; i
++) {
8432 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
8433 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
8434 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
8435 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
8439 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
8440 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
8441 int immh
, int immb
, int opcode
, int rn
, int rd
)
8443 int immhb
= immh
<< 3 | immb
;
8444 int size
= 32 - clz32(immh
) - 1;
8446 int esize
= 8 << size
;
8447 int elements
= dsize
/esize
;
8448 int shift
= (2 * esize
) - immhb
;
8449 bool round
= extract32(opcode
, 0, 1);
8450 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
8454 if (extract32(immh
, 3, 1)) {
8455 unallocated_encoding(s
);
8459 if (!fp_access_check(s
)) {
8463 tcg_rn
= tcg_temp_new_i64();
8464 tcg_rd
= tcg_temp_new_i64();
8465 tcg_final
= tcg_temp_new_i64();
8466 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
8469 uint64_t round_const
= 1ULL << (shift
- 1);
8470 tcg_round
= tcg_const_i64(round_const
);
8472 TCGV_UNUSED_I64(tcg_round
);
8475 for (i
= 0; i
< elements
; i
++) {
8476 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
8477 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8478 false, true, size
+1, shift
);
8480 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8484 clear_vec_high(s
, rd
);
8485 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8487 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8491 tcg_temp_free_i64(tcg_round
);
8493 tcg_temp_free_i64(tcg_rn
);
8494 tcg_temp_free_i64(tcg_rd
);
8495 tcg_temp_free_i64(tcg_final
);
8500 /* C3.6.14 AdvSIMD shift by immediate
8501 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8502 * +---+---+---+-------------+------+------+--------+---+------+------+
8503 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8504 * +---+---+---+-------------+------+------+--------+---+------+------+
8506 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
8508 int rd
= extract32(insn
, 0, 5);
8509 int rn
= extract32(insn
, 5, 5);
8510 int opcode
= extract32(insn
, 11, 5);
8511 int immb
= extract32(insn
, 16, 3);
8512 int immh
= extract32(insn
, 19, 4);
8513 bool is_u
= extract32(insn
, 29, 1);
8514 bool is_q
= extract32(insn
, 30, 1);
8517 case 0x08: /* SRI */
8519 unallocated_encoding(s
);
8523 case 0x00: /* SSHR / USHR */
8524 case 0x02: /* SSRA / USRA (accumulate) */
8525 case 0x04: /* SRSHR / URSHR (rounding) */
8526 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8527 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8529 case 0x0a: /* SHL / SLI */
8530 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8532 case 0x10: /* SHRN */
8533 case 0x11: /* RSHRN / SQRSHRUN */
8535 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
8538 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
8541 case 0x12: /* SQSHRN / UQSHRN */
8542 case 0x13: /* SQRSHRN / UQRSHRN */
8543 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
8546 case 0x14: /* SSHLL / USHLL */
8547 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8549 case 0x1c: /* SCVTF / UCVTF */
8550 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
8553 case 0xc: /* SQSHLU */
8555 unallocated_encoding(s
);
8558 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
8560 case 0xe: /* SQSHL, UQSHL */
8561 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
8563 case 0x1f: /* FCVTZS/ FCVTZU */
8564 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
8567 unallocated_encoding(s
);
8572 /* Generate code to do a "long" addition or subtraction, ie one done in
8573 * TCGv_i64 on vector lanes twice the width specified by size.
8575 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
8576 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
8578 static NeonGenTwo64OpFn
* const fns
[3][2] = {
8579 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
8580 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
8581 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
8583 NeonGenTwo64OpFn
*genfn
;
8586 genfn
= fns
[size
][is_sub
];
8587 genfn(tcg_res
, tcg_op1
, tcg_op2
);
8590 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
8591 int opcode
, int rd
, int rn
, int rm
)
8593 /* 3-reg-different widening insns: 64 x 64 -> 128 */
8594 TCGv_i64 tcg_res
[2];
8597 tcg_res
[0] = tcg_temp_new_i64();
8598 tcg_res
[1] = tcg_temp_new_i64();
8600 /* Does this op do an adding accumulate, a subtracting accumulate,
8601 * or no accumulate at all?
8619 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8620 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8623 /* size == 2 means two 32x32->64 operations; this is worth special
8624 * casing because we can generally handle it inline.
8627 for (pass
= 0; pass
< 2; pass
++) {
8628 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8629 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8630 TCGv_i64 tcg_passres
;
8631 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
8633 int elt
= pass
+ is_q
* 2;
8635 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
8636 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
8639 tcg_passres
= tcg_res
[pass
];
8641 tcg_passres
= tcg_temp_new_i64();
8645 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8646 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8648 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8649 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8651 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8652 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8654 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
8655 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
8657 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
8658 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
8659 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
8661 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
8662 tcg_temp_free_i64(tcg_tmp1
);
8663 tcg_temp_free_i64(tcg_tmp2
);
8666 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8667 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8668 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8669 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8671 case 9: /* SQDMLAL, SQDMLAL2 */
8672 case 11: /* SQDMLSL, SQDMLSL2 */
8673 case 13: /* SQDMULL, SQDMULL2 */
8674 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8675 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
8676 tcg_passres
, tcg_passres
);
8679 g_assert_not_reached();
8682 if (opcode
== 9 || opcode
== 11) {
8683 /* saturating accumulate ops */
8685 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
8687 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
8688 tcg_res
[pass
], tcg_passres
);
8689 } else if (accop
> 0) {
8690 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8691 } else if (accop
< 0) {
8692 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8696 tcg_temp_free_i64(tcg_passres
);
8699 tcg_temp_free_i64(tcg_op1
);
8700 tcg_temp_free_i64(tcg_op2
);
8703 /* size 0 or 1, generally helper functions */
8704 for (pass
= 0; pass
< 2; pass
++) {
8705 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8706 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8707 TCGv_i64 tcg_passres
;
8708 int elt
= pass
+ is_q
* 2;
8710 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
8711 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
8714 tcg_passres
= tcg_res
[pass
];
8716 tcg_passres
= tcg_temp_new_i64();
8720 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8721 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8723 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
8724 static NeonGenWidenFn
* const widenfns
[2][2] = {
8725 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8726 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8728 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8730 widenfn(tcg_op2_64
, tcg_op2
);
8731 widenfn(tcg_passres
, tcg_op1
);
8732 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
8733 tcg_passres
, tcg_op2_64
);
8734 tcg_temp_free_i64(tcg_op2_64
);
8737 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8738 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8741 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8743 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8747 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
8749 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
8753 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8754 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8755 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8758 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
8760 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
8764 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8766 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8770 case 9: /* SQDMLAL, SQDMLAL2 */
8771 case 11: /* SQDMLSL, SQDMLSL2 */
8772 case 13: /* SQDMULL, SQDMULL2 */
8774 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8775 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
8776 tcg_passres
, tcg_passres
);
8778 case 14: /* PMULL */
8780 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
8783 g_assert_not_reached();
8785 tcg_temp_free_i32(tcg_op1
);
8786 tcg_temp_free_i32(tcg_op2
);
8789 if (opcode
== 9 || opcode
== 11) {
8790 /* saturating accumulate ops */
8792 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
8794 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
8798 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
8799 tcg_res
[pass
], tcg_passres
);
8801 tcg_temp_free_i64(tcg_passres
);
8806 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8807 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8808 tcg_temp_free_i64(tcg_res
[0]);
8809 tcg_temp_free_i64(tcg_res
[1]);
8812 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
8813 int opcode
, int rd
, int rn
, int rm
)
8815 TCGv_i64 tcg_res
[2];
8816 int part
= is_q
? 2 : 0;
8819 for (pass
= 0; pass
< 2; pass
++) {
8820 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8821 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8822 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
8823 static NeonGenWidenFn
* const widenfns
[3][2] = {
8824 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8825 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8826 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
8828 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8830 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8831 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
8832 widenfn(tcg_op2_wide
, tcg_op2
);
8833 tcg_temp_free_i32(tcg_op2
);
8834 tcg_res
[pass
] = tcg_temp_new_i64();
8835 gen_neon_addl(size
, (opcode
== 3),
8836 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
8837 tcg_temp_free_i64(tcg_op1
);
8838 tcg_temp_free_i64(tcg_op2_wide
);
8841 for (pass
= 0; pass
< 2; pass
++) {
8842 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8843 tcg_temp_free_i64(tcg_res
[pass
]);
8847 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8849 tcg_gen_addi_i64(in
, in
, 1U << 31);
8850 tcg_gen_extrh_i64_i32(res
, in
);
8853 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
8854 int opcode
, int rd
, int rn
, int rm
)
8856 TCGv_i32 tcg_res
[2];
8857 int part
= is_q
? 2 : 0;
8860 for (pass
= 0; pass
< 2; pass
++) {
8861 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8862 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8863 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
8864 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
8865 { gen_helper_neon_narrow_high_u8
,
8866 gen_helper_neon_narrow_round_high_u8
},
8867 { gen_helper_neon_narrow_high_u16
,
8868 gen_helper_neon_narrow_round_high_u16
},
8869 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
8871 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
8873 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8874 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8876 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
8878 tcg_temp_free_i64(tcg_op1
);
8879 tcg_temp_free_i64(tcg_op2
);
8881 tcg_res
[pass
] = tcg_temp_new_i32();
8882 gennarrow(tcg_res
[pass
], tcg_wideres
);
8883 tcg_temp_free_i64(tcg_wideres
);
8886 for (pass
= 0; pass
< 2; pass
++) {
8887 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
8888 tcg_temp_free_i32(tcg_res
[pass
]);
8891 clear_vec_high(s
, rd
);
8895 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
8897 /* PMULL of 64 x 64 -> 128 is an odd special case because it
8898 * is the only three-reg-diff instruction which produces a
8899 * 128-bit wide result from a single operation. However since
8900 * it's possible to calculate the two halves more or less
8901 * separately we just use two helper calls.
8903 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8904 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8905 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8907 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
8908 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
8909 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
8910 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
8911 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
8912 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
8914 tcg_temp_free_i64(tcg_op1
);
8915 tcg_temp_free_i64(tcg_op2
);
8916 tcg_temp_free_i64(tcg_res
);
8919 /* C3.6.15 AdvSIMD three different
8920 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8921 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8922 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8923 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8925 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8927 /* Instructions in this group fall into three basic classes
8928 * (in each case with the operation working on each element in
8929 * the input vectors):
8930 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
8932 * (2) wide 64 x 128 -> 128
8933 * (3) narrowing 128 x 128 -> 64
8934 * Here we do initial decode, catch unallocated cases and
8935 * dispatch to separate functions for each class.
8937 int is_q
= extract32(insn
, 30, 1);
8938 int is_u
= extract32(insn
, 29, 1);
8939 int size
= extract32(insn
, 22, 2);
8940 int opcode
= extract32(insn
, 12, 4);
8941 int rm
= extract32(insn
, 16, 5);
8942 int rn
= extract32(insn
, 5, 5);
8943 int rd
= extract32(insn
, 0, 5);
8946 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
8947 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
8948 /* 64 x 128 -> 128 */
8950 unallocated_encoding(s
);
8953 if (!fp_access_check(s
)) {
8956 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8958 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
8959 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
8960 /* 128 x 128 -> 64 */
8962 unallocated_encoding(s
);
8965 if (!fp_access_check(s
)) {
8968 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8970 case 14: /* PMULL, PMULL2 */
8971 if (is_u
|| size
== 1 || size
== 2) {
8972 unallocated_encoding(s
);
8976 if (!arm_dc_feature(s
, ARM_FEATURE_V8_PMULL
)) {
8977 unallocated_encoding(s
);
8980 if (!fp_access_check(s
)) {
8983 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
8987 case 9: /* SQDMLAL, SQDMLAL2 */
8988 case 11: /* SQDMLSL, SQDMLSL2 */
8989 case 13: /* SQDMULL, SQDMULL2 */
8990 if (is_u
|| size
== 0) {
8991 unallocated_encoding(s
);
8995 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8996 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8997 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8998 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8999 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
9000 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
9001 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
9002 /* 64 x 64 -> 128 */
9004 unallocated_encoding(s
);
9008 if (!fp_access_check(s
)) {
9012 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
9015 /* opcode 15 not allocated */
9016 unallocated_encoding(s
);
9021 /* Logic op (opcode == 3) subgroup of C3.6.16. */
9022 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
9024 int rd
= extract32(insn
, 0, 5);
9025 int rn
= extract32(insn
, 5, 5);
9026 int rm
= extract32(insn
, 16, 5);
9027 int size
= extract32(insn
, 22, 2);
9028 bool is_u
= extract32(insn
, 29, 1);
9029 bool is_q
= extract32(insn
, 30, 1);
9030 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
9033 if (!fp_access_check(s
)) {
9037 tcg_op1
= tcg_temp_new_i64();
9038 tcg_op2
= tcg_temp_new_i64();
9039 tcg_res
[0] = tcg_temp_new_i64();
9040 tcg_res
[1] = tcg_temp_new_i64();
9042 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
9043 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9044 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9049 tcg_gen_and_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9052 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9055 tcg_gen_or_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9058 tcg_gen_orc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9063 /* B* ops need res loaded to operate on */
9064 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9069 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9071 case 1: /* BSL bitwise select */
9072 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_op2
);
9073 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
9074 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op1
);
9076 case 2: /* BIT, bitwise insert if true */
9077 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
9078 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_op2
);
9079 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9081 case 3: /* BIF, bitwise insert if false */
9082 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
9083 tcg_gen_andc_i64(tcg_op1
, tcg_op1
, tcg_op2
);
9084 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9090 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
9092 tcg_gen_movi_i64(tcg_res
[1], 0);
9094 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
9096 tcg_temp_free_i64(tcg_op1
);
9097 tcg_temp_free_i64(tcg_op2
);
9098 tcg_temp_free_i64(tcg_res
[0]);
9099 tcg_temp_free_i64(tcg_res
[1]);
9102 /* Helper functions for 32 bit comparisons */
9103 static void gen_max_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
9105 tcg_gen_movcond_i32(TCG_COND_GE
, res
, op1
, op2
, op1
, op2
);
9108 static void gen_max_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
9110 tcg_gen_movcond_i32(TCG_COND_GEU
, res
, op1
, op2
, op1
, op2
);
9113 static void gen_min_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
9115 tcg_gen_movcond_i32(TCG_COND_LE
, res
, op1
, op2
, op1
, op2
);
9118 static void gen_min_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
9120 tcg_gen_movcond_i32(TCG_COND_LEU
, res
, op1
, op2
, op1
, op2
);
9123 /* Pairwise op subgroup of C3.6.16.
9125 * This is called directly or via the handle_3same_float for float pairwise
9126 * operations where the opcode and size are calculated differently.
9128 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
9129 int size
, int rn
, int rm
, int rd
)
9134 /* Floating point operations need fpst */
9135 if (opcode
>= 0x58) {
9136 fpst
= get_fpstatus_ptr();
9138 TCGV_UNUSED_PTR(fpst
);
9141 if (!fp_access_check(s
)) {
9145 /* These operations work on the concatenated rm:rn, with each pair of
9146 * adjacent elements being operated on to produce an element in the result.
9149 TCGv_i64 tcg_res
[2];
9151 for (pass
= 0; pass
< 2; pass
++) {
9152 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9153 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9154 int passreg
= (pass
== 0) ? rn
: rm
;
9156 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
9157 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
9158 tcg_res
[pass
] = tcg_temp_new_i64();
9161 case 0x17: /* ADDP */
9162 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9164 case 0x58: /* FMAXNMP */
9165 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9167 case 0x5a: /* FADDP */
9168 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9170 case 0x5e: /* FMAXP */
9171 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9173 case 0x78: /* FMINNMP */
9174 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9176 case 0x7e: /* FMINP */
9177 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9180 g_assert_not_reached();
9183 tcg_temp_free_i64(tcg_op1
);
9184 tcg_temp_free_i64(tcg_op2
);
9187 for (pass
= 0; pass
< 2; pass
++) {
9188 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9189 tcg_temp_free_i64(tcg_res
[pass
]);
9192 int maxpass
= is_q
? 4 : 2;
9193 TCGv_i32 tcg_res
[4];
9195 for (pass
= 0; pass
< maxpass
; pass
++) {
9196 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9197 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9198 NeonGenTwoOpFn
*genfn
= NULL
;
9199 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
9200 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
9202 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
9203 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
9204 tcg_res
[pass
] = tcg_temp_new_i32();
9207 case 0x17: /* ADDP */
9209 static NeonGenTwoOpFn
* const fns
[3] = {
9210 gen_helper_neon_padd_u8
,
9211 gen_helper_neon_padd_u16
,
9217 case 0x14: /* SMAXP, UMAXP */
9219 static NeonGenTwoOpFn
* const fns
[3][2] = {
9220 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
9221 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
9222 { gen_max_s32
, gen_max_u32
},
9224 genfn
= fns
[size
][u
];
9227 case 0x15: /* SMINP, UMINP */
9229 static NeonGenTwoOpFn
* const fns
[3][2] = {
9230 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
9231 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
9232 { gen_min_s32
, gen_min_u32
},
9234 genfn
= fns
[size
][u
];
9237 /* The FP operations are all on single floats (32 bit) */
9238 case 0x58: /* FMAXNMP */
9239 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9241 case 0x5a: /* FADDP */
9242 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9244 case 0x5e: /* FMAXP */
9245 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9247 case 0x78: /* FMINNMP */
9248 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9250 case 0x7e: /* FMINP */
9251 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9254 g_assert_not_reached();
9257 /* FP ops called directly, otherwise call now */
9259 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9262 tcg_temp_free_i32(tcg_op1
);
9263 tcg_temp_free_i32(tcg_op2
);
9266 for (pass
= 0; pass
< maxpass
; pass
++) {
9267 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9268 tcg_temp_free_i32(tcg_res
[pass
]);
9271 clear_vec_high(s
, rd
);
9275 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
9276 tcg_temp_free_ptr(fpst
);
9280 /* Floating point op subgroup of C3.6.16. */
9281 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
9283 /* For floating point ops, the U, size[1] and opcode bits
9284 * together indicate the operation. size[0] indicates single
9287 int fpopcode
= extract32(insn
, 11, 5)
9288 | (extract32(insn
, 23, 1) << 5)
9289 | (extract32(insn
, 29, 1) << 6);
9290 int is_q
= extract32(insn
, 30, 1);
9291 int size
= extract32(insn
, 22, 1);
9292 int rm
= extract32(insn
, 16, 5);
9293 int rn
= extract32(insn
, 5, 5);
9294 int rd
= extract32(insn
, 0, 5);
9296 int datasize
= is_q
? 128 : 64;
9297 int esize
= 32 << size
;
9298 int elements
= datasize
/ esize
;
9300 if (size
== 1 && !is_q
) {
9301 unallocated_encoding(s
);
9306 case 0x58: /* FMAXNMP */
9307 case 0x5a: /* FADDP */
9308 case 0x5e: /* FMAXP */
9309 case 0x78: /* FMINNMP */
9310 case 0x7e: /* FMINP */
9311 if (size
&& !is_q
) {
9312 unallocated_encoding(s
);
9315 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
9318 case 0x1b: /* FMULX */
9319 case 0x1f: /* FRECPS */
9320 case 0x3f: /* FRSQRTS */
9321 case 0x5d: /* FACGE */
9322 case 0x7d: /* FACGT */
9323 case 0x19: /* FMLA */
9324 case 0x39: /* FMLS */
9325 case 0x18: /* FMAXNM */
9326 case 0x1a: /* FADD */
9327 case 0x1c: /* FCMEQ */
9328 case 0x1e: /* FMAX */
9329 case 0x38: /* FMINNM */
9330 case 0x3a: /* FSUB */
9331 case 0x3e: /* FMIN */
9332 case 0x5b: /* FMUL */
9333 case 0x5c: /* FCMGE */
9334 case 0x5f: /* FDIV */
9335 case 0x7a: /* FABD */
9336 case 0x7c: /* FCMGT */
9337 if (!fp_access_check(s
)) {
9341 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
9344 unallocated_encoding(s
);
9349 /* Integer op subgroup of C3.6.16. */
9350 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
9352 int is_q
= extract32(insn
, 30, 1);
9353 int u
= extract32(insn
, 29, 1);
9354 int size
= extract32(insn
, 22, 2);
9355 int opcode
= extract32(insn
, 11, 5);
9356 int rm
= extract32(insn
, 16, 5);
9357 int rn
= extract32(insn
, 5, 5);
9358 int rd
= extract32(insn
, 0, 5);
9362 case 0x13: /* MUL, PMUL */
9363 if (u
&& size
!= 0) {
9364 unallocated_encoding(s
);
9368 case 0x0: /* SHADD, UHADD */
9369 case 0x2: /* SRHADD, URHADD */
9370 case 0x4: /* SHSUB, UHSUB */
9371 case 0xc: /* SMAX, UMAX */
9372 case 0xd: /* SMIN, UMIN */
9373 case 0xe: /* SABD, UABD */
9374 case 0xf: /* SABA, UABA */
9375 case 0x12: /* MLA, MLS */
9377 unallocated_encoding(s
);
9381 case 0x16: /* SQDMULH, SQRDMULH */
9382 if (size
== 0 || size
== 3) {
9383 unallocated_encoding(s
);
9388 if (size
== 3 && !is_q
) {
9389 unallocated_encoding(s
);
9395 if (!fp_access_check(s
)) {
9401 for (pass
= 0; pass
< 2; pass
++) {
9402 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9403 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9404 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9406 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9407 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9409 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
9411 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9413 tcg_temp_free_i64(tcg_res
);
9414 tcg_temp_free_i64(tcg_op1
);
9415 tcg_temp_free_i64(tcg_op2
);
9418 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9419 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9420 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9421 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9422 NeonGenTwoOpFn
*genfn
= NULL
;
9423 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
9425 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
9426 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
9429 case 0x0: /* SHADD, UHADD */
9431 static NeonGenTwoOpFn
* const fns
[3][2] = {
9432 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
9433 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
9434 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
9436 genfn
= fns
[size
][u
];
9439 case 0x1: /* SQADD, UQADD */
9441 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9442 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9443 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9444 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9446 genenvfn
= fns
[size
][u
];
9449 case 0x2: /* SRHADD, URHADD */
9451 static NeonGenTwoOpFn
* const fns
[3][2] = {
9452 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
9453 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
9454 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
9456 genfn
= fns
[size
][u
];
9459 case 0x4: /* SHSUB, UHSUB */
9461 static NeonGenTwoOpFn
* const fns
[3][2] = {
9462 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
9463 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
9464 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
9466 genfn
= fns
[size
][u
];
9469 case 0x5: /* SQSUB, UQSUB */
9471 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9472 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9473 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9474 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9476 genenvfn
= fns
[size
][u
];
9479 case 0x6: /* CMGT, CMHI */
9481 static NeonGenTwoOpFn
* const fns
[3][2] = {
9482 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_u8
},
9483 { gen_helper_neon_cgt_s16
, gen_helper_neon_cgt_u16
},
9484 { gen_helper_neon_cgt_s32
, gen_helper_neon_cgt_u32
},
9486 genfn
= fns
[size
][u
];
9489 case 0x7: /* CMGE, CMHS */
9491 static NeonGenTwoOpFn
* const fns
[3][2] = {
9492 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_u8
},
9493 { gen_helper_neon_cge_s16
, gen_helper_neon_cge_u16
},
9494 { gen_helper_neon_cge_s32
, gen_helper_neon_cge_u32
},
9496 genfn
= fns
[size
][u
];
9499 case 0x8: /* SSHL, USHL */
9501 static NeonGenTwoOpFn
* const fns
[3][2] = {
9502 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
9503 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
9504 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
9506 genfn
= fns
[size
][u
];
9509 case 0x9: /* SQSHL, UQSHL */
9511 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9512 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9513 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9514 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9516 genenvfn
= fns
[size
][u
];
9519 case 0xa: /* SRSHL, URSHL */
9521 static NeonGenTwoOpFn
* const fns
[3][2] = {
9522 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
9523 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
9524 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
9526 genfn
= fns
[size
][u
];
9529 case 0xb: /* SQRSHL, UQRSHL */
9531 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9532 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9533 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9534 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9536 genenvfn
= fns
[size
][u
];
9539 case 0xc: /* SMAX, UMAX */
9541 static NeonGenTwoOpFn
* const fns
[3][2] = {
9542 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
9543 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
9544 { gen_max_s32
, gen_max_u32
},
9546 genfn
= fns
[size
][u
];
9550 case 0xd: /* SMIN, UMIN */
9552 static NeonGenTwoOpFn
* const fns
[3][2] = {
9553 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
9554 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
9555 { gen_min_s32
, gen_min_u32
},
9557 genfn
= fns
[size
][u
];
9560 case 0xe: /* SABD, UABD */
9561 case 0xf: /* SABA, UABA */
9563 static NeonGenTwoOpFn
* const fns
[3][2] = {
9564 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
9565 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
9566 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
9568 genfn
= fns
[size
][u
];
9571 case 0x10: /* ADD, SUB */
9573 static NeonGenTwoOpFn
* const fns
[3][2] = {
9574 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9575 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9576 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9578 genfn
= fns
[size
][u
];
9581 case 0x11: /* CMTST, CMEQ */
9583 static NeonGenTwoOpFn
* const fns
[3][2] = {
9584 { gen_helper_neon_tst_u8
, gen_helper_neon_ceq_u8
},
9585 { gen_helper_neon_tst_u16
, gen_helper_neon_ceq_u16
},
9586 { gen_helper_neon_tst_u32
, gen_helper_neon_ceq_u32
},
9588 genfn
= fns
[size
][u
];
9591 case 0x13: /* MUL, PMUL */
9595 genfn
= gen_helper_neon_mul_p8
;
9598 /* fall through : MUL */
9599 case 0x12: /* MLA, MLS */
9601 static NeonGenTwoOpFn
* const fns
[3] = {
9602 gen_helper_neon_mul_u8
,
9603 gen_helper_neon_mul_u16
,
9609 case 0x16: /* SQDMULH, SQRDMULH */
9611 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9612 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9613 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9615 assert(size
== 1 || size
== 2);
9616 genenvfn
= fns
[size
- 1][u
];
9620 g_assert_not_reached();
9624 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
9626 genfn(tcg_res
, tcg_op1
, tcg_op2
);
9629 if (opcode
== 0xf || opcode
== 0x12) {
9630 /* SABA, UABA, MLA, MLS: accumulating ops */
9631 static NeonGenTwoOpFn
* const fns
[3][2] = {
9632 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9633 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9634 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9636 bool is_sub
= (opcode
== 0x12 && u
); /* MLS */
9638 genfn
= fns
[size
][is_sub
];
9639 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
9640 genfn(tcg_res
, tcg_op1
, tcg_res
);
9643 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9645 tcg_temp_free_i32(tcg_res
);
9646 tcg_temp_free_i32(tcg_op1
);
9647 tcg_temp_free_i32(tcg_op2
);
9652 clear_vec_high(s
, rd
);
9656 /* C3.6.16 AdvSIMD three same
9657 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
9658 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9659 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
9660 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9662 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
9664 int opcode
= extract32(insn
, 11, 5);
9667 case 0x3: /* logic ops */
9668 disas_simd_3same_logic(s
, insn
);
9670 case 0x17: /* ADDP */
9671 case 0x14: /* SMAXP, UMAXP */
9672 case 0x15: /* SMINP, UMINP */
9674 /* Pairwise operations */
9675 int is_q
= extract32(insn
, 30, 1);
9676 int u
= extract32(insn
, 29, 1);
9677 int size
= extract32(insn
, 22, 2);
9678 int rm
= extract32(insn
, 16, 5);
9679 int rn
= extract32(insn
, 5, 5);
9680 int rd
= extract32(insn
, 0, 5);
9681 if (opcode
== 0x17) {
9682 if (u
|| (size
== 3 && !is_q
)) {
9683 unallocated_encoding(s
);
9688 unallocated_encoding(s
);
9692 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
9696 /* floating point ops, sz[1] and U are part of opcode */
9697 disas_simd_3same_float(s
, insn
);
9700 disas_simd_3same_int(s
, insn
);
9705 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
9706 int size
, int rn
, int rd
)
9708 /* Handle 2-reg-misc ops which are widening (so each size element
9709 * in the source becomes a 2*size element in the destination.
9710 * The only instruction like this is FCVTL.
9715 /* 32 -> 64 bit fp conversion */
9716 TCGv_i64 tcg_res
[2];
9717 int srcelt
= is_q
? 2 : 0;
9719 for (pass
= 0; pass
< 2; pass
++) {
9720 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9721 tcg_res
[pass
] = tcg_temp_new_i64();
9723 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
9724 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
9725 tcg_temp_free_i32(tcg_op
);
9727 for (pass
= 0; pass
< 2; pass
++) {
9728 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9729 tcg_temp_free_i64(tcg_res
[pass
]);
9732 /* 16 -> 32 bit fp conversion */
9733 int srcelt
= is_q
? 4 : 0;
9734 TCGv_i32 tcg_res
[4];
9736 for (pass
= 0; pass
< 4; pass
++) {
9737 tcg_res
[pass
] = tcg_temp_new_i32();
9739 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
9740 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
9743 for (pass
= 0; pass
< 4; pass
++) {
9744 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9745 tcg_temp_free_i32(tcg_res
[pass
]);
9750 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
9751 bool is_q
, int size
, int rn
, int rd
)
9753 int op
= (opcode
<< 1) | u
;
9754 int opsz
= op
+ size
;
9755 int grp_size
= 3 - opsz
;
9756 int dsize
= is_q
? 128 : 64;
9760 unallocated_encoding(s
);
9764 if (!fp_access_check(s
)) {
9769 /* Special case bytes, use bswap op on each group of elements */
9770 int groups
= dsize
/ (8 << grp_size
);
9772 for (i
= 0; i
< groups
; i
++) {
9773 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9775 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
9778 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
9781 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
9784 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
9787 g_assert_not_reached();
9789 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
9790 tcg_temp_free_i64(tcg_tmp
);
9793 clear_vec_high(s
, rd
);
9796 int revmask
= (1 << grp_size
) - 1;
9797 int esize
= 8 << size
;
9798 int elements
= dsize
/ esize
;
9799 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9800 TCGv_i64 tcg_rd
= tcg_const_i64(0);
9801 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
9803 for (i
= 0; i
< elements
; i
++) {
9804 int e_rev
= (i
& 0xf) ^ revmask
;
9805 int off
= e_rev
* esize
;
9806 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
9808 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
9809 tcg_rn
, off
- 64, esize
);
9811 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
9814 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
9815 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
9817 tcg_temp_free_i64(tcg_rd_hi
);
9818 tcg_temp_free_i64(tcg_rd
);
9819 tcg_temp_free_i64(tcg_rn
);
9823 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
9824 bool is_q
, int size
, int rn
, int rd
)
9826 /* Implement the pairwise operations from 2-misc:
9827 * SADDLP, UADDLP, SADALP, UADALP.
9828 * These all add pairs of elements in the input to produce a
9829 * double-width result element in the output (possibly accumulating).
9831 bool accum
= (opcode
== 0x6);
9832 int maxpass
= is_q
? 2 : 1;
9834 TCGv_i64 tcg_res
[2];
9837 /* 32 + 32 -> 64 op */
9838 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
9840 for (pass
= 0; pass
< maxpass
; pass
++) {
9841 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9842 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9844 tcg_res
[pass
] = tcg_temp_new_i64();
9846 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
9847 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
9848 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9850 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
9851 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9854 tcg_temp_free_i64(tcg_op1
);
9855 tcg_temp_free_i64(tcg_op2
);
9858 for (pass
= 0; pass
< maxpass
; pass
++) {
9859 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9860 NeonGenOneOpFn
*genfn
;
9861 static NeonGenOneOpFn
* const fns
[2][2] = {
9862 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
9863 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
9866 genfn
= fns
[size
][u
];
9868 tcg_res
[pass
] = tcg_temp_new_i64();
9870 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9871 genfn(tcg_res
[pass
], tcg_op
);
9874 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
9876 gen_helper_neon_addl_u16(tcg_res
[pass
],
9877 tcg_res
[pass
], tcg_op
);
9879 gen_helper_neon_addl_u32(tcg_res
[pass
],
9880 tcg_res
[pass
], tcg_op
);
9883 tcg_temp_free_i64(tcg_op
);
9887 tcg_res
[1] = tcg_const_i64(0);
9889 for (pass
= 0; pass
< 2; pass
++) {
9890 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9891 tcg_temp_free_i64(tcg_res
[pass
]);
9895 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
9897 /* Implement SHLL and SHLL2 */
9899 int part
= is_q
? 2 : 0;
9900 TCGv_i64 tcg_res
[2];
9902 for (pass
= 0; pass
< 2; pass
++) {
9903 static NeonGenWidenFn
* const widenfns
[3] = {
9904 gen_helper_neon_widen_u8
,
9905 gen_helper_neon_widen_u16
,
9906 tcg_gen_extu_i32_i64
,
9908 NeonGenWidenFn
*widenfn
= widenfns
[size
];
9909 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9911 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
9912 tcg_res
[pass
] = tcg_temp_new_i64();
9913 widenfn(tcg_res
[pass
], tcg_op
);
9914 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
9916 tcg_temp_free_i32(tcg_op
);
9919 for (pass
= 0; pass
< 2; pass
++) {
9920 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9921 tcg_temp_free_i64(tcg_res
[pass
]);
9925 /* C3.6.17 AdvSIMD two reg misc
9926 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9927 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9928 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9929 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9931 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9933 int size
= extract32(insn
, 22, 2);
9934 int opcode
= extract32(insn
, 12, 5);
9935 bool u
= extract32(insn
, 29, 1);
9936 bool is_q
= extract32(insn
, 30, 1);
9937 int rn
= extract32(insn
, 5, 5);
9938 int rd
= extract32(insn
, 0, 5);
9939 bool need_fpstatus
= false;
9940 bool need_rmode
= false;
9943 TCGv_ptr tcg_fpstatus
;
9946 case 0x0: /* REV64, REV32 */
9947 case 0x1: /* REV16 */
9948 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9950 case 0x5: /* CNT, NOT, RBIT */
9951 if (u
&& size
== 0) {
9952 /* NOT: adjust size so we can use the 64-bits-at-a-time loop. */
9955 } else if (u
&& size
== 1) {
9958 } else if (!u
&& size
== 0) {
9962 unallocated_encoding(s
);
9964 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
9965 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
9967 unallocated_encoding(s
);
9970 if (!fp_access_check(s
)) {
9974 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
9976 case 0x4: /* CLS, CLZ */
9978 unallocated_encoding(s
);
9982 case 0x2: /* SADDLP, UADDLP */
9983 case 0x6: /* SADALP, UADALP */
9985 unallocated_encoding(s
);
9988 if (!fp_access_check(s
)) {
9991 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9993 case 0x13: /* SHLL, SHLL2 */
9994 if (u
== 0 || size
== 3) {
9995 unallocated_encoding(s
);
9998 if (!fp_access_check(s
)) {
10001 handle_shll(s
, is_q
, size
, rn
, rd
);
10003 case 0xa: /* CMLT */
10005 unallocated_encoding(s
);
10009 case 0x8: /* CMGT, CMGE */
10010 case 0x9: /* CMEQ, CMLE */
10011 case 0xb: /* ABS, NEG */
10012 if (size
== 3 && !is_q
) {
10013 unallocated_encoding(s
);
10017 case 0x3: /* SUQADD, USQADD */
10018 if (size
== 3 && !is_q
) {
10019 unallocated_encoding(s
);
10022 if (!fp_access_check(s
)) {
10025 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
10027 case 0x7: /* SQABS, SQNEG */
10028 if (size
== 3 && !is_q
) {
10029 unallocated_encoding(s
);
10034 case 0x16 ... 0x1d:
10037 /* Floating point: U, size[1] and opcode indicate operation;
10038 * size[0] indicates single or double precision.
10040 int is_double
= extract32(size
, 0, 1);
10041 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
10042 size
= is_double
? 3 : 2;
10044 case 0x2f: /* FABS */
10045 case 0x6f: /* FNEG */
10046 if (size
== 3 && !is_q
) {
10047 unallocated_encoding(s
);
10051 case 0x1d: /* SCVTF */
10052 case 0x5d: /* UCVTF */
10054 bool is_signed
= (opcode
== 0x1d) ? true : false;
10055 int elements
= is_double
? 2 : is_q
? 4 : 2;
10056 if (is_double
&& !is_q
) {
10057 unallocated_encoding(s
);
10060 if (!fp_access_check(s
)) {
10063 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
10066 case 0x2c: /* FCMGT (zero) */
10067 case 0x2d: /* FCMEQ (zero) */
10068 case 0x2e: /* FCMLT (zero) */
10069 case 0x6c: /* FCMGE (zero) */
10070 case 0x6d: /* FCMLE (zero) */
10071 if (size
== 3 && !is_q
) {
10072 unallocated_encoding(s
);
10075 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
10077 case 0x7f: /* FSQRT */
10078 if (size
== 3 && !is_q
) {
10079 unallocated_encoding(s
);
10083 case 0x1a: /* FCVTNS */
10084 case 0x1b: /* FCVTMS */
10085 case 0x3a: /* FCVTPS */
10086 case 0x3b: /* FCVTZS */
10087 case 0x5a: /* FCVTNU */
10088 case 0x5b: /* FCVTMU */
10089 case 0x7a: /* FCVTPU */
10090 case 0x7b: /* FCVTZU */
10091 need_fpstatus
= true;
10093 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
10094 if (size
== 3 && !is_q
) {
10095 unallocated_encoding(s
);
10099 case 0x5c: /* FCVTAU */
10100 case 0x1c: /* FCVTAS */
10101 need_fpstatus
= true;
10103 rmode
= FPROUNDING_TIEAWAY
;
10104 if (size
== 3 && !is_q
) {
10105 unallocated_encoding(s
);
10109 case 0x3c: /* URECPE */
10111 unallocated_encoding(s
);
10115 case 0x3d: /* FRECPE */
10116 case 0x7d: /* FRSQRTE */
10117 if (size
== 3 && !is_q
) {
10118 unallocated_encoding(s
);
10121 if (!fp_access_check(s
)) {
10124 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
10126 case 0x56: /* FCVTXN, FCVTXN2 */
10128 unallocated_encoding(s
);
10132 case 0x16: /* FCVTN, FCVTN2 */
10133 /* handle_2misc_narrow does a 2*size -> size operation, but these
10134 * instructions encode the source size rather than dest size.
10136 if (!fp_access_check(s
)) {
10139 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
10141 case 0x17: /* FCVTL, FCVTL2 */
10142 if (!fp_access_check(s
)) {
10145 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
10147 case 0x18: /* FRINTN */
10148 case 0x19: /* FRINTM */
10149 case 0x38: /* FRINTP */
10150 case 0x39: /* FRINTZ */
10152 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
10154 case 0x59: /* FRINTX */
10155 case 0x79: /* FRINTI */
10156 need_fpstatus
= true;
10157 if (size
== 3 && !is_q
) {
10158 unallocated_encoding(s
);
10162 case 0x58: /* FRINTA */
10164 rmode
= FPROUNDING_TIEAWAY
;
10165 need_fpstatus
= true;
10166 if (size
== 3 && !is_q
) {
10167 unallocated_encoding(s
);
10171 case 0x7c: /* URSQRTE */
10173 unallocated_encoding(s
);
10176 need_fpstatus
= true;
10179 unallocated_encoding(s
);
10185 unallocated_encoding(s
);
10189 if (!fp_access_check(s
)) {
10193 if (need_fpstatus
) {
10194 tcg_fpstatus
= get_fpstatus_ptr();
10196 TCGV_UNUSED_PTR(tcg_fpstatus
);
10199 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
10200 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10202 TCGV_UNUSED_I32(tcg_rmode
);
10206 /* All 64-bit element operations can be shared with scalar 2misc */
10209 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
10210 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10211 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10213 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10215 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
10216 tcg_rmode
, tcg_fpstatus
);
10218 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10220 tcg_temp_free_i64(tcg_res
);
10221 tcg_temp_free_i64(tcg_op
);
10226 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
10227 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10228 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10231 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
10234 /* Special cases for 32 bit elements */
10236 case 0xa: /* CMLT */
10237 /* 32 bit integer comparison against zero, result is
10238 * test ? (2^32 - 1) : 0. We implement via setcond(test)
10241 cond
= TCG_COND_LT
;
10243 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
10244 tcg_gen_neg_i32(tcg_res
, tcg_res
);
10246 case 0x8: /* CMGT, CMGE */
10247 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
10249 case 0x9: /* CMEQ, CMLE */
10250 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
10252 case 0x4: /* CLS */
10254 tcg_gen_clzi_i32(tcg_res
, tcg_op
, 32);
10256 tcg_gen_clrsb_i32(tcg_res
, tcg_op
);
10259 case 0x7: /* SQABS, SQNEG */
10261 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
10263 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
10266 case 0xb: /* ABS, NEG */
10268 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10270 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10271 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10272 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
10273 tcg_zero
, tcg_op
, tcg_res
);
10274 tcg_temp_free_i32(tcg_zero
);
10277 case 0x2f: /* FABS */
10278 gen_helper_vfp_abss(tcg_res
, tcg_op
);
10280 case 0x6f: /* FNEG */
10281 gen_helper_vfp_negs(tcg_res
, tcg_op
);
10283 case 0x7f: /* FSQRT */
10284 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
10286 case 0x1a: /* FCVTNS */
10287 case 0x1b: /* FCVTMS */
10288 case 0x1c: /* FCVTAS */
10289 case 0x3a: /* FCVTPS */
10290 case 0x3b: /* FCVTZS */
10292 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10293 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
10294 tcg_shift
, tcg_fpstatus
);
10295 tcg_temp_free_i32(tcg_shift
);
10298 case 0x5a: /* FCVTNU */
10299 case 0x5b: /* FCVTMU */
10300 case 0x5c: /* FCVTAU */
10301 case 0x7a: /* FCVTPU */
10302 case 0x7b: /* FCVTZU */
10304 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10305 gen_helper_vfp_touls(tcg_res
, tcg_op
,
10306 tcg_shift
, tcg_fpstatus
);
10307 tcg_temp_free_i32(tcg_shift
);
10310 case 0x18: /* FRINTN */
10311 case 0x19: /* FRINTM */
10312 case 0x38: /* FRINTP */
10313 case 0x39: /* FRINTZ */
10314 case 0x58: /* FRINTA */
10315 case 0x79: /* FRINTI */
10316 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
10318 case 0x59: /* FRINTX */
10319 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
10321 case 0x7c: /* URSQRTE */
10322 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
10325 g_assert_not_reached();
10328 /* Use helpers for 8 and 16 bit elements */
10330 case 0x5: /* CNT, RBIT */
10331 /* For these two insns size is part of the opcode specifier
10332 * (handled earlier); they always operate on byte elements.
10335 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
10337 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
10340 case 0x7: /* SQABS, SQNEG */
10342 NeonGenOneOpEnvFn
*genfn
;
10343 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
10344 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
10345 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
10347 genfn
= fns
[size
][u
];
10348 genfn(tcg_res
, cpu_env
, tcg_op
);
10351 case 0x8: /* CMGT, CMGE */
10352 case 0x9: /* CMEQ, CMLE */
10353 case 0xa: /* CMLT */
10355 static NeonGenTwoOpFn
* const fns
[3][2] = {
10356 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
10357 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
10358 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
10360 NeonGenTwoOpFn
*genfn
;
10363 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10365 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
10366 comp
= (opcode
- 0x8) * 2 + u
;
10367 /* ...but LE, LT are implemented as reverse GE, GT */
10368 reverse
= (comp
> 2);
10372 genfn
= fns
[comp
][size
];
10374 genfn(tcg_res
, tcg_zero
, tcg_op
);
10376 genfn(tcg_res
, tcg_op
, tcg_zero
);
10378 tcg_temp_free_i32(tcg_zero
);
10381 case 0xb: /* ABS, NEG */
10383 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10385 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
10387 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
10389 tcg_temp_free_i32(tcg_zero
);
10392 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
10394 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
10398 case 0x4: /* CLS, CLZ */
10401 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
10403 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
10407 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
10409 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
10414 g_assert_not_reached();
10418 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10420 tcg_temp_free_i32(tcg_res
);
10421 tcg_temp_free_i32(tcg_op
);
10425 clear_vec_high(s
, rd
);
10429 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10430 tcg_temp_free_i32(tcg_rmode
);
10432 if (need_fpstatus
) {
10433 tcg_temp_free_ptr(tcg_fpstatus
);
10437 /* C3.6.13 AdvSIMD scalar x indexed element
10438 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10439 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10440 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10441 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10442 * C3.6.18 AdvSIMD vector x indexed element
10443 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10444 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10445 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10446 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10448 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
10450 /* This encoding has two kinds of instruction:
10451 * normal, where we perform elt x idxelt => elt for each
10452 * element in the vector
10453 * long, where we perform elt x idxelt and generate a result of
10454 * double the width of the input element
10455 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
10457 bool is_scalar
= extract32(insn
, 28, 1);
10458 bool is_q
= extract32(insn
, 30, 1);
10459 bool u
= extract32(insn
, 29, 1);
10460 int size
= extract32(insn
, 22, 2);
10461 int l
= extract32(insn
, 21, 1);
10462 int m
= extract32(insn
, 20, 1);
10463 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
10464 int rm
= extract32(insn
, 16, 4);
10465 int opcode
= extract32(insn
, 12, 4);
10466 int h
= extract32(insn
, 11, 1);
10467 int rn
= extract32(insn
, 5, 5);
10468 int rd
= extract32(insn
, 0, 5);
10469 bool is_long
= false;
10470 bool is_fp
= false;
10475 case 0x0: /* MLA */
10476 case 0x4: /* MLS */
10477 if (!u
|| is_scalar
) {
10478 unallocated_encoding(s
);
10482 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10483 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10484 case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
10486 unallocated_encoding(s
);
10491 case 0x3: /* SQDMLAL, SQDMLAL2 */
10492 case 0x7: /* SQDMLSL, SQDMLSL2 */
10493 case 0xb: /* SQDMULL, SQDMULL2 */
10496 case 0xc: /* SQDMULH */
10497 case 0xd: /* SQRDMULH */
10499 unallocated_encoding(s
);
10503 case 0x8: /* MUL */
10504 if (u
|| is_scalar
) {
10505 unallocated_encoding(s
);
10509 case 0x1: /* FMLA */
10510 case 0x5: /* FMLS */
10512 unallocated_encoding(s
);
10516 case 0x9: /* FMUL, FMULX */
10517 if (!extract32(size
, 1, 1)) {
10518 unallocated_encoding(s
);
10524 unallocated_encoding(s
);
10529 /* low bit of size indicates single/double */
10530 size
= extract32(size
, 0, 1) ? 3 : 2;
10532 index
= h
<< 1 | l
;
10535 unallocated_encoding(s
);
10544 index
= h
<< 2 | l
<< 1 | m
;
10547 index
= h
<< 1 | l
;
10551 unallocated_encoding(s
);
10556 if (!fp_access_check(s
)) {
10561 fpst
= get_fpstatus_ptr();
10563 TCGV_UNUSED_PTR(fpst
);
10567 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10570 assert(is_fp
&& is_q
&& !is_long
);
10572 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
10574 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10575 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10576 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10578 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10581 case 0x5: /* FMLS */
10582 /* As usual for ARM, separate negation for fused multiply-add */
10583 gen_helper_vfp_negd(tcg_op
, tcg_op
);
10585 case 0x1: /* FMLA */
10586 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10587 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10589 case 0x9: /* FMUL, FMULX */
10591 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10593 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10597 g_assert_not_reached();
10600 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10601 tcg_temp_free_i64(tcg_op
);
10602 tcg_temp_free_i64(tcg_res
);
10606 clear_vec_high(s
, rd
);
10609 tcg_temp_free_i64(tcg_idx
);
10610 } else if (!is_long
) {
10611 /* 32 bit floating point, or 16 or 32 bit integer.
10612 * For the 16 bit scalar case we use the usual Neon helpers and
10613 * rely on the fact that 0 op 0 == 0 with no side effects.
10615 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10616 int pass
, maxpasses
;
10621 maxpasses
= is_q
? 4 : 2;
10624 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10626 if (size
== 1 && !is_scalar
) {
10627 /* The simplest way to handle the 16x16 indexed ops is to duplicate
10628 * the index into both halves of the 32 bit tcg_idx and then use
10629 * the usual Neon helpers.
10631 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10634 for (pass
= 0; pass
< maxpasses
; pass
++) {
10635 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10636 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10638 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
10641 case 0x0: /* MLA */
10642 case 0x4: /* MLS */
10643 case 0x8: /* MUL */
10645 static NeonGenTwoOpFn
* const fns
[2][2] = {
10646 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
10647 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
10649 NeonGenTwoOpFn
*genfn
;
10650 bool is_sub
= opcode
== 0x4;
10653 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
10655 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
10657 if (opcode
== 0x8) {
10660 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
10661 genfn
= fns
[size
- 1][is_sub
];
10662 genfn(tcg_res
, tcg_op
, tcg_res
);
10665 case 0x5: /* FMLS */
10666 /* As usual for ARM, separate negation for fused multiply-add */
10667 gen_helper_vfp_negs(tcg_op
, tcg_op
);
10669 case 0x1: /* FMLA */
10670 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10671 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10673 case 0x9: /* FMUL, FMULX */
10675 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10677 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10680 case 0xc: /* SQDMULH */
10682 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
10685 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
10689 case 0xd: /* SQRDMULH */
10691 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
10694 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
10699 g_assert_not_reached();
10703 write_fp_sreg(s
, rd
, tcg_res
);
10705 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10708 tcg_temp_free_i32(tcg_op
);
10709 tcg_temp_free_i32(tcg_res
);
10712 tcg_temp_free_i32(tcg_idx
);
10715 clear_vec_high(s
, rd
);
10718 /* long ops: 16x16->32 or 32x32->64 */
10719 TCGv_i64 tcg_res
[2];
10721 bool satop
= extract32(opcode
, 0, 1);
10722 TCGMemOp memop
= MO_32
;
10729 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10731 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
10733 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10734 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10735 TCGv_i64 tcg_passres
;
10741 passelt
= pass
+ (is_q
* 2);
10744 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
10746 tcg_res
[pass
] = tcg_temp_new_i64();
10748 if (opcode
== 0xa || opcode
== 0xb) {
10749 /* Non-accumulating ops */
10750 tcg_passres
= tcg_res
[pass
];
10752 tcg_passres
= tcg_temp_new_i64();
10755 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
10756 tcg_temp_free_i64(tcg_op
);
10759 /* saturating, doubling */
10760 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10761 tcg_passres
, tcg_passres
);
10764 if (opcode
== 0xa || opcode
== 0xb) {
10768 /* Accumulating op: handle accumulate step */
10769 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10772 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10773 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10775 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10776 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10778 case 0x7: /* SQDMLSL, SQDMLSL2 */
10779 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10781 case 0x3: /* SQDMLAL, SQDMLAL2 */
10782 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10787 g_assert_not_reached();
10789 tcg_temp_free_i64(tcg_passres
);
10791 tcg_temp_free_i64(tcg_idx
);
10794 clear_vec_high(s
, rd
);
10797 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10800 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10803 /* The simplest way to handle the 16x16 indexed ops is to
10804 * duplicate the index into both halves of the 32 bit tcg_idx
10805 * and then use the usual Neon helpers.
10807 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10810 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10811 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10812 TCGv_i64 tcg_passres
;
10815 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10817 read_vec_element_i32(s
, tcg_op
, rn
,
10818 pass
+ (is_q
* 2), MO_32
);
10821 tcg_res
[pass
] = tcg_temp_new_i64();
10823 if (opcode
== 0xa || opcode
== 0xb) {
10824 /* Non-accumulating ops */
10825 tcg_passres
= tcg_res
[pass
];
10827 tcg_passres
= tcg_temp_new_i64();
10830 if (memop
& MO_SIGN
) {
10831 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
10833 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
10836 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10837 tcg_passres
, tcg_passres
);
10839 tcg_temp_free_i32(tcg_op
);
10841 if (opcode
== 0xa || opcode
== 0xb) {
10845 /* Accumulating op: handle accumulate step */
10846 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10849 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10850 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
10853 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10854 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
10857 case 0x7: /* SQDMLSL, SQDMLSL2 */
10858 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10860 case 0x3: /* SQDMLAL, SQDMLAL2 */
10861 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10866 g_assert_not_reached();
10868 tcg_temp_free_i64(tcg_passres
);
10870 tcg_temp_free_i32(tcg_idx
);
10873 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
10878 tcg_res
[1] = tcg_const_i64(0);
10881 for (pass
= 0; pass
< 2; pass
++) {
10882 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10883 tcg_temp_free_i64(tcg_res
[pass
]);
10887 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
10888 tcg_temp_free_ptr(fpst
);
10892 /* C3.6.19 Crypto AES
10893 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10894 * +-----------------+------+-----------+--------+-----+------+------+
10895 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10896 * +-----------------+------+-----------+--------+-----+------+------+
10898 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
10900 int size
= extract32(insn
, 22, 2);
10901 int opcode
= extract32(insn
, 12, 5);
10902 int rn
= extract32(insn
, 5, 5);
10903 int rd
= extract32(insn
, 0, 5);
10905 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
;
10906 CryptoThreeOpEnvFn
*genfn
;
10908 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)
10910 unallocated_encoding(s
);
10915 case 0x4: /* AESE */
10917 genfn
= gen_helper_crypto_aese
;
10919 case 0x6: /* AESMC */
10921 genfn
= gen_helper_crypto_aesmc
;
10923 case 0x5: /* AESD */
10925 genfn
= gen_helper_crypto_aese
;
10927 case 0x7: /* AESIMC */
10929 genfn
= gen_helper_crypto_aesmc
;
10932 unallocated_encoding(s
);
10936 if (!fp_access_check(s
)) {
10940 /* Note that we convert the Vx register indexes into the
10941 * index within the vfp.regs[] array, so we can share the
10942 * helper with the AArch32 instructions.
10944 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10945 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10946 tcg_decrypt
= tcg_const_i32(decrypt
);
10948 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
);
10950 tcg_temp_free_i32(tcg_rd_regno
);
10951 tcg_temp_free_i32(tcg_rn_regno
);
10952 tcg_temp_free_i32(tcg_decrypt
);
10955 /* C3.6.20 Crypto three-reg SHA
10956 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
10957 * +-----------------+------+---+------+---+--------+-----+------+------+
10958 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
10959 * +-----------------+------+---+------+---+--------+-----+------+------+
10961 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
10963 int size
= extract32(insn
, 22, 2);
10964 int opcode
= extract32(insn
, 12, 3);
10965 int rm
= extract32(insn
, 16, 5);
10966 int rn
= extract32(insn
, 5, 5);
10967 int rd
= extract32(insn
, 0, 5);
10968 CryptoThreeOpEnvFn
*genfn
;
10969 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
;
10970 int feature
= ARM_FEATURE_V8_SHA256
;
10973 unallocated_encoding(s
);
10978 case 0: /* SHA1C */
10979 case 1: /* SHA1P */
10980 case 2: /* SHA1M */
10981 case 3: /* SHA1SU0 */
10983 feature
= ARM_FEATURE_V8_SHA1
;
10985 case 4: /* SHA256H */
10986 genfn
= gen_helper_crypto_sha256h
;
10988 case 5: /* SHA256H2 */
10989 genfn
= gen_helper_crypto_sha256h2
;
10991 case 6: /* SHA256SU1 */
10992 genfn
= gen_helper_crypto_sha256su1
;
10995 unallocated_encoding(s
);
10999 if (!arm_dc_feature(s
, feature
)) {
11000 unallocated_encoding(s
);
11004 if (!fp_access_check(s
)) {
11008 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
11009 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
11010 tcg_rm_regno
= tcg_const_i32(rm
<< 1);
11013 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
);
11015 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
11017 gen_helper_crypto_sha1_3reg(cpu_env
, tcg_rd_regno
,
11018 tcg_rn_regno
, tcg_rm_regno
, tcg_opcode
);
11019 tcg_temp_free_i32(tcg_opcode
);
11022 tcg_temp_free_i32(tcg_rd_regno
);
11023 tcg_temp_free_i32(tcg_rn_regno
);
11024 tcg_temp_free_i32(tcg_rm_regno
);
11027 /* C3.6.21 Crypto two-reg SHA
11028 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
11029 * +-----------------+------+-----------+--------+-----+------+------+
11030 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
11031 * +-----------------+------+-----------+--------+-----+------+------+
11033 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
11035 int size
= extract32(insn
, 22, 2);
11036 int opcode
= extract32(insn
, 12, 5);
11037 int rn
= extract32(insn
, 5, 5);
11038 int rd
= extract32(insn
, 0, 5);
11039 CryptoTwoOpEnvFn
*genfn
;
11041 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
;
11044 unallocated_encoding(s
);
11049 case 0: /* SHA1H */
11050 feature
= ARM_FEATURE_V8_SHA1
;
11051 genfn
= gen_helper_crypto_sha1h
;
11053 case 1: /* SHA1SU1 */
11054 feature
= ARM_FEATURE_V8_SHA1
;
11055 genfn
= gen_helper_crypto_sha1su1
;
11057 case 2: /* SHA256SU0 */
11058 feature
= ARM_FEATURE_V8_SHA256
;
11059 genfn
= gen_helper_crypto_sha256su0
;
11062 unallocated_encoding(s
);
11066 if (!arm_dc_feature(s
, feature
)) {
11067 unallocated_encoding(s
);
11071 if (!fp_access_check(s
)) {
11075 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
11076 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
11078 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
);
11080 tcg_temp_free_i32(tcg_rd_regno
);
11081 tcg_temp_free_i32(tcg_rn_regno
);
11084 /* C3.6 Data processing - SIMD, inc Crypto
11086 * As the decode gets a little complex we are using a table based
11087 * approach for this part of the decode.
11089 static const AArch64DecodeTable data_proc_simd
[] = {
11090 /* pattern , mask , fn */
11091 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
11092 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
11093 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
11094 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
11095 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
11096 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
11097 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
11098 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
11099 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
11100 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
11101 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
11102 { 0x2e000000, 0xbf208400, disas_simd_ext
},
11103 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
11104 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
11105 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
11106 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
11107 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
11108 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
11109 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
11110 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
11111 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
11112 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
11113 { 0x00000000, 0x00000000, NULL
}
11116 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
11118 /* Note that this is called with all non-FP cases from
11119 * table C3-6 so it must UNDEF for entries not specifically
11120 * allocated to instructions in that table.
11122 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
11126 unallocated_encoding(s
);
11130 /* C3.6 Data processing - SIMD and floating point */
11131 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
11133 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
11134 disas_data_proc_fp(s
, insn
);
11136 /* SIMD, including crypto */
11137 disas_data_proc_simd(s
, insn
);
11141 /* C3.1 A64 instruction index by encoding */
11142 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
11146 insn
= arm_ldl_code(env
, s
->pc
, s
->sctlr_b
);
11150 s
->fp_access_checked
= false;
11152 switch (extract32(insn
, 25, 4)) {
11153 case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
11154 unallocated_encoding(s
);
11156 case 0x8: case 0x9: /* Data processing - immediate */
11157 disas_data_proc_imm(s
, insn
);
11159 case 0xa: case 0xb: /* Branch, exception generation and system insns */
11160 disas_b_exc_sys(s
, insn
);
11165 case 0xe: /* Loads and stores */
11166 disas_ldst(s
, insn
);
11169 case 0xd: /* Data processing - register */
11170 disas_data_proc_reg(s
, insn
);
11173 case 0xf: /* Data processing - SIMD and floating point */
11174 disas_data_proc_simd_fp(s
, insn
);
11177 assert(FALSE
); /* all 15 cases should be handled above */
11181 /* if we allocated any temporaries, free them here */
11185 void gen_intermediate_code_a64(ARMCPU
*cpu
, TranslationBlock
*tb
)
11187 CPUState
*cs
= CPU(cpu
);
11188 CPUARMState
*env
= &cpu
->env
;
11189 DisasContext dc1
, *dc
= &dc1
;
11190 target_ulong pc_start
;
11191 target_ulong next_page_start
;
11199 dc
->is_jmp
= DISAS_NEXT
;
11201 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
11205 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
11206 * there is no secure EL1, so we route exceptions to EL3.
11208 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
11209 !arm_el_is_aa64(env
, 3);
11212 dc
->be_data
= ARM_TBFLAG_BE_DATA(tb
->flags
) ? MO_BE
: MO_LE
;
11213 dc
->condexec_mask
= 0;
11214 dc
->condexec_cond
= 0;
11215 dc
->mmu_idx
= ARM_TBFLAG_MMUIDX(tb
->flags
);
11216 dc
->tbi0
= ARM_TBFLAG_TBI0(tb
->flags
);
11217 dc
->tbi1
= ARM_TBFLAG_TBI1(tb
->flags
);
11218 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
11219 #if !defined(CONFIG_USER_ONLY)
11220 dc
->user
= (dc
->current_el
== 0);
11222 dc
->fp_excp_el
= ARM_TBFLAG_FPEXC_EL(tb
->flags
);
11224 dc
->vec_stride
= 0;
11225 dc
->cp_regs
= cpu
->cp_regs
;
11226 dc
->features
= env
->features
;
11228 /* Single step state. The code-generation logic here is:
11230 * generate code with no special handling for single-stepping (except
11231 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
11232 * this happens anyway because those changes are all system register or
11234 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
11235 * emit code for one insn
11236 * emit code to clear PSTATE.SS
11237 * emit code to generate software step exception for completed step
11238 * end TB (as usual for having generated an exception)
11239 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
11240 * emit code to generate a software step exception
11243 dc
->ss_active
= ARM_TBFLAG_SS_ACTIVE(tb
->flags
);
11244 dc
->pstate_ss
= ARM_TBFLAG_PSTATE_SS(tb
->flags
);
11245 dc
->is_ldex
= false;
11246 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
11248 init_tmp_a64_array(dc
);
11250 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
11252 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
11253 if (max_insns
== 0) {
11254 max_insns
= CF_COUNT_MASK
;
11256 if (max_insns
> TCG_MAX_INSNS
) {
11257 max_insns
= TCG_MAX_INSNS
;
11262 tcg_clear_temp_count();
11265 dc
->insn_start_idx
= tcg_op_buf_count();
11266 tcg_gen_insn_start(dc
->pc
, 0, 0);
11269 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
11271 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
11272 if (bp
->pc
== dc
->pc
) {
11273 if (bp
->flags
& BP_CPU
) {
11274 gen_a64_set_pc_im(dc
->pc
);
11275 gen_helper_check_breakpoints(cpu_env
);
11276 /* End the TB early; it likely won't be executed */
11277 dc
->is_jmp
= DISAS_UPDATE
;
11279 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
11280 /* The address covered by the breakpoint must be
11281 included in [tb->pc, tb->pc + tb->size) in order
11282 to for it to be properly cleared -- thus we
11283 increment the PC here so that the logic setting
11284 tb->size below does the right thing. */
11286 goto done_generating
;
11293 if (num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
11297 if (dc
->ss_active
&& !dc
->pstate_ss
) {
11298 /* Singlestep state is Active-pending.
11299 * If we're in this state at the start of a TB then either
11300 * a) we just took an exception to an EL which is being debugged
11301 * and this is the first insn in the exception handler
11302 * b) debug exceptions were masked and we just unmasked them
11303 * without changing EL (eg by clearing PSTATE.D)
11304 * In either case we're going to take a swstep exception in the
11305 * "did not step an insn" case, and so the syndrome ISV and EX
11306 * bits should be zero.
11308 assert(num_insns
== 1);
11309 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0),
11310 default_exception_el(dc
));
11311 dc
->is_jmp
= DISAS_EXC
;
11315 disas_a64_insn(env
, dc
);
11317 if (tcg_check_temp_count()) {
11318 fprintf(stderr
, "TCG temporary leak before "TARGET_FMT_lx
"\n",
11322 /* Translation stops when a conditional branch is encountered.
11323 * Otherwise the subsequent code could get translated several times.
11324 * Also stop translation when a page boundary is reached. This
11325 * ensures prefetch aborts occur at the right place.
11327 } while (!dc
->is_jmp
&& !tcg_op_buf_full() &&
11328 !cs
->singlestep_enabled
&&
11331 dc
->pc
< next_page_start
&&
11332 num_insns
< max_insns
);
11334 if (tb
->cflags
& CF_LAST_IO
) {
11338 if (unlikely(cs
->singlestep_enabled
|| dc
->ss_active
)
11339 && dc
->is_jmp
!= DISAS_EXC
) {
11340 /* Note that this means single stepping WFI doesn't halt the CPU.
11341 * For conditional branch insns this is harmless unreachable code as
11342 * gen_goto_tb() has already handled emitting the debug exception
11343 * (and thus a tb-jump is not possible when singlestepping).
11345 assert(dc
->is_jmp
!= DISAS_TB_JUMP
);
11346 if (dc
->is_jmp
!= DISAS_JUMP
) {
11347 gen_a64_set_pc_im(dc
->pc
);
11349 if (cs
->singlestep_enabled
) {
11350 gen_exception_internal(EXCP_DEBUG
);
11352 gen_step_complete_exception(dc
);
11355 switch (dc
->is_jmp
) {
11357 gen_goto_tb(dc
, 1, dc
->pc
);
11361 gen_a64_set_pc_im(dc
->pc
);
11364 /* indicate that the hash table must be used to find the next TB */
11365 tcg_gen_exit_tb(0);
11367 case DISAS_TB_JUMP
:
11372 gen_a64_set_pc_im(dc
->pc
);
11373 gen_helper_wfe(cpu_env
);
11376 gen_a64_set_pc_im(dc
->pc
);
11377 gen_helper_yield(cpu_env
);
11380 /* This is a special case because we don't want to just halt the CPU
11381 * if trying to debug across a WFI.
11383 gen_a64_set_pc_im(dc
->pc
);
11384 gen_helper_wfi(cpu_env
);
11385 /* The helper doesn't necessarily throw an exception, but we
11386 * must go back to the main loop to check for interrupts anyway.
11388 tcg_gen_exit_tb(0);
11394 gen_tb_end(tb
, num_insns
);
11397 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
) &&
11398 qemu_log_in_addr_range(pc_start
)) {
11400 qemu_log("----------------\n");
11401 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
11402 log_target_disas(cs
, pc_start
, dc
->pc
- pc_start
,
11403 4 | (bswap_code(dc
->sctlr_b
) ? 2 : 0));
11408 tb
->size
= dc
->pc
- pc_start
;
11409 tb
->icount
= num_insns
;