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.1 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"
23 #include "tcg/tcg-op.h"
24 #include "tcg/tcg-op-gvec.h"
27 #include "translate.h"
28 #include "internals.h"
29 #include "qemu/host-utils.h"
30 #include "semihosting/semihost.h"
31 #include "exec/gen-icount.h"
32 #include "exec/helper-proto.h"
33 #include "exec/helper-gen.h"
36 #include "translate-a64.h"
37 #include "qemu/atomic128.h"
39 static TCGv_i64 cpu_X
[32];
40 static TCGv_i64 cpu_pc
;
42 /* Load/store exclusive handling */
43 static TCGv_i64 cpu_exclusive_high
;
45 static const char *regnames
[] = {
46 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
47 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
48 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
49 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
53 A64_SHIFT_TYPE_LSL
= 0,
54 A64_SHIFT_TYPE_LSR
= 1,
55 A64_SHIFT_TYPE_ASR
= 2,
56 A64_SHIFT_TYPE_ROR
= 3
59 /* Table based decoder typedefs - used when the relevant bits for decode
60 * are too awkwardly scattered across the instruction (eg SIMD).
62 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
64 typedef struct AArch64DecodeTable
{
67 AArch64DecodeFn
*disas_fn
;
70 /* initialize TCG globals. */
71 void a64_translate_init(void)
75 cpu_pc
= tcg_global_mem_new_i64(cpu_env
,
76 offsetof(CPUARMState
, pc
),
78 for (i
= 0; i
< 32; i
++) {
79 cpu_X
[i
] = tcg_global_mem_new_i64(cpu_env
,
80 offsetof(CPUARMState
, xregs
[i
]),
84 cpu_exclusive_high
= tcg_global_mem_new_i64(cpu_env
,
85 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
89 * Return the core mmu_idx to use for A64 "unprivileged load/store" insns
91 static int get_a64_user_mem_index(DisasContext
*s
)
94 * If AccType_UNPRIV is not used, the insn uses AccType_NORMAL,
95 * which is the usual mmu_idx for this cpu state.
97 ARMMMUIdx useridx
= s
->mmu_idx
;
101 * We have pre-computed the condition for AccType_UNPRIV.
102 * Therefore we should never get here with a mmu_idx for
103 * which we do not know the corresponding user mmu_idx.
106 case ARMMMUIdx_E10_1
:
107 case ARMMMUIdx_E10_1_PAN
:
108 useridx
= ARMMMUIdx_E10_0
;
110 case ARMMMUIdx_E20_2
:
111 case ARMMMUIdx_E20_2_PAN
:
112 useridx
= ARMMMUIdx_E20_0
;
114 case ARMMMUIdx_SE10_1
:
115 case ARMMMUIdx_SE10_1_PAN
:
116 useridx
= ARMMMUIdx_SE10_0
;
118 case ARMMMUIdx_SE20_2
:
119 case ARMMMUIdx_SE20_2_PAN
:
120 useridx
= ARMMMUIdx_SE20_0
;
123 g_assert_not_reached();
126 return arm_to_core_mmu_idx(useridx
);
129 static void set_btype_raw(int val
)
131 tcg_gen_st_i32(tcg_constant_i32(val
), cpu_env
,
132 offsetof(CPUARMState
, btype
));
135 static void set_btype(DisasContext
*s
, int val
)
137 /* BTYPE is a 2-bit field, and 0 should be done with reset_btype. */
138 tcg_debug_assert(val
>= 1 && val
<= 3);
143 static void reset_btype(DisasContext
*s
)
151 void gen_a64_set_pc_im(uint64_t val
)
153 tcg_gen_movi_i64(cpu_pc
, val
);
157 * Handle Top Byte Ignore (TBI) bits.
159 * If address tagging is enabled via the TCR TBI bits:
160 * + for EL2 and EL3 there is only one TBI bit, and if it is set
161 * then the address is zero-extended, clearing bits [63:56]
162 * + for EL0 and EL1, TBI0 controls addresses with bit 55 == 0
163 * and TBI1 controls addressses with bit 55 == 1.
164 * If the appropriate TBI bit is set for the address then
165 * the address is sign-extended from bit 55 into bits [63:56]
167 * Here We have concatenated TBI{1,0} into tbi.
169 static void gen_top_byte_ignore(DisasContext
*s
, TCGv_i64 dst
,
170 TCGv_i64 src
, int tbi
)
173 /* Load unmodified address */
174 tcg_gen_mov_i64(dst
, src
);
175 } else if (!regime_has_2_ranges(s
->mmu_idx
)) {
176 /* Force tag byte to all zero */
177 tcg_gen_extract_i64(dst
, src
, 0, 56);
179 /* Sign-extend from bit 55. */
180 tcg_gen_sextract_i64(dst
, src
, 0, 56);
184 /* tbi0 but !tbi1: only use the extension if positive */
185 tcg_gen_and_i64(dst
, dst
, src
);
188 /* !tbi0 but tbi1: only use the extension if negative */
189 tcg_gen_or_i64(dst
, dst
, src
);
192 /* tbi0 and tbi1: always use the extension */
195 g_assert_not_reached();
200 static void gen_a64_set_pc(DisasContext
*s
, TCGv_i64 src
)
203 * If address tagging is enabled for instructions via the TCR TBI bits,
204 * then loading an address into the PC will clear out any tag.
206 gen_top_byte_ignore(s
, cpu_pc
, src
, s
->tbii
);
210 * Handle MTE and/or TBI.
212 * For TBI, ideally, we would do nothing. Proper behaviour on fault is
213 * for the tag to be present in the FAR_ELx register. But for user-only
214 * mode we do not have a TLB with which to implement this, so we must
215 * remove the top byte now.
217 * Always return a fresh temporary that we can increment independently
218 * of the write-back address.
221 TCGv_i64
clean_data_tbi(DisasContext
*s
, TCGv_i64 addr
)
223 TCGv_i64 clean
= new_tmp_a64(s
);
224 #ifdef CONFIG_USER_ONLY
225 gen_top_byte_ignore(s
, clean
, addr
, s
->tbid
);
227 tcg_gen_mov_i64(clean
, addr
);
232 /* Insert a zero tag into src, with the result at dst. */
233 static void gen_address_with_allocation_tag0(TCGv_i64 dst
, TCGv_i64 src
)
235 tcg_gen_andi_i64(dst
, src
, ~MAKE_64BIT_MASK(56, 4));
238 static void gen_probe_access(DisasContext
*s
, TCGv_i64 ptr
,
239 MMUAccessType acc
, int log2_size
)
241 gen_helper_probe_access(cpu_env
, ptr
,
242 tcg_constant_i32(acc
),
243 tcg_constant_i32(get_mem_index(s
)),
244 tcg_constant_i32(1 << log2_size
));
248 * For MTE, check a single logical or atomic access. This probes a single
249 * address, the exact one specified. The size and alignment of the access
250 * is not relevant to MTE, per se, but watchpoints do require the size,
251 * and we want to recognize those before making any other changes to state.
253 static TCGv_i64
gen_mte_check1_mmuidx(DisasContext
*s
, TCGv_i64 addr
,
254 bool is_write
, bool tag_checked
,
255 int log2_size
, bool is_unpriv
,
258 if (tag_checked
&& s
->mte_active
[is_unpriv
]) {
262 desc
= FIELD_DP32(desc
, MTEDESC
, MIDX
, core_idx
);
263 desc
= FIELD_DP32(desc
, MTEDESC
, TBI
, s
->tbid
);
264 desc
= FIELD_DP32(desc
, MTEDESC
, TCMA
, s
->tcma
);
265 desc
= FIELD_DP32(desc
, MTEDESC
, WRITE
, is_write
);
266 desc
= FIELD_DP32(desc
, MTEDESC
, SIZEM1
, (1 << log2_size
) - 1);
268 ret
= new_tmp_a64(s
);
269 gen_helper_mte_check(ret
, cpu_env
, tcg_constant_i32(desc
), addr
);
273 return clean_data_tbi(s
, addr
);
276 TCGv_i64
gen_mte_check1(DisasContext
*s
, TCGv_i64 addr
, bool is_write
,
277 bool tag_checked
, int log2_size
)
279 return gen_mte_check1_mmuidx(s
, addr
, is_write
, tag_checked
, log2_size
,
280 false, get_mem_index(s
));
284 * For MTE, check multiple logical sequential accesses.
286 TCGv_i64
gen_mte_checkN(DisasContext
*s
, TCGv_i64 addr
, bool is_write
,
287 bool tag_checked
, int size
)
289 if (tag_checked
&& s
->mte_active
[0]) {
293 desc
= FIELD_DP32(desc
, MTEDESC
, MIDX
, get_mem_index(s
));
294 desc
= FIELD_DP32(desc
, MTEDESC
, TBI
, s
->tbid
);
295 desc
= FIELD_DP32(desc
, MTEDESC
, TCMA
, s
->tcma
);
296 desc
= FIELD_DP32(desc
, MTEDESC
, WRITE
, is_write
);
297 desc
= FIELD_DP32(desc
, MTEDESC
, SIZEM1
, size
- 1);
299 ret
= new_tmp_a64(s
);
300 gen_helper_mte_check(ret
, cpu_env
, tcg_constant_i32(desc
), addr
);
304 return clean_data_tbi(s
, addr
);
307 typedef struct DisasCompare64
{
312 static void a64_test_cc(DisasCompare64
*c64
, int cc
)
316 arm_test_cc(&c32
, cc
);
318 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
319 * properly. The NE/EQ comparisons are also fine with this choice. */
320 c64
->cond
= c32
.cond
;
321 c64
->value
= tcg_temp_new_i64();
322 tcg_gen_ext_i32_i64(c64
->value
, c32
.value
);
327 static void a64_free_cc(DisasCompare64
*c64
)
329 tcg_temp_free_i64(c64
->value
);
332 static void gen_rebuild_hflags(DisasContext
*s
)
334 gen_helper_rebuild_hflags_a64(cpu_env
, tcg_constant_i32(s
->current_el
));
337 static void gen_exception_internal(int excp
)
339 assert(excp_is_internal(excp
));
340 gen_helper_exception_internal(cpu_env
, tcg_constant_i32(excp
));
343 static void gen_exception_internal_insn(DisasContext
*s
, uint64_t pc
, int excp
)
345 gen_a64_set_pc_im(pc
);
346 gen_exception_internal(excp
);
347 s
->base
.is_jmp
= DISAS_NORETURN
;
350 static void gen_exception_bkpt_insn(DisasContext
*s
, uint32_t syndrome
)
352 gen_a64_set_pc_im(s
->pc_curr
);
353 gen_helper_exception_bkpt_insn(cpu_env
, tcg_constant_i32(syndrome
));
354 s
->base
.is_jmp
= DISAS_NORETURN
;
357 static void gen_step_complete_exception(DisasContext
*s
)
359 /* We just completed step of an insn. Move from Active-not-pending
360 * to Active-pending, and then also take the swstep exception.
361 * This corresponds to making the (IMPDEF) choice to prioritize
362 * swstep exceptions over asynchronous exceptions taken to an exception
363 * level where debug is disabled. This choice has the advantage that
364 * we do not need to maintain internal state corresponding to the
365 * ISV/EX syndrome bits between completion of the step and generation
366 * of the exception, and our syndrome information is always correct.
369 gen_swstep_exception(s
, 1, s
->is_ldex
);
370 s
->base
.is_jmp
= DISAS_NORETURN
;
373 static inline bool use_goto_tb(DisasContext
*s
, uint64_t dest
)
378 return translator_use_goto_tb(&s
->base
, dest
);
381 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
383 if (use_goto_tb(s
, dest
)) {
385 gen_a64_set_pc_im(dest
);
386 tcg_gen_exit_tb(s
->base
.tb
, n
);
387 s
->base
.is_jmp
= DISAS_NORETURN
;
389 gen_a64_set_pc_im(dest
);
391 gen_step_complete_exception(s
);
393 tcg_gen_lookup_and_goto_ptr();
394 s
->base
.is_jmp
= DISAS_NORETURN
;
399 static void init_tmp_a64_array(DisasContext
*s
)
401 #ifdef CONFIG_DEBUG_TCG
402 memset(s
->tmp_a64
, 0, sizeof(s
->tmp_a64
));
404 s
->tmp_a64_count
= 0;
407 static void free_tmp_a64(DisasContext
*s
)
410 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
411 tcg_temp_free_i64(s
->tmp_a64
[i
]);
413 init_tmp_a64_array(s
);
416 TCGv_i64
new_tmp_a64(DisasContext
*s
)
418 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
419 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
422 TCGv_i64
new_tmp_a64_local(DisasContext
*s
)
424 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
425 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_local_new_i64();
428 TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
430 TCGv_i64 t
= new_tmp_a64(s
);
431 tcg_gen_movi_i64(t
, 0);
436 * Register access functions
438 * These functions are used for directly accessing a register in where
439 * changes to the final register value are likely to be made. If you
440 * need to use a register for temporary calculation (e.g. index type
441 * operations) use the read_* form.
443 * B1.2.1 Register mappings
445 * In instruction register encoding 31 can refer to ZR (zero register) or
446 * the SP (stack pointer) depending on context. In QEMU's case we map SP
447 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
448 * This is the point of the _sp forms.
450 TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
453 return new_tmp_a64_zero(s
);
459 /* register access for when 31 == SP */
460 TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
465 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
466 * representing the register contents. This TCGv is an auto-freed
467 * temporary so it need not be explicitly freed, and may be modified.
469 TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
471 TCGv_i64 v
= new_tmp_a64(s
);
474 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
476 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
479 tcg_gen_movi_i64(v
, 0);
484 TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
486 TCGv_i64 v
= new_tmp_a64(s
);
488 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
490 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
495 /* Return the offset into CPUARMState of a slice (from
496 * the least significant end) of FP register Qn (ie
498 * (Note that this is not the same mapping as for A32; see cpu.h)
500 static inline int fp_reg_offset(DisasContext
*s
, int regno
, MemOp size
)
502 return vec_reg_offset(s
, regno
, 0, size
);
505 /* Offset of the high half of the 128 bit vector Qn */
506 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
508 return vec_reg_offset(s
, regno
, 1, MO_64
);
511 /* Convenience accessors for reading and writing single and double
512 * FP registers. Writing clears the upper parts of the associated
513 * 128 bit vector register, as required by the architecture.
514 * Note that unlike the GP register accessors, the values returned
515 * by the read functions must be manually freed.
517 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
519 TCGv_i64 v
= tcg_temp_new_i64();
521 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
525 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
527 TCGv_i32 v
= tcg_temp_new_i32();
529 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
533 static TCGv_i32
read_fp_hreg(DisasContext
*s
, int reg
)
535 TCGv_i32 v
= tcg_temp_new_i32();
537 tcg_gen_ld16u_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_16
));
541 /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64).
542 * If SVE is not enabled, then there are only 128 bits in the vector.
544 static void clear_vec_high(DisasContext
*s
, bool is_q
, int rd
)
546 unsigned ofs
= fp_reg_offset(s
, rd
, MO_64
);
547 unsigned vsz
= vec_full_reg_size(s
);
549 /* Nop move, with side effect of clearing the tail. */
550 tcg_gen_gvec_mov(MO_64
, ofs
, ofs
, is_q
? 16 : 8, vsz
);
553 void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
555 unsigned ofs
= fp_reg_offset(s
, reg
, MO_64
);
557 tcg_gen_st_i64(v
, cpu_env
, ofs
);
558 clear_vec_high(s
, false, reg
);
561 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
563 TCGv_i64 tmp
= tcg_temp_new_i64();
565 tcg_gen_extu_i32_i64(tmp
, v
);
566 write_fp_dreg(s
, reg
, tmp
);
567 tcg_temp_free_i64(tmp
);
570 /* Expand a 2-operand AdvSIMD vector operation using an expander function. */
571 static void gen_gvec_fn2(DisasContext
*s
, bool is_q
, int rd
, int rn
,
572 GVecGen2Fn
*gvec_fn
, int vece
)
574 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
575 is_q
? 16 : 8, vec_full_reg_size(s
));
578 /* Expand a 2-operand + immediate AdvSIMD vector operation using
579 * an expander function.
581 static void gen_gvec_fn2i(DisasContext
*s
, bool is_q
, int rd
, int rn
,
582 int64_t imm
, GVecGen2iFn
*gvec_fn
, int vece
)
584 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
585 imm
, is_q
? 16 : 8, vec_full_reg_size(s
));
588 /* Expand a 3-operand AdvSIMD vector operation using an expander function. */
589 static void gen_gvec_fn3(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
590 GVecGen3Fn
*gvec_fn
, int vece
)
592 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
593 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8, vec_full_reg_size(s
));
596 /* Expand a 4-operand AdvSIMD vector operation using an expander function. */
597 static void gen_gvec_fn4(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
598 int rx
, GVecGen4Fn
*gvec_fn
, int vece
)
600 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
601 vec_full_reg_offset(s
, rm
), vec_full_reg_offset(s
, rx
),
602 is_q
? 16 : 8, vec_full_reg_size(s
));
605 /* Expand a 2-operand operation using an out-of-line helper. */
606 static void gen_gvec_op2_ool(DisasContext
*s
, bool is_q
, int rd
,
607 int rn
, int data
, gen_helper_gvec_2
*fn
)
609 tcg_gen_gvec_2_ool(vec_full_reg_offset(s
, rd
),
610 vec_full_reg_offset(s
, rn
),
611 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
614 /* Expand a 3-operand operation using an out-of-line helper. */
615 static void gen_gvec_op3_ool(DisasContext
*s
, bool is_q
, int rd
,
616 int rn
, int rm
, int data
, gen_helper_gvec_3
*fn
)
618 tcg_gen_gvec_3_ool(vec_full_reg_offset(s
, rd
),
619 vec_full_reg_offset(s
, rn
),
620 vec_full_reg_offset(s
, rm
),
621 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
624 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
625 * an out-of-line helper.
627 static void gen_gvec_op3_fpst(DisasContext
*s
, bool is_q
, int rd
, int rn
,
628 int rm
, bool is_fp16
, int data
,
629 gen_helper_gvec_3_ptr
*fn
)
631 TCGv_ptr fpst
= fpstatus_ptr(is_fp16
? FPST_FPCR_F16
: FPST_FPCR
);
632 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
633 vec_full_reg_offset(s
, rn
),
634 vec_full_reg_offset(s
, rm
), fpst
,
635 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
636 tcg_temp_free_ptr(fpst
);
639 /* Expand a 3-operand + qc + operation using an out-of-line helper. */
640 static void gen_gvec_op3_qc(DisasContext
*s
, bool is_q
, int rd
, int rn
,
641 int rm
, gen_helper_gvec_3_ptr
*fn
)
643 TCGv_ptr qc_ptr
= tcg_temp_new_ptr();
645 tcg_gen_addi_ptr(qc_ptr
, cpu_env
, offsetof(CPUARMState
, vfp
.qc
));
646 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
647 vec_full_reg_offset(s
, rn
),
648 vec_full_reg_offset(s
, rm
), qc_ptr
,
649 is_q
? 16 : 8, vec_full_reg_size(s
), 0, fn
);
650 tcg_temp_free_ptr(qc_ptr
);
653 /* Expand a 4-operand operation using an out-of-line helper. */
654 static void gen_gvec_op4_ool(DisasContext
*s
, bool is_q
, int rd
, int rn
,
655 int rm
, int ra
, int data
, gen_helper_gvec_4
*fn
)
657 tcg_gen_gvec_4_ool(vec_full_reg_offset(s
, rd
),
658 vec_full_reg_offset(s
, rn
),
659 vec_full_reg_offset(s
, rm
),
660 vec_full_reg_offset(s
, ra
),
661 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
665 * Expand a 4-operand + fpstatus pointer + simd data value operation using
666 * an out-of-line helper.
668 static void gen_gvec_op4_fpst(DisasContext
*s
, bool is_q
, int rd
, int rn
,
669 int rm
, int ra
, bool is_fp16
, int data
,
670 gen_helper_gvec_4_ptr
*fn
)
672 TCGv_ptr fpst
= fpstatus_ptr(is_fp16
? FPST_FPCR_F16
: FPST_FPCR
);
673 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s
, rd
),
674 vec_full_reg_offset(s
, rn
),
675 vec_full_reg_offset(s
, rm
),
676 vec_full_reg_offset(s
, ra
), fpst
,
677 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
678 tcg_temp_free_ptr(fpst
);
681 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
682 * than the 32 bit equivalent.
684 static inline void gen_set_NZ64(TCGv_i64 result
)
686 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
687 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
690 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
691 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
694 gen_set_NZ64(result
);
696 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
697 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
699 tcg_gen_movi_i32(cpu_CF
, 0);
700 tcg_gen_movi_i32(cpu_VF
, 0);
703 /* dest = T0 + T1; compute C, N, V and Z flags */
704 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
707 TCGv_i64 result
, flag
, tmp
;
708 result
= tcg_temp_new_i64();
709 flag
= tcg_temp_new_i64();
710 tmp
= tcg_temp_new_i64();
712 tcg_gen_movi_i64(tmp
, 0);
713 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
715 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
717 gen_set_NZ64(result
);
719 tcg_gen_xor_i64(flag
, result
, t0
);
720 tcg_gen_xor_i64(tmp
, t0
, t1
);
721 tcg_gen_andc_i64(flag
, flag
, tmp
);
722 tcg_temp_free_i64(tmp
);
723 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
725 tcg_gen_mov_i64(dest
, result
);
726 tcg_temp_free_i64(result
);
727 tcg_temp_free_i64(flag
);
729 /* 32 bit arithmetic */
730 TCGv_i32 t0_32
= tcg_temp_new_i32();
731 TCGv_i32 t1_32
= tcg_temp_new_i32();
732 TCGv_i32 tmp
= tcg_temp_new_i32();
734 tcg_gen_movi_i32(tmp
, 0);
735 tcg_gen_extrl_i64_i32(t0_32
, t0
);
736 tcg_gen_extrl_i64_i32(t1_32
, t1
);
737 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
738 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
739 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
740 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
741 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
742 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
744 tcg_temp_free_i32(tmp
);
745 tcg_temp_free_i32(t0_32
);
746 tcg_temp_free_i32(t1_32
);
750 /* dest = T0 - T1; compute C, N, V and Z flags */
751 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
754 /* 64 bit arithmetic */
755 TCGv_i64 result
, flag
, tmp
;
757 result
= tcg_temp_new_i64();
758 flag
= tcg_temp_new_i64();
759 tcg_gen_sub_i64(result
, t0
, t1
);
761 gen_set_NZ64(result
);
763 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
764 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
766 tcg_gen_xor_i64(flag
, result
, t0
);
767 tmp
= tcg_temp_new_i64();
768 tcg_gen_xor_i64(tmp
, t0
, t1
);
769 tcg_gen_and_i64(flag
, flag
, tmp
);
770 tcg_temp_free_i64(tmp
);
771 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
772 tcg_gen_mov_i64(dest
, result
);
773 tcg_temp_free_i64(flag
);
774 tcg_temp_free_i64(result
);
776 /* 32 bit arithmetic */
777 TCGv_i32 t0_32
= tcg_temp_new_i32();
778 TCGv_i32 t1_32
= tcg_temp_new_i32();
781 tcg_gen_extrl_i64_i32(t0_32
, t0
);
782 tcg_gen_extrl_i64_i32(t1_32
, t1
);
783 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
784 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
785 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
786 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
787 tmp
= tcg_temp_new_i32();
788 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
789 tcg_temp_free_i32(t0_32
);
790 tcg_temp_free_i32(t1_32
);
791 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
792 tcg_temp_free_i32(tmp
);
793 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
797 /* dest = T0 + T1 + CF; do not compute flags. */
798 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
800 TCGv_i64 flag
= tcg_temp_new_i64();
801 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
802 tcg_gen_add_i64(dest
, t0
, t1
);
803 tcg_gen_add_i64(dest
, dest
, flag
);
804 tcg_temp_free_i64(flag
);
807 tcg_gen_ext32u_i64(dest
, dest
);
811 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
812 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
815 TCGv_i64 result
= tcg_temp_new_i64();
816 TCGv_i64 cf_64
= tcg_temp_new_i64();
817 TCGv_i64 vf_64
= tcg_temp_new_i64();
818 TCGv_i64 tmp
= tcg_temp_new_i64();
819 TCGv_i64 zero
= tcg_constant_i64(0);
821 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
822 tcg_gen_add2_i64(result
, cf_64
, t0
, zero
, cf_64
, zero
);
823 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, zero
);
824 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
825 gen_set_NZ64(result
);
827 tcg_gen_xor_i64(vf_64
, result
, t0
);
828 tcg_gen_xor_i64(tmp
, t0
, t1
);
829 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
830 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
832 tcg_gen_mov_i64(dest
, result
);
834 tcg_temp_free_i64(tmp
);
835 tcg_temp_free_i64(vf_64
);
836 tcg_temp_free_i64(cf_64
);
837 tcg_temp_free_i64(result
);
839 TCGv_i32 t0_32
= tcg_temp_new_i32();
840 TCGv_i32 t1_32
= tcg_temp_new_i32();
841 TCGv_i32 tmp
= tcg_temp_new_i32();
842 TCGv_i32 zero
= tcg_constant_i32(0);
844 tcg_gen_extrl_i64_i32(t0_32
, t0
);
845 tcg_gen_extrl_i64_i32(t1_32
, t1
);
846 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, zero
, cpu_CF
, zero
);
847 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, zero
);
849 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
850 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
851 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
852 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
853 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
855 tcg_temp_free_i32(tmp
);
856 tcg_temp_free_i32(t1_32
);
857 tcg_temp_free_i32(t0_32
);
862 * Load/Store generators
866 * Store from GPR register to memory.
868 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
869 TCGv_i64 tcg_addr
, MemOp memop
, int memidx
,
871 unsigned int iss_srt
,
872 bool iss_sf
, bool iss_ar
)
874 memop
= finalize_memop(s
, memop
);
875 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, memop
);
880 syn
= syn_data_abort_with_iss(0,
886 0, 0, 0, 0, 0, false);
887 disas_set_insn_syndrome(s
, syn
);
891 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
892 TCGv_i64 tcg_addr
, MemOp memop
,
894 unsigned int iss_srt
,
895 bool iss_sf
, bool iss_ar
)
897 do_gpr_st_memidx(s
, source
, tcg_addr
, memop
, get_mem_index(s
),
898 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
902 * Load from memory to GPR register
904 static void do_gpr_ld_memidx(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
905 MemOp memop
, bool extend
, int memidx
,
906 bool iss_valid
, unsigned int iss_srt
,
907 bool iss_sf
, bool iss_ar
)
909 memop
= finalize_memop(s
, memop
);
910 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
912 if (extend
&& (memop
& MO_SIGN
)) {
913 g_assert((memop
& MO_SIZE
) <= MO_32
);
914 tcg_gen_ext32u_i64(dest
, dest
);
920 syn
= syn_data_abort_with_iss(0,
922 (memop
& MO_SIGN
) != 0,
926 0, 0, 0, 0, 0, false);
927 disas_set_insn_syndrome(s
, syn
);
931 static void do_gpr_ld(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
932 MemOp memop
, bool extend
,
933 bool iss_valid
, unsigned int iss_srt
,
934 bool iss_sf
, bool iss_ar
)
936 do_gpr_ld_memidx(s
, dest
, tcg_addr
, memop
, extend
, get_mem_index(s
),
937 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
941 * Store from FP register to memory
943 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
945 /* This writes the bottom N bits of a 128 bit wide vector to memory */
946 TCGv_i64 tmplo
= tcg_temp_new_i64();
949 tcg_gen_ld_i64(tmplo
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
952 mop
= finalize_memop(s
, size
);
953 tcg_gen_qemu_st_i64(tmplo
, tcg_addr
, get_mem_index(s
), mop
);
955 bool be
= s
->be_data
== MO_BE
;
956 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
957 TCGv_i64 tmphi
= tcg_temp_new_i64();
959 tcg_gen_ld_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
961 mop
= s
->be_data
| MO_UQ
;
962 tcg_gen_qemu_st_i64(be
? tmphi
: tmplo
, tcg_addr
, get_mem_index(s
),
963 mop
| (s
->align_mem
? MO_ALIGN_16
: 0));
964 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
965 tcg_gen_qemu_st_i64(be
? tmplo
: tmphi
, tcg_hiaddr
,
966 get_mem_index(s
), mop
);
968 tcg_temp_free_i64(tcg_hiaddr
);
969 tcg_temp_free_i64(tmphi
);
972 tcg_temp_free_i64(tmplo
);
976 * Load from memory to FP register
978 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
980 /* This always zero-extends and writes to a full 128 bit wide vector */
981 TCGv_i64 tmplo
= tcg_temp_new_i64();
982 TCGv_i64 tmphi
= NULL
;
986 mop
= finalize_memop(s
, size
);
987 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), mop
);
989 bool be
= s
->be_data
== MO_BE
;
992 tmphi
= tcg_temp_new_i64();
993 tcg_hiaddr
= tcg_temp_new_i64();
995 mop
= s
->be_data
| MO_UQ
;
996 tcg_gen_qemu_ld_i64(be
? tmphi
: tmplo
, tcg_addr
, get_mem_index(s
),
997 mop
| (s
->align_mem
? MO_ALIGN_16
: 0));
998 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
999 tcg_gen_qemu_ld_i64(be
? tmplo
: tmphi
, tcg_hiaddr
,
1000 get_mem_index(s
), mop
);
1001 tcg_temp_free_i64(tcg_hiaddr
);
1004 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
1005 tcg_temp_free_i64(tmplo
);
1008 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
1009 tcg_temp_free_i64(tmphi
);
1011 clear_vec_high(s
, tmphi
!= NULL
, 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
, MemOp memop
)
1030 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1031 switch ((unsigned)memop
) {
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
, MemOp 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
, MemOp 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
, MemOp 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
, MemOp mop
)
1131 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1133 read_vec_element(s
, tcg_tmp
, srcidx
, element
, mop
& MO_SIZE
);
1134 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), mop
);
1136 tcg_temp_free_i64(tcg_tmp
);
1139 /* Load from memory to vector register */
1140 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
1141 TCGv_i64 tcg_addr
, MemOp mop
)
1143 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1145 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), mop
);
1146 write_vec_element(s
, tcg_tmp
, destidx
, element
, mop
& MO_SIZE
);
1148 tcg_temp_free_i64(tcg_tmp
);
1151 /* Check that FP/Neon access is enabled. If it is, return
1152 * true. If not, emit code to generate an appropriate exception,
1153 * and return false; the caller should not emit any code for
1154 * the instruction. Note that this check must happen after all
1155 * unallocated-encoding checks (otherwise the syndrome information
1156 * for the resulting exception will be incorrect).
1158 static bool fp_access_check(DisasContext
*s
)
1160 if (s
->fp_excp_el
) {
1161 assert(!s
->fp_access_checked
);
1162 s
->fp_access_checked
= true;
1164 gen_exception_insn_el(s
, s
->pc_curr
, EXCP_UDEF
,
1165 syn_fp_access_trap(1, 0xe, false, 0),
1169 s
->fp_access_checked
= true;
1173 /* Check that SVE access is enabled. If it is, return true.
1174 * If not, emit code to generate an appropriate exception and return false.
1176 bool sve_access_check(DisasContext
*s
)
1178 if (s
->sve_excp_el
) {
1179 assert(!s
->sve_access_checked
);
1180 s
->sve_access_checked
= true;
1182 gen_exception_insn_el(s
, s
->pc_curr
, EXCP_UDEF
,
1183 syn_sve_access_trap(), s
->sve_excp_el
);
1186 s
->sve_access_checked
= true;
1187 return fp_access_check(s
);
1191 * This utility function is for doing register extension with an
1192 * optional shift. You will likely want to pass a temporary for the
1193 * destination register. See DecodeRegExtend() in the ARM ARM.
1195 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1196 int option
, unsigned int shift
)
1198 int extsize
= extract32(option
, 0, 2);
1199 bool is_signed
= extract32(option
, 2, 1);
1204 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1207 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1210 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1213 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1219 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1222 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1225 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1228 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1234 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1238 static inline void gen_check_sp_alignment(DisasContext
*s
)
1240 /* The AArch64 architecture mandates that (if enabled via PSTATE
1241 * or SCTLR bits) there is a check that SP is 16-aligned on every
1242 * SP-relative load or store (with an exception generated if it is not).
1243 * In line with general QEMU practice regarding misaligned accesses,
1244 * we omit these checks for the sake of guest program performance.
1245 * This function is provided as a hook so we can more easily add these
1246 * checks in future (possibly as a "favour catching guest program bugs
1247 * over speed" user selectable option).
1252 * This provides a simple table based table lookup decoder. It is
1253 * intended to be used when the relevant bits for decode are too
1254 * awkwardly placed and switch/if based logic would be confusing and
1255 * deeply nested. Since it's a linear search through the table, tables
1256 * should be kept small.
1258 * It returns the first handler where insn & mask == pattern, or
1259 * NULL if there is no match.
1260 * The table is terminated by an empty mask (i.e. 0)
1262 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1265 const AArch64DecodeTable
*tptr
= table
;
1267 while (tptr
->mask
) {
1268 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1269 return tptr
->disas_fn
;
1277 * The instruction disassembly implemented here matches
1278 * the instruction encoding classifications in chapter C4
1279 * of the ARM Architecture Reference Manual (DDI0487B_a);
1280 * classification names and decode diagrams here should generally
1281 * match up with those in the manual.
1284 /* Unconditional branch (immediate)
1286 * +----+-----------+-------------------------------------+
1287 * | op | 0 0 1 0 1 | imm26 |
1288 * +----+-----------+-------------------------------------+
1290 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1292 uint64_t addr
= s
->pc_curr
+ sextract32(insn
, 0, 26) * 4;
1294 if (insn
& (1U << 31)) {
1295 /* BL Branch with link */
1296 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->base
.pc_next
);
1299 /* B Branch / BL Branch with link */
1301 gen_goto_tb(s
, 0, addr
);
1304 /* Compare and branch (immediate)
1305 * 31 30 25 24 23 5 4 0
1306 * +----+-------------+----+---------------------+--------+
1307 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1308 * +----+-------------+----+---------------------+--------+
1310 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1312 unsigned int sf
, op
, rt
;
1314 TCGLabel
*label_match
;
1317 sf
= extract32(insn
, 31, 1);
1318 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1319 rt
= extract32(insn
, 0, 5);
1320 addr
= s
->pc_curr
+ sextract32(insn
, 5, 19) * 4;
1322 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1323 label_match
= gen_new_label();
1326 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1327 tcg_cmp
, 0, label_match
);
1329 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1330 gen_set_label(label_match
);
1331 gen_goto_tb(s
, 1, addr
);
1334 /* Test and branch (immediate)
1335 * 31 30 25 24 23 19 18 5 4 0
1336 * +----+-------------+----+-------+-------------+------+
1337 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1338 * +----+-------------+----+-------+-------------+------+
1340 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1342 unsigned int bit_pos
, op
, rt
;
1344 TCGLabel
*label_match
;
1347 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1348 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1349 addr
= s
->pc_curr
+ sextract32(insn
, 5, 14) * 4;
1350 rt
= extract32(insn
, 0, 5);
1352 tcg_cmp
= tcg_temp_new_i64();
1353 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1354 label_match
= gen_new_label();
1357 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1358 tcg_cmp
, 0, label_match
);
1359 tcg_temp_free_i64(tcg_cmp
);
1360 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1361 gen_set_label(label_match
);
1362 gen_goto_tb(s
, 1, addr
);
1365 /* Conditional branch (immediate)
1366 * 31 25 24 23 5 4 3 0
1367 * +---------------+----+---------------------+----+------+
1368 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1369 * +---------------+----+---------------------+----+------+
1371 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1376 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1377 unallocated_encoding(s
);
1380 addr
= s
->pc_curr
+ sextract32(insn
, 5, 19) * 4;
1381 cond
= extract32(insn
, 0, 4);
1385 /* genuinely conditional branches */
1386 TCGLabel
*label_match
= gen_new_label();
1387 arm_gen_test_cc(cond
, label_match
);
1388 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1389 gen_set_label(label_match
);
1390 gen_goto_tb(s
, 1, addr
);
1392 /* 0xe and 0xf are both "always" conditions */
1393 gen_goto_tb(s
, 0, addr
);
1397 /* HINT instruction group, including various allocated HINTs */
1398 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1399 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1401 unsigned int selector
= crm
<< 3 | op2
;
1404 unallocated_encoding(s
);
1409 case 0b00000: /* NOP */
1411 case 0b00011: /* WFI */
1412 s
->base
.is_jmp
= DISAS_WFI
;
1414 case 0b00001: /* YIELD */
1415 /* When running in MTTCG we don't generate jumps to the yield and
1416 * WFE helpers as it won't affect the scheduling of other vCPUs.
1417 * If we wanted to more completely model WFE/SEV so we don't busy
1418 * spin unnecessarily we would need to do something more involved.
1420 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1421 s
->base
.is_jmp
= DISAS_YIELD
;
1424 case 0b00010: /* WFE */
1425 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1426 s
->base
.is_jmp
= DISAS_WFE
;
1429 case 0b00100: /* SEV */
1430 case 0b00101: /* SEVL */
1431 case 0b00110: /* DGH */
1432 /* we treat all as NOP at least for now */
1434 case 0b00111: /* XPACLRI */
1435 if (s
->pauth_active
) {
1436 gen_helper_xpaci(cpu_X
[30], cpu_env
, cpu_X
[30]);
1439 case 0b01000: /* PACIA1716 */
1440 if (s
->pauth_active
) {
1441 gen_helper_pacia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1444 case 0b01010: /* PACIB1716 */
1445 if (s
->pauth_active
) {
1446 gen_helper_pacib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1449 case 0b01100: /* AUTIA1716 */
1450 if (s
->pauth_active
) {
1451 gen_helper_autia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1454 case 0b01110: /* AUTIB1716 */
1455 if (s
->pauth_active
) {
1456 gen_helper_autib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1459 case 0b10000: /* ESB */
1460 /* Without RAS, we must implement this as NOP. */
1461 if (dc_isar_feature(aa64_ras
, s
)) {
1463 * QEMU does not have a source of physical SErrors,
1464 * so we are only concerned with virtual SErrors.
1465 * The pseudocode in the ARM for this case is
1466 * if PSTATE.EL IN {EL0, EL1} && EL2Enabled() then
1467 * AArch64.vESBOperation();
1468 * Most of the condition can be evaluated at translation time.
1469 * Test for EL2 present, and defer test for SEL2 to runtime.
1471 if (s
->current_el
<= 1 && arm_dc_feature(s
, ARM_FEATURE_EL2
)) {
1472 gen_helper_vesb(cpu_env
);
1476 case 0b11000: /* PACIAZ */
1477 if (s
->pauth_active
) {
1478 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30],
1479 new_tmp_a64_zero(s
));
1482 case 0b11001: /* PACIASP */
1483 if (s
->pauth_active
) {
1484 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1487 case 0b11010: /* PACIBZ */
1488 if (s
->pauth_active
) {
1489 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30],
1490 new_tmp_a64_zero(s
));
1493 case 0b11011: /* PACIBSP */
1494 if (s
->pauth_active
) {
1495 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1498 case 0b11100: /* AUTIAZ */
1499 if (s
->pauth_active
) {
1500 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30],
1501 new_tmp_a64_zero(s
));
1504 case 0b11101: /* AUTIASP */
1505 if (s
->pauth_active
) {
1506 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1509 case 0b11110: /* AUTIBZ */
1510 if (s
->pauth_active
) {
1511 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30],
1512 new_tmp_a64_zero(s
));
1515 case 0b11111: /* AUTIBSP */
1516 if (s
->pauth_active
) {
1517 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1521 /* default specified as NOP equivalent */
1526 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1528 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1531 /* CLREX, DSB, DMB, ISB */
1532 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1533 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1538 unallocated_encoding(s
);
1549 case 1: /* MBReqTypes_Reads */
1550 bar
= TCG_BAR_SC
| TCG_MO_LD_LD
| TCG_MO_LD_ST
;
1552 case 2: /* MBReqTypes_Writes */
1553 bar
= TCG_BAR_SC
| TCG_MO_ST_ST
;
1555 default: /* MBReqTypes_All */
1556 bar
= TCG_BAR_SC
| TCG_MO_ALL
;
1562 /* We need to break the TB after this insn to execute
1563 * a self-modified code correctly and also to take
1564 * any pending interrupts immediately.
1567 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1571 if (crm
!= 0 || !dc_isar_feature(aa64_sb
, s
)) {
1572 goto do_unallocated
;
1575 * TODO: There is no speculation barrier opcode for TCG;
1576 * MB and end the TB instead.
1578 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
1579 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1584 unallocated_encoding(s
);
1589 static void gen_xaflag(void)
1591 TCGv_i32 z
= tcg_temp_new_i32();
1593 tcg_gen_setcondi_i32(TCG_COND_EQ
, z
, cpu_ZF
, 0);
1602 tcg_gen_or_i32(cpu_NF
, cpu_CF
, z
);
1603 tcg_gen_subi_i32(cpu_NF
, cpu_NF
, 1);
1606 tcg_gen_and_i32(cpu_ZF
, z
, cpu_CF
);
1607 tcg_gen_xori_i32(cpu_ZF
, cpu_ZF
, 1);
1609 /* (!C & Z) << 31 -> -(Z & ~C) */
1610 tcg_gen_andc_i32(cpu_VF
, z
, cpu_CF
);
1611 tcg_gen_neg_i32(cpu_VF
, cpu_VF
);
1614 tcg_gen_or_i32(cpu_CF
, cpu_CF
, z
);
1616 tcg_temp_free_i32(z
);
1619 static void gen_axflag(void)
1621 tcg_gen_sari_i32(cpu_VF
, cpu_VF
, 31); /* V ? -1 : 0 */
1622 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, cpu_VF
); /* C & !V */
1624 /* !(Z | V) -> !(!ZF | V) -> ZF & !V -> ZF & ~VF */
1625 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, cpu_VF
);
1627 tcg_gen_movi_i32(cpu_NF
, 0);
1628 tcg_gen_movi_i32(cpu_VF
, 0);
1631 /* MSR (immediate) - move immediate to processor state field */
1632 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1633 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1635 int op
= op1
<< 3 | op2
;
1637 /* End the TB by default, chaining is ok. */
1638 s
->base
.is_jmp
= DISAS_TOO_MANY
;
1641 case 0x00: /* CFINV */
1642 if (crm
!= 0 || !dc_isar_feature(aa64_condm_4
, s
)) {
1643 goto do_unallocated
;
1645 tcg_gen_xori_i32(cpu_CF
, cpu_CF
, 1);
1646 s
->base
.is_jmp
= DISAS_NEXT
;
1649 case 0x01: /* XAFlag */
1650 if (crm
!= 0 || !dc_isar_feature(aa64_condm_5
, s
)) {
1651 goto do_unallocated
;
1654 s
->base
.is_jmp
= DISAS_NEXT
;
1657 case 0x02: /* AXFlag */
1658 if (crm
!= 0 || !dc_isar_feature(aa64_condm_5
, s
)) {
1659 goto do_unallocated
;
1662 s
->base
.is_jmp
= DISAS_NEXT
;
1665 case 0x03: /* UAO */
1666 if (!dc_isar_feature(aa64_uao
, s
) || s
->current_el
== 0) {
1667 goto do_unallocated
;
1670 set_pstate_bits(PSTATE_UAO
);
1672 clear_pstate_bits(PSTATE_UAO
);
1674 gen_rebuild_hflags(s
);
1677 case 0x04: /* PAN */
1678 if (!dc_isar_feature(aa64_pan
, s
) || s
->current_el
== 0) {
1679 goto do_unallocated
;
1682 set_pstate_bits(PSTATE_PAN
);
1684 clear_pstate_bits(PSTATE_PAN
);
1686 gen_rebuild_hflags(s
);
1689 case 0x05: /* SPSel */
1690 if (s
->current_el
== 0) {
1691 goto do_unallocated
;
1693 gen_helper_msr_i_spsel(cpu_env
, tcg_constant_i32(crm
& PSTATE_SP
));
1696 case 0x19: /* SSBS */
1697 if (!dc_isar_feature(aa64_ssbs
, s
)) {
1698 goto do_unallocated
;
1701 set_pstate_bits(PSTATE_SSBS
);
1703 clear_pstate_bits(PSTATE_SSBS
);
1705 /* Don't need to rebuild hflags since SSBS is a nop */
1708 case 0x1a: /* DIT */
1709 if (!dc_isar_feature(aa64_dit
, s
)) {
1710 goto do_unallocated
;
1713 set_pstate_bits(PSTATE_DIT
);
1715 clear_pstate_bits(PSTATE_DIT
);
1717 /* There's no need to rebuild hflags because DIT is a nop */
1720 case 0x1e: /* DAIFSet */
1721 gen_helper_msr_i_daifset(cpu_env
, tcg_constant_i32(crm
));
1724 case 0x1f: /* DAIFClear */
1725 gen_helper_msr_i_daifclear(cpu_env
, tcg_constant_i32(crm
));
1726 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1727 s
->base
.is_jmp
= DISAS_UPDATE_EXIT
;
1730 case 0x1c: /* TCO */
1731 if (dc_isar_feature(aa64_mte
, s
)) {
1732 /* Full MTE is enabled -- set the TCO bit as directed. */
1734 set_pstate_bits(PSTATE_TCO
);
1736 clear_pstate_bits(PSTATE_TCO
);
1738 gen_rebuild_hflags(s
);
1739 /* Many factors, including TCO, go into MTE_ACTIVE. */
1740 s
->base
.is_jmp
= DISAS_UPDATE_NOCHAIN
;
1741 } else if (dc_isar_feature(aa64_mte_insn_reg
, s
)) {
1742 /* Only "instructions accessible at EL0" -- PSTATE.TCO is WI. */
1743 s
->base
.is_jmp
= DISAS_NEXT
;
1745 goto do_unallocated
;
1751 unallocated_encoding(s
);
1756 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1758 TCGv_i32 tmp
= tcg_temp_new_i32();
1759 TCGv_i32 nzcv
= tcg_temp_new_i32();
1761 /* build bit 31, N */
1762 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1763 /* build bit 30, Z */
1764 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1765 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1766 /* build bit 29, C */
1767 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1768 /* build bit 28, V */
1769 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1770 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1771 /* generate result */
1772 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1774 tcg_temp_free_i32(nzcv
);
1775 tcg_temp_free_i32(tmp
);
1778 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1780 TCGv_i32 nzcv
= tcg_temp_new_i32();
1782 /* take NZCV from R[t] */
1783 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1786 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1788 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1789 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1791 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1792 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1794 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1795 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1796 tcg_temp_free_i32(nzcv
);
1799 static void gen_sysreg_undef(DisasContext
*s
, bool isread
,
1800 uint8_t op0
, uint8_t op1
, uint8_t op2
,
1801 uint8_t crn
, uint8_t crm
, uint8_t rt
)
1804 * Generate code to emit an UNDEF with correct syndrome
1805 * information for a failed system register access.
1806 * This is EC_UNCATEGORIZED (ie a standard UNDEF) in most cases,
1807 * but if FEAT_IDST is implemented then read accesses to registers
1808 * in the feature ID space are reported with the EC_SYSTEMREGISTERTRAP
1813 if (isread
&& dc_isar_feature(aa64_ids
, s
) &&
1814 arm_cpreg_encoding_in_idspace(op0
, op1
, op2
, crn
, crm
)) {
1815 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1817 syndrome
= syn_uncategorized();
1819 gen_exception_insn_el(s
, s
->pc_curr
, EXCP_UDEF
, syndrome
,
1820 default_exception_el(s
));
1823 /* MRS - move from system register
1824 * MSR (register) - move to system register
1827 * These are all essentially the same insn in 'read' and 'write'
1828 * versions, with varying op0 fields.
1830 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1831 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1832 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1834 const ARMCPRegInfo
*ri
;
1837 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1838 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1839 crn
, crm
, op0
, op1
, op2
));
1842 /* Unknown register; this might be a guest error or a QEMU
1843 * unimplemented feature.
1845 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1846 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1847 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1848 gen_sysreg_undef(s
, isread
, op0
, op1
, op2
, crn
, crm
, rt
);
1852 /* Check access permissions */
1853 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1854 gen_sysreg_undef(s
, isread
, op0
, op1
, op2
, crn
, crm
, rt
);
1859 /* Emit code to perform further access permissions checks at
1860 * runtime; this may result in an exception.
1864 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1865 gen_a64_set_pc_im(s
->pc_curr
);
1866 gen_helper_access_check_cp_reg(cpu_env
,
1867 tcg_constant_ptr(ri
),
1868 tcg_constant_i32(syndrome
),
1869 tcg_constant_i32(isread
));
1870 } else if (ri
->type
& ARM_CP_RAISES_EXC
) {
1872 * The readfn or writefn might raise an exception;
1873 * synchronize the CPU state in case it does.
1875 gen_a64_set_pc_im(s
->pc_curr
);
1878 /* Handle special cases first */
1879 switch (ri
->type
& ARM_CP_SPECIAL_MASK
) {
1885 tcg_rt
= cpu_reg(s
, rt
);
1887 gen_get_nzcv(tcg_rt
);
1889 gen_set_nzcv(tcg_rt
);
1892 case ARM_CP_CURRENTEL
:
1893 /* Reads as current EL value from pstate, which is
1894 * guaranteed to be constant by the tb flags.
1896 tcg_rt
= cpu_reg(s
, rt
);
1897 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1900 /* Writes clear the aligned block of memory which rt points into. */
1901 if (s
->mte_active
[0]) {
1904 desc
= FIELD_DP32(desc
, MTEDESC
, MIDX
, get_mem_index(s
));
1905 desc
= FIELD_DP32(desc
, MTEDESC
, TBI
, s
->tbid
);
1906 desc
= FIELD_DP32(desc
, MTEDESC
, TCMA
, s
->tcma
);
1908 tcg_rt
= new_tmp_a64(s
);
1909 gen_helper_mte_check_zva(tcg_rt
, cpu_env
,
1910 tcg_constant_i32(desc
), cpu_reg(s
, rt
));
1912 tcg_rt
= clean_data_tbi(s
, cpu_reg(s
, rt
));
1914 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1918 TCGv_i64 clean_addr
, tag
;
1921 * DC_GVA, like DC_ZVA, requires that we supply the original
1922 * pointer for an invalid page. Probe that address first.
1924 tcg_rt
= cpu_reg(s
, rt
);
1925 clean_addr
= clean_data_tbi(s
, tcg_rt
);
1926 gen_probe_access(s
, clean_addr
, MMU_DATA_STORE
, MO_8
);
1929 /* Extract the tag from the register to match STZGM. */
1930 tag
= tcg_temp_new_i64();
1931 tcg_gen_shri_i64(tag
, tcg_rt
, 56);
1932 gen_helper_stzgm_tags(cpu_env
, clean_addr
, tag
);
1933 tcg_temp_free_i64(tag
);
1937 case ARM_CP_DC_GZVA
:
1939 TCGv_i64 clean_addr
, tag
;
1941 /* For DC_GZVA, we can rely on DC_ZVA for the proper fault. */
1942 tcg_rt
= cpu_reg(s
, rt
);
1943 clean_addr
= clean_data_tbi(s
, tcg_rt
);
1944 gen_helper_dc_zva(cpu_env
, clean_addr
);
1947 /* Extract the tag from the register to match STZGM. */
1948 tag
= tcg_temp_new_i64();
1949 tcg_gen_shri_i64(tag
, tcg_rt
, 56);
1950 gen_helper_stzgm_tags(cpu_env
, clean_addr
, tag
);
1951 tcg_temp_free_i64(tag
);
1956 g_assert_not_reached();
1958 if ((ri
->type
& ARM_CP_FPU
) && !fp_access_check(s
)) {
1960 } else if ((ri
->type
& ARM_CP_SVE
) && !sve_access_check(s
)) {
1964 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1968 tcg_rt
= cpu_reg(s
, rt
);
1971 if (ri
->type
& ARM_CP_CONST
) {
1972 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1973 } else if (ri
->readfn
) {
1974 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tcg_constant_ptr(ri
));
1976 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1979 if (ri
->type
& ARM_CP_CONST
) {
1980 /* If not forbidden by access permissions, treat as WI */
1982 } else if (ri
->writefn
) {
1983 gen_helper_set_cp_reg64(cpu_env
, tcg_constant_ptr(ri
), tcg_rt
);
1985 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1989 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1990 /* I/O operations must end the TB here (whether read or write) */
1991 s
->base
.is_jmp
= DISAS_UPDATE_EXIT
;
1993 if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1995 * A write to any coprocessor regiser that ends a TB
1996 * must rebuild the hflags for the next TB.
1998 gen_rebuild_hflags(s
);
2000 * We default to ending the TB on a coprocessor register write,
2001 * but allow this to be suppressed by the register definition
2002 * (usually only necessary to work around guest bugs).
2004 s
->base
.is_jmp
= DISAS_UPDATE_EXIT
;
2009 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
2010 * +---------------------+---+-----+-----+-------+-------+-----+------+
2011 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
2012 * +---------------------+---+-----+-----+-------+-------+-----+------+
2014 static void disas_system(DisasContext
*s
, uint32_t insn
)
2016 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
2017 l
= extract32(insn
, 21, 1);
2018 op0
= extract32(insn
, 19, 2);
2019 op1
= extract32(insn
, 16, 3);
2020 crn
= extract32(insn
, 12, 4);
2021 crm
= extract32(insn
, 8, 4);
2022 op2
= extract32(insn
, 5, 3);
2023 rt
= extract32(insn
, 0, 5);
2026 if (l
|| rt
!= 31) {
2027 unallocated_encoding(s
);
2031 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
2032 handle_hint(s
, insn
, op1
, op2
, crm
);
2034 case 3: /* CLREX, DSB, DMB, ISB */
2035 handle_sync(s
, insn
, op1
, op2
, crm
);
2037 case 4: /* MSR (immediate) */
2038 handle_msr_i(s
, insn
, op1
, op2
, crm
);
2041 unallocated_encoding(s
);
2046 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
2049 /* Exception generation
2051 * 31 24 23 21 20 5 4 2 1 0
2052 * +-----------------+-----+------------------------+-----+----+
2053 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
2054 * +-----------------------+------------------------+----------+
2056 static void disas_exc(DisasContext
*s
, uint32_t insn
)
2058 int opc
= extract32(insn
, 21, 3);
2059 int op2_ll
= extract32(insn
, 0, 5);
2060 int imm16
= extract32(insn
, 5, 16);
2064 /* For SVC, HVC and SMC we advance the single-step state
2065 * machine before taking the exception. This is architecturally
2066 * mandated, to ensure that single-stepping a system call
2067 * instruction works properly.
2072 gen_exception_insn_el(s
, s
->base
.pc_next
, EXCP_SWI
,
2073 syn_aa64_svc(imm16
), default_exception_el(s
));
2076 if (s
->current_el
== 0) {
2077 unallocated_encoding(s
);
2080 /* The pre HVC helper handles cases when HVC gets trapped
2081 * as an undefined insn by runtime configuration.
2083 gen_a64_set_pc_im(s
->pc_curr
);
2084 gen_helper_pre_hvc(cpu_env
);
2086 gen_exception_insn_el(s
, s
->base
.pc_next
, EXCP_HVC
,
2087 syn_aa64_hvc(imm16
), 2);
2090 if (s
->current_el
== 0) {
2091 unallocated_encoding(s
);
2094 gen_a64_set_pc_im(s
->pc_curr
);
2095 gen_helper_pre_smc(cpu_env
, tcg_constant_i32(syn_aa64_smc(imm16
)));
2097 gen_exception_insn_el(s
, s
->base
.pc_next
, EXCP_SMC
,
2098 syn_aa64_smc(imm16
), 3);
2101 unallocated_encoding(s
);
2107 unallocated_encoding(s
);
2111 gen_exception_bkpt_insn(s
, syn_aa64_bkpt(imm16
));
2115 unallocated_encoding(s
);
2118 /* HLT. This has two purposes.
2119 * Architecturally, it is an external halting debug instruction.
2120 * Since QEMU doesn't implement external debug, we treat this as
2121 * it is required for halting debug disabled: it will UNDEF.
2122 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
2124 if (semihosting_enabled() && imm16
== 0xf000) {
2125 #ifndef CONFIG_USER_ONLY
2126 /* In system mode, don't allow userspace access to semihosting,
2127 * to provide some semblance of security (and for consistency
2128 * with our 32-bit semihosting).
2130 if (s
->current_el
== 0) {
2131 unallocated_encoding(s
);
2135 gen_exception_internal_insn(s
, s
->pc_curr
, EXCP_SEMIHOST
);
2137 unallocated_encoding(s
);
2141 if (op2_ll
< 1 || op2_ll
> 3) {
2142 unallocated_encoding(s
);
2145 /* DCPS1, DCPS2, DCPS3 */
2146 unallocated_encoding(s
);
2149 unallocated_encoding(s
);
2154 /* Unconditional branch (register)
2155 * 31 25 24 21 20 16 15 10 9 5 4 0
2156 * +---------------+-------+-------+-------+------+-------+
2157 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
2158 * +---------------+-------+-------+-------+------+-------+
2160 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
2162 unsigned int opc
, op2
, op3
, rn
, op4
;
2163 unsigned btype_mod
= 2; /* 0: BR, 1: BLR, 2: other */
2167 opc
= extract32(insn
, 21, 4);
2168 op2
= extract32(insn
, 16, 5);
2169 op3
= extract32(insn
, 10, 6);
2170 rn
= extract32(insn
, 5, 5);
2171 op4
= extract32(insn
, 0, 5);
2174 goto do_unallocated
;
2186 goto do_unallocated
;
2188 dst
= cpu_reg(s
, rn
);
2193 if (!dc_isar_feature(aa64_pauth
, s
)) {
2194 goto do_unallocated
;
2198 if (rn
!= 0x1f || op4
!= 0x1f) {
2199 goto do_unallocated
;
2202 modifier
= cpu_X
[31];
2204 /* BRAAZ, BRABZ, BLRAAZ, BLRABZ */
2206 goto do_unallocated
;
2208 modifier
= new_tmp_a64_zero(s
);
2210 if (s
->pauth_active
) {
2211 dst
= new_tmp_a64(s
);
2213 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2215 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2218 dst
= cpu_reg(s
, rn
);
2223 goto do_unallocated
;
2225 gen_a64_set_pc(s
, dst
);
2226 /* BLR also needs to load return address */
2228 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->base
.pc_next
);
2234 if (!dc_isar_feature(aa64_pauth
, s
)) {
2235 goto do_unallocated
;
2237 if ((op3
& ~1) != 2) {
2238 goto do_unallocated
;
2240 btype_mod
= opc
& 1;
2241 if (s
->pauth_active
) {
2242 dst
= new_tmp_a64(s
);
2243 modifier
= cpu_reg_sp(s
, op4
);
2245 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2247 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2250 dst
= cpu_reg(s
, rn
);
2252 gen_a64_set_pc(s
, dst
);
2253 /* BLRAA also needs to load return address */
2255 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->base
.pc_next
);
2260 if (s
->current_el
== 0) {
2261 goto do_unallocated
;
2266 goto do_unallocated
;
2268 dst
= tcg_temp_new_i64();
2269 tcg_gen_ld_i64(dst
, cpu_env
,
2270 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2273 case 2: /* ERETAA */
2274 case 3: /* ERETAB */
2275 if (!dc_isar_feature(aa64_pauth
, s
)) {
2276 goto do_unallocated
;
2278 if (rn
!= 0x1f || op4
!= 0x1f) {
2279 goto do_unallocated
;
2281 dst
= tcg_temp_new_i64();
2282 tcg_gen_ld_i64(dst
, cpu_env
,
2283 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2284 if (s
->pauth_active
) {
2285 modifier
= cpu_X
[31];
2287 gen_helper_autia(dst
, cpu_env
, dst
, modifier
);
2289 gen_helper_autib(dst
, cpu_env
, dst
, modifier
);
2295 goto do_unallocated
;
2297 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
2301 gen_helper_exception_return(cpu_env
, dst
);
2302 tcg_temp_free_i64(dst
);
2303 /* Must exit loop to check un-masked IRQs */
2304 s
->base
.is_jmp
= DISAS_EXIT
;
2308 if (op3
!= 0 || op4
!= 0 || rn
!= 0x1f) {
2309 goto do_unallocated
;
2311 unallocated_encoding(s
);
2317 unallocated_encoding(s
);
2321 switch (btype_mod
) {
2323 if (dc_isar_feature(aa64_bti
, s
)) {
2324 /* BR to {x16,x17} or !guard -> 1, else 3. */
2325 set_btype(s
, rn
== 16 || rn
== 17 || !s
->guarded_page
? 1 : 3);
2330 if (dc_isar_feature(aa64_bti
, s
)) {
2331 /* BLR sets BTYPE to 2, regardless of source guarded page. */
2336 default: /* RET or none of the above. */
2337 /* BTYPE will be set to 0 by normal end-of-insn processing. */
2341 s
->base
.is_jmp
= DISAS_JUMP
;
2344 /* Branches, exception generating and system instructions */
2345 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
2347 switch (extract32(insn
, 25, 7)) {
2348 case 0x0a: case 0x0b:
2349 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
2350 disas_uncond_b_imm(s
, insn
);
2352 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
2353 disas_comp_b_imm(s
, insn
);
2355 case 0x1b: case 0x5b: /* Test & branch (immediate) */
2356 disas_test_b_imm(s
, insn
);
2358 case 0x2a: /* Conditional branch (immediate) */
2359 disas_cond_b_imm(s
, insn
);
2361 case 0x6a: /* Exception generation / System */
2362 if (insn
& (1 << 24)) {
2363 if (extract32(insn
, 22, 2) == 0) {
2364 disas_system(s
, insn
);
2366 unallocated_encoding(s
);
2372 case 0x6b: /* Unconditional branch (register) */
2373 disas_uncond_b_reg(s
, insn
);
2376 unallocated_encoding(s
);
2382 * Load/Store exclusive instructions are implemented by remembering
2383 * the value/address loaded, and seeing if these are the same
2384 * when the store is performed. This is not actually the architecturally
2385 * mandated semantics, but it works for typical guest code sequences
2386 * and avoids having to monitor regular stores.
2388 * The store exclusive uses the atomic cmpxchg primitives to avoid
2389 * races in multi-threaded linux-user and when MTTCG softmmu is
2392 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
2393 TCGv_i64 addr
, int size
, bool is_pair
)
2395 int idx
= get_mem_index(s
);
2396 MemOp memop
= s
->be_data
;
2398 g_assert(size
<= 3);
2400 g_assert(size
>= 2);
2402 /* The pair must be single-copy atomic for the doubleword. */
2403 memop
|= MO_64
| MO_ALIGN
;
2404 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2405 if (s
->be_data
== MO_LE
) {
2406 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 0, 32);
2407 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 32, 32);
2409 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 32, 32);
2410 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 0, 32);
2413 /* The pair must be single-copy atomic for *each* doubleword, not
2414 the entire quadword, however it must be quadword aligned. */
2416 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
,
2417 memop
| MO_ALIGN_16
);
2419 TCGv_i64 addr2
= tcg_temp_new_i64();
2420 tcg_gen_addi_i64(addr2
, addr
, 8);
2421 tcg_gen_qemu_ld_i64(cpu_exclusive_high
, addr2
, idx
, memop
);
2422 tcg_temp_free_i64(addr2
);
2424 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2425 tcg_gen_mov_i64(cpu_reg(s
, rt2
), cpu_exclusive_high
);
2428 memop
|= size
| MO_ALIGN
;
2429 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2430 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2432 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
2435 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
2436 TCGv_i64 addr
, int size
, int is_pair
)
2438 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
2439 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
2442 * [addr + datasize] = {Rt2};
2448 * env->exclusive_addr = -1;
2450 TCGLabel
*fail_label
= gen_new_label();
2451 TCGLabel
*done_label
= gen_new_label();
2454 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
2456 tmp
= tcg_temp_new_i64();
2459 if (s
->be_data
== MO_LE
) {
2460 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2462 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt2
), cpu_reg(s
, rt
));
2464 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
,
2465 cpu_exclusive_val
, tmp
,
2467 MO_64
| MO_ALIGN
| s
->be_data
);
2468 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2469 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2470 if (!HAVE_CMPXCHG128
) {
2471 gen_helper_exit_atomic(cpu_env
);
2473 * Produce a result so we have a well-formed opcode
2474 * stream when the following (dead) code uses 'tmp'.
2475 * TCG will remove the dead ops for us.
2477 tcg_gen_movi_i64(tmp
, 0);
2478 } else if (s
->be_data
== MO_LE
) {
2479 gen_helper_paired_cmpxchg64_le_parallel(tmp
, cpu_env
,
2484 gen_helper_paired_cmpxchg64_be_parallel(tmp
, cpu_env
,
2489 } else if (s
->be_data
== MO_LE
) {
2490 gen_helper_paired_cmpxchg64_le(tmp
, cpu_env
, cpu_exclusive_addr
,
2491 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2493 gen_helper_paired_cmpxchg64_be(tmp
, cpu_env
, cpu_exclusive_addr
,
2494 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2497 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
, cpu_exclusive_val
,
2498 cpu_reg(s
, rt
), get_mem_index(s
),
2499 size
| MO_ALIGN
| s
->be_data
);
2500 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2502 tcg_gen_mov_i64(cpu_reg(s
, rd
), tmp
);
2503 tcg_temp_free_i64(tmp
);
2504 tcg_gen_br(done_label
);
2506 gen_set_label(fail_label
);
2507 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
2508 gen_set_label(done_label
);
2509 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
2512 static void gen_compare_and_swap(DisasContext
*s
, int rs
, int rt
,
2515 TCGv_i64 tcg_rs
= cpu_reg(s
, rs
);
2516 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2517 int memidx
= get_mem_index(s
);
2518 TCGv_i64 clean_addr
;
2521 gen_check_sp_alignment(s
);
2523 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
), true, rn
!= 31, size
);
2524 tcg_gen_atomic_cmpxchg_i64(tcg_rs
, clean_addr
, tcg_rs
, tcg_rt
, memidx
,
2525 size
| MO_ALIGN
| s
->be_data
);
2528 static void gen_compare_and_swap_pair(DisasContext
*s
, int rs
, int rt
,
2531 TCGv_i64 s1
= cpu_reg(s
, rs
);
2532 TCGv_i64 s2
= cpu_reg(s
, rs
+ 1);
2533 TCGv_i64 t1
= cpu_reg(s
, rt
);
2534 TCGv_i64 t2
= cpu_reg(s
, rt
+ 1);
2535 TCGv_i64 clean_addr
;
2536 int memidx
= get_mem_index(s
);
2539 gen_check_sp_alignment(s
);
2542 /* This is a single atomic access, despite the "pair". */
2543 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
), true, rn
!= 31, size
+ 1);
2546 TCGv_i64 cmp
= tcg_temp_new_i64();
2547 TCGv_i64 val
= tcg_temp_new_i64();
2549 if (s
->be_data
== MO_LE
) {
2550 tcg_gen_concat32_i64(val
, t1
, t2
);
2551 tcg_gen_concat32_i64(cmp
, s1
, s2
);
2553 tcg_gen_concat32_i64(val
, t2
, t1
);
2554 tcg_gen_concat32_i64(cmp
, s2
, s1
);
2557 tcg_gen_atomic_cmpxchg_i64(cmp
, clean_addr
, cmp
, val
, memidx
,
2558 MO_64
| MO_ALIGN
| s
->be_data
);
2559 tcg_temp_free_i64(val
);
2561 if (s
->be_data
== MO_LE
) {
2562 tcg_gen_extr32_i64(s1
, s2
, cmp
);
2564 tcg_gen_extr32_i64(s2
, s1
, cmp
);
2566 tcg_temp_free_i64(cmp
);
2567 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2568 if (HAVE_CMPXCHG128
) {
2569 TCGv_i32 tcg_rs
= tcg_constant_i32(rs
);
2570 if (s
->be_data
== MO_LE
) {
2571 gen_helper_casp_le_parallel(cpu_env
, tcg_rs
,
2572 clean_addr
, t1
, t2
);
2574 gen_helper_casp_be_parallel(cpu_env
, tcg_rs
,
2575 clean_addr
, t1
, t2
);
2578 gen_helper_exit_atomic(cpu_env
);
2579 s
->base
.is_jmp
= DISAS_NORETURN
;
2582 TCGv_i64 d1
= tcg_temp_new_i64();
2583 TCGv_i64 d2
= tcg_temp_new_i64();
2584 TCGv_i64 a2
= tcg_temp_new_i64();
2585 TCGv_i64 c1
= tcg_temp_new_i64();
2586 TCGv_i64 c2
= tcg_temp_new_i64();
2587 TCGv_i64 zero
= tcg_constant_i64(0);
2589 /* Load the two words, in memory order. */
2590 tcg_gen_qemu_ld_i64(d1
, clean_addr
, memidx
,
2591 MO_64
| MO_ALIGN_16
| s
->be_data
);
2592 tcg_gen_addi_i64(a2
, clean_addr
, 8);
2593 tcg_gen_qemu_ld_i64(d2
, a2
, memidx
, MO_64
| s
->be_data
);
2595 /* Compare the two words, also in memory order. */
2596 tcg_gen_setcond_i64(TCG_COND_EQ
, c1
, d1
, s1
);
2597 tcg_gen_setcond_i64(TCG_COND_EQ
, c2
, d2
, s2
);
2598 tcg_gen_and_i64(c2
, c2
, c1
);
2600 /* If compare equal, write back new data, else write back old data. */
2601 tcg_gen_movcond_i64(TCG_COND_NE
, c1
, c2
, zero
, t1
, d1
);
2602 tcg_gen_movcond_i64(TCG_COND_NE
, c2
, c2
, zero
, t2
, d2
);
2603 tcg_gen_qemu_st_i64(c1
, clean_addr
, memidx
, MO_64
| s
->be_data
);
2604 tcg_gen_qemu_st_i64(c2
, a2
, memidx
, MO_64
| s
->be_data
);
2605 tcg_temp_free_i64(a2
);
2606 tcg_temp_free_i64(c1
);
2607 tcg_temp_free_i64(c2
);
2609 /* Write back the data from memory to Rs. */
2610 tcg_gen_mov_i64(s1
, d1
);
2611 tcg_gen_mov_i64(s2
, d2
);
2612 tcg_temp_free_i64(d1
);
2613 tcg_temp_free_i64(d2
);
2617 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2618 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2620 static bool disas_ldst_compute_iss_sf(int size
, bool is_signed
, int opc
)
2622 int opc0
= extract32(opc
, 0, 1);
2626 regsize
= opc0
? 32 : 64;
2628 regsize
= size
== 3 ? 64 : 32;
2630 return regsize
== 64;
2633 /* Load/store exclusive
2635 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2636 * +-----+-------------+----+---+----+------+----+-------+------+------+
2637 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2638 * +-----+-------------+----+---+----+------+----+-------+------+------+
2640 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2641 * L: 0 -> store, 1 -> load
2642 * o2: 0 -> exclusive, 1 -> not
2643 * o1: 0 -> single register, 1 -> register pair
2644 * o0: 1 -> load-acquire/store-release, 0 -> not
2646 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
2648 int rt
= extract32(insn
, 0, 5);
2649 int rn
= extract32(insn
, 5, 5);
2650 int rt2
= extract32(insn
, 10, 5);
2651 int rs
= extract32(insn
, 16, 5);
2652 int is_lasr
= extract32(insn
, 15, 1);
2653 int o2_L_o1_o0
= extract32(insn
, 21, 3) * 2 | is_lasr
;
2654 int size
= extract32(insn
, 30, 2);
2655 TCGv_i64 clean_addr
;
2657 switch (o2_L_o1_o0
) {
2658 case 0x0: /* STXR */
2659 case 0x1: /* STLXR */
2661 gen_check_sp_alignment(s
);
2664 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2666 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2667 true, rn
!= 31, size
);
2668 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, false);
2671 case 0x4: /* LDXR */
2672 case 0x5: /* LDAXR */
2674 gen_check_sp_alignment(s
);
2676 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2677 false, rn
!= 31, size
);
2679 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, false);
2681 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2685 case 0x8: /* STLLR */
2686 if (!dc_isar_feature(aa64_lor
, s
)) {
2689 /* StoreLORelease is the same as Store-Release for QEMU. */
2691 case 0x9: /* STLR */
2692 /* Generate ISS for non-exclusive accesses including LASR. */
2694 gen_check_sp_alignment(s
);
2696 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2697 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2698 true, rn
!= 31, size
);
2699 /* TODO: ARMv8.4-LSE SCTLR.nAA */
2700 do_gpr_st(s
, cpu_reg(s
, rt
), clean_addr
, size
| MO_ALIGN
, true, rt
,
2701 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2704 case 0xc: /* LDLAR */
2705 if (!dc_isar_feature(aa64_lor
, s
)) {
2708 /* LoadLOAcquire is the same as Load-Acquire for QEMU. */
2710 case 0xd: /* LDAR */
2711 /* Generate ISS for non-exclusive accesses including LASR. */
2713 gen_check_sp_alignment(s
);
2715 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2716 false, rn
!= 31, size
);
2717 /* TODO: ARMv8.4-LSE SCTLR.nAA */
2718 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, size
| MO_ALIGN
, false, true,
2719 rt
, disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2720 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2723 case 0x2: case 0x3: /* CASP / STXP */
2724 if (size
& 2) { /* STXP / STLXP */
2726 gen_check_sp_alignment(s
);
2729 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2731 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2732 true, rn
!= 31, size
);
2733 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, true);
2737 && ((rt
| rs
) & 1) == 0
2738 && dc_isar_feature(aa64_atomics
, s
)) {
2740 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2745 case 0x6: case 0x7: /* CASPA / LDXP */
2746 if (size
& 2) { /* LDXP / LDAXP */
2748 gen_check_sp_alignment(s
);
2750 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2751 false, rn
!= 31, size
);
2753 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, true);
2755 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2760 && ((rt
| rs
) & 1) == 0
2761 && dc_isar_feature(aa64_atomics
, s
)) {
2762 /* CASPA / CASPAL */
2763 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2769 case 0xb: /* CASL */
2770 case 0xe: /* CASA */
2771 case 0xf: /* CASAL */
2772 if (rt2
== 31 && dc_isar_feature(aa64_atomics
, s
)) {
2773 gen_compare_and_swap(s
, rs
, rt
, rn
, size
);
2778 unallocated_encoding(s
);
2782 * Load register (literal)
2784 * 31 30 29 27 26 25 24 23 5 4 0
2785 * +-----+-------+---+-----+-------------------+-------+
2786 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2787 * +-----+-------+---+-----+-------------------+-------+
2789 * V: 1 -> vector (simd/fp)
2790 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2791 * 10-> 32 bit signed, 11 -> prefetch
2792 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2794 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
2796 int rt
= extract32(insn
, 0, 5);
2797 int64_t imm
= sextract32(insn
, 5, 19) << 2;
2798 bool is_vector
= extract32(insn
, 26, 1);
2799 int opc
= extract32(insn
, 30, 2);
2800 bool is_signed
= false;
2802 TCGv_i64 tcg_rt
, clean_addr
;
2806 unallocated_encoding(s
);
2810 if (!fp_access_check(s
)) {
2815 /* PRFM (literal) : prefetch */
2818 size
= 2 + extract32(opc
, 0, 1);
2819 is_signed
= extract32(opc
, 1, 1);
2822 tcg_rt
= cpu_reg(s
, rt
);
2824 clean_addr
= tcg_constant_i64(s
->pc_curr
+ imm
);
2826 do_fp_ld(s
, rt
, clean_addr
, size
);
2828 /* Only unsigned 32bit loads target 32bit registers. */
2829 bool iss_sf
= opc
!= 0;
2831 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
+ is_signed
* MO_SIGN
,
2832 false, true, rt
, iss_sf
, false);
2837 * LDNP (Load Pair - non-temporal hint)
2838 * LDP (Load Pair - non vector)
2839 * LDPSW (Load Pair Signed Word - non vector)
2840 * STNP (Store Pair - non-temporal hint)
2841 * STP (Store Pair - non vector)
2842 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2843 * LDP (Load Pair of SIMD&FP)
2844 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2845 * STP (Store Pair of SIMD&FP)
2847 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2848 * +-----+-------+---+---+-------+---+-----------------------------+
2849 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2850 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2852 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2854 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2855 * V: 0 -> GPR, 1 -> Vector
2856 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2857 * 10 -> signed offset, 11 -> pre-index
2858 * L: 0 -> Store 1 -> Load
2860 * Rt, Rt2 = GPR or SIMD registers to be stored
2861 * Rn = general purpose register containing address
2862 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2864 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
2866 int rt
= extract32(insn
, 0, 5);
2867 int rn
= extract32(insn
, 5, 5);
2868 int rt2
= extract32(insn
, 10, 5);
2869 uint64_t offset
= sextract64(insn
, 15, 7);
2870 int index
= extract32(insn
, 23, 2);
2871 bool is_vector
= extract32(insn
, 26, 1);
2872 bool is_load
= extract32(insn
, 22, 1);
2873 int opc
= extract32(insn
, 30, 2);
2875 bool is_signed
= false;
2876 bool postindex
= false;
2878 bool set_tag
= false;
2880 TCGv_i64 clean_addr
, dirty_addr
;
2885 unallocated_encoding(s
);
2891 } else if (opc
== 1 && !is_load
) {
2893 if (!dc_isar_feature(aa64_mte_insn_reg
, s
) || index
== 0) {
2894 unallocated_encoding(s
);
2900 size
= 2 + extract32(opc
, 1, 1);
2901 is_signed
= extract32(opc
, 0, 1);
2902 if (!is_load
&& is_signed
) {
2903 unallocated_encoding(s
);
2909 case 1: /* post-index */
2914 /* signed offset with "non-temporal" hint. Since we don't emulate
2915 * caches we don't care about hints to the cache system about
2916 * data access patterns, and handle this identically to plain
2920 /* There is no non-temporal-hint version of LDPSW */
2921 unallocated_encoding(s
);
2926 case 2: /* signed offset, rn not updated */
2929 case 3: /* pre-index */
2935 if (is_vector
&& !fp_access_check(s
)) {
2939 offset
<<= (set_tag
? LOG2_TAG_GRANULE
: size
);
2942 gen_check_sp_alignment(s
);
2945 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
2947 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
2953 * TODO: We could rely on the stores below, at least for
2954 * system mode, if we arrange to add MO_ALIGN_16.
2956 gen_helper_stg_stub(cpu_env
, dirty_addr
);
2957 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2958 gen_helper_stg_parallel(cpu_env
, dirty_addr
, dirty_addr
);
2960 gen_helper_stg(cpu_env
, dirty_addr
, dirty_addr
);
2964 clean_addr
= gen_mte_checkN(s
, dirty_addr
, !is_load
,
2965 (wback
|| rn
!= 31) && !set_tag
, 2 << size
);
2969 do_fp_ld(s
, rt
, clean_addr
, size
);
2971 do_fp_st(s
, rt
, clean_addr
, size
);
2973 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2975 do_fp_ld(s
, rt2
, clean_addr
, size
);
2977 do_fp_st(s
, rt2
, clean_addr
, size
);
2980 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2981 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2984 TCGv_i64 tmp
= tcg_temp_new_i64();
2986 /* Do not modify tcg_rt before recognizing any exception
2987 * from the second load.
2989 do_gpr_ld(s
, tmp
, clean_addr
, size
+ is_signed
* MO_SIGN
,
2990 false, false, 0, false, false);
2991 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2992 do_gpr_ld(s
, tcg_rt2
, clean_addr
, size
+ is_signed
* MO_SIGN
,
2993 false, false, 0, false, false);
2995 tcg_gen_mov_i64(tcg_rt
, tmp
);
2996 tcg_temp_free_i64(tmp
);
2998 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
2999 false, 0, false, false);
3000 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
3001 do_gpr_st(s
, tcg_rt2
, clean_addr
, size
,
3002 false, 0, false, false);
3008 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3010 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
3015 * Load/store (immediate post-indexed)
3016 * Load/store (immediate pre-indexed)
3017 * Load/store (unscaled immediate)
3019 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
3020 * +----+-------+---+-----+-----+---+--------+-----+------+------+
3021 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
3022 * +----+-------+---+-----+-----+---+--------+-----+------+------+
3024 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
3026 * V = 0 -> non-vector
3027 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
3028 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
3030 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
3036 int rn
= extract32(insn
, 5, 5);
3037 int imm9
= sextract32(insn
, 12, 9);
3038 int idx
= extract32(insn
, 10, 2);
3039 bool is_signed
= false;
3040 bool is_store
= false;
3041 bool is_extended
= false;
3042 bool is_unpriv
= (idx
== 2);
3043 bool iss_valid
= !is_vector
;
3048 TCGv_i64 clean_addr
, dirty_addr
;
3051 size
|= (opc
& 2) << 1;
3052 if (size
> 4 || is_unpriv
) {
3053 unallocated_encoding(s
);
3056 is_store
= ((opc
& 1) == 0);
3057 if (!fp_access_check(s
)) {
3061 if (size
== 3 && opc
== 2) {
3062 /* PRFM - prefetch */
3064 unallocated_encoding(s
);
3069 if (opc
== 3 && size
> 1) {
3070 unallocated_encoding(s
);
3073 is_store
= (opc
== 0);
3074 is_signed
= extract32(opc
, 1, 1);
3075 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3093 g_assert_not_reached();
3097 gen_check_sp_alignment(s
);
3100 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3102 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
3105 memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
3106 clean_addr
= gen_mte_check1_mmuidx(s
, dirty_addr
, is_store
,
3107 writeback
|| rn
!= 31,
3108 size
, is_unpriv
, memidx
);
3112 do_fp_st(s
, rt
, clean_addr
, size
);
3114 do_fp_ld(s
, rt
, clean_addr
, size
);
3117 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3118 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3121 do_gpr_st_memidx(s
, tcg_rt
, clean_addr
, size
, memidx
,
3122 iss_valid
, rt
, iss_sf
, false);
3124 do_gpr_ld_memidx(s
, tcg_rt
, clean_addr
, size
+ is_signed
* MO_SIGN
,
3125 is_extended
, memidx
,
3126 iss_valid
, rt
, iss_sf
, false);
3131 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
3133 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
3135 tcg_gen_mov_i64(tcg_rn
, dirty_addr
);
3140 * Load/store (register offset)
3142 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3143 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
3144 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
3145 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
3148 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
3149 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
3151 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
3152 * opc<0>: 0 -> store, 1 -> load
3153 * V: 1 -> vector/simd
3154 * opt: extend encoding (see DecodeRegExtend)
3155 * S: if S=1 then scale (essentially index by sizeof(size))
3156 * Rt: register to transfer into/out of
3157 * Rn: address register or SP for base
3158 * Rm: offset register or ZR for offset
3160 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
3166 int rn
= extract32(insn
, 5, 5);
3167 int shift
= extract32(insn
, 12, 1);
3168 int rm
= extract32(insn
, 16, 5);
3169 int opt
= extract32(insn
, 13, 3);
3170 bool is_signed
= false;
3171 bool is_store
= false;
3172 bool is_extended
= false;
3174 TCGv_i64 tcg_rm
, clean_addr
, dirty_addr
;
3176 if (extract32(opt
, 1, 1) == 0) {
3177 unallocated_encoding(s
);
3182 size
|= (opc
& 2) << 1;
3184 unallocated_encoding(s
);
3187 is_store
= !extract32(opc
, 0, 1);
3188 if (!fp_access_check(s
)) {
3192 if (size
== 3 && opc
== 2) {
3193 /* PRFM - prefetch */
3196 if (opc
== 3 && size
> 1) {
3197 unallocated_encoding(s
);
3200 is_store
= (opc
== 0);
3201 is_signed
= extract32(opc
, 1, 1);
3202 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3206 gen_check_sp_alignment(s
);
3208 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3210 tcg_rm
= read_cpu_reg(s
, rm
, 1);
3211 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
3213 tcg_gen_add_i64(dirty_addr
, dirty_addr
, tcg_rm
);
3214 clean_addr
= gen_mte_check1(s
, dirty_addr
, is_store
, true, size
);
3218 do_fp_st(s
, rt
, clean_addr
, size
);
3220 do_fp_ld(s
, rt
, clean_addr
, size
);
3223 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3224 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3226 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3227 true, rt
, iss_sf
, false);
3229 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
+ is_signed
* MO_SIGN
,
3230 is_extended
, true, rt
, iss_sf
, false);
3236 * Load/store (unsigned immediate)
3238 * 31 30 29 27 26 25 24 23 22 21 10 9 5
3239 * +----+-------+---+-----+-----+------------+-------+------+
3240 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
3241 * +----+-------+---+-----+-----+------------+-------+------+
3244 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
3245 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
3247 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
3248 * opc<0>: 0 -> store, 1 -> load
3249 * Rn: base address register (inc SP)
3250 * Rt: target register
3252 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
3258 int rn
= extract32(insn
, 5, 5);
3259 unsigned int imm12
= extract32(insn
, 10, 12);
3260 unsigned int offset
;
3262 TCGv_i64 clean_addr
, dirty_addr
;
3265 bool is_signed
= false;
3266 bool is_extended
= false;
3269 size
|= (opc
& 2) << 1;
3271 unallocated_encoding(s
);
3274 is_store
= !extract32(opc
, 0, 1);
3275 if (!fp_access_check(s
)) {
3279 if (size
== 3 && opc
== 2) {
3280 /* PRFM - prefetch */
3283 if (opc
== 3 && size
> 1) {
3284 unallocated_encoding(s
);
3287 is_store
= (opc
== 0);
3288 is_signed
= extract32(opc
, 1, 1);
3289 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3293 gen_check_sp_alignment(s
);
3295 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3296 offset
= imm12
<< size
;
3297 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3298 clean_addr
= gen_mte_check1(s
, dirty_addr
, is_store
, rn
!= 31, size
);
3302 do_fp_st(s
, rt
, clean_addr
, size
);
3304 do_fp_ld(s
, rt
, clean_addr
, size
);
3307 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3308 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3310 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3311 true, rt
, iss_sf
, false);
3313 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
+ is_signed
* MO_SIGN
,
3314 is_extended
, true, rt
, iss_sf
, false);
3319 /* Atomic memory operations
3321 * 31 30 27 26 24 22 21 16 15 12 10 5 0
3322 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
3323 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
3324 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
3326 * Rt: the result register
3327 * Rn: base address or SP
3328 * Rs: the source register for the operation
3329 * V: vector flag (always 0 as of v8.3)
3333 static void disas_ldst_atomic(DisasContext
*s
, uint32_t insn
,
3334 int size
, int rt
, bool is_vector
)
3336 int rs
= extract32(insn
, 16, 5);
3337 int rn
= extract32(insn
, 5, 5);
3338 int o3_opc
= extract32(insn
, 12, 4);
3339 bool r
= extract32(insn
, 22, 1);
3340 bool a
= extract32(insn
, 23, 1);
3341 TCGv_i64 tcg_rs
, tcg_rt
, clean_addr
;
3342 AtomicThreeOpFn
*fn
= NULL
;
3343 MemOp mop
= s
->be_data
| size
| MO_ALIGN
;
3345 if (is_vector
|| !dc_isar_feature(aa64_atomics
, s
)) {
3346 unallocated_encoding(s
);
3350 case 000: /* LDADD */
3351 fn
= tcg_gen_atomic_fetch_add_i64
;
3353 case 001: /* LDCLR */
3354 fn
= tcg_gen_atomic_fetch_and_i64
;
3356 case 002: /* LDEOR */
3357 fn
= tcg_gen_atomic_fetch_xor_i64
;
3359 case 003: /* LDSET */
3360 fn
= tcg_gen_atomic_fetch_or_i64
;
3362 case 004: /* LDSMAX */
3363 fn
= tcg_gen_atomic_fetch_smax_i64
;
3366 case 005: /* LDSMIN */
3367 fn
= tcg_gen_atomic_fetch_smin_i64
;
3370 case 006: /* LDUMAX */
3371 fn
= tcg_gen_atomic_fetch_umax_i64
;
3373 case 007: /* LDUMIN */
3374 fn
= tcg_gen_atomic_fetch_umin_i64
;
3377 fn
= tcg_gen_atomic_xchg_i64
;
3379 case 014: /* LDAPR, LDAPRH, LDAPRB */
3380 if (!dc_isar_feature(aa64_rcpc_8_3
, s
) ||
3381 rs
!= 31 || a
!= 1 || r
!= 0) {
3382 unallocated_encoding(s
);
3387 unallocated_encoding(s
);
3392 gen_check_sp_alignment(s
);
3394 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
), false, rn
!= 31, size
);
3396 if (o3_opc
== 014) {
3398 * LDAPR* are a special case because they are a simple load, not a
3399 * fetch-and-do-something op.
3400 * The architectural consistency requirements here are weaker than
3401 * full load-acquire (we only need "load-acquire processor consistent"),
3402 * but we choose to implement them as full LDAQ.
3404 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, size
, false,
3405 true, rt
, disas_ldst_compute_iss_sf(size
, false, 0), true);
3406 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
3410 tcg_rs
= read_cpu_reg(s
, rs
, true);
3411 tcg_rt
= cpu_reg(s
, rt
);
3413 if (o3_opc
== 1) { /* LDCLR */
3414 tcg_gen_not_i64(tcg_rs
, tcg_rs
);
3417 /* The tcg atomic primitives are all full barriers. Therefore we
3418 * can ignore the Acquire and Release bits of this instruction.
3420 fn(tcg_rt
, clean_addr
, tcg_rs
, get_mem_index(s
), mop
);
3422 if ((mop
& MO_SIGN
) && size
!= MO_64
) {
3423 tcg_gen_ext32u_i64(tcg_rt
, tcg_rt
);
3428 * PAC memory operations
3430 * 31 30 27 26 24 22 21 12 11 10 5 0
3431 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3432 * | size | 1 1 1 | V | 0 0 | M S | 1 | imm9 | W | 1 | Rn | Rt |
3433 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3435 * Rt: the result register
3436 * Rn: base address or SP
3437 * V: vector flag (always 0 as of v8.3)
3438 * M: clear for key DA, set for key DB
3439 * W: pre-indexing flag
3442 static void disas_ldst_pac(DisasContext
*s
, uint32_t insn
,
3443 int size
, int rt
, bool is_vector
)
3445 int rn
= extract32(insn
, 5, 5);
3446 bool is_wback
= extract32(insn
, 11, 1);
3447 bool use_key_a
= !extract32(insn
, 23, 1);
3449 TCGv_i64 clean_addr
, dirty_addr
, tcg_rt
;
3451 if (size
!= 3 || is_vector
|| !dc_isar_feature(aa64_pauth
, s
)) {
3452 unallocated_encoding(s
);
3457 gen_check_sp_alignment(s
);
3459 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3461 if (s
->pauth_active
) {
3463 gen_helper_autda(dirty_addr
, cpu_env
, dirty_addr
,
3464 new_tmp_a64_zero(s
));
3466 gen_helper_autdb(dirty_addr
, cpu_env
, dirty_addr
,
3467 new_tmp_a64_zero(s
));
3471 /* Form the 10-bit signed, scaled offset. */
3472 offset
= (extract32(insn
, 22, 1) << 9) | extract32(insn
, 12, 9);
3473 offset
= sextract32(offset
<< size
, 0, 10 + size
);
3474 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3476 /* Note that "clean" and "dirty" here refer to TBI not PAC. */
3477 clean_addr
= gen_mte_check1(s
, dirty_addr
, false,
3478 is_wback
|| rn
!= 31, size
);
3480 tcg_rt
= cpu_reg(s
, rt
);
3481 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
,
3482 /* extend */ false, /* iss_valid */ !is_wback
,
3483 /* iss_srt */ rt
, /* iss_sf */ true, /* iss_ar */ false);
3486 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
3491 * LDAPR/STLR (unscaled immediate)
3493 * 31 30 24 22 21 12 10 5 0
3494 * +------+-------------+-----+---+--------+-----+----+-----+
3495 * | size | 0 1 1 0 0 1 | opc | 0 | imm9 | 0 0 | Rn | Rt |
3496 * +------+-------------+-----+---+--------+-----+----+-----+
3498 * Rt: source or destination register
3500 * imm9: unscaled immediate offset
3501 * opc: 00: STLUR*, 01/10/11: various LDAPUR*
3502 * size: size of load/store
3504 static void disas_ldst_ldapr_stlr(DisasContext
*s
, uint32_t insn
)
3506 int rt
= extract32(insn
, 0, 5);
3507 int rn
= extract32(insn
, 5, 5);
3508 int offset
= sextract32(insn
, 12, 9);
3509 int opc
= extract32(insn
, 22, 2);
3510 int size
= extract32(insn
, 30, 2);
3511 TCGv_i64 clean_addr
, dirty_addr
;
3512 bool is_store
= false;
3513 bool extend
= false;
3517 if (!dc_isar_feature(aa64_rcpc_8_4
, s
)) {
3518 unallocated_encoding(s
);
3522 /* TODO: ARMv8.4-LSE SCTLR.nAA */
3523 mop
= size
| MO_ALIGN
;
3526 case 0: /* STLURB */
3529 case 1: /* LDAPUR* */
3531 case 2: /* LDAPURS* 64-bit variant */
3533 unallocated_encoding(s
);
3538 case 3: /* LDAPURS* 32-bit variant */
3540 unallocated_encoding(s
);
3544 extend
= true; /* zero-extend 32->64 after signed load */
3547 g_assert_not_reached();
3550 iss_sf
= disas_ldst_compute_iss_sf(size
, (mop
& MO_SIGN
) != 0, opc
);
3553 gen_check_sp_alignment(s
);
3556 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3557 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3558 clean_addr
= clean_data_tbi(s
, dirty_addr
);
3561 /* Store-Release semantics */
3562 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
3563 do_gpr_st(s
, cpu_reg(s
, rt
), clean_addr
, mop
, true, rt
, iss_sf
, true);
3566 * Load-AcquirePC semantics; we implement as the slightly more
3567 * restrictive Load-Acquire.
3569 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, mop
,
3570 extend
, true, rt
, iss_sf
, true);
3571 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
3575 /* Load/store register (all forms) */
3576 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
3578 int rt
= extract32(insn
, 0, 5);
3579 int opc
= extract32(insn
, 22, 2);
3580 bool is_vector
= extract32(insn
, 26, 1);
3581 int size
= extract32(insn
, 30, 2);
3583 switch (extract32(insn
, 24, 2)) {
3585 if (extract32(insn
, 21, 1) == 0) {
3586 /* Load/store register (unscaled immediate)
3587 * Load/store immediate pre/post-indexed
3588 * Load/store register unprivileged
3590 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
3593 switch (extract32(insn
, 10, 2)) {
3595 disas_ldst_atomic(s
, insn
, size
, rt
, is_vector
);
3598 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
3601 disas_ldst_pac(s
, insn
, size
, rt
, is_vector
);
3606 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
3609 unallocated_encoding(s
);
3612 /* AdvSIMD load/store multiple structures
3614 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
3615 * +---+---+---------------+---+-------------+--------+------+------+------+
3616 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
3617 * +---+---+---------------+---+-------------+--------+------+------+------+
3619 * AdvSIMD load/store multiple structures (post-indexed)
3621 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
3622 * +---+---+---------------+---+---+---------+--------+------+------+------+
3623 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
3624 * +---+---+---------------+---+---+---------+--------+------+------+------+
3626 * Rt: first (or only) SIMD&FP register to be transferred
3627 * Rn: base address or SP
3628 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3630 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
3632 int rt
= extract32(insn
, 0, 5);
3633 int rn
= extract32(insn
, 5, 5);
3634 int rm
= extract32(insn
, 16, 5);
3635 int size
= extract32(insn
, 10, 2);
3636 int opcode
= extract32(insn
, 12, 4);
3637 bool is_store
= !extract32(insn
, 22, 1);
3638 bool is_postidx
= extract32(insn
, 23, 1);
3639 bool is_q
= extract32(insn
, 30, 1);
3640 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3641 MemOp endian
, align
, mop
;
3643 int total
; /* total bytes */
3644 int elements
; /* elements per vector */
3645 int rpt
; /* num iterations */
3646 int selem
; /* structure elements */
3649 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
3650 unallocated_encoding(s
);
3654 if (!is_postidx
&& rm
!= 0) {
3655 unallocated_encoding(s
);
3659 /* From the shared decode logic */
3690 unallocated_encoding(s
);
3694 if (size
== 3 && !is_q
&& selem
!= 1) {
3696 unallocated_encoding(s
);
3700 if (!fp_access_check(s
)) {
3705 gen_check_sp_alignment(s
);
3708 /* For our purposes, bytes are always little-endian. */
3709 endian
= s
->be_data
;
3714 total
= rpt
* selem
* (is_q
? 16 : 8);
3715 tcg_rn
= cpu_reg_sp(s
, rn
);
3718 * Issue the MTE check vs the logical repeat count, before we
3719 * promote consecutive little-endian elements below.
3721 clean_addr
= gen_mte_checkN(s
, tcg_rn
, is_store
, is_postidx
|| rn
!= 31,
3725 * Consecutive little-endian elements from a single register
3726 * can be promoted to a larger little-endian operation.
3729 if (selem
== 1 && endian
== MO_LE
) {
3730 align
= pow2_align(size
);
3733 if (!s
->align_mem
) {
3736 mop
= endian
| size
| align
;
3738 elements
= (is_q
? 16 : 8) >> size
;
3739 tcg_ebytes
= tcg_constant_i64(1 << size
);
3740 for (r
= 0; r
< rpt
; r
++) {
3742 for (e
= 0; e
< elements
; e
++) {
3744 for (xs
= 0; xs
< selem
; xs
++) {
3745 int tt
= (rt
+ r
+ xs
) % 32;
3747 do_vec_st(s
, tt
, e
, clean_addr
, mop
);
3749 do_vec_ld(s
, tt
, e
, clean_addr
, mop
);
3751 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
3757 /* For non-quad operations, setting a slice of the low
3758 * 64 bits of the register clears the high 64 bits (in
3759 * the ARM ARM pseudocode this is implicit in the fact
3760 * that 'rval' is a 64 bit wide variable).
3761 * For quad operations, we might still need to zero the
3764 for (r
= 0; r
< rpt
* selem
; r
++) {
3765 int tt
= (rt
+ r
) % 32;
3766 clear_vec_high(s
, is_q
, tt
);
3772 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, total
);
3774 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3779 /* AdvSIMD load/store single structure
3781 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3782 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3783 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3784 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3786 * AdvSIMD load/store single structure (post-indexed)
3788 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3789 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3790 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3791 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3793 * Rt: first (or only) SIMD&FP register to be transferred
3794 * Rn: base address or SP
3795 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3796 * index = encoded in Q:S:size dependent on size
3798 * lane_size = encoded in R, opc
3799 * transfer width = encoded in opc, S, size
3801 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
3803 int rt
= extract32(insn
, 0, 5);
3804 int rn
= extract32(insn
, 5, 5);
3805 int rm
= extract32(insn
, 16, 5);
3806 int size
= extract32(insn
, 10, 2);
3807 int S
= extract32(insn
, 12, 1);
3808 int opc
= extract32(insn
, 13, 3);
3809 int R
= extract32(insn
, 21, 1);
3810 int is_load
= extract32(insn
, 22, 1);
3811 int is_postidx
= extract32(insn
, 23, 1);
3812 int is_q
= extract32(insn
, 30, 1);
3814 int scale
= extract32(opc
, 1, 2);
3815 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
3816 bool replicate
= false;
3817 int index
= is_q
<< 3 | S
<< 2 | size
;
3819 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3822 if (extract32(insn
, 31, 1)) {
3823 unallocated_encoding(s
);
3826 if (!is_postidx
&& rm
!= 0) {
3827 unallocated_encoding(s
);
3833 if (!is_load
|| S
) {
3834 unallocated_encoding(s
);
3843 if (extract32(size
, 0, 1)) {
3844 unallocated_encoding(s
);
3850 if (extract32(size
, 1, 1)) {
3851 unallocated_encoding(s
);
3854 if (!extract32(size
, 0, 1)) {
3858 unallocated_encoding(s
);
3866 g_assert_not_reached();
3869 if (!fp_access_check(s
)) {
3874 gen_check_sp_alignment(s
);
3877 total
= selem
<< scale
;
3878 tcg_rn
= cpu_reg_sp(s
, rn
);
3880 clean_addr
= gen_mte_checkN(s
, tcg_rn
, !is_load
, is_postidx
|| rn
!= 31,
3882 mop
= finalize_memop(s
, scale
);
3884 tcg_ebytes
= tcg_constant_i64(1 << scale
);
3885 for (xs
= 0; xs
< selem
; xs
++) {
3887 /* Load and replicate to all elements */
3888 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3890 tcg_gen_qemu_ld_i64(tcg_tmp
, clean_addr
, get_mem_index(s
), mop
);
3891 tcg_gen_gvec_dup_i64(scale
, vec_full_reg_offset(s
, rt
),
3892 (is_q
+ 1) * 8, vec_full_reg_size(s
),
3894 tcg_temp_free_i64(tcg_tmp
);
3896 /* Load/store one element per register */
3898 do_vec_ld(s
, rt
, index
, clean_addr
, mop
);
3900 do_vec_st(s
, rt
, index
, clean_addr
, mop
);
3903 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
3909 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, total
);
3911 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3917 * Load/Store memory tags
3919 * 31 30 29 24 22 21 12 10 5 0
3920 * +-----+-------------+-----+---+------+-----+------+------+
3921 * | 1 1 | 0 1 1 0 0 1 | op1 | 1 | imm9 | op2 | Rn | Rt |
3922 * +-----+-------------+-----+---+------+-----+------+------+
3924 static void disas_ldst_tag(DisasContext
*s
, uint32_t insn
)
3926 int rt
= extract32(insn
, 0, 5);
3927 int rn
= extract32(insn
, 5, 5);
3928 uint64_t offset
= sextract64(insn
, 12, 9) << LOG2_TAG_GRANULE
;
3929 int op2
= extract32(insn
, 10, 2);
3930 int op1
= extract32(insn
, 22, 2);
3931 bool is_load
= false, is_pair
= false, is_zero
= false, is_mult
= false;
3933 TCGv_i64 addr
, clean_addr
, tcg_rt
;
3935 /* We checked insn bits [29:24,21] in the caller. */
3936 if (extract32(insn
, 30, 2) != 3) {
3937 goto do_unallocated
;
3941 * @index is a tri-state variable which has 3 states:
3942 * < 0 : post-index, writeback
3943 * = 0 : signed offset
3944 * > 0 : pre-index, writeback
3953 if (s
->current_el
== 0 || offset
!= 0) {
3954 goto do_unallocated
;
3956 is_mult
= is_zero
= true;
3976 if (s
->current_el
== 0 || offset
!= 0) {
3977 goto do_unallocated
;
3985 is_pair
= is_zero
= true;
3989 if (s
->current_el
== 0 || offset
!= 0) {
3990 goto do_unallocated
;
3992 is_mult
= is_load
= true;
3998 unallocated_encoding(s
);
4003 ? !dc_isar_feature(aa64_mte
, s
)
4004 : !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
4005 goto do_unallocated
;
4009 gen_check_sp_alignment(s
);
4012 addr
= read_cpu_reg_sp(s
, rn
, true);
4014 /* pre-index or signed offset */
4015 tcg_gen_addi_i64(addr
, addr
, offset
);
4019 tcg_rt
= cpu_reg(s
, rt
);
4022 int size
= 4 << s
->dcz_blocksize
;
4025 gen_helper_stzgm_tags(cpu_env
, addr
, tcg_rt
);
4028 * The non-tags portion of STZGM is mostly like DC_ZVA,
4029 * except the alignment happens before the access.
4031 clean_addr
= clean_data_tbi(s
, addr
);
4032 tcg_gen_andi_i64(clean_addr
, clean_addr
, -size
);
4033 gen_helper_dc_zva(cpu_env
, clean_addr
);
4034 } else if (s
->ata
) {
4036 gen_helper_ldgm(tcg_rt
, cpu_env
, addr
);
4038 gen_helper_stgm(cpu_env
, addr
, tcg_rt
);
4041 MMUAccessType acc
= is_load
? MMU_DATA_LOAD
: MMU_DATA_STORE
;
4042 int size
= 4 << GMID_EL1_BS
;
4044 clean_addr
= clean_data_tbi(s
, addr
);
4045 tcg_gen_andi_i64(clean_addr
, clean_addr
, -size
);
4046 gen_probe_access(s
, clean_addr
, acc
, size
);
4049 /* The result tags are zeros. */
4050 tcg_gen_movi_i64(tcg_rt
, 0);
4057 tcg_gen_andi_i64(addr
, addr
, -TAG_GRANULE
);
4058 tcg_rt
= cpu_reg(s
, rt
);
4060 gen_helper_ldg(tcg_rt
, cpu_env
, addr
, tcg_rt
);
4062 clean_addr
= clean_data_tbi(s
, addr
);
4063 gen_probe_access(s
, clean_addr
, MMU_DATA_LOAD
, MO_8
);
4064 gen_address_with_allocation_tag0(tcg_rt
, addr
);
4067 tcg_rt
= cpu_reg_sp(s
, rt
);
4070 * For STG and ST2G, we need to check alignment and probe memory.
4071 * TODO: For STZG and STZ2G, we could rely on the stores below,
4072 * at least for system mode; user-only won't enforce alignment.
4075 gen_helper_st2g_stub(cpu_env
, addr
);
4077 gen_helper_stg_stub(cpu_env
, addr
);
4079 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
4081 gen_helper_st2g_parallel(cpu_env
, addr
, tcg_rt
);
4083 gen_helper_stg_parallel(cpu_env
, addr
, tcg_rt
);
4087 gen_helper_st2g(cpu_env
, addr
, tcg_rt
);
4089 gen_helper_stg(cpu_env
, addr
, tcg_rt
);
4095 TCGv_i64 clean_addr
= clean_data_tbi(s
, addr
);
4096 TCGv_i64 tcg_zero
= tcg_constant_i64(0);
4097 int mem_index
= get_mem_index(s
);
4098 int i
, n
= (1 + is_pair
) << LOG2_TAG_GRANULE
;
4100 tcg_gen_qemu_st_i64(tcg_zero
, clean_addr
, mem_index
,
4101 MO_UQ
| MO_ALIGN_16
);
4102 for (i
= 8; i
< n
; i
+= 8) {
4103 tcg_gen_addi_i64(clean_addr
, clean_addr
, 8);
4104 tcg_gen_qemu_st_i64(tcg_zero
, clean_addr
, mem_index
, MO_UQ
);
4109 /* pre-index or post-index */
4112 tcg_gen_addi_i64(addr
, addr
, offset
);
4114 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), addr
);
4118 /* Loads and stores */
4119 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
4121 switch (extract32(insn
, 24, 6)) {
4122 case 0x08: /* Load/store exclusive */
4123 disas_ldst_excl(s
, insn
);
4125 case 0x18: case 0x1c: /* Load register (literal) */
4126 disas_ld_lit(s
, insn
);
4128 case 0x28: case 0x29:
4129 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
4130 disas_ldst_pair(s
, insn
);
4132 case 0x38: case 0x39:
4133 case 0x3c: case 0x3d: /* Load/store register (all forms) */
4134 disas_ldst_reg(s
, insn
);
4136 case 0x0c: /* AdvSIMD load/store multiple structures */
4137 disas_ldst_multiple_struct(s
, insn
);
4139 case 0x0d: /* AdvSIMD load/store single structure */
4140 disas_ldst_single_struct(s
, insn
);
4143 if (extract32(insn
, 21, 1) != 0) {
4144 disas_ldst_tag(s
, insn
);
4145 } else if (extract32(insn
, 10, 2) == 0) {
4146 disas_ldst_ldapr_stlr(s
, insn
);
4148 unallocated_encoding(s
);
4152 unallocated_encoding(s
);
4157 /* PC-rel. addressing
4158 * 31 30 29 28 24 23 5 4 0
4159 * +----+-------+-----------+-------------------+------+
4160 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
4161 * +----+-------+-----------+-------------------+------+
4163 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
4165 unsigned int page
, rd
;
4169 page
= extract32(insn
, 31, 1);
4170 /* SignExtend(immhi:immlo) -> offset */
4171 offset
= sextract64(insn
, 5, 19);
4172 offset
= offset
<< 2 | extract32(insn
, 29, 2);
4173 rd
= extract32(insn
, 0, 5);
4177 /* ADRP (page based) */
4182 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
4186 * Add/subtract (immediate)
4188 * 31 30 29 28 23 22 21 10 9 5 4 0
4189 * +--+--+--+-------------+--+-------------+-----+-----+
4190 * |sf|op| S| 1 0 0 0 1 0 |sh| imm12 | Rn | Rd |
4191 * +--+--+--+-------------+--+-------------+-----+-----+
4193 * sf: 0 -> 32bit, 1 -> 64bit
4194 * op: 0 -> add , 1 -> sub
4196 * sh: 1 -> LSL imm by 12
4198 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
4200 int rd
= extract32(insn
, 0, 5);
4201 int rn
= extract32(insn
, 5, 5);
4202 uint64_t imm
= extract32(insn
, 10, 12);
4203 bool shift
= extract32(insn
, 22, 1);
4204 bool setflags
= extract32(insn
, 29, 1);
4205 bool sub_op
= extract32(insn
, 30, 1);
4206 bool is_64bit
= extract32(insn
, 31, 1);
4208 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
4209 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
4210 TCGv_i64 tcg_result
;
4216 tcg_result
= tcg_temp_new_i64();
4219 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
4221 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
4224 TCGv_i64 tcg_imm
= tcg_constant_i64(imm
);
4226 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
4228 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
4233 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4235 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4238 tcg_temp_free_i64(tcg_result
);
4242 * Add/subtract (immediate, with tags)
4244 * 31 30 29 28 23 22 21 16 14 10 9 5 4 0
4245 * +--+--+--+-------------+--+---------+--+-------+-----+-----+
4246 * |sf|op| S| 1 0 0 0 1 1 |o2| uimm6 |o3| uimm4 | Rn | Rd |
4247 * +--+--+--+-------------+--+---------+--+-------+-----+-----+
4249 * op: 0 -> add, 1 -> sub
4251 static void disas_add_sub_imm_with_tags(DisasContext
*s
, uint32_t insn
)
4253 int rd
= extract32(insn
, 0, 5);
4254 int rn
= extract32(insn
, 5, 5);
4255 int uimm4
= extract32(insn
, 10, 4);
4256 int uimm6
= extract32(insn
, 16, 6);
4257 bool sub_op
= extract32(insn
, 30, 1);
4258 TCGv_i64 tcg_rn
, tcg_rd
;
4261 /* Test all of sf=1, S=0, o2=0, o3=0. */
4262 if ((insn
& 0xa040c000u
) != 0x80000000u
||
4263 !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
4264 unallocated_encoding(s
);
4268 imm
= uimm6
<< LOG2_TAG_GRANULE
;
4273 tcg_rn
= cpu_reg_sp(s
, rn
);
4274 tcg_rd
= cpu_reg_sp(s
, rd
);
4277 gen_helper_addsubg(tcg_rd
, cpu_env
, tcg_rn
,
4278 tcg_constant_i32(imm
),
4279 tcg_constant_i32(uimm4
));
4281 tcg_gen_addi_i64(tcg_rd
, tcg_rn
, imm
);
4282 gen_address_with_allocation_tag0(tcg_rd
, tcg_rd
);
4286 /* The input should be a value in the bottom e bits (with higher
4287 * bits zero); returns that value replicated into every element
4288 * of size e in a 64 bit integer.
4290 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
4300 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
4301 static inline uint64_t bitmask64(unsigned int length
)
4303 assert(length
> 0 && length
<= 64);
4304 return ~0ULL >> (64 - length
);
4307 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
4308 * only require the wmask. Returns false if the imms/immr/immn are a reserved
4309 * value (ie should cause a guest UNDEF exception), and true if they are
4310 * valid, in which case the decoded bit pattern is written to result.
4312 bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
4313 unsigned int imms
, unsigned int immr
)
4316 unsigned e
, levels
, s
, r
;
4319 assert(immn
< 2 && imms
< 64 && immr
< 64);
4321 /* The bit patterns we create here are 64 bit patterns which
4322 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
4323 * 64 bits each. Each element contains the same value: a run
4324 * of between 1 and e-1 non-zero bits, rotated within the
4325 * element by between 0 and e-1 bits.
4327 * The element size and run length are encoded into immn (1 bit)
4328 * and imms (6 bits) as follows:
4329 * 64 bit elements: immn = 1, imms = <length of run - 1>
4330 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
4331 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
4332 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
4333 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
4334 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
4335 * Notice that immn = 0, imms = 11111x is the only combination
4336 * not covered by one of the above options; this is reserved.
4337 * Further, <length of run - 1> all-ones is a reserved pattern.
4339 * In all cases the rotation is by immr % e (and immr is 6 bits).
4342 /* First determine the element size */
4343 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
4345 /* This is the immn == 0, imms == 0x11111x case */
4355 /* <length of run - 1> mustn't be all-ones. */
4359 /* Create the value of one element: s+1 set bits rotated
4360 * by r within the element (which is e bits wide)...
4362 mask
= bitmask64(s
+ 1);
4364 mask
= (mask
>> r
) | (mask
<< (e
- r
));
4365 mask
&= bitmask64(e
);
4367 /* ...then replicate the element over the whole 64 bit value */
4368 mask
= bitfield_replicate(mask
, e
);
4373 /* Logical (immediate)
4374 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
4375 * +----+-----+-------------+---+------+------+------+------+
4376 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
4377 * +----+-----+-------------+---+------+------+------+------+
4379 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
4381 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
4382 TCGv_i64 tcg_rd
, tcg_rn
;
4384 bool is_and
= false;
4386 sf
= extract32(insn
, 31, 1);
4387 opc
= extract32(insn
, 29, 2);
4388 is_n
= extract32(insn
, 22, 1);
4389 immr
= extract32(insn
, 16, 6);
4390 imms
= extract32(insn
, 10, 6);
4391 rn
= extract32(insn
, 5, 5);
4392 rd
= extract32(insn
, 0, 5);
4395 unallocated_encoding(s
);
4399 if (opc
== 0x3) { /* ANDS */
4400 tcg_rd
= cpu_reg(s
, rd
);
4402 tcg_rd
= cpu_reg_sp(s
, rd
);
4404 tcg_rn
= cpu_reg(s
, rn
);
4406 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
4407 /* some immediate field values are reserved */
4408 unallocated_encoding(s
);
4413 wmask
&= 0xffffffff;
4417 case 0x3: /* ANDS */
4419 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
4423 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
4426 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
4429 assert(FALSE
); /* must handle all above */
4433 if (!sf
&& !is_and
) {
4434 /* zero extend final result; we know we can skip this for AND
4435 * since the immediate had the high 32 bits clear.
4437 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4440 if (opc
== 3) { /* ANDS */
4441 gen_logic_CC(sf
, tcg_rd
);
4446 * Move wide (immediate)
4448 * 31 30 29 28 23 22 21 20 5 4 0
4449 * +--+-----+-------------+-----+----------------+------+
4450 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
4451 * +--+-----+-------------+-----+----------------+------+
4453 * sf: 0 -> 32 bit, 1 -> 64 bit
4454 * opc: 00 -> N, 10 -> Z, 11 -> K
4455 * hw: shift/16 (0,16, and sf only 32, 48)
4457 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
4459 int rd
= extract32(insn
, 0, 5);
4460 uint64_t imm
= extract32(insn
, 5, 16);
4461 int sf
= extract32(insn
, 31, 1);
4462 int opc
= extract32(insn
, 29, 2);
4463 int pos
= extract32(insn
, 21, 2) << 4;
4464 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4466 if (!sf
&& (pos
>= 32)) {
4467 unallocated_encoding(s
);
4481 tcg_gen_movi_i64(tcg_rd
, imm
);
4484 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_constant_i64(imm
), pos
, 16);
4486 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4490 unallocated_encoding(s
);
4496 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
4497 * +----+-----+-------------+---+------+------+------+------+
4498 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
4499 * +----+-----+-------------+---+------+------+------+------+
4501 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
4503 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
4504 TCGv_i64 tcg_rd
, tcg_tmp
;
4506 sf
= extract32(insn
, 31, 1);
4507 opc
= extract32(insn
, 29, 2);
4508 n
= extract32(insn
, 22, 1);
4509 ri
= extract32(insn
, 16, 6);
4510 si
= extract32(insn
, 10, 6);
4511 rn
= extract32(insn
, 5, 5);
4512 rd
= extract32(insn
, 0, 5);
4513 bitsize
= sf
? 64 : 32;
4515 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
4516 unallocated_encoding(s
);
4520 tcg_rd
= cpu_reg(s
, rd
);
4522 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
4523 to be smaller than bitsize, we'll never reference data outside the
4524 low 32-bits anyway. */
4525 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
4527 /* Recognize simple(r) extractions. */
4529 /* Wd<s-r:0> = Wn<s:r> */
4530 len
= (si
- ri
) + 1;
4531 if (opc
== 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
4532 tcg_gen_sextract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
4534 } else if (opc
== 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
4535 tcg_gen_extract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
4538 /* opc == 1, BFXIL fall through to deposit */
4539 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
4542 /* Handle the ri > si case with a deposit
4543 * Wd<32+s-r,32-r> = Wn<s:0>
4546 pos
= (bitsize
- ri
) & (bitsize
- 1);
4549 if (opc
== 0 && len
< ri
) {
4550 /* SBFM: sign extend the destination field from len to fill
4551 the balance of the word. Let the deposit below insert all
4552 of those sign bits. */
4553 tcg_gen_sextract_i64(tcg_tmp
, tcg_tmp
, 0, len
);
4557 if (opc
== 1) { /* BFM, BFXIL */
4558 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
4560 /* SBFM or UBFM: We start with zero, and we haven't modified
4561 any bits outside bitsize, therefore the zero-extension
4562 below is unneeded. */
4563 tcg_gen_deposit_z_i64(tcg_rd
, tcg_tmp
, pos
, len
);
4568 if (!sf
) { /* zero extend final result */
4569 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4574 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
4575 * +----+------+-------------+---+----+------+--------+------+------+
4576 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
4577 * +----+------+-------------+---+----+------+--------+------+------+
4579 static void disas_extract(DisasContext
*s
, uint32_t insn
)
4581 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
4583 sf
= extract32(insn
, 31, 1);
4584 n
= extract32(insn
, 22, 1);
4585 rm
= extract32(insn
, 16, 5);
4586 imm
= extract32(insn
, 10, 6);
4587 rn
= extract32(insn
, 5, 5);
4588 rd
= extract32(insn
, 0, 5);
4589 op21
= extract32(insn
, 29, 2);
4590 op0
= extract32(insn
, 21, 1);
4591 bitsize
= sf
? 64 : 32;
4593 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
4594 unallocated_encoding(s
);
4596 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
4598 tcg_rd
= cpu_reg(s
, rd
);
4600 if (unlikely(imm
== 0)) {
4601 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
4602 * so an extract from bit 0 is a special case.
4605 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
4607 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
4610 tcg_rm
= cpu_reg(s
, rm
);
4611 tcg_rn
= cpu_reg(s
, rn
);
4614 /* Specialization to ROR happens in EXTRACT2. */
4615 tcg_gen_extract2_i64(tcg_rd
, tcg_rm
, tcg_rn
, imm
);
4617 TCGv_i32 t0
= tcg_temp_new_i32();
4619 tcg_gen_extrl_i64_i32(t0
, tcg_rm
);
4621 tcg_gen_rotri_i32(t0
, t0
, imm
);
4623 TCGv_i32 t1
= tcg_temp_new_i32();
4624 tcg_gen_extrl_i64_i32(t1
, tcg_rn
);
4625 tcg_gen_extract2_i32(t0
, t0
, t1
, imm
);
4626 tcg_temp_free_i32(t1
);
4628 tcg_gen_extu_i32_i64(tcg_rd
, t0
);
4629 tcg_temp_free_i32(t0
);
4635 /* Data processing - immediate */
4636 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
4638 switch (extract32(insn
, 23, 6)) {
4639 case 0x20: case 0x21: /* PC-rel. addressing */
4640 disas_pc_rel_adr(s
, insn
);
4642 case 0x22: /* Add/subtract (immediate) */
4643 disas_add_sub_imm(s
, insn
);
4645 case 0x23: /* Add/subtract (immediate, with tags) */
4646 disas_add_sub_imm_with_tags(s
, insn
);
4648 case 0x24: /* Logical (immediate) */
4649 disas_logic_imm(s
, insn
);
4651 case 0x25: /* Move wide (immediate) */
4652 disas_movw_imm(s
, insn
);
4654 case 0x26: /* Bitfield */
4655 disas_bitfield(s
, insn
);
4657 case 0x27: /* Extract */
4658 disas_extract(s
, insn
);
4661 unallocated_encoding(s
);
4666 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
4667 * Note that it is the caller's responsibility to ensure that the
4668 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
4669 * mandated semantics for out of range shifts.
4671 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4672 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
4674 switch (shift_type
) {
4675 case A64_SHIFT_TYPE_LSL
:
4676 tcg_gen_shl_i64(dst
, src
, shift_amount
);
4678 case A64_SHIFT_TYPE_LSR
:
4679 tcg_gen_shr_i64(dst
, src
, shift_amount
);
4681 case A64_SHIFT_TYPE_ASR
:
4683 tcg_gen_ext32s_i64(dst
, src
);
4685 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
4687 case A64_SHIFT_TYPE_ROR
:
4689 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
4692 t0
= tcg_temp_new_i32();
4693 t1
= tcg_temp_new_i32();
4694 tcg_gen_extrl_i64_i32(t0
, src
);
4695 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
4696 tcg_gen_rotr_i32(t0
, t0
, t1
);
4697 tcg_gen_extu_i32_i64(dst
, t0
);
4698 tcg_temp_free_i32(t0
);
4699 tcg_temp_free_i32(t1
);
4703 assert(FALSE
); /* all shift types should be handled */
4707 if (!sf
) { /* zero extend final result */
4708 tcg_gen_ext32u_i64(dst
, dst
);
4712 /* Shift a TCGv src by immediate, put result in dst.
4713 * The shift amount must be in range (this should always be true as the
4714 * relevant instructions will UNDEF on bad shift immediates).
4716 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4717 enum a64_shift_type shift_type
, unsigned int shift_i
)
4719 assert(shift_i
< (sf
? 64 : 32));
4722 tcg_gen_mov_i64(dst
, src
);
4724 shift_reg(dst
, src
, sf
, shift_type
, tcg_constant_i64(shift_i
));
4728 /* Logical (shifted register)
4729 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4730 * +----+-----+-----------+-------+---+------+--------+------+------+
4731 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
4732 * +----+-----+-----------+-------+---+------+--------+------+------+
4734 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
4736 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
4737 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
4739 sf
= extract32(insn
, 31, 1);
4740 opc
= extract32(insn
, 29, 2);
4741 shift_type
= extract32(insn
, 22, 2);
4742 invert
= extract32(insn
, 21, 1);
4743 rm
= extract32(insn
, 16, 5);
4744 shift_amount
= extract32(insn
, 10, 6);
4745 rn
= extract32(insn
, 5, 5);
4746 rd
= extract32(insn
, 0, 5);
4748 if (!sf
&& (shift_amount
& (1 << 5))) {
4749 unallocated_encoding(s
);
4753 tcg_rd
= cpu_reg(s
, rd
);
4755 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
4756 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
4757 * register-register MOV and MVN, so it is worth special casing.
4759 tcg_rm
= cpu_reg(s
, rm
);
4761 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
4763 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4767 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
4769 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
4775 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4778 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
4781 tcg_rn
= cpu_reg(s
, rn
);
4783 switch (opc
| (invert
<< 2)) {
4786 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4789 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4792 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4796 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4799 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4802 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4810 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4814 gen_logic_CC(sf
, tcg_rd
);
4819 * Add/subtract (extended register)
4821 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
4822 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4823 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
4824 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4826 * sf: 0 -> 32bit, 1 -> 64bit
4827 * op: 0 -> add , 1 -> sub
4830 * option: extension type (see DecodeRegExtend)
4831 * imm3: optional shift to Rm
4833 * Rd = Rn + LSL(extend(Rm), amount)
4835 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
4837 int rd
= extract32(insn
, 0, 5);
4838 int rn
= extract32(insn
, 5, 5);
4839 int imm3
= extract32(insn
, 10, 3);
4840 int option
= extract32(insn
, 13, 3);
4841 int rm
= extract32(insn
, 16, 5);
4842 int opt
= extract32(insn
, 22, 2);
4843 bool setflags
= extract32(insn
, 29, 1);
4844 bool sub_op
= extract32(insn
, 30, 1);
4845 bool sf
= extract32(insn
, 31, 1);
4847 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
4849 TCGv_i64 tcg_result
;
4851 if (imm3
> 4 || opt
!= 0) {
4852 unallocated_encoding(s
);
4856 /* non-flag setting ops may use SP */
4858 tcg_rd
= cpu_reg_sp(s
, rd
);
4860 tcg_rd
= cpu_reg(s
, rd
);
4862 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
4864 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4865 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
4867 tcg_result
= tcg_temp_new_i64();
4871 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4873 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4877 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4879 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4884 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4886 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4889 tcg_temp_free_i64(tcg_result
);
4893 * Add/subtract (shifted register)
4895 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4896 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4897 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
4898 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4900 * sf: 0 -> 32bit, 1 -> 64bit
4901 * op: 0 -> add , 1 -> sub
4903 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
4904 * imm6: Shift amount to apply to Rm before the add/sub
4906 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
4908 int rd
= extract32(insn
, 0, 5);
4909 int rn
= extract32(insn
, 5, 5);
4910 int imm6
= extract32(insn
, 10, 6);
4911 int rm
= extract32(insn
, 16, 5);
4912 int shift_type
= extract32(insn
, 22, 2);
4913 bool setflags
= extract32(insn
, 29, 1);
4914 bool sub_op
= extract32(insn
, 30, 1);
4915 bool sf
= extract32(insn
, 31, 1);
4917 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4918 TCGv_i64 tcg_rn
, tcg_rm
;
4919 TCGv_i64 tcg_result
;
4921 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
4922 unallocated_encoding(s
);
4926 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4927 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4929 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
4931 tcg_result
= tcg_temp_new_i64();
4935 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4937 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4941 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4943 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4948 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4950 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4953 tcg_temp_free_i64(tcg_result
);
4956 /* Data-processing (3 source)
4958 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
4959 * +--+------+-----------+------+------+----+------+------+------+
4960 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
4961 * +--+------+-----------+------+------+----+------+------+------+
4963 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
4965 int rd
= extract32(insn
, 0, 5);
4966 int rn
= extract32(insn
, 5, 5);
4967 int ra
= extract32(insn
, 10, 5);
4968 int rm
= extract32(insn
, 16, 5);
4969 int op_id
= (extract32(insn
, 29, 3) << 4) |
4970 (extract32(insn
, 21, 3) << 1) |
4971 extract32(insn
, 15, 1);
4972 bool sf
= extract32(insn
, 31, 1);
4973 bool is_sub
= extract32(op_id
, 0, 1);
4974 bool is_high
= extract32(op_id
, 2, 1);
4975 bool is_signed
= false;
4980 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
4982 case 0x42: /* SMADDL */
4983 case 0x43: /* SMSUBL */
4984 case 0x44: /* SMULH */
4987 case 0x0: /* MADD (32bit) */
4988 case 0x1: /* MSUB (32bit) */
4989 case 0x40: /* MADD (64bit) */
4990 case 0x41: /* MSUB (64bit) */
4991 case 0x4a: /* UMADDL */
4992 case 0x4b: /* UMSUBL */
4993 case 0x4c: /* UMULH */
4996 unallocated_encoding(s
);
5001 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
5002 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5003 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
5004 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
5007 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
5009 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
5012 tcg_temp_free_i64(low_bits
);
5016 tcg_op1
= tcg_temp_new_i64();
5017 tcg_op2
= tcg_temp_new_i64();
5018 tcg_tmp
= tcg_temp_new_i64();
5021 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
5022 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
5025 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
5026 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
5028 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
5029 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
5033 if (ra
== 31 && !is_sub
) {
5034 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
5035 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
5037 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
5039 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
5041 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
5046 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
5049 tcg_temp_free_i64(tcg_op1
);
5050 tcg_temp_free_i64(tcg_op2
);
5051 tcg_temp_free_i64(tcg_tmp
);
5054 /* Add/subtract (with carry)
5055 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
5056 * +--+--+--+------------------------+------+-------------+------+-----+
5057 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | 0 0 0 0 0 0 | Rn | Rd |
5058 * +--+--+--+------------------------+------+-------------+------+-----+
5061 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
5063 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
5064 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
5066 sf
= extract32(insn
, 31, 1);
5067 op
= extract32(insn
, 30, 1);
5068 setflags
= extract32(insn
, 29, 1);
5069 rm
= extract32(insn
, 16, 5);
5070 rn
= extract32(insn
, 5, 5);
5071 rd
= extract32(insn
, 0, 5);
5073 tcg_rd
= cpu_reg(s
, rd
);
5074 tcg_rn
= cpu_reg(s
, rn
);
5077 tcg_y
= new_tmp_a64(s
);
5078 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
5080 tcg_y
= cpu_reg(s
, rm
);
5084 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
5086 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
5091 * Rotate right into flags
5092 * 31 30 29 21 15 10 5 4 0
5093 * +--+--+--+-----------------+--------+-----------+------+--+------+
5094 * |sf|op| S| 1 1 0 1 0 0 0 0 | imm6 | 0 0 0 0 1 | Rn |o2| mask |
5095 * +--+--+--+-----------------+--------+-----------+------+--+------+
5097 static void disas_rotate_right_into_flags(DisasContext
*s
, uint32_t insn
)
5099 int mask
= extract32(insn
, 0, 4);
5100 int o2
= extract32(insn
, 4, 1);
5101 int rn
= extract32(insn
, 5, 5);
5102 int imm6
= extract32(insn
, 15, 6);
5103 int sf_op_s
= extract32(insn
, 29, 3);
5107 if (sf_op_s
!= 5 || o2
!= 0 || !dc_isar_feature(aa64_condm_4
, s
)) {
5108 unallocated_encoding(s
);
5112 tcg_rn
= read_cpu_reg(s
, rn
, 1);
5113 tcg_gen_rotri_i64(tcg_rn
, tcg_rn
, imm6
);
5115 nzcv
= tcg_temp_new_i32();
5116 tcg_gen_extrl_i64_i32(nzcv
, tcg_rn
);
5118 if (mask
& 8) { /* N */
5119 tcg_gen_shli_i32(cpu_NF
, nzcv
, 31 - 3);
5121 if (mask
& 4) { /* Z */
5122 tcg_gen_not_i32(cpu_ZF
, nzcv
);
5123 tcg_gen_andi_i32(cpu_ZF
, cpu_ZF
, 4);
5125 if (mask
& 2) { /* C */
5126 tcg_gen_extract_i32(cpu_CF
, nzcv
, 1, 1);
5128 if (mask
& 1) { /* V */
5129 tcg_gen_shli_i32(cpu_VF
, nzcv
, 31 - 0);
5132 tcg_temp_free_i32(nzcv
);
5136 * Evaluate into flags
5137 * 31 30 29 21 15 14 10 5 4 0
5138 * +--+--+--+-----------------+---------+----+---------+------+--+------+
5139 * |sf|op| S| 1 1 0 1 0 0 0 0 | opcode2 | sz | 0 0 1 0 | Rn |o3| mask |
5140 * +--+--+--+-----------------+---------+----+---------+------+--+------+
5142 static void disas_evaluate_into_flags(DisasContext
*s
, uint32_t insn
)
5144 int o3_mask
= extract32(insn
, 0, 5);
5145 int rn
= extract32(insn
, 5, 5);
5146 int o2
= extract32(insn
, 15, 6);
5147 int sz
= extract32(insn
, 14, 1);
5148 int sf_op_s
= extract32(insn
, 29, 3);
5152 if (sf_op_s
!= 1 || o2
!= 0 || o3_mask
!= 0xd ||
5153 !dc_isar_feature(aa64_condm_4
, s
)) {
5154 unallocated_encoding(s
);
5157 shift
= sz
? 16 : 24; /* SETF16 or SETF8 */
5159 tmp
= tcg_temp_new_i32();
5160 tcg_gen_extrl_i64_i32(tmp
, cpu_reg(s
, rn
));
5161 tcg_gen_shli_i32(cpu_NF
, tmp
, shift
);
5162 tcg_gen_shli_i32(cpu_VF
, tmp
, shift
- 1);
5163 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
5164 tcg_gen_xor_i32(cpu_VF
, cpu_VF
, cpu_NF
);
5165 tcg_temp_free_i32(tmp
);
5168 /* Conditional compare (immediate / register)
5169 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
5170 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
5171 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
5172 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
5175 static void disas_cc(DisasContext
*s
, uint32_t insn
)
5177 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
5178 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
5179 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
5182 if (!extract32(insn
, 29, 1)) {
5183 unallocated_encoding(s
);
5186 if (insn
& (1 << 10 | 1 << 4)) {
5187 unallocated_encoding(s
);
5190 sf
= extract32(insn
, 31, 1);
5191 op
= extract32(insn
, 30, 1);
5192 is_imm
= extract32(insn
, 11, 1);
5193 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
5194 cond
= extract32(insn
, 12, 4);
5195 rn
= extract32(insn
, 5, 5);
5196 nzcv
= extract32(insn
, 0, 4);
5198 /* Set T0 = !COND. */
5199 tcg_t0
= tcg_temp_new_i32();
5200 arm_test_cc(&c
, cond
);
5201 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
5204 /* Load the arguments for the new comparison. */
5206 tcg_y
= new_tmp_a64(s
);
5207 tcg_gen_movi_i64(tcg_y
, y
);
5209 tcg_y
= cpu_reg(s
, y
);
5211 tcg_rn
= cpu_reg(s
, rn
);
5213 /* Set the flags for the new comparison. */
5214 tcg_tmp
= tcg_temp_new_i64();
5216 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
5218 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
5220 tcg_temp_free_i64(tcg_tmp
);
5222 /* If COND was false, force the flags to #nzcv. Compute two masks
5223 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
5224 * For tcg hosts that support ANDC, we can make do with just T1.
5225 * In either case, allow the tcg optimizer to delete any unused mask.
5227 tcg_t1
= tcg_temp_new_i32();
5228 tcg_t2
= tcg_temp_new_i32();
5229 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
5230 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
5232 if (nzcv
& 8) { /* N */
5233 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
5235 if (TCG_TARGET_HAS_andc_i32
) {
5236 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
5238 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
5241 if (nzcv
& 4) { /* Z */
5242 if (TCG_TARGET_HAS_andc_i32
) {
5243 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
5245 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
5248 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
5250 if (nzcv
& 2) { /* C */
5251 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
5253 if (TCG_TARGET_HAS_andc_i32
) {
5254 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
5256 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
5259 if (nzcv
& 1) { /* V */
5260 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
5262 if (TCG_TARGET_HAS_andc_i32
) {
5263 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
5265 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
5268 tcg_temp_free_i32(tcg_t0
);
5269 tcg_temp_free_i32(tcg_t1
);
5270 tcg_temp_free_i32(tcg_t2
);
5273 /* Conditional select
5274 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
5275 * +----+----+---+-----------------+------+------+-----+------+------+
5276 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
5277 * +----+----+---+-----------------+------+------+-----+------+------+
5279 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
5281 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
5282 TCGv_i64 tcg_rd
, zero
;
5285 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
5286 /* S == 1 or op2<1> == 1 */
5287 unallocated_encoding(s
);
5290 sf
= extract32(insn
, 31, 1);
5291 else_inv
= extract32(insn
, 30, 1);
5292 rm
= extract32(insn
, 16, 5);
5293 cond
= extract32(insn
, 12, 4);
5294 else_inc
= extract32(insn
, 10, 1);
5295 rn
= extract32(insn
, 5, 5);
5296 rd
= extract32(insn
, 0, 5);
5298 tcg_rd
= cpu_reg(s
, rd
);
5300 a64_test_cc(&c
, cond
);
5301 zero
= tcg_constant_i64(0);
5303 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
5305 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
5307 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
5310 TCGv_i64 t_true
= cpu_reg(s
, rn
);
5311 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
5312 if (else_inv
&& else_inc
) {
5313 tcg_gen_neg_i64(t_false
, t_false
);
5314 } else if (else_inv
) {
5315 tcg_gen_not_i64(t_false
, t_false
);
5316 } else if (else_inc
) {
5317 tcg_gen_addi_i64(t_false
, t_false
, 1);
5319 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
5325 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5329 static void handle_clz(DisasContext
*s
, unsigned int sf
,
5330 unsigned int rn
, unsigned int rd
)
5332 TCGv_i64 tcg_rd
, tcg_rn
;
5333 tcg_rd
= cpu_reg(s
, rd
);
5334 tcg_rn
= cpu_reg(s
, rn
);
5337 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
5339 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
5340 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
5341 tcg_gen_clzi_i32(tcg_tmp32
, tcg_tmp32
, 32);
5342 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
5343 tcg_temp_free_i32(tcg_tmp32
);
5347 static void handle_cls(DisasContext
*s
, unsigned int sf
,
5348 unsigned int rn
, unsigned int rd
)
5350 TCGv_i64 tcg_rd
, tcg_rn
;
5351 tcg_rd
= cpu_reg(s
, rd
);
5352 tcg_rn
= cpu_reg(s
, rn
);
5355 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
5357 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
5358 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
5359 tcg_gen_clrsb_i32(tcg_tmp32
, tcg_tmp32
);
5360 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
5361 tcg_temp_free_i32(tcg_tmp32
);
5365 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
5366 unsigned int rn
, unsigned int rd
)
5368 TCGv_i64 tcg_rd
, tcg_rn
;
5369 tcg_rd
= cpu_reg(s
, rd
);
5370 tcg_rn
= cpu_reg(s
, rn
);
5373 gen_helper_rbit64(tcg_rd
, tcg_rn
);
5375 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
5376 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
5377 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
5378 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
5379 tcg_temp_free_i32(tcg_tmp32
);
5383 /* REV with sf==1, opcode==3 ("REV64") */
5384 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
5385 unsigned int rn
, unsigned int rd
)
5388 unallocated_encoding(s
);
5391 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
5394 /* REV with sf==0, opcode==2
5395 * REV32 (sf==1, opcode==2)
5397 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
5398 unsigned int rn
, unsigned int rd
)
5400 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5401 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
5404 tcg_gen_bswap64_i64(tcg_rd
, tcg_rn
);
5405 tcg_gen_rotri_i64(tcg_rd
, tcg_rd
, 32);
5407 tcg_gen_bswap32_i64(tcg_rd
, tcg_rn
, TCG_BSWAP_OZ
);
5411 /* REV16 (opcode==1) */
5412 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
5413 unsigned int rn
, unsigned int rd
)
5415 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5416 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5417 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
5418 TCGv_i64 mask
= tcg_constant_i64(sf
? 0x00ff00ff00ff00ffull
: 0x00ff00ff);
5420 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 8);
5421 tcg_gen_and_i64(tcg_rd
, tcg_rn
, mask
);
5422 tcg_gen_and_i64(tcg_tmp
, tcg_tmp
, mask
);
5423 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 8);
5424 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
5426 tcg_temp_free_i64(tcg_tmp
);
5429 /* Data-processing (1 source)
5430 * 31 30 29 28 21 20 16 15 10 9 5 4 0
5431 * +----+---+---+-----------------+---------+--------+------+------+
5432 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
5433 * +----+---+---+-----------------+---------+--------+------+------+
5435 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
5437 unsigned int sf
, opcode
, opcode2
, rn
, rd
;
5440 if (extract32(insn
, 29, 1)) {
5441 unallocated_encoding(s
);
5445 sf
= extract32(insn
, 31, 1);
5446 opcode
= extract32(insn
, 10, 6);
5447 opcode2
= extract32(insn
, 16, 5);
5448 rn
= extract32(insn
, 5, 5);
5449 rd
= extract32(insn
, 0, 5);
5451 #define MAP(SF, O2, O1) ((SF) | (O1 << 1) | (O2 << 7))
5453 switch (MAP(sf
, opcode2
, opcode
)) {
5454 case MAP(0, 0x00, 0x00): /* RBIT */
5455 case MAP(1, 0x00, 0x00):
5456 handle_rbit(s
, sf
, rn
, rd
);
5458 case MAP(0, 0x00, 0x01): /* REV16 */
5459 case MAP(1, 0x00, 0x01):
5460 handle_rev16(s
, sf
, rn
, rd
);
5462 case MAP(0, 0x00, 0x02): /* REV/REV32 */
5463 case MAP(1, 0x00, 0x02):
5464 handle_rev32(s
, sf
, rn
, rd
);
5466 case MAP(1, 0x00, 0x03): /* REV64 */
5467 handle_rev64(s
, sf
, rn
, rd
);
5469 case MAP(0, 0x00, 0x04): /* CLZ */
5470 case MAP(1, 0x00, 0x04):
5471 handle_clz(s
, sf
, rn
, rd
);
5473 case MAP(0, 0x00, 0x05): /* CLS */
5474 case MAP(1, 0x00, 0x05):
5475 handle_cls(s
, sf
, rn
, rd
);
5477 case MAP(1, 0x01, 0x00): /* PACIA */
5478 if (s
->pauth_active
) {
5479 tcg_rd
= cpu_reg(s
, rd
);
5480 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5481 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5482 goto do_unallocated
;
5485 case MAP(1, 0x01, 0x01): /* PACIB */
5486 if (s
->pauth_active
) {
5487 tcg_rd
= cpu_reg(s
, rd
);
5488 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5489 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5490 goto do_unallocated
;
5493 case MAP(1, 0x01, 0x02): /* PACDA */
5494 if (s
->pauth_active
) {
5495 tcg_rd
= cpu_reg(s
, rd
);
5496 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5497 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5498 goto do_unallocated
;
5501 case MAP(1, 0x01, 0x03): /* PACDB */
5502 if (s
->pauth_active
) {
5503 tcg_rd
= cpu_reg(s
, rd
);
5504 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5505 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5506 goto do_unallocated
;
5509 case MAP(1, 0x01, 0x04): /* AUTIA */
5510 if (s
->pauth_active
) {
5511 tcg_rd
= cpu_reg(s
, rd
);
5512 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5513 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5514 goto do_unallocated
;
5517 case MAP(1, 0x01, 0x05): /* AUTIB */
5518 if (s
->pauth_active
) {
5519 tcg_rd
= cpu_reg(s
, rd
);
5520 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5521 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5522 goto do_unallocated
;
5525 case MAP(1, 0x01, 0x06): /* AUTDA */
5526 if (s
->pauth_active
) {
5527 tcg_rd
= cpu_reg(s
, rd
);
5528 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5529 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5530 goto do_unallocated
;
5533 case MAP(1, 0x01, 0x07): /* AUTDB */
5534 if (s
->pauth_active
) {
5535 tcg_rd
= cpu_reg(s
, rd
);
5536 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5537 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5538 goto do_unallocated
;
5541 case MAP(1, 0x01, 0x08): /* PACIZA */
5542 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5543 goto do_unallocated
;
5544 } else if (s
->pauth_active
) {
5545 tcg_rd
= cpu_reg(s
, rd
);
5546 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5549 case MAP(1, 0x01, 0x09): /* PACIZB */
5550 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5551 goto do_unallocated
;
5552 } else if (s
->pauth_active
) {
5553 tcg_rd
= cpu_reg(s
, rd
);
5554 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5557 case MAP(1, 0x01, 0x0a): /* PACDZA */
5558 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5559 goto do_unallocated
;
5560 } else if (s
->pauth_active
) {
5561 tcg_rd
= cpu_reg(s
, rd
);
5562 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5565 case MAP(1, 0x01, 0x0b): /* PACDZB */
5566 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5567 goto do_unallocated
;
5568 } else if (s
->pauth_active
) {
5569 tcg_rd
= cpu_reg(s
, rd
);
5570 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5573 case MAP(1, 0x01, 0x0c): /* AUTIZA */
5574 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5575 goto do_unallocated
;
5576 } else if (s
->pauth_active
) {
5577 tcg_rd
= cpu_reg(s
, rd
);
5578 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5581 case MAP(1, 0x01, 0x0d): /* AUTIZB */
5582 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5583 goto do_unallocated
;
5584 } else if (s
->pauth_active
) {
5585 tcg_rd
= cpu_reg(s
, rd
);
5586 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5589 case MAP(1, 0x01, 0x0e): /* AUTDZA */
5590 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5591 goto do_unallocated
;
5592 } else if (s
->pauth_active
) {
5593 tcg_rd
= cpu_reg(s
, rd
);
5594 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5597 case MAP(1, 0x01, 0x0f): /* AUTDZB */
5598 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5599 goto do_unallocated
;
5600 } else if (s
->pauth_active
) {
5601 tcg_rd
= cpu_reg(s
, rd
);
5602 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5605 case MAP(1, 0x01, 0x10): /* XPACI */
5606 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5607 goto do_unallocated
;
5608 } else if (s
->pauth_active
) {
5609 tcg_rd
= cpu_reg(s
, rd
);
5610 gen_helper_xpaci(tcg_rd
, cpu_env
, tcg_rd
);
5613 case MAP(1, 0x01, 0x11): /* XPACD */
5614 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5615 goto do_unallocated
;
5616 } else if (s
->pauth_active
) {
5617 tcg_rd
= cpu_reg(s
, rd
);
5618 gen_helper_xpacd(tcg_rd
, cpu_env
, tcg_rd
);
5623 unallocated_encoding(s
);
5630 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
5631 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5633 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
5634 tcg_rd
= cpu_reg(s
, rd
);
5636 if (!sf
&& is_signed
) {
5637 tcg_n
= new_tmp_a64(s
);
5638 tcg_m
= new_tmp_a64(s
);
5639 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
5640 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
5642 tcg_n
= read_cpu_reg(s
, rn
, sf
);
5643 tcg_m
= read_cpu_reg(s
, rm
, sf
);
5647 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
5649 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
5652 if (!sf
) { /* zero extend final result */
5653 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5657 /* LSLV, LSRV, ASRV, RORV */
5658 static void handle_shift_reg(DisasContext
*s
,
5659 enum a64_shift_type shift_type
, unsigned int sf
,
5660 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5662 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
5663 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5664 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
5666 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
5667 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
5668 tcg_temp_free_i64(tcg_shift
);
5671 /* CRC32[BHWX], CRC32C[BHWX] */
5672 static void handle_crc32(DisasContext
*s
,
5673 unsigned int sf
, unsigned int sz
, bool crc32c
,
5674 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5676 TCGv_i64 tcg_acc
, tcg_val
;
5679 if (!dc_isar_feature(aa64_crc32
, s
)
5680 || (sf
== 1 && sz
!= 3)
5681 || (sf
== 0 && sz
== 3)) {
5682 unallocated_encoding(s
);
5687 tcg_val
= cpu_reg(s
, rm
);
5701 g_assert_not_reached();
5703 tcg_val
= new_tmp_a64(s
);
5704 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
5707 tcg_acc
= cpu_reg(s
, rn
);
5708 tcg_bytes
= tcg_constant_i32(1 << sz
);
5711 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5713 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5717 /* Data-processing (2 source)
5718 * 31 30 29 28 21 20 16 15 10 9 5 4 0
5719 * +----+---+---+-----------------+------+--------+------+------+
5720 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
5721 * +----+---+---+-----------------+------+--------+------+------+
5723 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
5725 unsigned int sf
, rm
, opcode
, rn
, rd
, setflag
;
5726 sf
= extract32(insn
, 31, 1);
5727 setflag
= extract32(insn
, 29, 1);
5728 rm
= extract32(insn
, 16, 5);
5729 opcode
= extract32(insn
, 10, 6);
5730 rn
= extract32(insn
, 5, 5);
5731 rd
= extract32(insn
, 0, 5);
5733 if (setflag
&& opcode
!= 0) {
5734 unallocated_encoding(s
);
5739 case 0: /* SUBP(S) */
5740 if (sf
== 0 || !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
5741 goto do_unallocated
;
5743 TCGv_i64 tcg_n
, tcg_m
, tcg_d
;
5745 tcg_n
= read_cpu_reg_sp(s
, rn
, true);
5746 tcg_m
= read_cpu_reg_sp(s
, rm
, true);
5747 tcg_gen_sextract_i64(tcg_n
, tcg_n
, 0, 56);
5748 tcg_gen_sextract_i64(tcg_m
, tcg_m
, 0, 56);
5749 tcg_d
= cpu_reg(s
, rd
);
5752 gen_sub_CC(true, tcg_d
, tcg_n
, tcg_m
);
5754 tcg_gen_sub_i64(tcg_d
, tcg_n
, tcg_m
);
5759 handle_div(s
, false, sf
, rm
, rn
, rd
);
5762 handle_div(s
, true, sf
, rm
, rn
, rd
);
5765 if (sf
== 0 || !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
5766 goto do_unallocated
;
5769 gen_helper_irg(cpu_reg_sp(s
, rd
), cpu_env
,
5770 cpu_reg_sp(s
, rn
), cpu_reg(s
, rm
));
5772 gen_address_with_allocation_tag0(cpu_reg_sp(s
, rd
),
5777 if (sf
== 0 || !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
5778 goto do_unallocated
;
5780 TCGv_i64 t
= tcg_temp_new_i64();
5782 tcg_gen_extract_i64(t
, cpu_reg_sp(s
, rn
), 56, 4);
5783 tcg_gen_shl_i64(t
, tcg_constant_i64(1), t
);
5784 tcg_gen_or_i64(cpu_reg(s
, rd
), cpu_reg(s
, rm
), t
);
5786 tcg_temp_free_i64(t
);
5790 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
5793 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
5796 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
5799 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
5801 case 12: /* PACGA */
5802 if (sf
== 0 || !dc_isar_feature(aa64_pauth
, s
)) {
5803 goto do_unallocated
;
5805 gen_helper_pacga(cpu_reg(s
, rd
), cpu_env
,
5806 cpu_reg(s
, rn
), cpu_reg_sp(s
, rm
));
5815 case 23: /* CRC32 */
5817 int sz
= extract32(opcode
, 0, 2);
5818 bool crc32c
= extract32(opcode
, 2, 1);
5819 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
5824 unallocated_encoding(s
);
5830 * Data processing - register
5831 * 31 30 29 28 25 21 20 16 10 0
5832 * +--+---+--+---+-------+-----+-------+-------+---------+
5833 * | |op0| |op1| 1 0 1 | op2 | | op3 | |
5834 * +--+---+--+---+-------+-----+-------+-------+---------+
5836 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
5838 int op0
= extract32(insn
, 30, 1);
5839 int op1
= extract32(insn
, 28, 1);
5840 int op2
= extract32(insn
, 21, 4);
5841 int op3
= extract32(insn
, 10, 6);
5846 /* Add/sub (extended register) */
5847 disas_add_sub_ext_reg(s
, insn
);
5849 /* Add/sub (shifted register) */
5850 disas_add_sub_reg(s
, insn
);
5853 /* Logical (shifted register) */
5854 disas_logic_reg(s
, insn
);
5862 case 0x00: /* Add/subtract (with carry) */
5863 disas_adc_sbc(s
, insn
);
5866 case 0x01: /* Rotate right into flags */
5868 disas_rotate_right_into_flags(s
, insn
);
5871 case 0x02: /* Evaluate into flags */
5875 disas_evaluate_into_flags(s
, insn
);
5879 goto do_unallocated
;
5883 case 0x2: /* Conditional compare */
5884 disas_cc(s
, insn
); /* both imm and reg forms */
5887 case 0x4: /* Conditional select */
5888 disas_cond_select(s
, insn
);
5891 case 0x6: /* Data-processing */
5892 if (op0
) { /* (1 source) */
5893 disas_data_proc_1src(s
, insn
);
5894 } else { /* (2 source) */
5895 disas_data_proc_2src(s
, insn
);
5898 case 0x8 ... 0xf: /* (3 source) */
5899 disas_data_proc_3src(s
, insn
);
5904 unallocated_encoding(s
);
5909 static void handle_fp_compare(DisasContext
*s
, int size
,
5910 unsigned int rn
, unsigned int rm
,
5911 bool cmp_with_zero
, bool signal_all_nans
)
5913 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
5914 TCGv_ptr fpst
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
5916 if (size
== MO_64
) {
5917 TCGv_i64 tcg_vn
, tcg_vm
;
5919 tcg_vn
= read_fp_dreg(s
, rn
);
5920 if (cmp_with_zero
) {
5921 tcg_vm
= tcg_constant_i64(0);
5923 tcg_vm
= read_fp_dreg(s
, rm
);
5925 if (signal_all_nans
) {
5926 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5928 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5930 tcg_temp_free_i64(tcg_vn
);
5931 tcg_temp_free_i64(tcg_vm
);
5933 TCGv_i32 tcg_vn
= tcg_temp_new_i32();
5934 TCGv_i32 tcg_vm
= tcg_temp_new_i32();
5936 read_vec_element_i32(s
, tcg_vn
, rn
, 0, size
);
5937 if (cmp_with_zero
) {
5938 tcg_gen_movi_i32(tcg_vm
, 0);
5940 read_vec_element_i32(s
, tcg_vm
, rm
, 0, size
);
5945 if (signal_all_nans
) {
5946 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5948 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5952 if (signal_all_nans
) {
5953 gen_helper_vfp_cmpeh_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5955 gen_helper_vfp_cmph_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5959 g_assert_not_reached();
5962 tcg_temp_free_i32(tcg_vn
);
5963 tcg_temp_free_i32(tcg_vm
);
5966 tcg_temp_free_ptr(fpst
);
5968 gen_set_nzcv(tcg_flags
);
5970 tcg_temp_free_i64(tcg_flags
);
5973 /* Floating point compare
5974 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
5975 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5976 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
5977 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5979 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
5981 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
5984 mos
= extract32(insn
, 29, 3);
5985 type
= extract32(insn
, 22, 2);
5986 rm
= extract32(insn
, 16, 5);
5987 op
= extract32(insn
, 14, 2);
5988 rn
= extract32(insn
, 5, 5);
5989 opc
= extract32(insn
, 3, 2);
5990 op2r
= extract32(insn
, 0, 3);
5992 if (mos
|| op
|| op2r
) {
5993 unallocated_encoding(s
);
6006 if (dc_isar_feature(aa64_fp16
, s
)) {
6011 unallocated_encoding(s
);
6015 if (!fp_access_check(s
)) {
6019 handle_fp_compare(s
, size
, rn
, rm
, opc
& 1, opc
& 2);
6022 /* Floating point conditional compare
6023 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
6024 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
6025 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
6026 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
6028 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
6030 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
6031 TCGLabel
*label_continue
= NULL
;
6034 mos
= extract32(insn
, 29, 3);
6035 type
= extract32(insn
, 22, 2);
6036 rm
= extract32(insn
, 16, 5);
6037 cond
= extract32(insn
, 12, 4);
6038 rn
= extract32(insn
, 5, 5);
6039 op
= extract32(insn
, 4, 1);
6040 nzcv
= extract32(insn
, 0, 4);
6043 unallocated_encoding(s
);
6056 if (dc_isar_feature(aa64_fp16
, s
)) {
6061 unallocated_encoding(s
);
6065 if (!fp_access_check(s
)) {
6069 if (cond
< 0x0e) { /* not always */
6070 TCGLabel
*label_match
= gen_new_label();
6071 label_continue
= gen_new_label();
6072 arm_gen_test_cc(cond
, label_match
);
6074 gen_set_nzcv(tcg_constant_i64(nzcv
<< 28));
6075 tcg_gen_br(label_continue
);
6076 gen_set_label(label_match
);
6079 handle_fp_compare(s
, size
, rn
, rm
, false, op
);
6082 gen_set_label(label_continue
);
6086 /* Floating point conditional select
6087 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6088 * +---+---+---+-----------+------+---+------+------+-----+------+------+
6089 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
6090 * +---+---+---+-----------+------+---+------+------+-----+------+------+
6092 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
6094 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
6095 TCGv_i64 t_true
, t_false
;
6099 mos
= extract32(insn
, 29, 3);
6100 type
= extract32(insn
, 22, 2);
6101 rm
= extract32(insn
, 16, 5);
6102 cond
= extract32(insn
, 12, 4);
6103 rn
= extract32(insn
, 5, 5);
6104 rd
= extract32(insn
, 0, 5);
6107 unallocated_encoding(s
);
6120 if (dc_isar_feature(aa64_fp16
, s
)) {
6125 unallocated_encoding(s
);
6129 if (!fp_access_check(s
)) {
6133 /* Zero extend sreg & hreg inputs to 64 bits now. */
6134 t_true
= tcg_temp_new_i64();
6135 t_false
= tcg_temp_new_i64();
6136 read_vec_element(s
, t_true
, rn
, 0, sz
);
6137 read_vec_element(s
, t_false
, rm
, 0, sz
);
6139 a64_test_cc(&c
, cond
);
6140 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, tcg_constant_i64(0),
6142 tcg_temp_free_i64(t_false
);
6145 /* Note that sregs & hregs write back zeros to the high bits,
6146 and we've already done the zero-extension. */
6147 write_fp_dreg(s
, rd
, t_true
);
6148 tcg_temp_free_i64(t_true
);
6151 /* Floating-point data-processing (1 source) - half precision */
6152 static void handle_fp_1src_half(DisasContext
*s
, int opcode
, int rd
, int rn
)
6154 TCGv_ptr fpst
= NULL
;
6155 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
6156 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6159 case 0x0: /* FMOV */
6160 tcg_gen_mov_i32(tcg_res
, tcg_op
);
6162 case 0x1: /* FABS */
6163 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
6165 case 0x2: /* FNEG */
6166 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
6168 case 0x3: /* FSQRT */
6169 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6170 gen_helper_sqrt_f16(tcg_res
, tcg_op
, fpst
);
6172 case 0x8: /* FRINTN */
6173 case 0x9: /* FRINTP */
6174 case 0xa: /* FRINTM */
6175 case 0xb: /* FRINTZ */
6176 case 0xc: /* FRINTA */
6178 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
6179 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6181 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6182 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
6184 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6185 tcg_temp_free_i32(tcg_rmode
);
6188 case 0xe: /* FRINTX */
6189 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6190 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, fpst
);
6192 case 0xf: /* FRINTI */
6193 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6194 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
6197 g_assert_not_reached();
6200 write_fp_sreg(s
, rd
, tcg_res
);
6203 tcg_temp_free_ptr(fpst
);
6205 tcg_temp_free_i32(tcg_op
);
6206 tcg_temp_free_i32(tcg_res
);
6209 /* Floating-point data-processing (1 source) - single precision */
6210 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
6212 void (*gen_fpst
)(TCGv_i32
, TCGv_i32
, TCGv_ptr
);
6213 TCGv_i32 tcg_op
, tcg_res
;
6217 tcg_op
= read_fp_sreg(s
, rn
);
6218 tcg_res
= tcg_temp_new_i32();
6221 case 0x0: /* FMOV */
6222 tcg_gen_mov_i32(tcg_res
, tcg_op
);
6224 case 0x1: /* FABS */
6225 gen_helper_vfp_abss(tcg_res
, tcg_op
);
6227 case 0x2: /* FNEG */
6228 gen_helper_vfp_negs(tcg_res
, tcg_op
);
6230 case 0x3: /* FSQRT */
6231 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
6233 case 0x6: /* BFCVT */
6234 gen_fpst
= gen_helper_bfcvt
;
6236 case 0x8: /* FRINTN */
6237 case 0x9: /* FRINTP */
6238 case 0xa: /* FRINTM */
6239 case 0xb: /* FRINTZ */
6240 case 0xc: /* FRINTA */
6241 rmode
= arm_rmode_to_sf(opcode
& 7);
6242 gen_fpst
= gen_helper_rints
;
6244 case 0xe: /* FRINTX */
6245 gen_fpst
= gen_helper_rints_exact
;
6247 case 0xf: /* FRINTI */
6248 gen_fpst
= gen_helper_rints
;
6250 case 0x10: /* FRINT32Z */
6251 rmode
= float_round_to_zero
;
6252 gen_fpst
= gen_helper_frint32_s
;
6254 case 0x11: /* FRINT32X */
6255 gen_fpst
= gen_helper_frint32_s
;
6257 case 0x12: /* FRINT64Z */
6258 rmode
= float_round_to_zero
;
6259 gen_fpst
= gen_helper_frint64_s
;
6261 case 0x13: /* FRINT64X */
6262 gen_fpst
= gen_helper_frint64_s
;
6265 g_assert_not_reached();
6268 fpst
= fpstatus_ptr(FPST_FPCR
);
6270 TCGv_i32 tcg_rmode
= tcg_const_i32(rmode
);
6271 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6272 gen_fpst(tcg_res
, tcg_op
, fpst
);
6273 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6274 tcg_temp_free_i32(tcg_rmode
);
6276 gen_fpst(tcg_res
, tcg_op
, fpst
);
6278 tcg_temp_free_ptr(fpst
);
6281 write_fp_sreg(s
, rd
, tcg_res
);
6282 tcg_temp_free_i32(tcg_op
);
6283 tcg_temp_free_i32(tcg_res
);
6286 /* Floating-point data-processing (1 source) - double precision */
6287 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
6289 void (*gen_fpst
)(TCGv_i64
, TCGv_i64
, TCGv_ptr
);
6290 TCGv_i64 tcg_op
, tcg_res
;
6295 case 0x0: /* FMOV */
6296 gen_gvec_fn2(s
, false, rd
, rn
, tcg_gen_gvec_mov
, 0);
6300 tcg_op
= read_fp_dreg(s
, rn
);
6301 tcg_res
= tcg_temp_new_i64();
6304 case 0x1: /* FABS */
6305 gen_helper_vfp_absd(tcg_res
, tcg_op
);
6307 case 0x2: /* FNEG */
6308 gen_helper_vfp_negd(tcg_res
, tcg_op
);
6310 case 0x3: /* FSQRT */
6311 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
6313 case 0x8: /* FRINTN */
6314 case 0x9: /* FRINTP */
6315 case 0xa: /* FRINTM */
6316 case 0xb: /* FRINTZ */
6317 case 0xc: /* FRINTA */
6318 rmode
= arm_rmode_to_sf(opcode
& 7);
6319 gen_fpst
= gen_helper_rintd
;
6321 case 0xe: /* FRINTX */
6322 gen_fpst
= gen_helper_rintd_exact
;
6324 case 0xf: /* FRINTI */
6325 gen_fpst
= gen_helper_rintd
;
6327 case 0x10: /* FRINT32Z */
6328 rmode
= float_round_to_zero
;
6329 gen_fpst
= gen_helper_frint32_d
;
6331 case 0x11: /* FRINT32X */
6332 gen_fpst
= gen_helper_frint32_d
;
6334 case 0x12: /* FRINT64Z */
6335 rmode
= float_round_to_zero
;
6336 gen_fpst
= gen_helper_frint64_d
;
6338 case 0x13: /* FRINT64X */
6339 gen_fpst
= gen_helper_frint64_d
;
6342 g_assert_not_reached();
6345 fpst
= fpstatus_ptr(FPST_FPCR
);
6347 TCGv_i32 tcg_rmode
= tcg_const_i32(rmode
);
6348 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6349 gen_fpst(tcg_res
, tcg_op
, fpst
);
6350 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6351 tcg_temp_free_i32(tcg_rmode
);
6353 gen_fpst(tcg_res
, tcg_op
, fpst
);
6355 tcg_temp_free_ptr(fpst
);
6358 write_fp_dreg(s
, rd
, tcg_res
);
6359 tcg_temp_free_i64(tcg_op
);
6360 tcg_temp_free_i64(tcg_res
);
6363 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
6364 int rd
, int rn
, int dtype
, int ntype
)
6369 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
6371 /* Single to double */
6372 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
6373 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
6374 write_fp_dreg(s
, rd
, tcg_rd
);
6375 tcg_temp_free_i64(tcg_rd
);
6377 /* Single to half */
6378 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
6379 TCGv_i32 ahp
= get_ahp_flag();
6380 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
6382 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
6383 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
6384 write_fp_sreg(s
, rd
, tcg_rd
);
6385 tcg_temp_free_i32(tcg_rd
);
6386 tcg_temp_free_i32(ahp
);
6387 tcg_temp_free_ptr(fpst
);
6389 tcg_temp_free_i32(tcg_rn
);
6394 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
6395 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
6397 /* Double to single */
6398 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
6400 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
6401 TCGv_i32 ahp
= get_ahp_flag();
6402 /* Double to half */
6403 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
6404 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
6405 tcg_temp_free_ptr(fpst
);
6406 tcg_temp_free_i32(ahp
);
6408 write_fp_sreg(s
, rd
, tcg_rd
);
6409 tcg_temp_free_i32(tcg_rd
);
6410 tcg_temp_free_i64(tcg_rn
);
6415 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
6416 TCGv_ptr tcg_fpst
= fpstatus_ptr(FPST_FPCR
);
6417 TCGv_i32 tcg_ahp
= get_ahp_flag();
6418 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
6420 /* Half to single */
6421 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
6422 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
6423 write_fp_sreg(s
, rd
, tcg_rd
);
6424 tcg_temp_free_i32(tcg_rd
);
6426 /* Half to double */
6427 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
6428 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
6429 write_fp_dreg(s
, rd
, tcg_rd
);
6430 tcg_temp_free_i64(tcg_rd
);
6432 tcg_temp_free_i32(tcg_rn
);
6433 tcg_temp_free_ptr(tcg_fpst
);
6434 tcg_temp_free_i32(tcg_ahp
);
6438 g_assert_not_reached();
6442 /* Floating point data-processing (1 source)
6443 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
6444 * +---+---+---+-----------+------+---+--------+-----------+------+------+
6445 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
6446 * +---+---+---+-----------+------+---+--------+-----------+------+------+
6448 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
6450 int mos
= extract32(insn
, 29, 3);
6451 int type
= extract32(insn
, 22, 2);
6452 int opcode
= extract32(insn
, 15, 6);
6453 int rn
= extract32(insn
, 5, 5);
6454 int rd
= extract32(insn
, 0, 5);
6457 goto do_unallocated
;
6461 case 0x4: case 0x5: case 0x7:
6463 /* FCVT between half, single and double precision */
6464 int dtype
= extract32(opcode
, 0, 2);
6465 if (type
== 2 || dtype
== type
) {
6466 goto do_unallocated
;
6468 if (!fp_access_check(s
)) {
6472 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
6476 case 0x10 ... 0x13: /* FRINT{32,64}{X,Z} */
6477 if (type
> 1 || !dc_isar_feature(aa64_frint
, s
)) {
6478 goto do_unallocated
;
6484 /* 32-to-32 and 64-to-64 ops */
6487 if (!fp_access_check(s
)) {
6490 handle_fp_1src_single(s
, opcode
, rd
, rn
);
6493 if (!fp_access_check(s
)) {
6496 handle_fp_1src_double(s
, opcode
, rd
, rn
);
6499 if (!dc_isar_feature(aa64_fp16
, s
)) {
6500 goto do_unallocated
;
6503 if (!fp_access_check(s
)) {
6506 handle_fp_1src_half(s
, opcode
, rd
, rn
);
6509 goto do_unallocated
;
6516 if (!dc_isar_feature(aa64_bf16
, s
)) {
6517 goto do_unallocated
;
6519 if (!fp_access_check(s
)) {
6522 handle_fp_1src_single(s
, opcode
, rd
, rn
);
6525 goto do_unallocated
;
6531 unallocated_encoding(s
);
6536 /* Floating-point data-processing (2 source) - single precision */
6537 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
6538 int rd
, int rn
, int rm
)
6545 tcg_res
= tcg_temp_new_i32();
6546 fpst
= fpstatus_ptr(FPST_FPCR
);
6547 tcg_op1
= read_fp_sreg(s
, rn
);
6548 tcg_op2
= read_fp_sreg(s
, rm
);
6551 case 0x0: /* FMUL */
6552 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6554 case 0x1: /* FDIV */
6555 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6557 case 0x2: /* FADD */
6558 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6560 case 0x3: /* FSUB */
6561 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6563 case 0x4: /* FMAX */
6564 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6566 case 0x5: /* FMIN */
6567 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6569 case 0x6: /* FMAXNM */
6570 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6572 case 0x7: /* FMINNM */
6573 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6575 case 0x8: /* FNMUL */
6576 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6577 gen_helper_vfp_negs(tcg_res
, tcg_res
);
6581 write_fp_sreg(s
, rd
, tcg_res
);
6583 tcg_temp_free_ptr(fpst
);
6584 tcg_temp_free_i32(tcg_op1
);
6585 tcg_temp_free_i32(tcg_op2
);
6586 tcg_temp_free_i32(tcg_res
);
6589 /* Floating-point data-processing (2 source) - double precision */
6590 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
6591 int rd
, int rn
, int rm
)
6598 tcg_res
= tcg_temp_new_i64();
6599 fpst
= fpstatus_ptr(FPST_FPCR
);
6600 tcg_op1
= read_fp_dreg(s
, rn
);
6601 tcg_op2
= read_fp_dreg(s
, rm
);
6604 case 0x0: /* FMUL */
6605 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6607 case 0x1: /* FDIV */
6608 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6610 case 0x2: /* FADD */
6611 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6613 case 0x3: /* FSUB */
6614 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6616 case 0x4: /* FMAX */
6617 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6619 case 0x5: /* FMIN */
6620 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6622 case 0x6: /* FMAXNM */
6623 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6625 case 0x7: /* FMINNM */
6626 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6628 case 0x8: /* FNMUL */
6629 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6630 gen_helper_vfp_negd(tcg_res
, tcg_res
);
6634 write_fp_dreg(s
, rd
, tcg_res
);
6636 tcg_temp_free_ptr(fpst
);
6637 tcg_temp_free_i64(tcg_op1
);
6638 tcg_temp_free_i64(tcg_op2
);
6639 tcg_temp_free_i64(tcg_res
);
6642 /* Floating-point data-processing (2 source) - half precision */
6643 static void handle_fp_2src_half(DisasContext
*s
, int opcode
,
6644 int rd
, int rn
, int rm
)
6651 tcg_res
= tcg_temp_new_i32();
6652 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6653 tcg_op1
= read_fp_hreg(s
, rn
);
6654 tcg_op2
= read_fp_hreg(s
, rm
);
6657 case 0x0: /* FMUL */
6658 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6660 case 0x1: /* FDIV */
6661 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6663 case 0x2: /* FADD */
6664 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6666 case 0x3: /* FSUB */
6667 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6669 case 0x4: /* FMAX */
6670 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6672 case 0x5: /* FMIN */
6673 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6675 case 0x6: /* FMAXNM */
6676 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6678 case 0x7: /* FMINNM */
6679 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6681 case 0x8: /* FNMUL */
6682 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6683 tcg_gen_xori_i32(tcg_res
, tcg_res
, 0x8000);
6686 g_assert_not_reached();
6689 write_fp_sreg(s
, rd
, tcg_res
);
6691 tcg_temp_free_ptr(fpst
);
6692 tcg_temp_free_i32(tcg_op1
);
6693 tcg_temp_free_i32(tcg_op2
);
6694 tcg_temp_free_i32(tcg_res
);
6697 /* Floating point data-processing (2 source)
6698 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6699 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6700 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
6701 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6703 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
6705 int mos
= extract32(insn
, 29, 3);
6706 int type
= extract32(insn
, 22, 2);
6707 int rd
= extract32(insn
, 0, 5);
6708 int rn
= extract32(insn
, 5, 5);
6709 int rm
= extract32(insn
, 16, 5);
6710 int opcode
= extract32(insn
, 12, 4);
6712 if (opcode
> 8 || mos
) {
6713 unallocated_encoding(s
);
6719 if (!fp_access_check(s
)) {
6722 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
6725 if (!fp_access_check(s
)) {
6728 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
6731 if (!dc_isar_feature(aa64_fp16
, s
)) {
6732 unallocated_encoding(s
);
6735 if (!fp_access_check(s
)) {
6738 handle_fp_2src_half(s
, opcode
, rd
, rn
, rm
);
6741 unallocated_encoding(s
);
6745 /* Floating-point data-processing (3 source) - single precision */
6746 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
6747 int rd
, int rn
, int rm
, int ra
)
6749 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
6750 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6751 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
6753 tcg_op1
= read_fp_sreg(s
, rn
);
6754 tcg_op2
= read_fp_sreg(s
, rm
);
6755 tcg_op3
= read_fp_sreg(s
, ra
);
6757 /* These are fused multiply-add, and must be done as one
6758 * floating point operation with no rounding between the
6759 * multiplication and addition steps.
6760 * NB that doing the negations here as separate steps is
6761 * correct : an input NaN should come out with its sign bit
6762 * flipped if it is a negated-input.
6765 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
6769 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
6772 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6774 write_fp_sreg(s
, rd
, tcg_res
);
6776 tcg_temp_free_ptr(fpst
);
6777 tcg_temp_free_i32(tcg_op1
);
6778 tcg_temp_free_i32(tcg_op2
);
6779 tcg_temp_free_i32(tcg_op3
);
6780 tcg_temp_free_i32(tcg_res
);
6783 /* Floating-point data-processing (3 source) - double precision */
6784 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
6785 int rd
, int rn
, int rm
, int ra
)
6787 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
6788 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6789 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
6791 tcg_op1
= read_fp_dreg(s
, rn
);
6792 tcg_op2
= read_fp_dreg(s
, rm
);
6793 tcg_op3
= read_fp_dreg(s
, ra
);
6795 /* These are fused multiply-add, and must be done as one
6796 * floating point operation with no rounding between the
6797 * multiplication and addition steps.
6798 * NB that doing the negations here as separate steps is
6799 * correct : an input NaN should come out with its sign bit
6800 * flipped if it is a negated-input.
6803 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
6807 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
6810 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6812 write_fp_dreg(s
, rd
, tcg_res
);
6814 tcg_temp_free_ptr(fpst
);
6815 tcg_temp_free_i64(tcg_op1
);
6816 tcg_temp_free_i64(tcg_op2
);
6817 tcg_temp_free_i64(tcg_op3
);
6818 tcg_temp_free_i64(tcg_res
);
6821 /* Floating-point data-processing (3 source) - half precision */
6822 static void handle_fp_3src_half(DisasContext
*s
, bool o0
, bool o1
,
6823 int rd
, int rn
, int rm
, int ra
)
6825 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
6826 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6827 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6829 tcg_op1
= read_fp_hreg(s
, rn
);
6830 tcg_op2
= read_fp_hreg(s
, rm
);
6831 tcg_op3
= read_fp_hreg(s
, ra
);
6833 /* These are fused multiply-add, and must be done as one
6834 * floating point operation with no rounding between the
6835 * multiplication and addition steps.
6836 * NB that doing the negations here as separate steps is
6837 * correct : an input NaN should come out with its sign bit
6838 * flipped if it is a negated-input.
6841 tcg_gen_xori_i32(tcg_op3
, tcg_op3
, 0x8000);
6845 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
6848 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6850 write_fp_sreg(s
, rd
, tcg_res
);
6852 tcg_temp_free_ptr(fpst
);
6853 tcg_temp_free_i32(tcg_op1
);
6854 tcg_temp_free_i32(tcg_op2
);
6855 tcg_temp_free_i32(tcg_op3
);
6856 tcg_temp_free_i32(tcg_res
);
6859 /* Floating point data-processing (3 source)
6860 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
6861 * +---+---+---+-----------+------+----+------+----+------+------+------+
6862 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
6863 * +---+---+---+-----------+------+----+------+----+------+------+------+
6865 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
6867 int mos
= extract32(insn
, 29, 3);
6868 int type
= extract32(insn
, 22, 2);
6869 int rd
= extract32(insn
, 0, 5);
6870 int rn
= extract32(insn
, 5, 5);
6871 int ra
= extract32(insn
, 10, 5);
6872 int rm
= extract32(insn
, 16, 5);
6873 bool o0
= extract32(insn
, 15, 1);
6874 bool o1
= extract32(insn
, 21, 1);
6877 unallocated_encoding(s
);
6883 if (!fp_access_check(s
)) {
6886 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6889 if (!fp_access_check(s
)) {
6892 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6895 if (!dc_isar_feature(aa64_fp16
, s
)) {
6896 unallocated_encoding(s
);
6899 if (!fp_access_check(s
)) {
6902 handle_fp_3src_half(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6905 unallocated_encoding(s
);
6909 /* Floating point immediate
6910 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
6911 * +---+---+---+-----------+------+---+------------+-------+------+------+
6912 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
6913 * +---+---+---+-----------+------+---+------------+-------+------+------+
6915 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
6917 int rd
= extract32(insn
, 0, 5);
6918 int imm5
= extract32(insn
, 5, 5);
6919 int imm8
= extract32(insn
, 13, 8);
6920 int type
= extract32(insn
, 22, 2);
6921 int mos
= extract32(insn
, 29, 3);
6926 unallocated_encoding(s
);
6939 if (dc_isar_feature(aa64_fp16
, s
)) {
6944 unallocated_encoding(s
);
6948 if (!fp_access_check(s
)) {
6952 imm
= vfp_expand_imm(sz
, imm8
);
6953 write_fp_dreg(s
, rd
, tcg_constant_i64(imm
));
6956 /* Handle floating point <=> fixed point conversions. Note that we can
6957 * also deal with fp <=> integer conversions as a special case (scale == 64)
6958 * OPTME: consider handling that special case specially or at least skipping
6959 * the call to scalbn in the helpers for zero shifts.
6961 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
6962 bool itof
, int rmode
, int scale
, int sf
, int type
)
6964 bool is_signed
= !(opcode
& 1);
6965 TCGv_ptr tcg_fpstatus
;
6966 TCGv_i32 tcg_shift
, tcg_single
;
6967 TCGv_i64 tcg_double
;
6969 tcg_fpstatus
= fpstatus_ptr(type
== 3 ? FPST_FPCR_F16
: FPST_FPCR
);
6971 tcg_shift
= tcg_constant_i32(64 - scale
);
6974 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
6976 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
6979 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
6981 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
6984 tcg_int
= tcg_extend
;
6988 case 1: /* float64 */
6989 tcg_double
= tcg_temp_new_i64();
6991 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6992 tcg_shift
, tcg_fpstatus
);
6994 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6995 tcg_shift
, tcg_fpstatus
);
6997 write_fp_dreg(s
, rd
, tcg_double
);
6998 tcg_temp_free_i64(tcg_double
);
7001 case 0: /* float32 */
7002 tcg_single
= tcg_temp_new_i32();
7004 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
7005 tcg_shift
, tcg_fpstatus
);
7007 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
7008 tcg_shift
, tcg_fpstatus
);
7010 write_fp_sreg(s
, rd
, tcg_single
);
7011 tcg_temp_free_i32(tcg_single
);
7014 case 3: /* float16 */
7015 tcg_single
= tcg_temp_new_i32();
7017 gen_helper_vfp_sqtoh(tcg_single
, tcg_int
,
7018 tcg_shift
, tcg_fpstatus
);
7020 gen_helper_vfp_uqtoh(tcg_single
, tcg_int
,
7021 tcg_shift
, tcg_fpstatus
);
7023 write_fp_sreg(s
, rd
, tcg_single
);
7024 tcg_temp_free_i32(tcg_single
);
7028 g_assert_not_reached();
7031 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
7034 if (extract32(opcode
, 2, 1)) {
7035 /* There are too many rounding modes to all fit into rmode,
7036 * so FCVTA[US] is a special case.
7038 rmode
= FPROUNDING_TIEAWAY
;
7041 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
7043 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7046 case 1: /* float64 */
7047 tcg_double
= read_fp_dreg(s
, rn
);
7050 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
7051 tcg_shift
, tcg_fpstatus
);
7053 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
7054 tcg_shift
, tcg_fpstatus
);
7058 gen_helper_vfp_tould(tcg_int
, tcg_double
,
7059 tcg_shift
, tcg_fpstatus
);
7061 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
7062 tcg_shift
, tcg_fpstatus
);
7066 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
7068 tcg_temp_free_i64(tcg_double
);
7071 case 0: /* float32 */
7072 tcg_single
= read_fp_sreg(s
, rn
);
7075 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
7076 tcg_shift
, tcg_fpstatus
);
7078 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
7079 tcg_shift
, tcg_fpstatus
);
7082 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
7084 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
7085 tcg_shift
, tcg_fpstatus
);
7087 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
7088 tcg_shift
, tcg_fpstatus
);
7090 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
7091 tcg_temp_free_i32(tcg_dest
);
7093 tcg_temp_free_i32(tcg_single
);
7096 case 3: /* float16 */
7097 tcg_single
= read_fp_sreg(s
, rn
);
7100 gen_helper_vfp_tosqh(tcg_int
, tcg_single
,
7101 tcg_shift
, tcg_fpstatus
);
7103 gen_helper_vfp_touqh(tcg_int
, tcg_single
,
7104 tcg_shift
, tcg_fpstatus
);
7107 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
7109 gen_helper_vfp_toslh(tcg_dest
, tcg_single
,
7110 tcg_shift
, tcg_fpstatus
);
7112 gen_helper_vfp_toulh(tcg_dest
, tcg_single
,
7113 tcg_shift
, tcg_fpstatus
);
7115 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
7116 tcg_temp_free_i32(tcg_dest
);
7118 tcg_temp_free_i32(tcg_single
);
7122 g_assert_not_reached();
7125 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7126 tcg_temp_free_i32(tcg_rmode
);
7129 tcg_temp_free_ptr(tcg_fpstatus
);
7132 /* Floating point <-> fixed point conversions
7133 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
7134 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
7135 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
7136 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
7138 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
7140 int rd
= extract32(insn
, 0, 5);
7141 int rn
= extract32(insn
, 5, 5);
7142 int scale
= extract32(insn
, 10, 6);
7143 int opcode
= extract32(insn
, 16, 3);
7144 int rmode
= extract32(insn
, 19, 2);
7145 int type
= extract32(insn
, 22, 2);
7146 bool sbit
= extract32(insn
, 29, 1);
7147 bool sf
= extract32(insn
, 31, 1);
7150 if (sbit
|| (!sf
&& scale
< 32)) {
7151 unallocated_encoding(s
);
7156 case 0: /* float32 */
7157 case 1: /* float64 */
7159 case 3: /* float16 */
7160 if (dc_isar_feature(aa64_fp16
, s
)) {
7165 unallocated_encoding(s
);
7169 switch ((rmode
<< 3) | opcode
) {
7170 case 0x2: /* SCVTF */
7171 case 0x3: /* UCVTF */
7174 case 0x18: /* FCVTZS */
7175 case 0x19: /* FCVTZU */
7179 unallocated_encoding(s
);
7183 if (!fp_access_check(s
)) {
7187 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
7190 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
7192 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
7193 * without conversion.
7197 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
7203 tmp
= tcg_temp_new_i64();
7204 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
7205 write_fp_dreg(s
, rd
, tmp
);
7206 tcg_temp_free_i64(tmp
);
7210 write_fp_dreg(s
, rd
, tcg_rn
);
7213 /* 64 bit to top half. */
7214 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
7215 clear_vec_high(s
, true, rd
);
7219 tmp
= tcg_temp_new_i64();
7220 tcg_gen_ext16u_i64(tmp
, tcg_rn
);
7221 write_fp_dreg(s
, rd
, tmp
);
7222 tcg_temp_free_i64(tmp
);
7225 g_assert_not_reached();
7228 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
7233 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
7237 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
7240 /* 64 bits from top half */
7241 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
7245 tcg_gen_ld16u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_16
));
7248 g_assert_not_reached();
7253 static void handle_fjcvtzs(DisasContext
*s
, int rd
, int rn
)
7255 TCGv_i64 t
= read_fp_dreg(s
, rn
);
7256 TCGv_ptr fpstatus
= fpstatus_ptr(FPST_FPCR
);
7258 gen_helper_fjcvtzs(t
, t
, fpstatus
);
7260 tcg_temp_free_ptr(fpstatus
);
7262 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), t
);
7263 tcg_gen_extrh_i64_i32(cpu_ZF
, t
);
7264 tcg_gen_movi_i32(cpu_CF
, 0);
7265 tcg_gen_movi_i32(cpu_NF
, 0);
7266 tcg_gen_movi_i32(cpu_VF
, 0);
7268 tcg_temp_free_i64(t
);
7271 /* Floating point <-> integer conversions
7272 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
7273 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
7274 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
7275 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
7277 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
7279 int rd
= extract32(insn
, 0, 5);
7280 int rn
= extract32(insn
, 5, 5);
7281 int opcode
= extract32(insn
, 16, 3);
7282 int rmode
= extract32(insn
, 19, 2);
7283 int type
= extract32(insn
, 22, 2);
7284 bool sbit
= extract32(insn
, 29, 1);
7285 bool sf
= extract32(insn
, 31, 1);
7289 goto do_unallocated
;
7297 case 4: /* FCVTAS */
7298 case 5: /* FCVTAU */
7300 goto do_unallocated
;
7303 case 0: /* FCVT[NPMZ]S */
7304 case 1: /* FCVT[NPMZ]U */
7306 case 0: /* float32 */
7307 case 1: /* float64 */
7309 case 3: /* float16 */
7310 if (!dc_isar_feature(aa64_fp16
, s
)) {
7311 goto do_unallocated
;
7315 goto do_unallocated
;
7317 if (!fp_access_check(s
)) {
7320 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
7324 switch (sf
<< 7 | type
<< 5 | rmode
<< 3 | opcode
) {
7325 case 0b01100110: /* FMOV half <-> 32-bit int */
7327 case 0b11100110: /* FMOV half <-> 64-bit int */
7329 if (!dc_isar_feature(aa64_fp16
, s
)) {
7330 goto do_unallocated
;
7333 case 0b00000110: /* FMOV 32-bit */
7335 case 0b10100110: /* FMOV 64-bit */
7337 case 0b11001110: /* FMOV top half of 128-bit */
7339 if (!fp_access_check(s
)) {
7343 handle_fmov(s
, rd
, rn
, type
, itof
);
7346 case 0b00111110: /* FJCVTZS */
7347 if (!dc_isar_feature(aa64_jscvt
, s
)) {
7348 goto do_unallocated
;
7349 } else if (fp_access_check(s
)) {
7350 handle_fjcvtzs(s
, rd
, rn
);
7356 unallocated_encoding(s
);
7363 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
7364 * 31 30 29 28 25 24 0
7365 * +---+---+---+---------+-----------------------------+
7366 * | | 0 | | 1 1 1 1 | |
7367 * +---+---+---+---------+-----------------------------+
7369 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
7371 if (extract32(insn
, 24, 1)) {
7372 /* Floating point data-processing (3 source) */
7373 disas_fp_3src(s
, insn
);
7374 } else if (extract32(insn
, 21, 1) == 0) {
7375 /* Floating point to fixed point conversions */
7376 disas_fp_fixed_conv(s
, insn
);
7378 switch (extract32(insn
, 10, 2)) {
7380 /* Floating point conditional compare */
7381 disas_fp_ccomp(s
, insn
);
7384 /* Floating point data-processing (2 source) */
7385 disas_fp_2src(s
, insn
);
7388 /* Floating point conditional select */
7389 disas_fp_csel(s
, insn
);
7392 switch (ctz32(extract32(insn
, 12, 4))) {
7393 case 0: /* [15:12] == xxx1 */
7394 /* Floating point immediate */
7395 disas_fp_imm(s
, insn
);
7397 case 1: /* [15:12] == xx10 */
7398 /* Floating point compare */
7399 disas_fp_compare(s
, insn
);
7401 case 2: /* [15:12] == x100 */
7402 /* Floating point data-processing (1 source) */
7403 disas_fp_1src(s
, insn
);
7405 case 3: /* [15:12] == 1000 */
7406 unallocated_encoding(s
);
7408 default: /* [15:12] == 0000 */
7409 /* Floating point <-> integer conversions */
7410 disas_fp_int_conv(s
, insn
);
7418 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
7421 /* Extract 64 bits from the middle of two concatenated 64 bit
7422 * vector register slices left:right. The extracted bits start
7423 * at 'pos' bits into the right (least significant) side.
7424 * We return the result in tcg_right, and guarantee not to
7427 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
7428 assert(pos
> 0 && pos
< 64);
7430 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
7431 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
7432 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
7434 tcg_temp_free_i64(tcg_tmp
);
7438 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
7439 * +---+---+-------------+-----+---+------+---+------+---+------+------+
7440 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
7441 * +---+---+-------------+-----+---+------+---+------+---+------+------+
7443 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
7445 int is_q
= extract32(insn
, 30, 1);
7446 int op2
= extract32(insn
, 22, 2);
7447 int imm4
= extract32(insn
, 11, 4);
7448 int rm
= extract32(insn
, 16, 5);
7449 int rn
= extract32(insn
, 5, 5);
7450 int rd
= extract32(insn
, 0, 5);
7451 int pos
= imm4
<< 3;
7452 TCGv_i64 tcg_resl
, tcg_resh
;
7454 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
7455 unallocated_encoding(s
);
7459 if (!fp_access_check(s
)) {
7463 tcg_resh
= tcg_temp_new_i64();
7464 tcg_resl
= tcg_temp_new_i64();
7466 /* Vd gets bits starting at pos bits into Vm:Vn. This is
7467 * either extracting 128 bits from a 128:128 concatenation, or
7468 * extracting 64 bits from a 64:64 concatenation.
7471 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
7473 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
7474 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
7482 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
7483 EltPosns
*elt
= eltposns
;
7490 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
7492 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
7495 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
7496 tcg_hh
= tcg_temp_new_i64();
7497 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
7498 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
7499 tcg_temp_free_i64(tcg_hh
);
7503 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
7504 tcg_temp_free_i64(tcg_resl
);
7506 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
7508 tcg_temp_free_i64(tcg_resh
);
7509 clear_vec_high(s
, is_q
, rd
);
7513 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
7514 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
7515 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
7516 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
7518 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
7520 int op2
= extract32(insn
, 22, 2);
7521 int is_q
= extract32(insn
, 30, 1);
7522 int rm
= extract32(insn
, 16, 5);
7523 int rn
= extract32(insn
, 5, 5);
7524 int rd
= extract32(insn
, 0, 5);
7525 int is_tbx
= extract32(insn
, 12, 1);
7526 int len
= (extract32(insn
, 13, 2) + 1) * 16;
7529 unallocated_encoding(s
);
7533 if (!fp_access_check(s
)) {
7537 tcg_gen_gvec_2_ptr(vec_full_reg_offset(s
, rd
),
7538 vec_full_reg_offset(s
, rm
), cpu_env
,
7539 is_q
? 16 : 8, vec_full_reg_size(s
),
7540 (len
<< 6) | (is_tbx
<< 5) | rn
,
7541 gen_helper_simd_tblx
);
7545 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
7546 * +---+---+-------------+------+---+------+---+------------------+------+
7547 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
7548 * +---+---+-------------+------+---+------+---+------------------+------+
7550 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
7552 int rd
= extract32(insn
, 0, 5);
7553 int rn
= extract32(insn
, 5, 5);
7554 int rm
= extract32(insn
, 16, 5);
7555 int size
= extract32(insn
, 22, 2);
7556 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
7557 * bit 2 indicates 1 vs 2 variant of the insn.
7559 int opcode
= extract32(insn
, 12, 2);
7560 bool part
= extract32(insn
, 14, 1);
7561 bool is_q
= extract32(insn
, 30, 1);
7562 int esize
= 8 << size
;
7564 int datasize
= is_q
? 128 : 64;
7565 int elements
= datasize
/ esize
;
7566 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
7568 if (opcode
== 0 || (size
== 3 && !is_q
)) {
7569 unallocated_encoding(s
);
7573 if (!fp_access_check(s
)) {
7577 tcg_resl
= tcg_const_i64(0);
7578 tcg_resh
= is_q
? tcg_const_i64(0) : NULL
;
7579 tcg_res
= tcg_temp_new_i64();
7581 for (i
= 0; i
< elements
; i
++) {
7583 case 1: /* UZP1/2 */
7585 int midpoint
= elements
/ 2;
7587 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
7589 read_vec_element(s
, tcg_res
, rm
,
7590 2 * (i
- midpoint
) + part
, size
);
7594 case 2: /* TRN1/2 */
7596 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
7598 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
7601 case 3: /* ZIP1/2 */
7603 int base
= part
* elements
/ 2;
7605 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
7607 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
7612 g_assert_not_reached();
7617 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
7618 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
7620 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
7621 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
7625 tcg_temp_free_i64(tcg_res
);
7627 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
7628 tcg_temp_free_i64(tcg_resl
);
7631 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
7632 tcg_temp_free_i64(tcg_resh
);
7634 clear_vec_high(s
, is_q
, rd
);
7638 * do_reduction_op helper
7640 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
7641 * important for correct NaN propagation that we do these
7642 * operations in exactly the order specified by the pseudocode.
7644 * This is a recursive function, TCG temps should be freed by the
7645 * calling function once it is done with the values.
7647 static TCGv_i32
do_reduction_op(DisasContext
*s
, int fpopcode
, int rn
,
7648 int esize
, int size
, int vmap
, TCGv_ptr fpst
)
7650 if (esize
== size
) {
7652 MemOp msize
= esize
== 16 ? MO_16
: MO_32
;
7655 /* We should have one register left here */
7656 assert(ctpop8(vmap
) == 1);
7657 element
= ctz32(vmap
);
7658 assert(element
< 8);
7660 tcg_elem
= tcg_temp_new_i32();
7661 read_vec_element_i32(s
, tcg_elem
, rn
, element
, msize
);
7664 int bits
= size
/ 2;
7665 int shift
= ctpop8(vmap
) / 2;
7666 int vmap_lo
= (vmap
>> shift
) & vmap
;
7667 int vmap_hi
= (vmap
& ~vmap_lo
);
7668 TCGv_i32 tcg_hi
, tcg_lo
, tcg_res
;
7670 tcg_hi
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_hi
, fpst
);
7671 tcg_lo
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_lo
, fpst
);
7672 tcg_res
= tcg_temp_new_i32();
7675 case 0x0c: /* fmaxnmv half-precision */
7676 gen_helper_advsimd_maxnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7678 case 0x0f: /* fmaxv half-precision */
7679 gen_helper_advsimd_maxh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7681 case 0x1c: /* fminnmv half-precision */
7682 gen_helper_advsimd_minnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7684 case 0x1f: /* fminv half-precision */
7685 gen_helper_advsimd_minh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7687 case 0x2c: /* fmaxnmv */
7688 gen_helper_vfp_maxnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7690 case 0x2f: /* fmaxv */
7691 gen_helper_vfp_maxs(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7693 case 0x3c: /* fminnmv */
7694 gen_helper_vfp_minnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7696 case 0x3f: /* fminv */
7697 gen_helper_vfp_mins(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7700 g_assert_not_reached();
7703 tcg_temp_free_i32(tcg_hi
);
7704 tcg_temp_free_i32(tcg_lo
);
7709 /* AdvSIMD across lanes
7710 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7711 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7712 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7713 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7715 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
7717 int rd
= extract32(insn
, 0, 5);
7718 int rn
= extract32(insn
, 5, 5);
7719 int size
= extract32(insn
, 22, 2);
7720 int opcode
= extract32(insn
, 12, 5);
7721 bool is_q
= extract32(insn
, 30, 1);
7722 bool is_u
= extract32(insn
, 29, 1);
7724 bool is_min
= false;
7728 TCGv_i64 tcg_res
, tcg_elt
;
7731 case 0x1b: /* ADDV */
7733 unallocated_encoding(s
);
7737 case 0x3: /* SADDLV, UADDLV */
7738 case 0xa: /* SMAXV, UMAXV */
7739 case 0x1a: /* SMINV, UMINV */
7740 if (size
== 3 || (size
== 2 && !is_q
)) {
7741 unallocated_encoding(s
);
7745 case 0xc: /* FMAXNMV, FMINNMV */
7746 case 0xf: /* FMAXV, FMINV */
7747 /* Bit 1 of size field encodes min vs max and the actual size
7748 * depends on the encoding of the U bit. If not set (and FP16
7749 * enabled) then we do half-precision float instead of single
7752 is_min
= extract32(size
, 1, 1);
7754 if (!is_u
&& dc_isar_feature(aa64_fp16
, s
)) {
7756 } else if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
7757 unallocated_encoding(s
);
7764 unallocated_encoding(s
);
7768 if (!fp_access_check(s
)) {
7773 elements
= (is_q
? 128 : 64) / esize
;
7775 tcg_res
= tcg_temp_new_i64();
7776 tcg_elt
= tcg_temp_new_i64();
7778 /* These instructions operate across all lanes of a vector
7779 * to produce a single result. We can guarantee that a 64
7780 * bit intermediate is sufficient:
7781 * + for [US]ADDLV the maximum element size is 32 bits, and
7782 * the result type is 64 bits
7783 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
7784 * same as the element size, which is 32 bits at most
7785 * For the integer operations we can choose to work at 64
7786 * or 32 bits and truncate at the end; for simplicity
7787 * we use 64 bits always. The floating point
7788 * ops do require 32 bit intermediates, though.
7791 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
7793 for (i
= 1; i
< elements
; i
++) {
7794 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
7797 case 0x03: /* SADDLV / UADDLV */
7798 case 0x1b: /* ADDV */
7799 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
7801 case 0x0a: /* SMAXV / UMAXV */
7803 tcg_gen_umax_i64(tcg_res
, tcg_res
, tcg_elt
);
7805 tcg_gen_smax_i64(tcg_res
, tcg_res
, tcg_elt
);
7808 case 0x1a: /* SMINV / UMINV */
7810 tcg_gen_umin_i64(tcg_res
, tcg_res
, tcg_elt
);
7812 tcg_gen_smin_i64(tcg_res
, tcg_res
, tcg_elt
);
7816 g_assert_not_reached();
7821 /* Floating point vector reduction ops which work across 32
7822 * bit (single) or 16 bit (half-precision) intermediates.
7823 * Note that correct NaN propagation requires that we do these
7824 * operations in exactly the order specified by the pseudocode.
7826 TCGv_ptr fpst
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
7827 int fpopcode
= opcode
| is_min
<< 4 | is_u
<< 5;
7828 int vmap
= (1 << elements
) - 1;
7829 TCGv_i32 tcg_res32
= do_reduction_op(s
, fpopcode
, rn
, esize
,
7830 (is_q
? 128 : 64), vmap
, fpst
);
7831 tcg_gen_extu_i32_i64(tcg_res
, tcg_res32
);
7832 tcg_temp_free_i32(tcg_res32
);
7833 tcg_temp_free_ptr(fpst
);
7836 tcg_temp_free_i64(tcg_elt
);
7838 /* Now truncate the result to the width required for the final output */
7839 if (opcode
== 0x03) {
7840 /* SADDLV, UADDLV: result is 2*esize */
7846 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
7849 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
7852 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
7857 g_assert_not_reached();
7860 write_fp_dreg(s
, rd
, tcg_res
);
7861 tcg_temp_free_i64(tcg_res
);
7864 /* DUP (Element, Vector)
7866 * 31 30 29 21 20 16 15 10 9 5 4 0
7867 * +---+---+-------------------+--------+-------------+------+------+
7868 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7869 * +---+---+-------------------+--------+-------------+------+------+
7871 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7873 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
7876 int size
= ctz32(imm5
);
7879 if (size
> 3 || (size
== 3 && !is_q
)) {
7880 unallocated_encoding(s
);
7884 if (!fp_access_check(s
)) {
7888 index
= imm5
>> (size
+ 1);
7889 tcg_gen_gvec_dup_mem(size
, vec_full_reg_offset(s
, rd
),
7890 vec_reg_offset(s
, rn
, index
, size
),
7891 is_q
? 16 : 8, vec_full_reg_size(s
));
7894 /* DUP (element, scalar)
7895 * 31 21 20 16 15 10 9 5 4 0
7896 * +-----------------------+--------+-------------+------+------+
7897 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7898 * +-----------------------+--------+-------------+------+------+
7900 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
7903 int size
= ctz32(imm5
);
7908 unallocated_encoding(s
);
7912 if (!fp_access_check(s
)) {
7916 index
= imm5
>> (size
+ 1);
7918 /* This instruction just extracts the specified element and
7919 * zero-extends it into the bottom of the destination register.
7921 tmp
= tcg_temp_new_i64();
7922 read_vec_element(s
, tmp
, rn
, index
, size
);
7923 write_fp_dreg(s
, rd
, tmp
);
7924 tcg_temp_free_i64(tmp
);
7929 * 31 30 29 21 20 16 15 10 9 5 4 0
7930 * +---+---+-------------------+--------+-------------+------+------+
7931 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
7932 * +---+---+-------------------+--------+-------------+------+------+
7934 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7936 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
7939 int size
= ctz32(imm5
);
7940 uint32_t dofs
, oprsz
, maxsz
;
7942 if (size
> 3 || ((size
== 3) && !is_q
)) {
7943 unallocated_encoding(s
);
7947 if (!fp_access_check(s
)) {
7951 dofs
= vec_full_reg_offset(s
, rd
);
7952 oprsz
= is_q
? 16 : 8;
7953 maxsz
= vec_full_reg_size(s
);
7955 tcg_gen_gvec_dup_i64(size
, dofs
, oprsz
, maxsz
, cpu_reg(s
, rn
));
7960 * 31 21 20 16 15 14 11 10 9 5 4 0
7961 * +-----------------------+--------+------------+---+------+------+
7962 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7963 * +-----------------------+--------+------------+---+------+------+
7965 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7966 * index: encoded in imm5<4:size+1>
7968 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
7971 int size
= ctz32(imm5
);
7972 int src_index
, dst_index
;
7976 unallocated_encoding(s
);
7980 if (!fp_access_check(s
)) {
7984 dst_index
= extract32(imm5
, 1+size
, 5);
7985 src_index
= extract32(imm4
, size
, 4);
7987 tmp
= tcg_temp_new_i64();
7989 read_vec_element(s
, tmp
, rn
, src_index
, size
);
7990 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
7992 tcg_temp_free_i64(tmp
);
7994 /* INS is considered a 128-bit write for SVE. */
7995 clear_vec_high(s
, true, rd
);
8001 * 31 21 20 16 15 10 9 5 4 0
8002 * +-----------------------+--------+-------------+------+------+
8003 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
8004 * +-----------------------+--------+-------------+------+------+
8006 * size: encoded in imm5 (see ARM ARM LowestSetBit())
8007 * index: encoded in imm5<4:size+1>
8009 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
8011 int size
= ctz32(imm5
);
8015 unallocated_encoding(s
);
8019 if (!fp_access_check(s
)) {
8023 idx
= extract32(imm5
, 1 + size
, 4 - size
);
8024 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
8026 /* INS is considered a 128-bit write for SVE. */
8027 clear_vec_high(s
, true, rd
);
8034 * 31 30 29 21 20 16 15 12 10 9 5 4 0
8035 * +---+---+-------------------+--------+-------------+------+------+
8036 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
8037 * +---+---+-------------------+--------+-------------+------+------+
8039 * U: unsigned when set
8040 * size: encoded in imm5 (see ARM ARM LowestSetBit())
8042 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
8043 int rn
, int rd
, int imm5
)
8045 int size
= ctz32(imm5
);
8049 /* Check for UnallocatedEncodings */
8051 if (size
> 2 || (size
== 2 && !is_q
)) {
8052 unallocated_encoding(s
);
8057 || (size
< 3 && is_q
)
8058 || (size
== 3 && !is_q
)) {
8059 unallocated_encoding(s
);
8064 if (!fp_access_check(s
)) {
8068 element
= extract32(imm5
, 1+size
, 4);
8070 tcg_rd
= cpu_reg(s
, rd
);
8071 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
8072 if (is_signed
&& !is_q
) {
8073 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
8078 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
8079 * +---+---+----+-----------------+------+---+------+---+------+------+
8080 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
8081 * +---+---+----+-----------------+------+---+------+---+------+------+
8083 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
8085 int rd
= extract32(insn
, 0, 5);
8086 int rn
= extract32(insn
, 5, 5);
8087 int imm4
= extract32(insn
, 11, 4);
8088 int op
= extract32(insn
, 29, 1);
8089 int is_q
= extract32(insn
, 30, 1);
8090 int imm5
= extract32(insn
, 16, 5);
8095 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
8097 unallocated_encoding(s
);
8102 /* DUP (element - vector) */
8103 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
8107 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
8112 handle_simd_insg(s
, rd
, rn
, imm5
);
8114 unallocated_encoding(s
);
8119 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
8120 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
8123 unallocated_encoding(s
);
8129 /* AdvSIMD modified immediate
8130 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
8131 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
8132 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
8133 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
8135 * There are a number of operations that can be carried out here:
8136 * MOVI - move (shifted) imm into register
8137 * MVNI - move inverted (shifted) imm into register
8138 * ORR - bitwise OR of (shifted) imm with register
8139 * BIC - bitwise clear of (shifted) imm with register
8140 * With ARMv8.2 we also have:
8141 * FMOV half-precision
8143 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
8145 int rd
= extract32(insn
, 0, 5);
8146 int cmode
= extract32(insn
, 12, 4);
8147 int o2
= extract32(insn
, 11, 1);
8148 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
8149 bool is_neg
= extract32(insn
, 29, 1);
8150 bool is_q
= extract32(insn
, 30, 1);
8153 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
8154 /* Check for FMOV (vector, immediate) - half-precision */
8155 if (!(dc_isar_feature(aa64_fp16
, s
) && o2
&& cmode
== 0xf)) {
8156 unallocated_encoding(s
);
8161 if (!fp_access_check(s
)) {
8165 if (cmode
== 15 && o2
&& !is_neg
) {
8166 /* FMOV (vector, immediate) - half-precision */
8167 imm
= vfp_expand_imm(MO_16
, abcdefgh
);
8168 /* now duplicate across the lanes */
8169 imm
= dup_const(MO_16
, imm
);
8171 imm
= asimd_imm_const(abcdefgh
, cmode
, is_neg
);
8174 if (!((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9)) {
8175 /* MOVI or MVNI, with MVNI negation handled above. */
8176 tcg_gen_gvec_dup_imm(MO_64
, vec_full_reg_offset(s
, rd
), is_q
? 16 : 8,
8177 vec_full_reg_size(s
), imm
);
8179 /* ORR or BIC, with BIC negation to AND handled above. */
8181 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_andi
, MO_64
);
8183 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_ori
, MO_64
);
8188 /* AdvSIMD scalar copy
8189 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
8190 * +-----+----+-----------------+------+---+------+---+------+------+
8191 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
8192 * +-----+----+-----------------+------+---+------+---+------+------+
8194 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
8196 int rd
= extract32(insn
, 0, 5);
8197 int rn
= extract32(insn
, 5, 5);
8198 int imm4
= extract32(insn
, 11, 4);
8199 int imm5
= extract32(insn
, 16, 5);
8200 int op
= extract32(insn
, 29, 1);
8202 if (op
!= 0 || imm4
!= 0) {
8203 unallocated_encoding(s
);
8207 /* DUP (element, scalar) */
8208 handle_simd_dupes(s
, rd
, rn
, imm5
);
8211 /* AdvSIMD scalar pairwise
8212 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
8213 * +-----+---+-----------+------+-----------+--------+-----+------+------+
8214 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
8215 * +-----+---+-----------+------+-----------+--------+-----+------+------+
8217 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
8219 int u
= extract32(insn
, 29, 1);
8220 int size
= extract32(insn
, 22, 2);
8221 int opcode
= extract32(insn
, 12, 5);
8222 int rn
= extract32(insn
, 5, 5);
8223 int rd
= extract32(insn
, 0, 5);
8226 /* For some ops (the FP ones), size[1] is part of the encoding.
8227 * For ADDP strictly it is not but size[1] is always 1 for valid
8230 opcode
|= (extract32(size
, 1, 1) << 5);
8233 case 0x3b: /* ADDP */
8234 if (u
|| size
!= 3) {
8235 unallocated_encoding(s
);
8238 if (!fp_access_check(s
)) {
8244 case 0xc: /* FMAXNMP */
8245 case 0xd: /* FADDP */
8246 case 0xf: /* FMAXP */
8247 case 0x2c: /* FMINNMP */
8248 case 0x2f: /* FMINP */
8249 /* FP op, size[0] is 32 or 64 bit*/
8251 if (!dc_isar_feature(aa64_fp16
, s
)) {
8252 unallocated_encoding(s
);
8258 size
= extract32(size
, 0, 1) ? MO_64
: MO_32
;
8261 if (!fp_access_check(s
)) {
8265 fpst
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
8268 unallocated_encoding(s
);
8272 if (size
== MO_64
) {
8273 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8274 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8275 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8277 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
8278 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
8281 case 0x3b: /* ADDP */
8282 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
8284 case 0xc: /* FMAXNMP */
8285 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8287 case 0xd: /* FADDP */
8288 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8290 case 0xf: /* FMAXP */
8291 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8293 case 0x2c: /* FMINNMP */
8294 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8296 case 0x2f: /* FMINP */
8297 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8300 g_assert_not_reached();
8303 write_fp_dreg(s
, rd
, tcg_res
);
8305 tcg_temp_free_i64(tcg_op1
);
8306 tcg_temp_free_i64(tcg_op2
);
8307 tcg_temp_free_i64(tcg_res
);
8309 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8310 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8311 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8313 read_vec_element_i32(s
, tcg_op1
, rn
, 0, size
);
8314 read_vec_element_i32(s
, tcg_op2
, rn
, 1, size
);
8316 if (size
== MO_16
) {
8318 case 0xc: /* FMAXNMP */
8319 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8321 case 0xd: /* FADDP */
8322 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8324 case 0xf: /* FMAXP */
8325 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8327 case 0x2c: /* FMINNMP */
8328 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8330 case 0x2f: /* FMINP */
8331 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8334 g_assert_not_reached();
8338 case 0xc: /* FMAXNMP */
8339 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8341 case 0xd: /* FADDP */
8342 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8344 case 0xf: /* FMAXP */
8345 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8347 case 0x2c: /* FMINNMP */
8348 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8350 case 0x2f: /* FMINP */
8351 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8354 g_assert_not_reached();
8358 write_fp_sreg(s
, rd
, tcg_res
);
8360 tcg_temp_free_i32(tcg_op1
);
8361 tcg_temp_free_i32(tcg_op2
);
8362 tcg_temp_free_i32(tcg_res
);
8366 tcg_temp_free_ptr(fpst
);
8371 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
8373 * This code is handles the common shifting code and is used by both
8374 * the vector and scalar code.
8376 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
8377 TCGv_i64 tcg_rnd
, bool accumulate
,
8378 bool is_u
, int size
, int shift
)
8380 bool extended_result
= false;
8381 bool round
= tcg_rnd
!= NULL
;
8383 TCGv_i64 tcg_src_hi
;
8385 if (round
&& size
== 3) {
8386 extended_result
= true;
8387 ext_lshift
= 64 - shift
;
8388 tcg_src_hi
= tcg_temp_new_i64();
8389 } else if (shift
== 64) {
8390 if (!accumulate
&& is_u
) {
8391 /* result is zero */
8392 tcg_gen_movi_i64(tcg_res
, 0);
8397 /* Deal with the rounding step */
8399 if (extended_result
) {
8400 TCGv_i64 tcg_zero
= tcg_constant_i64(0);
8402 /* take care of sign extending tcg_res */
8403 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
8404 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
8405 tcg_src
, tcg_src_hi
,
8408 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
8413 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
8417 /* Now do the shift right */
8418 if (round
&& extended_result
) {
8419 /* extended case, >64 bit precision required */
8420 if (ext_lshift
== 0) {
8421 /* special case, only high bits matter */
8422 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
8424 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
8425 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
8426 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
8431 /* essentially shifting in 64 zeros */
8432 tcg_gen_movi_i64(tcg_src
, 0);
8434 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
8438 /* effectively extending the sign-bit */
8439 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
8441 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
8447 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
8449 tcg_gen_mov_i64(tcg_res
, tcg_src
);
8452 if (extended_result
) {
8453 tcg_temp_free_i64(tcg_src_hi
);
8457 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
8458 static void handle_scalar_simd_shri(DisasContext
*s
,
8459 bool is_u
, int immh
, int immb
,
8460 int opcode
, int rn
, int rd
)
8463 int immhb
= immh
<< 3 | immb
;
8464 int shift
= 2 * (8 << size
) - immhb
;
8465 bool accumulate
= false;
8467 bool insert
= false;
8472 if (!extract32(immh
, 3, 1)) {
8473 unallocated_encoding(s
);
8477 if (!fp_access_check(s
)) {
8482 case 0x02: /* SSRA / USRA (accumulate) */
8485 case 0x04: /* SRSHR / URSHR (rounding) */
8488 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8489 accumulate
= round
= true;
8491 case 0x08: /* SRI */
8497 tcg_round
= tcg_constant_i64(1ULL << (shift
- 1));
8502 tcg_rn
= read_fp_dreg(s
, rn
);
8503 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
8506 /* shift count same as element size is valid but does nothing;
8507 * special case to avoid potential shift by 64.
8509 int esize
= 8 << size
;
8510 if (shift
!= esize
) {
8511 tcg_gen_shri_i64(tcg_rn
, tcg_rn
, shift
);
8512 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, 0, esize
- shift
);
8515 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8516 accumulate
, is_u
, size
, shift
);
8519 write_fp_dreg(s
, rd
, tcg_rd
);
8521 tcg_temp_free_i64(tcg_rn
);
8522 tcg_temp_free_i64(tcg_rd
);
8525 /* SHL/SLI - Scalar shift left */
8526 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
8527 int immh
, int immb
, int opcode
,
8530 int size
= 32 - clz32(immh
) - 1;
8531 int immhb
= immh
<< 3 | immb
;
8532 int shift
= immhb
- (8 << size
);
8536 if (!extract32(immh
, 3, 1)) {
8537 unallocated_encoding(s
);
8541 if (!fp_access_check(s
)) {
8545 tcg_rn
= read_fp_dreg(s
, rn
);
8546 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
8549 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, shift
, 64 - shift
);
8551 tcg_gen_shli_i64(tcg_rd
, tcg_rn
, shift
);
8554 write_fp_dreg(s
, rd
, tcg_rd
);
8556 tcg_temp_free_i64(tcg_rn
);
8557 tcg_temp_free_i64(tcg_rd
);
8560 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
8561 * (signed/unsigned) narrowing */
8562 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
8563 bool is_u_shift
, bool is_u_narrow
,
8564 int immh
, int immb
, int opcode
,
8567 int immhb
= immh
<< 3 | immb
;
8568 int size
= 32 - clz32(immh
) - 1;
8569 int esize
= 8 << size
;
8570 int shift
= (2 * esize
) - immhb
;
8571 int elements
= is_scalar
? 1 : (64 / esize
);
8572 bool round
= extract32(opcode
, 0, 1);
8573 MemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
8574 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
8575 TCGv_i32 tcg_rd_narrowed
;
8578 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
8579 { gen_helper_neon_narrow_sat_s8
,
8580 gen_helper_neon_unarrow_sat8
},
8581 { gen_helper_neon_narrow_sat_s16
,
8582 gen_helper_neon_unarrow_sat16
},
8583 { gen_helper_neon_narrow_sat_s32
,
8584 gen_helper_neon_unarrow_sat32
},
8587 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
8588 gen_helper_neon_narrow_sat_u8
,
8589 gen_helper_neon_narrow_sat_u16
,
8590 gen_helper_neon_narrow_sat_u32
,
8593 NeonGenNarrowEnvFn
*narrowfn
;
8599 if (extract32(immh
, 3, 1)) {
8600 unallocated_encoding(s
);
8604 if (!fp_access_check(s
)) {
8609 narrowfn
= unsigned_narrow_fns
[size
];
8611 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
8614 tcg_rn
= tcg_temp_new_i64();
8615 tcg_rd
= tcg_temp_new_i64();
8616 tcg_rd_narrowed
= tcg_temp_new_i32();
8617 tcg_final
= tcg_const_i64(0);
8620 tcg_round
= tcg_constant_i64(1ULL << (shift
- 1));
8625 for (i
= 0; i
< elements
; i
++) {
8626 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
8627 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8628 false, is_u_shift
, size
+1, shift
);
8629 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
8630 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
8631 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8635 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8637 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8640 tcg_temp_free_i64(tcg_rn
);
8641 tcg_temp_free_i64(tcg_rd
);
8642 tcg_temp_free_i32(tcg_rd_narrowed
);
8643 tcg_temp_free_i64(tcg_final
);
8645 clear_vec_high(s
, is_q
, rd
);
8648 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
8649 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
8650 bool src_unsigned
, bool dst_unsigned
,
8651 int immh
, int immb
, int rn
, int rd
)
8653 int immhb
= immh
<< 3 | immb
;
8654 int size
= 32 - clz32(immh
) - 1;
8655 int shift
= immhb
- (8 << size
);
8659 assert(!(scalar
&& is_q
));
8662 if (!is_q
&& extract32(immh
, 3, 1)) {
8663 unallocated_encoding(s
);
8667 /* Since we use the variable-shift helpers we must
8668 * replicate the shift count into each element of
8669 * the tcg_shift value.
8673 shift
|= shift
<< 8;
8676 shift
|= shift
<< 16;
8682 g_assert_not_reached();
8686 if (!fp_access_check(s
)) {
8691 TCGv_i64 tcg_shift
= tcg_constant_i64(shift
);
8692 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
8693 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
8694 { NULL
, gen_helper_neon_qshl_u64
},
8696 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
8697 int maxpass
= is_q
? 2 : 1;
8699 for (pass
= 0; pass
< maxpass
; pass
++) {
8700 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8702 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8703 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8704 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
8706 tcg_temp_free_i64(tcg_op
);
8708 clear_vec_high(s
, is_q
, rd
);
8710 TCGv_i32 tcg_shift
= tcg_constant_i32(shift
);
8711 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
8713 { gen_helper_neon_qshl_s8
,
8714 gen_helper_neon_qshl_s16
,
8715 gen_helper_neon_qshl_s32
},
8716 { gen_helper_neon_qshlu_s8
,
8717 gen_helper_neon_qshlu_s16
,
8718 gen_helper_neon_qshlu_s32
}
8720 { NULL
, NULL
, NULL
},
8721 { gen_helper_neon_qshl_u8
,
8722 gen_helper_neon_qshl_u16
,
8723 gen_helper_neon_qshl_u32
}
8726 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
8727 MemOp memop
= scalar
? size
: MO_32
;
8728 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
8730 for (pass
= 0; pass
< maxpass
; pass
++) {
8731 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8733 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
8734 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8738 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
8741 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
8746 g_assert_not_reached();
8748 write_fp_sreg(s
, rd
, tcg_op
);
8750 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
8753 tcg_temp_free_i32(tcg_op
);
8757 clear_vec_high(s
, is_q
, rd
);
8762 /* Common vector code for handling integer to FP conversion */
8763 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
8764 int elements
, int is_signed
,
8765 int fracbits
, int size
)
8767 TCGv_ptr tcg_fpst
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
8768 TCGv_i32 tcg_shift
= NULL
;
8770 MemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
8773 if (fracbits
|| size
== MO_64
) {
8774 tcg_shift
= tcg_constant_i32(fracbits
);
8777 if (size
== MO_64
) {
8778 TCGv_i64 tcg_int64
= tcg_temp_new_i64();
8779 TCGv_i64 tcg_double
= tcg_temp_new_i64();
8781 for (pass
= 0; pass
< elements
; pass
++) {
8782 read_vec_element(s
, tcg_int64
, rn
, pass
, mop
);
8785 gen_helper_vfp_sqtod(tcg_double
, tcg_int64
,
8786 tcg_shift
, tcg_fpst
);
8788 gen_helper_vfp_uqtod(tcg_double
, tcg_int64
,
8789 tcg_shift
, tcg_fpst
);
8791 if (elements
== 1) {
8792 write_fp_dreg(s
, rd
, tcg_double
);
8794 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
8798 tcg_temp_free_i64(tcg_int64
);
8799 tcg_temp_free_i64(tcg_double
);
8802 TCGv_i32 tcg_int32
= tcg_temp_new_i32();
8803 TCGv_i32 tcg_float
= tcg_temp_new_i32();
8805 for (pass
= 0; pass
< elements
; pass
++) {
8806 read_vec_element_i32(s
, tcg_int32
, rn
, pass
, mop
);
8812 gen_helper_vfp_sltos(tcg_float
, tcg_int32
,
8813 tcg_shift
, tcg_fpst
);
8815 gen_helper_vfp_ultos(tcg_float
, tcg_int32
,
8816 tcg_shift
, tcg_fpst
);
8820 gen_helper_vfp_sitos(tcg_float
, tcg_int32
, tcg_fpst
);
8822 gen_helper_vfp_uitos(tcg_float
, tcg_int32
, tcg_fpst
);
8829 gen_helper_vfp_sltoh(tcg_float
, tcg_int32
,
8830 tcg_shift
, tcg_fpst
);
8832 gen_helper_vfp_ultoh(tcg_float
, tcg_int32
,
8833 tcg_shift
, tcg_fpst
);
8837 gen_helper_vfp_sitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8839 gen_helper_vfp_uitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8844 g_assert_not_reached();
8847 if (elements
== 1) {
8848 write_fp_sreg(s
, rd
, tcg_float
);
8850 write_vec_element_i32(s
, tcg_float
, rd
, pass
, size
);
8854 tcg_temp_free_i32(tcg_int32
);
8855 tcg_temp_free_i32(tcg_float
);
8858 tcg_temp_free_ptr(tcg_fpst
);
8860 clear_vec_high(s
, elements
<< size
== 16, rd
);
8863 /* UCVTF/SCVTF - Integer to FP conversion */
8864 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
8865 bool is_q
, bool is_u
,
8866 int immh
, int immb
, int opcode
,
8869 int size
, elements
, fracbits
;
8870 int immhb
= immh
<< 3 | immb
;
8874 if (!is_scalar
&& !is_q
) {
8875 unallocated_encoding(s
);
8878 } else if (immh
& 4) {
8880 } else if (immh
& 2) {
8882 if (!dc_isar_feature(aa64_fp16
, s
)) {
8883 unallocated_encoding(s
);
8887 /* immh == 0 would be a failure of the decode logic */
8888 g_assert(immh
== 1);
8889 unallocated_encoding(s
);
8896 elements
= (8 << is_q
) >> size
;
8898 fracbits
= (16 << size
) - immhb
;
8900 if (!fp_access_check(s
)) {
8904 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
8907 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
8908 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
8909 bool is_q
, bool is_u
,
8910 int immh
, int immb
, int rn
, int rd
)
8912 int immhb
= immh
<< 3 | immb
;
8913 int pass
, size
, fracbits
;
8914 TCGv_ptr tcg_fpstatus
;
8915 TCGv_i32 tcg_rmode
, tcg_shift
;
8919 if (!is_scalar
&& !is_q
) {
8920 unallocated_encoding(s
);
8923 } else if (immh
& 0x4) {
8925 } else if (immh
& 0x2) {
8927 if (!dc_isar_feature(aa64_fp16
, s
)) {
8928 unallocated_encoding(s
);
8932 /* Should have split out AdvSIMD modified immediate earlier. */
8934 unallocated_encoding(s
);
8938 if (!fp_access_check(s
)) {
8942 assert(!(is_scalar
&& is_q
));
8944 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
8945 tcg_fpstatus
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
8946 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
8947 fracbits
= (16 << size
) - immhb
;
8948 tcg_shift
= tcg_constant_i32(fracbits
);
8950 if (size
== MO_64
) {
8951 int maxpass
= is_scalar
? 1 : 2;
8953 for (pass
= 0; pass
< maxpass
; pass
++) {
8954 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8956 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8958 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8960 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8962 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
8963 tcg_temp_free_i64(tcg_op
);
8965 clear_vec_high(s
, is_q
, rd
);
8967 void (*fn
)(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
8968 int maxpass
= is_scalar
? 1 : ((8 << is_q
) >> size
);
8973 fn
= gen_helper_vfp_touhh
;
8975 fn
= gen_helper_vfp_toshh
;
8980 fn
= gen_helper_vfp_touls
;
8982 fn
= gen_helper_vfp_tosls
;
8986 g_assert_not_reached();
8989 for (pass
= 0; pass
< maxpass
; pass
++) {
8990 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8992 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
8993 fn(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8995 write_fp_sreg(s
, rd
, tcg_op
);
8997 write_vec_element_i32(s
, tcg_op
, rd
, pass
, size
);
8999 tcg_temp_free_i32(tcg_op
);
9002 clear_vec_high(s
, is_q
, rd
);
9006 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9007 tcg_temp_free_ptr(tcg_fpstatus
);
9008 tcg_temp_free_i32(tcg_rmode
);
9011 /* AdvSIMD scalar shift by immediate
9012 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
9013 * +-----+---+-------------+------+------+--------+---+------+------+
9014 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
9015 * +-----+---+-------------+------+------+--------+---+------+------+
9017 * This is the scalar version so it works on a fixed sized registers
9019 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
9021 int rd
= extract32(insn
, 0, 5);
9022 int rn
= extract32(insn
, 5, 5);
9023 int opcode
= extract32(insn
, 11, 5);
9024 int immb
= extract32(insn
, 16, 3);
9025 int immh
= extract32(insn
, 19, 4);
9026 bool is_u
= extract32(insn
, 29, 1);
9029 unallocated_encoding(s
);
9034 case 0x08: /* SRI */
9036 unallocated_encoding(s
);
9040 case 0x00: /* SSHR / USHR */
9041 case 0x02: /* SSRA / USRA */
9042 case 0x04: /* SRSHR / URSHR */
9043 case 0x06: /* SRSRA / URSRA */
9044 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9046 case 0x0a: /* SHL / SLI */
9047 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9049 case 0x1c: /* SCVTF, UCVTF */
9050 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
9053 case 0x10: /* SQSHRUN, SQSHRUN2 */
9054 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
9056 unallocated_encoding(s
);
9059 handle_vec_simd_sqshrn(s
, true, false, false, true,
9060 immh
, immb
, opcode
, rn
, rd
);
9062 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
9063 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
9064 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
9065 immh
, immb
, opcode
, rn
, rd
);
9067 case 0xc: /* SQSHLU */
9069 unallocated_encoding(s
);
9072 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
9074 case 0xe: /* SQSHL, UQSHL */
9075 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
9077 case 0x1f: /* FCVTZS, FCVTZU */
9078 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
9081 unallocated_encoding(s
);
9086 /* AdvSIMD scalar three different
9087 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
9088 * +-----+---+-----------+------+---+------+--------+-----+------+------+
9089 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
9090 * +-----+---+-----------+------+---+------+--------+-----+------+------+
9092 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
9094 bool is_u
= extract32(insn
, 29, 1);
9095 int size
= extract32(insn
, 22, 2);
9096 int opcode
= extract32(insn
, 12, 4);
9097 int rm
= extract32(insn
, 16, 5);
9098 int rn
= extract32(insn
, 5, 5);
9099 int rd
= extract32(insn
, 0, 5);
9102 unallocated_encoding(s
);
9107 case 0x9: /* SQDMLAL, SQDMLAL2 */
9108 case 0xb: /* SQDMLSL, SQDMLSL2 */
9109 case 0xd: /* SQDMULL, SQDMULL2 */
9110 if (size
== 0 || size
== 3) {
9111 unallocated_encoding(s
);
9116 unallocated_encoding(s
);
9120 if (!fp_access_check(s
)) {
9125 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9126 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9127 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9129 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
9130 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
9132 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
9133 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
9136 case 0xd: /* SQDMULL, SQDMULL2 */
9138 case 0xb: /* SQDMLSL, SQDMLSL2 */
9139 tcg_gen_neg_i64(tcg_res
, tcg_res
);
9141 case 0x9: /* SQDMLAL, SQDMLAL2 */
9142 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
9143 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
9147 g_assert_not_reached();
9150 write_fp_dreg(s
, rd
, tcg_res
);
9152 tcg_temp_free_i64(tcg_op1
);
9153 tcg_temp_free_i64(tcg_op2
);
9154 tcg_temp_free_i64(tcg_res
);
9156 TCGv_i32 tcg_op1
= read_fp_hreg(s
, rn
);
9157 TCGv_i32 tcg_op2
= read_fp_hreg(s
, rm
);
9158 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9160 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
9161 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
9164 case 0xd: /* SQDMULL, SQDMULL2 */
9166 case 0xb: /* SQDMLSL, SQDMLSL2 */
9167 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
9169 case 0x9: /* SQDMLAL, SQDMLAL2 */
9171 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
9172 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
9173 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
9175 tcg_temp_free_i64(tcg_op3
);
9179 g_assert_not_reached();
9182 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
9183 write_fp_dreg(s
, rd
, tcg_res
);
9185 tcg_temp_free_i32(tcg_op1
);
9186 tcg_temp_free_i32(tcg_op2
);
9187 tcg_temp_free_i64(tcg_res
);
9191 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
9192 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
9194 /* Handle 64x64->64 opcodes which are shared between the scalar
9195 * and vector 3-same groups. We cover every opcode where size == 3
9196 * is valid in either the three-reg-same (integer, not pairwise)
9197 * or scalar-three-reg-same groups.
9202 case 0x1: /* SQADD */
9204 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9206 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9209 case 0x5: /* SQSUB */
9211 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9213 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9216 case 0x6: /* CMGT, CMHI */
9217 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
9218 * We implement this using setcond (test) and then negating.
9220 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
9222 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
9223 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
9225 case 0x7: /* CMGE, CMHS */
9226 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
9228 case 0x11: /* CMTST, CMEQ */
9233 gen_cmtst_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9235 case 0x8: /* SSHL, USHL */
9237 gen_ushl_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9239 gen_sshl_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9242 case 0x9: /* SQSHL, UQSHL */
9244 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9246 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9249 case 0xa: /* SRSHL, URSHL */
9251 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
9253 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
9256 case 0xb: /* SQRSHL, UQRSHL */
9258 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9260 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9263 case 0x10: /* ADD, SUB */
9265 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9267 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9271 g_assert_not_reached();
9275 /* Handle the 3-same-operands float operations; shared by the scalar
9276 * and vector encodings. The caller must filter out any encodings
9277 * not allocated for the encoding it is dealing with.
9279 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
9280 int fpopcode
, int rd
, int rn
, int rm
)
9283 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
9285 for (pass
= 0; pass
< elements
; pass
++) {
9288 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9289 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9290 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9292 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9293 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9296 case 0x39: /* FMLS */
9297 /* As usual for ARM, separate negation for fused multiply-add */
9298 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
9300 case 0x19: /* FMLA */
9301 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9302 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
9305 case 0x18: /* FMAXNM */
9306 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9308 case 0x1a: /* FADD */
9309 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9311 case 0x1b: /* FMULX */
9312 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9314 case 0x1c: /* FCMEQ */
9315 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9317 case 0x1e: /* FMAX */
9318 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9320 case 0x1f: /* FRECPS */
9321 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9323 case 0x38: /* FMINNM */
9324 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9326 case 0x3a: /* FSUB */
9327 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9329 case 0x3e: /* FMIN */
9330 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9332 case 0x3f: /* FRSQRTS */
9333 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9335 case 0x5b: /* FMUL */
9336 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9338 case 0x5c: /* FCMGE */
9339 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9341 case 0x5d: /* FACGE */
9342 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9344 case 0x5f: /* FDIV */
9345 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9347 case 0x7a: /* FABD */
9348 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9349 gen_helper_vfp_absd(tcg_res
, tcg_res
);
9351 case 0x7c: /* FCMGT */
9352 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9354 case 0x7d: /* FACGT */
9355 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9358 g_assert_not_reached();
9361 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9363 tcg_temp_free_i64(tcg_res
);
9364 tcg_temp_free_i64(tcg_op1
);
9365 tcg_temp_free_i64(tcg_op2
);
9368 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9369 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9370 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9372 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
9373 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
9376 case 0x39: /* FMLS */
9377 /* As usual for ARM, separate negation for fused multiply-add */
9378 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
9380 case 0x19: /* FMLA */
9381 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9382 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
9385 case 0x1a: /* FADD */
9386 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9388 case 0x1b: /* FMULX */
9389 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9391 case 0x1c: /* FCMEQ */
9392 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9394 case 0x1e: /* FMAX */
9395 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9397 case 0x1f: /* FRECPS */
9398 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9400 case 0x18: /* FMAXNM */
9401 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9403 case 0x38: /* FMINNM */
9404 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9406 case 0x3a: /* FSUB */
9407 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9409 case 0x3e: /* FMIN */
9410 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9412 case 0x3f: /* FRSQRTS */
9413 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9415 case 0x5b: /* FMUL */
9416 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9418 case 0x5c: /* FCMGE */
9419 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9421 case 0x5d: /* FACGE */
9422 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9424 case 0x5f: /* FDIV */
9425 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9427 case 0x7a: /* FABD */
9428 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9429 gen_helper_vfp_abss(tcg_res
, tcg_res
);
9431 case 0x7c: /* FCMGT */
9432 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9434 case 0x7d: /* FACGT */
9435 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9438 g_assert_not_reached();
9441 if (elements
== 1) {
9442 /* scalar single so clear high part */
9443 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9445 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
9446 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
9447 tcg_temp_free_i64(tcg_tmp
);
9449 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9452 tcg_temp_free_i32(tcg_res
);
9453 tcg_temp_free_i32(tcg_op1
);
9454 tcg_temp_free_i32(tcg_op2
);
9458 tcg_temp_free_ptr(fpst
);
9460 clear_vec_high(s
, elements
* (size
? 8 : 4) > 8, rd
);
9463 /* AdvSIMD scalar three same
9464 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
9465 * +-----+---+-----------+------+---+------+--------+---+------+------+
9466 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
9467 * +-----+---+-----------+------+---+------+--------+---+------+------+
9469 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
9471 int rd
= extract32(insn
, 0, 5);
9472 int rn
= extract32(insn
, 5, 5);
9473 int opcode
= extract32(insn
, 11, 5);
9474 int rm
= extract32(insn
, 16, 5);
9475 int size
= extract32(insn
, 22, 2);
9476 bool u
= extract32(insn
, 29, 1);
9479 if (opcode
>= 0x18) {
9480 /* Floating point: U, size[1] and opcode indicate operation */
9481 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
9483 case 0x1b: /* FMULX */
9484 case 0x1f: /* FRECPS */
9485 case 0x3f: /* FRSQRTS */
9486 case 0x5d: /* FACGE */
9487 case 0x7d: /* FACGT */
9488 case 0x1c: /* FCMEQ */
9489 case 0x5c: /* FCMGE */
9490 case 0x7c: /* FCMGT */
9491 case 0x7a: /* FABD */
9494 unallocated_encoding(s
);
9498 if (!fp_access_check(s
)) {
9502 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
9507 case 0x1: /* SQADD, UQADD */
9508 case 0x5: /* SQSUB, UQSUB */
9509 case 0x9: /* SQSHL, UQSHL */
9510 case 0xb: /* SQRSHL, UQRSHL */
9512 case 0x8: /* SSHL, USHL */
9513 case 0xa: /* SRSHL, URSHL */
9514 case 0x6: /* CMGT, CMHI */
9515 case 0x7: /* CMGE, CMHS */
9516 case 0x11: /* CMTST, CMEQ */
9517 case 0x10: /* ADD, SUB (vector) */
9519 unallocated_encoding(s
);
9523 case 0x16: /* SQDMULH, SQRDMULH (vector) */
9524 if (size
!= 1 && size
!= 2) {
9525 unallocated_encoding(s
);
9530 unallocated_encoding(s
);
9534 if (!fp_access_check(s
)) {
9538 tcg_rd
= tcg_temp_new_i64();
9541 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
9542 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
9544 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
9545 tcg_temp_free_i64(tcg_rn
);
9546 tcg_temp_free_i64(tcg_rm
);
9548 /* Do a single operation on the lowest element in the vector.
9549 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
9550 * no side effects for all these operations.
9551 * OPTME: special-purpose helpers would avoid doing some
9552 * unnecessary work in the helper for the 8 and 16 bit cases.
9554 NeonGenTwoOpEnvFn
*genenvfn
;
9555 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9556 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
9557 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
9559 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
9560 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
9563 case 0x1: /* SQADD, UQADD */
9565 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9566 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9567 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9568 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9570 genenvfn
= fns
[size
][u
];
9573 case 0x5: /* SQSUB, UQSUB */
9575 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9576 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9577 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9578 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9580 genenvfn
= fns
[size
][u
];
9583 case 0x9: /* SQSHL, UQSHL */
9585 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9586 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9587 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9588 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9590 genenvfn
= fns
[size
][u
];
9593 case 0xb: /* SQRSHL, UQRSHL */
9595 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9596 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9597 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9598 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9600 genenvfn
= fns
[size
][u
];
9603 case 0x16: /* SQDMULH, SQRDMULH */
9605 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9606 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9607 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9609 assert(size
== 1 || size
== 2);
9610 genenvfn
= fns
[size
- 1][u
];
9614 g_assert_not_reached();
9617 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
9618 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
9619 tcg_temp_free_i32(tcg_rd32
);
9620 tcg_temp_free_i32(tcg_rn
);
9621 tcg_temp_free_i32(tcg_rm
);
9624 write_fp_dreg(s
, rd
, tcg_rd
);
9626 tcg_temp_free_i64(tcg_rd
);
9629 /* AdvSIMD scalar three same FP16
9630 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
9631 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9632 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
9633 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9634 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
9635 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
9637 static void disas_simd_scalar_three_reg_same_fp16(DisasContext
*s
,
9640 int rd
= extract32(insn
, 0, 5);
9641 int rn
= extract32(insn
, 5, 5);
9642 int opcode
= extract32(insn
, 11, 3);
9643 int rm
= extract32(insn
, 16, 5);
9644 bool u
= extract32(insn
, 29, 1);
9645 bool a
= extract32(insn
, 23, 1);
9646 int fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
9653 case 0x03: /* FMULX */
9654 case 0x04: /* FCMEQ (reg) */
9655 case 0x07: /* FRECPS */
9656 case 0x0f: /* FRSQRTS */
9657 case 0x14: /* FCMGE (reg) */
9658 case 0x15: /* FACGE */
9659 case 0x1a: /* FABD */
9660 case 0x1c: /* FCMGT (reg) */
9661 case 0x1d: /* FACGT */
9664 unallocated_encoding(s
);
9668 if (!dc_isar_feature(aa64_fp16
, s
)) {
9669 unallocated_encoding(s
);
9672 if (!fp_access_check(s
)) {
9676 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
9678 tcg_op1
= read_fp_hreg(s
, rn
);
9679 tcg_op2
= read_fp_hreg(s
, rm
);
9680 tcg_res
= tcg_temp_new_i32();
9683 case 0x03: /* FMULX */
9684 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9686 case 0x04: /* FCMEQ (reg) */
9687 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9689 case 0x07: /* FRECPS */
9690 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9692 case 0x0f: /* FRSQRTS */
9693 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9695 case 0x14: /* FCMGE (reg) */
9696 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9698 case 0x15: /* FACGE */
9699 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9701 case 0x1a: /* FABD */
9702 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9703 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
9705 case 0x1c: /* FCMGT (reg) */
9706 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9708 case 0x1d: /* FACGT */
9709 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9712 g_assert_not_reached();
9715 write_fp_sreg(s
, rd
, tcg_res
);
9718 tcg_temp_free_i32(tcg_res
);
9719 tcg_temp_free_i32(tcg_op1
);
9720 tcg_temp_free_i32(tcg_op2
);
9721 tcg_temp_free_ptr(fpst
);
9724 /* AdvSIMD scalar three same extra
9725 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
9726 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9727 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
9728 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9730 static void disas_simd_scalar_three_reg_same_extra(DisasContext
*s
,
9733 int rd
= extract32(insn
, 0, 5);
9734 int rn
= extract32(insn
, 5, 5);
9735 int opcode
= extract32(insn
, 11, 4);
9736 int rm
= extract32(insn
, 16, 5);
9737 int size
= extract32(insn
, 22, 2);
9738 bool u
= extract32(insn
, 29, 1);
9739 TCGv_i32 ele1
, ele2
, ele3
;
9743 switch (u
* 16 + opcode
) {
9744 case 0x10: /* SQRDMLAH (vector) */
9745 case 0x11: /* SQRDMLSH (vector) */
9746 if (size
!= 1 && size
!= 2) {
9747 unallocated_encoding(s
);
9750 feature
= dc_isar_feature(aa64_rdm
, s
);
9753 unallocated_encoding(s
);
9757 unallocated_encoding(s
);
9760 if (!fp_access_check(s
)) {
9764 /* Do a single operation on the lowest element in the vector.
9765 * We use the standard Neon helpers and rely on 0 OP 0 == 0
9766 * with no side effects for all these operations.
9767 * OPTME: special-purpose helpers would avoid doing some
9768 * unnecessary work in the helper for the 16 bit cases.
9770 ele1
= tcg_temp_new_i32();
9771 ele2
= tcg_temp_new_i32();
9772 ele3
= tcg_temp_new_i32();
9774 read_vec_element_i32(s
, ele1
, rn
, 0, size
);
9775 read_vec_element_i32(s
, ele2
, rm
, 0, size
);
9776 read_vec_element_i32(s
, ele3
, rd
, 0, size
);
9779 case 0x0: /* SQRDMLAH */
9781 gen_helper_neon_qrdmlah_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9783 gen_helper_neon_qrdmlah_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9786 case 0x1: /* SQRDMLSH */
9788 gen_helper_neon_qrdmlsh_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9790 gen_helper_neon_qrdmlsh_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9794 g_assert_not_reached();
9796 tcg_temp_free_i32(ele1
);
9797 tcg_temp_free_i32(ele2
);
9799 res
= tcg_temp_new_i64();
9800 tcg_gen_extu_i32_i64(res
, ele3
);
9801 tcg_temp_free_i32(ele3
);
9803 write_fp_dreg(s
, rd
, res
);
9804 tcg_temp_free_i64(res
);
9807 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
9808 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
9809 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
9811 /* Handle 64->64 opcodes which are shared between the scalar and
9812 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
9813 * is valid in either group and also the double-precision fp ops.
9814 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
9820 case 0x4: /* CLS, CLZ */
9822 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
9824 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
9828 /* This opcode is shared with CNT and RBIT but we have earlier
9829 * enforced that size == 3 if and only if this is the NOT insn.
9831 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
9833 case 0x7: /* SQABS, SQNEG */
9835 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
9837 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
9840 case 0xa: /* CMLT */
9841 /* 64 bit integer comparison against zero, result is
9842 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
9847 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
9848 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
9850 case 0x8: /* CMGT, CMGE */
9851 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
9853 case 0x9: /* CMEQ, CMLE */
9854 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
9856 case 0xb: /* ABS, NEG */
9858 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
9860 tcg_gen_abs_i64(tcg_rd
, tcg_rn
);
9863 case 0x2f: /* FABS */
9864 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
9866 case 0x6f: /* FNEG */
9867 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
9869 case 0x7f: /* FSQRT */
9870 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
9872 case 0x1a: /* FCVTNS */
9873 case 0x1b: /* FCVTMS */
9874 case 0x1c: /* FCVTAS */
9875 case 0x3a: /* FCVTPS */
9876 case 0x3b: /* FCVTZS */
9877 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_constant_i32(0), tcg_fpstatus
);
9879 case 0x5a: /* FCVTNU */
9880 case 0x5b: /* FCVTMU */
9881 case 0x5c: /* FCVTAU */
9882 case 0x7a: /* FCVTPU */
9883 case 0x7b: /* FCVTZU */
9884 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_constant_i32(0), tcg_fpstatus
);
9886 case 0x18: /* FRINTN */
9887 case 0x19: /* FRINTM */
9888 case 0x38: /* FRINTP */
9889 case 0x39: /* FRINTZ */
9890 case 0x58: /* FRINTA */
9891 case 0x79: /* FRINTI */
9892 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9894 case 0x59: /* FRINTX */
9895 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9897 case 0x1e: /* FRINT32Z */
9898 case 0x5e: /* FRINT32X */
9899 gen_helper_frint32_d(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9901 case 0x1f: /* FRINT64Z */
9902 case 0x5f: /* FRINT64X */
9903 gen_helper_frint64_d(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9906 g_assert_not_reached();
9910 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
9911 bool is_scalar
, bool is_u
, bool is_q
,
9912 int size
, int rn
, int rd
)
9914 bool is_double
= (size
== MO_64
);
9917 if (!fp_access_check(s
)) {
9921 fpst
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
9924 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9925 TCGv_i64 tcg_zero
= tcg_constant_i64(0);
9926 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9927 NeonGenTwoDoubleOpFn
*genfn
;
9932 case 0x2e: /* FCMLT (zero) */
9935 case 0x2c: /* FCMGT (zero) */
9936 genfn
= gen_helper_neon_cgt_f64
;
9938 case 0x2d: /* FCMEQ (zero) */
9939 genfn
= gen_helper_neon_ceq_f64
;
9941 case 0x6d: /* FCMLE (zero) */
9944 case 0x6c: /* FCMGE (zero) */
9945 genfn
= gen_helper_neon_cge_f64
;
9948 g_assert_not_reached();
9951 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9952 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9954 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
9956 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
9958 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9960 tcg_temp_free_i64(tcg_res
);
9961 tcg_temp_free_i64(tcg_op
);
9963 clear_vec_high(s
, !is_scalar
, rd
);
9965 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9966 TCGv_i32 tcg_zero
= tcg_constant_i32(0);
9967 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9968 NeonGenTwoSingleOpFn
*genfn
;
9970 int pass
, maxpasses
;
9972 if (size
== MO_16
) {
9974 case 0x2e: /* FCMLT (zero) */
9977 case 0x2c: /* FCMGT (zero) */
9978 genfn
= gen_helper_advsimd_cgt_f16
;
9980 case 0x2d: /* FCMEQ (zero) */
9981 genfn
= gen_helper_advsimd_ceq_f16
;
9983 case 0x6d: /* FCMLE (zero) */
9986 case 0x6c: /* FCMGE (zero) */
9987 genfn
= gen_helper_advsimd_cge_f16
;
9990 g_assert_not_reached();
9994 case 0x2e: /* FCMLT (zero) */
9997 case 0x2c: /* FCMGT (zero) */
9998 genfn
= gen_helper_neon_cgt_f32
;
10000 case 0x2d: /* FCMEQ (zero) */
10001 genfn
= gen_helper_neon_ceq_f32
;
10003 case 0x6d: /* FCMLE (zero) */
10006 case 0x6c: /* FCMGE (zero) */
10007 genfn
= gen_helper_neon_cge_f32
;
10010 g_assert_not_reached();
10017 int vector_size
= 8 << is_q
;
10018 maxpasses
= vector_size
>> size
;
10021 for (pass
= 0; pass
< maxpasses
; pass
++) {
10022 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10024 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
10026 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
10029 write_fp_sreg(s
, rd
, tcg_res
);
10031 write_vec_element_i32(s
, tcg_res
, rd
, pass
, size
);
10034 tcg_temp_free_i32(tcg_res
);
10035 tcg_temp_free_i32(tcg_op
);
10037 clear_vec_high(s
, is_q
, rd
);
10041 tcg_temp_free_ptr(fpst
);
10044 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
10045 bool is_scalar
, bool is_u
, bool is_q
,
10046 int size
, int rn
, int rd
)
10048 bool is_double
= (size
== 3);
10049 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
10052 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10053 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10056 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10057 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10059 case 0x3d: /* FRECPE */
10060 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
10062 case 0x3f: /* FRECPX */
10063 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
10065 case 0x7d: /* FRSQRTE */
10066 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
10069 g_assert_not_reached();
10071 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10073 tcg_temp_free_i64(tcg_res
);
10074 tcg_temp_free_i64(tcg_op
);
10075 clear_vec_high(s
, !is_scalar
, rd
);
10077 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10078 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10079 int pass
, maxpasses
;
10084 maxpasses
= is_q
? 4 : 2;
10087 for (pass
= 0; pass
< maxpasses
; pass
++) {
10088 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
10091 case 0x3c: /* URECPE */
10092 gen_helper_recpe_u32(tcg_res
, tcg_op
);
10094 case 0x3d: /* FRECPE */
10095 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
10097 case 0x3f: /* FRECPX */
10098 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
10100 case 0x7d: /* FRSQRTE */
10101 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
10104 g_assert_not_reached();
10108 write_fp_sreg(s
, rd
, tcg_res
);
10110 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10113 tcg_temp_free_i32(tcg_res
);
10114 tcg_temp_free_i32(tcg_op
);
10116 clear_vec_high(s
, is_q
, rd
);
10119 tcg_temp_free_ptr(fpst
);
10122 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
10123 int opcode
, bool u
, bool is_q
,
10124 int size
, int rn
, int rd
)
10126 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
10127 * in the source becomes a size element in the destination).
10130 TCGv_i32 tcg_res
[2];
10131 int destelt
= is_q
? 2 : 0;
10132 int passes
= scalar
? 1 : 2;
10135 tcg_res
[1] = tcg_constant_i32(0);
10138 for (pass
= 0; pass
< passes
; pass
++) {
10139 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10140 NeonGenNarrowFn
*genfn
= NULL
;
10141 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
10144 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
10146 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10148 tcg_res
[pass
] = tcg_temp_new_i32();
10151 case 0x12: /* XTN, SQXTUN */
10153 static NeonGenNarrowFn
* const xtnfns
[3] = {
10154 gen_helper_neon_narrow_u8
,
10155 gen_helper_neon_narrow_u16
,
10156 tcg_gen_extrl_i64_i32
,
10158 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
10159 gen_helper_neon_unarrow_sat8
,
10160 gen_helper_neon_unarrow_sat16
,
10161 gen_helper_neon_unarrow_sat32
,
10164 genenvfn
= sqxtunfns
[size
];
10166 genfn
= xtnfns
[size
];
10170 case 0x14: /* SQXTN, UQXTN */
10172 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
10173 { gen_helper_neon_narrow_sat_s8
,
10174 gen_helper_neon_narrow_sat_u8
},
10175 { gen_helper_neon_narrow_sat_s16
,
10176 gen_helper_neon_narrow_sat_u16
},
10177 { gen_helper_neon_narrow_sat_s32
,
10178 gen_helper_neon_narrow_sat_u32
},
10180 genenvfn
= fns
[size
][u
];
10183 case 0x16: /* FCVTN, FCVTN2 */
10184 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
10186 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
10188 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
10189 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
10190 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
10191 TCGv_i32 ahp
= get_ahp_flag();
10193 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
10194 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, fpst
, ahp
);
10195 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, fpst
, ahp
);
10196 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
10197 tcg_temp_free_i32(tcg_lo
);
10198 tcg_temp_free_i32(tcg_hi
);
10199 tcg_temp_free_ptr(fpst
);
10200 tcg_temp_free_i32(ahp
);
10203 case 0x36: /* BFCVTN, BFCVTN2 */
10205 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
10206 gen_helper_bfcvt_pair(tcg_res
[pass
], tcg_op
, fpst
);
10207 tcg_temp_free_ptr(fpst
);
10210 case 0x56: /* FCVTXN, FCVTXN2 */
10211 /* 64 bit to 32 bit float conversion
10212 * with von Neumann rounding (round to odd)
10215 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
10218 g_assert_not_reached();
10222 genfn(tcg_res
[pass
], tcg_op
);
10223 } else if (genenvfn
) {
10224 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
10227 tcg_temp_free_i64(tcg_op
);
10230 for (pass
= 0; pass
< 2; pass
++) {
10231 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
10232 tcg_temp_free_i32(tcg_res
[pass
]);
10234 clear_vec_high(s
, is_q
, rd
);
10237 /* Remaining saturating accumulating ops */
10238 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
10239 bool is_q
, int size
, int rn
, int rd
)
10241 bool is_double
= (size
== 3);
10244 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
10245 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
10248 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10249 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
10250 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
10252 if (is_u
) { /* USQADD */
10253 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10254 } else { /* SUQADD */
10255 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10257 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
10259 tcg_temp_free_i64(tcg_rd
);
10260 tcg_temp_free_i64(tcg_rn
);
10261 clear_vec_high(s
, !is_scalar
, rd
);
10263 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
10264 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
10265 int pass
, maxpasses
;
10270 maxpasses
= is_q
? 4 : 2;
10273 for (pass
= 0; pass
< maxpasses
; pass
++) {
10275 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
10276 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
10278 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
10279 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
10282 if (is_u
) { /* USQADD */
10285 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10288 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10291 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10294 g_assert_not_reached();
10296 } else { /* SUQADD */
10299 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10302 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10305 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10308 g_assert_not_reached();
10313 write_vec_element(s
, tcg_constant_i64(0), rd
, 0, MO_64
);
10315 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
10317 tcg_temp_free_i32(tcg_rd
);
10318 tcg_temp_free_i32(tcg_rn
);
10319 clear_vec_high(s
, is_q
, rd
);
10323 /* AdvSIMD scalar two reg misc
10324 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
10325 * +-----+---+-----------+------+-----------+--------+-----+------+------+
10326 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
10327 * +-----+---+-----------+------+-----------+--------+-----+------+------+
10329 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
10331 int rd
= extract32(insn
, 0, 5);
10332 int rn
= extract32(insn
, 5, 5);
10333 int opcode
= extract32(insn
, 12, 5);
10334 int size
= extract32(insn
, 22, 2);
10335 bool u
= extract32(insn
, 29, 1);
10336 bool is_fcvt
= false;
10338 TCGv_i32 tcg_rmode
;
10339 TCGv_ptr tcg_fpstatus
;
10342 case 0x3: /* USQADD / SUQADD*/
10343 if (!fp_access_check(s
)) {
10346 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
10348 case 0x7: /* SQABS / SQNEG */
10350 case 0xa: /* CMLT */
10352 unallocated_encoding(s
);
10356 case 0x8: /* CMGT, CMGE */
10357 case 0x9: /* CMEQ, CMLE */
10358 case 0xb: /* ABS, NEG */
10360 unallocated_encoding(s
);
10364 case 0x12: /* SQXTUN */
10366 unallocated_encoding(s
);
10370 case 0x14: /* SQXTN, UQXTN */
10372 unallocated_encoding(s
);
10375 if (!fp_access_check(s
)) {
10378 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
10381 case 0x16 ... 0x1d:
10383 /* Floating point: U, size[1] and opcode indicate operation;
10384 * size[0] indicates single or double precision.
10386 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
10387 size
= extract32(size
, 0, 1) ? 3 : 2;
10389 case 0x2c: /* FCMGT (zero) */
10390 case 0x2d: /* FCMEQ (zero) */
10391 case 0x2e: /* FCMLT (zero) */
10392 case 0x6c: /* FCMGE (zero) */
10393 case 0x6d: /* FCMLE (zero) */
10394 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
10396 case 0x1d: /* SCVTF */
10397 case 0x5d: /* UCVTF */
10399 bool is_signed
= (opcode
== 0x1d);
10400 if (!fp_access_check(s
)) {
10403 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
10406 case 0x3d: /* FRECPE */
10407 case 0x3f: /* FRECPX */
10408 case 0x7d: /* FRSQRTE */
10409 if (!fp_access_check(s
)) {
10412 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
10414 case 0x1a: /* FCVTNS */
10415 case 0x1b: /* FCVTMS */
10416 case 0x3a: /* FCVTPS */
10417 case 0x3b: /* FCVTZS */
10418 case 0x5a: /* FCVTNU */
10419 case 0x5b: /* FCVTMU */
10420 case 0x7a: /* FCVTPU */
10421 case 0x7b: /* FCVTZU */
10423 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
10425 case 0x1c: /* FCVTAS */
10426 case 0x5c: /* FCVTAU */
10427 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
10429 rmode
= FPROUNDING_TIEAWAY
;
10431 case 0x56: /* FCVTXN, FCVTXN2 */
10433 unallocated_encoding(s
);
10436 if (!fp_access_check(s
)) {
10439 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
10442 unallocated_encoding(s
);
10447 unallocated_encoding(s
);
10451 if (!fp_access_check(s
)) {
10456 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
10457 tcg_fpstatus
= fpstatus_ptr(FPST_FPCR
);
10458 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
10461 tcg_fpstatus
= NULL
;
10465 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
10466 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
10468 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
10469 write_fp_dreg(s
, rd
, tcg_rd
);
10470 tcg_temp_free_i64(tcg_rd
);
10471 tcg_temp_free_i64(tcg_rn
);
10473 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
10474 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
10476 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
10479 case 0x7: /* SQABS, SQNEG */
10481 NeonGenOneOpEnvFn
*genfn
;
10482 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
10483 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
10484 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
10485 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
10487 genfn
= fns
[size
][u
];
10488 genfn(tcg_rd
, cpu_env
, tcg_rn
);
10491 case 0x1a: /* FCVTNS */
10492 case 0x1b: /* FCVTMS */
10493 case 0x1c: /* FCVTAS */
10494 case 0x3a: /* FCVTPS */
10495 case 0x3b: /* FCVTZS */
10496 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_constant_i32(0),
10499 case 0x5a: /* FCVTNU */
10500 case 0x5b: /* FCVTMU */
10501 case 0x5c: /* FCVTAU */
10502 case 0x7a: /* FCVTPU */
10503 case 0x7b: /* FCVTZU */
10504 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_constant_i32(0),
10508 g_assert_not_reached();
10511 write_fp_sreg(s
, rd
, tcg_rd
);
10512 tcg_temp_free_i32(tcg_rd
);
10513 tcg_temp_free_i32(tcg_rn
);
10517 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
10518 tcg_temp_free_i32(tcg_rmode
);
10519 tcg_temp_free_ptr(tcg_fpstatus
);
10523 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
10524 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
10525 int immh
, int immb
, int opcode
, int rn
, int rd
)
10527 int size
= 32 - clz32(immh
) - 1;
10528 int immhb
= immh
<< 3 | immb
;
10529 int shift
= 2 * (8 << size
) - immhb
;
10530 GVecGen2iFn
*gvec_fn
;
10532 if (extract32(immh
, 3, 1) && !is_q
) {
10533 unallocated_encoding(s
);
10536 tcg_debug_assert(size
<= 3);
10538 if (!fp_access_check(s
)) {
10543 case 0x02: /* SSRA / USRA (accumulate) */
10544 gvec_fn
= is_u
? gen_gvec_usra
: gen_gvec_ssra
;
10547 case 0x08: /* SRI */
10548 gvec_fn
= gen_gvec_sri
;
10551 case 0x00: /* SSHR / USHR */
10553 if (shift
== 8 << size
) {
10554 /* Shift count the same size as element size produces zero. */
10555 tcg_gen_gvec_dup_imm(size
, vec_full_reg_offset(s
, rd
),
10556 is_q
? 16 : 8, vec_full_reg_size(s
), 0);
10559 gvec_fn
= tcg_gen_gvec_shri
;
10561 /* Shift count the same size as element size produces all sign. */
10562 if (shift
== 8 << size
) {
10565 gvec_fn
= tcg_gen_gvec_sari
;
10569 case 0x04: /* SRSHR / URSHR (rounding) */
10570 gvec_fn
= is_u
? gen_gvec_urshr
: gen_gvec_srshr
;
10573 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10574 gvec_fn
= is_u
? gen_gvec_ursra
: gen_gvec_srsra
;
10578 g_assert_not_reached();
10581 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, gvec_fn
, size
);
10584 /* SHL/SLI - Vector shift left */
10585 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
10586 int immh
, int immb
, int opcode
, int rn
, int rd
)
10588 int size
= 32 - clz32(immh
) - 1;
10589 int immhb
= immh
<< 3 | immb
;
10590 int shift
= immhb
- (8 << size
);
10592 /* Range of size is limited by decode: immh is a non-zero 4 bit field */
10593 assert(size
>= 0 && size
<= 3);
10595 if (extract32(immh
, 3, 1) && !is_q
) {
10596 unallocated_encoding(s
);
10600 if (!fp_access_check(s
)) {
10605 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, gen_gvec_sli
, size
);
10607 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shli
, size
);
10611 /* USHLL/SHLL - Vector shift left with widening */
10612 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
10613 int immh
, int immb
, int opcode
, int rn
, int rd
)
10615 int size
= 32 - clz32(immh
) - 1;
10616 int immhb
= immh
<< 3 | immb
;
10617 int shift
= immhb
- (8 << size
);
10619 int esize
= 8 << size
;
10620 int elements
= dsize
/esize
;
10621 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
10622 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
10626 unallocated_encoding(s
);
10630 if (!fp_access_check(s
)) {
10634 /* For the LL variants the store is larger than the load,
10635 * so if rd == rn we would overwrite parts of our input.
10636 * So load everything right now and use shifts in the main loop.
10638 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
10640 for (i
= 0; i
< elements
; i
++) {
10641 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
10642 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
10643 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
10644 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
10648 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
10649 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
10650 int immh
, int immb
, int opcode
, int rn
, int rd
)
10652 int immhb
= immh
<< 3 | immb
;
10653 int size
= 32 - clz32(immh
) - 1;
10655 int esize
= 8 << size
;
10656 int elements
= dsize
/esize
;
10657 int shift
= (2 * esize
) - immhb
;
10658 bool round
= extract32(opcode
, 0, 1);
10659 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
10660 TCGv_i64 tcg_round
;
10663 if (extract32(immh
, 3, 1)) {
10664 unallocated_encoding(s
);
10668 if (!fp_access_check(s
)) {
10672 tcg_rn
= tcg_temp_new_i64();
10673 tcg_rd
= tcg_temp_new_i64();
10674 tcg_final
= tcg_temp_new_i64();
10675 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
10678 tcg_round
= tcg_constant_i64(1ULL << (shift
- 1));
10683 for (i
= 0; i
< elements
; i
++) {
10684 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
10685 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
10686 false, true, size
+1, shift
);
10688 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
10692 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
10694 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
10696 tcg_temp_free_i64(tcg_rn
);
10697 tcg_temp_free_i64(tcg_rd
);
10698 tcg_temp_free_i64(tcg_final
);
10700 clear_vec_high(s
, is_q
, rd
);
10704 /* AdvSIMD shift by immediate
10705 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
10706 * +---+---+---+-------------+------+------+--------+---+------+------+
10707 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
10708 * +---+---+---+-------------+------+------+--------+---+------+------+
10710 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
10712 int rd
= extract32(insn
, 0, 5);
10713 int rn
= extract32(insn
, 5, 5);
10714 int opcode
= extract32(insn
, 11, 5);
10715 int immb
= extract32(insn
, 16, 3);
10716 int immh
= extract32(insn
, 19, 4);
10717 bool is_u
= extract32(insn
, 29, 1);
10718 bool is_q
= extract32(insn
, 30, 1);
10720 /* data_proc_simd[] has sent immh == 0 to disas_simd_mod_imm. */
10724 case 0x08: /* SRI */
10726 unallocated_encoding(s
);
10730 case 0x00: /* SSHR / USHR */
10731 case 0x02: /* SSRA / USRA (accumulate) */
10732 case 0x04: /* SRSHR / URSHR (rounding) */
10733 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10734 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10736 case 0x0a: /* SHL / SLI */
10737 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10739 case 0x10: /* SHRN */
10740 case 0x11: /* RSHRN / SQRSHRUN */
10742 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
10745 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
10748 case 0x12: /* SQSHRN / UQSHRN */
10749 case 0x13: /* SQRSHRN / UQRSHRN */
10750 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
10753 case 0x14: /* SSHLL / USHLL */
10754 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10756 case 0x1c: /* SCVTF / UCVTF */
10757 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
10760 case 0xc: /* SQSHLU */
10762 unallocated_encoding(s
);
10765 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
10767 case 0xe: /* SQSHL, UQSHL */
10768 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
10770 case 0x1f: /* FCVTZS/ FCVTZU */
10771 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
10774 unallocated_encoding(s
);
10779 /* Generate code to do a "long" addition or subtraction, ie one done in
10780 * TCGv_i64 on vector lanes twice the width specified by size.
10782 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
10783 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
10785 static NeonGenTwo64OpFn
* const fns
[3][2] = {
10786 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
10787 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
10788 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
10790 NeonGenTwo64OpFn
*genfn
;
10793 genfn
= fns
[size
][is_sub
];
10794 genfn(tcg_res
, tcg_op1
, tcg_op2
);
10797 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
10798 int opcode
, int rd
, int rn
, int rm
)
10800 /* 3-reg-different widening insns: 64 x 64 -> 128 */
10801 TCGv_i64 tcg_res
[2];
10804 tcg_res
[0] = tcg_temp_new_i64();
10805 tcg_res
[1] = tcg_temp_new_i64();
10807 /* Does this op do an adding accumulate, a subtracting accumulate,
10808 * or no accumulate at all?
10826 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10827 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10830 /* size == 2 means two 32x32->64 operations; this is worth special
10831 * casing because we can generally handle it inline.
10834 for (pass
= 0; pass
< 2; pass
++) {
10835 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10836 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10837 TCGv_i64 tcg_passres
;
10838 MemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
10840 int elt
= pass
+ is_q
* 2;
10842 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
10843 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
10846 tcg_passres
= tcg_res
[pass
];
10848 tcg_passres
= tcg_temp_new_i64();
10852 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10853 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10855 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10856 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10858 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10859 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10861 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
10862 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
10864 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
10865 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
10866 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
10868 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
10869 tcg_temp_free_i64(tcg_tmp1
);
10870 tcg_temp_free_i64(tcg_tmp2
);
10873 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10874 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10875 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10876 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10878 case 9: /* SQDMLAL, SQDMLAL2 */
10879 case 11: /* SQDMLSL, SQDMLSL2 */
10880 case 13: /* SQDMULL, SQDMULL2 */
10881 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10882 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10883 tcg_passres
, tcg_passres
);
10886 g_assert_not_reached();
10889 if (opcode
== 9 || opcode
== 11) {
10890 /* saturating accumulate ops */
10892 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10894 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10895 tcg_res
[pass
], tcg_passres
);
10896 } else if (accop
> 0) {
10897 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10898 } else if (accop
< 0) {
10899 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10903 tcg_temp_free_i64(tcg_passres
);
10906 tcg_temp_free_i64(tcg_op1
);
10907 tcg_temp_free_i64(tcg_op2
);
10910 /* size 0 or 1, generally helper functions */
10911 for (pass
= 0; pass
< 2; pass
++) {
10912 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10913 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10914 TCGv_i64 tcg_passres
;
10915 int elt
= pass
+ is_q
* 2;
10917 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
10918 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
10921 tcg_passres
= tcg_res
[pass
];
10923 tcg_passres
= tcg_temp_new_i64();
10927 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10928 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10930 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
10931 static NeonGenWidenFn
* const widenfns
[2][2] = {
10932 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10933 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10935 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10937 widenfn(tcg_op2_64
, tcg_op2
);
10938 widenfn(tcg_passres
, tcg_op1
);
10939 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
10940 tcg_passres
, tcg_op2_64
);
10941 tcg_temp_free_i64(tcg_op2_64
);
10944 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10945 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10948 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10950 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10954 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
10956 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
10960 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10961 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10962 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10965 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
10967 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
10971 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10973 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10977 case 9: /* SQDMLAL, SQDMLAL2 */
10978 case 11: /* SQDMLSL, SQDMLSL2 */
10979 case 13: /* SQDMULL, SQDMULL2 */
10981 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10982 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10983 tcg_passres
, tcg_passres
);
10986 g_assert_not_reached();
10988 tcg_temp_free_i32(tcg_op1
);
10989 tcg_temp_free_i32(tcg_op2
);
10992 if (opcode
== 9 || opcode
== 11) {
10993 /* saturating accumulate ops */
10995 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10997 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
11001 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
11002 tcg_res
[pass
], tcg_passres
);
11004 tcg_temp_free_i64(tcg_passres
);
11009 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
11010 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
11011 tcg_temp_free_i64(tcg_res
[0]);
11012 tcg_temp_free_i64(tcg_res
[1]);
11015 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
11016 int opcode
, int rd
, int rn
, int rm
)
11018 TCGv_i64 tcg_res
[2];
11019 int part
= is_q
? 2 : 0;
11022 for (pass
= 0; pass
< 2; pass
++) {
11023 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11024 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11025 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
11026 static NeonGenWidenFn
* const widenfns
[3][2] = {
11027 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
11028 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
11029 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
11031 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
11033 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11034 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
11035 widenfn(tcg_op2_wide
, tcg_op2
);
11036 tcg_temp_free_i32(tcg_op2
);
11037 tcg_res
[pass
] = tcg_temp_new_i64();
11038 gen_neon_addl(size
, (opcode
== 3),
11039 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
11040 tcg_temp_free_i64(tcg_op1
);
11041 tcg_temp_free_i64(tcg_op2_wide
);
11044 for (pass
= 0; pass
< 2; pass
++) {
11045 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11046 tcg_temp_free_i64(tcg_res
[pass
]);
11050 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
11052 tcg_gen_addi_i64(in
, in
, 1U << 31);
11053 tcg_gen_extrh_i64_i32(res
, in
);
11056 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
11057 int opcode
, int rd
, int rn
, int rm
)
11059 TCGv_i32 tcg_res
[2];
11060 int part
= is_q
? 2 : 0;
11063 for (pass
= 0; pass
< 2; pass
++) {
11064 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11065 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11066 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
11067 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
11068 { gen_helper_neon_narrow_high_u8
,
11069 gen_helper_neon_narrow_round_high_u8
},
11070 { gen_helper_neon_narrow_high_u16
,
11071 gen_helper_neon_narrow_round_high_u16
},
11072 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
11074 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
11076 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11077 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
11079 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
11081 tcg_temp_free_i64(tcg_op1
);
11082 tcg_temp_free_i64(tcg_op2
);
11084 tcg_res
[pass
] = tcg_temp_new_i32();
11085 gennarrow(tcg_res
[pass
], tcg_wideres
);
11086 tcg_temp_free_i64(tcg_wideres
);
11089 for (pass
= 0; pass
< 2; pass
++) {
11090 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
11091 tcg_temp_free_i32(tcg_res
[pass
]);
11093 clear_vec_high(s
, is_q
, rd
);
11096 /* AdvSIMD three different
11097 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
11098 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
11099 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
11100 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
11102 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
11104 /* Instructions in this group fall into three basic classes
11105 * (in each case with the operation working on each element in
11106 * the input vectors):
11107 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
11109 * (2) wide 64 x 128 -> 128
11110 * (3) narrowing 128 x 128 -> 64
11111 * Here we do initial decode, catch unallocated cases and
11112 * dispatch to separate functions for each class.
11114 int is_q
= extract32(insn
, 30, 1);
11115 int is_u
= extract32(insn
, 29, 1);
11116 int size
= extract32(insn
, 22, 2);
11117 int opcode
= extract32(insn
, 12, 4);
11118 int rm
= extract32(insn
, 16, 5);
11119 int rn
= extract32(insn
, 5, 5);
11120 int rd
= extract32(insn
, 0, 5);
11123 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
11124 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
11125 /* 64 x 128 -> 128 */
11127 unallocated_encoding(s
);
11130 if (!fp_access_check(s
)) {
11133 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
11135 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
11136 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
11137 /* 128 x 128 -> 64 */
11139 unallocated_encoding(s
);
11142 if (!fp_access_check(s
)) {
11145 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
11147 case 14: /* PMULL, PMULL2 */
11149 unallocated_encoding(s
);
11153 case 0: /* PMULL.P8 */
11154 if (!fp_access_check(s
)) {
11157 /* The Q field specifies lo/hi half input for this insn. */
11158 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, is_q
,
11159 gen_helper_neon_pmull_h
);
11162 case 3: /* PMULL.P64 */
11163 if (!dc_isar_feature(aa64_pmull
, s
)) {
11164 unallocated_encoding(s
);
11167 if (!fp_access_check(s
)) {
11170 /* The Q field specifies lo/hi half input for this insn. */
11171 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, is_q
,
11172 gen_helper_gvec_pmull_q
);
11176 unallocated_encoding(s
);
11180 case 9: /* SQDMLAL, SQDMLAL2 */
11181 case 11: /* SQDMLSL, SQDMLSL2 */
11182 case 13: /* SQDMULL, SQDMULL2 */
11183 if (is_u
|| size
== 0) {
11184 unallocated_encoding(s
);
11188 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
11189 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
11190 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
11191 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
11192 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
11193 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
11194 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
11195 /* 64 x 64 -> 128 */
11197 unallocated_encoding(s
);
11200 if (!fp_access_check(s
)) {
11204 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
11207 /* opcode 15 not allocated */
11208 unallocated_encoding(s
);
11213 /* Logic op (opcode == 3) subgroup of C3.6.16. */
11214 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
11216 int rd
= extract32(insn
, 0, 5);
11217 int rn
= extract32(insn
, 5, 5);
11218 int rm
= extract32(insn
, 16, 5);
11219 int size
= extract32(insn
, 22, 2);
11220 bool is_u
= extract32(insn
, 29, 1);
11221 bool is_q
= extract32(insn
, 30, 1);
11223 if (!fp_access_check(s
)) {
11227 switch (size
+ 4 * is_u
) {
11229 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_and
, 0);
11232 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_andc
, 0);
11235 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_or
, 0);
11238 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_orc
, 0);
11241 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_xor
, 0);
11244 case 5: /* BSL bitwise select */
11245 gen_gvec_fn4(s
, is_q
, rd
, rd
, rn
, rm
, tcg_gen_gvec_bitsel
, 0);
11247 case 6: /* BIT, bitwise insert if true */
11248 gen_gvec_fn4(s
, is_q
, rd
, rm
, rn
, rd
, tcg_gen_gvec_bitsel
, 0);
11250 case 7: /* BIF, bitwise insert if false */
11251 gen_gvec_fn4(s
, is_q
, rd
, rm
, rd
, rn
, tcg_gen_gvec_bitsel
, 0);
11255 g_assert_not_reached();
11259 /* Pairwise op subgroup of C3.6.16.
11261 * This is called directly or via the handle_3same_float for float pairwise
11262 * operations where the opcode and size are calculated differently.
11264 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
11265 int size
, int rn
, int rm
, int rd
)
11270 /* Floating point operations need fpst */
11271 if (opcode
>= 0x58) {
11272 fpst
= fpstatus_ptr(FPST_FPCR
);
11277 if (!fp_access_check(s
)) {
11281 /* These operations work on the concatenated rm:rn, with each pair of
11282 * adjacent elements being operated on to produce an element in the result.
11285 TCGv_i64 tcg_res
[2];
11287 for (pass
= 0; pass
< 2; pass
++) {
11288 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11289 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11290 int passreg
= (pass
== 0) ? rn
: rm
;
11292 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
11293 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
11294 tcg_res
[pass
] = tcg_temp_new_i64();
11297 case 0x17: /* ADDP */
11298 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11300 case 0x58: /* FMAXNMP */
11301 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11303 case 0x5a: /* FADDP */
11304 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11306 case 0x5e: /* FMAXP */
11307 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11309 case 0x78: /* FMINNMP */
11310 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11312 case 0x7e: /* FMINP */
11313 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11316 g_assert_not_reached();
11319 tcg_temp_free_i64(tcg_op1
);
11320 tcg_temp_free_i64(tcg_op2
);
11323 for (pass
= 0; pass
< 2; pass
++) {
11324 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11325 tcg_temp_free_i64(tcg_res
[pass
]);
11328 int maxpass
= is_q
? 4 : 2;
11329 TCGv_i32 tcg_res
[4];
11331 for (pass
= 0; pass
< maxpass
; pass
++) {
11332 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11333 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11334 NeonGenTwoOpFn
*genfn
= NULL
;
11335 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
11336 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
11338 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
11339 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
11340 tcg_res
[pass
] = tcg_temp_new_i32();
11343 case 0x17: /* ADDP */
11345 static NeonGenTwoOpFn
* const fns
[3] = {
11346 gen_helper_neon_padd_u8
,
11347 gen_helper_neon_padd_u16
,
11353 case 0x14: /* SMAXP, UMAXP */
11355 static NeonGenTwoOpFn
* const fns
[3][2] = {
11356 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
11357 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
11358 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
11360 genfn
= fns
[size
][u
];
11363 case 0x15: /* SMINP, UMINP */
11365 static NeonGenTwoOpFn
* const fns
[3][2] = {
11366 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
11367 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
11368 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
11370 genfn
= fns
[size
][u
];
11373 /* The FP operations are all on single floats (32 bit) */
11374 case 0x58: /* FMAXNMP */
11375 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11377 case 0x5a: /* FADDP */
11378 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11380 case 0x5e: /* FMAXP */
11381 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11383 case 0x78: /* FMINNMP */
11384 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11386 case 0x7e: /* FMINP */
11387 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11390 g_assert_not_reached();
11393 /* FP ops called directly, otherwise call now */
11395 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11398 tcg_temp_free_i32(tcg_op1
);
11399 tcg_temp_free_i32(tcg_op2
);
11402 for (pass
= 0; pass
< maxpass
; pass
++) {
11403 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
11404 tcg_temp_free_i32(tcg_res
[pass
]);
11406 clear_vec_high(s
, is_q
, rd
);
11410 tcg_temp_free_ptr(fpst
);
11414 /* Floating point op subgroup of C3.6.16. */
11415 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
11417 /* For floating point ops, the U, size[1] and opcode bits
11418 * together indicate the operation. size[0] indicates single
11421 int fpopcode
= extract32(insn
, 11, 5)
11422 | (extract32(insn
, 23, 1) << 5)
11423 | (extract32(insn
, 29, 1) << 6);
11424 int is_q
= extract32(insn
, 30, 1);
11425 int size
= extract32(insn
, 22, 1);
11426 int rm
= extract32(insn
, 16, 5);
11427 int rn
= extract32(insn
, 5, 5);
11428 int rd
= extract32(insn
, 0, 5);
11430 int datasize
= is_q
? 128 : 64;
11431 int esize
= 32 << size
;
11432 int elements
= datasize
/ esize
;
11434 if (size
== 1 && !is_q
) {
11435 unallocated_encoding(s
);
11439 switch (fpopcode
) {
11440 case 0x58: /* FMAXNMP */
11441 case 0x5a: /* FADDP */
11442 case 0x5e: /* FMAXP */
11443 case 0x78: /* FMINNMP */
11444 case 0x7e: /* FMINP */
11445 if (size
&& !is_q
) {
11446 unallocated_encoding(s
);
11449 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
11452 case 0x1b: /* FMULX */
11453 case 0x1f: /* FRECPS */
11454 case 0x3f: /* FRSQRTS */
11455 case 0x5d: /* FACGE */
11456 case 0x7d: /* FACGT */
11457 case 0x19: /* FMLA */
11458 case 0x39: /* FMLS */
11459 case 0x18: /* FMAXNM */
11460 case 0x1a: /* FADD */
11461 case 0x1c: /* FCMEQ */
11462 case 0x1e: /* FMAX */
11463 case 0x38: /* FMINNM */
11464 case 0x3a: /* FSUB */
11465 case 0x3e: /* FMIN */
11466 case 0x5b: /* FMUL */
11467 case 0x5c: /* FCMGE */
11468 case 0x5f: /* FDIV */
11469 case 0x7a: /* FABD */
11470 case 0x7c: /* FCMGT */
11471 if (!fp_access_check(s
)) {
11474 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
11477 case 0x1d: /* FMLAL */
11478 case 0x3d: /* FMLSL */
11479 case 0x59: /* FMLAL2 */
11480 case 0x79: /* FMLSL2 */
11481 if (size
& 1 || !dc_isar_feature(aa64_fhm
, s
)) {
11482 unallocated_encoding(s
);
11485 if (fp_access_check(s
)) {
11486 int is_s
= extract32(insn
, 23, 1);
11487 int is_2
= extract32(insn
, 29, 1);
11488 int data
= (is_2
<< 1) | is_s
;
11489 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
11490 vec_full_reg_offset(s
, rn
),
11491 vec_full_reg_offset(s
, rm
), cpu_env
,
11492 is_q
? 16 : 8, vec_full_reg_size(s
),
11493 data
, gen_helper_gvec_fmlal_a64
);
11498 unallocated_encoding(s
);
11503 /* Integer op subgroup of C3.6.16. */
11504 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
11506 int is_q
= extract32(insn
, 30, 1);
11507 int u
= extract32(insn
, 29, 1);
11508 int size
= extract32(insn
, 22, 2);
11509 int opcode
= extract32(insn
, 11, 5);
11510 int rm
= extract32(insn
, 16, 5);
11511 int rn
= extract32(insn
, 5, 5);
11512 int rd
= extract32(insn
, 0, 5);
11517 case 0x13: /* MUL, PMUL */
11518 if (u
&& size
!= 0) {
11519 unallocated_encoding(s
);
11523 case 0x0: /* SHADD, UHADD */
11524 case 0x2: /* SRHADD, URHADD */
11525 case 0x4: /* SHSUB, UHSUB */
11526 case 0xc: /* SMAX, UMAX */
11527 case 0xd: /* SMIN, UMIN */
11528 case 0xe: /* SABD, UABD */
11529 case 0xf: /* SABA, UABA */
11530 case 0x12: /* MLA, MLS */
11532 unallocated_encoding(s
);
11536 case 0x16: /* SQDMULH, SQRDMULH */
11537 if (size
== 0 || size
== 3) {
11538 unallocated_encoding(s
);
11543 if (size
== 3 && !is_q
) {
11544 unallocated_encoding(s
);
11550 if (!fp_access_check(s
)) {
11555 case 0x01: /* SQADD, UQADD */
11557 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uqadd_qc
, size
);
11559 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqadd_qc
, size
);
11562 case 0x05: /* SQSUB, UQSUB */
11564 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uqsub_qc
, size
);
11566 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqsub_qc
, size
);
11569 case 0x08: /* SSHL, USHL */
11571 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_ushl
, size
);
11573 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sshl
, size
);
11576 case 0x0c: /* SMAX, UMAX */
11578 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umax
, size
);
11580 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smax
, size
);
11583 case 0x0d: /* SMIN, UMIN */
11585 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umin
, size
);
11587 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smin
, size
);
11590 case 0xe: /* SABD, UABD */
11592 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uabd
, size
);
11594 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sabd
, size
);
11597 case 0xf: /* SABA, UABA */
11599 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uaba
, size
);
11601 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_saba
, size
);
11604 case 0x10: /* ADD, SUB */
11606 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_sub
, size
);
11608 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_add
, size
);
11611 case 0x13: /* MUL, PMUL */
11612 if (!u
) { /* MUL */
11613 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_mul
, size
);
11614 } else { /* PMUL */
11615 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, 0, gen_helper_gvec_pmul_b
);
11618 case 0x12: /* MLA, MLS */
11620 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_mls
, size
);
11622 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_mla
, size
);
11625 case 0x16: /* SQDMULH, SQRDMULH */
11627 static gen_helper_gvec_3_ptr
* const fns
[2][2] = {
11628 { gen_helper_neon_sqdmulh_h
, gen_helper_neon_sqrdmulh_h
},
11629 { gen_helper_neon_sqdmulh_s
, gen_helper_neon_sqrdmulh_s
},
11631 gen_gvec_op3_qc(s
, is_q
, rd
, rn
, rm
, fns
[size
- 1][u
]);
11635 if (!u
) { /* CMTST */
11636 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_cmtst
, size
);
11640 cond
= TCG_COND_EQ
;
11642 case 0x06: /* CMGT, CMHI */
11643 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
11645 case 0x07: /* CMGE, CMHS */
11646 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
11648 tcg_gen_gvec_cmp(cond
, size
, vec_full_reg_offset(s
, rd
),
11649 vec_full_reg_offset(s
, rn
),
11650 vec_full_reg_offset(s
, rm
),
11651 is_q
? 16 : 8, vec_full_reg_size(s
));
11657 for (pass
= 0; pass
< 2; pass
++) {
11658 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11659 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11660 TCGv_i64 tcg_res
= tcg_temp_new_i64();
11662 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11663 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
11665 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
11667 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
11669 tcg_temp_free_i64(tcg_res
);
11670 tcg_temp_free_i64(tcg_op1
);
11671 tcg_temp_free_i64(tcg_op2
);
11674 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
11675 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11676 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11677 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11678 NeonGenTwoOpFn
*genfn
= NULL
;
11679 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
11681 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
11682 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
11685 case 0x0: /* SHADD, UHADD */
11687 static NeonGenTwoOpFn
* const fns
[3][2] = {
11688 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
11689 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
11690 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
11692 genfn
= fns
[size
][u
];
11695 case 0x2: /* SRHADD, URHADD */
11697 static NeonGenTwoOpFn
* const fns
[3][2] = {
11698 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
11699 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
11700 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
11702 genfn
= fns
[size
][u
];
11705 case 0x4: /* SHSUB, UHSUB */
11707 static NeonGenTwoOpFn
* const fns
[3][2] = {
11708 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
11709 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
11710 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
11712 genfn
= fns
[size
][u
];
11715 case 0x9: /* SQSHL, UQSHL */
11717 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11718 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
11719 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
11720 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
11722 genenvfn
= fns
[size
][u
];
11725 case 0xa: /* SRSHL, URSHL */
11727 static NeonGenTwoOpFn
* const fns
[3][2] = {
11728 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
11729 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
11730 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
11732 genfn
= fns
[size
][u
];
11735 case 0xb: /* SQRSHL, UQRSHL */
11737 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11738 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
11739 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
11740 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
11742 genenvfn
= fns
[size
][u
];
11746 g_assert_not_reached();
11750 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
11752 genfn(tcg_res
, tcg_op1
, tcg_op2
);
11755 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
11757 tcg_temp_free_i32(tcg_res
);
11758 tcg_temp_free_i32(tcg_op1
);
11759 tcg_temp_free_i32(tcg_op2
);
11762 clear_vec_high(s
, is_q
, rd
);
11765 /* AdvSIMD three same
11766 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11767 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11768 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11769 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11771 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
11773 int opcode
= extract32(insn
, 11, 5);
11776 case 0x3: /* logic ops */
11777 disas_simd_3same_logic(s
, insn
);
11779 case 0x17: /* ADDP */
11780 case 0x14: /* SMAXP, UMAXP */
11781 case 0x15: /* SMINP, UMINP */
11783 /* Pairwise operations */
11784 int is_q
= extract32(insn
, 30, 1);
11785 int u
= extract32(insn
, 29, 1);
11786 int size
= extract32(insn
, 22, 2);
11787 int rm
= extract32(insn
, 16, 5);
11788 int rn
= extract32(insn
, 5, 5);
11789 int rd
= extract32(insn
, 0, 5);
11790 if (opcode
== 0x17) {
11791 if (u
|| (size
== 3 && !is_q
)) {
11792 unallocated_encoding(s
);
11797 unallocated_encoding(s
);
11801 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
11804 case 0x18 ... 0x31:
11805 /* floating point ops, sz[1] and U are part of opcode */
11806 disas_simd_3same_float(s
, insn
);
11809 disas_simd_3same_int(s
, insn
);
11815 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11817 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11818 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11819 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11820 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11822 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11823 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11826 static void disas_simd_three_reg_same_fp16(DisasContext
*s
, uint32_t insn
)
11828 int opcode
= extract32(insn
, 11, 3);
11829 int u
= extract32(insn
, 29, 1);
11830 int a
= extract32(insn
, 23, 1);
11831 int is_q
= extract32(insn
, 30, 1);
11832 int rm
= extract32(insn
, 16, 5);
11833 int rn
= extract32(insn
, 5, 5);
11834 int rd
= extract32(insn
, 0, 5);
11836 * For these floating point ops, the U, a and opcode bits
11837 * together indicate the operation.
11839 int fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
11840 int datasize
= is_q
? 128 : 64;
11841 int elements
= datasize
/ 16;
11846 switch (fpopcode
) {
11847 case 0x0: /* FMAXNM */
11848 case 0x1: /* FMLA */
11849 case 0x2: /* FADD */
11850 case 0x3: /* FMULX */
11851 case 0x4: /* FCMEQ */
11852 case 0x6: /* FMAX */
11853 case 0x7: /* FRECPS */
11854 case 0x8: /* FMINNM */
11855 case 0x9: /* FMLS */
11856 case 0xa: /* FSUB */
11857 case 0xe: /* FMIN */
11858 case 0xf: /* FRSQRTS */
11859 case 0x13: /* FMUL */
11860 case 0x14: /* FCMGE */
11861 case 0x15: /* FACGE */
11862 case 0x17: /* FDIV */
11863 case 0x1a: /* FABD */
11864 case 0x1c: /* FCMGT */
11865 case 0x1d: /* FACGT */
11868 case 0x10: /* FMAXNMP */
11869 case 0x12: /* FADDP */
11870 case 0x16: /* FMAXP */
11871 case 0x18: /* FMINNMP */
11872 case 0x1e: /* FMINP */
11876 unallocated_encoding(s
);
11880 if (!dc_isar_feature(aa64_fp16
, s
)) {
11881 unallocated_encoding(s
);
11885 if (!fp_access_check(s
)) {
11889 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
11892 int maxpass
= is_q
? 8 : 4;
11893 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11894 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11895 TCGv_i32 tcg_res
[8];
11897 for (pass
= 0; pass
< maxpass
; pass
++) {
11898 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
11899 int passelt
= (pass
<< 1) & (maxpass
- 1);
11901 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_16
);
11902 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_16
);
11903 tcg_res
[pass
] = tcg_temp_new_i32();
11905 switch (fpopcode
) {
11906 case 0x10: /* FMAXNMP */
11907 gen_helper_advsimd_maxnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11910 case 0x12: /* FADDP */
11911 gen_helper_advsimd_addh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11913 case 0x16: /* FMAXP */
11914 gen_helper_advsimd_maxh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11916 case 0x18: /* FMINNMP */
11917 gen_helper_advsimd_minnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11920 case 0x1e: /* FMINP */
11921 gen_helper_advsimd_minh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11924 g_assert_not_reached();
11928 for (pass
= 0; pass
< maxpass
; pass
++) {
11929 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_16
);
11930 tcg_temp_free_i32(tcg_res
[pass
]);
11933 tcg_temp_free_i32(tcg_op1
);
11934 tcg_temp_free_i32(tcg_op2
);
11937 for (pass
= 0; pass
< elements
; pass
++) {
11938 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11939 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11940 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11942 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_16
);
11943 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_16
);
11945 switch (fpopcode
) {
11946 case 0x0: /* FMAXNM */
11947 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11949 case 0x1: /* FMLA */
11950 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11951 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11954 case 0x2: /* FADD */
11955 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11957 case 0x3: /* FMULX */
11958 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11960 case 0x4: /* FCMEQ */
11961 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11963 case 0x6: /* FMAX */
11964 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11966 case 0x7: /* FRECPS */
11967 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11969 case 0x8: /* FMINNM */
11970 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11972 case 0x9: /* FMLS */
11973 /* As usual for ARM, separate negation for fused multiply-add */
11974 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
11975 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11976 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11979 case 0xa: /* FSUB */
11980 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11982 case 0xe: /* FMIN */
11983 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11985 case 0xf: /* FRSQRTS */
11986 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11988 case 0x13: /* FMUL */
11989 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11991 case 0x14: /* FCMGE */
11992 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11994 case 0x15: /* FACGE */
11995 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11997 case 0x17: /* FDIV */
11998 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12000 case 0x1a: /* FABD */
12001 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12002 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
12004 case 0x1c: /* FCMGT */
12005 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12007 case 0x1d: /* FACGT */
12008 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12011 g_assert_not_reached();
12014 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12015 tcg_temp_free_i32(tcg_res
);
12016 tcg_temp_free_i32(tcg_op1
);
12017 tcg_temp_free_i32(tcg_op2
);
12021 tcg_temp_free_ptr(fpst
);
12023 clear_vec_high(s
, is_q
, rd
);
12026 /* AdvSIMD three same extra
12027 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
12028 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
12029 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
12030 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
12032 static void disas_simd_three_reg_same_extra(DisasContext
*s
, uint32_t insn
)
12034 int rd
= extract32(insn
, 0, 5);
12035 int rn
= extract32(insn
, 5, 5);
12036 int opcode
= extract32(insn
, 11, 4);
12037 int rm
= extract32(insn
, 16, 5);
12038 int size
= extract32(insn
, 22, 2);
12039 bool u
= extract32(insn
, 29, 1);
12040 bool is_q
= extract32(insn
, 30, 1);
12044 switch (u
* 16 + opcode
) {
12045 case 0x10: /* SQRDMLAH (vector) */
12046 case 0x11: /* SQRDMLSH (vector) */
12047 if (size
!= 1 && size
!= 2) {
12048 unallocated_encoding(s
);
12051 feature
= dc_isar_feature(aa64_rdm
, s
);
12053 case 0x02: /* SDOT (vector) */
12054 case 0x12: /* UDOT (vector) */
12055 if (size
!= MO_32
) {
12056 unallocated_encoding(s
);
12059 feature
= dc_isar_feature(aa64_dp
, s
);
12061 case 0x03: /* USDOT */
12062 if (size
!= MO_32
) {
12063 unallocated_encoding(s
);
12066 feature
= dc_isar_feature(aa64_i8mm
, s
);
12068 case 0x04: /* SMMLA */
12069 case 0x14: /* UMMLA */
12070 case 0x05: /* USMMLA */
12071 if (!is_q
|| size
!= MO_32
) {
12072 unallocated_encoding(s
);
12075 feature
= dc_isar_feature(aa64_i8mm
, s
);
12077 case 0x18: /* FCMLA, #0 */
12078 case 0x19: /* FCMLA, #90 */
12079 case 0x1a: /* FCMLA, #180 */
12080 case 0x1b: /* FCMLA, #270 */
12081 case 0x1c: /* FCADD, #90 */
12082 case 0x1e: /* FCADD, #270 */
12084 || (size
== 1 && !dc_isar_feature(aa64_fp16
, s
))
12085 || (size
== 3 && !is_q
)) {
12086 unallocated_encoding(s
);
12089 feature
= dc_isar_feature(aa64_fcma
, s
);
12091 case 0x1d: /* BFMMLA */
12092 if (size
!= MO_16
|| !is_q
) {
12093 unallocated_encoding(s
);
12096 feature
= dc_isar_feature(aa64_bf16
, s
);
12100 case 1: /* BFDOT */
12101 case 3: /* BFMLAL{B,T} */
12102 feature
= dc_isar_feature(aa64_bf16
, s
);
12105 unallocated_encoding(s
);
12110 unallocated_encoding(s
);
12114 unallocated_encoding(s
);
12117 if (!fp_access_check(s
)) {
12122 case 0x0: /* SQRDMLAH (vector) */
12123 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqrdmlah_qc
, size
);
12126 case 0x1: /* SQRDMLSH (vector) */
12127 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqrdmlsh_qc
, size
);
12130 case 0x2: /* SDOT / UDOT */
12131 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, 0,
12132 u
? gen_helper_gvec_udot_b
: gen_helper_gvec_sdot_b
);
12135 case 0x3: /* USDOT */
12136 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, 0, gen_helper_gvec_usdot_b
);
12139 case 0x04: /* SMMLA, UMMLA */
12140 gen_gvec_op4_ool(s
, 1, rd
, rn
, rm
, rd
, 0,
12141 u
? gen_helper_gvec_ummla_b
12142 : gen_helper_gvec_smmla_b
);
12144 case 0x05: /* USMMLA */
12145 gen_gvec_op4_ool(s
, 1, rd
, rn
, rm
, rd
, 0, gen_helper_gvec_usmmla_b
);
12148 case 0x8: /* FCMLA, #0 */
12149 case 0x9: /* FCMLA, #90 */
12150 case 0xa: /* FCMLA, #180 */
12151 case 0xb: /* FCMLA, #270 */
12152 rot
= extract32(opcode
, 0, 2);
12155 gen_gvec_op4_fpst(s
, is_q
, rd
, rn
, rm
, rd
, true, rot
,
12156 gen_helper_gvec_fcmlah
);
12159 gen_gvec_op4_fpst(s
, is_q
, rd
, rn
, rm
, rd
, false, rot
,
12160 gen_helper_gvec_fcmlas
);
12163 gen_gvec_op4_fpst(s
, is_q
, rd
, rn
, rm
, rd
, false, rot
,
12164 gen_helper_gvec_fcmlad
);
12167 g_assert_not_reached();
12171 case 0xc: /* FCADD, #90 */
12172 case 0xe: /* FCADD, #270 */
12173 rot
= extract32(opcode
, 1, 1);
12176 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
12177 gen_helper_gvec_fcaddh
);
12180 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
12181 gen_helper_gvec_fcadds
);
12184 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
12185 gen_helper_gvec_fcaddd
);
12188 g_assert_not_reached();
12192 case 0xd: /* BFMMLA */
12193 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, 0, gen_helper_gvec_bfmmla
);
12197 case 1: /* BFDOT */
12198 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, 0, gen_helper_gvec_bfdot
);
12200 case 3: /* BFMLAL{B,T} */
12201 gen_gvec_op4_fpst(s
, 1, rd
, rn
, rm
, rd
, false, is_q
,
12202 gen_helper_gvec_bfmlal
);
12205 g_assert_not_reached();
12210 g_assert_not_reached();
12214 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
12215 int size
, int rn
, int rd
)
12217 /* Handle 2-reg-misc ops which are widening (so each size element
12218 * in the source becomes a 2*size element in the destination.
12219 * The only instruction like this is FCVTL.
12224 /* 32 -> 64 bit fp conversion */
12225 TCGv_i64 tcg_res
[2];
12226 int srcelt
= is_q
? 2 : 0;
12228 for (pass
= 0; pass
< 2; pass
++) {
12229 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12230 tcg_res
[pass
] = tcg_temp_new_i64();
12232 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
12233 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
12234 tcg_temp_free_i32(tcg_op
);
12236 for (pass
= 0; pass
< 2; pass
++) {
12237 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
12238 tcg_temp_free_i64(tcg_res
[pass
]);
12241 /* 16 -> 32 bit fp conversion */
12242 int srcelt
= is_q
? 4 : 0;
12243 TCGv_i32 tcg_res
[4];
12244 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
12245 TCGv_i32 ahp
= get_ahp_flag();
12247 for (pass
= 0; pass
< 4; pass
++) {
12248 tcg_res
[pass
] = tcg_temp_new_i32();
12250 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
12251 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
12254 for (pass
= 0; pass
< 4; pass
++) {
12255 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
12256 tcg_temp_free_i32(tcg_res
[pass
]);
12259 tcg_temp_free_ptr(fpst
);
12260 tcg_temp_free_i32(ahp
);
12264 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
12265 bool is_q
, int size
, int rn
, int rd
)
12267 int op
= (opcode
<< 1) | u
;
12268 int opsz
= op
+ size
;
12269 int grp_size
= 3 - opsz
;
12270 int dsize
= is_q
? 128 : 64;
12274 unallocated_encoding(s
);
12278 if (!fp_access_check(s
)) {
12283 /* Special case bytes, use bswap op on each group of elements */
12284 int groups
= dsize
/ (8 << grp_size
);
12286 for (i
= 0; i
< groups
; i
++) {
12287 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
12289 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
12290 switch (grp_size
) {
12292 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
, TCG_BSWAP_IZ
);
12295 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
, TCG_BSWAP_IZ
);
12298 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
12301 g_assert_not_reached();
12303 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
12304 tcg_temp_free_i64(tcg_tmp
);
12306 clear_vec_high(s
, is_q
, rd
);
12308 int revmask
= (1 << grp_size
) - 1;
12309 int esize
= 8 << size
;
12310 int elements
= dsize
/ esize
;
12311 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
12312 TCGv_i64 tcg_rd
= tcg_const_i64(0);
12313 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
12315 for (i
= 0; i
< elements
; i
++) {
12316 int e_rev
= (i
& 0xf) ^ revmask
;
12317 int off
= e_rev
* esize
;
12318 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
12320 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
12321 tcg_rn
, off
- 64, esize
);
12323 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
12326 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
12327 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
12329 tcg_temp_free_i64(tcg_rd_hi
);
12330 tcg_temp_free_i64(tcg_rd
);
12331 tcg_temp_free_i64(tcg_rn
);
12335 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
12336 bool is_q
, int size
, int rn
, int rd
)
12338 /* Implement the pairwise operations from 2-misc:
12339 * SADDLP, UADDLP, SADALP, UADALP.
12340 * These all add pairs of elements in the input to produce a
12341 * double-width result element in the output (possibly accumulating).
12343 bool accum
= (opcode
== 0x6);
12344 int maxpass
= is_q
? 2 : 1;
12346 TCGv_i64 tcg_res
[2];
12349 /* 32 + 32 -> 64 op */
12350 MemOp memop
= size
+ (u
? 0 : MO_SIGN
);
12352 for (pass
= 0; pass
< maxpass
; pass
++) {
12353 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
12354 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
12356 tcg_res
[pass
] = tcg_temp_new_i64();
12358 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
12359 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
12360 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
12362 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
12363 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
12366 tcg_temp_free_i64(tcg_op1
);
12367 tcg_temp_free_i64(tcg_op2
);
12370 for (pass
= 0; pass
< maxpass
; pass
++) {
12371 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12372 NeonGenOne64OpFn
*genfn
;
12373 static NeonGenOne64OpFn
* const fns
[2][2] = {
12374 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
12375 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
12378 genfn
= fns
[size
][u
];
12380 tcg_res
[pass
] = tcg_temp_new_i64();
12382 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12383 genfn(tcg_res
[pass
], tcg_op
);
12386 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
12388 gen_helper_neon_addl_u16(tcg_res
[pass
],
12389 tcg_res
[pass
], tcg_op
);
12391 gen_helper_neon_addl_u32(tcg_res
[pass
],
12392 tcg_res
[pass
], tcg_op
);
12395 tcg_temp_free_i64(tcg_op
);
12399 tcg_res
[1] = tcg_constant_i64(0);
12401 for (pass
= 0; pass
< 2; pass
++) {
12402 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
12403 tcg_temp_free_i64(tcg_res
[pass
]);
12407 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
12409 /* Implement SHLL and SHLL2 */
12411 int part
= is_q
? 2 : 0;
12412 TCGv_i64 tcg_res
[2];
12414 for (pass
= 0; pass
< 2; pass
++) {
12415 static NeonGenWidenFn
* const widenfns
[3] = {
12416 gen_helper_neon_widen_u8
,
12417 gen_helper_neon_widen_u16
,
12418 tcg_gen_extu_i32_i64
,
12420 NeonGenWidenFn
*widenfn
= widenfns
[size
];
12421 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12423 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
12424 tcg_res
[pass
] = tcg_temp_new_i64();
12425 widenfn(tcg_res
[pass
], tcg_op
);
12426 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
12428 tcg_temp_free_i32(tcg_op
);
12431 for (pass
= 0; pass
< 2; pass
++) {
12432 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
12433 tcg_temp_free_i64(tcg_res
[pass
]);
12437 /* AdvSIMD two reg misc
12438 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
12439 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
12440 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
12441 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
12443 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
12445 int size
= extract32(insn
, 22, 2);
12446 int opcode
= extract32(insn
, 12, 5);
12447 bool u
= extract32(insn
, 29, 1);
12448 bool is_q
= extract32(insn
, 30, 1);
12449 int rn
= extract32(insn
, 5, 5);
12450 int rd
= extract32(insn
, 0, 5);
12451 bool need_fpstatus
= false;
12452 bool need_rmode
= false;
12454 TCGv_i32 tcg_rmode
;
12455 TCGv_ptr tcg_fpstatus
;
12458 case 0x0: /* REV64, REV32 */
12459 case 0x1: /* REV16 */
12460 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
12462 case 0x5: /* CNT, NOT, RBIT */
12463 if (u
&& size
== 0) {
12466 } else if (u
&& size
== 1) {
12469 } else if (!u
&& size
== 0) {
12473 unallocated_encoding(s
);
12475 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
12476 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
12478 unallocated_encoding(s
);
12481 if (!fp_access_check(s
)) {
12485 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
12487 case 0x4: /* CLS, CLZ */
12489 unallocated_encoding(s
);
12493 case 0x2: /* SADDLP, UADDLP */
12494 case 0x6: /* SADALP, UADALP */
12496 unallocated_encoding(s
);
12499 if (!fp_access_check(s
)) {
12502 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
12504 case 0x13: /* SHLL, SHLL2 */
12505 if (u
== 0 || size
== 3) {
12506 unallocated_encoding(s
);
12509 if (!fp_access_check(s
)) {
12512 handle_shll(s
, is_q
, size
, rn
, rd
);
12514 case 0xa: /* CMLT */
12516 unallocated_encoding(s
);
12520 case 0x8: /* CMGT, CMGE */
12521 case 0x9: /* CMEQ, CMLE */
12522 case 0xb: /* ABS, NEG */
12523 if (size
== 3 && !is_q
) {
12524 unallocated_encoding(s
);
12528 case 0x3: /* SUQADD, USQADD */
12529 if (size
== 3 && !is_q
) {
12530 unallocated_encoding(s
);
12533 if (!fp_access_check(s
)) {
12536 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
12538 case 0x7: /* SQABS, SQNEG */
12539 if (size
== 3 && !is_q
) {
12540 unallocated_encoding(s
);
12545 case 0x16 ... 0x1f:
12547 /* Floating point: U, size[1] and opcode indicate operation;
12548 * size[0] indicates single or double precision.
12550 int is_double
= extract32(size
, 0, 1);
12551 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
12552 size
= is_double
? 3 : 2;
12554 case 0x2f: /* FABS */
12555 case 0x6f: /* FNEG */
12556 if (size
== 3 && !is_q
) {
12557 unallocated_encoding(s
);
12561 case 0x1d: /* SCVTF */
12562 case 0x5d: /* UCVTF */
12564 bool is_signed
= (opcode
== 0x1d) ? true : false;
12565 int elements
= is_double
? 2 : is_q
? 4 : 2;
12566 if (is_double
&& !is_q
) {
12567 unallocated_encoding(s
);
12570 if (!fp_access_check(s
)) {
12573 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
12576 case 0x2c: /* FCMGT (zero) */
12577 case 0x2d: /* FCMEQ (zero) */
12578 case 0x2e: /* FCMLT (zero) */
12579 case 0x6c: /* FCMGE (zero) */
12580 case 0x6d: /* FCMLE (zero) */
12581 if (size
== 3 && !is_q
) {
12582 unallocated_encoding(s
);
12585 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
12587 case 0x7f: /* FSQRT */
12588 if (size
== 3 && !is_q
) {
12589 unallocated_encoding(s
);
12593 case 0x1a: /* FCVTNS */
12594 case 0x1b: /* FCVTMS */
12595 case 0x3a: /* FCVTPS */
12596 case 0x3b: /* FCVTZS */
12597 case 0x5a: /* FCVTNU */
12598 case 0x5b: /* FCVTMU */
12599 case 0x7a: /* FCVTPU */
12600 case 0x7b: /* FCVTZU */
12601 need_fpstatus
= true;
12603 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12604 if (size
== 3 && !is_q
) {
12605 unallocated_encoding(s
);
12609 case 0x5c: /* FCVTAU */
12610 case 0x1c: /* FCVTAS */
12611 need_fpstatus
= true;
12613 rmode
= FPROUNDING_TIEAWAY
;
12614 if (size
== 3 && !is_q
) {
12615 unallocated_encoding(s
);
12619 case 0x3c: /* URECPE */
12621 unallocated_encoding(s
);
12625 case 0x3d: /* FRECPE */
12626 case 0x7d: /* FRSQRTE */
12627 if (size
== 3 && !is_q
) {
12628 unallocated_encoding(s
);
12631 if (!fp_access_check(s
)) {
12634 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
12636 case 0x56: /* FCVTXN, FCVTXN2 */
12638 unallocated_encoding(s
);
12642 case 0x16: /* FCVTN, FCVTN2 */
12643 /* handle_2misc_narrow does a 2*size -> size operation, but these
12644 * instructions encode the source size rather than dest size.
12646 if (!fp_access_check(s
)) {
12649 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
12651 case 0x36: /* BFCVTN, BFCVTN2 */
12652 if (!dc_isar_feature(aa64_bf16
, s
) || size
!= 2) {
12653 unallocated_encoding(s
);
12656 if (!fp_access_check(s
)) {
12659 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
12661 case 0x17: /* FCVTL, FCVTL2 */
12662 if (!fp_access_check(s
)) {
12665 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
12667 case 0x18: /* FRINTN */
12668 case 0x19: /* FRINTM */
12669 case 0x38: /* FRINTP */
12670 case 0x39: /* FRINTZ */
12672 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12674 case 0x59: /* FRINTX */
12675 case 0x79: /* FRINTI */
12676 need_fpstatus
= true;
12677 if (size
== 3 && !is_q
) {
12678 unallocated_encoding(s
);
12682 case 0x58: /* FRINTA */
12684 rmode
= FPROUNDING_TIEAWAY
;
12685 need_fpstatus
= true;
12686 if (size
== 3 && !is_q
) {
12687 unallocated_encoding(s
);
12691 case 0x7c: /* URSQRTE */
12693 unallocated_encoding(s
);
12697 case 0x1e: /* FRINT32Z */
12698 case 0x1f: /* FRINT64Z */
12700 rmode
= FPROUNDING_ZERO
;
12702 case 0x5e: /* FRINT32X */
12703 case 0x5f: /* FRINT64X */
12704 need_fpstatus
= true;
12705 if ((size
== 3 && !is_q
) || !dc_isar_feature(aa64_frint
, s
)) {
12706 unallocated_encoding(s
);
12711 unallocated_encoding(s
);
12717 unallocated_encoding(s
);
12721 if (!fp_access_check(s
)) {
12725 if (need_fpstatus
|| need_rmode
) {
12726 tcg_fpstatus
= fpstatus_ptr(FPST_FPCR
);
12728 tcg_fpstatus
= NULL
;
12731 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12732 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12739 if (u
&& size
== 0) { /* NOT */
12740 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_not
, 0);
12744 case 0x8: /* CMGT, CMGE */
12746 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_cge0
, size
);
12748 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_cgt0
, size
);
12751 case 0x9: /* CMEQ, CMLE */
12753 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_cle0
, size
);
12755 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_ceq0
, size
);
12758 case 0xa: /* CMLT */
12759 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_clt0
, size
);
12762 if (u
) { /* ABS, NEG */
12763 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_neg
, size
);
12765 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_abs
, size
);
12771 /* All 64-bit element operations can be shared with scalar 2misc */
12774 /* Coverity claims (size == 3 && !is_q) has been eliminated
12775 * from all paths leading to here.
12777 tcg_debug_assert(is_q
);
12778 for (pass
= 0; pass
< 2; pass
++) {
12779 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12780 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12782 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12784 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
12785 tcg_rmode
, tcg_fpstatus
);
12787 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12789 tcg_temp_free_i64(tcg_res
);
12790 tcg_temp_free_i64(tcg_op
);
12795 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
12796 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12797 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12799 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
12802 /* Special cases for 32 bit elements */
12804 case 0x4: /* CLS */
12806 tcg_gen_clzi_i32(tcg_res
, tcg_op
, 32);
12808 tcg_gen_clrsb_i32(tcg_res
, tcg_op
);
12811 case 0x7: /* SQABS, SQNEG */
12813 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
12815 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
12818 case 0x2f: /* FABS */
12819 gen_helper_vfp_abss(tcg_res
, tcg_op
);
12821 case 0x6f: /* FNEG */
12822 gen_helper_vfp_negs(tcg_res
, tcg_op
);
12824 case 0x7f: /* FSQRT */
12825 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
12827 case 0x1a: /* FCVTNS */
12828 case 0x1b: /* FCVTMS */
12829 case 0x1c: /* FCVTAS */
12830 case 0x3a: /* FCVTPS */
12831 case 0x3b: /* FCVTZS */
12832 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
12833 tcg_constant_i32(0), tcg_fpstatus
);
12835 case 0x5a: /* FCVTNU */
12836 case 0x5b: /* FCVTMU */
12837 case 0x5c: /* FCVTAU */
12838 case 0x7a: /* FCVTPU */
12839 case 0x7b: /* FCVTZU */
12840 gen_helper_vfp_touls(tcg_res
, tcg_op
,
12841 tcg_constant_i32(0), tcg_fpstatus
);
12843 case 0x18: /* FRINTN */
12844 case 0x19: /* FRINTM */
12845 case 0x38: /* FRINTP */
12846 case 0x39: /* FRINTZ */
12847 case 0x58: /* FRINTA */
12848 case 0x79: /* FRINTI */
12849 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
12851 case 0x59: /* FRINTX */
12852 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12854 case 0x7c: /* URSQRTE */
12855 gen_helper_rsqrte_u32(tcg_res
, tcg_op
);
12857 case 0x1e: /* FRINT32Z */
12858 case 0x5e: /* FRINT32X */
12859 gen_helper_frint32_s(tcg_res
, tcg_op
, tcg_fpstatus
);
12861 case 0x1f: /* FRINT64Z */
12862 case 0x5f: /* FRINT64X */
12863 gen_helper_frint64_s(tcg_res
, tcg_op
, tcg_fpstatus
);
12866 g_assert_not_reached();
12869 /* Use helpers for 8 and 16 bit elements */
12871 case 0x5: /* CNT, RBIT */
12872 /* For these two insns size is part of the opcode specifier
12873 * (handled earlier); they always operate on byte elements.
12876 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
12878 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
12881 case 0x7: /* SQABS, SQNEG */
12883 NeonGenOneOpEnvFn
*genfn
;
12884 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
12885 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
12886 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
12888 genfn
= fns
[size
][u
];
12889 genfn(tcg_res
, cpu_env
, tcg_op
);
12892 case 0x4: /* CLS, CLZ */
12895 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
12897 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
12901 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
12903 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
12908 g_assert_not_reached();
12912 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
12914 tcg_temp_free_i32(tcg_res
);
12915 tcg_temp_free_i32(tcg_op
);
12918 clear_vec_high(s
, is_q
, rd
);
12921 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12922 tcg_temp_free_i32(tcg_rmode
);
12924 if (need_fpstatus
) {
12925 tcg_temp_free_ptr(tcg_fpstatus
);
12929 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12931 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12932 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12933 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12934 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12935 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12936 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12938 * This actually covers two groups where scalar access is governed by
12939 * bit 28. A bunch of the instructions (float to integral) only exist
12940 * in the vector form and are un-allocated for the scalar decode. Also
12941 * in the scalar decode Q is always 1.
12943 static void disas_simd_two_reg_misc_fp16(DisasContext
*s
, uint32_t insn
)
12945 int fpop
, opcode
, a
, u
;
12949 bool only_in_vector
= false;
12952 TCGv_i32 tcg_rmode
= NULL
;
12953 TCGv_ptr tcg_fpstatus
= NULL
;
12954 bool need_rmode
= false;
12955 bool need_fpst
= true;
12958 if (!dc_isar_feature(aa64_fp16
, s
)) {
12959 unallocated_encoding(s
);
12963 rd
= extract32(insn
, 0, 5);
12964 rn
= extract32(insn
, 5, 5);
12966 a
= extract32(insn
, 23, 1);
12967 u
= extract32(insn
, 29, 1);
12968 is_scalar
= extract32(insn
, 28, 1);
12969 is_q
= extract32(insn
, 30, 1);
12971 opcode
= extract32(insn
, 12, 5);
12972 fpop
= deposit32(opcode
, 5, 1, a
);
12973 fpop
= deposit32(fpop
, 6, 1, u
);
12976 case 0x1d: /* SCVTF */
12977 case 0x5d: /* UCVTF */
12984 elements
= (is_q
? 8 : 4);
12987 if (!fp_access_check(s
)) {
12990 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !u
, 0, MO_16
);
12994 case 0x2c: /* FCMGT (zero) */
12995 case 0x2d: /* FCMEQ (zero) */
12996 case 0x2e: /* FCMLT (zero) */
12997 case 0x6c: /* FCMGE (zero) */
12998 case 0x6d: /* FCMLE (zero) */
12999 handle_2misc_fcmp_zero(s
, fpop
, is_scalar
, 0, is_q
, MO_16
, rn
, rd
);
13001 case 0x3d: /* FRECPE */
13002 case 0x3f: /* FRECPX */
13004 case 0x18: /* FRINTN */
13006 only_in_vector
= true;
13007 rmode
= FPROUNDING_TIEEVEN
;
13009 case 0x19: /* FRINTM */
13011 only_in_vector
= true;
13012 rmode
= FPROUNDING_NEGINF
;
13014 case 0x38: /* FRINTP */
13016 only_in_vector
= true;
13017 rmode
= FPROUNDING_POSINF
;
13019 case 0x39: /* FRINTZ */
13021 only_in_vector
= true;
13022 rmode
= FPROUNDING_ZERO
;
13024 case 0x58: /* FRINTA */
13026 only_in_vector
= true;
13027 rmode
= FPROUNDING_TIEAWAY
;
13029 case 0x59: /* FRINTX */
13030 case 0x79: /* FRINTI */
13031 only_in_vector
= true;
13032 /* current rounding mode */
13034 case 0x1a: /* FCVTNS */
13036 rmode
= FPROUNDING_TIEEVEN
;
13038 case 0x1b: /* FCVTMS */
13040 rmode
= FPROUNDING_NEGINF
;
13042 case 0x1c: /* FCVTAS */
13044 rmode
= FPROUNDING_TIEAWAY
;
13046 case 0x3a: /* FCVTPS */
13048 rmode
= FPROUNDING_POSINF
;
13050 case 0x3b: /* FCVTZS */
13052 rmode
= FPROUNDING_ZERO
;
13054 case 0x5a: /* FCVTNU */
13056 rmode
= FPROUNDING_TIEEVEN
;
13058 case 0x5b: /* FCVTMU */
13060 rmode
= FPROUNDING_NEGINF
;
13062 case 0x5c: /* FCVTAU */
13064 rmode
= FPROUNDING_TIEAWAY
;
13066 case 0x7a: /* FCVTPU */
13068 rmode
= FPROUNDING_POSINF
;
13070 case 0x7b: /* FCVTZU */
13072 rmode
= FPROUNDING_ZERO
;
13074 case 0x2f: /* FABS */
13075 case 0x6f: /* FNEG */
13078 case 0x7d: /* FRSQRTE */
13079 case 0x7f: /* FSQRT (vector) */
13082 unallocated_encoding(s
);
13087 /* Check additional constraints for the scalar encoding */
13090 unallocated_encoding(s
);
13093 /* FRINTxx is only in the vector form */
13094 if (only_in_vector
) {
13095 unallocated_encoding(s
);
13100 if (!fp_access_check(s
)) {
13104 if (need_rmode
|| need_fpst
) {
13105 tcg_fpstatus
= fpstatus_ptr(FPST_FPCR_F16
);
13109 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
13110 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
13114 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
13115 TCGv_i32 tcg_res
= tcg_temp_new_i32();
13118 case 0x1a: /* FCVTNS */
13119 case 0x1b: /* FCVTMS */
13120 case 0x1c: /* FCVTAS */
13121 case 0x3a: /* FCVTPS */
13122 case 0x3b: /* FCVTZS */
13123 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13125 case 0x3d: /* FRECPE */
13126 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13128 case 0x3f: /* FRECPX */
13129 gen_helper_frecpx_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13131 case 0x5a: /* FCVTNU */
13132 case 0x5b: /* FCVTMU */
13133 case 0x5c: /* FCVTAU */
13134 case 0x7a: /* FCVTPU */
13135 case 0x7b: /* FCVTZU */
13136 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13138 case 0x6f: /* FNEG */
13139 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
13141 case 0x7d: /* FRSQRTE */
13142 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13145 g_assert_not_reached();
13148 /* limit any sign extension going on */
13149 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0xffff);
13150 write_fp_sreg(s
, rd
, tcg_res
);
13152 tcg_temp_free_i32(tcg_res
);
13153 tcg_temp_free_i32(tcg_op
);
13155 for (pass
= 0; pass
< (is_q
? 8 : 4); pass
++) {
13156 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13157 TCGv_i32 tcg_res
= tcg_temp_new_i32();
13159 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_16
);
13162 case 0x1a: /* FCVTNS */
13163 case 0x1b: /* FCVTMS */
13164 case 0x1c: /* FCVTAS */
13165 case 0x3a: /* FCVTPS */
13166 case 0x3b: /* FCVTZS */
13167 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13169 case 0x3d: /* FRECPE */
13170 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13172 case 0x5a: /* FCVTNU */
13173 case 0x5b: /* FCVTMU */
13174 case 0x5c: /* FCVTAU */
13175 case 0x7a: /* FCVTPU */
13176 case 0x7b: /* FCVTZU */
13177 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13179 case 0x18: /* FRINTN */
13180 case 0x19: /* FRINTM */
13181 case 0x38: /* FRINTP */
13182 case 0x39: /* FRINTZ */
13183 case 0x58: /* FRINTA */
13184 case 0x79: /* FRINTI */
13185 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13187 case 0x59: /* FRINTX */
13188 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
13190 case 0x2f: /* FABS */
13191 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
13193 case 0x6f: /* FNEG */
13194 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
13196 case 0x7d: /* FRSQRTE */
13197 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13199 case 0x7f: /* FSQRT */
13200 gen_helper_sqrt_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13203 g_assert_not_reached();
13206 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
13208 tcg_temp_free_i32(tcg_res
);
13209 tcg_temp_free_i32(tcg_op
);
13212 clear_vec_high(s
, is_q
, rd
);
13216 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
13217 tcg_temp_free_i32(tcg_rmode
);
13220 if (tcg_fpstatus
) {
13221 tcg_temp_free_ptr(tcg_fpstatus
);
13225 /* AdvSIMD scalar x indexed element
13226 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
13227 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
13228 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
13229 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
13230 * AdvSIMD vector x indexed element
13231 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
13232 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
13233 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
13234 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
13236 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
13238 /* This encoding has two kinds of instruction:
13239 * normal, where we perform elt x idxelt => elt for each
13240 * element in the vector
13241 * long, where we perform elt x idxelt and generate a result of
13242 * double the width of the input element
13243 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
13245 bool is_scalar
= extract32(insn
, 28, 1);
13246 bool is_q
= extract32(insn
, 30, 1);
13247 bool u
= extract32(insn
, 29, 1);
13248 int size
= extract32(insn
, 22, 2);
13249 int l
= extract32(insn
, 21, 1);
13250 int m
= extract32(insn
, 20, 1);
13251 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
13252 int rm
= extract32(insn
, 16, 4);
13253 int opcode
= extract32(insn
, 12, 4);
13254 int h
= extract32(insn
, 11, 1);
13255 int rn
= extract32(insn
, 5, 5);
13256 int rd
= extract32(insn
, 0, 5);
13257 bool is_long
= false;
13259 bool is_fp16
= false;
13263 switch (16 * u
+ opcode
) {
13264 case 0x08: /* MUL */
13265 case 0x10: /* MLA */
13266 case 0x14: /* MLS */
13268 unallocated_encoding(s
);
13272 case 0x02: /* SMLAL, SMLAL2 */
13273 case 0x12: /* UMLAL, UMLAL2 */
13274 case 0x06: /* SMLSL, SMLSL2 */
13275 case 0x16: /* UMLSL, UMLSL2 */
13276 case 0x0a: /* SMULL, SMULL2 */
13277 case 0x1a: /* UMULL, UMULL2 */
13279 unallocated_encoding(s
);
13284 case 0x03: /* SQDMLAL, SQDMLAL2 */
13285 case 0x07: /* SQDMLSL, SQDMLSL2 */
13286 case 0x0b: /* SQDMULL, SQDMULL2 */
13289 case 0x0c: /* SQDMULH */
13290 case 0x0d: /* SQRDMULH */
13292 case 0x01: /* FMLA */
13293 case 0x05: /* FMLS */
13294 case 0x09: /* FMUL */
13295 case 0x19: /* FMULX */
13298 case 0x1d: /* SQRDMLAH */
13299 case 0x1f: /* SQRDMLSH */
13300 if (!dc_isar_feature(aa64_rdm
, s
)) {
13301 unallocated_encoding(s
);
13305 case 0x0e: /* SDOT */
13306 case 0x1e: /* UDOT */
13307 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_dp
, s
)) {
13308 unallocated_encoding(s
);
13314 case 0: /* SUDOT */
13315 case 2: /* USDOT */
13316 if (is_scalar
|| !dc_isar_feature(aa64_i8mm
, s
)) {
13317 unallocated_encoding(s
);
13322 case 1: /* BFDOT */
13323 if (is_scalar
|| !dc_isar_feature(aa64_bf16
, s
)) {
13324 unallocated_encoding(s
);
13329 case 3: /* BFMLAL{B,T} */
13330 if (is_scalar
|| !dc_isar_feature(aa64_bf16
, s
)) {
13331 unallocated_encoding(s
);
13334 /* can't set is_fp without other incorrect size checks */
13338 unallocated_encoding(s
);
13342 case 0x11: /* FCMLA #0 */
13343 case 0x13: /* FCMLA #90 */
13344 case 0x15: /* FCMLA #180 */
13345 case 0x17: /* FCMLA #270 */
13346 if (is_scalar
|| !dc_isar_feature(aa64_fcma
, s
)) {
13347 unallocated_encoding(s
);
13352 case 0x00: /* FMLAL */
13353 case 0x04: /* FMLSL */
13354 case 0x18: /* FMLAL2 */
13355 case 0x1c: /* FMLSL2 */
13356 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_fhm
, s
)) {
13357 unallocated_encoding(s
);
13361 /* is_fp, but we pass cpu_env not fp_status. */
13364 unallocated_encoding(s
);
13369 case 1: /* normal fp */
13370 /* convert insn encoded size to MemOp size */
13372 case 0: /* half-precision */
13376 case MO_32
: /* single precision */
13377 case MO_64
: /* double precision */
13380 unallocated_encoding(s
);
13385 case 2: /* complex fp */
13386 /* Each indexable element is a complex pair. */
13391 unallocated_encoding(s
);
13399 unallocated_encoding(s
);
13404 default: /* integer */
13408 unallocated_encoding(s
);
13413 if (is_fp16
&& !dc_isar_feature(aa64_fp16
, s
)) {
13414 unallocated_encoding(s
);
13418 /* Given MemOp size, adjust register and indexing. */
13421 index
= h
<< 2 | l
<< 1 | m
;
13424 index
= h
<< 1 | l
;
13429 unallocated_encoding(s
);
13436 g_assert_not_reached();
13439 if (!fp_access_check(s
)) {
13444 fpst
= fpstatus_ptr(is_fp16
? FPST_FPCR_F16
: FPST_FPCR
);
13449 switch (16 * u
+ opcode
) {
13450 case 0x0e: /* SDOT */
13451 case 0x1e: /* UDOT */
13452 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, index
,
13453 u
? gen_helper_gvec_udot_idx_b
13454 : gen_helper_gvec_sdot_idx_b
);
13457 switch (extract32(insn
, 22, 2)) {
13458 case 0: /* SUDOT */
13459 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, index
,
13460 gen_helper_gvec_sudot_idx_b
);
13462 case 1: /* BFDOT */
13463 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, index
,
13464 gen_helper_gvec_bfdot_idx
);
13466 case 2: /* USDOT */
13467 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, index
,
13468 gen_helper_gvec_usdot_idx_b
);
13470 case 3: /* BFMLAL{B,T} */
13471 gen_gvec_op4_fpst(s
, 1, rd
, rn
, rm
, rd
, 0, (index
<< 1) | is_q
,
13472 gen_helper_gvec_bfmlal_idx
);
13475 g_assert_not_reached();
13476 case 0x11: /* FCMLA #0 */
13477 case 0x13: /* FCMLA #90 */
13478 case 0x15: /* FCMLA #180 */
13479 case 0x17: /* FCMLA #270 */
13481 int rot
= extract32(insn
, 13, 2);
13482 int data
= (index
<< 2) | rot
;
13483 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s
, rd
),
13484 vec_full_reg_offset(s
, rn
),
13485 vec_full_reg_offset(s
, rm
),
13486 vec_full_reg_offset(s
, rd
), fpst
,
13487 is_q
? 16 : 8, vec_full_reg_size(s
), data
,
13489 ? gen_helper_gvec_fcmlas_idx
13490 : gen_helper_gvec_fcmlah_idx
);
13491 tcg_temp_free_ptr(fpst
);
13495 case 0x00: /* FMLAL */
13496 case 0x04: /* FMLSL */
13497 case 0x18: /* FMLAL2 */
13498 case 0x1c: /* FMLSL2 */
13500 int is_s
= extract32(opcode
, 2, 1);
13502 int data
= (index
<< 2) | (is_2
<< 1) | is_s
;
13503 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
13504 vec_full_reg_offset(s
, rn
),
13505 vec_full_reg_offset(s
, rm
), cpu_env
,
13506 is_q
? 16 : 8, vec_full_reg_size(s
),
13507 data
, gen_helper_gvec_fmlal_idx_a64
);
13511 case 0x08: /* MUL */
13512 if (!is_long
&& !is_scalar
) {
13513 static gen_helper_gvec_3
* const fns
[3] = {
13514 gen_helper_gvec_mul_idx_h
,
13515 gen_helper_gvec_mul_idx_s
,
13516 gen_helper_gvec_mul_idx_d
,
13518 tcg_gen_gvec_3_ool(vec_full_reg_offset(s
, rd
),
13519 vec_full_reg_offset(s
, rn
),
13520 vec_full_reg_offset(s
, rm
),
13521 is_q
? 16 : 8, vec_full_reg_size(s
),
13522 index
, fns
[size
- 1]);
13527 case 0x10: /* MLA */
13528 if (!is_long
&& !is_scalar
) {
13529 static gen_helper_gvec_4
* const fns
[3] = {
13530 gen_helper_gvec_mla_idx_h
,
13531 gen_helper_gvec_mla_idx_s
,
13532 gen_helper_gvec_mla_idx_d
,
13534 tcg_gen_gvec_4_ool(vec_full_reg_offset(s
, rd
),
13535 vec_full_reg_offset(s
, rn
),
13536 vec_full_reg_offset(s
, rm
),
13537 vec_full_reg_offset(s
, rd
),
13538 is_q
? 16 : 8, vec_full_reg_size(s
),
13539 index
, fns
[size
- 1]);
13544 case 0x14: /* MLS */
13545 if (!is_long
&& !is_scalar
) {
13546 static gen_helper_gvec_4
* const fns
[3] = {
13547 gen_helper_gvec_mls_idx_h
,
13548 gen_helper_gvec_mls_idx_s
,
13549 gen_helper_gvec_mls_idx_d
,
13551 tcg_gen_gvec_4_ool(vec_full_reg_offset(s
, rd
),
13552 vec_full_reg_offset(s
, rn
),
13553 vec_full_reg_offset(s
, rm
),
13554 vec_full_reg_offset(s
, rd
),
13555 is_q
? 16 : 8, vec_full_reg_size(s
),
13556 index
, fns
[size
- 1]);
13563 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
13566 assert(is_fp
&& is_q
&& !is_long
);
13568 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
13570 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13571 TCGv_i64 tcg_op
= tcg_temp_new_i64();
13572 TCGv_i64 tcg_res
= tcg_temp_new_i64();
13574 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
13576 switch (16 * u
+ opcode
) {
13577 case 0x05: /* FMLS */
13578 /* As usual for ARM, separate negation for fused multiply-add */
13579 gen_helper_vfp_negd(tcg_op
, tcg_op
);
13581 case 0x01: /* FMLA */
13582 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
13583 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
13585 case 0x09: /* FMUL */
13586 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13588 case 0x19: /* FMULX */
13589 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13592 g_assert_not_reached();
13595 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
13596 tcg_temp_free_i64(tcg_op
);
13597 tcg_temp_free_i64(tcg_res
);
13600 tcg_temp_free_i64(tcg_idx
);
13601 clear_vec_high(s
, !is_scalar
, rd
);
13602 } else if (!is_long
) {
13603 /* 32 bit floating point, or 16 or 32 bit integer.
13604 * For the 16 bit scalar case we use the usual Neon helpers and
13605 * rely on the fact that 0 op 0 == 0 with no side effects.
13607 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13608 int pass
, maxpasses
;
13613 maxpasses
= is_q
? 4 : 2;
13616 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13618 if (size
== 1 && !is_scalar
) {
13619 /* The simplest way to handle the 16x16 indexed ops is to duplicate
13620 * the index into both halves of the 32 bit tcg_idx and then use
13621 * the usual Neon helpers.
13623 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13626 for (pass
= 0; pass
< maxpasses
; pass
++) {
13627 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13628 TCGv_i32 tcg_res
= tcg_temp_new_i32();
13630 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
13632 switch (16 * u
+ opcode
) {
13633 case 0x08: /* MUL */
13634 case 0x10: /* MLA */
13635 case 0x14: /* MLS */
13637 static NeonGenTwoOpFn
* const fns
[2][2] = {
13638 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
13639 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
13641 NeonGenTwoOpFn
*genfn
;
13642 bool is_sub
= opcode
== 0x4;
13645 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
13647 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
13649 if (opcode
== 0x8) {
13652 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
13653 genfn
= fns
[size
- 1][is_sub
];
13654 genfn(tcg_res
, tcg_op
, tcg_res
);
13657 case 0x05: /* FMLS */
13658 case 0x01: /* FMLA */
13659 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13660 is_scalar
? size
: MO_32
);
13663 if (opcode
== 0x5) {
13664 /* As usual for ARM, separate negation for fused
13666 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80008000);
13669 gen_helper_advsimd_muladdh(tcg_res
, tcg_op
, tcg_idx
,
13672 gen_helper_advsimd_muladd2h(tcg_res
, tcg_op
, tcg_idx
,
13677 if (opcode
== 0x5) {
13678 /* As usual for ARM, separate negation for
13679 * fused multiply-add */
13680 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80000000);
13682 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
,
13686 g_assert_not_reached();
13689 case 0x09: /* FMUL */
13693 gen_helper_advsimd_mulh(tcg_res
, tcg_op
,
13696 gen_helper_advsimd_mul2h(tcg_res
, tcg_op
,
13701 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13704 g_assert_not_reached();
13707 case 0x19: /* FMULX */
13711 gen_helper_advsimd_mulxh(tcg_res
, tcg_op
,
13714 gen_helper_advsimd_mulx2h(tcg_res
, tcg_op
,
13719 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13722 g_assert_not_reached();
13725 case 0x0c: /* SQDMULH */
13727 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
13730 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
13734 case 0x0d: /* SQRDMULH */
13736 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
13739 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
13743 case 0x1d: /* SQRDMLAH */
13744 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13745 is_scalar
? size
: MO_32
);
13747 gen_helper_neon_qrdmlah_s16(tcg_res
, cpu_env
,
13748 tcg_op
, tcg_idx
, tcg_res
);
13750 gen_helper_neon_qrdmlah_s32(tcg_res
, cpu_env
,
13751 tcg_op
, tcg_idx
, tcg_res
);
13754 case 0x1f: /* SQRDMLSH */
13755 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13756 is_scalar
? size
: MO_32
);
13758 gen_helper_neon_qrdmlsh_s16(tcg_res
, cpu_env
,
13759 tcg_op
, tcg_idx
, tcg_res
);
13761 gen_helper_neon_qrdmlsh_s32(tcg_res
, cpu_env
,
13762 tcg_op
, tcg_idx
, tcg_res
);
13766 g_assert_not_reached();
13770 write_fp_sreg(s
, rd
, tcg_res
);
13772 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
13775 tcg_temp_free_i32(tcg_op
);
13776 tcg_temp_free_i32(tcg_res
);
13779 tcg_temp_free_i32(tcg_idx
);
13780 clear_vec_high(s
, is_q
, rd
);
13782 /* long ops: 16x16->32 or 32x32->64 */
13783 TCGv_i64 tcg_res
[2];
13785 bool satop
= extract32(opcode
, 0, 1);
13786 MemOp memop
= MO_32
;
13793 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
13795 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
13797 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13798 TCGv_i64 tcg_op
= tcg_temp_new_i64();
13799 TCGv_i64 tcg_passres
;
13805 passelt
= pass
+ (is_q
* 2);
13808 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
13810 tcg_res
[pass
] = tcg_temp_new_i64();
13812 if (opcode
== 0xa || opcode
== 0xb) {
13813 /* Non-accumulating ops */
13814 tcg_passres
= tcg_res
[pass
];
13816 tcg_passres
= tcg_temp_new_i64();
13819 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
13820 tcg_temp_free_i64(tcg_op
);
13823 /* saturating, doubling */
13824 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
13825 tcg_passres
, tcg_passres
);
13828 if (opcode
== 0xa || opcode
== 0xb) {
13832 /* Accumulating op: handle accumulate step */
13833 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13836 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13837 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13839 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13840 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13842 case 0x7: /* SQDMLSL, SQDMLSL2 */
13843 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
13845 case 0x3: /* SQDMLAL, SQDMLAL2 */
13846 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
13851 g_assert_not_reached();
13853 tcg_temp_free_i64(tcg_passres
);
13855 tcg_temp_free_i64(tcg_idx
);
13857 clear_vec_high(s
, !is_scalar
, rd
);
13859 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13862 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13865 /* The simplest way to handle the 16x16 indexed ops is to
13866 * duplicate the index into both halves of the 32 bit tcg_idx
13867 * and then use the usual Neon helpers.
13869 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13872 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13873 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13874 TCGv_i64 tcg_passres
;
13877 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
13879 read_vec_element_i32(s
, tcg_op
, rn
,
13880 pass
+ (is_q
* 2), MO_32
);
13883 tcg_res
[pass
] = tcg_temp_new_i64();
13885 if (opcode
== 0xa || opcode
== 0xb) {
13886 /* Non-accumulating ops */
13887 tcg_passres
= tcg_res
[pass
];
13889 tcg_passres
= tcg_temp_new_i64();
13892 if (memop
& MO_SIGN
) {
13893 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
13895 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
13898 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
13899 tcg_passres
, tcg_passres
);
13901 tcg_temp_free_i32(tcg_op
);
13903 if (opcode
== 0xa || opcode
== 0xb) {
13907 /* Accumulating op: handle accumulate step */
13908 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13911 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13912 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
13915 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13916 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
13919 case 0x7: /* SQDMLSL, SQDMLSL2 */
13920 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
13922 case 0x3: /* SQDMLAL, SQDMLAL2 */
13923 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
13928 g_assert_not_reached();
13930 tcg_temp_free_i64(tcg_passres
);
13932 tcg_temp_free_i32(tcg_idx
);
13935 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
13940 tcg_res
[1] = tcg_constant_i64(0);
13943 for (pass
= 0; pass
< 2; pass
++) {
13944 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13945 tcg_temp_free_i64(tcg_res
[pass
]);
13950 tcg_temp_free_ptr(fpst
);
13955 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13956 * +-----------------+------+-----------+--------+-----+------+------+
13957 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13958 * +-----------------+------+-----------+--------+-----+------+------+
13960 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
13962 int size
= extract32(insn
, 22, 2);
13963 int opcode
= extract32(insn
, 12, 5);
13964 int rn
= extract32(insn
, 5, 5);
13965 int rd
= extract32(insn
, 0, 5);
13967 gen_helper_gvec_2
*genfn2
= NULL
;
13968 gen_helper_gvec_3
*genfn3
= NULL
;
13970 if (!dc_isar_feature(aa64_aes
, s
) || size
!= 0) {
13971 unallocated_encoding(s
);
13976 case 0x4: /* AESE */
13978 genfn3
= gen_helper_crypto_aese
;
13980 case 0x6: /* AESMC */
13982 genfn2
= gen_helper_crypto_aesmc
;
13984 case 0x5: /* AESD */
13986 genfn3
= gen_helper_crypto_aese
;
13988 case 0x7: /* AESIMC */
13990 genfn2
= gen_helper_crypto_aesmc
;
13993 unallocated_encoding(s
);
13997 if (!fp_access_check(s
)) {
14001 gen_gvec_op2_ool(s
, true, rd
, rn
, decrypt
, genfn2
);
14003 gen_gvec_op3_ool(s
, true, rd
, rd
, rn
, decrypt
, genfn3
);
14007 /* Crypto three-reg SHA
14008 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
14009 * +-----------------+------+---+------+---+--------+-----+------+------+
14010 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
14011 * +-----------------+------+---+------+---+--------+-----+------+------+
14013 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
14015 int size
= extract32(insn
, 22, 2);
14016 int opcode
= extract32(insn
, 12, 3);
14017 int rm
= extract32(insn
, 16, 5);
14018 int rn
= extract32(insn
, 5, 5);
14019 int rd
= extract32(insn
, 0, 5);
14020 gen_helper_gvec_3
*genfn
;
14024 unallocated_encoding(s
);
14029 case 0: /* SHA1C */
14030 genfn
= gen_helper_crypto_sha1c
;
14031 feature
= dc_isar_feature(aa64_sha1
, s
);
14033 case 1: /* SHA1P */
14034 genfn
= gen_helper_crypto_sha1p
;
14035 feature
= dc_isar_feature(aa64_sha1
, s
);
14037 case 2: /* SHA1M */
14038 genfn
= gen_helper_crypto_sha1m
;
14039 feature
= dc_isar_feature(aa64_sha1
, s
);
14041 case 3: /* SHA1SU0 */
14042 genfn
= gen_helper_crypto_sha1su0
;
14043 feature
= dc_isar_feature(aa64_sha1
, s
);
14045 case 4: /* SHA256H */
14046 genfn
= gen_helper_crypto_sha256h
;
14047 feature
= dc_isar_feature(aa64_sha256
, s
);
14049 case 5: /* SHA256H2 */
14050 genfn
= gen_helper_crypto_sha256h2
;
14051 feature
= dc_isar_feature(aa64_sha256
, s
);
14053 case 6: /* SHA256SU1 */
14054 genfn
= gen_helper_crypto_sha256su1
;
14055 feature
= dc_isar_feature(aa64_sha256
, s
);
14058 unallocated_encoding(s
);
14063 unallocated_encoding(s
);
14067 if (!fp_access_check(s
)) {
14070 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, 0, genfn
);
14073 /* Crypto two-reg SHA
14074 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
14075 * +-----------------+------+-----------+--------+-----+------+------+
14076 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
14077 * +-----------------+------+-----------+--------+-----+------+------+
14079 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
14081 int size
= extract32(insn
, 22, 2);
14082 int opcode
= extract32(insn
, 12, 5);
14083 int rn
= extract32(insn
, 5, 5);
14084 int rd
= extract32(insn
, 0, 5);
14085 gen_helper_gvec_2
*genfn
;
14089 unallocated_encoding(s
);
14094 case 0: /* SHA1H */
14095 feature
= dc_isar_feature(aa64_sha1
, s
);
14096 genfn
= gen_helper_crypto_sha1h
;
14098 case 1: /* SHA1SU1 */
14099 feature
= dc_isar_feature(aa64_sha1
, s
);
14100 genfn
= gen_helper_crypto_sha1su1
;
14102 case 2: /* SHA256SU0 */
14103 feature
= dc_isar_feature(aa64_sha256
, s
);
14104 genfn
= gen_helper_crypto_sha256su0
;
14107 unallocated_encoding(s
);
14112 unallocated_encoding(s
);
14116 if (!fp_access_check(s
)) {
14119 gen_gvec_op2_ool(s
, true, rd
, rn
, 0, genfn
);
14122 static void gen_rax1_i64(TCGv_i64 d
, TCGv_i64 n
, TCGv_i64 m
)
14124 tcg_gen_rotli_i64(d
, m
, 1);
14125 tcg_gen_xor_i64(d
, d
, n
);
14128 static void gen_rax1_vec(unsigned vece
, TCGv_vec d
, TCGv_vec n
, TCGv_vec m
)
14130 tcg_gen_rotli_vec(vece
, d
, m
, 1);
14131 tcg_gen_xor_vec(vece
, d
, d
, n
);
14134 void gen_gvec_rax1(unsigned vece
, uint32_t rd_ofs
, uint32_t rn_ofs
,
14135 uint32_t rm_ofs
, uint32_t opr_sz
, uint32_t max_sz
)
14137 static const TCGOpcode vecop_list
[] = { INDEX_op_rotli_vec
, 0 };
14138 static const GVecGen3 op
= {
14139 .fni8
= gen_rax1_i64
,
14140 .fniv
= gen_rax1_vec
,
14141 .opt_opc
= vecop_list
,
14142 .fno
= gen_helper_crypto_rax1
,
14145 tcg_gen_gvec_3(rd_ofs
, rn_ofs
, rm_ofs
, opr_sz
, max_sz
, &op
);
14148 /* Crypto three-reg SHA512
14149 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
14150 * +-----------------------+------+---+---+-----+--------+------+------+
14151 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
14152 * +-----------------------+------+---+---+-----+--------+------+------+
14154 static void disas_crypto_three_reg_sha512(DisasContext
*s
, uint32_t insn
)
14156 int opcode
= extract32(insn
, 10, 2);
14157 int o
= extract32(insn
, 14, 1);
14158 int rm
= extract32(insn
, 16, 5);
14159 int rn
= extract32(insn
, 5, 5);
14160 int rd
= extract32(insn
, 0, 5);
14162 gen_helper_gvec_3
*oolfn
= NULL
;
14163 GVecGen3Fn
*gvecfn
= NULL
;
14167 case 0: /* SHA512H */
14168 feature
= dc_isar_feature(aa64_sha512
, s
);
14169 oolfn
= gen_helper_crypto_sha512h
;
14171 case 1: /* SHA512H2 */
14172 feature
= dc_isar_feature(aa64_sha512
, s
);
14173 oolfn
= gen_helper_crypto_sha512h2
;
14175 case 2: /* SHA512SU1 */
14176 feature
= dc_isar_feature(aa64_sha512
, s
);
14177 oolfn
= gen_helper_crypto_sha512su1
;
14180 feature
= dc_isar_feature(aa64_sha3
, s
);
14181 gvecfn
= gen_gvec_rax1
;
14184 g_assert_not_reached();
14188 case 0: /* SM3PARTW1 */
14189 feature
= dc_isar_feature(aa64_sm3
, s
);
14190 oolfn
= gen_helper_crypto_sm3partw1
;
14192 case 1: /* SM3PARTW2 */
14193 feature
= dc_isar_feature(aa64_sm3
, s
);
14194 oolfn
= gen_helper_crypto_sm3partw2
;
14196 case 2: /* SM4EKEY */
14197 feature
= dc_isar_feature(aa64_sm4
, s
);
14198 oolfn
= gen_helper_crypto_sm4ekey
;
14201 unallocated_encoding(s
);
14207 unallocated_encoding(s
);
14211 if (!fp_access_check(s
)) {
14216 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, 0, oolfn
);
14218 gen_gvec_fn3(s
, true, rd
, rn
, rm
, gvecfn
, MO_64
);
14222 /* Crypto two-reg SHA512
14223 * 31 12 11 10 9 5 4 0
14224 * +-----------------------------------------+--------+------+------+
14225 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
14226 * +-----------------------------------------+--------+------+------+
14228 static void disas_crypto_two_reg_sha512(DisasContext
*s
, uint32_t insn
)
14230 int opcode
= extract32(insn
, 10, 2);
14231 int rn
= extract32(insn
, 5, 5);
14232 int rd
= extract32(insn
, 0, 5);
14236 case 0: /* SHA512SU0 */
14237 feature
= dc_isar_feature(aa64_sha512
, s
);
14240 feature
= dc_isar_feature(aa64_sm4
, s
);
14243 unallocated_encoding(s
);
14248 unallocated_encoding(s
);
14252 if (!fp_access_check(s
)) {
14257 case 0: /* SHA512SU0 */
14258 gen_gvec_op2_ool(s
, true, rd
, rn
, 0, gen_helper_crypto_sha512su0
);
14261 gen_gvec_op3_ool(s
, true, rd
, rd
, rn
, 0, gen_helper_crypto_sm4e
);
14264 g_assert_not_reached();
14268 /* Crypto four-register
14269 * 31 23 22 21 20 16 15 14 10 9 5 4 0
14270 * +-------------------+-----+------+---+------+------+------+
14271 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
14272 * +-------------------+-----+------+---+------+------+------+
14274 static void disas_crypto_four_reg(DisasContext
*s
, uint32_t insn
)
14276 int op0
= extract32(insn
, 21, 2);
14277 int rm
= extract32(insn
, 16, 5);
14278 int ra
= extract32(insn
, 10, 5);
14279 int rn
= extract32(insn
, 5, 5);
14280 int rd
= extract32(insn
, 0, 5);
14286 feature
= dc_isar_feature(aa64_sha3
, s
);
14288 case 2: /* SM3SS1 */
14289 feature
= dc_isar_feature(aa64_sm3
, s
);
14292 unallocated_encoding(s
);
14297 unallocated_encoding(s
);
14301 if (!fp_access_check(s
)) {
14306 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
[2];
14309 tcg_op1
= tcg_temp_new_i64();
14310 tcg_op2
= tcg_temp_new_i64();
14311 tcg_op3
= tcg_temp_new_i64();
14312 tcg_res
[0] = tcg_temp_new_i64();
14313 tcg_res
[1] = tcg_temp_new_i64();
14315 for (pass
= 0; pass
< 2; pass
++) {
14316 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
14317 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
14318 read_vec_element(s
, tcg_op3
, ra
, pass
, MO_64
);
14322 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
14325 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
14327 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
14329 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
14330 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
14332 tcg_temp_free_i64(tcg_op1
);
14333 tcg_temp_free_i64(tcg_op2
);
14334 tcg_temp_free_i64(tcg_op3
);
14335 tcg_temp_free_i64(tcg_res
[0]);
14336 tcg_temp_free_i64(tcg_res
[1]);
14338 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
, tcg_zero
;
14340 tcg_op1
= tcg_temp_new_i32();
14341 tcg_op2
= tcg_temp_new_i32();
14342 tcg_op3
= tcg_temp_new_i32();
14343 tcg_res
= tcg_temp_new_i32();
14344 tcg_zero
= tcg_constant_i32(0);
14346 read_vec_element_i32(s
, tcg_op1
, rn
, 3, MO_32
);
14347 read_vec_element_i32(s
, tcg_op2
, rm
, 3, MO_32
);
14348 read_vec_element_i32(s
, tcg_op3
, ra
, 3, MO_32
);
14350 tcg_gen_rotri_i32(tcg_res
, tcg_op1
, 20);
14351 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op2
);
14352 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op3
);
14353 tcg_gen_rotri_i32(tcg_res
, tcg_res
, 25);
14355 write_vec_element_i32(s
, tcg_zero
, rd
, 0, MO_32
);
14356 write_vec_element_i32(s
, tcg_zero
, rd
, 1, MO_32
);
14357 write_vec_element_i32(s
, tcg_zero
, rd
, 2, MO_32
);
14358 write_vec_element_i32(s
, tcg_res
, rd
, 3, MO_32
);
14360 tcg_temp_free_i32(tcg_op1
);
14361 tcg_temp_free_i32(tcg_op2
);
14362 tcg_temp_free_i32(tcg_op3
);
14363 tcg_temp_free_i32(tcg_res
);
14368 * 31 21 20 16 15 10 9 5 4 0
14369 * +-----------------------+------+--------+------+------+
14370 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
14371 * +-----------------------+------+--------+------+------+
14373 static void disas_crypto_xar(DisasContext
*s
, uint32_t insn
)
14375 int rm
= extract32(insn
, 16, 5);
14376 int imm6
= extract32(insn
, 10, 6);
14377 int rn
= extract32(insn
, 5, 5);
14378 int rd
= extract32(insn
, 0, 5);
14380 if (!dc_isar_feature(aa64_sha3
, s
)) {
14381 unallocated_encoding(s
);
14385 if (!fp_access_check(s
)) {
14389 gen_gvec_xar(MO_64
, vec_full_reg_offset(s
, rd
),
14390 vec_full_reg_offset(s
, rn
),
14391 vec_full_reg_offset(s
, rm
), imm6
, 16,
14392 vec_full_reg_size(s
));
14395 /* Crypto three-reg imm2
14396 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
14397 * +-----------------------+------+-----+------+--------+------+------+
14398 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
14399 * +-----------------------+------+-----+------+--------+------+------+
14401 static void disas_crypto_three_reg_imm2(DisasContext
*s
, uint32_t insn
)
14403 static gen_helper_gvec_3
* const fns
[4] = {
14404 gen_helper_crypto_sm3tt1a
, gen_helper_crypto_sm3tt1b
,
14405 gen_helper_crypto_sm3tt2a
, gen_helper_crypto_sm3tt2b
,
14407 int opcode
= extract32(insn
, 10, 2);
14408 int imm2
= extract32(insn
, 12, 2);
14409 int rm
= extract32(insn
, 16, 5);
14410 int rn
= extract32(insn
, 5, 5);
14411 int rd
= extract32(insn
, 0, 5);
14413 if (!dc_isar_feature(aa64_sm3
, s
)) {
14414 unallocated_encoding(s
);
14418 if (!fp_access_check(s
)) {
14422 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, imm2
, fns
[opcode
]);
14425 /* C3.6 Data processing - SIMD, inc Crypto
14427 * As the decode gets a little complex we are using a table based
14428 * approach for this part of the decode.
14430 static const AArch64DecodeTable data_proc_simd
[] = {
14431 /* pattern , mask , fn */
14432 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
14433 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra
},
14434 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
14435 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
14436 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
14437 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
14438 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
14439 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
14440 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
14441 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
14442 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
14443 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
14444 { 0x2e000000, 0xbf208400, disas_simd_ext
},
14445 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
14446 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra
},
14447 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
14448 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
14449 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
14450 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
14451 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
14452 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
14453 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
14454 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
14455 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
14456 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512
},
14457 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512
},
14458 { 0xce000000, 0xff808000, disas_crypto_four_reg
},
14459 { 0xce800000, 0xffe00000, disas_crypto_xar
},
14460 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2
},
14461 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16
},
14462 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16
},
14463 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16
},
14464 { 0x00000000, 0x00000000, NULL
}
14467 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
14469 /* Note that this is called with all non-FP cases from
14470 * table C3-6 so it must UNDEF for entries not specifically
14471 * allocated to instructions in that table.
14473 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
14477 unallocated_encoding(s
);
14481 /* C3.6 Data processing - SIMD and floating point */
14482 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
14484 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
14485 disas_data_proc_fp(s
, insn
);
14487 /* SIMD, including crypto */
14488 disas_data_proc_simd(s
, insn
);
14494 * @env: The cpu environment
14495 * @s: The DisasContext
14497 * Return true if the page is guarded.
14499 static bool is_guarded_page(CPUARMState
*env
, DisasContext
*s
)
14501 uint64_t addr
= s
->base
.pc_first
;
14502 #ifdef CONFIG_USER_ONLY
14503 return page_get_flags(addr
) & PAGE_BTI
;
14505 int mmu_idx
= arm_to_core_mmu_idx(s
->mmu_idx
);
14506 unsigned int index
= tlb_index(env
, mmu_idx
, addr
);
14507 CPUTLBEntry
*entry
= tlb_entry(env
, mmu_idx
, addr
);
14510 * We test this immediately after reading an insn, which means
14511 * that any normal page must be in the TLB. The only exception
14512 * would be for executing from flash or device memory, which
14513 * does not retain the TLB entry.
14515 * FIXME: Assume false for those, for now. We could use
14516 * arm_cpu_get_phys_page_attrs_debug to re-read the page
14517 * table entry even for that case.
14519 return (tlb_hit(entry
->addr_code
, addr
) &&
14520 arm_tlb_bti_gp(&env_tlb(env
)->d
[mmu_idx
].iotlb
[index
].attrs
));
14525 * btype_destination_ok:
14526 * @insn: The instruction at the branch destination
14527 * @bt: SCTLR_ELx.BT
14528 * @btype: PSTATE.BTYPE, and is non-zero
14530 * On a guarded page, there are a limited number of insns
14531 * that may be present at the branch target:
14532 * - branch target identifiers,
14533 * - paciasp, pacibsp,
14536 * Anything else causes a Branch Target Exception.
14538 * Return true if the branch is compatible, false to raise BTITRAP.
14540 static bool btype_destination_ok(uint32_t insn
, bool bt
, int btype
)
14542 if ((insn
& 0xfffff01fu
) == 0xd503201fu
) {
14544 switch (extract32(insn
, 5, 7)) {
14545 case 0b011001: /* PACIASP */
14546 case 0b011011: /* PACIBSP */
14548 * If SCTLR_ELx.BT, then PACI*SP are not compatible
14549 * with btype == 3. Otherwise all btype are ok.
14551 return !bt
|| btype
!= 3;
14552 case 0b100000: /* BTI */
14553 /* Not compatible with any btype. */
14555 case 0b100010: /* BTI c */
14556 /* Not compatible with btype == 3 */
14558 case 0b100100: /* BTI j */
14559 /* Not compatible with btype == 2 */
14561 case 0b100110: /* BTI jc */
14562 /* Compatible with any btype. */
14566 switch (insn
& 0xffe0001fu
) {
14567 case 0xd4200000u
: /* BRK */
14568 case 0xd4400000u
: /* HLT */
14569 /* Give priority to the breakpoint exception. */
14576 static void aarch64_tr_init_disas_context(DisasContextBase
*dcbase
,
14579 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14580 CPUARMState
*env
= cpu
->env_ptr
;
14581 ARMCPU
*arm_cpu
= env_archcpu(env
);
14582 CPUARMTBFlags tb_flags
= arm_tbflags_from_tb(dc
->base
.tb
);
14583 int bound
, core_mmu_idx
;
14585 dc
->isar
= &arm_cpu
->isar
;
14588 dc
->aarch64
= true;
14589 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
14590 * there is no secure EL1, so we route exceptions to EL3.
14592 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
14593 !arm_el_is_aa64(env
, 3);
14596 dc
->be_data
= EX_TBFLAG_ANY(tb_flags
, BE_DATA
) ? MO_BE
: MO_LE
;
14597 dc
->condexec_mask
= 0;
14598 dc
->condexec_cond
= 0;
14599 core_mmu_idx
= EX_TBFLAG_ANY(tb_flags
, MMUIDX
);
14600 dc
->mmu_idx
= core_to_aa64_mmu_idx(core_mmu_idx
);
14601 dc
->tbii
= EX_TBFLAG_A64(tb_flags
, TBII
);
14602 dc
->tbid
= EX_TBFLAG_A64(tb_flags
, TBID
);
14603 dc
->tcma
= EX_TBFLAG_A64(tb_flags
, TCMA
);
14604 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
14605 #if !defined(CONFIG_USER_ONLY)
14606 dc
->user
= (dc
->current_el
== 0);
14608 dc
->fp_excp_el
= EX_TBFLAG_ANY(tb_flags
, FPEXC_EL
);
14609 dc
->align_mem
= EX_TBFLAG_ANY(tb_flags
, ALIGN_MEM
);
14610 dc
->pstate_il
= EX_TBFLAG_ANY(tb_flags
, PSTATE__IL
);
14611 dc
->sve_excp_el
= EX_TBFLAG_A64(tb_flags
, SVEEXC_EL
);
14612 dc
->vl
= (EX_TBFLAG_A64(tb_flags
, VL
) + 1) * 16;
14613 dc
->pauth_active
= EX_TBFLAG_A64(tb_flags
, PAUTH_ACTIVE
);
14614 dc
->bt
= EX_TBFLAG_A64(tb_flags
, BT
);
14615 dc
->btype
= EX_TBFLAG_A64(tb_flags
, BTYPE
);
14616 dc
->unpriv
= EX_TBFLAG_A64(tb_flags
, UNPRIV
);
14617 dc
->ata
= EX_TBFLAG_A64(tb_flags
, ATA
);
14618 dc
->mte_active
[0] = EX_TBFLAG_A64(tb_flags
, MTE_ACTIVE
);
14619 dc
->mte_active
[1] = EX_TBFLAG_A64(tb_flags
, MTE0_ACTIVE
);
14621 dc
->vec_stride
= 0;
14622 dc
->cp_regs
= arm_cpu
->cp_regs
;
14623 dc
->features
= env
->features
;
14624 dc
->dcz_blocksize
= arm_cpu
->dcz_blocksize
;
14626 #ifdef CONFIG_USER_ONLY
14627 /* In sve_probe_page, we assume TBI is enabled. */
14628 tcg_debug_assert(dc
->tbid
& 1);
14631 /* Single step state. The code-generation logic here is:
14633 * generate code with no special handling for single-stepping (except
14634 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
14635 * this happens anyway because those changes are all system register or
14637 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
14638 * emit code for one insn
14639 * emit code to clear PSTATE.SS
14640 * emit code to generate software step exception for completed step
14641 * end TB (as usual for having generated an exception)
14642 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
14643 * emit code to generate a software step exception
14646 dc
->ss_active
= EX_TBFLAG_ANY(tb_flags
, SS_ACTIVE
);
14647 dc
->pstate_ss
= EX_TBFLAG_ANY(tb_flags
, PSTATE__SS
);
14648 dc
->is_ldex
= false;
14649 dc
->debug_target_el
= EX_TBFLAG_ANY(tb_flags
, DEBUG_TARGET_EL
);
14651 /* Bound the number of insns to execute to those left on the page. */
14652 bound
= -(dc
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
14654 /* If architectural single step active, limit to 1. */
14655 if (dc
->ss_active
) {
14658 dc
->base
.max_insns
= MIN(dc
->base
.max_insns
, bound
);
14660 init_tmp_a64_array(dc
);
14663 static void aarch64_tr_tb_start(DisasContextBase
*db
, CPUState
*cpu
)
14667 static void aarch64_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
14669 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14671 tcg_gen_insn_start(dc
->base
.pc_next
, 0, 0);
14672 dc
->insn_start
= tcg_last_op();
14675 static void aarch64_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
14677 DisasContext
*s
= container_of(dcbase
, DisasContext
, base
);
14678 CPUARMState
*env
= cpu
->env_ptr
;
14679 uint64_t pc
= s
->base
.pc_next
;
14682 /* Singlestep exceptions have the highest priority. */
14683 if (s
->ss_active
&& !s
->pstate_ss
) {
14684 /* Singlestep state is Active-pending.
14685 * If we're in this state at the start of a TB then either
14686 * a) we just took an exception to an EL which is being debugged
14687 * and this is the first insn in the exception handler
14688 * b) debug exceptions were masked and we just unmasked them
14689 * without changing EL (eg by clearing PSTATE.D)
14690 * In either case we're going to take a swstep exception in the
14691 * "did not step an insn" case, and so the syndrome ISV and EX
14692 * bits should be zero.
14694 assert(s
->base
.num_insns
== 1);
14695 gen_swstep_exception(s
, 0, 0);
14696 s
->base
.is_jmp
= DISAS_NORETURN
;
14697 s
->base
.pc_next
= pc
+ 4;
14703 * PC alignment fault. This has priority over the instruction abort
14704 * that we would receive from a translation fault via arm_ldl_code.
14705 * This should only be possible after an indirect branch, at the
14708 assert(s
->base
.num_insns
== 1);
14709 gen_helper_exception_pc_alignment(cpu_env
, tcg_constant_tl(pc
));
14710 s
->base
.is_jmp
= DISAS_NORETURN
;
14711 s
->base
.pc_next
= QEMU_ALIGN_UP(pc
, 4);
14716 insn
= arm_ldl_code(env
, &s
->base
, pc
, s
->sctlr_b
);
14718 s
->base
.pc_next
= pc
+ 4;
14720 s
->fp_access_checked
= false;
14721 s
->sve_access_checked
= false;
14723 if (s
->pstate_il
) {
14725 * Illegal execution state. This has priority over BTI
14726 * exceptions, but comes after instruction abort exceptions.
14728 gen_exception_insn_el(s
, s
->pc_curr
, EXCP_UDEF
,
14729 syn_illegalstate(), default_exception_el(s
));
14733 if (dc_isar_feature(aa64_bti
, s
)) {
14734 if (s
->base
.num_insns
== 1) {
14736 * At the first insn of the TB, compute s->guarded_page.
14737 * We delayed computing this until successfully reading
14738 * the first insn of the TB, above. This (mostly) ensures
14739 * that the softmmu tlb entry has been populated, and the
14740 * page table GP bit is available.
14742 * Note that we need to compute this even if btype == 0,
14743 * because this value is used for BR instructions later
14744 * where ENV is not available.
14746 s
->guarded_page
= is_guarded_page(env
, s
);
14748 /* First insn can have btype set to non-zero. */
14749 tcg_debug_assert(s
->btype
>= 0);
14752 * Note that the Branch Target Exception has fairly high
14753 * priority -- below debugging exceptions but above most
14754 * everything else. This allows us to handle this now
14755 * instead of waiting until the insn is otherwise decoded.
14759 && !btype_destination_ok(insn
, s
->bt
, s
->btype
)) {
14760 gen_exception_insn_el(s
, s
->pc_curr
, EXCP_UDEF
,
14761 syn_btitrap(s
->btype
),
14762 default_exception_el(s
));
14766 /* Not the first insn: btype must be 0. */
14767 tcg_debug_assert(s
->btype
== 0);
14771 switch (extract32(insn
, 25, 4)) {
14772 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
14773 unallocated_encoding(s
);
14776 if (!disas_sve(s
, insn
)) {
14777 unallocated_encoding(s
);
14780 case 0x8: case 0x9: /* Data processing - immediate */
14781 disas_data_proc_imm(s
, insn
);
14783 case 0xa: case 0xb: /* Branch, exception generation and system insns */
14784 disas_b_exc_sys(s
, insn
);
14789 case 0xe: /* Loads and stores */
14790 disas_ldst(s
, insn
);
14793 case 0xd: /* Data processing - register */
14794 disas_data_proc_reg(s
, insn
);
14797 case 0xf: /* Data processing - SIMD and floating point */
14798 disas_data_proc_simd_fp(s
, insn
);
14801 assert(FALSE
); /* all 15 cases should be handled above */
14805 /* if we allocated any temporaries, free them here */
14809 * After execution of most insns, btype is reset to 0.
14810 * Note that we set btype == -1 when the insn sets btype.
14812 if (s
->btype
> 0 && s
->base
.is_jmp
!= DISAS_NORETURN
) {
14816 translator_loop_temp_check(&s
->base
);
14819 static void aarch64_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
14821 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14823 if (unlikely(dc
->ss_active
)) {
14824 /* Note that this means single stepping WFI doesn't halt the CPU.
14825 * For conditional branch insns this is harmless unreachable code as
14826 * gen_goto_tb() has already handled emitting the debug exception
14827 * (and thus a tb-jump is not possible when singlestepping).
14829 switch (dc
->base
.is_jmp
) {
14831 gen_a64_set_pc_im(dc
->base
.pc_next
);
14835 gen_step_complete_exception(dc
);
14837 case DISAS_NORETURN
:
14841 switch (dc
->base
.is_jmp
) {
14843 case DISAS_TOO_MANY
:
14844 gen_goto_tb(dc
, 1, dc
->base
.pc_next
);
14847 case DISAS_UPDATE_EXIT
:
14848 gen_a64_set_pc_im(dc
->base
.pc_next
);
14851 tcg_gen_exit_tb(NULL
, 0);
14853 case DISAS_UPDATE_NOCHAIN
:
14854 gen_a64_set_pc_im(dc
->base
.pc_next
);
14857 tcg_gen_lookup_and_goto_ptr();
14859 case DISAS_NORETURN
:
14863 gen_a64_set_pc_im(dc
->base
.pc_next
);
14864 gen_helper_wfe(cpu_env
);
14867 gen_a64_set_pc_im(dc
->base
.pc_next
);
14868 gen_helper_yield(cpu_env
);
14872 * This is a special case because we don't want to just halt
14873 * the CPU if trying to debug across a WFI.
14875 gen_a64_set_pc_im(dc
->base
.pc_next
);
14876 gen_helper_wfi(cpu_env
, tcg_constant_i32(4));
14878 * The helper doesn't necessarily throw an exception, but we
14879 * must go back to the main loop to check for interrupts anyway.
14881 tcg_gen_exit_tb(NULL
, 0);
14887 static void aarch64_tr_disas_log(const DisasContextBase
*dcbase
,
14888 CPUState
*cpu
, FILE *logfile
)
14890 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14892 fprintf(logfile
, "IN: %s\n", lookup_symbol(dc
->base
.pc_first
));
14893 target_disas(logfile
, cpu
, dc
->base
.pc_first
, dc
->base
.tb
->size
);
14896 const TranslatorOps aarch64_translator_ops
= {
14897 .init_disas_context
= aarch64_tr_init_disas_context
,
14898 .tb_start
= aarch64_tr_tb_start
,
14899 .insn_start
= aarch64_tr_insn_start
,
14900 .translate_insn
= aarch64_tr_translate_insn
,
14901 .tb_stop
= aarch64_tr_tb_stop
,
14902 .disas_log
= aarch64_tr_disas_log
,