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 operation using an out-of-line helper. */
644 static void gen_gvec_op3_ool(DisasContext
*s
, bool is_q
, int rd
,
645 int rn
, int rm
, int data
, gen_helper_gvec_3
*fn
)
647 tcg_gen_gvec_3_ool(vec_full_reg_offset(s
, rd
),
648 vec_full_reg_offset(s
, rn
),
649 vec_full_reg_offset(s
, rm
),
650 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
653 /* Expand a 3-operand + env pointer operation using
654 * an out-of-line helper.
656 static void gen_gvec_op3_env(DisasContext
*s
, bool is_q
, int rd
,
657 int rn
, int rm
, gen_helper_gvec_3_ptr
*fn
)
659 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
660 vec_full_reg_offset(s
, rn
),
661 vec_full_reg_offset(s
, rm
), cpu_env
,
662 is_q
? 16 : 8, vec_full_reg_size(s
), 0, fn
);
665 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
666 * an out-of-line helper.
668 static void gen_gvec_op3_fpst(DisasContext
*s
, bool is_q
, int rd
, int rn
,
669 int rm
, bool is_fp16
, int data
,
670 gen_helper_gvec_3_ptr
*fn
)
672 TCGv_ptr fpst
= get_fpstatus_ptr(is_fp16
);
673 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
674 vec_full_reg_offset(s
, rn
),
675 vec_full_reg_offset(s
, rm
), fpst
,
676 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
677 tcg_temp_free_ptr(fpst
);
680 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
681 * than the 32 bit equivalent.
683 static inline void gen_set_NZ64(TCGv_i64 result
)
685 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
686 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
689 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
690 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
693 gen_set_NZ64(result
);
695 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
696 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
698 tcg_gen_movi_i32(cpu_CF
, 0);
699 tcg_gen_movi_i32(cpu_VF
, 0);
702 /* dest = T0 + T1; compute C, N, V and Z flags */
703 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
706 TCGv_i64 result
, flag
, tmp
;
707 result
= tcg_temp_new_i64();
708 flag
= tcg_temp_new_i64();
709 tmp
= tcg_temp_new_i64();
711 tcg_gen_movi_i64(tmp
, 0);
712 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
714 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
716 gen_set_NZ64(result
);
718 tcg_gen_xor_i64(flag
, result
, t0
);
719 tcg_gen_xor_i64(tmp
, t0
, t1
);
720 tcg_gen_andc_i64(flag
, flag
, tmp
);
721 tcg_temp_free_i64(tmp
);
722 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
724 tcg_gen_mov_i64(dest
, result
);
725 tcg_temp_free_i64(result
);
726 tcg_temp_free_i64(flag
);
728 /* 32 bit arithmetic */
729 TCGv_i32 t0_32
= tcg_temp_new_i32();
730 TCGv_i32 t1_32
= tcg_temp_new_i32();
731 TCGv_i32 tmp
= tcg_temp_new_i32();
733 tcg_gen_movi_i32(tmp
, 0);
734 tcg_gen_extrl_i64_i32(t0_32
, t0
);
735 tcg_gen_extrl_i64_i32(t1_32
, t1
);
736 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
737 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
738 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
739 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
740 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
741 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
743 tcg_temp_free_i32(tmp
);
744 tcg_temp_free_i32(t0_32
);
745 tcg_temp_free_i32(t1_32
);
749 /* dest = T0 - T1; compute C, N, V and Z flags */
750 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
753 /* 64 bit arithmetic */
754 TCGv_i64 result
, flag
, tmp
;
756 result
= tcg_temp_new_i64();
757 flag
= tcg_temp_new_i64();
758 tcg_gen_sub_i64(result
, t0
, t1
);
760 gen_set_NZ64(result
);
762 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
763 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
765 tcg_gen_xor_i64(flag
, result
, t0
);
766 tmp
= tcg_temp_new_i64();
767 tcg_gen_xor_i64(tmp
, t0
, t1
);
768 tcg_gen_and_i64(flag
, flag
, tmp
);
769 tcg_temp_free_i64(tmp
);
770 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
771 tcg_gen_mov_i64(dest
, result
);
772 tcg_temp_free_i64(flag
);
773 tcg_temp_free_i64(result
);
775 /* 32 bit arithmetic */
776 TCGv_i32 t0_32
= tcg_temp_new_i32();
777 TCGv_i32 t1_32
= tcg_temp_new_i32();
780 tcg_gen_extrl_i64_i32(t0_32
, t0
);
781 tcg_gen_extrl_i64_i32(t1_32
, t1
);
782 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
783 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
784 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
785 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
786 tmp
= tcg_temp_new_i32();
787 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
788 tcg_temp_free_i32(t0_32
);
789 tcg_temp_free_i32(t1_32
);
790 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
791 tcg_temp_free_i32(tmp
);
792 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
796 /* dest = T0 + T1 + CF; do not compute flags. */
797 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
799 TCGv_i64 flag
= tcg_temp_new_i64();
800 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
801 tcg_gen_add_i64(dest
, t0
, t1
);
802 tcg_gen_add_i64(dest
, dest
, flag
);
803 tcg_temp_free_i64(flag
);
806 tcg_gen_ext32u_i64(dest
, dest
);
810 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
811 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
814 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
815 result
= tcg_temp_new_i64();
816 cf_64
= tcg_temp_new_i64();
817 vf_64
= tcg_temp_new_i64();
818 tmp
= tcg_const_i64(0);
820 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
821 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
822 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
823 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
824 gen_set_NZ64(result
);
826 tcg_gen_xor_i64(vf_64
, result
, t0
);
827 tcg_gen_xor_i64(tmp
, t0
, t1
);
828 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
829 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
831 tcg_gen_mov_i64(dest
, result
);
833 tcg_temp_free_i64(tmp
);
834 tcg_temp_free_i64(vf_64
);
835 tcg_temp_free_i64(cf_64
);
836 tcg_temp_free_i64(result
);
838 TCGv_i32 t0_32
, t1_32
, tmp
;
839 t0_32
= tcg_temp_new_i32();
840 t1_32
= tcg_temp_new_i32();
841 tmp
= tcg_const_i32(0);
843 tcg_gen_extrl_i64_i32(t0_32
, t0
);
844 tcg_gen_extrl_i64_i32(t1_32
, t1
);
845 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
846 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
848 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
849 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
850 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
851 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
852 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
854 tcg_temp_free_i32(tmp
);
855 tcg_temp_free_i32(t1_32
);
856 tcg_temp_free_i32(t0_32
);
861 * Load/Store generators
865 * Store from GPR register to memory.
867 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
868 TCGv_i64 tcg_addr
, int size
, int memidx
,
870 unsigned int iss_srt
,
871 bool iss_sf
, bool iss_ar
)
874 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, s
->be_data
+ size
);
879 syn
= syn_data_abort_with_iss(0,
885 0, 0, 0, 0, 0, false);
886 disas_set_insn_syndrome(s
, syn
);
890 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
891 TCGv_i64 tcg_addr
, int size
,
893 unsigned int iss_srt
,
894 bool iss_sf
, bool iss_ar
)
896 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
),
897 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
901 * Load from memory to GPR register
903 static void do_gpr_ld_memidx(DisasContext
*s
,
904 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
905 int size
, bool is_signed
,
906 bool extend
, int memidx
,
907 bool iss_valid
, unsigned int iss_srt
,
908 bool iss_sf
, bool iss_ar
)
910 TCGMemOp memop
= s
->be_data
+ size
;
918 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
920 if (extend
&& is_signed
) {
922 tcg_gen_ext32u_i64(dest
, dest
);
928 syn
= syn_data_abort_with_iss(0,
934 0, 0, 0, 0, 0, false);
935 disas_set_insn_syndrome(s
, syn
);
939 static void do_gpr_ld(DisasContext
*s
,
940 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
941 int size
, bool is_signed
, bool extend
,
942 bool iss_valid
, unsigned int iss_srt
,
943 bool iss_sf
, bool iss_ar
)
945 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
947 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
951 * Store from FP register to memory
953 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
955 /* This writes the bottom N bits of a 128 bit wide vector to memory */
956 TCGv_i64 tmp
= tcg_temp_new_i64();
957 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
959 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
),
962 bool be
= s
->be_data
== MO_BE
;
963 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
965 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
966 tcg_gen_qemu_st_i64(tmp
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
968 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
969 tcg_gen_qemu_st_i64(tmp
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
971 tcg_temp_free_i64(tcg_hiaddr
);
974 tcg_temp_free_i64(tmp
);
978 * Load from memory to FP register
980 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
982 /* This always zero-extends and writes to a full 128 bit wide vector */
983 TCGv_i64 tmplo
= tcg_temp_new_i64();
987 TCGMemOp memop
= s
->be_data
+ size
;
988 tmphi
= tcg_const_i64(0);
989 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
991 bool be
= s
->be_data
== MO_BE
;
994 tmphi
= tcg_temp_new_i64();
995 tcg_hiaddr
= tcg_temp_new_i64();
997 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
998 tcg_gen_qemu_ld_i64(tmplo
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
1000 tcg_gen_qemu_ld_i64(tmphi
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
1002 tcg_temp_free_i64(tcg_hiaddr
);
1005 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
1006 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
1008 tcg_temp_free_i64(tmplo
);
1009 tcg_temp_free_i64(tmphi
);
1011 clear_vec_high(s
, true, destidx
);
1015 * Vector load/store helpers.
1017 * The principal difference between this and a FP load is that we don't
1018 * zero extend as we are filling a partial chunk of the vector register.
1019 * These functions don't support 128 bit loads/stores, which would be
1020 * normal load/store operations.
1022 * The _i32 versions are useful when operating on 32 bit quantities
1023 * (eg for floating point single or using Neon helper functions).
1026 /* Get value of an element within a vector register */
1027 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
1028 int element
, TCGMemOp memop
)
1030 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1033 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
1036 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
1039 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
1042 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
1045 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
1048 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
1052 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
1055 g_assert_not_reached();
1059 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
1060 int element
, TCGMemOp memop
)
1062 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1065 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
1068 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
1071 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
1074 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
1078 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
1081 g_assert_not_reached();
1085 /* Set value of an element within a vector register */
1086 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
1087 int element
, TCGMemOp memop
)
1089 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1092 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
1095 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
1098 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
1101 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
1104 g_assert_not_reached();
1108 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
1109 int destidx
, int element
, TCGMemOp memop
)
1111 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1114 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
1117 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
1120 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
1123 g_assert_not_reached();
1127 /* Store from vector register to memory */
1128 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
1129 TCGv_i64 tcg_addr
, int size
)
1131 TCGMemOp memop
= s
->be_data
+ size
;
1132 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1134 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
1135 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
1137 tcg_temp_free_i64(tcg_tmp
);
1140 /* Load from memory to vector register */
1141 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
1142 TCGv_i64 tcg_addr
, int size
)
1144 TCGMemOp memop
= s
->be_data
+ size
;
1145 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1147 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
1148 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
1150 tcg_temp_free_i64(tcg_tmp
);
1153 /* Check that FP/Neon access is enabled. If it is, return
1154 * true. If not, emit code to generate an appropriate exception,
1155 * and return false; the caller should not emit any code for
1156 * the instruction. Note that this check must happen after all
1157 * unallocated-encoding checks (otherwise the syndrome information
1158 * for the resulting exception will be incorrect).
1160 static inline bool fp_access_check(DisasContext
*s
)
1162 assert(!s
->fp_access_checked
);
1163 s
->fp_access_checked
= true;
1165 if (!s
->fp_excp_el
) {
1169 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false),
1174 /* Check that SVE access is enabled. If it is, return true.
1175 * If not, emit code to generate an appropriate exception and return false.
1177 bool sve_access_check(DisasContext
*s
)
1179 if (s
->sve_excp_el
) {
1180 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_sve_access_trap(),
1184 return fp_access_check(s
);
1188 * This utility function is for doing register extension with an
1189 * optional shift. You will likely want to pass a temporary for the
1190 * destination register. See DecodeRegExtend() in the ARM ARM.
1192 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1193 int option
, unsigned int shift
)
1195 int extsize
= extract32(option
, 0, 2);
1196 bool is_signed
= extract32(option
, 2, 1);
1201 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1204 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1207 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1210 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1216 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1219 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1222 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1225 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1231 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1235 static inline void gen_check_sp_alignment(DisasContext
*s
)
1237 /* The AArch64 architecture mandates that (if enabled via PSTATE
1238 * or SCTLR bits) there is a check that SP is 16-aligned on every
1239 * SP-relative load or store (with an exception generated if it is not).
1240 * In line with general QEMU practice regarding misaligned accesses,
1241 * we omit these checks for the sake of guest program performance.
1242 * This function is provided as a hook so we can more easily add these
1243 * checks in future (possibly as a "favour catching guest program bugs
1244 * over speed" user selectable option).
1249 * This provides a simple table based table lookup decoder. It is
1250 * intended to be used when the relevant bits for decode are too
1251 * awkwardly placed and switch/if based logic would be confusing and
1252 * deeply nested. Since it's a linear search through the table, tables
1253 * should be kept small.
1255 * It returns the first handler where insn & mask == pattern, or
1256 * NULL if there is no match.
1257 * The table is terminated by an empty mask (i.e. 0)
1259 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1262 const AArch64DecodeTable
*tptr
= table
;
1264 while (tptr
->mask
) {
1265 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1266 return tptr
->disas_fn
;
1274 * The instruction disassembly implemented here matches
1275 * the instruction encoding classifications in chapter C4
1276 * of the ARM Architecture Reference Manual (DDI0487B_a);
1277 * classification names and decode diagrams here should generally
1278 * match up with those in the manual.
1281 /* Unconditional branch (immediate)
1283 * +----+-----------+-------------------------------------+
1284 * | op | 0 0 1 0 1 | imm26 |
1285 * +----+-----------+-------------------------------------+
1287 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1289 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1291 if (insn
& (1U << 31)) {
1292 /* BL Branch with link */
1293 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1296 /* B Branch / BL Branch with link */
1297 gen_goto_tb(s
, 0, addr
);
1300 /* Compare and branch (immediate)
1301 * 31 30 25 24 23 5 4 0
1302 * +----+-------------+----+---------------------+--------+
1303 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1304 * +----+-------------+----+---------------------+--------+
1306 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1308 unsigned int sf
, op
, rt
;
1310 TCGLabel
*label_match
;
1313 sf
= extract32(insn
, 31, 1);
1314 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1315 rt
= extract32(insn
, 0, 5);
1316 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1318 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1319 label_match
= gen_new_label();
1321 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1322 tcg_cmp
, 0, label_match
);
1324 gen_goto_tb(s
, 0, s
->pc
);
1325 gen_set_label(label_match
);
1326 gen_goto_tb(s
, 1, addr
);
1329 /* Test and branch (immediate)
1330 * 31 30 25 24 23 19 18 5 4 0
1331 * +----+-------------+----+-------+-------------+------+
1332 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1333 * +----+-------------+----+-------+-------------+------+
1335 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1337 unsigned int bit_pos
, op
, rt
;
1339 TCGLabel
*label_match
;
1342 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1343 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1344 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1345 rt
= extract32(insn
, 0, 5);
1347 tcg_cmp
= tcg_temp_new_i64();
1348 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1349 label_match
= gen_new_label();
1350 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1351 tcg_cmp
, 0, label_match
);
1352 tcg_temp_free_i64(tcg_cmp
);
1353 gen_goto_tb(s
, 0, s
->pc
);
1354 gen_set_label(label_match
);
1355 gen_goto_tb(s
, 1, addr
);
1358 /* Conditional branch (immediate)
1359 * 31 25 24 23 5 4 3 0
1360 * +---------------+----+---------------------+----+------+
1361 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1362 * +---------------+----+---------------------+----+------+
1364 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1369 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1370 unallocated_encoding(s
);
1373 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1374 cond
= extract32(insn
, 0, 4);
1377 /* genuinely conditional branches */
1378 TCGLabel
*label_match
= gen_new_label();
1379 arm_gen_test_cc(cond
, label_match
);
1380 gen_goto_tb(s
, 0, s
->pc
);
1381 gen_set_label(label_match
);
1382 gen_goto_tb(s
, 1, addr
);
1384 /* 0xe and 0xf are both "always" conditions */
1385 gen_goto_tb(s
, 0, addr
);
1389 /* HINT instruction group, including various allocated HINTs */
1390 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1391 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1393 unsigned int selector
= crm
<< 3 | op2
;
1396 unallocated_encoding(s
);
1404 s
->base
.is_jmp
= DISAS_WFI
;
1406 /* When running in MTTCG we don't generate jumps to the yield and
1407 * WFE helpers as it won't affect the scheduling of other vCPUs.
1408 * If we wanted to more completely model WFE/SEV so we don't busy
1409 * spin unnecessarily we would need to do something more involved.
1412 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1413 s
->base
.is_jmp
= DISAS_YIELD
;
1417 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1418 s
->base
.is_jmp
= DISAS_WFE
;
1423 /* we treat all as NOP at least for now */
1426 /* default specified as NOP equivalent */
1431 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1433 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1436 /* CLREX, DSB, DMB, ISB */
1437 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1438 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1443 unallocated_encoding(s
);
1454 case 1: /* MBReqTypes_Reads */
1455 bar
= TCG_BAR_SC
| TCG_MO_LD_LD
| TCG_MO_LD_ST
;
1457 case 2: /* MBReqTypes_Writes */
1458 bar
= TCG_BAR_SC
| TCG_MO_ST_ST
;
1460 default: /* MBReqTypes_All */
1461 bar
= TCG_BAR_SC
| TCG_MO_ALL
;
1467 /* We need to break the TB after this insn to execute
1468 * a self-modified code correctly and also to take
1469 * any pending interrupts immediately.
1471 gen_goto_tb(s
, 0, s
->pc
);
1474 unallocated_encoding(s
);
1479 /* MSR (immediate) - move immediate to processor state field */
1480 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1481 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1483 int op
= op1
<< 3 | op2
;
1485 case 0x05: /* SPSel */
1486 if (s
->current_el
== 0) {
1487 unallocated_encoding(s
);
1491 case 0x1e: /* DAIFSet */
1492 case 0x1f: /* DAIFClear */
1494 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1495 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1496 gen_a64_set_pc_im(s
->pc
- 4);
1497 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1498 tcg_temp_free_i32(tcg_imm
);
1499 tcg_temp_free_i32(tcg_op
);
1500 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1501 gen_a64_set_pc_im(s
->pc
);
1502 s
->base
.is_jmp
= (op
== 0x1f ? DISAS_EXIT
: DISAS_JUMP
);
1506 unallocated_encoding(s
);
1511 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1513 TCGv_i32 tmp
= tcg_temp_new_i32();
1514 TCGv_i32 nzcv
= tcg_temp_new_i32();
1516 /* build bit 31, N */
1517 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1518 /* build bit 30, Z */
1519 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1520 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1521 /* build bit 29, C */
1522 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1523 /* build bit 28, V */
1524 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1525 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1526 /* generate result */
1527 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1529 tcg_temp_free_i32(nzcv
);
1530 tcg_temp_free_i32(tmp
);
1533 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1536 TCGv_i32 nzcv
= tcg_temp_new_i32();
1538 /* take NZCV from R[t] */
1539 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1542 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1544 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1545 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1547 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1548 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1550 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1551 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1552 tcg_temp_free_i32(nzcv
);
1555 /* MRS - move from system register
1556 * MSR (register) - move to system register
1559 * These are all essentially the same insn in 'read' and 'write'
1560 * versions, with varying op0 fields.
1562 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1563 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1564 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1566 const ARMCPRegInfo
*ri
;
1569 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1570 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1571 crn
, crm
, op0
, op1
, op2
));
1574 /* Unknown register; this might be a guest error or a QEMU
1575 * unimplemented feature.
1577 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1578 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1579 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1580 unallocated_encoding(s
);
1584 /* Check access permissions */
1585 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1586 unallocated_encoding(s
);
1591 /* Emit code to perform further access permissions checks at
1592 * runtime; this may result in an exception.
1595 TCGv_i32 tcg_syn
, tcg_isread
;
1598 gen_a64_set_pc_im(s
->pc
- 4);
1599 tmpptr
= tcg_const_ptr(ri
);
1600 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1601 tcg_syn
= tcg_const_i32(syndrome
);
1602 tcg_isread
= tcg_const_i32(isread
);
1603 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
, tcg_isread
);
1604 tcg_temp_free_ptr(tmpptr
);
1605 tcg_temp_free_i32(tcg_syn
);
1606 tcg_temp_free_i32(tcg_isread
);
1609 /* Handle special cases first */
1610 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1614 tcg_rt
= cpu_reg(s
, rt
);
1616 gen_get_nzcv(tcg_rt
);
1618 gen_set_nzcv(tcg_rt
);
1621 case ARM_CP_CURRENTEL
:
1622 /* Reads as current EL value from pstate, which is
1623 * guaranteed to be constant by the tb flags.
1625 tcg_rt
= cpu_reg(s
, rt
);
1626 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1629 /* Writes clear the aligned block of memory which rt points into. */
1630 tcg_rt
= cpu_reg(s
, rt
);
1631 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1636 if ((ri
->type
& ARM_CP_FPU
) && !fp_access_check(s
)) {
1638 } else if ((ri
->type
& ARM_CP_SVE
) && !sve_access_check(s
)) {
1642 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1646 tcg_rt
= cpu_reg(s
, rt
);
1649 if (ri
->type
& ARM_CP_CONST
) {
1650 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1651 } else if (ri
->readfn
) {
1653 tmpptr
= tcg_const_ptr(ri
);
1654 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1655 tcg_temp_free_ptr(tmpptr
);
1657 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1660 if (ri
->type
& ARM_CP_CONST
) {
1661 /* If not forbidden by access permissions, treat as WI */
1663 } else if (ri
->writefn
) {
1665 tmpptr
= tcg_const_ptr(ri
);
1666 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1667 tcg_temp_free_ptr(tmpptr
);
1669 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1673 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1674 /* I/O operations must end the TB here (whether read or write) */
1676 s
->base
.is_jmp
= DISAS_UPDATE
;
1677 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1678 /* We default to ending the TB on a coprocessor register write,
1679 * but allow this to be suppressed by the register definition
1680 * (usually only necessary to work around guest bugs).
1682 s
->base
.is_jmp
= DISAS_UPDATE
;
1687 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1688 * +---------------------+---+-----+-----+-------+-------+-----+------+
1689 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1690 * +---------------------+---+-----+-----+-------+-------+-----+------+
1692 static void disas_system(DisasContext
*s
, uint32_t insn
)
1694 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1695 l
= extract32(insn
, 21, 1);
1696 op0
= extract32(insn
, 19, 2);
1697 op1
= extract32(insn
, 16, 3);
1698 crn
= extract32(insn
, 12, 4);
1699 crm
= extract32(insn
, 8, 4);
1700 op2
= extract32(insn
, 5, 3);
1701 rt
= extract32(insn
, 0, 5);
1704 if (l
|| rt
!= 31) {
1705 unallocated_encoding(s
);
1709 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
1710 handle_hint(s
, insn
, op1
, op2
, crm
);
1712 case 3: /* CLREX, DSB, DMB, ISB */
1713 handle_sync(s
, insn
, op1
, op2
, crm
);
1715 case 4: /* MSR (immediate) */
1716 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1719 unallocated_encoding(s
);
1724 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1727 /* Exception generation
1729 * 31 24 23 21 20 5 4 2 1 0
1730 * +-----------------+-----+------------------------+-----+----+
1731 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1732 * +-----------------------+------------------------+----------+
1734 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1736 int opc
= extract32(insn
, 21, 3);
1737 int op2_ll
= extract32(insn
, 0, 5);
1738 int imm16
= extract32(insn
, 5, 16);
1743 /* For SVC, HVC and SMC we advance the single-step state
1744 * machine before taking the exception. This is architecturally
1745 * mandated, to ensure that single-stepping a system call
1746 * instruction works properly.
1751 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
),
1752 default_exception_el(s
));
1755 if (s
->current_el
== 0) {
1756 unallocated_encoding(s
);
1759 /* The pre HVC helper handles cases when HVC gets trapped
1760 * as an undefined insn by runtime configuration.
1762 gen_a64_set_pc_im(s
->pc
- 4);
1763 gen_helper_pre_hvc(cpu_env
);
1765 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
), 2);
1768 if (s
->current_el
== 0) {
1769 unallocated_encoding(s
);
1772 gen_a64_set_pc_im(s
->pc
- 4);
1773 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1774 gen_helper_pre_smc(cpu_env
, tmp
);
1775 tcg_temp_free_i32(tmp
);
1777 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
), 3);
1780 unallocated_encoding(s
);
1786 unallocated_encoding(s
);
1790 gen_exception_bkpt_insn(s
, 4, syn_aa64_bkpt(imm16
));
1794 unallocated_encoding(s
);
1797 /* HLT. This has two purposes.
1798 * Architecturally, it is an external halting debug instruction.
1799 * Since QEMU doesn't implement external debug, we treat this as
1800 * it is required for halting debug disabled: it will UNDEF.
1801 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1803 if (semihosting_enabled() && imm16
== 0xf000) {
1804 #ifndef CONFIG_USER_ONLY
1805 /* In system mode, don't allow userspace access to semihosting,
1806 * to provide some semblance of security (and for consistency
1807 * with our 32-bit semihosting).
1809 if (s
->current_el
== 0) {
1810 unsupported_encoding(s
, insn
);
1814 gen_exception_internal_insn(s
, 0, EXCP_SEMIHOST
);
1816 unsupported_encoding(s
, insn
);
1820 if (op2_ll
< 1 || op2_ll
> 3) {
1821 unallocated_encoding(s
);
1824 /* DCPS1, DCPS2, DCPS3 */
1825 unsupported_encoding(s
, insn
);
1828 unallocated_encoding(s
);
1833 /* Unconditional branch (register)
1834 * 31 25 24 21 20 16 15 10 9 5 4 0
1835 * +---------------+-------+-------+-------+------+-------+
1836 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1837 * +---------------+-------+-------+-------+------+-------+
1839 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1841 unsigned int opc
, op2
, op3
, rn
, op4
;
1843 opc
= extract32(insn
, 21, 4);
1844 op2
= extract32(insn
, 16, 5);
1845 op3
= extract32(insn
, 10, 6);
1846 rn
= extract32(insn
, 5, 5);
1847 op4
= extract32(insn
, 0, 5);
1849 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1850 unallocated_encoding(s
);
1858 gen_a64_set_pc(s
, cpu_reg(s
, rn
));
1859 /* BLR also needs to load return address */
1861 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1865 if (s
->current_el
== 0) {
1866 unallocated_encoding(s
);
1869 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
1872 gen_helper_exception_return(cpu_env
);
1873 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
1876 /* Must exit loop to check un-masked IRQs */
1877 s
->base
.is_jmp
= DISAS_EXIT
;
1881 unallocated_encoding(s
);
1883 unsupported_encoding(s
, insn
);
1887 unallocated_encoding(s
);
1891 s
->base
.is_jmp
= DISAS_JUMP
;
1894 /* Branches, exception generating and system instructions */
1895 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1897 switch (extract32(insn
, 25, 7)) {
1898 case 0x0a: case 0x0b:
1899 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1900 disas_uncond_b_imm(s
, insn
);
1902 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1903 disas_comp_b_imm(s
, insn
);
1905 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1906 disas_test_b_imm(s
, insn
);
1908 case 0x2a: /* Conditional branch (immediate) */
1909 disas_cond_b_imm(s
, insn
);
1911 case 0x6a: /* Exception generation / System */
1912 if (insn
& (1 << 24)) {
1913 disas_system(s
, insn
);
1918 case 0x6b: /* Unconditional branch (register) */
1919 disas_uncond_b_reg(s
, insn
);
1922 unallocated_encoding(s
);
1928 * Load/Store exclusive instructions are implemented by remembering
1929 * the value/address loaded, and seeing if these are the same
1930 * when the store is performed. This is not actually the architecturally
1931 * mandated semantics, but it works for typical guest code sequences
1932 * and avoids having to monitor regular stores.
1934 * The store exclusive uses the atomic cmpxchg primitives to avoid
1935 * races in multi-threaded linux-user and when MTTCG softmmu is
1938 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
1939 TCGv_i64 addr
, int size
, bool is_pair
)
1941 int idx
= get_mem_index(s
);
1942 TCGMemOp memop
= s
->be_data
;
1944 g_assert(size
<= 3);
1946 g_assert(size
>= 2);
1948 /* The pair must be single-copy atomic for the doubleword. */
1949 memop
|= MO_64
| MO_ALIGN
;
1950 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
1951 if (s
->be_data
== MO_LE
) {
1952 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 0, 32);
1953 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 32, 32);
1955 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 32, 32);
1956 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 0, 32);
1959 /* The pair must be single-copy atomic for *each* doubleword, not
1960 the entire quadword, however it must be quadword aligned. */
1962 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
,
1963 memop
| MO_ALIGN_16
);
1965 TCGv_i64 addr2
= tcg_temp_new_i64();
1966 tcg_gen_addi_i64(addr2
, addr
, 8);
1967 tcg_gen_qemu_ld_i64(cpu_exclusive_high
, addr2
, idx
, memop
);
1968 tcg_temp_free_i64(addr2
);
1970 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
1971 tcg_gen_mov_i64(cpu_reg(s
, rt2
), cpu_exclusive_high
);
1974 memop
|= size
| MO_ALIGN
;
1975 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
1976 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
1978 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
1981 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1982 TCGv_i64 addr
, int size
, int is_pair
)
1984 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1985 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1988 * [addr + datasize] = {Rt2};
1994 * env->exclusive_addr = -1;
1996 TCGLabel
*fail_label
= gen_new_label();
1997 TCGLabel
*done_label
= gen_new_label();
2000 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
2002 tmp
= tcg_temp_new_i64();
2005 if (s
->be_data
== MO_LE
) {
2006 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2008 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt2
), cpu_reg(s
, rt
));
2010 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
,
2011 cpu_exclusive_val
, tmp
,
2013 MO_64
| MO_ALIGN
| s
->be_data
);
2014 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2015 } else if (s
->be_data
== MO_LE
) {
2016 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2017 gen_helper_paired_cmpxchg64_le_parallel(tmp
, cpu_env
,
2022 gen_helper_paired_cmpxchg64_le(tmp
, cpu_env
, cpu_exclusive_addr
,
2023 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2026 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2027 gen_helper_paired_cmpxchg64_be_parallel(tmp
, cpu_env
,
2032 gen_helper_paired_cmpxchg64_be(tmp
, cpu_env
, cpu_exclusive_addr
,
2033 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2037 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
, cpu_exclusive_val
,
2038 cpu_reg(s
, rt
), get_mem_index(s
),
2039 size
| MO_ALIGN
| s
->be_data
);
2040 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2042 tcg_gen_mov_i64(cpu_reg(s
, rd
), tmp
);
2043 tcg_temp_free_i64(tmp
);
2044 tcg_gen_br(done_label
);
2046 gen_set_label(fail_label
);
2047 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
2048 gen_set_label(done_label
);
2049 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
2052 static void gen_compare_and_swap(DisasContext
*s
, int rs
, int rt
,
2055 TCGv_i64 tcg_rs
= cpu_reg(s
, rs
);
2056 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2057 int memidx
= get_mem_index(s
);
2058 TCGv_i64 addr
= cpu_reg_sp(s
, rn
);
2061 gen_check_sp_alignment(s
);
2063 tcg_gen_atomic_cmpxchg_i64(tcg_rs
, addr
, tcg_rs
, tcg_rt
, memidx
,
2064 size
| MO_ALIGN
| s
->be_data
);
2067 static void gen_compare_and_swap_pair(DisasContext
*s
, int rs
, int rt
,
2070 TCGv_i64 s1
= cpu_reg(s
, rs
);
2071 TCGv_i64 s2
= cpu_reg(s
, rs
+ 1);
2072 TCGv_i64 t1
= cpu_reg(s
, rt
);
2073 TCGv_i64 t2
= cpu_reg(s
, rt
+ 1);
2074 TCGv_i64 addr
= cpu_reg_sp(s
, rn
);
2075 int memidx
= get_mem_index(s
);
2078 gen_check_sp_alignment(s
);
2082 TCGv_i64 cmp
= tcg_temp_new_i64();
2083 TCGv_i64 val
= tcg_temp_new_i64();
2085 if (s
->be_data
== MO_LE
) {
2086 tcg_gen_concat32_i64(val
, t1
, t2
);
2087 tcg_gen_concat32_i64(cmp
, s1
, s2
);
2089 tcg_gen_concat32_i64(val
, t2
, t1
);
2090 tcg_gen_concat32_i64(cmp
, s2
, s1
);
2093 tcg_gen_atomic_cmpxchg_i64(cmp
, addr
, cmp
, val
, memidx
,
2094 MO_64
| MO_ALIGN
| s
->be_data
);
2095 tcg_temp_free_i64(val
);
2097 if (s
->be_data
== MO_LE
) {
2098 tcg_gen_extr32_i64(s1
, s2
, cmp
);
2100 tcg_gen_extr32_i64(s2
, s1
, cmp
);
2102 tcg_temp_free_i64(cmp
);
2103 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2104 TCGv_i32 tcg_rs
= tcg_const_i32(rs
);
2106 if (s
->be_data
== MO_LE
) {
2107 gen_helper_casp_le_parallel(cpu_env
, tcg_rs
, addr
, t1
, t2
);
2109 gen_helper_casp_be_parallel(cpu_env
, tcg_rs
, addr
, t1
, t2
);
2111 tcg_temp_free_i32(tcg_rs
);
2113 TCGv_i64 d1
= tcg_temp_new_i64();
2114 TCGv_i64 d2
= tcg_temp_new_i64();
2115 TCGv_i64 a2
= tcg_temp_new_i64();
2116 TCGv_i64 c1
= tcg_temp_new_i64();
2117 TCGv_i64 c2
= tcg_temp_new_i64();
2118 TCGv_i64 zero
= tcg_const_i64(0);
2120 /* Load the two words, in memory order. */
2121 tcg_gen_qemu_ld_i64(d1
, addr
, memidx
,
2122 MO_64
| MO_ALIGN_16
| s
->be_data
);
2123 tcg_gen_addi_i64(a2
, addr
, 8);
2124 tcg_gen_qemu_ld_i64(d2
, addr
, memidx
, MO_64
| s
->be_data
);
2126 /* Compare the two words, also in memory order. */
2127 tcg_gen_setcond_i64(TCG_COND_EQ
, c1
, d1
, s1
);
2128 tcg_gen_setcond_i64(TCG_COND_EQ
, c2
, d2
, s2
);
2129 tcg_gen_and_i64(c2
, c2
, c1
);
2131 /* If compare equal, write back new data, else write back old data. */
2132 tcg_gen_movcond_i64(TCG_COND_NE
, c1
, c2
, zero
, t1
, d1
);
2133 tcg_gen_movcond_i64(TCG_COND_NE
, c2
, c2
, zero
, t2
, d2
);
2134 tcg_gen_qemu_st_i64(c1
, addr
, memidx
, MO_64
| s
->be_data
);
2135 tcg_gen_qemu_st_i64(c2
, a2
, memidx
, MO_64
| s
->be_data
);
2136 tcg_temp_free_i64(a2
);
2137 tcg_temp_free_i64(c1
);
2138 tcg_temp_free_i64(c2
);
2139 tcg_temp_free_i64(zero
);
2141 /* Write back the data from memory to Rs. */
2142 tcg_gen_mov_i64(s1
, d1
);
2143 tcg_gen_mov_i64(s2
, d2
);
2144 tcg_temp_free_i64(d1
);
2145 tcg_temp_free_i64(d2
);
2149 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2150 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2152 static bool disas_ldst_compute_iss_sf(int size
, bool is_signed
, int opc
)
2154 int opc0
= extract32(opc
, 0, 1);
2158 regsize
= opc0
? 32 : 64;
2160 regsize
= size
== 3 ? 64 : 32;
2162 return regsize
== 64;
2165 /* Load/store exclusive
2167 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2168 * +-----+-------------+----+---+----+------+----+-------+------+------+
2169 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2170 * +-----+-------------+----+---+----+------+----+-------+------+------+
2172 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2173 * L: 0 -> store, 1 -> load
2174 * o2: 0 -> exclusive, 1 -> not
2175 * o1: 0 -> single register, 1 -> register pair
2176 * o0: 1 -> load-acquire/store-release, 0 -> not
2178 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
2180 int rt
= extract32(insn
, 0, 5);
2181 int rn
= extract32(insn
, 5, 5);
2182 int rt2
= extract32(insn
, 10, 5);
2183 int rs
= extract32(insn
, 16, 5);
2184 int is_lasr
= extract32(insn
, 15, 1);
2185 int o2_L_o1_o0
= extract32(insn
, 21, 3) * 2 | is_lasr
;
2186 int size
= extract32(insn
, 30, 2);
2189 switch (o2_L_o1_o0
) {
2190 case 0x0: /* STXR */
2191 case 0x1: /* STLXR */
2193 gen_check_sp_alignment(s
);
2196 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2198 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2199 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, false);
2202 case 0x4: /* LDXR */
2203 case 0x5: /* LDAXR */
2205 gen_check_sp_alignment(s
);
2207 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2209 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, false);
2211 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2215 case 0x9: /* STLR */
2216 /* Generate ISS for non-exclusive accesses including LASR. */
2218 gen_check_sp_alignment(s
);
2220 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2221 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2222 do_gpr_st(s
, cpu_reg(s
, rt
), tcg_addr
, size
, true, rt
,
2223 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2226 case 0xd: /* LDAR */
2227 /* Generate ISS for non-exclusive accesses including LASR. */
2229 gen_check_sp_alignment(s
);
2231 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2232 do_gpr_ld(s
, cpu_reg(s
, rt
), tcg_addr
, size
, false, false, true, rt
,
2233 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2234 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2237 case 0x2: case 0x3: /* CASP / STXP */
2238 if (size
& 2) { /* STXP / STLXP */
2240 gen_check_sp_alignment(s
);
2243 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2245 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2246 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, true);
2250 && ((rt
| rs
) & 1) == 0
2251 && arm_dc_feature(s
, ARM_FEATURE_V8_ATOMICS
)) {
2253 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2258 case 0x6: case 0x7: /* CASPA / LDXP */
2259 if (size
& 2) { /* LDXP / LDAXP */
2261 gen_check_sp_alignment(s
);
2263 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2265 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, true);
2267 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2272 && ((rt
| rs
) & 1) == 0
2273 && arm_dc_feature(s
, ARM_FEATURE_V8_ATOMICS
)) {
2274 /* CASPA / CASPAL */
2275 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2281 case 0xb: /* CASL */
2282 case 0xe: /* CASA */
2283 case 0xf: /* CASAL */
2284 if (rt2
== 31 && arm_dc_feature(s
, ARM_FEATURE_V8_ATOMICS
)) {
2285 gen_compare_and_swap(s
, rs
, rt
, rn
, size
);
2290 unallocated_encoding(s
);
2294 * Load register (literal)
2296 * 31 30 29 27 26 25 24 23 5 4 0
2297 * +-----+-------+---+-----+-------------------+-------+
2298 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2299 * +-----+-------+---+-----+-------------------+-------+
2301 * V: 1 -> vector (simd/fp)
2302 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2303 * 10-> 32 bit signed, 11 -> prefetch
2304 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2306 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
2308 int rt
= extract32(insn
, 0, 5);
2309 int64_t imm
= sextract32(insn
, 5, 19) << 2;
2310 bool is_vector
= extract32(insn
, 26, 1);
2311 int opc
= extract32(insn
, 30, 2);
2312 bool is_signed
= false;
2314 TCGv_i64 tcg_rt
, tcg_addr
;
2318 unallocated_encoding(s
);
2322 if (!fp_access_check(s
)) {
2327 /* PRFM (literal) : prefetch */
2330 size
= 2 + extract32(opc
, 0, 1);
2331 is_signed
= extract32(opc
, 1, 1);
2334 tcg_rt
= cpu_reg(s
, rt
);
2336 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
2338 do_fp_ld(s
, rt
, tcg_addr
, size
);
2340 /* Only unsigned 32bit loads target 32bit registers. */
2341 bool iss_sf
= opc
!= 0;
2343 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false,
2344 true, rt
, iss_sf
, false);
2346 tcg_temp_free_i64(tcg_addr
);
2350 * LDNP (Load Pair - non-temporal hint)
2351 * LDP (Load Pair - non vector)
2352 * LDPSW (Load Pair Signed Word - non vector)
2353 * STNP (Store Pair - non-temporal hint)
2354 * STP (Store Pair - non vector)
2355 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2356 * LDP (Load Pair of SIMD&FP)
2357 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2358 * STP (Store Pair of SIMD&FP)
2360 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2361 * +-----+-------+---+---+-------+---+-----------------------------+
2362 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2363 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2365 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2367 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2368 * V: 0 -> GPR, 1 -> Vector
2369 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2370 * 10 -> signed offset, 11 -> pre-index
2371 * L: 0 -> Store 1 -> Load
2373 * Rt, Rt2 = GPR or SIMD registers to be stored
2374 * Rn = general purpose register containing address
2375 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2377 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
2379 int rt
= extract32(insn
, 0, 5);
2380 int rn
= extract32(insn
, 5, 5);
2381 int rt2
= extract32(insn
, 10, 5);
2382 uint64_t offset
= sextract64(insn
, 15, 7);
2383 int index
= extract32(insn
, 23, 2);
2384 bool is_vector
= extract32(insn
, 26, 1);
2385 bool is_load
= extract32(insn
, 22, 1);
2386 int opc
= extract32(insn
, 30, 2);
2388 bool is_signed
= false;
2389 bool postindex
= false;
2392 TCGv_i64 tcg_addr
; /* calculated address */
2396 unallocated_encoding(s
);
2403 size
= 2 + extract32(opc
, 1, 1);
2404 is_signed
= extract32(opc
, 0, 1);
2405 if (!is_load
&& is_signed
) {
2406 unallocated_encoding(s
);
2412 case 1: /* post-index */
2417 /* signed offset with "non-temporal" hint. Since we don't emulate
2418 * caches we don't care about hints to the cache system about
2419 * data access patterns, and handle this identically to plain
2423 /* There is no non-temporal-hint version of LDPSW */
2424 unallocated_encoding(s
);
2429 case 2: /* signed offset, rn not updated */
2432 case 3: /* pre-index */
2438 if (is_vector
&& !fp_access_check(s
)) {
2445 gen_check_sp_alignment(s
);
2448 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2451 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2456 do_fp_ld(s
, rt
, tcg_addr
, size
);
2458 do_fp_st(s
, rt
, tcg_addr
, size
);
2460 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2462 do_fp_ld(s
, rt2
, tcg_addr
, size
);
2464 do_fp_st(s
, rt2
, tcg_addr
, size
);
2467 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2468 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2471 TCGv_i64 tmp
= tcg_temp_new_i64();
2473 /* Do not modify tcg_rt before recognizing any exception
2474 * from the second load.
2476 do_gpr_ld(s
, tmp
, tcg_addr
, size
, is_signed
, false,
2477 false, 0, false, false);
2478 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2479 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false,
2480 false, 0, false, false);
2482 tcg_gen_mov_i64(tcg_rt
, tmp
);
2483 tcg_temp_free_i64(tmp
);
2485 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2486 false, 0, false, false);
2487 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2488 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
,
2489 false, 0, false, false);
2495 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
2497 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2499 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
2504 * Load/store (immediate post-indexed)
2505 * Load/store (immediate pre-indexed)
2506 * Load/store (unscaled immediate)
2508 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2509 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2510 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2511 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2513 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2515 * V = 0 -> non-vector
2516 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2517 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2519 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
2525 int rn
= extract32(insn
, 5, 5);
2526 int imm9
= sextract32(insn
, 12, 9);
2527 int idx
= extract32(insn
, 10, 2);
2528 bool is_signed
= false;
2529 bool is_store
= false;
2530 bool is_extended
= false;
2531 bool is_unpriv
= (idx
== 2);
2532 bool iss_valid
= !is_vector
;
2539 size
|= (opc
& 2) << 1;
2540 if (size
> 4 || is_unpriv
) {
2541 unallocated_encoding(s
);
2544 is_store
= ((opc
& 1) == 0);
2545 if (!fp_access_check(s
)) {
2549 if (size
== 3 && opc
== 2) {
2550 /* PRFM - prefetch */
2552 unallocated_encoding(s
);
2557 if (opc
== 3 && size
> 1) {
2558 unallocated_encoding(s
);
2561 is_store
= (opc
== 0);
2562 is_signed
= extract32(opc
, 1, 1);
2563 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2581 g_assert_not_reached();
2585 gen_check_sp_alignment(s
);
2587 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2590 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2595 do_fp_st(s
, rt
, tcg_addr
, size
);
2597 do_fp_ld(s
, rt
, tcg_addr
, size
);
2600 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2601 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2602 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2605 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
,
2606 iss_valid
, rt
, iss_sf
, false);
2608 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
2609 is_signed
, is_extended
, memidx
,
2610 iss_valid
, rt
, iss_sf
, false);
2615 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2617 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2619 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2624 * Load/store (register offset)
2626 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2627 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2628 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2629 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2632 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2633 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2635 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2636 * opc<0>: 0 -> store, 1 -> load
2637 * V: 1 -> vector/simd
2638 * opt: extend encoding (see DecodeRegExtend)
2639 * S: if S=1 then scale (essentially index by sizeof(size))
2640 * Rt: register to transfer into/out of
2641 * Rn: address register or SP for base
2642 * Rm: offset register or ZR for offset
2644 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
2650 int rn
= extract32(insn
, 5, 5);
2651 int shift
= extract32(insn
, 12, 1);
2652 int rm
= extract32(insn
, 16, 5);
2653 int opt
= extract32(insn
, 13, 3);
2654 bool is_signed
= false;
2655 bool is_store
= false;
2656 bool is_extended
= false;
2661 if (extract32(opt
, 1, 1) == 0) {
2662 unallocated_encoding(s
);
2667 size
|= (opc
& 2) << 1;
2669 unallocated_encoding(s
);
2672 is_store
= !extract32(opc
, 0, 1);
2673 if (!fp_access_check(s
)) {
2677 if (size
== 3 && opc
== 2) {
2678 /* PRFM - prefetch */
2681 if (opc
== 3 && size
> 1) {
2682 unallocated_encoding(s
);
2685 is_store
= (opc
== 0);
2686 is_signed
= extract32(opc
, 1, 1);
2687 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2691 gen_check_sp_alignment(s
);
2693 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2695 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2696 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2698 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2702 do_fp_st(s
, rt
, tcg_addr
, size
);
2704 do_fp_ld(s
, rt
, tcg_addr
, size
);
2707 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2708 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2710 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2711 true, rt
, iss_sf
, false);
2713 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
,
2714 is_signed
, is_extended
,
2715 true, rt
, iss_sf
, false);
2721 * Load/store (unsigned immediate)
2723 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2724 * +----+-------+---+-----+-----+------------+-------+------+
2725 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2726 * +----+-------+---+-----+-----+------------+-------+------+
2729 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2730 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2732 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2733 * opc<0>: 0 -> store, 1 -> load
2734 * Rn: base address register (inc SP)
2735 * Rt: target register
2737 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
2743 int rn
= extract32(insn
, 5, 5);
2744 unsigned int imm12
= extract32(insn
, 10, 12);
2745 unsigned int offset
;
2750 bool is_signed
= false;
2751 bool is_extended
= false;
2754 size
|= (opc
& 2) << 1;
2756 unallocated_encoding(s
);
2759 is_store
= !extract32(opc
, 0, 1);
2760 if (!fp_access_check(s
)) {
2764 if (size
== 3 && opc
== 2) {
2765 /* PRFM - prefetch */
2768 if (opc
== 3 && size
> 1) {
2769 unallocated_encoding(s
);
2772 is_store
= (opc
== 0);
2773 is_signed
= extract32(opc
, 1, 1);
2774 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2778 gen_check_sp_alignment(s
);
2780 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2781 offset
= imm12
<< size
;
2782 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2786 do_fp_st(s
, rt
, tcg_addr
, size
);
2788 do_fp_ld(s
, rt
, tcg_addr
, size
);
2791 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2792 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2794 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2795 true, rt
, iss_sf
, false);
2797 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
,
2798 true, rt
, iss_sf
, false);
2803 /* Atomic memory operations
2805 * 31 30 27 26 24 22 21 16 15 12 10 5 0
2806 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
2807 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
2808 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
2810 * Rt: the result register
2811 * Rn: base address or SP
2812 * Rs: the source register for the operation
2813 * V: vector flag (always 0 as of v8.3)
2817 static void disas_ldst_atomic(DisasContext
*s
, uint32_t insn
,
2818 int size
, int rt
, bool is_vector
)
2820 int rs
= extract32(insn
, 16, 5);
2821 int rn
= extract32(insn
, 5, 5);
2822 int o3_opc
= extract32(insn
, 12, 4);
2823 int feature
= ARM_FEATURE_V8_ATOMICS
;
2824 TCGv_i64 tcg_rn
, tcg_rs
;
2825 AtomicThreeOpFn
*fn
;
2828 unallocated_encoding(s
);
2832 case 000: /* LDADD */
2833 fn
= tcg_gen_atomic_fetch_add_i64
;
2835 case 001: /* LDCLR */
2836 fn
= tcg_gen_atomic_fetch_and_i64
;
2838 case 002: /* LDEOR */
2839 fn
= tcg_gen_atomic_fetch_xor_i64
;
2841 case 003: /* LDSET */
2842 fn
= tcg_gen_atomic_fetch_or_i64
;
2844 case 004: /* LDSMAX */
2845 fn
= tcg_gen_atomic_fetch_smax_i64
;
2847 case 005: /* LDSMIN */
2848 fn
= tcg_gen_atomic_fetch_smin_i64
;
2850 case 006: /* LDUMAX */
2851 fn
= tcg_gen_atomic_fetch_umax_i64
;
2853 case 007: /* LDUMIN */
2854 fn
= tcg_gen_atomic_fetch_umin_i64
;
2857 fn
= tcg_gen_atomic_xchg_i64
;
2860 unallocated_encoding(s
);
2863 if (!arm_dc_feature(s
, feature
)) {
2864 unallocated_encoding(s
);
2869 gen_check_sp_alignment(s
);
2871 tcg_rn
= cpu_reg_sp(s
, rn
);
2872 tcg_rs
= read_cpu_reg(s
, rs
, true);
2874 if (o3_opc
== 1) { /* LDCLR */
2875 tcg_gen_not_i64(tcg_rs
, tcg_rs
);
2878 /* The tcg atomic primitives are all full barriers. Therefore we
2879 * can ignore the Acquire and Release bits of this instruction.
2881 fn(cpu_reg(s
, rt
), tcg_rn
, tcg_rs
, get_mem_index(s
),
2882 s
->be_data
| size
| MO_ALIGN
);
2885 /* Load/store register (all forms) */
2886 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2888 int rt
= extract32(insn
, 0, 5);
2889 int opc
= extract32(insn
, 22, 2);
2890 bool is_vector
= extract32(insn
, 26, 1);
2891 int size
= extract32(insn
, 30, 2);
2893 switch (extract32(insn
, 24, 2)) {
2895 if (extract32(insn
, 21, 1) == 0) {
2896 /* Load/store register (unscaled immediate)
2897 * Load/store immediate pre/post-indexed
2898 * Load/store register unprivileged
2900 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
2903 switch (extract32(insn
, 10, 2)) {
2905 disas_ldst_atomic(s
, insn
, size
, rt
, is_vector
);
2908 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
2913 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
2916 unallocated_encoding(s
);
2919 /* AdvSIMD load/store multiple structures
2921 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2922 * +---+---+---------------+---+-------------+--------+------+------+------+
2923 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2924 * +---+---+---------------+---+-------------+--------+------+------+------+
2926 * AdvSIMD load/store multiple structures (post-indexed)
2928 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2929 * +---+---+---------------+---+---+---------+--------+------+------+------+
2930 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2931 * +---+---+---------------+---+---+---------+--------+------+------+------+
2933 * Rt: first (or only) SIMD&FP register to be transferred
2934 * Rn: base address or SP
2935 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2937 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
2939 int rt
= extract32(insn
, 0, 5);
2940 int rn
= extract32(insn
, 5, 5);
2941 int size
= extract32(insn
, 10, 2);
2942 int opcode
= extract32(insn
, 12, 4);
2943 bool is_store
= !extract32(insn
, 22, 1);
2944 bool is_postidx
= extract32(insn
, 23, 1);
2945 bool is_q
= extract32(insn
, 30, 1);
2946 TCGv_i64 tcg_addr
, tcg_rn
;
2948 int ebytes
= 1 << size
;
2949 int elements
= (is_q
? 128 : 64) / (8 << size
);
2950 int rpt
; /* num iterations */
2951 int selem
; /* structure elements */
2954 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
2955 unallocated_encoding(s
);
2959 /* From the shared decode logic */
2990 unallocated_encoding(s
);
2994 if (size
== 3 && !is_q
&& selem
!= 1) {
2996 unallocated_encoding(s
);
3000 if (!fp_access_check(s
)) {
3005 gen_check_sp_alignment(s
);
3008 tcg_rn
= cpu_reg_sp(s
, rn
);
3009 tcg_addr
= tcg_temp_new_i64();
3010 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
3012 for (r
= 0; r
< rpt
; r
++) {
3014 for (e
= 0; e
< elements
; e
++) {
3015 int tt
= (rt
+ r
) % 32;
3017 for (xs
= 0; xs
< selem
; xs
++) {
3019 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
3021 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
3023 /* For non-quad operations, setting a slice of the low
3024 * 64 bits of the register clears the high 64 bits (in
3025 * the ARM ARM pseudocode this is implicit in the fact
3026 * that 'rval' is a 64 bit wide variable).
3027 * For quad operations, we might still need to zero the
3028 * high bits of SVE. We optimize by noticing that we only
3029 * need to do this the first time we touch a register.
3031 if (e
== 0 && (r
== 0 || xs
== selem
- 1)) {
3032 clear_vec_high(s
, is_q
, tt
);
3035 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
3042 int rm
= extract32(insn
, 16, 5);
3044 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
3046 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3049 tcg_temp_free_i64(tcg_addr
);
3052 /* AdvSIMD load/store single structure
3054 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3055 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3056 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3057 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3059 * AdvSIMD load/store single structure (post-indexed)
3061 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3062 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3063 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3064 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3066 * Rt: first (or only) SIMD&FP register to be transferred
3067 * Rn: base address or SP
3068 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3069 * index = encoded in Q:S:size dependent on size
3071 * lane_size = encoded in R, opc
3072 * transfer width = encoded in opc, S, size
3074 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
3076 int rt
= extract32(insn
, 0, 5);
3077 int rn
= extract32(insn
, 5, 5);
3078 int size
= extract32(insn
, 10, 2);
3079 int S
= extract32(insn
, 12, 1);
3080 int opc
= extract32(insn
, 13, 3);
3081 int R
= extract32(insn
, 21, 1);
3082 int is_load
= extract32(insn
, 22, 1);
3083 int is_postidx
= extract32(insn
, 23, 1);
3084 int is_q
= extract32(insn
, 30, 1);
3086 int scale
= extract32(opc
, 1, 2);
3087 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
3088 bool replicate
= false;
3089 int index
= is_q
<< 3 | S
<< 2 | size
;
3091 TCGv_i64 tcg_addr
, tcg_rn
;
3095 if (!is_load
|| S
) {
3096 unallocated_encoding(s
);
3105 if (extract32(size
, 0, 1)) {
3106 unallocated_encoding(s
);
3112 if (extract32(size
, 1, 1)) {
3113 unallocated_encoding(s
);
3116 if (!extract32(size
, 0, 1)) {
3120 unallocated_encoding(s
);
3128 g_assert_not_reached();
3131 if (!fp_access_check(s
)) {
3135 ebytes
= 1 << scale
;
3138 gen_check_sp_alignment(s
);
3141 tcg_rn
= cpu_reg_sp(s
, rn
);
3142 tcg_addr
= tcg_temp_new_i64();
3143 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
3145 for (xs
= 0; xs
< selem
; xs
++) {
3147 /* Load and replicate to all elements */
3149 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3151 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
3152 get_mem_index(s
), s
->be_data
+ scale
);
3155 mulconst
= 0x0101010101010101ULL
;
3158 mulconst
= 0x0001000100010001ULL
;
3161 mulconst
= 0x0000000100000001ULL
;
3167 g_assert_not_reached();
3170 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
3172 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
3174 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
3176 tcg_temp_free_i64(tcg_tmp
);
3177 clear_vec_high(s
, is_q
, rt
);
3179 /* Load/store one element per register */
3181 do_vec_ld(s
, rt
, index
, tcg_addr
, scale
);
3183 do_vec_st(s
, rt
, index
, tcg_addr
, scale
);
3186 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
3191 int rm
= extract32(insn
, 16, 5);
3193 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
3195 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3198 tcg_temp_free_i64(tcg_addr
);
3201 /* Loads and stores */
3202 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
3204 switch (extract32(insn
, 24, 6)) {
3205 case 0x08: /* Load/store exclusive */
3206 disas_ldst_excl(s
, insn
);
3208 case 0x18: case 0x1c: /* Load register (literal) */
3209 disas_ld_lit(s
, insn
);
3211 case 0x28: case 0x29:
3212 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
3213 disas_ldst_pair(s
, insn
);
3215 case 0x38: case 0x39:
3216 case 0x3c: case 0x3d: /* Load/store register (all forms) */
3217 disas_ldst_reg(s
, insn
);
3219 case 0x0c: /* AdvSIMD load/store multiple structures */
3220 disas_ldst_multiple_struct(s
, insn
);
3222 case 0x0d: /* AdvSIMD load/store single structure */
3223 disas_ldst_single_struct(s
, insn
);
3226 unallocated_encoding(s
);
3231 /* PC-rel. addressing
3232 * 31 30 29 28 24 23 5 4 0
3233 * +----+-------+-----------+-------------------+------+
3234 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
3235 * +----+-------+-----------+-------------------+------+
3237 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
3239 unsigned int page
, rd
;
3243 page
= extract32(insn
, 31, 1);
3244 /* SignExtend(immhi:immlo) -> offset */
3245 offset
= sextract64(insn
, 5, 19);
3246 offset
= offset
<< 2 | extract32(insn
, 29, 2);
3247 rd
= extract32(insn
, 0, 5);
3251 /* ADRP (page based) */
3256 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
3260 * Add/subtract (immediate)
3262 * 31 30 29 28 24 23 22 21 10 9 5 4 0
3263 * +--+--+--+-----------+-----+-------------+-----+-----+
3264 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
3265 * +--+--+--+-----------+-----+-------------+-----+-----+
3267 * sf: 0 -> 32bit, 1 -> 64bit
3268 * op: 0 -> add , 1 -> sub
3270 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
3272 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
3274 int rd
= extract32(insn
, 0, 5);
3275 int rn
= extract32(insn
, 5, 5);
3276 uint64_t imm
= extract32(insn
, 10, 12);
3277 int shift
= extract32(insn
, 22, 2);
3278 bool setflags
= extract32(insn
, 29, 1);
3279 bool sub_op
= extract32(insn
, 30, 1);
3280 bool is_64bit
= extract32(insn
, 31, 1);
3282 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
3283 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
3284 TCGv_i64 tcg_result
;
3293 unallocated_encoding(s
);
3297 tcg_result
= tcg_temp_new_i64();
3300 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
3302 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
3305 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
3307 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3309 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3311 tcg_temp_free_i64(tcg_imm
);
3315 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3317 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3320 tcg_temp_free_i64(tcg_result
);
3323 /* The input should be a value in the bottom e bits (with higher
3324 * bits zero); returns that value replicated into every element
3325 * of size e in a 64 bit integer.
3327 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
3337 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
3338 static inline uint64_t bitmask64(unsigned int length
)
3340 assert(length
> 0 && length
<= 64);
3341 return ~0ULL >> (64 - length
);
3344 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
3345 * only require the wmask. Returns false if the imms/immr/immn are a reserved
3346 * value (ie should cause a guest UNDEF exception), and true if they are
3347 * valid, in which case the decoded bit pattern is written to result.
3349 bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
3350 unsigned int imms
, unsigned int immr
)
3353 unsigned e
, levels
, s
, r
;
3356 assert(immn
< 2 && imms
< 64 && immr
< 64);
3358 /* The bit patterns we create here are 64 bit patterns which
3359 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
3360 * 64 bits each. Each element contains the same value: a run
3361 * of between 1 and e-1 non-zero bits, rotated within the
3362 * element by between 0 and e-1 bits.
3364 * The element size and run length are encoded into immn (1 bit)
3365 * and imms (6 bits) as follows:
3366 * 64 bit elements: immn = 1, imms = <length of run - 1>
3367 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
3368 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
3369 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
3370 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
3371 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
3372 * Notice that immn = 0, imms = 11111x is the only combination
3373 * not covered by one of the above options; this is reserved.
3374 * Further, <length of run - 1> all-ones is a reserved pattern.
3376 * In all cases the rotation is by immr % e (and immr is 6 bits).
3379 /* First determine the element size */
3380 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
3382 /* This is the immn == 0, imms == 0x11111x case */
3392 /* <length of run - 1> mustn't be all-ones. */
3396 /* Create the value of one element: s+1 set bits rotated
3397 * by r within the element (which is e bits wide)...
3399 mask
= bitmask64(s
+ 1);
3401 mask
= (mask
>> r
) | (mask
<< (e
- r
));
3402 mask
&= bitmask64(e
);
3404 /* ...then replicate the element over the whole 64 bit value */
3405 mask
= bitfield_replicate(mask
, e
);
3410 /* Logical (immediate)
3411 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3412 * +----+-----+-------------+---+------+------+------+------+
3413 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
3414 * +----+-----+-------------+---+------+------+------+------+
3416 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
3418 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
3419 TCGv_i64 tcg_rd
, tcg_rn
;
3421 bool is_and
= false;
3423 sf
= extract32(insn
, 31, 1);
3424 opc
= extract32(insn
, 29, 2);
3425 is_n
= extract32(insn
, 22, 1);
3426 immr
= extract32(insn
, 16, 6);
3427 imms
= extract32(insn
, 10, 6);
3428 rn
= extract32(insn
, 5, 5);
3429 rd
= extract32(insn
, 0, 5);
3432 unallocated_encoding(s
);
3436 if (opc
== 0x3) { /* ANDS */
3437 tcg_rd
= cpu_reg(s
, rd
);
3439 tcg_rd
= cpu_reg_sp(s
, rd
);
3441 tcg_rn
= cpu_reg(s
, rn
);
3443 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
3444 /* some immediate field values are reserved */
3445 unallocated_encoding(s
);
3450 wmask
&= 0xffffffff;
3454 case 0x3: /* ANDS */
3456 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
3460 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
3463 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
3466 assert(FALSE
); /* must handle all above */
3470 if (!sf
&& !is_and
) {
3471 /* zero extend final result; we know we can skip this for AND
3472 * since the immediate had the high 32 bits clear.
3474 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3477 if (opc
== 3) { /* ANDS */
3478 gen_logic_CC(sf
, tcg_rd
);
3483 * Move wide (immediate)
3485 * 31 30 29 28 23 22 21 20 5 4 0
3486 * +--+-----+-------------+-----+----------------+------+
3487 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
3488 * +--+-----+-------------+-----+----------------+------+
3490 * sf: 0 -> 32 bit, 1 -> 64 bit
3491 * opc: 00 -> N, 10 -> Z, 11 -> K
3492 * hw: shift/16 (0,16, and sf only 32, 48)
3494 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
3496 int rd
= extract32(insn
, 0, 5);
3497 uint64_t imm
= extract32(insn
, 5, 16);
3498 int sf
= extract32(insn
, 31, 1);
3499 int opc
= extract32(insn
, 29, 2);
3500 int pos
= extract32(insn
, 21, 2) << 4;
3501 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3504 if (!sf
&& (pos
>= 32)) {
3505 unallocated_encoding(s
);
3519 tcg_gen_movi_i64(tcg_rd
, imm
);
3522 tcg_imm
= tcg_const_i64(imm
);
3523 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
3524 tcg_temp_free_i64(tcg_imm
);
3526 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3530 unallocated_encoding(s
);
3536 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3537 * +----+-----+-------------+---+------+------+------+------+
3538 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3539 * +----+-----+-------------+---+------+------+------+------+
3541 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
3543 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
3544 TCGv_i64 tcg_rd
, tcg_tmp
;
3546 sf
= extract32(insn
, 31, 1);
3547 opc
= extract32(insn
, 29, 2);
3548 n
= extract32(insn
, 22, 1);
3549 ri
= extract32(insn
, 16, 6);
3550 si
= extract32(insn
, 10, 6);
3551 rn
= extract32(insn
, 5, 5);
3552 rd
= extract32(insn
, 0, 5);
3553 bitsize
= sf
? 64 : 32;
3555 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
3556 unallocated_encoding(s
);
3560 tcg_rd
= cpu_reg(s
, rd
);
3562 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3563 to be smaller than bitsize, we'll never reference data outside the
3564 low 32-bits anyway. */
3565 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
3567 /* Recognize simple(r) extractions. */
3569 /* Wd<s-r:0> = Wn<s:r> */
3570 len
= (si
- ri
) + 1;
3571 if (opc
== 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
3572 tcg_gen_sextract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3574 } else if (opc
== 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
3575 tcg_gen_extract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3578 /* opc == 1, BXFIL fall through to deposit */
3579 tcg_gen_extract_i64(tcg_tmp
, tcg_tmp
, ri
, len
);
3582 /* Handle the ri > si case with a deposit
3583 * Wd<32+s-r,32-r> = Wn<s:0>
3586 pos
= (bitsize
- ri
) & (bitsize
- 1);
3589 if (opc
== 0 && len
< ri
) {
3590 /* SBFM: sign extend the destination field from len to fill
3591 the balance of the word. Let the deposit below insert all
3592 of those sign bits. */
3593 tcg_gen_sextract_i64(tcg_tmp
, tcg_tmp
, 0, len
);
3597 if (opc
== 1) { /* BFM, BXFIL */
3598 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
3600 /* SBFM or UBFM: We start with zero, and we haven't modified
3601 any bits outside bitsize, therefore the zero-extension
3602 below is unneeded. */
3603 tcg_gen_deposit_z_i64(tcg_rd
, tcg_tmp
, pos
, len
);
3608 if (!sf
) { /* zero extend final result */
3609 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3614 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3615 * +----+------+-------------+---+----+------+--------+------+------+
3616 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3617 * +----+------+-------------+---+----+------+--------+------+------+
3619 static void disas_extract(DisasContext
*s
, uint32_t insn
)
3621 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
3623 sf
= extract32(insn
, 31, 1);
3624 n
= extract32(insn
, 22, 1);
3625 rm
= extract32(insn
, 16, 5);
3626 imm
= extract32(insn
, 10, 6);
3627 rn
= extract32(insn
, 5, 5);
3628 rd
= extract32(insn
, 0, 5);
3629 op21
= extract32(insn
, 29, 2);
3630 op0
= extract32(insn
, 21, 1);
3631 bitsize
= sf
? 64 : 32;
3633 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
3634 unallocated_encoding(s
);
3636 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
3638 tcg_rd
= cpu_reg(s
, rd
);
3640 if (unlikely(imm
== 0)) {
3641 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3642 * so an extract from bit 0 is a special case.
3645 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
3647 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
3649 } else if (rm
== rn
) { /* ROR */
3650 tcg_rm
= cpu_reg(s
, rm
);
3652 tcg_gen_rotri_i64(tcg_rd
, tcg_rm
, imm
);
3654 TCGv_i32 tmp
= tcg_temp_new_i32();
3655 tcg_gen_extrl_i64_i32(tmp
, tcg_rm
);
3656 tcg_gen_rotri_i32(tmp
, tmp
, imm
);
3657 tcg_gen_extu_i32_i64(tcg_rd
, tmp
);
3658 tcg_temp_free_i32(tmp
);
3661 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3662 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3663 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
3664 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
3665 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
3667 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3673 /* Data processing - immediate */
3674 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
3676 switch (extract32(insn
, 23, 6)) {
3677 case 0x20: case 0x21: /* PC-rel. addressing */
3678 disas_pc_rel_adr(s
, insn
);
3680 case 0x22: case 0x23: /* Add/subtract (immediate) */
3681 disas_add_sub_imm(s
, insn
);
3683 case 0x24: /* Logical (immediate) */
3684 disas_logic_imm(s
, insn
);
3686 case 0x25: /* Move wide (immediate) */
3687 disas_movw_imm(s
, insn
);
3689 case 0x26: /* Bitfield */
3690 disas_bitfield(s
, insn
);
3692 case 0x27: /* Extract */
3693 disas_extract(s
, insn
);
3696 unallocated_encoding(s
);
3701 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3702 * Note that it is the caller's responsibility to ensure that the
3703 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3704 * mandated semantics for out of range shifts.
3706 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3707 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
3709 switch (shift_type
) {
3710 case A64_SHIFT_TYPE_LSL
:
3711 tcg_gen_shl_i64(dst
, src
, shift_amount
);
3713 case A64_SHIFT_TYPE_LSR
:
3714 tcg_gen_shr_i64(dst
, src
, shift_amount
);
3716 case A64_SHIFT_TYPE_ASR
:
3718 tcg_gen_ext32s_i64(dst
, src
);
3720 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
3722 case A64_SHIFT_TYPE_ROR
:
3724 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
3727 t0
= tcg_temp_new_i32();
3728 t1
= tcg_temp_new_i32();
3729 tcg_gen_extrl_i64_i32(t0
, src
);
3730 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
3731 tcg_gen_rotr_i32(t0
, t0
, t1
);
3732 tcg_gen_extu_i32_i64(dst
, t0
);
3733 tcg_temp_free_i32(t0
);
3734 tcg_temp_free_i32(t1
);
3738 assert(FALSE
); /* all shift types should be handled */
3742 if (!sf
) { /* zero extend final result */
3743 tcg_gen_ext32u_i64(dst
, dst
);
3747 /* Shift a TCGv src by immediate, put result in dst.
3748 * The shift amount must be in range (this should always be true as the
3749 * relevant instructions will UNDEF on bad shift immediates).
3751 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3752 enum a64_shift_type shift_type
, unsigned int shift_i
)
3754 assert(shift_i
< (sf
? 64 : 32));
3757 tcg_gen_mov_i64(dst
, src
);
3759 TCGv_i64 shift_const
;
3761 shift_const
= tcg_const_i64(shift_i
);
3762 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
3763 tcg_temp_free_i64(shift_const
);
3767 /* Logical (shifted register)
3768 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3769 * +----+-----+-----------+-------+---+------+--------+------+------+
3770 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3771 * +----+-----+-----------+-------+---+------+--------+------+------+
3773 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
3775 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
3776 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
3778 sf
= extract32(insn
, 31, 1);
3779 opc
= extract32(insn
, 29, 2);
3780 shift_type
= extract32(insn
, 22, 2);
3781 invert
= extract32(insn
, 21, 1);
3782 rm
= extract32(insn
, 16, 5);
3783 shift_amount
= extract32(insn
, 10, 6);
3784 rn
= extract32(insn
, 5, 5);
3785 rd
= extract32(insn
, 0, 5);
3787 if (!sf
&& (shift_amount
& (1 << 5))) {
3788 unallocated_encoding(s
);
3792 tcg_rd
= cpu_reg(s
, rd
);
3794 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3795 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3796 * register-register MOV and MVN, so it is worth special casing.
3798 tcg_rm
= cpu_reg(s
, rm
);
3800 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3802 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3806 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3808 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3814 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3817 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3820 tcg_rn
= cpu_reg(s
, rn
);
3822 switch (opc
| (invert
<< 2)) {
3825 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3828 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3831 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3835 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3838 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3841 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3849 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3853 gen_logic_CC(sf
, tcg_rd
);
3858 * Add/subtract (extended register)
3860 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3861 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3862 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3863 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3865 * sf: 0 -> 32bit, 1 -> 64bit
3866 * op: 0 -> add , 1 -> sub
3869 * option: extension type (see DecodeRegExtend)
3870 * imm3: optional shift to Rm
3872 * Rd = Rn + LSL(extend(Rm), amount)
3874 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3876 int rd
= extract32(insn
, 0, 5);
3877 int rn
= extract32(insn
, 5, 5);
3878 int imm3
= extract32(insn
, 10, 3);
3879 int option
= extract32(insn
, 13, 3);
3880 int rm
= extract32(insn
, 16, 5);
3881 bool setflags
= extract32(insn
, 29, 1);
3882 bool sub_op
= extract32(insn
, 30, 1);
3883 bool sf
= extract32(insn
, 31, 1);
3885 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3887 TCGv_i64 tcg_result
;
3890 unallocated_encoding(s
);
3894 /* non-flag setting ops may use SP */
3896 tcg_rd
= cpu_reg_sp(s
, rd
);
3898 tcg_rd
= cpu_reg(s
, rd
);
3900 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3902 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3903 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3905 tcg_result
= tcg_temp_new_i64();
3909 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3911 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3915 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3917 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3922 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3924 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3927 tcg_temp_free_i64(tcg_result
);
3931 * Add/subtract (shifted register)
3933 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3934 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3935 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3936 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3938 * sf: 0 -> 32bit, 1 -> 64bit
3939 * op: 0 -> add , 1 -> sub
3941 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3942 * imm6: Shift amount to apply to Rm before the add/sub
3944 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
3946 int rd
= extract32(insn
, 0, 5);
3947 int rn
= extract32(insn
, 5, 5);
3948 int imm6
= extract32(insn
, 10, 6);
3949 int rm
= extract32(insn
, 16, 5);
3950 int shift_type
= extract32(insn
, 22, 2);
3951 bool setflags
= extract32(insn
, 29, 1);
3952 bool sub_op
= extract32(insn
, 30, 1);
3953 bool sf
= extract32(insn
, 31, 1);
3955 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3956 TCGv_i64 tcg_rn
, tcg_rm
;
3957 TCGv_i64 tcg_result
;
3959 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
3960 unallocated_encoding(s
);
3964 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3965 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3967 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
3969 tcg_result
= tcg_temp_new_i64();
3973 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3975 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3979 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3981 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3986 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3988 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3991 tcg_temp_free_i64(tcg_result
);
3994 /* Data-processing (3 source)
3996 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3997 * +--+------+-----------+------+------+----+------+------+------+
3998 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3999 * +--+------+-----------+------+------+----+------+------+------+
4001 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
4003 int rd
= extract32(insn
, 0, 5);
4004 int rn
= extract32(insn
, 5, 5);
4005 int ra
= extract32(insn
, 10, 5);
4006 int rm
= extract32(insn
, 16, 5);
4007 int op_id
= (extract32(insn
, 29, 3) << 4) |
4008 (extract32(insn
, 21, 3) << 1) |
4009 extract32(insn
, 15, 1);
4010 bool sf
= extract32(insn
, 31, 1);
4011 bool is_sub
= extract32(op_id
, 0, 1);
4012 bool is_high
= extract32(op_id
, 2, 1);
4013 bool is_signed
= false;
4018 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
4020 case 0x42: /* SMADDL */
4021 case 0x43: /* SMSUBL */
4022 case 0x44: /* SMULH */
4025 case 0x0: /* MADD (32bit) */
4026 case 0x1: /* MSUB (32bit) */
4027 case 0x40: /* MADD (64bit) */
4028 case 0x41: /* MSUB (64bit) */
4029 case 0x4a: /* UMADDL */
4030 case 0x4b: /* UMSUBL */
4031 case 0x4c: /* UMULH */
4034 unallocated_encoding(s
);
4039 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
4040 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4041 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4042 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
4045 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4047 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4050 tcg_temp_free_i64(low_bits
);
4054 tcg_op1
= tcg_temp_new_i64();
4055 tcg_op2
= tcg_temp_new_i64();
4056 tcg_tmp
= tcg_temp_new_i64();
4059 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
4060 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
4063 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
4064 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
4066 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
4067 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
4071 if (ra
== 31 && !is_sub
) {
4072 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
4073 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
4075 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
4077 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4079 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4084 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
4087 tcg_temp_free_i64(tcg_op1
);
4088 tcg_temp_free_i64(tcg_op2
);
4089 tcg_temp_free_i64(tcg_tmp
);
4092 /* Add/subtract (with carry)
4093 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
4094 * +--+--+--+------------------------+------+---------+------+-----+
4095 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
4096 * +--+--+--+------------------------+------+---------+------+-----+
4100 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
4102 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
4103 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
4105 if (extract32(insn
, 10, 6) != 0) {
4106 unallocated_encoding(s
);
4110 sf
= extract32(insn
, 31, 1);
4111 op
= extract32(insn
, 30, 1);
4112 setflags
= extract32(insn
, 29, 1);
4113 rm
= extract32(insn
, 16, 5);
4114 rn
= extract32(insn
, 5, 5);
4115 rd
= extract32(insn
, 0, 5);
4117 tcg_rd
= cpu_reg(s
, rd
);
4118 tcg_rn
= cpu_reg(s
, rn
);
4121 tcg_y
= new_tmp_a64(s
);
4122 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
4124 tcg_y
= cpu_reg(s
, rm
);
4128 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4130 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4134 /* Conditional compare (immediate / register)
4135 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4136 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4137 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
4138 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4141 static void disas_cc(DisasContext
*s
, uint32_t insn
)
4143 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
4144 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
4145 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
4148 if (!extract32(insn
, 29, 1)) {
4149 unallocated_encoding(s
);
4152 if (insn
& (1 << 10 | 1 << 4)) {
4153 unallocated_encoding(s
);
4156 sf
= extract32(insn
, 31, 1);
4157 op
= extract32(insn
, 30, 1);
4158 is_imm
= extract32(insn
, 11, 1);
4159 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
4160 cond
= extract32(insn
, 12, 4);
4161 rn
= extract32(insn
, 5, 5);
4162 nzcv
= extract32(insn
, 0, 4);
4164 /* Set T0 = !COND. */
4165 tcg_t0
= tcg_temp_new_i32();
4166 arm_test_cc(&c
, cond
);
4167 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
4170 /* Load the arguments for the new comparison. */
4172 tcg_y
= new_tmp_a64(s
);
4173 tcg_gen_movi_i64(tcg_y
, y
);
4175 tcg_y
= cpu_reg(s
, y
);
4177 tcg_rn
= cpu_reg(s
, rn
);
4179 /* Set the flags for the new comparison. */
4180 tcg_tmp
= tcg_temp_new_i64();
4182 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4184 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4186 tcg_temp_free_i64(tcg_tmp
);
4188 /* If COND was false, force the flags to #nzcv. Compute two masks
4189 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
4190 * For tcg hosts that support ANDC, we can make do with just T1.
4191 * In either case, allow the tcg optimizer to delete any unused mask.
4193 tcg_t1
= tcg_temp_new_i32();
4194 tcg_t2
= tcg_temp_new_i32();
4195 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
4196 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
4198 if (nzcv
& 8) { /* N */
4199 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4201 if (TCG_TARGET_HAS_andc_i32
) {
4202 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4204 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
4207 if (nzcv
& 4) { /* Z */
4208 if (TCG_TARGET_HAS_andc_i32
) {
4209 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
4211 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
4214 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
4216 if (nzcv
& 2) { /* C */
4217 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
4219 if (TCG_TARGET_HAS_andc_i32
) {
4220 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
4222 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
4225 if (nzcv
& 1) { /* V */
4226 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4228 if (TCG_TARGET_HAS_andc_i32
) {
4229 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4231 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
4234 tcg_temp_free_i32(tcg_t0
);
4235 tcg_temp_free_i32(tcg_t1
);
4236 tcg_temp_free_i32(tcg_t2
);
4239 /* Conditional select
4240 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
4241 * +----+----+---+-----------------+------+------+-----+------+------+
4242 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
4243 * +----+----+---+-----------------+------+------+-----+------+------+
4245 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
4247 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
4248 TCGv_i64 tcg_rd
, zero
;
4251 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
4252 /* S == 1 or op2<1> == 1 */
4253 unallocated_encoding(s
);
4256 sf
= extract32(insn
, 31, 1);
4257 else_inv
= extract32(insn
, 30, 1);
4258 rm
= extract32(insn
, 16, 5);
4259 cond
= extract32(insn
, 12, 4);
4260 else_inc
= extract32(insn
, 10, 1);
4261 rn
= extract32(insn
, 5, 5);
4262 rd
= extract32(insn
, 0, 5);
4264 tcg_rd
= cpu_reg(s
, rd
);
4266 a64_test_cc(&c
, cond
);
4267 zero
= tcg_const_i64(0);
4269 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
4271 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
4273 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
4276 TCGv_i64 t_true
= cpu_reg(s
, rn
);
4277 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
4278 if (else_inv
&& else_inc
) {
4279 tcg_gen_neg_i64(t_false
, t_false
);
4280 } else if (else_inv
) {
4281 tcg_gen_not_i64(t_false
, t_false
);
4282 } else if (else_inc
) {
4283 tcg_gen_addi_i64(t_false
, t_false
, 1);
4285 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
4288 tcg_temp_free_i64(zero
);
4292 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4296 static void handle_clz(DisasContext
*s
, unsigned int sf
,
4297 unsigned int rn
, unsigned int rd
)
4299 TCGv_i64 tcg_rd
, tcg_rn
;
4300 tcg_rd
= cpu_reg(s
, rd
);
4301 tcg_rn
= cpu_reg(s
, rn
);
4304 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
4306 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4307 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4308 tcg_gen_clzi_i32(tcg_tmp32
, tcg_tmp32
, 32);
4309 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4310 tcg_temp_free_i32(tcg_tmp32
);
4314 static void handle_cls(DisasContext
*s
, unsigned int sf
,
4315 unsigned int rn
, unsigned int rd
)
4317 TCGv_i64 tcg_rd
, tcg_rn
;
4318 tcg_rd
= cpu_reg(s
, rd
);
4319 tcg_rn
= cpu_reg(s
, rn
);
4322 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
4324 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4325 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4326 tcg_gen_clrsb_i32(tcg_tmp32
, tcg_tmp32
);
4327 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4328 tcg_temp_free_i32(tcg_tmp32
);
4332 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
4333 unsigned int rn
, unsigned int rd
)
4335 TCGv_i64 tcg_rd
, tcg_rn
;
4336 tcg_rd
= cpu_reg(s
, rd
);
4337 tcg_rn
= cpu_reg(s
, rn
);
4340 gen_helper_rbit64(tcg_rd
, tcg_rn
);
4342 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4343 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4344 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
4345 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4346 tcg_temp_free_i32(tcg_tmp32
);
4350 /* REV with sf==1, opcode==3 ("REV64") */
4351 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
4352 unsigned int rn
, unsigned int rd
)
4355 unallocated_encoding(s
);
4358 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
4361 /* REV with sf==0, opcode==2
4362 * REV32 (sf==1, opcode==2)
4364 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
4365 unsigned int rn
, unsigned int rd
)
4367 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4370 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4371 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4373 /* bswap32_i64 requires zero high word */
4374 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
4375 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
4376 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
4377 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
4378 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4380 tcg_temp_free_i64(tcg_tmp
);
4382 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
4383 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
4387 /* REV16 (opcode==1) */
4388 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
4389 unsigned int rn
, unsigned int rd
)
4391 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4392 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4393 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4394 TCGv_i64 mask
= tcg_const_i64(sf
? 0x00ff00ff00ff00ffull
: 0x00ff00ff);
4396 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 8);
4397 tcg_gen_and_i64(tcg_rd
, tcg_rn
, mask
);
4398 tcg_gen_and_i64(tcg_tmp
, tcg_tmp
, mask
);
4399 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 8);
4400 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4402 tcg_temp_free_i64(mask
);
4403 tcg_temp_free_i64(tcg_tmp
);
4406 /* Data-processing (1 source)
4407 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4408 * +----+---+---+-----------------+---------+--------+------+------+
4409 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
4410 * +----+---+---+-----------------+---------+--------+------+------+
4412 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
4414 unsigned int sf
, opcode
, rn
, rd
;
4416 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
4417 unallocated_encoding(s
);
4421 sf
= extract32(insn
, 31, 1);
4422 opcode
= extract32(insn
, 10, 6);
4423 rn
= extract32(insn
, 5, 5);
4424 rd
= extract32(insn
, 0, 5);
4428 handle_rbit(s
, sf
, rn
, rd
);
4431 handle_rev16(s
, sf
, rn
, rd
);
4434 handle_rev32(s
, sf
, rn
, rd
);
4437 handle_rev64(s
, sf
, rn
, rd
);
4440 handle_clz(s
, sf
, rn
, rd
);
4443 handle_cls(s
, sf
, rn
, rd
);
4448 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
4449 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4451 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
4452 tcg_rd
= cpu_reg(s
, rd
);
4454 if (!sf
&& is_signed
) {
4455 tcg_n
= new_tmp_a64(s
);
4456 tcg_m
= new_tmp_a64(s
);
4457 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
4458 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
4460 tcg_n
= read_cpu_reg(s
, rn
, sf
);
4461 tcg_m
= read_cpu_reg(s
, rm
, sf
);
4465 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
4467 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
4470 if (!sf
) { /* zero extend final result */
4471 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4475 /* LSLV, LSRV, ASRV, RORV */
4476 static void handle_shift_reg(DisasContext
*s
,
4477 enum a64_shift_type shift_type
, unsigned int sf
,
4478 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4480 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
4481 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4482 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4484 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
4485 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
4486 tcg_temp_free_i64(tcg_shift
);
4489 /* CRC32[BHWX], CRC32C[BHWX] */
4490 static void handle_crc32(DisasContext
*s
,
4491 unsigned int sf
, unsigned int sz
, bool crc32c
,
4492 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4494 TCGv_i64 tcg_acc
, tcg_val
;
4497 if (!arm_dc_feature(s
, ARM_FEATURE_CRC
)
4498 || (sf
== 1 && sz
!= 3)
4499 || (sf
== 0 && sz
== 3)) {
4500 unallocated_encoding(s
);
4505 tcg_val
= cpu_reg(s
, rm
);
4519 g_assert_not_reached();
4521 tcg_val
= new_tmp_a64(s
);
4522 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
4525 tcg_acc
= cpu_reg(s
, rn
);
4526 tcg_bytes
= tcg_const_i32(1 << sz
);
4529 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4531 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4534 tcg_temp_free_i32(tcg_bytes
);
4537 /* Data-processing (2 source)
4538 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4539 * +----+---+---+-----------------+------+--------+------+------+
4540 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
4541 * +----+---+---+-----------------+------+--------+------+------+
4543 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
4545 unsigned int sf
, rm
, opcode
, rn
, rd
;
4546 sf
= extract32(insn
, 31, 1);
4547 rm
= extract32(insn
, 16, 5);
4548 opcode
= extract32(insn
, 10, 6);
4549 rn
= extract32(insn
, 5, 5);
4550 rd
= extract32(insn
, 0, 5);
4552 if (extract32(insn
, 29, 1)) {
4553 unallocated_encoding(s
);
4559 handle_div(s
, false, sf
, rm
, rn
, rd
);
4562 handle_div(s
, true, sf
, rm
, rn
, rd
);
4565 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
4568 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
4571 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
4574 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
4583 case 23: /* CRC32 */
4585 int sz
= extract32(opcode
, 0, 2);
4586 bool crc32c
= extract32(opcode
, 2, 1);
4587 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
4591 unallocated_encoding(s
);
4596 /* Data processing - register */
4597 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
4599 switch (extract32(insn
, 24, 5)) {
4600 case 0x0a: /* Logical (shifted register) */
4601 disas_logic_reg(s
, insn
);
4603 case 0x0b: /* Add/subtract */
4604 if (insn
& (1 << 21)) { /* (extended register) */
4605 disas_add_sub_ext_reg(s
, insn
);
4607 disas_add_sub_reg(s
, insn
);
4610 case 0x1b: /* Data-processing (3 source) */
4611 disas_data_proc_3src(s
, insn
);
4614 switch (extract32(insn
, 21, 3)) {
4615 case 0x0: /* Add/subtract (with carry) */
4616 disas_adc_sbc(s
, insn
);
4618 case 0x2: /* Conditional compare */
4619 disas_cc(s
, insn
); /* both imm and reg forms */
4621 case 0x4: /* Conditional select */
4622 disas_cond_select(s
, insn
);
4624 case 0x6: /* Data-processing */
4625 if (insn
& (1 << 30)) { /* (1 source) */
4626 disas_data_proc_1src(s
, insn
);
4627 } else { /* (2 source) */
4628 disas_data_proc_2src(s
, insn
);
4632 unallocated_encoding(s
);
4637 unallocated_encoding(s
);
4642 static void handle_fp_compare(DisasContext
*s
, int size
,
4643 unsigned int rn
, unsigned int rm
,
4644 bool cmp_with_zero
, bool signal_all_nans
)
4646 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
4647 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
4649 if (size
== MO_64
) {
4650 TCGv_i64 tcg_vn
, tcg_vm
;
4652 tcg_vn
= read_fp_dreg(s
, rn
);
4653 if (cmp_with_zero
) {
4654 tcg_vm
= tcg_const_i64(0);
4656 tcg_vm
= read_fp_dreg(s
, rm
);
4658 if (signal_all_nans
) {
4659 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4661 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4663 tcg_temp_free_i64(tcg_vn
);
4664 tcg_temp_free_i64(tcg_vm
);
4666 TCGv_i32 tcg_vn
= tcg_temp_new_i32();
4667 TCGv_i32 tcg_vm
= tcg_temp_new_i32();
4669 read_vec_element_i32(s
, tcg_vn
, rn
, 0, size
);
4670 if (cmp_with_zero
) {
4671 tcg_gen_movi_i32(tcg_vm
, 0);
4673 read_vec_element_i32(s
, tcg_vm
, rm
, 0, size
);
4678 if (signal_all_nans
) {
4679 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4681 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4685 if (signal_all_nans
) {
4686 gen_helper_vfp_cmpeh_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4688 gen_helper_vfp_cmph_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4692 g_assert_not_reached();
4695 tcg_temp_free_i32(tcg_vn
);
4696 tcg_temp_free_i32(tcg_vm
);
4699 tcg_temp_free_ptr(fpst
);
4701 gen_set_nzcv(tcg_flags
);
4703 tcg_temp_free_i64(tcg_flags
);
4706 /* Floating point compare
4707 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
4708 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4709 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
4710 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4712 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
4714 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
4717 mos
= extract32(insn
, 29, 3);
4718 type
= extract32(insn
, 22, 2);
4719 rm
= extract32(insn
, 16, 5);
4720 op
= extract32(insn
, 14, 2);
4721 rn
= extract32(insn
, 5, 5);
4722 opc
= extract32(insn
, 3, 2);
4723 op2r
= extract32(insn
, 0, 3);
4725 if (mos
|| op
|| op2r
) {
4726 unallocated_encoding(s
);
4739 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
4744 unallocated_encoding(s
);
4748 if (!fp_access_check(s
)) {
4752 handle_fp_compare(s
, size
, rn
, rm
, opc
& 1, opc
& 2);
4755 /* Floating point conditional compare
4756 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4757 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4758 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
4759 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4761 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
4763 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
4765 TCGLabel
*label_continue
= NULL
;
4768 mos
= extract32(insn
, 29, 3);
4769 type
= extract32(insn
, 22, 2);
4770 rm
= extract32(insn
, 16, 5);
4771 cond
= extract32(insn
, 12, 4);
4772 rn
= extract32(insn
, 5, 5);
4773 op
= extract32(insn
, 4, 1);
4774 nzcv
= extract32(insn
, 0, 4);
4777 unallocated_encoding(s
);
4790 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
4795 unallocated_encoding(s
);
4799 if (!fp_access_check(s
)) {
4803 if (cond
< 0x0e) { /* not always */
4804 TCGLabel
*label_match
= gen_new_label();
4805 label_continue
= gen_new_label();
4806 arm_gen_test_cc(cond
, label_match
);
4808 tcg_flags
= tcg_const_i64(nzcv
<< 28);
4809 gen_set_nzcv(tcg_flags
);
4810 tcg_temp_free_i64(tcg_flags
);
4811 tcg_gen_br(label_continue
);
4812 gen_set_label(label_match
);
4815 handle_fp_compare(s
, size
, rn
, rm
, false, op
);
4818 gen_set_label(label_continue
);
4822 /* Floating point conditional select
4823 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4824 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4825 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
4826 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4828 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
4830 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
4831 TCGv_i64 t_true
, t_false
, t_zero
;
4835 mos
= extract32(insn
, 29, 3);
4836 type
= extract32(insn
, 22, 2);
4837 rm
= extract32(insn
, 16, 5);
4838 cond
= extract32(insn
, 12, 4);
4839 rn
= extract32(insn
, 5, 5);
4840 rd
= extract32(insn
, 0, 5);
4843 unallocated_encoding(s
);
4856 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
4861 unallocated_encoding(s
);
4865 if (!fp_access_check(s
)) {
4869 /* Zero extend sreg & hreg inputs to 64 bits now. */
4870 t_true
= tcg_temp_new_i64();
4871 t_false
= tcg_temp_new_i64();
4872 read_vec_element(s
, t_true
, rn
, 0, sz
);
4873 read_vec_element(s
, t_false
, rm
, 0, sz
);
4875 a64_test_cc(&c
, cond
);
4876 t_zero
= tcg_const_i64(0);
4877 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, t_zero
, t_true
, t_false
);
4878 tcg_temp_free_i64(t_zero
);
4879 tcg_temp_free_i64(t_false
);
4882 /* Note that sregs & hregs write back zeros to the high bits,
4883 and we've already done the zero-extension. */
4884 write_fp_dreg(s
, rd
, t_true
);
4885 tcg_temp_free_i64(t_true
);
4888 /* Floating-point data-processing (1 source) - half precision */
4889 static void handle_fp_1src_half(DisasContext
*s
, int opcode
, int rd
, int rn
)
4891 TCGv_ptr fpst
= NULL
;
4892 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
4893 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4896 case 0x0: /* FMOV */
4897 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4899 case 0x1: /* FABS */
4900 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
4902 case 0x2: /* FNEG */
4903 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
4905 case 0x3: /* FSQRT */
4906 fpst
= get_fpstatus_ptr(true);
4907 gen_helper_sqrt_f16(tcg_res
, tcg_op
, fpst
);
4909 case 0x8: /* FRINTN */
4910 case 0x9: /* FRINTP */
4911 case 0xa: /* FRINTM */
4912 case 0xb: /* FRINTZ */
4913 case 0xc: /* FRINTA */
4915 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4916 fpst
= get_fpstatus_ptr(true);
4918 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
4919 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
4921 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
4922 tcg_temp_free_i32(tcg_rmode
);
4925 case 0xe: /* FRINTX */
4926 fpst
= get_fpstatus_ptr(true);
4927 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, fpst
);
4929 case 0xf: /* FRINTI */
4930 fpst
= get_fpstatus_ptr(true);
4931 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
4937 write_fp_sreg(s
, rd
, tcg_res
);
4940 tcg_temp_free_ptr(fpst
);
4942 tcg_temp_free_i32(tcg_op
);
4943 tcg_temp_free_i32(tcg_res
);
4946 /* Floating-point data-processing (1 source) - single precision */
4947 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
4953 fpst
= get_fpstatus_ptr(false);
4954 tcg_op
= read_fp_sreg(s
, rn
);
4955 tcg_res
= tcg_temp_new_i32();
4958 case 0x0: /* FMOV */
4959 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4961 case 0x1: /* FABS */
4962 gen_helper_vfp_abss(tcg_res
, tcg_op
);
4964 case 0x2: /* FNEG */
4965 gen_helper_vfp_negs(tcg_res
, tcg_op
);
4967 case 0x3: /* FSQRT */
4968 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
4970 case 0x8: /* FRINTN */
4971 case 0x9: /* FRINTP */
4972 case 0xa: /* FRINTM */
4973 case 0xb: /* FRINTZ */
4974 case 0xc: /* FRINTA */
4976 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4978 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
4979 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4981 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
4982 tcg_temp_free_i32(tcg_rmode
);
4985 case 0xe: /* FRINTX */
4986 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
4988 case 0xf: /* FRINTI */
4989 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4995 write_fp_sreg(s
, rd
, tcg_res
);
4997 tcg_temp_free_ptr(fpst
);
4998 tcg_temp_free_i32(tcg_op
);
4999 tcg_temp_free_i32(tcg_res
);
5002 /* Floating-point data-processing (1 source) - double precision */
5003 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
5010 case 0x0: /* FMOV */
5011 gen_gvec_fn2(s
, false, rd
, rn
, tcg_gen_gvec_mov
, 0);
5015 fpst
= get_fpstatus_ptr(false);
5016 tcg_op
= read_fp_dreg(s
, rn
);
5017 tcg_res
= tcg_temp_new_i64();
5020 case 0x1: /* FABS */
5021 gen_helper_vfp_absd(tcg_res
, tcg_op
);
5023 case 0x2: /* FNEG */
5024 gen_helper_vfp_negd(tcg_res
, tcg_op
);
5026 case 0x3: /* FSQRT */
5027 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
5029 case 0x8: /* FRINTN */
5030 case 0x9: /* FRINTP */
5031 case 0xa: /* FRINTM */
5032 case 0xb: /* FRINTZ */
5033 case 0xc: /* FRINTA */
5035 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
5037 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5038 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
5040 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5041 tcg_temp_free_i32(tcg_rmode
);
5044 case 0xe: /* FRINTX */
5045 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
5047 case 0xf: /* FRINTI */
5048 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
5054 write_fp_dreg(s
, rd
, tcg_res
);
5056 tcg_temp_free_ptr(fpst
);
5057 tcg_temp_free_i64(tcg_op
);
5058 tcg_temp_free_i64(tcg_res
);
5061 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
5062 int rd
, int rn
, int dtype
, int ntype
)
5067 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5069 /* Single to double */
5070 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5071 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
5072 write_fp_dreg(s
, rd
, tcg_rd
);
5073 tcg_temp_free_i64(tcg_rd
);
5075 /* Single to half */
5076 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5077 TCGv_i32 ahp
= get_ahp_flag();
5078 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5080 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5081 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5082 write_fp_sreg(s
, rd
, tcg_rd
);
5083 tcg_temp_free_i32(tcg_rd
);
5084 tcg_temp_free_i32(ahp
);
5085 tcg_temp_free_ptr(fpst
);
5087 tcg_temp_free_i32(tcg_rn
);
5092 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
5093 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5095 /* Double to single */
5096 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
5098 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5099 TCGv_i32 ahp
= get_ahp_flag();
5100 /* Double to half */
5101 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5102 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5103 tcg_temp_free_ptr(fpst
);
5104 tcg_temp_free_i32(ahp
);
5106 write_fp_sreg(s
, rd
, tcg_rd
);
5107 tcg_temp_free_i32(tcg_rd
);
5108 tcg_temp_free_i64(tcg_rn
);
5113 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5114 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(false);
5115 TCGv_i32 tcg_ahp
= get_ahp_flag();
5116 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
5118 /* Half to single */
5119 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5120 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5121 write_fp_sreg(s
, rd
, tcg_rd
);
5122 tcg_temp_free_ptr(tcg_fpst
);
5123 tcg_temp_free_i32(tcg_ahp
);
5124 tcg_temp_free_i32(tcg_rd
);
5126 /* Half to double */
5127 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5128 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5129 write_fp_dreg(s
, rd
, tcg_rd
);
5130 tcg_temp_free_i64(tcg_rd
);
5132 tcg_temp_free_i32(tcg_rn
);
5140 /* Floating point data-processing (1 source)
5141 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
5142 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5143 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
5144 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5146 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
5148 int type
= extract32(insn
, 22, 2);
5149 int opcode
= extract32(insn
, 15, 6);
5150 int rn
= extract32(insn
, 5, 5);
5151 int rd
= extract32(insn
, 0, 5);
5154 case 0x4: case 0x5: case 0x7:
5156 /* FCVT between half, single and double precision */
5157 int dtype
= extract32(opcode
, 0, 2);
5158 if (type
== 2 || dtype
== type
) {
5159 unallocated_encoding(s
);
5162 if (!fp_access_check(s
)) {
5166 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
5172 /* 32-to-32 and 64-to-64 ops */
5175 if (!fp_access_check(s
)) {
5179 handle_fp_1src_single(s
, opcode
, rd
, rn
);
5182 if (!fp_access_check(s
)) {
5186 handle_fp_1src_double(s
, opcode
, rd
, rn
);
5189 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5190 unallocated_encoding(s
);
5194 if (!fp_access_check(s
)) {
5198 handle_fp_1src_half(s
, opcode
, rd
, rn
);
5201 unallocated_encoding(s
);
5205 unallocated_encoding(s
);
5210 /* Floating-point data-processing (2 source) - single precision */
5211 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
5212 int rd
, int rn
, int rm
)
5219 tcg_res
= tcg_temp_new_i32();
5220 fpst
= get_fpstatus_ptr(false);
5221 tcg_op1
= read_fp_sreg(s
, rn
);
5222 tcg_op2
= read_fp_sreg(s
, rm
);
5225 case 0x0: /* FMUL */
5226 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5228 case 0x1: /* FDIV */
5229 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5231 case 0x2: /* FADD */
5232 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5234 case 0x3: /* FSUB */
5235 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5237 case 0x4: /* FMAX */
5238 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5240 case 0x5: /* FMIN */
5241 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5243 case 0x6: /* FMAXNM */
5244 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5246 case 0x7: /* FMINNM */
5247 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5249 case 0x8: /* FNMUL */
5250 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5251 gen_helper_vfp_negs(tcg_res
, tcg_res
);
5255 write_fp_sreg(s
, rd
, tcg_res
);
5257 tcg_temp_free_ptr(fpst
);
5258 tcg_temp_free_i32(tcg_op1
);
5259 tcg_temp_free_i32(tcg_op2
);
5260 tcg_temp_free_i32(tcg_res
);
5263 /* Floating-point data-processing (2 source) - double precision */
5264 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
5265 int rd
, int rn
, int rm
)
5272 tcg_res
= tcg_temp_new_i64();
5273 fpst
= get_fpstatus_ptr(false);
5274 tcg_op1
= read_fp_dreg(s
, rn
);
5275 tcg_op2
= read_fp_dreg(s
, rm
);
5278 case 0x0: /* FMUL */
5279 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5281 case 0x1: /* FDIV */
5282 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5284 case 0x2: /* FADD */
5285 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5287 case 0x3: /* FSUB */
5288 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5290 case 0x4: /* FMAX */
5291 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5293 case 0x5: /* FMIN */
5294 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5296 case 0x6: /* FMAXNM */
5297 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5299 case 0x7: /* FMINNM */
5300 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5302 case 0x8: /* FNMUL */
5303 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5304 gen_helper_vfp_negd(tcg_res
, tcg_res
);
5308 write_fp_dreg(s
, rd
, tcg_res
);
5310 tcg_temp_free_ptr(fpst
);
5311 tcg_temp_free_i64(tcg_op1
);
5312 tcg_temp_free_i64(tcg_op2
);
5313 tcg_temp_free_i64(tcg_res
);
5316 /* Floating-point data-processing (2 source) - half precision */
5317 static void handle_fp_2src_half(DisasContext
*s
, int opcode
,
5318 int rd
, int rn
, int rm
)
5325 tcg_res
= tcg_temp_new_i32();
5326 fpst
= get_fpstatus_ptr(true);
5327 tcg_op1
= read_fp_hreg(s
, rn
);
5328 tcg_op2
= read_fp_hreg(s
, rm
);
5331 case 0x0: /* FMUL */
5332 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5334 case 0x1: /* FDIV */
5335 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5337 case 0x2: /* FADD */
5338 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5340 case 0x3: /* FSUB */
5341 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5343 case 0x4: /* FMAX */
5344 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5346 case 0x5: /* FMIN */
5347 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5349 case 0x6: /* FMAXNM */
5350 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5352 case 0x7: /* FMINNM */
5353 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5355 case 0x8: /* FNMUL */
5356 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5357 tcg_gen_xori_i32(tcg_res
, tcg_res
, 0x8000);
5360 g_assert_not_reached();
5363 write_fp_sreg(s
, rd
, tcg_res
);
5365 tcg_temp_free_ptr(fpst
);
5366 tcg_temp_free_i32(tcg_op1
);
5367 tcg_temp_free_i32(tcg_op2
);
5368 tcg_temp_free_i32(tcg_res
);
5371 /* Floating point data-processing (2 source)
5372 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5373 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5374 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
5375 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5377 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
5379 int type
= extract32(insn
, 22, 2);
5380 int rd
= extract32(insn
, 0, 5);
5381 int rn
= extract32(insn
, 5, 5);
5382 int rm
= extract32(insn
, 16, 5);
5383 int opcode
= extract32(insn
, 12, 4);
5386 unallocated_encoding(s
);
5392 if (!fp_access_check(s
)) {
5395 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
5398 if (!fp_access_check(s
)) {
5401 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
5404 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5405 unallocated_encoding(s
);
5408 if (!fp_access_check(s
)) {
5411 handle_fp_2src_half(s
, opcode
, rd
, rn
, rm
);
5414 unallocated_encoding(s
);
5418 /* Floating-point data-processing (3 source) - single precision */
5419 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
5420 int rd
, int rn
, int rm
, int ra
)
5422 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
5423 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5424 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5426 tcg_op1
= read_fp_sreg(s
, rn
);
5427 tcg_op2
= read_fp_sreg(s
, rm
);
5428 tcg_op3
= read_fp_sreg(s
, ra
);
5430 /* These are fused multiply-add, and must be done as one
5431 * floating point operation with no rounding between the
5432 * multiplication and addition steps.
5433 * NB that doing the negations here as separate steps is
5434 * correct : an input NaN should come out with its sign bit
5435 * flipped if it is a negated-input.
5438 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
5442 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
5445 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
5447 write_fp_sreg(s
, rd
, tcg_res
);
5449 tcg_temp_free_ptr(fpst
);
5450 tcg_temp_free_i32(tcg_op1
);
5451 tcg_temp_free_i32(tcg_op2
);
5452 tcg_temp_free_i32(tcg_op3
);
5453 tcg_temp_free_i32(tcg_res
);
5456 /* Floating-point data-processing (3 source) - double precision */
5457 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
5458 int rd
, int rn
, int rm
, int ra
)
5460 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
5461 TCGv_i64 tcg_res
= tcg_temp_new_i64();
5462 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5464 tcg_op1
= read_fp_dreg(s
, rn
);
5465 tcg_op2
= read_fp_dreg(s
, rm
);
5466 tcg_op3
= read_fp_dreg(s
, ra
);
5468 /* These are fused multiply-add, and must be done as one
5469 * floating point operation with no rounding between the
5470 * multiplication and addition steps.
5471 * NB that doing the negations here as separate steps is
5472 * correct : an input NaN should come out with its sign bit
5473 * flipped if it is a negated-input.
5476 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
5480 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
5483 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
5485 write_fp_dreg(s
, rd
, tcg_res
);
5487 tcg_temp_free_ptr(fpst
);
5488 tcg_temp_free_i64(tcg_op1
);
5489 tcg_temp_free_i64(tcg_op2
);
5490 tcg_temp_free_i64(tcg_op3
);
5491 tcg_temp_free_i64(tcg_res
);
5494 /* Floating-point data-processing (3 source) - half precision */
5495 static void handle_fp_3src_half(DisasContext
*s
, bool o0
, bool o1
,
5496 int rd
, int rn
, int rm
, int ra
)
5498 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
5499 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5500 TCGv_ptr fpst
= get_fpstatus_ptr(true);
5502 tcg_op1
= read_fp_hreg(s
, rn
);
5503 tcg_op2
= read_fp_hreg(s
, rm
);
5504 tcg_op3
= read_fp_hreg(s
, ra
);
5506 /* These are fused multiply-add, and must be done as one
5507 * floating point operation with no rounding between the
5508 * multiplication and addition steps.
5509 * NB that doing the negations here as separate steps is
5510 * correct : an input NaN should come out with its sign bit
5511 * flipped if it is a negated-input.
5514 tcg_gen_xori_i32(tcg_op3
, tcg_op3
, 0x8000);
5518 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
5521 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
5523 write_fp_sreg(s
, rd
, tcg_res
);
5525 tcg_temp_free_ptr(fpst
);
5526 tcg_temp_free_i32(tcg_op1
);
5527 tcg_temp_free_i32(tcg_op2
);
5528 tcg_temp_free_i32(tcg_op3
);
5529 tcg_temp_free_i32(tcg_res
);
5532 /* Floating point data-processing (3 source)
5533 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
5534 * +---+---+---+-----------+------+----+------+----+------+------+------+
5535 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
5536 * +---+---+---+-----------+------+----+------+----+------+------+------+
5538 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
5540 int type
= extract32(insn
, 22, 2);
5541 int rd
= extract32(insn
, 0, 5);
5542 int rn
= extract32(insn
, 5, 5);
5543 int ra
= extract32(insn
, 10, 5);
5544 int rm
= extract32(insn
, 16, 5);
5545 bool o0
= extract32(insn
, 15, 1);
5546 bool o1
= extract32(insn
, 21, 1);
5550 if (!fp_access_check(s
)) {
5553 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
5556 if (!fp_access_check(s
)) {
5559 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
5562 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5563 unallocated_encoding(s
);
5566 if (!fp_access_check(s
)) {
5569 handle_fp_3src_half(s
, o0
, o1
, rd
, rn
, rm
, ra
);
5572 unallocated_encoding(s
);
5576 /* The imm8 encodes the sign bit, enough bits to represent an exponent in
5577 * the range 01....1xx to 10....0xx, and the most significant 4 bits of
5578 * the mantissa; see VFPExpandImm() in the v8 ARM ARM.
5580 uint64_t vfp_expand_imm(int size
, uint8_t imm8
)
5586 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
5587 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
5588 extract32(imm8
, 0, 6);
5592 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
5593 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
5594 (extract32(imm8
, 0, 6) << 3);
5598 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
5599 (extract32(imm8
, 6, 1) ? 0x3000 : 0x4000) |
5600 (extract32(imm8
, 0, 6) << 6);
5603 g_assert_not_reached();
5608 /* Floating point immediate
5609 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
5610 * +---+---+---+-----------+------+---+------------+-------+------+------+
5611 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
5612 * +---+---+---+-----------+------+---+------------+-------+------+------+
5614 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
5616 int rd
= extract32(insn
, 0, 5);
5617 int imm8
= extract32(insn
, 13, 8);
5618 int type
= extract32(insn
, 22, 2);
5632 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5637 unallocated_encoding(s
);
5641 if (!fp_access_check(s
)) {
5645 imm
= vfp_expand_imm(sz
, imm8
);
5647 tcg_res
= tcg_const_i64(imm
);
5648 write_fp_dreg(s
, rd
, tcg_res
);
5649 tcg_temp_free_i64(tcg_res
);
5652 /* Handle floating point <=> fixed point conversions. Note that we can
5653 * also deal with fp <=> integer conversions as a special case (scale == 64)
5654 * OPTME: consider handling that special case specially or at least skipping
5655 * the call to scalbn in the helpers for zero shifts.
5657 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
5658 bool itof
, int rmode
, int scale
, int sf
, int type
)
5660 bool is_signed
= !(opcode
& 1);
5661 TCGv_ptr tcg_fpstatus
;
5662 TCGv_i32 tcg_shift
, tcg_single
;
5663 TCGv_i64 tcg_double
;
5665 tcg_fpstatus
= get_fpstatus_ptr(type
== 3);
5667 tcg_shift
= tcg_const_i32(64 - scale
);
5670 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
5672 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
5675 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
5677 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
5680 tcg_int
= tcg_extend
;
5684 case 1: /* float64 */
5685 tcg_double
= tcg_temp_new_i64();
5687 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
5688 tcg_shift
, tcg_fpstatus
);
5690 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
5691 tcg_shift
, tcg_fpstatus
);
5693 write_fp_dreg(s
, rd
, tcg_double
);
5694 tcg_temp_free_i64(tcg_double
);
5697 case 0: /* float32 */
5698 tcg_single
= tcg_temp_new_i32();
5700 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
5701 tcg_shift
, tcg_fpstatus
);
5703 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
5704 tcg_shift
, tcg_fpstatus
);
5706 write_fp_sreg(s
, rd
, tcg_single
);
5707 tcg_temp_free_i32(tcg_single
);
5710 case 3: /* float16 */
5711 tcg_single
= tcg_temp_new_i32();
5713 gen_helper_vfp_sqtoh(tcg_single
, tcg_int
,
5714 tcg_shift
, tcg_fpstatus
);
5716 gen_helper_vfp_uqtoh(tcg_single
, tcg_int
,
5717 tcg_shift
, tcg_fpstatus
);
5719 write_fp_sreg(s
, rd
, tcg_single
);
5720 tcg_temp_free_i32(tcg_single
);
5724 g_assert_not_reached();
5727 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
5730 if (extract32(opcode
, 2, 1)) {
5731 /* There are too many rounding modes to all fit into rmode,
5732 * so FCVTA[US] is a special case.
5734 rmode
= FPROUNDING_TIEAWAY
;
5737 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
5739 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
5742 case 1: /* float64 */
5743 tcg_double
= read_fp_dreg(s
, rn
);
5746 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
5747 tcg_shift
, tcg_fpstatus
);
5749 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
5750 tcg_shift
, tcg_fpstatus
);
5754 gen_helper_vfp_tould(tcg_int
, tcg_double
,
5755 tcg_shift
, tcg_fpstatus
);
5757 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
5758 tcg_shift
, tcg_fpstatus
);
5762 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
5764 tcg_temp_free_i64(tcg_double
);
5767 case 0: /* float32 */
5768 tcg_single
= read_fp_sreg(s
, rn
);
5771 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
5772 tcg_shift
, tcg_fpstatus
);
5774 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
5775 tcg_shift
, tcg_fpstatus
);
5778 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
5780 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
5781 tcg_shift
, tcg_fpstatus
);
5783 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
5784 tcg_shift
, tcg_fpstatus
);
5786 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
5787 tcg_temp_free_i32(tcg_dest
);
5789 tcg_temp_free_i32(tcg_single
);
5792 case 3: /* float16 */
5793 tcg_single
= read_fp_sreg(s
, rn
);
5796 gen_helper_vfp_tosqh(tcg_int
, tcg_single
,
5797 tcg_shift
, tcg_fpstatus
);
5799 gen_helper_vfp_touqh(tcg_int
, tcg_single
,
5800 tcg_shift
, tcg_fpstatus
);
5803 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
5805 gen_helper_vfp_toslh(tcg_dest
, tcg_single
,
5806 tcg_shift
, tcg_fpstatus
);
5808 gen_helper_vfp_toulh(tcg_dest
, tcg_single
,
5809 tcg_shift
, tcg_fpstatus
);
5811 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
5812 tcg_temp_free_i32(tcg_dest
);
5814 tcg_temp_free_i32(tcg_single
);
5818 g_assert_not_reached();
5821 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
5822 tcg_temp_free_i32(tcg_rmode
);
5825 tcg_temp_free_ptr(tcg_fpstatus
);
5826 tcg_temp_free_i32(tcg_shift
);
5829 /* Floating point <-> fixed point conversions
5830 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
5831 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
5832 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
5833 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
5835 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
5837 int rd
= extract32(insn
, 0, 5);
5838 int rn
= extract32(insn
, 5, 5);
5839 int scale
= extract32(insn
, 10, 6);
5840 int opcode
= extract32(insn
, 16, 3);
5841 int rmode
= extract32(insn
, 19, 2);
5842 int type
= extract32(insn
, 22, 2);
5843 bool sbit
= extract32(insn
, 29, 1);
5844 bool sf
= extract32(insn
, 31, 1);
5847 if (sbit
|| (!sf
&& scale
< 32)) {
5848 unallocated_encoding(s
);
5853 case 0: /* float32 */
5854 case 1: /* float64 */
5856 case 3: /* float16 */
5857 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5862 unallocated_encoding(s
);
5866 switch ((rmode
<< 3) | opcode
) {
5867 case 0x2: /* SCVTF */
5868 case 0x3: /* UCVTF */
5871 case 0x18: /* FCVTZS */
5872 case 0x19: /* FCVTZU */
5876 unallocated_encoding(s
);
5880 if (!fp_access_check(s
)) {
5884 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
5887 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
5889 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
5890 * without conversion.
5894 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
5900 tmp
= tcg_temp_new_i64();
5901 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
5902 write_fp_dreg(s
, rd
, tmp
);
5903 tcg_temp_free_i64(tmp
);
5907 write_fp_dreg(s
, rd
, tcg_rn
);
5910 /* 64 bit to top half. */
5911 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5912 clear_vec_high(s
, true, rd
);
5916 tmp
= tcg_temp_new_i64();
5917 tcg_gen_ext16u_i64(tmp
, tcg_rn
);
5918 write_fp_dreg(s
, rd
, tmp
);
5919 tcg_temp_free_i64(tmp
);
5922 g_assert_not_reached();
5925 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5930 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
5934 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
5937 /* 64 bits from top half */
5938 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
5942 tcg_gen_ld16u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_16
));
5945 g_assert_not_reached();
5950 /* Floating point <-> integer conversions
5951 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
5952 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5953 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
5954 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5956 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
5958 int rd
= extract32(insn
, 0, 5);
5959 int rn
= extract32(insn
, 5, 5);
5960 int opcode
= extract32(insn
, 16, 3);
5961 int rmode
= extract32(insn
, 19, 2);
5962 int type
= extract32(insn
, 22, 2);
5963 bool sbit
= extract32(insn
, 29, 1);
5964 bool sf
= extract32(insn
, 31, 1);
5967 unallocated_encoding(s
);
5973 bool itof
= opcode
& 1;
5976 unallocated_encoding(s
);
5980 switch (sf
<< 3 | type
<< 1 | rmode
) {
5981 case 0x0: /* 32 bit */
5982 case 0xa: /* 64 bit */
5983 case 0xd: /* 64 bit to top half of quad */
5985 case 0x6: /* 16-bit float, 32-bit int */
5986 case 0xe: /* 16-bit float, 64-bit int */
5987 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5992 /* all other sf/type/rmode combinations are invalid */
5993 unallocated_encoding(s
);
5997 if (!fp_access_check(s
)) {
6000 handle_fmov(s
, rd
, rn
, type
, itof
);
6002 /* actual FP conversions */
6003 bool itof
= extract32(opcode
, 1, 1);
6005 if (rmode
!= 0 && opcode
> 1) {
6006 unallocated_encoding(s
);
6010 case 0: /* float32 */
6011 case 1: /* float64 */
6013 case 3: /* float16 */
6014 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
6019 unallocated_encoding(s
);
6023 if (!fp_access_check(s
)) {
6026 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
6030 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
6031 * 31 30 29 28 25 24 0
6032 * +---+---+---+---------+-----------------------------+
6033 * | | 0 | | 1 1 1 1 | |
6034 * +---+---+---+---------+-----------------------------+
6036 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
6038 if (extract32(insn
, 24, 1)) {
6039 /* Floating point data-processing (3 source) */
6040 disas_fp_3src(s
, insn
);
6041 } else if (extract32(insn
, 21, 1) == 0) {
6042 /* Floating point to fixed point conversions */
6043 disas_fp_fixed_conv(s
, insn
);
6045 switch (extract32(insn
, 10, 2)) {
6047 /* Floating point conditional compare */
6048 disas_fp_ccomp(s
, insn
);
6051 /* Floating point data-processing (2 source) */
6052 disas_fp_2src(s
, insn
);
6055 /* Floating point conditional select */
6056 disas_fp_csel(s
, insn
);
6059 switch (ctz32(extract32(insn
, 12, 4))) {
6060 case 0: /* [15:12] == xxx1 */
6061 /* Floating point immediate */
6062 disas_fp_imm(s
, insn
);
6064 case 1: /* [15:12] == xx10 */
6065 /* Floating point compare */
6066 disas_fp_compare(s
, insn
);
6068 case 2: /* [15:12] == x100 */
6069 /* Floating point data-processing (1 source) */
6070 disas_fp_1src(s
, insn
);
6072 case 3: /* [15:12] == 1000 */
6073 unallocated_encoding(s
);
6075 default: /* [15:12] == 0000 */
6076 /* Floating point <-> integer conversions */
6077 disas_fp_int_conv(s
, insn
);
6085 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
6088 /* Extract 64 bits from the middle of two concatenated 64 bit
6089 * vector register slices left:right. The extracted bits start
6090 * at 'pos' bits into the right (least significant) side.
6091 * We return the result in tcg_right, and guarantee not to
6094 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
6095 assert(pos
> 0 && pos
< 64);
6097 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
6098 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
6099 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
6101 tcg_temp_free_i64(tcg_tmp
);
6105 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
6106 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6107 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
6108 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6110 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
6112 int is_q
= extract32(insn
, 30, 1);
6113 int op2
= extract32(insn
, 22, 2);
6114 int imm4
= extract32(insn
, 11, 4);
6115 int rm
= extract32(insn
, 16, 5);
6116 int rn
= extract32(insn
, 5, 5);
6117 int rd
= extract32(insn
, 0, 5);
6118 int pos
= imm4
<< 3;
6119 TCGv_i64 tcg_resl
, tcg_resh
;
6121 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
6122 unallocated_encoding(s
);
6126 if (!fp_access_check(s
)) {
6130 tcg_resh
= tcg_temp_new_i64();
6131 tcg_resl
= tcg_temp_new_i64();
6133 /* Vd gets bits starting at pos bits into Vm:Vn. This is
6134 * either extracting 128 bits from a 128:128 concatenation, or
6135 * extracting 64 bits from a 64:64 concatenation.
6138 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
6140 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
6141 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6143 tcg_gen_movi_i64(tcg_resh
, 0);
6150 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
6151 EltPosns
*elt
= eltposns
;
6158 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
6160 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
6163 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6164 tcg_hh
= tcg_temp_new_i64();
6165 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
6166 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
6167 tcg_temp_free_i64(tcg_hh
);
6171 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6172 tcg_temp_free_i64(tcg_resl
);
6173 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6174 tcg_temp_free_i64(tcg_resh
);
6178 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
6179 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6180 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
6181 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6183 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
6185 int op2
= extract32(insn
, 22, 2);
6186 int is_q
= extract32(insn
, 30, 1);
6187 int rm
= extract32(insn
, 16, 5);
6188 int rn
= extract32(insn
, 5, 5);
6189 int rd
= extract32(insn
, 0, 5);
6190 int is_tblx
= extract32(insn
, 12, 1);
6191 int len
= extract32(insn
, 13, 2);
6192 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
6193 TCGv_i32 tcg_regno
, tcg_numregs
;
6196 unallocated_encoding(s
);
6200 if (!fp_access_check(s
)) {
6204 /* This does a table lookup: for every byte element in the input
6205 * we index into a table formed from up to four vector registers,
6206 * and then the output is the result of the lookups. Our helper
6207 * function does the lookup operation for a single 64 bit part of
6210 tcg_resl
= tcg_temp_new_i64();
6211 tcg_resh
= tcg_temp_new_i64();
6214 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6216 tcg_gen_movi_i64(tcg_resl
, 0);
6218 if (is_tblx
&& is_q
) {
6219 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6221 tcg_gen_movi_i64(tcg_resh
, 0);
6224 tcg_idx
= tcg_temp_new_i64();
6225 tcg_regno
= tcg_const_i32(rn
);
6226 tcg_numregs
= tcg_const_i32(len
+ 1);
6227 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
6228 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
6229 tcg_regno
, tcg_numregs
);
6231 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
6232 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
6233 tcg_regno
, tcg_numregs
);
6235 tcg_temp_free_i64(tcg_idx
);
6236 tcg_temp_free_i32(tcg_regno
);
6237 tcg_temp_free_i32(tcg_numregs
);
6239 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6240 tcg_temp_free_i64(tcg_resl
);
6241 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6242 tcg_temp_free_i64(tcg_resh
);
6246 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
6247 * +---+---+-------------+------+---+------+---+------------------+------+
6248 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
6249 * +---+---+-------------+------+---+------+---+------------------+------+
6251 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
6253 int rd
= extract32(insn
, 0, 5);
6254 int rn
= extract32(insn
, 5, 5);
6255 int rm
= extract32(insn
, 16, 5);
6256 int size
= extract32(insn
, 22, 2);
6257 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
6258 * bit 2 indicates 1 vs 2 variant of the insn.
6260 int opcode
= extract32(insn
, 12, 2);
6261 bool part
= extract32(insn
, 14, 1);
6262 bool is_q
= extract32(insn
, 30, 1);
6263 int esize
= 8 << size
;
6265 int datasize
= is_q
? 128 : 64;
6266 int elements
= datasize
/ esize
;
6267 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
6269 if (opcode
== 0 || (size
== 3 && !is_q
)) {
6270 unallocated_encoding(s
);
6274 if (!fp_access_check(s
)) {
6278 tcg_resl
= tcg_const_i64(0);
6279 tcg_resh
= tcg_const_i64(0);
6280 tcg_res
= tcg_temp_new_i64();
6282 for (i
= 0; i
< elements
; i
++) {
6284 case 1: /* UZP1/2 */
6286 int midpoint
= elements
/ 2;
6288 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
6290 read_vec_element(s
, tcg_res
, rm
,
6291 2 * (i
- midpoint
) + part
, size
);
6295 case 2: /* TRN1/2 */
6297 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
6299 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
6302 case 3: /* ZIP1/2 */
6304 int base
= part
* elements
/ 2;
6306 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
6308 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
6313 g_assert_not_reached();
6318 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
6319 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
6321 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
6322 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
6326 tcg_temp_free_i64(tcg_res
);
6328 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6329 tcg_temp_free_i64(tcg_resl
);
6330 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6331 tcg_temp_free_i64(tcg_resh
);
6335 * do_reduction_op helper
6337 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
6338 * important for correct NaN propagation that we do these
6339 * operations in exactly the order specified by the pseudocode.
6341 * This is a recursive function, TCG temps should be freed by the
6342 * calling function once it is done with the values.
6344 static TCGv_i32
do_reduction_op(DisasContext
*s
, int fpopcode
, int rn
,
6345 int esize
, int size
, int vmap
, TCGv_ptr fpst
)
6347 if (esize
== size
) {
6349 TCGMemOp msize
= esize
== 16 ? MO_16
: MO_32
;
6352 /* We should have one register left here */
6353 assert(ctpop8(vmap
) == 1);
6354 element
= ctz32(vmap
);
6355 assert(element
< 8);
6357 tcg_elem
= tcg_temp_new_i32();
6358 read_vec_element_i32(s
, tcg_elem
, rn
, element
, msize
);
6361 int bits
= size
/ 2;
6362 int shift
= ctpop8(vmap
) / 2;
6363 int vmap_lo
= (vmap
>> shift
) & vmap
;
6364 int vmap_hi
= (vmap
& ~vmap_lo
);
6365 TCGv_i32 tcg_hi
, tcg_lo
, tcg_res
;
6367 tcg_hi
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_hi
, fpst
);
6368 tcg_lo
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_lo
, fpst
);
6369 tcg_res
= tcg_temp_new_i32();
6372 case 0x0c: /* fmaxnmv half-precision */
6373 gen_helper_advsimd_maxnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6375 case 0x0f: /* fmaxv half-precision */
6376 gen_helper_advsimd_maxh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6378 case 0x1c: /* fminnmv half-precision */
6379 gen_helper_advsimd_minnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6381 case 0x1f: /* fminv half-precision */
6382 gen_helper_advsimd_minh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6384 case 0x2c: /* fmaxnmv */
6385 gen_helper_vfp_maxnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6387 case 0x2f: /* fmaxv */
6388 gen_helper_vfp_maxs(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6390 case 0x3c: /* fminnmv */
6391 gen_helper_vfp_minnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6393 case 0x3f: /* fminv */
6394 gen_helper_vfp_mins(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6397 g_assert_not_reached();
6400 tcg_temp_free_i32(tcg_hi
);
6401 tcg_temp_free_i32(tcg_lo
);
6406 /* AdvSIMD across lanes
6407 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6408 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6409 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6410 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6412 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
6414 int rd
= extract32(insn
, 0, 5);
6415 int rn
= extract32(insn
, 5, 5);
6416 int size
= extract32(insn
, 22, 2);
6417 int opcode
= extract32(insn
, 12, 5);
6418 bool is_q
= extract32(insn
, 30, 1);
6419 bool is_u
= extract32(insn
, 29, 1);
6421 bool is_min
= false;
6425 TCGv_i64 tcg_res
, tcg_elt
;
6428 case 0x1b: /* ADDV */
6430 unallocated_encoding(s
);
6434 case 0x3: /* SADDLV, UADDLV */
6435 case 0xa: /* SMAXV, UMAXV */
6436 case 0x1a: /* SMINV, UMINV */
6437 if (size
== 3 || (size
== 2 && !is_q
)) {
6438 unallocated_encoding(s
);
6442 case 0xc: /* FMAXNMV, FMINNMV */
6443 case 0xf: /* FMAXV, FMINV */
6444 /* Bit 1 of size field encodes min vs max and the actual size
6445 * depends on the encoding of the U bit. If not set (and FP16
6446 * enabled) then we do half-precision float instead of single
6449 is_min
= extract32(size
, 1, 1);
6451 if (!is_u
&& arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
6453 } else if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
6454 unallocated_encoding(s
);
6461 unallocated_encoding(s
);
6465 if (!fp_access_check(s
)) {
6470 elements
= (is_q
? 128 : 64) / esize
;
6472 tcg_res
= tcg_temp_new_i64();
6473 tcg_elt
= tcg_temp_new_i64();
6475 /* These instructions operate across all lanes of a vector
6476 * to produce a single result. We can guarantee that a 64
6477 * bit intermediate is sufficient:
6478 * + for [US]ADDLV the maximum element size is 32 bits, and
6479 * the result type is 64 bits
6480 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
6481 * same as the element size, which is 32 bits at most
6482 * For the integer operations we can choose to work at 64
6483 * or 32 bits and truncate at the end; for simplicity
6484 * we use 64 bits always. The floating point
6485 * ops do require 32 bit intermediates, though.
6488 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
6490 for (i
= 1; i
< elements
; i
++) {
6491 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
6494 case 0x03: /* SADDLV / UADDLV */
6495 case 0x1b: /* ADDV */
6496 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
6498 case 0x0a: /* SMAXV / UMAXV */
6500 tcg_gen_umax_i64(tcg_res
, tcg_res
, tcg_elt
);
6502 tcg_gen_smax_i64(tcg_res
, tcg_res
, tcg_elt
);
6505 case 0x1a: /* SMINV / UMINV */
6507 tcg_gen_umin_i64(tcg_res
, tcg_res
, tcg_elt
);
6509 tcg_gen_smin_i64(tcg_res
, tcg_res
, tcg_elt
);
6513 g_assert_not_reached();
6518 /* Floating point vector reduction ops which work across 32
6519 * bit (single) or 16 bit (half-precision) intermediates.
6520 * Note that correct NaN propagation requires that we do these
6521 * operations in exactly the order specified by the pseudocode.
6523 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
6524 int fpopcode
= opcode
| is_min
<< 4 | is_u
<< 5;
6525 int vmap
= (1 << elements
) - 1;
6526 TCGv_i32 tcg_res32
= do_reduction_op(s
, fpopcode
, rn
, esize
,
6527 (is_q
? 128 : 64), vmap
, fpst
);
6528 tcg_gen_extu_i32_i64(tcg_res
, tcg_res32
);
6529 tcg_temp_free_i32(tcg_res32
);
6530 tcg_temp_free_ptr(fpst
);
6533 tcg_temp_free_i64(tcg_elt
);
6535 /* Now truncate the result to the width required for the final output */
6536 if (opcode
== 0x03) {
6537 /* SADDLV, UADDLV: result is 2*esize */
6543 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
6546 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
6549 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
6554 g_assert_not_reached();
6557 write_fp_dreg(s
, rd
, tcg_res
);
6558 tcg_temp_free_i64(tcg_res
);
6561 /* DUP (Element, Vector)
6563 * 31 30 29 21 20 16 15 10 9 5 4 0
6564 * +---+---+-------------------+--------+-------------+------+------+
6565 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
6566 * +---+---+-------------------+--------+-------------+------+------+
6568 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6570 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
6573 int size
= ctz32(imm5
);
6574 int index
= imm5
>> (size
+ 1);
6576 if (size
> 3 || (size
== 3 && !is_q
)) {
6577 unallocated_encoding(s
);
6581 if (!fp_access_check(s
)) {
6585 tcg_gen_gvec_dup_mem(size
, vec_full_reg_offset(s
, rd
),
6586 vec_reg_offset(s
, rn
, index
, size
),
6587 is_q
? 16 : 8, vec_full_reg_size(s
));
6590 /* DUP (element, scalar)
6591 * 31 21 20 16 15 10 9 5 4 0
6592 * +-----------------------+--------+-------------+------+------+
6593 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
6594 * +-----------------------+--------+-------------+------+------+
6596 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
6599 int size
= ctz32(imm5
);
6604 unallocated_encoding(s
);
6608 if (!fp_access_check(s
)) {
6612 index
= imm5
>> (size
+ 1);
6614 /* This instruction just extracts the specified element and
6615 * zero-extends it into the bottom of the destination register.
6617 tmp
= tcg_temp_new_i64();
6618 read_vec_element(s
, tmp
, rn
, index
, size
);
6619 write_fp_dreg(s
, rd
, tmp
);
6620 tcg_temp_free_i64(tmp
);
6625 * 31 30 29 21 20 16 15 10 9 5 4 0
6626 * +---+---+-------------------+--------+-------------+------+------+
6627 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
6628 * +---+---+-------------------+--------+-------------+------+------+
6630 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6632 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
6635 int size
= ctz32(imm5
);
6636 uint32_t dofs
, oprsz
, maxsz
;
6638 if (size
> 3 || ((size
== 3) && !is_q
)) {
6639 unallocated_encoding(s
);
6643 if (!fp_access_check(s
)) {
6647 dofs
= vec_full_reg_offset(s
, rd
);
6648 oprsz
= is_q
? 16 : 8;
6649 maxsz
= vec_full_reg_size(s
);
6651 tcg_gen_gvec_dup_i64(size
, dofs
, oprsz
, maxsz
, cpu_reg(s
, rn
));
6656 * 31 21 20 16 15 14 11 10 9 5 4 0
6657 * +-----------------------+--------+------------+---+------+------+
6658 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6659 * +-----------------------+--------+------------+---+------+------+
6661 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6662 * index: encoded in imm5<4:size+1>
6664 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
6667 int size
= ctz32(imm5
);
6668 int src_index
, dst_index
;
6672 unallocated_encoding(s
);
6676 if (!fp_access_check(s
)) {
6680 dst_index
= extract32(imm5
, 1+size
, 5);
6681 src_index
= extract32(imm4
, size
, 4);
6683 tmp
= tcg_temp_new_i64();
6685 read_vec_element(s
, tmp
, rn
, src_index
, size
);
6686 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
6688 tcg_temp_free_i64(tmp
);
6694 * 31 21 20 16 15 10 9 5 4 0
6695 * +-----------------------+--------+-------------+------+------+
6696 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
6697 * +-----------------------+--------+-------------+------+------+
6699 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6700 * index: encoded in imm5<4:size+1>
6702 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
6704 int size
= ctz32(imm5
);
6708 unallocated_encoding(s
);
6712 if (!fp_access_check(s
)) {
6716 idx
= extract32(imm5
, 1 + size
, 4 - size
);
6717 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
6724 * 31 30 29 21 20 16 15 12 10 9 5 4 0
6725 * +---+---+-------------------+--------+-------------+------+------+
6726 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
6727 * +---+---+-------------------+--------+-------------+------+------+
6729 * U: unsigned when set
6730 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6732 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
6733 int rn
, int rd
, int imm5
)
6735 int size
= ctz32(imm5
);
6739 /* Check for UnallocatedEncodings */
6741 if (size
> 2 || (size
== 2 && !is_q
)) {
6742 unallocated_encoding(s
);
6747 || (size
< 3 && is_q
)
6748 || (size
== 3 && !is_q
)) {
6749 unallocated_encoding(s
);
6754 if (!fp_access_check(s
)) {
6758 element
= extract32(imm5
, 1+size
, 4);
6760 tcg_rd
= cpu_reg(s
, rd
);
6761 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
6762 if (is_signed
&& !is_q
) {
6763 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
6768 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
6769 * +---+---+----+-----------------+------+---+------+---+------+------+
6770 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6771 * +---+---+----+-----------------+------+---+------+---+------+------+
6773 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
6775 int rd
= extract32(insn
, 0, 5);
6776 int rn
= extract32(insn
, 5, 5);
6777 int imm4
= extract32(insn
, 11, 4);
6778 int op
= extract32(insn
, 29, 1);
6779 int is_q
= extract32(insn
, 30, 1);
6780 int imm5
= extract32(insn
, 16, 5);
6785 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
6787 unallocated_encoding(s
);
6792 /* DUP (element - vector) */
6793 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
6797 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
6802 handle_simd_insg(s
, rd
, rn
, imm5
);
6804 unallocated_encoding(s
);
6809 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
6810 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
6813 unallocated_encoding(s
);
6819 /* AdvSIMD modified immediate
6820 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
6821 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
6822 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
6823 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
6825 * There are a number of operations that can be carried out here:
6826 * MOVI - move (shifted) imm into register
6827 * MVNI - move inverted (shifted) imm into register
6828 * ORR - bitwise OR of (shifted) imm with register
6829 * BIC - bitwise clear of (shifted) imm with register
6830 * With ARMv8.2 we also have:
6831 * FMOV half-precision
6833 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
6835 int rd
= extract32(insn
, 0, 5);
6836 int cmode
= extract32(insn
, 12, 4);
6837 int cmode_3_1
= extract32(cmode
, 1, 3);
6838 int cmode_0
= extract32(cmode
, 0, 1);
6839 int o2
= extract32(insn
, 11, 1);
6840 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
6841 bool is_neg
= extract32(insn
, 29, 1);
6842 bool is_q
= extract32(insn
, 30, 1);
6845 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
6846 /* Check for FMOV (vector, immediate) - half-precision */
6847 if (!(arm_dc_feature(s
, ARM_FEATURE_V8_FP16
) && o2
&& cmode
== 0xf)) {
6848 unallocated_encoding(s
);
6853 if (!fp_access_check(s
)) {
6857 /* See AdvSIMDExpandImm() in ARM ARM */
6858 switch (cmode_3_1
) {
6859 case 0: /* Replicate(Zeros(24):imm8, 2) */
6860 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
6861 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
6862 case 3: /* Replicate(imm8:Zeros(24), 2) */
6864 int shift
= cmode_3_1
* 8;
6865 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
6868 case 4: /* Replicate(Zeros(8):imm8, 4) */
6869 case 5: /* Replicate(imm8:Zeros(8), 4) */
6871 int shift
= (cmode_3_1
& 0x1) * 8;
6872 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
6877 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
6878 imm
= (abcdefgh
<< 16) | 0xffff;
6880 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
6881 imm
= (abcdefgh
<< 8) | 0xff;
6883 imm
= bitfield_replicate(imm
, 32);
6886 if (!cmode_0
&& !is_neg
) {
6887 imm
= bitfield_replicate(abcdefgh
, 8);
6888 } else if (!cmode_0
&& is_neg
) {
6891 for (i
= 0; i
< 8; i
++) {
6892 if ((abcdefgh
) & (1 << i
)) {
6893 imm
|= 0xffULL
<< (i
* 8);
6896 } else if (cmode_0
) {
6898 imm
= (abcdefgh
& 0x3f) << 48;
6899 if (abcdefgh
& 0x80) {
6900 imm
|= 0x8000000000000000ULL
;
6902 if (abcdefgh
& 0x40) {
6903 imm
|= 0x3fc0000000000000ULL
;
6905 imm
|= 0x4000000000000000ULL
;
6909 /* FMOV (vector, immediate) - half-precision */
6910 imm
= vfp_expand_imm(MO_16
, abcdefgh
);
6911 /* now duplicate across the lanes */
6912 imm
= bitfield_replicate(imm
, 16);
6914 imm
= (abcdefgh
& 0x3f) << 19;
6915 if (abcdefgh
& 0x80) {
6918 if (abcdefgh
& 0x40) {
6929 fprintf(stderr
, "%s: cmode_3_1: %x\n", __func__
, cmode_3_1
);
6930 g_assert_not_reached();
6933 if (cmode_3_1
!= 7 && is_neg
) {
6937 if (!((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9)) {
6938 /* MOVI or MVNI, with MVNI negation handled above. */
6939 tcg_gen_gvec_dup64i(vec_full_reg_offset(s
, rd
), is_q
? 16 : 8,
6940 vec_full_reg_size(s
), imm
);
6942 /* ORR or BIC, with BIC negation to AND handled above. */
6944 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_andi
, MO_64
);
6946 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_ori
, MO_64
);
6951 /* AdvSIMD scalar copy
6952 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
6953 * +-----+----+-----------------+------+---+------+---+------+------+
6954 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6955 * +-----+----+-----------------+------+---+------+---+------+------+
6957 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
6959 int rd
= extract32(insn
, 0, 5);
6960 int rn
= extract32(insn
, 5, 5);
6961 int imm4
= extract32(insn
, 11, 4);
6962 int imm5
= extract32(insn
, 16, 5);
6963 int op
= extract32(insn
, 29, 1);
6965 if (op
!= 0 || imm4
!= 0) {
6966 unallocated_encoding(s
);
6970 /* DUP (element, scalar) */
6971 handle_simd_dupes(s
, rd
, rn
, imm5
);
6974 /* AdvSIMD scalar pairwise
6975 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6976 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6977 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6978 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6980 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
6982 int u
= extract32(insn
, 29, 1);
6983 int size
= extract32(insn
, 22, 2);
6984 int opcode
= extract32(insn
, 12, 5);
6985 int rn
= extract32(insn
, 5, 5);
6986 int rd
= extract32(insn
, 0, 5);
6989 /* For some ops (the FP ones), size[1] is part of the encoding.
6990 * For ADDP strictly it is not but size[1] is always 1 for valid
6993 opcode
|= (extract32(size
, 1, 1) << 5);
6996 case 0x3b: /* ADDP */
6997 if (u
|| size
!= 3) {
6998 unallocated_encoding(s
);
7001 if (!fp_access_check(s
)) {
7007 case 0xc: /* FMAXNMP */
7008 case 0xd: /* FADDP */
7009 case 0xf: /* FMAXP */
7010 case 0x2c: /* FMINNMP */
7011 case 0x2f: /* FMINP */
7012 /* FP op, size[0] is 32 or 64 bit*/
7014 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
7015 unallocated_encoding(s
);
7021 size
= extract32(size
, 0, 1) ? MO_64
: MO_32
;
7024 if (!fp_access_check(s
)) {
7028 fpst
= get_fpstatus_ptr(size
== MO_16
);
7031 unallocated_encoding(s
);
7035 if (size
== MO_64
) {
7036 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7037 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7038 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7040 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
7041 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
7044 case 0x3b: /* ADDP */
7045 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
7047 case 0xc: /* FMAXNMP */
7048 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7050 case 0xd: /* FADDP */
7051 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7053 case 0xf: /* FMAXP */
7054 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7056 case 0x2c: /* FMINNMP */
7057 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7059 case 0x2f: /* FMINP */
7060 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7063 g_assert_not_reached();
7066 write_fp_dreg(s
, rd
, tcg_res
);
7068 tcg_temp_free_i64(tcg_op1
);
7069 tcg_temp_free_i64(tcg_op2
);
7070 tcg_temp_free_i64(tcg_res
);
7072 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7073 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7074 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7076 read_vec_element_i32(s
, tcg_op1
, rn
, 0, size
);
7077 read_vec_element_i32(s
, tcg_op2
, rn
, 1, size
);
7079 if (size
== MO_16
) {
7081 case 0xc: /* FMAXNMP */
7082 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7084 case 0xd: /* FADDP */
7085 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7087 case 0xf: /* FMAXP */
7088 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7090 case 0x2c: /* FMINNMP */
7091 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7093 case 0x2f: /* FMINP */
7094 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7097 g_assert_not_reached();
7101 case 0xc: /* FMAXNMP */
7102 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7104 case 0xd: /* FADDP */
7105 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7107 case 0xf: /* FMAXP */
7108 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7110 case 0x2c: /* FMINNMP */
7111 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7113 case 0x2f: /* FMINP */
7114 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7117 g_assert_not_reached();
7121 write_fp_sreg(s
, rd
, tcg_res
);
7123 tcg_temp_free_i32(tcg_op1
);
7124 tcg_temp_free_i32(tcg_op2
);
7125 tcg_temp_free_i32(tcg_res
);
7129 tcg_temp_free_ptr(fpst
);
7134 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
7136 * This code is handles the common shifting code and is used by both
7137 * the vector and scalar code.
7139 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
7140 TCGv_i64 tcg_rnd
, bool accumulate
,
7141 bool is_u
, int size
, int shift
)
7143 bool extended_result
= false;
7144 bool round
= tcg_rnd
!= NULL
;
7146 TCGv_i64 tcg_src_hi
;
7148 if (round
&& size
== 3) {
7149 extended_result
= true;
7150 ext_lshift
= 64 - shift
;
7151 tcg_src_hi
= tcg_temp_new_i64();
7152 } else if (shift
== 64) {
7153 if (!accumulate
&& is_u
) {
7154 /* result is zero */
7155 tcg_gen_movi_i64(tcg_res
, 0);
7160 /* Deal with the rounding step */
7162 if (extended_result
) {
7163 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7165 /* take care of sign extending tcg_res */
7166 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
7167 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7168 tcg_src
, tcg_src_hi
,
7171 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7175 tcg_temp_free_i64(tcg_zero
);
7177 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
7181 /* Now do the shift right */
7182 if (round
&& extended_result
) {
7183 /* extended case, >64 bit precision required */
7184 if (ext_lshift
== 0) {
7185 /* special case, only high bits matter */
7186 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
7188 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7189 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
7190 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
7195 /* essentially shifting in 64 zeros */
7196 tcg_gen_movi_i64(tcg_src
, 0);
7198 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7202 /* effectively extending the sign-bit */
7203 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
7205 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
7211 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
7213 tcg_gen_mov_i64(tcg_res
, tcg_src
);
7216 if (extended_result
) {
7217 tcg_temp_free_i64(tcg_src_hi
);
7221 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
7222 static void handle_scalar_simd_shri(DisasContext
*s
,
7223 bool is_u
, int immh
, int immb
,
7224 int opcode
, int rn
, int rd
)
7227 int immhb
= immh
<< 3 | immb
;
7228 int shift
= 2 * (8 << size
) - immhb
;
7229 bool accumulate
= false;
7231 bool insert
= false;
7236 if (!extract32(immh
, 3, 1)) {
7237 unallocated_encoding(s
);
7241 if (!fp_access_check(s
)) {
7246 case 0x02: /* SSRA / USRA (accumulate) */
7249 case 0x04: /* SRSHR / URSHR (rounding) */
7252 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7253 accumulate
= round
= true;
7255 case 0x08: /* SRI */
7261 uint64_t round_const
= 1ULL << (shift
- 1);
7262 tcg_round
= tcg_const_i64(round_const
);
7267 tcg_rn
= read_fp_dreg(s
, rn
);
7268 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
7271 /* shift count same as element size is valid but does nothing;
7272 * special case to avoid potential shift by 64.
7274 int esize
= 8 << size
;
7275 if (shift
!= esize
) {
7276 tcg_gen_shri_i64(tcg_rn
, tcg_rn
, shift
);
7277 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, 0, esize
- shift
);
7280 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
7281 accumulate
, is_u
, size
, shift
);
7284 write_fp_dreg(s
, rd
, tcg_rd
);
7286 tcg_temp_free_i64(tcg_rn
);
7287 tcg_temp_free_i64(tcg_rd
);
7289 tcg_temp_free_i64(tcg_round
);
7293 /* SHL/SLI - Scalar shift left */
7294 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
7295 int immh
, int immb
, int opcode
,
7298 int size
= 32 - clz32(immh
) - 1;
7299 int immhb
= immh
<< 3 | immb
;
7300 int shift
= immhb
- (8 << size
);
7301 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
7302 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
7304 if (!extract32(immh
, 3, 1)) {
7305 unallocated_encoding(s
);
7309 if (!fp_access_check(s
)) {
7313 tcg_rn
= read_fp_dreg(s
, rn
);
7314 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
7317 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, shift
, 64 - shift
);
7319 tcg_gen_shli_i64(tcg_rd
, tcg_rn
, shift
);
7322 write_fp_dreg(s
, rd
, tcg_rd
);
7324 tcg_temp_free_i64(tcg_rn
);
7325 tcg_temp_free_i64(tcg_rd
);
7328 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
7329 * (signed/unsigned) narrowing */
7330 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
7331 bool is_u_shift
, bool is_u_narrow
,
7332 int immh
, int immb
, int opcode
,
7335 int immhb
= immh
<< 3 | immb
;
7336 int size
= 32 - clz32(immh
) - 1;
7337 int esize
= 8 << size
;
7338 int shift
= (2 * esize
) - immhb
;
7339 int elements
= is_scalar
? 1 : (64 / esize
);
7340 bool round
= extract32(opcode
, 0, 1);
7341 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
7342 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
7343 TCGv_i32 tcg_rd_narrowed
;
7346 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
7347 { gen_helper_neon_narrow_sat_s8
,
7348 gen_helper_neon_unarrow_sat8
},
7349 { gen_helper_neon_narrow_sat_s16
,
7350 gen_helper_neon_unarrow_sat16
},
7351 { gen_helper_neon_narrow_sat_s32
,
7352 gen_helper_neon_unarrow_sat32
},
7355 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
7356 gen_helper_neon_narrow_sat_u8
,
7357 gen_helper_neon_narrow_sat_u16
,
7358 gen_helper_neon_narrow_sat_u32
,
7361 NeonGenNarrowEnvFn
*narrowfn
;
7367 if (extract32(immh
, 3, 1)) {
7368 unallocated_encoding(s
);
7372 if (!fp_access_check(s
)) {
7377 narrowfn
= unsigned_narrow_fns
[size
];
7379 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
7382 tcg_rn
= tcg_temp_new_i64();
7383 tcg_rd
= tcg_temp_new_i64();
7384 tcg_rd_narrowed
= tcg_temp_new_i32();
7385 tcg_final
= tcg_const_i64(0);
7388 uint64_t round_const
= 1ULL << (shift
- 1);
7389 tcg_round
= tcg_const_i64(round_const
);
7394 for (i
= 0; i
< elements
; i
++) {
7395 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
7396 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
7397 false, is_u_shift
, size
+1, shift
);
7398 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
7399 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
7400 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
7404 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
7406 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
7410 tcg_temp_free_i64(tcg_round
);
7412 tcg_temp_free_i64(tcg_rn
);
7413 tcg_temp_free_i64(tcg_rd
);
7414 tcg_temp_free_i32(tcg_rd_narrowed
);
7415 tcg_temp_free_i64(tcg_final
);
7417 clear_vec_high(s
, is_q
, rd
);
7420 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
7421 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
7422 bool src_unsigned
, bool dst_unsigned
,
7423 int immh
, int immb
, int rn
, int rd
)
7425 int immhb
= immh
<< 3 | immb
;
7426 int size
= 32 - clz32(immh
) - 1;
7427 int shift
= immhb
- (8 << size
);
7431 assert(!(scalar
&& is_q
));
7434 if (!is_q
&& extract32(immh
, 3, 1)) {
7435 unallocated_encoding(s
);
7439 /* Since we use the variable-shift helpers we must
7440 * replicate the shift count into each element of
7441 * the tcg_shift value.
7445 shift
|= shift
<< 8;
7448 shift
|= shift
<< 16;
7454 g_assert_not_reached();
7458 if (!fp_access_check(s
)) {
7463 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
7464 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
7465 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
7466 { NULL
, gen_helper_neon_qshl_u64
},
7468 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
7469 int maxpass
= is_q
? 2 : 1;
7471 for (pass
= 0; pass
< maxpass
; pass
++) {
7472 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7474 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7475 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
7476 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
7478 tcg_temp_free_i64(tcg_op
);
7480 tcg_temp_free_i64(tcg_shift
);
7481 clear_vec_high(s
, is_q
, rd
);
7483 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
7484 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
7486 { gen_helper_neon_qshl_s8
,
7487 gen_helper_neon_qshl_s16
,
7488 gen_helper_neon_qshl_s32
},
7489 { gen_helper_neon_qshlu_s8
,
7490 gen_helper_neon_qshlu_s16
,
7491 gen_helper_neon_qshlu_s32
}
7493 { NULL
, NULL
, NULL
},
7494 { gen_helper_neon_qshl_u8
,
7495 gen_helper_neon_qshl_u16
,
7496 gen_helper_neon_qshl_u32
}
7499 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
7500 TCGMemOp memop
= scalar
? size
: MO_32
;
7501 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
7503 for (pass
= 0; pass
< maxpass
; pass
++) {
7504 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7506 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
7507 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
7511 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
7514 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
7519 g_assert_not_reached();
7521 write_fp_sreg(s
, rd
, tcg_op
);
7523 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
7526 tcg_temp_free_i32(tcg_op
);
7528 tcg_temp_free_i32(tcg_shift
);
7531 clear_vec_high(s
, is_q
, rd
);
7536 /* Common vector code for handling integer to FP conversion */
7537 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
7538 int elements
, int is_signed
,
7539 int fracbits
, int size
)
7541 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(size
== MO_16
);
7542 TCGv_i32 tcg_shift
= NULL
;
7544 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
7547 if (fracbits
|| size
== MO_64
) {
7548 tcg_shift
= tcg_const_i32(fracbits
);
7551 if (size
== MO_64
) {
7552 TCGv_i64 tcg_int64
= tcg_temp_new_i64();
7553 TCGv_i64 tcg_double
= tcg_temp_new_i64();
7555 for (pass
= 0; pass
< elements
; pass
++) {
7556 read_vec_element(s
, tcg_int64
, rn
, pass
, mop
);
7559 gen_helper_vfp_sqtod(tcg_double
, tcg_int64
,
7560 tcg_shift
, tcg_fpst
);
7562 gen_helper_vfp_uqtod(tcg_double
, tcg_int64
,
7563 tcg_shift
, tcg_fpst
);
7565 if (elements
== 1) {
7566 write_fp_dreg(s
, rd
, tcg_double
);
7568 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
7572 tcg_temp_free_i64(tcg_int64
);
7573 tcg_temp_free_i64(tcg_double
);
7576 TCGv_i32 tcg_int32
= tcg_temp_new_i32();
7577 TCGv_i32 tcg_float
= tcg_temp_new_i32();
7579 for (pass
= 0; pass
< elements
; pass
++) {
7580 read_vec_element_i32(s
, tcg_int32
, rn
, pass
, mop
);
7586 gen_helper_vfp_sltos(tcg_float
, tcg_int32
,
7587 tcg_shift
, tcg_fpst
);
7589 gen_helper_vfp_ultos(tcg_float
, tcg_int32
,
7590 tcg_shift
, tcg_fpst
);
7594 gen_helper_vfp_sitos(tcg_float
, tcg_int32
, tcg_fpst
);
7596 gen_helper_vfp_uitos(tcg_float
, tcg_int32
, tcg_fpst
);
7603 gen_helper_vfp_sltoh(tcg_float
, tcg_int32
,
7604 tcg_shift
, tcg_fpst
);
7606 gen_helper_vfp_ultoh(tcg_float
, tcg_int32
,
7607 tcg_shift
, tcg_fpst
);
7611 gen_helper_vfp_sitoh(tcg_float
, tcg_int32
, tcg_fpst
);
7613 gen_helper_vfp_uitoh(tcg_float
, tcg_int32
, tcg_fpst
);
7618 g_assert_not_reached();
7621 if (elements
== 1) {
7622 write_fp_sreg(s
, rd
, tcg_float
);
7624 write_vec_element_i32(s
, tcg_float
, rd
, pass
, size
);
7628 tcg_temp_free_i32(tcg_int32
);
7629 tcg_temp_free_i32(tcg_float
);
7632 tcg_temp_free_ptr(tcg_fpst
);
7634 tcg_temp_free_i32(tcg_shift
);
7637 clear_vec_high(s
, elements
<< size
== 16, rd
);
7640 /* UCVTF/SCVTF - Integer to FP conversion */
7641 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
7642 bool is_q
, bool is_u
,
7643 int immh
, int immb
, int opcode
,
7646 int size
, elements
, fracbits
;
7647 int immhb
= immh
<< 3 | immb
;
7651 if (!is_scalar
&& !is_q
) {
7652 unallocated_encoding(s
);
7655 } else if (immh
& 4) {
7657 } else if (immh
& 2) {
7659 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
7660 unallocated_encoding(s
);
7664 /* immh == 0 would be a failure of the decode logic */
7665 g_assert(immh
== 1);
7666 unallocated_encoding(s
);
7673 elements
= (8 << is_q
) >> size
;
7675 fracbits
= (16 << size
) - immhb
;
7677 if (!fp_access_check(s
)) {
7681 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
7684 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
7685 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
7686 bool is_q
, bool is_u
,
7687 int immh
, int immb
, int rn
, int rd
)
7689 int immhb
= immh
<< 3 | immb
;
7690 int pass
, size
, fracbits
;
7691 TCGv_ptr tcg_fpstatus
;
7692 TCGv_i32 tcg_rmode
, tcg_shift
;
7696 if (!is_scalar
&& !is_q
) {
7697 unallocated_encoding(s
);
7700 } else if (immh
& 0x4) {
7702 } else if (immh
& 0x2) {
7704 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
7705 unallocated_encoding(s
);
7709 /* Should have split out AdvSIMD modified immediate earlier. */
7711 unallocated_encoding(s
);
7715 if (!fp_access_check(s
)) {
7719 assert(!(is_scalar
&& is_q
));
7721 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
7722 tcg_fpstatus
= get_fpstatus_ptr(size
== MO_16
);
7723 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7724 fracbits
= (16 << size
) - immhb
;
7725 tcg_shift
= tcg_const_i32(fracbits
);
7727 if (size
== MO_64
) {
7728 int maxpass
= is_scalar
? 1 : 2;
7730 for (pass
= 0; pass
< maxpass
; pass
++) {
7731 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7733 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7735 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
7737 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
7739 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
7740 tcg_temp_free_i64(tcg_op
);
7742 clear_vec_high(s
, is_q
, rd
);
7744 void (*fn
)(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
7745 int maxpass
= is_scalar
? 1 : ((8 << is_q
) >> size
);
7750 fn
= gen_helper_vfp_touhh
;
7752 fn
= gen_helper_vfp_toshh
;
7757 fn
= gen_helper_vfp_touls
;
7759 fn
= gen_helper_vfp_tosls
;
7763 g_assert_not_reached();
7766 for (pass
= 0; pass
< maxpass
; pass
++) {
7767 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7769 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
7770 fn(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
7772 write_fp_sreg(s
, rd
, tcg_op
);
7774 write_vec_element_i32(s
, tcg_op
, rd
, pass
, size
);
7776 tcg_temp_free_i32(tcg_op
);
7779 clear_vec_high(s
, is_q
, rd
);
7783 tcg_temp_free_ptr(tcg_fpstatus
);
7784 tcg_temp_free_i32(tcg_shift
);
7785 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7786 tcg_temp_free_i32(tcg_rmode
);
7789 /* AdvSIMD scalar shift by immediate
7790 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
7791 * +-----+---+-------------+------+------+--------+---+------+------+
7792 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
7793 * +-----+---+-------------+------+------+--------+---+------+------+
7795 * This is the scalar version so it works on a fixed sized registers
7797 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
7799 int rd
= extract32(insn
, 0, 5);
7800 int rn
= extract32(insn
, 5, 5);
7801 int opcode
= extract32(insn
, 11, 5);
7802 int immb
= extract32(insn
, 16, 3);
7803 int immh
= extract32(insn
, 19, 4);
7804 bool is_u
= extract32(insn
, 29, 1);
7807 unallocated_encoding(s
);
7812 case 0x08: /* SRI */
7814 unallocated_encoding(s
);
7818 case 0x00: /* SSHR / USHR */
7819 case 0x02: /* SSRA / USRA */
7820 case 0x04: /* SRSHR / URSHR */
7821 case 0x06: /* SRSRA / URSRA */
7822 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
7824 case 0x0a: /* SHL / SLI */
7825 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
7827 case 0x1c: /* SCVTF, UCVTF */
7828 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
7831 case 0x10: /* SQSHRUN, SQSHRUN2 */
7832 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
7834 unallocated_encoding(s
);
7837 handle_vec_simd_sqshrn(s
, true, false, false, true,
7838 immh
, immb
, opcode
, rn
, rd
);
7840 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
7841 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
7842 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
7843 immh
, immb
, opcode
, rn
, rd
);
7845 case 0xc: /* SQSHLU */
7847 unallocated_encoding(s
);
7850 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
7852 case 0xe: /* SQSHL, UQSHL */
7853 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
7855 case 0x1f: /* FCVTZS, FCVTZU */
7856 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
7859 unallocated_encoding(s
);
7864 /* AdvSIMD scalar three different
7865 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
7866 * +-----+---+-----------+------+---+------+--------+-----+------+------+
7867 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
7868 * +-----+---+-----------+------+---+------+--------+-----+------+------+
7870 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
7872 bool is_u
= extract32(insn
, 29, 1);
7873 int size
= extract32(insn
, 22, 2);
7874 int opcode
= extract32(insn
, 12, 4);
7875 int rm
= extract32(insn
, 16, 5);
7876 int rn
= extract32(insn
, 5, 5);
7877 int rd
= extract32(insn
, 0, 5);
7880 unallocated_encoding(s
);
7885 case 0x9: /* SQDMLAL, SQDMLAL2 */
7886 case 0xb: /* SQDMLSL, SQDMLSL2 */
7887 case 0xd: /* SQDMULL, SQDMULL2 */
7888 if (size
== 0 || size
== 3) {
7889 unallocated_encoding(s
);
7894 unallocated_encoding(s
);
7898 if (!fp_access_check(s
)) {
7903 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7904 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7905 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7907 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
7908 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
7910 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
7911 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
7914 case 0xd: /* SQDMULL, SQDMULL2 */
7916 case 0xb: /* SQDMLSL, SQDMLSL2 */
7917 tcg_gen_neg_i64(tcg_res
, tcg_res
);
7919 case 0x9: /* SQDMLAL, SQDMLAL2 */
7920 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
7921 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
7925 g_assert_not_reached();
7928 write_fp_dreg(s
, rd
, tcg_res
);
7930 tcg_temp_free_i64(tcg_op1
);
7931 tcg_temp_free_i64(tcg_op2
);
7932 tcg_temp_free_i64(tcg_res
);
7934 TCGv_i32 tcg_op1
= read_fp_hreg(s
, rn
);
7935 TCGv_i32 tcg_op2
= read_fp_hreg(s
, rm
);
7936 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7938 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
7939 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
7942 case 0xd: /* SQDMULL, SQDMULL2 */
7944 case 0xb: /* SQDMLSL, SQDMLSL2 */
7945 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
7947 case 0x9: /* SQDMLAL, SQDMLAL2 */
7949 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
7950 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
7951 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
7953 tcg_temp_free_i64(tcg_op3
);
7957 g_assert_not_reached();
7960 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
7961 write_fp_dreg(s
, rd
, tcg_res
);
7963 tcg_temp_free_i32(tcg_op1
);
7964 tcg_temp_free_i32(tcg_op2
);
7965 tcg_temp_free_i64(tcg_res
);
7969 /* CMTST : test is "if (X & Y != 0)". */
7970 static void gen_cmtst_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
7972 tcg_gen_and_i32(d
, a
, b
);
7973 tcg_gen_setcondi_i32(TCG_COND_NE
, d
, d
, 0);
7974 tcg_gen_neg_i32(d
, d
);
7977 static void gen_cmtst_i64(TCGv_i64 d
, TCGv_i64 a
, TCGv_i64 b
)
7979 tcg_gen_and_i64(d
, a
, b
);
7980 tcg_gen_setcondi_i64(TCG_COND_NE
, d
, d
, 0);
7981 tcg_gen_neg_i64(d
, d
);
7984 static void gen_cmtst_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, TCGv_vec b
)
7986 tcg_gen_and_vec(vece
, d
, a
, b
);
7987 tcg_gen_dupi_vec(vece
, a
, 0);
7988 tcg_gen_cmp_vec(TCG_COND_NE
, vece
, d
, d
, a
);
7991 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
7992 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
7994 /* Handle 64x64->64 opcodes which are shared between the scalar
7995 * and vector 3-same groups. We cover every opcode where size == 3
7996 * is valid in either the three-reg-same (integer, not pairwise)
7997 * or scalar-three-reg-same groups.
8002 case 0x1: /* SQADD */
8004 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8006 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8009 case 0x5: /* SQSUB */
8011 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8013 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8016 case 0x6: /* CMGT, CMHI */
8017 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
8018 * We implement this using setcond (test) and then negating.
8020 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
8022 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
8023 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
8025 case 0x7: /* CMGE, CMHS */
8026 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
8028 case 0x11: /* CMTST, CMEQ */
8033 gen_cmtst_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8035 case 0x8: /* SSHL, USHL */
8037 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8039 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8042 case 0x9: /* SQSHL, UQSHL */
8044 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8046 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8049 case 0xa: /* SRSHL, URSHL */
8051 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8053 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8056 case 0xb: /* SQRSHL, UQRSHL */
8058 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8060 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8063 case 0x10: /* ADD, SUB */
8065 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8067 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8071 g_assert_not_reached();
8075 /* Handle the 3-same-operands float operations; shared by the scalar
8076 * and vector encodings. The caller must filter out any encodings
8077 * not allocated for the encoding it is dealing with.
8079 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
8080 int fpopcode
, int rd
, int rn
, int rm
)
8083 TCGv_ptr fpst
= get_fpstatus_ptr(false);
8085 for (pass
= 0; pass
< elements
; pass
++) {
8088 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8089 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8090 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8092 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8093 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8096 case 0x39: /* FMLS */
8097 /* As usual for ARM, separate negation for fused multiply-add */
8098 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
8100 case 0x19: /* FMLA */
8101 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8102 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
8105 case 0x18: /* FMAXNM */
8106 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8108 case 0x1a: /* FADD */
8109 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8111 case 0x1b: /* FMULX */
8112 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8114 case 0x1c: /* FCMEQ */
8115 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8117 case 0x1e: /* FMAX */
8118 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8120 case 0x1f: /* FRECPS */
8121 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8123 case 0x38: /* FMINNM */
8124 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8126 case 0x3a: /* FSUB */
8127 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8129 case 0x3e: /* FMIN */
8130 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8132 case 0x3f: /* FRSQRTS */
8133 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8135 case 0x5b: /* FMUL */
8136 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8138 case 0x5c: /* FCMGE */
8139 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8141 case 0x5d: /* FACGE */
8142 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8144 case 0x5f: /* FDIV */
8145 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8147 case 0x7a: /* FABD */
8148 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8149 gen_helper_vfp_absd(tcg_res
, tcg_res
);
8151 case 0x7c: /* FCMGT */
8152 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8154 case 0x7d: /* FACGT */
8155 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8158 g_assert_not_reached();
8161 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8163 tcg_temp_free_i64(tcg_res
);
8164 tcg_temp_free_i64(tcg_op1
);
8165 tcg_temp_free_i64(tcg_op2
);
8168 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8169 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8170 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8172 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
8173 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
8176 case 0x39: /* FMLS */
8177 /* As usual for ARM, separate negation for fused multiply-add */
8178 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
8180 case 0x19: /* FMLA */
8181 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8182 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
8185 case 0x1a: /* FADD */
8186 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8188 case 0x1b: /* FMULX */
8189 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8191 case 0x1c: /* FCMEQ */
8192 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8194 case 0x1e: /* FMAX */
8195 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8197 case 0x1f: /* FRECPS */
8198 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8200 case 0x18: /* FMAXNM */
8201 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8203 case 0x38: /* FMINNM */
8204 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8206 case 0x3a: /* FSUB */
8207 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8209 case 0x3e: /* FMIN */
8210 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8212 case 0x3f: /* FRSQRTS */
8213 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8215 case 0x5b: /* FMUL */
8216 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8218 case 0x5c: /* FCMGE */
8219 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8221 case 0x5d: /* FACGE */
8222 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8224 case 0x5f: /* FDIV */
8225 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8227 case 0x7a: /* FABD */
8228 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8229 gen_helper_vfp_abss(tcg_res
, tcg_res
);
8231 case 0x7c: /* FCMGT */
8232 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8234 case 0x7d: /* FACGT */
8235 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8238 g_assert_not_reached();
8241 if (elements
== 1) {
8242 /* scalar single so clear high part */
8243 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
8245 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
8246 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
8247 tcg_temp_free_i64(tcg_tmp
);
8249 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8252 tcg_temp_free_i32(tcg_res
);
8253 tcg_temp_free_i32(tcg_op1
);
8254 tcg_temp_free_i32(tcg_op2
);
8258 tcg_temp_free_ptr(fpst
);
8260 clear_vec_high(s
, elements
* (size
? 8 : 4) > 8, rd
);
8263 /* AdvSIMD scalar three same
8264 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8265 * +-----+---+-----------+------+---+------+--------+---+------+------+
8266 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8267 * +-----+---+-----------+------+---+------+--------+---+------+------+
8269 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
8271 int rd
= extract32(insn
, 0, 5);
8272 int rn
= extract32(insn
, 5, 5);
8273 int opcode
= extract32(insn
, 11, 5);
8274 int rm
= extract32(insn
, 16, 5);
8275 int size
= extract32(insn
, 22, 2);
8276 bool u
= extract32(insn
, 29, 1);
8279 if (opcode
>= 0x18) {
8280 /* Floating point: U, size[1] and opcode indicate operation */
8281 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
8283 case 0x1b: /* FMULX */
8284 case 0x1f: /* FRECPS */
8285 case 0x3f: /* FRSQRTS */
8286 case 0x5d: /* FACGE */
8287 case 0x7d: /* FACGT */
8288 case 0x1c: /* FCMEQ */
8289 case 0x5c: /* FCMGE */
8290 case 0x7c: /* FCMGT */
8291 case 0x7a: /* FABD */
8294 unallocated_encoding(s
);
8298 if (!fp_access_check(s
)) {
8302 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
8307 case 0x1: /* SQADD, UQADD */
8308 case 0x5: /* SQSUB, UQSUB */
8309 case 0x9: /* SQSHL, UQSHL */
8310 case 0xb: /* SQRSHL, UQRSHL */
8312 case 0x8: /* SSHL, USHL */
8313 case 0xa: /* SRSHL, URSHL */
8314 case 0x6: /* CMGT, CMHI */
8315 case 0x7: /* CMGE, CMHS */
8316 case 0x11: /* CMTST, CMEQ */
8317 case 0x10: /* ADD, SUB (vector) */
8319 unallocated_encoding(s
);
8323 case 0x16: /* SQDMULH, SQRDMULH (vector) */
8324 if (size
!= 1 && size
!= 2) {
8325 unallocated_encoding(s
);
8330 unallocated_encoding(s
);
8334 if (!fp_access_check(s
)) {
8338 tcg_rd
= tcg_temp_new_i64();
8341 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
8342 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
8344 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
8345 tcg_temp_free_i64(tcg_rn
);
8346 tcg_temp_free_i64(tcg_rm
);
8348 /* Do a single operation on the lowest element in the vector.
8349 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
8350 * no side effects for all these operations.
8351 * OPTME: special-purpose helpers would avoid doing some
8352 * unnecessary work in the helper for the 8 and 16 bit cases.
8354 NeonGenTwoOpEnvFn
*genenvfn
;
8355 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
8356 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
8357 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
8359 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
8360 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
8363 case 0x1: /* SQADD, UQADD */
8365 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8366 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
8367 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
8368 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
8370 genenvfn
= fns
[size
][u
];
8373 case 0x5: /* SQSUB, UQSUB */
8375 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8376 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
8377 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
8378 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
8380 genenvfn
= fns
[size
][u
];
8383 case 0x9: /* SQSHL, UQSHL */
8385 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8386 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
8387 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
8388 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
8390 genenvfn
= fns
[size
][u
];
8393 case 0xb: /* SQRSHL, UQRSHL */
8395 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8396 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
8397 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
8398 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
8400 genenvfn
= fns
[size
][u
];
8403 case 0x16: /* SQDMULH, SQRDMULH */
8405 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
8406 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
8407 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
8409 assert(size
== 1 || size
== 2);
8410 genenvfn
= fns
[size
- 1][u
];
8414 g_assert_not_reached();
8417 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
8418 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
8419 tcg_temp_free_i32(tcg_rd32
);
8420 tcg_temp_free_i32(tcg_rn
);
8421 tcg_temp_free_i32(tcg_rm
);
8424 write_fp_dreg(s
, rd
, tcg_rd
);
8426 tcg_temp_free_i64(tcg_rd
);
8429 /* AdvSIMD scalar three same FP16
8430 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
8431 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8432 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
8433 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8434 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
8435 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
8437 static void disas_simd_scalar_three_reg_same_fp16(DisasContext
*s
,
8440 int rd
= extract32(insn
, 0, 5);
8441 int rn
= extract32(insn
, 5, 5);
8442 int opcode
= extract32(insn
, 11, 3);
8443 int rm
= extract32(insn
, 16, 5);
8444 bool u
= extract32(insn
, 29, 1);
8445 bool a
= extract32(insn
, 23, 1);
8446 int fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
8453 case 0x03: /* FMULX */
8454 case 0x04: /* FCMEQ (reg) */
8455 case 0x07: /* FRECPS */
8456 case 0x0f: /* FRSQRTS */
8457 case 0x14: /* FCMGE (reg) */
8458 case 0x15: /* FACGE */
8459 case 0x1a: /* FABD */
8460 case 0x1c: /* FCMGT (reg) */
8461 case 0x1d: /* FACGT */
8464 unallocated_encoding(s
);
8468 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
8469 unallocated_encoding(s
);
8472 if (!fp_access_check(s
)) {
8476 fpst
= get_fpstatus_ptr(true);
8478 tcg_op1
= read_fp_hreg(s
, rn
);
8479 tcg_op2
= read_fp_hreg(s
, rm
);
8480 tcg_res
= tcg_temp_new_i32();
8483 case 0x03: /* FMULX */
8484 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8486 case 0x04: /* FCMEQ (reg) */
8487 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8489 case 0x07: /* FRECPS */
8490 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8492 case 0x0f: /* FRSQRTS */
8493 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8495 case 0x14: /* FCMGE (reg) */
8496 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8498 case 0x15: /* FACGE */
8499 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8501 case 0x1a: /* FABD */
8502 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8503 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
8505 case 0x1c: /* FCMGT (reg) */
8506 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8508 case 0x1d: /* FACGT */
8509 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8512 g_assert_not_reached();
8515 write_fp_sreg(s
, rd
, tcg_res
);
8518 tcg_temp_free_i32(tcg_res
);
8519 tcg_temp_free_i32(tcg_op1
);
8520 tcg_temp_free_i32(tcg_op2
);
8521 tcg_temp_free_ptr(fpst
);
8524 /* AdvSIMD scalar three same extra
8525 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
8526 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
8527 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
8528 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
8530 static void disas_simd_scalar_three_reg_same_extra(DisasContext
*s
,
8533 int rd
= extract32(insn
, 0, 5);
8534 int rn
= extract32(insn
, 5, 5);
8535 int opcode
= extract32(insn
, 11, 4);
8536 int rm
= extract32(insn
, 16, 5);
8537 int size
= extract32(insn
, 22, 2);
8538 bool u
= extract32(insn
, 29, 1);
8539 TCGv_i32 ele1
, ele2
, ele3
;
8543 switch (u
* 16 + opcode
) {
8544 case 0x10: /* SQRDMLAH (vector) */
8545 case 0x11: /* SQRDMLSH (vector) */
8546 if (size
!= 1 && size
!= 2) {
8547 unallocated_encoding(s
);
8550 feature
= ARM_FEATURE_V8_RDM
;
8553 unallocated_encoding(s
);
8556 if (!arm_dc_feature(s
, feature
)) {
8557 unallocated_encoding(s
);
8560 if (!fp_access_check(s
)) {
8564 /* Do a single operation on the lowest element in the vector.
8565 * We use the standard Neon helpers and rely on 0 OP 0 == 0
8566 * with no side effects for all these operations.
8567 * OPTME: special-purpose helpers would avoid doing some
8568 * unnecessary work in the helper for the 16 bit cases.
8570 ele1
= tcg_temp_new_i32();
8571 ele2
= tcg_temp_new_i32();
8572 ele3
= tcg_temp_new_i32();
8574 read_vec_element_i32(s
, ele1
, rn
, 0, size
);
8575 read_vec_element_i32(s
, ele2
, rm
, 0, size
);
8576 read_vec_element_i32(s
, ele3
, rd
, 0, size
);
8579 case 0x0: /* SQRDMLAH */
8581 gen_helper_neon_qrdmlah_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8583 gen_helper_neon_qrdmlah_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8586 case 0x1: /* SQRDMLSH */
8588 gen_helper_neon_qrdmlsh_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8590 gen_helper_neon_qrdmlsh_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8594 g_assert_not_reached();
8596 tcg_temp_free_i32(ele1
);
8597 tcg_temp_free_i32(ele2
);
8599 res
= tcg_temp_new_i64();
8600 tcg_gen_extu_i32_i64(res
, ele3
);
8601 tcg_temp_free_i32(ele3
);
8603 write_fp_dreg(s
, rd
, res
);
8604 tcg_temp_free_i64(res
);
8607 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
8608 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
8609 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
8611 /* Handle 64->64 opcodes which are shared between the scalar and
8612 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
8613 * is valid in either group and also the double-precision fp ops.
8614 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
8620 case 0x4: /* CLS, CLZ */
8622 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
8624 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
8628 /* This opcode is shared with CNT and RBIT but we have earlier
8629 * enforced that size == 3 if and only if this is the NOT insn.
8631 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
8633 case 0x7: /* SQABS, SQNEG */
8635 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
8637 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
8640 case 0xa: /* CMLT */
8641 /* 64 bit integer comparison against zero, result is
8642 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
8647 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
8648 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
8650 case 0x8: /* CMGT, CMGE */
8651 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
8653 case 0x9: /* CMEQ, CMLE */
8654 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
8656 case 0xb: /* ABS, NEG */
8658 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
8660 TCGv_i64 tcg_zero
= tcg_const_i64(0);
8661 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
8662 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
8664 tcg_temp_free_i64(tcg_zero
);
8667 case 0x2f: /* FABS */
8668 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
8670 case 0x6f: /* FNEG */
8671 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
8673 case 0x7f: /* FSQRT */
8674 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
8676 case 0x1a: /* FCVTNS */
8677 case 0x1b: /* FCVTMS */
8678 case 0x1c: /* FCVTAS */
8679 case 0x3a: /* FCVTPS */
8680 case 0x3b: /* FCVTZS */
8682 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8683 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8684 tcg_temp_free_i32(tcg_shift
);
8687 case 0x5a: /* FCVTNU */
8688 case 0x5b: /* FCVTMU */
8689 case 0x5c: /* FCVTAU */
8690 case 0x7a: /* FCVTPU */
8691 case 0x7b: /* FCVTZU */
8693 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8694 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8695 tcg_temp_free_i32(tcg_shift
);
8698 case 0x18: /* FRINTN */
8699 case 0x19: /* FRINTM */
8700 case 0x38: /* FRINTP */
8701 case 0x39: /* FRINTZ */
8702 case 0x58: /* FRINTA */
8703 case 0x79: /* FRINTI */
8704 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
8706 case 0x59: /* FRINTX */
8707 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
8710 g_assert_not_reached();
8714 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
8715 bool is_scalar
, bool is_u
, bool is_q
,
8716 int size
, int rn
, int rd
)
8718 bool is_double
= (size
== MO_64
);
8721 if (!fp_access_check(s
)) {
8725 fpst
= get_fpstatus_ptr(size
== MO_16
);
8728 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8729 TCGv_i64 tcg_zero
= tcg_const_i64(0);
8730 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8731 NeonGenTwoDoubleOPFn
*genfn
;
8736 case 0x2e: /* FCMLT (zero) */
8739 case 0x2c: /* FCMGT (zero) */
8740 genfn
= gen_helper_neon_cgt_f64
;
8742 case 0x2d: /* FCMEQ (zero) */
8743 genfn
= gen_helper_neon_ceq_f64
;
8745 case 0x6d: /* FCMLE (zero) */
8748 case 0x6c: /* FCMGE (zero) */
8749 genfn
= gen_helper_neon_cge_f64
;
8752 g_assert_not_reached();
8755 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
8756 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8758 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
8760 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
8762 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8764 tcg_temp_free_i64(tcg_res
);
8765 tcg_temp_free_i64(tcg_zero
);
8766 tcg_temp_free_i64(tcg_op
);
8768 clear_vec_high(s
, !is_scalar
, rd
);
8770 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8771 TCGv_i32 tcg_zero
= tcg_const_i32(0);
8772 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8773 NeonGenTwoSingleOPFn
*genfn
;
8775 int pass
, maxpasses
;
8777 if (size
== MO_16
) {
8779 case 0x2e: /* FCMLT (zero) */
8782 case 0x2c: /* FCMGT (zero) */
8783 genfn
= gen_helper_advsimd_cgt_f16
;
8785 case 0x2d: /* FCMEQ (zero) */
8786 genfn
= gen_helper_advsimd_ceq_f16
;
8788 case 0x6d: /* FCMLE (zero) */
8791 case 0x6c: /* FCMGE (zero) */
8792 genfn
= gen_helper_advsimd_cge_f16
;
8795 g_assert_not_reached();
8799 case 0x2e: /* FCMLT (zero) */
8802 case 0x2c: /* FCMGT (zero) */
8803 genfn
= gen_helper_neon_cgt_f32
;
8805 case 0x2d: /* FCMEQ (zero) */
8806 genfn
= gen_helper_neon_ceq_f32
;
8808 case 0x6d: /* FCMLE (zero) */
8811 case 0x6c: /* FCMGE (zero) */
8812 genfn
= gen_helper_neon_cge_f32
;
8815 g_assert_not_reached();
8822 int vector_size
= 8 << is_q
;
8823 maxpasses
= vector_size
>> size
;
8826 for (pass
= 0; pass
< maxpasses
; pass
++) {
8827 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
8829 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
8831 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
8834 write_fp_sreg(s
, rd
, tcg_res
);
8836 write_vec_element_i32(s
, tcg_res
, rd
, pass
, size
);
8839 tcg_temp_free_i32(tcg_res
);
8840 tcg_temp_free_i32(tcg_zero
);
8841 tcg_temp_free_i32(tcg_op
);
8843 clear_vec_high(s
, is_q
, rd
);
8847 tcg_temp_free_ptr(fpst
);
8850 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
8851 bool is_scalar
, bool is_u
, bool is_q
,
8852 int size
, int rn
, int rd
)
8854 bool is_double
= (size
== 3);
8855 TCGv_ptr fpst
= get_fpstatus_ptr(false);
8858 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8859 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8862 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
8863 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8865 case 0x3d: /* FRECPE */
8866 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
8868 case 0x3f: /* FRECPX */
8869 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
8871 case 0x7d: /* FRSQRTE */
8872 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
8875 g_assert_not_reached();
8877 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8879 tcg_temp_free_i64(tcg_res
);
8880 tcg_temp_free_i64(tcg_op
);
8881 clear_vec_high(s
, !is_scalar
, rd
);
8883 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8884 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8885 int pass
, maxpasses
;
8890 maxpasses
= is_q
? 4 : 2;
8893 for (pass
= 0; pass
< maxpasses
; pass
++) {
8894 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
8897 case 0x3c: /* URECPE */
8898 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
8900 case 0x3d: /* FRECPE */
8901 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
8903 case 0x3f: /* FRECPX */
8904 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
8906 case 0x7d: /* FRSQRTE */
8907 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
8910 g_assert_not_reached();
8914 write_fp_sreg(s
, rd
, tcg_res
);
8916 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8919 tcg_temp_free_i32(tcg_res
);
8920 tcg_temp_free_i32(tcg_op
);
8922 clear_vec_high(s
, is_q
, rd
);
8925 tcg_temp_free_ptr(fpst
);
8928 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
8929 int opcode
, bool u
, bool is_q
,
8930 int size
, int rn
, int rd
)
8932 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
8933 * in the source becomes a size element in the destination).
8936 TCGv_i32 tcg_res
[2];
8937 int destelt
= is_q
? 2 : 0;
8938 int passes
= scalar
? 1 : 2;
8941 tcg_res
[1] = tcg_const_i32(0);
8944 for (pass
= 0; pass
< passes
; pass
++) {
8945 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8946 NeonGenNarrowFn
*genfn
= NULL
;
8947 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
8950 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
8952 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8954 tcg_res
[pass
] = tcg_temp_new_i32();
8957 case 0x12: /* XTN, SQXTUN */
8959 static NeonGenNarrowFn
* const xtnfns
[3] = {
8960 gen_helper_neon_narrow_u8
,
8961 gen_helper_neon_narrow_u16
,
8962 tcg_gen_extrl_i64_i32
,
8964 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
8965 gen_helper_neon_unarrow_sat8
,
8966 gen_helper_neon_unarrow_sat16
,
8967 gen_helper_neon_unarrow_sat32
,
8970 genenvfn
= sqxtunfns
[size
];
8972 genfn
= xtnfns
[size
];
8976 case 0x14: /* SQXTN, UQXTN */
8978 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
8979 { gen_helper_neon_narrow_sat_s8
,
8980 gen_helper_neon_narrow_sat_u8
},
8981 { gen_helper_neon_narrow_sat_s16
,
8982 gen_helper_neon_narrow_sat_u16
},
8983 { gen_helper_neon_narrow_sat_s32
,
8984 gen_helper_neon_narrow_sat_u32
},
8986 genenvfn
= fns
[size
][u
];
8989 case 0x16: /* FCVTN, FCVTN2 */
8990 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
8992 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
8994 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
8995 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
8996 TCGv_ptr fpst
= get_fpstatus_ptr(false);
8997 TCGv_i32 ahp
= get_ahp_flag();
8999 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
9000 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, fpst
, ahp
);
9001 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, fpst
, ahp
);
9002 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
9003 tcg_temp_free_i32(tcg_lo
);
9004 tcg_temp_free_i32(tcg_hi
);
9005 tcg_temp_free_ptr(fpst
);
9006 tcg_temp_free_i32(ahp
);
9009 case 0x56: /* FCVTXN, FCVTXN2 */
9010 /* 64 bit to 32 bit float conversion
9011 * with von Neumann rounding (round to odd)
9014 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
9017 g_assert_not_reached();
9021 genfn(tcg_res
[pass
], tcg_op
);
9022 } else if (genenvfn
) {
9023 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
9026 tcg_temp_free_i64(tcg_op
);
9029 for (pass
= 0; pass
< 2; pass
++) {
9030 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
9031 tcg_temp_free_i32(tcg_res
[pass
]);
9033 clear_vec_high(s
, is_q
, rd
);
9036 /* Remaining saturating accumulating ops */
9037 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
9038 bool is_q
, int size
, int rn
, int rd
)
9040 bool is_double
= (size
== 3);
9043 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9044 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9047 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9048 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
9049 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9051 if (is_u
) { /* USQADD */
9052 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9053 } else { /* SUQADD */
9054 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9056 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9058 tcg_temp_free_i64(tcg_rd
);
9059 tcg_temp_free_i64(tcg_rn
);
9060 clear_vec_high(s
, !is_scalar
, rd
);
9062 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9063 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9064 int pass
, maxpasses
;
9069 maxpasses
= is_q
? 4 : 2;
9072 for (pass
= 0; pass
< maxpasses
; pass
++) {
9074 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
9075 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
9077 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
9078 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9081 if (is_u
) { /* USQADD */
9084 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9087 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9090 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9093 g_assert_not_reached();
9095 } else { /* SUQADD */
9098 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9101 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9104 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9107 g_assert_not_reached();
9112 TCGv_i64 tcg_zero
= tcg_const_i64(0);
9113 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
9114 tcg_temp_free_i64(tcg_zero
);
9116 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9118 tcg_temp_free_i32(tcg_rd
);
9119 tcg_temp_free_i32(tcg_rn
);
9120 clear_vec_high(s
, is_q
, rd
);
9124 /* AdvSIMD scalar two reg misc
9125 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9126 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9127 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9128 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9130 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9132 int rd
= extract32(insn
, 0, 5);
9133 int rn
= extract32(insn
, 5, 5);
9134 int opcode
= extract32(insn
, 12, 5);
9135 int size
= extract32(insn
, 22, 2);
9136 bool u
= extract32(insn
, 29, 1);
9137 bool is_fcvt
= false;
9140 TCGv_ptr tcg_fpstatus
;
9143 case 0x3: /* USQADD / SUQADD*/
9144 if (!fp_access_check(s
)) {
9147 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
9149 case 0x7: /* SQABS / SQNEG */
9151 case 0xa: /* CMLT */
9153 unallocated_encoding(s
);
9157 case 0x8: /* CMGT, CMGE */
9158 case 0x9: /* CMEQ, CMLE */
9159 case 0xb: /* ABS, NEG */
9161 unallocated_encoding(s
);
9165 case 0x12: /* SQXTUN */
9167 unallocated_encoding(s
);
9171 case 0x14: /* SQXTN, UQXTN */
9173 unallocated_encoding(s
);
9176 if (!fp_access_check(s
)) {
9179 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
9184 /* Floating point: U, size[1] and opcode indicate operation;
9185 * size[0] indicates single or double precision.
9187 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9188 size
= extract32(size
, 0, 1) ? 3 : 2;
9190 case 0x2c: /* FCMGT (zero) */
9191 case 0x2d: /* FCMEQ (zero) */
9192 case 0x2e: /* FCMLT (zero) */
9193 case 0x6c: /* FCMGE (zero) */
9194 case 0x6d: /* FCMLE (zero) */
9195 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
9197 case 0x1d: /* SCVTF */
9198 case 0x5d: /* UCVTF */
9200 bool is_signed
= (opcode
== 0x1d);
9201 if (!fp_access_check(s
)) {
9204 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
9207 case 0x3d: /* FRECPE */
9208 case 0x3f: /* FRECPX */
9209 case 0x7d: /* FRSQRTE */
9210 if (!fp_access_check(s
)) {
9213 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
9215 case 0x1a: /* FCVTNS */
9216 case 0x1b: /* FCVTMS */
9217 case 0x3a: /* FCVTPS */
9218 case 0x3b: /* FCVTZS */
9219 case 0x5a: /* FCVTNU */
9220 case 0x5b: /* FCVTMU */
9221 case 0x7a: /* FCVTPU */
9222 case 0x7b: /* FCVTZU */
9224 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9226 case 0x1c: /* FCVTAS */
9227 case 0x5c: /* FCVTAU */
9228 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
9230 rmode
= FPROUNDING_TIEAWAY
;
9232 case 0x56: /* FCVTXN, FCVTXN2 */
9234 unallocated_encoding(s
);
9237 if (!fp_access_check(s
)) {
9240 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
9243 unallocated_encoding(s
);
9248 unallocated_encoding(s
);
9252 if (!fp_access_check(s
)) {
9257 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
9258 tcg_fpstatus
= get_fpstatus_ptr(false);
9259 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9262 tcg_fpstatus
= NULL
;
9266 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
9267 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9269 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
9270 write_fp_dreg(s
, rd
, tcg_rd
);
9271 tcg_temp_free_i64(tcg_rd
);
9272 tcg_temp_free_i64(tcg_rn
);
9274 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9275 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9277 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
9280 case 0x7: /* SQABS, SQNEG */
9282 NeonGenOneOpEnvFn
*genfn
;
9283 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
9284 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
9285 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
9286 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
9288 genfn
= fns
[size
][u
];
9289 genfn(tcg_rd
, cpu_env
, tcg_rn
);
9292 case 0x1a: /* FCVTNS */
9293 case 0x1b: /* FCVTMS */
9294 case 0x1c: /* FCVTAS */
9295 case 0x3a: /* FCVTPS */
9296 case 0x3b: /* FCVTZS */
9298 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9299 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9300 tcg_temp_free_i32(tcg_shift
);
9303 case 0x5a: /* FCVTNU */
9304 case 0x5b: /* FCVTMU */
9305 case 0x5c: /* FCVTAU */
9306 case 0x7a: /* FCVTPU */
9307 case 0x7b: /* FCVTZU */
9309 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9310 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9311 tcg_temp_free_i32(tcg_shift
);
9315 g_assert_not_reached();
9318 write_fp_sreg(s
, rd
, tcg_rd
);
9319 tcg_temp_free_i32(tcg_rd
);
9320 tcg_temp_free_i32(tcg_rn
);
9324 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9325 tcg_temp_free_i32(tcg_rmode
);
9326 tcg_temp_free_ptr(tcg_fpstatus
);
9330 static void gen_ssra8_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9332 tcg_gen_vec_sar8i_i64(a
, a
, shift
);
9333 tcg_gen_vec_add8_i64(d
, d
, a
);
9336 static void gen_ssra16_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9338 tcg_gen_vec_sar16i_i64(a
, a
, shift
);
9339 tcg_gen_vec_add16_i64(d
, d
, a
);
9342 static void gen_ssra32_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9344 tcg_gen_sari_i32(a
, a
, shift
);
9345 tcg_gen_add_i32(d
, d
, a
);
9348 static void gen_ssra64_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9350 tcg_gen_sari_i64(a
, a
, shift
);
9351 tcg_gen_add_i64(d
, d
, a
);
9354 static void gen_ssra_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9356 tcg_gen_sari_vec(vece
, a
, a
, sh
);
9357 tcg_gen_add_vec(vece
, d
, d
, a
);
9360 static void gen_usra8_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9362 tcg_gen_vec_shr8i_i64(a
, a
, shift
);
9363 tcg_gen_vec_add8_i64(d
, d
, a
);
9366 static void gen_usra16_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9368 tcg_gen_vec_shr16i_i64(a
, a
, shift
);
9369 tcg_gen_vec_add16_i64(d
, d
, a
);
9372 static void gen_usra32_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9374 tcg_gen_shri_i32(a
, a
, shift
);
9375 tcg_gen_add_i32(d
, d
, a
);
9378 static void gen_usra64_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9380 tcg_gen_shri_i64(a
, a
, shift
);
9381 tcg_gen_add_i64(d
, d
, a
);
9384 static void gen_usra_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9386 tcg_gen_shri_vec(vece
, a
, a
, sh
);
9387 tcg_gen_add_vec(vece
, d
, d
, a
);
9390 static void gen_shr8_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9392 uint64_t mask
= dup_const(MO_8
, 0xff >> shift
);
9393 TCGv_i64 t
= tcg_temp_new_i64();
9395 tcg_gen_shri_i64(t
, a
, shift
);
9396 tcg_gen_andi_i64(t
, t
, mask
);
9397 tcg_gen_andi_i64(d
, d
, ~mask
);
9398 tcg_gen_or_i64(d
, d
, t
);
9399 tcg_temp_free_i64(t
);
9402 static void gen_shr16_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9404 uint64_t mask
= dup_const(MO_16
, 0xffff >> shift
);
9405 TCGv_i64 t
= tcg_temp_new_i64();
9407 tcg_gen_shri_i64(t
, a
, shift
);
9408 tcg_gen_andi_i64(t
, t
, mask
);
9409 tcg_gen_andi_i64(d
, d
, ~mask
);
9410 tcg_gen_or_i64(d
, d
, t
);
9411 tcg_temp_free_i64(t
);
9414 static void gen_shr32_ins_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9416 tcg_gen_shri_i32(a
, a
, shift
);
9417 tcg_gen_deposit_i32(d
, d
, a
, 0, 32 - shift
);
9420 static void gen_shr64_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9422 tcg_gen_shri_i64(a
, a
, shift
);
9423 tcg_gen_deposit_i64(d
, d
, a
, 0, 64 - shift
);
9426 static void gen_shr_ins_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9428 uint64_t mask
= (2ull << ((8 << vece
) - 1)) - 1;
9429 TCGv_vec t
= tcg_temp_new_vec_matching(d
);
9430 TCGv_vec m
= tcg_temp_new_vec_matching(d
);
9432 tcg_gen_dupi_vec(vece
, m
, mask
^ (mask
>> sh
));
9433 tcg_gen_shri_vec(vece
, t
, a
, sh
);
9434 tcg_gen_and_vec(vece
, d
, d
, m
);
9435 tcg_gen_or_vec(vece
, d
, d
, t
);
9437 tcg_temp_free_vec(t
);
9438 tcg_temp_free_vec(m
);
9441 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
9442 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
9443 int immh
, int immb
, int opcode
, int rn
, int rd
)
9445 static const GVecGen2i ssra_op
[4] = {
9446 { .fni8
= gen_ssra8_i64
,
9447 .fniv
= gen_ssra_vec
,
9449 .opc
= INDEX_op_sari_vec
,
9451 { .fni8
= gen_ssra16_i64
,
9452 .fniv
= gen_ssra_vec
,
9454 .opc
= INDEX_op_sari_vec
,
9456 { .fni4
= gen_ssra32_i32
,
9457 .fniv
= gen_ssra_vec
,
9459 .opc
= INDEX_op_sari_vec
,
9461 { .fni8
= gen_ssra64_i64
,
9462 .fniv
= gen_ssra_vec
,
9463 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9465 .opc
= INDEX_op_sari_vec
,
9468 static const GVecGen2i usra_op
[4] = {
9469 { .fni8
= gen_usra8_i64
,
9470 .fniv
= gen_usra_vec
,
9472 .opc
= INDEX_op_shri_vec
,
9474 { .fni8
= gen_usra16_i64
,
9475 .fniv
= gen_usra_vec
,
9477 .opc
= INDEX_op_shri_vec
,
9479 { .fni4
= gen_usra32_i32
,
9480 .fniv
= gen_usra_vec
,
9482 .opc
= INDEX_op_shri_vec
,
9484 { .fni8
= gen_usra64_i64
,
9485 .fniv
= gen_usra_vec
,
9486 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9488 .opc
= INDEX_op_shri_vec
,
9491 static const GVecGen2i sri_op
[4] = {
9492 { .fni8
= gen_shr8_ins_i64
,
9493 .fniv
= gen_shr_ins_vec
,
9495 .opc
= INDEX_op_shri_vec
,
9497 { .fni8
= gen_shr16_ins_i64
,
9498 .fniv
= gen_shr_ins_vec
,
9500 .opc
= INDEX_op_shri_vec
,
9502 { .fni4
= gen_shr32_ins_i32
,
9503 .fniv
= gen_shr_ins_vec
,
9505 .opc
= INDEX_op_shri_vec
,
9507 { .fni8
= gen_shr64_ins_i64
,
9508 .fniv
= gen_shr_ins_vec
,
9509 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9511 .opc
= INDEX_op_shri_vec
,
9515 int size
= 32 - clz32(immh
) - 1;
9516 int immhb
= immh
<< 3 | immb
;
9517 int shift
= 2 * (8 << size
) - immhb
;
9518 bool accumulate
= false;
9519 int dsize
= is_q
? 128 : 64;
9520 int esize
= 8 << size
;
9521 int elements
= dsize
/esize
;
9522 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
9523 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
9524 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
9526 uint64_t round_const
;
9529 if (extract32(immh
, 3, 1) && !is_q
) {
9530 unallocated_encoding(s
);
9533 tcg_debug_assert(size
<= 3);
9535 if (!fp_access_check(s
)) {
9540 case 0x02: /* SSRA / USRA (accumulate) */
9542 /* Shift count same as element size produces zero to add. */
9543 if (shift
== 8 << size
) {
9546 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &usra_op
[size
]);
9548 /* Shift count same as element size produces all sign to add. */
9549 if (shift
== 8 << size
) {
9552 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &ssra_op
[size
]);
9555 case 0x08: /* SRI */
9556 /* Shift count same as element size is valid but does nothing. */
9557 if (shift
== 8 << size
) {
9560 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &sri_op
[size
]);
9563 case 0x00: /* SSHR / USHR */
9565 if (shift
== 8 << size
) {
9566 /* Shift count the same size as element size produces zero. */
9567 tcg_gen_gvec_dup8i(vec_full_reg_offset(s
, rd
),
9568 is_q
? 16 : 8, vec_full_reg_size(s
), 0);
9570 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shri
, size
);
9573 /* Shift count the same size as element size produces all sign. */
9574 if (shift
== 8 << size
) {
9577 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_sari
, size
);
9581 case 0x04: /* SRSHR / URSHR (rounding) */
9583 case 0x06: /* SRSRA / URSRA (accum + rounding) */
9587 g_assert_not_reached();
9590 round_const
= 1ULL << (shift
- 1);
9591 tcg_round
= tcg_const_i64(round_const
);
9593 for (i
= 0; i
< elements
; i
++) {
9594 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
9596 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
9599 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
9600 accumulate
, is_u
, size
, shift
);
9602 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
9604 tcg_temp_free_i64(tcg_round
);
9607 clear_vec_high(s
, is_q
, rd
);
9610 static void gen_shl8_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9612 uint64_t mask
= dup_const(MO_8
, 0xff << shift
);
9613 TCGv_i64 t
= tcg_temp_new_i64();
9615 tcg_gen_shli_i64(t
, a
, shift
);
9616 tcg_gen_andi_i64(t
, t
, mask
);
9617 tcg_gen_andi_i64(d
, d
, ~mask
);
9618 tcg_gen_or_i64(d
, d
, t
);
9619 tcg_temp_free_i64(t
);
9622 static void gen_shl16_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9624 uint64_t mask
= dup_const(MO_16
, 0xffff << shift
);
9625 TCGv_i64 t
= tcg_temp_new_i64();
9627 tcg_gen_shli_i64(t
, a
, shift
);
9628 tcg_gen_andi_i64(t
, t
, mask
);
9629 tcg_gen_andi_i64(d
, d
, ~mask
);
9630 tcg_gen_or_i64(d
, d
, t
);
9631 tcg_temp_free_i64(t
);
9634 static void gen_shl32_ins_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9636 tcg_gen_deposit_i32(d
, d
, a
, shift
, 32 - shift
);
9639 static void gen_shl64_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9641 tcg_gen_deposit_i64(d
, d
, a
, shift
, 64 - shift
);
9644 static void gen_shl_ins_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9646 uint64_t mask
= (1ull << sh
) - 1;
9647 TCGv_vec t
= tcg_temp_new_vec_matching(d
);
9648 TCGv_vec m
= tcg_temp_new_vec_matching(d
);
9650 tcg_gen_dupi_vec(vece
, m
, mask
);
9651 tcg_gen_shli_vec(vece
, t
, a
, sh
);
9652 tcg_gen_and_vec(vece
, d
, d
, m
);
9653 tcg_gen_or_vec(vece
, d
, d
, t
);
9655 tcg_temp_free_vec(t
);
9656 tcg_temp_free_vec(m
);
9659 /* SHL/SLI - Vector shift left */
9660 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
9661 int immh
, int immb
, int opcode
, int rn
, int rd
)
9663 static const GVecGen2i shi_op
[4] = {
9664 { .fni8
= gen_shl8_ins_i64
,
9665 .fniv
= gen_shl_ins_vec
,
9666 .opc
= INDEX_op_shli_vec
,
9667 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9670 { .fni8
= gen_shl16_ins_i64
,
9671 .fniv
= gen_shl_ins_vec
,
9672 .opc
= INDEX_op_shli_vec
,
9673 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9676 { .fni4
= gen_shl32_ins_i32
,
9677 .fniv
= gen_shl_ins_vec
,
9678 .opc
= INDEX_op_shli_vec
,
9679 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9682 { .fni8
= gen_shl64_ins_i64
,
9683 .fniv
= gen_shl_ins_vec
,
9684 .opc
= INDEX_op_shli_vec
,
9685 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9689 int size
= 32 - clz32(immh
) - 1;
9690 int immhb
= immh
<< 3 | immb
;
9691 int shift
= immhb
- (8 << size
);
9693 if (extract32(immh
, 3, 1) && !is_q
) {
9694 unallocated_encoding(s
);
9698 if (size
> 3 && !is_q
) {
9699 unallocated_encoding(s
);
9703 if (!fp_access_check(s
)) {
9708 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &shi_op
[size
]);
9710 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shli
, size
);
9714 /* USHLL/SHLL - Vector shift left with widening */
9715 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
9716 int immh
, int immb
, int opcode
, int rn
, int rd
)
9718 int size
= 32 - clz32(immh
) - 1;
9719 int immhb
= immh
<< 3 | immb
;
9720 int shift
= immhb
- (8 << size
);
9722 int esize
= 8 << size
;
9723 int elements
= dsize
/esize
;
9724 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
9725 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
9729 unallocated_encoding(s
);
9733 if (!fp_access_check(s
)) {
9737 /* For the LL variants the store is larger than the load,
9738 * so if rd == rn we would overwrite parts of our input.
9739 * So load everything right now and use shifts in the main loop.
9741 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
9743 for (i
= 0; i
< elements
; i
++) {
9744 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
9745 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
9746 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
9747 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
9751 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
9752 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
9753 int immh
, int immb
, int opcode
, int rn
, int rd
)
9755 int immhb
= immh
<< 3 | immb
;
9756 int size
= 32 - clz32(immh
) - 1;
9758 int esize
= 8 << size
;
9759 int elements
= dsize
/esize
;
9760 int shift
= (2 * esize
) - immhb
;
9761 bool round
= extract32(opcode
, 0, 1);
9762 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
9766 if (extract32(immh
, 3, 1)) {
9767 unallocated_encoding(s
);
9771 if (!fp_access_check(s
)) {
9775 tcg_rn
= tcg_temp_new_i64();
9776 tcg_rd
= tcg_temp_new_i64();
9777 tcg_final
= tcg_temp_new_i64();
9778 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
9781 uint64_t round_const
= 1ULL << (shift
- 1);
9782 tcg_round
= tcg_const_i64(round_const
);
9787 for (i
= 0; i
< elements
; i
++) {
9788 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
9789 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
9790 false, true, size
+1, shift
);
9792 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
9796 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
9798 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
9801 tcg_temp_free_i64(tcg_round
);
9803 tcg_temp_free_i64(tcg_rn
);
9804 tcg_temp_free_i64(tcg_rd
);
9805 tcg_temp_free_i64(tcg_final
);
9807 clear_vec_high(s
, is_q
, rd
);
9811 /* AdvSIMD shift by immediate
9812 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
9813 * +---+---+---+-------------+------+------+--------+---+------+------+
9814 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
9815 * +---+---+---+-------------+------+------+--------+---+------+------+
9817 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
9819 int rd
= extract32(insn
, 0, 5);
9820 int rn
= extract32(insn
, 5, 5);
9821 int opcode
= extract32(insn
, 11, 5);
9822 int immb
= extract32(insn
, 16, 3);
9823 int immh
= extract32(insn
, 19, 4);
9824 bool is_u
= extract32(insn
, 29, 1);
9825 bool is_q
= extract32(insn
, 30, 1);
9828 case 0x08: /* SRI */
9830 unallocated_encoding(s
);
9834 case 0x00: /* SSHR / USHR */
9835 case 0x02: /* SSRA / USRA (accumulate) */
9836 case 0x04: /* SRSHR / URSHR (rounding) */
9837 case 0x06: /* SRSRA / URSRA (accum + rounding) */
9838 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9840 case 0x0a: /* SHL / SLI */
9841 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9843 case 0x10: /* SHRN */
9844 case 0x11: /* RSHRN / SQRSHRUN */
9846 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
9849 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
9852 case 0x12: /* SQSHRN / UQSHRN */
9853 case 0x13: /* SQRSHRN / UQRSHRN */
9854 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
9857 case 0x14: /* SSHLL / USHLL */
9858 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9860 case 0x1c: /* SCVTF / UCVTF */
9861 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
9864 case 0xc: /* SQSHLU */
9866 unallocated_encoding(s
);
9869 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
9871 case 0xe: /* SQSHL, UQSHL */
9872 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
9874 case 0x1f: /* FCVTZS/ FCVTZU */
9875 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
9878 unallocated_encoding(s
);
9883 /* Generate code to do a "long" addition or subtraction, ie one done in
9884 * TCGv_i64 on vector lanes twice the width specified by size.
9886 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
9887 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
9889 static NeonGenTwo64OpFn
* const fns
[3][2] = {
9890 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
9891 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
9892 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
9894 NeonGenTwo64OpFn
*genfn
;
9897 genfn
= fns
[size
][is_sub
];
9898 genfn(tcg_res
, tcg_op1
, tcg_op2
);
9901 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
9902 int opcode
, int rd
, int rn
, int rm
)
9904 /* 3-reg-different widening insns: 64 x 64 -> 128 */
9905 TCGv_i64 tcg_res
[2];
9908 tcg_res
[0] = tcg_temp_new_i64();
9909 tcg_res
[1] = tcg_temp_new_i64();
9911 /* Does this op do an adding accumulate, a subtracting accumulate,
9912 * or no accumulate at all?
9930 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
9931 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
9934 /* size == 2 means two 32x32->64 operations; this is worth special
9935 * casing because we can generally handle it inline.
9938 for (pass
= 0; pass
< 2; pass
++) {
9939 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9940 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9941 TCGv_i64 tcg_passres
;
9942 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
9944 int elt
= pass
+ is_q
* 2;
9946 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
9947 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
9950 tcg_passres
= tcg_res
[pass
];
9952 tcg_passres
= tcg_temp_new_i64();
9956 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
9957 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
9959 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
9960 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
9962 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
9963 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
9965 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
9966 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
9968 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
9969 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
9970 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
9972 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
9973 tcg_temp_free_i64(tcg_tmp1
);
9974 tcg_temp_free_i64(tcg_tmp2
);
9977 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
9978 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
9979 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
9980 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
9982 case 9: /* SQDMLAL, SQDMLAL2 */
9983 case 11: /* SQDMLSL, SQDMLSL2 */
9984 case 13: /* SQDMULL, SQDMULL2 */
9985 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
9986 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
9987 tcg_passres
, tcg_passres
);
9990 g_assert_not_reached();
9993 if (opcode
== 9 || opcode
== 11) {
9994 /* saturating accumulate ops */
9996 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
9998 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
9999 tcg_res
[pass
], tcg_passres
);
10000 } else if (accop
> 0) {
10001 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10002 } else if (accop
< 0) {
10003 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10007 tcg_temp_free_i64(tcg_passres
);
10010 tcg_temp_free_i64(tcg_op1
);
10011 tcg_temp_free_i64(tcg_op2
);
10014 /* size 0 or 1, generally helper functions */
10015 for (pass
= 0; pass
< 2; pass
++) {
10016 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10017 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10018 TCGv_i64 tcg_passres
;
10019 int elt
= pass
+ is_q
* 2;
10021 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
10022 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
10025 tcg_passres
= tcg_res
[pass
];
10027 tcg_passres
= tcg_temp_new_i64();
10031 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10032 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10034 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
10035 static NeonGenWidenFn
* const widenfns
[2][2] = {
10036 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10037 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10039 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10041 widenfn(tcg_op2_64
, tcg_op2
);
10042 widenfn(tcg_passres
, tcg_op1
);
10043 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
10044 tcg_passres
, tcg_op2_64
);
10045 tcg_temp_free_i64(tcg_op2_64
);
10048 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10049 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10052 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10054 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10058 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
10060 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
10064 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10065 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10066 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10069 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
10071 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
10075 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10077 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10081 case 9: /* SQDMLAL, SQDMLAL2 */
10082 case 11: /* SQDMLSL, SQDMLSL2 */
10083 case 13: /* SQDMULL, SQDMULL2 */
10085 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10086 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10087 tcg_passres
, tcg_passres
);
10089 case 14: /* PMULL */
10091 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
10094 g_assert_not_reached();
10096 tcg_temp_free_i32(tcg_op1
);
10097 tcg_temp_free_i32(tcg_op2
);
10100 if (opcode
== 9 || opcode
== 11) {
10101 /* saturating accumulate ops */
10103 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10105 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10109 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
10110 tcg_res
[pass
], tcg_passres
);
10112 tcg_temp_free_i64(tcg_passres
);
10117 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10118 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10119 tcg_temp_free_i64(tcg_res
[0]);
10120 tcg_temp_free_i64(tcg_res
[1]);
10123 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
10124 int opcode
, int rd
, int rn
, int rm
)
10126 TCGv_i64 tcg_res
[2];
10127 int part
= is_q
? 2 : 0;
10130 for (pass
= 0; pass
< 2; pass
++) {
10131 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10132 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10133 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
10134 static NeonGenWidenFn
* const widenfns
[3][2] = {
10135 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10136 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10137 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
10139 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10141 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10142 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
10143 widenfn(tcg_op2_wide
, tcg_op2
);
10144 tcg_temp_free_i32(tcg_op2
);
10145 tcg_res
[pass
] = tcg_temp_new_i64();
10146 gen_neon_addl(size
, (opcode
== 3),
10147 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
10148 tcg_temp_free_i64(tcg_op1
);
10149 tcg_temp_free_i64(tcg_op2_wide
);
10152 for (pass
= 0; pass
< 2; pass
++) {
10153 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10154 tcg_temp_free_i64(tcg_res
[pass
]);
10158 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
10160 tcg_gen_addi_i64(in
, in
, 1U << 31);
10161 tcg_gen_extrh_i64_i32(res
, in
);
10164 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
10165 int opcode
, int rd
, int rn
, int rm
)
10167 TCGv_i32 tcg_res
[2];
10168 int part
= is_q
? 2 : 0;
10171 for (pass
= 0; pass
< 2; pass
++) {
10172 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10173 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10174 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
10175 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
10176 { gen_helper_neon_narrow_high_u8
,
10177 gen_helper_neon_narrow_round_high_u8
},
10178 { gen_helper_neon_narrow_high_u16
,
10179 gen_helper_neon_narrow_round_high_u16
},
10180 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
10182 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
10184 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10185 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
10187 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
10189 tcg_temp_free_i64(tcg_op1
);
10190 tcg_temp_free_i64(tcg_op2
);
10192 tcg_res
[pass
] = tcg_temp_new_i32();
10193 gennarrow(tcg_res
[pass
], tcg_wideres
);
10194 tcg_temp_free_i64(tcg_wideres
);
10197 for (pass
= 0; pass
< 2; pass
++) {
10198 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
10199 tcg_temp_free_i32(tcg_res
[pass
]);
10201 clear_vec_high(s
, is_q
, rd
);
10204 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
10206 /* PMULL of 64 x 64 -> 128 is an odd special case because it
10207 * is the only three-reg-diff instruction which produces a
10208 * 128-bit wide result from a single operation. However since
10209 * it's possible to calculate the two halves more or less
10210 * separately we just use two helper calls.
10212 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10213 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10214 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10216 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
10217 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
10218 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
10219 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
10220 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
10221 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
10223 tcg_temp_free_i64(tcg_op1
);
10224 tcg_temp_free_i64(tcg_op2
);
10225 tcg_temp_free_i64(tcg_res
);
10228 /* AdvSIMD three different
10229 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
10230 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10231 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
10232 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10234 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
10236 /* Instructions in this group fall into three basic classes
10237 * (in each case with the operation working on each element in
10238 * the input vectors):
10239 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
10241 * (2) wide 64 x 128 -> 128
10242 * (3) narrowing 128 x 128 -> 64
10243 * Here we do initial decode, catch unallocated cases and
10244 * dispatch to separate functions for each class.
10246 int is_q
= extract32(insn
, 30, 1);
10247 int is_u
= extract32(insn
, 29, 1);
10248 int size
= extract32(insn
, 22, 2);
10249 int opcode
= extract32(insn
, 12, 4);
10250 int rm
= extract32(insn
, 16, 5);
10251 int rn
= extract32(insn
, 5, 5);
10252 int rd
= extract32(insn
, 0, 5);
10255 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
10256 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
10257 /* 64 x 128 -> 128 */
10259 unallocated_encoding(s
);
10262 if (!fp_access_check(s
)) {
10265 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10267 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
10268 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
10269 /* 128 x 128 -> 64 */
10271 unallocated_encoding(s
);
10274 if (!fp_access_check(s
)) {
10277 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10279 case 14: /* PMULL, PMULL2 */
10280 if (is_u
|| size
== 1 || size
== 2) {
10281 unallocated_encoding(s
);
10285 if (!arm_dc_feature(s
, ARM_FEATURE_V8_PMULL
)) {
10286 unallocated_encoding(s
);
10289 if (!fp_access_check(s
)) {
10292 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
10296 case 9: /* SQDMLAL, SQDMLAL2 */
10297 case 11: /* SQDMLSL, SQDMLSL2 */
10298 case 13: /* SQDMULL, SQDMULL2 */
10299 if (is_u
|| size
== 0) {
10300 unallocated_encoding(s
);
10304 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10305 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10306 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10307 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10308 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10309 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10310 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
10311 /* 64 x 64 -> 128 */
10313 unallocated_encoding(s
);
10317 if (!fp_access_check(s
)) {
10321 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10324 /* opcode 15 not allocated */
10325 unallocated_encoding(s
);
10330 static void gen_bsl_i64(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
10332 tcg_gen_xor_i64(rn
, rn
, rm
);
10333 tcg_gen_and_i64(rn
, rn
, rd
);
10334 tcg_gen_xor_i64(rd
, rm
, rn
);
10337 static void gen_bit_i64(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
10339 tcg_gen_xor_i64(rn
, rn
, rd
);
10340 tcg_gen_and_i64(rn
, rn
, rm
);
10341 tcg_gen_xor_i64(rd
, rd
, rn
);
10344 static void gen_bif_i64(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
10346 tcg_gen_xor_i64(rn
, rn
, rd
);
10347 tcg_gen_andc_i64(rn
, rn
, rm
);
10348 tcg_gen_xor_i64(rd
, rd
, rn
);
10351 static void gen_bsl_vec(unsigned vece
, TCGv_vec rd
, TCGv_vec rn
, TCGv_vec rm
)
10353 tcg_gen_xor_vec(vece
, rn
, rn
, rm
);
10354 tcg_gen_and_vec(vece
, rn
, rn
, rd
);
10355 tcg_gen_xor_vec(vece
, rd
, rm
, rn
);
10358 static void gen_bit_vec(unsigned vece
, TCGv_vec rd
, TCGv_vec rn
, TCGv_vec rm
)
10360 tcg_gen_xor_vec(vece
, rn
, rn
, rd
);
10361 tcg_gen_and_vec(vece
, rn
, rn
, rm
);
10362 tcg_gen_xor_vec(vece
, rd
, rd
, rn
);
10365 static void gen_bif_vec(unsigned vece
, TCGv_vec rd
, TCGv_vec rn
, TCGv_vec rm
)
10367 tcg_gen_xor_vec(vece
, rn
, rn
, rd
);
10368 tcg_gen_andc_vec(vece
, rn
, rn
, rm
);
10369 tcg_gen_xor_vec(vece
, rd
, rd
, rn
);
10372 /* Logic op (opcode == 3) subgroup of C3.6.16. */
10373 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
10375 static const GVecGen3 bsl_op
= {
10376 .fni8
= gen_bsl_i64
,
10377 .fniv
= gen_bsl_vec
,
10378 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10381 static const GVecGen3 bit_op
= {
10382 .fni8
= gen_bit_i64
,
10383 .fniv
= gen_bit_vec
,
10384 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10387 static const GVecGen3 bif_op
= {
10388 .fni8
= gen_bif_i64
,
10389 .fniv
= gen_bif_vec
,
10390 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10394 int rd
= extract32(insn
, 0, 5);
10395 int rn
= extract32(insn
, 5, 5);
10396 int rm
= extract32(insn
, 16, 5);
10397 int size
= extract32(insn
, 22, 2);
10398 bool is_u
= extract32(insn
, 29, 1);
10399 bool is_q
= extract32(insn
, 30, 1);
10401 if (!fp_access_check(s
)) {
10405 switch (size
+ 4 * is_u
) {
10407 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_and
, 0);
10410 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_andc
, 0);
10413 if (rn
== rm
) { /* MOV */
10414 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_mov
, 0);
10416 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_or
, 0);
10420 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_orc
, 0);
10423 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_xor
, 0);
10426 case 5: /* BSL bitwise select */
10427 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bsl_op
);
10429 case 6: /* BIT, bitwise insert if true */
10430 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bit_op
);
10432 case 7: /* BIF, bitwise insert if false */
10433 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bif_op
);
10437 g_assert_not_reached();
10441 /* Pairwise op subgroup of C3.6.16.
10443 * This is called directly or via the handle_3same_float for float pairwise
10444 * operations where the opcode and size are calculated differently.
10446 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
10447 int size
, int rn
, int rm
, int rd
)
10452 /* Floating point operations need fpst */
10453 if (opcode
>= 0x58) {
10454 fpst
= get_fpstatus_ptr(false);
10459 if (!fp_access_check(s
)) {
10463 /* These operations work on the concatenated rm:rn, with each pair of
10464 * adjacent elements being operated on to produce an element in the result.
10467 TCGv_i64 tcg_res
[2];
10469 for (pass
= 0; pass
< 2; pass
++) {
10470 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10471 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10472 int passreg
= (pass
== 0) ? rn
: rm
;
10474 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
10475 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
10476 tcg_res
[pass
] = tcg_temp_new_i64();
10479 case 0x17: /* ADDP */
10480 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10482 case 0x58: /* FMAXNMP */
10483 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10485 case 0x5a: /* FADDP */
10486 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10488 case 0x5e: /* FMAXP */
10489 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10491 case 0x78: /* FMINNMP */
10492 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10494 case 0x7e: /* FMINP */
10495 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10498 g_assert_not_reached();
10501 tcg_temp_free_i64(tcg_op1
);
10502 tcg_temp_free_i64(tcg_op2
);
10505 for (pass
= 0; pass
< 2; pass
++) {
10506 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10507 tcg_temp_free_i64(tcg_res
[pass
]);
10510 int maxpass
= is_q
? 4 : 2;
10511 TCGv_i32 tcg_res
[4];
10513 for (pass
= 0; pass
< maxpass
; pass
++) {
10514 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10515 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10516 NeonGenTwoOpFn
*genfn
= NULL
;
10517 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
10518 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
10520 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
10521 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
10522 tcg_res
[pass
] = tcg_temp_new_i32();
10525 case 0x17: /* ADDP */
10527 static NeonGenTwoOpFn
* const fns
[3] = {
10528 gen_helper_neon_padd_u8
,
10529 gen_helper_neon_padd_u16
,
10535 case 0x14: /* SMAXP, UMAXP */
10537 static NeonGenTwoOpFn
* const fns
[3][2] = {
10538 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
10539 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
10540 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
10542 genfn
= fns
[size
][u
];
10545 case 0x15: /* SMINP, UMINP */
10547 static NeonGenTwoOpFn
* const fns
[3][2] = {
10548 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
10549 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
10550 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
10552 genfn
= fns
[size
][u
];
10555 /* The FP operations are all on single floats (32 bit) */
10556 case 0x58: /* FMAXNMP */
10557 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10559 case 0x5a: /* FADDP */
10560 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10562 case 0x5e: /* FMAXP */
10563 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10565 case 0x78: /* FMINNMP */
10566 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10568 case 0x7e: /* FMINP */
10569 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10572 g_assert_not_reached();
10575 /* FP ops called directly, otherwise call now */
10577 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10580 tcg_temp_free_i32(tcg_op1
);
10581 tcg_temp_free_i32(tcg_op2
);
10584 for (pass
= 0; pass
< maxpass
; pass
++) {
10585 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
10586 tcg_temp_free_i32(tcg_res
[pass
]);
10588 clear_vec_high(s
, is_q
, rd
);
10592 tcg_temp_free_ptr(fpst
);
10596 /* Floating point op subgroup of C3.6.16. */
10597 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
10599 /* For floating point ops, the U, size[1] and opcode bits
10600 * together indicate the operation. size[0] indicates single
10603 int fpopcode
= extract32(insn
, 11, 5)
10604 | (extract32(insn
, 23, 1) << 5)
10605 | (extract32(insn
, 29, 1) << 6);
10606 int is_q
= extract32(insn
, 30, 1);
10607 int size
= extract32(insn
, 22, 1);
10608 int rm
= extract32(insn
, 16, 5);
10609 int rn
= extract32(insn
, 5, 5);
10610 int rd
= extract32(insn
, 0, 5);
10612 int datasize
= is_q
? 128 : 64;
10613 int esize
= 32 << size
;
10614 int elements
= datasize
/ esize
;
10616 if (size
== 1 && !is_q
) {
10617 unallocated_encoding(s
);
10621 switch (fpopcode
) {
10622 case 0x58: /* FMAXNMP */
10623 case 0x5a: /* FADDP */
10624 case 0x5e: /* FMAXP */
10625 case 0x78: /* FMINNMP */
10626 case 0x7e: /* FMINP */
10627 if (size
&& !is_q
) {
10628 unallocated_encoding(s
);
10631 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
10634 case 0x1b: /* FMULX */
10635 case 0x1f: /* FRECPS */
10636 case 0x3f: /* FRSQRTS */
10637 case 0x5d: /* FACGE */
10638 case 0x7d: /* FACGT */
10639 case 0x19: /* FMLA */
10640 case 0x39: /* FMLS */
10641 case 0x18: /* FMAXNM */
10642 case 0x1a: /* FADD */
10643 case 0x1c: /* FCMEQ */
10644 case 0x1e: /* FMAX */
10645 case 0x38: /* FMINNM */
10646 case 0x3a: /* FSUB */
10647 case 0x3e: /* FMIN */
10648 case 0x5b: /* FMUL */
10649 case 0x5c: /* FCMGE */
10650 case 0x5f: /* FDIV */
10651 case 0x7a: /* FABD */
10652 case 0x7c: /* FCMGT */
10653 if (!fp_access_check(s
)) {
10657 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
10660 unallocated_encoding(s
);
10665 static void gen_mla8_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10667 gen_helper_neon_mul_u8(a
, a
, b
);
10668 gen_helper_neon_add_u8(d
, d
, a
);
10671 static void gen_mla16_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10673 gen_helper_neon_mul_u16(a
, a
, b
);
10674 gen_helper_neon_add_u16(d
, d
, a
);
10677 static void gen_mla32_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10679 tcg_gen_mul_i32(a
, a
, b
);
10680 tcg_gen_add_i32(d
, d
, a
);
10683 static void gen_mla64_i64(TCGv_i64 d
, TCGv_i64 a
, TCGv_i64 b
)
10685 tcg_gen_mul_i64(a
, a
, b
);
10686 tcg_gen_add_i64(d
, d
, a
);
10689 static void gen_mla_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, TCGv_vec b
)
10691 tcg_gen_mul_vec(vece
, a
, a
, b
);
10692 tcg_gen_add_vec(vece
, d
, d
, a
);
10695 static void gen_mls8_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10697 gen_helper_neon_mul_u8(a
, a
, b
);
10698 gen_helper_neon_sub_u8(d
, d
, a
);
10701 static void gen_mls16_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10703 gen_helper_neon_mul_u16(a
, a
, b
);
10704 gen_helper_neon_sub_u16(d
, d
, a
);
10707 static void gen_mls32_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10709 tcg_gen_mul_i32(a
, a
, b
);
10710 tcg_gen_sub_i32(d
, d
, a
);
10713 static void gen_mls64_i64(TCGv_i64 d
, TCGv_i64 a
, TCGv_i64 b
)
10715 tcg_gen_mul_i64(a
, a
, b
);
10716 tcg_gen_sub_i64(d
, d
, a
);
10719 static void gen_mls_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, TCGv_vec b
)
10721 tcg_gen_mul_vec(vece
, a
, a
, b
);
10722 tcg_gen_sub_vec(vece
, d
, d
, a
);
10725 /* Integer op subgroup of C3.6.16. */
10726 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
10728 static const GVecGen3 cmtst_op
[4] = {
10729 { .fni4
= gen_helper_neon_tst_u8
,
10730 .fniv
= gen_cmtst_vec
,
10732 { .fni4
= gen_helper_neon_tst_u16
,
10733 .fniv
= gen_cmtst_vec
,
10735 { .fni4
= gen_cmtst_i32
,
10736 .fniv
= gen_cmtst_vec
,
10738 { .fni8
= gen_cmtst_i64
,
10739 .fniv
= gen_cmtst_vec
,
10740 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10743 static const GVecGen3 mla_op
[4] = {
10744 { .fni4
= gen_mla8_i32
,
10745 .fniv
= gen_mla_vec
,
10746 .opc
= INDEX_op_mul_vec
,
10749 { .fni4
= gen_mla16_i32
,
10750 .fniv
= gen_mla_vec
,
10751 .opc
= INDEX_op_mul_vec
,
10754 { .fni4
= gen_mla32_i32
,
10755 .fniv
= gen_mla_vec
,
10756 .opc
= INDEX_op_mul_vec
,
10759 { .fni8
= gen_mla64_i64
,
10760 .fniv
= gen_mla_vec
,
10761 .opc
= INDEX_op_mul_vec
,
10762 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10766 static const GVecGen3 mls_op
[4] = {
10767 { .fni4
= gen_mls8_i32
,
10768 .fniv
= gen_mls_vec
,
10769 .opc
= INDEX_op_mul_vec
,
10772 { .fni4
= gen_mls16_i32
,
10773 .fniv
= gen_mls_vec
,
10774 .opc
= INDEX_op_mul_vec
,
10777 { .fni4
= gen_mls32_i32
,
10778 .fniv
= gen_mls_vec
,
10779 .opc
= INDEX_op_mul_vec
,
10782 { .fni8
= gen_mls64_i64
,
10783 .fniv
= gen_mls_vec
,
10784 .opc
= INDEX_op_mul_vec
,
10785 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10790 int is_q
= extract32(insn
, 30, 1);
10791 int u
= extract32(insn
, 29, 1);
10792 int size
= extract32(insn
, 22, 2);
10793 int opcode
= extract32(insn
, 11, 5);
10794 int rm
= extract32(insn
, 16, 5);
10795 int rn
= extract32(insn
, 5, 5);
10796 int rd
= extract32(insn
, 0, 5);
10801 case 0x13: /* MUL, PMUL */
10802 if (u
&& size
!= 0) {
10803 unallocated_encoding(s
);
10807 case 0x0: /* SHADD, UHADD */
10808 case 0x2: /* SRHADD, URHADD */
10809 case 0x4: /* SHSUB, UHSUB */
10810 case 0xc: /* SMAX, UMAX */
10811 case 0xd: /* SMIN, UMIN */
10812 case 0xe: /* SABD, UABD */
10813 case 0xf: /* SABA, UABA */
10814 case 0x12: /* MLA, MLS */
10816 unallocated_encoding(s
);
10820 case 0x16: /* SQDMULH, SQRDMULH */
10821 if (size
== 0 || size
== 3) {
10822 unallocated_encoding(s
);
10827 if (size
== 3 && !is_q
) {
10828 unallocated_encoding(s
);
10834 if (!fp_access_check(s
)) {
10839 case 0x10: /* ADD, SUB */
10841 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_sub
, size
);
10843 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_add
, size
);
10846 case 0x13: /* MUL, PMUL */
10847 if (!u
) { /* MUL */
10848 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_mul
, size
);
10852 case 0x12: /* MLA, MLS */
10854 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mls_op
[size
]);
10856 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mla_op
[size
]);
10860 if (!u
) { /* CMTST */
10861 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &cmtst_op
[size
]);
10865 cond
= TCG_COND_EQ
;
10867 case 0x06: /* CMGT, CMHI */
10868 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
10870 case 0x07: /* CMGE, CMHS */
10871 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
10873 tcg_gen_gvec_cmp(cond
, size
, vec_full_reg_offset(s
, rd
),
10874 vec_full_reg_offset(s
, rn
),
10875 vec_full_reg_offset(s
, rm
),
10876 is_q
? 16 : 8, vec_full_reg_size(s
));
10882 for (pass
= 0; pass
< 2; pass
++) {
10883 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10884 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10885 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10887 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10888 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
10890 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
10892 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10894 tcg_temp_free_i64(tcg_res
);
10895 tcg_temp_free_i64(tcg_op1
);
10896 tcg_temp_free_i64(tcg_op2
);
10899 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
10900 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10901 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10902 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10903 NeonGenTwoOpFn
*genfn
= NULL
;
10904 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
10906 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
10907 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
10910 case 0x0: /* SHADD, UHADD */
10912 static NeonGenTwoOpFn
* const fns
[3][2] = {
10913 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
10914 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
10915 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
10917 genfn
= fns
[size
][u
];
10920 case 0x1: /* SQADD, UQADD */
10922 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
10923 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
10924 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
10925 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
10927 genenvfn
= fns
[size
][u
];
10930 case 0x2: /* SRHADD, URHADD */
10932 static NeonGenTwoOpFn
* const fns
[3][2] = {
10933 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
10934 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
10935 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
10937 genfn
= fns
[size
][u
];
10940 case 0x4: /* SHSUB, UHSUB */
10942 static NeonGenTwoOpFn
* const fns
[3][2] = {
10943 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
10944 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
10945 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
10947 genfn
= fns
[size
][u
];
10950 case 0x5: /* SQSUB, UQSUB */
10952 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
10953 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
10954 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
10955 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
10957 genenvfn
= fns
[size
][u
];
10960 case 0x8: /* SSHL, USHL */
10962 static NeonGenTwoOpFn
* const fns
[3][2] = {
10963 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
10964 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
10965 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
10967 genfn
= fns
[size
][u
];
10970 case 0x9: /* SQSHL, UQSHL */
10972 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
10973 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
10974 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
10975 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
10977 genenvfn
= fns
[size
][u
];
10980 case 0xa: /* SRSHL, URSHL */
10982 static NeonGenTwoOpFn
* const fns
[3][2] = {
10983 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
10984 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
10985 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
10987 genfn
= fns
[size
][u
];
10990 case 0xb: /* SQRSHL, UQRSHL */
10992 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
10993 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
10994 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
10995 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
10997 genenvfn
= fns
[size
][u
];
11000 case 0xc: /* SMAX, UMAX */
11002 static NeonGenTwoOpFn
* const fns
[3][2] = {
11003 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
11004 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
11005 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
11007 genfn
= fns
[size
][u
];
11011 case 0xd: /* SMIN, UMIN */
11013 static NeonGenTwoOpFn
* const fns
[3][2] = {
11014 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
11015 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
11016 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
11018 genfn
= fns
[size
][u
];
11021 case 0xe: /* SABD, UABD */
11022 case 0xf: /* SABA, UABA */
11024 static NeonGenTwoOpFn
* const fns
[3][2] = {
11025 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
11026 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
11027 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
11029 genfn
= fns
[size
][u
];
11032 case 0x13: /* MUL, PMUL */
11033 assert(u
); /* PMUL */
11035 genfn
= gen_helper_neon_mul_p8
;
11037 case 0x16: /* SQDMULH, SQRDMULH */
11039 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
11040 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
11041 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
11043 assert(size
== 1 || size
== 2);
11044 genenvfn
= fns
[size
- 1][u
];
11048 g_assert_not_reached();
11052 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
11054 genfn(tcg_res
, tcg_op1
, tcg_op2
);
11057 if (opcode
== 0xf) {
11058 /* SABA, UABA: accumulating ops */
11059 static NeonGenTwoOpFn
* const fns
[3] = {
11060 gen_helper_neon_add_u8
,
11061 gen_helper_neon_add_u16
,
11065 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
11066 fns
[size
](tcg_res
, tcg_op1
, tcg_res
);
11069 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
11071 tcg_temp_free_i32(tcg_res
);
11072 tcg_temp_free_i32(tcg_op1
);
11073 tcg_temp_free_i32(tcg_op2
);
11076 clear_vec_high(s
, is_q
, rd
);
11079 /* AdvSIMD three same
11080 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11081 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11082 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11083 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11085 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
11087 int opcode
= extract32(insn
, 11, 5);
11090 case 0x3: /* logic ops */
11091 disas_simd_3same_logic(s
, insn
);
11093 case 0x17: /* ADDP */
11094 case 0x14: /* SMAXP, UMAXP */
11095 case 0x15: /* SMINP, UMINP */
11097 /* Pairwise operations */
11098 int is_q
= extract32(insn
, 30, 1);
11099 int u
= extract32(insn
, 29, 1);
11100 int size
= extract32(insn
, 22, 2);
11101 int rm
= extract32(insn
, 16, 5);
11102 int rn
= extract32(insn
, 5, 5);
11103 int rd
= extract32(insn
, 0, 5);
11104 if (opcode
== 0x17) {
11105 if (u
|| (size
== 3 && !is_q
)) {
11106 unallocated_encoding(s
);
11111 unallocated_encoding(s
);
11115 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
11118 case 0x18 ... 0x31:
11119 /* floating point ops, sz[1] and U are part of opcode */
11120 disas_simd_3same_float(s
, insn
);
11123 disas_simd_3same_int(s
, insn
);
11129 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11131 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11132 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11133 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11134 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11136 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11137 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11140 static void disas_simd_three_reg_same_fp16(DisasContext
*s
, uint32_t insn
)
11142 int opcode
, fpopcode
;
11143 int is_q
, u
, a
, rm
, rn
, rd
;
11144 int datasize
, elements
;
11147 bool pairwise
= false;
11149 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
11150 unallocated_encoding(s
);
11154 if (!fp_access_check(s
)) {
11158 /* For these floating point ops, the U, a and opcode bits
11159 * together indicate the operation.
11161 opcode
= extract32(insn
, 11, 3);
11162 u
= extract32(insn
, 29, 1);
11163 a
= extract32(insn
, 23, 1);
11164 is_q
= extract32(insn
, 30, 1);
11165 rm
= extract32(insn
, 16, 5);
11166 rn
= extract32(insn
, 5, 5);
11167 rd
= extract32(insn
, 0, 5);
11169 fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
11170 datasize
= is_q
? 128 : 64;
11171 elements
= datasize
/ 16;
11173 switch (fpopcode
) {
11174 case 0x10: /* FMAXNMP */
11175 case 0x12: /* FADDP */
11176 case 0x16: /* FMAXP */
11177 case 0x18: /* FMINNMP */
11178 case 0x1e: /* FMINP */
11183 fpst
= get_fpstatus_ptr(true);
11186 int maxpass
= is_q
? 8 : 4;
11187 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11188 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11189 TCGv_i32 tcg_res
[8];
11191 for (pass
= 0; pass
< maxpass
; pass
++) {
11192 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
11193 int passelt
= (pass
<< 1) & (maxpass
- 1);
11195 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_16
);
11196 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_16
);
11197 tcg_res
[pass
] = tcg_temp_new_i32();
11199 switch (fpopcode
) {
11200 case 0x10: /* FMAXNMP */
11201 gen_helper_advsimd_maxnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11204 case 0x12: /* FADDP */
11205 gen_helper_advsimd_addh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11207 case 0x16: /* FMAXP */
11208 gen_helper_advsimd_maxh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11210 case 0x18: /* FMINNMP */
11211 gen_helper_advsimd_minnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11214 case 0x1e: /* FMINP */
11215 gen_helper_advsimd_minh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11218 g_assert_not_reached();
11222 for (pass
= 0; pass
< maxpass
; pass
++) {
11223 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_16
);
11224 tcg_temp_free_i32(tcg_res
[pass
]);
11227 tcg_temp_free_i32(tcg_op1
);
11228 tcg_temp_free_i32(tcg_op2
);
11231 for (pass
= 0; pass
< elements
; pass
++) {
11232 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11233 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11234 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11236 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_16
);
11237 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_16
);
11239 switch (fpopcode
) {
11240 case 0x0: /* FMAXNM */
11241 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11243 case 0x1: /* FMLA */
11244 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11245 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11248 case 0x2: /* FADD */
11249 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11251 case 0x3: /* FMULX */
11252 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11254 case 0x4: /* FCMEQ */
11255 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11257 case 0x6: /* FMAX */
11258 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11260 case 0x7: /* FRECPS */
11261 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11263 case 0x8: /* FMINNM */
11264 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11266 case 0x9: /* FMLS */
11267 /* As usual for ARM, separate negation for fused multiply-add */
11268 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
11269 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11270 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11273 case 0xa: /* FSUB */
11274 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11276 case 0xe: /* FMIN */
11277 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11279 case 0xf: /* FRSQRTS */
11280 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11282 case 0x13: /* FMUL */
11283 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11285 case 0x14: /* FCMGE */
11286 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11288 case 0x15: /* FACGE */
11289 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11291 case 0x17: /* FDIV */
11292 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11294 case 0x1a: /* FABD */
11295 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11296 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
11298 case 0x1c: /* FCMGT */
11299 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11301 case 0x1d: /* FACGT */
11302 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11305 fprintf(stderr
, "%s: insn %#04x, fpop %#2x @ %#" PRIx64
"\n",
11306 __func__
, insn
, fpopcode
, s
->pc
);
11307 g_assert_not_reached();
11310 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11311 tcg_temp_free_i32(tcg_res
);
11312 tcg_temp_free_i32(tcg_op1
);
11313 tcg_temp_free_i32(tcg_op2
);
11317 tcg_temp_free_ptr(fpst
);
11319 clear_vec_high(s
, is_q
, rd
);
11322 /* AdvSIMD three same extra
11323 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
11324 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11325 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
11326 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11328 static void disas_simd_three_reg_same_extra(DisasContext
*s
, uint32_t insn
)
11330 int rd
= extract32(insn
, 0, 5);
11331 int rn
= extract32(insn
, 5, 5);
11332 int opcode
= extract32(insn
, 11, 4);
11333 int rm
= extract32(insn
, 16, 5);
11334 int size
= extract32(insn
, 22, 2);
11335 bool u
= extract32(insn
, 29, 1);
11336 bool is_q
= extract32(insn
, 30, 1);
11339 switch (u
* 16 + opcode
) {
11340 case 0x10: /* SQRDMLAH (vector) */
11341 case 0x11: /* SQRDMLSH (vector) */
11342 if (size
!= 1 && size
!= 2) {
11343 unallocated_encoding(s
);
11346 feature
= ARM_FEATURE_V8_RDM
;
11348 case 0x02: /* SDOT (vector) */
11349 case 0x12: /* UDOT (vector) */
11350 if (size
!= MO_32
) {
11351 unallocated_encoding(s
);
11354 feature
= ARM_FEATURE_V8_DOTPROD
;
11356 case 0x8: /* FCMLA, #0 */
11357 case 0x9: /* FCMLA, #90 */
11358 case 0xa: /* FCMLA, #180 */
11359 case 0xb: /* FCMLA, #270 */
11360 case 0xc: /* FCADD, #90 */
11361 case 0xe: /* FCADD, #270 */
11363 || (size
== 1 && !arm_dc_feature(s
, ARM_FEATURE_V8_FP16
))
11364 || (size
== 3 && !is_q
)) {
11365 unallocated_encoding(s
);
11368 feature
= ARM_FEATURE_V8_FCMA
;
11371 unallocated_encoding(s
);
11374 if (!arm_dc_feature(s
, feature
)) {
11375 unallocated_encoding(s
);
11378 if (!fp_access_check(s
)) {
11383 case 0x0: /* SQRDMLAH (vector) */
11386 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s16
);
11389 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s32
);
11392 g_assert_not_reached();
11396 case 0x1: /* SQRDMLSH (vector) */
11399 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s16
);
11402 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s32
);
11405 g_assert_not_reached();
11409 case 0x2: /* SDOT / UDOT */
11410 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, 0,
11411 u
? gen_helper_gvec_udot_b
: gen_helper_gvec_sdot_b
);
11414 case 0x8: /* FCMLA, #0 */
11415 case 0x9: /* FCMLA, #90 */
11416 case 0xa: /* FCMLA, #180 */
11417 case 0xb: /* FCMLA, #270 */
11418 rot
= extract32(opcode
, 0, 2);
11421 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, true, rot
,
11422 gen_helper_gvec_fcmlah
);
11425 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11426 gen_helper_gvec_fcmlas
);
11429 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11430 gen_helper_gvec_fcmlad
);
11433 g_assert_not_reached();
11437 case 0xc: /* FCADD, #90 */
11438 case 0xe: /* FCADD, #270 */
11439 rot
= extract32(opcode
, 1, 1);
11442 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11443 gen_helper_gvec_fcaddh
);
11446 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11447 gen_helper_gvec_fcadds
);
11450 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11451 gen_helper_gvec_fcaddd
);
11454 g_assert_not_reached();
11459 g_assert_not_reached();
11463 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
11464 int size
, int rn
, int rd
)
11466 /* Handle 2-reg-misc ops which are widening (so each size element
11467 * in the source becomes a 2*size element in the destination.
11468 * The only instruction like this is FCVTL.
11473 /* 32 -> 64 bit fp conversion */
11474 TCGv_i64 tcg_res
[2];
11475 int srcelt
= is_q
? 2 : 0;
11477 for (pass
= 0; pass
< 2; pass
++) {
11478 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11479 tcg_res
[pass
] = tcg_temp_new_i64();
11481 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
11482 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
11483 tcg_temp_free_i32(tcg_op
);
11485 for (pass
= 0; pass
< 2; pass
++) {
11486 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11487 tcg_temp_free_i64(tcg_res
[pass
]);
11490 /* 16 -> 32 bit fp conversion */
11491 int srcelt
= is_q
? 4 : 0;
11492 TCGv_i32 tcg_res
[4];
11493 TCGv_ptr fpst
= get_fpstatus_ptr(false);
11494 TCGv_i32 ahp
= get_ahp_flag();
11496 for (pass
= 0; pass
< 4; pass
++) {
11497 tcg_res
[pass
] = tcg_temp_new_i32();
11499 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
11500 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
11503 for (pass
= 0; pass
< 4; pass
++) {
11504 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
11505 tcg_temp_free_i32(tcg_res
[pass
]);
11508 tcg_temp_free_ptr(fpst
);
11509 tcg_temp_free_i32(ahp
);
11513 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
11514 bool is_q
, int size
, int rn
, int rd
)
11516 int op
= (opcode
<< 1) | u
;
11517 int opsz
= op
+ size
;
11518 int grp_size
= 3 - opsz
;
11519 int dsize
= is_q
? 128 : 64;
11523 unallocated_encoding(s
);
11527 if (!fp_access_check(s
)) {
11532 /* Special case bytes, use bswap op on each group of elements */
11533 int groups
= dsize
/ (8 << grp_size
);
11535 for (i
= 0; i
< groups
; i
++) {
11536 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
11538 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
11539 switch (grp_size
) {
11541 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
11544 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
11547 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
11550 g_assert_not_reached();
11552 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
11553 tcg_temp_free_i64(tcg_tmp
);
11555 clear_vec_high(s
, is_q
, rd
);
11557 int revmask
= (1 << grp_size
) - 1;
11558 int esize
= 8 << size
;
11559 int elements
= dsize
/ esize
;
11560 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
11561 TCGv_i64 tcg_rd
= tcg_const_i64(0);
11562 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
11564 for (i
= 0; i
< elements
; i
++) {
11565 int e_rev
= (i
& 0xf) ^ revmask
;
11566 int off
= e_rev
* esize
;
11567 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
11569 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
11570 tcg_rn
, off
- 64, esize
);
11572 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
11575 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
11576 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
11578 tcg_temp_free_i64(tcg_rd_hi
);
11579 tcg_temp_free_i64(tcg_rd
);
11580 tcg_temp_free_i64(tcg_rn
);
11584 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
11585 bool is_q
, int size
, int rn
, int rd
)
11587 /* Implement the pairwise operations from 2-misc:
11588 * SADDLP, UADDLP, SADALP, UADALP.
11589 * These all add pairs of elements in the input to produce a
11590 * double-width result element in the output (possibly accumulating).
11592 bool accum
= (opcode
== 0x6);
11593 int maxpass
= is_q
? 2 : 1;
11595 TCGv_i64 tcg_res
[2];
11598 /* 32 + 32 -> 64 op */
11599 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
11601 for (pass
= 0; pass
< maxpass
; pass
++) {
11602 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11603 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11605 tcg_res
[pass
] = tcg_temp_new_i64();
11607 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
11608 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
11609 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11611 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
11612 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
11615 tcg_temp_free_i64(tcg_op1
);
11616 tcg_temp_free_i64(tcg_op2
);
11619 for (pass
= 0; pass
< maxpass
; pass
++) {
11620 TCGv_i64 tcg_op
= tcg_temp_new_i64();
11621 NeonGenOneOpFn
*genfn
;
11622 static NeonGenOneOpFn
* const fns
[2][2] = {
11623 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
11624 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
11627 genfn
= fns
[size
][u
];
11629 tcg_res
[pass
] = tcg_temp_new_i64();
11631 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
11632 genfn(tcg_res
[pass
], tcg_op
);
11635 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
11637 gen_helper_neon_addl_u16(tcg_res
[pass
],
11638 tcg_res
[pass
], tcg_op
);
11640 gen_helper_neon_addl_u32(tcg_res
[pass
],
11641 tcg_res
[pass
], tcg_op
);
11644 tcg_temp_free_i64(tcg_op
);
11648 tcg_res
[1] = tcg_const_i64(0);
11650 for (pass
= 0; pass
< 2; pass
++) {
11651 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11652 tcg_temp_free_i64(tcg_res
[pass
]);
11656 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
11658 /* Implement SHLL and SHLL2 */
11660 int part
= is_q
? 2 : 0;
11661 TCGv_i64 tcg_res
[2];
11663 for (pass
= 0; pass
< 2; pass
++) {
11664 static NeonGenWidenFn
* const widenfns
[3] = {
11665 gen_helper_neon_widen_u8
,
11666 gen_helper_neon_widen_u16
,
11667 tcg_gen_extu_i32_i64
,
11669 NeonGenWidenFn
*widenfn
= widenfns
[size
];
11670 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11672 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
11673 tcg_res
[pass
] = tcg_temp_new_i64();
11674 widenfn(tcg_res
[pass
], tcg_op
);
11675 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
11677 tcg_temp_free_i32(tcg_op
);
11680 for (pass
= 0; pass
< 2; pass
++) {
11681 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11682 tcg_temp_free_i64(tcg_res
[pass
]);
11686 /* AdvSIMD two reg misc
11687 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
11688 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11689 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
11690 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11692 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
11694 int size
= extract32(insn
, 22, 2);
11695 int opcode
= extract32(insn
, 12, 5);
11696 bool u
= extract32(insn
, 29, 1);
11697 bool is_q
= extract32(insn
, 30, 1);
11698 int rn
= extract32(insn
, 5, 5);
11699 int rd
= extract32(insn
, 0, 5);
11700 bool need_fpstatus
= false;
11701 bool need_rmode
= false;
11703 TCGv_i32 tcg_rmode
;
11704 TCGv_ptr tcg_fpstatus
;
11707 case 0x0: /* REV64, REV32 */
11708 case 0x1: /* REV16 */
11709 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
11711 case 0x5: /* CNT, NOT, RBIT */
11712 if (u
&& size
== 0) {
11715 } else if (u
&& size
== 1) {
11718 } else if (!u
&& size
== 0) {
11722 unallocated_encoding(s
);
11724 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
11725 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
11727 unallocated_encoding(s
);
11730 if (!fp_access_check(s
)) {
11734 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
11736 case 0x4: /* CLS, CLZ */
11738 unallocated_encoding(s
);
11742 case 0x2: /* SADDLP, UADDLP */
11743 case 0x6: /* SADALP, UADALP */
11745 unallocated_encoding(s
);
11748 if (!fp_access_check(s
)) {
11751 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
11753 case 0x13: /* SHLL, SHLL2 */
11754 if (u
== 0 || size
== 3) {
11755 unallocated_encoding(s
);
11758 if (!fp_access_check(s
)) {
11761 handle_shll(s
, is_q
, size
, rn
, rd
);
11763 case 0xa: /* CMLT */
11765 unallocated_encoding(s
);
11769 case 0x8: /* CMGT, CMGE */
11770 case 0x9: /* CMEQ, CMLE */
11771 case 0xb: /* ABS, NEG */
11772 if (size
== 3 && !is_q
) {
11773 unallocated_encoding(s
);
11777 case 0x3: /* SUQADD, USQADD */
11778 if (size
== 3 && !is_q
) {
11779 unallocated_encoding(s
);
11782 if (!fp_access_check(s
)) {
11785 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
11787 case 0x7: /* SQABS, SQNEG */
11788 if (size
== 3 && !is_q
) {
11789 unallocated_encoding(s
);
11794 case 0x16 ... 0x1d:
11797 /* Floating point: U, size[1] and opcode indicate operation;
11798 * size[0] indicates single or double precision.
11800 int is_double
= extract32(size
, 0, 1);
11801 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
11802 size
= is_double
? 3 : 2;
11804 case 0x2f: /* FABS */
11805 case 0x6f: /* FNEG */
11806 if (size
== 3 && !is_q
) {
11807 unallocated_encoding(s
);
11811 case 0x1d: /* SCVTF */
11812 case 0x5d: /* UCVTF */
11814 bool is_signed
= (opcode
== 0x1d) ? true : false;
11815 int elements
= is_double
? 2 : is_q
? 4 : 2;
11816 if (is_double
&& !is_q
) {
11817 unallocated_encoding(s
);
11820 if (!fp_access_check(s
)) {
11823 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
11826 case 0x2c: /* FCMGT (zero) */
11827 case 0x2d: /* FCMEQ (zero) */
11828 case 0x2e: /* FCMLT (zero) */
11829 case 0x6c: /* FCMGE (zero) */
11830 case 0x6d: /* FCMLE (zero) */
11831 if (size
== 3 && !is_q
) {
11832 unallocated_encoding(s
);
11835 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
11837 case 0x7f: /* FSQRT */
11838 if (size
== 3 && !is_q
) {
11839 unallocated_encoding(s
);
11843 case 0x1a: /* FCVTNS */
11844 case 0x1b: /* FCVTMS */
11845 case 0x3a: /* FCVTPS */
11846 case 0x3b: /* FCVTZS */
11847 case 0x5a: /* FCVTNU */
11848 case 0x5b: /* FCVTMU */
11849 case 0x7a: /* FCVTPU */
11850 case 0x7b: /* FCVTZU */
11851 need_fpstatus
= true;
11853 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
11854 if (size
== 3 && !is_q
) {
11855 unallocated_encoding(s
);
11859 case 0x5c: /* FCVTAU */
11860 case 0x1c: /* FCVTAS */
11861 need_fpstatus
= true;
11863 rmode
= FPROUNDING_TIEAWAY
;
11864 if (size
== 3 && !is_q
) {
11865 unallocated_encoding(s
);
11869 case 0x3c: /* URECPE */
11871 unallocated_encoding(s
);
11875 case 0x3d: /* FRECPE */
11876 case 0x7d: /* FRSQRTE */
11877 if (size
== 3 && !is_q
) {
11878 unallocated_encoding(s
);
11881 if (!fp_access_check(s
)) {
11884 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
11886 case 0x56: /* FCVTXN, FCVTXN2 */
11888 unallocated_encoding(s
);
11892 case 0x16: /* FCVTN, FCVTN2 */
11893 /* handle_2misc_narrow does a 2*size -> size operation, but these
11894 * instructions encode the source size rather than dest size.
11896 if (!fp_access_check(s
)) {
11899 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
11901 case 0x17: /* FCVTL, FCVTL2 */
11902 if (!fp_access_check(s
)) {
11905 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
11907 case 0x18: /* FRINTN */
11908 case 0x19: /* FRINTM */
11909 case 0x38: /* FRINTP */
11910 case 0x39: /* FRINTZ */
11912 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
11914 case 0x59: /* FRINTX */
11915 case 0x79: /* FRINTI */
11916 need_fpstatus
= true;
11917 if (size
== 3 && !is_q
) {
11918 unallocated_encoding(s
);
11922 case 0x58: /* FRINTA */
11924 rmode
= FPROUNDING_TIEAWAY
;
11925 need_fpstatus
= true;
11926 if (size
== 3 && !is_q
) {
11927 unallocated_encoding(s
);
11931 case 0x7c: /* URSQRTE */
11933 unallocated_encoding(s
);
11936 need_fpstatus
= true;
11939 unallocated_encoding(s
);
11945 unallocated_encoding(s
);
11949 if (!fp_access_check(s
)) {
11953 if (need_fpstatus
|| need_rmode
) {
11954 tcg_fpstatus
= get_fpstatus_ptr(false);
11956 tcg_fpstatus
= NULL
;
11959 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
11960 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
11967 if (u
&& size
== 0) { /* NOT */
11968 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_not
, 0);
11974 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_neg
, size
);
11981 /* All 64-bit element operations can be shared with scalar 2misc */
11984 /* Coverity claims (size == 3 && !is_q) has been eliminated
11985 * from all paths leading to here.
11987 tcg_debug_assert(is_q
);
11988 for (pass
= 0; pass
< 2; pass
++) {
11989 TCGv_i64 tcg_op
= tcg_temp_new_i64();
11990 TCGv_i64 tcg_res
= tcg_temp_new_i64();
11992 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
11994 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
11995 tcg_rmode
, tcg_fpstatus
);
11997 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
11999 tcg_temp_free_i64(tcg_res
);
12000 tcg_temp_free_i64(tcg_op
);
12005 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
12006 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12007 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12010 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
12013 /* Special cases for 32 bit elements */
12015 case 0xa: /* CMLT */
12016 /* 32 bit integer comparison against zero, result is
12017 * test ? (2^32 - 1) : 0. We implement via setcond(test)
12020 cond
= TCG_COND_LT
;
12022 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
12023 tcg_gen_neg_i32(tcg_res
, tcg_res
);
12025 case 0x8: /* CMGT, CMGE */
12026 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
12028 case 0x9: /* CMEQ, CMLE */
12029 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
12031 case 0x4: /* CLS */
12033 tcg_gen_clzi_i32(tcg_res
, tcg_op
, 32);
12035 tcg_gen_clrsb_i32(tcg_res
, tcg_op
);
12038 case 0x7: /* SQABS, SQNEG */
12040 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
12042 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
12045 case 0xb: /* ABS, NEG */
12047 tcg_gen_neg_i32(tcg_res
, tcg_op
);
12049 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12050 tcg_gen_neg_i32(tcg_res
, tcg_op
);
12051 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
12052 tcg_zero
, tcg_op
, tcg_res
);
12053 tcg_temp_free_i32(tcg_zero
);
12056 case 0x2f: /* FABS */
12057 gen_helper_vfp_abss(tcg_res
, tcg_op
);
12059 case 0x6f: /* FNEG */
12060 gen_helper_vfp_negs(tcg_res
, tcg_op
);
12062 case 0x7f: /* FSQRT */
12063 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
12065 case 0x1a: /* FCVTNS */
12066 case 0x1b: /* FCVTMS */
12067 case 0x1c: /* FCVTAS */
12068 case 0x3a: /* FCVTPS */
12069 case 0x3b: /* FCVTZS */
12071 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12072 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
12073 tcg_shift
, tcg_fpstatus
);
12074 tcg_temp_free_i32(tcg_shift
);
12077 case 0x5a: /* FCVTNU */
12078 case 0x5b: /* FCVTMU */
12079 case 0x5c: /* FCVTAU */
12080 case 0x7a: /* FCVTPU */
12081 case 0x7b: /* FCVTZU */
12083 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12084 gen_helper_vfp_touls(tcg_res
, tcg_op
,
12085 tcg_shift
, tcg_fpstatus
);
12086 tcg_temp_free_i32(tcg_shift
);
12089 case 0x18: /* FRINTN */
12090 case 0x19: /* FRINTM */
12091 case 0x38: /* FRINTP */
12092 case 0x39: /* FRINTZ */
12093 case 0x58: /* FRINTA */
12094 case 0x79: /* FRINTI */
12095 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
12097 case 0x59: /* FRINTX */
12098 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12100 case 0x7c: /* URSQRTE */
12101 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
12104 g_assert_not_reached();
12107 /* Use helpers for 8 and 16 bit elements */
12109 case 0x5: /* CNT, RBIT */
12110 /* For these two insns size is part of the opcode specifier
12111 * (handled earlier); they always operate on byte elements.
12114 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
12116 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
12119 case 0x7: /* SQABS, SQNEG */
12121 NeonGenOneOpEnvFn
*genfn
;
12122 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
12123 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
12124 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
12126 genfn
= fns
[size
][u
];
12127 genfn(tcg_res
, cpu_env
, tcg_op
);
12130 case 0x8: /* CMGT, CMGE */
12131 case 0x9: /* CMEQ, CMLE */
12132 case 0xa: /* CMLT */
12134 static NeonGenTwoOpFn
* const fns
[3][2] = {
12135 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
12136 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
12137 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
12139 NeonGenTwoOpFn
*genfn
;
12142 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12144 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
12145 comp
= (opcode
- 0x8) * 2 + u
;
12146 /* ...but LE, LT are implemented as reverse GE, GT */
12147 reverse
= (comp
> 2);
12151 genfn
= fns
[comp
][size
];
12153 genfn(tcg_res
, tcg_zero
, tcg_op
);
12155 genfn(tcg_res
, tcg_op
, tcg_zero
);
12157 tcg_temp_free_i32(tcg_zero
);
12160 case 0xb: /* ABS, NEG */
12162 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12164 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
12166 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
12168 tcg_temp_free_i32(tcg_zero
);
12171 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
12173 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
12177 case 0x4: /* CLS, CLZ */
12180 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
12182 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
12186 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
12188 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
12193 g_assert_not_reached();
12197 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
12199 tcg_temp_free_i32(tcg_res
);
12200 tcg_temp_free_i32(tcg_op
);
12203 clear_vec_high(s
, is_q
, rd
);
12206 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12207 tcg_temp_free_i32(tcg_rmode
);
12209 if (need_fpstatus
) {
12210 tcg_temp_free_ptr(tcg_fpstatus
);
12214 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12216 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12217 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12218 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12219 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12220 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12221 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12223 * This actually covers two groups where scalar access is governed by
12224 * bit 28. A bunch of the instructions (float to integral) only exist
12225 * in the vector form and are un-allocated for the scalar decode. Also
12226 * in the scalar decode Q is always 1.
12228 static void disas_simd_two_reg_misc_fp16(DisasContext
*s
, uint32_t insn
)
12230 int fpop
, opcode
, a
, u
;
12234 bool only_in_vector
= false;
12237 TCGv_i32 tcg_rmode
= NULL
;
12238 TCGv_ptr tcg_fpstatus
= NULL
;
12239 bool need_rmode
= false;
12240 bool need_fpst
= true;
12243 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
12244 unallocated_encoding(s
);
12248 rd
= extract32(insn
, 0, 5);
12249 rn
= extract32(insn
, 5, 5);
12251 a
= extract32(insn
, 23, 1);
12252 u
= extract32(insn
, 29, 1);
12253 is_scalar
= extract32(insn
, 28, 1);
12254 is_q
= extract32(insn
, 30, 1);
12256 opcode
= extract32(insn
, 12, 5);
12257 fpop
= deposit32(opcode
, 5, 1, a
);
12258 fpop
= deposit32(fpop
, 6, 1, u
);
12260 rd
= extract32(insn
, 0, 5);
12261 rn
= extract32(insn
, 5, 5);
12264 case 0x1d: /* SCVTF */
12265 case 0x5d: /* UCVTF */
12272 elements
= (is_q
? 8 : 4);
12275 if (!fp_access_check(s
)) {
12278 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !u
, 0, MO_16
);
12282 case 0x2c: /* FCMGT (zero) */
12283 case 0x2d: /* FCMEQ (zero) */
12284 case 0x2e: /* FCMLT (zero) */
12285 case 0x6c: /* FCMGE (zero) */
12286 case 0x6d: /* FCMLE (zero) */
12287 handle_2misc_fcmp_zero(s
, fpop
, is_scalar
, 0, is_q
, MO_16
, rn
, rd
);
12289 case 0x3d: /* FRECPE */
12290 case 0x3f: /* FRECPX */
12292 case 0x18: /* FRINTN */
12294 only_in_vector
= true;
12295 rmode
= FPROUNDING_TIEEVEN
;
12297 case 0x19: /* FRINTM */
12299 only_in_vector
= true;
12300 rmode
= FPROUNDING_NEGINF
;
12302 case 0x38: /* FRINTP */
12304 only_in_vector
= true;
12305 rmode
= FPROUNDING_POSINF
;
12307 case 0x39: /* FRINTZ */
12309 only_in_vector
= true;
12310 rmode
= FPROUNDING_ZERO
;
12312 case 0x58: /* FRINTA */
12314 only_in_vector
= true;
12315 rmode
= FPROUNDING_TIEAWAY
;
12317 case 0x59: /* FRINTX */
12318 case 0x79: /* FRINTI */
12319 only_in_vector
= true;
12320 /* current rounding mode */
12322 case 0x1a: /* FCVTNS */
12324 rmode
= FPROUNDING_TIEEVEN
;
12326 case 0x1b: /* FCVTMS */
12328 rmode
= FPROUNDING_NEGINF
;
12330 case 0x1c: /* FCVTAS */
12332 rmode
= FPROUNDING_TIEAWAY
;
12334 case 0x3a: /* FCVTPS */
12336 rmode
= FPROUNDING_POSINF
;
12338 case 0x3b: /* FCVTZS */
12340 rmode
= FPROUNDING_ZERO
;
12342 case 0x5a: /* FCVTNU */
12344 rmode
= FPROUNDING_TIEEVEN
;
12346 case 0x5b: /* FCVTMU */
12348 rmode
= FPROUNDING_NEGINF
;
12350 case 0x5c: /* FCVTAU */
12352 rmode
= FPROUNDING_TIEAWAY
;
12354 case 0x7a: /* FCVTPU */
12356 rmode
= FPROUNDING_POSINF
;
12358 case 0x7b: /* FCVTZU */
12360 rmode
= FPROUNDING_ZERO
;
12362 case 0x2f: /* FABS */
12363 case 0x6f: /* FNEG */
12366 case 0x7d: /* FRSQRTE */
12367 case 0x7f: /* FSQRT (vector) */
12370 fprintf(stderr
, "%s: insn %#04x fpop %#2x\n", __func__
, insn
, fpop
);
12371 g_assert_not_reached();
12375 /* Check additional constraints for the scalar encoding */
12378 unallocated_encoding(s
);
12381 /* FRINTxx is only in the vector form */
12382 if (only_in_vector
) {
12383 unallocated_encoding(s
);
12388 if (!fp_access_check(s
)) {
12392 if (need_rmode
|| need_fpst
) {
12393 tcg_fpstatus
= get_fpstatus_ptr(true);
12397 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12398 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12402 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
12403 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12406 case 0x1a: /* FCVTNS */
12407 case 0x1b: /* FCVTMS */
12408 case 0x1c: /* FCVTAS */
12409 case 0x3a: /* FCVTPS */
12410 case 0x3b: /* FCVTZS */
12411 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12413 case 0x3d: /* FRECPE */
12414 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12416 case 0x3f: /* FRECPX */
12417 gen_helper_frecpx_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12419 case 0x5a: /* FCVTNU */
12420 case 0x5b: /* FCVTMU */
12421 case 0x5c: /* FCVTAU */
12422 case 0x7a: /* FCVTPU */
12423 case 0x7b: /* FCVTZU */
12424 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12426 case 0x6f: /* FNEG */
12427 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12429 case 0x7d: /* FRSQRTE */
12430 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12433 g_assert_not_reached();
12436 /* limit any sign extension going on */
12437 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0xffff);
12438 write_fp_sreg(s
, rd
, tcg_res
);
12440 tcg_temp_free_i32(tcg_res
);
12441 tcg_temp_free_i32(tcg_op
);
12443 for (pass
= 0; pass
< (is_q
? 8 : 4); pass
++) {
12444 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12445 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12447 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_16
);
12450 case 0x1a: /* FCVTNS */
12451 case 0x1b: /* FCVTMS */
12452 case 0x1c: /* FCVTAS */
12453 case 0x3a: /* FCVTPS */
12454 case 0x3b: /* FCVTZS */
12455 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12457 case 0x3d: /* FRECPE */
12458 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12460 case 0x5a: /* FCVTNU */
12461 case 0x5b: /* FCVTMU */
12462 case 0x5c: /* FCVTAU */
12463 case 0x7a: /* FCVTPU */
12464 case 0x7b: /* FCVTZU */
12465 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12467 case 0x18: /* FRINTN */
12468 case 0x19: /* FRINTM */
12469 case 0x38: /* FRINTP */
12470 case 0x39: /* FRINTZ */
12471 case 0x58: /* FRINTA */
12472 case 0x79: /* FRINTI */
12473 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12475 case 0x59: /* FRINTX */
12476 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12478 case 0x2f: /* FABS */
12479 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
12481 case 0x6f: /* FNEG */
12482 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12484 case 0x7d: /* FRSQRTE */
12485 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12487 case 0x7f: /* FSQRT */
12488 gen_helper_sqrt_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12491 g_assert_not_reached();
12494 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12496 tcg_temp_free_i32(tcg_res
);
12497 tcg_temp_free_i32(tcg_op
);
12500 clear_vec_high(s
, is_q
, rd
);
12504 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12505 tcg_temp_free_i32(tcg_rmode
);
12508 if (tcg_fpstatus
) {
12509 tcg_temp_free_ptr(tcg_fpstatus
);
12513 /* AdvSIMD scalar x indexed element
12514 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12515 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12516 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12517 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12518 * AdvSIMD vector x indexed element
12519 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12520 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12521 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12522 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12524 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
12526 /* This encoding has two kinds of instruction:
12527 * normal, where we perform elt x idxelt => elt for each
12528 * element in the vector
12529 * long, where we perform elt x idxelt and generate a result of
12530 * double the width of the input element
12531 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
12533 bool is_scalar
= extract32(insn
, 28, 1);
12534 bool is_q
= extract32(insn
, 30, 1);
12535 bool u
= extract32(insn
, 29, 1);
12536 int size
= extract32(insn
, 22, 2);
12537 int l
= extract32(insn
, 21, 1);
12538 int m
= extract32(insn
, 20, 1);
12539 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
12540 int rm
= extract32(insn
, 16, 4);
12541 int opcode
= extract32(insn
, 12, 4);
12542 int h
= extract32(insn
, 11, 1);
12543 int rn
= extract32(insn
, 5, 5);
12544 int rd
= extract32(insn
, 0, 5);
12545 bool is_long
= false;
12547 bool is_fp16
= false;
12551 switch (16 * u
+ opcode
) {
12552 case 0x08: /* MUL */
12553 case 0x10: /* MLA */
12554 case 0x14: /* MLS */
12556 unallocated_encoding(s
);
12560 case 0x02: /* SMLAL, SMLAL2 */
12561 case 0x12: /* UMLAL, UMLAL2 */
12562 case 0x06: /* SMLSL, SMLSL2 */
12563 case 0x16: /* UMLSL, UMLSL2 */
12564 case 0x0a: /* SMULL, SMULL2 */
12565 case 0x1a: /* UMULL, UMULL2 */
12567 unallocated_encoding(s
);
12572 case 0x03: /* SQDMLAL, SQDMLAL2 */
12573 case 0x07: /* SQDMLSL, SQDMLSL2 */
12574 case 0x0b: /* SQDMULL, SQDMULL2 */
12577 case 0x0c: /* SQDMULH */
12578 case 0x0d: /* SQRDMULH */
12580 case 0x01: /* FMLA */
12581 case 0x05: /* FMLS */
12582 case 0x09: /* FMUL */
12583 case 0x19: /* FMULX */
12586 case 0x1d: /* SQRDMLAH */
12587 case 0x1f: /* SQRDMLSH */
12588 if (!arm_dc_feature(s
, ARM_FEATURE_V8_RDM
)) {
12589 unallocated_encoding(s
);
12593 case 0x0e: /* SDOT */
12594 case 0x1e: /* UDOT */
12595 if (size
!= MO_32
|| !arm_dc_feature(s
, ARM_FEATURE_V8_DOTPROD
)) {
12596 unallocated_encoding(s
);
12600 case 0x11: /* FCMLA #0 */
12601 case 0x13: /* FCMLA #90 */
12602 case 0x15: /* FCMLA #180 */
12603 case 0x17: /* FCMLA #270 */
12604 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FCMA
)) {
12605 unallocated_encoding(s
);
12611 unallocated_encoding(s
);
12616 case 1: /* normal fp */
12617 /* convert insn encoded size to TCGMemOp size */
12619 case 0: /* half-precision */
12623 case MO_32
: /* single precision */
12624 case MO_64
: /* double precision */
12627 unallocated_encoding(s
);
12632 case 2: /* complex fp */
12633 /* Each indexable element is a complex pair. */
12638 unallocated_encoding(s
);
12646 unallocated_encoding(s
);
12651 default: /* integer */
12655 unallocated_encoding(s
);
12660 if (is_fp16
&& !arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
12661 unallocated_encoding(s
);
12665 /* Given TCGMemOp size, adjust register and indexing. */
12668 index
= h
<< 2 | l
<< 1 | m
;
12671 index
= h
<< 1 | l
;
12676 unallocated_encoding(s
);
12683 g_assert_not_reached();
12686 if (!fp_access_check(s
)) {
12691 fpst
= get_fpstatus_ptr(is_fp16
);
12696 switch (16 * u
+ opcode
) {
12697 case 0x0e: /* SDOT */
12698 case 0x1e: /* UDOT */
12699 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, index
,
12700 u
? gen_helper_gvec_udot_idx_b
12701 : gen_helper_gvec_sdot_idx_b
);
12703 case 0x11: /* FCMLA #0 */
12704 case 0x13: /* FCMLA #90 */
12705 case 0x15: /* FCMLA #180 */
12706 case 0x17: /* FCMLA #270 */
12708 int rot
= extract32(insn
, 13, 2);
12709 int data
= (index
<< 2) | rot
;
12710 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
12711 vec_full_reg_offset(s
, rn
),
12712 vec_full_reg_offset(s
, rm
), fpst
,
12713 is_q
? 16 : 8, vec_full_reg_size(s
), data
,
12715 ? gen_helper_gvec_fcmlas_idx
12716 : gen_helper_gvec_fcmlah_idx
);
12717 tcg_temp_free_ptr(fpst
);
12723 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
12726 assert(is_fp
&& is_q
&& !is_long
);
12728 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
12730 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
12731 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12732 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12734 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12736 switch (16 * u
+ opcode
) {
12737 case 0x05: /* FMLS */
12738 /* As usual for ARM, separate negation for fused multiply-add */
12739 gen_helper_vfp_negd(tcg_op
, tcg_op
);
12741 case 0x01: /* FMLA */
12742 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12743 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
12745 case 0x09: /* FMUL */
12746 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12748 case 0x19: /* FMULX */
12749 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12752 g_assert_not_reached();
12755 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12756 tcg_temp_free_i64(tcg_op
);
12757 tcg_temp_free_i64(tcg_res
);
12760 tcg_temp_free_i64(tcg_idx
);
12761 clear_vec_high(s
, !is_scalar
, rd
);
12762 } else if (!is_long
) {
12763 /* 32 bit floating point, or 16 or 32 bit integer.
12764 * For the 16 bit scalar case we use the usual Neon helpers and
12765 * rely on the fact that 0 op 0 == 0 with no side effects.
12767 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
12768 int pass
, maxpasses
;
12773 maxpasses
= is_q
? 4 : 2;
12776 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
12778 if (size
== 1 && !is_scalar
) {
12779 /* The simplest way to handle the 16x16 indexed ops is to duplicate
12780 * the index into both halves of the 32 bit tcg_idx and then use
12781 * the usual Neon helpers.
12783 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
12786 for (pass
= 0; pass
< maxpasses
; pass
++) {
12787 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12788 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12790 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
12792 switch (16 * u
+ opcode
) {
12793 case 0x08: /* MUL */
12794 case 0x10: /* MLA */
12795 case 0x14: /* MLS */
12797 static NeonGenTwoOpFn
* const fns
[2][2] = {
12798 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
12799 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
12801 NeonGenTwoOpFn
*genfn
;
12802 bool is_sub
= opcode
== 0x4;
12805 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
12807 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
12809 if (opcode
== 0x8) {
12812 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
12813 genfn
= fns
[size
- 1][is_sub
];
12814 genfn(tcg_res
, tcg_op
, tcg_res
);
12817 case 0x05: /* FMLS */
12818 case 0x01: /* FMLA */
12819 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
12820 is_scalar
? size
: MO_32
);
12823 if (opcode
== 0x5) {
12824 /* As usual for ARM, separate negation for fused
12826 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80008000);
12829 gen_helper_advsimd_muladdh(tcg_res
, tcg_op
, tcg_idx
,
12832 gen_helper_advsimd_muladd2h(tcg_res
, tcg_op
, tcg_idx
,
12837 if (opcode
== 0x5) {
12838 /* As usual for ARM, separate negation for
12839 * fused multiply-add */
12840 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80000000);
12842 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
,
12846 g_assert_not_reached();
12849 case 0x09: /* FMUL */
12853 gen_helper_advsimd_mulh(tcg_res
, tcg_op
,
12856 gen_helper_advsimd_mul2h(tcg_res
, tcg_op
,
12861 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12864 g_assert_not_reached();
12867 case 0x19: /* FMULX */
12871 gen_helper_advsimd_mulxh(tcg_res
, tcg_op
,
12874 gen_helper_advsimd_mulx2h(tcg_res
, tcg_op
,
12879 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12882 g_assert_not_reached();
12885 case 0x0c: /* SQDMULH */
12887 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
12890 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
12894 case 0x0d: /* SQRDMULH */
12896 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
12899 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
12903 case 0x1d: /* SQRDMLAH */
12904 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
12905 is_scalar
? size
: MO_32
);
12907 gen_helper_neon_qrdmlah_s16(tcg_res
, cpu_env
,
12908 tcg_op
, tcg_idx
, tcg_res
);
12910 gen_helper_neon_qrdmlah_s32(tcg_res
, cpu_env
,
12911 tcg_op
, tcg_idx
, tcg_res
);
12914 case 0x1f: /* SQRDMLSH */
12915 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
12916 is_scalar
? size
: MO_32
);
12918 gen_helper_neon_qrdmlsh_s16(tcg_res
, cpu_env
,
12919 tcg_op
, tcg_idx
, tcg_res
);
12921 gen_helper_neon_qrdmlsh_s32(tcg_res
, cpu_env
,
12922 tcg_op
, tcg_idx
, tcg_res
);
12926 g_assert_not_reached();
12930 write_fp_sreg(s
, rd
, tcg_res
);
12932 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
12935 tcg_temp_free_i32(tcg_op
);
12936 tcg_temp_free_i32(tcg_res
);
12939 tcg_temp_free_i32(tcg_idx
);
12940 clear_vec_high(s
, is_q
, rd
);
12942 /* long ops: 16x16->32 or 32x32->64 */
12943 TCGv_i64 tcg_res
[2];
12945 bool satop
= extract32(opcode
, 0, 1);
12946 TCGMemOp memop
= MO_32
;
12953 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
12955 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
12957 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
12958 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12959 TCGv_i64 tcg_passres
;
12965 passelt
= pass
+ (is_q
* 2);
12968 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
12970 tcg_res
[pass
] = tcg_temp_new_i64();
12972 if (opcode
== 0xa || opcode
== 0xb) {
12973 /* Non-accumulating ops */
12974 tcg_passres
= tcg_res
[pass
];
12976 tcg_passres
= tcg_temp_new_i64();
12979 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
12980 tcg_temp_free_i64(tcg_op
);
12983 /* saturating, doubling */
12984 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
12985 tcg_passres
, tcg_passres
);
12988 if (opcode
== 0xa || opcode
== 0xb) {
12992 /* Accumulating op: handle accumulate step */
12993 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
12996 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
12997 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
12999 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13000 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13002 case 0x7: /* SQDMLSL, SQDMLSL2 */
13003 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
13005 case 0x3: /* SQDMLAL, SQDMLAL2 */
13006 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
13011 g_assert_not_reached();
13013 tcg_temp_free_i64(tcg_passres
);
13015 tcg_temp_free_i64(tcg_idx
);
13017 clear_vec_high(s
, !is_scalar
, rd
);
13019 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13022 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13025 /* The simplest way to handle the 16x16 indexed ops is to
13026 * duplicate the index into both halves of the 32 bit tcg_idx
13027 * and then use the usual Neon helpers.
13029 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13032 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13033 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13034 TCGv_i64 tcg_passres
;
13037 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
13039 read_vec_element_i32(s
, tcg_op
, rn
,
13040 pass
+ (is_q
* 2), MO_32
);
13043 tcg_res
[pass
] = tcg_temp_new_i64();
13045 if (opcode
== 0xa || opcode
== 0xb) {
13046 /* Non-accumulating ops */
13047 tcg_passres
= tcg_res
[pass
];
13049 tcg_passres
= tcg_temp_new_i64();
13052 if (memop
& MO_SIGN
) {
13053 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
13055 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
13058 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
13059 tcg_passres
, tcg_passres
);
13061 tcg_temp_free_i32(tcg_op
);
13063 if (opcode
== 0xa || opcode
== 0xb) {
13067 /* Accumulating op: handle accumulate step */
13068 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13071 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13072 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
13075 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13076 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
13079 case 0x7: /* SQDMLSL, SQDMLSL2 */
13080 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
13082 case 0x3: /* SQDMLAL, SQDMLAL2 */
13083 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
13088 g_assert_not_reached();
13090 tcg_temp_free_i64(tcg_passres
);
13092 tcg_temp_free_i32(tcg_idx
);
13095 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
13100 tcg_res
[1] = tcg_const_i64(0);
13103 for (pass
= 0; pass
< 2; pass
++) {
13104 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13105 tcg_temp_free_i64(tcg_res
[pass
]);
13110 tcg_temp_free_ptr(fpst
);
13115 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13116 * +-----------------+------+-----------+--------+-----+------+------+
13117 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13118 * +-----------------+------+-----------+--------+-----+------+------+
13120 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
13122 int size
= extract32(insn
, 22, 2);
13123 int opcode
= extract32(insn
, 12, 5);
13124 int rn
= extract32(insn
, 5, 5);
13125 int rd
= extract32(insn
, 0, 5);
13127 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13128 TCGv_i32 tcg_decrypt
;
13129 CryptoThreeOpIntFn
*genfn
;
13131 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)
13133 unallocated_encoding(s
);
13138 case 0x4: /* AESE */
13140 genfn
= gen_helper_crypto_aese
;
13142 case 0x6: /* AESMC */
13144 genfn
= gen_helper_crypto_aesmc
;
13146 case 0x5: /* AESD */
13148 genfn
= gen_helper_crypto_aese
;
13150 case 0x7: /* AESIMC */
13152 genfn
= gen_helper_crypto_aesmc
;
13155 unallocated_encoding(s
);
13159 if (!fp_access_check(s
)) {
13163 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13164 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13165 tcg_decrypt
= tcg_const_i32(decrypt
);
13167 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_decrypt
);
13169 tcg_temp_free_ptr(tcg_rd_ptr
);
13170 tcg_temp_free_ptr(tcg_rn_ptr
);
13171 tcg_temp_free_i32(tcg_decrypt
);
13174 /* Crypto three-reg SHA
13175 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
13176 * +-----------------+------+---+------+---+--------+-----+------+------+
13177 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
13178 * +-----------------+------+---+------+---+--------+-----+------+------+
13180 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
13182 int size
= extract32(insn
, 22, 2);
13183 int opcode
= extract32(insn
, 12, 3);
13184 int rm
= extract32(insn
, 16, 5);
13185 int rn
= extract32(insn
, 5, 5);
13186 int rd
= extract32(insn
, 0, 5);
13187 CryptoThreeOpFn
*genfn
;
13188 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13189 int feature
= ARM_FEATURE_V8_SHA256
;
13192 unallocated_encoding(s
);
13197 case 0: /* SHA1C */
13198 case 1: /* SHA1P */
13199 case 2: /* SHA1M */
13200 case 3: /* SHA1SU0 */
13202 feature
= ARM_FEATURE_V8_SHA1
;
13204 case 4: /* SHA256H */
13205 genfn
= gen_helper_crypto_sha256h
;
13207 case 5: /* SHA256H2 */
13208 genfn
= gen_helper_crypto_sha256h2
;
13210 case 6: /* SHA256SU1 */
13211 genfn
= gen_helper_crypto_sha256su1
;
13214 unallocated_encoding(s
);
13218 if (!arm_dc_feature(s
, feature
)) {
13219 unallocated_encoding(s
);
13223 if (!fp_access_check(s
)) {
13227 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13228 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13229 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13232 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13234 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
13236 gen_helper_crypto_sha1_3reg(tcg_rd_ptr
, tcg_rn_ptr
,
13237 tcg_rm_ptr
, tcg_opcode
);
13238 tcg_temp_free_i32(tcg_opcode
);
13241 tcg_temp_free_ptr(tcg_rd_ptr
);
13242 tcg_temp_free_ptr(tcg_rn_ptr
);
13243 tcg_temp_free_ptr(tcg_rm_ptr
);
13246 /* Crypto two-reg SHA
13247 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13248 * +-----------------+------+-----------+--------+-----+------+------+
13249 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13250 * +-----------------+------+-----------+--------+-----+------+------+
13252 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
13254 int size
= extract32(insn
, 22, 2);
13255 int opcode
= extract32(insn
, 12, 5);
13256 int rn
= extract32(insn
, 5, 5);
13257 int rd
= extract32(insn
, 0, 5);
13258 CryptoTwoOpFn
*genfn
;
13260 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13263 unallocated_encoding(s
);
13268 case 0: /* SHA1H */
13269 feature
= ARM_FEATURE_V8_SHA1
;
13270 genfn
= gen_helper_crypto_sha1h
;
13272 case 1: /* SHA1SU1 */
13273 feature
= ARM_FEATURE_V8_SHA1
;
13274 genfn
= gen_helper_crypto_sha1su1
;
13276 case 2: /* SHA256SU0 */
13277 feature
= ARM_FEATURE_V8_SHA256
;
13278 genfn
= gen_helper_crypto_sha256su0
;
13281 unallocated_encoding(s
);
13285 if (!arm_dc_feature(s
, feature
)) {
13286 unallocated_encoding(s
);
13290 if (!fp_access_check(s
)) {
13294 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13295 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13297 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13299 tcg_temp_free_ptr(tcg_rd_ptr
);
13300 tcg_temp_free_ptr(tcg_rn_ptr
);
13303 /* Crypto three-reg SHA512
13304 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13305 * +-----------------------+------+---+---+-----+--------+------+------+
13306 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
13307 * +-----------------------+------+---+---+-----+--------+------+------+
13309 static void disas_crypto_three_reg_sha512(DisasContext
*s
, uint32_t insn
)
13311 int opcode
= extract32(insn
, 10, 2);
13312 int o
= extract32(insn
, 14, 1);
13313 int rm
= extract32(insn
, 16, 5);
13314 int rn
= extract32(insn
, 5, 5);
13315 int rd
= extract32(insn
, 0, 5);
13317 CryptoThreeOpFn
*genfn
;
13321 case 0: /* SHA512H */
13322 feature
= ARM_FEATURE_V8_SHA512
;
13323 genfn
= gen_helper_crypto_sha512h
;
13325 case 1: /* SHA512H2 */
13326 feature
= ARM_FEATURE_V8_SHA512
;
13327 genfn
= gen_helper_crypto_sha512h2
;
13329 case 2: /* SHA512SU1 */
13330 feature
= ARM_FEATURE_V8_SHA512
;
13331 genfn
= gen_helper_crypto_sha512su1
;
13334 feature
= ARM_FEATURE_V8_SHA3
;
13340 case 0: /* SM3PARTW1 */
13341 feature
= ARM_FEATURE_V8_SM3
;
13342 genfn
= gen_helper_crypto_sm3partw1
;
13344 case 1: /* SM3PARTW2 */
13345 feature
= ARM_FEATURE_V8_SM3
;
13346 genfn
= gen_helper_crypto_sm3partw2
;
13348 case 2: /* SM4EKEY */
13349 feature
= ARM_FEATURE_V8_SM4
;
13350 genfn
= gen_helper_crypto_sm4ekey
;
13353 unallocated_encoding(s
);
13358 if (!arm_dc_feature(s
, feature
)) {
13359 unallocated_encoding(s
);
13363 if (!fp_access_check(s
)) {
13368 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13370 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13371 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13372 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13374 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13376 tcg_temp_free_ptr(tcg_rd_ptr
);
13377 tcg_temp_free_ptr(tcg_rn_ptr
);
13378 tcg_temp_free_ptr(tcg_rm_ptr
);
13380 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13383 tcg_op1
= tcg_temp_new_i64();
13384 tcg_op2
= tcg_temp_new_i64();
13385 tcg_res
[0] = tcg_temp_new_i64();
13386 tcg_res
[1] = tcg_temp_new_i64();
13388 for (pass
= 0; pass
< 2; pass
++) {
13389 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13390 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13392 tcg_gen_rotli_i64(tcg_res
[pass
], tcg_op2
, 1);
13393 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13395 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13396 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13398 tcg_temp_free_i64(tcg_op1
);
13399 tcg_temp_free_i64(tcg_op2
);
13400 tcg_temp_free_i64(tcg_res
[0]);
13401 tcg_temp_free_i64(tcg_res
[1]);
13405 /* Crypto two-reg SHA512
13406 * 31 12 11 10 9 5 4 0
13407 * +-----------------------------------------+--------+------+------+
13408 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
13409 * +-----------------------------------------+--------+------+------+
13411 static void disas_crypto_two_reg_sha512(DisasContext
*s
, uint32_t insn
)
13413 int opcode
= extract32(insn
, 10, 2);
13414 int rn
= extract32(insn
, 5, 5);
13415 int rd
= extract32(insn
, 0, 5);
13416 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13418 CryptoTwoOpFn
*genfn
;
13421 case 0: /* SHA512SU0 */
13422 feature
= ARM_FEATURE_V8_SHA512
;
13423 genfn
= gen_helper_crypto_sha512su0
;
13426 feature
= ARM_FEATURE_V8_SM4
;
13427 genfn
= gen_helper_crypto_sm4e
;
13430 unallocated_encoding(s
);
13434 if (!arm_dc_feature(s
, feature
)) {
13435 unallocated_encoding(s
);
13439 if (!fp_access_check(s
)) {
13443 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13444 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13446 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13448 tcg_temp_free_ptr(tcg_rd_ptr
);
13449 tcg_temp_free_ptr(tcg_rn_ptr
);
13452 /* Crypto four-register
13453 * 31 23 22 21 20 16 15 14 10 9 5 4 0
13454 * +-------------------+-----+------+---+------+------+------+
13455 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
13456 * +-------------------+-----+------+---+------+------+------+
13458 static void disas_crypto_four_reg(DisasContext
*s
, uint32_t insn
)
13460 int op0
= extract32(insn
, 21, 2);
13461 int rm
= extract32(insn
, 16, 5);
13462 int ra
= extract32(insn
, 10, 5);
13463 int rn
= extract32(insn
, 5, 5);
13464 int rd
= extract32(insn
, 0, 5);
13470 feature
= ARM_FEATURE_V8_SHA3
;
13472 case 2: /* SM3SS1 */
13473 feature
= ARM_FEATURE_V8_SM3
;
13476 unallocated_encoding(s
);
13480 if (!arm_dc_feature(s
, feature
)) {
13481 unallocated_encoding(s
);
13485 if (!fp_access_check(s
)) {
13490 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
[2];
13493 tcg_op1
= tcg_temp_new_i64();
13494 tcg_op2
= tcg_temp_new_i64();
13495 tcg_op3
= tcg_temp_new_i64();
13496 tcg_res
[0] = tcg_temp_new_i64();
13497 tcg_res
[1] = tcg_temp_new_i64();
13499 for (pass
= 0; pass
< 2; pass
++) {
13500 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13501 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13502 read_vec_element(s
, tcg_op3
, ra
, pass
, MO_64
);
13506 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13509 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13511 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13513 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13514 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13516 tcg_temp_free_i64(tcg_op1
);
13517 tcg_temp_free_i64(tcg_op2
);
13518 tcg_temp_free_i64(tcg_op3
);
13519 tcg_temp_free_i64(tcg_res
[0]);
13520 tcg_temp_free_i64(tcg_res
[1]);
13522 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
, tcg_zero
;
13524 tcg_op1
= tcg_temp_new_i32();
13525 tcg_op2
= tcg_temp_new_i32();
13526 tcg_op3
= tcg_temp_new_i32();
13527 tcg_res
= tcg_temp_new_i32();
13528 tcg_zero
= tcg_const_i32(0);
13530 read_vec_element_i32(s
, tcg_op1
, rn
, 3, MO_32
);
13531 read_vec_element_i32(s
, tcg_op2
, rm
, 3, MO_32
);
13532 read_vec_element_i32(s
, tcg_op3
, ra
, 3, MO_32
);
13534 tcg_gen_rotri_i32(tcg_res
, tcg_op1
, 20);
13535 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op2
);
13536 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op3
);
13537 tcg_gen_rotri_i32(tcg_res
, tcg_res
, 25);
13539 write_vec_element_i32(s
, tcg_zero
, rd
, 0, MO_32
);
13540 write_vec_element_i32(s
, tcg_zero
, rd
, 1, MO_32
);
13541 write_vec_element_i32(s
, tcg_zero
, rd
, 2, MO_32
);
13542 write_vec_element_i32(s
, tcg_res
, rd
, 3, MO_32
);
13544 tcg_temp_free_i32(tcg_op1
);
13545 tcg_temp_free_i32(tcg_op2
);
13546 tcg_temp_free_i32(tcg_op3
);
13547 tcg_temp_free_i32(tcg_res
);
13548 tcg_temp_free_i32(tcg_zero
);
13553 * 31 21 20 16 15 10 9 5 4 0
13554 * +-----------------------+------+--------+------+------+
13555 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
13556 * +-----------------------+------+--------+------+------+
13558 static void disas_crypto_xar(DisasContext
*s
, uint32_t insn
)
13560 int rm
= extract32(insn
, 16, 5);
13561 int imm6
= extract32(insn
, 10, 6);
13562 int rn
= extract32(insn
, 5, 5);
13563 int rd
= extract32(insn
, 0, 5);
13564 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13567 if (!arm_dc_feature(s
, ARM_FEATURE_V8_SHA3
)) {
13568 unallocated_encoding(s
);
13572 if (!fp_access_check(s
)) {
13576 tcg_op1
= tcg_temp_new_i64();
13577 tcg_op2
= tcg_temp_new_i64();
13578 tcg_res
[0] = tcg_temp_new_i64();
13579 tcg_res
[1] = tcg_temp_new_i64();
13581 for (pass
= 0; pass
< 2; pass
++) {
13582 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13583 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13585 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
13586 tcg_gen_rotri_i64(tcg_res
[pass
], tcg_res
[pass
], imm6
);
13588 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13589 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13591 tcg_temp_free_i64(tcg_op1
);
13592 tcg_temp_free_i64(tcg_op2
);
13593 tcg_temp_free_i64(tcg_res
[0]);
13594 tcg_temp_free_i64(tcg_res
[1]);
13597 /* Crypto three-reg imm2
13598 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13599 * +-----------------------+------+-----+------+--------+------+------+
13600 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
13601 * +-----------------------+------+-----+------+--------+------+------+
13603 static void disas_crypto_three_reg_imm2(DisasContext
*s
, uint32_t insn
)
13605 int opcode
= extract32(insn
, 10, 2);
13606 int imm2
= extract32(insn
, 12, 2);
13607 int rm
= extract32(insn
, 16, 5);
13608 int rn
= extract32(insn
, 5, 5);
13609 int rd
= extract32(insn
, 0, 5);
13610 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13611 TCGv_i32 tcg_imm2
, tcg_opcode
;
13613 if (!arm_dc_feature(s
, ARM_FEATURE_V8_SM3
)) {
13614 unallocated_encoding(s
);
13618 if (!fp_access_check(s
)) {
13622 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13623 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13624 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13625 tcg_imm2
= tcg_const_i32(imm2
);
13626 tcg_opcode
= tcg_const_i32(opcode
);
13628 gen_helper_crypto_sm3tt(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
, tcg_imm2
,
13631 tcg_temp_free_ptr(tcg_rd_ptr
);
13632 tcg_temp_free_ptr(tcg_rn_ptr
);
13633 tcg_temp_free_ptr(tcg_rm_ptr
);
13634 tcg_temp_free_i32(tcg_imm2
);
13635 tcg_temp_free_i32(tcg_opcode
);
13638 /* C3.6 Data processing - SIMD, inc Crypto
13640 * As the decode gets a little complex we are using a table based
13641 * approach for this part of the decode.
13643 static const AArch64DecodeTable data_proc_simd
[] = {
13644 /* pattern , mask , fn */
13645 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
13646 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra
},
13647 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
13648 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
13649 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
13650 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
13651 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
13652 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
13653 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
13654 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
13655 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
13656 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
13657 { 0x2e000000, 0xbf208400, disas_simd_ext
},
13658 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
13659 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra
},
13660 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
13661 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
13662 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
13663 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
13664 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
13665 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
13666 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
13667 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
13668 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
13669 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512
},
13670 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512
},
13671 { 0xce000000, 0xff808000, disas_crypto_four_reg
},
13672 { 0xce800000, 0xffe00000, disas_crypto_xar
},
13673 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2
},
13674 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16
},
13675 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16
},
13676 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16
},
13677 { 0x00000000, 0x00000000, NULL
}
13680 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
13682 /* Note that this is called with all non-FP cases from
13683 * table C3-6 so it must UNDEF for entries not specifically
13684 * allocated to instructions in that table.
13686 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
13690 unallocated_encoding(s
);
13694 /* C3.6 Data processing - SIMD and floating point */
13695 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
13697 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
13698 disas_data_proc_fp(s
, insn
);
13700 /* SIMD, including crypto */
13701 disas_data_proc_simd(s
, insn
);
13705 /* C3.1 A64 instruction index by encoding */
13706 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
13710 insn
= arm_ldl_code(env
, s
->pc
, s
->sctlr_b
);
13714 s
->fp_access_checked
= false;
13716 switch (extract32(insn
, 25, 4)) {
13717 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
13718 unallocated_encoding(s
);
13721 if (!arm_dc_feature(s
, ARM_FEATURE_SVE
) || !disas_sve(s
, insn
)) {
13722 unallocated_encoding(s
);
13725 case 0x8: case 0x9: /* Data processing - immediate */
13726 disas_data_proc_imm(s
, insn
);
13728 case 0xa: case 0xb: /* Branch, exception generation and system insns */
13729 disas_b_exc_sys(s
, insn
);
13734 case 0xe: /* Loads and stores */
13735 disas_ldst(s
, insn
);
13738 case 0xd: /* Data processing - register */
13739 disas_data_proc_reg(s
, insn
);
13742 case 0xf: /* Data processing - SIMD and floating point */
13743 disas_data_proc_simd_fp(s
, insn
);
13746 assert(FALSE
); /* all 15 cases should be handled above */
13750 /* if we allocated any temporaries, free them here */
13754 static void aarch64_tr_init_disas_context(DisasContextBase
*dcbase
,
13757 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13758 CPUARMState
*env
= cpu
->env_ptr
;
13759 ARMCPU
*arm_cpu
= arm_env_get_cpu(env
);
13762 dc
->pc
= dc
->base
.pc_first
;
13766 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
13767 * there is no secure EL1, so we route exceptions to EL3.
13769 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
13770 !arm_el_is_aa64(env
, 3);
13773 dc
->be_data
= ARM_TBFLAG_BE_DATA(dc
->base
.tb
->flags
) ? MO_BE
: MO_LE
;
13774 dc
->condexec_mask
= 0;
13775 dc
->condexec_cond
= 0;
13776 dc
->mmu_idx
= core_to_arm_mmu_idx(env
, ARM_TBFLAG_MMUIDX(dc
->base
.tb
->flags
));
13777 dc
->tbi0
= ARM_TBFLAG_TBI0(dc
->base
.tb
->flags
);
13778 dc
->tbi1
= ARM_TBFLAG_TBI1(dc
->base
.tb
->flags
);
13779 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
13780 #if !defined(CONFIG_USER_ONLY)
13781 dc
->user
= (dc
->current_el
== 0);
13783 dc
->fp_excp_el
= ARM_TBFLAG_FPEXC_EL(dc
->base
.tb
->flags
);
13784 dc
->sve_excp_el
= ARM_TBFLAG_SVEEXC_EL(dc
->base
.tb
->flags
);
13785 dc
->sve_len
= (ARM_TBFLAG_ZCR_LEN(dc
->base
.tb
->flags
) + 1) * 16;
13787 dc
->vec_stride
= 0;
13788 dc
->cp_regs
= arm_cpu
->cp_regs
;
13789 dc
->features
= env
->features
;
13791 /* Single step state. The code-generation logic here is:
13793 * generate code with no special handling for single-stepping (except
13794 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
13795 * this happens anyway because those changes are all system register or
13797 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
13798 * emit code for one insn
13799 * emit code to clear PSTATE.SS
13800 * emit code to generate software step exception for completed step
13801 * end TB (as usual for having generated an exception)
13802 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
13803 * emit code to generate a software step exception
13806 dc
->ss_active
= ARM_TBFLAG_SS_ACTIVE(dc
->base
.tb
->flags
);
13807 dc
->pstate_ss
= ARM_TBFLAG_PSTATE_SS(dc
->base
.tb
->flags
);
13808 dc
->is_ldex
= false;
13809 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
13811 /* Bound the number of insns to execute to those left on the page. */
13812 bound
= -(dc
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
13814 /* If architectural single step active, limit to 1. */
13815 if (dc
->ss_active
) {
13818 dc
->base
.max_insns
= MIN(dc
->base
.max_insns
, bound
);
13820 init_tmp_a64_array(dc
);
13823 static void aarch64_tr_tb_start(DisasContextBase
*db
, CPUState
*cpu
)
13825 tcg_clear_temp_count();
13828 static void aarch64_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
13830 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13832 tcg_gen_insn_start(dc
->pc
, 0, 0);
13833 dc
->insn_start
= tcg_last_op();
13836 static bool aarch64_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cpu
,
13837 const CPUBreakpoint
*bp
)
13839 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13841 if (bp
->flags
& BP_CPU
) {
13842 gen_a64_set_pc_im(dc
->pc
);
13843 gen_helper_check_breakpoints(cpu_env
);
13844 /* End the TB early; it likely won't be executed */
13845 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
13847 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
13848 /* The address covered by the breakpoint must be
13849 included in [tb->pc, tb->pc + tb->size) in order
13850 to for it to be properly cleared -- thus we
13851 increment the PC here so that the logic setting
13852 tb->size below does the right thing. */
13854 dc
->base
.is_jmp
= DISAS_NORETURN
;
13860 static void aarch64_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
13862 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13863 CPUARMState
*env
= cpu
->env_ptr
;
13865 if (dc
->ss_active
&& !dc
->pstate_ss
) {
13866 /* Singlestep state is Active-pending.
13867 * If we're in this state at the start of a TB then either
13868 * a) we just took an exception to an EL which is being debugged
13869 * and this is the first insn in the exception handler
13870 * b) debug exceptions were masked and we just unmasked them
13871 * without changing EL (eg by clearing PSTATE.D)
13872 * In either case we're going to take a swstep exception in the
13873 * "did not step an insn" case, and so the syndrome ISV and EX
13874 * bits should be zero.
13876 assert(dc
->base
.num_insns
== 1);
13877 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0),
13878 default_exception_el(dc
));
13879 dc
->base
.is_jmp
= DISAS_NORETURN
;
13881 disas_a64_insn(env
, dc
);
13884 dc
->base
.pc_next
= dc
->pc
;
13885 translator_loop_temp_check(&dc
->base
);
13888 static void aarch64_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
13890 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13892 if (unlikely(dc
->base
.singlestep_enabled
|| dc
->ss_active
)) {
13893 /* Note that this means single stepping WFI doesn't halt the CPU.
13894 * For conditional branch insns this is harmless unreachable code as
13895 * gen_goto_tb() has already handled emitting the debug exception
13896 * (and thus a tb-jump is not possible when singlestepping).
13898 switch (dc
->base
.is_jmp
) {
13900 gen_a64_set_pc_im(dc
->pc
);
13904 if (dc
->base
.singlestep_enabled
) {
13905 gen_exception_internal(EXCP_DEBUG
);
13907 gen_step_complete_exception(dc
);
13910 case DISAS_NORETURN
:
13914 switch (dc
->base
.is_jmp
) {
13916 case DISAS_TOO_MANY
:
13917 gen_goto_tb(dc
, 1, dc
->pc
);
13921 gen_a64_set_pc_im(dc
->pc
);
13924 tcg_gen_exit_tb(NULL
, 0);
13927 tcg_gen_lookup_and_goto_ptr();
13929 case DISAS_NORETURN
:
13933 gen_a64_set_pc_im(dc
->pc
);
13934 gen_helper_wfe(cpu_env
);
13937 gen_a64_set_pc_im(dc
->pc
);
13938 gen_helper_yield(cpu_env
);
13942 /* This is a special case because we don't want to just halt the CPU
13943 * if trying to debug across a WFI.
13945 TCGv_i32 tmp
= tcg_const_i32(4);
13947 gen_a64_set_pc_im(dc
->pc
);
13948 gen_helper_wfi(cpu_env
, tmp
);
13949 tcg_temp_free_i32(tmp
);
13950 /* The helper doesn't necessarily throw an exception, but we
13951 * must go back to the main loop to check for interrupts anyway.
13953 tcg_gen_exit_tb(NULL
, 0);
13959 /* Functions above can change dc->pc, so re-align db->pc_next */
13960 dc
->base
.pc_next
= dc
->pc
;
13963 static void aarch64_tr_disas_log(const DisasContextBase
*dcbase
,
13966 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13968 qemu_log("IN: %s\n", lookup_symbol(dc
->base
.pc_first
));
13969 log_target_disas(cpu
, dc
->base
.pc_first
, dc
->base
.tb
->size
);
13972 const TranslatorOps aarch64_translator_ops
= {
13973 .init_disas_context
= aarch64_tr_init_disas_context
,
13974 .tb_start
= aarch64_tr_tb_start
,
13975 .insn_start
= aarch64_tr_insn_start
,
13976 .breakpoint_check
= aarch64_tr_breakpoint_check
,
13977 .translate_insn
= aarch64_tr_translate_insn
,
13978 .tb_stop
= aarch64_tr_tb_stop
,
13979 .disas_log
= aarch64_tr_disas_log
,