4 * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
22 #include "exec/exec-all.h"
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"
31 #include "hw/semihosting/semihost.h"
32 #include "exec/gen-icount.h"
34 #include "exec/helper-proto.h"
35 #include "exec/helper-gen.h"
38 #include "trace-tcg.h"
39 #include "translate-a64.h"
40 #include "qemu/atomic128.h"
42 static TCGv_i64 cpu_X
[32];
43 static TCGv_i64 cpu_pc
;
45 /* Load/store exclusive handling */
46 static TCGv_i64 cpu_exclusive_high
;
48 static const char *regnames
[] = {
49 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
50 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
51 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
52 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
56 A64_SHIFT_TYPE_LSL
= 0,
57 A64_SHIFT_TYPE_LSR
= 1,
58 A64_SHIFT_TYPE_ASR
= 2,
59 A64_SHIFT_TYPE_ROR
= 3
62 /* Table based decoder typedefs - used when the relevant bits for decode
63 * are too awkwardly scattered across the instruction (eg SIMD).
65 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
67 typedef struct AArch64DecodeTable
{
70 AArch64DecodeFn
*disas_fn
;
73 /* initialize TCG globals. */
74 void a64_translate_init(void)
78 cpu_pc
= tcg_global_mem_new_i64(cpu_env
,
79 offsetof(CPUARMState
, pc
),
81 for (i
= 0; i
< 32; i
++) {
82 cpu_X
[i
] = tcg_global_mem_new_i64(cpu_env
,
83 offsetof(CPUARMState
, xregs
[i
]),
87 cpu_exclusive_high
= tcg_global_mem_new_i64(cpu_env
,
88 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
92 * Return the core mmu_idx to use for A64 "unprivileged load/store" insns
94 static int get_a64_user_mem_index(DisasContext
*s
)
97 * If AccType_UNPRIV is not used, the insn uses AccType_NORMAL,
98 * which is the usual mmu_idx for this cpu state.
100 ARMMMUIdx useridx
= s
->mmu_idx
;
104 * We have pre-computed the condition for AccType_UNPRIV.
105 * Therefore we should never get here with a mmu_idx for
106 * which we do not know the corresponding user mmu_idx.
109 case ARMMMUIdx_E10_1
:
110 case ARMMMUIdx_E10_1_PAN
:
111 useridx
= ARMMMUIdx_E10_0
;
113 case ARMMMUIdx_E20_2
:
114 case ARMMMUIdx_E20_2_PAN
:
115 useridx
= ARMMMUIdx_E20_0
;
117 case ARMMMUIdx_SE10_1
:
118 case ARMMMUIdx_SE10_1_PAN
:
119 useridx
= ARMMMUIdx_SE10_0
;
122 g_assert_not_reached();
125 return arm_to_core_mmu_idx(useridx
);
128 static void reset_btype(DisasContext
*s
)
131 TCGv_i32 zero
= tcg_const_i32(0);
132 tcg_gen_st_i32(zero
, cpu_env
, offsetof(CPUARMState
, btype
));
133 tcg_temp_free_i32(zero
);
138 static void set_btype(DisasContext
*s
, int val
)
142 /* BTYPE is a 2-bit field, and 0 should be done with reset_btype. */
143 tcg_debug_assert(val
>= 1 && val
<= 3);
145 tcg_val
= tcg_const_i32(val
);
146 tcg_gen_st_i32(tcg_val
, cpu_env
, offsetof(CPUARMState
, btype
));
147 tcg_temp_free_i32(tcg_val
);
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);
183 TCGv_i64 tcg_zero
= tcg_const_i64(0);
186 * The two TBI bits differ.
187 * If tbi0, then !tbi1: only use the extension if positive.
188 * if !tbi0, then tbi1: only use the extension if negative.
190 tcg_gen_movcond_i64(tbi
== 1 ? TCG_COND_GE
: TCG_COND_LT
,
191 dst
, dst
, tcg_zero
, dst
, src
);
192 tcg_temp_free_i64(tcg_zero
);
197 static void gen_a64_set_pc(DisasContext
*s
, TCGv_i64 src
)
200 * If address tagging is enabled for instructions via the TCR TBI bits,
201 * then loading an address into the PC will clear out any tag.
203 gen_top_byte_ignore(s
, cpu_pc
, src
, s
->tbii
);
207 * Handle MTE and/or TBI.
209 * For TBI, ideally, we would do nothing. Proper behaviour on fault is
210 * for the tag to be present in the FAR_ELx register. But for user-only
211 * mode we do not have a TLB with which to implement this, so we must
212 * remove the top byte now.
214 * Always return a fresh temporary that we can increment independently
215 * of the write-back address.
218 TCGv_i64
clean_data_tbi(DisasContext
*s
, TCGv_i64 addr
)
220 TCGv_i64 clean
= new_tmp_a64(s
);
221 #ifdef CONFIG_USER_ONLY
222 gen_top_byte_ignore(s
, clean
, addr
, s
->tbid
);
224 tcg_gen_mov_i64(clean
, addr
);
229 /* Insert a zero tag into src, with the result at dst. */
230 static void gen_address_with_allocation_tag0(TCGv_i64 dst
, TCGv_i64 src
)
232 tcg_gen_andi_i64(dst
, src
, ~MAKE_64BIT_MASK(56, 4));
235 static void gen_probe_access(DisasContext
*s
, TCGv_i64 ptr
,
236 MMUAccessType acc
, int log2_size
)
238 TCGv_i32 t_acc
= tcg_const_i32(acc
);
239 TCGv_i32 t_idx
= tcg_const_i32(get_mem_index(s
));
240 TCGv_i32 t_size
= tcg_const_i32(1 << log2_size
);
242 gen_helper_probe_access(cpu_env
, ptr
, t_acc
, t_idx
, t_size
);
243 tcg_temp_free_i32(t_acc
);
244 tcg_temp_free_i32(t_idx
);
245 tcg_temp_free_i32(t_size
);
249 * For MTE, check a single logical or atomic access. This probes a single
250 * address, the exact one specified. The size and alignment of the access
251 * is not relevant to MTE, per se, but watchpoints do require the size,
252 * and we want to recognize those before making any other changes to state.
254 static TCGv_i64
gen_mte_check1_mmuidx(DisasContext
*s
, TCGv_i64 addr
,
255 bool is_write
, bool tag_checked
,
256 int log2_size
, bool is_unpriv
,
259 if (tag_checked
&& s
->mte_active
[is_unpriv
]) {
264 desc
= FIELD_DP32(desc
, MTEDESC
, MIDX
, core_idx
);
265 desc
= FIELD_DP32(desc
, MTEDESC
, TBI
, s
->tbid
);
266 desc
= FIELD_DP32(desc
, MTEDESC
, TCMA
, s
->tcma
);
267 desc
= FIELD_DP32(desc
, MTEDESC
, WRITE
, is_write
);
268 desc
= FIELD_DP32(desc
, MTEDESC
, ESIZE
, 1 << log2_size
);
269 tcg_desc
= tcg_const_i32(desc
);
271 ret
= new_tmp_a64(s
);
272 gen_helper_mte_check1(ret
, cpu_env
, tcg_desc
, addr
);
273 tcg_temp_free_i32(tcg_desc
);
277 return clean_data_tbi(s
, addr
);
280 TCGv_i64
gen_mte_check1(DisasContext
*s
, TCGv_i64 addr
, bool is_write
,
281 bool tag_checked
, int log2_size
)
283 return gen_mte_check1_mmuidx(s
, addr
, is_write
, tag_checked
, log2_size
,
284 false, get_mem_index(s
));
288 * For MTE, check multiple logical sequential accesses.
290 TCGv_i64
gen_mte_checkN(DisasContext
*s
, TCGv_i64 addr
, bool is_write
,
291 bool tag_checked
, int log2_esize
, int total_size
)
293 if (tag_checked
&& s
->mte_active
[0] && total_size
!= (1 << log2_esize
)) {
298 desc
= FIELD_DP32(desc
, MTEDESC
, MIDX
, get_mem_index(s
));
299 desc
= FIELD_DP32(desc
, MTEDESC
, TBI
, s
->tbid
);
300 desc
= FIELD_DP32(desc
, MTEDESC
, TCMA
, s
->tcma
);
301 desc
= FIELD_DP32(desc
, MTEDESC
, WRITE
, is_write
);
302 desc
= FIELD_DP32(desc
, MTEDESC
, ESIZE
, 1 << log2_esize
);
303 desc
= FIELD_DP32(desc
, MTEDESC
, TSIZE
, total_size
);
304 tcg_desc
= tcg_const_i32(desc
);
306 ret
= new_tmp_a64(s
);
307 gen_helper_mte_checkN(ret
, cpu_env
, tcg_desc
, addr
);
308 tcg_temp_free_i32(tcg_desc
);
312 return gen_mte_check1(s
, addr
, is_write
, tag_checked
, log2_esize
);
315 typedef struct DisasCompare64
{
320 static void a64_test_cc(DisasCompare64
*c64
, int cc
)
324 arm_test_cc(&c32
, cc
);
326 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
327 * properly. The NE/EQ comparisons are also fine with this choice. */
328 c64
->cond
= c32
.cond
;
329 c64
->value
= tcg_temp_new_i64();
330 tcg_gen_ext_i32_i64(c64
->value
, c32
.value
);
335 static void a64_free_cc(DisasCompare64
*c64
)
337 tcg_temp_free_i64(c64
->value
);
340 static void gen_exception_internal(int excp
)
342 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
344 assert(excp_is_internal(excp
));
345 gen_helper_exception_internal(cpu_env
, tcg_excp
);
346 tcg_temp_free_i32(tcg_excp
);
349 static void gen_exception_internal_insn(DisasContext
*s
, uint64_t pc
, int excp
)
351 gen_a64_set_pc_im(pc
);
352 gen_exception_internal(excp
);
353 s
->base
.is_jmp
= DISAS_NORETURN
;
356 static void gen_exception_insn(DisasContext
*s
, uint64_t pc
, int excp
,
357 uint32_t syndrome
, uint32_t target_el
)
359 gen_a64_set_pc_im(pc
);
360 gen_exception(excp
, syndrome
, target_el
);
361 s
->base
.is_jmp
= DISAS_NORETURN
;
364 static void gen_exception_bkpt_insn(DisasContext
*s
, uint32_t syndrome
)
368 gen_a64_set_pc_im(s
->pc_curr
);
369 tcg_syn
= tcg_const_i32(syndrome
);
370 gen_helper_exception_bkpt_insn(cpu_env
, tcg_syn
);
371 tcg_temp_free_i32(tcg_syn
);
372 s
->base
.is_jmp
= DISAS_NORETURN
;
375 static void gen_step_complete_exception(DisasContext
*s
)
377 /* We just completed step of an insn. Move from Active-not-pending
378 * to Active-pending, and then also take the swstep exception.
379 * This corresponds to making the (IMPDEF) choice to prioritize
380 * swstep exceptions over asynchronous exceptions taken to an exception
381 * level where debug is disabled. This choice has the advantage that
382 * we do not need to maintain internal state corresponding to the
383 * ISV/EX syndrome bits between completion of the step and generation
384 * of the exception, and our syndrome information is always correct.
387 gen_swstep_exception(s
, 1, s
->is_ldex
);
388 s
->base
.is_jmp
= DISAS_NORETURN
;
391 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
393 /* No direct tb linking with singlestep (either QEMU's or the ARM
394 * debug architecture kind) or deterministic io
396 if (s
->base
.singlestep_enabled
|| s
->ss_active
||
397 (tb_cflags(s
->base
.tb
) & CF_LAST_IO
)) {
401 #ifndef CONFIG_USER_ONLY
402 /* Only link tbs from inside the same guest page */
403 if ((s
->base
.tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
411 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
413 TranslationBlock
*tb
;
416 if (use_goto_tb(s
, n
, dest
)) {
418 gen_a64_set_pc_im(dest
);
419 tcg_gen_exit_tb(tb
, n
);
420 s
->base
.is_jmp
= DISAS_NORETURN
;
422 gen_a64_set_pc_im(dest
);
424 gen_step_complete_exception(s
);
425 } else if (s
->base
.singlestep_enabled
) {
426 gen_exception_internal(EXCP_DEBUG
);
428 tcg_gen_lookup_and_goto_ptr();
429 s
->base
.is_jmp
= DISAS_NORETURN
;
434 void unallocated_encoding(DisasContext
*s
)
436 /* Unallocated and reserved encodings are uncategorized */
437 gen_exception_insn(s
, s
->pc_curr
, EXCP_UDEF
, syn_uncategorized(),
438 default_exception_el(s
));
441 static void init_tmp_a64_array(DisasContext
*s
)
443 #ifdef CONFIG_DEBUG_TCG
444 memset(s
->tmp_a64
, 0, sizeof(s
->tmp_a64
));
446 s
->tmp_a64_count
= 0;
449 static void free_tmp_a64(DisasContext
*s
)
452 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
453 tcg_temp_free_i64(s
->tmp_a64
[i
]);
455 init_tmp_a64_array(s
);
458 TCGv_i64
new_tmp_a64(DisasContext
*s
)
460 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
461 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
464 TCGv_i64
new_tmp_a64_local(DisasContext
*s
)
466 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
467 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_local_new_i64();
470 TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
472 TCGv_i64 t
= new_tmp_a64(s
);
473 tcg_gen_movi_i64(t
, 0);
478 * Register access functions
480 * These functions are used for directly accessing a register in where
481 * changes to the final register value are likely to be made. If you
482 * need to use a register for temporary calculation (e.g. index type
483 * operations) use the read_* form.
485 * B1.2.1 Register mappings
487 * In instruction register encoding 31 can refer to ZR (zero register) or
488 * the SP (stack pointer) depending on context. In QEMU's case we map SP
489 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
490 * This is the point of the _sp forms.
492 TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
495 return new_tmp_a64_zero(s
);
501 /* register access for when 31 == SP */
502 TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
507 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
508 * representing the register contents. This TCGv is an auto-freed
509 * temporary so it need not be explicitly freed, and may be modified.
511 TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
513 TCGv_i64 v
= new_tmp_a64(s
);
516 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
518 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
521 tcg_gen_movi_i64(v
, 0);
526 TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
528 TCGv_i64 v
= new_tmp_a64(s
);
530 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
532 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
537 /* Return the offset into CPUARMState of a slice (from
538 * the least significant end) of FP register Qn (ie
540 * (Note that this is not the same mapping as for A32; see cpu.h)
542 static inline int fp_reg_offset(DisasContext
*s
, int regno
, MemOp size
)
544 return vec_reg_offset(s
, regno
, 0, size
);
547 /* Offset of the high half of the 128 bit vector Qn */
548 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
550 return vec_reg_offset(s
, regno
, 1, MO_64
);
553 /* Convenience accessors for reading and writing single and double
554 * FP registers. Writing clears the upper parts of the associated
555 * 128 bit vector register, as required by the architecture.
556 * Note that unlike the GP register accessors, the values returned
557 * by the read functions must be manually freed.
559 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
561 TCGv_i64 v
= tcg_temp_new_i64();
563 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
567 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
569 TCGv_i32 v
= tcg_temp_new_i32();
571 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
575 static TCGv_i32
read_fp_hreg(DisasContext
*s
, int reg
)
577 TCGv_i32 v
= tcg_temp_new_i32();
579 tcg_gen_ld16u_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_16
));
583 /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64).
584 * If SVE is not enabled, then there are only 128 bits in the vector.
586 static void clear_vec_high(DisasContext
*s
, bool is_q
, int rd
)
588 unsigned ofs
= fp_reg_offset(s
, rd
, MO_64
);
589 unsigned vsz
= vec_full_reg_size(s
);
591 /* Nop move, with side effect of clearing the tail. */
592 tcg_gen_gvec_mov(MO_64
, ofs
, ofs
, is_q
? 16 : 8, vsz
);
595 void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
597 unsigned ofs
= fp_reg_offset(s
, reg
, MO_64
);
599 tcg_gen_st_i64(v
, cpu_env
, ofs
);
600 clear_vec_high(s
, false, reg
);
603 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
605 TCGv_i64 tmp
= tcg_temp_new_i64();
607 tcg_gen_extu_i32_i64(tmp
, v
);
608 write_fp_dreg(s
, reg
, tmp
);
609 tcg_temp_free_i64(tmp
);
612 TCGv_ptr
get_fpstatus_ptr(bool is_f16
)
614 TCGv_ptr statusptr
= tcg_temp_new_ptr();
617 /* In A64 all instructions (both FP and Neon) use the FPCR; there
618 * is no equivalent of the A32 Neon "standard FPSCR value".
619 * However half-precision operations operate under a different
620 * FZ16 flag and use vfp.fp_status_f16 instead of vfp.fp_status.
623 offset
= offsetof(CPUARMState
, vfp
.fp_status_f16
);
625 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
627 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
631 /* Expand a 2-operand AdvSIMD vector operation using an expander function. */
632 static void gen_gvec_fn2(DisasContext
*s
, bool is_q
, int rd
, int rn
,
633 GVecGen2Fn
*gvec_fn
, int vece
)
635 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
636 is_q
? 16 : 8, vec_full_reg_size(s
));
639 /* Expand a 2-operand + immediate AdvSIMD vector operation using
640 * an expander function.
642 static void gen_gvec_fn2i(DisasContext
*s
, bool is_q
, int rd
, int rn
,
643 int64_t imm
, GVecGen2iFn
*gvec_fn
, int vece
)
645 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
646 imm
, is_q
? 16 : 8, vec_full_reg_size(s
));
649 /* Expand a 3-operand AdvSIMD vector operation using an expander function. */
650 static void gen_gvec_fn3(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
651 GVecGen3Fn
*gvec_fn
, int vece
)
653 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
654 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8, vec_full_reg_size(s
));
657 /* Expand a 4-operand AdvSIMD vector operation using an expander function. */
658 static void gen_gvec_fn4(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
659 int rx
, GVecGen4Fn
*gvec_fn
, int vece
)
661 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
662 vec_full_reg_offset(s
, rm
), vec_full_reg_offset(s
, rx
),
663 is_q
? 16 : 8, vec_full_reg_size(s
));
666 /* Expand a 2-operand operation using an out-of-line helper. */
667 static void gen_gvec_op2_ool(DisasContext
*s
, bool is_q
, int rd
,
668 int rn
, int data
, gen_helper_gvec_2
*fn
)
670 tcg_gen_gvec_2_ool(vec_full_reg_offset(s
, rd
),
671 vec_full_reg_offset(s
, rn
),
672 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
675 /* Expand a 3-operand operation using an out-of-line helper. */
676 static void gen_gvec_op3_ool(DisasContext
*s
, bool is_q
, int rd
,
677 int rn
, int rm
, int data
, gen_helper_gvec_3
*fn
)
679 tcg_gen_gvec_3_ool(vec_full_reg_offset(s
, rd
),
680 vec_full_reg_offset(s
, rn
),
681 vec_full_reg_offset(s
, rm
),
682 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
685 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
686 * an out-of-line helper.
688 static void gen_gvec_op3_fpst(DisasContext
*s
, bool is_q
, int rd
, int rn
,
689 int rm
, bool is_fp16
, int data
,
690 gen_helper_gvec_3_ptr
*fn
)
692 TCGv_ptr fpst
= get_fpstatus_ptr(is_fp16
);
693 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
694 vec_full_reg_offset(s
, rn
),
695 vec_full_reg_offset(s
, rm
), fpst
,
696 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
697 tcg_temp_free_ptr(fpst
);
700 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
701 * than the 32 bit equivalent.
703 static inline void gen_set_NZ64(TCGv_i64 result
)
705 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
706 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
709 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
710 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
713 gen_set_NZ64(result
);
715 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
716 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
718 tcg_gen_movi_i32(cpu_CF
, 0);
719 tcg_gen_movi_i32(cpu_VF
, 0);
722 /* dest = T0 + T1; compute C, N, V and Z flags */
723 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
726 TCGv_i64 result
, flag
, tmp
;
727 result
= tcg_temp_new_i64();
728 flag
= tcg_temp_new_i64();
729 tmp
= tcg_temp_new_i64();
731 tcg_gen_movi_i64(tmp
, 0);
732 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
734 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
736 gen_set_NZ64(result
);
738 tcg_gen_xor_i64(flag
, result
, t0
);
739 tcg_gen_xor_i64(tmp
, t0
, t1
);
740 tcg_gen_andc_i64(flag
, flag
, tmp
);
741 tcg_temp_free_i64(tmp
);
742 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
744 tcg_gen_mov_i64(dest
, result
);
745 tcg_temp_free_i64(result
);
746 tcg_temp_free_i64(flag
);
748 /* 32 bit arithmetic */
749 TCGv_i32 t0_32
= tcg_temp_new_i32();
750 TCGv_i32 t1_32
= tcg_temp_new_i32();
751 TCGv_i32 tmp
= tcg_temp_new_i32();
753 tcg_gen_movi_i32(tmp
, 0);
754 tcg_gen_extrl_i64_i32(t0_32
, t0
);
755 tcg_gen_extrl_i64_i32(t1_32
, t1
);
756 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
757 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
758 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
759 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
760 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
761 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
763 tcg_temp_free_i32(tmp
);
764 tcg_temp_free_i32(t0_32
);
765 tcg_temp_free_i32(t1_32
);
769 /* dest = T0 - T1; compute C, N, V and Z flags */
770 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
773 /* 64 bit arithmetic */
774 TCGv_i64 result
, flag
, tmp
;
776 result
= tcg_temp_new_i64();
777 flag
= tcg_temp_new_i64();
778 tcg_gen_sub_i64(result
, t0
, t1
);
780 gen_set_NZ64(result
);
782 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
783 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
785 tcg_gen_xor_i64(flag
, result
, t0
);
786 tmp
= tcg_temp_new_i64();
787 tcg_gen_xor_i64(tmp
, t0
, t1
);
788 tcg_gen_and_i64(flag
, flag
, tmp
);
789 tcg_temp_free_i64(tmp
);
790 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
791 tcg_gen_mov_i64(dest
, result
);
792 tcg_temp_free_i64(flag
);
793 tcg_temp_free_i64(result
);
795 /* 32 bit arithmetic */
796 TCGv_i32 t0_32
= tcg_temp_new_i32();
797 TCGv_i32 t1_32
= tcg_temp_new_i32();
800 tcg_gen_extrl_i64_i32(t0_32
, t0
);
801 tcg_gen_extrl_i64_i32(t1_32
, t1
);
802 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
803 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
804 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
805 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
806 tmp
= tcg_temp_new_i32();
807 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
808 tcg_temp_free_i32(t0_32
);
809 tcg_temp_free_i32(t1_32
);
810 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
811 tcg_temp_free_i32(tmp
);
812 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
816 /* dest = T0 + T1 + CF; do not compute flags. */
817 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
819 TCGv_i64 flag
= tcg_temp_new_i64();
820 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
821 tcg_gen_add_i64(dest
, t0
, t1
);
822 tcg_gen_add_i64(dest
, dest
, flag
);
823 tcg_temp_free_i64(flag
);
826 tcg_gen_ext32u_i64(dest
, dest
);
830 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
831 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
834 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
835 result
= tcg_temp_new_i64();
836 cf_64
= tcg_temp_new_i64();
837 vf_64
= tcg_temp_new_i64();
838 tmp
= tcg_const_i64(0);
840 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
841 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
842 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
843 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
844 gen_set_NZ64(result
);
846 tcg_gen_xor_i64(vf_64
, result
, t0
);
847 tcg_gen_xor_i64(tmp
, t0
, t1
);
848 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
849 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
851 tcg_gen_mov_i64(dest
, result
);
853 tcg_temp_free_i64(tmp
);
854 tcg_temp_free_i64(vf_64
);
855 tcg_temp_free_i64(cf_64
);
856 tcg_temp_free_i64(result
);
858 TCGv_i32 t0_32
, t1_32
, tmp
;
859 t0_32
= tcg_temp_new_i32();
860 t1_32
= tcg_temp_new_i32();
861 tmp
= tcg_const_i32(0);
863 tcg_gen_extrl_i64_i32(t0_32
, t0
);
864 tcg_gen_extrl_i64_i32(t1_32
, t1
);
865 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
866 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
868 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
869 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
870 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
871 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
872 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
874 tcg_temp_free_i32(tmp
);
875 tcg_temp_free_i32(t1_32
);
876 tcg_temp_free_i32(t0_32
);
881 * Load/Store generators
885 * Store from GPR register to memory.
887 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
888 TCGv_i64 tcg_addr
, int size
, int memidx
,
890 unsigned int iss_srt
,
891 bool iss_sf
, bool iss_ar
)
894 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, s
->be_data
+ size
);
899 syn
= syn_data_abort_with_iss(0,
905 0, 0, 0, 0, 0, false);
906 disas_set_insn_syndrome(s
, syn
);
910 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
911 TCGv_i64 tcg_addr
, int size
,
913 unsigned int iss_srt
,
914 bool iss_sf
, bool iss_ar
)
916 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
),
917 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
921 * Load from memory to GPR register
923 static void do_gpr_ld_memidx(DisasContext
*s
,
924 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
925 int size
, bool is_signed
,
926 bool extend
, int memidx
,
927 bool iss_valid
, unsigned int iss_srt
,
928 bool iss_sf
, bool iss_ar
)
930 MemOp memop
= s
->be_data
+ size
;
938 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
940 if (extend
&& is_signed
) {
942 tcg_gen_ext32u_i64(dest
, dest
);
948 syn
= syn_data_abort_with_iss(0,
954 0, 0, 0, 0, 0, false);
955 disas_set_insn_syndrome(s
, syn
);
959 static void do_gpr_ld(DisasContext
*s
,
960 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
961 int size
, bool is_signed
, bool extend
,
962 bool iss_valid
, unsigned int iss_srt
,
963 bool iss_sf
, bool iss_ar
)
965 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
967 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
971 * Store from FP register to memory
973 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
975 /* This writes the bottom N bits of a 128 bit wide vector to memory */
976 TCGv_i64 tmp
= tcg_temp_new_i64();
977 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
979 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
),
982 bool be
= s
->be_data
== MO_BE
;
983 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
985 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
986 tcg_gen_qemu_st_i64(tmp
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
988 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
989 tcg_gen_qemu_st_i64(tmp
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
991 tcg_temp_free_i64(tcg_hiaddr
);
994 tcg_temp_free_i64(tmp
);
998 * Load from memory to FP register
1000 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
1002 /* This always zero-extends and writes to a full 128 bit wide vector */
1003 TCGv_i64 tmplo
= tcg_temp_new_i64();
1004 TCGv_i64 tmphi
= NULL
;
1007 MemOp memop
= s
->be_data
+ size
;
1008 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
1010 bool be
= s
->be_data
== MO_BE
;
1011 TCGv_i64 tcg_hiaddr
;
1013 tmphi
= tcg_temp_new_i64();
1014 tcg_hiaddr
= tcg_temp_new_i64();
1016 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
1017 tcg_gen_qemu_ld_i64(tmplo
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
1019 tcg_gen_qemu_ld_i64(tmphi
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
1021 tcg_temp_free_i64(tcg_hiaddr
);
1024 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
1025 tcg_temp_free_i64(tmplo
);
1028 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
1029 tcg_temp_free_i64(tmphi
);
1031 clear_vec_high(s
, tmphi
!= NULL
, destidx
);
1035 * Vector load/store helpers.
1037 * The principal difference between this and a FP load is that we don't
1038 * zero extend as we are filling a partial chunk of the vector register.
1039 * These functions don't support 128 bit loads/stores, which would be
1040 * normal load/store operations.
1042 * The _i32 versions are useful when operating on 32 bit quantities
1043 * (eg for floating point single or using Neon helper functions).
1046 /* Get value of an element within a vector register */
1047 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
1048 int element
, MemOp memop
)
1050 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1053 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
1056 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
1059 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
1062 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
1065 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
1068 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
1072 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
1075 g_assert_not_reached();
1079 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
1080 int element
, MemOp memop
)
1082 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1085 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
1088 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
1091 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
1094 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
1098 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
1101 g_assert_not_reached();
1105 /* Set value of an element within a vector register */
1106 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
1107 int element
, MemOp memop
)
1109 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1112 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
1115 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
1118 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
1121 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
1124 g_assert_not_reached();
1128 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
1129 int destidx
, int element
, MemOp memop
)
1131 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1134 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
1137 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
1140 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
1143 g_assert_not_reached();
1147 /* Store from vector register to memory */
1148 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
1149 TCGv_i64 tcg_addr
, int size
, MemOp endian
)
1151 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1153 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
1154 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), endian
| size
);
1156 tcg_temp_free_i64(tcg_tmp
);
1159 /* Load from memory to vector register */
1160 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
1161 TCGv_i64 tcg_addr
, int size
, MemOp endian
)
1163 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1165 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), endian
| size
);
1166 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
1168 tcg_temp_free_i64(tcg_tmp
);
1171 /* Check that FP/Neon access is enabled. If it is, return
1172 * true. If not, emit code to generate an appropriate exception,
1173 * and return false; the caller should not emit any code for
1174 * the instruction. Note that this check must happen after all
1175 * unallocated-encoding checks (otherwise the syndrome information
1176 * for the resulting exception will be incorrect).
1178 static inline bool fp_access_check(DisasContext
*s
)
1180 assert(!s
->fp_access_checked
);
1181 s
->fp_access_checked
= true;
1183 if (!s
->fp_excp_el
) {
1187 gen_exception_insn(s
, s
->pc_curr
, EXCP_UDEF
,
1188 syn_fp_access_trap(1, 0xe, false), s
->fp_excp_el
);
1192 /* Check that SVE access is enabled. If it is, return true.
1193 * If not, emit code to generate an appropriate exception and return false.
1195 bool sve_access_check(DisasContext
*s
)
1197 if (s
->sve_excp_el
) {
1198 gen_exception_insn(s
, s
->pc_curr
, EXCP_UDEF
, syn_sve_access_trap(),
1202 return fp_access_check(s
);
1206 * This utility function is for doing register extension with an
1207 * optional shift. You will likely want to pass a temporary for the
1208 * destination register. See DecodeRegExtend() in the ARM ARM.
1210 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1211 int option
, unsigned int shift
)
1213 int extsize
= extract32(option
, 0, 2);
1214 bool is_signed
= extract32(option
, 2, 1);
1219 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1222 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1225 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1228 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1234 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1237 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1240 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1243 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1249 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1253 static inline void gen_check_sp_alignment(DisasContext
*s
)
1255 /* The AArch64 architecture mandates that (if enabled via PSTATE
1256 * or SCTLR bits) there is a check that SP is 16-aligned on every
1257 * SP-relative load or store (with an exception generated if it is not).
1258 * In line with general QEMU practice regarding misaligned accesses,
1259 * we omit these checks for the sake of guest program performance.
1260 * This function is provided as a hook so we can more easily add these
1261 * checks in future (possibly as a "favour catching guest program bugs
1262 * over speed" user selectable option).
1267 * This provides a simple table based table lookup decoder. It is
1268 * intended to be used when the relevant bits for decode are too
1269 * awkwardly placed and switch/if based logic would be confusing and
1270 * deeply nested. Since it's a linear search through the table, tables
1271 * should be kept small.
1273 * It returns the first handler where insn & mask == pattern, or
1274 * NULL if there is no match.
1275 * The table is terminated by an empty mask (i.e. 0)
1277 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1280 const AArch64DecodeTable
*tptr
= table
;
1282 while (tptr
->mask
) {
1283 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1284 return tptr
->disas_fn
;
1292 * The instruction disassembly implemented here matches
1293 * the instruction encoding classifications in chapter C4
1294 * of the ARM Architecture Reference Manual (DDI0487B_a);
1295 * classification names and decode diagrams here should generally
1296 * match up with those in the manual.
1299 /* Unconditional branch (immediate)
1301 * +----+-----------+-------------------------------------+
1302 * | op | 0 0 1 0 1 | imm26 |
1303 * +----+-----------+-------------------------------------+
1305 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1307 uint64_t addr
= s
->pc_curr
+ sextract32(insn
, 0, 26) * 4;
1309 if (insn
& (1U << 31)) {
1310 /* BL Branch with link */
1311 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->base
.pc_next
);
1314 /* B Branch / BL Branch with link */
1316 gen_goto_tb(s
, 0, addr
);
1319 /* Compare and branch (immediate)
1320 * 31 30 25 24 23 5 4 0
1321 * +----+-------------+----+---------------------+--------+
1322 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1323 * +----+-------------+----+---------------------+--------+
1325 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1327 unsigned int sf
, op
, rt
;
1329 TCGLabel
*label_match
;
1332 sf
= extract32(insn
, 31, 1);
1333 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1334 rt
= extract32(insn
, 0, 5);
1335 addr
= s
->pc_curr
+ sextract32(insn
, 5, 19) * 4;
1337 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1338 label_match
= gen_new_label();
1341 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1342 tcg_cmp
, 0, label_match
);
1344 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1345 gen_set_label(label_match
);
1346 gen_goto_tb(s
, 1, addr
);
1349 /* Test and branch (immediate)
1350 * 31 30 25 24 23 19 18 5 4 0
1351 * +----+-------------+----+-------+-------------+------+
1352 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1353 * +----+-------------+----+-------+-------------+------+
1355 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1357 unsigned int bit_pos
, op
, rt
;
1359 TCGLabel
*label_match
;
1362 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1363 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1364 addr
= s
->pc_curr
+ sextract32(insn
, 5, 14) * 4;
1365 rt
= extract32(insn
, 0, 5);
1367 tcg_cmp
= tcg_temp_new_i64();
1368 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1369 label_match
= gen_new_label();
1372 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1373 tcg_cmp
, 0, label_match
);
1374 tcg_temp_free_i64(tcg_cmp
);
1375 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1376 gen_set_label(label_match
);
1377 gen_goto_tb(s
, 1, addr
);
1380 /* Conditional branch (immediate)
1381 * 31 25 24 23 5 4 3 0
1382 * +---------------+----+---------------------+----+------+
1383 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1384 * +---------------+----+---------------------+----+------+
1386 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1391 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1392 unallocated_encoding(s
);
1395 addr
= s
->pc_curr
+ sextract32(insn
, 5, 19) * 4;
1396 cond
= extract32(insn
, 0, 4);
1400 /* genuinely conditional branches */
1401 TCGLabel
*label_match
= gen_new_label();
1402 arm_gen_test_cc(cond
, label_match
);
1403 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1404 gen_set_label(label_match
);
1405 gen_goto_tb(s
, 1, addr
);
1407 /* 0xe and 0xf are both "always" conditions */
1408 gen_goto_tb(s
, 0, addr
);
1412 /* HINT instruction group, including various allocated HINTs */
1413 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1414 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1416 unsigned int selector
= crm
<< 3 | op2
;
1419 unallocated_encoding(s
);
1424 case 0b00000: /* NOP */
1426 case 0b00011: /* WFI */
1427 s
->base
.is_jmp
= DISAS_WFI
;
1429 case 0b00001: /* YIELD */
1430 /* When running in MTTCG we don't generate jumps to the yield and
1431 * WFE helpers as it won't affect the scheduling of other vCPUs.
1432 * If we wanted to more completely model WFE/SEV so we don't busy
1433 * spin unnecessarily we would need to do something more involved.
1435 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1436 s
->base
.is_jmp
= DISAS_YIELD
;
1439 case 0b00010: /* WFE */
1440 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1441 s
->base
.is_jmp
= DISAS_WFE
;
1444 case 0b00100: /* SEV */
1445 case 0b00101: /* SEVL */
1446 /* we treat all as NOP at least for now */
1448 case 0b00111: /* XPACLRI */
1449 if (s
->pauth_active
) {
1450 gen_helper_xpaci(cpu_X
[30], cpu_env
, cpu_X
[30]);
1453 case 0b01000: /* PACIA1716 */
1454 if (s
->pauth_active
) {
1455 gen_helper_pacia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1458 case 0b01010: /* PACIB1716 */
1459 if (s
->pauth_active
) {
1460 gen_helper_pacib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1463 case 0b01100: /* AUTIA1716 */
1464 if (s
->pauth_active
) {
1465 gen_helper_autia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1468 case 0b01110: /* AUTIB1716 */
1469 if (s
->pauth_active
) {
1470 gen_helper_autib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1473 case 0b11000: /* PACIAZ */
1474 if (s
->pauth_active
) {
1475 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30],
1476 new_tmp_a64_zero(s
));
1479 case 0b11001: /* PACIASP */
1480 if (s
->pauth_active
) {
1481 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1484 case 0b11010: /* PACIBZ */
1485 if (s
->pauth_active
) {
1486 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30],
1487 new_tmp_a64_zero(s
));
1490 case 0b11011: /* PACIBSP */
1491 if (s
->pauth_active
) {
1492 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1495 case 0b11100: /* AUTIAZ */
1496 if (s
->pauth_active
) {
1497 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30],
1498 new_tmp_a64_zero(s
));
1501 case 0b11101: /* AUTIASP */
1502 if (s
->pauth_active
) {
1503 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1506 case 0b11110: /* AUTIBZ */
1507 if (s
->pauth_active
) {
1508 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30],
1509 new_tmp_a64_zero(s
));
1512 case 0b11111: /* AUTIBSP */
1513 if (s
->pauth_active
) {
1514 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1518 /* default specified as NOP equivalent */
1523 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1525 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1528 /* CLREX, DSB, DMB, ISB */
1529 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1530 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1535 unallocated_encoding(s
);
1546 case 1: /* MBReqTypes_Reads */
1547 bar
= TCG_BAR_SC
| TCG_MO_LD_LD
| TCG_MO_LD_ST
;
1549 case 2: /* MBReqTypes_Writes */
1550 bar
= TCG_BAR_SC
| TCG_MO_ST_ST
;
1552 default: /* MBReqTypes_All */
1553 bar
= TCG_BAR_SC
| TCG_MO_ALL
;
1559 /* We need to break the TB after this insn to execute
1560 * a self-modified code correctly and also to take
1561 * any pending interrupts immediately.
1564 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1568 if (crm
!= 0 || !dc_isar_feature(aa64_sb
, s
)) {
1569 goto do_unallocated
;
1572 * TODO: There is no speculation barrier opcode for TCG;
1573 * MB and end the TB instead.
1575 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
1576 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1581 unallocated_encoding(s
);
1586 static void gen_xaflag(void)
1588 TCGv_i32 z
= tcg_temp_new_i32();
1590 tcg_gen_setcondi_i32(TCG_COND_EQ
, z
, cpu_ZF
, 0);
1599 tcg_gen_or_i32(cpu_NF
, cpu_CF
, z
);
1600 tcg_gen_subi_i32(cpu_NF
, cpu_NF
, 1);
1603 tcg_gen_and_i32(cpu_ZF
, z
, cpu_CF
);
1604 tcg_gen_xori_i32(cpu_ZF
, cpu_ZF
, 1);
1606 /* (!C & Z) << 31 -> -(Z & ~C) */
1607 tcg_gen_andc_i32(cpu_VF
, z
, cpu_CF
);
1608 tcg_gen_neg_i32(cpu_VF
, cpu_VF
);
1611 tcg_gen_or_i32(cpu_CF
, cpu_CF
, z
);
1613 tcg_temp_free_i32(z
);
1616 static void gen_axflag(void)
1618 tcg_gen_sari_i32(cpu_VF
, cpu_VF
, 31); /* V ? -1 : 0 */
1619 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, cpu_VF
); /* C & !V */
1621 /* !(Z | V) -> !(!ZF | V) -> ZF & !V -> ZF & ~VF */
1622 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, cpu_VF
);
1624 tcg_gen_movi_i32(cpu_NF
, 0);
1625 tcg_gen_movi_i32(cpu_VF
, 0);
1628 /* MSR (immediate) - move immediate to processor state field */
1629 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1630 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1633 int op
= op1
<< 3 | op2
;
1635 /* End the TB by default, chaining is ok. */
1636 s
->base
.is_jmp
= DISAS_TOO_MANY
;
1639 case 0x00: /* CFINV */
1640 if (crm
!= 0 || !dc_isar_feature(aa64_condm_4
, s
)) {
1641 goto do_unallocated
;
1643 tcg_gen_xori_i32(cpu_CF
, cpu_CF
, 1);
1644 s
->base
.is_jmp
= DISAS_NEXT
;
1647 case 0x01: /* XAFlag */
1648 if (crm
!= 0 || !dc_isar_feature(aa64_condm_5
, s
)) {
1649 goto do_unallocated
;
1652 s
->base
.is_jmp
= DISAS_NEXT
;
1655 case 0x02: /* AXFlag */
1656 if (crm
!= 0 || !dc_isar_feature(aa64_condm_5
, s
)) {
1657 goto do_unallocated
;
1660 s
->base
.is_jmp
= DISAS_NEXT
;
1663 case 0x03: /* UAO */
1664 if (!dc_isar_feature(aa64_uao
, s
) || s
->current_el
== 0) {
1665 goto do_unallocated
;
1668 set_pstate_bits(PSTATE_UAO
);
1670 clear_pstate_bits(PSTATE_UAO
);
1672 t1
= tcg_const_i32(s
->current_el
);
1673 gen_helper_rebuild_hflags_a64(cpu_env
, t1
);
1674 tcg_temp_free_i32(t1
);
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 t1
= tcg_const_i32(s
->current_el
);
1687 gen_helper_rebuild_hflags_a64(cpu_env
, t1
);
1688 tcg_temp_free_i32(t1
);
1691 case 0x05: /* SPSel */
1692 if (s
->current_el
== 0) {
1693 goto do_unallocated
;
1695 t1
= tcg_const_i32(crm
& PSTATE_SP
);
1696 gen_helper_msr_i_spsel(cpu_env
, t1
);
1697 tcg_temp_free_i32(t1
);
1700 case 0x1e: /* DAIFSet */
1701 t1
= tcg_const_i32(crm
);
1702 gen_helper_msr_i_daifset(cpu_env
, t1
);
1703 tcg_temp_free_i32(t1
);
1706 case 0x1f: /* DAIFClear */
1707 t1
= tcg_const_i32(crm
);
1708 gen_helper_msr_i_daifclear(cpu_env
, t1
);
1709 tcg_temp_free_i32(t1
);
1710 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1711 s
->base
.is_jmp
= DISAS_UPDATE_EXIT
;
1714 case 0x1c: /* TCO */
1715 if (dc_isar_feature(aa64_mte
, s
)) {
1716 /* Full MTE is enabled -- set the TCO bit as directed. */
1718 set_pstate_bits(PSTATE_TCO
);
1720 clear_pstate_bits(PSTATE_TCO
);
1722 t1
= tcg_const_i32(s
->current_el
);
1723 gen_helper_rebuild_hflags_a64(cpu_env
, t1
);
1724 tcg_temp_free_i32(t1
);
1725 /* Many factors, including TCO, go into MTE_ACTIVE. */
1726 s
->base
.is_jmp
= DISAS_UPDATE_NOCHAIN
;
1727 } else if (dc_isar_feature(aa64_mte_insn_reg
, s
)) {
1728 /* Only "instructions accessible at EL0" -- PSTATE.TCO is WI. */
1729 s
->base
.is_jmp
= DISAS_NEXT
;
1731 goto do_unallocated
;
1737 unallocated_encoding(s
);
1742 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1744 TCGv_i32 tmp
= tcg_temp_new_i32();
1745 TCGv_i32 nzcv
= tcg_temp_new_i32();
1747 /* build bit 31, N */
1748 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1749 /* build bit 30, Z */
1750 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1751 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1752 /* build bit 29, C */
1753 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1754 /* build bit 28, V */
1755 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1756 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1757 /* generate result */
1758 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1760 tcg_temp_free_i32(nzcv
);
1761 tcg_temp_free_i32(tmp
);
1764 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1766 TCGv_i32 nzcv
= tcg_temp_new_i32();
1768 /* take NZCV from R[t] */
1769 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1772 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1774 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1775 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1777 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1778 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1780 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1781 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1782 tcg_temp_free_i32(nzcv
);
1785 /* MRS - move from system register
1786 * MSR (register) - move to system register
1789 * These are all essentially the same insn in 'read' and 'write'
1790 * versions, with varying op0 fields.
1792 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1793 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1794 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1796 const ARMCPRegInfo
*ri
;
1799 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1800 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1801 crn
, crm
, op0
, op1
, op2
));
1804 /* Unknown register; this might be a guest error or a QEMU
1805 * unimplemented feature.
1807 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1808 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1809 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1810 unallocated_encoding(s
);
1814 /* Check access permissions */
1815 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1816 unallocated_encoding(s
);
1821 /* Emit code to perform further access permissions checks at
1822 * runtime; this may result in an exception.
1825 TCGv_i32 tcg_syn
, tcg_isread
;
1828 gen_a64_set_pc_im(s
->pc_curr
);
1829 tmpptr
= tcg_const_ptr(ri
);
1830 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1831 tcg_syn
= tcg_const_i32(syndrome
);
1832 tcg_isread
= tcg_const_i32(isread
);
1833 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
, tcg_isread
);
1834 tcg_temp_free_ptr(tmpptr
);
1835 tcg_temp_free_i32(tcg_syn
);
1836 tcg_temp_free_i32(tcg_isread
);
1837 } else if (ri
->type
& ARM_CP_RAISES_EXC
) {
1839 * The readfn or writefn might raise an exception;
1840 * synchronize the CPU state in case it does.
1842 gen_a64_set_pc_im(s
->pc_curr
);
1845 /* Handle special cases first */
1846 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1850 tcg_rt
= cpu_reg(s
, rt
);
1852 gen_get_nzcv(tcg_rt
);
1854 gen_set_nzcv(tcg_rt
);
1857 case ARM_CP_CURRENTEL
:
1858 /* Reads as current EL value from pstate, which is
1859 * guaranteed to be constant by the tb flags.
1861 tcg_rt
= cpu_reg(s
, rt
);
1862 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1865 /* Writes clear the aligned block of memory which rt points into. */
1866 if (s
->mte_active
[0]) {
1870 desc
= FIELD_DP32(desc
, MTEDESC
, MIDX
, get_mem_index(s
));
1871 desc
= FIELD_DP32(desc
, MTEDESC
, TBI
, s
->tbid
);
1872 desc
= FIELD_DP32(desc
, MTEDESC
, TCMA
, s
->tcma
);
1873 t_desc
= tcg_const_i32(desc
);
1875 tcg_rt
= new_tmp_a64(s
);
1876 gen_helper_mte_check_zva(tcg_rt
, cpu_env
, t_desc
, cpu_reg(s
, rt
));
1877 tcg_temp_free_i32(t_desc
);
1879 tcg_rt
= clean_data_tbi(s
, cpu_reg(s
, rt
));
1881 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1885 TCGv_i64 clean_addr
, tag
;
1888 * DC_GVA, like DC_ZVA, requires that we supply the original
1889 * pointer for an invalid page. Probe that address first.
1891 tcg_rt
= cpu_reg(s
, rt
);
1892 clean_addr
= clean_data_tbi(s
, tcg_rt
);
1893 gen_probe_access(s
, clean_addr
, MMU_DATA_STORE
, MO_8
);
1896 /* Extract the tag from the register to match STZGM. */
1897 tag
= tcg_temp_new_i64();
1898 tcg_gen_shri_i64(tag
, tcg_rt
, 56);
1899 gen_helper_stzgm_tags(cpu_env
, clean_addr
, tag
);
1900 tcg_temp_free_i64(tag
);
1904 case ARM_CP_DC_GZVA
:
1906 TCGv_i64 clean_addr
, tag
;
1908 /* For DC_GZVA, we can rely on DC_ZVA for the proper fault. */
1909 tcg_rt
= cpu_reg(s
, rt
);
1910 clean_addr
= clean_data_tbi(s
, tcg_rt
);
1911 gen_helper_dc_zva(cpu_env
, clean_addr
);
1914 /* Extract the tag from the register to match STZGM. */
1915 tag
= tcg_temp_new_i64();
1916 tcg_gen_shri_i64(tag
, tcg_rt
, 56);
1917 gen_helper_stzgm_tags(cpu_env
, clean_addr
, tag
);
1918 tcg_temp_free_i64(tag
);
1925 if ((ri
->type
& ARM_CP_FPU
) && !fp_access_check(s
)) {
1927 } else if ((ri
->type
& ARM_CP_SVE
) && !sve_access_check(s
)) {
1931 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1935 tcg_rt
= cpu_reg(s
, rt
);
1938 if (ri
->type
& ARM_CP_CONST
) {
1939 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1940 } else if (ri
->readfn
) {
1942 tmpptr
= tcg_const_ptr(ri
);
1943 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1944 tcg_temp_free_ptr(tmpptr
);
1946 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1949 if (ri
->type
& ARM_CP_CONST
) {
1950 /* If not forbidden by access permissions, treat as WI */
1952 } else if (ri
->writefn
) {
1954 tmpptr
= tcg_const_ptr(ri
);
1955 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1956 tcg_temp_free_ptr(tmpptr
);
1958 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1962 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1963 /* I/O operations must end the TB here (whether read or write) */
1964 s
->base
.is_jmp
= DISAS_UPDATE_EXIT
;
1966 if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1968 * A write to any coprocessor regiser that ends a TB
1969 * must rebuild the hflags for the next TB.
1971 TCGv_i32 tcg_el
= tcg_const_i32(s
->current_el
);
1972 gen_helper_rebuild_hflags_a64(cpu_env
, tcg_el
);
1973 tcg_temp_free_i32(tcg_el
);
1975 * We default to ending the TB on a coprocessor register write,
1976 * but allow this to be suppressed by the register definition
1977 * (usually only necessary to work around guest bugs).
1979 s
->base
.is_jmp
= DISAS_UPDATE_EXIT
;
1984 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1985 * +---------------------+---+-----+-----+-------+-------+-----+------+
1986 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1987 * +---------------------+---+-----+-----+-------+-------+-----+------+
1989 static void disas_system(DisasContext
*s
, uint32_t insn
)
1991 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1992 l
= extract32(insn
, 21, 1);
1993 op0
= extract32(insn
, 19, 2);
1994 op1
= extract32(insn
, 16, 3);
1995 crn
= extract32(insn
, 12, 4);
1996 crm
= extract32(insn
, 8, 4);
1997 op2
= extract32(insn
, 5, 3);
1998 rt
= extract32(insn
, 0, 5);
2001 if (l
|| rt
!= 31) {
2002 unallocated_encoding(s
);
2006 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
2007 handle_hint(s
, insn
, op1
, op2
, crm
);
2009 case 3: /* CLREX, DSB, DMB, ISB */
2010 handle_sync(s
, insn
, op1
, op2
, crm
);
2012 case 4: /* MSR (immediate) */
2013 handle_msr_i(s
, insn
, op1
, op2
, crm
);
2016 unallocated_encoding(s
);
2021 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
2024 /* Exception generation
2026 * 31 24 23 21 20 5 4 2 1 0
2027 * +-----------------+-----+------------------------+-----+----+
2028 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
2029 * +-----------------------+------------------------+----------+
2031 static void disas_exc(DisasContext
*s
, uint32_t insn
)
2033 int opc
= extract32(insn
, 21, 3);
2034 int op2_ll
= extract32(insn
, 0, 5);
2035 int imm16
= extract32(insn
, 5, 16);
2040 /* For SVC, HVC and SMC we advance the single-step state
2041 * machine before taking the exception. This is architecturally
2042 * mandated, to ensure that single-stepping a system call
2043 * instruction works properly.
2048 gen_exception_insn(s
, s
->base
.pc_next
, EXCP_SWI
,
2049 syn_aa64_svc(imm16
), default_exception_el(s
));
2052 if (s
->current_el
== 0) {
2053 unallocated_encoding(s
);
2056 /* The pre HVC helper handles cases when HVC gets trapped
2057 * as an undefined insn by runtime configuration.
2059 gen_a64_set_pc_im(s
->pc_curr
);
2060 gen_helper_pre_hvc(cpu_env
);
2062 gen_exception_insn(s
, s
->base
.pc_next
, EXCP_HVC
,
2063 syn_aa64_hvc(imm16
), 2);
2066 if (s
->current_el
== 0) {
2067 unallocated_encoding(s
);
2070 gen_a64_set_pc_im(s
->pc_curr
);
2071 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
2072 gen_helper_pre_smc(cpu_env
, tmp
);
2073 tcg_temp_free_i32(tmp
);
2075 gen_exception_insn(s
, s
->base
.pc_next
, EXCP_SMC
,
2076 syn_aa64_smc(imm16
), 3);
2079 unallocated_encoding(s
);
2085 unallocated_encoding(s
);
2089 gen_exception_bkpt_insn(s
, syn_aa64_bkpt(imm16
));
2093 unallocated_encoding(s
);
2096 /* HLT. This has two purposes.
2097 * Architecturally, it is an external halting debug instruction.
2098 * Since QEMU doesn't implement external debug, we treat this as
2099 * it is required for halting debug disabled: it will UNDEF.
2100 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
2102 if (semihosting_enabled() && imm16
== 0xf000) {
2103 #ifndef CONFIG_USER_ONLY
2104 /* In system mode, don't allow userspace access to semihosting,
2105 * to provide some semblance of security (and for consistency
2106 * with our 32-bit semihosting).
2108 if (s
->current_el
== 0) {
2109 unsupported_encoding(s
, insn
);
2113 gen_exception_internal_insn(s
, s
->pc_curr
, EXCP_SEMIHOST
);
2115 unsupported_encoding(s
, insn
);
2119 if (op2_ll
< 1 || op2_ll
> 3) {
2120 unallocated_encoding(s
);
2123 /* DCPS1, DCPS2, DCPS3 */
2124 unsupported_encoding(s
, insn
);
2127 unallocated_encoding(s
);
2132 /* Unconditional branch (register)
2133 * 31 25 24 21 20 16 15 10 9 5 4 0
2134 * +---------------+-------+-------+-------+------+-------+
2135 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
2136 * +---------------+-------+-------+-------+------+-------+
2138 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
2140 unsigned int opc
, op2
, op3
, rn
, op4
;
2141 unsigned btype_mod
= 2; /* 0: BR, 1: BLR, 2: other */
2145 opc
= extract32(insn
, 21, 4);
2146 op2
= extract32(insn
, 16, 5);
2147 op3
= extract32(insn
, 10, 6);
2148 rn
= extract32(insn
, 5, 5);
2149 op4
= extract32(insn
, 0, 5);
2152 goto do_unallocated
;
2164 goto do_unallocated
;
2166 dst
= cpu_reg(s
, rn
);
2171 if (!dc_isar_feature(aa64_pauth
, s
)) {
2172 goto do_unallocated
;
2176 if (rn
!= 0x1f || op4
!= 0x1f) {
2177 goto do_unallocated
;
2180 modifier
= cpu_X
[31];
2182 /* BRAAZ, BRABZ, BLRAAZ, BLRABZ */
2184 goto do_unallocated
;
2186 modifier
= new_tmp_a64_zero(s
);
2188 if (s
->pauth_active
) {
2189 dst
= new_tmp_a64(s
);
2191 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2193 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2196 dst
= cpu_reg(s
, rn
);
2201 goto do_unallocated
;
2203 gen_a64_set_pc(s
, dst
);
2204 /* BLR also needs to load return address */
2206 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->base
.pc_next
);
2212 if (!dc_isar_feature(aa64_pauth
, s
)) {
2213 goto do_unallocated
;
2215 if ((op3
& ~1) != 2) {
2216 goto do_unallocated
;
2218 btype_mod
= opc
& 1;
2219 if (s
->pauth_active
) {
2220 dst
= new_tmp_a64(s
);
2221 modifier
= cpu_reg_sp(s
, op4
);
2223 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2225 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2228 dst
= cpu_reg(s
, rn
);
2230 gen_a64_set_pc(s
, dst
);
2231 /* BLRAA also needs to load return address */
2233 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->base
.pc_next
);
2238 if (s
->current_el
== 0) {
2239 goto do_unallocated
;
2244 goto do_unallocated
;
2246 dst
= tcg_temp_new_i64();
2247 tcg_gen_ld_i64(dst
, cpu_env
,
2248 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2251 case 2: /* ERETAA */
2252 case 3: /* ERETAB */
2253 if (!dc_isar_feature(aa64_pauth
, s
)) {
2254 goto do_unallocated
;
2256 if (rn
!= 0x1f || op4
!= 0x1f) {
2257 goto do_unallocated
;
2259 dst
= tcg_temp_new_i64();
2260 tcg_gen_ld_i64(dst
, cpu_env
,
2261 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2262 if (s
->pauth_active
) {
2263 modifier
= cpu_X
[31];
2265 gen_helper_autia(dst
, cpu_env
, dst
, modifier
);
2267 gen_helper_autib(dst
, cpu_env
, dst
, modifier
);
2273 goto do_unallocated
;
2275 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
2279 gen_helper_exception_return(cpu_env
, dst
);
2280 tcg_temp_free_i64(dst
);
2281 /* Must exit loop to check un-masked IRQs */
2282 s
->base
.is_jmp
= DISAS_EXIT
;
2286 if (op3
!= 0 || op4
!= 0 || rn
!= 0x1f) {
2287 goto do_unallocated
;
2289 unsupported_encoding(s
, insn
);
2295 unallocated_encoding(s
);
2299 switch (btype_mod
) {
2301 if (dc_isar_feature(aa64_bti
, s
)) {
2302 /* BR to {x16,x17} or !guard -> 1, else 3. */
2303 set_btype(s
, rn
== 16 || rn
== 17 || !s
->guarded_page
? 1 : 3);
2308 if (dc_isar_feature(aa64_bti
, s
)) {
2309 /* BLR sets BTYPE to 2, regardless of source guarded page. */
2314 default: /* RET or none of the above. */
2315 /* BTYPE will be set to 0 by normal end-of-insn processing. */
2319 s
->base
.is_jmp
= DISAS_JUMP
;
2322 /* Branches, exception generating and system instructions */
2323 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
2325 switch (extract32(insn
, 25, 7)) {
2326 case 0x0a: case 0x0b:
2327 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
2328 disas_uncond_b_imm(s
, insn
);
2330 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
2331 disas_comp_b_imm(s
, insn
);
2333 case 0x1b: case 0x5b: /* Test & branch (immediate) */
2334 disas_test_b_imm(s
, insn
);
2336 case 0x2a: /* Conditional branch (immediate) */
2337 disas_cond_b_imm(s
, insn
);
2339 case 0x6a: /* Exception generation / System */
2340 if (insn
& (1 << 24)) {
2341 if (extract32(insn
, 22, 2) == 0) {
2342 disas_system(s
, insn
);
2344 unallocated_encoding(s
);
2350 case 0x6b: /* Unconditional branch (register) */
2351 disas_uncond_b_reg(s
, insn
);
2354 unallocated_encoding(s
);
2360 * Load/Store exclusive instructions are implemented by remembering
2361 * the value/address loaded, and seeing if these are the same
2362 * when the store is performed. This is not actually the architecturally
2363 * mandated semantics, but it works for typical guest code sequences
2364 * and avoids having to monitor regular stores.
2366 * The store exclusive uses the atomic cmpxchg primitives to avoid
2367 * races in multi-threaded linux-user and when MTTCG softmmu is
2370 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
2371 TCGv_i64 addr
, int size
, bool is_pair
)
2373 int idx
= get_mem_index(s
);
2374 MemOp memop
= s
->be_data
;
2376 g_assert(size
<= 3);
2378 g_assert(size
>= 2);
2380 /* The pair must be single-copy atomic for the doubleword. */
2381 memop
|= MO_64
| MO_ALIGN
;
2382 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2383 if (s
->be_data
== MO_LE
) {
2384 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 0, 32);
2385 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 32, 32);
2387 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 32, 32);
2388 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 0, 32);
2391 /* The pair must be single-copy atomic for *each* doubleword, not
2392 the entire quadword, however it must be quadword aligned. */
2394 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
,
2395 memop
| MO_ALIGN_16
);
2397 TCGv_i64 addr2
= tcg_temp_new_i64();
2398 tcg_gen_addi_i64(addr2
, addr
, 8);
2399 tcg_gen_qemu_ld_i64(cpu_exclusive_high
, addr2
, idx
, memop
);
2400 tcg_temp_free_i64(addr2
);
2402 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2403 tcg_gen_mov_i64(cpu_reg(s
, rt2
), cpu_exclusive_high
);
2406 memop
|= size
| MO_ALIGN
;
2407 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2408 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2410 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
2413 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
2414 TCGv_i64 addr
, int size
, int is_pair
)
2416 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
2417 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
2420 * [addr + datasize] = {Rt2};
2426 * env->exclusive_addr = -1;
2428 TCGLabel
*fail_label
= gen_new_label();
2429 TCGLabel
*done_label
= gen_new_label();
2432 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
2434 tmp
= tcg_temp_new_i64();
2437 if (s
->be_data
== MO_LE
) {
2438 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2440 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt2
), cpu_reg(s
, rt
));
2442 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
,
2443 cpu_exclusive_val
, tmp
,
2445 MO_64
| MO_ALIGN
| s
->be_data
);
2446 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2447 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2448 if (!HAVE_CMPXCHG128
) {
2449 gen_helper_exit_atomic(cpu_env
);
2450 s
->base
.is_jmp
= DISAS_NORETURN
;
2451 } else if (s
->be_data
== MO_LE
) {
2452 gen_helper_paired_cmpxchg64_le_parallel(tmp
, cpu_env
,
2457 gen_helper_paired_cmpxchg64_be_parallel(tmp
, cpu_env
,
2462 } else if (s
->be_data
== MO_LE
) {
2463 gen_helper_paired_cmpxchg64_le(tmp
, cpu_env
, cpu_exclusive_addr
,
2464 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2466 gen_helper_paired_cmpxchg64_be(tmp
, cpu_env
, cpu_exclusive_addr
,
2467 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2470 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
, cpu_exclusive_val
,
2471 cpu_reg(s
, rt
), get_mem_index(s
),
2472 size
| MO_ALIGN
| s
->be_data
);
2473 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2475 tcg_gen_mov_i64(cpu_reg(s
, rd
), tmp
);
2476 tcg_temp_free_i64(tmp
);
2477 tcg_gen_br(done_label
);
2479 gen_set_label(fail_label
);
2480 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
2481 gen_set_label(done_label
);
2482 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
2485 static void gen_compare_and_swap(DisasContext
*s
, int rs
, int rt
,
2488 TCGv_i64 tcg_rs
= cpu_reg(s
, rs
);
2489 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2490 int memidx
= get_mem_index(s
);
2491 TCGv_i64 clean_addr
;
2494 gen_check_sp_alignment(s
);
2496 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
), true, rn
!= 31, size
);
2497 tcg_gen_atomic_cmpxchg_i64(tcg_rs
, clean_addr
, tcg_rs
, tcg_rt
, memidx
,
2498 size
| MO_ALIGN
| s
->be_data
);
2501 static void gen_compare_and_swap_pair(DisasContext
*s
, int rs
, int rt
,
2504 TCGv_i64 s1
= cpu_reg(s
, rs
);
2505 TCGv_i64 s2
= cpu_reg(s
, rs
+ 1);
2506 TCGv_i64 t1
= cpu_reg(s
, rt
);
2507 TCGv_i64 t2
= cpu_reg(s
, rt
+ 1);
2508 TCGv_i64 clean_addr
;
2509 int memidx
= get_mem_index(s
);
2512 gen_check_sp_alignment(s
);
2515 /* This is a single atomic access, despite the "pair". */
2516 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
), true, rn
!= 31, size
+ 1);
2519 TCGv_i64 cmp
= tcg_temp_new_i64();
2520 TCGv_i64 val
= tcg_temp_new_i64();
2522 if (s
->be_data
== MO_LE
) {
2523 tcg_gen_concat32_i64(val
, t1
, t2
);
2524 tcg_gen_concat32_i64(cmp
, s1
, s2
);
2526 tcg_gen_concat32_i64(val
, t2
, t1
);
2527 tcg_gen_concat32_i64(cmp
, s2
, s1
);
2530 tcg_gen_atomic_cmpxchg_i64(cmp
, clean_addr
, cmp
, val
, memidx
,
2531 MO_64
| MO_ALIGN
| s
->be_data
);
2532 tcg_temp_free_i64(val
);
2534 if (s
->be_data
== MO_LE
) {
2535 tcg_gen_extr32_i64(s1
, s2
, cmp
);
2537 tcg_gen_extr32_i64(s2
, s1
, cmp
);
2539 tcg_temp_free_i64(cmp
);
2540 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2541 if (HAVE_CMPXCHG128
) {
2542 TCGv_i32 tcg_rs
= tcg_const_i32(rs
);
2543 if (s
->be_data
== MO_LE
) {
2544 gen_helper_casp_le_parallel(cpu_env
, tcg_rs
,
2545 clean_addr
, t1
, t2
);
2547 gen_helper_casp_be_parallel(cpu_env
, tcg_rs
,
2548 clean_addr
, t1
, t2
);
2550 tcg_temp_free_i32(tcg_rs
);
2552 gen_helper_exit_atomic(cpu_env
);
2553 s
->base
.is_jmp
= DISAS_NORETURN
;
2556 TCGv_i64 d1
= tcg_temp_new_i64();
2557 TCGv_i64 d2
= tcg_temp_new_i64();
2558 TCGv_i64 a2
= tcg_temp_new_i64();
2559 TCGv_i64 c1
= tcg_temp_new_i64();
2560 TCGv_i64 c2
= tcg_temp_new_i64();
2561 TCGv_i64 zero
= tcg_const_i64(0);
2563 /* Load the two words, in memory order. */
2564 tcg_gen_qemu_ld_i64(d1
, clean_addr
, memidx
,
2565 MO_64
| MO_ALIGN_16
| s
->be_data
);
2566 tcg_gen_addi_i64(a2
, clean_addr
, 8);
2567 tcg_gen_qemu_ld_i64(d2
, a2
, memidx
, MO_64
| s
->be_data
);
2569 /* Compare the two words, also in memory order. */
2570 tcg_gen_setcond_i64(TCG_COND_EQ
, c1
, d1
, s1
);
2571 tcg_gen_setcond_i64(TCG_COND_EQ
, c2
, d2
, s2
);
2572 tcg_gen_and_i64(c2
, c2
, c1
);
2574 /* If compare equal, write back new data, else write back old data. */
2575 tcg_gen_movcond_i64(TCG_COND_NE
, c1
, c2
, zero
, t1
, d1
);
2576 tcg_gen_movcond_i64(TCG_COND_NE
, c2
, c2
, zero
, t2
, d2
);
2577 tcg_gen_qemu_st_i64(c1
, clean_addr
, memidx
, MO_64
| s
->be_data
);
2578 tcg_gen_qemu_st_i64(c2
, a2
, memidx
, MO_64
| s
->be_data
);
2579 tcg_temp_free_i64(a2
);
2580 tcg_temp_free_i64(c1
);
2581 tcg_temp_free_i64(c2
);
2582 tcg_temp_free_i64(zero
);
2584 /* Write back the data from memory to Rs. */
2585 tcg_gen_mov_i64(s1
, d1
);
2586 tcg_gen_mov_i64(s2
, d2
);
2587 tcg_temp_free_i64(d1
);
2588 tcg_temp_free_i64(d2
);
2592 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2593 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2595 static bool disas_ldst_compute_iss_sf(int size
, bool is_signed
, int opc
)
2597 int opc0
= extract32(opc
, 0, 1);
2601 regsize
= opc0
? 32 : 64;
2603 regsize
= size
== 3 ? 64 : 32;
2605 return regsize
== 64;
2608 /* Load/store exclusive
2610 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2611 * +-----+-------------+----+---+----+------+----+-------+------+------+
2612 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2613 * +-----+-------------+----+---+----+------+----+-------+------+------+
2615 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2616 * L: 0 -> store, 1 -> load
2617 * o2: 0 -> exclusive, 1 -> not
2618 * o1: 0 -> single register, 1 -> register pair
2619 * o0: 1 -> load-acquire/store-release, 0 -> not
2621 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
2623 int rt
= extract32(insn
, 0, 5);
2624 int rn
= extract32(insn
, 5, 5);
2625 int rt2
= extract32(insn
, 10, 5);
2626 int rs
= extract32(insn
, 16, 5);
2627 int is_lasr
= extract32(insn
, 15, 1);
2628 int o2_L_o1_o0
= extract32(insn
, 21, 3) * 2 | is_lasr
;
2629 int size
= extract32(insn
, 30, 2);
2630 TCGv_i64 clean_addr
;
2632 switch (o2_L_o1_o0
) {
2633 case 0x0: /* STXR */
2634 case 0x1: /* STLXR */
2636 gen_check_sp_alignment(s
);
2639 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2641 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2642 true, rn
!= 31, size
);
2643 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, false);
2646 case 0x4: /* LDXR */
2647 case 0x5: /* LDAXR */
2649 gen_check_sp_alignment(s
);
2651 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2652 false, rn
!= 31, size
);
2654 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, false);
2656 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2660 case 0x8: /* STLLR */
2661 if (!dc_isar_feature(aa64_lor
, s
)) {
2664 /* StoreLORelease is the same as Store-Release for QEMU. */
2666 case 0x9: /* STLR */
2667 /* Generate ISS for non-exclusive accesses including LASR. */
2669 gen_check_sp_alignment(s
);
2671 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2672 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2673 true, rn
!= 31, size
);
2674 do_gpr_st(s
, cpu_reg(s
, rt
), clean_addr
, size
, true, rt
,
2675 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2678 case 0xc: /* LDLAR */
2679 if (!dc_isar_feature(aa64_lor
, s
)) {
2682 /* LoadLOAcquire is the same as Load-Acquire for QEMU. */
2684 case 0xd: /* LDAR */
2685 /* Generate ISS for non-exclusive accesses including LASR. */
2687 gen_check_sp_alignment(s
);
2689 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2690 false, rn
!= 31, size
);
2691 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, size
, false, false, true, rt
,
2692 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2693 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2696 case 0x2: case 0x3: /* CASP / STXP */
2697 if (size
& 2) { /* STXP / STLXP */
2699 gen_check_sp_alignment(s
);
2702 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2704 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2705 true, rn
!= 31, size
);
2706 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, true);
2710 && ((rt
| rs
) & 1) == 0
2711 && dc_isar_feature(aa64_atomics
, s
)) {
2713 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2718 case 0x6: case 0x7: /* CASPA / LDXP */
2719 if (size
& 2) { /* LDXP / LDAXP */
2721 gen_check_sp_alignment(s
);
2723 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2724 false, rn
!= 31, size
);
2726 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, true);
2728 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2733 && ((rt
| rs
) & 1) == 0
2734 && dc_isar_feature(aa64_atomics
, s
)) {
2735 /* CASPA / CASPAL */
2736 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2742 case 0xb: /* CASL */
2743 case 0xe: /* CASA */
2744 case 0xf: /* CASAL */
2745 if (rt2
== 31 && dc_isar_feature(aa64_atomics
, s
)) {
2746 gen_compare_and_swap(s
, rs
, rt
, rn
, size
);
2751 unallocated_encoding(s
);
2755 * Load register (literal)
2757 * 31 30 29 27 26 25 24 23 5 4 0
2758 * +-----+-------+---+-----+-------------------+-------+
2759 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2760 * +-----+-------+---+-----+-------------------+-------+
2762 * V: 1 -> vector (simd/fp)
2763 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2764 * 10-> 32 bit signed, 11 -> prefetch
2765 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2767 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
2769 int rt
= extract32(insn
, 0, 5);
2770 int64_t imm
= sextract32(insn
, 5, 19) << 2;
2771 bool is_vector
= extract32(insn
, 26, 1);
2772 int opc
= extract32(insn
, 30, 2);
2773 bool is_signed
= false;
2775 TCGv_i64 tcg_rt
, clean_addr
;
2779 unallocated_encoding(s
);
2783 if (!fp_access_check(s
)) {
2788 /* PRFM (literal) : prefetch */
2791 size
= 2 + extract32(opc
, 0, 1);
2792 is_signed
= extract32(opc
, 1, 1);
2795 tcg_rt
= cpu_reg(s
, rt
);
2797 clean_addr
= tcg_const_i64(s
->pc_curr
+ imm
);
2799 do_fp_ld(s
, rt
, clean_addr
, size
);
2801 /* Only unsigned 32bit loads target 32bit registers. */
2802 bool iss_sf
= opc
!= 0;
2804 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, is_signed
, false,
2805 true, rt
, iss_sf
, false);
2807 tcg_temp_free_i64(clean_addr
);
2811 * LDNP (Load Pair - non-temporal hint)
2812 * LDP (Load Pair - non vector)
2813 * LDPSW (Load Pair Signed Word - non vector)
2814 * STNP (Store Pair - non-temporal hint)
2815 * STP (Store Pair - non vector)
2816 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2817 * LDP (Load Pair of SIMD&FP)
2818 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2819 * STP (Store Pair of SIMD&FP)
2821 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2822 * +-----+-------+---+---+-------+---+-----------------------------+
2823 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2824 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2826 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2828 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2829 * V: 0 -> GPR, 1 -> Vector
2830 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2831 * 10 -> signed offset, 11 -> pre-index
2832 * L: 0 -> Store 1 -> Load
2834 * Rt, Rt2 = GPR or SIMD registers to be stored
2835 * Rn = general purpose register containing address
2836 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2838 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
2840 int rt
= extract32(insn
, 0, 5);
2841 int rn
= extract32(insn
, 5, 5);
2842 int rt2
= extract32(insn
, 10, 5);
2843 uint64_t offset
= sextract64(insn
, 15, 7);
2844 int index
= extract32(insn
, 23, 2);
2845 bool is_vector
= extract32(insn
, 26, 1);
2846 bool is_load
= extract32(insn
, 22, 1);
2847 int opc
= extract32(insn
, 30, 2);
2849 bool is_signed
= false;
2850 bool postindex
= false;
2852 bool set_tag
= false;
2854 TCGv_i64 clean_addr
, dirty_addr
;
2859 unallocated_encoding(s
);
2865 } else if (opc
== 1 && !is_load
) {
2867 if (!dc_isar_feature(aa64_mte_insn_reg
, s
) || index
== 0) {
2868 unallocated_encoding(s
);
2874 size
= 2 + extract32(opc
, 1, 1);
2875 is_signed
= extract32(opc
, 0, 1);
2876 if (!is_load
&& is_signed
) {
2877 unallocated_encoding(s
);
2883 case 1: /* post-index */
2888 /* signed offset with "non-temporal" hint. Since we don't emulate
2889 * caches we don't care about hints to the cache system about
2890 * data access patterns, and handle this identically to plain
2894 /* There is no non-temporal-hint version of LDPSW */
2895 unallocated_encoding(s
);
2900 case 2: /* signed offset, rn not updated */
2903 case 3: /* pre-index */
2909 if (is_vector
&& !fp_access_check(s
)) {
2913 offset
<<= (set_tag
? LOG2_TAG_GRANULE
: size
);
2916 gen_check_sp_alignment(s
);
2919 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
2921 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
2927 * TODO: We could rely on the stores below, at least for
2928 * system mode, if we arrange to add MO_ALIGN_16.
2930 gen_helper_stg_stub(cpu_env
, dirty_addr
);
2931 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2932 gen_helper_stg_parallel(cpu_env
, dirty_addr
, dirty_addr
);
2934 gen_helper_stg(cpu_env
, dirty_addr
, dirty_addr
);
2938 clean_addr
= gen_mte_checkN(s
, dirty_addr
, !is_load
,
2939 (wback
|| rn
!= 31) && !set_tag
,
2944 do_fp_ld(s
, rt
, clean_addr
, size
);
2946 do_fp_st(s
, rt
, clean_addr
, size
);
2948 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2950 do_fp_ld(s
, rt2
, clean_addr
, size
);
2952 do_fp_st(s
, rt2
, clean_addr
, size
);
2955 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2956 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2959 TCGv_i64 tmp
= tcg_temp_new_i64();
2961 /* Do not modify tcg_rt before recognizing any exception
2962 * from the second load.
2964 do_gpr_ld(s
, tmp
, clean_addr
, size
, is_signed
, false,
2965 false, 0, false, false);
2966 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2967 do_gpr_ld(s
, tcg_rt2
, clean_addr
, size
, is_signed
, false,
2968 false, 0, false, false);
2970 tcg_gen_mov_i64(tcg_rt
, tmp
);
2971 tcg_temp_free_i64(tmp
);
2973 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
2974 false, 0, false, false);
2975 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2976 do_gpr_st(s
, tcg_rt2
, clean_addr
, size
,
2977 false, 0, false, false);
2983 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
2985 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
2990 * Load/store (immediate post-indexed)
2991 * Load/store (immediate pre-indexed)
2992 * Load/store (unscaled immediate)
2994 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2995 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2996 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2997 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2999 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
3001 * V = 0 -> non-vector
3002 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
3003 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
3005 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
3011 int rn
= extract32(insn
, 5, 5);
3012 int imm9
= sextract32(insn
, 12, 9);
3013 int idx
= extract32(insn
, 10, 2);
3014 bool is_signed
= false;
3015 bool is_store
= false;
3016 bool is_extended
= false;
3017 bool is_unpriv
= (idx
== 2);
3018 bool iss_valid
= !is_vector
;
3023 TCGv_i64 clean_addr
, dirty_addr
;
3026 size
|= (opc
& 2) << 1;
3027 if (size
> 4 || is_unpriv
) {
3028 unallocated_encoding(s
);
3031 is_store
= ((opc
& 1) == 0);
3032 if (!fp_access_check(s
)) {
3036 if (size
== 3 && opc
== 2) {
3037 /* PRFM - prefetch */
3039 unallocated_encoding(s
);
3044 if (opc
== 3 && size
> 1) {
3045 unallocated_encoding(s
);
3048 is_store
= (opc
== 0);
3049 is_signed
= extract32(opc
, 1, 1);
3050 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3068 g_assert_not_reached();
3072 gen_check_sp_alignment(s
);
3075 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3077 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
3080 memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
3081 clean_addr
= gen_mte_check1_mmuidx(s
, dirty_addr
, is_store
,
3082 writeback
|| rn
!= 31,
3083 size
, is_unpriv
, memidx
);
3087 do_fp_st(s
, rt
, clean_addr
, size
);
3089 do_fp_ld(s
, rt
, clean_addr
, size
);
3092 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3093 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3096 do_gpr_st_memidx(s
, tcg_rt
, clean_addr
, size
, memidx
,
3097 iss_valid
, rt
, iss_sf
, false);
3099 do_gpr_ld_memidx(s
, tcg_rt
, clean_addr
, size
,
3100 is_signed
, is_extended
, memidx
,
3101 iss_valid
, rt
, iss_sf
, false);
3106 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
3108 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
3110 tcg_gen_mov_i64(tcg_rn
, dirty_addr
);
3115 * Load/store (register offset)
3117 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3118 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
3119 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
3120 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
3123 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
3124 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
3126 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
3127 * opc<0>: 0 -> store, 1 -> load
3128 * V: 1 -> vector/simd
3129 * opt: extend encoding (see DecodeRegExtend)
3130 * S: if S=1 then scale (essentially index by sizeof(size))
3131 * Rt: register to transfer into/out of
3132 * Rn: address register or SP for base
3133 * Rm: offset register or ZR for offset
3135 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
3141 int rn
= extract32(insn
, 5, 5);
3142 int shift
= extract32(insn
, 12, 1);
3143 int rm
= extract32(insn
, 16, 5);
3144 int opt
= extract32(insn
, 13, 3);
3145 bool is_signed
= false;
3146 bool is_store
= false;
3147 bool is_extended
= false;
3149 TCGv_i64 tcg_rm
, clean_addr
, dirty_addr
;
3151 if (extract32(opt
, 1, 1) == 0) {
3152 unallocated_encoding(s
);
3157 size
|= (opc
& 2) << 1;
3159 unallocated_encoding(s
);
3162 is_store
= !extract32(opc
, 0, 1);
3163 if (!fp_access_check(s
)) {
3167 if (size
== 3 && opc
== 2) {
3168 /* PRFM - prefetch */
3171 if (opc
== 3 && size
> 1) {
3172 unallocated_encoding(s
);
3175 is_store
= (opc
== 0);
3176 is_signed
= extract32(opc
, 1, 1);
3177 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3181 gen_check_sp_alignment(s
);
3183 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3185 tcg_rm
= read_cpu_reg(s
, rm
, 1);
3186 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
3188 tcg_gen_add_i64(dirty_addr
, dirty_addr
, tcg_rm
);
3189 clean_addr
= gen_mte_check1(s
, dirty_addr
, is_store
, true, size
);
3193 do_fp_st(s
, rt
, clean_addr
, size
);
3195 do_fp_ld(s
, rt
, clean_addr
, size
);
3198 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3199 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3201 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3202 true, rt
, iss_sf
, false);
3204 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
,
3205 is_signed
, is_extended
,
3206 true, rt
, iss_sf
, false);
3212 * Load/store (unsigned immediate)
3214 * 31 30 29 27 26 25 24 23 22 21 10 9 5
3215 * +----+-------+---+-----+-----+------------+-------+------+
3216 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
3217 * +----+-------+---+-----+-----+------------+-------+------+
3220 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
3221 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
3223 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
3224 * opc<0>: 0 -> store, 1 -> load
3225 * Rn: base address register (inc SP)
3226 * Rt: target register
3228 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
3234 int rn
= extract32(insn
, 5, 5);
3235 unsigned int imm12
= extract32(insn
, 10, 12);
3236 unsigned int offset
;
3238 TCGv_i64 clean_addr
, dirty_addr
;
3241 bool is_signed
= false;
3242 bool is_extended
= false;
3245 size
|= (opc
& 2) << 1;
3247 unallocated_encoding(s
);
3250 is_store
= !extract32(opc
, 0, 1);
3251 if (!fp_access_check(s
)) {
3255 if (size
== 3 && opc
== 2) {
3256 /* PRFM - prefetch */
3259 if (opc
== 3 && size
> 1) {
3260 unallocated_encoding(s
);
3263 is_store
= (opc
== 0);
3264 is_signed
= extract32(opc
, 1, 1);
3265 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3269 gen_check_sp_alignment(s
);
3271 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3272 offset
= imm12
<< size
;
3273 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3274 clean_addr
= gen_mte_check1(s
, dirty_addr
, is_store
, rn
!= 31, size
);
3278 do_fp_st(s
, rt
, clean_addr
, size
);
3280 do_fp_ld(s
, rt
, clean_addr
, size
);
3283 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3284 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3286 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3287 true, rt
, iss_sf
, false);
3289 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, is_signed
, is_extended
,
3290 true, rt
, iss_sf
, false);
3295 /* Atomic memory operations
3297 * 31 30 27 26 24 22 21 16 15 12 10 5 0
3298 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
3299 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
3300 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
3302 * Rt: the result register
3303 * Rn: base address or SP
3304 * Rs: the source register for the operation
3305 * V: vector flag (always 0 as of v8.3)
3309 static void disas_ldst_atomic(DisasContext
*s
, uint32_t insn
,
3310 int size
, int rt
, bool is_vector
)
3312 int rs
= extract32(insn
, 16, 5);
3313 int rn
= extract32(insn
, 5, 5);
3314 int o3_opc
= extract32(insn
, 12, 4);
3315 bool r
= extract32(insn
, 22, 1);
3316 bool a
= extract32(insn
, 23, 1);
3317 TCGv_i64 tcg_rs
, clean_addr
;
3318 AtomicThreeOpFn
*fn
;
3320 if (is_vector
|| !dc_isar_feature(aa64_atomics
, s
)) {
3321 unallocated_encoding(s
);
3325 case 000: /* LDADD */
3326 fn
= tcg_gen_atomic_fetch_add_i64
;
3328 case 001: /* LDCLR */
3329 fn
= tcg_gen_atomic_fetch_and_i64
;
3331 case 002: /* LDEOR */
3332 fn
= tcg_gen_atomic_fetch_xor_i64
;
3334 case 003: /* LDSET */
3335 fn
= tcg_gen_atomic_fetch_or_i64
;
3337 case 004: /* LDSMAX */
3338 fn
= tcg_gen_atomic_fetch_smax_i64
;
3340 case 005: /* LDSMIN */
3341 fn
= tcg_gen_atomic_fetch_smin_i64
;
3343 case 006: /* LDUMAX */
3344 fn
= tcg_gen_atomic_fetch_umax_i64
;
3346 case 007: /* LDUMIN */
3347 fn
= tcg_gen_atomic_fetch_umin_i64
;
3350 fn
= tcg_gen_atomic_xchg_i64
;
3352 case 014: /* LDAPR, LDAPRH, LDAPRB */
3353 if (!dc_isar_feature(aa64_rcpc_8_3
, s
) ||
3354 rs
!= 31 || a
!= 1 || r
!= 0) {
3355 unallocated_encoding(s
);
3360 unallocated_encoding(s
);
3365 gen_check_sp_alignment(s
);
3367 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
), false, rn
!= 31, size
);
3369 if (o3_opc
== 014) {
3371 * LDAPR* are a special case because they are a simple load, not a
3372 * fetch-and-do-something op.
3373 * The architectural consistency requirements here are weaker than
3374 * full load-acquire (we only need "load-acquire processor consistent"),
3375 * but we choose to implement them as full LDAQ.
3377 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, size
, false, false,
3378 true, rt
, disas_ldst_compute_iss_sf(size
, false, 0), true);
3379 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
3383 tcg_rs
= read_cpu_reg(s
, rs
, true);
3385 if (o3_opc
== 1) { /* LDCLR */
3386 tcg_gen_not_i64(tcg_rs
, tcg_rs
);
3389 /* The tcg atomic primitives are all full barriers. Therefore we
3390 * can ignore the Acquire and Release bits of this instruction.
3392 fn(cpu_reg(s
, rt
), clean_addr
, tcg_rs
, get_mem_index(s
),
3393 s
->be_data
| size
| MO_ALIGN
);
3397 * PAC memory operations
3399 * 31 30 27 26 24 22 21 12 11 10 5 0
3400 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3401 * | size | 1 1 1 | V | 0 0 | M S | 1 | imm9 | W | 1 | Rn | Rt |
3402 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3404 * Rt: the result register
3405 * Rn: base address or SP
3406 * V: vector flag (always 0 as of v8.3)
3407 * M: clear for key DA, set for key DB
3408 * W: pre-indexing flag
3411 static void disas_ldst_pac(DisasContext
*s
, uint32_t insn
,
3412 int size
, int rt
, bool is_vector
)
3414 int rn
= extract32(insn
, 5, 5);
3415 bool is_wback
= extract32(insn
, 11, 1);
3416 bool use_key_a
= !extract32(insn
, 23, 1);
3418 TCGv_i64 clean_addr
, dirty_addr
, tcg_rt
;
3420 if (size
!= 3 || is_vector
|| !dc_isar_feature(aa64_pauth
, s
)) {
3421 unallocated_encoding(s
);
3426 gen_check_sp_alignment(s
);
3428 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3430 if (s
->pauth_active
) {
3432 gen_helper_autda(dirty_addr
, cpu_env
, dirty_addr
, cpu_X
[31]);
3434 gen_helper_autdb(dirty_addr
, cpu_env
, dirty_addr
, cpu_X
[31]);
3438 /* Form the 10-bit signed, scaled offset. */
3439 offset
= (extract32(insn
, 22, 1) << 9) | extract32(insn
, 12, 9);
3440 offset
= sextract32(offset
<< size
, 0, 10 + size
);
3441 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3443 /* Note that "clean" and "dirty" here refer to TBI not PAC. */
3444 clean_addr
= gen_mte_check1(s
, dirty_addr
, false,
3445 is_wback
|| rn
!= 31, size
);
3447 tcg_rt
= cpu_reg(s
, rt
);
3448 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, /* is_signed */ false,
3449 /* extend */ false, /* iss_valid */ !is_wback
,
3450 /* iss_srt */ rt
, /* iss_sf */ true, /* iss_ar */ false);
3453 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
3458 * LDAPR/STLR (unscaled immediate)
3460 * 31 30 24 22 21 12 10 5 0
3461 * +------+-------------+-----+---+--------+-----+----+-----+
3462 * | size | 0 1 1 0 0 1 | opc | 0 | imm9 | 0 0 | Rn | Rt |
3463 * +------+-------------+-----+---+--------+-----+----+-----+
3465 * Rt: source or destination register
3467 * imm9: unscaled immediate offset
3468 * opc: 00: STLUR*, 01/10/11: various LDAPUR*
3469 * size: size of load/store
3471 static void disas_ldst_ldapr_stlr(DisasContext
*s
, uint32_t insn
)
3473 int rt
= extract32(insn
, 0, 5);
3474 int rn
= extract32(insn
, 5, 5);
3475 int offset
= sextract32(insn
, 12, 9);
3476 int opc
= extract32(insn
, 22, 2);
3477 int size
= extract32(insn
, 30, 2);
3478 TCGv_i64 clean_addr
, dirty_addr
;
3479 bool is_store
= false;
3480 bool is_signed
= false;
3481 bool extend
= false;
3484 if (!dc_isar_feature(aa64_rcpc_8_4
, s
)) {
3485 unallocated_encoding(s
);
3490 case 0: /* STLURB */
3493 case 1: /* LDAPUR* */
3495 case 2: /* LDAPURS* 64-bit variant */
3497 unallocated_encoding(s
);
3502 case 3: /* LDAPURS* 32-bit variant */
3504 unallocated_encoding(s
);
3508 extend
= true; /* zero-extend 32->64 after signed load */
3511 g_assert_not_reached();
3514 iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3517 gen_check_sp_alignment(s
);
3520 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3521 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3522 clean_addr
= clean_data_tbi(s
, dirty_addr
);
3525 /* Store-Release semantics */
3526 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
3527 do_gpr_st(s
, cpu_reg(s
, rt
), clean_addr
, size
, true, rt
, iss_sf
, true);
3530 * Load-AcquirePC semantics; we implement as the slightly more
3531 * restrictive Load-Acquire.
3533 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, size
, is_signed
, extend
,
3534 true, rt
, iss_sf
, true);
3535 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
3539 /* Load/store register (all forms) */
3540 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
3542 int rt
= extract32(insn
, 0, 5);
3543 int opc
= extract32(insn
, 22, 2);
3544 bool is_vector
= extract32(insn
, 26, 1);
3545 int size
= extract32(insn
, 30, 2);
3547 switch (extract32(insn
, 24, 2)) {
3549 if (extract32(insn
, 21, 1) == 0) {
3550 /* Load/store register (unscaled immediate)
3551 * Load/store immediate pre/post-indexed
3552 * Load/store register unprivileged
3554 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
3557 switch (extract32(insn
, 10, 2)) {
3559 disas_ldst_atomic(s
, insn
, size
, rt
, is_vector
);
3562 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
3565 disas_ldst_pac(s
, insn
, size
, rt
, is_vector
);
3570 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
3573 unallocated_encoding(s
);
3576 /* AdvSIMD load/store multiple structures
3578 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
3579 * +---+---+---------------+---+-------------+--------+------+------+------+
3580 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
3581 * +---+---+---------------+---+-------------+--------+------+------+------+
3583 * AdvSIMD load/store multiple structures (post-indexed)
3585 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
3586 * +---+---+---------------+---+---+---------+--------+------+------+------+
3587 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
3588 * +---+---+---------------+---+---+---------+--------+------+------+------+
3590 * Rt: first (or only) SIMD&FP register to be transferred
3591 * Rn: base address or SP
3592 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3594 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
3596 int rt
= extract32(insn
, 0, 5);
3597 int rn
= extract32(insn
, 5, 5);
3598 int rm
= extract32(insn
, 16, 5);
3599 int size
= extract32(insn
, 10, 2);
3600 int opcode
= extract32(insn
, 12, 4);
3601 bool is_store
= !extract32(insn
, 22, 1);
3602 bool is_postidx
= extract32(insn
, 23, 1);
3603 bool is_q
= extract32(insn
, 30, 1);
3604 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3605 MemOp endian
= s
->be_data
;
3607 int total
; /* total bytes */
3608 int elements
; /* elements per vector */
3609 int rpt
; /* num iterations */
3610 int selem
; /* structure elements */
3613 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
3614 unallocated_encoding(s
);
3618 if (!is_postidx
&& rm
!= 0) {
3619 unallocated_encoding(s
);
3623 /* From the shared decode logic */
3654 unallocated_encoding(s
);
3658 if (size
== 3 && !is_q
&& selem
!= 1) {
3660 unallocated_encoding(s
);
3664 if (!fp_access_check(s
)) {
3669 gen_check_sp_alignment(s
);
3672 /* For our purposes, bytes are always little-endian. */
3677 total
= rpt
* selem
* (is_q
? 16 : 8);
3678 tcg_rn
= cpu_reg_sp(s
, rn
);
3681 * Issue the MTE check vs the logical repeat count, before we
3682 * promote consecutive little-endian elements below.
3684 clean_addr
= gen_mte_checkN(s
, tcg_rn
, is_store
, is_postidx
|| rn
!= 31,
3688 * Consecutive little-endian elements from a single register
3689 * can be promoted to a larger little-endian operation.
3691 if (selem
== 1 && endian
== MO_LE
) {
3694 elements
= (is_q
? 16 : 8) >> size
;
3696 tcg_ebytes
= tcg_const_i64(1 << size
);
3697 for (r
= 0; r
< rpt
; r
++) {
3699 for (e
= 0; e
< elements
; e
++) {
3701 for (xs
= 0; xs
< selem
; xs
++) {
3702 int tt
= (rt
+ r
+ xs
) % 32;
3704 do_vec_st(s
, tt
, e
, clean_addr
, size
, endian
);
3706 do_vec_ld(s
, tt
, e
, clean_addr
, size
, endian
);
3708 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
3712 tcg_temp_free_i64(tcg_ebytes
);
3715 /* For non-quad operations, setting a slice of the low
3716 * 64 bits of the register clears the high 64 bits (in
3717 * the ARM ARM pseudocode this is implicit in the fact
3718 * that 'rval' is a 64 bit wide variable).
3719 * For quad operations, we might still need to zero the
3722 for (r
= 0; r
< rpt
* selem
; r
++) {
3723 int tt
= (rt
+ r
) % 32;
3724 clear_vec_high(s
, is_q
, tt
);
3730 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, total
);
3732 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3737 /* AdvSIMD load/store single structure
3739 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3740 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3741 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3742 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3744 * AdvSIMD load/store single structure (post-indexed)
3746 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3747 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3748 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3749 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3751 * Rt: first (or only) SIMD&FP register to be transferred
3752 * Rn: base address or SP
3753 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3754 * index = encoded in Q:S:size dependent on size
3756 * lane_size = encoded in R, opc
3757 * transfer width = encoded in opc, S, size
3759 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
3761 int rt
= extract32(insn
, 0, 5);
3762 int rn
= extract32(insn
, 5, 5);
3763 int rm
= extract32(insn
, 16, 5);
3764 int size
= extract32(insn
, 10, 2);
3765 int S
= extract32(insn
, 12, 1);
3766 int opc
= extract32(insn
, 13, 3);
3767 int R
= extract32(insn
, 21, 1);
3768 int is_load
= extract32(insn
, 22, 1);
3769 int is_postidx
= extract32(insn
, 23, 1);
3770 int is_q
= extract32(insn
, 30, 1);
3772 int scale
= extract32(opc
, 1, 2);
3773 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
3774 bool replicate
= false;
3775 int index
= is_q
<< 3 | S
<< 2 | size
;
3777 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3779 if (extract32(insn
, 31, 1)) {
3780 unallocated_encoding(s
);
3783 if (!is_postidx
&& rm
!= 0) {
3784 unallocated_encoding(s
);
3790 if (!is_load
|| S
) {
3791 unallocated_encoding(s
);
3800 if (extract32(size
, 0, 1)) {
3801 unallocated_encoding(s
);
3807 if (extract32(size
, 1, 1)) {
3808 unallocated_encoding(s
);
3811 if (!extract32(size
, 0, 1)) {
3815 unallocated_encoding(s
);
3823 g_assert_not_reached();
3826 if (!fp_access_check(s
)) {
3831 gen_check_sp_alignment(s
);
3834 total
= selem
<< scale
;
3835 tcg_rn
= cpu_reg_sp(s
, rn
);
3837 clean_addr
= gen_mte_checkN(s
, tcg_rn
, !is_load
, is_postidx
|| rn
!= 31,
3840 tcg_ebytes
= tcg_const_i64(1 << scale
);
3841 for (xs
= 0; xs
< selem
; xs
++) {
3843 /* Load and replicate to all elements */
3844 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3846 tcg_gen_qemu_ld_i64(tcg_tmp
, clean_addr
,
3847 get_mem_index(s
), s
->be_data
+ scale
);
3848 tcg_gen_gvec_dup_i64(scale
, vec_full_reg_offset(s
, rt
),
3849 (is_q
+ 1) * 8, vec_full_reg_size(s
),
3851 tcg_temp_free_i64(tcg_tmp
);
3853 /* Load/store one element per register */
3855 do_vec_ld(s
, rt
, index
, clean_addr
, scale
, s
->be_data
);
3857 do_vec_st(s
, rt
, index
, clean_addr
, scale
, s
->be_data
);
3860 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
3863 tcg_temp_free_i64(tcg_ebytes
);
3867 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, total
);
3869 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3875 * Load/Store memory tags
3877 * 31 30 29 24 22 21 12 10 5 0
3878 * +-----+-------------+-----+---+------+-----+------+------+
3879 * | 1 1 | 0 1 1 0 0 1 | op1 | 1 | imm9 | op2 | Rn | Rt |
3880 * +-----+-------------+-----+---+------+-----+------+------+
3882 static void disas_ldst_tag(DisasContext
*s
, uint32_t insn
)
3884 int rt
= extract32(insn
, 0, 5);
3885 int rn
= extract32(insn
, 5, 5);
3886 uint64_t offset
= sextract64(insn
, 12, 9) << LOG2_TAG_GRANULE
;
3887 int op2
= extract32(insn
, 10, 2);
3888 int op1
= extract32(insn
, 22, 2);
3889 bool is_load
= false, is_pair
= false, is_zero
= false, is_mult
= false;
3891 TCGv_i64 addr
, clean_addr
, tcg_rt
;
3893 /* We checked insn bits [29:24,21] in the caller. */
3894 if (extract32(insn
, 30, 2) != 3) {
3895 goto do_unallocated
;
3899 * @index is a tri-state variable which has 3 states:
3900 * < 0 : post-index, writeback
3901 * = 0 : signed offset
3902 * > 0 : pre-index, writeback
3911 if (s
->current_el
== 0 || offset
!= 0) {
3912 goto do_unallocated
;
3914 is_mult
= is_zero
= true;
3934 if (s
->current_el
== 0 || offset
!= 0) {
3935 goto do_unallocated
;
3943 is_pair
= is_zero
= true;
3947 if (s
->current_el
== 0 || offset
!= 0) {
3948 goto do_unallocated
;
3950 is_mult
= is_load
= true;
3956 unallocated_encoding(s
);
3961 ? !dc_isar_feature(aa64_mte
, s
)
3962 : !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
3963 goto do_unallocated
;
3967 gen_check_sp_alignment(s
);
3970 addr
= read_cpu_reg_sp(s
, rn
, true);
3972 /* pre-index or signed offset */
3973 tcg_gen_addi_i64(addr
, addr
, offset
);
3977 tcg_rt
= cpu_reg(s
, rt
);
3980 int size
= 4 << s
->dcz_blocksize
;
3983 gen_helper_stzgm_tags(cpu_env
, addr
, tcg_rt
);
3986 * The non-tags portion of STZGM is mostly like DC_ZVA,
3987 * except the alignment happens before the access.
3989 clean_addr
= clean_data_tbi(s
, addr
);
3990 tcg_gen_andi_i64(clean_addr
, clean_addr
, -size
);
3991 gen_helper_dc_zva(cpu_env
, clean_addr
);
3992 } else if (s
->ata
) {
3994 gen_helper_ldgm(tcg_rt
, cpu_env
, addr
);
3996 gen_helper_stgm(cpu_env
, addr
, tcg_rt
);
3999 MMUAccessType acc
= is_load
? MMU_DATA_LOAD
: MMU_DATA_STORE
;
4000 int size
= 4 << GMID_EL1_BS
;
4002 clean_addr
= clean_data_tbi(s
, addr
);
4003 tcg_gen_andi_i64(clean_addr
, clean_addr
, -size
);
4004 gen_probe_access(s
, clean_addr
, acc
, size
);
4007 /* The result tags are zeros. */
4008 tcg_gen_movi_i64(tcg_rt
, 0);
4015 tcg_gen_andi_i64(addr
, addr
, -TAG_GRANULE
);
4016 tcg_rt
= cpu_reg(s
, rt
);
4018 gen_helper_ldg(tcg_rt
, cpu_env
, addr
, tcg_rt
);
4020 clean_addr
= clean_data_tbi(s
, addr
);
4021 gen_probe_access(s
, clean_addr
, MMU_DATA_LOAD
, MO_8
);
4022 gen_address_with_allocation_tag0(tcg_rt
, addr
);
4025 tcg_rt
= cpu_reg_sp(s
, rt
);
4028 * For STG and ST2G, we need to check alignment and probe memory.
4029 * TODO: For STZG and STZ2G, we could rely on the stores below,
4030 * at least for system mode; user-only won't enforce alignment.
4033 gen_helper_st2g_stub(cpu_env
, addr
);
4035 gen_helper_stg_stub(cpu_env
, addr
);
4037 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
4039 gen_helper_st2g_parallel(cpu_env
, addr
, tcg_rt
);
4041 gen_helper_stg_parallel(cpu_env
, addr
, tcg_rt
);
4045 gen_helper_st2g(cpu_env
, addr
, tcg_rt
);
4047 gen_helper_stg(cpu_env
, addr
, tcg_rt
);
4053 TCGv_i64 clean_addr
= clean_data_tbi(s
, addr
);
4054 TCGv_i64 tcg_zero
= tcg_const_i64(0);
4055 int mem_index
= get_mem_index(s
);
4056 int i
, n
= (1 + is_pair
) << LOG2_TAG_GRANULE
;
4058 tcg_gen_qemu_st_i64(tcg_zero
, clean_addr
, mem_index
,
4059 MO_Q
| MO_ALIGN_16
);
4060 for (i
= 8; i
< n
; i
+= 8) {
4061 tcg_gen_addi_i64(clean_addr
, clean_addr
, 8);
4062 tcg_gen_qemu_st_i64(tcg_zero
, clean_addr
, mem_index
, MO_Q
);
4064 tcg_temp_free_i64(tcg_zero
);
4068 /* pre-index or post-index */
4071 tcg_gen_addi_i64(addr
, addr
, offset
);
4073 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), addr
);
4077 /* Loads and stores */
4078 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
4080 switch (extract32(insn
, 24, 6)) {
4081 case 0x08: /* Load/store exclusive */
4082 disas_ldst_excl(s
, insn
);
4084 case 0x18: case 0x1c: /* Load register (literal) */
4085 disas_ld_lit(s
, insn
);
4087 case 0x28: case 0x29:
4088 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
4089 disas_ldst_pair(s
, insn
);
4091 case 0x38: case 0x39:
4092 case 0x3c: case 0x3d: /* Load/store register (all forms) */
4093 disas_ldst_reg(s
, insn
);
4095 case 0x0c: /* AdvSIMD load/store multiple structures */
4096 disas_ldst_multiple_struct(s
, insn
);
4098 case 0x0d: /* AdvSIMD load/store single structure */
4099 disas_ldst_single_struct(s
, insn
);
4102 if (extract32(insn
, 21, 1) != 0) {
4103 disas_ldst_tag(s
, insn
);
4104 } else if (extract32(insn
, 10, 2) == 0) {
4105 disas_ldst_ldapr_stlr(s
, insn
);
4107 unallocated_encoding(s
);
4111 unallocated_encoding(s
);
4116 /* PC-rel. addressing
4117 * 31 30 29 28 24 23 5 4 0
4118 * +----+-------+-----------+-------------------+------+
4119 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
4120 * +----+-------+-----------+-------------------+------+
4122 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
4124 unsigned int page
, rd
;
4128 page
= extract32(insn
, 31, 1);
4129 /* SignExtend(immhi:immlo) -> offset */
4130 offset
= sextract64(insn
, 5, 19);
4131 offset
= offset
<< 2 | extract32(insn
, 29, 2);
4132 rd
= extract32(insn
, 0, 5);
4136 /* ADRP (page based) */
4141 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
4145 * Add/subtract (immediate)
4147 * 31 30 29 28 23 22 21 10 9 5 4 0
4148 * +--+--+--+-------------+--+-------------+-----+-----+
4149 * |sf|op| S| 1 0 0 0 1 0 |sh| imm12 | Rn | Rd |
4150 * +--+--+--+-------------+--+-------------+-----+-----+
4152 * sf: 0 -> 32bit, 1 -> 64bit
4153 * op: 0 -> add , 1 -> sub
4155 * sh: 1 -> LSL imm by 12
4157 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
4159 int rd
= extract32(insn
, 0, 5);
4160 int rn
= extract32(insn
, 5, 5);
4161 uint64_t imm
= extract32(insn
, 10, 12);
4162 bool shift
= extract32(insn
, 22, 1);
4163 bool setflags
= extract32(insn
, 29, 1);
4164 bool sub_op
= extract32(insn
, 30, 1);
4165 bool is_64bit
= extract32(insn
, 31, 1);
4167 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
4168 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
4169 TCGv_i64 tcg_result
;
4175 tcg_result
= tcg_temp_new_i64();
4178 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
4180 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
4183 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
4185 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
4187 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
4189 tcg_temp_free_i64(tcg_imm
);
4193 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4195 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4198 tcg_temp_free_i64(tcg_result
);
4202 * Add/subtract (immediate, with tags)
4204 * 31 30 29 28 23 22 21 16 14 10 9 5 4 0
4205 * +--+--+--+-------------+--+---------+--+-------+-----+-----+
4206 * |sf|op| S| 1 0 0 0 1 1 |o2| uimm6 |o3| uimm4 | Rn | Rd |
4207 * +--+--+--+-------------+--+---------+--+-------+-----+-----+
4209 * op: 0 -> add, 1 -> sub
4211 static void disas_add_sub_imm_with_tags(DisasContext
*s
, uint32_t insn
)
4213 int rd
= extract32(insn
, 0, 5);
4214 int rn
= extract32(insn
, 5, 5);
4215 int uimm4
= extract32(insn
, 10, 4);
4216 int uimm6
= extract32(insn
, 16, 6);
4217 bool sub_op
= extract32(insn
, 30, 1);
4218 TCGv_i64 tcg_rn
, tcg_rd
;
4221 /* Test all of sf=1, S=0, o2=0, o3=0. */
4222 if ((insn
& 0xa040c000u
) != 0x80000000u
||
4223 !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
4224 unallocated_encoding(s
);
4228 imm
= uimm6
<< LOG2_TAG_GRANULE
;
4233 tcg_rn
= cpu_reg_sp(s
, rn
);
4234 tcg_rd
= cpu_reg_sp(s
, rd
);
4237 TCGv_i32 offset
= tcg_const_i32(imm
);
4238 TCGv_i32 tag_offset
= tcg_const_i32(uimm4
);
4240 gen_helper_addsubg(tcg_rd
, cpu_env
, tcg_rn
, offset
, tag_offset
);
4241 tcg_temp_free_i32(tag_offset
);
4242 tcg_temp_free_i32(offset
);
4244 tcg_gen_addi_i64(tcg_rd
, tcg_rn
, imm
);
4245 gen_address_with_allocation_tag0(tcg_rd
, tcg_rd
);
4249 /* The input should be a value in the bottom e bits (with higher
4250 * bits zero); returns that value replicated into every element
4251 * of size e in a 64 bit integer.
4253 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
4263 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
4264 static inline uint64_t bitmask64(unsigned int length
)
4266 assert(length
> 0 && length
<= 64);
4267 return ~0ULL >> (64 - length
);
4270 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
4271 * only require the wmask. Returns false if the imms/immr/immn are a reserved
4272 * value (ie should cause a guest UNDEF exception), and true if they are
4273 * valid, in which case the decoded bit pattern is written to result.
4275 bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
4276 unsigned int imms
, unsigned int immr
)
4279 unsigned e
, levels
, s
, r
;
4282 assert(immn
< 2 && imms
< 64 && immr
< 64);
4284 /* The bit patterns we create here are 64 bit patterns which
4285 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
4286 * 64 bits each. Each element contains the same value: a run
4287 * of between 1 and e-1 non-zero bits, rotated within the
4288 * element by between 0 and e-1 bits.
4290 * The element size and run length are encoded into immn (1 bit)
4291 * and imms (6 bits) as follows:
4292 * 64 bit elements: immn = 1, imms = <length of run - 1>
4293 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
4294 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
4295 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
4296 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
4297 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
4298 * Notice that immn = 0, imms = 11111x is the only combination
4299 * not covered by one of the above options; this is reserved.
4300 * Further, <length of run - 1> all-ones is a reserved pattern.
4302 * In all cases the rotation is by immr % e (and immr is 6 bits).
4305 /* First determine the element size */
4306 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
4308 /* This is the immn == 0, imms == 0x11111x case */
4318 /* <length of run - 1> mustn't be all-ones. */
4322 /* Create the value of one element: s+1 set bits rotated
4323 * by r within the element (which is e bits wide)...
4325 mask
= bitmask64(s
+ 1);
4327 mask
= (mask
>> r
) | (mask
<< (e
- r
));
4328 mask
&= bitmask64(e
);
4330 /* ...then replicate the element over the whole 64 bit value */
4331 mask
= bitfield_replicate(mask
, e
);
4336 /* Logical (immediate)
4337 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
4338 * +----+-----+-------------+---+------+------+------+------+
4339 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
4340 * +----+-----+-------------+---+------+------+------+------+
4342 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
4344 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
4345 TCGv_i64 tcg_rd
, tcg_rn
;
4347 bool is_and
= false;
4349 sf
= extract32(insn
, 31, 1);
4350 opc
= extract32(insn
, 29, 2);
4351 is_n
= extract32(insn
, 22, 1);
4352 immr
= extract32(insn
, 16, 6);
4353 imms
= extract32(insn
, 10, 6);
4354 rn
= extract32(insn
, 5, 5);
4355 rd
= extract32(insn
, 0, 5);
4358 unallocated_encoding(s
);
4362 if (opc
== 0x3) { /* ANDS */
4363 tcg_rd
= cpu_reg(s
, rd
);
4365 tcg_rd
= cpu_reg_sp(s
, rd
);
4367 tcg_rn
= cpu_reg(s
, rn
);
4369 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
4370 /* some immediate field values are reserved */
4371 unallocated_encoding(s
);
4376 wmask
&= 0xffffffff;
4380 case 0x3: /* ANDS */
4382 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
4386 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
4389 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
4392 assert(FALSE
); /* must handle all above */
4396 if (!sf
&& !is_and
) {
4397 /* zero extend final result; we know we can skip this for AND
4398 * since the immediate had the high 32 bits clear.
4400 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4403 if (opc
== 3) { /* ANDS */
4404 gen_logic_CC(sf
, tcg_rd
);
4409 * Move wide (immediate)
4411 * 31 30 29 28 23 22 21 20 5 4 0
4412 * +--+-----+-------------+-----+----------------+------+
4413 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
4414 * +--+-----+-------------+-----+----------------+------+
4416 * sf: 0 -> 32 bit, 1 -> 64 bit
4417 * opc: 00 -> N, 10 -> Z, 11 -> K
4418 * hw: shift/16 (0,16, and sf only 32, 48)
4420 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
4422 int rd
= extract32(insn
, 0, 5);
4423 uint64_t imm
= extract32(insn
, 5, 16);
4424 int sf
= extract32(insn
, 31, 1);
4425 int opc
= extract32(insn
, 29, 2);
4426 int pos
= extract32(insn
, 21, 2) << 4;
4427 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4430 if (!sf
&& (pos
>= 32)) {
4431 unallocated_encoding(s
);
4445 tcg_gen_movi_i64(tcg_rd
, imm
);
4448 tcg_imm
= tcg_const_i64(imm
);
4449 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
4450 tcg_temp_free_i64(tcg_imm
);
4452 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4456 unallocated_encoding(s
);
4462 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
4463 * +----+-----+-------------+---+------+------+------+------+
4464 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
4465 * +----+-----+-------------+---+------+------+------+------+
4467 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
4469 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
4470 TCGv_i64 tcg_rd
, tcg_tmp
;
4472 sf
= extract32(insn
, 31, 1);
4473 opc
= extract32(insn
, 29, 2);
4474 n
= extract32(insn
, 22, 1);
4475 ri
= extract32(insn
, 16, 6);
4476 si
= extract32(insn
, 10, 6);
4477 rn
= extract32(insn
, 5, 5);
4478 rd
= extract32(insn
, 0, 5);
4479 bitsize
= sf
? 64 : 32;
4481 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
4482 unallocated_encoding(s
);
4486 tcg_rd
= cpu_reg(s
, rd
);
4488 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
4489 to be smaller than bitsize, we'll never reference data outside the
4490 low 32-bits anyway. */
4491 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
4493 /* Recognize simple(r) extractions. */
4495 /* Wd<s-r:0> = Wn<s:r> */
4496 len
= (si
- ri
) + 1;
4497 if (opc
== 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
4498 tcg_gen_sextract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
4500 } else if (opc
== 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
4501 tcg_gen_extract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
4504 /* opc == 1, BFXIL fall through to deposit */
4505 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
4508 /* Handle the ri > si case with a deposit
4509 * Wd<32+s-r,32-r> = Wn<s:0>
4512 pos
= (bitsize
- ri
) & (bitsize
- 1);
4515 if (opc
== 0 && len
< ri
) {
4516 /* SBFM: sign extend the destination field from len to fill
4517 the balance of the word. Let the deposit below insert all
4518 of those sign bits. */
4519 tcg_gen_sextract_i64(tcg_tmp
, tcg_tmp
, 0, len
);
4523 if (opc
== 1) { /* BFM, BFXIL */
4524 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
4526 /* SBFM or UBFM: We start with zero, and we haven't modified
4527 any bits outside bitsize, therefore the zero-extension
4528 below is unneeded. */
4529 tcg_gen_deposit_z_i64(tcg_rd
, tcg_tmp
, pos
, len
);
4534 if (!sf
) { /* zero extend final result */
4535 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4540 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
4541 * +----+------+-------------+---+----+------+--------+------+------+
4542 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
4543 * +----+------+-------------+---+----+------+--------+------+------+
4545 static void disas_extract(DisasContext
*s
, uint32_t insn
)
4547 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
4549 sf
= extract32(insn
, 31, 1);
4550 n
= extract32(insn
, 22, 1);
4551 rm
= extract32(insn
, 16, 5);
4552 imm
= extract32(insn
, 10, 6);
4553 rn
= extract32(insn
, 5, 5);
4554 rd
= extract32(insn
, 0, 5);
4555 op21
= extract32(insn
, 29, 2);
4556 op0
= extract32(insn
, 21, 1);
4557 bitsize
= sf
? 64 : 32;
4559 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
4560 unallocated_encoding(s
);
4562 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
4564 tcg_rd
= cpu_reg(s
, rd
);
4566 if (unlikely(imm
== 0)) {
4567 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
4568 * so an extract from bit 0 is a special case.
4571 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
4573 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
4576 tcg_rm
= cpu_reg(s
, rm
);
4577 tcg_rn
= cpu_reg(s
, rn
);
4580 /* Specialization to ROR happens in EXTRACT2. */
4581 tcg_gen_extract2_i64(tcg_rd
, tcg_rm
, tcg_rn
, imm
);
4583 TCGv_i32 t0
= tcg_temp_new_i32();
4585 tcg_gen_extrl_i64_i32(t0
, tcg_rm
);
4587 tcg_gen_rotri_i32(t0
, t0
, imm
);
4589 TCGv_i32 t1
= tcg_temp_new_i32();
4590 tcg_gen_extrl_i64_i32(t1
, tcg_rn
);
4591 tcg_gen_extract2_i32(t0
, t0
, t1
, imm
);
4592 tcg_temp_free_i32(t1
);
4594 tcg_gen_extu_i32_i64(tcg_rd
, t0
);
4595 tcg_temp_free_i32(t0
);
4601 /* Data processing - immediate */
4602 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
4604 switch (extract32(insn
, 23, 6)) {
4605 case 0x20: case 0x21: /* PC-rel. addressing */
4606 disas_pc_rel_adr(s
, insn
);
4608 case 0x22: /* Add/subtract (immediate) */
4609 disas_add_sub_imm(s
, insn
);
4611 case 0x23: /* Add/subtract (immediate, with tags) */
4612 disas_add_sub_imm_with_tags(s
, insn
);
4614 case 0x24: /* Logical (immediate) */
4615 disas_logic_imm(s
, insn
);
4617 case 0x25: /* Move wide (immediate) */
4618 disas_movw_imm(s
, insn
);
4620 case 0x26: /* Bitfield */
4621 disas_bitfield(s
, insn
);
4623 case 0x27: /* Extract */
4624 disas_extract(s
, insn
);
4627 unallocated_encoding(s
);
4632 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
4633 * Note that it is the caller's responsibility to ensure that the
4634 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
4635 * mandated semantics for out of range shifts.
4637 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4638 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
4640 switch (shift_type
) {
4641 case A64_SHIFT_TYPE_LSL
:
4642 tcg_gen_shl_i64(dst
, src
, shift_amount
);
4644 case A64_SHIFT_TYPE_LSR
:
4645 tcg_gen_shr_i64(dst
, src
, shift_amount
);
4647 case A64_SHIFT_TYPE_ASR
:
4649 tcg_gen_ext32s_i64(dst
, src
);
4651 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
4653 case A64_SHIFT_TYPE_ROR
:
4655 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
4658 t0
= tcg_temp_new_i32();
4659 t1
= tcg_temp_new_i32();
4660 tcg_gen_extrl_i64_i32(t0
, src
);
4661 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
4662 tcg_gen_rotr_i32(t0
, t0
, t1
);
4663 tcg_gen_extu_i32_i64(dst
, t0
);
4664 tcg_temp_free_i32(t0
);
4665 tcg_temp_free_i32(t1
);
4669 assert(FALSE
); /* all shift types should be handled */
4673 if (!sf
) { /* zero extend final result */
4674 tcg_gen_ext32u_i64(dst
, dst
);
4678 /* Shift a TCGv src by immediate, put result in dst.
4679 * The shift amount must be in range (this should always be true as the
4680 * relevant instructions will UNDEF on bad shift immediates).
4682 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4683 enum a64_shift_type shift_type
, unsigned int shift_i
)
4685 assert(shift_i
< (sf
? 64 : 32));
4688 tcg_gen_mov_i64(dst
, src
);
4690 TCGv_i64 shift_const
;
4692 shift_const
= tcg_const_i64(shift_i
);
4693 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
4694 tcg_temp_free_i64(shift_const
);
4698 /* Logical (shifted register)
4699 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4700 * +----+-----+-----------+-------+---+------+--------+------+------+
4701 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
4702 * +----+-----+-----------+-------+---+------+--------+------+------+
4704 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
4706 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
4707 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
4709 sf
= extract32(insn
, 31, 1);
4710 opc
= extract32(insn
, 29, 2);
4711 shift_type
= extract32(insn
, 22, 2);
4712 invert
= extract32(insn
, 21, 1);
4713 rm
= extract32(insn
, 16, 5);
4714 shift_amount
= extract32(insn
, 10, 6);
4715 rn
= extract32(insn
, 5, 5);
4716 rd
= extract32(insn
, 0, 5);
4718 if (!sf
&& (shift_amount
& (1 << 5))) {
4719 unallocated_encoding(s
);
4723 tcg_rd
= cpu_reg(s
, rd
);
4725 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
4726 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
4727 * register-register MOV and MVN, so it is worth special casing.
4729 tcg_rm
= cpu_reg(s
, rm
);
4731 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
4733 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4737 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
4739 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
4745 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4748 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
4751 tcg_rn
= cpu_reg(s
, rn
);
4753 switch (opc
| (invert
<< 2)) {
4756 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4759 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4762 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4766 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4769 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4772 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4780 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4784 gen_logic_CC(sf
, tcg_rd
);
4789 * Add/subtract (extended register)
4791 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
4792 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4793 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
4794 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4796 * sf: 0 -> 32bit, 1 -> 64bit
4797 * op: 0 -> add , 1 -> sub
4800 * option: extension type (see DecodeRegExtend)
4801 * imm3: optional shift to Rm
4803 * Rd = Rn + LSL(extend(Rm), amount)
4805 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
4807 int rd
= extract32(insn
, 0, 5);
4808 int rn
= extract32(insn
, 5, 5);
4809 int imm3
= extract32(insn
, 10, 3);
4810 int option
= extract32(insn
, 13, 3);
4811 int rm
= extract32(insn
, 16, 5);
4812 int opt
= extract32(insn
, 22, 2);
4813 bool setflags
= extract32(insn
, 29, 1);
4814 bool sub_op
= extract32(insn
, 30, 1);
4815 bool sf
= extract32(insn
, 31, 1);
4817 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
4819 TCGv_i64 tcg_result
;
4821 if (imm3
> 4 || opt
!= 0) {
4822 unallocated_encoding(s
);
4826 /* non-flag setting ops may use SP */
4828 tcg_rd
= cpu_reg_sp(s
, rd
);
4830 tcg_rd
= cpu_reg(s
, rd
);
4832 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
4834 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4835 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
4837 tcg_result
= tcg_temp_new_i64();
4841 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4843 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4847 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4849 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4854 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4856 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4859 tcg_temp_free_i64(tcg_result
);
4863 * Add/subtract (shifted register)
4865 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4866 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4867 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
4868 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4870 * sf: 0 -> 32bit, 1 -> 64bit
4871 * op: 0 -> add , 1 -> sub
4873 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
4874 * imm6: Shift amount to apply to Rm before the add/sub
4876 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
4878 int rd
= extract32(insn
, 0, 5);
4879 int rn
= extract32(insn
, 5, 5);
4880 int imm6
= extract32(insn
, 10, 6);
4881 int rm
= extract32(insn
, 16, 5);
4882 int shift_type
= extract32(insn
, 22, 2);
4883 bool setflags
= extract32(insn
, 29, 1);
4884 bool sub_op
= extract32(insn
, 30, 1);
4885 bool sf
= extract32(insn
, 31, 1);
4887 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4888 TCGv_i64 tcg_rn
, tcg_rm
;
4889 TCGv_i64 tcg_result
;
4891 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
4892 unallocated_encoding(s
);
4896 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4897 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4899 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
4901 tcg_result
= tcg_temp_new_i64();
4905 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4907 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4911 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4913 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4918 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4920 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4923 tcg_temp_free_i64(tcg_result
);
4926 /* Data-processing (3 source)
4928 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
4929 * +--+------+-----------+------+------+----+------+------+------+
4930 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
4931 * +--+------+-----------+------+------+----+------+------+------+
4933 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
4935 int rd
= extract32(insn
, 0, 5);
4936 int rn
= extract32(insn
, 5, 5);
4937 int ra
= extract32(insn
, 10, 5);
4938 int rm
= extract32(insn
, 16, 5);
4939 int op_id
= (extract32(insn
, 29, 3) << 4) |
4940 (extract32(insn
, 21, 3) << 1) |
4941 extract32(insn
, 15, 1);
4942 bool sf
= extract32(insn
, 31, 1);
4943 bool is_sub
= extract32(op_id
, 0, 1);
4944 bool is_high
= extract32(op_id
, 2, 1);
4945 bool is_signed
= false;
4950 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
4952 case 0x42: /* SMADDL */
4953 case 0x43: /* SMSUBL */
4954 case 0x44: /* SMULH */
4957 case 0x0: /* MADD (32bit) */
4958 case 0x1: /* MSUB (32bit) */
4959 case 0x40: /* MADD (64bit) */
4960 case 0x41: /* MSUB (64bit) */
4961 case 0x4a: /* UMADDL */
4962 case 0x4b: /* UMSUBL */
4963 case 0x4c: /* UMULH */
4966 unallocated_encoding(s
);
4971 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
4972 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4973 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4974 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
4977 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4979 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4982 tcg_temp_free_i64(low_bits
);
4986 tcg_op1
= tcg_temp_new_i64();
4987 tcg_op2
= tcg_temp_new_i64();
4988 tcg_tmp
= tcg_temp_new_i64();
4991 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
4992 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
4995 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
4996 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
4998 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
4999 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
5003 if (ra
== 31 && !is_sub
) {
5004 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
5005 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
5007 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
5009 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
5011 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
5016 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
5019 tcg_temp_free_i64(tcg_op1
);
5020 tcg_temp_free_i64(tcg_op2
);
5021 tcg_temp_free_i64(tcg_tmp
);
5024 /* Add/subtract (with carry)
5025 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
5026 * +--+--+--+------------------------+------+-------------+------+-----+
5027 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | 0 0 0 0 0 0 | Rn | Rd |
5028 * +--+--+--+------------------------+------+-------------+------+-----+
5031 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
5033 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
5034 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
5036 sf
= extract32(insn
, 31, 1);
5037 op
= extract32(insn
, 30, 1);
5038 setflags
= extract32(insn
, 29, 1);
5039 rm
= extract32(insn
, 16, 5);
5040 rn
= extract32(insn
, 5, 5);
5041 rd
= extract32(insn
, 0, 5);
5043 tcg_rd
= cpu_reg(s
, rd
);
5044 tcg_rn
= cpu_reg(s
, rn
);
5047 tcg_y
= new_tmp_a64(s
);
5048 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
5050 tcg_y
= cpu_reg(s
, rm
);
5054 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
5056 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
5061 * Rotate right into flags
5062 * 31 30 29 21 15 10 5 4 0
5063 * +--+--+--+-----------------+--------+-----------+------+--+------+
5064 * |sf|op| S| 1 1 0 1 0 0 0 0 | imm6 | 0 0 0 0 1 | Rn |o2| mask |
5065 * +--+--+--+-----------------+--------+-----------+------+--+------+
5067 static void disas_rotate_right_into_flags(DisasContext
*s
, uint32_t insn
)
5069 int mask
= extract32(insn
, 0, 4);
5070 int o2
= extract32(insn
, 4, 1);
5071 int rn
= extract32(insn
, 5, 5);
5072 int imm6
= extract32(insn
, 15, 6);
5073 int sf_op_s
= extract32(insn
, 29, 3);
5077 if (sf_op_s
!= 5 || o2
!= 0 || !dc_isar_feature(aa64_condm_4
, s
)) {
5078 unallocated_encoding(s
);
5082 tcg_rn
= read_cpu_reg(s
, rn
, 1);
5083 tcg_gen_rotri_i64(tcg_rn
, tcg_rn
, imm6
);
5085 nzcv
= tcg_temp_new_i32();
5086 tcg_gen_extrl_i64_i32(nzcv
, tcg_rn
);
5088 if (mask
& 8) { /* N */
5089 tcg_gen_shli_i32(cpu_NF
, nzcv
, 31 - 3);
5091 if (mask
& 4) { /* Z */
5092 tcg_gen_not_i32(cpu_ZF
, nzcv
);
5093 tcg_gen_andi_i32(cpu_ZF
, cpu_ZF
, 4);
5095 if (mask
& 2) { /* C */
5096 tcg_gen_extract_i32(cpu_CF
, nzcv
, 1, 1);
5098 if (mask
& 1) { /* V */
5099 tcg_gen_shli_i32(cpu_VF
, nzcv
, 31 - 0);
5102 tcg_temp_free_i32(nzcv
);
5106 * Evaluate into flags
5107 * 31 30 29 21 15 14 10 5 4 0
5108 * +--+--+--+-----------------+---------+----+---------+------+--+------+
5109 * |sf|op| S| 1 1 0 1 0 0 0 0 | opcode2 | sz | 0 0 1 0 | Rn |o3| mask |
5110 * +--+--+--+-----------------+---------+----+---------+------+--+------+
5112 static void disas_evaluate_into_flags(DisasContext
*s
, uint32_t insn
)
5114 int o3_mask
= extract32(insn
, 0, 5);
5115 int rn
= extract32(insn
, 5, 5);
5116 int o2
= extract32(insn
, 15, 6);
5117 int sz
= extract32(insn
, 14, 1);
5118 int sf_op_s
= extract32(insn
, 29, 3);
5122 if (sf_op_s
!= 1 || o2
!= 0 || o3_mask
!= 0xd ||
5123 !dc_isar_feature(aa64_condm_4
, s
)) {
5124 unallocated_encoding(s
);
5127 shift
= sz
? 16 : 24; /* SETF16 or SETF8 */
5129 tmp
= tcg_temp_new_i32();
5130 tcg_gen_extrl_i64_i32(tmp
, cpu_reg(s
, rn
));
5131 tcg_gen_shli_i32(cpu_NF
, tmp
, shift
);
5132 tcg_gen_shli_i32(cpu_VF
, tmp
, shift
- 1);
5133 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
5134 tcg_gen_xor_i32(cpu_VF
, cpu_VF
, cpu_NF
);
5135 tcg_temp_free_i32(tmp
);
5138 /* Conditional compare (immediate / register)
5139 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
5140 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
5141 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
5142 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
5145 static void disas_cc(DisasContext
*s
, uint32_t insn
)
5147 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
5148 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
5149 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
5152 if (!extract32(insn
, 29, 1)) {
5153 unallocated_encoding(s
);
5156 if (insn
& (1 << 10 | 1 << 4)) {
5157 unallocated_encoding(s
);
5160 sf
= extract32(insn
, 31, 1);
5161 op
= extract32(insn
, 30, 1);
5162 is_imm
= extract32(insn
, 11, 1);
5163 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
5164 cond
= extract32(insn
, 12, 4);
5165 rn
= extract32(insn
, 5, 5);
5166 nzcv
= extract32(insn
, 0, 4);
5168 /* Set T0 = !COND. */
5169 tcg_t0
= tcg_temp_new_i32();
5170 arm_test_cc(&c
, cond
);
5171 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
5174 /* Load the arguments for the new comparison. */
5176 tcg_y
= new_tmp_a64(s
);
5177 tcg_gen_movi_i64(tcg_y
, y
);
5179 tcg_y
= cpu_reg(s
, y
);
5181 tcg_rn
= cpu_reg(s
, rn
);
5183 /* Set the flags for the new comparison. */
5184 tcg_tmp
= tcg_temp_new_i64();
5186 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
5188 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
5190 tcg_temp_free_i64(tcg_tmp
);
5192 /* If COND was false, force the flags to #nzcv. Compute two masks
5193 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
5194 * For tcg hosts that support ANDC, we can make do with just T1.
5195 * In either case, allow the tcg optimizer to delete any unused mask.
5197 tcg_t1
= tcg_temp_new_i32();
5198 tcg_t2
= tcg_temp_new_i32();
5199 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
5200 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
5202 if (nzcv
& 8) { /* N */
5203 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
5205 if (TCG_TARGET_HAS_andc_i32
) {
5206 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
5208 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
5211 if (nzcv
& 4) { /* Z */
5212 if (TCG_TARGET_HAS_andc_i32
) {
5213 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
5215 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
5218 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
5220 if (nzcv
& 2) { /* C */
5221 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
5223 if (TCG_TARGET_HAS_andc_i32
) {
5224 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
5226 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
5229 if (nzcv
& 1) { /* V */
5230 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
5232 if (TCG_TARGET_HAS_andc_i32
) {
5233 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
5235 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
5238 tcg_temp_free_i32(tcg_t0
);
5239 tcg_temp_free_i32(tcg_t1
);
5240 tcg_temp_free_i32(tcg_t2
);
5243 /* Conditional select
5244 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
5245 * +----+----+---+-----------------+------+------+-----+------+------+
5246 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
5247 * +----+----+---+-----------------+------+------+-----+------+------+
5249 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
5251 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
5252 TCGv_i64 tcg_rd
, zero
;
5255 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
5256 /* S == 1 or op2<1> == 1 */
5257 unallocated_encoding(s
);
5260 sf
= extract32(insn
, 31, 1);
5261 else_inv
= extract32(insn
, 30, 1);
5262 rm
= extract32(insn
, 16, 5);
5263 cond
= extract32(insn
, 12, 4);
5264 else_inc
= extract32(insn
, 10, 1);
5265 rn
= extract32(insn
, 5, 5);
5266 rd
= extract32(insn
, 0, 5);
5268 tcg_rd
= cpu_reg(s
, rd
);
5270 a64_test_cc(&c
, cond
);
5271 zero
= tcg_const_i64(0);
5273 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
5275 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
5277 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
5280 TCGv_i64 t_true
= cpu_reg(s
, rn
);
5281 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
5282 if (else_inv
&& else_inc
) {
5283 tcg_gen_neg_i64(t_false
, t_false
);
5284 } else if (else_inv
) {
5285 tcg_gen_not_i64(t_false
, t_false
);
5286 } else if (else_inc
) {
5287 tcg_gen_addi_i64(t_false
, t_false
, 1);
5289 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
5292 tcg_temp_free_i64(zero
);
5296 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5300 static void handle_clz(DisasContext
*s
, unsigned int sf
,
5301 unsigned int rn
, unsigned int rd
)
5303 TCGv_i64 tcg_rd
, tcg_rn
;
5304 tcg_rd
= cpu_reg(s
, rd
);
5305 tcg_rn
= cpu_reg(s
, rn
);
5308 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
5310 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
5311 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
5312 tcg_gen_clzi_i32(tcg_tmp32
, tcg_tmp32
, 32);
5313 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
5314 tcg_temp_free_i32(tcg_tmp32
);
5318 static void handle_cls(DisasContext
*s
, unsigned int sf
,
5319 unsigned int rn
, unsigned int rd
)
5321 TCGv_i64 tcg_rd
, tcg_rn
;
5322 tcg_rd
= cpu_reg(s
, rd
);
5323 tcg_rn
= cpu_reg(s
, rn
);
5326 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
5328 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
5329 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
5330 tcg_gen_clrsb_i32(tcg_tmp32
, tcg_tmp32
);
5331 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
5332 tcg_temp_free_i32(tcg_tmp32
);
5336 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
5337 unsigned int rn
, unsigned int rd
)
5339 TCGv_i64 tcg_rd
, tcg_rn
;
5340 tcg_rd
= cpu_reg(s
, rd
);
5341 tcg_rn
= cpu_reg(s
, rn
);
5344 gen_helper_rbit64(tcg_rd
, tcg_rn
);
5346 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
5347 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
5348 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
5349 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
5350 tcg_temp_free_i32(tcg_tmp32
);
5354 /* REV with sf==1, opcode==3 ("REV64") */
5355 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
5356 unsigned int rn
, unsigned int rd
)
5359 unallocated_encoding(s
);
5362 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
5365 /* REV with sf==0, opcode==2
5366 * REV32 (sf==1, opcode==2)
5368 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
5369 unsigned int rn
, unsigned int rd
)
5371 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5374 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5375 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
5377 /* bswap32_i64 requires zero high word */
5378 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
5379 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
5380 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
5381 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
5382 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
5384 tcg_temp_free_i64(tcg_tmp
);
5386 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
5387 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
5391 /* REV16 (opcode==1) */
5392 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
5393 unsigned int rn
, unsigned int rd
)
5395 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5396 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5397 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
5398 TCGv_i64 mask
= tcg_const_i64(sf
? 0x00ff00ff00ff00ffull
: 0x00ff00ff);
5400 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 8);
5401 tcg_gen_and_i64(tcg_rd
, tcg_rn
, mask
);
5402 tcg_gen_and_i64(tcg_tmp
, tcg_tmp
, mask
);
5403 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 8);
5404 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
5406 tcg_temp_free_i64(mask
);
5407 tcg_temp_free_i64(tcg_tmp
);
5410 /* Data-processing (1 source)
5411 * 31 30 29 28 21 20 16 15 10 9 5 4 0
5412 * +----+---+---+-----------------+---------+--------+------+------+
5413 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
5414 * +----+---+---+-----------------+---------+--------+------+------+
5416 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
5418 unsigned int sf
, opcode
, opcode2
, rn
, rd
;
5421 if (extract32(insn
, 29, 1)) {
5422 unallocated_encoding(s
);
5426 sf
= extract32(insn
, 31, 1);
5427 opcode
= extract32(insn
, 10, 6);
5428 opcode2
= extract32(insn
, 16, 5);
5429 rn
= extract32(insn
, 5, 5);
5430 rd
= extract32(insn
, 0, 5);
5432 #define MAP(SF, O2, O1) ((SF) | (O1 << 1) | (O2 << 7))
5434 switch (MAP(sf
, opcode2
, opcode
)) {
5435 case MAP(0, 0x00, 0x00): /* RBIT */
5436 case MAP(1, 0x00, 0x00):
5437 handle_rbit(s
, sf
, rn
, rd
);
5439 case MAP(0, 0x00, 0x01): /* REV16 */
5440 case MAP(1, 0x00, 0x01):
5441 handle_rev16(s
, sf
, rn
, rd
);
5443 case MAP(0, 0x00, 0x02): /* REV/REV32 */
5444 case MAP(1, 0x00, 0x02):
5445 handle_rev32(s
, sf
, rn
, rd
);
5447 case MAP(1, 0x00, 0x03): /* REV64 */
5448 handle_rev64(s
, sf
, rn
, rd
);
5450 case MAP(0, 0x00, 0x04): /* CLZ */
5451 case MAP(1, 0x00, 0x04):
5452 handle_clz(s
, sf
, rn
, rd
);
5454 case MAP(0, 0x00, 0x05): /* CLS */
5455 case MAP(1, 0x00, 0x05):
5456 handle_cls(s
, sf
, rn
, rd
);
5458 case MAP(1, 0x01, 0x00): /* PACIA */
5459 if (s
->pauth_active
) {
5460 tcg_rd
= cpu_reg(s
, rd
);
5461 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5462 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5463 goto do_unallocated
;
5466 case MAP(1, 0x01, 0x01): /* PACIB */
5467 if (s
->pauth_active
) {
5468 tcg_rd
= cpu_reg(s
, rd
);
5469 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5470 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5471 goto do_unallocated
;
5474 case MAP(1, 0x01, 0x02): /* PACDA */
5475 if (s
->pauth_active
) {
5476 tcg_rd
= cpu_reg(s
, rd
);
5477 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5478 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5479 goto do_unallocated
;
5482 case MAP(1, 0x01, 0x03): /* PACDB */
5483 if (s
->pauth_active
) {
5484 tcg_rd
= cpu_reg(s
, rd
);
5485 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5486 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5487 goto do_unallocated
;
5490 case MAP(1, 0x01, 0x04): /* AUTIA */
5491 if (s
->pauth_active
) {
5492 tcg_rd
= cpu_reg(s
, rd
);
5493 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5494 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5495 goto do_unallocated
;
5498 case MAP(1, 0x01, 0x05): /* AUTIB */
5499 if (s
->pauth_active
) {
5500 tcg_rd
= cpu_reg(s
, rd
);
5501 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5502 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5503 goto do_unallocated
;
5506 case MAP(1, 0x01, 0x06): /* AUTDA */
5507 if (s
->pauth_active
) {
5508 tcg_rd
= cpu_reg(s
, rd
);
5509 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5510 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5511 goto do_unallocated
;
5514 case MAP(1, 0x01, 0x07): /* AUTDB */
5515 if (s
->pauth_active
) {
5516 tcg_rd
= cpu_reg(s
, rd
);
5517 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5518 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5519 goto do_unallocated
;
5522 case MAP(1, 0x01, 0x08): /* PACIZA */
5523 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5524 goto do_unallocated
;
5525 } else if (s
->pauth_active
) {
5526 tcg_rd
= cpu_reg(s
, rd
);
5527 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5530 case MAP(1, 0x01, 0x09): /* PACIZB */
5531 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5532 goto do_unallocated
;
5533 } else if (s
->pauth_active
) {
5534 tcg_rd
= cpu_reg(s
, rd
);
5535 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5538 case MAP(1, 0x01, 0x0a): /* PACDZA */
5539 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5540 goto do_unallocated
;
5541 } else if (s
->pauth_active
) {
5542 tcg_rd
= cpu_reg(s
, rd
);
5543 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5546 case MAP(1, 0x01, 0x0b): /* PACDZB */
5547 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5548 goto do_unallocated
;
5549 } else if (s
->pauth_active
) {
5550 tcg_rd
= cpu_reg(s
, rd
);
5551 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5554 case MAP(1, 0x01, 0x0c): /* AUTIZA */
5555 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5556 goto do_unallocated
;
5557 } else if (s
->pauth_active
) {
5558 tcg_rd
= cpu_reg(s
, rd
);
5559 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5562 case MAP(1, 0x01, 0x0d): /* AUTIZB */
5563 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5564 goto do_unallocated
;
5565 } else if (s
->pauth_active
) {
5566 tcg_rd
= cpu_reg(s
, rd
);
5567 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5570 case MAP(1, 0x01, 0x0e): /* AUTDZA */
5571 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5572 goto do_unallocated
;
5573 } else if (s
->pauth_active
) {
5574 tcg_rd
= cpu_reg(s
, rd
);
5575 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5578 case MAP(1, 0x01, 0x0f): /* AUTDZB */
5579 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5580 goto do_unallocated
;
5581 } else if (s
->pauth_active
) {
5582 tcg_rd
= cpu_reg(s
, rd
);
5583 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5586 case MAP(1, 0x01, 0x10): /* XPACI */
5587 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5588 goto do_unallocated
;
5589 } else if (s
->pauth_active
) {
5590 tcg_rd
= cpu_reg(s
, rd
);
5591 gen_helper_xpaci(tcg_rd
, cpu_env
, tcg_rd
);
5594 case MAP(1, 0x01, 0x11): /* XPACD */
5595 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5596 goto do_unallocated
;
5597 } else if (s
->pauth_active
) {
5598 tcg_rd
= cpu_reg(s
, rd
);
5599 gen_helper_xpacd(tcg_rd
, cpu_env
, tcg_rd
);
5604 unallocated_encoding(s
);
5611 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
5612 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5614 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
5615 tcg_rd
= cpu_reg(s
, rd
);
5617 if (!sf
&& is_signed
) {
5618 tcg_n
= new_tmp_a64(s
);
5619 tcg_m
= new_tmp_a64(s
);
5620 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
5621 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
5623 tcg_n
= read_cpu_reg(s
, rn
, sf
);
5624 tcg_m
= read_cpu_reg(s
, rm
, sf
);
5628 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
5630 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
5633 if (!sf
) { /* zero extend final result */
5634 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5638 /* LSLV, LSRV, ASRV, RORV */
5639 static void handle_shift_reg(DisasContext
*s
,
5640 enum a64_shift_type shift_type
, unsigned int sf
,
5641 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5643 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
5644 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5645 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
5647 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
5648 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
5649 tcg_temp_free_i64(tcg_shift
);
5652 /* CRC32[BHWX], CRC32C[BHWX] */
5653 static void handle_crc32(DisasContext
*s
,
5654 unsigned int sf
, unsigned int sz
, bool crc32c
,
5655 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5657 TCGv_i64 tcg_acc
, tcg_val
;
5660 if (!dc_isar_feature(aa64_crc32
, s
)
5661 || (sf
== 1 && sz
!= 3)
5662 || (sf
== 0 && sz
== 3)) {
5663 unallocated_encoding(s
);
5668 tcg_val
= cpu_reg(s
, rm
);
5682 g_assert_not_reached();
5684 tcg_val
= new_tmp_a64(s
);
5685 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
5688 tcg_acc
= cpu_reg(s
, rn
);
5689 tcg_bytes
= tcg_const_i32(1 << sz
);
5692 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5694 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5697 tcg_temp_free_i32(tcg_bytes
);
5700 /* Data-processing (2 source)
5701 * 31 30 29 28 21 20 16 15 10 9 5 4 0
5702 * +----+---+---+-----------------+------+--------+------+------+
5703 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
5704 * +----+---+---+-----------------+------+--------+------+------+
5706 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
5708 unsigned int sf
, rm
, opcode
, rn
, rd
, setflag
;
5709 sf
= extract32(insn
, 31, 1);
5710 setflag
= extract32(insn
, 29, 1);
5711 rm
= extract32(insn
, 16, 5);
5712 opcode
= extract32(insn
, 10, 6);
5713 rn
= extract32(insn
, 5, 5);
5714 rd
= extract32(insn
, 0, 5);
5716 if (setflag
&& opcode
!= 0) {
5717 unallocated_encoding(s
);
5722 case 0: /* SUBP(S) */
5723 if (sf
== 0 || !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
5724 goto do_unallocated
;
5726 TCGv_i64 tcg_n
, tcg_m
, tcg_d
;
5728 tcg_n
= read_cpu_reg_sp(s
, rn
, true);
5729 tcg_m
= read_cpu_reg_sp(s
, rm
, true);
5730 tcg_gen_sextract_i64(tcg_n
, tcg_n
, 0, 56);
5731 tcg_gen_sextract_i64(tcg_m
, tcg_m
, 0, 56);
5732 tcg_d
= cpu_reg(s
, rd
);
5735 gen_sub_CC(true, tcg_d
, tcg_n
, tcg_m
);
5737 tcg_gen_sub_i64(tcg_d
, tcg_n
, tcg_m
);
5742 handle_div(s
, false, sf
, rm
, rn
, rd
);
5745 handle_div(s
, true, sf
, rm
, rn
, rd
);
5748 if (sf
== 0 || !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
5749 goto do_unallocated
;
5752 gen_helper_irg(cpu_reg_sp(s
, rd
), cpu_env
,
5753 cpu_reg_sp(s
, rn
), cpu_reg(s
, rm
));
5755 gen_address_with_allocation_tag0(cpu_reg_sp(s
, rd
),
5760 if (sf
== 0 || !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
5761 goto do_unallocated
;
5763 TCGv_i64 t1
= tcg_const_i64(1);
5764 TCGv_i64 t2
= tcg_temp_new_i64();
5766 tcg_gen_extract_i64(t2
, cpu_reg_sp(s
, rn
), 56, 4);
5767 tcg_gen_shl_i64(t1
, t1
, t2
);
5768 tcg_gen_or_i64(cpu_reg(s
, rd
), cpu_reg(s
, rm
), t1
);
5770 tcg_temp_free_i64(t1
);
5771 tcg_temp_free_i64(t2
);
5775 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
5778 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
5781 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
5784 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
5786 case 12: /* PACGA */
5787 if (sf
== 0 || !dc_isar_feature(aa64_pauth
, s
)) {
5788 goto do_unallocated
;
5790 gen_helper_pacga(cpu_reg(s
, rd
), cpu_env
,
5791 cpu_reg(s
, rn
), cpu_reg_sp(s
, rm
));
5800 case 23: /* CRC32 */
5802 int sz
= extract32(opcode
, 0, 2);
5803 bool crc32c
= extract32(opcode
, 2, 1);
5804 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
5809 unallocated_encoding(s
);
5815 * Data processing - register
5816 * 31 30 29 28 25 21 20 16 10 0
5817 * +--+---+--+---+-------+-----+-------+-------+---------+
5818 * | |op0| |op1| 1 0 1 | op2 | | op3 | |
5819 * +--+---+--+---+-------+-----+-------+-------+---------+
5821 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
5823 int op0
= extract32(insn
, 30, 1);
5824 int op1
= extract32(insn
, 28, 1);
5825 int op2
= extract32(insn
, 21, 4);
5826 int op3
= extract32(insn
, 10, 6);
5831 /* Add/sub (extended register) */
5832 disas_add_sub_ext_reg(s
, insn
);
5834 /* Add/sub (shifted register) */
5835 disas_add_sub_reg(s
, insn
);
5838 /* Logical (shifted register) */
5839 disas_logic_reg(s
, insn
);
5847 case 0x00: /* Add/subtract (with carry) */
5848 disas_adc_sbc(s
, insn
);
5851 case 0x01: /* Rotate right into flags */
5853 disas_rotate_right_into_flags(s
, insn
);
5856 case 0x02: /* Evaluate into flags */
5860 disas_evaluate_into_flags(s
, insn
);
5864 goto do_unallocated
;
5868 case 0x2: /* Conditional compare */
5869 disas_cc(s
, insn
); /* both imm and reg forms */
5872 case 0x4: /* Conditional select */
5873 disas_cond_select(s
, insn
);
5876 case 0x6: /* Data-processing */
5877 if (op0
) { /* (1 source) */
5878 disas_data_proc_1src(s
, insn
);
5879 } else { /* (2 source) */
5880 disas_data_proc_2src(s
, insn
);
5883 case 0x8 ... 0xf: /* (3 source) */
5884 disas_data_proc_3src(s
, insn
);
5889 unallocated_encoding(s
);
5894 static void handle_fp_compare(DisasContext
*s
, int size
,
5895 unsigned int rn
, unsigned int rm
,
5896 bool cmp_with_zero
, bool signal_all_nans
)
5898 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
5899 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
5901 if (size
== MO_64
) {
5902 TCGv_i64 tcg_vn
, tcg_vm
;
5904 tcg_vn
= read_fp_dreg(s
, rn
);
5905 if (cmp_with_zero
) {
5906 tcg_vm
= tcg_const_i64(0);
5908 tcg_vm
= read_fp_dreg(s
, rm
);
5910 if (signal_all_nans
) {
5911 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5913 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5915 tcg_temp_free_i64(tcg_vn
);
5916 tcg_temp_free_i64(tcg_vm
);
5918 TCGv_i32 tcg_vn
= tcg_temp_new_i32();
5919 TCGv_i32 tcg_vm
= tcg_temp_new_i32();
5921 read_vec_element_i32(s
, tcg_vn
, rn
, 0, size
);
5922 if (cmp_with_zero
) {
5923 tcg_gen_movi_i32(tcg_vm
, 0);
5925 read_vec_element_i32(s
, tcg_vm
, rm
, 0, size
);
5930 if (signal_all_nans
) {
5931 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5933 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5937 if (signal_all_nans
) {
5938 gen_helper_vfp_cmpeh_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5940 gen_helper_vfp_cmph_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5944 g_assert_not_reached();
5947 tcg_temp_free_i32(tcg_vn
);
5948 tcg_temp_free_i32(tcg_vm
);
5951 tcg_temp_free_ptr(fpst
);
5953 gen_set_nzcv(tcg_flags
);
5955 tcg_temp_free_i64(tcg_flags
);
5958 /* Floating point compare
5959 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
5960 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5961 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
5962 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5964 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
5966 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
5969 mos
= extract32(insn
, 29, 3);
5970 type
= extract32(insn
, 22, 2);
5971 rm
= extract32(insn
, 16, 5);
5972 op
= extract32(insn
, 14, 2);
5973 rn
= extract32(insn
, 5, 5);
5974 opc
= extract32(insn
, 3, 2);
5975 op2r
= extract32(insn
, 0, 3);
5977 if (mos
|| op
|| op2r
) {
5978 unallocated_encoding(s
);
5991 if (dc_isar_feature(aa64_fp16
, s
)) {
5996 unallocated_encoding(s
);
6000 if (!fp_access_check(s
)) {
6004 handle_fp_compare(s
, size
, rn
, rm
, opc
& 1, opc
& 2);
6007 /* Floating point conditional compare
6008 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
6009 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
6010 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
6011 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
6013 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
6015 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
6017 TCGLabel
*label_continue
= NULL
;
6020 mos
= extract32(insn
, 29, 3);
6021 type
= extract32(insn
, 22, 2);
6022 rm
= extract32(insn
, 16, 5);
6023 cond
= extract32(insn
, 12, 4);
6024 rn
= extract32(insn
, 5, 5);
6025 op
= extract32(insn
, 4, 1);
6026 nzcv
= extract32(insn
, 0, 4);
6029 unallocated_encoding(s
);
6042 if (dc_isar_feature(aa64_fp16
, s
)) {
6047 unallocated_encoding(s
);
6051 if (!fp_access_check(s
)) {
6055 if (cond
< 0x0e) { /* not always */
6056 TCGLabel
*label_match
= gen_new_label();
6057 label_continue
= gen_new_label();
6058 arm_gen_test_cc(cond
, label_match
);
6060 tcg_flags
= tcg_const_i64(nzcv
<< 28);
6061 gen_set_nzcv(tcg_flags
);
6062 tcg_temp_free_i64(tcg_flags
);
6063 tcg_gen_br(label_continue
);
6064 gen_set_label(label_match
);
6067 handle_fp_compare(s
, size
, rn
, rm
, false, op
);
6070 gen_set_label(label_continue
);
6074 /* Floating point conditional select
6075 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6076 * +---+---+---+-----------+------+---+------+------+-----+------+------+
6077 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
6078 * +---+---+---+-----------+------+---+------+------+-----+------+------+
6080 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
6082 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
6083 TCGv_i64 t_true
, t_false
, t_zero
;
6087 mos
= extract32(insn
, 29, 3);
6088 type
= extract32(insn
, 22, 2);
6089 rm
= extract32(insn
, 16, 5);
6090 cond
= extract32(insn
, 12, 4);
6091 rn
= extract32(insn
, 5, 5);
6092 rd
= extract32(insn
, 0, 5);
6095 unallocated_encoding(s
);
6108 if (dc_isar_feature(aa64_fp16
, s
)) {
6113 unallocated_encoding(s
);
6117 if (!fp_access_check(s
)) {
6121 /* Zero extend sreg & hreg inputs to 64 bits now. */
6122 t_true
= tcg_temp_new_i64();
6123 t_false
= tcg_temp_new_i64();
6124 read_vec_element(s
, t_true
, rn
, 0, sz
);
6125 read_vec_element(s
, t_false
, rm
, 0, sz
);
6127 a64_test_cc(&c
, cond
);
6128 t_zero
= tcg_const_i64(0);
6129 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, t_zero
, t_true
, t_false
);
6130 tcg_temp_free_i64(t_zero
);
6131 tcg_temp_free_i64(t_false
);
6134 /* Note that sregs & hregs write back zeros to the high bits,
6135 and we've already done the zero-extension. */
6136 write_fp_dreg(s
, rd
, t_true
);
6137 tcg_temp_free_i64(t_true
);
6140 /* Floating-point data-processing (1 source) - half precision */
6141 static void handle_fp_1src_half(DisasContext
*s
, int opcode
, int rd
, int rn
)
6143 TCGv_ptr fpst
= NULL
;
6144 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
6145 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6148 case 0x0: /* FMOV */
6149 tcg_gen_mov_i32(tcg_res
, tcg_op
);
6151 case 0x1: /* FABS */
6152 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
6154 case 0x2: /* FNEG */
6155 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
6157 case 0x3: /* FSQRT */
6158 fpst
= get_fpstatus_ptr(true);
6159 gen_helper_sqrt_f16(tcg_res
, tcg_op
, fpst
);
6161 case 0x8: /* FRINTN */
6162 case 0x9: /* FRINTP */
6163 case 0xa: /* FRINTM */
6164 case 0xb: /* FRINTZ */
6165 case 0xc: /* FRINTA */
6167 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
6168 fpst
= get_fpstatus_ptr(true);
6170 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6171 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
6173 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6174 tcg_temp_free_i32(tcg_rmode
);
6177 case 0xe: /* FRINTX */
6178 fpst
= get_fpstatus_ptr(true);
6179 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, fpst
);
6181 case 0xf: /* FRINTI */
6182 fpst
= get_fpstatus_ptr(true);
6183 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
6189 write_fp_sreg(s
, rd
, tcg_res
);
6192 tcg_temp_free_ptr(fpst
);
6194 tcg_temp_free_i32(tcg_op
);
6195 tcg_temp_free_i32(tcg_res
);
6198 /* Floating-point data-processing (1 source) - single precision */
6199 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
6201 void (*gen_fpst
)(TCGv_i32
, TCGv_i32
, TCGv_ptr
);
6202 TCGv_i32 tcg_op
, tcg_res
;
6206 tcg_op
= read_fp_sreg(s
, rn
);
6207 tcg_res
= tcg_temp_new_i32();
6210 case 0x0: /* FMOV */
6211 tcg_gen_mov_i32(tcg_res
, tcg_op
);
6213 case 0x1: /* FABS */
6214 gen_helper_vfp_abss(tcg_res
, tcg_op
);
6216 case 0x2: /* FNEG */
6217 gen_helper_vfp_negs(tcg_res
, tcg_op
);
6219 case 0x3: /* FSQRT */
6220 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
6222 case 0x8: /* FRINTN */
6223 case 0x9: /* FRINTP */
6224 case 0xa: /* FRINTM */
6225 case 0xb: /* FRINTZ */
6226 case 0xc: /* FRINTA */
6227 rmode
= arm_rmode_to_sf(opcode
& 7);
6228 gen_fpst
= gen_helper_rints
;
6230 case 0xe: /* FRINTX */
6231 gen_fpst
= gen_helper_rints_exact
;
6233 case 0xf: /* FRINTI */
6234 gen_fpst
= gen_helper_rints
;
6236 case 0x10: /* FRINT32Z */
6237 rmode
= float_round_to_zero
;
6238 gen_fpst
= gen_helper_frint32_s
;
6240 case 0x11: /* FRINT32X */
6241 gen_fpst
= gen_helper_frint32_s
;
6243 case 0x12: /* FRINT64Z */
6244 rmode
= float_round_to_zero
;
6245 gen_fpst
= gen_helper_frint64_s
;
6247 case 0x13: /* FRINT64X */
6248 gen_fpst
= gen_helper_frint64_s
;
6251 g_assert_not_reached();
6254 fpst
= get_fpstatus_ptr(false);
6256 TCGv_i32 tcg_rmode
= tcg_const_i32(rmode
);
6257 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6258 gen_fpst(tcg_res
, tcg_op
, fpst
);
6259 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6260 tcg_temp_free_i32(tcg_rmode
);
6262 gen_fpst(tcg_res
, tcg_op
, fpst
);
6264 tcg_temp_free_ptr(fpst
);
6267 write_fp_sreg(s
, rd
, tcg_res
);
6268 tcg_temp_free_i32(tcg_op
);
6269 tcg_temp_free_i32(tcg_res
);
6272 /* Floating-point data-processing (1 source) - double precision */
6273 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
6275 void (*gen_fpst
)(TCGv_i64
, TCGv_i64
, TCGv_ptr
);
6276 TCGv_i64 tcg_op
, tcg_res
;
6281 case 0x0: /* FMOV */
6282 gen_gvec_fn2(s
, false, rd
, rn
, tcg_gen_gvec_mov
, 0);
6286 tcg_op
= read_fp_dreg(s
, rn
);
6287 tcg_res
= tcg_temp_new_i64();
6290 case 0x1: /* FABS */
6291 gen_helper_vfp_absd(tcg_res
, tcg_op
);
6293 case 0x2: /* FNEG */
6294 gen_helper_vfp_negd(tcg_res
, tcg_op
);
6296 case 0x3: /* FSQRT */
6297 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
6299 case 0x8: /* FRINTN */
6300 case 0x9: /* FRINTP */
6301 case 0xa: /* FRINTM */
6302 case 0xb: /* FRINTZ */
6303 case 0xc: /* FRINTA */
6304 rmode
= arm_rmode_to_sf(opcode
& 7);
6305 gen_fpst
= gen_helper_rintd
;
6307 case 0xe: /* FRINTX */
6308 gen_fpst
= gen_helper_rintd_exact
;
6310 case 0xf: /* FRINTI */
6311 gen_fpst
= gen_helper_rintd
;
6313 case 0x10: /* FRINT32Z */
6314 rmode
= float_round_to_zero
;
6315 gen_fpst
= gen_helper_frint32_d
;
6317 case 0x11: /* FRINT32X */
6318 gen_fpst
= gen_helper_frint32_d
;
6320 case 0x12: /* FRINT64Z */
6321 rmode
= float_round_to_zero
;
6322 gen_fpst
= gen_helper_frint64_d
;
6324 case 0x13: /* FRINT64X */
6325 gen_fpst
= gen_helper_frint64_d
;
6328 g_assert_not_reached();
6331 fpst
= get_fpstatus_ptr(false);
6333 TCGv_i32 tcg_rmode
= tcg_const_i32(rmode
);
6334 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6335 gen_fpst(tcg_res
, tcg_op
, fpst
);
6336 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6337 tcg_temp_free_i32(tcg_rmode
);
6339 gen_fpst(tcg_res
, tcg_op
, fpst
);
6341 tcg_temp_free_ptr(fpst
);
6344 write_fp_dreg(s
, rd
, tcg_res
);
6345 tcg_temp_free_i64(tcg_op
);
6346 tcg_temp_free_i64(tcg_res
);
6349 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
6350 int rd
, int rn
, int dtype
, int ntype
)
6355 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
6357 /* Single to double */
6358 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
6359 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
6360 write_fp_dreg(s
, rd
, tcg_rd
);
6361 tcg_temp_free_i64(tcg_rd
);
6363 /* Single to half */
6364 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
6365 TCGv_i32 ahp
= get_ahp_flag();
6366 TCGv_ptr fpst
= get_fpstatus_ptr(false);
6368 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
6369 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
6370 write_fp_sreg(s
, rd
, tcg_rd
);
6371 tcg_temp_free_i32(tcg_rd
);
6372 tcg_temp_free_i32(ahp
);
6373 tcg_temp_free_ptr(fpst
);
6375 tcg_temp_free_i32(tcg_rn
);
6380 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
6381 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
6383 /* Double to single */
6384 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
6386 TCGv_ptr fpst
= get_fpstatus_ptr(false);
6387 TCGv_i32 ahp
= get_ahp_flag();
6388 /* Double to half */
6389 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
6390 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
6391 tcg_temp_free_ptr(fpst
);
6392 tcg_temp_free_i32(ahp
);
6394 write_fp_sreg(s
, rd
, tcg_rd
);
6395 tcg_temp_free_i32(tcg_rd
);
6396 tcg_temp_free_i64(tcg_rn
);
6401 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
6402 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(false);
6403 TCGv_i32 tcg_ahp
= get_ahp_flag();
6404 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
6406 /* Half to single */
6407 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
6408 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
6409 write_fp_sreg(s
, rd
, tcg_rd
);
6410 tcg_temp_free_i32(tcg_rd
);
6412 /* Half to double */
6413 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
6414 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
6415 write_fp_dreg(s
, rd
, tcg_rd
);
6416 tcg_temp_free_i64(tcg_rd
);
6418 tcg_temp_free_i32(tcg_rn
);
6419 tcg_temp_free_ptr(tcg_fpst
);
6420 tcg_temp_free_i32(tcg_ahp
);
6428 /* Floating point data-processing (1 source)
6429 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
6430 * +---+---+---+-----------+------+---+--------+-----------+------+------+
6431 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
6432 * +---+---+---+-----------+------+---+--------+-----------+------+------+
6434 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
6436 int mos
= extract32(insn
, 29, 3);
6437 int type
= extract32(insn
, 22, 2);
6438 int opcode
= extract32(insn
, 15, 6);
6439 int rn
= extract32(insn
, 5, 5);
6440 int rd
= extract32(insn
, 0, 5);
6443 unallocated_encoding(s
);
6448 case 0x4: case 0x5: case 0x7:
6450 /* FCVT between half, single and double precision */
6451 int dtype
= extract32(opcode
, 0, 2);
6452 if (type
== 2 || dtype
== type
) {
6453 unallocated_encoding(s
);
6456 if (!fp_access_check(s
)) {
6460 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
6464 case 0x10 ... 0x13: /* FRINT{32,64}{X,Z} */
6465 if (type
> 1 || !dc_isar_feature(aa64_frint
, s
)) {
6466 unallocated_encoding(s
);
6473 /* 32-to-32 and 64-to-64 ops */
6476 if (!fp_access_check(s
)) {
6479 handle_fp_1src_single(s
, opcode
, rd
, rn
);
6482 if (!fp_access_check(s
)) {
6485 handle_fp_1src_double(s
, opcode
, rd
, rn
);
6488 if (!dc_isar_feature(aa64_fp16
, s
)) {
6489 unallocated_encoding(s
);
6493 if (!fp_access_check(s
)) {
6496 handle_fp_1src_half(s
, opcode
, rd
, rn
);
6499 unallocated_encoding(s
);
6504 unallocated_encoding(s
);
6509 /* Floating-point data-processing (2 source) - single precision */
6510 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
6511 int rd
, int rn
, int rm
)
6518 tcg_res
= tcg_temp_new_i32();
6519 fpst
= get_fpstatus_ptr(false);
6520 tcg_op1
= read_fp_sreg(s
, rn
);
6521 tcg_op2
= read_fp_sreg(s
, rm
);
6524 case 0x0: /* FMUL */
6525 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6527 case 0x1: /* FDIV */
6528 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6530 case 0x2: /* FADD */
6531 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6533 case 0x3: /* FSUB */
6534 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6536 case 0x4: /* FMAX */
6537 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6539 case 0x5: /* FMIN */
6540 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6542 case 0x6: /* FMAXNM */
6543 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6545 case 0x7: /* FMINNM */
6546 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6548 case 0x8: /* FNMUL */
6549 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6550 gen_helper_vfp_negs(tcg_res
, tcg_res
);
6554 write_fp_sreg(s
, rd
, tcg_res
);
6556 tcg_temp_free_ptr(fpst
);
6557 tcg_temp_free_i32(tcg_op1
);
6558 tcg_temp_free_i32(tcg_op2
);
6559 tcg_temp_free_i32(tcg_res
);
6562 /* Floating-point data-processing (2 source) - double precision */
6563 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
6564 int rd
, int rn
, int rm
)
6571 tcg_res
= tcg_temp_new_i64();
6572 fpst
= get_fpstatus_ptr(false);
6573 tcg_op1
= read_fp_dreg(s
, rn
);
6574 tcg_op2
= read_fp_dreg(s
, rm
);
6577 case 0x0: /* FMUL */
6578 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6580 case 0x1: /* FDIV */
6581 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6583 case 0x2: /* FADD */
6584 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6586 case 0x3: /* FSUB */
6587 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6589 case 0x4: /* FMAX */
6590 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6592 case 0x5: /* FMIN */
6593 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6595 case 0x6: /* FMAXNM */
6596 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6598 case 0x7: /* FMINNM */
6599 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6601 case 0x8: /* FNMUL */
6602 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6603 gen_helper_vfp_negd(tcg_res
, tcg_res
);
6607 write_fp_dreg(s
, rd
, tcg_res
);
6609 tcg_temp_free_ptr(fpst
);
6610 tcg_temp_free_i64(tcg_op1
);
6611 tcg_temp_free_i64(tcg_op2
);
6612 tcg_temp_free_i64(tcg_res
);
6615 /* Floating-point data-processing (2 source) - half precision */
6616 static void handle_fp_2src_half(DisasContext
*s
, int opcode
,
6617 int rd
, int rn
, int rm
)
6624 tcg_res
= tcg_temp_new_i32();
6625 fpst
= get_fpstatus_ptr(true);
6626 tcg_op1
= read_fp_hreg(s
, rn
);
6627 tcg_op2
= read_fp_hreg(s
, rm
);
6630 case 0x0: /* FMUL */
6631 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6633 case 0x1: /* FDIV */
6634 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6636 case 0x2: /* FADD */
6637 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6639 case 0x3: /* FSUB */
6640 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6642 case 0x4: /* FMAX */
6643 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6645 case 0x5: /* FMIN */
6646 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6648 case 0x6: /* FMAXNM */
6649 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6651 case 0x7: /* FMINNM */
6652 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6654 case 0x8: /* FNMUL */
6655 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6656 tcg_gen_xori_i32(tcg_res
, tcg_res
, 0x8000);
6659 g_assert_not_reached();
6662 write_fp_sreg(s
, rd
, tcg_res
);
6664 tcg_temp_free_ptr(fpst
);
6665 tcg_temp_free_i32(tcg_op1
);
6666 tcg_temp_free_i32(tcg_op2
);
6667 tcg_temp_free_i32(tcg_res
);
6670 /* Floating point data-processing (2 source)
6671 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6672 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6673 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
6674 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6676 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
6678 int mos
= extract32(insn
, 29, 3);
6679 int type
= extract32(insn
, 22, 2);
6680 int rd
= extract32(insn
, 0, 5);
6681 int rn
= extract32(insn
, 5, 5);
6682 int rm
= extract32(insn
, 16, 5);
6683 int opcode
= extract32(insn
, 12, 4);
6685 if (opcode
> 8 || mos
) {
6686 unallocated_encoding(s
);
6692 if (!fp_access_check(s
)) {
6695 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
6698 if (!fp_access_check(s
)) {
6701 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
6704 if (!dc_isar_feature(aa64_fp16
, s
)) {
6705 unallocated_encoding(s
);
6708 if (!fp_access_check(s
)) {
6711 handle_fp_2src_half(s
, opcode
, rd
, rn
, rm
);
6714 unallocated_encoding(s
);
6718 /* Floating-point data-processing (3 source) - single precision */
6719 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
6720 int rd
, int rn
, int rm
, int ra
)
6722 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
6723 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6724 TCGv_ptr fpst
= get_fpstatus_ptr(false);
6726 tcg_op1
= read_fp_sreg(s
, rn
);
6727 tcg_op2
= read_fp_sreg(s
, rm
);
6728 tcg_op3
= read_fp_sreg(s
, ra
);
6730 /* These are fused multiply-add, and must be done as one
6731 * floating point operation with no rounding between the
6732 * multiplication and addition steps.
6733 * NB that doing the negations here as separate steps is
6734 * correct : an input NaN should come out with its sign bit
6735 * flipped if it is a negated-input.
6738 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
6742 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
6745 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6747 write_fp_sreg(s
, rd
, tcg_res
);
6749 tcg_temp_free_ptr(fpst
);
6750 tcg_temp_free_i32(tcg_op1
);
6751 tcg_temp_free_i32(tcg_op2
);
6752 tcg_temp_free_i32(tcg_op3
);
6753 tcg_temp_free_i32(tcg_res
);
6756 /* Floating-point data-processing (3 source) - double precision */
6757 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
6758 int rd
, int rn
, int rm
, int ra
)
6760 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
6761 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6762 TCGv_ptr fpst
= get_fpstatus_ptr(false);
6764 tcg_op1
= read_fp_dreg(s
, rn
);
6765 tcg_op2
= read_fp_dreg(s
, rm
);
6766 tcg_op3
= read_fp_dreg(s
, ra
);
6768 /* These are fused multiply-add, and must be done as one
6769 * floating point operation with no rounding between the
6770 * multiplication and addition steps.
6771 * NB that doing the negations here as separate steps is
6772 * correct : an input NaN should come out with its sign bit
6773 * flipped if it is a negated-input.
6776 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
6780 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
6783 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6785 write_fp_dreg(s
, rd
, tcg_res
);
6787 tcg_temp_free_ptr(fpst
);
6788 tcg_temp_free_i64(tcg_op1
);
6789 tcg_temp_free_i64(tcg_op2
);
6790 tcg_temp_free_i64(tcg_op3
);
6791 tcg_temp_free_i64(tcg_res
);
6794 /* Floating-point data-processing (3 source) - half precision */
6795 static void handle_fp_3src_half(DisasContext
*s
, bool o0
, bool o1
,
6796 int rd
, int rn
, int rm
, int ra
)
6798 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
6799 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6800 TCGv_ptr fpst
= get_fpstatus_ptr(true);
6802 tcg_op1
= read_fp_hreg(s
, rn
);
6803 tcg_op2
= read_fp_hreg(s
, rm
);
6804 tcg_op3
= read_fp_hreg(s
, ra
);
6806 /* These are fused multiply-add, and must be done as one
6807 * floating point operation with no rounding between the
6808 * multiplication and addition steps.
6809 * NB that doing the negations here as separate steps is
6810 * correct : an input NaN should come out with its sign bit
6811 * flipped if it is a negated-input.
6814 tcg_gen_xori_i32(tcg_op3
, tcg_op3
, 0x8000);
6818 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
6821 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6823 write_fp_sreg(s
, rd
, tcg_res
);
6825 tcg_temp_free_ptr(fpst
);
6826 tcg_temp_free_i32(tcg_op1
);
6827 tcg_temp_free_i32(tcg_op2
);
6828 tcg_temp_free_i32(tcg_op3
);
6829 tcg_temp_free_i32(tcg_res
);
6832 /* Floating point data-processing (3 source)
6833 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
6834 * +---+---+---+-----------+------+----+------+----+------+------+------+
6835 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
6836 * +---+---+---+-----------+------+----+------+----+------+------+------+
6838 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
6840 int mos
= extract32(insn
, 29, 3);
6841 int type
= extract32(insn
, 22, 2);
6842 int rd
= extract32(insn
, 0, 5);
6843 int rn
= extract32(insn
, 5, 5);
6844 int ra
= extract32(insn
, 10, 5);
6845 int rm
= extract32(insn
, 16, 5);
6846 bool o0
= extract32(insn
, 15, 1);
6847 bool o1
= extract32(insn
, 21, 1);
6850 unallocated_encoding(s
);
6856 if (!fp_access_check(s
)) {
6859 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6862 if (!fp_access_check(s
)) {
6865 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6868 if (!dc_isar_feature(aa64_fp16
, s
)) {
6869 unallocated_encoding(s
);
6872 if (!fp_access_check(s
)) {
6875 handle_fp_3src_half(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6878 unallocated_encoding(s
);
6882 /* Floating point immediate
6883 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
6884 * +---+---+---+-----------+------+---+------------+-------+------+------+
6885 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
6886 * +---+---+---+-----------+------+---+------------+-------+------+------+
6888 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
6890 int rd
= extract32(insn
, 0, 5);
6891 int imm5
= extract32(insn
, 5, 5);
6892 int imm8
= extract32(insn
, 13, 8);
6893 int type
= extract32(insn
, 22, 2);
6894 int mos
= extract32(insn
, 29, 3);
6900 unallocated_encoding(s
);
6913 if (dc_isar_feature(aa64_fp16
, s
)) {
6918 unallocated_encoding(s
);
6922 if (!fp_access_check(s
)) {
6926 imm
= vfp_expand_imm(sz
, imm8
);
6928 tcg_res
= tcg_const_i64(imm
);
6929 write_fp_dreg(s
, rd
, tcg_res
);
6930 tcg_temp_free_i64(tcg_res
);
6933 /* Handle floating point <=> fixed point conversions. Note that we can
6934 * also deal with fp <=> integer conversions as a special case (scale == 64)
6935 * OPTME: consider handling that special case specially or at least skipping
6936 * the call to scalbn in the helpers for zero shifts.
6938 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
6939 bool itof
, int rmode
, int scale
, int sf
, int type
)
6941 bool is_signed
= !(opcode
& 1);
6942 TCGv_ptr tcg_fpstatus
;
6943 TCGv_i32 tcg_shift
, tcg_single
;
6944 TCGv_i64 tcg_double
;
6946 tcg_fpstatus
= get_fpstatus_ptr(type
== 3);
6948 tcg_shift
= tcg_const_i32(64 - scale
);
6951 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
6953 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
6956 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
6958 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
6961 tcg_int
= tcg_extend
;
6965 case 1: /* float64 */
6966 tcg_double
= tcg_temp_new_i64();
6968 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6969 tcg_shift
, tcg_fpstatus
);
6971 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6972 tcg_shift
, tcg_fpstatus
);
6974 write_fp_dreg(s
, rd
, tcg_double
);
6975 tcg_temp_free_i64(tcg_double
);
6978 case 0: /* float32 */
6979 tcg_single
= tcg_temp_new_i32();
6981 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6982 tcg_shift
, tcg_fpstatus
);
6984 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6985 tcg_shift
, tcg_fpstatus
);
6987 write_fp_sreg(s
, rd
, tcg_single
);
6988 tcg_temp_free_i32(tcg_single
);
6991 case 3: /* float16 */
6992 tcg_single
= tcg_temp_new_i32();
6994 gen_helper_vfp_sqtoh(tcg_single
, tcg_int
,
6995 tcg_shift
, tcg_fpstatus
);
6997 gen_helper_vfp_uqtoh(tcg_single
, tcg_int
,
6998 tcg_shift
, tcg_fpstatus
);
7000 write_fp_sreg(s
, rd
, tcg_single
);
7001 tcg_temp_free_i32(tcg_single
);
7005 g_assert_not_reached();
7008 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
7011 if (extract32(opcode
, 2, 1)) {
7012 /* There are too many rounding modes to all fit into rmode,
7013 * so FCVTA[US] is a special case.
7015 rmode
= FPROUNDING_TIEAWAY
;
7018 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
7020 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7023 case 1: /* float64 */
7024 tcg_double
= read_fp_dreg(s
, rn
);
7027 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
7028 tcg_shift
, tcg_fpstatus
);
7030 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
7031 tcg_shift
, tcg_fpstatus
);
7035 gen_helper_vfp_tould(tcg_int
, tcg_double
,
7036 tcg_shift
, tcg_fpstatus
);
7038 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
7039 tcg_shift
, tcg_fpstatus
);
7043 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
7045 tcg_temp_free_i64(tcg_double
);
7048 case 0: /* float32 */
7049 tcg_single
= read_fp_sreg(s
, rn
);
7052 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
7053 tcg_shift
, tcg_fpstatus
);
7055 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
7056 tcg_shift
, tcg_fpstatus
);
7059 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
7061 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
7062 tcg_shift
, tcg_fpstatus
);
7064 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
7065 tcg_shift
, tcg_fpstatus
);
7067 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
7068 tcg_temp_free_i32(tcg_dest
);
7070 tcg_temp_free_i32(tcg_single
);
7073 case 3: /* float16 */
7074 tcg_single
= read_fp_sreg(s
, rn
);
7077 gen_helper_vfp_tosqh(tcg_int
, tcg_single
,
7078 tcg_shift
, tcg_fpstatus
);
7080 gen_helper_vfp_touqh(tcg_int
, tcg_single
,
7081 tcg_shift
, tcg_fpstatus
);
7084 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
7086 gen_helper_vfp_toslh(tcg_dest
, tcg_single
,
7087 tcg_shift
, tcg_fpstatus
);
7089 gen_helper_vfp_toulh(tcg_dest
, tcg_single
,
7090 tcg_shift
, tcg_fpstatus
);
7092 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
7093 tcg_temp_free_i32(tcg_dest
);
7095 tcg_temp_free_i32(tcg_single
);
7099 g_assert_not_reached();
7102 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7103 tcg_temp_free_i32(tcg_rmode
);
7106 tcg_temp_free_ptr(tcg_fpstatus
);
7107 tcg_temp_free_i32(tcg_shift
);
7110 /* Floating point <-> fixed point conversions
7111 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
7112 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
7113 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
7114 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
7116 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
7118 int rd
= extract32(insn
, 0, 5);
7119 int rn
= extract32(insn
, 5, 5);
7120 int scale
= extract32(insn
, 10, 6);
7121 int opcode
= extract32(insn
, 16, 3);
7122 int rmode
= extract32(insn
, 19, 2);
7123 int type
= extract32(insn
, 22, 2);
7124 bool sbit
= extract32(insn
, 29, 1);
7125 bool sf
= extract32(insn
, 31, 1);
7128 if (sbit
|| (!sf
&& scale
< 32)) {
7129 unallocated_encoding(s
);
7134 case 0: /* float32 */
7135 case 1: /* float64 */
7137 case 3: /* float16 */
7138 if (dc_isar_feature(aa64_fp16
, s
)) {
7143 unallocated_encoding(s
);
7147 switch ((rmode
<< 3) | opcode
) {
7148 case 0x2: /* SCVTF */
7149 case 0x3: /* UCVTF */
7152 case 0x18: /* FCVTZS */
7153 case 0x19: /* FCVTZU */
7157 unallocated_encoding(s
);
7161 if (!fp_access_check(s
)) {
7165 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
7168 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
7170 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
7171 * without conversion.
7175 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
7181 tmp
= tcg_temp_new_i64();
7182 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
7183 write_fp_dreg(s
, rd
, tmp
);
7184 tcg_temp_free_i64(tmp
);
7188 write_fp_dreg(s
, rd
, tcg_rn
);
7191 /* 64 bit to top half. */
7192 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
7193 clear_vec_high(s
, true, rd
);
7197 tmp
= tcg_temp_new_i64();
7198 tcg_gen_ext16u_i64(tmp
, tcg_rn
);
7199 write_fp_dreg(s
, rd
, tmp
);
7200 tcg_temp_free_i64(tmp
);
7203 g_assert_not_reached();
7206 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
7211 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
7215 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
7218 /* 64 bits from top half */
7219 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
7223 tcg_gen_ld16u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_16
));
7226 g_assert_not_reached();
7231 static void handle_fjcvtzs(DisasContext
*s
, int rd
, int rn
)
7233 TCGv_i64 t
= read_fp_dreg(s
, rn
);
7234 TCGv_ptr fpstatus
= get_fpstatus_ptr(false);
7236 gen_helper_fjcvtzs(t
, t
, fpstatus
);
7238 tcg_temp_free_ptr(fpstatus
);
7240 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), t
);
7241 tcg_gen_extrh_i64_i32(cpu_ZF
, t
);
7242 tcg_gen_movi_i32(cpu_CF
, 0);
7243 tcg_gen_movi_i32(cpu_NF
, 0);
7244 tcg_gen_movi_i32(cpu_VF
, 0);
7246 tcg_temp_free_i64(t
);
7249 /* Floating point <-> integer conversions
7250 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
7251 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
7252 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
7253 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
7255 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
7257 int rd
= extract32(insn
, 0, 5);
7258 int rn
= extract32(insn
, 5, 5);
7259 int opcode
= extract32(insn
, 16, 3);
7260 int rmode
= extract32(insn
, 19, 2);
7261 int type
= extract32(insn
, 22, 2);
7262 bool sbit
= extract32(insn
, 29, 1);
7263 bool sf
= extract32(insn
, 31, 1);
7267 goto do_unallocated
;
7275 case 4: /* FCVTAS */
7276 case 5: /* FCVTAU */
7278 goto do_unallocated
;
7281 case 0: /* FCVT[NPMZ]S */
7282 case 1: /* FCVT[NPMZ]U */
7284 case 0: /* float32 */
7285 case 1: /* float64 */
7287 case 3: /* float16 */
7288 if (!dc_isar_feature(aa64_fp16
, s
)) {
7289 goto do_unallocated
;
7293 goto do_unallocated
;
7295 if (!fp_access_check(s
)) {
7298 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
7302 switch (sf
<< 7 | type
<< 5 | rmode
<< 3 | opcode
) {
7303 case 0b01100110: /* FMOV half <-> 32-bit int */
7305 case 0b11100110: /* FMOV half <-> 64-bit int */
7307 if (!dc_isar_feature(aa64_fp16
, s
)) {
7308 goto do_unallocated
;
7311 case 0b00000110: /* FMOV 32-bit */
7313 case 0b10100110: /* FMOV 64-bit */
7315 case 0b11001110: /* FMOV top half of 128-bit */
7317 if (!fp_access_check(s
)) {
7321 handle_fmov(s
, rd
, rn
, type
, itof
);
7324 case 0b00111110: /* FJCVTZS */
7325 if (!dc_isar_feature(aa64_jscvt
, s
)) {
7326 goto do_unallocated
;
7327 } else if (fp_access_check(s
)) {
7328 handle_fjcvtzs(s
, rd
, rn
);
7334 unallocated_encoding(s
);
7341 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
7342 * 31 30 29 28 25 24 0
7343 * +---+---+---+---------+-----------------------------+
7344 * | | 0 | | 1 1 1 1 | |
7345 * +---+---+---+---------+-----------------------------+
7347 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
7349 if (extract32(insn
, 24, 1)) {
7350 /* Floating point data-processing (3 source) */
7351 disas_fp_3src(s
, insn
);
7352 } else if (extract32(insn
, 21, 1) == 0) {
7353 /* Floating point to fixed point conversions */
7354 disas_fp_fixed_conv(s
, insn
);
7356 switch (extract32(insn
, 10, 2)) {
7358 /* Floating point conditional compare */
7359 disas_fp_ccomp(s
, insn
);
7362 /* Floating point data-processing (2 source) */
7363 disas_fp_2src(s
, insn
);
7366 /* Floating point conditional select */
7367 disas_fp_csel(s
, insn
);
7370 switch (ctz32(extract32(insn
, 12, 4))) {
7371 case 0: /* [15:12] == xxx1 */
7372 /* Floating point immediate */
7373 disas_fp_imm(s
, insn
);
7375 case 1: /* [15:12] == xx10 */
7376 /* Floating point compare */
7377 disas_fp_compare(s
, insn
);
7379 case 2: /* [15:12] == x100 */
7380 /* Floating point data-processing (1 source) */
7381 disas_fp_1src(s
, insn
);
7383 case 3: /* [15:12] == 1000 */
7384 unallocated_encoding(s
);
7386 default: /* [15:12] == 0000 */
7387 /* Floating point <-> integer conversions */
7388 disas_fp_int_conv(s
, insn
);
7396 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
7399 /* Extract 64 bits from the middle of two concatenated 64 bit
7400 * vector register slices left:right. The extracted bits start
7401 * at 'pos' bits into the right (least significant) side.
7402 * We return the result in tcg_right, and guarantee not to
7405 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
7406 assert(pos
> 0 && pos
< 64);
7408 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
7409 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
7410 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
7412 tcg_temp_free_i64(tcg_tmp
);
7416 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
7417 * +---+---+-------------+-----+---+------+---+------+---+------+------+
7418 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
7419 * +---+---+-------------+-----+---+------+---+------+---+------+------+
7421 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
7423 int is_q
= extract32(insn
, 30, 1);
7424 int op2
= extract32(insn
, 22, 2);
7425 int imm4
= extract32(insn
, 11, 4);
7426 int rm
= extract32(insn
, 16, 5);
7427 int rn
= extract32(insn
, 5, 5);
7428 int rd
= extract32(insn
, 0, 5);
7429 int pos
= imm4
<< 3;
7430 TCGv_i64 tcg_resl
, tcg_resh
;
7432 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
7433 unallocated_encoding(s
);
7437 if (!fp_access_check(s
)) {
7441 tcg_resh
= tcg_temp_new_i64();
7442 tcg_resl
= tcg_temp_new_i64();
7444 /* Vd gets bits starting at pos bits into Vm:Vn. This is
7445 * either extracting 128 bits from a 128:128 concatenation, or
7446 * extracting 64 bits from a 64:64 concatenation.
7449 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
7451 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
7452 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
7460 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
7461 EltPosns
*elt
= eltposns
;
7468 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
7470 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
7473 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
7474 tcg_hh
= tcg_temp_new_i64();
7475 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
7476 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
7477 tcg_temp_free_i64(tcg_hh
);
7481 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
7482 tcg_temp_free_i64(tcg_resl
);
7484 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
7486 tcg_temp_free_i64(tcg_resh
);
7487 clear_vec_high(s
, is_q
, rd
);
7491 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
7492 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
7493 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
7494 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
7496 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
7498 int op2
= extract32(insn
, 22, 2);
7499 int is_q
= extract32(insn
, 30, 1);
7500 int rm
= extract32(insn
, 16, 5);
7501 int rn
= extract32(insn
, 5, 5);
7502 int rd
= extract32(insn
, 0, 5);
7503 int is_tblx
= extract32(insn
, 12, 1);
7504 int len
= extract32(insn
, 13, 2);
7505 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
7506 TCGv_i32 tcg_regno
, tcg_numregs
;
7509 unallocated_encoding(s
);
7513 if (!fp_access_check(s
)) {
7517 /* This does a table lookup: for every byte element in the input
7518 * we index into a table formed from up to four vector registers,
7519 * and then the output is the result of the lookups. Our helper
7520 * function does the lookup operation for a single 64 bit part of
7523 tcg_resl
= tcg_temp_new_i64();
7527 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
7529 tcg_gen_movi_i64(tcg_resl
, 0);
7533 tcg_resh
= tcg_temp_new_i64();
7535 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
7537 tcg_gen_movi_i64(tcg_resh
, 0);
7541 tcg_idx
= tcg_temp_new_i64();
7542 tcg_regno
= tcg_const_i32(rn
);
7543 tcg_numregs
= tcg_const_i32(len
+ 1);
7544 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
7545 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
7546 tcg_regno
, tcg_numregs
);
7548 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
7549 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
7550 tcg_regno
, tcg_numregs
);
7552 tcg_temp_free_i64(tcg_idx
);
7553 tcg_temp_free_i32(tcg_regno
);
7554 tcg_temp_free_i32(tcg_numregs
);
7556 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
7557 tcg_temp_free_i64(tcg_resl
);
7560 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
7561 tcg_temp_free_i64(tcg_resh
);
7563 clear_vec_high(s
, is_q
, rd
);
7567 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
7568 * +---+---+-------------+------+---+------+---+------------------+------+
7569 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
7570 * +---+---+-------------+------+---+------+---+------------------+------+
7572 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
7574 int rd
= extract32(insn
, 0, 5);
7575 int rn
= extract32(insn
, 5, 5);
7576 int rm
= extract32(insn
, 16, 5);
7577 int size
= extract32(insn
, 22, 2);
7578 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
7579 * bit 2 indicates 1 vs 2 variant of the insn.
7581 int opcode
= extract32(insn
, 12, 2);
7582 bool part
= extract32(insn
, 14, 1);
7583 bool is_q
= extract32(insn
, 30, 1);
7584 int esize
= 8 << size
;
7586 int datasize
= is_q
? 128 : 64;
7587 int elements
= datasize
/ esize
;
7588 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
7590 if (opcode
== 0 || (size
== 3 && !is_q
)) {
7591 unallocated_encoding(s
);
7595 if (!fp_access_check(s
)) {
7599 tcg_resl
= tcg_const_i64(0);
7600 tcg_resh
= is_q
? tcg_const_i64(0) : NULL
;
7601 tcg_res
= tcg_temp_new_i64();
7603 for (i
= 0; i
< elements
; i
++) {
7605 case 1: /* UZP1/2 */
7607 int midpoint
= elements
/ 2;
7609 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
7611 read_vec_element(s
, tcg_res
, rm
,
7612 2 * (i
- midpoint
) + part
, size
);
7616 case 2: /* TRN1/2 */
7618 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
7620 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
7623 case 3: /* ZIP1/2 */
7625 int base
= part
* elements
/ 2;
7627 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
7629 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
7634 g_assert_not_reached();
7639 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
7640 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
7642 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
7643 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
7647 tcg_temp_free_i64(tcg_res
);
7649 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
7650 tcg_temp_free_i64(tcg_resl
);
7653 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
7654 tcg_temp_free_i64(tcg_resh
);
7656 clear_vec_high(s
, is_q
, rd
);
7660 * do_reduction_op helper
7662 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
7663 * important for correct NaN propagation that we do these
7664 * operations in exactly the order specified by the pseudocode.
7666 * This is a recursive function, TCG temps should be freed by the
7667 * calling function once it is done with the values.
7669 static TCGv_i32
do_reduction_op(DisasContext
*s
, int fpopcode
, int rn
,
7670 int esize
, int size
, int vmap
, TCGv_ptr fpst
)
7672 if (esize
== size
) {
7674 MemOp msize
= esize
== 16 ? MO_16
: MO_32
;
7677 /* We should have one register left here */
7678 assert(ctpop8(vmap
) == 1);
7679 element
= ctz32(vmap
);
7680 assert(element
< 8);
7682 tcg_elem
= tcg_temp_new_i32();
7683 read_vec_element_i32(s
, tcg_elem
, rn
, element
, msize
);
7686 int bits
= size
/ 2;
7687 int shift
= ctpop8(vmap
) / 2;
7688 int vmap_lo
= (vmap
>> shift
) & vmap
;
7689 int vmap_hi
= (vmap
& ~vmap_lo
);
7690 TCGv_i32 tcg_hi
, tcg_lo
, tcg_res
;
7692 tcg_hi
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_hi
, fpst
);
7693 tcg_lo
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_lo
, fpst
);
7694 tcg_res
= tcg_temp_new_i32();
7697 case 0x0c: /* fmaxnmv half-precision */
7698 gen_helper_advsimd_maxnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7700 case 0x0f: /* fmaxv half-precision */
7701 gen_helper_advsimd_maxh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7703 case 0x1c: /* fminnmv half-precision */
7704 gen_helper_advsimd_minnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7706 case 0x1f: /* fminv half-precision */
7707 gen_helper_advsimd_minh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7709 case 0x2c: /* fmaxnmv */
7710 gen_helper_vfp_maxnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7712 case 0x2f: /* fmaxv */
7713 gen_helper_vfp_maxs(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7715 case 0x3c: /* fminnmv */
7716 gen_helper_vfp_minnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7718 case 0x3f: /* fminv */
7719 gen_helper_vfp_mins(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7722 g_assert_not_reached();
7725 tcg_temp_free_i32(tcg_hi
);
7726 tcg_temp_free_i32(tcg_lo
);
7731 /* AdvSIMD across lanes
7732 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7733 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7734 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7735 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7737 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
7739 int rd
= extract32(insn
, 0, 5);
7740 int rn
= extract32(insn
, 5, 5);
7741 int size
= extract32(insn
, 22, 2);
7742 int opcode
= extract32(insn
, 12, 5);
7743 bool is_q
= extract32(insn
, 30, 1);
7744 bool is_u
= extract32(insn
, 29, 1);
7746 bool is_min
= false;
7750 TCGv_i64 tcg_res
, tcg_elt
;
7753 case 0x1b: /* ADDV */
7755 unallocated_encoding(s
);
7759 case 0x3: /* SADDLV, UADDLV */
7760 case 0xa: /* SMAXV, UMAXV */
7761 case 0x1a: /* SMINV, UMINV */
7762 if (size
== 3 || (size
== 2 && !is_q
)) {
7763 unallocated_encoding(s
);
7767 case 0xc: /* FMAXNMV, FMINNMV */
7768 case 0xf: /* FMAXV, FMINV */
7769 /* Bit 1 of size field encodes min vs max and the actual size
7770 * depends on the encoding of the U bit. If not set (and FP16
7771 * enabled) then we do half-precision float instead of single
7774 is_min
= extract32(size
, 1, 1);
7776 if (!is_u
&& dc_isar_feature(aa64_fp16
, s
)) {
7778 } else if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
7779 unallocated_encoding(s
);
7786 unallocated_encoding(s
);
7790 if (!fp_access_check(s
)) {
7795 elements
= (is_q
? 128 : 64) / esize
;
7797 tcg_res
= tcg_temp_new_i64();
7798 tcg_elt
= tcg_temp_new_i64();
7800 /* These instructions operate across all lanes of a vector
7801 * to produce a single result. We can guarantee that a 64
7802 * bit intermediate is sufficient:
7803 * + for [US]ADDLV the maximum element size is 32 bits, and
7804 * the result type is 64 bits
7805 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
7806 * same as the element size, which is 32 bits at most
7807 * For the integer operations we can choose to work at 64
7808 * or 32 bits and truncate at the end; for simplicity
7809 * we use 64 bits always. The floating point
7810 * ops do require 32 bit intermediates, though.
7813 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
7815 for (i
= 1; i
< elements
; i
++) {
7816 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
7819 case 0x03: /* SADDLV / UADDLV */
7820 case 0x1b: /* ADDV */
7821 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
7823 case 0x0a: /* SMAXV / UMAXV */
7825 tcg_gen_umax_i64(tcg_res
, tcg_res
, tcg_elt
);
7827 tcg_gen_smax_i64(tcg_res
, tcg_res
, tcg_elt
);
7830 case 0x1a: /* SMINV / UMINV */
7832 tcg_gen_umin_i64(tcg_res
, tcg_res
, tcg_elt
);
7834 tcg_gen_smin_i64(tcg_res
, tcg_res
, tcg_elt
);
7838 g_assert_not_reached();
7843 /* Floating point vector reduction ops which work across 32
7844 * bit (single) or 16 bit (half-precision) intermediates.
7845 * Note that correct NaN propagation requires that we do these
7846 * operations in exactly the order specified by the pseudocode.
7848 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
7849 int fpopcode
= opcode
| is_min
<< 4 | is_u
<< 5;
7850 int vmap
= (1 << elements
) - 1;
7851 TCGv_i32 tcg_res32
= do_reduction_op(s
, fpopcode
, rn
, esize
,
7852 (is_q
? 128 : 64), vmap
, fpst
);
7853 tcg_gen_extu_i32_i64(tcg_res
, tcg_res32
);
7854 tcg_temp_free_i32(tcg_res32
);
7855 tcg_temp_free_ptr(fpst
);
7858 tcg_temp_free_i64(tcg_elt
);
7860 /* Now truncate the result to the width required for the final output */
7861 if (opcode
== 0x03) {
7862 /* SADDLV, UADDLV: result is 2*esize */
7868 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
7871 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
7874 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
7879 g_assert_not_reached();
7882 write_fp_dreg(s
, rd
, tcg_res
);
7883 tcg_temp_free_i64(tcg_res
);
7886 /* DUP (Element, Vector)
7888 * 31 30 29 21 20 16 15 10 9 5 4 0
7889 * +---+---+-------------------+--------+-------------+------+------+
7890 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7891 * +---+---+-------------------+--------+-------------+------+------+
7893 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7895 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
7898 int size
= ctz32(imm5
);
7901 if (size
> 3 || (size
== 3 && !is_q
)) {
7902 unallocated_encoding(s
);
7906 if (!fp_access_check(s
)) {
7910 index
= imm5
>> (size
+ 1);
7911 tcg_gen_gvec_dup_mem(size
, vec_full_reg_offset(s
, rd
),
7912 vec_reg_offset(s
, rn
, index
, size
),
7913 is_q
? 16 : 8, vec_full_reg_size(s
));
7916 /* DUP (element, scalar)
7917 * 31 21 20 16 15 10 9 5 4 0
7918 * +-----------------------+--------+-------------+------+------+
7919 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7920 * +-----------------------+--------+-------------+------+------+
7922 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
7925 int size
= ctz32(imm5
);
7930 unallocated_encoding(s
);
7934 if (!fp_access_check(s
)) {
7938 index
= imm5
>> (size
+ 1);
7940 /* This instruction just extracts the specified element and
7941 * zero-extends it into the bottom of the destination register.
7943 tmp
= tcg_temp_new_i64();
7944 read_vec_element(s
, tmp
, rn
, index
, size
);
7945 write_fp_dreg(s
, rd
, tmp
);
7946 tcg_temp_free_i64(tmp
);
7951 * 31 30 29 21 20 16 15 10 9 5 4 0
7952 * +---+---+-------------------+--------+-------------+------+------+
7953 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
7954 * +---+---+-------------------+--------+-------------+------+------+
7956 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7958 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
7961 int size
= ctz32(imm5
);
7962 uint32_t dofs
, oprsz
, maxsz
;
7964 if (size
> 3 || ((size
== 3) && !is_q
)) {
7965 unallocated_encoding(s
);
7969 if (!fp_access_check(s
)) {
7973 dofs
= vec_full_reg_offset(s
, rd
);
7974 oprsz
= is_q
? 16 : 8;
7975 maxsz
= vec_full_reg_size(s
);
7977 tcg_gen_gvec_dup_i64(size
, dofs
, oprsz
, maxsz
, cpu_reg(s
, rn
));
7982 * 31 21 20 16 15 14 11 10 9 5 4 0
7983 * +-----------------------+--------+------------+---+------+------+
7984 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7985 * +-----------------------+--------+------------+---+------+------+
7987 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7988 * index: encoded in imm5<4:size+1>
7990 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
7993 int size
= ctz32(imm5
);
7994 int src_index
, dst_index
;
7998 unallocated_encoding(s
);
8002 if (!fp_access_check(s
)) {
8006 dst_index
= extract32(imm5
, 1+size
, 5);
8007 src_index
= extract32(imm4
, size
, 4);
8009 tmp
= tcg_temp_new_i64();
8011 read_vec_element(s
, tmp
, rn
, src_index
, size
);
8012 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
8014 tcg_temp_free_i64(tmp
);
8016 /* INS is considered a 128-bit write for SVE. */
8017 clear_vec_high(s
, true, rd
);
8023 * 31 21 20 16 15 10 9 5 4 0
8024 * +-----------------------+--------+-------------+------+------+
8025 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
8026 * +-----------------------+--------+-------------+------+------+
8028 * size: encoded in imm5 (see ARM ARM LowestSetBit())
8029 * index: encoded in imm5<4:size+1>
8031 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
8033 int size
= ctz32(imm5
);
8037 unallocated_encoding(s
);
8041 if (!fp_access_check(s
)) {
8045 idx
= extract32(imm5
, 1 + size
, 4 - size
);
8046 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
8048 /* INS is considered a 128-bit write for SVE. */
8049 clear_vec_high(s
, true, rd
);
8056 * 31 30 29 21 20 16 15 12 10 9 5 4 0
8057 * +---+---+-------------------+--------+-------------+------+------+
8058 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
8059 * +---+---+-------------------+--------+-------------+------+------+
8061 * U: unsigned when set
8062 * size: encoded in imm5 (see ARM ARM LowestSetBit())
8064 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
8065 int rn
, int rd
, int imm5
)
8067 int size
= ctz32(imm5
);
8071 /* Check for UnallocatedEncodings */
8073 if (size
> 2 || (size
== 2 && !is_q
)) {
8074 unallocated_encoding(s
);
8079 || (size
< 3 && is_q
)
8080 || (size
== 3 && !is_q
)) {
8081 unallocated_encoding(s
);
8086 if (!fp_access_check(s
)) {
8090 element
= extract32(imm5
, 1+size
, 4);
8092 tcg_rd
= cpu_reg(s
, rd
);
8093 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
8094 if (is_signed
&& !is_q
) {
8095 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
8100 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
8101 * +---+---+----+-----------------+------+---+------+---+------+------+
8102 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
8103 * +---+---+----+-----------------+------+---+------+---+------+------+
8105 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
8107 int rd
= extract32(insn
, 0, 5);
8108 int rn
= extract32(insn
, 5, 5);
8109 int imm4
= extract32(insn
, 11, 4);
8110 int op
= extract32(insn
, 29, 1);
8111 int is_q
= extract32(insn
, 30, 1);
8112 int imm5
= extract32(insn
, 16, 5);
8117 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
8119 unallocated_encoding(s
);
8124 /* DUP (element - vector) */
8125 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
8129 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
8134 handle_simd_insg(s
, rd
, rn
, imm5
);
8136 unallocated_encoding(s
);
8141 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
8142 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
8145 unallocated_encoding(s
);
8151 /* AdvSIMD modified immediate
8152 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
8153 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
8154 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
8155 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
8157 * There are a number of operations that can be carried out here:
8158 * MOVI - move (shifted) imm into register
8159 * MVNI - move inverted (shifted) imm into register
8160 * ORR - bitwise OR of (shifted) imm with register
8161 * BIC - bitwise clear of (shifted) imm with register
8162 * With ARMv8.2 we also have:
8163 * FMOV half-precision
8165 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
8167 int rd
= extract32(insn
, 0, 5);
8168 int cmode
= extract32(insn
, 12, 4);
8169 int cmode_3_1
= extract32(cmode
, 1, 3);
8170 int cmode_0
= extract32(cmode
, 0, 1);
8171 int o2
= extract32(insn
, 11, 1);
8172 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
8173 bool is_neg
= extract32(insn
, 29, 1);
8174 bool is_q
= extract32(insn
, 30, 1);
8177 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
8178 /* Check for FMOV (vector, immediate) - half-precision */
8179 if (!(dc_isar_feature(aa64_fp16
, s
) && o2
&& cmode
== 0xf)) {
8180 unallocated_encoding(s
);
8185 if (!fp_access_check(s
)) {
8189 /* See AdvSIMDExpandImm() in ARM ARM */
8190 switch (cmode_3_1
) {
8191 case 0: /* Replicate(Zeros(24):imm8, 2) */
8192 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
8193 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
8194 case 3: /* Replicate(imm8:Zeros(24), 2) */
8196 int shift
= cmode_3_1
* 8;
8197 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
8200 case 4: /* Replicate(Zeros(8):imm8, 4) */
8201 case 5: /* Replicate(imm8:Zeros(8), 4) */
8203 int shift
= (cmode_3_1
& 0x1) * 8;
8204 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
8209 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
8210 imm
= (abcdefgh
<< 16) | 0xffff;
8212 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
8213 imm
= (abcdefgh
<< 8) | 0xff;
8215 imm
= bitfield_replicate(imm
, 32);
8218 if (!cmode_0
&& !is_neg
) {
8219 imm
= bitfield_replicate(abcdefgh
, 8);
8220 } else if (!cmode_0
&& is_neg
) {
8223 for (i
= 0; i
< 8; i
++) {
8224 if ((abcdefgh
) & (1 << i
)) {
8225 imm
|= 0xffULL
<< (i
* 8);
8228 } else if (cmode_0
) {
8230 imm
= (abcdefgh
& 0x3f) << 48;
8231 if (abcdefgh
& 0x80) {
8232 imm
|= 0x8000000000000000ULL
;
8234 if (abcdefgh
& 0x40) {
8235 imm
|= 0x3fc0000000000000ULL
;
8237 imm
|= 0x4000000000000000ULL
;
8241 /* FMOV (vector, immediate) - half-precision */
8242 imm
= vfp_expand_imm(MO_16
, abcdefgh
);
8243 /* now duplicate across the lanes */
8244 imm
= bitfield_replicate(imm
, 16);
8246 imm
= (abcdefgh
& 0x3f) << 19;
8247 if (abcdefgh
& 0x80) {
8250 if (abcdefgh
& 0x40) {
8261 fprintf(stderr
, "%s: cmode_3_1: %x\n", __func__
, cmode_3_1
);
8262 g_assert_not_reached();
8265 if (cmode_3_1
!= 7 && is_neg
) {
8269 if (!((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9)) {
8270 /* MOVI or MVNI, with MVNI negation handled above. */
8271 tcg_gen_gvec_dup_imm(MO_64
, vec_full_reg_offset(s
, rd
), is_q
? 16 : 8,
8272 vec_full_reg_size(s
), imm
);
8274 /* ORR or BIC, with BIC negation to AND handled above. */
8276 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_andi
, MO_64
);
8278 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_ori
, MO_64
);
8283 /* AdvSIMD scalar copy
8284 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
8285 * +-----+----+-----------------+------+---+------+---+------+------+
8286 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
8287 * +-----+----+-----------------+------+---+------+---+------+------+
8289 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
8291 int rd
= extract32(insn
, 0, 5);
8292 int rn
= extract32(insn
, 5, 5);
8293 int imm4
= extract32(insn
, 11, 4);
8294 int imm5
= extract32(insn
, 16, 5);
8295 int op
= extract32(insn
, 29, 1);
8297 if (op
!= 0 || imm4
!= 0) {
8298 unallocated_encoding(s
);
8302 /* DUP (element, scalar) */
8303 handle_simd_dupes(s
, rd
, rn
, imm5
);
8306 /* AdvSIMD scalar pairwise
8307 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
8308 * +-----+---+-----------+------+-----------+--------+-----+------+------+
8309 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
8310 * +-----+---+-----------+------+-----------+--------+-----+------+------+
8312 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
8314 int u
= extract32(insn
, 29, 1);
8315 int size
= extract32(insn
, 22, 2);
8316 int opcode
= extract32(insn
, 12, 5);
8317 int rn
= extract32(insn
, 5, 5);
8318 int rd
= extract32(insn
, 0, 5);
8321 /* For some ops (the FP ones), size[1] is part of the encoding.
8322 * For ADDP strictly it is not but size[1] is always 1 for valid
8325 opcode
|= (extract32(size
, 1, 1) << 5);
8328 case 0x3b: /* ADDP */
8329 if (u
|| size
!= 3) {
8330 unallocated_encoding(s
);
8333 if (!fp_access_check(s
)) {
8339 case 0xc: /* FMAXNMP */
8340 case 0xd: /* FADDP */
8341 case 0xf: /* FMAXP */
8342 case 0x2c: /* FMINNMP */
8343 case 0x2f: /* FMINP */
8344 /* FP op, size[0] is 32 or 64 bit*/
8346 if (!dc_isar_feature(aa64_fp16
, s
)) {
8347 unallocated_encoding(s
);
8353 size
= extract32(size
, 0, 1) ? MO_64
: MO_32
;
8356 if (!fp_access_check(s
)) {
8360 fpst
= get_fpstatus_ptr(size
== MO_16
);
8363 unallocated_encoding(s
);
8367 if (size
== MO_64
) {
8368 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8369 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8370 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8372 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
8373 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
8376 case 0x3b: /* ADDP */
8377 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
8379 case 0xc: /* FMAXNMP */
8380 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8382 case 0xd: /* FADDP */
8383 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8385 case 0xf: /* FMAXP */
8386 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8388 case 0x2c: /* FMINNMP */
8389 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8391 case 0x2f: /* FMINP */
8392 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8395 g_assert_not_reached();
8398 write_fp_dreg(s
, rd
, tcg_res
);
8400 tcg_temp_free_i64(tcg_op1
);
8401 tcg_temp_free_i64(tcg_op2
);
8402 tcg_temp_free_i64(tcg_res
);
8404 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8405 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8406 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8408 read_vec_element_i32(s
, tcg_op1
, rn
, 0, size
);
8409 read_vec_element_i32(s
, tcg_op2
, rn
, 1, size
);
8411 if (size
== MO_16
) {
8413 case 0xc: /* FMAXNMP */
8414 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8416 case 0xd: /* FADDP */
8417 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8419 case 0xf: /* FMAXP */
8420 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8422 case 0x2c: /* FMINNMP */
8423 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8425 case 0x2f: /* FMINP */
8426 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8429 g_assert_not_reached();
8433 case 0xc: /* FMAXNMP */
8434 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8436 case 0xd: /* FADDP */
8437 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8439 case 0xf: /* FMAXP */
8440 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8442 case 0x2c: /* FMINNMP */
8443 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8445 case 0x2f: /* FMINP */
8446 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8449 g_assert_not_reached();
8453 write_fp_sreg(s
, rd
, tcg_res
);
8455 tcg_temp_free_i32(tcg_op1
);
8456 tcg_temp_free_i32(tcg_op2
);
8457 tcg_temp_free_i32(tcg_res
);
8461 tcg_temp_free_ptr(fpst
);
8466 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
8468 * This code is handles the common shifting code and is used by both
8469 * the vector and scalar code.
8471 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
8472 TCGv_i64 tcg_rnd
, bool accumulate
,
8473 bool is_u
, int size
, int shift
)
8475 bool extended_result
= false;
8476 bool round
= tcg_rnd
!= NULL
;
8478 TCGv_i64 tcg_src_hi
;
8480 if (round
&& size
== 3) {
8481 extended_result
= true;
8482 ext_lshift
= 64 - shift
;
8483 tcg_src_hi
= tcg_temp_new_i64();
8484 } else if (shift
== 64) {
8485 if (!accumulate
&& is_u
) {
8486 /* result is zero */
8487 tcg_gen_movi_i64(tcg_res
, 0);
8492 /* Deal with the rounding step */
8494 if (extended_result
) {
8495 TCGv_i64 tcg_zero
= tcg_const_i64(0);
8497 /* take care of sign extending tcg_res */
8498 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
8499 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
8500 tcg_src
, tcg_src_hi
,
8503 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
8507 tcg_temp_free_i64(tcg_zero
);
8509 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
8513 /* Now do the shift right */
8514 if (round
&& extended_result
) {
8515 /* extended case, >64 bit precision required */
8516 if (ext_lshift
== 0) {
8517 /* special case, only high bits matter */
8518 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
8520 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
8521 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
8522 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
8527 /* essentially shifting in 64 zeros */
8528 tcg_gen_movi_i64(tcg_src
, 0);
8530 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
8534 /* effectively extending the sign-bit */
8535 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
8537 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
8543 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
8545 tcg_gen_mov_i64(tcg_res
, tcg_src
);
8548 if (extended_result
) {
8549 tcg_temp_free_i64(tcg_src_hi
);
8553 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
8554 static void handle_scalar_simd_shri(DisasContext
*s
,
8555 bool is_u
, int immh
, int immb
,
8556 int opcode
, int rn
, int rd
)
8559 int immhb
= immh
<< 3 | immb
;
8560 int shift
= 2 * (8 << size
) - immhb
;
8561 bool accumulate
= false;
8563 bool insert
= false;
8568 if (!extract32(immh
, 3, 1)) {
8569 unallocated_encoding(s
);
8573 if (!fp_access_check(s
)) {
8578 case 0x02: /* SSRA / USRA (accumulate) */
8581 case 0x04: /* SRSHR / URSHR (rounding) */
8584 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8585 accumulate
= round
= true;
8587 case 0x08: /* SRI */
8593 uint64_t round_const
= 1ULL << (shift
- 1);
8594 tcg_round
= tcg_const_i64(round_const
);
8599 tcg_rn
= read_fp_dreg(s
, rn
);
8600 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
8603 /* shift count same as element size is valid but does nothing;
8604 * special case to avoid potential shift by 64.
8606 int esize
= 8 << size
;
8607 if (shift
!= esize
) {
8608 tcg_gen_shri_i64(tcg_rn
, tcg_rn
, shift
);
8609 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, 0, esize
- shift
);
8612 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8613 accumulate
, is_u
, size
, shift
);
8616 write_fp_dreg(s
, rd
, tcg_rd
);
8618 tcg_temp_free_i64(tcg_rn
);
8619 tcg_temp_free_i64(tcg_rd
);
8621 tcg_temp_free_i64(tcg_round
);
8625 /* SHL/SLI - Scalar shift left */
8626 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
8627 int immh
, int immb
, int opcode
,
8630 int size
= 32 - clz32(immh
) - 1;
8631 int immhb
= immh
<< 3 | immb
;
8632 int shift
= immhb
- (8 << size
);
8633 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8634 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8636 if (!extract32(immh
, 3, 1)) {
8637 unallocated_encoding(s
);
8641 if (!fp_access_check(s
)) {
8645 tcg_rn
= read_fp_dreg(s
, rn
);
8646 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
8649 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, shift
, 64 - shift
);
8651 tcg_gen_shli_i64(tcg_rd
, tcg_rn
, shift
);
8654 write_fp_dreg(s
, rd
, tcg_rd
);
8656 tcg_temp_free_i64(tcg_rn
);
8657 tcg_temp_free_i64(tcg_rd
);
8660 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
8661 * (signed/unsigned) narrowing */
8662 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
8663 bool is_u_shift
, bool is_u_narrow
,
8664 int immh
, int immb
, int opcode
,
8667 int immhb
= immh
<< 3 | immb
;
8668 int size
= 32 - clz32(immh
) - 1;
8669 int esize
= 8 << size
;
8670 int shift
= (2 * esize
) - immhb
;
8671 int elements
= is_scalar
? 1 : (64 / esize
);
8672 bool round
= extract32(opcode
, 0, 1);
8673 MemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
8674 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
8675 TCGv_i32 tcg_rd_narrowed
;
8678 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
8679 { gen_helper_neon_narrow_sat_s8
,
8680 gen_helper_neon_unarrow_sat8
},
8681 { gen_helper_neon_narrow_sat_s16
,
8682 gen_helper_neon_unarrow_sat16
},
8683 { gen_helper_neon_narrow_sat_s32
,
8684 gen_helper_neon_unarrow_sat32
},
8687 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
8688 gen_helper_neon_narrow_sat_u8
,
8689 gen_helper_neon_narrow_sat_u16
,
8690 gen_helper_neon_narrow_sat_u32
,
8693 NeonGenNarrowEnvFn
*narrowfn
;
8699 if (extract32(immh
, 3, 1)) {
8700 unallocated_encoding(s
);
8704 if (!fp_access_check(s
)) {
8709 narrowfn
= unsigned_narrow_fns
[size
];
8711 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
8714 tcg_rn
= tcg_temp_new_i64();
8715 tcg_rd
= tcg_temp_new_i64();
8716 tcg_rd_narrowed
= tcg_temp_new_i32();
8717 tcg_final
= tcg_const_i64(0);
8720 uint64_t round_const
= 1ULL << (shift
- 1);
8721 tcg_round
= tcg_const_i64(round_const
);
8726 for (i
= 0; i
< elements
; i
++) {
8727 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
8728 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8729 false, is_u_shift
, size
+1, shift
);
8730 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
8731 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
8732 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8736 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8738 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8742 tcg_temp_free_i64(tcg_round
);
8744 tcg_temp_free_i64(tcg_rn
);
8745 tcg_temp_free_i64(tcg_rd
);
8746 tcg_temp_free_i32(tcg_rd_narrowed
);
8747 tcg_temp_free_i64(tcg_final
);
8749 clear_vec_high(s
, is_q
, rd
);
8752 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
8753 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
8754 bool src_unsigned
, bool dst_unsigned
,
8755 int immh
, int immb
, int rn
, int rd
)
8757 int immhb
= immh
<< 3 | immb
;
8758 int size
= 32 - clz32(immh
) - 1;
8759 int shift
= immhb
- (8 << size
);
8763 assert(!(scalar
&& is_q
));
8766 if (!is_q
&& extract32(immh
, 3, 1)) {
8767 unallocated_encoding(s
);
8771 /* Since we use the variable-shift helpers we must
8772 * replicate the shift count into each element of
8773 * the tcg_shift value.
8777 shift
|= shift
<< 8;
8780 shift
|= shift
<< 16;
8786 g_assert_not_reached();
8790 if (!fp_access_check(s
)) {
8795 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
8796 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
8797 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
8798 { NULL
, gen_helper_neon_qshl_u64
},
8800 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
8801 int maxpass
= is_q
? 2 : 1;
8803 for (pass
= 0; pass
< maxpass
; pass
++) {
8804 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8806 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8807 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8808 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
8810 tcg_temp_free_i64(tcg_op
);
8812 tcg_temp_free_i64(tcg_shift
);
8813 clear_vec_high(s
, is_q
, rd
);
8815 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
8816 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
8818 { gen_helper_neon_qshl_s8
,
8819 gen_helper_neon_qshl_s16
,
8820 gen_helper_neon_qshl_s32
},
8821 { gen_helper_neon_qshlu_s8
,
8822 gen_helper_neon_qshlu_s16
,
8823 gen_helper_neon_qshlu_s32
}
8825 { NULL
, NULL
, NULL
},
8826 { gen_helper_neon_qshl_u8
,
8827 gen_helper_neon_qshl_u16
,
8828 gen_helper_neon_qshl_u32
}
8831 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
8832 MemOp memop
= scalar
? size
: MO_32
;
8833 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
8835 for (pass
= 0; pass
< maxpass
; pass
++) {
8836 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8838 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
8839 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8843 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
8846 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
8851 g_assert_not_reached();
8853 write_fp_sreg(s
, rd
, tcg_op
);
8855 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
8858 tcg_temp_free_i32(tcg_op
);
8860 tcg_temp_free_i32(tcg_shift
);
8863 clear_vec_high(s
, is_q
, rd
);
8868 /* Common vector code for handling integer to FP conversion */
8869 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
8870 int elements
, int is_signed
,
8871 int fracbits
, int size
)
8873 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(size
== MO_16
);
8874 TCGv_i32 tcg_shift
= NULL
;
8876 MemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
8879 if (fracbits
|| size
== MO_64
) {
8880 tcg_shift
= tcg_const_i32(fracbits
);
8883 if (size
== MO_64
) {
8884 TCGv_i64 tcg_int64
= tcg_temp_new_i64();
8885 TCGv_i64 tcg_double
= tcg_temp_new_i64();
8887 for (pass
= 0; pass
< elements
; pass
++) {
8888 read_vec_element(s
, tcg_int64
, rn
, pass
, mop
);
8891 gen_helper_vfp_sqtod(tcg_double
, tcg_int64
,
8892 tcg_shift
, tcg_fpst
);
8894 gen_helper_vfp_uqtod(tcg_double
, tcg_int64
,
8895 tcg_shift
, tcg_fpst
);
8897 if (elements
== 1) {
8898 write_fp_dreg(s
, rd
, tcg_double
);
8900 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
8904 tcg_temp_free_i64(tcg_int64
);
8905 tcg_temp_free_i64(tcg_double
);
8908 TCGv_i32 tcg_int32
= tcg_temp_new_i32();
8909 TCGv_i32 tcg_float
= tcg_temp_new_i32();
8911 for (pass
= 0; pass
< elements
; pass
++) {
8912 read_vec_element_i32(s
, tcg_int32
, rn
, pass
, mop
);
8918 gen_helper_vfp_sltos(tcg_float
, tcg_int32
,
8919 tcg_shift
, tcg_fpst
);
8921 gen_helper_vfp_ultos(tcg_float
, tcg_int32
,
8922 tcg_shift
, tcg_fpst
);
8926 gen_helper_vfp_sitos(tcg_float
, tcg_int32
, tcg_fpst
);
8928 gen_helper_vfp_uitos(tcg_float
, tcg_int32
, tcg_fpst
);
8935 gen_helper_vfp_sltoh(tcg_float
, tcg_int32
,
8936 tcg_shift
, tcg_fpst
);
8938 gen_helper_vfp_ultoh(tcg_float
, tcg_int32
,
8939 tcg_shift
, tcg_fpst
);
8943 gen_helper_vfp_sitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8945 gen_helper_vfp_uitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8950 g_assert_not_reached();
8953 if (elements
== 1) {
8954 write_fp_sreg(s
, rd
, tcg_float
);
8956 write_vec_element_i32(s
, tcg_float
, rd
, pass
, size
);
8960 tcg_temp_free_i32(tcg_int32
);
8961 tcg_temp_free_i32(tcg_float
);
8964 tcg_temp_free_ptr(tcg_fpst
);
8966 tcg_temp_free_i32(tcg_shift
);
8969 clear_vec_high(s
, elements
<< size
== 16, rd
);
8972 /* UCVTF/SCVTF - Integer to FP conversion */
8973 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
8974 bool is_q
, bool is_u
,
8975 int immh
, int immb
, int opcode
,
8978 int size
, elements
, fracbits
;
8979 int immhb
= immh
<< 3 | immb
;
8983 if (!is_scalar
&& !is_q
) {
8984 unallocated_encoding(s
);
8987 } else if (immh
& 4) {
8989 } else if (immh
& 2) {
8991 if (!dc_isar_feature(aa64_fp16
, s
)) {
8992 unallocated_encoding(s
);
8996 /* immh == 0 would be a failure of the decode logic */
8997 g_assert(immh
== 1);
8998 unallocated_encoding(s
);
9005 elements
= (8 << is_q
) >> size
;
9007 fracbits
= (16 << size
) - immhb
;
9009 if (!fp_access_check(s
)) {
9013 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
9016 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
9017 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
9018 bool is_q
, bool is_u
,
9019 int immh
, int immb
, int rn
, int rd
)
9021 int immhb
= immh
<< 3 | immb
;
9022 int pass
, size
, fracbits
;
9023 TCGv_ptr tcg_fpstatus
;
9024 TCGv_i32 tcg_rmode
, tcg_shift
;
9028 if (!is_scalar
&& !is_q
) {
9029 unallocated_encoding(s
);
9032 } else if (immh
& 0x4) {
9034 } else if (immh
& 0x2) {
9036 if (!dc_isar_feature(aa64_fp16
, s
)) {
9037 unallocated_encoding(s
);
9041 /* Should have split out AdvSIMD modified immediate earlier. */
9043 unallocated_encoding(s
);
9047 if (!fp_access_check(s
)) {
9051 assert(!(is_scalar
&& is_q
));
9053 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
9054 tcg_fpstatus
= get_fpstatus_ptr(size
== MO_16
);
9055 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9056 fracbits
= (16 << size
) - immhb
;
9057 tcg_shift
= tcg_const_i32(fracbits
);
9059 if (size
== MO_64
) {
9060 int maxpass
= is_scalar
? 1 : 2;
9062 for (pass
= 0; pass
< maxpass
; pass
++) {
9063 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9065 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9067 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
9069 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
9071 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
9072 tcg_temp_free_i64(tcg_op
);
9074 clear_vec_high(s
, is_q
, rd
);
9076 void (*fn
)(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
9077 int maxpass
= is_scalar
? 1 : ((8 << is_q
) >> size
);
9082 fn
= gen_helper_vfp_touhh
;
9084 fn
= gen_helper_vfp_toshh
;
9089 fn
= gen_helper_vfp_touls
;
9091 fn
= gen_helper_vfp_tosls
;
9095 g_assert_not_reached();
9098 for (pass
= 0; pass
< maxpass
; pass
++) {
9099 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9101 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
9102 fn(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
9104 write_fp_sreg(s
, rd
, tcg_op
);
9106 write_vec_element_i32(s
, tcg_op
, rd
, pass
, size
);
9108 tcg_temp_free_i32(tcg_op
);
9111 clear_vec_high(s
, is_q
, rd
);
9115 tcg_temp_free_ptr(tcg_fpstatus
);
9116 tcg_temp_free_i32(tcg_shift
);
9117 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9118 tcg_temp_free_i32(tcg_rmode
);
9121 /* AdvSIMD scalar shift by immediate
9122 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
9123 * +-----+---+-------------+------+------+--------+---+------+------+
9124 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
9125 * +-----+---+-------------+------+------+--------+---+------+------+
9127 * This is the scalar version so it works on a fixed sized registers
9129 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
9131 int rd
= extract32(insn
, 0, 5);
9132 int rn
= extract32(insn
, 5, 5);
9133 int opcode
= extract32(insn
, 11, 5);
9134 int immb
= extract32(insn
, 16, 3);
9135 int immh
= extract32(insn
, 19, 4);
9136 bool is_u
= extract32(insn
, 29, 1);
9139 unallocated_encoding(s
);
9144 case 0x08: /* SRI */
9146 unallocated_encoding(s
);
9150 case 0x00: /* SSHR / USHR */
9151 case 0x02: /* SSRA / USRA */
9152 case 0x04: /* SRSHR / URSHR */
9153 case 0x06: /* SRSRA / URSRA */
9154 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9156 case 0x0a: /* SHL / SLI */
9157 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9159 case 0x1c: /* SCVTF, UCVTF */
9160 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
9163 case 0x10: /* SQSHRUN, SQSHRUN2 */
9164 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
9166 unallocated_encoding(s
);
9169 handle_vec_simd_sqshrn(s
, true, false, false, true,
9170 immh
, immb
, opcode
, rn
, rd
);
9172 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
9173 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
9174 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
9175 immh
, immb
, opcode
, rn
, rd
);
9177 case 0xc: /* SQSHLU */
9179 unallocated_encoding(s
);
9182 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
9184 case 0xe: /* SQSHL, UQSHL */
9185 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
9187 case 0x1f: /* FCVTZS, FCVTZU */
9188 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
9191 unallocated_encoding(s
);
9196 /* AdvSIMD scalar three different
9197 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
9198 * +-----+---+-----------+------+---+------+--------+-----+------+------+
9199 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
9200 * +-----+---+-----------+------+---+------+--------+-----+------+------+
9202 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
9204 bool is_u
= extract32(insn
, 29, 1);
9205 int size
= extract32(insn
, 22, 2);
9206 int opcode
= extract32(insn
, 12, 4);
9207 int rm
= extract32(insn
, 16, 5);
9208 int rn
= extract32(insn
, 5, 5);
9209 int rd
= extract32(insn
, 0, 5);
9212 unallocated_encoding(s
);
9217 case 0x9: /* SQDMLAL, SQDMLAL2 */
9218 case 0xb: /* SQDMLSL, SQDMLSL2 */
9219 case 0xd: /* SQDMULL, SQDMULL2 */
9220 if (size
== 0 || size
== 3) {
9221 unallocated_encoding(s
);
9226 unallocated_encoding(s
);
9230 if (!fp_access_check(s
)) {
9235 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9236 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9237 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9239 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
9240 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
9242 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
9243 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
9246 case 0xd: /* SQDMULL, SQDMULL2 */
9248 case 0xb: /* SQDMLSL, SQDMLSL2 */
9249 tcg_gen_neg_i64(tcg_res
, tcg_res
);
9251 case 0x9: /* SQDMLAL, SQDMLAL2 */
9252 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
9253 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
9257 g_assert_not_reached();
9260 write_fp_dreg(s
, rd
, tcg_res
);
9262 tcg_temp_free_i64(tcg_op1
);
9263 tcg_temp_free_i64(tcg_op2
);
9264 tcg_temp_free_i64(tcg_res
);
9266 TCGv_i32 tcg_op1
= read_fp_hreg(s
, rn
);
9267 TCGv_i32 tcg_op2
= read_fp_hreg(s
, rm
);
9268 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9270 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
9271 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
9274 case 0xd: /* SQDMULL, SQDMULL2 */
9276 case 0xb: /* SQDMLSL, SQDMLSL2 */
9277 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
9279 case 0x9: /* SQDMLAL, SQDMLAL2 */
9281 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
9282 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
9283 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
9285 tcg_temp_free_i64(tcg_op3
);
9289 g_assert_not_reached();
9292 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
9293 write_fp_dreg(s
, rd
, tcg_res
);
9295 tcg_temp_free_i32(tcg_op1
);
9296 tcg_temp_free_i32(tcg_op2
);
9297 tcg_temp_free_i64(tcg_res
);
9301 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
9302 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
9304 /* Handle 64x64->64 opcodes which are shared between the scalar
9305 * and vector 3-same groups. We cover every opcode where size == 3
9306 * is valid in either the three-reg-same (integer, not pairwise)
9307 * or scalar-three-reg-same groups.
9312 case 0x1: /* SQADD */
9314 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9316 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9319 case 0x5: /* SQSUB */
9321 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9323 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9326 case 0x6: /* CMGT, CMHI */
9327 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
9328 * We implement this using setcond (test) and then negating.
9330 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
9332 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
9333 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
9335 case 0x7: /* CMGE, CMHS */
9336 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
9338 case 0x11: /* CMTST, CMEQ */
9343 gen_cmtst_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9345 case 0x8: /* SSHL, USHL */
9347 gen_ushl_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9349 gen_sshl_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9352 case 0x9: /* SQSHL, UQSHL */
9354 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9356 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9359 case 0xa: /* SRSHL, URSHL */
9361 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
9363 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
9366 case 0xb: /* SQRSHL, UQRSHL */
9368 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9370 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9373 case 0x10: /* ADD, SUB */
9375 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9377 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9381 g_assert_not_reached();
9385 /* Handle the 3-same-operands float operations; shared by the scalar
9386 * and vector encodings. The caller must filter out any encodings
9387 * not allocated for the encoding it is dealing with.
9389 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
9390 int fpopcode
, int rd
, int rn
, int rm
)
9393 TCGv_ptr fpst
= get_fpstatus_ptr(false);
9395 for (pass
= 0; pass
< elements
; pass
++) {
9398 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9399 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9400 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9402 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9403 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9406 case 0x39: /* FMLS */
9407 /* As usual for ARM, separate negation for fused multiply-add */
9408 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
9410 case 0x19: /* FMLA */
9411 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9412 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
9415 case 0x18: /* FMAXNM */
9416 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9418 case 0x1a: /* FADD */
9419 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9421 case 0x1b: /* FMULX */
9422 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9424 case 0x1c: /* FCMEQ */
9425 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9427 case 0x1e: /* FMAX */
9428 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9430 case 0x1f: /* FRECPS */
9431 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9433 case 0x38: /* FMINNM */
9434 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9436 case 0x3a: /* FSUB */
9437 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9439 case 0x3e: /* FMIN */
9440 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9442 case 0x3f: /* FRSQRTS */
9443 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9445 case 0x5b: /* FMUL */
9446 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9448 case 0x5c: /* FCMGE */
9449 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9451 case 0x5d: /* FACGE */
9452 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9454 case 0x5f: /* FDIV */
9455 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9457 case 0x7a: /* FABD */
9458 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9459 gen_helper_vfp_absd(tcg_res
, tcg_res
);
9461 case 0x7c: /* FCMGT */
9462 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9464 case 0x7d: /* FACGT */
9465 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9468 g_assert_not_reached();
9471 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9473 tcg_temp_free_i64(tcg_res
);
9474 tcg_temp_free_i64(tcg_op1
);
9475 tcg_temp_free_i64(tcg_op2
);
9478 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9479 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9480 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9482 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
9483 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
9486 case 0x39: /* FMLS */
9487 /* As usual for ARM, separate negation for fused multiply-add */
9488 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
9490 case 0x19: /* FMLA */
9491 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9492 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
9495 case 0x1a: /* FADD */
9496 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9498 case 0x1b: /* FMULX */
9499 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9501 case 0x1c: /* FCMEQ */
9502 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9504 case 0x1e: /* FMAX */
9505 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9507 case 0x1f: /* FRECPS */
9508 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9510 case 0x18: /* FMAXNM */
9511 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9513 case 0x38: /* FMINNM */
9514 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9516 case 0x3a: /* FSUB */
9517 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9519 case 0x3e: /* FMIN */
9520 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9522 case 0x3f: /* FRSQRTS */
9523 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9525 case 0x5b: /* FMUL */
9526 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9528 case 0x5c: /* FCMGE */
9529 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9531 case 0x5d: /* FACGE */
9532 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9534 case 0x5f: /* FDIV */
9535 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9537 case 0x7a: /* FABD */
9538 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9539 gen_helper_vfp_abss(tcg_res
, tcg_res
);
9541 case 0x7c: /* FCMGT */
9542 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9544 case 0x7d: /* FACGT */
9545 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9548 g_assert_not_reached();
9551 if (elements
== 1) {
9552 /* scalar single so clear high part */
9553 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9555 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
9556 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
9557 tcg_temp_free_i64(tcg_tmp
);
9559 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9562 tcg_temp_free_i32(tcg_res
);
9563 tcg_temp_free_i32(tcg_op1
);
9564 tcg_temp_free_i32(tcg_op2
);
9568 tcg_temp_free_ptr(fpst
);
9570 clear_vec_high(s
, elements
* (size
? 8 : 4) > 8, rd
);
9573 /* AdvSIMD scalar three same
9574 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
9575 * +-----+---+-----------+------+---+------+--------+---+------+------+
9576 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
9577 * +-----+---+-----------+------+---+------+--------+---+------+------+
9579 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
9581 int rd
= extract32(insn
, 0, 5);
9582 int rn
= extract32(insn
, 5, 5);
9583 int opcode
= extract32(insn
, 11, 5);
9584 int rm
= extract32(insn
, 16, 5);
9585 int size
= extract32(insn
, 22, 2);
9586 bool u
= extract32(insn
, 29, 1);
9589 if (opcode
>= 0x18) {
9590 /* Floating point: U, size[1] and opcode indicate operation */
9591 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
9593 case 0x1b: /* FMULX */
9594 case 0x1f: /* FRECPS */
9595 case 0x3f: /* FRSQRTS */
9596 case 0x5d: /* FACGE */
9597 case 0x7d: /* FACGT */
9598 case 0x1c: /* FCMEQ */
9599 case 0x5c: /* FCMGE */
9600 case 0x7c: /* FCMGT */
9601 case 0x7a: /* FABD */
9604 unallocated_encoding(s
);
9608 if (!fp_access_check(s
)) {
9612 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
9617 case 0x1: /* SQADD, UQADD */
9618 case 0x5: /* SQSUB, UQSUB */
9619 case 0x9: /* SQSHL, UQSHL */
9620 case 0xb: /* SQRSHL, UQRSHL */
9622 case 0x8: /* SSHL, USHL */
9623 case 0xa: /* SRSHL, URSHL */
9624 case 0x6: /* CMGT, CMHI */
9625 case 0x7: /* CMGE, CMHS */
9626 case 0x11: /* CMTST, CMEQ */
9627 case 0x10: /* ADD, SUB (vector) */
9629 unallocated_encoding(s
);
9633 case 0x16: /* SQDMULH, SQRDMULH (vector) */
9634 if (size
!= 1 && size
!= 2) {
9635 unallocated_encoding(s
);
9640 unallocated_encoding(s
);
9644 if (!fp_access_check(s
)) {
9648 tcg_rd
= tcg_temp_new_i64();
9651 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
9652 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
9654 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
9655 tcg_temp_free_i64(tcg_rn
);
9656 tcg_temp_free_i64(tcg_rm
);
9658 /* Do a single operation on the lowest element in the vector.
9659 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
9660 * no side effects for all these operations.
9661 * OPTME: special-purpose helpers would avoid doing some
9662 * unnecessary work in the helper for the 8 and 16 bit cases.
9664 NeonGenTwoOpEnvFn
*genenvfn
;
9665 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9666 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
9667 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
9669 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
9670 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
9673 case 0x1: /* SQADD, UQADD */
9675 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9676 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9677 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9678 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9680 genenvfn
= fns
[size
][u
];
9683 case 0x5: /* SQSUB, UQSUB */
9685 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9686 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9687 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9688 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9690 genenvfn
= fns
[size
][u
];
9693 case 0x9: /* SQSHL, UQSHL */
9695 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9696 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9697 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9698 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9700 genenvfn
= fns
[size
][u
];
9703 case 0xb: /* SQRSHL, UQRSHL */
9705 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9706 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9707 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9708 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9710 genenvfn
= fns
[size
][u
];
9713 case 0x16: /* SQDMULH, SQRDMULH */
9715 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9716 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9717 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9719 assert(size
== 1 || size
== 2);
9720 genenvfn
= fns
[size
- 1][u
];
9724 g_assert_not_reached();
9727 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
9728 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
9729 tcg_temp_free_i32(tcg_rd32
);
9730 tcg_temp_free_i32(tcg_rn
);
9731 tcg_temp_free_i32(tcg_rm
);
9734 write_fp_dreg(s
, rd
, tcg_rd
);
9736 tcg_temp_free_i64(tcg_rd
);
9739 /* AdvSIMD scalar three same FP16
9740 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
9741 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9742 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
9743 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9744 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
9745 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
9747 static void disas_simd_scalar_three_reg_same_fp16(DisasContext
*s
,
9750 int rd
= extract32(insn
, 0, 5);
9751 int rn
= extract32(insn
, 5, 5);
9752 int opcode
= extract32(insn
, 11, 3);
9753 int rm
= extract32(insn
, 16, 5);
9754 bool u
= extract32(insn
, 29, 1);
9755 bool a
= extract32(insn
, 23, 1);
9756 int fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
9763 case 0x03: /* FMULX */
9764 case 0x04: /* FCMEQ (reg) */
9765 case 0x07: /* FRECPS */
9766 case 0x0f: /* FRSQRTS */
9767 case 0x14: /* FCMGE (reg) */
9768 case 0x15: /* FACGE */
9769 case 0x1a: /* FABD */
9770 case 0x1c: /* FCMGT (reg) */
9771 case 0x1d: /* FACGT */
9774 unallocated_encoding(s
);
9778 if (!dc_isar_feature(aa64_fp16
, s
)) {
9779 unallocated_encoding(s
);
9782 if (!fp_access_check(s
)) {
9786 fpst
= get_fpstatus_ptr(true);
9788 tcg_op1
= read_fp_hreg(s
, rn
);
9789 tcg_op2
= read_fp_hreg(s
, rm
);
9790 tcg_res
= tcg_temp_new_i32();
9793 case 0x03: /* FMULX */
9794 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9796 case 0x04: /* FCMEQ (reg) */
9797 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9799 case 0x07: /* FRECPS */
9800 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9802 case 0x0f: /* FRSQRTS */
9803 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9805 case 0x14: /* FCMGE (reg) */
9806 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9808 case 0x15: /* FACGE */
9809 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9811 case 0x1a: /* FABD */
9812 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9813 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
9815 case 0x1c: /* FCMGT (reg) */
9816 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9818 case 0x1d: /* FACGT */
9819 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9822 g_assert_not_reached();
9825 write_fp_sreg(s
, rd
, tcg_res
);
9828 tcg_temp_free_i32(tcg_res
);
9829 tcg_temp_free_i32(tcg_op1
);
9830 tcg_temp_free_i32(tcg_op2
);
9831 tcg_temp_free_ptr(fpst
);
9834 /* AdvSIMD scalar three same extra
9835 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
9836 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9837 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
9838 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9840 static void disas_simd_scalar_three_reg_same_extra(DisasContext
*s
,
9843 int rd
= extract32(insn
, 0, 5);
9844 int rn
= extract32(insn
, 5, 5);
9845 int opcode
= extract32(insn
, 11, 4);
9846 int rm
= extract32(insn
, 16, 5);
9847 int size
= extract32(insn
, 22, 2);
9848 bool u
= extract32(insn
, 29, 1);
9849 TCGv_i32 ele1
, ele2
, ele3
;
9853 switch (u
* 16 + opcode
) {
9854 case 0x10: /* SQRDMLAH (vector) */
9855 case 0x11: /* SQRDMLSH (vector) */
9856 if (size
!= 1 && size
!= 2) {
9857 unallocated_encoding(s
);
9860 feature
= dc_isar_feature(aa64_rdm
, s
);
9863 unallocated_encoding(s
);
9867 unallocated_encoding(s
);
9870 if (!fp_access_check(s
)) {
9874 /* Do a single operation on the lowest element in the vector.
9875 * We use the standard Neon helpers and rely on 0 OP 0 == 0
9876 * with no side effects for all these operations.
9877 * OPTME: special-purpose helpers would avoid doing some
9878 * unnecessary work in the helper for the 16 bit cases.
9880 ele1
= tcg_temp_new_i32();
9881 ele2
= tcg_temp_new_i32();
9882 ele3
= tcg_temp_new_i32();
9884 read_vec_element_i32(s
, ele1
, rn
, 0, size
);
9885 read_vec_element_i32(s
, ele2
, rm
, 0, size
);
9886 read_vec_element_i32(s
, ele3
, rd
, 0, size
);
9889 case 0x0: /* SQRDMLAH */
9891 gen_helper_neon_qrdmlah_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9893 gen_helper_neon_qrdmlah_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9896 case 0x1: /* SQRDMLSH */
9898 gen_helper_neon_qrdmlsh_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9900 gen_helper_neon_qrdmlsh_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9904 g_assert_not_reached();
9906 tcg_temp_free_i32(ele1
);
9907 tcg_temp_free_i32(ele2
);
9909 res
= tcg_temp_new_i64();
9910 tcg_gen_extu_i32_i64(res
, ele3
);
9911 tcg_temp_free_i32(ele3
);
9913 write_fp_dreg(s
, rd
, res
);
9914 tcg_temp_free_i64(res
);
9917 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
9918 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
9919 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
9921 /* Handle 64->64 opcodes which are shared between the scalar and
9922 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
9923 * is valid in either group and also the double-precision fp ops.
9924 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
9930 case 0x4: /* CLS, CLZ */
9932 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
9934 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
9938 /* This opcode is shared with CNT and RBIT but we have earlier
9939 * enforced that size == 3 if and only if this is the NOT insn.
9941 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
9943 case 0x7: /* SQABS, SQNEG */
9945 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
9947 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
9950 case 0xa: /* CMLT */
9951 /* 64 bit integer comparison against zero, result is
9952 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
9957 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
9958 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
9960 case 0x8: /* CMGT, CMGE */
9961 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
9963 case 0x9: /* CMEQ, CMLE */
9964 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
9966 case 0xb: /* ABS, NEG */
9968 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
9970 tcg_gen_abs_i64(tcg_rd
, tcg_rn
);
9973 case 0x2f: /* FABS */
9974 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
9976 case 0x6f: /* FNEG */
9977 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
9979 case 0x7f: /* FSQRT */
9980 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
9982 case 0x1a: /* FCVTNS */
9983 case 0x1b: /* FCVTMS */
9984 case 0x1c: /* FCVTAS */
9985 case 0x3a: /* FCVTPS */
9986 case 0x3b: /* FCVTZS */
9988 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9989 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9990 tcg_temp_free_i32(tcg_shift
);
9993 case 0x5a: /* FCVTNU */
9994 case 0x5b: /* FCVTMU */
9995 case 0x5c: /* FCVTAU */
9996 case 0x7a: /* FCVTPU */
9997 case 0x7b: /* FCVTZU */
9999 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10000 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
10001 tcg_temp_free_i32(tcg_shift
);
10004 case 0x18: /* FRINTN */
10005 case 0x19: /* FRINTM */
10006 case 0x38: /* FRINTP */
10007 case 0x39: /* FRINTZ */
10008 case 0x58: /* FRINTA */
10009 case 0x79: /* FRINTI */
10010 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
10012 case 0x59: /* FRINTX */
10013 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
10015 case 0x1e: /* FRINT32Z */
10016 case 0x5e: /* FRINT32X */
10017 gen_helper_frint32_d(tcg_rd
, tcg_rn
, tcg_fpstatus
);
10019 case 0x1f: /* FRINT64Z */
10020 case 0x5f: /* FRINT64X */
10021 gen_helper_frint64_d(tcg_rd
, tcg_rn
, tcg_fpstatus
);
10024 g_assert_not_reached();
10028 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
10029 bool is_scalar
, bool is_u
, bool is_q
,
10030 int size
, int rn
, int rd
)
10032 bool is_double
= (size
== MO_64
);
10035 if (!fp_access_check(s
)) {
10039 fpst
= get_fpstatus_ptr(size
== MO_16
);
10042 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10043 TCGv_i64 tcg_zero
= tcg_const_i64(0);
10044 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10045 NeonGenTwoDoubleOpFn
*genfn
;
10050 case 0x2e: /* FCMLT (zero) */
10053 case 0x2c: /* FCMGT (zero) */
10054 genfn
= gen_helper_neon_cgt_f64
;
10056 case 0x2d: /* FCMEQ (zero) */
10057 genfn
= gen_helper_neon_ceq_f64
;
10059 case 0x6d: /* FCMLE (zero) */
10062 case 0x6c: /* FCMGE (zero) */
10063 genfn
= gen_helper_neon_cge_f64
;
10066 g_assert_not_reached();
10069 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10070 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10072 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
10074 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
10076 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10078 tcg_temp_free_i64(tcg_res
);
10079 tcg_temp_free_i64(tcg_zero
);
10080 tcg_temp_free_i64(tcg_op
);
10082 clear_vec_high(s
, !is_scalar
, rd
);
10084 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10085 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10086 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10087 NeonGenTwoSingleOpFn
*genfn
;
10089 int pass
, maxpasses
;
10091 if (size
== MO_16
) {
10093 case 0x2e: /* FCMLT (zero) */
10096 case 0x2c: /* FCMGT (zero) */
10097 genfn
= gen_helper_advsimd_cgt_f16
;
10099 case 0x2d: /* FCMEQ (zero) */
10100 genfn
= gen_helper_advsimd_ceq_f16
;
10102 case 0x6d: /* FCMLE (zero) */
10105 case 0x6c: /* FCMGE (zero) */
10106 genfn
= gen_helper_advsimd_cge_f16
;
10109 g_assert_not_reached();
10113 case 0x2e: /* FCMLT (zero) */
10116 case 0x2c: /* FCMGT (zero) */
10117 genfn
= gen_helper_neon_cgt_f32
;
10119 case 0x2d: /* FCMEQ (zero) */
10120 genfn
= gen_helper_neon_ceq_f32
;
10122 case 0x6d: /* FCMLE (zero) */
10125 case 0x6c: /* FCMGE (zero) */
10126 genfn
= gen_helper_neon_cge_f32
;
10129 g_assert_not_reached();
10136 int vector_size
= 8 << is_q
;
10137 maxpasses
= vector_size
>> size
;
10140 for (pass
= 0; pass
< maxpasses
; pass
++) {
10141 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10143 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
10145 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
10148 write_fp_sreg(s
, rd
, tcg_res
);
10150 write_vec_element_i32(s
, tcg_res
, rd
, pass
, size
);
10153 tcg_temp_free_i32(tcg_res
);
10154 tcg_temp_free_i32(tcg_zero
);
10155 tcg_temp_free_i32(tcg_op
);
10157 clear_vec_high(s
, is_q
, rd
);
10161 tcg_temp_free_ptr(fpst
);
10164 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
10165 bool is_scalar
, bool is_u
, bool is_q
,
10166 int size
, int rn
, int rd
)
10168 bool is_double
= (size
== 3);
10169 TCGv_ptr fpst
= get_fpstatus_ptr(false);
10172 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10173 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10176 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10177 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10179 case 0x3d: /* FRECPE */
10180 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
10182 case 0x3f: /* FRECPX */
10183 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
10185 case 0x7d: /* FRSQRTE */
10186 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
10189 g_assert_not_reached();
10191 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10193 tcg_temp_free_i64(tcg_res
);
10194 tcg_temp_free_i64(tcg_op
);
10195 clear_vec_high(s
, !is_scalar
, rd
);
10197 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10198 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10199 int pass
, maxpasses
;
10204 maxpasses
= is_q
? 4 : 2;
10207 for (pass
= 0; pass
< maxpasses
; pass
++) {
10208 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
10211 case 0x3c: /* URECPE */
10212 gen_helper_recpe_u32(tcg_res
, tcg_op
);
10214 case 0x3d: /* FRECPE */
10215 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
10217 case 0x3f: /* FRECPX */
10218 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
10220 case 0x7d: /* FRSQRTE */
10221 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
10224 g_assert_not_reached();
10228 write_fp_sreg(s
, rd
, tcg_res
);
10230 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10233 tcg_temp_free_i32(tcg_res
);
10234 tcg_temp_free_i32(tcg_op
);
10236 clear_vec_high(s
, is_q
, rd
);
10239 tcg_temp_free_ptr(fpst
);
10242 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
10243 int opcode
, bool u
, bool is_q
,
10244 int size
, int rn
, int rd
)
10246 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
10247 * in the source becomes a size element in the destination).
10250 TCGv_i32 tcg_res
[2];
10251 int destelt
= is_q
? 2 : 0;
10252 int passes
= scalar
? 1 : 2;
10255 tcg_res
[1] = tcg_const_i32(0);
10258 for (pass
= 0; pass
< passes
; pass
++) {
10259 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10260 NeonGenNarrowFn
*genfn
= NULL
;
10261 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
10264 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
10266 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10268 tcg_res
[pass
] = tcg_temp_new_i32();
10271 case 0x12: /* XTN, SQXTUN */
10273 static NeonGenNarrowFn
* const xtnfns
[3] = {
10274 gen_helper_neon_narrow_u8
,
10275 gen_helper_neon_narrow_u16
,
10276 tcg_gen_extrl_i64_i32
,
10278 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
10279 gen_helper_neon_unarrow_sat8
,
10280 gen_helper_neon_unarrow_sat16
,
10281 gen_helper_neon_unarrow_sat32
,
10284 genenvfn
= sqxtunfns
[size
];
10286 genfn
= xtnfns
[size
];
10290 case 0x14: /* SQXTN, UQXTN */
10292 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
10293 { gen_helper_neon_narrow_sat_s8
,
10294 gen_helper_neon_narrow_sat_u8
},
10295 { gen_helper_neon_narrow_sat_s16
,
10296 gen_helper_neon_narrow_sat_u16
},
10297 { gen_helper_neon_narrow_sat_s32
,
10298 gen_helper_neon_narrow_sat_u32
},
10300 genenvfn
= fns
[size
][u
];
10303 case 0x16: /* FCVTN, FCVTN2 */
10304 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
10306 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
10308 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
10309 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
10310 TCGv_ptr fpst
= get_fpstatus_ptr(false);
10311 TCGv_i32 ahp
= get_ahp_flag();
10313 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
10314 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, fpst
, ahp
);
10315 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, fpst
, ahp
);
10316 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
10317 tcg_temp_free_i32(tcg_lo
);
10318 tcg_temp_free_i32(tcg_hi
);
10319 tcg_temp_free_ptr(fpst
);
10320 tcg_temp_free_i32(ahp
);
10323 case 0x56: /* FCVTXN, FCVTXN2 */
10324 /* 64 bit to 32 bit float conversion
10325 * with von Neumann rounding (round to odd)
10328 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
10331 g_assert_not_reached();
10335 genfn(tcg_res
[pass
], tcg_op
);
10336 } else if (genenvfn
) {
10337 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
10340 tcg_temp_free_i64(tcg_op
);
10343 for (pass
= 0; pass
< 2; pass
++) {
10344 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
10345 tcg_temp_free_i32(tcg_res
[pass
]);
10347 clear_vec_high(s
, is_q
, rd
);
10350 /* Remaining saturating accumulating ops */
10351 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
10352 bool is_q
, int size
, int rn
, int rd
)
10354 bool is_double
= (size
== 3);
10357 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
10358 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
10361 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10362 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
10363 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
10365 if (is_u
) { /* USQADD */
10366 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10367 } else { /* SUQADD */
10368 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10370 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
10372 tcg_temp_free_i64(tcg_rd
);
10373 tcg_temp_free_i64(tcg_rn
);
10374 clear_vec_high(s
, !is_scalar
, rd
);
10376 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
10377 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
10378 int pass
, maxpasses
;
10383 maxpasses
= is_q
? 4 : 2;
10386 for (pass
= 0; pass
< maxpasses
; pass
++) {
10388 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
10389 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
10391 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
10392 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
10395 if (is_u
) { /* USQADD */
10398 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10401 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10404 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10407 g_assert_not_reached();
10409 } else { /* SUQADD */
10412 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10415 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10418 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10421 g_assert_not_reached();
10426 TCGv_i64 tcg_zero
= tcg_const_i64(0);
10427 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
10428 tcg_temp_free_i64(tcg_zero
);
10430 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
10432 tcg_temp_free_i32(tcg_rd
);
10433 tcg_temp_free_i32(tcg_rn
);
10434 clear_vec_high(s
, is_q
, rd
);
10438 /* AdvSIMD scalar two reg misc
10439 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
10440 * +-----+---+-----------+------+-----------+--------+-----+------+------+
10441 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
10442 * +-----+---+-----------+------+-----------+--------+-----+------+------+
10444 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
10446 int rd
= extract32(insn
, 0, 5);
10447 int rn
= extract32(insn
, 5, 5);
10448 int opcode
= extract32(insn
, 12, 5);
10449 int size
= extract32(insn
, 22, 2);
10450 bool u
= extract32(insn
, 29, 1);
10451 bool is_fcvt
= false;
10453 TCGv_i32 tcg_rmode
;
10454 TCGv_ptr tcg_fpstatus
;
10457 case 0x3: /* USQADD / SUQADD*/
10458 if (!fp_access_check(s
)) {
10461 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
10463 case 0x7: /* SQABS / SQNEG */
10465 case 0xa: /* CMLT */
10467 unallocated_encoding(s
);
10471 case 0x8: /* CMGT, CMGE */
10472 case 0x9: /* CMEQ, CMLE */
10473 case 0xb: /* ABS, NEG */
10475 unallocated_encoding(s
);
10479 case 0x12: /* SQXTUN */
10481 unallocated_encoding(s
);
10485 case 0x14: /* SQXTN, UQXTN */
10487 unallocated_encoding(s
);
10490 if (!fp_access_check(s
)) {
10493 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
10496 case 0x16 ... 0x1d:
10498 /* Floating point: U, size[1] and opcode indicate operation;
10499 * size[0] indicates single or double precision.
10501 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
10502 size
= extract32(size
, 0, 1) ? 3 : 2;
10504 case 0x2c: /* FCMGT (zero) */
10505 case 0x2d: /* FCMEQ (zero) */
10506 case 0x2e: /* FCMLT (zero) */
10507 case 0x6c: /* FCMGE (zero) */
10508 case 0x6d: /* FCMLE (zero) */
10509 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
10511 case 0x1d: /* SCVTF */
10512 case 0x5d: /* UCVTF */
10514 bool is_signed
= (opcode
== 0x1d);
10515 if (!fp_access_check(s
)) {
10518 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
10521 case 0x3d: /* FRECPE */
10522 case 0x3f: /* FRECPX */
10523 case 0x7d: /* FRSQRTE */
10524 if (!fp_access_check(s
)) {
10527 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
10529 case 0x1a: /* FCVTNS */
10530 case 0x1b: /* FCVTMS */
10531 case 0x3a: /* FCVTPS */
10532 case 0x3b: /* FCVTZS */
10533 case 0x5a: /* FCVTNU */
10534 case 0x5b: /* FCVTMU */
10535 case 0x7a: /* FCVTPU */
10536 case 0x7b: /* FCVTZU */
10538 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
10540 case 0x1c: /* FCVTAS */
10541 case 0x5c: /* FCVTAU */
10542 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
10544 rmode
= FPROUNDING_TIEAWAY
;
10546 case 0x56: /* FCVTXN, FCVTXN2 */
10548 unallocated_encoding(s
);
10551 if (!fp_access_check(s
)) {
10554 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
10557 unallocated_encoding(s
);
10562 unallocated_encoding(s
);
10566 if (!fp_access_check(s
)) {
10571 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
10572 tcg_fpstatus
= get_fpstatus_ptr(false);
10573 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
10576 tcg_fpstatus
= NULL
;
10580 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
10581 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
10583 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
10584 write_fp_dreg(s
, rd
, tcg_rd
);
10585 tcg_temp_free_i64(tcg_rd
);
10586 tcg_temp_free_i64(tcg_rn
);
10588 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
10589 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
10591 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
10594 case 0x7: /* SQABS, SQNEG */
10596 NeonGenOneOpEnvFn
*genfn
;
10597 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
10598 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
10599 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
10600 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
10602 genfn
= fns
[size
][u
];
10603 genfn(tcg_rd
, cpu_env
, tcg_rn
);
10606 case 0x1a: /* FCVTNS */
10607 case 0x1b: /* FCVTMS */
10608 case 0x1c: /* FCVTAS */
10609 case 0x3a: /* FCVTPS */
10610 case 0x3b: /* FCVTZS */
10612 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10613 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
10614 tcg_temp_free_i32(tcg_shift
);
10617 case 0x5a: /* FCVTNU */
10618 case 0x5b: /* FCVTMU */
10619 case 0x5c: /* FCVTAU */
10620 case 0x7a: /* FCVTPU */
10621 case 0x7b: /* FCVTZU */
10623 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10624 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
10625 tcg_temp_free_i32(tcg_shift
);
10629 g_assert_not_reached();
10632 write_fp_sreg(s
, rd
, tcg_rd
);
10633 tcg_temp_free_i32(tcg_rd
);
10634 tcg_temp_free_i32(tcg_rn
);
10638 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
10639 tcg_temp_free_i32(tcg_rmode
);
10640 tcg_temp_free_ptr(tcg_fpstatus
);
10644 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
10645 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
10646 int immh
, int immb
, int opcode
, int rn
, int rd
)
10648 int size
= 32 - clz32(immh
) - 1;
10649 int immhb
= immh
<< 3 | immb
;
10650 int shift
= 2 * (8 << size
) - immhb
;
10651 GVecGen2iFn
*gvec_fn
;
10653 if (extract32(immh
, 3, 1) && !is_q
) {
10654 unallocated_encoding(s
);
10657 tcg_debug_assert(size
<= 3);
10659 if (!fp_access_check(s
)) {
10664 case 0x02: /* SSRA / USRA (accumulate) */
10665 gvec_fn
= is_u
? gen_gvec_usra
: gen_gvec_ssra
;
10668 case 0x08: /* SRI */
10669 gvec_fn
= gen_gvec_sri
;
10672 case 0x00: /* SSHR / USHR */
10674 if (shift
== 8 << size
) {
10675 /* Shift count the same size as element size produces zero. */
10676 tcg_gen_gvec_dup_imm(size
, vec_full_reg_offset(s
, rd
),
10677 is_q
? 16 : 8, vec_full_reg_size(s
), 0);
10680 gvec_fn
= tcg_gen_gvec_shri
;
10682 /* Shift count the same size as element size produces all sign. */
10683 if (shift
== 8 << size
) {
10686 gvec_fn
= tcg_gen_gvec_sari
;
10690 case 0x04: /* SRSHR / URSHR (rounding) */
10691 gvec_fn
= is_u
? gen_gvec_urshr
: gen_gvec_srshr
;
10694 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10695 gvec_fn
= is_u
? gen_gvec_ursra
: gen_gvec_srsra
;
10699 g_assert_not_reached();
10702 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, gvec_fn
, size
);
10705 /* SHL/SLI - Vector shift left */
10706 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
10707 int immh
, int immb
, int opcode
, int rn
, int rd
)
10709 int size
= 32 - clz32(immh
) - 1;
10710 int immhb
= immh
<< 3 | immb
;
10711 int shift
= immhb
- (8 << size
);
10713 /* Range of size is limited by decode: immh is a non-zero 4 bit field */
10714 assert(size
>= 0 && size
<= 3);
10716 if (extract32(immh
, 3, 1) && !is_q
) {
10717 unallocated_encoding(s
);
10721 if (!fp_access_check(s
)) {
10726 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, gen_gvec_sli
, size
);
10728 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shli
, size
);
10732 /* USHLL/SHLL - Vector shift left with widening */
10733 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
10734 int immh
, int immb
, int opcode
, int rn
, int rd
)
10736 int size
= 32 - clz32(immh
) - 1;
10737 int immhb
= immh
<< 3 | immb
;
10738 int shift
= immhb
- (8 << size
);
10740 int esize
= 8 << size
;
10741 int elements
= dsize
/esize
;
10742 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
10743 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
10747 unallocated_encoding(s
);
10751 if (!fp_access_check(s
)) {
10755 /* For the LL variants the store is larger than the load,
10756 * so if rd == rn we would overwrite parts of our input.
10757 * So load everything right now and use shifts in the main loop.
10759 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
10761 for (i
= 0; i
< elements
; i
++) {
10762 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
10763 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
10764 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
10765 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
10769 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
10770 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
10771 int immh
, int immb
, int opcode
, int rn
, int rd
)
10773 int immhb
= immh
<< 3 | immb
;
10774 int size
= 32 - clz32(immh
) - 1;
10776 int esize
= 8 << size
;
10777 int elements
= dsize
/esize
;
10778 int shift
= (2 * esize
) - immhb
;
10779 bool round
= extract32(opcode
, 0, 1);
10780 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
10781 TCGv_i64 tcg_round
;
10784 if (extract32(immh
, 3, 1)) {
10785 unallocated_encoding(s
);
10789 if (!fp_access_check(s
)) {
10793 tcg_rn
= tcg_temp_new_i64();
10794 tcg_rd
= tcg_temp_new_i64();
10795 tcg_final
= tcg_temp_new_i64();
10796 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
10799 uint64_t round_const
= 1ULL << (shift
- 1);
10800 tcg_round
= tcg_const_i64(round_const
);
10805 for (i
= 0; i
< elements
; i
++) {
10806 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
10807 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
10808 false, true, size
+1, shift
);
10810 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
10814 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
10816 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
10819 tcg_temp_free_i64(tcg_round
);
10821 tcg_temp_free_i64(tcg_rn
);
10822 tcg_temp_free_i64(tcg_rd
);
10823 tcg_temp_free_i64(tcg_final
);
10825 clear_vec_high(s
, is_q
, rd
);
10829 /* AdvSIMD shift by immediate
10830 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
10831 * +---+---+---+-------------+------+------+--------+---+------+------+
10832 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
10833 * +---+---+---+-------------+------+------+--------+---+------+------+
10835 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
10837 int rd
= extract32(insn
, 0, 5);
10838 int rn
= extract32(insn
, 5, 5);
10839 int opcode
= extract32(insn
, 11, 5);
10840 int immb
= extract32(insn
, 16, 3);
10841 int immh
= extract32(insn
, 19, 4);
10842 bool is_u
= extract32(insn
, 29, 1);
10843 bool is_q
= extract32(insn
, 30, 1);
10845 /* data_proc_simd[] has sent immh == 0 to disas_simd_mod_imm. */
10849 case 0x08: /* SRI */
10851 unallocated_encoding(s
);
10855 case 0x00: /* SSHR / USHR */
10856 case 0x02: /* SSRA / USRA (accumulate) */
10857 case 0x04: /* SRSHR / URSHR (rounding) */
10858 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10859 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10861 case 0x0a: /* SHL / SLI */
10862 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10864 case 0x10: /* SHRN */
10865 case 0x11: /* RSHRN / SQRSHRUN */
10867 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
10870 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
10873 case 0x12: /* SQSHRN / UQSHRN */
10874 case 0x13: /* SQRSHRN / UQRSHRN */
10875 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
10878 case 0x14: /* SSHLL / USHLL */
10879 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10881 case 0x1c: /* SCVTF / UCVTF */
10882 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
10885 case 0xc: /* SQSHLU */
10887 unallocated_encoding(s
);
10890 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
10892 case 0xe: /* SQSHL, UQSHL */
10893 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
10895 case 0x1f: /* FCVTZS/ FCVTZU */
10896 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
10899 unallocated_encoding(s
);
10904 /* Generate code to do a "long" addition or subtraction, ie one done in
10905 * TCGv_i64 on vector lanes twice the width specified by size.
10907 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
10908 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
10910 static NeonGenTwo64OpFn
* const fns
[3][2] = {
10911 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
10912 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
10913 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
10915 NeonGenTwo64OpFn
*genfn
;
10918 genfn
= fns
[size
][is_sub
];
10919 genfn(tcg_res
, tcg_op1
, tcg_op2
);
10922 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
10923 int opcode
, int rd
, int rn
, int rm
)
10925 /* 3-reg-different widening insns: 64 x 64 -> 128 */
10926 TCGv_i64 tcg_res
[2];
10929 tcg_res
[0] = tcg_temp_new_i64();
10930 tcg_res
[1] = tcg_temp_new_i64();
10932 /* Does this op do an adding accumulate, a subtracting accumulate,
10933 * or no accumulate at all?
10951 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10952 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10955 /* size == 2 means two 32x32->64 operations; this is worth special
10956 * casing because we can generally handle it inline.
10959 for (pass
= 0; pass
< 2; pass
++) {
10960 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10961 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10962 TCGv_i64 tcg_passres
;
10963 MemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
10965 int elt
= pass
+ is_q
* 2;
10967 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
10968 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
10971 tcg_passres
= tcg_res
[pass
];
10973 tcg_passres
= tcg_temp_new_i64();
10977 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10978 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10980 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10981 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10983 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10984 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10986 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
10987 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
10989 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
10990 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
10991 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
10993 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
10994 tcg_temp_free_i64(tcg_tmp1
);
10995 tcg_temp_free_i64(tcg_tmp2
);
10998 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10999 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
11000 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
11001 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
11003 case 9: /* SQDMLAL, SQDMLAL2 */
11004 case 11: /* SQDMLSL, SQDMLSL2 */
11005 case 13: /* SQDMULL, SQDMULL2 */
11006 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
11007 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
11008 tcg_passres
, tcg_passres
);
11011 g_assert_not_reached();
11014 if (opcode
== 9 || opcode
== 11) {
11015 /* saturating accumulate ops */
11017 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
11019 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
11020 tcg_res
[pass
], tcg_passres
);
11021 } else if (accop
> 0) {
11022 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
11023 } else if (accop
< 0) {
11024 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
11028 tcg_temp_free_i64(tcg_passres
);
11031 tcg_temp_free_i64(tcg_op1
);
11032 tcg_temp_free_i64(tcg_op2
);
11035 /* size 0 or 1, generally helper functions */
11036 for (pass
= 0; pass
< 2; pass
++) {
11037 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11038 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11039 TCGv_i64 tcg_passres
;
11040 int elt
= pass
+ is_q
* 2;
11042 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
11043 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
11046 tcg_passres
= tcg_res
[pass
];
11048 tcg_passres
= tcg_temp_new_i64();
11052 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
11053 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
11055 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
11056 static NeonGenWidenFn
* const widenfns
[2][2] = {
11057 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
11058 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
11060 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
11062 widenfn(tcg_op2_64
, tcg_op2
);
11063 widenfn(tcg_passres
, tcg_op1
);
11064 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
11065 tcg_passres
, tcg_op2_64
);
11066 tcg_temp_free_i64(tcg_op2_64
);
11069 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
11070 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
11073 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
11075 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
11079 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
11081 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
11085 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
11086 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
11087 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
11090 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
11092 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
11096 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
11098 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
11102 case 9: /* SQDMLAL, SQDMLAL2 */
11103 case 11: /* SQDMLSL, SQDMLSL2 */
11104 case 13: /* SQDMULL, SQDMULL2 */
11106 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
11107 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
11108 tcg_passres
, tcg_passres
);
11111 g_assert_not_reached();
11113 tcg_temp_free_i32(tcg_op1
);
11114 tcg_temp_free_i32(tcg_op2
);
11117 if (opcode
== 9 || opcode
== 11) {
11118 /* saturating accumulate ops */
11120 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
11122 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
11126 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
11127 tcg_res
[pass
], tcg_passres
);
11129 tcg_temp_free_i64(tcg_passres
);
11134 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
11135 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
11136 tcg_temp_free_i64(tcg_res
[0]);
11137 tcg_temp_free_i64(tcg_res
[1]);
11140 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
11141 int opcode
, int rd
, int rn
, int rm
)
11143 TCGv_i64 tcg_res
[2];
11144 int part
= is_q
? 2 : 0;
11147 for (pass
= 0; pass
< 2; pass
++) {
11148 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11149 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11150 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
11151 static NeonGenWidenFn
* const widenfns
[3][2] = {
11152 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
11153 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
11154 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
11156 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
11158 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11159 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
11160 widenfn(tcg_op2_wide
, tcg_op2
);
11161 tcg_temp_free_i32(tcg_op2
);
11162 tcg_res
[pass
] = tcg_temp_new_i64();
11163 gen_neon_addl(size
, (opcode
== 3),
11164 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
11165 tcg_temp_free_i64(tcg_op1
);
11166 tcg_temp_free_i64(tcg_op2_wide
);
11169 for (pass
= 0; pass
< 2; pass
++) {
11170 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11171 tcg_temp_free_i64(tcg_res
[pass
]);
11175 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
11177 tcg_gen_addi_i64(in
, in
, 1U << 31);
11178 tcg_gen_extrh_i64_i32(res
, in
);
11181 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
11182 int opcode
, int rd
, int rn
, int rm
)
11184 TCGv_i32 tcg_res
[2];
11185 int part
= is_q
? 2 : 0;
11188 for (pass
= 0; pass
< 2; pass
++) {
11189 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11190 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11191 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
11192 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
11193 { gen_helper_neon_narrow_high_u8
,
11194 gen_helper_neon_narrow_round_high_u8
},
11195 { gen_helper_neon_narrow_high_u16
,
11196 gen_helper_neon_narrow_round_high_u16
},
11197 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
11199 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
11201 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11202 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
11204 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
11206 tcg_temp_free_i64(tcg_op1
);
11207 tcg_temp_free_i64(tcg_op2
);
11209 tcg_res
[pass
] = tcg_temp_new_i32();
11210 gennarrow(tcg_res
[pass
], tcg_wideres
);
11211 tcg_temp_free_i64(tcg_wideres
);
11214 for (pass
= 0; pass
< 2; pass
++) {
11215 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
11216 tcg_temp_free_i32(tcg_res
[pass
]);
11218 clear_vec_high(s
, is_q
, rd
);
11221 /* AdvSIMD three different
11222 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
11223 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
11224 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
11225 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
11227 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
11229 /* Instructions in this group fall into three basic classes
11230 * (in each case with the operation working on each element in
11231 * the input vectors):
11232 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
11234 * (2) wide 64 x 128 -> 128
11235 * (3) narrowing 128 x 128 -> 64
11236 * Here we do initial decode, catch unallocated cases and
11237 * dispatch to separate functions for each class.
11239 int is_q
= extract32(insn
, 30, 1);
11240 int is_u
= extract32(insn
, 29, 1);
11241 int size
= extract32(insn
, 22, 2);
11242 int opcode
= extract32(insn
, 12, 4);
11243 int rm
= extract32(insn
, 16, 5);
11244 int rn
= extract32(insn
, 5, 5);
11245 int rd
= extract32(insn
, 0, 5);
11248 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
11249 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
11250 /* 64 x 128 -> 128 */
11252 unallocated_encoding(s
);
11255 if (!fp_access_check(s
)) {
11258 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
11260 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
11261 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
11262 /* 128 x 128 -> 64 */
11264 unallocated_encoding(s
);
11267 if (!fp_access_check(s
)) {
11270 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
11272 case 14: /* PMULL, PMULL2 */
11274 unallocated_encoding(s
);
11278 case 0: /* PMULL.P8 */
11279 if (!fp_access_check(s
)) {
11282 /* The Q field specifies lo/hi half input for this insn. */
11283 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, is_q
,
11284 gen_helper_neon_pmull_h
);
11287 case 3: /* PMULL.P64 */
11288 if (!dc_isar_feature(aa64_pmull
, s
)) {
11289 unallocated_encoding(s
);
11292 if (!fp_access_check(s
)) {
11295 /* The Q field specifies lo/hi half input for this insn. */
11296 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, is_q
,
11297 gen_helper_gvec_pmull_q
);
11301 unallocated_encoding(s
);
11305 case 9: /* SQDMLAL, SQDMLAL2 */
11306 case 11: /* SQDMLSL, SQDMLSL2 */
11307 case 13: /* SQDMULL, SQDMULL2 */
11308 if (is_u
|| size
== 0) {
11309 unallocated_encoding(s
);
11313 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
11314 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
11315 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
11316 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
11317 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
11318 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
11319 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
11320 /* 64 x 64 -> 128 */
11322 unallocated_encoding(s
);
11325 if (!fp_access_check(s
)) {
11329 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
11332 /* opcode 15 not allocated */
11333 unallocated_encoding(s
);
11338 /* Logic op (opcode == 3) subgroup of C3.6.16. */
11339 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
11341 int rd
= extract32(insn
, 0, 5);
11342 int rn
= extract32(insn
, 5, 5);
11343 int rm
= extract32(insn
, 16, 5);
11344 int size
= extract32(insn
, 22, 2);
11345 bool is_u
= extract32(insn
, 29, 1);
11346 bool is_q
= extract32(insn
, 30, 1);
11348 if (!fp_access_check(s
)) {
11352 switch (size
+ 4 * is_u
) {
11354 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_and
, 0);
11357 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_andc
, 0);
11360 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_or
, 0);
11363 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_orc
, 0);
11366 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_xor
, 0);
11369 case 5: /* BSL bitwise select */
11370 gen_gvec_fn4(s
, is_q
, rd
, rd
, rn
, rm
, tcg_gen_gvec_bitsel
, 0);
11372 case 6: /* BIT, bitwise insert if true */
11373 gen_gvec_fn4(s
, is_q
, rd
, rm
, rn
, rd
, tcg_gen_gvec_bitsel
, 0);
11375 case 7: /* BIF, bitwise insert if false */
11376 gen_gvec_fn4(s
, is_q
, rd
, rm
, rd
, rn
, tcg_gen_gvec_bitsel
, 0);
11380 g_assert_not_reached();
11384 /* Pairwise op subgroup of C3.6.16.
11386 * This is called directly or via the handle_3same_float for float pairwise
11387 * operations where the opcode and size are calculated differently.
11389 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
11390 int size
, int rn
, int rm
, int rd
)
11395 /* Floating point operations need fpst */
11396 if (opcode
>= 0x58) {
11397 fpst
= get_fpstatus_ptr(false);
11402 if (!fp_access_check(s
)) {
11406 /* These operations work on the concatenated rm:rn, with each pair of
11407 * adjacent elements being operated on to produce an element in the result.
11410 TCGv_i64 tcg_res
[2];
11412 for (pass
= 0; pass
< 2; pass
++) {
11413 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11414 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11415 int passreg
= (pass
== 0) ? rn
: rm
;
11417 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
11418 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
11419 tcg_res
[pass
] = tcg_temp_new_i64();
11422 case 0x17: /* ADDP */
11423 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11425 case 0x58: /* FMAXNMP */
11426 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11428 case 0x5a: /* FADDP */
11429 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11431 case 0x5e: /* FMAXP */
11432 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11434 case 0x78: /* FMINNMP */
11435 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11437 case 0x7e: /* FMINP */
11438 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11441 g_assert_not_reached();
11444 tcg_temp_free_i64(tcg_op1
);
11445 tcg_temp_free_i64(tcg_op2
);
11448 for (pass
= 0; pass
< 2; pass
++) {
11449 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11450 tcg_temp_free_i64(tcg_res
[pass
]);
11453 int maxpass
= is_q
? 4 : 2;
11454 TCGv_i32 tcg_res
[4];
11456 for (pass
= 0; pass
< maxpass
; pass
++) {
11457 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11458 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11459 NeonGenTwoOpFn
*genfn
= NULL
;
11460 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
11461 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
11463 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
11464 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
11465 tcg_res
[pass
] = tcg_temp_new_i32();
11468 case 0x17: /* ADDP */
11470 static NeonGenTwoOpFn
* const fns
[3] = {
11471 gen_helper_neon_padd_u8
,
11472 gen_helper_neon_padd_u16
,
11478 case 0x14: /* SMAXP, UMAXP */
11480 static NeonGenTwoOpFn
* const fns
[3][2] = {
11481 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
11482 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
11483 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
11485 genfn
= fns
[size
][u
];
11488 case 0x15: /* SMINP, UMINP */
11490 static NeonGenTwoOpFn
* const fns
[3][2] = {
11491 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
11492 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
11493 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
11495 genfn
= fns
[size
][u
];
11498 /* The FP operations are all on single floats (32 bit) */
11499 case 0x58: /* FMAXNMP */
11500 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11502 case 0x5a: /* FADDP */
11503 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11505 case 0x5e: /* FMAXP */
11506 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11508 case 0x78: /* FMINNMP */
11509 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11511 case 0x7e: /* FMINP */
11512 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11515 g_assert_not_reached();
11518 /* FP ops called directly, otherwise call now */
11520 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11523 tcg_temp_free_i32(tcg_op1
);
11524 tcg_temp_free_i32(tcg_op2
);
11527 for (pass
= 0; pass
< maxpass
; pass
++) {
11528 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
11529 tcg_temp_free_i32(tcg_res
[pass
]);
11531 clear_vec_high(s
, is_q
, rd
);
11535 tcg_temp_free_ptr(fpst
);
11539 /* Floating point op subgroup of C3.6.16. */
11540 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
11542 /* For floating point ops, the U, size[1] and opcode bits
11543 * together indicate the operation. size[0] indicates single
11546 int fpopcode
= extract32(insn
, 11, 5)
11547 | (extract32(insn
, 23, 1) << 5)
11548 | (extract32(insn
, 29, 1) << 6);
11549 int is_q
= extract32(insn
, 30, 1);
11550 int size
= extract32(insn
, 22, 1);
11551 int rm
= extract32(insn
, 16, 5);
11552 int rn
= extract32(insn
, 5, 5);
11553 int rd
= extract32(insn
, 0, 5);
11555 int datasize
= is_q
? 128 : 64;
11556 int esize
= 32 << size
;
11557 int elements
= datasize
/ esize
;
11559 if (size
== 1 && !is_q
) {
11560 unallocated_encoding(s
);
11564 switch (fpopcode
) {
11565 case 0x58: /* FMAXNMP */
11566 case 0x5a: /* FADDP */
11567 case 0x5e: /* FMAXP */
11568 case 0x78: /* FMINNMP */
11569 case 0x7e: /* FMINP */
11570 if (size
&& !is_q
) {
11571 unallocated_encoding(s
);
11574 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
11577 case 0x1b: /* FMULX */
11578 case 0x1f: /* FRECPS */
11579 case 0x3f: /* FRSQRTS */
11580 case 0x5d: /* FACGE */
11581 case 0x7d: /* FACGT */
11582 case 0x19: /* FMLA */
11583 case 0x39: /* FMLS */
11584 case 0x18: /* FMAXNM */
11585 case 0x1a: /* FADD */
11586 case 0x1c: /* FCMEQ */
11587 case 0x1e: /* FMAX */
11588 case 0x38: /* FMINNM */
11589 case 0x3a: /* FSUB */
11590 case 0x3e: /* FMIN */
11591 case 0x5b: /* FMUL */
11592 case 0x5c: /* FCMGE */
11593 case 0x5f: /* FDIV */
11594 case 0x7a: /* FABD */
11595 case 0x7c: /* FCMGT */
11596 if (!fp_access_check(s
)) {
11599 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
11602 case 0x1d: /* FMLAL */
11603 case 0x3d: /* FMLSL */
11604 case 0x59: /* FMLAL2 */
11605 case 0x79: /* FMLSL2 */
11606 if (size
& 1 || !dc_isar_feature(aa64_fhm
, s
)) {
11607 unallocated_encoding(s
);
11610 if (fp_access_check(s
)) {
11611 int is_s
= extract32(insn
, 23, 1);
11612 int is_2
= extract32(insn
, 29, 1);
11613 int data
= (is_2
<< 1) | is_s
;
11614 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
11615 vec_full_reg_offset(s
, rn
),
11616 vec_full_reg_offset(s
, rm
), cpu_env
,
11617 is_q
? 16 : 8, vec_full_reg_size(s
),
11618 data
, gen_helper_gvec_fmlal_a64
);
11623 unallocated_encoding(s
);
11628 /* Integer op subgroup of C3.6.16. */
11629 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
11631 int is_q
= extract32(insn
, 30, 1);
11632 int u
= extract32(insn
, 29, 1);
11633 int size
= extract32(insn
, 22, 2);
11634 int opcode
= extract32(insn
, 11, 5);
11635 int rm
= extract32(insn
, 16, 5);
11636 int rn
= extract32(insn
, 5, 5);
11637 int rd
= extract32(insn
, 0, 5);
11642 case 0x13: /* MUL, PMUL */
11643 if (u
&& size
!= 0) {
11644 unallocated_encoding(s
);
11648 case 0x0: /* SHADD, UHADD */
11649 case 0x2: /* SRHADD, URHADD */
11650 case 0x4: /* SHSUB, UHSUB */
11651 case 0xc: /* SMAX, UMAX */
11652 case 0xd: /* SMIN, UMIN */
11653 case 0xe: /* SABD, UABD */
11654 case 0xf: /* SABA, UABA */
11655 case 0x12: /* MLA, MLS */
11657 unallocated_encoding(s
);
11661 case 0x16: /* SQDMULH, SQRDMULH */
11662 if (size
== 0 || size
== 3) {
11663 unallocated_encoding(s
);
11668 if (size
== 3 && !is_q
) {
11669 unallocated_encoding(s
);
11675 if (!fp_access_check(s
)) {
11680 case 0x01: /* SQADD, UQADD */
11682 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uqadd_qc
, size
);
11684 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqadd_qc
, size
);
11687 case 0x05: /* SQSUB, UQSUB */
11689 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uqsub_qc
, size
);
11691 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqsub_qc
, size
);
11694 case 0x08: /* SSHL, USHL */
11696 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_ushl
, size
);
11698 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sshl
, size
);
11701 case 0x0c: /* SMAX, UMAX */
11703 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umax
, size
);
11705 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smax
, size
);
11708 case 0x0d: /* SMIN, UMIN */
11710 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umin
, size
);
11712 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smin
, size
);
11715 case 0xe: /* SABD, UABD */
11717 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uabd
, size
);
11719 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sabd
, size
);
11722 case 0xf: /* SABA, UABA */
11724 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uaba
, size
);
11726 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_saba
, size
);
11729 case 0x10: /* ADD, SUB */
11731 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_sub
, size
);
11733 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_add
, size
);
11736 case 0x13: /* MUL, PMUL */
11737 if (!u
) { /* MUL */
11738 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_mul
, size
);
11739 } else { /* PMUL */
11740 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, 0, gen_helper_gvec_pmul_b
);
11743 case 0x12: /* MLA, MLS */
11745 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_mls
, size
);
11747 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_mla
, size
);
11751 if (!u
) { /* CMTST */
11752 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_cmtst
, size
);
11756 cond
= TCG_COND_EQ
;
11758 case 0x06: /* CMGT, CMHI */
11759 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
11761 case 0x07: /* CMGE, CMHS */
11762 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
11764 tcg_gen_gvec_cmp(cond
, size
, vec_full_reg_offset(s
, rd
),
11765 vec_full_reg_offset(s
, rn
),
11766 vec_full_reg_offset(s
, rm
),
11767 is_q
? 16 : 8, vec_full_reg_size(s
));
11773 for (pass
= 0; pass
< 2; pass
++) {
11774 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11775 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11776 TCGv_i64 tcg_res
= tcg_temp_new_i64();
11778 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11779 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
11781 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
11783 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
11785 tcg_temp_free_i64(tcg_res
);
11786 tcg_temp_free_i64(tcg_op1
);
11787 tcg_temp_free_i64(tcg_op2
);
11790 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
11791 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11792 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11793 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11794 NeonGenTwoOpFn
*genfn
= NULL
;
11795 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
11797 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
11798 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
11801 case 0x0: /* SHADD, UHADD */
11803 static NeonGenTwoOpFn
* const fns
[3][2] = {
11804 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
11805 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
11806 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
11808 genfn
= fns
[size
][u
];
11811 case 0x2: /* SRHADD, URHADD */
11813 static NeonGenTwoOpFn
* const fns
[3][2] = {
11814 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
11815 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
11816 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
11818 genfn
= fns
[size
][u
];
11821 case 0x4: /* SHSUB, UHSUB */
11823 static NeonGenTwoOpFn
* const fns
[3][2] = {
11824 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
11825 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
11826 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
11828 genfn
= fns
[size
][u
];
11831 case 0x9: /* SQSHL, UQSHL */
11833 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11834 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
11835 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
11836 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
11838 genenvfn
= fns
[size
][u
];
11841 case 0xa: /* SRSHL, URSHL */
11843 static NeonGenTwoOpFn
* const fns
[3][2] = {
11844 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
11845 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
11846 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
11848 genfn
= fns
[size
][u
];
11851 case 0xb: /* SQRSHL, UQRSHL */
11853 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11854 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
11855 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
11856 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
11858 genenvfn
= fns
[size
][u
];
11861 case 0x16: /* SQDMULH, SQRDMULH */
11863 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
11864 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
11865 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
11867 assert(size
== 1 || size
== 2);
11868 genenvfn
= fns
[size
- 1][u
];
11872 g_assert_not_reached();
11876 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
11878 genfn(tcg_res
, tcg_op1
, tcg_op2
);
11881 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
11883 tcg_temp_free_i32(tcg_res
);
11884 tcg_temp_free_i32(tcg_op1
);
11885 tcg_temp_free_i32(tcg_op2
);
11888 clear_vec_high(s
, is_q
, rd
);
11891 /* AdvSIMD three same
11892 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11893 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11894 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11895 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11897 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
11899 int opcode
= extract32(insn
, 11, 5);
11902 case 0x3: /* logic ops */
11903 disas_simd_3same_logic(s
, insn
);
11905 case 0x17: /* ADDP */
11906 case 0x14: /* SMAXP, UMAXP */
11907 case 0x15: /* SMINP, UMINP */
11909 /* Pairwise operations */
11910 int is_q
= extract32(insn
, 30, 1);
11911 int u
= extract32(insn
, 29, 1);
11912 int size
= extract32(insn
, 22, 2);
11913 int rm
= extract32(insn
, 16, 5);
11914 int rn
= extract32(insn
, 5, 5);
11915 int rd
= extract32(insn
, 0, 5);
11916 if (opcode
== 0x17) {
11917 if (u
|| (size
== 3 && !is_q
)) {
11918 unallocated_encoding(s
);
11923 unallocated_encoding(s
);
11927 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
11930 case 0x18 ... 0x31:
11931 /* floating point ops, sz[1] and U are part of opcode */
11932 disas_simd_3same_float(s
, insn
);
11935 disas_simd_3same_int(s
, insn
);
11941 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11943 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11944 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11945 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11946 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11948 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11949 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11952 static void disas_simd_three_reg_same_fp16(DisasContext
*s
, uint32_t insn
)
11954 int opcode
, fpopcode
;
11955 int is_q
, u
, a
, rm
, rn
, rd
;
11956 int datasize
, elements
;
11959 bool pairwise
= false;
11961 if (!dc_isar_feature(aa64_fp16
, s
)) {
11962 unallocated_encoding(s
);
11966 if (!fp_access_check(s
)) {
11970 /* For these floating point ops, the U, a and opcode bits
11971 * together indicate the operation.
11973 opcode
= extract32(insn
, 11, 3);
11974 u
= extract32(insn
, 29, 1);
11975 a
= extract32(insn
, 23, 1);
11976 is_q
= extract32(insn
, 30, 1);
11977 rm
= extract32(insn
, 16, 5);
11978 rn
= extract32(insn
, 5, 5);
11979 rd
= extract32(insn
, 0, 5);
11981 fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
11982 datasize
= is_q
? 128 : 64;
11983 elements
= datasize
/ 16;
11985 switch (fpopcode
) {
11986 case 0x10: /* FMAXNMP */
11987 case 0x12: /* FADDP */
11988 case 0x16: /* FMAXP */
11989 case 0x18: /* FMINNMP */
11990 case 0x1e: /* FMINP */
11995 fpst
= get_fpstatus_ptr(true);
11998 int maxpass
= is_q
? 8 : 4;
11999 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
12000 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
12001 TCGv_i32 tcg_res
[8];
12003 for (pass
= 0; pass
< maxpass
; pass
++) {
12004 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
12005 int passelt
= (pass
<< 1) & (maxpass
- 1);
12007 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_16
);
12008 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_16
);
12009 tcg_res
[pass
] = tcg_temp_new_i32();
12011 switch (fpopcode
) {
12012 case 0x10: /* FMAXNMP */
12013 gen_helper_advsimd_maxnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
12016 case 0x12: /* FADDP */
12017 gen_helper_advsimd_addh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
12019 case 0x16: /* FMAXP */
12020 gen_helper_advsimd_maxh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
12022 case 0x18: /* FMINNMP */
12023 gen_helper_advsimd_minnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
12026 case 0x1e: /* FMINP */
12027 gen_helper_advsimd_minh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
12030 g_assert_not_reached();
12034 for (pass
= 0; pass
< maxpass
; pass
++) {
12035 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_16
);
12036 tcg_temp_free_i32(tcg_res
[pass
]);
12039 tcg_temp_free_i32(tcg_op1
);
12040 tcg_temp_free_i32(tcg_op2
);
12043 for (pass
= 0; pass
< elements
; pass
++) {
12044 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
12045 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
12046 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12048 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_16
);
12049 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_16
);
12051 switch (fpopcode
) {
12052 case 0x0: /* FMAXNM */
12053 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12055 case 0x1: /* FMLA */
12056 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12057 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
12060 case 0x2: /* FADD */
12061 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12063 case 0x3: /* FMULX */
12064 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12066 case 0x4: /* FCMEQ */
12067 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12069 case 0x6: /* FMAX */
12070 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12072 case 0x7: /* FRECPS */
12073 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12075 case 0x8: /* FMINNM */
12076 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12078 case 0x9: /* FMLS */
12079 /* As usual for ARM, separate negation for fused multiply-add */
12080 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
12081 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12082 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
12085 case 0xa: /* FSUB */
12086 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12088 case 0xe: /* FMIN */
12089 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12091 case 0xf: /* FRSQRTS */
12092 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12094 case 0x13: /* FMUL */
12095 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12097 case 0x14: /* FCMGE */
12098 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12100 case 0x15: /* FACGE */
12101 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12103 case 0x17: /* FDIV */
12104 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12106 case 0x1a: /* FABD */
12107 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12108 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
12110 case 0x1c: /* FCMGT */
12111 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12113 case 0x1d: /* FACGT */
12114 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12117 fprintf(stderr
, "%s: insn %#04x, fpop %#2x @ %#" PRIx64
"\n",
12118 __func__
, insn
, fpopcode
, s
->pc_curr
);
12119 g_assert_not_reached();
12122 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12123 tcg_temp_free_i32(tcg_res
);
12124 tcg_temp_free_i32(tcg_op1
);
12125 tcg_temp_free_i32(tcg_op2
);
12129 tcg_temp_free_ptr(fpst
);
12131 clear_vec_high(s
, is_q
, rd
);
12134 /* AdvSIMD three same extra
12135 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
12136 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
12137 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
12138 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
12140 static void disas_simd_three_reg_same_extra(DisasContext
*s
, uint32_t insn
)
12142 int rd
= extract32(insn
, 0, 5);
12143 int rn
= extract32(insn
, 5, 5);
12144 int opcode
= extract32(insn
, 11, 4);
12145 int rm
= extract32(insn
, 16, 5);
12146 int size
= extract32(insn
, 22, 2);
12147 bool u
= extract32(insn
, 29, 1);
12148 bool is_q
= extract32(insn
, 30, 1);
12152 switch (u
* 16 + opcode
) {
12153 case 0x10: /* SQRDMLAH (vector) */
12154 case 0x11: /* SQRDMLSH (vector) */
12155 if (size
!= 1 && size
!= 2) {
12156 unallocated_encoding(s
);
12159 feature
= dc_isar_feature(aa64_rdm
, s
);
12161 case 0x02: /* SDOT (vector) */
12162 case 0x12: /* UDOT (vector) */
12163 if (size
!= MO_32
) {
12164 unallocated_encoding(s
);
12167 feature
= dc_isar_feature(aa64_dp
, s
);
12169 case 0x18: /* FCMLA, #0 */
12170 case 0x19: /* FCMLA, #90 */
12171 case 0x1a: /* FCMLA, #180 */
12172 case 0x1b: /* FCMLA, #270 */
12173 case 0x1c: /* FCADD, #90 */
12174 case 0x1e: /* FCADD, #270 */
12176 || (size
== 1 && !dc_isar_feature(aa64_fp16
, s
))
12177 || (size
== 3 && !is_q
)) {
12178 unallocated_encoding(s
);
12181 feature
= dc_isar_feature(aa64_fcma
, s
);
12184 unallocated_encoding(s
);
12188 unallocated_encoding(s
);
12191 if (!fp_access_check(s
)) {
12196 case 0x0: /* SQRDMLAH (vector) */
12197 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqrdmlah_qc
, size
);
12200 case 0x1: /* SQRDMLSH (vector) */
12201 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqrdmlsh_qc
, size
);
12204 case 0x2: /* SDOT / UDOT */
12205 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, 0,
12206 u
? gen_helper_gvec_udot_b
: gen_helper_gvec_sdot_b
);
12209 case 0x8: /* FCMLA, #0 */
12210 case 0x9: /* FCMLA, #90 */
12211 case 0xa: /* FCMLA, #180 */
12212 case 0xb: /* FCMLA, #270 */
12213 rot
= extract32(opcode
, 0, 2);
12216 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, true, rot
,
12217 gen_helper_gvec_fcmlah
);
12220 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
12221 gen_helper_gvec_fcmlas
);
12224 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
12225 gen_helper_gvec_fcmlad
);
12228 g_assert_not_reached();
12232 case 0xc: /* FCADD, #90 */
12233 case 0xe: /* FCADD, #270 */
12234 rot
= extract32(opcode
, 1, 1);
12237 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
12238 gen_helper_gvec_fcaddh
);
12241 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
12242 gen_helper_gvec_fcadds
);
12245 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
12246 gen_helper_gvec_fcaddd
);
12249 g_assert_not_reached();
12254 g_assert_not_reached();
12258 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
12259 int size
, int rn
, int rd
)
12261 /* Handle 2-reg-misc ops which are widening (so each size element
12262 * in the source becomes a 2*size element in the destination.
12263 * The only instruction like this is FCVTL.
12268 /* 32 -> 64 bit fp conversion */
12269 TCGv_i64 tcg_res
[2];
12270 int srcelt
= is_q
? 2 : 0;
12272 for (pass
= 0; pass
< 2; pass
++) {
12273 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12274 tcg_res
[pass
] = tcg_temp_new_i64();
12276 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
12277 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
12278 tcg_temp_free_i32(tcg_op
);
12280 for (pass
= 0; pass
< 2; pass
++) {
12281 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
12282 tcg_temp_free_i64(tcg_res
[pass
]);
12285 /* 16 -> 32 bit fp conversion */
12286 int srcelt
= is_q
? 4 : 0;
12287 TCGv_i32 tcg_res
[4];
12288 TCGv_ptr fpst
= get_fpstatus_ptr(false);
12289 TCGv_i32 ahp
= get_ahp_flag();
12291 for (pass
= 0; pass
< 4; pass
++) {
12292 tcg_res
[pass
] = tcg_temp_new_i32();
12294 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
12295 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
12298 for (pass
= 0; pass
< 4; pass
++) {
12299 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
12300 tcg_temp_free_i32(tcg_res
[pass
]);
12303 tcg_temp_free_ptr(fpst
);
12304 tcg_temp_free_i32(ahp
);
12308 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
12309 bool is_q
, int size
, int rn
, int rd
)
12311 int op
= (opcode
<< 1) | u
;
12312 int opsz
= op
+ size
;
12313 int grp_size
= 3 - opsz
;
12314 int dsize
= is_q
? 128 : 64;
12318 unallocated_encoding(s
);
12322 if (!fp_access_check(s
)) {
12327 /* Special case bytes, use bswap op on each group of elements */
12328 int groups
= dsize
/ (8 << grp_size
);
12330 for (i
= 0; i
< groups
; i
++) {
12331 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
12333 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
12334 switch (grp_size
) {
12336 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
12339 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
12342 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
12345 g_assert_not_reached();
12347 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
12348 tcg_temp_free_i64(tcg_tmp
);
12350 clear_vec_high(s
, is_q
, rd
);
12352 int revmask
= (1 << grp_size
) - 1;
12353 int esize
= 8 << size
;
12354 int elements
= dsize
/ esize
;
12355 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
12356 TCGv_i64 tcg_rd
= tcg_const_i64(0);
12357 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
12359 for (i
= 0; i
< elements
; i
++) {
12360 int e_rev
= (i
& 0xf) ^ revmask
;
12361 int off
= e_rev
* esize
;
12362 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
12364 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
12365 tcg_rn
, off
- 64, esize
);
12367 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
12370 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
12371 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
12373 tcg_temp_free_i64(tcg_rd_hi
);
12374 tcg_temp_free_i64(tcg_rd
);
12375 tcg_temp_free_i64(tcg_rn
);
12379 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
12380 bool is_q
, int size
, int rn
, int rd
)
12382 /* Implement the pairwise operations from 2-misc:
12383 * SADDLP, UADDLP, SADALP, UADALP.
12384 * These all add pairs of elements in the input to produce a
12385 * double-width result element in the output (possibly accumulating).
12387 bool accum
= (opcode
== 0x6);
12388 int maxpass
= is_q
? 2 : 1;
12390 TCGv_i64 tcg_res
[2];
12393 /* 32 + 32 -> 64 op */
12394 MemOp memop
= size
+ (u
? 0 : MO_SIGN
);
12396 for (pass
= 0; pass
< maxpass
; pass
++) {
12397 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
12398 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
12400 tcg_res
[pass
] = tcg_temp_new_i64();
12402 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
12403 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
12404 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
12406 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
12407 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
12410 tcg_temp_free_i64(tcg_op1
);
12411 tcg_temp_free_i64(tcg_op2
);
12414 for (pass
= 0; pass
< maxpass
; pass
++) {
12415 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12416 NeonGenOne64OpFn
*genfn
;
12417 static NeonGenOne64OpFn
* const fns
[2][2] = {
12418 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
12419 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
12422 genfn
= fns
[size
][u
];
12424 tcg_res
[pass
] = tcg_temp_new_i64();
12426 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12427 genfn(tcg_res
[pass
], tcg_op
);
12430 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
12432 gen_helper_neon_addl_u16(tcg_res
[pass
],
12433 tcg_res
[pass
], tcg_op
);
12435 gen_helper_neon_addl_u32(tcg_res
[pass
],
12436 tcg_res
[pass
], tcg_op
);
12439 tcg_temp_free_i64(tcg_op
);
12443 tcg_res
[1] = tcg_const_i64(0);
12445 for (pass
= 0; pass
< 2; pass
++) {
12446 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
12447 tcg_temp_free_i64(tcg_res
[pass
]);
12451 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
12453 /* Implement SHLL and SHLL2 */
12455 int part
= is_q
? 2 : 0;
12456 TCGv_i64 tcg_res
[2];
12458 for (pass
= 0; pass
< 2; pass
++) {
12459 static NeonGenWidenFn
* const widenfns
[3] = {
12460 gen_helper_neon_widen_u8
,
12461 gen_helper_neon_widen_u16
,
12462 tcg_gen_extu_i32_i64
,
12464 NeonGenWidenFn
*widenfn
= widenfns
[size
];
12465 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12467 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
12468 tcg_res
[pass
] = tcg_temp_new_i64();
12469 widenfn(tcg_res
[pass
], tcg_op
);
12470 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
12472 tcg_temp_free_i32(tcg_op
);
12475 for (pass
= 0; pass
< 2; pass
++) {
12476 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
12477 tcg_temp_free_i64(tcg_res
[pass
]);
12481 /* AdvSIMD two reg misc
12482 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
12483 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
12484 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
12485 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
12487 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
12489 int size
= extract32(insn
, 22, 2);
12490 int opcode
= extract32(insn
, 12, 5);
12491 bool u
= extract32(insn
, 29, 1);
12492 bool is_q
= extract32(insn
, 30, 1);
12493 int rn
= extract32(insn
, 5, 5);
12494 int rd
= extract32(insn
, 0, 5);
12495 bool need_fpstatus
= false;
12496 bool need_rmode
= false;
12498 TCGv_i32 tcg_rmode
;
12499 TCGv_ptr tcg_fpstatus
;
12502 case 0x0: /* REV64, REV32 */
12503 case 0x1: /* REV16 */
12504 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
12506 case 0x5: /* CNT, NOT, RBIT */
12507 if (u
&& size
== 0) {
12510 } else if (u
&& size
== 1) {
12513 } else if (!u
&& size
== 0) {
12517 unallocated_encoding(s
);
12519 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
12520 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
12522 unallocated_encoding(s
);
12525 if (!fp_access_check(s
)) {
12529 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
12531 case 0x4: /* CLS, CLZ */
12533 unallocated_encoding(s
);
12537 case 0x2: /* SADDLP, UADDLP */
12538 case 0x6: /* SADALP, UADALP */
12540 unallocated_encoding(s
);
12543 if (!fp_access_check(s
)) {
12546 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
12548 case 0x13: /* SHLL, SHLL2 */
12549 if (u
== 0 || size
== 3) {
12550 unallocated_encoding(s
);
12553 if (!fp_access_check(s
)) {
12556 handle_shll(s
, is_q
, size
, rn
, rd
);
12558 case 0xa: /* CMLT */
12560 unallocated_encoding(s
);
12564 case 0x8: /* CMGT, CMGE */
12565 case 0x9: /* CMEQ, CMLE */
12566 case 0xb: /* ABS, NEG */
12567 if (size
== 3 && !is_q
) {
12568 unallocated_encoding(s
);
12572 case 0x3: /* SUQADD, USQADD */
12573 if (size
== 3 && !is_q
) {
12574 unallocated_encoding(s
);
12577 if (!fp_access_check(s
)) {
12580 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
12582 case 0x7: /* SQABS, SQNEG */
12583 if (size
== 3 && !is_q
) {
12584 unallocated_encoding(s
);
12589 case 0x16 ... 0x1f:
12591 /* Floating point: U, size[1] and opcode indicate operation;
12592 * size[0] indicates single or double precision.
12594 int is_double
= extract32(size
, 0, 1);
12595 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
12596 size
= is_double
? 3 : 2;
12598 case 0x2f: /* FABS */
12599 case 0x6f: /* FNEG */
12600 if (size
== 3 && !is_q
) {
12601 unallocated_encoding(s
);
12605 case 0x1d: /* SCVTF */
12606 case 0x5d: /* UCVTF */
12608 bool is_signed
= (opcode
== 0x1d) ? true : false;
12609 int elements
= is_double
? 2 : is_q
? 4 : 2;
12610 if (is_double
&& !is_q
) {
12611 unallocated_encoding(s
);
12614 if (!fp_access_check(s
)) {
12617 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
12620 case 0x2c: /* FCMGT (zero) */
12621 case 0x2d: /* FCMEQ (zero) */
12622 case 0x2e: /* FCMLT (zero) */
12623 case 0x6c: /* FCMGE (zero) */
12624 case 0x6d: /* FCMLE (zero) */
12625 if (size
== 3 && !is_q
) {
12626 unallocated_encoding(s
);
12629 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
12631 case 0x7f: /* FSQRT */
12632 if (size
== 3 && !is_q
) {
12633 unallocated_encoding(s
);
12637 case 0x1a: /* FCVTNS */
12638 case 0x1b: /* FCVTMS */
12639 case 0x3a: /* FCVTPS */
12640 case 0x3b: /* FCVTZS */
12641 case 0x5a: /* FCVTNU */
12642 case 0x5b: /* FCVTMU */
12643 case 0x7a: /* FCVTPU */
12644 case 0x7b: /* FCVTZU */
12645 need_fpstatus
= true;
12647 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12648 if (size
== 3 && !is_q
) {
12649 unallocated_encoding(s
);
12653 case 0x5c: /* FCVTAU */
12654 case 0x1c: /* FCVTAS */
12655 need_fpstatus
= true;
12657 rmode
= FPROUNDING_TIEAWAY
;
12658 if (size
== 3 && !is_q
) {
12659 unallocated_encoding(s
);
12663 case 0x3c: /* URECPE */
12665 unallocated_encoding(s
);
12669 case 0x3d: /* FRECPE */
12670 case 0x7d: /* FRSQRTE */
12671 if (size
== 3 && !is_q
) {
12672 unallocated_encoding(s
);
12675 if (!fp_access_check(s
)) {
12678 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
12680 case 0x56: /* FCVTXN, FCVTXN2 */
12682 unallocated_encoding(s
);
12686 case 0x16: /* FCVTN, FCVTN2 */
12687 /* handle_2misc_narrow does a 2*size -> size operation, but these
12688 * instructions encode the source size rather than dest size.
12690 if (!fp_access_check(s
)) {
12693 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
12695 case 0x17: /* FCVTL, FCVTL2 */
12696 if (!fp_access_check(s
)) {
12699 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
12701 case 0x18: /* FRINTN */
12702 case 0x19: /* FRINTM */
12703 case 0x38: /* FRINTP */
12704 case 0x39: /* FRINTZ */
12706 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12708 case 0x59: /* FRINTX */
12709 case 0x79: /* FRINTI */
12710 need_fpstatus
= true;
12711 if (size
== 3 && !is_q
) {
12712 unallocated_encoding(s
);
12716 case 0x58: /* FRINTA */
12718 rmode
= FPROUNDING_TIEAWAY
;
12719 need_fpstatus
= true;
12720 if (size
== 3 && !is_q
) {
12721 unallocated_encoding(s
);
12725 case 0x7c: /* URSQRTE */
12727 unallocated_encoding(s
);
12731 case 0x1e: /* FRINT32Z */
12732 case 0x1f: /* FRINT64Z */
12734 rmode
= FPROUNDING_ZERO
;
12736 case 0x5e: /* FRINT32X */
12737 case 0x5f: /* FRINT64X */
12738 need_fpstatus
= true;
12739 if ((size
== 3 && !is_q
) || !dc_isar_feature(aa64_frint
, s
)) {
12740 unallocated_encoding(s
);
12745 unallocated_encoding(s
);
12751 unallocated_encoding(s
);
12755 if (!fp_access_check(s
)) {
12759 if (need_fpstatus
|| need_rmode
) {
12760 tcg_fpstatus
= get_fpstatus_ptr(false);
12762 tcg_fpstatus
= NULL
;
12765 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12766 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12773 if (u
&& size
== 0) { /* NOT */
12774 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_not
, 0);
12778 case 0x8: /* CMGT, CMGE */
12780 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_cge0
, size
);
12782 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_cgt0
, size
);
12785 case 0x9: /* CMEQ, CMLE */
12787 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_cle0
, size
);
12789 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_ceq0
, size
);
12792 case 0xa: /* CMLT */
12793 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_clt0
, size
);
12796 if (u
) { /* ABS, NEG */
12797 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_neg
, size
);
12799 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_abs
, size
);
12805 /* All 64-bit element operations can be shared with scalar 2misc */
12808 /* Coverity claims (size == 3 && !is_q) has been eliminated
12809 * from all paths leading to here.
12811 tcg_debug_assert(is_q
);
12812 for (pass
= 0; pass
< 2; pass
++) {
12813 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12814 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12816 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12818 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
12819 tcg_rmode
, tcg_fpstatus
);
12821 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12823 tcg_temp_free_i64(tcg_res
);
12824 tcg_temp_free_i64(tcg_op
);
12829 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
12830 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12831 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12833 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
12836 /* Special cases for 32 bit elements */
12838 case 0x4: /* CLS */
12840 tcg_gen_clzi_i32(tcg_res
, tcg_op
, 32);
12842 tcg_gen_clrsb_i32(tcg_res
, tcg_op
);
12845 case 0x7: /* SQABS, SQNEG */
12847 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
12849 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
12852 case 0x2f: /* FABS */
12853 gen_helper_vfp_abss(tcg_res
, tcg_op
);
12855 case 0x6f: /* FNEG */
12856 gen_helper_vfp_negs(tcg_res
, tcg_op
);
12858 case 0x7f: /* FSQRT */
12859 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
12861 case 0x1a: /* FCVTNS */
12862 case 0x1b: /* FCVTMS */
12863 case 0x1c: /* FCVTAS */
12864 case 0x3a: /* FCVTPS */
12865 case 0x3b: /* FCVTZS */
12867 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12868 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
12869 tcg_shift
, tcg_fpstatus
);
12870 tcg_temp_free_i32(tcg_shift
);
12873 case 0x5a: /* FCVTNU */
12874 case 0x5b: /* FCVTMU */
12875 case 0x5c: /* FCVTAU */
12876 case 0x7a: /* FCVTPU */
12877 case 0x7b: /* FCVTZU */
12879 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12880 gen_helper_vfp_touls(tcg_res
, tcg_op
,
12881 tcg_shift
, tcg_fpstatus
);
12882 tcg_temp_free_i32(tcg_shift
);
12885 case 0x18: /* FRINTN */
12886 case 0x19: /* FRINTM */
12887 case 0x38: /* FRINTP */
12888 case 0x39: /* FRINTZ */
12889 case 0x58: /* FRINTA */
12890 case 0x79: /* FRINTI */
12891 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
12893 case 0x59: /* FRINTX */
12894 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12896 case 0x7c: /* URSQRTE */
12897 gen_helper_rsqrte_u32(tcg_res
, tcg_op
);
12899 case 0x1e: /* FRINT32Z */
12900 case 0x5e: /* FRINT32X */
12901 gen_helper_frint32_s(tcg_res
, tcg_op
, tcg_fpstatus
);
12903 case 0x1f: /* FRINT64Z */
12904 case 0x5f: /* FRINT64X */
12905 gen_helper_frint64_s(tcg_res
, tcg_op
, tcg_fpstatus
);
12908 g_assert_not_reached();
12911 /* Use helpers for 8 and 16 bit elements */
12913 case 0x5: /* CNT, RBIT */
12914 /* For these two insns size is part of the opcode specifier
12915 * (handled earlier); they always operate on byte elements.
12918 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
12920 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
12923 case 0x7: /* SQABS, SQNEG */
12925 NeonGenOneOpEnvFn
*genfn
;
12926 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
12927 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
12928 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
12930 genfn
= fns
[size
][u
];
12931 genfn(tcg_res
, cpu_env
, tcg_op
);
12934 case 0x4: /* CLS, CLZ */
12937 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
12939 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
12943 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
12945 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
12950 g_assert_not_reached();
12954 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
12956 tcg_temp_free_i32(tcg_res
);
12957 tcg_temp_free_i32(tcg_op
);
12960 clear_vec_high(s
, is_q
, rd
);
12963 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12964 tcg_temp_free_i32(tcg_rmode
);
12966 if (need_fpstatus
) {
12967 tcg_temp_free_ptr(tcg_fpstatus
);
12971 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12973 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12974 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12975 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12976 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12977 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12978 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12980 * This actually covers two groups where scalar access is governed by
12981 * bit 28. A bunch of the instructions (float to integral) only exist
12982 * in the vector form and are un-allocated for the scalar decode. Also
12983 * in the scalar decode Q is always 1.
12985 static void disas_simd_two_reg_misc_fp16(DisasContext
*s
, uint32_t insn
)
12987 int fpop
, opcode
, a
, u
;
12991 bool only_in_vector
= false;
12994 TCGv_i32 tcg_rmode
= NULL
;
12995 TCGv_ptr tcg_fpstatus
= NULL
;
12996 bool need_rmode
= false;
12997 bool need_fpst
= true;
13000 if (!dc_isar_feature(aa64_fp16
, s
)) {
13001 unallocated_encoding(s
);
13005 rd
= extract32(insn
, 0, 5);
13006 rn
= extract32(insn
, 5, 5);
13008 a
= extract32(insn
, 23, 1);
13009 u
= extract32(insn
, 29, 1);
13010 is_scalar
= extract32(insn
, 28, 1);
13011 is_q
= extract32(insn
, 30, 1);
13013 opcode
= extract32(insn
, 12, 5);
13014 fpop
= deposit32(opcode
, 5, 1, a
);
13015 fpop
= deposit32(fpop
, 6, 1, u
);
13017 rd
= extract32(insn
, 0, 5);
13018 rn
= extract32(insn
, 5, 5);
13021 case 0x1d: /* SCVTF */
13022 case 0x5d: /* UCVTF */
13029 elements
= (is_q
? 8 : 4);
13032 if (!fp_access_check(s
)) {
13035 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !u
, 0, MO_16
);
13039 case 0x2c: /* FCMGT (zero) */
13040 case 0x2d: /* FCMEQ (zero) */
13041 case 0x2e: /* FCMLT (zero) */
13042 case 0x6c: /* FCMGE (zero) */
13043 case 0x6d: /* FCMLE (zero) */
13044 handle_2misc_fcmp_zero(s
, fpop
, is_scalar
, 0, is_q
, MO_16
, rn
, rd
);
13046 case 0x3d: /* FRECPE */
13047 case 0x3f: /* FRECPX */
13049 case 0x18: /* FRINTN */
13051 only_in_vector
= true;
13052 rmode
= FPROUNDING_TIEEVEN
;
13054 case 0x19: /* FRINTM */
13056 only_in_vector
= true;
13057 rmode
= FPROUNDING_NEGINF
;
13059 case 0x38: /* FRINTP */
13061 only_in_vector
= true;
13062 rmode
= FPROUNDING_POSINF
;
13064 case 0x39: /* FRINTZ */
13066 only_in_vector
= true;
13067 rmode
= FPROUNDING_ZERO
;
13069 case 0x58: /* FRINTA */
13071 only_in_vector
= true;
13072 rmode
= FPROUNDING_TIEAWAY
;
13074 case 0x59: /* FRINTX */
13075 case 0x79: /* FRINTI */
13076 only_in_vector
= true;
13077 /* current rounding mode */
13079 case 0x1a: /* FCVTNS */
13081 rmode
= FPROUNDING_TIEEVEN
;
13083 case 0x1b: /* FCVTMS */
13085 rmode
= FPROUNDING_NEGINF
;
13087 case 0x1c: /* FCVTAS */
13089 rmode
= FPROUNDING_TIEAWAY
;
13091 case 0x3a: /* FCVTPS */
13093 rmode
= FPROUNDING_POSINF
;
13095 case 0x3b: /* FCVTZS */
13097 rmode
= FPROUNDING_ZERO
;
13099 case 0x5a: /* FCVTNU */
13101 rmode
= FPROUNDING_TIEEVEN
;
13103 case 0x5b: /* FCVTMU */
13105 rmode
= FPROUNDING_NEGINF
;
13107 case 0x5c: /* FCVTAU */
13109 rmode
= FPROUNDING_TIEAWAY
;
13111 case 0x7a: /* FCVTPU */
13113 rmode
= FPROUNDING_POSINF
;
13115 case 0x7b: /* FCVTZU */
13117 rmode
= FPROUNDING_ZERO
;
13119 case 0x2f: /* FABS */
13120 case 0x6f: /* FNEG */
13123 case 0x7d: /* FRSQRTE */
13124 case 0x7f: /* FSQRT (vector) */
13127 fprintf(stderr
, "%s: insn %#04x fpop %#2x\n", __func__
, insn
, fpop
);
13128 g_assert_not_reached();
13132 /* Check additional constraints for the scalar encoding */
13135 unallocated_encoding(s
);
13138 /* FRINTxx is only in the vector form */
13139 if (only_in_vector
) {
13140 unallocated_encoding(s
);
13145 if (!fp_access_check(s
)) {
13149 if (need_rmode
|| need_fpst
) {
13150 tcg_fpstatus
= get_fpstatus_ptr(true);
13154 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
13155 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
13159 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
13160 TCGv_i32 tcg_res
= tcg_temp_new_i32();
13163 case 0x1a: /* FCVTNS */
13164 case 0x1b: /* FCVTMS */
13165 case 0x1c: /* FCVTAS */
13166 case 0x3a: /* FCVTPS */
13167 case 0x3b: /* FCVTZS */
13168 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13170 case 0x3d: /* FRECPE */
13171 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13173 case 0x3f: /* FRECPX */
13174 gen_helper_frecpx_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13176 case 0x5a: /* FCVTNU */
13177 case 0x5b: /* FCVTMU */
13178 case 0x5c: /* FCVTAU */
13179 case 0x7a: /* FCVTPU */
13180 case 0x7b: /* FCVTZU */
13181 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13183 case 0x6f: /* FNEG */
13184 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
13186 case 0x7d: /* FRSQRTE */
13187 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13190 g_assert_not_reached();
13193 /* limit any sign extension going on */
13194 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0xffff);
13195 write_fp_sreg(s
, rd
, tcg_res
);
13197 tcg_temp_free_i32(tcg_res
);
13198 tcg_temp_free_i32(tcg_op
);
13200 for (pass
= 0; pass
< (is_q
? 8 : 4); pass
++) {
13201 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13202 TCGv_i32 tcg_res
= tcg_temp_new_i32();
13204 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_16
);
13207 case 0x1a: /* FCVTNS */
13208 case 0x1b: /* FCVTMS */
13209 case 0x1c: /* FCVTAS */
13210 case 0x3a: /* FCVTPS */
13211 case 0x3b: /* FCVTZS */
13212 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13214 case 0x3d: /* FRECPE */
13215 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13217 case 0x5a: /* FCVTNU */
13218 case 0x5b: /* FCVTMU */
13219 case 0x5c: /* FCVTAU */
13220 case 0x7a: /* FCVTPU */
13221 case 0x7b: /* FCVTZU */
13222 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13224 case 0x18: /* FRINTN */
13225 case 0x19: /* FRINTM */
13226 case 0x38: /* FRINTP */
13227 case 0x39: /* FRINTZ */
13228 case 0x58: /* FRINTA */
13229 case 0x79: /* FRINTI */
13230 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13232 case 0x59: /* FRINTX */
13233 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
13235 case 0x2f: /* FABS */
13236 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
13238 case 0x6f: /* FNEG */
13239 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
13241 case 0x7d: /* FRSQRTE */
13242 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13244 case 0x7f: /* FSQRT */
13245 gen_helper_sqrt_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13248 g_assert_not_reached();
13251 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
13253 tcg_temp_free_i32(tcg_res
);
13254 tcg_temp_free_i32(tcg_op
);
13257 clear_vec_high(s
, is_q
, rd
);
13261 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
13262 tcg_temp_free_i32(tcg_rmode
);
13265 if (tcg_fpstatus
) {
13266 tcg_temp_free_ptr(tcg_fpstatus
);
13270 /* AdvSIMD scalar x indexed element
13271 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
13272 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
13273 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
13274 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
13275 * AdvSIMD vector x indexed element
13276 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
13277 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
13278 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
13279 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
13281 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
13283 /* This encoding has two kinds of instruction:
13284 * normal, where we perform elt x idxelt => elt for each
13285 * element in the vector
13286 * long, where we perform elt x idxelt and generate a result of
13287 * double the width of the input element
13288 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
13290 bool is_scalar
= extract32(insn
, 28, 1);
13291 bool is_q
= extract32(insn
, 30, 1);
13292 bool u
= extract32(insn
, 29, 1);
13293 int size
= extract32(insn
, 22, 2);
13294 int l
= extract32(insn
, 21, 1);
13295 int m
= extract32(insn
, 20, 1);
13296 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
13297 int rm
= extract32(insn
, 16, 4);
13298 int opcode
= extract32(insn
, 12, 4);
13299 int h
= extract32(insn
, 11, 1);
13300 int rn
= extract32(insn
, 5, 5);
13301 int rd
= extract32(insn
, 0, 5);
13302 bool is_long
= false;
13304 bool is_fp16
= false;
13308 switch (16 * u
+ opcode
) {
13309 case 0x08: /* MUL */
13310 case 0x10: /* MLA */
13311 case 0x14: /* MLS */
13313 unallocated_encoding(s
);
13317 case 0x02: /* SMLAL, SMLAL2 */
13318 case 0x12: /* UMLAL, UMLAL2 */
13319 case 0x06: /* SMLSL, SMLSL2 */
13320 case 0x16: /* UMLSL, UMLSL2 */
13321 case 0x0a: /* SMULL, SMULL2 */
13322 case 0x1a: /* UMULL, UMULL2 */
13324 unallocated_encoding(s
);
13329 case 0x03: /* SQDMLAL, SQDMLAL2 */
13330 case 0x07: /* SQDMLSL, SQDMLSL2 */
13331 case 0x0b: /* SQDMULL, SQDMULL2 */
13334 case 0x0c: /* SQDMULH */
13335 case 0x0d: /* SQRDMULH */
13337 case 0x01: /* FMLA */
13338 case 0x05: /* FMLS */
13339 case 0x09: /* FMUL */
13340 case 0x19: /* FMULX */
13343 case 0x1d: /* SQRDMLAH */
13344 case 0x1f: /* SQRDMLSH */
13345 if (!dc_isar_feature(aa64_rdm
, s
)) {
13346 unallocated_encoding(s
);
13350 case 0x0e: /* SDOT */
13351 case 0x1e: /* UDOT */
13352 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_dp
, s
)) {
13353 unallocated_encoding(s
);
13357 case 0x11: /* FCMLA #0 */
13358 case 0x13: /* FCMLA #90 */
13359 case 0x15: /* FCMLA #180 */
13360 case 0x17: /* FCMLA #270 */
13361 if (is_scalar
|| !dc_isar_feature(aa64_fcma
, s
)) {
13362 unallocated_encoding(s
);
13367 case 0x00: /* FMLAL */
13368 case 0x04: /* FMLSL */
13369 case 0x18: /* FMLAL2 */
13370 case 0x1c: /* FMLSL2 */
13371 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_fhm
, s
)) {
13372 unallocated_encoding(s
);
13376 /* is_fp, but we pass cpu_env not fp_status. */
13379 unallocated_encoding(s
);
13384 case 1: /* normal fp */
13385 /* convert insn encoded size to MemOp size */
13387 case 0: /* half-precision */
13391 case MO_32
: /* single precision */
13392 case MO_64
: /* double precision */
13395 unallocated_encoding(s
);
13400 case 2: /* complex fp */
13401 /* Each indexable element is a complex pair. */
13406 unallocated_encoding(s
);
13414 unallocated_encoding(s
);
13419 default: /* integer */
13423 unallocated_encoding(s
);
13428 if (is_fp16
&& !dc_isar_feature(aa64_fp16
, s
)) {
13429 unallocated_encoding(s
);
13433 /* Given MemOp size, adjust register and indexing. */
13436 index
= h
<< 2 | l
<< 1 | m
;
13439 index
= h
<< 1 | l
;
13444 unallocated_encoding(s
);
13451 g_assert_not_reached();
13454 if (!fp_access_check(s
)) {
13459 fpst
= get_fpstatus_ptr(is_fp16
);
13464 switch (16 * u
+ opcode
) {
13465 case 0x0e: /* SDOT */
13466 case 0x1e: /* UDOT */
13467 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, index
,
13468 u
? gen_helper_gvec_udot_idx_b
13469 : gen_helper_gvec_sdot_idx_b
);
13471 case 0x11: /* FCMLA #0 */
13472 case 0x13: /* FCMLA #90 */
13473 case 0x15: /* FCMLA #180 */
13474 case 0x17: /* FCMLA #270 */
13476 int rot
= extract32(insn
, 13, 2);
13477 int data
= (index
<< 2) | rot
;
13478 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
13479 vec_full_reg_offset(s
, rn
),
13480 vec_full_reg_offset(s
, rm
), fpst
,
13481 is_q
? 16 : 8, vec_full_reg_size(s
), data
,
13483 ? gen_helper_gvec_fcmlas_idx
13484 : gen_helper_gvec_fcmlah_idx
);
13485 tcg_temp_free_ptr(fpst
);
13489 case 0x00: /* FMLAL */
13490 case 0x04: /* FMLSL */
13491 case 0x18: /* FMLAL2 */
13492 case 0x1c: /* FMLSL2 */
13494 int is_s
= extract32(opcode
, 2, 1);
13496 int data
= (index
<< 2) | (is_2
<< 1) | is_s
;
13497 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
13498 vec_full_reg_offset(s
, rn
),
13499 vec_full_reg_offset(s
, rm
), cpu_env
,
13500 is_q
? 16 : 8, vec_full_reg_size(s
),
13501 data
, gen_helper_gvec_fmlal_idx_a64
);
13507 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
13510 assert(is_fp
&& is_q
&& !is_long
);
13512 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
13514 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13515 TCGv_i64 tcg_op
= tcg_temp_new_i64();
13516 TCGv_i64 tcg_res
= tcg_temp_new_i64();
13518 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
13520 switch (16 * u
+ opcode
) {
13521 case 0x05: /* FMLS */
13522 /* As usual for ARM, separate negation for fused multiply-add */
13523 gen_helper_vfp_negd(tcg_op
, tcg_op
);
13525 case 0x01: /* FMLA */
13526 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
13527 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
13529 case 0x09: /* FMUL */
13530 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13532 case 0x19: /* FMULX */
13533 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13536 g_assert_not_reached();
13539 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
13540 tcg_temp_free_i64(tcg_op
);
13541 tcg_temp_free_i64(tcg_res
);
13544 tcg_temp_free_i64(tcg_idx
);
13545 clear_vec_high(s
, !is_scalar
, rd
);
13546 } else if (!is_long
) {
13547 /* 32 bit floating point, or 16 or 32 bit integer.
13548 * For the 16 bit scalar case we use the usual Neon helpers and
13549 * rely on the fact that 0 op 0 == 0 with no side effects.
13551 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13552 int pass
, maxpasses
;
13557 maxpasses
= is_q
? 4 : 2;
13560 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13562 if (size
== 1 && !is_scalar
) {
13563 /* The simplest way to handle the 16x16 indexed ops is to duplicate
13564 * the index into both halves of the 32 bit tcg_idx and then use
13565 * the usual Neon helpers.
13567 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13570 for (pass
= 0; pass
< maxpasses
; pass
++) {
13571 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13572 TCGv_i32 tcg_res
= tcg_temp_new_i32();
13574 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
13576 switch (16 * u
+ opcode
) {
13577 case 0x08: /* MUL */
13578 case 0x10: /* MLA */
13579 case 0x14: /* MLS */
13581 static NeonGenTwoOpFn
* const fns
[2][2] = {
13582 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
13583 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
13585 NeonGenTwoOpFn
*genfn
;
13586 bool is_sub
= opcode
== 0x4;
13589 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
13591 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
13593 if (opcode
== 0x8) {
13596 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
13597 genfn
= fns
[size
- 1][is_sub
];
13598 genfn(tcg_res
, tcg_op
, tcg_res
);
13601 case 0x05: /* FMLS */
13602 case 0x01: /* FMLA */
13603 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13604 is_scalar
? size
: MO_32
);
13607 if (opcode
== 0x5) {
13608 /* As usual for ARM, separate negation for fused
13610 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80008000);
13613 gen_helper_advsimd_muladdh(tcg_res
, tcg_op
, tcg_idx
,
13616 gen_helper_advsimd_muladd2h(tcg_res
, tcg_op
, tcg_idx
,
13621 if (opcode
== 0x5) {
13622 /* As usual for ARM, separate negation for
13623 * fused multiply-add */
13624 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80000000);
13626 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
,
13630 g_assert_not_reached();
13633 case 0x09: /* FMUL */
13637 gen_helper_advsimd_mulh(tcg_res
, tcg_op
,
13640 gen_helper_advsimd_mul2h(tcg_res
, tcg_op
,
13645 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13648 g_assert_not_reached();
13651 case 0x19: /* FMULX */
13655 gen_helper_advsimd_mulxh(tcg_res
, tcg_op
,
13658 gen_helper_advsimd_mulx2h(tcg_res
, tcg_op
,
13663 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13666 g_assert_not_reached();
13669 case 0x0c: /* SQDMULH */
13671 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
13674 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
13678 case 0x0d: /* SQRDMULH */
13680 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
13683 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
13687 case 0x1d: /* SQRDMLAH */
13688 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13689 is_scalar
? size
: MO_32
);
13691 gen_helper_neon_qrdmlah_s16(tcg_res
, cpu_env
,
13692 tcg_op
, tcg_idx
, tcg_res
);
13694 gen_helper_neon_qrdmlah_s32(tcg_res
, cpu_env
,
13695 tcg_op
, tcg_idx
, tcg_res
);
13698 case 0x1f: /* SQRDMLSH */
13699 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13700 is_scalar
? size
: MO_32
);
13702 gen_helper_neon_qrdmlsh_s16(tcg_res
, cpu_env
,
13703 tcg_op
, tcg_idx
, tcg_res
);
13705 gen_helper_neon_qrdmlsh_s32(tcg_res
, cpu_env
,
13706 tcg_op
, tcg_idx
, tcg_res
);
13710 g_assert_not_reached();
13714 write_fp_sreg(s
, rd
, tcg_res
);
13716 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
13719 tcg_temp_free_i32(tcg_op
);
13720 tcg_temp_free_i32(tcg_res
);
13723 tcg_temp_free_i32(tcg_idx
);
13724 clear_vec_high(s
, is_q
, rd
);
13726 /* long ops: 16x16->32 or 32x32->64 */
13727 TCGv_i64 tcg_res
[2];
13729 bool satop
= extract32(opcode
, 0, 1);
13730 MemOp memop
= MO_32
;
13737 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
13739 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
13741 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13742 TCGv_i64 tcg_op
= tcg_temp_new_i64();
13743 TCGv_i64 tcg_passres
;
13749 passelt
= pass
+ (is_q
* 2);
13752 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
13754 tcg_res
[pass
] = tcg_temp_new_i64();
13756 if (opcode
== 0xa || opcode
== 0xb) {
13757 /* Non-accumulating ops */
13758 tcg_passres
= tcg_res
[pass
];
13760 tcg_passres
= tcg_temp_new_i64();
13763 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
13764 tcg_temp_free_i64(tcg_op
);
13767 /* saturating, doubling */
13768 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
13769 tcg_passres
, tcg_passres
);
13772 if (opcode
== 0xa || opcode
== 0xb) {
13776 /* Accumulating op: handle accumulate step */
13777 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13780 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13781 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13783 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13784 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13786 case 0x7: /* SQDMLSL, SQDMLSL2 */
13787 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
13789 case 0x3: /* SQDMLAL, SQDMLAL2 */
13790 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
13795 g_assert_not_reached();
13797 tcg_temp_free_i64(tcg_passres
);
13799 tcg_temp_free_i64(tcg_idx
);
13801 clear_vec_high(s
, !is_scalar
, rd
);
13803 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13806 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13809 /* The simplest way to handle the 16x16 indexed ops is to
13810 * duplicate the index into both halves of the 32 bit tcg_idx
13811 * and then use the usual Neon helpers.
13813 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13816 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13817 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13818 TCGv_i64 tcg_passres
;
13821 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
13823 read_vec_element_i32(s
, tcg_op
, rn
,
13824 pass
+ (is_q
* 2), MO_32
);
13827 tcg_res
[pass
] = tcg_temp_new_i64();
13829 if (opcode
== 0xa || opcode
== 0xb) {
13830 /* Non-accumulating ops */
13831 tcg_passres
= tcg_res
[pass
];
13833 tcg_passres
= tcg_temp_new_i64();
13836 if (memop
& MO_SIGN
) {
13837 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
13839 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
13842 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
13843 tcg_passres
, tcg_passres
);
13845 tcg_temp_free_i32(tcg_op
);
13847 if (opcode
== 0xa || opcode
== 0xb) {
13851 /* Accumulating op: handle accumulate step */
13852 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13855 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13856 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
13859 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13860 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
13863 case 0x7: /* SQDMLSL, SQDMLSL2 */
13864 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
13866 case 0x3: /* SQDMLAL, SQDMLAL2 */
13867 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
13872 g_assert_not_reached();
13874 tcg_temp_free_i64(tcg_passres
);
13876 tcg_temp_free_i32(tcg_idx
);
13879 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
13884 tcg_res
[1] = tcg_const_i64(0);
13887 for (pass
= 0; pass
< 2; pass
++) {
13888 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13889 tcg_temp_free_i64(tcg_res
[pass
]);
13894 tcg_temp_free_ptr(fpst
);
13899 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13900 * +-----------------+------+-----------+--------+-----+------+------+
13901 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13902 * +-----------------+------+-----------+--------+-----+------+------+
13904 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
13906 int size
= extract32(insn
, 22, 2);
13907 int opcode
= extract32(insn
, 12, 5);
13908 int rn
= extract32(insn
, 5, 5);
13909 int rd
= extract32(insn
, 0, 5);
13911 gen_helper_gvec_2
*genfn2
= NULL
;
13912 gen_helper_gvec_3
*genfn3
= NULL
;
13914 if (!dc_isar_feature(aa64_aes
, s
) || size
!= 0) {
13915 unallocated_encoding(s
);
13920 case 0x4: /* AESE */
13922 genfn3
= gen_helper_crypto_aese
;
13924 case 0x6: /* AESMC */
13926 genfn2
= gen_helper_crypto_aesmc
;
13928 case 0x5: /* AESD */
13930 genfn3
= gen_helper_crypto_aese
;
13932 case 0x7: /* AESIMC */
13934 genfn2
= gen_helper_crypto_aesmc
;
13937 unallocated_encoding(s
);
13941 if (!fp_access_check(s
)) {
13945 gen_gvec_op2_ool(s
, true, rd
, rn
, decrypt
, genfn2
);
13947 gen_gvec_op3_ool(s
, true, rd
, rd
, rn
, decrypt
, genfn3
);
13951 /* Crypto three-reg SHA
13952 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
13953 * +-----------------+------+---+------+---+--------+-----+------+------+
13954 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
13955 * +-----------------+------+---+------+---+--------+-----+------+------+
13957 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
13959 int size
= extract32(insn
, 22, 2);
13960 int opcode
= extract32(insn
, 12, 3);
13961 int rm
= extract32(insn
, 16, 5);
13962 int rn
= extract32(insn
, 5, 5);
13963 int rd
= extract32(insn
, 0, 5);
13964 gen_helper_gvec_3
*genfn
;
13968 unallocated_encoding(s
);
13973 case 0: /* SHA1C */
13974 genfn
= gen_helper_crypto_sha1c
;
13975 feature
= dc_isar_feature(aa64_sha1
, s
);
13977 case 1: /* SHA1P */
13978 genfn
= gen_helper_crypto_sha1p
;
13979 feature
= dc_isar_feature(aa64_sha1
, s
);
13981 case 2: /* SHA1M */
13982 genfn
= gen_helper_crypto_sha1m
;
13983 feature
= dc_isar_feature(aa64_sha1
, s
);
13985 case 3: /* SHA1SU0 */
13986 genfn
= gen_helper_crypto_sha1su0
;
13987 feature
= dc_isar_feature(aa64_sha1
, s
);
13989 case 4: /* SHA256H */
13990 genfn
= gen_helper_crypto_sha256h
;
13991 feature
= dc_isar_feature(aa64_sha256
, s
);
13993 case 5: /* SHA256H2 */
13994 genfn
= gen_helper_crypto_sha256h2
;
13995 feature
= dc_isar_feature(aa64_sha256
, s
);
13997 case 6: /* SHA256SU1 */
13998 genfn
= gen_helper_crypto_sha256su1
;
13999 feature
= dc_isar_feature(aa64_sha256
, s
);
14002 unallocated_encoding(s
);
14007 unallocated_encoding(s
);
14011 if (!fp_access_check(s
)) {
14014 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, 0, genfn
);
14017 /* Crypto two-reg SHA
14018 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
14019 * +-----------------+------+-----------+--------+-----+------+------+
14020 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
14021 * +-----------------+------+-----------+--------+-----+------+------+
14023 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
14025 int size
= extract32(insn
, 22, 2);
14026 int opcode
= extract32(insn
, 12, 5);
14027 int rn
= extract32(insn
, 5, 5);
14028 int rd
= extract32(insn
, 0, 5);
14029 gen_helper_gvec_2
*genfn
;
14033 unallocated_encoding(s
);
14038 case 0: /* SHA1H */
14039 feature
= dc_isar_feature(aa64_sha1
, s
);
14040 genfn
= gen_helper_crypto_sha1h
;
14042 case 1: /* SHA1SU1 */
14043 feature
= dc_isar_feature(aa64_sha1
, s
);
14044 genfn
= gen_helper_crypto_sha1su1
;
14046 case 2: /* SHA256SU0 */
14047 feature
= dc_isar_feature(aa64_sha256
, s
);
14048 genfn
= gen_helper_crypto_sha256su0
;
14051 unallocated_encoding(s
);
14056 unallocated_encoding(s
);
14060 if (!fp_access_check(s
)) {
14063 gen_gvec_op2_ool(s
, true, rd
, rn
, 0, genfn
);
14066 static void gen_rax1_i64(TCGv_i64 d
, TCGv_i64 n
, TCGv_i64 m
)
14068 tcg_gen_rotli_i64(d
, m
, 1);
14069 tcg_gen_xor_i64(d
, d
, n
);
14072 static void gen_rax1_vec(unsigned vece
, TCGv_vec d
, TCGv_vec n
, TCGv_vec m
)
14074 tcg_gen_rotli_vec(vece
, d
, m
, 1);
14075 tcg_gen_xor_vec(vece
, d
, d
, n
);
14078 void gen_gvec_rax1(unsigned vece
, uint32_t rd_ofs
, uint32_t rn_ofs
,
14079 uint32_t rm_ofs
, uint32_t opr_sz
, uint32_t max_sz
)
14081 static const TCGOpcode vecop_list
[] = { INDEX_op_rotli_vec
, 0 };
14082 static const GVecGen3 op
= {
14083 .fni8
= gen_rax1_i64
,
14084 .fniv
= gen_rax1_vec
,
14085 .opt_opc
= vecop_list
,
14086 .fno
= gen_helper_crypto_rax1
,
14089 tcg_gen_gvec_3(rd_ofs
, rn_ofs
, rm_ofs
, opr_sz
, max_sz
, &op
);
14092 /* Crypto three-reg SHA512
14093 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
14094 * +-----------------------+------+---+---+-----+--------+------+------+
14095 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
14096 * +-----------------------+------+---+---+-----+--------+------+------+
14098 static void disas_crypto_three_reg_sha512(DisasContext
*s
, uint32_t insn
)
14100 int opcode
= extract32(insn
, 10, 2);
14101 int o
= extract32(insn
, 14, 1);
14102 int rm
= extract32(insn
, 16, 5);
14103 int rn
= extract32(insn
, 5, 5);
14104 int rd
= extract32(insn
, 0, 5);
14106 gen_helper_gvec_3
*oolfn
= NULL
;
14107 GVecGen3Fn
*gvecfn
= NULL
;
14111 case 0: /* SHA512H */
14112 feature
= dc_isar_feature(aa64_sha512
, s
);
14113 oolfn
= gen_helper_crypto_sha512h
;
14115 case 1: /* SHA512H2 */
14116 feature
= dc_isar_feature(aa64_sha512
, s
);
14117 oolfn
= gen_helper_crypto_sha512h2
;
14119 case 2: /* SHA512SU1 */
14120 feature
= dc_isar_feature(aa64_sha512
, s
);
14121 oolfn
= gen_helper_crypto_sha512su1
;
14124 feature
= dc_isar_feature(aa64_sha3
, s
);
14125 gvecfn
= gen_gvec_rax1
;
14128 g_assert_not_reached();
14132 case 0: /* SM3PARTW1 */
14133 feature
= dc_isar_feature(aa64_sm3
, s
);
14134 oolfn
= gen_helper_crypto_sm3partw1
;
14136 case 1: /* SM3PARTW2 */
14137 feature
= dc_isar_feature(aa64_sm3
, s
);
14138 oolfn
= gen_helper_crypto_sm3partw2
;
14140 case 2: /* SM4EKEY */
14141 feature
= dc_isar_feature(aa64_sm4
, s
);
14142 oolfn
= gen_helper_crypto_sm4ekey
;
14145 unallocated_encoding(s
);
14151 unallocated_encoding(s
);
14155 if (!fp_access_check(s
)) {
14160 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, 0, oolfn
);
14162 gen_gvec_fn3(s
, true, rd
, rn
, rm
, gvecfn
, MO_64
);
14166 /* Crypto two-reg SHA512
14167 * 31 12 11 10 9 5 4 0
14168 * +-----------------------------------------+--------+------+------+
14169 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
14170 * +-----------------------------------------+--------+------+------+
14172 static void disas_crypto_two_reg_sha512(DisasContext
*s
, uint32_t insn
)
14174 int opcode
= extract32(insn
, 10, 2);
14175 int rn
= extract32(insn
, 5, 5);
14176 int rd
= extract32(insn
, 0, 5);
14180 case 0: /* SHA512SU0 */
14181 feature
= dc_isar_feature(aa64_sha512
, s
);
14184 feature
= dc_isar_feature(aa64_sm4
, s
);
14187 unallocated_encoding(s
);
14192 unallocated_encoding(s
);
14196 if (!fp_access_check(s
)) {
14201 case 0: /* SHA512SU0 */
14202 gen_gvec_op2_ool(s
, true, rd
, rn
, 0, gen_helper_crypto_sha512su0
);
14205 gen_gvec_op3_ool(s
, true, rd
, rd
, rn
, 0, gen_helper_crypto_sm4e
);
14208 g_assert_not_reached();
14212 /* Crypto four-register
14213 * 31 23 22 21 20 16 15 14 10 9 5 4 0
14214 * +-------------------+-----+------+---+------+------+------+
14215 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
14216 * +-------------------+-----+------+---+------+------+------+
14218 static void disas_crypto_four_reg(DisasContext
*s
, uint32_t insn
)
14220 int op0
= extract32(insn
, 21, 2);
14221 int rm
= extract32(insn
, 16, 5);
14222 int ra
= extract32(insn
, 10, 5);
14223 int rn
= extract32(insn
, 5, 5);
14224 int rd
= extract32(insn
, 0, 5);
14230 feature
= dc_isar_feature(aa64_sha3
, s
);
14232 case 2: /* SM3SS1 */
14233 feature
= dc_isar_feature(aa64_sm3
, s
);
14236 unallocated_encoding(s
);
14241 unallocated_encoding(s
);
14245 if (!fp_access_check(s
)) {
14250 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
[2];
14253 tcg_op1
= tcg_temp_new_i64();
14254 tcg_op2
= tcg_temp_new_i64();
14255 tcg_op3
= tcg_temp_new_i64();
14256 tcg_res
[0] = tcg_temp_new_i64();
14257 tcg_res
[1] = tcg_temp_new_i64();
14259 for (pass
= 0; pass
< 2; pass
++) {
14260 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
14261 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
14262 read_vec_element(s
, tcg_op3
, ra
, pass
, MO_64
);
14266 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
14269 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
14271 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
14273 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
14274 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
14276 tcg_temp_free_i64(tcg_op1
);
14277 tcg_temp_free_i64(tcg_op2
);
14278 tcg_temp_free_i64(tcg_op3
);
14279 tcg_temp_free_i64(tcg_res
[0]);
14280 tcg_temp_free_i64(tcg_res
[1]);
14282 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
, tcg_zero
;
14284 tcg_op1
= tcg_temp_new_i32();
14285 tcg_op2
= tcg_temp_new_i32();
14286 tcg_op3
= tcg_temp_new_i32();
14287 tcg_res
= tcg_temp_new_i32();
14288 tcg_zero
= tcg_const_i32(0);
14290 read_vec_element_i32(s
, tcg_op1
, rn
, 3, MO_32
);
14291 read_vec_element_i32(s
, tcg_op2
, rm
, 3, MO_32
);
14292 read_vec_element_i32(s
, tcg_op3
, ra
, 3, MO_32
);
14294 tcg_gen_rotri_i32(tcg_res
, tcg_op1
, 20);
14295 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op2
);
14296 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op3
);
14297 tcg_gen_rotri_i32(tcg_res
, tcg_res
, 25);
14299 write_vec_element_i32(s
, tcg_zero
, rd
, 0, MO_32
);
14300 write_vec_element_i32(s
, tcg_zero
, rd
, 1, MO_32
);
14301 write_vec_element_i32(s
, tcg_zero
, rd
, 2, MO_32
);
14302 write_vec_element_i32(s
, tcg_res
, rd
, 3, MO_32
);
14304 tcg_temp_free_i32(tcg_op1
);
14305 tcg_temp_free_i32(tcg_op2
);
14306 tcg_temp_free_i32(tcg_op3
);
14307 tcg_temp_free_i32(tcg_res
);
14308 tcg_temp_free_i32(tcg_zero
);
14313 * 31 21 20 16 15 10 9 5 4 0
14314 * +-----------------------+------+--------+------+------+
14315 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
14316 * +-----------------------+------+--------+------+------+
14318 static void disas_crypto_xar(DisasContext
*s
, uint32_t insn
)
14320 int rm
= extract32(insn
, 16, 5);
14321 int imm6
= extract32(insn
, 10, 6);
14322 int rn
= extract32(insn
, 5, 5);
14323 int rd
= extract32(insn
, 0, 5);
14324 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
14327 if (!dc_isar_feature(aa64_sha3
, s
)) {
14328 unallocated_encoding(s
);
14332 if (!fp_access_check(s
)) {
14336 tcg_op1
= tcg_temp_new_i64();
14337 tcg_op2
= tcg_temp_new_i64();
14338 tcg_res
[0] = tcg_temp_new_i64();
14339 tcg_res
[1] = tcg_temp_new_i64();
14341 for (pass
= 0; pass
< 2; pass
++) {
14342 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
14343 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
14345 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
14346 tcg_gen_rotri_i64(tcg_res
[pass
], tcg_res
[pass
], imm6
);
14348 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
14349 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
14351 tcg_temp_free_i64(tcg_op1
);
14352 tcg_temp_free_i64(tcg_op2
);
14353 tcg_temp_free_i64(tcg_res
[0]);
14354 tcg_temp_free_i64(tcg_res
[1]);
14357 /* Crypto three-reg imm2
14358 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
14359 * +-----------------------+------+-----+------+--------+------+------+
14360 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
14361 * +-----------------------+------+-----+------+--------+------+------+
14363 static void disas_crypto_three_reg_imm2(DisasContext
*s
, uint32_t insn
)
14365 static gen_helper_gvec_3
* const fns
[4] = {
14366 gen_helper_crypto_sm3tt1a
, gen_helper_crypto_sm3tt1b
,
14367 gen_helper_crypto_sm3tt2a
, gen_helper_crypto_sm3tt2b
,
14369 int opcode
= extract32(insn
, 10, 2);
14370 int imm2
= extract32(insn
, 12, 2);
14371 int rm
= extract32(insn
, 16, 5);
14372 int rn
= extract32(insn
, 5, 5);
14373 int rd
= extract32(insn
, 0, 5);
14375 if (!dc_isar_feature(aa64_sm3
, s
)) {
14376 unallocated_encoding(s
);
14380 if (!fp_access_check(s
)) {
14384 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, imm2
, fns
[opcode
]);
14387 /* C3.6 Data processing - SIMD, inc Crypto
14389 * As the decode gets a little complex we are using a table based
14390 * approach for this part of the decode.
14392 static const AArch64DecodeTable data_proc_simd
[] = {
14393 /* pattern , mask , fn */
14394 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
14395 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra
},
14396 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
14397 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
14398 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
14399 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
14400 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
14401 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
14402 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
14403 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
14404 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
14405 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
14406 { 0x2e000000, 0xbf208400, disas_simd_ext
},
14407 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
14408 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra
},
14409 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
14410 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
14411 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
14412 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
14413 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
14414 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
14415 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
14416 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
14417 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
14418 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512
},
14419 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512
},
14420 { 0xce000000, 0xff808000, disas_crypto_four_reg
},
14421 { 0xce800000, 0xffe00000, disas_crypto_xar
},
14422 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2
},
14423 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16
},
14424 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16
},
14425 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16
},
14426 { 0x00000000, 0x00000000, NULL
}
14429 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
14431 /* Note that this is called with all non-FP cases from
14432 * table C3-6 so it must UNDEF for entries not specifically
14433 * allocated to instructions in that table.
14435 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
14439 unallocated_encoding(s
);
14443 /* C3.6 Data processing - SIMD and floating point */
14444 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
14446 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
14447 disas_data_proc_fp(s
, insn
);
14449 /* SIMD, including crypto */
14450 disas_data_proc_simd(s
, insn
);
14456 * @env: The cpu environment
14457 * @s: The DisasContext
14459 * Return true if the page is guarded.
14461 static bool is_guarded_page(CPUARMState
*env
, DisasContext
*s
)
14463 #ifdef CONFIG_USER_ONLY
14464 return false; /* FIXME */
14466 uint64_t addr
= s
->base
.pc_first
;
14467 int mmu_idx
= arm_to_core_mmu_idx(s
->mmu_idx
);
14468 unsigned int index
= tlb_index(env
, mmu_idx
, addr
);
14469 CPUTLBEntry
*entry
= tlb_entry(env
, mmu_idx
, addr
);
14472 * We test this immediately after reading an insn, which means
14473 * that any normal page must be in the TLB. The only exception
14474 * would be for executing from flash or device memory, which
14475 * does not retain the TLB entry.
14477 * FIXME: Assume false for those, for now. We could use
14478 * arm_cpu_get_phys_page_attrs_debug to re-read the page
14479 * table entry even for that case.
14481 return (tlb_hit(entry
->addr_code
, addr
) &&
14482 arm_tlb_bti_gp(&env_tlb(env
)->d
[mmu_idx
].iotlb
[index
].attrs
));
14487 * btype_destination_ok:
14488 * @insn: The instruction at the branch destination
14489 * @bt: SCTLR_ELx.BT
14490 * @btype: PSTATE.BTYPE, and is non-zero
14492 * On a guarded page, there are a limited number of insns
14493 * that may be present at the branch target:
14494 * - branch target identifiers,
14495 * - paciasp, pacibsp,
14498 * Anything else causes a Branch Target Exception.
14500 * Return true if the branch is compatible, false to raise BTITRAP.
14502 static bool btype_destination_ok(uint32_t insn
, bool bt
, int btype
)
14504 if ((insn
& 0xfffff01fu
) == 0xd503201fu
) {
14506 switch (extract32(insn
, 5, 7)) {
14507 case 0b011001: /* PACIASP */
14508 case 0b011011: /* PACIBSP */
14510 * If SCTLR_ELx.BT, then PACI*SP are not compatible
14511 * with btype == 3. Otherwise all btype are ok.
14513 return !bt
|| btype
!= 3;
14514 case 0b100000: /* BTI */
14515 /* Not compatible with any btype. */
14517 case 0b100010: /* BTI c */
14518 /* Not compatible with btype == 3 */
14520 case 0b100100: /* BTI j */
14521 /* Not compatible with btype == 2 */
14523 case 0b100110: /* BTI jc */
14524 /* Compatible with any btype. */
14528 switch (insn
& 0xffe0001fu
) {
14529 case 0xd4200000u
: /* BRK */
14530 case 0xd4400000u
: /* HLT */
14531 /* Give priority to the breakpoint exception. */
14538 /* C3.1 A64 instruction index by encoding */
14539 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
14543 s
->pc_curr
= s
->base
.pc_next
;
14544 insn
= arm_ldl_code(env
, s
->base
.pc_next
, s
->sctlr_b
);
14546 s
->base
.pc_next
+= 4;
14548 s
->fp_access_checked
= false;
14550 if (dc_isar_feature(aa64_bti
, s
)) {
14551 if (s
->base
.num_insns
== 1) {
14553 * At the first insn of the TB, compute s->guarded_page.
14554 * We delayed computing this until successfully reading
14555 * the first insn of the TB, above. This (mostly) ensures
14556 * that the softmmu tlb entry has been populated, and the
14557 * page table GP bit is available.
14559 * Note that we need to compute this even if btype == 0,
14560 * because this value is used for BR instructions later
14561 * where ENV is not available.
14563 s
->guarded_page
= is_guarded_page(env
, s
);
14565 /* First insn can have btype set to non-zero. */
14566 tcg_debug_assert(s
->btype
>= 0);
14569 * Note that the Branch Target Exception has fairly high
14570 * priority -- below debugging exceptions but above most
14571 * everything else. This allows us to handle this now
14572 * instead of waiting until the insn is otherwise decoded.
14576 && !btype_destination_ok(insn
, s
->bt
, s
->btype
)) {
14577 gen_exception_insn(s
, s
->pc_curr
, EXCP_UDEF
,
14578 syn_btitrap(s
->btype
),
14579 default_exception_el(s
));
14583 /* Not the first insn: btype must be 0. */
14584 tcg_debug_assert(s
->btype
== 0);
14588 switch (extract32(insn
, 25, 4)) {
14589 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
14590 unallocated_encoding(s
);
14593 if (!dc_isar_feature(aa64_sve
, s
) || !disas_sve(s
, insn
)) {
14594 unallocated_encoding(s
);
14597 case 0x8: case 0x9: /* Data processing - immediate */
14598 disas_data_proc_imm(s
, insn
);
14600 case 0xa: case 0xb: /* Branch, exception generation and system insns */
14601 disas_b_exc_sys(s
, insn
);
14606 case 0xe: /* Loads and stores */
14607 disas_ldst(s
, insn
);
14610 case 0xd: /* Data processing - register */
14611 disas_data_proc_reg(s
, insn
);
14614 case 0xf: /* Data processing - SIMD and floating point */
14615 disas_data_proc_simd_fp(s
, insn
);
14618 assert(FALSE
); /* all 15 cases should be handled above */
14622 /* if we allocated any temporaries, free them here */
14626 * After execution of most insns, btype is reset to 0.
14627 * Note that we set btype == -1 when the insn sets btype.
14629 if (s
->btype
> 0 && s
->base
.is_jmp
!= DISAS_NORETURN
) {
14634 static void aarch64_tr_init_disas_context(DisasContextBase
*dcbase
,
14637 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14638 CPUARMState
*env
= cpu
->env_ptr
;
14639 ARMCPU
*arm_cpu
= env_archcpu(env
);
14640 uint32_t tb_flags
= dc
->base
.tb
->flags
;
14641 int bound
, core_mmu_idx
;
14643 dc
->isar
= &arm_cpu
->isar
;
14647 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
14648 * there is no secure EL1, so we route exceptions to EL3.
14650 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
14651 !arm_el_is_aa64(env
, 3);
14654 dc
->be_data
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, BE_DATA
) ? MO_BE
: MO_LE
;
14655 dc
->condexec_mask
= 0;
14656 dc
->condexec_cond
= 0;
14657 core_mmu_idx
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, MMUIDX
);
14658 dc
->mmu_idx
= core_to_aa64_mmu_idx(core_mmu_idx
);
14659 dc
->tbii
= FIELD_EX32(tb_flags
, TBFLAG_A64
, TBII
);
14660 dc
->tbid
= FIELD_EX32(tb_flags
, TBFLAG_A64
, TBID
);
14661 dc
->tcma
= FIELD_EX32(tb_flags
, TBFLAG_A64
, TCMA
);
14662 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
14663 #if !defined(CONFIG_USER_ONLY)
14664 dc
->user
= (dc
->current_el
== 0);
14666 dc
->fp_excp_el
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, FPEXC_EL
);
14667 dc
->sve_excp_el
= FIELD_EX32(tb_flags
, TBFLAG_A64
, SVEEXC_EL
);
14668 dc
->sve_len
= (FIELD_EX32(tb_flags
, TBFLAG_A64
, ZCR_LEN
) + 1) * 16;
14669 dc
->pauth_active
= FIELD_EX32(tb_flags
, TBFLAG_A64
, PAUTH_ACTIVE
);
14670 dc
->bt
= FIELD_EX32(tb_flags
, TBFLAG_A64
, BT
);
14671 dc
->btype
= FIELD_EX32(tb_flags
, TBFLAG_A64
, BTYPE
);
14672 dc
->unpriv
= FIELD_EX32(tb_flags
, TBFLAG_A64
, UNPRIV
);
14673 dc
->ata
= FIELD_EX32(tb_flags
, TBFLAG_A64
, ATA
);
14674 dc
->mte_active
[0] = FIELD_EX32(tb_flags
, TBFLAG_A64
, MTE_ACTIVE
);
14675 dc
->mte_active
[1] = FIELD_EX32(tb_flags
, TBFLAG_A64
, MTE0_ACTIVE
);
14677 dc
->vec_stride
= 0;
14678 dc
->cp_regs
= arm_cpu
->cp_regs
;
14679 dc
->features
= env
->features
;
14680 dc
->dcz_blocksize
= arm_cpu
->dcz_blocksize
;
14682 #ifdef CONFIG_USER_ONLY
14683 /* In sve_probe_page, we assume TBI is enabled. */
14684 tcg_debug_assert(dc
->tbid
& 1);
14687 /* Single step state. The code-generation logic here is:
14689 * generate code with no special handling for single-stepping (except
14690 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
14691 * this happens anyway because those changes are all system register or
14693 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
14694 * emit code for one insn
14695 * emit code to clear PSTATE.SS
14696 * emit code to generate software step exception for completed step
14697 * end TB (as usual for having generated an exception)
14698 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
14699 * emit code to generate a software step exception
14702 dc
->ss_active
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, SS_ACTIVE
);
14703 dc
->pstate_ss
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, PSTATE_SS
);
14704 dc
->is_ldex
= false;
14705 dc
->debug_target_el
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, DEBUG_TARGET_EL
);
14707 /* Bound the number of insns to execute to those left on the page. */
14708 bound
= -(dc
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
14710 /* If architectural single step active, limit to 1. */
14711 if (dc
->ss_active
) {
14714 dc
->base
.max_insns
= MIN(dc
->base
.max_insns
, bound
);
14716 init_tmp_a64_array(dc
);
14719 static void aarch64_tr_tb_start(DisasContextBase
*db
, CPUState
*cpu
)
14723 static void aarch64_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
14725 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14727 tcg_gen_insn_start(dc
->base
.pc_next
, 0, 0);
14728 dc
->insn_start
= tcg_last_op();
14731 static bool aarch64_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cpu
,
14732 const CPUBreakpoint
*bp
)
14734 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14736 if (bp
->flags
& BP_CPU
) {
14737 gen_a64_set_pc_im(dc
->base
.pc_next
);
14738 gen_helper_check_breakpoints(cpu_env
);
14739 /* End the TB early; it likely won't be executed */
14740 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
14742 gen_exception_internal_insn(dc
, dc
->base
.pc_next
, EXCP_DEBUG
);
14743 /* The address covered by the breakpoint must be
14744 included in [tb->pc, tb->pc + tb->size) in order
14745 to for it to be properly cleared -- thus we
14746 increment the PC here so that the logic setting
14747 tb->size below does the right thing. */
14748 dc
->base
.pc_next
+= 4;
14749 dc
->base
.is_jmp
= DISAS_NORETURN
;
14755 static void aarch64_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
14757 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14758 CPUARMState
*env
= cpu
->env_ptr
;
14760 if (dc
->ss_active
&& !dc
->pstate_ss
) {
14761 /* Singlestep state is Active-pending.
14762 * If we're in this state at the start of a TB then either
14763 * a) we just took an exception to an EL which is being debugged
14764 * and this is the first insn in the exception handler
14765 * b) debug exceptions were masked and we just unmasked them
14766 * without changing EL (eg by clearing PSTATE.D)
14767 * In either case we're going to take a swstep exception in the
14768 * "did not step an insn" case, and so the syndrome ISV and EX
14769 * bits should be zero.
14771 assert(dc
->base
.num_insns
== 1);
14772 gen_swstep_exception(dc
, 0, 0);
14773 dc
->base
.is_jmp
= DISAS_NORETURN
;
14775 disas_a64_insn(env
, dc
);
14778 translator_loop_temp_check(&dc
->base
);
14781 static void aarch64_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
14783 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14785 if (unlikely(dc
->base
.singlestep_enabled
|| dc
->ss_active
)) {
14786 /* Note that this means single stepping WFI doesn't halt the CPU.
14787 * For conditional branch insns this is harmless unreachable code as
14788 * gen_goto_tb() has already handled emitting the debug exception
14789 * (and thus a tb-jump is not possible when singlestepping).
14791 switch (dc
->base
.is_jmp
) {
14793 gen_a64_set_pc_im(dc
->base
.pc_next
);
14797 if (dc
->base
.singlestep_enabled
) {
14798 gen_exception_internal(EXCP_DEBUG
);
14800 gen_step_complete_exception(dc
);
14803 case DISAS_NORETURN
:
14807 switch (dc
->base
.is_jmp
) {
14809 case DISAS_TOO_MANY
:
14810 gen_goto_tb(dc
, 1, dc
->base
.pc_next
);
14813 case DISAS_UPDATE_EXIT
:
14814 gen_a64_set_pc_im(dc
->base
.pc_next
);
14817 tcg_gen_exit_tb(NULL
, 0);
14819 case DISAS_UPDATE_NOCHAIN
:
14820 gen_a64_set_pc_im(dc
->base
.pc_next
);
14823 tcg_gen_lookup_and_goto_ptr();
14825 case DISAS_NORETURN
:
14829 gen_a64_set_pc_im(dc
->base
.pc_next
);
14830 gen_helper_wfe(cpu_env
);
14833 gen_a64_set_pc_im(dc
->base
.pc_next
);
14834 gen_helper_yield(cpu_env
);
14838 /* This is a special case because we don't want to just halt the CPU
14839 * if trying to debug across a WFI.
14841 TCGv_i32 tmp
= tcg_const_i32(4);
14843 gen_a64_set_pc_im(dc
->base
.pc_next
);
14844 gen_helper_wfi(cpu_env
, tmp
);
14845 tcg_temp_free_i32(tmp
);
14846 /* The helper doesn't necessarily throw an exception, but we
14847 * must go back to the main loop to check for interrupts anyway.
14849 tcg_gen_exit_tb(NULL
, 0);
14856 static void aarch64_tr_disas_log(const DisasContextBase
*dcbase
,
14859 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14861 qemu_log("IN: %s\n", lookup_symbol(dc
->base
.pc_first
));
14862 log_target_disas(cpu
, dc
->base
.pc_first
, dc
->base
.tb
->size
);
14865 const TranslatorOps aarch64_translator_ops
= {
14866 .init_disas_context
= aarch64_tr_init_disas_context
,
14867 .tb_start
= aarch64_tr_tb_start
,
14868 .insn_start
= aarch64_tr_insn_start
,
14869 .breakpoint_check
= aarch64_tr_breakpoint_check
,
14870 .translate_insn
= aarch64_tr_translate_insn
,
14871 .tb_stop
= aarch64_tr_tb_stop
,
14872 .disas_log
= aarch64_tr_disas_log
,