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"
24 #include "tcg-op-gvec.h"
27 #include "translate.h"
28 #include "internals.h"
29 #include "qemu/host-utils.h"
31 #include "exec/semihost.h"
32 #include "exec/gen-icount.h"
34 #include "exec/helper-proto.h"
35 #include "exec/helper-gen.h"
38 #include "trace-tcg.h"
39 #include "translate-a64.h"
41 static TCGv_i64 cpu_X
[32];
42 static TCGv_i64 cpu_pc
;
44 /* Load/store exclusive handling */
45 static TCGv_i64 cpu_exclusive_high
;
47 static const char *regnames
[] = {
48 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
49 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
50 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
51 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
55 A64_SHIFT_TYPE_LSL
= 0,
56 A64_SHIFT_TYPE_LSR
= 1,
57 A64_SHIFT_TYPE_ASR
= 2,
58 A64_SHIFT_TYPE_ROR
= 3
61 /* Table based decoder typedefs - used when the relevant bits for decode
62 * are too awkwardly scattered across the instruction (eg SIMD).
64 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
66 typedef struct AArch64DecodeTable
{
69 AArch64DecodeFn
*disas_fn
;
72 /* Function prototype for gen_ functions for calling Neon helpers */
73 typedef void NeonGenOneOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
);
74 typedef void NeonGenTwoOpFn(TCGv_i32
, TCGv_i32
, TCGv_i32
);
75 typedef void NeonGenTwoOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
, TCGv_i32
);
76 typedef void NeonGenTwo64OpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
);
77 typedef void NeonGenTwo64OpEnvFn(TCGv_i64
, TCGv_ptr
, TCGv_i64
, TCGv_i64
);
78 typedef void NeonGenNarrowFn(TCGv_i32
, TCGv_i64
);
79 typedef void NeonGenNarrowEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i64
);
80 typedef void NeonGenWidenFn(TCGv_i64
, TCGv_i32
);
81 typedef void NeonGenTwoSingleOPFn(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
82 typedef void NeonGenTwoDoubleOPFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGv_ptr
);
83 typedef void NeonGenOneOpFn(TCGv_i64
, TCGv_i64
);
84 typedef void CryptoTwoOpFn(TCGv_ptr
, TCGv_ptr
);
85 typedef void CryptoThreeOpIntFn(TCGv_ptr
, TCGv_ptr
, TCGv_i32
);
86 typedef void CryptoThreeOpFn(TCGv_ptr
, TCGv_ptr
, TCGv_ptr
);
87 typedef void AtomicThreeOpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGArg
, TCGMemOp
);
89 /* initialize TCG globals. */
90 void a64_translate_init(void)
94 cpu_pc
= tcg_global_mem_new_i64(cpu_env
,
95 offsetof(CPUARMState
, pc
),
97 for (i
= 0; i
< 32; i
++) {
98 cpu_X
[i
] = tcg_global_mem_new_i64(cpu_env
,
99 offsetof(CPUARMState
, xregs
[i
]),
103 cpu_exclusive_high
= tcg_global_mem_new_i64(cpu_env
,
104 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
107 static inline int get_a64_user_mem_index(DisasContext
*s
)
109 /* Return the core mmu_idx to use for A64 "unprivileged load/store" insns:
110 * if EL1, access as if EL0; otherwise access at current EL
114 switch (s
->mmu_idx
) {
115 case ARMMMUIdx_S12NSE1
:
116 useridx
= ARMMMUIdx_S12NSE0
;
118 case ARMMMUIdx_S1SE1
:
119 useridx
= ARMMMUIdx_S1SE0
;
122 g_assert_not_reached();
124 useridx
= s
->mmu_idx
;
127 return arm_to_core_mmu_idx(useridx
);
130 void aarch64_cpu_dump_state(CPUState
*cs
, FILE *f
,
131 fprintf_function cpu_fprintf
, int flags
)
133 ARMCPU
*cpu
= ARM_CPU(cs
);
134 CPUARMState
*env
= &cpu
->env
;
135 uint32_t psr
= pstate_read(env
);
137 int el
= arm_current_el(env
);
138 const char *ns_status
;
140 cpu_fprintf(f
, "PC=%016"PRIx64
" SP=%016"PRIx64
"\n",
141 env
->pc
, env
->xregs
[31]);
142 for (i
= 0; i
< 31; i
++) {
143 cpu_fprintf(f
, "X%02d=%016"PRIx64
, i
, env
->xregs
[i
]);
145 cpu_fprintf(f
, "\n");
151 if (arm_feature(env
, ARM_FEATURE_EL3
) && el
!= 3) {
152 ns_status
= env
->cp15
.scr_el3
& SCR_NS
? "NS " : "S ";
157 cpu_fprintf(f
, "\nPSTATE=%08x %c%c%c%c %sEL%d%c\n",
159 psr
& PSTATE_N
? 'N' : '-',
160 psr
& PSTATE_Z
? 'Z' : '-',
161 psr
& PSTATE_C
? 'C' : '-',
162 psr
& PSTATE_V
? 'V' : '-',
165 psr
& PSTATE_SP
? 'h' : 't');
167 if (flags
& CPU_DUMP_FPU
) {
169 for (i
= 0; i
< numvfpregs
; i
++) {
170 uint64_t *q
= aa64_vfp_qreg(env
, i
);
173 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
"%c",
174 i
, vhi
, vlo
, (i
& 1 ? '\n' : ' '));
176 cpu_fprintf(f
, "FPCR: %08x FPSR: %08x\n",
177 vfp_get_fpcr(env
), vfp_get_fpsr(env
));
181 void gen_a64_set_pc_im(uint64_t val
)
183 tcg_gen_movi_i64(cpu_pc
, val
);
186 /* Load the PC from a generic TCG variable.
188 * If address tagging is enabled via the TCR TBI bits, then loading
189 * an address into the PC will clear out any tag in the it:
190 * + for EL2 and EL3 there is only one TBI bit, and if it is set
191 * then the address is zero-extended, clearing bits [63:56]
192 * + for EL0 and EL1, TBI0 controls addresses with bit 55 == 0
193 * and TBI1 controls addressses with bit 55 == 1.
194 * If the appropriate TBI bit is set for the address then
195 * the address is sign-extended from bit 55 into bits [63:56]
197 * We can avoid doing this for relative-branches, because the
198 * PC + offset can never overflow into the tag bits (assuming
199 * that virtual addresses are less than 56 bits wide, as they
200 * are currently), but we must handle it for branch-to-register.
202 static void gen_a64_set_pc(DisasContext
*s
, TCGv_i64 src
)
205 if (s
->current_el
<= 1) {
206 /* Test if NEITHER or BOTH TBI values are set. If so, no need to
207 * examine bit 55 of address, can just generate code.
208 * If mixed, then test via generated code
210 if (s
->tbi0
&& s
->tbi1
) {
211 TCGv_i64 tmp_reg
= tcg_temp_new_i64();
212 /* Both bits set, sign extension from bit 55 into [63:56] will
215 tcg_gen_shli_i64(tmp_reg
, src
, 8);
216 tcg_gen_sari_i64(cpu_pc
, tmp_reg
, 8);
217 tcg_temp_free_i64(tmp_reg
);
218 } else if (!s
->tbi0
&& !s
->tbi1
) {
219 /* Neither bit set, just load it as-is */
220 tcg_gen_mov_i64(cpu_pc
, src
);
222 TCGv_i64 tcg_tmpval
= tcg_temp_new_i64();
223 TCGv_i64 tcg_bit55
= tcg_temp_new_i64();
224 TCGv_i64 tcg_zero
= tcg_const_i64(0);
226 tcg_gen_andi_i64(tcg_bit55
, src
, (1ull << 55));
229 /* tbi0==1, tbi1==0, so 0-fill upper byte if bit 55 = 0 */
230 tcg_gen_andi_i64(tcg_tmpval
, src
,
231 0x00FFFFFFFFFFFFFFull
);
232 tcg_gen_movcond_i64(TCG_COND_EQ
, cpu_pc
, tcg_bit55
, tcg_zero
,
235 /* tbi0==0, tbi1==1, so 1-fill upper byte if bit 55 = 1 */
236 tcg_gen_ori_i64(tcg_tmpval
, src
,
237 0xFF00000000000000ull
);
238 tcg_gen_movcond_i64(TCG_COND_NE
, cpu_pc
, tcg_bit55
, tcg_zero
,
241 tcg_temp_free_i64(tcg_zero
);
242 tcg_temp_free_i64(tcg_bit55
);
243 tcg_temp_free_i64(tcg_tmpval
);
245 } else { /* EL > 1 */
247 /* Force tag byte to all zero */
248 tcg_gen_andi_i64(cpu_pc
, src
, 0x00FFFFFFFFFFFFFFull
);
250 /* Load unmodified address */
251 tcg_gen_mov_i64(cpu_pc
, src
);
256 typedef struct DisasCompare64
{
261 static void a64_test_cc(DisasCompare64
*c64
, int cc
)
265 arm_test_cc(&c32
, cc
);
267 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
268 * properly. The NE/EQ comparisons are also fine with this choice. */
269 c64
->cond
= c32
.cond
;
270 c64
->value
= tcg_temp_new_i64();
271 tcg_gen_ext_i32_i64(c64
->value
, c32
.value
);
276 static void a64_free_cc(DisasCompare64
*c64
)
278 tcg_temp_free_i64(c64
->value
);
281 static void gen_exception_internal(int excp
)
283 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
285 assert(excp_is_internal(excp
));
286 gen_helper_exception_internal(cpu_env
, tcg_excp
);
287 tcg_temp_free_i32(tcg_excp
);
290 static void gen_exception(int excp
, uint32_t syndrome
, uint32_t target_el
)
292 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
293 TCGv_i32 tcg_syn
= tcg_const_i32(syndrome
);
294 TCGv_i32 tcg_el
= tcg_const_i32(target_el
);
296 gen_helper_exception_with_syndrome(cpu_env
, tcg_excp
,
298 tcg_temp_free_i32(tcg_el
);
299 tcg_temp_free_i32(tcg_syn
);
300 tcg_temp_free_i32(tcg_excp
);
303 static void gen_exception_internal_insn(DisasContext
*s
, int offset
, int excp
)
305 gen_a64_set_pc_im(s
->pc
- offset
);
306 gen_exception_internal(excp
);
307 s
->base
.is_jmp
= DISAS_NORETURN
;
310 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
,
311 uint32_t syndrome
, uint32_t target_el
)
313 gen_a64_set_pc_im(s
->pc
- offset
);
314 gen_exception(excp
, syndrome
, target_el
);
315 s
->base
.is_jmp
= DISAS_NORETURN
;
318 static void gen_exception_bkpt_insn(DisasContext
*s
, int offset
,
323 gen_a64_set_pc_im(s
->pc
- offset
);
324 tcg_syn
= tcg_const_i32(syndrome
);
325 gen_helper_exception_bkpt_insn(cpu_env
, tcg_syn
);
326 tcg_temp_free_i32(tcg_syn
);
327 s
->base
.is_jmp
= DISAS_NORETURN
;
330 static void gen_ss_advance(DisasContext
*s
)
332 /* If the singlestep state is Active-not-pending, advance to
337 gen_helper_clear_pstate_ss(cpu_env
);
341 static void gen_step_complete_exception(DisasContext
*s
)
343 /* We just completed step of an insn. Move from Active-not-pending
344 * to Active-pending, and then also take the swstep exception.
345 * This corresponds to making the (IMPDEF) choice to prioritize
346 * swstep exceptions over asynchronous exceptions taken to an exception
347 * level where debug is disabled. This choice has the advantage that
348 * we do not need to maintain internal state corresponding to the
349 * ISV/EX syndrome bits between completion of the step and generation
350 * of the exception, and our syndrome information is always correct.
353 gen_exception(EXCP_UDEF
, syn_swstep(s
->ss_same_el
, 1, s
->is_ldex
),
354 default_exception_el(s
));
355 s
->base
.is_jmp
= DISAS_NORETURN
;
358 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
360 /* No direct tb linking with singlestep (either QEMU's or the ARM
361 * debug architecture kind) or deterministic io
363 if (s
->base
.singlestep_enabled
|| s
->ss_active
||
364 (tb_cflags(s
->base
.tb
) & CF_LAST_IO
)) {
368 #ifndef CONFIG_USER_ONLY
369 /* Only link tbs from inside the same guest page */
370 if ((s
->base
.tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
378 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
380 TranslationBlock
*tb
;
383 if (use_goto_tb(s
, n
, dest
)) {
385 gen_a64_set_pc_im(dest
);
386 tcg_gen_exit_tb(tb
, n
);
387 s
->base
.is_jmp
= DISAS_NORETURN
;
389 gen_a64_set_pc_im(dest
);
391 gen_step_complete_exception(s
);
392 } else if (s
->base
.singlestep_enabled
) {
393 gen_exception_internal(EXCP_DEBUG
);
395 tcg_gen_lookup_and_goto_ptr();
396 s
->base
.is_jmp
= DISAS_NORETURN
;
401 void unallocated_encoding(DisasContext
*s
)
403 /* Unallocated and reserved encodings are uncategorized */
404 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized(),
405 default_exception_el(s
));
408 static void init_tmp_a64_array(DisasContext
*s
)
410 #ifdef CONFIG_DEBUG_TCG
411 memset(s
->tmp_a64
, 0, sizeof(s
->tmp_a64
));
413 s
->tmp_a64_count
= 0;
416 static void free_tmp_a64(DisasContext
*s
)
419 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
420 tcg_temp_free_i64(s
->tmp_a64
[i
]);
422 init_tmp_a64_array(s
);
425 TCGv_i64
new_tmp_a64(DisasContext
*s
)
427 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
428 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
431 TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
433 TCGv_i64 t
= new_tmp_a64(s
);
434 tcg_gen_movi_i64(t
, 0);
439 * Register access functions
441 * These functions are used for directly accessing a register in where
442 * changes to the final register value are likely to be made. If you
443 * need to use a register for temporary calculation (e.g. index type
444 * operations) use the read_* form.
446 * B1.2.1 Register mappings
448 * In instruction register encoding 31 can refer to ZR (zero register) or
449 * the SP (stack pointer) depending on context. In QEMU's case we map SP
450 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
451 * This is the point of the _sp forms.
453 TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
456 return new_tmp_a64_zero(s
);
462 /* register access for when 31 == SP */
463 TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
468 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
469 * representing the register contents. This TCGv is an auto-freed
470 * temporary so it need not be explicitly freed, and may be modified.
472 TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
474 TCGv_i64 v
= new_tmp_a64(s
);
477 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
479 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
482 tcg_gen_movi_i64(v
, 0);
487 TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
489 TCGv_i64 v
= new_tmp_a64(s
);
491 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
493 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
498 /* Return the offset into CPUARMState of a slice (from
499 * the least significant end) of FP register Qn (ie
501 * (Note that this is not the same mapping as for A32; see cpu.h)
503 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
505 return vec_reg_offset(s
, regno
, 0, size
);
508 /* Offset of the high half of the 128 bit vector Qn */
509 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
511 return vec_reg_offset(s
, regno
, 1, MO_64
);
514 /* Convenience accessors for reading and writing single and double
515 * FP registers. Writing clears the upper parts of the associated
516 * 128 bit vector register, as required by the architecture.
517 * Note that unlike the GP register accessors, the values returned
518 * by the read functions must be manually freed.
520 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
522 TCGv_i64 v
= tcg_temp_new_i64();
524 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
528 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
530 TCGv_i32 v
= tcg_temp_new_i32();
532 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
536 static TCGv_i32
read_fp_hreg(DisasContext
*s
, int reg
)
538 TCGv_i32 v
= tcg_temp_new_i32();
540 tcg_gen_ld16u_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_16
));
544 /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64).
545 * If SVE is not enabled, then there are only 128 bits in the vector.
547 static void clear_vec_high(DisasContext
*s
, bool is_q
, int rd
)
549 unsigned ofs
= fp_reg_offset(s
, rd
, MO_64
);
550 unsigned vsz
= vec_full_reg_size(s
);
553 TCGv_i64 tcg_zero
= tcg_const_i64(0);
554 tcg_gen_st_i64(tcg_zero
, cpu_env
, ofs
+ 8);
555 tcg_temp_free_i64(tcg_zero
);
558 tcg_gen_gvec_dup8i(ofs
+ 16, vsz
- 16, vsz
- 16, 0);
562 void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
564 unsigned ofs
= fp_reg_offset(s
, reg
, MO_64
);
566 tcg_gen_st_i64(v
, cpu_env
, ofs
);
567 clear_vec_high(s
, false, reg
);
570 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
572 TCGv_i64 tmp
= tcg_temp_new_i64();
574 tcg_gen_extu_i32_i64(tmp
, v
);
575 write_fp_dreg(s
, reg
, tmp
);
576 tcg_temp_free_i64(tmp
);
579 TCGv_ptr
get_fpstatus_ptr(bool is_f16
)
581 TCGv_ptr statusptr
= tcg_temp_new_ptr();
584 /* In A64 all instructions (both FP and Neon) use the FPCR; there
585 * is no equivalent of the A32 Neon "standard FPSCR value".
586 * However half-precision operations operate under a different
587 * FZ16 flag and use vfp.fp_status_f16 instead of vfp.fp_status.
590 offset
= offsetof(CPUARMState
, vfp
.fp_status_f16
);
592 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
594 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
598 /* Expand a 2-operand AdvSIMD vector operation using an expander function. */
599 static void gen_gvec_fn2(DisasContext
*s
, bool is_q
, int rd
, int rn
,
600 GVecGen2Fn
*gvec_fn
, int vece
)
602 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
603 is_q
? 16 : 8, vec_full_reg_size(s
));
606 /* Expand a 2-operand + immediate AdvSIMD vector operation using
607 * an expander function.
609 static void gen_gvec_fn2i(DisasContext
*s
, bool is_q
, int rd
, int rn
,
610 int64_t imm
, GVecGen2iFn
*gvec_fn
, int vece
)
612 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
613 imm
, is_q
? 16 : 8, vec_full_reg_size(s
));
616 /* Expand a 3-operand AdvSIMD vector operation using an expander function. */
617 static void gen_gvec_fn3(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
618 GVecGen3Fn
*gvec_fn
, int vece
)
620 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
621 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8, vec_full_reg_size(s
));
624 /* Expand a 2-operand + immediate AdvSIMD vector operation using
627 static void gen_gvec_op2i(DisasContext
*s
, bool is_q
, int rd
,
628 int rn
, int64_t imm
, const GVecGen2i
*gvec_op
)
630 tcg_gen_gvec_2i(vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
631 is_q
? 16 : 8, vec_full_reg_size(s
), imm
, gvec_op
);
634 /* Expand a 3-operand AdvSIMD vector operation using an op descriptor. */
635 static void gen_gvec_op3(DisasContext
*s
, bool is_q
, int rd
,
636 int rn
, int rm
, const GVecGen3
*gvec_op
)
638 tcg_gen_gvec_3(vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
639 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8,
640 vec_full_reg_size(s
), gvec_op
);
643 /* Expand a 3-operand + env pointer operation using
644 * an out-of-line helper.
646 static void gen_gvec_op3_env(DisasContext
*s
, bool is_q
, int rd
,
647 int rn
, int rm
, gen_helper_gvec_3_ptr
*fn
)
649 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
650 vec_full_reg_offset(s
, rn
),
651 vec_full_reg_offset(s
, rm
), cpu_env
,
652 is_q
? 16 : 8, vec_full_reg_size(s
), 0, fn
);
655 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
656 * an out-of-line helper.
658 static void gen_gvec_op3_fpst(DisasContext
*s
, bool is_q
, int rd
, int rn
,
659 int rm
, bool is_fp16
, int data
,
660 gen_helper_gvec_3_ptr
*fn
)
662 TCGv_ptr fpst
= get_fpstatus_ptr(is_fp16
);
663 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
664 vec_full_reg_offset(s
, rn
),
665 vec_full_reg_offset(s
, rm
), fpst
,
666 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
667 tcg_temp_free_ptr(fpst
);
670 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
671 * than the 32 bit equivalent.
673 static inline void gen_set_NZ64(TCGv_i64 result
)
675 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
676 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
679 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
680 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
683 gen_set_NZ64(result
);
685 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
686 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
688 tcg_gen_movi_i32(cpu_CF
, 0);
689 tcg_gen_movi_i32(cpu_VF
, 0);
692 /* dest = T0 + T1; compute C, N, V and Z flags */
693 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
696 TCGv_i64 result
, flag
, tmp
;
697 result
= tcg_temp_new_i64();
698 flag
= tcg_temp_new_i64();
699 tmp
= tcg_temp_new_i64();
701 tcg_gen_movi_i64(tmp
, 0);
702 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
704 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
706 gen_set_NZ64(result
);
708 tcg_gen_xor_i64(flag
, result
, t0
);
709 tcg_gen_xor_i64(tmp
, t0
, t1
);
710 tcg_gen_andc_i64(flag
, flag
, tmp
);
711 tcg_temp_free_i64(tmp
);
712 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
714 tcg_gen_mov_i64(dest
, result
);
715 tcg_temp_free_i64(result
);
716 tcg_temp_free_i64(flag
);
718 /* 32 bit arithmetic */
719 TCGv_i32 t0_32
= tcg_temp_new_i32();
720 TCGv_i32 t1_32
= tcg_temp_new_i32();
721 TCGv_i32 tmp
= tcg_temp_new_i32();
723 tcg_gen_movi_i32(tmp
, 0);
724 tcg_gen_extrl_i64_i32(t0_32
, t0
);
725 tcg_gen_extrl_i64_i32(t1_32
, t1
);
726 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
727 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
728 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
729 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
730 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
731 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
733 tcg_temp_free_i32(tmp
);
734 tcg_temp_free_i32(t0_32
);
735 tcg_temp_free_i32(t1_32
);
739 /* dest = T0 - T1; compute C, N, V and Z flags */
740 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
743 /* 64 bit arithmetic */
744 TCGv_i64 result
, flag
, tmp
;
746 result
= tcg_temp_new_i64();
747 flag
= tcg_temp_new_i64();
748 tcg_gen_sub_i64(result
, t0
, t1
);
750 gen_set_NZ64(result
);
752 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
753 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
755 tcg_gen_xor_i64(flag
, result
, t0
);
756 tmp
= tcg_temp_new_i64();
757 tcg_gen_xor_i64(tmp
, t0
, t1
);
758 tcg_gen_and_i64(flag
, flag
, tmp
);
759 tcg_temp_free_i64(tmp
);
760 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
761 tcg_gen_mov_i64(dest
, result
);
762 tcg_temp_free_i64(flag
);
763 tcg_temp_free_i64(result
);
765 /* 32 bit arithmetic */
766 TCGv_i32 t0_32
= tcg_temp_new_i32();
767 TCGv_i32 t1_32
= tcg_temp_new_i32();
770 tcg_gen_extrl_i64_i32(t0_32
, t0
);
771 tcg_gen_extrl_i64_i32(t1_32
, t1
);
772 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
773 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
774 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
775 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
776 tmp
= tcg_temp_new_i32();
777 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
778 tcg_temp_free_i32(t0_32
);
779 tcg_temp_free_i32(t1_32
);
780 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
781 tcg_temp_free_i32(tmp
);
782 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
786 /* dest = T0 + T1 + CF; do not compute flags. */
787 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
789 TCGv_i64 flag
= tcg_temp_new_i64();
790 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
791 tcg_gen_add_i64(dest
, t0
, t1
);
792 tcg_gen_add_i64(dest
, dest
, flag
);
793 tcg_temp_free_i64(flag
);
796 tcg_gen_ext32u_i64(dest
, dest
);
800 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
801 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
804 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
805 result
= tcg_temp_new_i64();
806 cf_64
= tcg_temp_new_i64();
807 vf_64
= tcg_temp_new_i64();
808 tmp
= tcg_const_i64(0);
810 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
811 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
812 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
813 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
814 gen_set_NZ64(result
);
816 tcg_gen_xor_i64(vf_64
, result
, t0
);
817 tcg_gen_xor_i64(tmp
, t0
, t1
);
818 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
819 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
821 tcg_gen_mov_i64(dest
, result
);
823 tcg_temp_free_i64(tmp
);
824 tcg_temp_free_i64(vf_64
);
825 tcg_temp_free_i64(cf_64
);
826 tcg_temp_free_i64(result
);
828 TCGv_i32 t0_32
, t1_32
, tmp
;
829 t0_32
= tcg_temp_new_i32();
830 t1_32
= tcg_temp_new_i32();
831 tmp
= tcg_const_i32(0);
833 tcg_gen_extrl_i64_i32(t0_32
, t0
);
834 tcg_gen_extrl_i64_i32(t1_32
, t1
);
835 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
836 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
838 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
839 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
840 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
841 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
842 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
844 tcg_temp_free_i32(tmp
);
845 tcg_temp_free_i32(t1_32
);
846 tcg_temp_free_i32(t0_32
);
851 * Load/Store generators
855 * Store from GPR register to memory.
857 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
858 TCGv_i64 tcg_addr
, int size
, int memidx
,
860 unsigned int iss_srt
,
861 bool iss_sf
, bool iss_ar
)
864 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, s
->be_data
+ size
);
869 syn
= syn_data_abort_with_iss(0,
875 0, 0, 0, 0, 0, false);
876 disas_set_insn_syndrome(s
, syn
);
880 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
881 TCGv_i64 tcg_addr
, int size
,
883 unsigned int iss_srt
,
884 bool iss_sf
, bool iss_ar
)
886 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
),
887 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
891 * Load from memory to GPR register
893 static void do_gpr_ld_memidx(DisasContext
*s
,
894 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
895 int size
, bool is_signed
,
896 bool extend
, int memidx
,
897 bool iss_valid
, unsigned int iss_srt
,
898 bool iss_sf
, bool iss_ar
)
900 TCGMemOp memop
= s
->be_data
+ size
;
908 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
910 if (extend
&& is_signed
) {
912 tcg_gen_ext32u_i64(dest
, dest
);
918 syn
= syn_data_abort_with_iss(0,
924 0, 0, 0, 0, 0, false);
925 disas_set_insn_syndrome(s
, syn
);
929 static void do_gpr_ld(DisasContext
*s
,
930 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
931 int size
, bool is_signed
, bool extend
,
932 bool iss_valid
, unsigned int iss_srt
,
933 bool iss_sf
, bool iss_ar
)
935 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
937 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
941 * Store from FP register to memory
943 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
945 /* This writes the bottom N bits of a 128 bit wide vector to memory */
946 TCGv_i64 tmp
= tcg_temp_new_i64();
947 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
949 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
),
952 bool be
= s
->be_data
== MO_BE
;
953 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
955 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
956 tcg_gen_qemu_st_i64(tmp
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
958 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
959 tcg_gen_qemu_st_i64(tmp
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
961 tcg_temp_free_i64(tcg_hiaddr
);
964 tcg_temp_free_i64(tmp
);
968 * Load from memory to FP register
970 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
972 /* This always zero-extends and writes to a full 128 bit wide vector */
973 TCGv_i64 tmplo
= tcg_temp_new_i64();
977 TCGMemOp memop
= s
->be_data
+ size
;
978 tmphi
= tcg_const_i64(0);
979 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
981 bool be
= s
->be_data
== MO_BE
;
984 tmphi
= tcg_temp_new_i64();
985 tcg_hiaddr
= tcg_temp_new_i64();
987 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
988 tcg_gen_qemu_ld_i64(tmplo
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
990 tcg_gen_qemu_ld_i64(tmphi
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
992 tcg_temp_free_i64(tcg_hiaddr
);
995 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
996 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
998 tcg_temp_free_i64(tmplo
);
999 tcg_temp_free_i64(tmphi
);
1001 clear_vec_high(s
, true, destidx
);
1005 * Vector load/store helpers.
1007 * The principal difference between this and a FP load is that we don't
1008 * zero extend as we are filling a partial chunk of the vector register.
1009 * These functions don't support 128 bit loads/stores, which would be
1010 * normal load/store operations.
1012 * The _i32 versions are useful when operating on 32 bit quantities
1013 * (eg for floating point single or using Neon helper functions).
1016 /* Get value of an element within a vector register */
1017 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
1018 int element
, TCGMemOp memop
)
1020 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1023 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
1026 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
1029 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
1032 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
1035 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
1038 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
1042 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
1045 g_assert_not_reached();
1049 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
1050 int element
, TCGMemOp memop
)
1052 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1055 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
1058 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
1061 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
1064 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
1068 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
1071 g_assert_not_reached();
1075 /* Set value of an element within a vector register */
1076 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
1077 int element
, TCGMemOp memop
)
1079 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1082 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
1085 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
1088 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
1091 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
1094 g_assert_not_reached();
1098 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
1099 int destidx
, int element
, TCGMemOp memop
)
1101 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1104 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
1107 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
1110 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
1113 g_assert_not_reached();
1117 /* Store from vector register to memory */
1118 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
1119 TCGv_i64 tcg_addr
, int size
)
1121 TCGMemOp memop
= s
->be_data
+ size
;
1122 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1124 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
1125 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
1127 tcg_temp_free_i64(tcg_tmp
);
1130 /* Load from memory to vector register */
1131 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
1132 TCGv_i64 tcg_addr
, int size
)
1134 TCGMemOp memop
= s
->be_data
+ size
;
1135 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1137 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
1138 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
1140 tcg_temp_free_i64(tcg_tmp
);
1143 /* Check that FP/Neon access is enabled. If it is, return
1144 * true. If not, emit code to generate an appropriate exception,
1145 * and return false; the caller should not emit any code for
1146 * the instruction. Note that this check must happen after all
1147 * unallocated-encoding checks (otherwise the syndrome information
1148 * for the resulting exception will be incorrect).
1150 static inline bool fp_access_check(DisasContext
*s
)
1152 assert(!s
->fp_access_checked
);
1153 s
->fp_access_checked
= true;
1155 if (!s
->fp_excp_el
) {
1159 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false),
1164 /* Check that SVE access is enabled. If it is, return true.
1165 * If not, emit code to generate an appropriate exception and return false.
1167 bool sve_access_check(DisasContext
*s
)
1169 if (s
->sve_excp_el
) {
1170 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_sve_access_trap(),
1174 return fp_access_check(s
);
1178 * This utility function is for doing register extension with an
1179 * optional shift. You will likely want to pass a temporary for the
1180 * destination register. See DecodeRegExtend() in the ARM ARM.
1182 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1183 int option
, unsigned int shift
)
1185 int extsize
= extract32(option
, 0, 2);
1186 bool is_signed
= extract32(option
, 2, 1);
1191 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1194 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1197 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1200 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1206 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1209 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1212 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1215 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1221 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1225 static inline void gen_check_sp_alignment(DisasContext
*s
)
1227 /* The AArch64 architecture mandates that (if enabled via PSTATE
1228 * or SCTLR bits) there is a check that SP is 16-aligned on every
1229 * SP-relative load or store (with an exception generated if it is not).
1230 * In line with general QEMU practice regarding misaligned accesses,
1231 * we omit these checks for the sake of guest program performance.
1232 * This function is provided as a hook so we can more easily add these
1233 * checks in future (possibly as a "favour catching guest program bugs
1234 * over speed" user selectable option).
1239 * This provides a simple table based table lookup decoder. It is
1240 * intended to be used when the relevant bits for decode are too
1241 * awkwardly placed and switch/if based logic would be confusing and
1242 * deeply nested. Since it's a linear search through the table, tables
1243 * should be kept small.
1245 * It returns the first handler where insn & mask == pattern, or
1246 * NULL if there is no match.
1247 * The table is terminated by an empty mask (i.e. 0)
1249 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1252 const AArch64DecodeTable
*tptr
= table
;
1254 while (tptr
->mask
) {
1255 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1256 return tptr
->disas_fn
;
1264 * The instruction disassembly implemented here matches
1265 * the instruction encoding classifications in chapter C4
1266 * of the ARM Architecture Reference Manual (DDI0487B_a);
1267 * classification names and decode diagrams here should generally
1268 * match up with those in the manual.
1271 /* Unconditional branch (immediate)
1273 * +----+-----------+-------------------------------------+
1274 * | op | 0 0 1 0 1 | imm26 |
1275 * +----+-----------+-------------------------------------+
1277 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1279 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1281 if (insn
& (1U << 31)) {
1282 /* BL Branch with link */
1283 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1286 /* B Branch / BL Branch with link */
1287 gen_goto_tb(s
, 0, addr
);
1290 /* Compare and branch (immediate)
1291 * 31 30 25 24 23 5 4 0
1292 * +----+-------------+----+---------------------+--------+
1293 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1294 * +----+-------------+----+---------------------+--------+
1296 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1298 unsigned int sf
, op
, rt
;
1300 TCGLabel
*label_match
;
1303 sf
= extract32(insn
, 31, 1);
1304 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1305 rt
= extract32(insn
, 0, 5);
1306 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1308 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1309 label_match
= gen_new_label();
1311 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1312 tcg_cmp
, 0, label_match
);
1314 gen_goto_tb(s
, 0, s
->pc
);
1315 gen_set_label(label_match
);
1316 gen_goto_tb(s
, 1, addr
);
1319 /* Test and branch (immediate)
1320 * 31 30 25 24 23 19 18 5 4 0
1321 * +----+-------------+----+-------+-------------+------+
1322 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1323 * +----+-------------+----+-------+-------------+------+
1325 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1327 unsigned int bit_pos
, op
, rt
;
1329 TCGLabel
*label_match
;
1332 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1333 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1334 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1335 rt
= extract32(insn
, 0, 5);
1337 tcg_cmp
= tcg_temp_new_i64();
1338 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1339 label_match
= gen_new_label();
1340 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1341 tcg_cmp
, 0, label_match
);
1342 tcg_temp_free_i64(tcg_cmp
);
1343 gen_goto_tb(s
, 0, s
->pc
);
1344 gen_set_label(label_match
);
1345 gen_goto_tb(s
, 1, addr
);
1348 /* Conditional branch (immediate)
1349 * 31 25 24 23 5 4 3 0
1350 * +---------------+----+---------------------+----+------+
1351 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1352 * +---------------+----+---------------------+----+------+
1354 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1359 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1360 unallocated_encoding(s
);
1363 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1364 cond
= extract32(insn
, 0, 4);
1367 /* genuinely conditional branches */
1368 TCGLabel
*label_match
= gen_new_label();
1369 arm_gen_test_cc(cond
, label_match
);
1370 gen_goto_tb(s
, 0, s
->pc
);
1371 gen_set_label(label_match
);
1372 gen_goto_tb(s
, 1, addr
);
1374 /* 0xe and 0xf are both "always" conditions */
1375 gen_goto_tb(s
, 0, addr
);
1379 /* HINT instruction group, including various allocated HINTs */
1380 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1381 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1383 unsigned int selector
= crm
<< 3 | op2
;
1386 unallocated_encoding(s
);
1394 s
->base
.is_jmp
= DISAS_WFI
;
1396 /* When running in MTTCG we don't generate jumps to the yield and
1397 * WFE helpers as it won't affect the scheduling of other vCPUs.
1398 * If we wanted to more completely model WFE/SEV so we don't busy
1399 * spin unnecessarily we would need to do something more involved.
1402 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1403 s
->base
.is_jmp
= DISAS_YIELD
;
1407 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1408 s
->base
.is_jmp
= DISAS_WFE
;
1413 /* we treat all as NOP at least for now */
1416 /* default specified as NOP equivalent */
1421 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1423 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1426 /* CLREX, DSB, DMB, ISB */
1427 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1428 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1433 unallocated_encoding(s
);
1444 case 1: /* MBReqTypes_Reads */
1445 bar
= TCG_BAR_SC
| TCG_MO_LD_LD
| TCG_MO_LD_ST
;
1447 case 2: /* MBReqTypes_Writes */
1448 bar
= TCG_BAR_SC
| TCG_MO_ST_ST
;
1450 default: /* MBReqTypes_All */
1451 bar
= TCG_BAR_SC
| TCG_MO_ALL
;
1457 /* We need to break the TB after this insn to execute
1458 * a self-modified code correctly and also to take
1459 * any pending interrupts immediately.
1461 gen_goto_tb(s
, 0, s
->pc
);
1464 unallocated_encoding(s
);
1469 /* MSR (immediate) - move immediate to processor state field */
1470 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1471 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1473 int op
= op1
<< 3 | op2
;
1475 case 0x05: /* SPSel */
1476 if (s
->current_el
== 0) {
1477 unallocated_encoding(s
);
1481 case 0x1e: /* DAIFSet */
1482 case 0x1f: /* DAIFClear */
1484 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1485 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1486 gen_a64_set_pc_im(s
->pc
- 4);
1487 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1488 tcg_temp_free_i32(tcg_imm
);
1489 tcg_temp_free_i32(tcg_op
);
1490 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1491 gen_a64_set_pc_im(s
->pc
);
1492 s
->base
.is_jmp
= (op
== 0x1f ? DISAS_EXIT
: DISAS_JUMP
);
1496 unallocated_encoding(s
);
1501 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1503 TCGv_i32 tmp
= tcg_temp_new_i32();
1504 TCGv_i32 nzcv
= tcg_temp_new_i32();
1506 /* build bit 31, N */
1507 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1508 /* build bit 30, Z */
1509 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1510 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1511 /* build bit 29, C */
1512 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1513 /* build bit 28, V */
1514 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1515 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1516 /* generate result */
1517 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1519 tcg_temp_free_i32(nzcv
);
1520 tcg_temp_free_i32(tmp
);
1523 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1526 TCGv_i32 nzcv
= tcg_temp_new_i32();
1528 /* take NZCV from R[t] */
1529 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1532 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1534 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1535 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1537 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1538 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1540 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1541 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1542 tcg_temp_free_i32(nzcv
);
1545 /* MRS - move from system register
1546 * MSR (register) - move to system register
1549 * These are all essentially the same insn in 'read' and 'write'
1550 * versions, with varying op0 fields.
1552 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1553 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1554 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1556 const ARMCPRegInfo
*ri
;
1559 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1560 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1561 crn
, crm
, op0
, op1
, op2
));
1564 /* Unknown register; this might be a guest error or a QEMU
1565 * unimplemented feature.
1567 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1568 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1569 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1570 unallocated_encoding(s
);
1574 /* Check access permissions */
1575 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1576 unallocated_encoding(s
);
1581 /* Emit code to perform further access permissions checks at
1582 * runtime; this may result in an exception.
1585 TCGv_i32 tcg_syn
, tcg_isread
;
1588 gen_a64_set_pc_im(s
->pc
- 4);
1589 tmpptr
= tcg_const_ptr(ri
);
1590 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1591 tcg_syn
= tcg_const_i32(syndrome
);
1592 tcg_isread
= tcg_const_i32(isread
);
1593 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
, tcg_isread
);
1594 tcg_temp_free_ptr(tmpptr
);
1595 tcg_temp_free_i32(tcg_syn
);
1596 tcg_temp_free_i32(tcg_isread
);
1599 /* Handle special cases first */
1600 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1604 tcg_rt
= cpu_reg(s
, rt
);
1606 gen_get_nzcv(tcg_rt
);
1608 gen_set_nzcv(tcg_rt
);
1611 case ARM_CP_CURRENTEL
:
1612 /* Reads as current EL value from pstate, which is
1613 * guaranteed to be constant by the tb flags.
1615 tcg_rt
= cpu_reg(s
, rt
);
1616 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1619 /* Writes clear the aligned block of memory which rt points into. */
1620 tcg_rt
= cpu_reg(s
, rt
);
1621 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1626 if ((ri
->type
& ARM_CP_SVE
) && !sve_access_check(s
)) {
1629 if ((ri
->type
& ARM_CP_FPU
) && !fp_access_check(s
)) {
1633 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1637 tcg_rt
= cpu_reg(s
, rt
);
1640 if (ri
->type
& ARM_CP_CONST
) {
1641 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1642 } else if (ri
->readfn
) {
1644 tmpptr
= tcg_const_ptr(ri
);
1645 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1646 tcg_temp_free_ptr(tmpptr
);
1648 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1651 if (ri
->type
& ARM_CP_CONST
) {
1652 /* If not forbidden by access permissions, treat as WI */
1654 } else if (ri
->writefn
) {
1656 tmpptr
= tcg_const_ptr(ri
);
1657 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1658 tcg_temp_free_ptr(tmpptr
);
1660 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1664 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1665 /* I/O operations must end the TB here (whether read or write) */
1667 s
->base
.is_jmp
= DISAS_UPDATE
;
1668 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1669 /* We default to ending the TB on a coprocessor register write,
1670 * but allow this to be suppressed by the register definition
1671 * (usually only necessary to work around guest bugs).
1673 s
->base
.is_jmp
= DISAS_UPDATE
;
1678 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1679 * +---------------------+---+-----+-----+-------+-------+-----+------+
1680 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1681 * +---------------------+---+-----+-----+-------+-------+-----+------+
1683 static void disas_system(DisasContext
*s
, uint32_t insn
)
1685 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1686 l
= extract32(insn
, 21, 1);
1687 op0
= extract32(insn
, 19, 2);
1688 op1
= extract32(insn
, 16, 3);
1689 crn
= extract32(insn
, 12, 4);
1690 crm
= extract32(insn
, 8, 4);
1691 op2
= extract32(insn
, 5, 3);
1692 rt
= extract32(insn
, 0, 5);
1695 if (l
|| rt
!= 31) {
1696 unallocated_encoding(s
);
1700 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
1701 handle_hint(s
, insn
, op1
, op2
, crm
);
1703 case 3: /* CLREX, DSB, DMB, ISB */
1704 handle_sync(s
, insn
, op1
, op2
, crm
);
1706 case 4: /* MSR (immediate) */
1707 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1710 unallocated_encoding(s
);
1715 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1718 /* Exception generation
1720 * 31 24 23 21 20 5 4 2 1 0
1721 * +-----------------+-----+------------------------+-----+----+
1722 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1723 * +-----------------------+------------------------+----------+
1725 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1727 int opc
= extract32(insn
, 21, 3);
1728 int op2_ll
= extract32(insn
, 0, 5);
1729 int imm16
= extract32(insn
, 5, 16);
1734 /* For SVC, HVC and SMC we advance the single-step state
1735 * machine before taking the exception. This is architecturally
1736 * mandated, to ensure that single-stepping a system call
1737 * instruction works properly.
1742 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
),
1743 default_exception_el(s
));
1746 if (s
->current_el
== 0) {
1747 unallocated_encoding(s
);
1750 /* The pre HVC helper handles cases when HVC gets trapped
1751 * as an undefined insn by runtime configuration.
1753 gen_a64_set_pc_im(s
->pc
- 4);
1754 gen_helper_pre_hvc(cpu_env
);
1756 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
), 2);
1759 if (s
->current_el
== 0) {
1760 unallocated_encoding(s
);
1763 gen_a64_set_pc_im(s
->pc
- 4);
1764 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1765 gen_helper_pre_smc(cpu_env
, tmp
);
1766 tcg_temp_free_i32(tmp
);
1768 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
), 3);
1771 unallocated_encoding(s
);
1777 unallocated_encoding(s
);
1781 gen_exception_bkpt_insn(s
, 4, syn_aa64_bkpt(imm16
));
1785 unallocated_encoding(s
);
1788 /* HLT. This has two purposes.
1789 * Architecturally, it is an external halting debug instruction.
1790 * Since QEMU doesn't implement external debug, we treat this as
1791 * it is required for halting debug disabled: it will UNDEF.
1792 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1794 if (semihosting_enabled() && imm16
== 0xf000) {
1795 #ifndef CONFIG_USER_ONLY
1796 /* In system mode, don't allow userspace access to semihosting,
1797 * to provide some semblance of security (and for consistency
1798 * with our 32-bit semihosting).
1800 if (s
->current_el
== 0) {
1801 unsupported_encoding(s
, insn
);
1805 gen_exception_internal_insn(s
, 0, EXCP_SEMIHOST
);
1807 unsupported_encoding(s
, insn
);
1811 if (op2_ll
< 1 || op2_ll
> 3) {
1812 unallocated_encoding(s
);
1815 /* DCPS1, DCPS2, DCPS3 */
1816 unsupported_encoding(s
, insn
);
1819 unallocated_encoding(s
);
1824 /* Unconditional branch (register)
1825 * 31 25 24 21 20 16 15 10 9 5 4 0
1826 * +---------------+-------+-------+-------+------+-------+
1827 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1828 * +---------------+-------+-------+-------+------+-------+
1830 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1832 unsigned int opc
, op2
, op3
, rn
, op4
;
1834 opc
= extract32(insn
, 21, 4);
1835 op2
= extract32(insn
, 16, 5);
1836 op3
= extract32(insn
, 10, 6);
1837 rn
= extract32(insn
, 5, 5);
1838 op4
= extract32(insn
, 0, 5);
1840 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1841 unallocated_encoding(s
);
1849 gen_a64_set_pc(s
, cpu_reg(s
, rn
));
1850 /* BLR also needs to load return address */
1852 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1856 if (s
->current_el
== 0) {
1857 unallocated_encoding(s
);
1860 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
1863 gen_helper_exception_return(cpu_env
);
1864 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
1867 /* Must exit loop to check un-masked IRQs */
1868 s
->base
.is_jmp
= DISAS_EXIT
;
1872 unallocated_encoding(s
);
1874 unsupported_encoding(s
, insn
);
1878 unallocated_encoding(s
);
1882 s
->base
.is_jmp
= DISAS_JUMP
;
1885 /* Branches, exception generating and system instructions */
1886 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1888 switch (extract32(insn
, 25, 7)) {
1889 case 0x0a: case 0x0b:
1890 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1891 disas_uncond_b_imm(s
, insn
);
1893 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1894 disas_comp_b_imm(s
, insn
);
1896 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1897 disas_test_b_imm(s
, insn
);
1899 case 0x2a: /* Conditional branch (immediate) */
1900 disas_cond_b_imm(s
, insn
);
1902 case 0x6a: /* Exception generation / System */
1903 if (insn
& (1 << 24)) {
1904 disas_system(s
, insn
);
1909 case 0x6b: /* Unconditional branch (register) */
1910 disas_uncond_b_reg(s
, insn
);
1913 unallocated_encoding(s
);
1919 * Load/Store exclusive instructions are implemented by remembering
1920 * the value/address loaded, and seeing if these are the same
1921 * when the store is performed. This is not actually the architecturally
1922 * mandated semantics, but it works for typical guest code sequences
1923 * and avoids having to monitor regular stores.
1925 * The store exclusive uses the atomic cmpxchg primitives to avoid
1926 * races in multi-threaded linux-user and when MTTCG softmmu is
1929 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
1930 TCGv_i64 addr
, int size
, bool is_pair
)
1932 int idx
= get_mem_index(s
);
1933 TCGMemOp memop
= s
->be_data
;
1935 g_assert(size
<= 3);
1937 g_assert(size
>= 2);
1939 /* The pair must be single-copy atomic for the doubleword. */
1940 memop
|= MO_64
| MO_ALIGN
;
1941 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
1942 if (s
->be_data
== MO_LE
) {
1943 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 0, 32);
1944 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 32, 32);
1946 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 32, 32);
1947 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 0, 32);
1950 /* The pair must be single-copy atomic for *each* doubleword, not
1951 the entire quadword, however it must be quadword aligned. */
1953 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
,
1954 memop
| MO_ALIGN_16
);
1956 TCGv_i64 addr2
= tcg_temp_new_i64();
1957 tcg_gen_addi_i64(addr2
, addr
, 8);
1958 tcg_gen_qemu_ld_i64(cpu_exclusive_high
, addr2
, idx
, memop
);
1959 tcg_temp_free_i64(addr2
);
1961 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
1962 tcg_gen_mov_i64(cpu_reg(s
, rt2
), cpu_exclusive_high
);
1965 memop
|= size
| MO_ALIGN
;
1966 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
1967 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
1969 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
1972 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1973 TCGv_i64 addr
, int size
, int is_pair
)
1975 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1976 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1979 * [addr + datasize] = {Rt2};
1985 * env->exclusive_addr = -1;
1987 TCGLabel
*fail_label
= gen_new_label();
1988 TCGLabel
*done_label
= gen_new_label();
1991 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
1993 tmp
= tcg_temp_new_i64();
1996 if (s
->be_data
== MO_LE
) {
1997 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
1999 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt2
), cpu_reg(s
, rt
));
2001 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
,
2002 cpu_exclusive_val
, tmp
,
2004 MO_64
| MO_ALIGN
| s
->be_data
);
2005 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2006 } else if (s
->be_data
== MO_LE
) {
2007 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2008 gen_helper_paired_cmpxchg64_le_parallel(tmp
, cpu_env
,
2013 gen_helper_paired_cmpxchg64_le(tmp
, cpu_env
, cpu_exclusive_addr
,
2014 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2017 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2018 gen_helper_paired_cmpxchg64_be_parallel(tmp
, cpu_env
,
2023 gen_helper_paired_cmpxchg64_be(tmp
, cpu_env
, cpu_exclusive_addr
,
2024 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2028 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
, cpu_exclusive_val
,
2029 cpu_reg(s
, rt
), get_mem_index(s
),
2030 size
| MO_ALIGN
| s
->be_data
);
2031 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2033 tcg_gen_mov_i64(cpu_reg(s
, rd
), tmp
);
2034 tcg_temp_free_i64(tmp
);
2035 tcg_gen_br(done_label
);
2037 gen_set_label(fail_label
);
2038 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
2039 gen_set_label(done_label
);
2040 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
2043 static void gen_compare_and_swap(DisasContext
*s
, int rs
, int rt
,
2046 TCGv_i64 tcg_rs
= cpu_reg(s
, rs
);
2047 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2048 int memidx
= get_mem_index(s
);
2049 TCGv_i64 addr
= cpu_reg_sp(s
, rn
);
2052 gen_check_sp_alignment(s
);
2054 tcg_gen_atomic_cmpxchg_i64(tcg_rs
, addr
, tcg_rs
, tcg_rt
, memidx
,
2055 size
| MO_ALIGN
| s
->be_data
);
2058 static void gen_compare_and_swap_pair(DisasContext
*s
, int rs
, int rt
,
2061 TCGv_i64 s1
= cpu_reg(s
, rs
);
2062 TCGv_i64 s2
= cpu_reg(s
, rs
+ 1);
2063 TCGv_i64 t1
= cpu_reg(s
, rt
);
2064 TCGv_i64 t2
= cpu_reg(s
, rt
+ 1);
2065 TCGv_i64 addr
= cpu_reg_sp(s
, rn
);
2066 int memidx
= get_mem_index(s
);
2069 gen_check_sp_alignment(s
);
2073 TCGv_i64 cmp
= tcg_temp_new_i64();
2074 TCGv_i64 val
= tcg_temp_new_i64();
2076 if (s
->be_data
== MO_LE
) {
2077 tcg_gen_concat32_i64(val
, t1
, t2
);
2078 tcg_gen_concat32_i64(cmp
, s1
, s2
);
2080 tcg_gen_concat32_i64(val
, t2
, t1
);
2081 tcg_gen_concat32_i64(cmp
, s2
, s1
);
2084 tcg_gen_atomic_cmpxchg_i64(cmp
, addr
, cmp
, val
, memidx
,
2085 MO_64
| MO_ALIGN
| s
->be_data
);
2086 tcg_temp_free_i64(val
);
2088 if (s
->be_data
== MO_LE
) {
2089 tcg_gen_extr32_i64(s1
, s2
, cmp
);
2091 tcg_gen_extr32_i64(s2
, s1
, cmp
);
2093 tcg_temp_free_i64(cmp
);
2094 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2095 TCGv_i32 tcg_rs
= tcg_const_i32(rs
);
2097 if (s
->be_data
== MO_LE
) {
2098 gen_helper_casp_le_parallel(cpu_env
, tcg_rs
, addr
, t1
, t2
);
2100 gen_helper_casp_be_parallel(cpu_env
, tcg_rs
, addr
, t1
, t2
);
2102 tcg_temp_free_i32(tcg_rs
);
2104 TCGv_i64 d1
= tcg_temp_new_i64();
2105 TCGv_i64 d2
= tcg_temp_new_i64();
2106 TCGv_i64 a2
= tcg_temp_new_i64();
2107 TCGv_i64 c1
= tcg_temp_new_i64();
2108 TCGv_i64 c2
= tcg_temp_new_i64();
2109 TCGv_i64 zero
= tcg_const_i64(0);
2111 /* Load the two words, in memory order. */
2112 tcg_gen_qemu_ld_i64(d1
, addr
, memidx
,
2113 MO_64
| MO_ALIGN_16
| s
->be_data
);
2114 tcg_gen_addi_i64(a2
, addr
, 8);
2115 tcg_gen_qemu_ld_i64(d2
, addr
, memidx
, MO_64
| s
->be_data
);
2117 /* Compare the two words, also in memory order. */
2118 tcg_gen_setcond_i64(TCG_COND_EQ
, c1
, d1
, s1
);
2119 tcg_gen_setcond_i64(TCG_COND_EQ
, c2
, d2
, s2
);
2120 tcg_gen_and_i64(c2
, c2
, c1
);
2122 /* If compare equal, write back new data, else write back old data. */
2123 tcg_gen_movcond_i64(TCG_COND_NE
, c1
, c2
, zero
, t1
, d1
);
2124 tcg_gen_movcond_i64(TCG_COND_NE
, c2
, c2
, zero
, t2
, d2
);
2125 tcg_gen_qemu_st_i64(c1
, addr
, memidx
, MO_64
| s
->be_data
);
2126 tcg_gen_qemu_st_i64(c2
, a2
, memidx
, MO_64
| s
->be_data
);
2127 tcg_temp_free_i64(a2
);
2128 tcg_temp_free_i64(c1
);
2129 tcg_temp_free_i64(c2
);
2130 tcg_temp_free_i64(zero
);
2132 /* Write back the data from memory to Rs. */
2133 tcg_gen_mov_i64(s1
, d1
);
2134 tcg_gen_mov_i64(s2
, d2
);
2135 tcg_temp_free_i64(d1
);
2136 tcg_temp_free_i64(d2
);
2140 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2141 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2143 static bool disas_ldst_compute_iss_sf(int size
, bool is_signed
, int opc
)
2145 int opc0
= extract32(opc
, 0, 1);
2149 regsize
= opc0
? 32 : 64;
2151 regsize
= size
== 3 ? 64 : 32;
2153 return regsize
== 64;
2156 /* Load/store exclusive
2158 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2159 * +-----+-------------+----+---+----+------+----+-------+------+------+
2160 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2161 * +-----+-------------+----+---+----+------+----+-------+------+------+
2163 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2164 * L: 0 -> store, 1 -> load
2165 * o2: 0 -> exclusive, 1 -> not
2166 * o1: 0 -> single register, 1 -> register pair
2167 * o0: 1 -> load-acquire/store-release, 0 -> not
2169 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
2171 int rt
= extract32(insn
, 0, 5);
2172 int rn
= extract32(insn
, 5, 5);
2173 int rt2
= extract32(insn
, 10, 5);
2174 int rs
= extract32(insn
, 16, 5);
2175 int is_lasr
= extract32(insn
, 15, 1);
2176 int o2_L_o1_o0
= extract32(insn
, 21, 3) * 2 | is_lasr
;
2177 int size
= extract32(insn
, 30, 2);
2180 switch (o2_L_o1_o0
) {
2181 case 0x0: /* STXR */
2182 case 0x1: /* STLXR */
2184 gen_check_sp_alignment(s
);
2187 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2189 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2190 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, false);
2193 case 0x4: /* LDXR */
2194 case 0x5: /* LDAXR */
2196 gen_check_sp_alignment(s
);
2198 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2200 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, false);
2202 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2206 case 0x9: /* STLR */
2207 /* Generate ISS for non-exclusive accesses including LASR. */
2209 gen_check_sp_alignment(s
);
2211 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2212 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2213 do_gpr_st(s
, cpu_reg(s
, rt
), tcg_addr
, size
, true, rt
,
2214 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2217 case 0xd: /* LDAR */
2218 /* Generate ISS for non-exclusive accesses including LASR. */
2220 gen_check_sp_alignment(s
);
2222 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2223 do_gpr_ld(s
, cpu_reg(s
, rt
), tcg_addr
, size
, false, false, true, rt
,
2224 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2225 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2228 case 0x2: case 0x3: /* CASP / STXP */
2229 if (size
& 2) { /* STXP / STLXP */
2231 gen_check_sp_alignment(s
);
2234 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2236 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2237 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, true);
2241 && ((rt
| rs
) & 1) == 0
2242 && arm_dc_feature(s
, ARM_FEATURE_V8_ATOMICS
)) {
2244 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2249 case 0x6: case 0x7: /* CASPA / LDXP */
2250 if (size
& 2) { /* LDXP / LDAXP */
2252 gen_check_sp_alignment(s
);
2254 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2256 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, true);
2258 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2263 && ((rt
| rs
) & 1) == 0
2264 && arm_dc_feature(s
, ARM_FEATURE_V8_ATOMICS
)) {
2265 /* CASPA / CASPAL */
2266 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2272 case 0xb: /* CASL */
2273 case 0xe: /* CASA */
2274 case 0xf: /* CASAL */
2275 if (rt2
== 31 && arm_dc_feature(s
, ARM_FEATURE_V8_ATOMICS
)) {
2276 gen_compare_and_swap(s
, rs
, rt
, rn
, size
);
2281 unallocated_encoding(s
);
2285 * Load register (literal)
2287 * 31 30 29 27 26 25 24 23 5 4 0
2288 * +-----+-------+---+-----+-------------------+-------+
2289 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2290 * +-----+-------+---+-----+-------------------+-------+
2292 * V: 1 -> vector (simd/fp)
2293 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2294 * 10-> 32 bit signed, 11 -> prefetch
2295 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2297 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
2299 int rt
= extract32(insn
, 0, 5);
2300 int64_t imm
= sextract32(insn
, 5, 19) << 2;
2301 bool is_vector
= extract32(insn
, 26, 1);
2302 int opc
= extract32(insn
, 30, 2);
2303 bool is_signed
= false;
2305 TCGv_i64 tcg_rt
, tcg_addr
;
2309 unallocated_encoding(s
);
2313 if (!fp_access_check(s
)) {
2318 /* PRFM (literal) : prefetch */
2321 size
= 2 + extract32(opc
, 0, 1);
2322 is_signed
= extract32(opc
, 1, 1);
2325 tcg_rt
= cpu_reg(s
, rt
);
2327 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
2329 do_fp_ld(s
, rt
, tcg_addr
, size
);
2331 /* Only unsigned 32bit loads target 32bit registers. */
2332 bool iss_sf
= opc
!= 0;
2334 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false,
2335 true, rt
, iss_sf
, false);
2337 tcg_temp_free_i64(tcg_addr
);
2341 * LDNP (Load Pair - non-temporal hint)
2342 * LDP (Load Pair - non vector)
2343 * LDPSW (Load Pair Signed Word - non vector)
2344 * STNP (Store Pair - non-temporal hint)
2345 * STP (Store Pair - non vector)
2346 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2347 * LDP (Load Pair of SIMD&FP)
2348 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2349 * STP (Store Pair of SIMD&FP)
2351 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2352 * +-----+-------+---+---+-------+---+-----------------------------+
2353 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2354 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2356 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2358 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2359 * V: 0 -> GPR, 1 -> Vector
2360 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2361 * 10 -> signed offset, 11 -> pre-index
2362 * L: 0 -> Store 1 -> Load
2364 * Rt, Rt2 = GPR or SIMD registers to be stored
2365 * Rn = general purpose register containing address
2366 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2368 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
2370 int rt
= extract32(insn
, 0, 5);
2371 int rn
= extract32(insn
, 5, 5);
2372 int rt2
= extract32(insn
, 10, 5);
2373 uint64_t offset
= sextract64(insn
, 15, 7);
2374 int index
= extract32(insn
, 23, 2);
2375 bool is_vector
= extract32(insn
, 26, 1);
2376 bool is_load
= extract32(insn
, 22, 1);
2377 int opc
= extract32(insn
, 30, 2);
2379 bool is_signed
= false;
2380 bool postindex
= false;
2383 TCGv_i64 tcg_addr
; /* calculated address */
2387 unallocated_encoding(s
);
2394 size
= 2 + extract32(opc
, 1, 1);
2395 is_signed
= extract32(opc
, 0, 1);
2396 if (!is_load
&& is_signed
) {
2397 unallocated_encoding(s
);
2403 case 1: /* post-index */
2408 /* signed offset with "non-temporal" hint. Since we don't emulate
2409 * caches we don't care about hints to the cache system about
2410 * data access patterns, and handle this identically to plain
2414 /* There is no non-temporal-hint version of LDPSW */
2415 unallocated_encoding(s
);
2420 case 2: /* signed offset, rn not updated */
2423 case 3: /* pre-index */
2429 if (is_vector
&& !fp_access_check(s
)) {
2436 gen_check_sp_alignment(s
);
2439 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2442 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2447 do_fp_ld(s
, rt
, tcg_addr
, size
);
2449 do_fp_st(s
, rt
, tcg_addr
, size
);
2451 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2453 do_fp_ld(s
, rt2
, tcg_addr
, size
);
2455 do_fp_st(s
, rt2
, tcg_addr
, size
);
2458 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2459 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2462 TCGv_i64 tmp
= tcg_temp_new_i64();
2464 /* Do not modify tcg_rt before recognizing any exception
2465 * from the second load.
2467 do_gpr_ld(s
, tmp
, tcg_addr
, size
, is_signed
, false,
2468 false, 0, false, false);
2469 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2470 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false,
2471 false, 0, false, false);
2473 tcg_gen_mov_i64(tcg_rt
, tmp
);
2474 tcg_temp_free_i64(tmp
);
2476 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2477 false, 0, false, false);
2478 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2479 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
,
2480 false, 0, false, false);
2486 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
2488 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2490 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
2495 * Load/store (immediate post-indexed)
2496 * Load/store (immediate pre-indexed)
2497 * Load/store (unscaled immediate)
2499 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2500 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2501 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2502 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2504 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2506 * V = 0 -> non-vector
2507 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2508 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2510 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
2516 int rn
= extract32(insn
, 5, 5);
2517 int imm9
= sextract32(insn
, 12, 9);
2518 int idx
= extract32(insn
, 10, 2);
2519 bool is_signed
= false;
2520 bool is_store
= false;
2521 bool is_extended
= false;
2522 bool is_unpriv
= (idx
== 2);
2523 bool iss_valid
= !is_vector
;
2530 size
|= (opc
& 2) << 1;
2531 if (size
> 4 || is_unpriv
) {
2532 unallocated_encoding(s
);
2535 is_store
= ((opc
& 1) == 0);
2536 if (!fp_access_check(s
)) {
2540 if (size
== 3 && opc
== 2) {
2541 /* PRFM - prefetch */
2543 unallocated_encoding(s
);
2548 if (opc
== 3 && size
> 1) {
2549 unallocated_encoding(s
);
2552 is_store
= (opc
== 0);
2553 is_signed
= extract32(opc
, 1, 1);
2554 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2572 g_assert_not_reached();
2576 gen_check_sp_alignment(s
);
2578 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2581 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2586 do_fp_st(s
, rt
, tcg_addr
, size
);
2588 do_fp_ld(s
, rt
, tcg_addr
, size
);
2591 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2592 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2593 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2596 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
,
2597 iss_valid
, rt
, iss_sf
, false);
2599 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
2600 is_signed
, is_extended
, memidx
,
2601 iss_valid
, rt
, iss_sf
, false);
2606 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2608 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2610 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2615 * Load/store (register offset)
2617 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2618 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2619 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2620 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2623 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2624 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2626 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2627 * opc<0>: 0 -> store, 1 -> load
2628 * V: 1 -> vector/simd
2629 * opt: extend encoding (see DecodeRegExtend)
2630 * S: if S=1 then scale (essentially index by sizeof(size))
2631 * Rt: register to transfer into/out of
2632 * Rn: address register or SP for base
2633 * Rm: offset register or ZR for offset
2635 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
2641 int rn
= extract32(insn
, 5, 5);
2642 int shift
= extract32(insn
, 12, 1);
2643 int rm
= extract32(insn
, 16, 5);
2644 int opt
= extract32(insn
, 13, 3);
2645 bool is_signed
= false;
2646 bool is_store
= false;
2647 bool is_extended
= false;
2652 if (extract32(opt
, 1, 1) == 0) {
2653 unallocated_encoding(s
);
2658 size
|= (opc
& 2) << 1;
2660 unallocated_encoding(s
);
2663 is_store
= !extract32(opc
, 0, 1);
2664 if (!fp_access_check(s
)) {
2668 if (size
== 3 && opc
== 2) {
2669 /* PRFM - prefetch */
2672 if (opc
== 3 && size
> 1) {
2673 unallocated_encoding(s
);
2676 is_store
= (opc
== 0);
2677 is_signed
= extract32(opc
, 1, 1);
2678 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2682 gen_check_sp_alignment(s
);
2684 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2686 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2687 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2689 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2693 do_fp_st(s
, rt
, tcg_addr
, size
);
2695 do_fp_ld(s
, rt
, tcg_addr
, size
);
2698 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2699 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2701 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2702 true, rt
, iss_sf
, false);
2704 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
,
2705 is_signed
, is_extended
,
2706 true, rt
, iss_sf
, false);
2712 * Load/store (unsigned immediate)
2714 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2715 * +----+-------+---+-----+-----+------------+-------+------+
2716 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2717 * +----+-------+---+-----+-----+------------+-------+------+
2720 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2721 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2723 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2724 * opc<0>: 0 -> store, 1 -> load
2725 * Rn: base address register (inc SP)
2726 * Rt: target register
2728 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
2734 int rn
= extract32(insn
, 5, 5);
2735 unsigned int imm12
= extract32(insn
, 10, 12);
2736 unsigned int offset
;
2741 bool is_signed
= false;
2742 bool is_extended
= false;
2745 size
|= (opc
& 2) << 1;
2747 unallocated_encoding(s
);
2750 is_store
= !extract32(opc
, 0, 1);
2751 if (!fp_access_check(s
)) {
2755 if (size
== 3 && opc
== 2) {
2756 /* PRFM - prefetch */
2759 if (opc
== 3 && size
> 1) {
2760 unallocated_encoding(s
);
2763 is_store
= (opc
== 0);
2764 is_signed
= extract32(opc
, 1, 1);
2765 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2769 gen_check_sp_alignment(s
);
2771 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2772 offset
= imm12
<< size
;
2773 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2777 do_fp_st(s
, rt
, tcg_addr
, size
);
2779 do_fp_ld(s
, rt
, tcg_addr
, size
);
2782 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2783 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2785 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2786 true, rt
, iss_sf
, false);
2788 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
,
2789 true, rt
, iss_sf
, false);
2794 /* Atomic memory operations
2796 * 31 30 27 26 24 22 21 16 15 12 10 5 0
2797 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
2798 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
2799 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
2801 * Rt: the result register
2802 * Rn: base address or SP
2803 * Rs: the source register for the operation
2804 * V: vector flag (always 0 as of v8.3)
2808 static void disas_ldst_atomic(DisasContext
*s
, uint32_t insn
,
2809 int size
, int rt
, bool is_vector
)
2811 int rs
= extract32(insn
, 16, 5);
2812 int rn
= extract32(insn
, 5, 5);
2813 int o3_opc
= extract32(insn
, 12, 4);
2814 int feature
= ARM_FEATURE_V8_ATOMICS
;
2815 TCGv_i64 tcg_rn
, tcg_rs
;
2816 AtomicThreeOpFn
*fn
;
2819 unallocated_encoding(s
);
2823 case 000: /* LDADD */
2824 fn
= tcg_gen_atomic_fetch_add_i64
;
2826 case 001: /* LDCLR */
2827 fn
= tcg_gen_atomic_fetch_and_i64
;
2829 case 002: /* LDEOR */
2830 fn
= tcg_gen_atomic_fetch_xor_i64
;
2832 case 003: /* LDSET */
2833 fn
= tcg_gen_atomic_fetch_or_i64
;
2835 case 004: /* LDSMAX */
2836 fn
= tcg_gen_atomic_fetch_smax_i64
;
2838 case 005: /* LDSMIN */
2839 fn
= tcg_gen_atomic_fetch_smin_i64
;
2841 case 006: /* LDUMAX */
2842 fn
= tcg_gen_atomic_fetch_umax_i64
;
2844 case 007: /* LDUMIN */
2845 fn
= tcg_gen_atomic_fetch_umin_i64
;
2848 fn
= tcg_gen_atomic_xchg_i64
;
2851 unallocated_encoding(s
);
2854 if (!arm_dc_feature(s
, feature
)) {
2855 unallocated_encoding(s
);
2860 gen_check_sp_alignment(s
);
2862 tcg_rn
= cpu_reg_sp(s
, rn
);
2863 tcg_rs
= read_cpu_reg(s
, rs
, true);
2865 if (o3_opc
== 1) { /* LDCLR */
2866 tcg_gen_not_i64(tcg_rs
, tcg_rs
);
2869 /* The tcg atomic primitives are all full barriers. Therefore we
2870 * can ignore the Acquire and Release bits of this instruction.
2872 fn(cpu_reg(s
, rt
), tcg_rn
, tcg_rs
, get_mem_index(s
),
2873 s
->be_data
| size
| MO_ALIGN
);
2876 /* Load/store register (all forms) */
2877 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2879 int rt
= extract32(insn
, 0, 5);
2880 int opc
= extract32(insn
, 22, 2);
2881 bool is_vector
= extract32(insn
, 26, 1);
2882 int size
= extract32(insn
, 30, 2);
2884 switch (extract32(insn
, 24, 2)) {
2886 if (extract32(insn
, 21, 1) == 0) {
2887 /* Load/store register (unscaled immediate)
2888 * Load/store immediate pre/post-indexed
2889 * Load/store register unprivileged
2891 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
2894 switch (extract32(insn
, 10, 2)) {
2896 disas_ldst_atomic(s
, insn
, size
, rt
, is_vector
);
2899 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
2904 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
2907 unallocated_encoding(s
);
2910 /* AdvSIMD load/store multiple structures
2912 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2913 * +---+---+---------------+---+-------------+--------+------+------+------+
2914 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2915 * +---+---+---------------+---+-------------+--------+------+------+------+
2917 * AdvSIMD load/store multiple structures (post-indexed)
2919 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2920 * +---+---+---------------+---+---+---------+--------+------+------+------+
2921 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2922 * +---+---+---------------+---+---+---------+--------+------+------+------+
2924 * Rt: first (or only) SIMD&FP register to be transferred
2925 * Rn: base address or SP
2926 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2928 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
2930 int rt
= extract32(insn
, 0, 5);
2931 int rn
= extract32(insn
, 5, 5);
2932 int size
= extract32(insn
, 10, 2);
2933 int opcode
= extract32(insn
, 12, 4);
2934 bool is_store
= !extract32(insn
, 22, 1);
2935 bool is_postidx
= extract32(insn
, 23, 1);
2936 bool is_q
= extract32(insn
, 30, 1);
2937 TCGv_i64 tcg_addr
, tcg_rn
;
2939 int ebytes
= 1 << size
;
2940 int elements
= (is_q
? 128 : 64) / (8 << size
);
2941 int rpt
; /* num iterations */
2942 int selem
; /* structure elements */
2945 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
2946 unallocated_encoding(s
);
2950 /* From the shared decode logic */
2981 unallocated_encoding(s
);
2985 if (size
== 3 && !is_q
&& selem
!= 1) {
2987 unallocated_encoding(s
);
2991 if (!fp_access_check(s
)) {
2996 gen_check_sp_alignment(s
);
2999 tcg_rn
= cpu_reg_sp(s
, rn
);
3000 tcg_addr
= tcg_temp_new_i64();
3001 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
3003 for (r
= 0; r
< rpt
; r
++) {
3005 for (e
= 0; e
< elements
; e
++) {
3006 int tt
= (rt
+ r
) % 32;
3008 for (xs
= 0; xs
< selem
; xs
++) {
3010 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
3012 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
3014 /* For non-quad operations, setting a slice of the low
3015 * 64 bits of the register clears the high 64 bits (in
3016 * the ARM ARM pseudocode this is implicit in the fact
3017 * that 'rval' is a 64 bit wide variable).
3018 * For quad operations, we might still need to zero the
3019 * high bits of SVE. We optimize by noticing that we only
3020 * need to do this the first time we touch a register.
3022 if (e
== 0 && (r
== 0 || xs
== selem
- 1)) {
3023 clear_vec_high(s
, is_q
, tt
);
3026 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
3033 int rm
= extract32(insn
, 16, 5);
3035 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
3037 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3040 tcg_temp_free_i64(tcg_addr
);
3043 /* AdvSIMD load/store single structure
3045 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3046 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3047 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3048 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3050 * AdvSIMD load/store single structure (post-indexed)
3052 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3053 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3054 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3055 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3057 * Rt: first (or only) SIMD&FP register to be transferred
3058 * Rn: base address or SP
3059 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3060 * index = encoded in Q:S:size dependent on size
3062 * lane_size = encoded in R, opc
3063 * transfer width = encoded in opc, S, size
3065 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
3067 int rt
= extract32(insn
, 0, 5);
3068 int rn
= extract32(insn
, 5, 5);
3069 int size
= extract32(insn
, 10, 2);
3070 int S
= extract32(insn
, 12, 1);
3071 int opc
= extract32(insn
, 13, 3);
3072 int R
= extract32(insn
, 21, 1);
3073 int is_load
= extract32(insn
, 22, 1);
3074 int is_postidx
= extract32(insn
, 23, 1);
3075 int is_q
= extract32(insn
, 30, 1);
3077 int scale
= extract32(opc
, 1, 2);
3078 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
3079 bool replicate
= false;
3080 int index
= is_q
<< 3 | S
<< 2 | size
;
3082 TCGv_i64 tcg_addr
, tcg_rn
;
3086 if (!is_load
|| S
) {
3087 unallocated_encoding(s
);
3096 if (extract32(size
, 0, 1)) {
3097 unallocated_encoding(s
);
3103 if (extract32(size
, 1, 1)) {
3104 unallocated_encoding(s
);
3107 if (!extract32(size
, 0, 1)) {
3111 unallocated_encoding(s
);
3119 g_assert_not_reached();
3122 if (!fp_access_check(s
)) {
3126 ebytes
= 1 << scale
;
3129 gen_check_sp_alignment(s
);
3132 tcg_rn
= cpu_reg_sp(s
, rn
);
3133 tcg_addr
= tcg_temp_new_i64();
3134 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
3136 for (xs
= 0; xs
< selem
; xs
++) {
3138 /* Load and replicate to all elements */
3140 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3142 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
3143 get_mem_index(s
), s
->be_data
+ scale
);
3146 mulconst
= 0x0101010101010101ULL
;
3149 mulconst
= 0x0001000100010001ULL
;
3152 mulconst
= 0x0000000100000001ULL
;
3158 g_assert_not_reached();
3161 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
3163 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
3165 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
3167 tcg_temp_free_i64(tcg_tmp
);
3168 clear_vec_high(s
, is_q
, rt
);
3170 /* Load/store one element per register */
3172 do_vec_ld(s
, rt
, index
, tcg_addr
, scale
);
3174 do_vec_st(s
, rt
, index
, tcg_addr
, scale
);
3177 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
3182 int rm
= extract32(insn
, 16, 5);
3184 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
3186 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3189 tcg_temp_free_i64(tcg_addr
);
3192 /* Loads and stores */
3193 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
3195 switch (extract32(insn
, 24, 6)) {
3196 case 0x08: /* Load/store exclusive */
3197 disas_ldst_excl(s
, insn
);
3199 case 0x18: case 0x1c: /* Load register (literal) */
3200 disas_ld_lit(s
, insn
);
3202 case 0x28: case 0x29:
3203 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
3204 disas_ldst_pair(s
, insn
);
3206 case 0x38: case 0x39:
3207 case 0x3c: case 0x3d: /* Load/store register (all forms) */
3208 disas_ldst_reg(s
, insn
);
3210 case 0x0c: /* AdvSIMD load/store multiple structures */
3211 disas_ldst_multiple_struct(s
, insn
);
3213 case 0x0d: /* AdvSIMD load/store single structure */
3214 disas_ldst_single_struct(s
, insn
);
3217 unallocated_encoding(s
);
3222 /* PC-rel. addressing
3223 * 31 30 29 28 24 23 5 4 0
3224 * +----+-------+-----------+-------------------+------+
3225 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
3226 * +----+-------+-----------+-------------------+------+
3228 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
3230 unsigned int page
, rd
;
3234 page
= extract32(insn
, 31, 1);
3235 /* SignExtend(immhi:immlo) -> offset */
3236 offset
= sextract64(insn
, 5, 19);
3237 offset
= offset
<< 2 | extract32(insn
, 29, 2);
3238 rd
= extract32(insn
, 0, 5);
3242 /* ADRP (page based) */
3247 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
3251 * Add/subtract (immediate)
3253 * 31 30 29 28 24 23 22 21 10 9 5 4 0
3254 * +--+--+--+-----------+-----+-------------+-----+-----+
3255 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
3256 * +--+--+--+-----------+-----+-------------+-----+-----+
3258 * sf: 0 -> 32bit, 1 -> 64bit
3259 * op: 0 -> add , 1 -> sub
3261 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
3263 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
3265 int rd
= extract32(insn
, 0, 5);
3266 int rn
= extract32(insn
, 5, 5);
3267 uint64_t imm
= extract32(insn
, 10, 12);
3268 int shift
= extract32(insn
, 22, 2);
3269 bool setflags
= extract32(insn
, 29, 1);
3270 bool sub_op
= extract32(insn
, 30, 1);
3271 bool is_64bit
= extract32(insn
, 31, 1);
3273 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
3274 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
3275 TCGv_i64 tcg_result
;
3284 unallocated_encoding(s
);
3288 tcg_result
= tcg_temp_new_i64();
3291 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
3293 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
3296 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
3298 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3300 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3302 tcg_temp_free_i64(tcg_imm
);
3306 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3308 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3311 tcg_temp_free_i64(tcg_result
);
3314 /* The input should be a value in the bottom e bits (with higher
3315 * bits zero); returns that value replicated into every element
3316 * of size e in a 64 bit integer.
3318 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
3328 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
3329 static inline uint64_t bitmask64(unsigned int length
)
3331 assert(length
> 0 && length
<= 64);
3332 return ~0ULL >> (64 - length
);
3335 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
3336 * only require the wmask. Returns false if the imms/immr/immn are a reserved
3337 * value (ie should cause a guest UNDEF exception), and true if they are
3338 * valid, in which case the decoded bit pattern is written to result.
3340 bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
3341 unsigned int imms
, unsigned int immr
)
3344 unsigned e
, levels
, s
, r
;
3347 assert(immn
< 2 && imms
< 64 && immr
< 64);
3349 /* The bit patterns we create here are 64 bit patterns which
3350 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
3351 * 64 bits each. Each element contains the same value: a run
3352 * of between 1 and e-1 non-zero bits, rotated within the
3353 * element by between 0 and e-1 bits.
3355 * The element size and run length are encoded into immn (1 bit)
3356 * and imms (6 bits) as follows:
3357 * 64 bit elements: immn = 1, imms = <length of run - 1>
3358 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
3359 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
3360 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
3361 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
3362 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
3363 * Notice that immn = 0, imms = 11111x is the only combination
3364 * not covered by one of the above options; this is reserved.
3365 * Further, <length of run - 1> all-ones is a reserved pattern.
3367 * In all cases the rotation is by immr % e (and immr is 6 bits).
3370 /* First determine the element size */
3371 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
3373 /* This is the immn == 0, imms == 0x11111x case */
3383 /* <length of run - 1> mustn't be all-ones. */
3387 /* Create the value of one element: s+1 set bits rotated
3388 * by r within the element (which is e bits wide)...
3390 mask
= bitmask64(s
+ 1);
3392 mask
= (mask
>> r
) | (mask
<< (e
- r
));
3393 mask
&= bitmask64(e
);
3395 /* ...then replicate the element over the whole 64 bit value */
3396 mask
= bitfield_replicate(mask
, e
);
3401 /* Logical (immediate)
3402 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3403 * +----+-----+-------------+---+------+------+------+------+
3404 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
3405 * +----+-----+-------------+---+------+------+------+------+
3407 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
3409 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
3410 TCGv_i64 tcg_rd
, tcg_rn
;
3412 bool is_and
= false;
3414 sf
= extract32(insn
, 31, 1);
3415 opc
= extract32(insn
, 29, 2);
3416 is_n
= extract32(insn
, 22, 1);
3417 immr
= extract32(insn
, 16, 6);
3418 imms
= extract32(insn
, 10, 6);
3419 rn
= extract32(insn
, 5, 5);
3420 rd
= extract32(insn
, 0, 5);
3423 unallocated_encoding(s
);
3427 if (opc
== 0x3) { /* ANDS */
3428 tcg_rd
= cpu_reg(s
, rd
);
3430 tcg_rd
= cpu_reg_sp(s
, rd
);
3432 tcg_rn
= cpu_reg(s
, rn
);
3434 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
3435 /* some immediate field values are reserved */
3436 unallocated_encoding(s
);
3441 wmask
&= 0xffffffff;
3445 case 0x3: /* ANDS */
3447 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
3451 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
3454 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
3457 assert(FALSE
); /* must handle all above */
3461 if (!sf
&& !is_and
) {
3462 /* zero extend final result; we know we can skip this for AND
3463 * since the immediate had the high 32 bits clear.
3465 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3468 if (opc
== 3) { /* ANDS */
3469 gen_logic_CC(sf
, tcg_rd
);
3474 * Move wide (immediate)
3476 * 31 30 29 28 23 22 21 20 5 4 0
3477 * +--+-----+-------------+-----+----------------+------+
3478 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
3479 * +--+-----+-------------+-----+----------------+------+
3481 * sf: 0 -> 32 bit, 1 -> 64 bit
3482 * opc: 00 -> N, 10 -> Z, 11 -> K
3483 * hw: shift/16 (0,16, and sf only 32, 48)
3485 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
3487 int rd
= extract32(insn
, 0, 5);
3488 uint64_t imm
= extract32(insn
, 5, 16);
3489 int sf
= extract32(insn
, 31, 1);
3490 int opc
= extract32(insn
, 29, 2);
3491 int pos
= extract32(insn
, 21, 2) << 4;
3492 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3495 if (!sf
&& (pos
>= 32)) {
3496 unallocated_encoding(s
);
3510 tcg_gen_movi_i64(tcg_rd
, imm
);
3513 tcg_imm
= tcg_const_i64(imm
);
3514 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
3515 tcg_temp_free_i64(tcg_imm
);
3517 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3521 unallocated_encoding(s
);
3527 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3528 * +----+-----+-------------+---+------+------+------+------+
3529 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3530 * +----+-----+-------------+---+------+------+------+------+
3532 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
3534 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
3535 TCGv_i64 tcg_rd
, tcg_tmp
;
3537 sf
= extract32(insn
, 31, 1);
3538 opc
= extract32(insn
, 29, 2);
3539 n
= extract32(insn
, 22, 1);
3540 ri
= extract32(insn
, 16, 6);
3541 si
= extract32(insn
, 10, 6);
3542 rn
= extract32(insn
, 5, 5);
3543 rd
= extract32(insn
, 0, 5);
3544 bitsize
= sf
? 64 : 32;
3546 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
3547 unallocated_encoding(s
);
3551 tcg_rd
= cpu_reg(s
, rd
);
3553 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3554 to be smaller than bitsize, we'll never reference data outside the
3555 low 32-bits anyway. */
3556 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
3558 /* Recognize simple(r) extractions. */
3560 /* Wd<s-r:0> = Wn<s:r> */
3561 len
= (si
- ri
) + 1;
3562 if (opc
== 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
3563 tcg_gen_sextract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3565 } else if (opc
== 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
3566 tcg_gen_extract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3569 /* opc == 1, BXFIL fall through to deposit */
3570 tcg_gen_extract_i64(tcg_tmp
, tcg_tmp
, ri
, len
);
3573 /* Handle the ri > si case with a deposit
3574 * Wd<32+s-r,32-r> = Wn<s:0>
3577 pos
= (bitsize
- ri
) & (bitsize
- 1);
3580 if (opc
== 0 && len
< ri
) {
3581 /* SBFM: sign extend the destination field from len to fill
3582 the balance of the word. Let the deposit below insert all
3583 of those sign bits. */
3584 tcg_gen_sextract_i64(tcg_tmp
, tcg_tmp
, 0, len
);
3588 if (opc
== 1) { /* BFM, BXFIL */
3589 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
3591 /* SBFM or UBFM: We start with zero, and we haven't modified
3592 any bits outside bitsize, therefore the zero-extension
3593 below is unneeded. */
3594 tcg_gen_deposit_z_i64(tcg_rd
, tcg_tmp
, pos
, len
);
3599 if (!sf
) { /* zero extend final result */
3600 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3605 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3606 * +----+------+-------------+---+----+------+--------+------+------+
3607 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3608 * +----+------+-------------+---+----+------+--------+------+------+
3610 static void disas_extract(DisasContext
*s
, uint32_t insn
)
3612 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
3614 sf
= extract32(insn
, 31, 1);
3615 n
= extract32(insn
, 22, 1);
3616 rm
= extract32(insn
, 16, 5);
3617 imm
= extract32(insn
, 10, 6);
3618 rn
= extract32(insn
, 5, 5);
3619 rd
= extract32(insn
, 0, 5);
3620 op21
= extract32(insn
, 29, 2);
3621 op0
= extract32(insn
, 21, 1);
3622 bitsize
= sf
? 64 : 32;
3624 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
3625 unallocated_encoding(s
);
3627 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
3629 tcg_rd
= cpu_reg(s
, rd
);
3631 if (unlikely(imm
== 0)) {
3632 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3633 * so an extract from bit 0 is a special case.
3636 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
3638 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
3640 } else if (rm
== rn
) { /* ROR */
3641 tcg_rm
= cpu_reg(s
, rm
);
3643 tcg_gen_rotri_i64(tcg_rd
, tcg_rm
, imm
);
3645 TCGv_i32 tmp
= tcg_temp_new_i32();
3646 tcg_gen_extrl_i64_i32(tmp
, tcg_rm
);
3647 tcg_gen_rotri_i32(tmp
, tmp
, imm
);
3648 tcg_gen_extu_i32_i64(tcg_rd
, tmp
);
3649 tcg_temp_free_i32(tmp
);
3652 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3653 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3654 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
3655 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
3656 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
3658 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3664 /* Data processing - immediate */
3665 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
3667 switch (extract32(insn
, 23, 6)) {
3668 case 0x20: case 0x21: /* PC-rel. addressing */
3669 disas_pc_rel_adr(s
, insn
);
3671 case 0x22: case 0x23: /* Add/subtract (immediate) */
3672 disas_add_sub_imm(s
, insn
);
3674 case 0x24: /* Logical (immediate) */
3675 disas_logic_imm(s
, insn
);
3677 case 0x25: /* Move wide (immediate) */
3678 disas_movw_imm(s
, insn
);
3680 case 0x26: /* Bitfield */
3681 disas_bitfield(s
, insn
);
3683 case 0x27: /* Extract */
3684 disas_extract(s
, insn
);
3687 unallocated_encoding(s
);
3692 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3693 * Note that it is the caller's responsibility to ensure that the
3694 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3695 * mandated semantics for out of range shifts.
3697 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3698 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
3700 switch (shift_type
) {
3701 case A64_SHIFT_TYPE_LSL
:
3702 tcg_gen_shl_i64(dst
, src
, shift_amount
);
3704 case A64_SHIFT_TYPE_LSR
:
3705 tcg_gen_shr_i64(dst
, src
, shift_amount
);
3707 case A64_SHIFT_TYPE_ASR
:
3709 tcg_gen_ext32s_i64(dst
, src
);
3711 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
3713 case A64_SHIFT_TYPE_ROR
:
3715 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
3718 t0
= tcg_temp_new_i32();
3719 t1
= tcg_temp_new_i32();
3720 tcg_gen_extrl_i64_i32(t0
, src
);
3721 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
3722 tcg_gen_rotr_i32(t0
, t0
, t1
);
3723 tcg_gen_extu_i32_i64(dst
, t0
);
3724 tcg_temp_free_i32(t0
);
3725 tcg_temp_free_i32(t1
);
3729 assert(FALSE
); /* all shift types should be handled */
3733 if (!sf
) { /* zero extend final result */
3734 tcg_gen_ext32u_i64(dst
, dst
);
3738 /* Shift a TCGv src by immediate, put result in dst.
3739 * The shift amount must be in range (this should always be true as the
3740 * relevant instructions will UNDEF on bad shift immediates).
3742 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3743 enum a64_shift_type shift_type
, unsigned int shift_i
)
3745 assert(shift_i
< (sf
? 64 : 32));
3748 tcg_gen_mov_i64(dst
, src
);
3750 TCGv_i64 shift_const
;
3752 shift_const
= tcg_const_i64(shift_i
);
3753 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
3754 tcg_temp_free_i64(shift_const
);
3758 /* Logical (shifted register)
3759 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3760 * +----+-----+-----------+-------+---+------+--------+------+------+
3761 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3762 * +----+-----+-----------+-------+---+------+--------+------+------+
3764 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
3766 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
3767 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
3769 sf
= extract32(insn
, 31, 1);
3770 opc
= extract32(insn
, 29, 2);
3771 shift_type
= extract32(insn
, 22, 2);
3772 invert
= extract32(insn
, 21, 1);
3773 rm
= extract32(insn
, 16, 5);
3774 shift_amount
= extract32(insn
, 10, 6);
3775 rn
= extract32(insn
, 5, 5);
3776 rd
= extract32(insn
, 0, 5);
3778 if (!sf
&& (shift_amount
& (1 << 5))) {
3779 unallocated_encoding(s
);
3783 tcg_rd
= cpu_reg(s
, rd
);
3785 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3786 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3787 * register-register MOV and MVN, so it is worth special casing.
3789 tcg_rm
= cpu_reg(s
, rm
);
3791 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3793 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3797 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3799 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3805 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3808 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3811 tcg_rn
= cpu_reg(s
, rn
);
3813 switch (opc
| (invert
<< 2)) {
3816 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3819 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3822 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3826 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3829 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3832 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3840 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3844 gen_logic_CC(sf
, tcg_rd
);
3849 * Add/subtract (extended register)
3851 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3852 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3853 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3854 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3856 * sf: 0 -> 32bit, 1 -> 64bit
3857 * op: 0 -> add , 1 -> sub
3860 * option: extension type (see DecodeRegExtend)
3861 * imm3: optional shift to Rm
3863 * Rd = Rn + LSL(extend(Rm), amount)
3865 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3867 int rd
= extract32(insn
, 0, 5);
3868 int rn
= extract32(insn
, 5, 5);
3869 int imm3
= extract32(insn
, 10, 3);
3870 int option
= extract32(insn
, 13, 3);
3871 int rm
= extract32(insn
, 16, 5);
3872 bool setflags
= extract32(insn
, 29, 1);
3873 bool sub_op
= extract32(insn
, 30, 1);
3874 bool sf
= extract32(insn
, 31, 1);
3876 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3878 TCGv_i64 tcg_result
;
3881 unallocated_encoding(s
);
3885 /* non-flag setting ops may use SP */
3887 tcg_rd
= cpu_reg_sp(s
, rd
);
3889 tcg_rd
= cpu_reg(s
, rd
);
3891 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3893 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3894 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3896 tcg_result
= tcg_temp_new_i64();
3900 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3902 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3906 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3908 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3913 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3915 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3918 tcg_temp_free_i64(tcg_result
);
3922 * Add/subtract (shifted register)
3924 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3925 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3926 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3927 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3929 * sf: 0 -> 32bit, 1 -> 64bit
3930 * op: 0 -> add , 1 -> sub
3932 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3933 * imm6: Shift amount to apply to Rm before the add/sub
3935 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
3937 int rd
= extract32(insn
, 0, 5);
3938 int rn
= extract32(insn
, 5, 5);
3939 int imm6
= extract32(insn
, 10, 6);
3940 int rm
= extract32(insn
, 16, 5);
3941 int shift_type
= extract32(insn
, 22, 2);
3942 bool setflags
= extract32(insn
, 29, 1);
3943 bool sub_op
= extract32(insn
, 30, 1);
3944 bool sf
= extract32(insn
, 31, 1);
3946 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3947 TCGv_i64 tcg_rn
, tcg_rm
;
3948 TCGv_i64 tcg_result
;
3950 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
3951 unallocated_encoding(s
);
3955 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3956 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3958 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
3960 tcg_result
= tcg_temp_new_i64();
3964 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3966 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3970 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3972 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3977 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3979 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3982 tcg_temp_free_i64(tcg_result
);
3985 /* Data-processing (3 source)
3987 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3988 * +--+------+-----------+------+------+----+------+------+------+
3989 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3990 * +--+------+-----------+------+------+----+------+------+------+
3992 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
3994 int rd
= extract32(insn
, 0, 5);
3995 int rn
= extract32(insn
, 5, 5);
3996 int ra
= extract32(insn
, 10, 5);
3997 int rm
= extract32(insn
, 16, 5);
3998 int op_id
= (extract32(insn
, 29, 3) << 4) |
3999 (extract32(insn
, 21, 3) << 1) |
4000 extract32(insn
, 15, 1);
4001 bool sf
= extract32(insn
, 31, 1);
4002 bool is_sub
= extract32(op_id
, 0, 1);
4003 bool is_high
= extract32(op_id
, 2, 1);
4004 bool is_signed
= false;
4009 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
4011 case 0x42: /* SMADDL */
4012 case 0x43: /* SMSUBL */
4013 case 0x44: /* SMULH */
4016 case 0x0: /* MADD (32bit) */
4017 case 0x1: /* MSUB (32bit) */
4018 case 0x40: /* MADD (64bit) */
4019 case 0x41: /* MSUB (64bit) */
4020 case 0x4a: /* UMADDL */
4021 case 0x4b: /* UMSUBL */
4022 case 0x4c: /* UMULH */
4025 unallocated_encoding(s
);
4030 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
4031 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4032 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4033 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
4036 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4038 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4041 tcg_temp_free_i64(low_bits
);
4045 tcg_op1
= tcg_temp_new_i64();
4046 tcg_op2
= tcg_temp_new_i64();
4047 tcg_tmp
= tcg_temp_new_i64();
4050 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
4051 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
4054 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
4055 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
4057 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
4058 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
4062 if (ra
== 31 && !is_sub
) {
4063 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
4064 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
4066 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
4068 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4070 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4075 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
4078 tcg_temp_free_i64(tcg_op1
);
4079 tcg_temp_free_i64(tcg_op2
);
4080 tcg_temp_free_i64(tcg_tmp
);
4083 /* Add/subtract (with carry)
4084 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
4085 * +--+--+--+------------------------+------+---------+------+-----+
4086 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
4087 * +--+--+--+------------------------+------+---------+------+-----+
4091 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
4093 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
4094 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
4096 if (extract32(insn
, 10, 6) != 0) {
4097 unallocated_encoding(s
);
4101 sf
= extract32(insn
, 31, 1);
4102 op
= extract32(insn
, 30, 1);
4103 setflags
= extract32(insn
, 29, 1);
4104 rm
= extract32(insn
, 16, 5);
4105 rn
= extract32(insn
, 5, 5);
4106 rd
= extract32(insn
, 0, 5);
4108 tcg_rd
= cpu_reg(s
, rd
);
4109 tcg_rn
= cpu_reg(s
, rn
);
4112 tcg_y
= new_tmp_a64(s
);
4113 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
4115 tcg_y
= cpu_reg(s
, rm
);
4119 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4121 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4125 /* Conditional compare (immediate / register)
4126 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4127 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4128 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
4129 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4132 static void disas_cc(DisasContext
*s
, uint32_t insn
)
4134 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
4135 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
4136 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
4139 if (!extract32(insn
, 29, 1)) {
4140 unallocated_encoding(s
);
4143 if (insn
& (1 << 10 | 1 << 4)) {
4144 unallocated_encoding(s
);
4147 sf
= extract32(insn
, 31, 1);
4148 op
= extract32(insn
, 30, 1);
4149 is_imm
= extract32(insn
, 11, 1);
4150 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
4151 cond
= extract32(insn
, 12, 4);
4152 rn
= extract32(insn
, 5, 5);
4153 nzcv
= extract32(insn
, 0, 4);
4155 /* Set T0 = !COND. */
4156 tcg_t0
= tcg_temp_new_i32();
4157 arm_test_cc(&c
, cond
);
4158 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
4161 /* Load the arguments for the new comparison. */
4163 tcg_y
= new_tmp_a64(s
);
4164 tcg_gen_movi_i64(tcg_y
, y
);
4166 tcg_y
= cpu_reg(s
, y
);
4168 tcg_rn
= cpu_reg(s
, rn
);
4170 /* Set the flags for the new comparison. */
4171 tcg_tmp
= tcg_temp_new_i64();
4173 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4175 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4177 tcg_temp_free_i64(tcg_tmp
);
4179 /* If COND was false, force the flags to #nzcv. Compute two masks
4180 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
4181 * For tcg hosts that support ANDC, we can make do with just T1.
4182 * In either case, allow the tcg optimizer to delete any unused mask.
4184 tcg_t1
= tcg_temp_new_i32();
4185 tcg_t2
= tcg_temp_new_i32();
4186 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
4187 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
4189 if (nzcv
& 8) { /* N */
4190 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4192 if (TCG_TARGET_HAS_andc_i32
) {
4193 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4195 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
4198 if (nzcv
& 4) { /* Z */
4199 if (TCG_TARGET_HAS_andc_i32
) {
4200 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
4202 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
4205 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
4207 if (nzcv
& 2) { /* C */
4208 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
4210 if (TCG_TARGET_HAS_andc_i32
) {
4211 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
4213 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
4216 if (nzcv
& 1) { /* V */
4217 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4219 if (TCG_TARGET_HAS_andc_i32
) {
4220 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4222 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
4225 tcg_temp_free_i32(tcg_t0
);
4226 tcg_temp_free_i32(tcg_t1
);
4227 tcg_temp_free_i32(tcg_t2
);
4230 /* Conditional select
4231 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
4232 * +----+----+---+-----------------+------+------+-----+------+------+
4233 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
4234 * +----+----+---+-----------------+------+------+-----+------+------+
4236 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
4238 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
4239 TCGv_i64 tcg_rd
, zero
;
4242 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
4243 /* S == 1 or op2<1> == 1 */
4244 unallocated_encoding(s
);
4247 sf
= extract32(insn
, 31, 1);
4248 else_inv
= extract32(insn
, 30, 1);
4249 rm
= extract32(insn
, 16, 5);
4250 cond
= extract32(insn
, 12, 4);
4251 else_inc
= extract32(insn
, 10, 1);
4252 rn
= extract32(insn
, 5, 5);
4253 rd
= extract32(insn
, 0, 5);
4255 tcg_rd
= cpu_reg(s
, rd
);
4257 a64_test_cc(&c
, cond
);
4258 zero
= tcg_const_i64(0);
4260 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
4262 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
4264 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
4267 TCGv_i64 t_true
= cpu_reg(s
, rn
);
4268 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
4269 if (else_inv
&& else_inc
) {
4270 tcg_gen_neg_i64(t_false
, t_false
);
4271 } else if (else_inv
) {
4272 tcg_gen_not_i64(t_false
, t_false
);
4273 } else if (else_inc
) {
4274 tcg_gen_addi_i64(t_false
, t_false
, 1);
4276 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
4279 tcg_temp_free_i64(zero
);
4283 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4287 static void handle_clz(DisasContext
*s
, unsigned int sf
,
4288 unsigned int rn
, unsigned int rd
)
4290 TCGv_i64 tcg_rd
, tcg_rn
;
4291 tcg_rd
= cpu_reg(s
, rd
);
4292 tcg_rn
= cpu_reg(s
, rn
);
4295 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
4297 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4298 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4299 tcg_gen_clzi_i32(tcg_tmp32
, tcg_tmp32
, 32);
4300 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4301 tcg_temp_free_i32(tcg_tmp32
);
4305 static void handle_cls(DisasContext
*s
, unsigned int sf
,
4306 unsigned int rn
, unsigned int rd
)
4308 TCGv_i64 tcg_rd
, tcg_rn
;
4309 tcg_rd
= cpu_reg(s
, rd
);
4310 tcg_rn
= cpu_reg(s
, rn
);
4313 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
4315 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4316 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4317 tcg_gen_clrsb_i32(tcg_tmp32
, tcg_tmp32
);
4318 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4319 tcg_temp_free_i32(tcg_tmp32
);
4323 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
4324 unsigned int rn
, unsigned int rd
)
4326 TCGv_i64 tcg_rd
, tcg_rn
;
4327 tcg_rd
= cpu_reg(s
, rd
);
4328 tcg_rn
= cpu_reg(s
, rn
);
4331 gen_helper_rbit64(tcg_rd
, tcg_rn
);
4333 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4334 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4335 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
4336 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4337 tcg_temp_free_i32(tcg_tmp32
);
4341 /* REV with sf==1, opcode==3 ("REV64") */
4342 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
4343 unsigned int rn
, unsigned int rd
)
4346 unallocated_encoding(s
);
4349 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
4352 /* REV with sf==0, opcode==2
4353 * REV32 (sf==1, opcode==2)
4355 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
4356 unsigned int rn
, unsigned int rd
)
4358 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4361 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4362 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4364 /* bswap32_i64 requires zero high word */
4365 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
4366 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
4367 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
4368 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
4369 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4371 tcg_temp_free_i64(tcg_tmp
);
4373 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
4374 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
4378 /* REV16 (opcode==1) */
4379 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
4380 unsigned int rn
, unsigned int rd
)
4382 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4383 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4384 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4385 TCGv_i64 mask
= tcg_const_i64(sf
? 0x00ff00ff00ff00ffull
: 0x00ff00ff);
4387 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 8);
4388 tcg_gen_and_i64(tcg_rd
, tcg_rn
, mask
);
4389 tcg_gen_and_i64(tcg_tmp
, tcg_tmp
, mask
);
4390 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 8);
4391 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4393 tcg_temp_free_i64(mask
);
4394 tcg_temp_free_i64(tcg_tmp
);
4397 /* Data-processing (1 source)
4398 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4399 * +----+---+---+-----------------+---------+--------+------+------+
4400 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
4401 * +----+---+---+-----------------+---------+--------+------+------+
4403 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
4405 unsigned int sf
, opcode
, rn
, rd
;
4407 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
4408 unallocated_encoding(s
);
4412 sf
= extract32(insn
, 31, 1);
4413 opcode
= extract32(insn
, 10, 6);
4414 rn
= extract32(insn
, 5, 5);
4415 rd
= extract32(insn
, 0, 5);
4419 handle_rbit(s
, sf
, rn
, rd
);
4422 handle_rev16(s
, sf
, rn
, rd
);
4425 handle_rev32(s
, sf
, rn
, rd
);
4428 handle_rev64(s
, sf
, rn
, rd
);
4431 handle_clz(s
, sf
, rn
, rd
);
4434 handle_cls(s
, sf
, rn
, rd
);
4439 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
4440 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4442 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
4443 tcg_rd
= cpu_reg(s
, rd
);
4445 if (!sf
&& is_signed
) {
4446 tcg_n
= new_tmp_a64(s
);
4447 tcg_m
= new_tmp_a64(s
);
4448 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
4449 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
4451 tcg_n
= read_cpu_reg(s
, rn
, sf
);
4452 tcg_m
= read_cpu_reg(s
, rm
, sf
);
4456 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
4458 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
4461 if (!sf
) { /* zero extend final result */
4462 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4466 /* LSLV, LSRV, ASRV, RORV */
4467 static void handle_shift_reg(DisasContext
*s
,
4468 enum a64_shift_type shift_type
, unsigned int sf
,
4469 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4471 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
4472 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4473 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4475 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
4476 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
4477 tcg_temp_free_i64(tcg_shift
);
4480 /* CRC32[BHWX], CRC32C[BHWX] */
4481 static void handle_crc32(DisasContext
*s
,
4482 unsigned int sf
, unsigned int sz
, bool crc32c
,
4483 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4485 TCGv_i64 tcg_acc
, tcg_val
;
4488 if (!arm_dc_feature(s
, ARM_FEATURE_CRC
)
4489 || (sf
== 1 && sz
!= 3)
4490 || (sf
== 0 && sz
== 3)) {
4491 unallocated_encoding(s
);
4496 tcg_val
= cpu_reg(s
, rm
);
4510 g_assert_not_reached();
4512 tcg_val
= new_tmp_a64(s
);
4513 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
4516 tcg_acc
= cpu_reg(s
, rn
);
4517 tcg_bytes
= tcg_const_i32(1 << sz
);
4520 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4522 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4525 tcg_temp_free_i32(tcg_bytes
);
4528 /* Data-processing (2 source)
4529 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4530 * +----+---+---+-----------------+------+--------+------+------+
4531 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
4532 * +----+---+---+-----------------+------+--------+------+------+
4534 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
4536 unsigned int sf
, rm
, opcode
, rn
, rd
;
4537 sf
= extract32(insn
, 31, 1);
4538 rm
= extract32(insn
, 16, 5);
4539 opcode
= extract32(insn
, 10, 6);
4540 rn
= extract32(insn
, 5, 5);
4541 rd
= extract32(insn
, 0, 5);
4543 if (extract32(insn
, 29, 1)) {
4544 unallocated_encoding(s
);
4550 handle_div(s
, false, sf
, rm
, rn
, rd
);
4553 handle_div(s
, true, sf
, rm
, rn
, rd
);
4556 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
4559 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
4562 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
4565 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
4574 case 23: /* CRC32 */
4576 int sz
= extract32(opcode
, 0, 2);
4577 bool crc32c
= extract32(opcode
, 2, 1);
4578 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
4582 unallocated_encoding(s
);
4587 /* Data processing - register */
4588 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
4590 switch (extract32(insn
, 24, 5)) {
4591 case 0x0a: /* Logical (shifted register) */
4592 disas_logic_reg(s
, insn
);
4594 case 0x0b: /* Add/subtract */
4595 if (insn
& (1 << 21)) { /* (extended register) */
4596 disas_add_sub_ext_reg(s
, insn
);
4598 disas_add_sub_reg(s
, insn
);
4601 case 0x1b: /* Data-processing (3 source) */
4602 disas_data_proc_3src(s
, insn
);
4605 switch (extract32(insn
, 21, 3)) {
4606 case 0x0: /* Add/subtract (with carry) */
4607 disas_adc_sbc(s
, insn
);
4609 case 0x2: /* Conditional compare */
4610 disas_cc(s
, insn
); /* both imm and reg forms */
4612 case 0x4: /* Conditional select */
4613 disas_cond_select(s
, insn
);
4615 case 0x6: /* Data-processing */
4616 if (insn
& (1 << 30)) { /* (1 source) */
4617 disas_data_proc_1src(s
, insn
);
4618 } else { /* (2 source) */
4619 disas_data_proc_2src(s
, insn
);
4623 unallocated_encoding(s
);
4628 unallocated_encoding(s
);
4633 static void handle_fp_compare(DisasContext
*s
, int size
,
4634 unsigned int rn
, unsigned int rm
,
4635 bool cmp_with_zero
, bool signal_all_nans
)
4637 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
4638 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
4640 if (size
== MO_64
) {
4641 TCGv_i64 tcg_vn
, tcg_vm
;
4643 tcg_vn
= read_fp_dreg(s
, rn
);
4644 if (cmp_with_zero
) {
4645 tcg_vm
= tcg_const_i64(0);
4647 tcg_vm
= read_fp_dreg(s
, rm
);
4649 if (signal_all_nans
) {
4650 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4652 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4654 tcg_temp_free_i64(tcg_vn
);
4655 tcg_temp_free_i64(tcg_vm
);
4657 TCGv_i32 tcg_vn
= tcg_temp_new_i32();
4658 TCGv_i32 tcg_vm
= tcg_temp_new_i32();
4660 read_vec_element_i32(s
, tcg_vn
, rn
, 0, size
);
4661 if (cmp_with_zero
) {
4662 tcg_gen_movi_i32(tcg_vm
, 0);
4664 read_vec_element_i32(s
, tcg_vm
, rm
, 0, size
);
4669 if (signal_all_nans
) {
4670 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4672 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4676 if (signal_all_nans
) {
4677 gen_helper_vfp_cmpeh_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4679 gen_helper_vfp_cmph_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4683 g_assert_not_reached();
4686 tcg_temp_free_i32(tcg_vn
);
4687 tcg_temp_free_i32(tcg_vm
);
4690 tcg_temp_free_ptr(fpst
);
4692 gen_set_nzcv(tcg_flags
);
4694 tcg_temp_free_i64(tcg_flags
);
4697 /* Floating point compare
4698 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
4699 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4700 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
4701 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4703 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
4705 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
4708 mos
= extract32(insn
, 29, 3);
4709 type
= extract32(insn
, 22, 2);
4710 rm
= extract32(insn
, 16, 5);
4711 op
= extract32(insn
, 14, 2);
4712 rn
= extract32(insn
, 5, 5);
4713 opc
= extract32(insn
, 3, 2);
4714 op2r
= extract32(insn
, 0, 3);
4716 if (mos
|| op
|| op2r
) {
4717 unallocated_encoding(s
);
4730 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
4735 unallocated_encoding(s
);
4739 if (!fp_access_check(s
)) {
4743 handle_fp_compare(s
, size
, rn
, rm
, opc
& 1, opc
& 2);
4746 /* Floating point conditional compare
4747 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4748 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4749 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
4750 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4752 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
4754 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
4756 TCGLabel
*label_continue
= NULL
;
4759 mos
= extract32(insn
, 29, 3);
4760 type
= extract32(insn
, 22, 2);
4761 rm
= extract32(insn
, 16, 5);
4762 cond
= extract32(insn
, 12, 4);
4763 rn
= extract32(insn
, 5, 5);
4764 op
= extract32(insn
, 4, 1);
4765 nzcv
= extract32(insn
, 0, 4);
4768 unallocated_encoding(s
);
4781 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
4786 unallocated_encoding(s
);
4790 if (!fp_access_check(s
)) {
4794 if (cond
< 0x0e) { /* not always */
4795 TCGLabel
*label_match
= gen_new_label();
4796 label_continue
= gen_new_label();
4797 arm_gen_test_cc(cond
, label_match
);
4799 tcg_flags
= tcg_const_i64(nzcv
<< 28);
4800 gen_set_nzcv(tcg_flags
);
4801 tcg_temp_free_i64(tcg_flags
);
4802 tcg_gen_br(label_continue
);
4803 gen_set_label(label_match
);
4806 handle_fp_compare(s
, size
, rn
, rm
, false, op
);
4809 gen_set_label(label_continue
);
4813 /* Floating point conditional select
4814 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4815 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4816 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
4817 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4819 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
4821 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
4822 TCGv_i64 t_true
, t_false
, t_zero
;
4826 mos
= extract32(insn
, 29, 3);
4827 type
= extract32(insn
, 22, 2);
4828 rm
= extract32(insn
, 16, 5);
4829 cond
= extract32(insn
, 12, 4);
4830 rn
= extract32(insn
, 5, 5);
4831 rd
= extract32(insn
, 0, 5);
4834 unallocated_encoding(s
);
4847 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
4852 unallocated_encoding(s
);
4856 if (!fp_access_check(s
)) {
4860 /* Zero extend sreg & hreg inputs to 64 bits now. */
4861 t_true
= tcg_temp_new_i64();
4862 t_false
= tcg_temp_new_i64();
4863 read_vec_element(s
, t_true
, rn
, 0, sz
);
4864 read_vec_element(s
, t_false
, rm
, 0, sz
);
4866 a64_test_cc(&c
, cond
);
4867 t_zero
= tcg_const_i64(0);
4868 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, t_zero
, t_true
, t_false
);
4869 tcg_temp_free_i64(t_zero
);
4870 tcg_temp_free_i64(t_false
);
4873 /* Note that sregs & hregs write back zeros to the high bits,
4874 and we've already done the zero-extension. */
4875 write_fp_dreg(s
, rd
, t_true
);
4876 tcg_temp_free_i64(t_true
);
4879 /* Floating-point data-processing (1 source) - half precision */
4880 static void handle_fp_1src_half(DisasContext
*s
, int opcode
, int rd
, int rn
)
4882 TCGv_ptr fpst
= NULL
;
4883 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
4884 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4887 case 0x0: /* FMOV */
4888 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4890 case 0x1: /* FABS */
4891 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
4893 case 0x2: /* FNEG */
4894 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
4896 case 0x3: /* FSQRT */
4897 fpst
= get_fpstatus_ptr(true);
4898 gen_helper_sqrt_f16(tcg_res
, tcg_op
, fpst
);
4900 case 0x8: /* FRINTN */
4901 case 0x9: /* FRINTP */
4902 case 0xa: /* FRINTM */
4903 case 0xb: /* FRINTZ */
4904 case 0xc: /* FRINTA */
4906 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4907 fpst
= get_fpstatus_ptr(true);
4909 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
4910 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
4912 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
4913 tcg_temp_free_i32(tcg_rmode
);
4916 case 0xe: /* FRINTX */
4917 fpst
= get_fpstatus_ptr(true);
4918 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, fpst
);
4920 case 0xf: /* FRINTI */
4921 fpst
= get_fpstatus_ptr(true);
4922 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
4928 write_fp_sreg(s
, rd
, tcg_res
);
4931 tcg_temp_free_ptr(fpst
);
4933 tcg_temp_free_i32(tcg_op
);
4934 tcg_temp_free_i32(tcg_res
);
4937 /* Floating-point data-processing (1 source) - single precision */
4938 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
4944 fpst
= get_fpstatus_ptr(false);
4945 tcg_op
= read_fp_sreg(s
, rn
);
4946 tcg_res
= tcg_temp_new_i32();
4949 case 0x0: /* FMOV */
4950 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4952 case 0x1: /* FABS */
4953 gen_helper_vfp_abss(tcg_res
, tcg_op
);
4955 case 0x2: /* FNEG */
4956 gen_helper_vfp_negs(tcg_res
, tcg_op
);
4958 case 0x3: /* FSQRT */
4959 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
4961 case 0x8: /* FRINTN */
4962 case 0x9: /* FRINTP */
4963 case 0xa: /* FRINTM */
4964 case 0xb: /* FRINTZ */
4965 case 0xc: /* FRINTA */
4967 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4969 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
4970 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4972 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
4973 tcg_temp_free_i32(tcg_rmode
);
4976 case 0xe: /* FRINTX */
4977 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
4979 case 0xf: /* FRINTI */
4980 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4986 write_fp_sreg(s
, rd
, tcg_res
);
4988 tcg_temp_free_ptr(fpst
);
4989 tcg_temp_free_i32(tcg_op
);
4990 tcg_temp_free_i32(tcg_res
);
4993 /* Floating-point data-processing (1 source) - double precision */
4994 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
5001 case 0x0: /* FMOV */
5002 gen_gvec_fn2(s
, false, rd
, rn
, tcg_gen_gvec_mov
, 0);
5006 fpst
= get_fpstatus_ptr(false);
5007 tcg_op
= read_fp_dreg(s
, rn
);
5008 tcg_res
= tcg_temp_new_i64();
5011 case 0x1: /* FABS */
5012 gen_helper_vfp_absd(tcg_res
, tcg_op
);
5014 case 0x2: /* FNEG */
5015 gen_helper_vfp_negd(tcg_res
, tcg_op
);
5017 case 0x3: /* FSQRT */
5018 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
5020 case 0x8: /* FRINTN */
5021 case 0x9: /* FRINTP */
5022 case 0xa: /* FRINTM */
5023 case 0xb: /* FRINTZ */
5024 case 0xc: /* FRINTA */
5026 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
5028 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5029 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
5031 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5032 tcg_temp_free_i32(tcg_rmode
);
5035 case 0xe: /* FRINTX */
5036 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
5038 case 0xf: /* FRINTI */
5039 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
5045 write_fp_dreg(s
, rd
, tcg_res
);
5047 tcg_temp_free_ptr(fpst
);
5048 tcg_temp_free_i64(tcg_op
);
5049 tcg_temp_free_i64(tcg_res
);
5052 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
5053 int rd
, int rn
, int dtype
, int ntype
)
5058 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5060 /* Single to double */
5061 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5062 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
5063 write_fp_dreg(s
, rd
, tcg_rd
);
5064 tcg_temp_free_i64(tcg_rd
);
5066 /* Single to half */
5067 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5068 TCGv_i32 ahp
= get_ahp_flag();
5069 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5071 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5072 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5073 write_fp_sreg(s
, rd
, tcg_rd
);
5074 tcg_temp_free_i32(tcg_rd
);
5075 tcg_temp_free_i32(ahp
);
5076 tcg_temp_free_ptr(fpst
);
5078 tcg_temp_free_i32(tcg_rn
);
5083 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
5084 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5086 /* Double to single */
5087 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
5089 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5090 TCGv_i32 ahp
= get_ahp_flag();
5091 /* Double to half */
5092 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5093 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5094 tcg_temp_free_ptr(fpst
);
5095 tcg_temp_free_i32(ahp
);
5097 write_fp_sreg(s
, rd
, tcg_rd
);
5098 tcg_temp_free_i32(tcg_rd
);
5099 tcg_temp_free_i64(tcg_rn
);
5104 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5105 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(false);
5106 TCGv_i32 tcg_ahp
= get_ahp_flag();
5107 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
5109 /* Half to single */
5110 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5111 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5112 write_fp_sreg(s
, rd
, tcg_rd
);
5113 tcg_temp_free_ptr(tcg_fpst
);
5114 tcg_temp_free_i32(tcg_ahp
);
5115 tcg_temp_free_i32(tcg_rd
);
5117 /* Half to double */
5118 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5119 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5120 write_fp_dreg(s
, rd
, tcg_rd
);
5121 tcg_temp_free_i64(tcg_rd
);
5123 tcg_temp_free_i32(tcg_rn
);
5131 /* Floating point data-processing (1 source)
5132 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
5133 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5134 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
5135 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5137 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
5139 int type
= extract32(insn
, 22, 2);
5140 int opcode
= extract32(insn
, 15, 6);
5141 int rn
= extract32(insn
, 5, 5);
5142 int rd
= extract32(insn
, 0, 5);
5145 case 0x4: case 0x5: case 0x7:
5147 /* FCVT between half, single and double precision */
5148 int dtype
= extract32(opcode
, 0, 2);
5149 if (type
== 2 || dtype
== type
) {
5150 unallocated_encoding(s
);
5153 if (!fp_access_check(s
)) {
5157 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
5163 /* 32-to-32 and 64-to-64 ops */
5166 if (!fp_access_check(s
)) {
5170 handle_fp_1src_single(s
, opcode
, rd
, rn
);
5173 if (!fp_access_check(s
)) {
5177 handle_fp_1src_double(s
, opcode
, rd
, rn
);
5180 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5181 unallocated_encoding(s
);
5185 if (!fp_access_check(s
)) {
5189 handle_fp_1src_half(s
, opcode
, rd
, rn
);
5192 unallocated_encoding(s
);
5196 unallocated_encoding(s
);
5201 /* Floating-point data-processing (2 source) - single precision */
5202 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
5203 int rd
, int rn
, int rm
)
5210 tcg_res
= tcg_temp_new_i32();
5211 fpst
= get_fpstatus_ptr(false);
5212 tcg_op1
= read_fp_sreg(s
, rn
);
5213 tcg_op2
= read_fp_sreg(s
, rm
);
5216 case 0x0: /* FMUL */
5217 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5219 case 0x1: /* FDIV */
5220 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5222 case 0x2: /* FADD */
5223 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5225 case 0x3: /* FSUB */
5226 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5228 case 0x4: /* FMAX */
5229 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5231 case 0x5: /* FMIN */
5232 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5234 case 0x6: /* FMAXNM */
5235 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5237 case 0x7: /* FMINNM */
5238 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5240 case 0x8: /* FNMUL */
5241 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5242 gen_helper_vfp_negs(tcg_res
, tcg_res
);
5246 write_fp_sreg(s
, rd
, tcg_res
);
5248 tcg_temp_free_ptr(fpst
);
5249 tcg_temp_free_i32(tcg_op1
);
5250 tcg_temp_free_i32(tcg_op2
);
5251 tcg_temp_free_i32(tcg_res
);
5254 /* Floating-point data-processing (2 source) - double precision */
5255 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
5256 int rd
, int rn
, int rm
)
5263 tcg_res
= tcg_temp_new_i64();
5264 fpst
= get_fpstatus_ptr(false);
5265 tcg_op1
= read_fp_dreg(s
, rn
);
5266 tcg_op2
= read_fp_dreg(s
, rm
);
5269 case 0x0: /* FMUL */
5270 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5272 case 0x1: /* FDIV */
5273 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5275 case 0x2: /* FADD */
5276 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5278 case 0x3: /* FSUB */
5279 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5281 case 0x4: /* FMAX */
5282 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5284 case 0x5: /* FMIN */
5285 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5287 case 0x6: /* FMAXNM */
5288 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5290 case 0x7: /* FMINNM */
5291 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5293 case 0x8: /* FNMUL */
5294 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5295 gen_helper_vfp_negd(tcg_res
, tcg_res
);
5299 write_fp_dreg(s
, rd
, tcg_res
);
5301 tcg_temp_free_ptr(fpst
);
5302 tcg_temp_free_i64(tcg_op1
);
5303 tcg_temp_free_i64(tcg_op2
);
5304 tcg_temp_free_i64(tcg_res
);
5307 /* Floating-point data-processing (2 source) - half precision */
5308 static void handle_fp_2src_half(DisasContext
*s
, int opcode
,
5309 int rd
, int rn
, int rm
)
5316 tcg_res
= tcg_temp_new_i32();
5317 fpst
= get_fpstatus_ptr(true);
5318 tcg_op1
= read_fp_hreg(s
, rn
);
5319 tcg_op2
= read_fp_hreg(s
, rm
);
5322 case 0x0: /* FMUL */
5323 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5325 case 0x1: /* FDIV */
5326 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5328 case 0x2: /* FADD */
5329 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5331 case 0x3: /* FSUB */
5332 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5334 case 0x4: /* FMAX */
5335 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5337 case 0x5: /* FMIN */
5338 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5340 case 0x6: /* FMAXNM */
5341 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5343 case 0x7: /* FMINNM */
5344 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5346 case 0x8: /* FNMUL */
5347 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5348 tcg_gen_xori_i32(tcg_res
, tcg_res
, 0x8000);
5351 g_assert_not_reached();
5354 write_fp_sreg(s
, rd
, tcg_res
);
5356 tcg_temp_free_ptr(fpst
);
5357 tcg_temp_free_i32(tcg_op1
);
5358 tcg_temp_free_i32(tcg_op2
);
5359 tcg_temp_free_i32(tcg_res
);
5362 /* Floating point data-processing (2 source)
5363 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5364 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5365 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
5366 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5368 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
5370 int type
= extract32(insn
, 22, 2);
5371 int rd
= extract32(insn
, 0, 5);
5372 int rn
= extract32(insn
, 5, 5);
5373 int rm
= extract32(insn
, 16, 5);
5374 int opcode
= extract32(insn
, 12, 4);
5377 unallocated_encoding(s
);
5383 if (!fp_access_check(s
)) {
5386 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
5389 if (!fp_access_check(s
)) {
5392 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
5395 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5396 unallocated_encoding(s
);
5399 if (!fp_access_check(s
)) {
5402 handle_fp_2src_half(s
, opcode
, rd
, rn
, rm
);
5405 unallocated_encoding(s
);
5409 /* Floating-point data-processing (3 source) - single precision */
5410 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
5411 int rd
, int rn
, int rm
, int ra
)
5413 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
5414 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5415 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5417 tcg_op1
= read_fp_sreg(s
, rn
);
5418 tcg_op2
= read_fp_sreg(s
, rm
);
5419 tcg_op3
= read_fp_sreg(s
, ra
);
5421 /* These are fused multiply-add, and must be done as one
5422 * floating point operation with no rounding between the
5423 * multiplication and addition steps.
5424 * NB that doing the negations here as separate steps is
5425 * correct : an input NaN should come out with its sign bit
5426 * flipped if it is a negated-input.
5429 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
5433 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
5436 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
5438 write_fp_sreg(s
, rd
, tcg_res
);
5440 tcg_temp_free_ptr(fpst
);
5441 tcg_temp_free_i32(tcg_op1
);
5442 tcg_temp_free_i32(tcg_op2
);
5443 tcg_temp_free_i32(tcg_op3
);
5444 tcg_temp_free_i32(tcg_res
);
5447 /* Floating-point data-processing (3 source) - double precision */
5448 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
5449 int rd
, int rn
, int rm
, int ra
)
5451 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
5452 TCGv_i64 tcg_res
= tcg_temp_new_i64();
5453 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5455 tcg_op1
= read_fp_dreg(s
, rn
);
5456 tcg_op2
= read_fp_dreg(s
, rm
);
5457 tcg_op3
= read_fp_dreg(s
, ra
);
5459 /* These are fused multiply-add, and must be done as one
5460 * floating point operation with no rounding between the
5461 * multiplication and addition steps.
5462 * NB that doing the negations here as separate steps is
5463 * correct : an input NaN should come out with its sign bit
5464 * flipped if it is a negated-input.
5467 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
5471 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
5474 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
5476 write_fp_dreg(s
, rd
, tcg_res
);
5478 tcg_temp_free_ptr(fpst
);
5479 tcg_temp_free_i64(tcg_op1
);
5480 tcg_temp_free_i64(tcg_op2
);
5481 tcg_temp_free_i64(tcg_op3
);
5482 tcg_temp_free_i64(tcg_res
);
5485 /* Floating-point data-processing (3 source) - half precision */
5486 static void handle_fp_3src_half(DisasContext
*s
, bool o0
, bool o1
,
5487 int rd
, int rn
, int rm
, int ra
)
5489 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
5490 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5491 TCGv_ptr fpst
= get_fpstatus_ptr(true);
5493 tcg_op1
= read_fp_hreg(s
, rn
);
5494 tcg_op2
= read_fp_hreg(s
, rm
);
5495 tcg_op3
= read_fp_hreg(s
, ra
);
5497 /* These are fused multiply-add, and must be done as one
5498 * floating point operation with no rounding between the
5499 * multiplication and addition steps.
5500 * NB that doing the negations here as separate steps is
5501 * correct : an input NaN should come out with its sign bit
5502 * flipped if it is a negated-input.
5505 tcg_gen_xori_i32(tcg_op3
, tcg_op3
, 0x8000);
5509 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
5512 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
5514 write_fp_sreg(s
, rd
, tcg_res
);
5516 tcg_temp_free_ptr(fpst
);
5517 tcg_temp_free_i32(tcg_op1
);
5518 tcg_temp_free_i32(tcg_op2
);
5519 tcg_temp_free_i32(tcg_op3
);
5520 tcg_temp_free_i32(tcg_res
);
5523 /* Floating point data-processing (3 source)
5524 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
5525 * +---+---+---+-----------+------+----+------+----+------+------+------+
5526 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
5527 * +---+---+---+-----------+------+----+------+----+------+------+------+
5529 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
5531 int type
= extract32(insn
, 22, 2);
5532 int rd
= extract32(insn
, 0, 5);
5533 int rn
= extract32(insn
, 5, 5);
5534 int ra
= extract32(insn
, 10, 5);
5535 int rm
= extract32(insn
, 16, 5);
5536 bool o0
= extract32(insn
, 15, 1);
5537 bool o1
= extract32(insn
, 21, 1);
5541 if (!fp_access_check(s
)) {
5544 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
5547 if (!fp_access_check(s
)) {
5550 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
5553 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5554 unallocated_encoding(s
);
5557 if (!fp_access_check(s
)) {
5560 handle_fp_3src_half(s
, o0
, o1
, rd
, rn
, rm
, ra
);
5563 unallocated_encoding(s
);
5567 /* The imm8 encodes the sign bit, enough bits to represent an exponent in
5568 * the range 01....1xx to 10....0xx, and the most significant 4 bits of
5569 * the mantissa; see VFPExpandImm() in the v8 ARM ARM.
5571 uint64_t vfp_expand_imm(int size
, uint8_t imm8
)
5577 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
5578 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
5579 extract32(imm8
, 0, 6);
5583 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
5584 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
5585 (extract32(imm8
, 0, 6) << 3);
5589 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
5590 (extract32(imm8
, 6, 1) ? 0x3000 : 0x4000) |
5591 (extract32(imm8
, 0, 6) << 6);
5594 g_assert_not_reached();
5599 /* Floating point immediate
5600 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
5601 * +---+---+---+-----------+------+---+------------+-------+------+------+
5602 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
5603 * +---+---+---+-----------+------+---+------------+-------+------+------+
5605 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
5607 int rd
= extract32(insn
, 0, 5);
5608 int imm8
= extract32(insn
, 13, 8);
5609 int type
= extract32(insn
, 22, 2);
5623 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5628 unallocated_encoding(s
);
5632 if (!fp_access_check(s
)) {
5636 imm
= vfp_expand_imm(sz
, imm8
);
5638 tcg_res
= tcg_const_i64(imm
);
5639 write_fp_dreg(s
, rd
, tcg_res
);
5640 tcg_temp_free_i64(tcg_res
);
5643 /* Handle floating point <=> fixed point conversions. Note that we can
5644 * also deal with fp <=> integer conversions as a special case (scale == 64)
5645 * OPTME: consider handling that special case specially or at least skipping
5646 * the call to scalbn in the helpers for zero shifts.
5648 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
5649 bool itof
, int rmode
, int scale
, int sf
, int type
)
5651 bool is_signed
= !(opcode
& 1);
5652 TCGv_ptr tcg_fpstatus
;
5653 TCGv_i32 tcg_shift
, tcg_single
;
5654 TCGv_i64 tcg_double
;
5656 tcg_fpstatus
= get_fpstatus_ptr(type
== 3);
5658 tcg_shift
= tcg_const_i32(64 - scale
);
5661 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
5663 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
5666 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
5668 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
5671 tcg_int
= tcg_extend
;
5675 case 1: /* float64 */
5676 tcg_double
= tcg_temp_new_i64();
5678 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
5679 tcg_shift
, tcg_fpstatus
);
5681 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
5682 tcg_shift
, tcg_fpstatus
);
5684 write_fp_dreg(s
, rd
, tcg_double
);
5685 tcg_temp_free_i64(tcg_double
);
5688 case 0: /* float32 */
5689 tcg_single
= tcg_temp_new_i32();
5691 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
5692 tcg_shift
, tcg_fpstatus
);
5694 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
5695 tcg_shift
, tcg_fpstatus
);
5697 write_fp_sreg(s
, rd
, tcg_single
);
5698 tcg_temp_free_i32(tcg_single
);
5701 case 3: /* float16 */
5702 tcg_single
= tcg_temp_new_i32();
5704 gen_helper_vfp_sqtoh(tcg_single
, tcg_int
,
5705 tcg_shift
, tcg_fpstatus
);
5707 gen_helper_vfp_uqtoh(tcg_single
, tcg_int
,
5708 tcg_shift
, tcg_fpstatus
);
5710 write_fp_sreg(s
, rd
, tcg_single
);
5711 tcg_temp_free_i32(tcg_single
);
5715 g_assert_not_reached();
5718 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
5721 if (extract32(opcode
, 2, 1)) {
5722 /* There are too many rounding modes to all fit into rmode,
5723 * so FCVTA[US] is a special case.
5725 rmode
= FPROUNDING_TIEAWAY
;
5728 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
5730 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
5733 case 1: /* float64 */
5734 tcg_double
= read_fp_dreg(s
, rn
);
5737 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
5738 tcg_shift
, tcg_fpstatus
);
5740 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
5741 tcg_shift
, tcg_fpstatus
);
5745 gen_helper_vfp_tould(tcg_int
, tcg_double
,
5746 tcg_shift
, tcg_fpstatus
);
5748 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
5749 tcg_shift
, tcg_fpstatus
);
5753 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
5755 tcg_temp_free_i64(tcg_double
);
5758 case 0: /* float32 */
5759 tcg_single
= read_fp_sreg(s
, rn
);
5762 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
5763 tcg_shift
, tcg_fpstatus
);
5765 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
5766 tcg_shift
, tcg_fpstatus
);
5769 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
5771 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
5772 tcg_shift
, tcg_fpstatus
);
5774 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
5775 tcg_shift
, tcg_fpstatus
);
5777 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
5778 tcg_temp_free_i32(tcg_dest
);
5780 tcg_temp_free_i32(tcg_single
);
5783 case 3: /* float16 */
5784 tcg_single
= read_fp_sreg(s
, rn
);
5787 gen_helper_vfp_tosqh(tcg_int
, tcg_single
,
5788 tcg_shift
, tcg_fpstatus
);
5790 gen_helper_vfp_touqh(tcg_int
, tcg_single
,
5791 tcg_shift
, tcg_fpstatus
);
5794 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
5796 gen_helper_vfp_toslh(tcg_dest
, tcg_single
,
5797 tcg_shift
, tcg_fpstatus
);
5799 gen_helper_vfp_toulh(tcg_dest
, tcg_single
,
5800 tcg_shift
, tcg_fpstatus
);
5802 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
5803 tcg_temp_free_i32(tcg_dest
);
5805 tcg_temp_free_i32(tcg_single
);
5809 g_assert_not_reached();
5812 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
5813 tcg_temp_free_i32(tcg_rmode
);
5816 tcg_temp_free_ptr(tcg_fpstatus
);
5817 tcg_temp_free_i32(tcg_shift
);
5820 /* Floating point <-> fixed point conversions
5821 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
5822 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
5823 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
5824 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
5826 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
5828 int rd
= extract32(insn
, 0, 5);
5829 int rn
= extract32(insn
, 5, 5);
5830 int scale
= extract32(insn
, 10, 6);
5831 int opcode
= extract32(insn
, 16, 3);
5832 int rmode
= extract32(insn
, 19, 2);
5833 int type
= extract32(insn
, 22, 2);
5834 bool sbit
= extract32(insn
, 29, 1);
5835 bool sf
= extract32(insn
, 31, 1);
5838 if (sbit
|| (!sf
&& scale
< 32)) {
5839 unallocated_encoding(s
);
5844 case 0: /* float32 */
5845 case 1: /* float64 */
5847 case 3: /* float16 */
5848 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5853 unallocated_encoding(s
);
5857 switch ((rmode
<< 3) | opcode
) {
5858 case 0x2: /* SCVTF */
5859 case 0x3: /* UCVTF */
5862 case 0x18: /* FCVTZS */
5863 case 0x19: /* FCVTZU */
5867 unallocated_encoding(s
);
5871 if (!fp_access_check(s
)) {
5875 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
5878 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
5880 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
5881 * without conversion.
5885 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
5891 tmp
= tcg_temp_new_i64();
5892 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
5893 write_fp_dreg(s
, rd
, tmp
);
5894 tcg_temp_free_i64(tmp
);
5898 write_fp_dreg(s
, rd
, tcg_rn
);
5901 /* 64 bit to top half. */
5902 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5903 clear_vec_high(s
, true, rd
);
5907 tmp
= tcg_temp_new_i64();
5908 tcg_gen_ext16u_i64(tmp
, tcg_rn
);
5909 write_fp_dreg(s
, rd
, tmp
);
5910 tcg_temp_free_i64(tmp
);
5913 g_assert_not_reached();
5916 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5921 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
5925 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
5928 /* 64 bits from top half */
5929 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
5933 tcg_gen_ld16u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_16
));
5936 g_assert_not_reached();
5941 /* Floating point <-> integer conversions
5942 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
5943 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5944 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
5945 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5947 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
5949 int rd
= extract32(insn
, 0, 5);
5950 int rn
= extract32(insn
, 5, 5);
5951 int opcode
= extract32(insn
, 16, 3);
5952 int rmode
= extract32(insn
, 19, 2);
5953 int type
= extract32(insn
, 22, 2);
5954 bool sbit
= extract32(insn
, 29, 1);
5955 bool sf
= extract32(insn
, 31, 1);
5958 unallocated_encoding(s
);
5964 bool itof
= opcode
& 1;
5967 unallocated_encoding(s
);
5971 switch (sf
<< 3 | type
<< 1 | rmode
) {
5972 case 0x0: /* 32 bit */
5973 case 0xa: /* 64 bit */
5974 case 0xd: /* 64 bit to top half of quad */
5976 case 0x6: /* 16-bit float, 32-bit int */
5977 case 0xe: /* 16-bit float, 64-bit int */
5978 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5983 /* all other sf/type/rmode combinations are invalid */
5984 unallocated_encoding(s
);
5988 if (!fp_access_check(s
)) {
5991 handle_fmov(s
, rd
, rn
, type
, itof
);
5993 /* actual FP conversions */
5994 bool itof
= extract32(opcode
, 1, 1);
5996 if (rmode
!= 0 && opcode
> 1) {
5997 unallocated_encoding(s
);
6001 case 0: /* float32 */
6002 case 1: /* float64 */
6004 case 3: /* float16 */
6005 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
6010 unallocated_encoding(s
);
6014 if (!fp_access_check(s
)) {
6017 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
6021 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
6022 * 31 30 29 28 25 24 0
6023 * +---+---+---+---------+-----------------------------+
6024 * | | 0 | | 1 1 1 1 | |
6025 * +---+---+---+---------+-----------------------------+
6027 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
6029 if (extract32(insn
, 24, 1)) {
6030 /* Floating point data-processing (3 source) */
6031 disas_fp_3src(s
, insn
);
6032 } else if (extract32(insn
, 21, 1) == 0) {
6033 /* Floating point to fixed point conversions */
6034 disas_fp_fixed_conv(s
, insn
);
6036 switch (extract32(insn
, 10, 2)) {
6038 /* Floating point conditional compare */
6039 disas_fp_ccomp(s
, insn
);
6042 /* Floating point data-processing (2 source) */
6043 disas_fp_2src(s
, insn
);
6046 /* Floating point conditional select */
6047 disas_fp_csel(s
, insn
);
6050 switch (ctz32(extract32(insn
, 12, 4))) {
6051 case 0: /* [15:12] == xxx1 */
6052 /* Floating point immediate */
6053 disas_fp_imm(s
, insn
);
6055 case 1: /* [15:12] == xx10 */
6056 /* Floating point compare */
6057 disas_fp_compare(s
, insn
);
6059 case 2: /* [15:12] == x100 */
6060 /* Floating point data-processing (1 source) */
6061 disas_fp_1src(s
, insn
);
6063 case 3: /* [15:12] == 1000 */
6064 unallocated_encoding(s
);
6066 default: /* [15:12] == 0000 */
6067 /* Floating point <-> integer conversions */
6068 disas_fp_int_conv(s
, insn
);
6076 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
6079 /* Extract 64 bits from the middle of two concatenated 64 bit
6080 * vector register slices left:right. The extracted bits start
6081 * at 'pos' bits into the right (least significant) side.
6082 * We return the result in tcg_right, and guarantee not to
6085 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
6086 assert(pos
> 0 && pos
< 64);
6088 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
6089 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
6090 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
6092 tcg_temp_free_i64(tcg_tmp
);
6096 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
6097 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6098 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
6099 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6101 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
6103 int is_q
= extract32(insn
, 30, 1);
6104 int op2
= extract32(insn
, 22, 2);
6105 int imm4
= extract32(insn
, 11, 4);
6106 int rm
= extract32(insn
, 16, 5);
6107 int rn
= extract32(insn
, 5, 5);
6108 int rd
= extract32(insn
, 0, 5);
6109 int pos
= imm4
<< 3;
6110 TCGv_i64 tcg_resl
, tcg_resh
;
6112 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
6113 unallocated_encoding(s
);
6117 if (!fp_access_check(s
)) {
6121 tcg_resh
= tcg_temp_new_i64();
6122 tcg_resl
= tcg_temp_new_i64();
6124 /* Vd gets bits starting at pos bits into Vm:Vn. This is
6125 * either extracting 128 bits from a 128:128 concatenation, or
6126 * extracting 64 bits from a 64:64 concatenation.
6129 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
6131 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
6132 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6134 tcg_gen_movi_i64(tcg_resh
, 0);
6141 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
6142 EltPosns
*elt
= eltposns
;
6149 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
6151 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
6154 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6155 tcg_hh
= tcg_temp_new_i64();
6156 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
6157 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
6158 tcg_temp_free_i64(tcg_hh
);
6162 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6163 tcg_temp_free_i64(tcg_resl
);
6164 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6165 tcg_temp_free_i64(tcg_resh
);
6169 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
6170 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6171 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
6172 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6174 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
6176 int op2
= extract32(insn
, 22, 2);
6177 int is_q
= extract32(insn
, 30, 1);
6178 int rm
= extract32(insn
, 16, 5);
6179 int rn
= extract32(insn
, 5, 5);
6180 int rd
= extract32(insn
, 0, 5);
6181 int is_tblx
= extract32(insn
, 12, 1);
6182 int len
= extract32(insn
, 13, 2);
6183 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
6184 TCGv_i32 tcg_regno
, tcg_numregs
;
6187 unallocated_encoding(s
);
6191 if (!fp_access_check(s
)) {
6195 /* This does a table lookup: for every byte element in the input
6196 * we index into a table formed from up to four vector registers,
6197 * and then the output is the result of the lookups. Our helper
6198 * function does the lookup operation for a single 64 bit part of
6201 tcg_resl
= tcg_temp_new_i64();
6202 tcg_resh
= tcg_temp_new_i64();
6205 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6207 tcg_gen_movi_i64(tcg_resl
, 0);
6209 if (is_tblx
&& is_q
) {
6210 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6212 tcg_gen_movi_i64(tcg_resh
, 0);
6215 tcg_idx
= tcg_temp_new_i64();
6216 tcg_regno
= tcg_const_i32(rn
);
6217 tcg_numregs
= tcg_const_i32(len
+ 1);
6218 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
6219 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
6220 tcg_regno
, tcg_numregs
);
6222 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
6223 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
6224 tcg_regno
, tcg_numregs
);
6226 tcg_temp_free_i64(tcg_idx
);
6227 tcg_temp_free_i32(tcg_regno
);
6228 tcg_temp_free_i32(tcg_numregs
);
6230 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6231 tcg_temp_free_i64(tcg_resl
);
6232 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6233 tcg_temp_free_i64(tcg_resh
);
6237 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
6238 * +---+---+-------------+------+---+------+---+------------------+------+
6239 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
6240 * +---+---+-------------+------+---+------+---+------------------+------+
6242 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
6244 int rd
= extract32(insn
, 0, 5);
6245 int rn
= extract32(insn
, 5, 5);
6246 int rm
= extract32(insn
, 16, 5);
6247 int size
= extract32(insn
, 22, 2);
6248 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
6249 * bit 2 indicates 1 vs 2 variant of the insn.
6251 int opcode
= extract32(insn
, 12, 2);
6252 bool part
= extract32(insn
, 14, 1);
6253 bool is_q
= extract32(insn
, 30, 1);
6254 int esize
= 8 << size
;
6256 int datasize
= is_q
? 128 : 64;
6257 int elements
= datasize
/ esize
;
6258 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
6260 if (opcode
== 0 || (size
== 3 && !is_q
)) {
6261 unallocated_encoding(s
);
6265 if (!fp_access_check(s
)) {
6269 tcg_resl
= tcg_const_i64(0);
6270 tcg_resh
= tcg_const_i64(0);
6271 tcg_res
= tcg_temp_new_i64();
6273 for (i
= 0; i
< elements
; i
++) {
6275 case 1: /* UZP1/2 */
6277 int midpoint
= elements
/ 2;
6279 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
6281 read_vec_element(s
, tcg_res
, rm
,
6282 2 * (i
- midpoint
) + part
, size
);
6286 case 2: /* TRN1/2 */
6288 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
6290 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
6293 case 3: /* ZIP1/2 */
6295 int base
= part
* elements
/ 2;
6297 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
6299 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
6304 g_assert_not_reached();
6309 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
6310 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
6312 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
6313 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
6317 tcg_temp_free_i64(tcg_res
);
6319 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6320 tcg_temp_free_i64(tcg_resl
);
6321 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6322 tcg_temp_free_i64(tcg_resh
);
6326 * do_reduction_op helper
6328 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
6329 * important for correct NaN propagation that we do these
6330 * operations in exactly the order specified by the pseudocode.
6332 * This is a recursive function, TCG temps should be freed by the
6333 * calling function once it is done with the values.
6335 static TCGv_i32
do_reduction_op(DisasContext
*s
, int fpopcode
, int rn
,
6336 int esize
, int size
, int vmap
, TCGv_ptr fpst
)
6338 if (esize
== size
) {
6340 TCGMemOp msize
= esize
== 16 ? MO_16
: MO_32
;
6343 /* We should have one register left here */
6344 assert(ctpop8(vmap
) == 1);
6345 element
= ctz32(vmap
);
6346 assert(element
< 8);
6348 tcg_elem
= tcg_temp_new_i32();
6349 read_vec_element_i32(s
, tcg_elem
, rn
, element
, msize
);
6352 int bits
= size
/ 2;
6353 int shift
= ctpop8(vmap
) / 2;
6354 int vmap_lo
= (vmap
>> shift
) & vmap
;
6355 int vmap_hi
= (vmap
& ~vmap_lo
);
6356 TCGv_i32 tcg_hi
, tcg_lo
, tcg_res
;
6358 tcg_hi
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_hi
, fpst
);
6359 tcg_lo
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_lo
, fpst
);
6360 tcg_res
= tcg_temp_new_i32();
6363 case 0x0c: /* fmaxnmv half-precision */
6364 gen_helper_advsimd_maxnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6366 case 0x0f: /* fmaxv half-precision */
6367 gen_helper_advsimd_maxh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6369 case 0x1c: /* fminnmv half-precision */
6370 gen_helper_advsimd_minnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6372 case 0x1f: /* fminv half-precision */
6373 gen_helper_advsimd_minh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6375 case 0x2c: /* fmaxnmv */
6376 gen_helper_vfp_maxnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6378 case 0x2f: /* fmaxv */
6379 gen_helper_vfp_maxs(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6381 case 0x3c: /* fminnmv */
6382 gen_helper_vfp_minnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6384 case 0x3f: /* fminv */
6385 gen_helper_vfp_mins(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6388 g_assert_not_reached();
6391 tcg_temp_free_i32(tcg_hi
);
6392 tcg_temp_free_i32(tcg_lo
);
6397 /* AdvSIMD across lanes
6398 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6399 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6400 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6401 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6403 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
6405 int rd
= extract32(insn
, 0, 5);
6406 int rn
= extract32(insn
, 5, 5);
6407 int size
= extract32(insn
, 22, 2);
6408 int opcode
= extract32(insn
, 12, 5);
6409 bool is_q
= extract32(insn
, 30, 1);
6410 bool is_u
= extract32(insn
, 29, 1);
6412 bool is_min
= false;
6416 TCGv_i64 tcg_res
, tcg_elt
;
6419 case 0x1b: /* ADDV */
6421 unallocated_encoding(s
);
6425 case 0x3: /* SADDLV, UADDLV */
6426 case 0xa: /* SMAXV, UMAXV */
6427 case 0x1a: /* SMINV, UMINV */
6428 if (size
== 3 || (size
== 2 && !is_q
)) {
6429 unallocated_encoding(s
);
6433 case 0xc: /* FMAXNMV, FMINNMV */
6434 case 0xf: /* FMAXV, FMINV */
6435 /* Bit 1 of size field encodes min vs max and the actual size
6436 * depends on the encoding of the U bit. If not set (and FP16
6437 * enabled) then we do half-precision float instead of single
6440 is_min
= extract32(size
, 1, 1);
6442 if (!is_u
&& arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
6444 } else if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
6445 unallocated_encoding(s
);
6452 unallocated_encoding(s
);
6456 if (!fp_access_check(s
)) {
6461 elements
= (is_q
? 128 : 64) / esize
;
6463 tcg_res
= tcg_temp_new_i64();
6464 tcg_elt
= tcg_temp_new_i64();
6466 /* These instructions operate across all lanes of a vector
6467 * to produce a single result. We can guarantee that a 64
6468 * bit intermediate is sufficient:
6469 * + for [US]ADDLV the maximum element size is 32 bits, and
6470 * the result type is 64 bits
6471 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
6472 * same as the element size, which is 32 bits at most
6473 * For the integer operations we can choose to work at 64
6474 * or 32 bits and truncate at the end; for simplicity
6475 * we use 64 bits always. The floating point
6476 * ops do require 32 bit intermediates, though.
6479 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
6481 for (i
= 1; i
< elements
; i
++) {
6482 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
6485 case 0x03: /* SADDLV / UADDLV */
6486 case 0x1b: /* ADDV */
6487 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
6489 case 0x0a: /* SMAXV / UMAXV */
6491 tcg_gen_umax_i64(tcg_res
, tcg_res
, tcg_elt
);
6493 tcg_gen_smax_i64(tcg_res
, tcg_res
, tcg_elt
);
6496 case 0x1a: /* SMINV / UMINV */
6498 tcg_gen_umin_i64(tcg_res
, tcg_res
, tcg_elt
);
6500 tcg_gen_smin_i64(tcg_res
, tcg_res
, tcg_elt
);
6504 g_assert_not_reached();
6509 /* Floating point vector reduction ops which work across 32
6510 * bit (single) or 16 bit (half-precision) intermediates.
6511 * Note that correct NaN propagation requires that we do these
6512 * operations in exactly the order specified by the pseudocode.
6514 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
6515 int fpopcode
= opcode
| is_min
<< 4 | is_u
<< 5;
6516 int vmap
= (1 << elements
) - 1;
6517 TCGv_i32 tcg_res32
= do_reduction_op(s
, fpopcode
, rn
, esize
,
6518 (is_q
? 128 : 64), vmap
, fpst
);
6519 tcg_gen_extu_i32_i64(tcg_res
, tcg_res32
);
6520 tcg_temp_free_i32(tcg_res32
);
6521 tcg_temp_free_ptr(fpst
);
6524 tcg_temp_free_i64(tcg_elt
);
6526 /* Now truncate the result to the width required for the final output */
6527 if (opcode
== 0x03) {
6528 /* SADDLV, UADDLV: result is 2*esize */
6534 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
6537 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
6540 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
6545 g_assert_not_reached();
6548 write_fp_dreg(s
, rd
, tcg_res
);
6549 tcg_temp_free_i64(tcg_res
);
6552 /* DUP (Element, Vector)
6554 * 31 30 29 21 20 16 15 10 9 5 4 0
6555 * +---+---+-------------------+--------+-------------+------+------+
6556 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
6557 * +---+---+-------------------+--------+-------------+------+------+
6559 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6561 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
6564 int size
= ctz32(imm5
);
6565 int index
= imm5
>> (size
+ 1);
6567 if (size
> 3 || (size
== 3 && !is_q
)) {
6568 unallocated_encoding(s
);
6572 if (!fp_access_check(s
)) {
6576 tcg_gen_gvec_dup_mem(size
, vec_full_reg_offset(s
, rd
),
6577 vec_reg_offset(s
, rn
, index
, size
),
6578 is_q
? 16 : 8, vec_full_reg_size(s
));
6581 /* DUP (element, scalar)
6582 * 31 21 20 16 15 10 9 5 4 0
6583 * +-----------------------+--------+-------------+------+------+
6584 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
6585 * +-----------------------+--------+-------------+------+------+
6587 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
6590 int size
= ctz32(imm5
);
6595 unallocated_encoding(s
);
6599 if (!fp_access_check(s
)) {
6603 index
= imm5
>> (size
+ 1);
6605 /* This instruction just extracts the specified element and
6606 * zero-extends it into the bottom of the destination register.
6608 tmp
= tcg_temp_new_i64();
6609 read_vec_element(s
, tmp
, rn
, index
, size
);
6610 write_fp_dreg(s
, rd
, tmp
);
6611 tcg_temp_free_i64(tmp
);
6616 * 31 30 29 21 20 16 15 10 9 5 4 0
6617 * +---+---+-------------------+--------+-------------+------+------+
6618 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
6619 * +---+---+-------------------+--------+-------------+------+------+
6621 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6623 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
6626 int size
= ctz32(imm5
);
6627 uint32_t dofs
, oprsz
, maxsz
;
6629 if (size
> 3 || ((size
== 3) && !is_q
)) {
6630 unallocated_encoding(s
);
6634 if (!fp_access_check(s
)) {
6638 dofs
= vec_full_reg_offset(s
, rd
);
6639 oprsz
= is_q
? 16 : 8;
6640 maxsz
= vec_full_reg_size(s
);
6642 tcg_gen_gvec_dup_i64(size
, dofs
, oprsz
, maxsz
, cpu_reg(s
, rn
));
6647 * 31 21 20 16 15 14 11 10 9 5 4 0
6648 * +-----------------------+--------+------------+---+------+------+
6649 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6650 * +-----------------------+--------+------------+---+------+------+
6652 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6653 * index: encoded in imm5<4:size+1>
6655 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
6658 int size
= ctz32(imm5
);
6659 int src_index
, dst_index
;
6663 unallocated_encoding(s
);
6667 if (!fp_access_check(s
)) {
6671 dst_index
= extract32(imm5
, 1+size
, 5);
6672 src_index
= extract32(imm4
, size
, 4);
6674 tmp
= tcg_temp_new_i64();
6676 read_vec_element(s
, tmp
, rn
, src_index
, size
);
6677 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
6679 tcg_temp_free_i64(tmp
);
6685 * 31 21 20 16 15 10 9 5 4 0
6686 * +-----------------------+--------+-------------+------+------+
6687 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
6688 * +-----------------------+--------+-------------+------+------+
6690 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6691 * index: encoded in imm5<4:size+1>
6693 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
6695 int size
= ctz32(imm5
);
6699 unallocated_encoding(s
);
6703 if (!fp_access_check(s
)) {
6707 idx
= extract32(imm5
, 1 + size
, 4 - size
);
6708 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
6715 * 31 30 29 21 20 16 15 12 10 9 5 4 0
6716 * +---+---+-------------------+--------+-------------+------+------+
6717 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
6718 * +---+---+-------------------+--------+-------------+------+------+
6720 * U: unsigned when set
6721 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6723 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
6724 int rn
, int rd
, int imm5
)
6726 int size
= ctz32(imm5
);
6730 /* Check for UnallocatedEncodings */
6732 if (size
> 2 || (size
== 2 && !is_q
)) {
6733 unallocated_encoding(s
);
6738 || (size
< 3 && is_q
)
6739 || (size
== 3 && !is_q
)) {
6740 unallocated_encoding(s
);
6745 if (!fp_access_check(s
)) {
6749 element
= extract32(imm5
, 1+size
, 4);
6751 tcg_rd
= cpu_reg(s
, rd
);
6752 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
6753 if (is_signed
&& !is_q
) {
6754 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
6759 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
6760 * +---+---+----+-----------------+------+---+------+---+------+------+
6761 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6762 * +---+---+----+-----------------+------+---+------+---+------+------+
6764 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
6766 int rd
= extract32(insn
, 0, 5);
6767 int rn
= extract32(insn
, 5, 5);
6768 int imm4
= extract32(insn
, 11, 4);
6769 int op
= extract32(insn
, 29, 1);
6770 int is_q
= extract32(insn
, 30, 1);
6771 int imm5
= extract32(insn
, 16, 5);
6776 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
6778 unallocated_encoding(s
);
6783 /* DUP (element - vector) */
6784 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
6788 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
6793 handle_simd_insg(s
, rd
, rn
, imm5
);
6795 unallocated_encoding(s
);
6800 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
6801 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
6804 unallocated_encoding(s
);
6810 /* AdvSIMD modified immediate
6811 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
6812 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
6813 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
6814 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
6816 * There are a number of operations that can be carried out here:
6817 * MOVI - move (shifted) imm into register
6818 * MVNI - move inverted (shifted) imm into register
6819 * ORR - bitwise OR of (shifted) imm with register
6820 * BIC - bitwise clear of (shifted) imm with register
6821 * With ARMv8.2 we also have:
6822 * FMOV half-precision
6824 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
6826 int rd
= extract32(insn
, 0, 5);
6827 int cmode
= extract32(insn
, 12, 4);
6828 int cmode_3_1
= extract32(cmode
, 1, 3);
6829 int cmode_0
= extract32(cmode
, 0, 1);
6830 int o2
= extract32(insn
, 11, 1);
6831 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
6832 bool is_neg
= extract32(insn
, 29, 1);
6833 bool is_q
= extract32(insn
, 30, 1);
6836 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
6837 /* Check for FMOV (vector, immediate) - half-precision */
6838 if (!(arm_dc_feature(s
, ARM_FEATURE_V8_FP16
) && o2
&& cmode
== 0xf)) {
6839 unallocated_encoding(s
);
6844 if (!fp_access_check(s
)) {
6848 /* See AdvSIMDExpandImm() in ARM ARM */
6849 switch (cmode_3_1
) {
6850 case 0: /* Replicate(Zeros(24):imm8, 2) */
6851 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
6852 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
6853 case 3: /* Replicate(imm8:Zeros(24), 2) */
6855 int shift
= cmode_3_1
* 8;
6856 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
6859 case 4: /* Replicate(Zeros(8):imm8, 4) */
6860 case 5: /* Replicate(imm8:Zeros(8), 4) */
6862 int shift
= (cmode_3_1
& 0x1) * 8;
6863 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
6868 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
6869 imm
= (abcdefgh
<< 16) | 0xffff;
6871 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
6872 imm
= (abcdefgh
<< 8) | 0xff;
6874 imm
= bitfield_replicate(imm
, 32);
6877 if (!cmode_0
&& !is_neg
) {
6878 imm
= bitfield_replicate(abcdefgh
, 8);
6879 } else if (!cmode_0
&& is_neg
) {
6882 for (i
= 0; i
< 8; i
++) {
6883 if ((abcdefgh
) & (1 << i
)) {
6884 imm
|= 0xffULL
<< (i
* 8);
6887 } else if (cmode_0
) {
6889 imm
= (abcdefgh
& 0x3f) << 48;
6890 if (abcdefgh
& 0x80) {
6891 imm
|= 0x8000000000000000ULL
;
6893 if (abcdefgh
& 0x40) {
6894 imm
|= 0x3fc0000000000000ULL
;
6896 imm
|= 0x4000000000000000ULL
;
6900 /* FMOV (vector, immediate) - half-precision */
6901 imm
= vfp_expand_imm(MO_16
, abcdefgh
);
6902 /* now duplicate across the lanes */
6903 imm
= bitfield_replicate(imm
, 16);
6905 imm
= (abcdefgh
& 0x3f) << 19;
6906 if (abcdefgh
& 0x80) {
6909 if (abcdefgh
& 0x40) {
6920 fprintf(stderr
, "%s: cmode_3_1: %x\n", __func__
, cmode_3_1
);
6921 g_assert_not_reached();
6924 if (cmode_3_1
!= 7 && is_neg
) {
6928 if (!((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9)) {
6929 /* MOVI or MVNI, with MVNI negation handled above. */
6930 tcg_gen_gvec_dup64i(vec_full_reg_offset(s
, rd
), is_q
? 16 : 8,
6931 vec_full_reg_size(s
), imm
);
6933 /* ORR or BIC, with BIC negation to AND handled above. */
6935 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_andi
, MO_64
);
6937 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_ori
, MO_64
);
6942 /* AdvSIMD scalar copy
6943 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
6944 * +-----+----+-----------------+------+---+------+---+------+------+
6945 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6946 * +-----+----+-----------------+------+---+------+---+------+------+
6948 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
6950 int rd
= extract32(insn
, 0, 5);
6951 int rn
= extract32(insn
, 5, 5);
6952 int imm4
= extract32(insn
, 11, 4);
6953 int imm5
= extract32(insn
, 16, 5);
6954 int op
= extract32(insn
, 29, 1);
6956 if (op
!= 0 || imm4
!= 0) {
6957 unallocated_encoding(s
);
6961 /* DUP (element, scalar) */
6962 handle_simd_dupes(s
, rd
, rn
, imm5
);
6965 /* AdvSIMD scalar pairwise
6966 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6967 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6968 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6969 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6971 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
6973 int u
= extract32(insn
, 29, 1);
6974 int size
= extract32(insn
, 22, 2);
6975 int opcode
= extract32(insn
, 12, 5);
6976 int rn
= extract32(insn
, 5, 5);
6977 int rd
= extract32(insn
, 0, 5);
6980 /* For some ops (the FP ones), size[1] is part of the encoding.
6981 * For ADDP strictly it is not but size[1] is always 1 for valid
6984 opcode
|= (extract32(size
, 1, 1) << 5);
6987 case 0x3b: /* ADDP */
6988 if (u
|| size
!= 3) {
6989 unallocated_encoding(s
);
6992 if (!fp_access_check(s
)) {
6998 case 0xc: /* FMAXNMP */
6999 case 0xd: /* FADDP */
7000 case 0xf: /* FMAXP */
7001 case 0x2c: /* FMINNMP */
7002 case 0x2f: /* FMINP */
7003 /* FP op, size[0] is 32 or 64 bit*/
7005 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
7006 unallocated_encoding(s
);
7012 size
= extract32(size
, 0, 1) ? MO_64
: MO_32
;
7015 if (!fp_access_check(s
)) {
7019 fpst
= get_fpstatus_ptr(size
== MO_16
);
7022 unallocated_encoding(s
);
7026 if (size
== MO_64
) {
7027 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7028 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7029 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7031 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
7032 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
7035 case 0x3b: /* ADDP */
7036 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
7038 case 0xc: /* FMAXNMP */
7039 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7041 case 0xd: /* FADDP */
7042 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7044 case 0xf: /* FMAXP */
7045 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7047 case 0x2c: /* FMINNMP */
7048 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7050 case 0x2f: /* FMINP */
7051 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7054 g_assert_not_reached();
7057 write_fp_dreg(s
, rd
, tcg_res
);
7059 tcg_temp_free_i64(tcg_op1
);
7060 tcg_temp_free_i64(tcg_op2
);
7061 tcg_temp_free_i64(tcg_res
);
7063 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7064 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7065 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7067 read_vec_element_i32(s
, tcg_op1
, rn
, 0, size
);
7068 read_vec_element_i32(s
, tcg_op2
, rn
, 1, size
);
7070 if (size
== MO_16
) {
7072 case 0xc: /* FMAXNMP */
7073 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7075 case 0xd: /* FADDP */
7076 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7078 case 0xf: /* FMAXP */
7079 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7081 case 0x2c: /* FMINNMP */
7082 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7084 case 0x2f: /* FMINP */
7085 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7088 g_assert_not_reached();
7092 case 0xc: /* FMAXNMP */
7093 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7095 case 0xd: /* FADDP */
7096 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7098 case 0xf: /* FMAXP */
7099 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7101 case 0x2c: /* FMINNMP */
7102 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7104 case 0x2f: /* FMINP */
7105 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7108 g_assert_not_reached();
7112 write_fp_sreg(s
, rd
, tcg_res
);
7114 tcg_temp_free_i32(tcg_op1
);
7115 tcg_temp_free_i32(tcg_op2
);
7116 tcg_temp_free_i32(tcg_res
);
7120 tcg_temp_free_ptr(fpst
);
7125 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
7127 * This code is handles the common shifting code and is used by both
7128 * the vector and scalar code.
7130 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
7131 TCGv_i64 tcg_rnd
, bool accumulate
,
7132 bool is_u
, int size
, int shift
)
7134 bool extended_result
= false;
7135 bool round
= tcg_rnd
!= NULL
;
7137 TCGv_i64 tcg_src_hi
;
7139 if (round
&& size
== 3) {
7140 extended_result
= true;
7141 ext_lshift
= 64 - shift
;
7142 tcg_src_hi
= tcg_temp_new_i64();
7143 } else if (shift
== 64) {
7144 if (!accumulate
&& is_u
) {
7145 /* result is zero */
7146 tcg_gen_movi_i64(tcg_res
, 0);
7151 /* Deal with the rounding step */
7153 if (extended_result
) {
7154 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7156 /* take care of sign extending tcg_res */
7157 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
7158 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7159 tcg_src
, tcg_src_hi
,
7162 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7166 tcg_temp_free_i64(tcg_zero
);
7168 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
7172 /* Now do the shift right */
7173 if (round
&& extended_result
) {
7174 /* extended case, >64 bit precision required */
7175 if (ext_lshift
== 0) {
7176 /* special case, only high bits matter */
7177 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
7179 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7180 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
7181 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
7186 /* essentially shifting in 64 zeros */
7187 tcg_gen_movi_i64(tcg_src
, 0);
7189 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7193 /* effectively extending the sign-bit */
7194 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
7196 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
7202 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
7204 tcg_gen_mov_i64(tcg_res
, tcg_src
);
7207 if (extended_result
) {
7208 tcg_temp_free_i64(tcg_src_hi
);
7212 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
7213 static void handle_scalar_simd_shri(DisasContext
*s
,
7214 bool is_u
, int immh
, int immb
,
7215 int opcode
, int rn
, int rd
)
7218 int immhb
= immh
<< 3 | immb
;
7219 int shift
= 2 * (8 << size
) - immhb
;
7220 bool accumulate
= false;
7222 bool insert
= false;
7227 if (!extract32(immh
, 3, 1)) {
7228 unallocated_encoding(s
);
7232 if (!fp_access_check(s
)) {
7237 case 0x02: /* SSRA / USRA (accumulate) */
7240 case 0x04: /* SRSHR / URSHR (rounding) */
7243 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7244 accumulate
= round
= true;
7246 case 0x08: /* SRI */
7252 uint64_t round_const
= 1ULL << (shift
- 1);
7253 tcg_round
= tcg_const_i64(round_const
);
7258 tcg_rn
= read_fp_dreg(s
, rn
);
7259 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
7262 /* shift count same as element size is valid but does nothing;
7263 * special case to avoid potential shift by 64.
7265 int esize
= 8 << size
;
7266 if (shift
!= esize
) {
7267 tcg_gen_shri_i64(tcg_rn
, tcg_rn
, shift
);
7268 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, 0, esize
- shift
);
7271 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
7272 accumulate
, is_u
, size
, shift
);
7275 write_fp_dreg(s
, rd
, tcg_rd
);
7277 tcg_temp_free_i64(tcg_rn
);
7278 tcg_temp_free_i64(tcg_rd
);
7280 tcg_temp_free_i64(tcg_round
);
7284 /* SHL/SLI - Scalar shift left */
7285 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
7286 int immh
, int immb
, int opcode
,
7289 int size
= 32 - clz32(immh
) - 1;
7290 int immhb
= immh
<< 3 | immb
;
7291 int shift
= immhb
- (8 << size
);
7292 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
7293 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
7295 if (!extract32(immh
, 3, 1)) {
7296 unallocated_encoding(s
);
7300 if (!fp_access_check(s
)) {
7304 tcg_rn
= read_fp_dreg(s
, rn
);
7305 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
7308 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, shift
, 64 - shift
);
7310 tcg_gen_shli_i64(tcg_rd
, tcg_rn
, shift
);
7313 write_fp_dreg(s
, rd
, tcg_rd
);
7315 tcg_temp_free_i64(tcg_rn
);
7316 tcg_temp_free_i64(tcg_rd
);
7319 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
7320 * (signed/unsigned) narrowing */
7321 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
7322 bool is_u_shift
, bool is_u_narrow
,
7323 int immh
, int immb
, int opcode
,
7326 int immhb
= immh
<< 3 | immb
;
7327 int size
= 32 - clz32(immh
) - 1;
7328 int esize
= 8 << size
;
7329 int shift
= (2 * esize
) - immhb
;
7330 int elements
= is_scalar
? 1 : (64 / esize
);
7331 bool round
= extract32(opcode
, 0, 1);
7332 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
7333 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
7334 TCGv_i32 tcg_rd_narrowed
;
7337 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
7338 { gen_helper_neon_narrow_sat_s8
,
7339 gen_helper_neon_unarrow_sat8
},
7340 { gen_helper_neon_narrow_sat_s16
,
7341 gen_helper_neon_unarrow_sat16
},
7342 { gen_helper_neon_narrow_sat_s32
,
7343 gen_helper_neon_unarrow_sat32
},
7346 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
7347 gen_helper_neon_narrow_sat_u8
,
7348 gen_helper_neon_narrow_sat_u16
,
7349 gen_helper_neon_narrow_sat_u32
,
7352 NeonGenNarrowEnvFn
*narrowfn
;
7358 if (extract32(immh
, 3, 1)) {
7359 unallocated_encoding(s
);
7363 if (!fp_access_check(s
)) {
7368 narrowfn
= unsigned_narrow_fns
[size
];
7370 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
7373 tcg_rn
= tcg_temp_new_i64();
7374 tcg_rd
= tcg_temp_new_i64();
7375 tcg_rd_narrowed
= tcg_temp_new_i32();
7376 tcg_final
= tcg_const_i64(0);
7379 uint64_t round_const
= 1ULL << (shift
- 1);
7380 tcg_round
= tcg_const_i64(round_const
);
7385 for (i
= 0; i
< elements
; i
++) {
7386 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
7387 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
7388 false, is_u_shift
, size
+1, shift
);
7389 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
7390 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
7391 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
7395 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
7397 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
7401 tcg_temp_free_i64(tcg_round
);
7403 tcg_temp_free_i64(tcg_rn
);
7404 tcg_temp_free_i64(tcg_rd
);
7405 tcg_temp_free_i32(tcg_rd_narrowed
);
7406 tcg_temp_free_i64(tcg_final
);
7408 clear_vec_high(s
, is_q
, rd
);
7411 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
7412 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
7413 bool src_unsigned
, bool dst_unsigned
,
7414 int immh
, int immb
, int rn
, int rd
)
7416 int immhb
= immh
<< 3 | immb
;
7417 int size
= 32 - clz32(immh
) - 1;
7418 int shift
= immhb
- (8 << size
);
7422 assert(!(scalar
&& is_q
));
7425 if (!is_q
&& extract32(immh
, 3, 1)) {
7426 unallocated_encoding(s
);
7430 /* Since we use the variable-shift helpers we must
7431 * replicate the shift count into each element of
7432 * the tcg_shift value.
7436 shift
|= shift
<< 8;
7439 shift
|= shift
<< 16;
7445 g_assert_not_reached();
7449 if (!fp_access_check(s
)) {
7454 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
7455 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
7456 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
7457 { NULL
, gen_helper_neon_qshl_u64
},
7459 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
7460 int maxpass
= is_q
? 2 : 1;
7462 for (pass
= 0; pass
< maxpass
; pass
++) {
7463 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7465 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7466 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
7467 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
7469 tcg_temp_free_i64(tcg_op
);
7471 tcg_temp_free_i64(tcg_shift
);
7472 clear_vec_high(s
, is_q
, rd
);
7474 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
7475 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
7477 { gen_helper_neon_qshl_s8
,
7478 gen_helper_neon_qshl_s16
,
7479 gen_helper_neon_qshl_s32
},
7480 { gen_helper_neon_qshlu_s8
,
7481 gen_helper_neon_qshlu_s16
,
7482 gen_helper_neon_qshlu_s32
}
7484 { NULL
, NULL
, NULL
},
7485 { gen_helper_neon_qshl_u8
,
7486 gen_helper_neon_qshl_u16
,
7487 gen_helper_neon_qshl_u32
}
7490 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
7491 TCGMemOp memop
= scalar
? size
: MO_32
;
7492 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
7494 for (pass
= 0; pass
< maxpass
; pass
++) {
7495 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7497 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
7498 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
7502 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
7505 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
7510 g_assert_not_reached();
7512 write_fp_sreg(s
, rd
, tcg_op
);
7514 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
7517 tcg_temp_free_i32(tcg_op
);
7519 tcg_temp_free_i32(tcg_shift
);
7522 clear_vec_high(s
, is_q
, rd
);
7527 /* Common vector code for handling integer to FP conversion */
7528 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
7529 int elements
, int is_signed
,
7530 int fracbits
, int size
)
7532 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(size
== MO_16
);
7533 TCGv_i32 tcg_shift
= NULL
;
7535 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
7538 if (fracbits
|| size
== MO_64
) {
7539 tcg_shift
= tcg_const_i32(fracbits
);
7542 if (size
== MO_64
) {
7543 TCGv_i64 tcg_int64
= tcg_temp_new_i64();
7544 TCGv_i64 tcg_double
= tcg_temp_new_i64();
7546 for (pass
= 0; pass
< elements
; pass
++) {
7547 read_vec_element(s
, tcg_int64
, rn
, pass
, mop
);
7550 gen_helper_vfp_sqtod(tcg_double
, tcg_int64
,
7551 tcg_shift
, tcg_fpst
);
7553 gen_helper_vfp_uqtod(tcg_double
, tcg_int64
,
7554 tcg_shift
, tcg_fpst
);
7556 if (elements
== 1) {
7557 write_fp_dreg(s
, rd
, tcg_double
);
7559 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
7563 tcg_temp_free_i64(tcg_int64
);
7564 tcg_temp_free_i64(tcg_double
);
7567 TCGv_i32 tcg_int32
= tcg_temp_new_i32();
7568 TCGv_i32 tcg_float
= tcg_temp_new_i32();
7570 for (pass
= 0; pass
< elements
; pass
++) {
7571 read_vec_element_i32(s
, tcg_int32
, rn
, pass
, mop
);
7577 gen_helper_vfp_sltos(tcg_float
, tcg_int32
,
7578 tcg_shift
, tcg_fpst
);
7580 gen_helper_vfp_ultos(tcg_float
, tcg_int32
,
7581 tcg_shift
, tcg_fpst
);
7585 gen_helper_vfp_sitos(tcg_float
, tcg_int32
, tcg_fpst
);
7587 gen_helper_vfp_uitos(tcg_float
, tcg_int32
, tcg_fpst
);
7594 gen_helper_vfp_sltoh(tcg_float
, tcg_int32
,
7595 tcg_shift
, tcg_fpst
);
7597 gen_helper_vfp_ultoh(tcg_float
, tcg_int32
,
7598 tcg_shift
, tcg_fpst
);
7602 gen_helper_vfp_sitoh(tcg_float
, tcg_int32
, tcg_fpst
);
7604 gen_helper_vfp_uitoh(tcg_float
, tcg_int32
, tcg_fpst
);
7609 g_assert_not_reached();
7612 if (elements
== 1) {
7613 write_fp_sreg(s
, rd
, tcg_float
);
7615 write_vec_element_i32(s
, tcg_float
, rd
, pass
, size
);
7619 tcg_temp_free_i32(tcg_int32
);
7620 tcg_temp_free_i32(tcg_float
);
7623 tcg_temp_free_ptr(tcg_fpst
);
7625 tcg_temp_free_i32(tcg_shift
);
7628 clear_vec_high(s
, elements
<< size
== 16, rd
);
7631 /* UCVTF/SCVTF - Integer to FP conversion */
7632 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
7633 bool is_q
, bool is_u
,
7634 int immh
, int immb
, int opcode
,
7637 int size
, elements
, fracbits
;
7638 int immhb
= immh
<< 3 | immb
;
7642 if (!is_scalar
&& !is_q
) {
7643 unallocated_encoding(s
);
7646 } else if (immh
& 4) {
7648 } else if (immh
& 2) {
7650 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
7651 unallocated_encoding(s
);
7655 /* immh == 0 would be a failure of the decode logic */
7656 g_assert(immh
== 1);
7657 unallocated_encoding(s
);
7664 elements
= (8 << is_q
) >> size
;
7666 fracbits
= (16 << size
) - immhb
;
7668 if (!fp_access_check(s
)) {
7672 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
7675 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
7676 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
7677 bool is_q
, bool is_u
,
7678 int immh
, int immb
, int rn
, int rd
)
7680 int immhb
= immh
<< 3 | immb
;
7681 int pass
, size
, fracbits
;
7682 TCGv_ptr tcg_fpstatus
;
7683 TCGv_i32 tcg_rmode
, tcg_shift
;
7687 if (!is_scalar
&& !is_q
) {
7688 unallocated_encoding(s
);
7691 } else if (immh
& 0x4) {
7693 } else if (immh
& 0x2) {
7695 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
7696 unallocated_encoding(s
);
7700 /* Should have split out AdvSIMD modified immediate earlier. */
7702 unallocated_encoding(s
);
7706 if (!fp_access_check(s
)) {
7710 assert(!(is_scalar
&& is_q
));
7712 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
7713 tcg_fpstatus
= get_fpstatus_ptr(size
== MO_16
);
7714 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7715 fracbits
= (16 << size
) - immhb
;
7716 tcg_shift
= tcg_const_i32(fracbits
);
7718 if (size
== MO_64
) {
7719 int maxpass
= is_scalar
? 1 : 2;
7721 for (pass
= 0; pass
< maxpass
; pass
++) {
7722 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7724 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7726 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
7728 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
7730 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
7731 tcg_temp_free_i64(tcg_op
);
7733 clear_vec_high(s
, is_q
, rd
);
7735 void (*fn
)(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
7736 int maxpass
= is_scalar
? 1 : ((8 << is_q
) >> size
);
7741 fn
= gen_helper_vfp_touhh
;
7743 fn
= gen_helper_vfp_toshh
;
7748 fn
= gen_helper_vfp_touls
;
7750 fn
= gen_helper_vfp_tosls
;
7754 g_assert_not_reached();
7757 for (pass
= 0; pass
< maxpass
; pass
++) {
7758 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7760 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
7761 fn(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
7763 write_fp_sreg(s
, rd
, tcg_op
);
7765 write_vec_element_i32(s
, tcg_op
, rd
, pass
, size
);
7767 tcg_temp_free_i32(tcg_op
);
7770 clear_vec_high(s
, is_q
, rd
);
7774 tcg_temp_free_ptr(tcg_fpstatus
);
7775 tcg_temp_free_i32(tcg_shift
);
7776 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7777 tcg_temp_free_i32(tcg_rmode
);
7780 /* AdvSIMD scalar shift by immediate
7781 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
7782 * +-----+---+-------------+------+------+--------+---+------+------+
7783 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
7784 * +-----+---+-------------+------+------+--------+---+------+------+
7786 * This is the scalar version so it works on a fixed sized registers
7788 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
7790 int rd
= extract32(insn
, 0, 5);
7791 int rn
= extract32(insn
, 5, 5);
7792 int opcode
= extract32(insn
, 11, 5);
7793 int immb
= extract32(insn
, 16, 3);
7794 int immh
= extract32(insn
, 19, 4);
7795 bool is_u
= extract32(insn
, 29, 1);
7798 unallocated_encoding(s
);
7803 case 0x08: /* SRI */
7805 unallocated_encoding(s
);
7809 case 0x00: /* SSHR / USHR */
7810 case 0x02: /* SSRA / USRA */
7811 case 0x04: /* SRSHR / URSHR */
7812 case 0x06: /* SRSRA / URSRA */
7813 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
7815 case 0x0a: /* SHL / SLI */
7816 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
7818 case 0x1c: /* SCVTF, UCVTF */
7819 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
7822 case 0x10: /* SQSHRUN, SQSHRUN2 */
7823 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
7825 unallocated_encoding(s
);
7828 handle_vec_simd_sqshrn(s
, true, false, false, true,
7829 immh
, immb
, opcode
, rn
, rd
);
7831 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
7832 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
7833 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
7834 immh
, immb
, opcode
, rn
, rd
);
7836 case 0xc: /* SQSHLU */
7838 unallocated_encoding(s
);
7841 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
7843 case 0xe: /* SQSHL, UQSHL */
7844 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
7846 case 0x1f: /* FCVTZS, FCVTZU */
7847 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
7850 unallocated_encoding(s
);
7855 /* AdvSIMD scalar three different
7856 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
7857 * +-----+---+-----------+------+---+------+--------+-----+------+------+
7858 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
7859 * +-----+---+-----------+------+---+------+--------+-----+------+------+
7861 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
7863 bool is_u
= extract32(insn
, 29, 1);
7864 int size
= extract32(insn
, 22, 2);
7865 int opcode
= extract32(insn
, 12, 4);
7866 int rm
= extract32(insn
, 16, 5);
7867 int rn
= extract32(insn
, 5, 5);
7868 int rd
= extract32(insn
, 0, 5);
7871 unallocated_encoding(s
);
7876 case 0x9: /* SQDMLAL, SQDMLAL2 */
7877 case 0xb: /* SQDMLSL, SQDMLSL2 */
7878 case 0xd: /* SQDMULL, SQDMULL2 */
7879 if (size
== 0 || size
== 3) {
7880 unallocated_encoding(s
);
7885 unallocated_encoding(s
);
7889 if (!fp_access_check(s
)) {
7894 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7895 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7896 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7898 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
7899 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
7901 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
7902 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
7905 case 0xd: /* SQDMULL, SQDMULL2 */
7907 case 0xb: /* SQDMLSL, SQDMLSL2 */
7908 tcg_gen_neg_i64(tcg_res
, tcg_res
);
7910 case 0x9: /* SQDMLAL, SQDMLAL2 */
7911 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
7912 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
7916 g_assert_not_reached();
7919 write_fp_dreg(s
, rd
, tcg_res
);
7921 tcg_temp_free_i64(tcg_op1
);
7922 tcg_temp_free_i64(tcg_op2
);
7923 tcg_temp_free_i64(tcg_res
);
7925 TCGv_i32 tcg_op1
= read_fp_hreg(s
, rn
);
7926 TCGv_i32 tcg_op2
= read_fp_hreg(s
, rm
);
7927 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7929 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
7930 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
7933 case 0xd: /* SQDMULL, SQDMULL2 */
7935 case 0xb: /* SQDMLSL, SQDMLSL2 */
7936 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
7938 case 0x9: /* SQDMLAL, SQDMLAL2 */
7940 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
7941 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
7942 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
7944 tcg_temp_free_i64(tcg_op3
);
7948 g_assert_not_reached();
7951 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
7952 write_fp_dreg(s
, rd
, tcg_res
);
7954 tcg_temp_free_i32(tcg_op1
);
7955 tcg_temp_free_i32(tcg_op2
);
7956 tcg_temp_free_i64(tcg_res
);
7960 /* CMTST : test is "if (X & Y != 0)". */
7961 static void gen_cmtst_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
7963 tcg_gen_and_i32(d
, a
, b
);
7964 tcg_gen_setcondi_i32(TCG_COND_NE
, d
, d
, 0);
7965 tcg_gen_neg_i32(d
, d
);
7968 static void gen_cmtst_i64(TCGv_i64 d
, TCGv_i64 a
, TCGv_i64 b
)
7970 tcg_gen_and_i64(d
, a
, b
);
7971 tcg_gen_setcondi_i64(TCG_COND_NE
, d
, d
, 0);
7972 tcg_gen_neg_i64(d
, d
);
7975 static void gen_cmtst_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, TCGv_vec b
)
7977 tcg_gen_and_vec(vece
, d
, a
, b
);
7978 tcg_gen_dupi_vec(vece
, a
, 0);
7979 tcg_gen_cmp_vec(TCG_COND_NE
, vece
, d
, d
, a
);
7982 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
7983 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
7985 /* Handle 64x64->64 opcodes which are shared between the scalar
7986 * and vector 3-same groups. We cover every opcode where size == 3
7987 * is valid in either the three-reg-same (integer, not pairwise)
7988 * or scalar-three-reg-same groups.
7993 case 0x1: /* SQADD */
7995 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7997 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8000 case 0x5: /* SQSUB */
8002 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8004 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8007 case 0x6: /* CMGT, CMHI */
8008 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
8009 * We implement this using setcond (test) and then negating.
8011 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
8013 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
8014 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
8016 case 0x7: /* CMGE, CMHS */
8017 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
8019 case 0x11: /* CMTST, CMEQ */
8024 gen_cmtst_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8026 case 0x8: /* SSHL, USHL */
8028 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8030 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8033 case 0x9: /* SQSHL, UQSHL */
8035 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8037 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8040 case 0xa: /* SRSHL, URSHL */
8042 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8044 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8047 case 0xb: /* SQRSHL, UQRSHL */
8049 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8051 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8054 case 0x10: /* ADD, SUB */
8056 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8058 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8062 g_assert_not_reached();
8066 /* Handle the 3-same-operands float operations; shared by the scalar
8067 * and vector encodings. The caller must filter out any encodings
8068 * not allocated for the encoding it is dealing with.
8070 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
8071 int fpopcode
, int rd
, int rn
, int rm
)
8074 TCGv_ptr fpst
= get_fpstatus_ptr(false);
8076 for (pass
= 0; pass
< elements
; pass
++) {
8079 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8080 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8081 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8083 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8084 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8087 case 0x39: /* FMLS */
8088 /* As usual for ARM, separate negation for fused multiply-add */
8089 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
8091 case 0x19: /* FMLA */
8092 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8093 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
8096 case 0x18: /* FMAXNM */
8097 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8099 case 0x1a: /* FADD */
8100 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8102 case 0x1b: /* FMULX */
8103 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8105 case 0x1c: /* FCMEQ */
8106 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8108 case 0x1e: /* FMAX */
8109 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8111 case 0x1f: /* FRECPS */
8112 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8114 case 0x38: /* FMINNM */
8115 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8117 case 0x3a: /* FSUB */
8118 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8120 case 0x3e: /* FMIN */
8121 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8123 case 0x3f: /* FRSQRTS */
8124 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8126 case 0x5b: /* FMUL */
8127 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8129 case 0x5c: /* FCMGE */
8130 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8132 case 0x5d: /* FACGE */
8133 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8135 case 0x5f: /* FDIV */
8136 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8138 case 0x7a: /* FABD */
8139 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8140 gen_helper_vfp_absd(tcg_res
, tcg_res
);
8142 case 0x7c: /* FCMGT */
8143 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8145 case 0x7d: /* FACGT */
8146 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8149 g_assert_not_reached();
8152 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8154 tcg_temp_free_i64(tcg_res
);
8155 tcg_temp_free_i64(tcg_op1
);
8156 tcg_temp_free_i64(tcg_op2
);
8159 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8160 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8161 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8163 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
8164 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
8167 case 0x39: /* FMLS */
8168 /* As usual for ARM, separate negation for fused multiply-add */
8169 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
8171 case 0x19: /* FMLA */
8172 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8173 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
8176 case 0x1a: /* FADD */
8177 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8179 case 0x1b: /* FMULX */
8180 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8182 case 0x1c: /* FCMEQ */
8183 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8185 case 0x1e: /* FMAX */
8186 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8188 case 0x1f: /* FRECPS */
8189 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8191 case 0x18: /* FMAXNM */
8192 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8194 case 0x38: /* FMINNM */
8195 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8197 case 0x3a: /* FSUB */
8198 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8200 case 0x3e: /* FMIN */
8201 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8203 case 0x3f: /* FRSQRTS */
8204 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8206 case 0x5b: /* FMUL */
8207 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8209 case 0x5c: /* FCMGE */
8210 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8212 case 0x5d: /* FACGE */
8213 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8215 case 0x5f: /* FDIV */
8216 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8218 case 0x7a: /* FABD */
8219 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8220 gen_helper_vfp_abss(tcg_res
, tcg_res
);
8222 case 0x7c: /* FCMGT */
8223 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8225 case 0x7d: /* FACGT */
8226 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8229 g_assert_not_reached();
8232 if (elements
== 1) {
8233 /* scalar single so clear high part */
8234 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
8236 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
8237 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
8238 tcg_temp_free_i64(tcg_tmp
);
8240 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8243 tcg_temp_free_i32(tcg_res
);
8244 tcg_temp_free_i32(tcg_op1
);
8245 tcg_temp_free_i32(tcg_op2
);
8249 tcg_temp_free_ptr(fpst
);
8251 clear_vec_high(s
, elements
* (size
? 8 : 4) > 8, rd
);
8254 /* AdvSIMD scalar three same
8255 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8256 * +-----+---+-----------+------+---+------+--------+---+------+------+
8257 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8258 * +-----+---+-----------+------+---+------+--------+---+------+------+
8260 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
8262 int rd
= extract32(insn
, 0, 5);
8263 int rn
= extract32(insn
, 5, 5);
8264 int opcode
= extract32(insn
, 11, 5);
8265 int rm
= extract32(insn
, 16, 5);
8266 int size
= extract32(insn
, 22, 2);
8267 bool u
= extract32(insn
, 29, 1);
8270 if (opcode
>= 0x18) {
8271 /* Floating point: U, size[1] and opcode indicate operation */
8272 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
8274 case 0x1b: /* FMULX */
8275 case 0x1f: /* FRECPS */
8276 case 0x3f: /* FRSQRTS */
8277 case 0x5d: /* FACGE */
8278 case 0x7d: /* FACGT */
8279 case 0x1c: /* FCMEQ */
8280 case 0x5c: /* FCMGE */
8281 case 0x7c: /* FCMGT */
8282 case 0x7a: /* FABD */
8285 unallocated_encoding(s
);
8289 if (!fp_access_check(s
)) {
8293 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
8298 case 0x1: /* SQADD, UQADD */
8299 case 0x5: /* SQSUB, UQSUB */
8300 case 0x9: /* SQSHL, UQSHL */
8301 case 0xb: /* SQRSHL, UQRSHL */
8303 case 0x8: /* SSHL, USHL */
8304 case 0xa: /* SRSHL, URSHL */
8305 case 0x6: /* CMGT, CMHI */
8306 case 0x7: /* CMGE, CMHS */
8307 case 0x11: /* CMTST, CMEQ */
8308 case 0x10: /* ADD, SUB (vector) */
8310 unallocated_encoding(s
);
8314 case 0x16: /* SQDMULH, SQRDMULH (vector) */
8315 if (size
!= 1 && size
!= 2) {
8316 unallocated_encoding(s
);
8321 unallocated_encoding(s
);
8325 if (!fp_access_check(s
)) {
8329 tcg_rd
= tcg_temp_new_i64();
8332 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
8333 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
8335 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
8336 tcg_temp_free_i64(tcg_rn
);
8337 tcg_temp_free_i64(tcg_rm
);
8339 /* Do a single operation on the lowest element in the vector.
8340 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
8341 * no side effects for all these operations.
8342 * OPTME: special-purpose helpers would avoid doing some
8343 * unnecessary work in the helper for the 8 and 16 bit cases.
8345 NeonGenTwoOpEnvFn
*genenvfn
;
8346 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
8347 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
8348 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
8350 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
8351 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
8354 case 0x1: /* SQADD, UQADD */
8356 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8357 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
8358 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
8359 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
8361 genenvfn
= fns
[size
][u
];
8364 case 0x5: /* SQSUB, UQSUB */
8366 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8367 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
8368 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
8369 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
8371 genenvfn
= fns
[size
][u
];
8374 case 0x9: /* SQSHL, UQSHL */
8376 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8377 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
8378 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
8379 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
8381 genenvfn
= fns
[size
][u
];
8384 case 0xb: /* SQRSHL, UQRSHL */
8386 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8387 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
8388 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
8389 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
8391 genenvfn
= fns
[size
][u
];
8394 case 0x16: /* SQDMULH, SQRDMULH */
8396 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
8397 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
8398 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
8400 assert(size
== 1 || size
== 2);
8401 genenvfn
= fns
[size
- 1][u
];
8405 g_assert_not_reached();
8408 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
8409 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
8410 tcg_temp_free_i32(tcg_rd32
);
8411 tcg_temp_free_i32(tcg_rn
);
8412 tcg_temp_free_i32(tcg_rm
);
8415 write_fp_dreg(s
, rd
, tcg_rd
);
8417 tcg_temp_free_i64(tcg_rd
);
8420 /* AdvSIMD scalar three same FP16
8421 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
8422 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8423 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
8424 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8425 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
8426 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
8428 static void disas_simd_scalar_three_reg_same_fp16(DisasContext
*s
,
8431 int rd
= extract32(insn
, 0, 5);
8432 int rn
= extract32(insn
, 5, 5);
8433 int opcode
= extract32(insn
, 11, 3);
8434 int rm
= extract32(insn
, 16, 5);
8435 bool u
= extract32(insn
, 29, 1);
8436 bool a
= extract32(insn
, 23, 1);
8437 int fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
8444 case 0x03: /* FMULX */
8445 case 0x04: /* FCMEQ (reg) */
8446 case 0x07: /* FRECPS */
8447 case 0x0f: /* FRSQRTS */
8448 case 0x14: /* FCMGE (reg) */
8449 case 0x15: /* FACGE */
8450 case 0x1a: /* FABD */
8451 case 0x1c: /* FCMGT (reg) */
8452 case 0x1d: /* FACGT */
8455 unallocated_encoding(s
);
8459 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
8460 unallocated_encoding(s
);
8463 if (!fp_access_check(s
)) {
8467 fpst
= get_fpstatus_ptr(true);
8469 tcg_op1
= read_fp_hreg(s
, rn
);
8470 tcg_op2
= read_fp_hreg(s
, rm
);
8471 tcg_res
= tcg_temp_new_i32();
8474 case 0x03: /* FMULX */
8475 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8477 case 0x04: /* FCMEQ (reg) */
8478 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8480 case 0x07: /* FRECPS */
8481 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8483 case 0x0f: /* FRSQRTS */
8484 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8486 case 0x14: /* FCMGE (reg) */
8487 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8489 case 0x15: /* FACGE */
8490 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8492 case 0x1a: /* FABD */
8493 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8494 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
8496 case 0x1c: /* FCMGT (reg) */
8497 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8499 case 0x1d: /* FACGT */
8500 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8503 g_assert_not_reached();
8506 write_fp_sreg(s
, rd
, tcg_res
);
8509 tcg_temp_free_i32(tcg_res
);
8510 tcg_temp_free_i32(tcg_op1
);
8511 tcg_temp_free_i32(tcg_op2
);
8512 tcg_temp_free_ptr(fpst
);
8515 /* AdvSIMD scalar three same extra
8516 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
8517 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
8518 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
8519 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
8521 static void disas_simd_scalar_three_reg_same_extra(DisasContext
*s
,
8524 int rd
= extract32(insn
, 0, 5);
8525 int rn
= extract32(insn
, 5, 5);
8526 int opcode
= extract32(insn
, 11, 4);
8527 int rm
= extract32(insn
, 16, 5);
8528 int size
= extract32(insn
, 22, 2);
8529 bool u
= extract32(insn
, 29, 1);
8530 TCGv_i32 ele1
, ele2
, ele3
;
8534 switch (u
* 16 + opcode
) {
8535 case 0x10: /* SQRDMLAH (vector) */
8536 case 0x11: /* SQRDMLSH (vector) */
8537 if (size
!= 1 && size
!= 2) {
8538 unallocated_encoding(s
);
8541 feature
= ARM_FEATURE_V8_RDM
;
8544 unallocated_encoding(s
);
8547 if (!arm_dc_feature(s
, feature
)) {
8548 unallocated_encoding(s
);
8551 if (!fp_access_check(s
)) {
8555 /* Do a single operation on the lowest element in the vector.
8556 * We use the standard Neon helpers and rely on 0 OP 0 == 0
8557 * with no side effects for all these operations.
8558 * OPTME: special-purpose helpers would avoid doing some
8559 * unnecessary work in the helper for the 16 bit cases.
8561 ele1
= tcg_temp_new_i32();
8562 ele2
= tcg_temp_new_i32();
8563 ele3
= tcg_temp_new_i32();
8565 read_vec_element_i32(s
, ele1
, rn
, 0, size
);
8566 read_vec_element_i32(s
, ele2
, rm
, 0, size
);
8567 read_vec_element_i32(s
, ele3
, rd
, 0, size
);
8570 case 0x0: /* SQRDMLAH */
8572 gen_helper_neon_qrdmlah_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8574 gen_helper_neon_qrdmlah_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8577 case 0x1: /* SQRDMLSH */
8579 gen_helper_neon_qrdmlsh_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8581 gen_helper_neon_qrdmlsh_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8585 g_assert_not_reached();
8587 tcg_temp_free_i32(ele1
);
8588 tcg_temp_free_i32(ele2
);
8590 res
= tcg_temp_new_i64();
8591 tcg_gen_extu_i32_i64(res
, ele3
);
8592 tcg_temp_free_i32(ele3
);
8594 write_fp_dreg(s
, rd
, res
);
8595 tcg_temp_free_i64(res
);
8598 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
8599 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
8600 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
8602 /* Handle 64->64 opcodes which are shared between the scalar and
8603 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
8604 * is valid in either group and also the double-precision fp ops.
8605 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
8611 case 0x4: /* CLS, CLZ */
8613 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
8615 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
8619 /* This opcode is shared with CNT and RBIT but we have earlier
8620 * enforced that size == 3 if and only if this is the NOT insn.
8622 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
8624 case 0x7: /* SQABS, SQNEG */
8626 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
8628 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
8631 case 0xa: /* CMLT */
8632 /* 64 bit integer comparison against zero, result is
8633 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
8638 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
8639 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
8641 case 0x8: /* CMGT, CMGE */
8642 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
8644 case 0x9: /* CMEQ, CMLE */
8645 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
8647 case 0xb: /* ABS, NEG */
8649 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
8651 TCGv_i64 tcg_zero
= tcg_const_i64(0);
8652 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
8653 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
8655 tcg_temp_free_i64(tcg_zero
);
8658 case 0x2f: /* FABS */
8659 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
8661 case 0x6f: /* FNEG */
8662 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
8664 case 0x7f: /* FSQRT */
8665 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
8667 case 0x1a: /* FCVTNS */
8668 case 0x1b: /* FCVTMS */
8669 case 0x1c: /* FCVTAS */
8670 case 0x3a: /* FCVTPS */
8671 case 0x3b: /* FCVTZS */
8673 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8674 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8675 tcg_temp_free_i32(tcg_shift
);
8678 case 0x5a: /* FCVTNU */
8679 case 0x5b: /* FCVTMU */
8680 case 0x5c: /* FCVTAU */
8681 case 0x7a: /* FCVTPU */
8682 case 0x7b: /* FCVTZU */
8684 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8685 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8686 tcg_temp_free_i32(tcg_shift
);
8689 case 0x18: /* FRINTN */
8690 case 0x19: /* FRINTM */
8691 case 0x38: /* FRINTP */
8692 case 0x39: /* FRINTZ */
8693 case 0x58: /* FRINTA */
8694 case 0x79: /* FRINTI */
8695 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
8697 case 0x59: /* FRINTX */
8698 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
8701 g_assert_not_reached();
8705 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
8706 bool is_scalar
, bool is_u
, bool is_q
,
8707 int size
, int rn
, int rd
)
8709 bool is_double
= (size
== MO_64
);
8712 if (!fp_access_check(s
)) {
8716 fpst
= get_fpstatus_ptr(size
== MO_16
);
8719 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8720 TCGv_i64 tcg_zero
= tcg_const_i64(0);
8721 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8722 NeonGenTwoDoubleOPFn
*genfn
;
8727 case 0x2e: /* FCMLT (zero) */
8730 case 0x2c: /* FCMGT (zero) */
8731 genfn
= gen_helper_neon_cgt_f64
;
8733 case 0x2d: /* FCMEQ (zero) */
8734 genfn
= gen_helper_neon_ceq_f64
;
8736 case 0x6d: /* FCMLE (zero) */
8739 case 0x6c: /* FCMGE (zero) */
8740 genfn
= gen_helper_neon_cge_f64
;
8743 g_assert_not_reached();
8746 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
8747 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8749 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
8751 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
8753 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8755 tcg_temp_free_i64(tcg_res
);
8756 tcg_temp_free_i64(tcg_zero
);
8757 tcg_temp_free_i64(tcg_op
);
8759 clear_vec_high(s
, !is_scalar
, rd
);
8761 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8762 TCGv_i32 tcg_zero
= tcg_const_i32(0);
8763 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8764 NeonGenTwoSingleOPFn
*genfn
;
8766 int pass
, maxpasses
;
8768 if (size
== MO_16
) {
8770 case 0x2e: /* FCMLT (zero) */
8773 case 0x2c: /* FCMGT (zero) */
8774 genfn
= gen_helper_advsimd_cgt_f16
;
8776 case 0x2d: /* FCMEQ (zero) */
8777 genfn
= gen_helper_advsimd_ceq_f16
;
8779 case 0x6d: /* FCMLE (zero) */
8782 case 0x6c: /* FCMGE (zero) */
8783 genfn
= gen_helper_advsimd_cge_f16
;
8786 g_assert_not_reached();
8790 case 0x2e: /* FCMLT (zero) */
8793 case 0x2c: /* FCMGT (zero) */
8794 genfn
= gen_helper_neon_cgt_f32
;
8796 case 0x2d: /* FCMEQ (zero) */
8797 genfn
= gen_helper_neon_ceq_f32
;
8799 case 0x6d: /* FCMLE (zero) */
8802 case 0x6c: /* FCMGE (zero) */
8803 genfn
= gen_helper_neon_cge_f32
;
8806 g_assert_not_reached();
8813 int vector_size
= 8 << is_q
;
8814 maxpasses
= vector_size
>> size
;
8817 for (pass
= 0; pass
< maxpasses
; pass
++) {
8818 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
8820 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
8822 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
8825 write_fp_sreg(s
, rd
, tcg_res
);
8827 write_vec_element_i32(s
, tcg_res
, rd
, pass
, size
);
8830 tcg_temp_free_i32(tcg_res
);
8831 tcg_temp_free_i32(tcg_zero
);
8832 tcg_temp_free_i32(tcg_op
);
8834 clear_vec_high(s
, is_q
, rd
);
8838 tcg_temp_free_ptr(fpst
);
8841 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
8842 bool is_scalar
, bool is_u
, bool is_q
,
8843 int size
, int rn
, int rd
)
8845 bool is_double
= (size
== 3);
8846 TCGv_ptr fpst
= get_fpstatus_ptr(false);
8849 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8850 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8853 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
8854 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8856 case 0x3d: /* FRECPE */
8857 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
8859 case 0x3f: /* FRECPX */
8860 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
8862 case 0x7d: /* FRSQRTE */
8863 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
8866 g_assert_not_reached();
8868 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8870 tcg_temp_free_i64(tcg_res
);
8871 tcg_temp_free_i64(tcg_op
);
8872 clear_vec_high(s
, !is_scalar
, rd
);
8874 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8875 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8876 int pass
, maxpasses
;
8881 maxpasses
= is_q
? 4 : 2;
8884 for (pass
= 0; pass
< maxpasses
; pass
++) {
8885 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
8888 case 0x3c: /* URECPE */
8889 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
8891 case 0x3d: /* FRECPE */
8892 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
8894 case 0x3f: /* FRECPX */
8895 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
8897 case 0x7d: /* FRSQRTE */
8898 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
8901 g_assert_not_reached();
8905 write_fp_sreg(s
, rd
, tcg_res
);
8907 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8910 tcg_temp_free_i32(tcg_res
);
8911 tcg_temp_free_i32(tcg_op
);
8913 clear_vec_high(s
, is_q
, rd
);
8916 tcg_temp_free_ptr(fpst
);
8919 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
8920 int opcode
, bool u
, bool is_q
,
8921 int size
, int rn
, int rd
)
8923 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
8924 * in the source becomes a size element in the destination).
8927 TCGv_i32 tcg_res
[2];
8928 int destelt
= is_q
? 2 : 0;
8929 int passes
= scalar
? 1 : 2;
8932 tcg_res
[1] = tcg_const_i32(0);
8935 for (pass
= 0; pass
< passes
; pass
++) {
8936 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8937 NeonGenNarrowFn
*genfn
= NULL
;
8938 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
8941 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
8943 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8945 tcg_res
[pass
] = tcg_temp_new_i32();
8948 case 0x12: /* XTN, SQXTUN */
8950 static NeonGenNarrowFn
* const xtnfns
[3] = {
8951 gen_helper_neon_narrow_u8
,
8952 gen_helper_neon_narrow_u16
,
8953 tcg_gen_extrl_i64_i32
,
8955 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
8956 gen_helper_neon_unarrow_sat8
,
8957 gen_helper_neon_unarrow_sat16
,
8958 gen_helper_neon_unarrow_sat32
,
8961 genenvfn
= sqxtunfns
[size
];
8963 genfn
= xtnfns
[size
];
8967 case 0x14: /* SQXTN, UQXTN */
8969 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
8970 { gen_helper_neon_narrow_sat_s8
,
8971 gen_helper_neon_narrow_sat_u8
},
8972 { gen_helper_neon_narrow_sat_s16
,
8973 gen_helper_neon_narrow_sat_u16
},
8974 { gen_helper_neon_narrow_sat_s32
,
8975 gen_helper_neon_narrow_sat_u32
},
8977 genenvfn
= fns
[size
][u
];
8980 case 0x16: /* FCVTN, FCVTN2 */
8981 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
8983 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
8985 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
8986 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
8987 TCGv_ptr fpst
= get_fpstatus_ptr(false);
8988 TCGv_i32 ahp
= get_ahp_flag();
8990 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
8991 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, fpst
, ahp
);
8992 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, fpst
, ahp
);
8993 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
8994 tcg_temp_free_i32(tcg_lo
);
8995 tcg_temp_free_i32(tcg_hi
);
8996 tcg_temp_free_ptr(fpst
);
8997 tcg_temp_free_i32(ahp
);
9000 case 0x56: /* FCVTXN, FCVTXN2 */
9001 /* 64 bit to 32 bit float conversion
9002 * with von Neumann rounding (round to odd)
9005 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
9008 g_assert_not_reached();
9012 genfn(tcg_res
[pass
], tcg_op
);
9013 } else if (genenvfn
) {
9014 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
9017 tcg_temp_free_i64(tcg_op
);
9020 for (pass
= 0; pass
< 2; pass
++) {
9021 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
9022 tcg_temp_free_i32(tcg_res
[pass
]);
9024 clear_vec_high(s
, is_q
, rd
);
9027 /* Remaining saturating accumulating ops */
9028 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
9029 bool is_q
, int size
, int rn
, int rd
)
9031 bool is_double
= (size
== 3);
9034 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9035 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9038 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9039 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
9040 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9042 if (is_u
) { /* USQADD */
9043 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9044 } else { /* SUQADD */
9045 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9047 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9049 tcg_temp_free_i64(tcg_rd
);
9050 tcg_temp_free_i64(tcg_rn
);
9051 clear_vec_high(s
, !is_scalar
, rd
);
9053 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9054 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9055 int pass
, maxpasses
;
9060 maxpasses
= is_q
? 4 : 2;
9063 for (pass
= 0; pass
< maxpasses
; pass
++) {
9065 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
9066 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
9068 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
9069 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9072 if (is_u
) { /* USQADD */
9075 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9078 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9081 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9084 g_assert_not_reached();
9086 } else { /* SUQADD */
9089 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9092 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9095 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9098 g_assert_not_reached();
9103 TCGv_i64 tcg_zero
= tcg_const_i64(0);
9104 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
9105 tcg_temp_free_i64(tcg_zero
);
9107 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9109 tcg_temp_free_i32(tcg_rd
);
9110 tcg_temp_free_i32(tcg_rn
);
9111 clear_vec_high(s
, is_q
, rd
);
9115 /* AdvSIMD scalar two reg misc
9116 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9117 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9118 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9119 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9121 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9123 int rd
= extract32(insn
, 0, 5);
9124 int rn
= extract32(insn
, 5, 5);
9125 int opcode
= extract32(insn
, 12, 5);
9126 int size
= extract32(insn
, 22, 2);
9127 bool u
= extract32(insn
, 29, 1);
9128 bool is_fcvt
= false;
9131 TCGv_ptr tcg_fpstatus
;
9134 case 0x3: /* USQADD / SUQADD*/
9135 if (!fp_access_check(s
)) {
9138 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
9140 case 0x7: /* SQABS / SQNEG */
9142 case 0xa: /* CMLT */
9144 unallocated_encoding(s
);
9148 case 0x8: /* CMGT, CMGE */
9149 case 0x9: /* CMEQ, CMLE */
9150 case 0xb: /* ABS, NEG */
9152 unallocated_encoding(s
);
9156 case 0x12: /* SQXTUN */
9158 unallocated_encoding(s
);
9162 case 0x14: /* SQXTN, UQXTN */
9164 unallocated_encoding(s
);
9167 if (!fp_access_check(s
)) {
9170 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
9175 /* Floating point: U, size[1] and opcode indicate operation;
9176 * size[0] indicates single or double precision.
9178 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9179 size
= extract32(size
, 0, 1) ? 3 : 2;
9181 case 0x2c: /* FCMGT (zero) */
9182 case 0x2d: /* FCMEQ (zero) */
9183 case 0x2e: /* FCMLT (zero) */
9184 case 0x6c: /* FCMGE (zero) */
9185 case 0x6d: /* FCMLE (zero) */
9186 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
9188 case 0x1d: /* SCVTF */
9189 case 0x5d: /* UCVTF */
9191 bool is_signed
= (opcode
== 0x1d);
9192 if (!fp_access_check(s
)) {
9195 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
9198 case 0x3d: /* FRECPE */
9199 case 0x3f: /* FRECPX */
9200 case 0x7d: /* FRSQRTE */
9201 if (!fp_access_check(s
)) {
9204 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
9206 case 0x1a: /* FCVTNS */
9207 case 0x1b: /* FCVTMS */
9208 case 0x3a: /* FCVTPS */
9209 case 0x3b: /* FCVTZS */
9210 case 0x5a: /* FCVTNU */
9211 case 0x5b: /* FCVTMU */
9212 case 0x7a: /* FCVTPU */
9213 case 0x7b: /* FCVTZU */
9215 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9217 case 0x1c: /* FCVTAS */
9218 case 0x5c: /* FCVTAU */
9219 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
9221 rmode
= FPROUNDING_TIEAWAY
;
9223 case 0x56: /* FCVTXN, FCVTXN2 */
9225 unallocated_encoding(s
);
9228 if (!fp_access_check(s
)) {
9231 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
9234 unallocated_encoding(s
);
9239 unallocated_encoding(s
);
9243 if (!fp_access_check(s
)) {
9248 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
9249 tcg_fpstatus
= get_fpstatus_ptr(false);
9250 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9253 tcg_fpstatus
= NULL
;
9257 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
9258 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9260 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
9261 write_fp_dreg(s
, rd
, tcg_rd
);
9262 tcg_temp_free_i64(tcg_rd
);
9263 tcg_temp_free_i64(tcg_rn
);
9265 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9266 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9268 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
9271 case 0x7: /* SQABS, SQNEG */
9273 NeonGenOneOpEnvFn
*genfn
;
9274 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
9275 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
9276 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
9277 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
9279 genfn
= fns
[size
][u
];
9280 genfn(tcg_rd
, cpu_env
, tcg_rn
);
9283 case 0x1a: /* FCVTNS */
9284 case 0x1b: /* FCVTMS */
9285 case 0x1c: /* FCVTAS */
9286 case 0x3a: /* FCVTPS */
9287 case 0x3b: /* FCVTZS */
9289 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9290 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9291 tcg_temp_free_i32(tcg_shift
);
9294 case 0x5a: /* FCVTNU */
9295 case 0x5b: /* FCVTMU */
9296 case 0x5c: /* FCVTAU */
9297 case 0x7a: /* FCVTPU */
9298 case 0x7b: /* FCVTZU */
9300 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9301 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9302 tcg_temp_free_i32(tcg_shift
);
9306 g_assert_not_reached();
9309 write_fp_sreg(s
, rd
, tcg_rd
);
9310 tcg_temp_free_i32(tcg_rd
);
9311 tcg_temp_free_i32(tcg_rn
);
9315 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9316 tcg_temp_free_i32(tcg_rmode
);
9317 tcg_temp_free_ptr(tcg_fpstatus
);
9321 static void gen_ssra8_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9323 tcg_gen_vec_sar8i_i64(a
, a
, shift
);
9324 tcg_gen_vec_add8_i64(d
, d
, a
);
9327 static void gen_ssra16_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9329 tcg_gen_vec_sar16i_i64(a
, a
, shift
);
9330 tcg_gen_vec_add16_i64(d
, d
, a
);
9333 static void gen_ssra32_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9335 tcg_gen_sari_i32(a
, a
, shift
);
9336 tcg_gen_add_i32(d
, d
, a
);
9339 static void gen_ssra64_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9341 tcg_gen_sari_i64(a
, a
, shift
);
9342 tcg_gen_add_i64(d
, d
, a
);
9345 static void gen_ssra_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9347 tcg_gen_sari_vec(vece
, a
, a
, sh
);
9348 tcg_gen_add_vec(vece
, d
, d
, a
);
9351 static void gen_usra8_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9353 tcg_gen_vec_shr8i_i64(a
, a
, shift
);
9354 tcg_gen_vec_add8_i64(d
, d
, a
);
9357 static void gen_usra16_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9359 tcg_gen_vec_shr16i_i64(a
, a
, shift
);
9360 tcg_gen_vec_add16_i64(d
, d
, a
);
9363 static void gen_usra32_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9365 tcg_gen_shri_i32(a
, a
, shift
);
9366 tcg_gen_add_i32(d
, d
, a
);
9369 static void gen_usra64_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9371 tcg_gen_shri_i64(a
, a
, shift
);
9372 tcg_gen_add_i64(d
, d
, a
);
9375 static void gen_usra_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9377 tcg_gen_shri_vec(vece
, a
, a
, sh
);
9378 tcg_gen_add_vec(vece
, d
, d
, a
);
9381 static void gen_shr8_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9383 uint64_t mask
= dup_const(MO_8
, 0xff >> shift
);
9384 TCGv_i64 t
= tcg_temp_new_i64();
9386 tcg_gen_shri_i64(t
, a
, shift
);
9387 tcg_gen_andi_i64(t
, t
, mask
);
9388 tcg_gen_andi_i64(d
, d
, ~mask
);
9389 tcg_gen_or_i64(d
, d
, t
);
9390 tcg_temp_free_i64(t
);
9393 static void gen_shr16_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9395 uint64_t mask
= dup_const(MO_16
, 0xffff >> shift
);
9396 TCGv_i64 t
= tcg_temp_new_i64();
9398 tcg_gen_shri_i64(t
, a
, shift
);
9399 tcg_gen_andi_i64(t
, t
, mask
);
9400 tcg_gen_andi_i64(d
, d
, ~mask
);
9401 tcg_gen_or_i64(d
, d
, t
);
9402 tcg_temp_free_i64(t
);
9405 static void gen_shr32_ins_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9407 tcg_gen_shri_i32(a
, a
, shift
);
9408 tcg_gen_deposit_i32(d
, d
, a
, 0, 32 - shift
);
9411 static void gen_shr64_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9413 tcg_gen_shri_i64(a
, a
, shift
);
9414 tcg_gen_deposit_i64(d
, d
, a
, 0, 64 - shift
);
9417 static void gen_shr_ins_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9419 uint64_t mask
= (2ull << ((8 << vece
) - 1)) - 1;
9420 TCGv_vec t
= tcg_temp_new_vec_matching(d
);
9421 TCGv_vec m
= tcg_temp_new_vec_matching(d
);
9423 tcg_gen_dupi_vec(vece
, m
, mask
^ (mask
>> sh
));
9424 tcg_gen_shri_vec(vece
, t
, a
, sh
);
9425 tcg_gen_and_vec(vece
, d
, d
, m
);
9426 tcg_gen_or_vec(vece
, d
, d
, t
);
9428 tcg_temp_free_vec(t
);
9429 tcg_temp_free_vec(m
);
9432 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
9433 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
9434 int immh
, int immb
, int opcode
, int rn
, int rd
)
9436 static const GVecGen2i ssra_op
[4] = {
9437 { .fni8
= gen_ssra8_i64
,
9438 .fniv
= gen_ssra_vec
,
9440 .opc
= INDEX_op_sari_vec
,
9442 { .fni8
= gen_ssra16_i64
,
9443 .fniv
= gen_ssra_vec
,
9445 .opc
= INDEX_op_sari_vec
,
9447 { .fni4
= gen_ssra32_i32
,
9448 .fniv
= gen_ssra_vec
,
9450 .opc
= INDEX_op_sari_vec
,
9452 { .fni8
= gen_ssra64_i64
,
9453 .fniv
= gen_ssra_vec
,
9454 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9456 .opc
= INDEX_op_sari_vec
,
9459 static const GVecGen2i usra_op
[4] = {
9460 { .fni8
= gen_usra8_i64
,
9461 .fniv
= gen_usra_vec
,
9463 .opc
= INDEX_op_shri_vec
,
9465 { .fni8
= gen_usra16_i64
,
9466 .fniv
= gen_usra_vec
,
9468 .opc
= INDEX_op_shri_vec
,
9470 { .fni4
= gen_usra32_i32
,
9471 .fniv
= gen_usra_vec
,
9473 .opc
= INDEX_op_shri_vec
,
9475 { .fni8
= gen_usra64_i64
,
9476 .fniv
= gen_usra_vec
,
9477 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9479 .opc
= INDEX_op_shri_vec
,
9482 static const GVecGen2i sri_op
[4] = {
9483 { .fni8
= gen_shr8_ins_i64
,
9484 .fniv
= gen_shr_ins_vec
,
9486 .opc
= INDEX_op_shri_vec
,
9488 { .fni8
= gen_shr16_ins_i64
,
9489 .fniv
= gen_shr_ins_vec
,
9491 .opc
= INDEX_op_shri_vec
,
9493 { .fni4
= gen_shr32_ins_i32
,
9494 .fniv
= gen_shr_ins_vec
,
9496 .opc
= INDEX_op_shri_vec
,
9498 { .fni8
= gen_shr64_ins_i64
,
9499 .fniv
= gen_shr_ins_vec
,
9500 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9502 .opc
= INDEX_op_shri_vec
,
9506 int size
= 32 - clz32(immh
) - 1;
9507 int immhb
= immh
<< 3 | immb
;
9508 int shift
= 2 * (8 << size
) - immhb
;
9509 bool accumulate
= false;
9510 int dsize
= is_q
? 128 : 64;
9511 int esize
= 8 << size
;
9512 int elements
= dsize
/esize
;
9513 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
9514 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
9515 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
9517 uint64_t round_const
;
9520 if (extract32(immh
, 3, 1) && !is_q
) {
9521 unallocated_encoding(s
);
9524 tcg_debug_assert(size
<= 3);
9526 if (!fp_access_check(s
)) {
9531 case 0x02: /* SSRA / USRA (accumulate) */
9533 /* Shift count same as element size produces zero to add. */
9534 if (shift
== 8 << size
) {
9537 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &usra_op
[size
]);
9539 /* Shift count same as element size produces all sign to add. */
9540 if (shift
== 8 << size
) {
9543 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &ssra_op
[size
]);
9546 case 0x08: /* SRI */
9547 /* Shift count same as element size is valid but does nothing. */
9548 if (shift
== 8 << size
) {
9551 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &sri_op
[size
]);
9554 case 0x00: /* SSHR / USHR */
9556 if (shift
== 8 << size
) {
9557 /* Shift count the same size as element size produces zero. */
9558 tcg_gen_gvec_dup8i(vec_full_reg_offset(s
, rd
),
9559 is_q
? 16 : 8, vec_full_reg_size(s
), 0);
9561 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shri
, size
);
9564 /* Shift count the same size as element size produces all sign. */
9565 if (shift
== 8 << size
) {
9568 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_sari
, size
);
9572 case 0x04: /* SRSHR / URSHR (rounding) */
9574 case 0x06: /* SRSRA / URSRA (accum + rounding) */
9578 g_assert_not_reached();
9581 round_const
= 1ULL << (shift
- 1);
9582 tcg_round
= tcg_const_i64(round_const
);
9584 for (i
= 0; i
< elements
; i
++) {
9585 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
9587 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
9590 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
9591 accumulate
, is_u
, size
, shift
);
9593 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
9595 tcg_temp_free_i64(tcg_round
);
9598 clear_vec_high(s
, is_q
, rd
);
9601 static void gen_shl8_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9603 uint64_t mask
= dup_const(MO_8
, 0xff << shift
);
9604 TCGv_i64 t
= tcg_temp_new_i64();
9606 tcg_gen_shli_i64(t
, a
, shift
);
9607 tcg_gen_andi_i64(t
, t
, mask
);
9608 tcg_gen_andi_i64(d
, d
, ~mask
);
9609 tcg_gen_or_i64(d
, d
, t
);
9610 tcg_temp_free_i64(t
);
9613 static void gen_shl16_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9615 uint64_t mask
= dup_const(MO_16
, 0xffff << shift
);
9616 TCGv_i64 t
= tcg_temp_new_i64();
9618 tcg_gen_shli_i64(t
, a
, shift
);
9619 tcg_gen_andi_i64(t
, t
, mask
);
9620 tcg_gen_andi_i64(d
, d
, ~mask
);
9621 tcg_gen_or_i64(d
, d
, t
);
9622 tcg_temp_free_i64(t
);
9625 static void gen_shl32_ins_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9627 tcg_gen_deposit_i32(d
, d
, a
, shift
, 32 - shift
);
9630 static void gen_shl64_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9632 tcg_gen_deposit_i64(d
, d
, a
, shift
, 64 - shift
);
9635 static void gen_shl_ins_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9637 uint64_t mask
= (1ull << sh
) - 1;
9638 TCGv_vec t
= tcg_temp_new_vec_matching(d
);
9639 TCGv_vec m
= tcg_temp_new_vec_matching(d
);
9641 tcg_gen_dupi_vec(vece
, m
, mask
);
9642 tcg_gen_shli_vec(vece
, t
, a
, sh
);
9643 tcg_gen_and_vec(vece
, d
, d
, m
);
9644 tcg_gen_or_vec(vece
, d
, d
, t
);
9646 tcg_temp_free_vec(t
);
9647 tcg_temp_free_vec(m
);
9650 /* SHL/SLI - Vector shift left */
9651 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
9652 int immh
, int immb
, int opcode
, int rn
, int rd
)
9654 static const GVecGen2i shi_op
[4] = {
9655 { .fni8
= gen_shl8_ins_i64
,
9656 .fniv
= gen_shl_ins_vec
,
9657 .opc
= INDEX_op_shli_vec
,
9658 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9661 { .fni8
= gen_shl16_ins_i64
,
9662 .fniv
= gen_shl_ins_vec
,
9663 .opc
= INDEX_op_shli_vec
,
9664 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9667 { .fni4
= gen_shl32_ins_i32
,
9668 .fniv
= gen_shl_ins_vec
,
9669 .opc
= INDEX_op_shli_vec
,
9670 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9673 { .fni8
= gen_shl64_ins_i64
,
9674 .fniv
= gen_shl_ins_vec
,
9675 .opc
= INDEX_op_shli_vec
,
9676 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9680 int size
= 32 - clz32(immh
) - 1;
9681 int immhb
= immh
<< 3 | immb
;
9682 int shift
= immhb
- (8 << size
);
9684 if (extract32(immh
, 3, 1) && !is_q
) {
9685 unallocated_encoding(s
);
9689 if (size
> 3 && !is_q
) {
9690 unallocated_encoding(s
);
9694 if (!fp_access_check(s
)) {
9699 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &shi_op
[size
]);
9701 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shli
, size
);
9705 /* USHLL/SHLL - Vector shift left with widening */
9706 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
9707 int immh
, int immb
, int opcode
, int rn
, int rd
)
9709 int size
= 32 - clz32(immh
) - 1;
9710 int immhb
= immh
<< 3 | immb
;
9711 int shift
= immhb
- (8 << size
);
9713 int esize
= 8 << size
;
9714 int elements
= dsize
/esize
;
9715 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
9716 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
9720 unallocated_encoding(s
);
9724 if (!fp_access_check(s
)) {
9728 /* For the LL variants the store is larger than the load,
9729 * so if rd == rn we would overwrite parts of our input.
9730 * So load everything right now and use shifts in the main loop.
9732 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
9734 for (i
= 0; i
< elements
; i
++) {
9735 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
9736 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
9737 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
9738 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
9742 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
9743 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
9744 int immh
, int immb
, int opcode
, int rn
, int rd
)
9746 int immhb
= immh
<< 3 | immb
;
9747 int size
= 32 - clz32(immh
) - 1;
9749 int esize
= 8 << size
;
9750 int elements
= dsize
/esize
;
9751 int shift
= (2 * esize
) - immhb
;
9752 bool round
= extract32(opcode
, 0, 1);
9753 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
9757 if (extract32(immh
, 3, 1)) {
9758 unallocated_encoding(s
);
9762 if (!fp_access_check(s
)) {
9766 tcg_rn
= tcg_temp_new_i64();
9767 tcg_rd
= tcg_temp_new_i64();
9768 tcg_final
= tcg_temp_new_i64();
9769 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
9772 uint64_t round_const
= 1ULL << (shift
- 1);
9773 tcg_round
= tcg_const_i64(round_const
);
9778 for (i
= 0; i
< elements
; i
++) {
9779 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
9780 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
9781 false, true, size
+1, shift
);
9783 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
9787 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
9789 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
9792 tcg_temp_free_i64(tcg_round
);
9794 tcg_temp_free_i64(tcg_rn
);
9795 tcg_temp_free_i64(tcg_rd
);
9796 tcg_temp_free_i64(tcg_final
);
9798 clear_vec_high(s
, is_q
, rd
);
9802 /* AdvSIMD shift by immediate
9803 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
9804 * +---+---+---+-------------+------+------+--------+---+------+------+
9805 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
9806 * +---+---+---+-------------+------+------+--------+---+------+------+
9808 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
9810 int rd
= extract32(insn
, 0, 5);
9811 int rn
= extract32(insn
, 5, 5);
9812 int opcode
= extract32(insn
, 11, 5);
9813 int immb
= extract32(insn
, 16, 3);
9814 int immh
= extract32(insn
, 19, 4);
9815 bool is_u
= extract32(insn
, 29, 1);
9816 bool is_q
= extract32(insn
, 30, 1);
9819 case 0x08: /* SRI */
9821 unallocated_encoding(s
);
9825 case 0x00: /* SSHR / USHR */
9826 case 0x02: /* SSRA / USRA (accumulate) */
9827 case 0x04: /* SRSHR / URSHR (rounding) */
9828 case 0x06: /* SRSRA / URSRA (accum + rounding) */
9829 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9831 case 0x0a: /* SHL / SLI */
9832 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9834 case 0x10: /* SHRN */
9835 case 0x11: /* RSHRN / SQRSHRUN */
9837 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
9840 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
9843 case 0x12: /* SQSHRN / UQSHRN */
9844 case 0x13: /* SQRSHRN / UQRSHRN */
9845 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
9848 case 0x14: /* SSHLL / USHLL */
9849 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9851 case 0x1c: /* SCVTF / UCVTF */
9852 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
9855 case 0xc: /* SQSHLU */
9857 unallocated_encoding(s
);
9860 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
9862 case 0xe: /* SQSHL, UQSHL */
9863 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
9865 case 0x1f: /* FCVTZS/ FCVTZU */
9866 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
9869 unallocated_encoding(s
);
9874 /* Generate code to do a "long" addition or subtraction, ie one done in
9875 * TCGv_i64 on vector lanes twice the width specified by size.
9877 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
9878 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
9880 static NeonGenTwo64OpFn
* const fns
[3][2] = {
9881 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
9882 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
9883 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
9885 NeonGenTwo64OpFn
*genfn
;
9888 genfn
= fns
[size
][is_sub
];
9889 genfn(tcg_res
, tcg_op1
, tcg_op2
);
9892 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
9893 int opcode
, int rd
, int rn
, int rm
)
9895 /* 3-reg-different widening insns: 64 x 64 -> 128 */
9896 TCGv_i64 tcg_res
[2];
9899 tcg_res
[0] = tcg_temp_new_i64();
9900 tcg_res
[1] = tcg_temp_new_i64();
9902 /* Does this op do an adding accumulate, a subtracting accumulate,
9903 * or no accumulate at all?
9921 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
9922 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
9925 /* size == 2 means two 32x32->64 operations; this is worth special
9926 * casing because we can generally handle it inline.
9929 for (pass
= 0; pass
< 2; pass
++) {
9930 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9931 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9932 TCGv_i64 tcg_passres
;
9933 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
9935 int elt
= pass
+ is_q
* 2;
9937 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
9938 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
9941 tcg_passres
= tcg_res
[pass
];
9943 tcg_passres
= tcg_temp_new_i64();
9947 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
9948 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
9950 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
9951 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
9953 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
9954 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
9956 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
9957 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
9959 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
9960 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
9961 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
9963 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
9964 tcg_temp_free_i64(tcg_tmp1
);
9965 tcg_temp_free_i64(tcg_tmp2
);
9968 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
9969 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
9970 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
9971 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
9973 case 9: /* SQDMLAL, SQDMLAL2 */
9974 case 11: /* SQDMLSL, SQDMLSL2 */
9975 case 13: /* SQDMULL, SQDMULL2 */
9976 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
9977 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
9978 tcg_passres
, tcg_passres
);
9981 g_assert_not_reached();
9984 if (opcode
== 9 || opcode
== 11) {
9985 /* saturating accumulate ops */
9987 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
9989 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
9990 tcg_res
[pass
], tcg_passres
);
9991 } else if (accop
> 0) {
9992 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
9993 } else if (accop
< 0) {
9994 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
9998 tcg_temp_free_i64(tcg_passres
);
10001 tcg_temp_free_i64(tcg_op1
);
10002 tcg_temp_free_i64(tcg_op2
);
10005 /* size 0 or 1, generally helper functions */
10006 for (pass
= 0; pass
< 2; pass
++) {
10007 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10008 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10009 TCGv_i64 tcg_passres
;
10010 int elt
= pass
+ is_q
* 2;
10012 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
10013 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
10016 tcg_passres
= tcg_res
[pass
];
10018 tcg_passres
= tcg_temp_new_i64();
10022 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10023 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10025 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
10026 static NeonGenWidenFn
* const widenfns
[2][2] = {
10027 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10028 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10030 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10032 widenfn(tcg_op2_64
, tcg_op2
);
10033 widenfn(tcg_passres
, tcg_op1
);
10034 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
10035 tcg_passres
, tcg_op2_64
);
10036 tcg_temp_free_i64(tcg_op2_64
);
10039 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10040 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10043 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10045 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10049 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
10051 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
10055 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10056 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10057 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10060 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
10062 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
10066 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10068 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10072 case 9: /* SQDMLAL, SQDMLAL2 */
10073 case 11: /* SQDMLSL, SQDMLSL2 */
10074 case 13: /* SQDMULL, SQDMULL2 */
10076 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10077 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10078 tcg_passres
, tcg_passres
);
10080 case 14: /* PMULL */
10082 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
10085 g_assert_not_reached();
10087 tcg_temp_free_i32(tcg_op1
);
10088 tcg_temp_free_i32(tcg_op2
);
10091 if (opcode
== 9 || opcode
== 11) {
10092 /* saturating accumulate ops */
10094 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10096 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10100 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
10101 tcg_res
[pass
], tcg_passres
);
10103 tcg_temp_free_i64(tcg_passres
);
10108 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10109 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10110 tcg_temp_free_i64(tcg_res
[0]);
10111 tcg_temp_free_i64(tcg_res
[1]);
10114 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
10115 int opcode
, int rd
, int rn
, int rm
)
10117 TCGv_i64 tcg_res
[2];
10118 int part
= is_q
? 2 : 0;
10121 for (pass
= 0; pass
< 2; pass
++) {
10122 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10123 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10124 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
10125 static NeonGenWidenFn
* const widenfns
[3][2] = {
10126 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10127 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10128 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
10130 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10132 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10133 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
10134 widenfn(tcg_op2_wide
, tcg_op2
);
10135 tcg_temp_free_i32(tcg_op2
);
10136 tcg_res
[pass
] = tcg_temp_new_i64();
10137 gen_neon_addl(size
, (opcode
== 3),
10138 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
10139 tcg_temp_free_i64(tcg_op1
);
10140 tcg_temp_free_i64(tcg_op2_wide
);
10143 for (pass
= 0; pass
< 2; pass
++) {
10144 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10145 tcg_temp_free_i64(tcg_res
[pass
]);
10149 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
10151 tcg_gen_addi_i64(in
, in
, 1U << 31);
10152 tcg_gen_extrh_i64_i32(res
, in
);
10155 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
10156 int opcode
, int rd
, int rn
, int rm
)
10158 TCGv_i32 tcg_res
[2];
10159 int part
= is_q
? 2 : 0;
10162 for (pass
= 0; pass
< 2; pass
++) {
10163 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10164 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10165 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
10166 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
10167 { gen_helper_neon_narrow_high_u8
,
10168 gen_helper_neon_narrow_round_high_u8
},
10169 { gen_helper_neon_narrow_high_u16
,
10170 gen_helper_neon_narrow_round_high_u16
},
10171 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
10173 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
10175 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10176 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
10178 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
10180 tcg_temp_free_i64(tcg_op1
);
10181 tcg_temp_free_i64(tcg_op2
);
10183 tcg_res
[pass
] = tcg_temp_new_i32();
10184 gennarrow(tcg_res
[pass
], tcg_wideres
);
10185 tcg_temp_free_i64(tcg_wideres
);
10188 for (pass
= 0; pass
< 2; pass
++) {
10189 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
10190 tcg_temp_free_i32(tcg_res
[pass
]);
10192 clear_vec_high(s
, is_q
, rd
);
10195 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
10197 /* PMULL of 64 x 64 -> 128 is an odd special case because it
10198 * is the only three-reg-diff instruction which produces a
10199 * 128-bit wide result from a single operation. However since
10200 * it's possible to calculate the two halves more or less
10201 * separately we just use two helper calls.
10203 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10204 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10205 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10207 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
10208 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
10209 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
10210 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
10211 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
10212 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
10214 tcg_temp_free_i64(tcg_op1
);
10215 tcg_temp_free_i64(tcg_op2
);
10216 tcg_temp_free_i64(tcg_res
);
10219 /* AdvSIMD three different
10220 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
10221 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10222 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
10223 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10225 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
10227 /* Instructions in this group fall into three basic classes
10228 * (in each case with the operation working on each element in
10229 * the input vectors):
10230 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
10232 * (2) wide 64 x 128 -> 128
10233 * (3) narrowing 128 x 128 -> 64
10234 * Here we do initial decode, catch unallocated cases and
10235 * dispatch to separate functions for each class.
10237 int is_q
= extract32(insn
, 30, 1);
10238 int is_u
= extract32(insn
, 29, 1);
10239 int size
= extract32(insn
, 22, 2);
10240 int opcode
= extract32(insn
, 12, 4);
10241 int rm
= extract32(insn
, 16, 5);
10242 int rn
= extract32(insn
, 5, 5);
10243 int rd
= extract32(insn
, 0, 5);
10246 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
10247 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
10248 /* 64 x 128 -> 128 */
10250 unallocated_encoding(s
);
10253 if (!fp_access_check(s
)) {
10256 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10258 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
10259 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
10260 /* 128 x 128 -> 64 */
10262 unallocated_encoding(s
);
10265 if (!fp_access_check(s
)) {
10268 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10270 case 14: /* PMULL, PMULL2 */
10271 if (is_u
|| size
== 1 || size
== 2) {
10272 unallocated_encoding(s
);
10276 if (!arm_dc_feature(s
, ARM_FEATURE_V8_PMULL
)) {
10277 unallocated_encoding(s
);
10280 if (!fp_access_check(s
)) {
10283 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
10287 case 9: /* SQDMLAL, SQDMLAL2 */
10288 case 11: /* SQDMLSL, SQDMLSL2 */
10289 case 13: /* SQDMULL, SQDMULL2 */
10290 if (is_u
|| size
== 0) {
10291 unallocated_encoding(s
);
10295 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10296 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10297 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10298 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10299 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10300 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10301 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
10302 /* 64 x 64 -> 128 */
10304 unallocated_encoding(s
);
10308 if (!fp_access_check(s
)) {
10312 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10315 /* opcode 15 not allocated */
10316 unallocated_encoding(s
);
10321 static void gen_bsl_i64(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
10323 tcg_gen_xor_i64(rn
, rn
, rm
);
10324 tcg_gen_and_i64(rn
, rn
, rd
);
10325 tcg_gen_xor_i64(rd
, rm
, rn
);
10328 static void gen_bit_i64(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
10330 tcg_gen_xor_i64(rn
, rn
, rd
);
10331 tcg_gen_and_i64(rn
, rn
, rm
);
10332 tcg_gen_xor_i64(rd
, rd
, rn
);
10335 static void gen_bif_i64(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
10337 tcg_gen_xor_i64(rn
, rn
, rd
);
10338 tcg_gen_andc_i64(rn
, rn
, rm
);
10339 tcg_gen_xor_i64(rd
, rd
, rn
);
10342 static void gen_bsl_vec(unsigned vece
, TCGv_vec rd
, TCGv_vec rn
, TCGv_vec rm
)
10344 tcg_gen_xor_vec(vece
, rn
, rn
, rm
);
10345 tcg_gen_and_vec(vece
, rn
, rn
, rd
);
10346 tcg_gen_xor_vec(vece
, rd
, rm
, rn
);
10349 static void gen_bit_vec(unsigned vece
, TCGv_vec rd
, TCGv_vec rn
, TCGv_vec rm
)
10351 tcg_gen_xor_vec(vece
, rn
, rn
, rd
);
10352 tcg_gen_and_vec(vece
, rn
, rn
, rm
);
10353 tcg_gen_xor_vec(vece
, rd
, rd
, rn
);
10356 static void gen_bif_vec(unsigned vece
, TCGv_vec rd
, TCGv_vec rn
, TCGv_vec rm
)
10358 tcg_gen_xor_vec(vece
, rn
, rn
, rd
);
10359 tcg_gen_andc_vec(vece
, rn
, rn
, rm
);
10360 tcg_gen_xor_vec(vece
, rd
, rd
, rn
);
10363 /* Logic op (opcode == 3) subgroup of C3.6.16. */
10364 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
10366 static const GVecGen3 bsl_op
= {
10367 .fni8
= gen_bsl_i64
,
10368 .fniv
= gen_bsl_vec
,
10369 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10372 static const GVecGen3 bit_op
= {
10373 .fni8
= gen_bit_i64
,
10374 .fniv
= gen_bit_vec
,
10375 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10378 static const GVecGen3 bif_op
= {
10379 .fni8
= gen_bif_i64
,
10380 .fniv
= gen_bif_vec
,
10381 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10385 int rd
= extract32(insn
, 0, 5);
10386 int rn
= extract32(insn
, 5, 5);
10387 int rm
= extract32(insn
, 16, 5);
10388 int size
= extract32(insn
, 22, 2);
10389 bool is_u
= extract32(insn
, 29, 1);
10390 bool is_q
= extract32(insn
, 30, 1);
10392 if (!fp_access_check(s
)) {
10396 switch (size
+ 4 * is_u
) {
10398 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_and
, 0);
10401 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_andc
, 0);
10404 if (rn
== rm
) { /* MOV */
10405 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_mov
, 0);
10407 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_or
, 0);
10411 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_orc
, 0);
10414 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_xor
, 0);
10417 case 5: /* BSL bitwise select */
10418 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bsl_op
);
10420 case 6: /* BIT, bitwise insert if true */
10421 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bit_op
);
10423 case 7: /* BIF, bitwise insert if false */
10424 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bif_op
);
10428 g_assert_not_reached();
10432 /* Pairwise op subgroup of C3.6.16.
10434 * This is called directly or via the handle_3same_float for float pairwise
10435 * operations where the opcode and size are calculated differently.
10437 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
10438 int size
, int rn
, int rm
, int rd
)
10443 /* Floating point operations need fpst */
10444 if (opcode
>= 0x58) {
10445 fpst
= get_fpstatus_ptr(false);
10450 if (!fp_access_check(s
)) {
10454 /* These operations work on the concatenated rm:rn, with each pair of
10455 * adjacent elements being operated on to produce an element in the result.
10458 TCGv_i64 tcg_res
[2];
10460 for (pass
= 0; pass
< 2; pass
++) {
10461 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10462 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10463 int passreg
= (pass
== 0) ? rn
: rm
;
10465 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
10466 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
10467 tcg_res
[pass
] = tcg_temp_new_i64();
10470 case 0x17: /* ADDP */
10471 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10473 case 0x58: /* FMAXNMP */
10474 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10476 case 0x5a: /* FADDP */
10477 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10479 case 0x5e: /* FMAXP */
10480 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10482 case 0x78: /* FMINNMP */
10483 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10485 case 0x7e: /* FMINP */
10486 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10489 g_assert_not_reached();
10492 tcg_temp_free_i64(tcg_op1
);
10493 tcg_temp_free_i64(tcg_op2
);
10496 for (pass
= 0; pass
< 2; pass
++) {
10497 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10498 tcg_temp_free_i64(tcg_res
[pass
]);
10501 int maxpass
= is_q
? 4 : 2;
10502 TCGv_i32 tcg_res
[4];
10504 for (pass
= 0; pass
< maxpass
; pass
++) {
10505 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10506 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10507 NeonGenTwoOpFn
*genfn
= NULL
;
10508 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
10509 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
10511 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
10512 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
10513 tcg_res
[pass
] = tcg_temp_new_i32();
10516 case 0x17: /* ADDP */
10518 static NeonGenTwoOpFn
* const fns
[3] = {
10519 gen_helper_neon_padd_u8
,
10520 gen_helper_neon_padd_u16
,
10526 case 0x14: /* SMAXP, UMAXP */
10528 static NeonGenTwoOpFn
* const fns
[3][2] = {
10529 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
10530 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
10531 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
10533 genfn
= fns
[size
][u
];
10536 case 0x15: /* SMINP, UMINP */
10538 static NeonGenTwoOpFn
* const fns
[3][2] = {
10539 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
10540 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
10541 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
10543 genfn
= fns
[size
][u
];
10546 /* The FP operations are all on single floats (32 bit) */
10547 case 0x58: /* FMAXNMP */
10548 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10550 case 0x5a: /* FADDP */
10551 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10553 case 0x5e: /* FMAXP */
10554 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10556 case 0x78: /* FMINNMP */
10557 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10559 case 0x7e: /* FMINP */
10560 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10563 g_assert_not_reached();
10566 /* FP ops called directly, otherwise call now */
10568 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10571 tcg_temp_free_i32(tcg_op1
);
10572 tcg_temp_free_i32(tcg_op2
);
10575 for (pass
= 0; pass
< maxpass
; pass
++) {
10576 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
10577 tcg_temp_free_i32(tcg_res
[pass
]);
10579 clear_vec_high(s
, is_q
, rd
);
10583 tcg_temp_free_ptr(fpst
);
10587 /* Floating point op subgroup of C3.6.16. */
10588 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
10590 /* For floating point ops, the U, size[1] and opcode bits
10591 * together indicate the operation. size[0] indicates single
10594 int fpopcode
= extract32(insn
, 11, 5)
10595 | (extract32(insn
, 23, 1) << 5)
10596 | (extract32(insn
, 29, 1) << 6);
10597 int is_q
= extract32(insn
, 30, 1);
10598 int size
= extract32(insn
, 22, 1);
10599 int rm
= extract32(insn
, 16, 5);
10600 int rn
= extract32(insn
, 5, 5);
10601 int rd
= extract32(insn
, 0, 5);
10603 int datasize
= is_q
? 128 : 64;
10604 int esize
= 32 << size
;
10605 int elements
= datasize
/ esize
;
10607 if (size
== 1 && !is_q
) {
10608 unallocated_encoding(s
);
10612 switch (fpopcode
) {
10613 case 0x58: /* FMAXNMP */
10614 case 0x5a: /* FADDP */
10615 case 0x5e: /* FMAXP */
10616 case 0x78: /* FMINNMP */
10617 case 0x7e: /* FMINP */
10618 if (size
&& !is_q
) {
10619 unallocated_encoding(s
);
10622 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
10625 case 0x1b: /* FMULX */
10626 case 0x1f: /* FRECPS */
10627 case 0x3f: /* FRSQRTS */
10628 case 0x5d: /* FACGE */
10629 case 0x7d: /* FACGT */
10630 case 0x19: /* FMLA */
10631 case 0x39: /* FMLS */
10632 case 0x18: /* FMAXNM */
10633 case 0x1a: /* FADD */
10634 case 0x1c: /* FCMEQ */
10635 case 0x1e: /* FMAX */
10636 case 0x38: /* FMINNM */
10637 case 0x3a: /* FSUB */
10638 case 0x3e: /* FMIN */
10639 case 0x5b: /* FMUL */
10640 case 0x5c: /* FCMGE */
10641 case 0x5f: /* FDIV */
10642 case 0x7a: /* FABD */
10643 case 0x7c: /* FCMGT */
10644 if (!fp_access_check(s
)) {
10648 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
10651 unallocated_encoding(s
);
10656 static void gen_mla8_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10658 gen_helper_neon_mul_u8(a
, a
, b
);
10659 gen_helper_neon_add_u8(d
, d
, a
);
10662 static void gen_mla16_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10664 gen_helper_neon_mul_u16(a
, a
, b
);
10665 gen_helper_neon_add_u16(d
, d
, a
);
10668 static void gen_mla32_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10670 tcg_gen_mul_i32(a
, a
, b
);
10671 tcg_gen_add_i32(d
, d
, a
);
10674 static void gen_mla64_i64(TCGv_i64 d
, TCGv_i64 a
, TCGv_i64 b
)
10676 tcg_gen_mul_i64(a
, a
, b
);
10677 tcg_gen_add_i64(d
, d
, a
);
10680 static void gen_mla_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, TCGv_vec b
)
10682 tcg_gen_mul_vec(vece
, a
, a
, b
);
10683 tcg_gen_add_vec(vece
, d
, d
, a
);
10686 static void gen_mls8_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10688 gen_helper_neon_mul_u8(a
, a
, b
);
10689 gen_helper_neon_sub_u8(d
, d
, a
);
10692 static void gen_mls16_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10694 gen_helper_neon_mul_u16(a
, a
, b
);
10695 gen_helper_neon_sub_u16(d
, d
, a
);
10698 static void gen_mls32_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10700 tcg_gen_mul_i32(a
, a
, b
);
10701 tcg_gen_sub_i32(d
, d
, a
);
10704 static void gen_mls64_i64(TCGv_i64 d
, TCGv_i64 a
, TCGv_i64 b
)
10706 tcg_gen_mul_i64(a
, a
, b
);
10707 tcg_gen_sub_i64(d
, d
, a
);
10710 static void gen_mls_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, TCGv_vec b
)
10712 tcg_gen_mul_vec(vece
, a
, a
, b
);
10713 tcg_gen_sub_vec(vece
, d
, d
, a
);
10716 /* Integer op subgroup of C3.6.16. */
10717 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
10719 static const GVecGen3 cmtst_op
[4] = {
10720 { .fni4
= gen_helper_neon_tst_u8
,
10721 .fniv
= gen_cmtst_vec
,
10723 { .fni4
= gen_helper_neon_tst_u16
,
10724 .fniv
= gen_cmtst_vec
,
10726 { .fni4
= gen_cmtst_i32
,
10727 .fniv
= gen_cmtst_vec
,
10729 { .fni8
= gen_cmtst_i64
,
10730 .fniv
= gen_cmtst_vec
,
10731 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10734 static const GVecGen3 mla_op
[4] = {
10735 { .fni4
= gen_mla8_i32
,
10736 .fniv
= gen_mla_vec
,
10737 .opc
= INDEX_op_mul_vec
,
10740 { .fni4
= gen_mla16_i32
,
10741 .fniv
= gen_mla_vec
,
10742 .opc
= INDEX_op_mul_vec
,
10745 { .fni4
= gen_mla32_i32
,
10746 .fniv
= gen_mla_vec
,
10747 .opc
= INDEX_op_mul_vec
,
10750 { .fni8
= gen_mla64_i64
,
10751 .fniv
= gen_mla_vec
,
10752 .opc
= INDEX_op_mul_vec
,
10753 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10757 static const GVecGen3 mls_op
[4] = {
10758 { .fni4
= gen_mls8_i32
,
10759 .fniv
= gen_mls_vec
,
10760 .opc
= INDEX_op_mul_vec
,
10763 { .fni4
= gen_mls16_i32
,
10764 .fniv
= gen_mls_vec
,
10765 .opc
= INDEX_op_mul_vec
,
10768 { .fni4
= gen_mls32_i32
,
10769 .fniv
= gen_mls_vec
,
10770 .opc
= INDEX_op_mul_vec
,
10773 { .fni8
= gen_mls64_i64
,
10774 .fniv
= gen_mls_vec
,
10775 .opc
= INDEX_op_mul_vec
,
10776 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10781 int is_q
= extract32(insn
, 30, 1);
10782 int u
= extract32(insn
, 29, 1);
10783 int size
= extract32(insn
, 22, 2);
10784 int opcode
= extract32(insn
, 11, 5);
10785 int rm
= extract32(insn
, 16, 5);
10786 int rn
= extract32(insn
, 5, 5);
10787 int rd
= extract32(insn
, 0, 5);
10792 case 0x13: /* MUL, PMUL */
10793 if (u
&& size
!= 0) {
10794 unallocated_encoding(s
);
10798 case 0x0: /* SHADD, UHADD */
10799 case 0x2: /* SRHADD, URHADD */
10800 case 0x4: /* SHSUB, UHSUB */
10801 case 0xc: /* SMAX, UMAX */
10802 case 0xd: /* SMIN, UMIN */
10803 case 0xe: /* SABD, UABD */
10804 case 0xf: /* SABA, UABA */
10805 case 0x12: /* MLA, MLS */
10807 unallocated_encoding(s
);
10811 case 0x16: /* SQDMULH, SQRDMULH */
10812 if (size
== 0 || size
== 3) {
10813 unallocated_encoding(s
);
10818 if (size
== 3 && !is_q
) {
10819 unallocated_encoding(s
);
10825 if (!fp_access_check(s
)) {
10830 case 0x10: /* ADD, SUB */
10832 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_sub
, size
);
10834 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_add
, size
);
10837 case 0x13: /* MUL, PMUL */
10838 if (!u
) { /* MUL */
10839 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_mul
, size
);
10843 case 0x12: /* MLA, MLS */
10845 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mls_op
[size
]);
10847 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mla_op
[size
]);
10851 if (!u
) { /* CMTST */
10852 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &cmtst_op
[size
]);
10856 cond
= TCG_COND_EQ
;
10858 case 0x06: /* CMGT, CMHI */
10859 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
10861 case 0x07: /* CMGE, CMHS */
10862 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
10864 tcg_gen_gvec_cmp(cond
, size
, vec_full_reg_offset(s
, rd
),
10865 vec_full_reg_offset(s
, rn
),
10866 vec_full_reg_offset(s
, rm
),
10867 is_q
? 16 : 8, vec_full_reg_size(s
));
10873 for (pass
= 0; pass
< 2; pass
++) {
10874 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10875 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10876 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10878 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10879 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
10881 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
10883 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10885 tcg_temp_free_i64(tcg_res
);
10886 tcg_temp_free_i64(tcg_op1
);
10887 tcg_temp_free_i64(tcg_op2
);
10890 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
10891 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10892 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10893 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10894 NeonGenTwoOpFn
*genfn
= NULL
;
10895 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
10897 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
10898 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
10901 case 0x0: /* SHADD, UHADD */
10903 static NeonGenTwoOpFn
* const fns
[3][2] = {
10904 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
10905 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
10906 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
10908 genfn
= fns
[size
][u
];
10911 case 0x1: /* SQADD, UQADD */
10913 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
10914 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
10915 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
10916 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
10918 genenvfn
= fns
[size
][u
];
10921 case 0x2: /* SRHADD, URHADD */
10923 static NeonGenTwoOpFn
* const fns
[3][2] = {
10924 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
10925 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
10926 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
10928 genfn
= fns
[size
][u
];
10931 case 0x4: /* SHSUB, UHSUB */
10933 static NeonGenTwoOpFn
* const fns
[3][2] = {
10934 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
10935 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
10936 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
10938 genfn
= fns
[size
][u
];
10941 case 0x5: /* SQSUB, UQSUB */
10943 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
10944 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
10945 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
10946 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
10948 genenvfn
= fns
[size
][u
];
10951 case 0x8: /* SSHL, USHL */
10953 static NeonGenTwoOpFn
* const fns
[3][2] = {
10954 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
10955 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
10956 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
10958 genfn
= fns
[size
][u
];
10961 case 0x9: /* SQSHL, UQSHL */
10963 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
10964 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
10965 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
10966 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
10968 genenvfn
= fns
[size
][u
];
10971 case 0xa: /* SRSHL, URSHL */
10973 static NeonGenTwoOpFn
* const fns
[3][2] = {
10974 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
10975 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
10976 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
10978 genfn
= fns
[size
][u
];
10981 case 0xb: /* SQRSHL, UQRSHL */
10983 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
10984 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
10985 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
10986 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
10988 genenvfn
= fns
[size
][u
];
10991 case 0xc: /* SMAX, UMAX */
10993 static NeonGenTwoOpFn
* const fns
[3][2] = {
10994 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
10995 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
10996 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
10998 genfn
= fns
[size
][u
];
11002 case 0xd: /* SMIN, UMIN */
11004 static NeonGenTwoOpFn
* const fns
[3][2] = {
11005 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
11006 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
11007 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
11009 genfn
= fns
[size
][u
];
11012 case 0xe: /* SABD, UABD */
11013 case 0xf: /* SABA, UABA */
11015 static NeonGenTwoOpFn
* const fns
[3][2] = {
11016 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
11017 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
11018 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
11020 genfn
= fns
[size
][u
];
11023 case 0x13: /* MUL, PMUL */
11024 assert(u
); /* PMUL */
11026 genfn
= gen_helper_neon_mul_p8
;
11028 case 0x16: /* SQDMULH, SQRDMULH */
11030 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
11031 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
11032 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
11034 assert(size
== 1 || size
== 2);
11035 genenvfn
= fns
[size
- 1][u
];
11039 g_assert_not_reached();
11043 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
11045 genfn(tcg_res
, tcg_op1
, tcg_op2
);
11048 if (opcode
== 0xf) {
11049 /* SABA, UABA: accumulating ops */
11050 static NeonGenTwoOpFn
* const fns
[3] = {
11051 gen_helper_neon_add_u8
,
11052 gen_helper_neon_add_u16
,
11056 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
11057 fns
[size
](tcg_res
, tcg_op1
, tcg_res
);
11060 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
11062 tcg_temp_free_i32(tcg_res
);
11063 tcg_temp_free_i32(tcg_op1
);
11064 tcg_temp_free_i32(tcg_op2
);
11067 clear_vec_high(s
, is_q
, rd
);
11070 /* AdvSIMD three same
11071 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11072 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11073 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11074 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11076 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
11078 int opcode
= extract32(insn
, 11, 5);
11081 case 0x3: /* logic ops */
11082 disas_simd_3same_logic(s
, insn
);
11084 case 0x17: /* ADDP */
11085 case 0x14: /* SMAXP, UMAXP */
11086 case 0x15: /* SMINP, UMINP */
11088 /* Pairwise operations */
11089 int is_q
= extract32(insn
, 30, 1);
11090 int u
= extract32(insn
, 29, 1);
11091 int size
= extract32(insn
, 22, 2);
11092 int rm
= extract32(insn
, 16, 5);
11093 int rn
= extract32(insn
, 5, 5);
11094 int rd
= extract32(insn
, 0, 5);
11095 if (opcode
== 0x17) {
11096 if (u
|| (size
== 3 && !is_q
)) {
11097 unallocated_encoding(s
);
11102 unallocated_encoding(s
);
11106 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
11109 case 0x18 ... 0x31:
11110 /* floating point ops, sz[1] and U are part of opcode */
11111 disas_simd_3same_float(s
, insn
);
11114 disas_simd_3same_int(s
, insn
);
11120 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11122 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11123 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11124 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11125 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11127 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11128 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11131 static void disas_simd_three_reg_same_fp16(DisasContext
*s
, uint32_t insn
)
11133 int opcode
, fpopcode
;
11134 int is_q
, u
, a
, rm
, rn
, rd
;
11135 int datasize
, elements
;
11138 bool pairwise
= false;
11140 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
11141 unallocated_encoding(s
);
11145 if (!fp_access_check(s
)) {
11149 /* For these floating point ops, the U, a and opcode bits
11150 * together indicate the operation.
11152 opcode
= extract32(insn
, 11, 3);
11153 u
= extract32(insn
, 29, 1);
11154 a
= extract32(insn
, 23, 1);
11155 is_q
= extract32(insn
, 30, 1);
11156 rm
= extract32(insn
, 16, 5);
11157 rn
= extract32(insn
, 5, 5);
11158 rd
= extract32(insn
, 0, 5);
11160 fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
11161 datasize
= is_q
? 128 : 64;
11162 elements
= datasize
/ 16;
11164 switch (fpopcode
) {
11165 case 0x10: /* FMAXNMP */
11166 case 0x12: /* FADDP */
11167 case 0x16: /* FMAXP */
11168 case 0x18: /* FMINNMP */
11169 case 0x1e: /* FMINP */
11174 fpst
= get_fpstatus_ptr(true);
11177 int maxpass
= is_q
? 8 : 4;
11178 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11179 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11180 TCGv_i32 tcg_res
[8];
11182 for (pass
= 0; pass
< maxpass
; pass
++) {
11183 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
11184 int passelt
= (pass
<< 1) & (maxpass
- 1);
11186 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_16
);
11187 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_16
);
11188 tcg_res
[pass
] = tcg_temp_new_i32();
11190 switch (fpopcode
) {
11191 case 0x10: /* FMAXNMP */
11192 gen_helper_advsimd_maxnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11195 case 0x12: /* FADDP */
11196 gen_helper_advsimd_addh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11198 case 0x16: /* FMAXP */
11199 gen_helper_advsimd_maxh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11201 case 0x18: /* FMINNMP */
11202 gen_helper_advsimd_minnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11205 case 0x1e: /* FMINP */
11206 gen_helper_advsimd_minh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11209 g_assert_not_reached();
11213 for (pass
= 0; pass
< maxpass
; pass
++) {
11214 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_16
);
11215 tcg_temp_free_i32(tcg_res
[pass
]);
11218 tcg_temp_free_i32(tcg_op1
);
11219 tcg_temp_free_i32(tcg_op2
);
11222 for (pass
= 0; pass
< elements
; pass
++) {
11223 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11224 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11225 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11227 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_16
);
11228 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_16
);
11230 switch (fpopcode
) {
11231 case 0x0: /* FMAXNM */
11232 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11234 case 0x1: /* FMLA */
11235 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11236 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11239 case 0x2: /* FADD */
11240 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11242 case 0x3: /* FMULX */
11243 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11245 case 0x4: /* FCMEQ */
11246 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11248 case 0x6: /* FMAX */
11249 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11251 case 0x7: /* FRECPS */
11252 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11254 case 0x8: /* FMINNM */
11255 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11257 case 0x9: /* FMLS */
11258 /* As usual for ARM, separate negation for fused multiply-add */
11259 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
11260 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11261 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11264 case 0xa: /* FSUB */
11265 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11267 case 0xe: /* FMIN */
11268 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11270 case 0xf: /* FRSQRTS */
11271 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11273 case 0x13: /* FMUL */
11274 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11276 case 0x14: /* FCMGE */
11277 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11279 case 0x15: /* FACGE */
11280 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11282 case 0x17: /* FDIV */
11283 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11285 case 0x1a: /* FABD */
11286 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11287 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
11289 case 0x1c: /* FCMGT */
11290 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11292 case 0x1d: /* FACGT */
11293 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11296 fprintf(stderr
, "%s: insn %#04x, fpop %#2x @ %#" PRIx64
"\n",
11297 __func__
, insn
, fpopcode
, s
->pc
);
11298 g_assert_not_reached();
11301 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11302 tcg_temp_free_i32(tcg_res
);
11303 tcg_temp_free_i32(tcg_op1
);
11304 tcg_temp_free_i32(tcg_op2
);
11308 tcg_temp_free_ptr(fpst
);
11310 clear_vec_high(s
, is_q
, rd
);
11313 /* AdvSIMD three same extra
11314 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
11315 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11316 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
11317 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11319 static void disas_simd_three_reg_same_extra(DisasContext
*s
, uint32_t insn
)
11321 int rd
= extract32(insn
, 0, 5);
11322 int rn
= extract32(insn
, 5, 5);
11323 int opcode
= extract32(insn
, 11, 4);
11324 int rm
= extract32(insn
, 16, 5);
11325 int size
= extract32(insn
, 22, 2);
11326 bool u
= extract32(insn
, 29, 1);
11327 bool is_q
= extract32(insn
, 30, 1);
11330 switch (u
* 16 + opcode
) {
11331 case 0x10: /* SQRDMLAH (vector) */
11332 case 0x11: /* SQRDMLSH (vector) */
11333 if (size
!= 1 && size
!= 2) {
11334 unallocated_encoding(s
);
11337 feature
= ARM_FEATURE_V8_RDM
;
11339 case 0x8: /* FCMLA, #0 */
11340 case 0x9: /* FCMLA, #90 */
11341 case 0xa: /* FCMLA, #180 */
11342 case 0xb: /* FCMLA, #270 */
11343 case 0xc: /* FCADD, #90 */
11344 case 0xe: /* FCADD, #270 */
11346 || (size
== 1 && !arm_dc_feature(s
, ARM_FEATURE_V8_FP16
))
11347 || (size
== 3 && !is_q
)) {
11348 unallocated_encoding(s
);
11351 feature
= ARM_FEATURE_V8_FCMA
;
11354 unallocated_encoding(s
);
11357 if (!arm_dc_feature(s
, feature
)) {
11358 unallocated_encoding(s
);
11361 if (!fp_access_check(s
)) {
11366 case 0x0: /* SQRDMLAH (vector) */
11369 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s16
);
11372 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s32
);
11375 g_assert_not_reached();
11379 case 0x1: /* SQRDMLSH (vector) */
11382 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s16
);
11385 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s32
);
11388 g_assert_not_reached();
11392 case 0x8: /* FCMLA, #0 */
11393 case 0x9: /* FCMLA, #90 */
11394 case 0xa: /* FCMLA, #180 */
11395 case 0xb: /* FCMLA, #270 */
11396 rot
= extract32(opcode
, 0, 2);
11399 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, true, rot
,
11400 gen_helper_gvec_fcmlah
);
11403 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11404 gen_helper_gvec_fcmlas
);
11407 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11408 gen_helper_gvec_fcmlad
);
11411 g_assert_not_reached();
11415 case 0xc: /* FCADD, #90 */
11416 case 0xe: /* FCADD, #270 */
11417 rot
= extract32(opcode
, 1, 1);
11420 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11421 gen_helper_gvec_fcaddh
);
11424 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11425 gen_helper_gvec_fcadds
);
11428 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11429 gen_helper_gvec_fcaddd
);
11432 g_assert_not_reached();
11437 g_assert_not_reached();
11441 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
11442 int size
, int rn
, int rd
)
11444 /* Handle 2-reg-misc ops which are widening (so each size element
11445 * in the source becomes a 2*size element in the destination.
11446 * The only instruction like this is FCVTL.
11451 /* 32 -> 64 bit fp conversion */
11452 TCGv_i64 tcg_res
[2];
11453 int srcelt
= is_q
? 2 : 0;
11455 for (pass
= 0; pass
< 2; pass
++) {
11456 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11457 tcg_res
[pass
] = tcg_temp_new_i64();
11459 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
11460 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
11461 tcg_temp_free_i32(tcg_op
);
11463 for (pass
= 0; pass
< 2; pass
++) {
11464 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11465 tcg_temp_free_i64(tcg_res
[pass
]);
11468 /* 16 -> 32 bit fp conversion */
11469 int srcelt
= is_q
? 4 : 0;
11470 TCGv_i32 tcg_res
[4];
11471 TCGv_ptr fpst
= get_fpstatus_ptr(false);
11472 TCGv_i32 ahp
= get_ahp_flag();
11474 for (pass
= 0; pass
< 4; pass
++) {
11475 tcg_res
[pass
] = tcg_temp_new_i32();
11477 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
11478 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
11481 for (pass
= 0; pass
< 4; pass
++) {
11482 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
11483 tcg_temp_free_i32(tcg_res
[pass
]);
11486 tcg_temp_free_ptr(fpst
);
11487 tcg_temp_free_i32(ahp
);
11491 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
11492 bool is_q
, int size
, int rn
, int rd
)
11494 int op
= (opcode
<< 1) | u
;
11495 int opsz
= op
+ size
;
11496 int grp_size
= 3 - opsz
;
11497 int dsize
= is_q
? 128 : 64;
11501 unallocated_encoding(s
);
11505 if (!fp_access_check(s
)) {
11510 /* Special case bytes, use bswap op on each group of elements */
11511 int groups
= dsize
/ (8 << grp_size
);
11513 for (i
= 0; i
< groups
; i
++) {
11514 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
11516 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
11517 switch (grp_size
) {
11519 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
11522 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
11525 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
11528 g_assert_not_reached();
11530 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
11531 tcg_temp_free_i64(tcg_tmp
);
11533 clear_vec_high(s
, is_q
, rd
);
11535 int revmask
= (1 << grp_size
) - 1;
11536 int esize
= 8 << size
;
11537 int elements
= dsize
/ esize
;
11538 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
11539 TCGv_i64 tcg_rd
= tcg_const_i64(0);
11540 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
11542 for (i
= 0; i
< elements
; i
++) {
11543 int e_rev
= (i
& 0xf) ^ revmask
;
11544 int off
= e_rev
* esize
;
11545 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
11547 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
11548 tcg_rn
, off
- 64, esize
);
11550 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
11553 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
11554 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
11556 tcg_temp_free_i64(tcg_rd_hi
);
11557 tcg_temp_free_i64(tcg_rd
);
11558 tcg_temp_free_i64(tcg_rn
);
11562 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
11563 bool is_q
, int size
, int rn
, int rd
)
11565 /* Implement the pairwise operations from 2-misc:
11566 * SADDLP, UADDLP, SADALP, UADALP.
11567 * These all add pairs of elements in the input to produce a
11568 * double-width result element in the output (possibly accumulating).
11570 bool accum
= (opcode
== 0x6);
11571 int maxpass
= is_q
? 2 : 1;
11573 TCGv_i64 tcg_res
[2];
11576 /* 32 + 32 -> 64 op */
11577 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
11579 for (pass
= 0; pass
< maxpass
; pass
++) {
11580 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11581 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11583 tcg_res
[pass
] = tcg_temp_new_i64();
11585 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
11586 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
11587 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11589 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
11590 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
11593 tcg_temp_free_i64(tcg_op1
);
11594 tcg_temp_free_i64(tcg_op2
);
11597 for (pass
= 0; pass
< maxpass
; pass
++) {
11598 TCGv_i64 tcg_op
= tcg_temp_new_i64();
11599 NeonGenOneOpFn
*genfn
;
11600 static NeonGenOneOpFn
* const fns
[2][2] = {
11601 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
11602 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
11605 genfn
= fns
[size
][u
];
11607 tcg_res
[pass
] = tcg_temp_new_i64();
11609 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
11610 genfn(tcg_res
[pass
], tcg_op
);
11613 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
11615 gen_helper_neon_addl_u16(tcg_res
[pass
],
11616 tcg_res
[pass
], tcg_op
);
11618 gen_helper_neon_addl_u32(tcg_res
[pass
],
11619 tcg_res
[pass
], tcg_op
);
11622 tcg_temp_free_i64(tcg_op
);
11626 tcg_res
[1] = tcg_const_i64(0);
11628 for (pass
= 0; pass
< 2; pass
++) {
11629 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11630 tcg_temp_free_i64(tcg_res
[pass
]);
11634 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
11636 /* Implement SHLL and SHLL2 */
11638 int part
= is_q
? 2 : 0;
11639 TCGv_i64 tcg_res
[2];
11641 for (pass
= 0; pass
< 2; pass
++) {
11642 static NeonGenWidenFn
* const widenfns
[3] = {
11643 gen_helper_neon_widen_u8
,
11644 gen_helper_neon_widen_u16
,
11645 tcg_gen_extu_i32_i64
,
11647 NeonGenWidenFn
*widenfn
= widenfns
[size
];
11648 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11650 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
11651 tcg_res
[pass
] = tcg_temp_new_i64();
11652 widenfn(tcg_res
[pass
], tcg_op
);
11653 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
11655 tcg_temp_free_i32(tcg_op
);
11658 for (pass
= 0; pass
< 2; pass
++) {
11659 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11660 tcg_temp_free_i64(tcg_res
[pass
]);
11664 /* AdvSIMD two reg misc
11665 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
11666 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11667 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
11668 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11670 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
11672 int size
= extract32(insn
, 22, 2);
11673 int opcode
= extract32(insn
, 12, 5);
11674 bool u
= extract32(insn
, 29, 1);
11675 bool is_q
= extract32(insn
, 30, 1);
11676 int rn
= extract32(insn
, 5, 5);
11677 int rd
= extract32(insn
, 0, 5);
11678 bool need_fpstatus
= false;
11679 bool need_rmode
= false;
11681 TCGv_i32 tcg_rmode
;
11682 TCGv_ptr tcg_fpstatus
;
11685 case 0x0: /* REV64, REV32 */
11686 case 0x1: /* REV16 */
11687 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
11689 case 0x5: /* CNT, NOT, RBIT */
11690 if (u
&& size
== 0) {
11693 } else if (u
&& size
== 1) {
11696 } else if (!u
&& size
== 0) {
11700 unallocated_encoding(s
);
11702 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
11703 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
11705 unallocated_encoding(s
);
11708 if (!fp_access_check(s
)) {
11712 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
11714 case 0x4: /* CLS, CLZ */
11716 unallocated_encoding(s
);
11720 case 0x2: /* SADDLP, UADDLP */
11721 case 0x6: /* SADALP, UADALP */
11723 unallocated_encoding(s
);
11726 if (!fp_access_check(s
)) {
11729 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
11731 case 0x13: /* SHLL, SHLL2 */
11732 if (u
== 0 || size
== 3) {
11733 unallocated_encoding(s
);
11736 if (!fp_access_check(s
)) {
11739 handle_shll(s
, is_q
, size
, rn
, rd
);
11741 case 0xa: /* CMLT */
11743 unallocated_encoding(s
);
11747 case 0x8: /* CMGT, CMGE */
11748 case 0x9: /* CMEQ, CMLE */
11749 case 0xb: /* ABS, NEG */
11750 if (size
== 3 && !is_q
) {
11751 unallocated_encoding(s
);
11755 case 0x3: /* SUQADD, USQADD */
11756 if (size
== 3 && !is_q
) {
11757 unallocated_encoding(s
);
11760 if (!fp_access_check(s
)) {
11763 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
11765 case 0x7: /* SQABS, SQNEG */
11766 if (size
== 3 && !is_q
) {
11767 unallocated_encoding(s
);
11772 case 0x16 ... 0x1d:
11775 /* Floating point: U, size[1] and opcode indicate operation;
11776 * size[0] indicates single or double precision.
11778 int is_double
= extract32(size
, 0, 1);
11779 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
11780 size
= is_double
? 3 : 2;
11782 case 0x2f: /* FABS */
11783 case 0x6f: /* FNEG */
11784 if (size
== 3 && !is_q
) {
11785 unallocated_encoding(s
);
11789 case 0x1d: /* SCVTF */
11790 case 0x5d: /* UCVTF */
11792 bool is_signed
= (opcode
== 0x1d) ? true : false;
11793 int elements
= is_double
? 2 : is_q
? 4 : 2;
11794 if (is_double
&& !is_q
) {
11795 unallocated_encoding(s
);
11798 if (!fp_access_check(s
)) {
11801 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
11804 case 0x2c: /* FCMGT (zero) */
11805 case 0x2d: /* FCMEQ (zero) */
11806 case 0x2e: /* FCMLT (zero) */
11807 case 0x6c: /* FCMGE (zero) */
11808 case 0x6d: /* FCMLE (zero) */
11809 if (size
== 3 && !is_q
) {
11810 unallocated_encoding(s
);
11813 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
11815 case 0x7f: /* FSQRT */
11816 if (size
== 3 && !is_q
) {
11817 unallocated_encoding(s
);
11821 case 0x1a: /* FCVTNS */
11822 case 0x1b: /* FCVTMS */
11823 case 0x3a: /* FCVTPS */
11824 case 0x3b: /* FCVTZS */
11825 case 0x5a: /* FCVTNU */
11826 case 0x5b: /* FCVTMU */
11827 case 0x7a: /* FCVTPU */
11828 case 0x7b: /* FCVTZU */
11829 need_fpstatus
= true;
11831 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
11832 if (size
== 3 && !is_q
) {
11833 unallocated_encoding(s
);
11837 case 0x5c: /* FCVTAU */
11838 case 0x1c: /* FCVTAS */
11839 need_fpstatus
= true;
11841 rmode
= FPROUNDING_TIEAWAY
;
11842 if (size
== 3 && !is_q
) {
11843 unallocated_encoding(s
);
11847 case 0x3c: /* URECPE */
11849 unallocated_encoding(s
);
11853 case 0x3d: /* FRECPE */
11854 case 0x7d: /* FRSQRTE */
11855 if (size
== 3 && !is_q
) {
11856 unallocated_encoding(s
);
11859 if (!fp_access_check(s
)) {
11862 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
11864 case 0x56: /* FCVTXN, FCVTXN2 */
11866 unallocated_encoding(s
);
11870 case 0x16: /* FCVTN, FCVTN2 */
11871 /* handle_2misc_narrow does a 2*size -> size operation, but these
11872 * instructions encode the source size rather than dest size.
11874 if (!fp_access_check(s
)) {
11877 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
11879 case 0x17: /* FCVTL, FCVTL2 */
11880 if (!fp_access_check(s
)) {
11883 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
11885 case 0x18: /* FRINTN */
11886 case 0x19: /* FRINTM */
11887 case 0x38: /* FRINTP */
11888 case 0x39: /* FRINTZ */
11890 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
11892 case 0x59: /* FRINTX */
11893 case 0x79: /* FRINTI */
11894 need_fpstatus
= true;
11895 if (size
== 3 && !is_q
) {
11896 unallocated_encoding(s
);
11900 case 0x58: /* FRINTA */
11902 rmode
= FPROUNDING_TIEAWAY
;
11903 need_fpstatus
= true;
11904 if (size
== 3 && !is_q
) {
11905 unallocated_encoding(s
);
11909 case 0x7c: /* URSQRTE */
11911 unallocated_encoding(s
);
11914 need_fpstatus
= true;
11917 unallocated_encoding(s
);
11923 unallocated_encoding(s
);
11927 if (!fp_access_check(s
)) {
11931 if (need_fpstatus
|| need_rmode
) {
11932 tcg_fpstatus
= get_fpstatus_ptr(false);
11934 tcg_fpstatus
= NULL
;
11937 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
11938 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
11945 if (u
&& size
== 0) { /* NOT */
11946 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_not
, 0);
11952 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_neg
, size
);
11959 /* All 64-bit element operations can be shared with scalar 2misc */
11962 /* Coverity claims (size == 3 && !is_q) has been eliminated
11963 * from all paths leading to here.
11965 tcg_debug_assert(is_q
);
11966 for (pass
= 0; pass
< 2; pass
++) {
11967 TCGv_i64 tcg_op
= tcg_temp_new_i64();
11968 TCGv_i64 tcg_res
= tcg_temp_new_i64();
11970 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
11972 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
11973 tcg_rmode
, tcg_fpstatus
);
11975 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
11977 tcg_temp_free_i64(tcg_res
);
11978 tcg_temp_free_i64(tcg_op
);
11983 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
11984 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11985 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11988 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
11991 /* Special cases for 32 bit elements */
11993 case 0xa: /* CMLT */
11994 /* 32 bit integer comparison against zero, result is
11995 * test ? (2^32 - 1) : 0. We implement via setcond(test)
11998 cond
= TCG_COND_LT
;
12000 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
12001 tcg_gen_neg_i32(tcg_res
, tcg_res
);
12003 case 0x8: /* CMGT, CMGE */
12004 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
12006 case 0x9: /* CMEQ, CMLE */
12007 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
12009 case 0x4: /* CLS */
12011 tcg_gen_clzi_i32(tcg_res
, tcg_op
, 32);
12013 tcg_gen_clrsb_i32(tcg_res
, tcg_op
);
12016 case 0x7: /* SQABS, SQNEG */
12018 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
12020 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
12023 case 0xb: /* ABS, NEG */
12025 tcg_gen_neg_i32(tcg_res
, tcg_op
);
12027 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12028 tcg_gen_neg_i32(tcg_res
, tcg_op
);
12029 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
12030 tcg_zero
, tcg_op
, tcg_res
);
12031 tcg_temp_free_i32(tcg_zero
);
12034 case 0x2f: /* FABS */
12035 gen_helper_vfp_abss(tcg_res
, tcg_op
);
12037 case 0x6f: /* FNEG */
12038 gen_helper_vfp_negs(tcg_res
, tcg_op
);
12040 case 0x7f: /* FSQRT */
12041 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
12043 case 0x1a: /* FCVTNS */
12044 case 0x1b: /* FCVTMS */
12045 case 0x1c: /* FCVTAS */
12046 case 0x3a: /* FCVTPS */
12047 case 0x3b: /* FCVTZS */
12049 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12050 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
12051 tcg_shift
, tcg_fpstatus
);
12052 tcg_temp_free_i32(tcg_shift
);
12055 case 0x5a: /* FCVTNU */
12056 case 0x5b: /* FCVTMU */
12057 case 0x5c: /* FCVTAU */
12058 case 0x7a: /* FCVTPU */
12059 case 0x7b: /* FCVTZU */
12061 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12062 gen_helper_vfp_touls(tcg_res
, tcg_op
,
12063 tcg_shift
, tcg_fpstatus
);
12064 tcg_temp_free_i32(tcg_shift
);
12067 case 0x18: /* FRINTN */
12068 case 0x19: /* FRINTM */
12069 case 0x38: /* FRINTP */
12070 case 0x39: /* FRINTZ */
12071 case 0x58: /* FRINTA */
12072 case 0x79: /* FRINTI */
12073 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
12075 case 0x59: /* FRINTX */
12076 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12078 case 0x7c: /* URSQRTE */
12079 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
12082 g_assert_not_reached();
12085 /* Use helpers for 8 and 16 bit elements */
12087 case 0x5: /* CNT, RBIT */
12088 /* For these two insns size is part of the opcode specifier
12089 * (handled earlier); they always operate on byte elements.
12092 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
12094 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
12097 case 0x7: /* SQABS, SQNEG */
12099 NeonGenOneOpEnvFn
*genfn
;
12100 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
12101 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
12102 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
12104 genfn
= fns
[size
][u
];
12105 genfn(tcg_res
, cpu_env
, tcg_op
);
12108 case 0x8: /* CMGT, CMGE */
12109 case 0x9: /* CMEQ, CMLE */
12110 case 0xa: /* CMLT */
12112 static NeonGenTwoOpFn
* const fns
[3][2] = {
12113 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
12114 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
12115 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
12117 NeonGenTwoOpFn
*genfn
;
12120 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12122 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
12123 comp
= (opcode
- 0x8) * 2 + u
;
12124 /* ...but LE, LT are implemented as reverse GE, GT */
12125 reverse
= (comp
> 2);
12129 genfn
= fns
[comp
][size
];
12131 genfn(tcg_res
, tcg_zero
, tcg_op
);
12133 genfn(tcg_res
, tcg_op
, tcg_zero
);
12135 tcg_temp_free_i32(tcg_zero
);
12138 case 0xb: /* ABS, NEG */
12140 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12142 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
12144 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
12146 tcg_temp_free_i32(tcg_zero
);
12149 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
12151 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
12155 case 0x4: /* CLS, CLZ */
12158 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
12160 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
12164 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
12166 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
12171 g_assert_not_reached();
12175 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
12177 tcg_temp_free_i32(tcg_res
);
12178 tcg_temp_free_i32(tcg_op
);
12181 clear_vec_high(s
, is_q
, rd
);
12184 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12185 tcg_temp_free_i32(tcg_rmode
);
12187 if (need_fpstatus
) {
12188 tcg_temp_free_ptr(tcg_fpstatus
);
12192 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12194 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12195 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12196 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12197 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12198 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12199 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12201 * This actually covers two groups where scalar access is governed by
12202 * bit 28. A bunch of the instructions (float to integral) only exist
12203 * in the vector form and are un-allocated for the scalar decode. Also
12204 * in the scalar decode Q is always 1.
12206 static void disas_simd_two_reg_misc_fp16(DisasContext
*s
, uint32_t insn
)
12208 int fpop
, opcode
, a
, u
;
12212 bool only_in_vector
= false;
12215 TCGv_i32 tcg_rmode
= NULL
;
12216 TCGv_ptr tcg_fpstatus
= NULL
;
12217 bool need_rmode
= false;
12218 bool need_fpst
= true;
12221 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
12222 unallocated_encoding(s
);
12226 rd
= extract32(insn
, 0, 5);
12227 rn
= extract32(insn
, 5, 5);
12229 a
= extract32(insn
, 23, 1);
12230 u
= extract32(insn
, 29, 1);
12231 is_scalar
= extract32(insn
, 28, 1);
12232 is_q
= extract32(insn
, 30, 1);
12234 opcode
= extract32(insn
, 12, 5);
12235 fpop
= deposit32(opcode
, 5, 1, a
);
12236 fpop
= deposit32(fpop
, 6, 1, u
);
12238 rd
= extract32(insn
, 0, 5);
12239 rn
= extract32(insn
, 5, 5);
12242 case 0x1d: /* SCVTF */
12243 case 0x5d: /* UCVTF */
12250 elements
= (is_q
? 8 : 4);
12253 if (!fp_access_check(s
)) {
12256 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !u
, 0, MO_16
);
12260 case 0x2c: /* FCMGT (zero) */
12261 case 0x2d: /* FCMEQ (zero) */
12262 case 0x2e: /* FCMLT (zero) */
12263 case 0x6c: /* FCMGE (zero) */
12264 case 0x6d: /* FCMLE (zero) */
12265 handle_2misc_fcmp_zero(s
, fpop
, is_scalar
, 0, is_q
, MO_16
, rn
, rd
);
12267 case 0x3d: /* FRECPE */
12268 case 0x3f: /* FRECPX */
12270 case 0x18: /* FRINTN */
12272 only_in_vector
= true;
12273 rmode
= FPROUNDING_TIEEVEN
;
12275 case 0x19: /* FRINTM */
12277 only_in_vector
= true;
12278 rmode
= FPROUNDING_NEGINF
;
12280 case 0x38: /* FRINTP */
12282 only_in_vector
= true;
12283 rmode
= FPROUNDING_POSINF
;
12285 case 0x39: /* FRINTZ */
12287 only_in_vector
= true;
12288 rmode
= FPROUNDING_ZERO
;
12290 case 0x58: /* FRINTA */
12292 only_in_vector
= true;
12293 rmode
= FPROUNDING_TIEAWAY
;
12295 case 0x59: /* FRINTX */
12296 case 0x79: /* FRINTI */
12297 only_in_vector
= true;
12298 /* current rounding mode */
12300 case 0x1a: /* FCVTNS */
12302 rmode
= FPROUNDING_TIEEVEN
;
12304 case 0x1b: /* FCVTMS */
12306 rmode
= FPROUNDING_NEGINF
;
12308 case 0x1c: /* FCVTAS */
12310 rmode
= FPROUNDING_TIEAWAY
;
12312 case 0x3a: /* FCVTPS */
12314 rmode
= FPROUNDING_POSINF
;
12316 case 0x3b: /* FCVTZS */
12318 rmode
= FPROUNDING_ZERO
;
12320 case 0x5a: /* FCVTNU */
12322 rmode
= FPROUNDING_TIEEVEN
;
12324 case 0x5b: /* FCVTMU */
12326 rmode
= FPROUNDING_NEGINF
;
12328 case 0x5c: /* FCVTAU */
12330 rmode
= FPROUNDING_TIEAWAY
;
12332 case 0x7a: /* FCVTPU */
12334 rmode
= FPROUNDING_POSINF
;
12336 case 0x7b: /* FCVTZU */
12338 rmode
= FPROUNDING_ZERO
;
12340 case 0x2f: /* FABS */
12341 case 0x6f: /* FNEG */
12344 case 0x7d: /* FRSQRTE */
12345 case 0x7f: /* FSQRT (vector) */
12348 fprintf(stderr
, "%s: insn %#04x fpop %#2x\n", __func__
, insn
, fpop
);
12349 g_assert_not_reached();
12353 /* Check additional constraints for the scalar encoding */
12356 unallocated_encoding(s
);
12359 /* FRINTxx is only in the vector form */
12360 if (only_in_vector
) {
12361 unallocated_encoding(s
);
12366 if (!fp_access_check(s
)) {
12370 if (need_rmode
|| need_fpst
) {
12371 tcg_fpstatus
= get_fpstatus_ptr(true);
12375 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12376 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12380 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
12381 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12384 case 0x1a: /* FCVTNS */
12385 case 0x1b: /* FCVTMS */
12386 case 0x1c: /* FCVTAS */
12387 case 0x3a: /* FCVTPS */
12388 case 0x3b: /* FCVTZS */
12389 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12391 case 0x3d: /* FRECPE */
12392 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12394 case 0x3f: /* FRECPX */
12395 gen_helper_frecpx_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12397 case 0x5a: /* FCVTNU */
12398 case 0x5b: /* FCVTMU */
12399 case 0x5c: /* FCVTAU */
12400 case 0x7a: /* FCVTPU */
12401 case 0x7b: /* FCVTZU */
12402 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12404 case 0x6f: /* FNEG */
12405 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12407 case 0x7d: /* FRSQRTE */
12408 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12411 g_assert_not_reached();
12414 /* limit any sign extension going on */
12415 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0xffff);
12416 write_fp_sreg(s
, rd
, tcg_res
);
12418 tcg_temp_free_i32(tcg_res
);
12419 tcg_temp_free_i32(tcg_op
);
12421 for (pass
= 0; pass
< (is_q
? 8 : 4); pass
++) {
12422 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12423 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12425 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_16
);
12428 case 0x1a: /* FCVTNS */
12429 case 0x1b: /* FCVTMS */
12430 case 0x1c: /* FCVTAS */
12431 case 0x3a: /* FCVTPS */
12432 case 0x3b: /* FCVTZS */
12433 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12435 case 0x3d: /* FRECPE */
12436 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12438 case 0x5a: /* FCVTNU */
12439 case 0x5b: /* FCVTMU */
12440 case 0x5c: /* FCVTAU */
12441 case 0x7a: /* FCVTPU */
12442 case 0x7b: /* FCVTZU */
12443 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12445 case 0x18: /* FRINTN */
12446 case 0x19: /* FRINTM */
12447 case 0x38: /* FRINTP */
12448 case 0x39: /* FRINTZ */
12449 case 0x58: /* FRINTA */
12450 case 0x79: /* FRINTI */
12451 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12453 case 0x59: /* FRINTX */
12454 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12456 case 0x2f: /* FABS */
12457 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
12459 case 0x6f: /* FNEG */
12460 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12462 case 0x7d: /* FRSQRTE */
12463 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12465 case 0x7f: /* FSQRT */
12466 gen_helper_sqrt_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12469 g_assert_not_reached();
12472 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12474 tcg_temp_free_i32(tcg_res
);
12475 tcg_temp_free_i32(tcg_op
);
12478 clear_vec_high(s
, is_q
, rd
);
12482 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12483 tcg_temp_free_i32(tcg_rmode
);
12486 if (tcg_fpstatus
) {
12487 tcg_temp_free_ptr(tcg_fpstatus
);
12491 /* AdvSIMD scalar x indexed element
12492 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12493 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12494 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12495 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12496 * AdvSIMD vector x indexed element
12497 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12498 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12499 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12500 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12502 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
12504 /* This encoding has two kinds of instruction:
12505 * normal, where we perform elt x idxelt => elt for each
12506 * element in the vector
12507 * long, where we perform elt x idxelt and generate a result of
12508 * double the width of the input element
12509 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
12511 bool is_scalar
= extract32(insn
, 28, 1);
12512 bool is_q
= extract32(insn
, 30, 1);
12513 bool u
= extract32(insn
, 29, 1);
12514 int size
= extract32(insn
, 22, 2);
12515 int l
= extract32(insn
, 21, 1);
12516 int m
= extract32(insn
, 20, 1);
12517 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
12518 int rm
= extract32(insn
, 16, 4);
12519 int opcode
= extract32(insn
, 12, 4);
12520 int h
= extract32(insn
, 11, 1);
12521 int rn
= extract32(insn
, 5, 5);
12522 int rd
= extract32(insn
, 0, 5);
12523 bool is_long
= false;
12525 bool is_fp16
= false;
12529 switch (16 * u
+ opcode
) {
12530 case 0x08: /* MUL */
12531 case 0x10: /* MLA */
12532 case 0x14: /* MLS */
12534 unallocated_encoding(s
);
12538 case 0x02: /* SMLAL, SMLAL2 */
12539 case 0x12: /* UMLAL, UMLAL2 */
12540 case 0x06: /* SMLSL, SMLSL2 */
12541 case 0x16: /* UMLSL, UMLSL2 */
12542 case 0x0a: /* SMULL, SMULL2 */
12543 case 0x1a: /* UMULL, UMULL2 */
12545 unallocated_encoding(s
);
12550 case 0x03: /* SQDMLAL, SQDMLAL2 */
12551 case 0x07: /* SQDMLSL, SQDMLSL2 */
12552 case 0x0b: /* SQDMULL, SQDMULL2 */
12555 case 0x0c: /* SQDMULH */
12556 case 0x0d: /* SQRDMULH */
12558 case 0x01: /* FMLA */
12559 case 0x05: /* FMLS */
12560 case 0x09: /* FMUL */
12561 case 0x19: /* FMULX */
12564 case 0x1d: /* SQRDMLAH */
12565 case 0x1f: /* SQRDMLSH */
12566 if (!arm_dc_feature(s
, ARM_FEATURE_V8_RDM
)) {
12567 unallocated_encoding(s
);
12571 case 0x11: /* FCMLA #0 */
12572 case 0x13: /* FCMLA #90 */
12573 case 0x15: /* FCMLA #180 */
12574 case 0x17: /* FCMLA #270 */
12575 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FCMA
)) {
12576 unallocated_encoding(s
);
12582 unallocated_encoding(s
);
12587 case 1: /* normal fp */
12588 /* convert insn encoded size to TCGMemOp size */
12590 case 0: /* half-precision */
12594 case MO_32
: /* single precision */
12595 case MO_64
: /* double precision */
12598 unallocated_encoding(s
);
12603 case 2: /* complex fp */
12604 /* Each indexable element is a complex pair. */
12609 unallocated_encoding(s
);
12617 unallocated_encoding(s
);
12622 default: /* integer */
12626 unallocated_encoding(s
);
12631 if (is_fp16
&& !arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
12632 unallocated_encoding(s
);
12636 /* Given TCGMemOp size, adjust register and indexing. */
12639 index
= h
<< 2 | l
<< 1 | m
;
12642 index
= h
<< 1 | l
;
12647 unallocated_encoding(s
);
12654 g_assert_not_reached();
12657 if (!fp_access_check(s
)) {
12662 fpst
= get_fpstatus_ptr(is_fp16
);
12667 switch (16 * u
+ opcode
) {
12668 case 0x11: /* FCMLA #0 */
12669 case 0x13: /* FCMLA #90 */
12670 case 0x15: /* FCMLA #180 */
12671 case 0x17: /* FCMLA #270 */
12672 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
12673 vec_full_reg_offset(s
, rn
),
12674 vec_reg_offset(s
, rm
, index
, size
), fpst
,
12675 is_q
? 16 : 8, vec_full_reg_size(s
),
12676 extract32(insn
, 13, 2), /* rot */
12678 ? gen_helper_gvec_fcmlas_idx
12679 : gen_helper_gvec_fcmlah_idx
);
12680 tcg_temp_free_ptr(fpst
);
12685 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
12688 assert(is_fp
&& is_q
&& !is_long
);
12690 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
12692 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
12693 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12694 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12696 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12698 switch (16 * u
+ opcode
) {
12699 case 0x05: /* FMLS */
12700 /* As usual for ARM, separate negation for fused multiply-add */
12701 gen_helper_vfp_negd(tcg_op
, tcg_op
);
12703 case 0x01: /* FMLA */
12704 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12705 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
12707 case 0x09: /* FMUL */
12708 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12710 case 0x19: /* FMULX */
12711 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12714 g_assert_not_reached();
12717 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12718 tcg_temp_free_i64(tcg_op
);
12719 tcg_temp_free_i64(tcg_res
);
12722 tcg_temp_free_i64(tcg_idx
);
12723 clear_vec_high(s
, !is_scalar
, rd
);
12724 } else if (!is_long
) {
12725 /* 32 bit floating point, or 16 or 32 bit integer.
12726 * For the 16 bit scalar case we use the usual Neon helpers and
12727 * rely on the fact that 0 op 0 == 0 with no side effects.
12729 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
12730 int pass
, maxpasses
;
12735 maxpasses
= is_q
? 4 : 2;
12738 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
12740 if (size
== 1 && !is_scalar
) {
12741 /* The simplest way to handle the 16x16 indexed ops is to duplicate
12742 * the index into both halves of the 32 bit tcg_idx and then use
12743 * the usual Neon helpers.
12745 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
12748 for (pass
= 0; pass
< maxpasses
; pass
++) {
12749 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12750 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12752 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
12754 switch (16 * u
+ opcode
) {
12755 case 0x08: /* MUL */
12756 case 0x10: /* MLA */
12757 case 0x14: /* MLS */
12759 static NeonGenTwoOpFn
* const fns
[2][2] = {
12760 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
12761 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
12763 NeonGenTwoOpFn
*genfn
;
12764 bool is_sub
= opcode
== 0x4;
12767 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
12769 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
12771 if (opcode
== 0x8) {
12774 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
12775 genfn
= fns
[size
- 1][is_sub
];
12776 genfn(tcg_res
, tcg_op
, tcg_res
);
12779 case 0x05: /* FMLS */
12780 case 0x01: /* FMLA */
12781 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
12782 is_scalar
? size
: MO_32
);
12785 if (opcode
== 0x5) {
12786 /* As usual for ARM, separate negation for fused
12788 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80008000);
12791 gen_helper_advsimd_muladdh(tcg_res
, tcg_op
, tcg_idx
,
12794 gen_helper_advsimd_muladd2h(tcg_res
, tcg_op
, tcg_idx
,
12799 if (opcode
== 0x5) {
12800 /* As usual for ARM, separate negation for
12801 * fused multiply-add */
12802 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80000000);
12804 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
,
12808 g_assert_not_reached();
12811 case 0x09: /* FMUL */
12815 gen_helper_advsimd_mulh(tcg_res
, tcg_op
,
12818 gen_helper_advsimd_mul2h(tcg_res
, tcg_op
,
12823 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12826 g_assert_not_reached();
12829 case 0x19: /* FMULX */
12833 gen_helper_advsimd_mulxh(tcg_res
, tcg_op
,
12836 gen_helper_advsimd_mulx2h(tcg_res
, tcg_op
,
12841 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12844 g_assert_not_reached();
12847 case 0x0c: /* SQDMULH */
12849 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
12852 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
12856 case 0x0d: /* SQRDMULH */
12858 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
12861 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
12865 case 0x1d: /* SQRDMLAH */
12866 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
12867 is_scalar
? size
: MO_32
);
12869 gen_helper_neon_qrdmlah_s16(tcg_res
, cpu_env
,
12870 tcg_op
, tcg_idx
, tcg_res
);
12872 gen_helper_neon_qrdmlah_s32(tcg_res
, cpu_env
,
12873 tcg_op
, tcg_idx
, tcg_res
);
12876 case 0x1f: /* SQRDMLSH */
12877 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
12878 is_scalar
? size
: MO_32
);
12880 gen_helper_neon_qrdmlsh_s16(tcg_res
, cpu_env
,
12881 tcg_op
, tcg_idx
, tcg_res
);
12883 gen_helper_neon_qrdmlsh_s32(tcg_res
, cpu_env
,
12884 tcg_op
, tcg_idx
, tcg_res
);
12888 g_assert_not_reached();
12892 write_fp_sreg(s
, rd
, tcg_res
);
12894 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
12897 tcg_temp_free_i32(tcg_op
);
12898 tcg_temp_free_i32(tcg_res
);
12901 tcg_temp_free_i32(tcg_idx
);
12902 clear_vec_high(s
, is_q
, rd
);
12904 /* long ops: 16x16->32 or 32x32->64 */
12905 TCGv_i64 tcg_res
[2];
12907 bool satop
= extract32(opcode
, 0, 1);
12908 TCGMemOp memop
= MO_32
;
12915 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
12917 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
12919 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
12920 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12921 TCGv_i64 tcg_passres
;
12927 passelt
= pass
+ (is_q
* 2);
12930 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
12932 tcg_res
[pass
] = tcg_temp_new_i64();
12934 if (opcode
== 0xa || opcode
== 0xb) {
12935 /* Non-accumulating ops */
12936 tcg_passres
= tcg_res
[pass
];
12938 tcg_passres
= tcg_temp_new_i64();
12941 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
12942 tcg_temp_free_i64(tcg_op
);
12945 /* saturating, doubling */
12946 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
12947 tcg_passres
, tcg_passres
);
12950 if (opcode
== 0xa || opcode
== 0xb) {
12954 /* Accumulating op: handle accumulate step */
12955 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
12958 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
12959 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
12961 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
12962 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
12964 case 0x7: /* SQDMLSL, SQDMLSL2 */
12965 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
12967 case 0x3: /* SQDMLAL, SQDMLAL2 */
12968 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
12973 g_assert_not_reached();
12975 tcg_temp_free_i64(tcg_passres
);
12977 tcg_temp_free_i64(tcg_idx
);
12979 clear_vec_high(s
, !is_scalar
, rd
);
12981 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
12984 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
12987 /* The simplest way to handle the 16x16 indexed ops is to
12988 * duplicate the index into both halves of the 32 bit tcg_idx
12989 * and then use the usual Neon helpers.
12991 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
12994 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
12995 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12996 TCGv_i64 tcg_passres
;
12999 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
13001 read_vec_element_i32(s
, tcg_op
, rn
,
13002 pass
+ (is_q
* 2), MO_32
);
13005 tcg_res
[pass
] = tcg_temp_new_i64();
13007 if (opcode
== 0xa || opcode
== 0xb) {
13008 /* Non-accumulating ops */
13009 tcg_passres
= tcg_res
[pass
];
13011 tcg_passres
= tcg_temp_new_i64();
13014 if (memop
& MO_SIGN
) {
13015 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
13017 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
13020 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
13021 tcg_passres
, tcg_passres
);
13023 tcg_temp_free_i32(tcg_op
);
13025 if (opcode
== 0xa || opcode
== 0xb) {
13029 /* Accumulating op: handle accumulate step */
13030 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13033 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13034 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
13037 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13038 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
13041 case 0x7: /* SQDMLSL, SQDMLSL2 */
13042 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
13044 case 0x3: /* SQDMLAL, SQDMLAL2 */
13045 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
13050 g_assert_not_reached();
13052 tcg_temp_free_i64(tcg_passres
);
13054 tcg_temp_free_i32(tcg_idx
);
13057 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
13062 tcg_res
[1] = tcg_const_i64(0);
13065 for (pass
= 0; pass
< 2; pass
++) {
13066 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13067 tcg_temp_free_i64(tcg_res
[pass
]);
13072 tcg_temp_free_ptr(fpst
);
13077 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13078 * +-----------------+------+-----------+--------+-----+------+------+
13079 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13080 * +-----------------+------+-----------+--------+-----+------+------+
13082 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
13084 int size
= extract32(insn
, 22, 2);
13085 int opcode
= extract32(insn
, 12, 5);
13086 int rn
= extract32(insn
, 5, 5);
13087 int rd
= extract32(insn
, 0, 5);
13089 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13090 TCGv_i32 tcg_decrypt
;
13091 CryptoThreeOpIntFn
*genfn
;
13093 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)
13095 unallocated_encoding(s
);
13100 case 0x4: /* AESE */
13102 genfn
= gen_helper_crypto_aese
;
13104 case 0x6: /* AESMC */
13106 genfn
= gen_helper_crypto_aesmc
;
13108 case 0x5: /* AESD */
13110 genfn
= gen_helper_crypto_aese
;
13112 case 0x7: /* AESIMC */
13114 genfn
= gen_helper_crypto_aesmc
;
13117 unallocated_encoding(s
);
13121 if (!fp_access_check(s
)) {
13125 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13126 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13127 tcg_decrypt
= tcg_const_i32(decrypt
);
13129 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_decrypt
);
13131 tcg_temp_free_ptr(tcg_rd_ptr
);
13132 tcg_temp_free_ptr(tcg_rn_ptr
);
13133 tcg_temp_free_i32(tcg_decrypt
);
13136 /* Crypto three-reg SHA
13137 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
13138 * +-----------------+------+---+------+---+--------+-----+------+------+
13139 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
13140 * +-----------------+------+---+------+---+--------+-----+------+------+
13142 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
13144 int size
= extract32(insn
, 22, 2);
13145 int opcode
= extract32(insn
, 12, 3);
13146 int rm
= extract32(insn
, 16, 5);
13147 int rn
= extract32(insn
, 5, 5);
13148 int rd
= extract32(insn
, 0, 5);
13149 CryptoThreeOpFn
*genfn
;
13150 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13151 int feature
= ARM_FEATURE_V8_SHA256
;
13154 unallocated_encoding(s
);
13159 case 0: /* SHA1C */
13160 case 1: /* SHA1P */
13161 case 2: /* SHA1M */
13162 case 3: /* SHA1SU0 */
13164 feature
= ARM_FEATURE_V8_SHA1
;
13166 case 4: /* SHA256H */
13167 genfn
= gen_helper_crypto_sha256h
;
13169 case 5: /* SHA256H2 */
13170 genfn
= gen_helper_crypto_sha256h2
;
13172 case 6: /* SHA256SU1 */
13173 genfn
= gen_helper_crypto_sha256su1
;
13176 unallocated_encoding(s
);
13180 if (!arm_dc_feature(s
, feature
)) {
13181 unallocated_encoding(s
);
13185 if (!fp_access_check(s
)) {
13189 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13190 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13191 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13194 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13196 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
13198 gen_helper_crypto_sha1_3reg(tcg_rd_ptr
, tcg_rn_ptr
,
13199 tcg_rm_ptr
, tcg_opcode
);
13200 tcg_temp_free_i32(tcg_opcode
);
13203 tcg_temp_free_ptr(tcg_rd_ptr
);
13204 tcg_temp_free_ptr(tcg_rn_ptr
);
13205 tcg_temp_free_ptr(tcg_rm_ptr
);
13208 /* Crypto two-reg SHA
13209 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13210 * +-----------------+------+-----------+--------+-----+------+------+
13211 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13212 * +-----------------+------+-----------+--------+-----+------+------+
13214 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
13216 int size
= extract32(insn
, 22, 2);
13217 int opcode
= extract32(insn
, 12, 5);
13218 int rn
= extract32(insn
, 5, 5);
13219 int rd
= extract32(insn
, 0, 5);
13220 CryptoTwoOpFn
*genfn
;
13222 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13225 unallocated_encoding(s
);
13230 case 0: /* SHA1H */
13231 feature
= ARM_FEATURE_V8_SHA1
;
13232 genfn
= gen_helper_crypto_sha1h
;
13234 case 1: /* SHA1SU1 */
13235 feature
= ARM_FEATURE_V8_SHA1
;
13236 genfn
= gen_helper_crypto_sha1su1
;
13238 case 2: /* SHA256SU0 */
13239 feature
= ARM_FEATURE_V8_SHA256
;
13240 genfn
= gen_helper_crypto_sha256su0
;
13243 unallocated_encoding(s
);
13247 if (!arm_dc_feature(s
, feature
)) {
13248 unallocated_encoding(s
);
13252 if (!fp_access_check(s
)) {
13256 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13257 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13259 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13261 tcg_temp_free_ptr(tcg_rd_ptr
);
13262 tcg_temp_free_ptr(tcg_rn_ptr
);
13265 /* Crypto three-reg SHA512
13266 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13267 * +-----------------------+------+---+---+-----+--------+------+------+
13268 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
13269 * +-----------------------+------+---+---+-----+--------+------+------+
13271 static void disas_crypto_three_reg_sha512(DisasContext
*s
, uint32_t insn
)
13273 int opcode
= extract32(insn
, 10, 2);
13274 int o
= extract32(insn
, 14, 1);
13275 int rm
= extract32(insn
, 16, 5);
13276 int rn
= extract32(insn
, 5, 5);
13277 int rd
= extract32(insn
, 0, 5);
13279 CryptoThreeOpFn
*genfn
;
13283 case 0: /* SHA512H */
13284 feature
= ARM_FEATURE_V8_SHA512
;
13285 genfn
= gen_helper_crypto_sha512h
;
13287 case 1: /* SHA512H2 */
13288 feature
= ARM_FEATURE_V8_SHA512
;
13289 genfn
= gen_helper_crypto_sha512h2
;
13291 case 2: /* SHA512SU1 */
13292 feature
= ARM_FEATURE_V8_SHA512
;
13293 genfn
= gen_helper_crypto_sha512su1
;
13296 feature
= ARM_FEATURE_V8_SHA3
;
13302 case 0: /* SM3PARTW1 */
13303 feature
= ARM_FEATURE_V8_SM3
;
13304 genfn
= gen_helper_crypto_sm3partw1
;
13306 case 1: /* SM3PARTW2 */
13307 feature
= ARM_FEATURE_V8_SM3
;
13308 genfn
= gen_helper_crypto_sm3partw2
;
13310 case 2: /* SM4EKEY */
13311 feature
= ARM_FEATURE_V8_SM4
;
13312 genfn
= gen_helper_crypto_sm4ekey
;
13315 unallocated_encoding(s
);
13320 if (!arm_dc_feature(s
, feature
)) {
13321 unallocated_encoding(s
);
13325 if (!fp_access_check(s
)) {
13330 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13332 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13333 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13334 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13336 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13338 tcg_temp_free_ptr(tcg_rd_ptr
);
13339 tcg_temp_free_ptr(tcg_rn_ptr
);
13340 tcg_temp_free_ptr(tcg_rm_ptr
);
13342 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13345 tcg_op1
= tcg_temp_new_i64();
13346 tcg_op2
= tcg_temp_new_i64();
13347 tcg_res
[0] = tcg_temp_new_i64();
13348 tcg_res
[1] = tcg_temp_new_i64();
13350 for (pass
= 0; pass
< 2; pass
++) {
13351 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13352 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13354 tcg_gen_rotli_i64(tcg_res
[pass
], tcg_op2
, 1);
13355 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13357 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13358 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13360 tcg_temp_free_i64(tcg_op1
);
13361 tcg_temp_free_i64(tcg_op2
);
13362 tcg_temp_free_i64(tcg_res
[0]);
13363 tcg_temp_free_i64(tcg_res
[1]);
13367 /* Crypto two-reg SHA512
13368 * 31 12 11 10 9 5 4 0
13369 * +-----------------------------------------+--------+------+------+
13370 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
13371 * +-----------------------------------------+--------+------+------+
13373 static void disas_crypto_two_reg_sha512(DisasContext
*s
, uint32_t insn
)
13375 int opcode
= extract32(insn
, 10, 2);
13376 int rn
= extract32(insn
, 5, 5);
13377 int rd
= extract32(insn
, 0, 5);
13378 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13380 CryptoTwoOpFn
*genfn
;
13383 case 0: /* SHA512SU0 */
13384 feature
= ARM_FEATURE_V8_SHA512
;
13385 genfn
= gen_helper_crypto_sha512su0
;
13388 feature
= ARM_FEATURE_V8_SM4
;
13389 genfn
= gen_helper_crypto_sm4e
;
13392 unallocated_encoding(s
);
13396 if (!arm_dc_feature(s
, feature
)) {
13397 unallocated_encoding(s
);
13401 if (!fp_access_check(s
)) {
13405 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13406 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13408 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13410 tcg_temp_free_ptr(tcg_rd_ptr
);
13411 tcg_temp_free_ptr(tcg_rn_ptr
);
13414 /* Crypto four-register
13415 * 31 23 22 21 20 16 15 14 10 9 5 4 0
13416 * +-------------------+-----+------+---+------+------+------+
13417 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
13418 * +-------------------+-----+------+---+------+------+------+
13420 static void disas_crypto_four_reg(DisasContext
*s
, uint32_t insn
)
13422 int op0
= extract32(insn
, 21, 2);
13423 int rm
= extract32(insn
, 16, 5);
13424 int ra
= extract32(insn
, 10, 5);
13425 int rn
= extract32(insn
, 5, 5);
13426 int rd
= extract32(insn
, 0, 5);
13432 feature
= ARM_FEATURE_V8_SHA3
;
13434 case 2: /* SM3SS1 */
13435 feature
= ARM_FEATURE_V8_SM3
;
13438 unallocated_encoding(s
);
13442 if (!arm_dc_feature(s
, feature
)) {
13443 unallocated_encoding(s
);
13447 if (!fp_access_check(s
)) {
13452 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
[2];
13455 tcg_op1
= tcg_temp_new_i64();
13456 tcg_op2
= tcg_temp_new_i64();
13457 tcg_op3
= tcg_temp_new_i64();
13458 tcg_res
[0] = tcg_temp_new_i64();
13459 tcg_res
[1] = tcg_temp_new_i64();
13461 for (pass
= 0; pass
< 2; pass
++) {
13462 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13463 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13464 read_vec_element(s
, tcg_op3
, ra
, pass
, MO_64
);
13468 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13471 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13473 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13475 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13476 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13478 tcg_temp_free_i64(tcg_op1
);
13479 tcg_temp_free_i64(tcg_op2
);
13480 tcg_temp_free_i64(tcg_op3
);
13481 tcg_temp_free_i64(tcg_res
[0]);
13482 tcg_temp_free_i64(tcg_res
[1]);
13484 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
, tcg_zero
;
13486 tcg_op1
= tcg_temp_new_i32();
13487 tcg_op2
= tcg_temp_new_i32();
13488 tcg_op3
= tcg_temp_new_i32();
13489 tcg_res
= tcg_temp_new_i32();
13490 tcg_zero
= tcg_const_i32(0);
13492 read_vec_element_i32(s
, tcg_op1
, rn
, 3, MO_32
);
13493 read_vec_element_i32(s
, tcg_op2
, rm
, 3, MO_32
);
13494 read_vec_element_i32(s
, tcg_op3
, ra
, 3, MO_32
);
13496 tcg_gen_rotri_i32(tcg_res
, tcg_op1
, 20);
13497 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op2
);
13498 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op3
);
13499 tcg_gen_rotri_i32(tcg_res
, tcg_res
, 25);
13501 write_vec_element_i32(s
, tcg_zero
, rd
, 0, MO_32
);
13502 write_vec_element_i32(s
, tcg_zero
, rd
, 1, MO_32
);
13503 write_vec_element_i32(s
, tcg_zero
, rd
, 2, MO_32
);
13504 write_vec_element_i32(s
, tcg_res
, rd
, 3, MO_32
);
13506 tcg_temp_free_i32(tcg_op1
);
13507 tcg_temp_free_i32(tcg_op2
);
13508 tcg_temp_free_i32(tcg_op3
);
13509 tcg_temp_free_i32(tcg_res
);
13510 tcg_temp_free_i32(tcg_zero
);
13515 * 31 21 20 16 15 10 9 5 4 0
13516 * +-----------------------+------+--------+------+------+
13517 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
13518 * +-----------------------+------+--------+------+------+
13520 static void disas_crypto_xar(DisasContext
*s
, uint32_t insn
)
13522 int rm
= extract32(insn
, 16, 5);
13523 int imm6
= extract32(insn
, 10, 6);
13524 int rn
= extract32(insn
, 5, 5);
13525 int rd
= extract32(insn
, 0, 5);
13526 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13529 if (!arm_dc_feature(s
, ARM_FEATURE_V8_SHA3
)) {
13530 unallocated_encoding(s
);
13534 if (!fp_access_check(s
)) {
13538 tcg_op1
= tcg_temp_new_i64();
13539 tcg_op2
= tcg_temp_new_i64();
13540 tcg_res
[0] = tcg_temp_new_i64();
13541 tcg_res
[1] = tcg_temp_new_i64();
13543 for (pass
= 0; pass
< 2; pass
++) {
13544 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13545 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13547 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
13548 tcg_gen_rotri_i64(tcg_res
[pass
], tcg_res
[pass
], imm6
);
13550 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13551 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13553 tcg_temp_free_i64(tcg_op1
);
13554 tcg_temp_free_i64(tcg_op2
);
13555 tcg_temp_free_i64(tcg_res
[0]);
13556 tcg_temp_free_i64(tcg_res
[1]);
13559 /* Crypto three-reg imm2
13560 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13561 * +-----------------------+------+-----+------+--------+------+------+
13562 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
13563 * +-----------------------+------+-----+------+--------+------+------+
13565 static void disas_crypto_three_reg_imm2(DisasContext
*s
, uint32_t insn
)
13567 int opcode
= extract32(insn
, 10, 2);
13568 int imm2
= extract32(insn
, 12, 2);
13569 int rm
= extract32(insn
, 16, 5);
13570 int rn
= extract32(insn
, 5, 5);
13571 int rd
= extract32(insn
, 0, 5);
13572 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13573 TCGv_i32 tcg_imm2
, tcg_opcode
;
13575 if (!arm_dc_feature(s
, ARM_FEATURE_V8_SM3
)) {
13576 unallocated_encoding(s
);
13580 if (!fp_access_check(s
)) {
13584 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13585 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13586 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13587 tcg_imm2
= tcg_const_i32(imm2
);
13588 tcg_opcode
= tcg_const_i32(opcode
);
13590 gen_helper_crypto_sm3tt(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
, tcg_imm2
,
13593 tcg_temp_free_ptr(tcg_rd_ptr
);
13594 tcg_temp_free_ptr(tcg_rn_ptr
);
13595 tcg_temp_free_ptr(tcg_rm_ptr
);
13596 tcg_temp_free_i32(tcg_imm2
);
13597 tcg_temp_free_i32(tcg_opcode
);
13600 /* C3.6 Data processing - SIMD, inc Crypto
13602 * As the decode gets a little complex we are using a table based
13603 * approach for this part of the decode.
13605 static const AArch64DecodeTable data_proc_simd
[] = {
13606 /* pattern , mask , fn */
13607 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
13608 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra
},
13609 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
13610 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
13611 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
13612 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
13613 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
13614 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
13615 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
13616 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
13617 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
13618 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
13619 { 0x2e000000, 0xbf208400, disas_simd_ext
},
13620 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
13621 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra
},
13622 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
13623 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
13624 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
13625 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
13626 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
13627 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
13628 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
13629 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
13630 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
13631 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512
},
13632 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512
},
13633 { 0xce000000, 0xff808000, disas_crypto_four_reg
},
13634 { 0xce800000, 0xffe00000, disas_crypto_xar
},
13635 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2
},
13636 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16
},
13637 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16
},
13638 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16
},
13639 { 0x00000000, 0x00000000, NULL
}
13642 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
13644 /* Note that this is called with all non-FP cases from
13645 * table C3-6 so it must UNDEF for entries not specifically
13646 * allocated to instructions in that table.
13648 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
13652 unallocated_encoding(s
);
13656 /* C3.6 Data processing - SIMD and floating point */
13657 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
13659 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
13660 disas_data_proc_fp(s
, insn
);
13662 /* SIMD, including crypto */
13663 disas_data_proc_simd(s
, insn
);
13667 /* C3.1 A64 instruction index by encoding */
13668 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
13672 insn
= arm_ldl_code(env
, s
->pc
, s
->sctlr_b
);
13676 s
->fp_access_checked
= false;
13678 switch (extract32(insn
, 25, 4)) {
13679 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
13680 unallocated_encoding(s
);
13683 if (!arm_dc_feature(s
, ARM_FEATURE_SVE
) || !disas_sve(s
, insn
)) {
13684 unallocated_encoding(s
);
13687 case 0x8: case 0x9: /* Data processing - immediate */
13688 disas_data_proc_imm(s
, insn
);
13690 case 0xa: case 0xb: /* Branch, exception generation and system insns */
13691 disas_b_exc_sys(s
, insn
);
13696 case 0xe: /* Loads and stores */
13697 disas_ldst(s
, insn
);
13700 case 0xd: /* Data processing - register */
13701 disas_data_proc_reg(s
, insn
);
13704 case 0xf: /* Data processing - SIMD and floating point */
13705 disas_data_proc_simd_fp(s
, insn
);
13708 assert(FALSE
); /* all 15 cases should be handled above */
13712 /* if we allocated any temporaries, free them here */
13716 static void aarch64_tr_init_disas_context(DisasContextBase
*dcbase
,
13719 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13720 CPUARMState
*env
= cpu
->env_ptr
;
13721 ARMCPU
*arm_cpu
= arm_env_get_cpu(env
);
13724 dc
->pc
= dc
->base
.pc_first
;
13728 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
13729 * there is no secure EL1, so we route exceptions to EL3.
13731 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
13732 !arm_el_is_aa64(env
, 3);
13735 dc
->be_data
= ARM_TBFLAG_BE_DATA(dc
->base
.tb
->flags
) ? MO_BE
: MO_LE
;
13736 dc
->condexec_mask
= 0;
13737 dc
->condexec_cond
= 0;
13738 dc
->mmu_idx
= core_to_arm_mmu_idx(env
, ARM_TBFLAG_MMUIDX(dc
->base
.tb
->flags
));
13739 dc
->tbi0
= ARM_TBFLAG_TBI0(dc
->base
.tb
->flags
);
13740 dc
->tbi1
= ARM_TBFLAG_TBI1(dc
->base
.tb
->flags
);
13741 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
13742 #if !defined(CONFIG_USER_ONLY)
13743 dc
->user
= (dc
->current_el
== 0);
13745 dc
->fp_excp_el
= ARM_TBFLAG_FPEXC_EL(dc
->base
.tb
->flags
);
13746 dc
->sve_excp_el
= ARM_TBFLAG_SVEEXC_EL(dc
->base
.tb
->flags
);
13747 dc
->sve_len
= (ARM_TBFLAG_ZCR_LEN(dc
->base
.tb
->flags
) + 1) * 16;
13749 dc
->vec_stride
= 0;
13750 dc
->cp_regs
= arm_cpu
->cp_regs
;
13751 dc
->features
= env
->features
;
13753 /* Single step state. The code-generation logic here is:
13755 * generate code with no special handling for single-stepping (except
13756 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
13757 * this happens anyway because those changes are all system register or
13759 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
13760 * emit code for one insn
13761 * emit code to clear PSTATE.SS
13762 * emit code to generate software step exception for completed step
13763 * end TB (as usual for having generated an exception)
13764 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
13765 * emit code to generate a software step exception
13768 dc
->ss_active
= ARM_TBFLAG_SS_ACTIVE(dc
->base
.tb
->flags
);
13769 dc
->pstate_ss
= ARM_TBFLAG_PSTATE_SS(dc
->base
.tb
->flags
);
13770 dc
->is_ldex
= false;
13771 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
13773 /* Bound the number of insns to execute to those left on the page. */
13774 bound
= -(dc
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
13776 /* If architectural single step active, limit to 1. */
13777 if (dc
->ss_active
) {
13780 dc
->base
.max_insns
= MIN(dc
->base
.max_insns
, bound
);
13782 init_tmp_a64_array(dc
);
13785 static void aarch64_tr_tb_start(DisasContextBase
*db
, CPUState
*cpu
)
13787 tcg_clear_temp_count();
13790 static void aarch64_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
13792 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13794 tcg_gen_insn_start(dc
->pc
, 0, 0);
13795 dc
->insn_start
= tcg_last_op();
13798 static bool aarch64_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cpu
,
13799 const CPUBreakpoint
*bp
)
13801 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13803 if (bp
->flags
& BP_CPU
) {
13804 gen_a64_set_pc_im(dc
->pc
);
13805 gen_helper_check_breakpoints(cpu_env
);
13806 /* End the TB early; it likely won't be executed */
13807 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
13809 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
13810 /* The address covered by the breakpoint must be
13811 included in [tb->pc, tb->pc + tb->size) in order
13812 to for it to be properly cleared -- thus we
13813 increment the PC here so that the logic setting
13814 tb->size below does the right thing. */
13816 dc
->base
.is_jmp
= DISAS_NORETURN
;
13822 static void aarch64_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
13824 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13825 CPUARMState
*env
= cpu
->env_ptr
;
13827 if (dc
->ss_active
&& !dc
->pstate_ss
) {
13828 /* Singlestep state is Active-pending.
13829 * If we're in this state at the start of a TB then either
13830 * a) we just took an exception to an EL which is being debugged
13831 * and this is the first insn in the exception handler
13832 * b) debug exceptions were masked and we just unmasked them
13833 * without changing EL (eg by clearing PSTATE.D)
13834 * In either case we're going to take a swstep exception in the
13835 * "did not step an insn" case, and so the syndrome ISV and EX
13836 * bits should be zero.
13838 assert(dc
->base
.num_insns
== 1);
13839 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0),
13840 default_exception_el(dc
));
13841 dc
->base
.is_jmp
= DISAS_NORETURN
;
13843 disas_a64_insn(env
, dc
);
13846 dc
->base
.pc_next
= dc
->pc
;
13847 translator_loop_temp_check(&dc
->base
);
13850 static void aarch64_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
13852 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13854 if (unlikely(dc
->base
.singlestep_enabled
|| dc
->ss_active
)) {
13855 /* Note that this means single stepping WFI doesn't halt the CPU.
13856 * For conditional branch insns this is harmless unreachable code as
13857 * gen_goto_tb() has already handled emitting the debug exception
13858 * (and thus a tb-jump is not possible when singlestepping).
13860 switch (dc
->base
.is_jmp
) {
13862 gen_a64_set_pc_im(dc
->pc
);
13866 if (dc
->base
.singlestep_enabled
) {
13867 gen_exception_internal(EXCP_DEBUG
);
13869 gen_step_complete_exception(dc
);
13872 case DISAS_NORETURN
:
13876 switch (dc
->base
.is_jmp
) {
13878 case DISAS_TOO_MANY
:
13879 gen_goto_tb(dc
, 1, dc
->pc
);
13883 gen_a64_set_pc_im(dc
->pc
);
13886 tcg_gen_exit_tb(NULL
, 0);
13889 tcg_gen_lookup_and_goto_ptr();
13891 case DISAS_NORETURN
:
13895 gen_a64_set_pc_im(dc
->pc
);
13896 gen_helper_wfe(cpu_env
);
13899 gen_a64_set_pc_im(dc
->pc
);
13900 gen_helper_yield(cpu_env
);
13904 /* This is a special case because we don't want to just halt the CPU
13905 * if trying to debug across a WFI.
13907 TCGv_i32 tmp
= tcg_const_i32(4);
13909 gen_a64_set_pc_im(dc
->pc
);
13910 gen_helper_wfi(cpu_env
, tmp
);
13911 tcg_temp_free_i32(tmp
);
13912 /* The helper doesn't necessarily throw an exception, but we
13913 * must go back to the main loop to check for interrupts anyway.
13915 tcg_gen_exit_tb(NULL
, 0);
13921 /* Functions above can change dc->pc, so re-align db->pc_next */
13922 dc
->base
.pc_next
= dc
->pc
;
13925 static void aarch64_tr_disas_log(const DisasContextBase
*dcbase
,
13928 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13930 qemu_log("IN: %s\n", lookup_symbol(dc
->base
.pc_first
));
13931 log_target_disas(cpu
, dc
->base
.pc_first
, dc
->base
.tb
->size
);
13934 const TranslatorOps aarch64_translator_ops
= {
13935 .init_disas_context
= aarch64_tr_init_disas_context
,
13936 .tb_start
= aarch64_tr_tb_start
,
13937 .insn_start
= aarch64_tr_insn_start
,
13938 .breakpoint_check
= aarch64_tr_breakpoint_check
,
13939 .translate_insn
= aarch64_tr_translate_insn
,
13940 .tb_stop
= aarch64_tr_tb_stop
,
13941 .disas_log
= aarch64_tr_disas_log
,