4 * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
22 #include "exec/exec-all.h"
23 #include "tcg/tcg-op.h"
24 #include "tcg/tcg-op-gvec.h"
27 #include "translate.h"
28 #include "internals.h"
29 #include "qemu/host-utils.h"
30 #include "semihosting/semihost.h"
31 #include "exec/gen-icount.h"
32 #include "exec/helper-proto.h"
33 #include "exec/helper-gen.h"
36 #include "translate-a64.h"
37 #include "qemu/atomic128.h"
39 static TCGv_i64 cpu_X
[32];
40 static TCGv_i64 cpu_pc
;
42 /* Load/store exclusive handling */
43 static TCGv_i64 cpu_exclusive_high
;
45 static const char *regnames
[] = {
46 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
47 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
48 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
49 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
53 A64_SHIFT_TYPE_LSL
= 0,
54 A64_SHIFT_TYPE_LSR
= 1,
55 A64_SHIFT_TYPE_ASR
= 2,
56 A64_SHIFT_TYPE_ROR
= 3
59 /* Table based decoder typedefs - used when the relevant bits for decode
60 * are too awkwardly scattered across the instruction (eg SIMD).
62 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
64 typedef struct AArch64DecodeTable
{
67 AArch64DecodeFn
*disas_fn
;
70 /* initialize TCG globals. */
71 void a64_translate_init(void)
75 cpu_pc
= tcg_global_mem_new_i64(cpu_env
,
76 offsetof(CPUARMState
, pc
),
78 for (i
= 0; i
< 32; i
++) {
79 cpu_X
[i
] = tcg_global_mem_new_i64(cpu_env
,
80 offsetof(CPUARMState
, xregs
[i
]),
84 cpu_exclusive_high
= tcg_global_mem_new_i64(cpu_env
,
85 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
89 * Return the core mmu_idx to use for A64 "unprivileged load/store" insns
91 static int get_a64_user_mem_index(DisasContext
*s
)
94 * If AccType_UNPRIV is not used, the insn uses AccType_NORMAL,
95 * which is the usual mmu_idx for this cpu state.
97 ARMMMUIdx useridx
= s
->mmu_idx
;
101 * We have pre-computed the condition for AccType_UNPRIV.
102 * Therefore we should never get here with a mmu_idx for
103 * which we do not know the corresponding user mmu_idx.
106 case ARMMMUIdx_E10_1
:
107 case ARMMMUIdx_E10_1_PAN
:
108 useridx
= ARMMMUIdx_E10_0
;
110 case ARMMMUIdx_E20_2
:
111 case ARMMMUIdx_E20_2_PAN
:
112 useridx
= ARMMMUIdx_E20_0
;
115 g_assert_not_reached();
118 return arm_to_core_mmu_idx(useridx
);
121 static void set_btype_raw(int val
)
123 tcg_gen_st_i32(tcg_constant_i32(val
), cpu_env
,
124 offsetof(CPUARMState
, btype
));
127 static void set_btype(DisasContext
*s
, int val
)
129 /* BTYPE is a 2-bit field, and 0 should be done with reset_btype. */
130 tcg_debug_assert(val
>= 1 && val
<= 3);
135 static void reset_btype(DisasContext
*s
)
143 static void gen_pc_plus_diff(DisasContext
*s
, TCGv_i64 dest
, target_long diff
)
145 assert(s
->pc_save
!= -1);
146 if (tb_cflags(s
->base
.tb
) & CF_PCREL
) {
147 tcg_gen_addi_i64(dest
, cpu_pc
, (s
->pc_curr
- s
->pc_save
) + diff
);
149 tcg_gen_movi_i64(dest
, s
->pc_curr
+ diff
);
153 void gen_a64_update_pc(DisasContext
*s
, target_long diff
)
155 gen_pc_plus_diff(s
, cpu_pc
, diff
);
156 s
->pc_save
= s
->pc_curr
+ diff
;
160 * Handle Top Byte Ignore (TBI) bits.
162 * If address tagging is enabled via the TCR TBI bits:
163 * + for EL2 and EL3 there is only one TBI bit, and if it is set
164 * then the address is zero-extended, clearing bits [63:56]
165 * + for EL0 and EL1, TBI0 controls addresses with bit 55 == 0
166 * and TBI1 controls addressses with bit 55 == 1.
167 * If the appropriate TBI bit is set for the address then
168 * the address is sign-extended from bit 55 into bits [63:56]
170 * Here We have concatenated TBI{1,0} into tbi.
172 static void gen_top_byte_ignore(DisasContext
*s
, TCGv_i64 dst
,
173 TCGv_i64 src
, int tbi
)
176 /* Load unmodified address */
177 tcg_gen_mov_i64(dst
, src
);
178 } else if (!regime_has_2_ranges(s
->mmu_idx
)) {
179 /* Force tag byte to all zero */
180 tcg_gen_extract_i64(dst
, src
, 0, 56);
182 /* Sign-extend from bit 55. */
183 tcg_gen_sextract_i64(dst
, src
, 0, 56);
187 /* tbi0 but !tbi1: only use the extension if positive */
188 tcg_gen_and_i64(dst
, dst
, src
);
191 /* !tbi0 but tbi1: only use the extension if negative */
192 tcg_gen_or_i64(dst
, dst
, src
);
195 /* tbi0 and tbi1: always use the extension */
198 g_assert_not_reached();
203 static void gen_a64_set_pc(DisasContext
*s
, TCGv_i64 src
)
206 * If address tagging is enabled for instructions via the TCR TBI bits,
207 * then loading an address into the PC will clear out any tag.
209 gen_top_byte_ignore(s
, cpu_pc
, src
, s
->tbii
);
214 * Handle MTE and/or TBI.
216 * For TBI, ideally, we would do nothing. Proper behaviour on fault is
217 * for the tag to be present in the FAR_ELx register. But for user-only
218 * mode we do not have a TLB with which to implement this, so we must
219 * remove the top byte now.
221 * Always return a fresh temporary that we can increment independently
222 * of the write-back address.
225 TCGv_i64
clean_data_tbi(DisasContext
*s
, TCGv_i64 addr
)
227 TCGv_i64 clean
= new_tmp_a64(s
);
228 #ifdef CONFIG_USER_ONLY
229 gen_top_byte_ignore(s
, clean
, addr
, s
->tbid
);
231 tcg_gen_mov_i64(clean
, addr
);
236 /* Insert a zero tag into src, with the result at dst. */
237 static void gen_address_with_allocation_tag0(TCGv_i64 dst
, TCGv_i64 src
)
239 tcg_gen_andi_i64(dst
, src
, ~MAKE_64BIT_MASK(56, 4));
242 static void gen_probe_access(DisasContext
*s
, TCGv_i64 ptr
,
243 MMUAccessType acc
, int log2_size
)
245 gen_helper_probe_access(cpu_env
, ptr
,
246 tcg_constant_i32(acc
),
247 tcg_constant_i32(get_mem_index(s
)),
248 tcg_constant_i32(1 << log2_size
));
252 * For MTE, check a single logical or atomic access. This probes a single
253 * address, the exact one specified. The size and alignment of the access
254 * is not relevant to MTE, per se, but watchpoints do require the size,
255 * and we want to recognize those before making any other changes to state.
257 static TCGv_i64
gen_mte_check1_mmuidx(DisasContext
*s
, TCGv_i64 addr
,
258 bool is_write
, bool tag_checked
,
259 int log2_size
, bool is_unpriv
,
262 if (tag_checked
&& s
->mte_active
[is_unpriv
]) {
266 desc
= FIELD_DP32(desc
, MTEDESC
, MIDX
, core_idx
);
267 desc
= FIELD_DP32(desc
, MTEDESC
, TBI
, s
->tbid
);
268 desc
= FIELD_DP32(desc
, MTEDESC
, TCMA
, s
->tcma
);
269 desc
= FIELD_DP32(desc
, MTEDESC
, WRITE
, is_write
);
270 desc
= FIELD_DP32(desc
, MTEDESC
, SIZEM1
, (1 << log2_size
) - 1);
272 ret
= new_tmp_a64(s
);
273 gen_helper_mte_check(ret
, cpu_env
, tcg_constant_i32(desc
), addr
);
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 size
)
293 if (tag_checked
&& s
->mte_active
[0]) {
297 desc
= FIELD_DP32(desc
, MTEDESC
, MIDX
, get_mem_index(s
));
298 desc
= FIELD_DP32(desc
, MTEDESC
, TBI
, s
->tbid
);
299 desc
= FIELD_DP32(desc
, MTEDESC
, TCMA
, s
->tcma
);
300 desc
= FIELD_DP32(desc
, MTEDESC
, WRITE
, is_write
);
301 desc
= FIELD_DP32(desc
, MTEDESC
, SIZEM1
, size
- 1);
303 ret
= new_tmp_a64(s
);
304 gen_helper_mte_check(ret
, cpu_env
, tcg_constant_i32(desc
), addr
);
308 return clean_data_tbi(s
, addr
);
311 typedef struct DisasCompare64
{
316 static void a64_test_cc(DisasCompare64
*c64
, int cc
)
320 arm_test_cc(&c32
, cc
);
323 * Sign-extend the 32-bit value so that the GE/LT comparisons work
324 * properly. The NE/EQ comparisons are also fine with this choice.
326 c64
->cond
= c32
.cond
;
327 c64
->value
= tcg_temp_new_i64();
328 tcg_gen_ext_i32_i64(c64
->value
, c32
.value
);
331 static void gen_rebuild_hflags(DisasContext
*s
)
333 gen_helper_rebuild_hflags_a64(cpu_env
, tcg_constant_i32(s
->current_el
));
336 static void gen_exception_internal(int excp
)
338 assert(excp_is_internal(excp
));
339 gen_helper_exception_internal(cpu_env
, tcg_constant_i32(excp
));
342 static void gen_exception_internal_insn(DisasContext
*s
, int excp
)
344 gen_a64_update_pc(s
, 0);
345 gen_exception_internal(excp
);
346 s
->base
.is_jmp
= DISAS_NORETURN
;
349 static void gen_exception_bkpt_insn(DisasContext
*s
, uint32_t syndrome
)
351 gen_a64_update_pc(s
, 0);
352 gen_helper_exception_bkpt_insn(cpu_env
, tcg_constant_i32(syndrome
));
353 s
->base
.is_jmp
= DISAS_NORETURN
;
356 static void gen_step_complete_exception(DisasContext
*s
)
358 /* We just completed step of an insn. Move from Active-not-pending
359 * to Active-pending, and then also take the swstep exception.
360 * This corresponds to making the (IMPDEF) choice to prioritize
361 * swstep exceptions over asynchronous exceptions taken to an exception
362 * level where debug is disabled. This choice has the advantage that
363 * we do not need to maintain internal state corresponding to the
364 * ISV/EX syndrome bits between completion of the step and generation
365 * of the exception, and our syndrome information is always correct.
368 gen_swstep_exception(s
, 1, s
->is_ldex
);
369 s
->base
.is_jmp
= DISAS_NORETURN
;
372 static inline bool use_goto_tb(DisasContext
*s
, uint64_t dest
)
377 return translator_use_goto_tb(&s
->base
, dest
);
380 static void gen_goto_tb(DisasContext
*s
, int n
, int64_t diff
)
382 if (use_goto_tb(s
, s
->pc_curr
+ diff
)) {
384 * For pcrel, the pc must always be up-to-date on entry to
385 * the linked TB, so that it can use simple additions for all
386 * further adjustments. For !pcrel, the linked TB is compiled
387 * to know its full virtual address, so we can delay the
388 * update to pc to the unlinked path. A long chain of links
389 * can thus avoid many updates to the PC.
391 if (tb_cflags(s
->base
.tb
) & CF_PCREL
) {
392 gen_a64_update_pc(s
, diff
);
396 gen_a64_update_pc(s
, diff
);
398 tcg_gen_exit_tb(s
->base
.tb
, n
);
399 s
->base
.is_jmp
= DISAS_NORETURN
;
401 gen_a64_update_pc(s
, diff
);
403 gen_step_complete_exception(s
);
405 tcg_gen_lookup_and_goto_ptr();
406 s
->base
.is_jmp
= DISAS_NORETURN
;
411 static void init_tmp_a64_array(DisasContext
*s
)
413 #ifdef CONFIG_DEBUG_TCG
414 memset(s
->tmp_a64
, 0, sizeof(s
->tmp_a64
));
416 s
->tmp_a64_count
= 0;
419 static void free_tmp_a64(DisasContext
*s
)
422 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
423 tcg_temp_free_i64(s
->tmp_a64
[i
]);
425 init_tmp_a64_array(s
);
428 TCGv_i64
new_tmp_a64(DisasContext
*s
)
430 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
431 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
434 TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
436 TCGv_i64 t
= new_tmp_a64(s
);
437 tcg_gen_movi_i64(t
, 0);
442 * Register access functions
444 * These functions are used for directly accessing a register in where
445 * changes to the final register value are likely to be made. If you
446 * need to use a register for temporary calculation (e.g. index type
447 * operations) use the read_* form.
449 * B1.2.1 Register mappings
451 * In instruction register encoding 31 can refer to ZR (zero register) or
452 * the SP (stack pointer) depending on context. In QEMU's case we map SP
453 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
454 * This is the point of the _sp forms.
456 TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
459 return new_tmp_a64_zero(s
);
465 /* register access for when 31 == SP */
466 TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
471 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
472 * representing the register contents. This TCGv is an auto-freed
473 * temporary so it need not be explicitly freed, and may be modified.
475 TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
477 TCGv_i64 v
= new_tmp_a64(s
);
480 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
482 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
485 tcg_gen_movi_i64(v
, 0);
490 TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
492 TCGv_i64 v
= new_tmp_a64(s
);
494 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
496 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
501 /* Return the offset into CPUARMState of a slice (from
502 * the least significant end) of FP register Qn (ie
504 * (Note that this is not the same mapping as for A32; see cpu.h)
506 static inline int fp_reg_offset(DisasContext
*s
, int regno
, MemOp size
)
508 return vec_reg_offset(s
, regno
, 0, size
);
511 /* Offset of the high half of the 128 bit vector Qn */
512 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
514 return vec_reg_offset(s
, regno
, 1, MO_64
);
517 /* Convenience accessors for reading and writing single and double
518 * FP registers. Writing clears the upper parts of the associated
519 * 128 bit vector register, as required by the architecture.
520 * Note that unlike the GP register accessors, the values returned
521 * by the read functions must be manually freed.
523 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
525 TCGv_i64 v
= tcg_temp_new_i64();
527 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
531 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
533 TCGv_i32 v
= tcg_temp_new_i32();
535 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
539 static TCGv_i32
read_fp_hreg(DisasContext
*s
, int reg
)
541 TCGv_i32 v
= tcg_temp_new_i32();
543 tcg_gen_ld16u_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_16
));
547 /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64).
548 * If SVE is not enabled, then there are only 128 bits in the vector.
550 static void clear_vec_high(DisasContext
*s
, bool is_q
, int rd
)
552 unsigned ofs
= fp_reg_offset(s
, rd
, MO_64
);
553 unsigned vsz
= vec_full_reg_size(s
);
555 /* Nop move, with side effect of clearing the tail. */
556 tcg_gen_gvec_mov(MO_64
, ofs
, ofs
, is_q
? 16 : 8, vsz
);
559 void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
561 unsigned ofs
= fp_reg_offset(s
, reg
, MO_64
);
563 tcg_gen_st_i64(v
, cpu_env
, ofs
);
564 clear_vec_high(s
, false, reg
);
567 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
569 TCGv_i64 tmp
= tcg_temp_new_i64();
571 tcg_gen_extu_i32_i64(tmp
, v
);
572 write_fp_dreg(s
, reg
, tmp
);
573 tcg_temp_free_i64(tmp
);
576 /* Expand a 2-operand AdvSIMD vector operation using an expander function. */
577 static void gen_gvec_fn2(DisasContext
*s
, bool is_q
, int rd
, int rn
,
578 GVecGen2Fn
*gvec_fn
, int vece
)
580 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
581 is_q
? 16 : 8, vec_full_reg_size(s
));
584 /* Expand a 2-operand + immediate AdvSIMD vector operation using
585 * an expander function.
587 static void gen_gvec_fn2i(DisasContext
*s
, bool is_q
, int rd
, int rn
,
588 int64_t imm
, GVecGen2iFn
*gvec_fn
, int vece
)
590 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
591 imm
, is_q
? 16 : 8, vec_full_reg_size(s
));
594 /* Expand a 3-operand AdvSIMD vector operation using an expander function. */
595 static void gen_gvec_fn3(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
596 GVecGen3Fn
*gvec_fn
, int vece
)
598 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
599 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8, vec_full_reg_size(s
));
602 /* Expand a 4-operand AdvSIMD vector operation using an expander function. */
603 static void gen_gvec_fn4(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
604 int rx
, GVecGen4Fn
*gvec_fn
, int vece
)
606 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
607 vec_full_reg_offset(s
, rm
), vec_full_reg_offset(s
, rx
),
608 is_q
? 16 : 8, vec_full_reg_size(s
));
611 /* Expand a 2-operand operation using an out-of-line helper. */
612 static void gen_gvec_op2_ool(DisasContext
*s
, bool is_q
, int rd
,
613 int rn
, int data
, gen_helper_gvec_2
*fn
)
615 tcg_gen_gvec_2_ool(vec_full_reg_offset(s
, rd
),
616 vec_full_reg_offset(s
, rn
),
617 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
620 /* Expand a 3-operand operation using an out-of-line helper. */
621 static void gen_gvec_op3_ool(DisasContext
*s
, bool is_q
, int rd
,
622 int rn
, int rm
, int data
, gen_helper_gvec_3
*fn
)
624 tcg_gen_gvec_3_ool(vec_full_reg_offset(s
, rd
),
625 vec_full_reg_offset(s
, rn
),
626 vec_full_reg_offset(s
, rm
),
627 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
630 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
631 * an out-of-line helper.
633 static void gen_gvec_op3_fpst(DisasContext
*s
, bool is_q
, int rd
, int rn
,
634 int rm
, bool is_fp16
, int data
,
635 gen_helper_gvec_3_ptr
*fn
)
637 TCGv_ptr fpst
= fpstatus_ptr(is_fp16
? FPST_FPCR_F16
: FPST_FPCR
);
638 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
639 vec_full_reg_offset(s
, rn
),
640 vec_full_reg_offset(s
, rm
), fpst
,
641 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
642 tcg_temp_free_ptr(fpst
);
645 /* Expand a 3-operand + qc + operation using an out-of-line helper. */
646 static void gen_gvec_op3_qc(DisasContext
*s
, bool is_q
, int rd
, int rn
,
647 int rm
, gen_helper_gvec_3_ptr
*fn
)
649 TCGv_ptr qc_ptr
= tcg_temp_new_ptr();
651 tcg_gen_addi_ptr(qc_ptr
, cpu_env
, offsetof(CPUARMState
, vfp
.qc
));
652 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
653 vec_full_reg_offset(s
, rn
),
654 vec_full_reg_offset(s
, rm
), qc_ptr
,
655 is_q
? 16 : 8, vec_full_reg_size(s
), 0, fn
);
656 tcg_temp_free_ptr(qc_ptr
);
659 /* Expand a 4-operand operation using an out-of-line helper. */
660 static void gen_gvec_op4_ool(DisasContext
*s
, bool is_q
, int rd
, int rn
,
661 int rm
, int ra
, int data
, gen_helper_gvec_4
*fn
)
663 tcg_gen_gvec_4_ool(vec_full_reg_offset(s
, rd
),
664 vec_full_reg_offset(s
, rn
),
665 vec_full_reg_offset(s
, rm
),
666 vec_full_reg_offset(s
, ra
),
667 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
671 * Expand a 4-operand + fpstatus pointer + simd data value operation using
672 * an out-of-line helper.
674 static void gen_gvec_op4_fpst(DisasContext
*s
, bool is_q
, int rd
, int rn
,
675 int rm
, int ra
, bool is_fp16
, int data
,
676 gen_helper_gvec_4_ptr
*fn
)
678 TCGv_ptr fpst
= fpstatus_ptr(is_fp16
? FPST_FPCR_F16
: FPST_FPCR
);
679 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s
, rd
),
680 vec_full_reg_offset(s
, rn
),
681 vec_full_reg_offset(s
, rm
),
682 vec_full_reg_offset(s
, ra
), fpst
,
683 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
684 tcg_temp_free_ptr(fpst
);
687 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
688 * than the 32 bit equivalent.
690 static inline void gen_set_NZ64(TCGv_i64 result
)
692 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
693 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
696 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
697 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
700 gen_set_NZ64(result
);
702 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
703 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
705 tcg_gen_movi_i32(cpu_CF
, 0);
706 tcg_gen_movi_i32(cpu_VF
, 0);
709 /* dest = T0 + T1; compute C, N, V and Z flags */
710 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
713 TCGv_i64 result
, flag
, tmp
;
714 result
= tcg_temp_new_i64();
715 flag
= tcg_temp_new_i64();
716 tmp
= tcg_temp_new_i64();
718 tcg_gen_movi_i64(tmp
, 0);
719 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
721 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
723 gen_set_NZ64(result
);
725 tcg_gen_xor_i64(flag
, result
, t0
);
726 tcg_gen_xor_i64(tmp
, t0
, t1
);
727 tcg_gen_andc_i64(flag
, flag
, tmp
);
728 tcg_temp_free_i64(tmp
);
729 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
731 tcg_gen_mov_i64(dest
, result
);
732 tcg_temp_free_i64(result
);
733 tcg_temp_free_i64(flag
);
735 /* 32 bit arithmetic */
736 TCGv_i32 t0_32
= tcg_temp_new_i32();
737 TCGv_i32 t1_32
= tcg_temp_new_i32();
738 TCGv_i32 tmp
= tcg_temp_new_i32();
740 tcg_gen_movi_i32(tmp
, 0);
741 tcg_gen_extrl_i64_i32(t0_32
, t0
);
742 tcg_gen_extrl_i64_i32(t1_32
, t1
);
743 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
744 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
745 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
746 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
747 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
748 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
750 tcg_temp_free_i32(tmp
);
751 tcg_temp_free_i32(t0_32
);
752 tcg_temp_free_i32(t1_32
);
756 /* dest = T0 - T1; compute C, N, V and Z flags */
757 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
760 /* 64 bit arithmetic */
761 TCGv_i64 result
, flag
, tmp
;
763 result
= tcg_temp_new_i64();
764 flag
= tcg_temp_new_i64();
765 tcg_gen_sub_i64(result
, t0
, t1
);
767 gen_set_NZ64(result
);
769 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
770 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
772 tcg_gen_xor_i64(flag
, result
, t0
);
773 tmp
= tcg_temp_new_i64();
774 tcg_gen_xor_i64(tmp
, t0
, t1
);
775 tcg_gen_and_i64(flag
, flag
, tmp
);
776 tcg_temp_free_i64(tmp
);
777 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
778 tcg_gen_mov_i64(dest
, result
);
779 tcg_temp_free_i64(flag
);
780 tcg_temp_free_i64(result
);
782 /* 32 bit arithmetic */
783 TCGv_i32 t0_32
= tcg_temp_new_i32();
784 TCGv_i32 t1_32
= tcg_temp_new_i32();
787 tcg_gen_extrl_i64_i32(t0_32
, t0
);
788 tcg_gen_extrl_i64_i32(t1_32
, t1
);
789 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
790 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
791 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
792 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
793 tmp
= tcg_temp_new_i32();
794 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
795 tcg_temp_free_i32(t0_32
);
796 tcg_temp_free_i32(t1_32
);
797 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
798 tcg_temp_free_i32(tmp
);
799 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
803 /* dest = T0 + T1 + CF; do not compute flags. */
804 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
806 TCGv_i64 flag
= tcg_temp_new_i64();
807 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
808 tcg_gen_add_i64(dest
, t0
, t1
);
809 tcg_gen_add_i64(dest
, dest
, flag
);
810 tcg_temp_free_i64(flag
);
813 tcg_gen_ext32u_i64(dest
, dest
);
817 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
818 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
821 TCGv_i64 result
= tcg_temp_new_i64();
822 TCGv_i64 cf_64
= tcg_temp_new_i64();
823 TCGv_i64 vf_64
= tcg_temp_new_i64();
824 TCGv_i64 tmp
= tcg_temp_new_i64();
825 TCGv_i64 zero
= tcg_constant_i64(0);
827 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
828 tcg_gen_add2_i64(result
, cf_64
, t0
, zero
, cf_64
, zero
);
829 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, zero
);
830 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
831 gen_set_NZ64(result
);
833 tcg_gen_xor_i64(vf_64
, result
, t0
);
834 tcg_gen_xor_i64(tmp
, t0
, t1
);
835 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
836 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
838 tcg_gen_mov_i64(dest
, result
);
840 tcg_temp_free_i64(tmp
);
841 tcg_temp_free_i64(vf_64
);
842 tcg_temp_free_i64(cf_64
);
843 tcg_temp_free_i64(result
);
845 TCGv_i32 t0_32
= tcg_temp_new_i32();
846 TCGv_i32 t1_32
= tcg_temp_new_i32();
847 TCGv_i32 tmp
= tcg_temp_new_i32();
848 TCGv_i32 zero
= tcg_constant_i32(0);
850 tcg_gen_extrl_i64_i32(t0_32
, t0
);
851 tcg_gen_extrl_i64_i32(t1_32
, t1
);
852 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, zero
, cpu_CF
, zero
);
853 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, zero
);
855 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
856 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
857 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
858 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
859 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
861 tcg_temp_free_i32(tmp
);
862 tcg_temp_free_i32(t1_32
);
863 tcg_temp_free_i32(t0_32
);
868 * Load/Store generators
872 * Store from GPR register to memory.
874 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
875 TCGv_i64 tcg_addr
, MemOp memop
, int memidx
,
877 unsigned int iss_srt
,
878 bool iss_sf
, bool iss_ar
)
880 memop
= finalize_memop(s
, memop
);
881 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, memop
);
886 syn
= syn_data_abort_with_iss(0,
892 0, 0, 0, 0, 0, false);
893 disas_set_insn_syndrome(s
, syn
);
897 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
898 TCGv_i64 tcg_addr
, MemOp memop
,
900 unsigned int iss_srt
,
901 bool iss_sf
, bool iss_ar
)
903 do_gpr_st_memidx(s
, source
, tcg_addr
, memop
, get_mem_index(s
),
904 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
908 * Load from memory to GPR register
910 static void do_gpr_ld_memidx(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
911 MemOp memop
, bool extend
, int memidx
,
912 bool iss_valid
, unsigned int iss_srt
,
913 bool iss_sf
, bool iss_ar
)
915 memop
= finalize_memop(s
, memop
);
916 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
918 if (extend
&& (memop
& MO_SIGN
)) {
919 g_assert((memop
& MO_SIZE
) <= MO_32
);
920 tcg_gen_ext32u_i64(dest
, dest
);
926 syn
= syn_data_abort_with_iss(0,
928 (memop
& MO_SIGN
) != 0,
932 0, 0, 0, 0, 0, false);
933 disas_set_insn_syndrome(s
, syn
);
937 static void do_gpr_ld(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
938 MemOp memop
, bool extend
,
939 bool iss_valid
, unsigned int iss_srt
,
940 bool iss_sf
, bool iss_ar
)
942 do_gpr_ld_memidx(s
, dest
, tcg_addr
, memop
, extend
, get_mem_index(s
),
943 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
947 * Store from FP register to memory
949 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
951 /* This writes the bottom N bits of a 128 bit wide vector to memory */
952 TCGv_i64 tmplo
= tcg_temp_new_i64();
955 tcg_gen_ld_i64(tmplo
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
958 mop
= finalize_memop(s
, size
);
959 tcg_gen_qemu_st_i64(tmplo
, tcg_addr
, get_mem_index(s
), mop
);
961 bool be
= s
->be_data
== MO_BE
;
962 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
963 TCGv_i64 tmphi
= tcg_temp_new_i64();
965 tcg_gen_ld_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
967 mop
= s
->be_data
| MO_UQ
;
968 tcg_gen_qemu_st_i64(be
? tmphi
: tmplo
, tcg_addr
, get_mem_index(s
),
969 mop
| (s
->align_mem
? MO_ALIGN_16
: 0));
970 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
971 tcg_gen_qemu_st_i64(be
? tmplo
: tmphi
, tcg_hiaddr
,
972 get_mem_index(s
), mop
);
974 tcg_temp_free_i64(tcg_hiaddr
);
975 tcg_temp_free_i64(tmphi
);
978 tcg_temp_free_i64(tmplo
);
982 * Load from memory to FP register
984 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
986 /* This always zero-extends and writes to a full 128 bit wide vector */
987 TCGv_i64 tmplo
= tcg_temp_new_i64();
988 TCGv_i64 tmphi
= NULL
;
992 mop
= finalize_memop(s
, size
);
993 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), mop
);
995 bool be
= s
->be_data
== MO_BE
;
998 tmphi
= tcg_temp_new_i64();
999 tcg_hiaddr
= tcg_temp_new_i64();
1001 mop
= s
->be_data
| MO_UQ
;
1002 tcg_gen_qemu_ld_i64(be
? tmphi
: tmplo
, tcg_addr
, get_mem_index(s
),
1003 mop
| (s
->align_mem
? MO_ALIGN_16
: 0));
1004 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
1005 tcg_gen_qemu_ld_i64(be
? tmplo
: tmphi
, tcg_hiaddr
,
1006 get_mem_index(s
), mop
);
1007 tcg_temp_free_i64(tcg_hiaddr
);
1010 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
1011 tcg_temp_free_i64(tmplo
);
1014 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
1015 tcg_temp_free_i64(tmphi
);
1017 clear_vec_high(s
, tmphi
!= NULL
, destidx
);
1021 * Vector load/store helpers.
1023 * The principal difference between this and a FP load is that we don't
1024 * zero extend as we are filling a partial chunk of the vector register.
1025 * These functions don't support 128 bit loads/stores, which would be
1026 * normal load/store operations.
1028 * The _i32 versions are useful when operating on 32 bit quantities
1029 * (eg for floating point single or using Neon helper functions).
1032 /* Get value of an element within a vector register */
1033 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
1034 int element
, MemOp memop
)
1036 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1037 switch ((unsigned)memop
) {
1039 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
1042 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
1045 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
1048 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
1051 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
1054 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
1058 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
1061 g_assert_not_reached();
1065 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
1066 int element
, MemOp memop
)
1068 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1071 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
1074 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
1077 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
1080 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
1084 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
1087 g_assert_not_reached();
1091 /* Set value of an element within a vector register */
1092 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
1093 int element
, MemOp memop
)
1095 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1098 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
1101 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
1104 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
1107 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
1110 g_assert_not_reached();
1114 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
1115 int destidx
, int element
, MemOp memop
)
1117 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1120 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
1123 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
1126 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
1129 g_assert_not_reached();
1133 /* Store from vector register to memory */
1134 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
1135 TCGv_i64 tcg_addr
, MemOp mop
)
1137 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1139 read_vec_element(s
, tcg_tmp
, srcidx
, element
, mop
& MO_SIZE
);
1140 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), mop
);
1142 tcg_temp_free_i64(tcg_tmp
);
1145 /* Load from memory to vector register */
1146 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
1147 TCGv_i64 tcg_addr
, MemOp mop
)
1149 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1151 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), mop
);
1152 write_vec_element(s
, tcg_tmp
, destidx
, element
, mop
& MO_SIZE
);
1154 tcg_temp_free_i64(tcg_tmp
);
1157 /* Check that FP/Neon access is enabled. If it is, return
1158 * true. If not, emit code to generate an appropriate exception,
1159 * and return false; the caller should not emit any code for
1160 * the instruction. Note that this check must happen after all
1161 * unallocated-encoding checks (otherwise the syndrome information
1162 * for the resulting exception will be incorrect).
1164 static bool fp_access_check_only(DisasContext
*s
)
1166 if (s
->fp_excp_el
) {
1167 assert(!s
->fp_access_checked
);
1168 s
->fp_access_checked
= true;
1170 gen_exception_insn_el(s
, 0, EXCP_UDEF
,
1171 syn_fp_access_trap(1, 0xe, false, 0),
1175 s
->fp_access_checked
= true;
1179 static bool fp_access_check(DisasContext
*s
)
1181 if (!fp_access_check_only(s
)) {
1184 if (s
->sme_trap_nonstreaming
&& s
->is_nonstreaming
) {
1185 gen_exception_insn(s
, 0, EXCP_UDEF
,
1186 syn_smetrap(SME_ET_Streaming
, false));
1193 * Check that SVE access is enabled. If it is, return true.
1194 * If not, emit code to generate an appropriate exception and return false.
1195 * This function corresponds to CheckSVEEnabled().
1197 bool sve_access_check(DisasContext
*s
)
1199 if (s
->pstate_sm
|| !dc_isar_feature(aa64_sve
, s
)) {
1200 assert(dc_isar_feature(aa64_sme
, s
));
1201 if (!sme_sm_enabled_check(s
)) {
1204 } else if (s
->sve_excp_el
) {
1205 gen_exception_insn_el(s
, 0, EXCP_UDEF
,
1206 syn_sve_access_trap(), s
->sve_excp_el
);
1209 s
->sve_access_checked
= true;
1210 return fp_access_check(s
);
1213 /* Assert that we only raise one exception per instruction. */
1214 assert(!s
->sve_access_checked
);
1215 s
->sve_access_checked
= true;
1220 * Check that SME access is enabled, raise an exception if not.
1221 * Note that this function corresponds to CheckSMEAccess and is
1222 * only used directly for cpregs.
1224 static bool sme_access_check(DisasContext
*s
)
1226 if (s
->sme_excp_el
) {
1227 gen_exception_insn_el(s
, 0, EXCP_UDEF
,
1228 syn_smetrap(SME_ET_AccessTrap
, false),
1235 /* This function corresponds to CheckSMEEnabled. */
1236 bool sme_enabled_check(DisasContext
*s
)
1239 * Note that unlike sve_excp_el, we have not constrained sme_excp_el
1240 * to be zero when fp_excp_el has priority. This is because we need
1241 * sme_excp_el by itself for cpregs access checks.
1243 if (!s
->fp_excp_el
|| s
->sme_excp_el
< s
->fp_excp_el
) {
1244 s
->fp_access_checked
= true;
1245 return sme_access_check(s
);
1247 return fp_access_check_only(s
);
1250 /* Common subroutine for CheckSMEAnd*Enabled. */
1251 bool sme_enabled_check_with_svcr(DisasContext
*s
, unsigned req
)
1253 if (!sme_enabled_check(s
)) {
1256 if (FIELD_EX64(req
, SVCR
, SM
) && !s
->pstate_sm
) {
1257 gen_exception_insn(s
, 0, EXCP_UDEF
,
1258 syn_smetrap(SME_ET_NotStreaming
, false));
1261 if (FIELD_EX64(req
, SVCR
, ZA
) && !s
->pstate_za
) {
1262 gen_exception_insn(s
, 0, EXCP_UDEF
,
1263 syn_smetrap(SME_ET_InactiveZA
, false));
1270 * This utility function is for doing register extension with an
1271 * optional shift. You will likely want to pass a temporary for the
1272 * destination register. See DecodeRegExtend() in the ARM ARM.
1274 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1275 int option
, unsigned int shift
)
1277 int extsize
= extract32(option
, 0, 2);
1278 bool is_signed
= extract32(option
, 2, 1);
1283 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1286 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1289 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1292 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1298 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1301 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1304 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1307 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1313 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1317 static inline void gen_check_sp_alignment(DisasContext
*s
)
1319 /* The AArch64 architecture mandates that (if enabled via PSTATE
1320 * or SCTLR bits) there is a check that SP is 16-aligned on every
1321 * SP-relative load or store (with an exception generated if it is not).
1322 * In line with general QEMU practice regarding misaligned accesses,
1323 * we omit these checks for the sake of guest program performance.
1324 * This function is provided as a hook so we can more easily add these
1325 * checks in future (possibly as a "favour catching guest program bugs
1326 * over speed" user selectable option).
1331 * This provides a simple table based table lookup decoder. It is
1332 * intended to be used when the relevant bits for decode are too
1333 * awkwardly placed and switch/if based logic would be confusing and
1334 * deeply nested. Since it's a linear search through the table, tables
1335 * should be kept small.
1337 * It returns the first handler where insn & mask == pattern, or
1338 * NULL if there is no match.
1339 * The table is terminated by an empty mask (i.e. 0)
1341 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1344 const AArch64DecodeTable
*tptr
= table
;
1346 while (tptr
->mask
) {
1347 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1348 return tptr
->disas_fn
;
1356 * The instruction disassembly implemented here matches
1357 * the instruction encoding classifications in chapter C4
1358 * of the ARM Architecture Reference Manual (DDI0487B_a);
1359 * classification names and decode diagrams here should generally
1360 * match up with those in the manual.
1363 /* Unconditional branch (immediate)
1365 * +----+-----------+-------------------------------------+
1366 * | op | 0 0 1 0 1 | imm26 |
1367 * +----+-----------+-------------------------------------+
1369 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1371 int64_t diff
= sextract32(insn
, 0, 26) * 4;
1373 if (insn
& (1U << 31)) {
1374 /* BL Branch with link */
1375 gen_pc_plus_diff(s
, cpu_reg(s
, 30), curr_insn_len(s
));
1378 /* B Branch / BL Branch with link */
1380 gen_goto_tb(s
, 0, diff
);
1383 /* Compare and branch (immediate)
1384 * 31 30 25 24 23 5 4 0
1385 * +----+-------------+----+---------------------+--------+
1386 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1387 * +----+-------------+----+---------------------+--------+
1389 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1391 unsigned int sf
, op
, rt
;
1396 sf
= extract32(insn
, 31, 1);
1397 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1398 rt
= extract32(insn
, 0, 5);
1399 diff
= sextract32(insn
, 5, 19) * 4;
1401 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1404 match
= gen_disas_label(s
);
1405 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1406 tcg_cmp
, 0, match
.label
);
1407 gen_goto_tb(s
, 0, 4);
1408 set_disas_label(s
, match
);
1409 gen_goto_tb(s
, 1, diff
);
1412 /* Test and branch (immediate)
1413 * 31 30 25 24 23 19 18 5 4 0
1414 * +----+-------------+----+-------+-------------+------+
1415 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1416 * +----+-------------+----+-------+-------------+------+
1418 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1420 unsigned int bit_pos
, op
, rt
;
1425 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1426 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1427 diff
= sextract32(insn
, 5, 14) * 4;
1428 rt
= extract32(insn
, 0, 5);
1430 tcg_cmp
= tcg_temp_new_i64();
1431 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1435 match
= gen_disas_label(s
);
1436 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1437 tcg_cmp
, 0, match
.label
);
1438 tcg_temp_free_i64(tcg_cmp
);
1439 gen_goto_tb(s
, 0, 4);
1440 set_disas_label(s
, match
);
1441 gen_goto_tb(s
, 1, diff
);
1444 /* Conditional branch (immediate)
1445 * 31 25 24 23 5 4 3 0
1446 * +---------------+----+---------------------+----+------+
1447 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1448 * +---------------+----+---------------------+----+------+
1450 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1455 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1456 unallocated_encoding(s
);
1459 diff
= sextract32(insn
, 5, 19) * 4;
1460 cond
= extract32(insn
, 0, 4);
1464 /* genuinely conditional branches */
1465 DisasLabel match
= gen_disas_label(s
);
1466 arm_gen_test_cc(cond
, match
.label
);
1467 gen_goto_tb(s
, 0, 4);
1468 set_disas_label(s
, match
);
1469 gen_goto_tb(s
, 1, diff
);
1471 /* 0xe and 0xf are both "always" conditions */
1472 gen_goto_tb(s
, 0, diff
);
1476 /* HINT instruction group, including various allocated HINTs */
1477 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1478 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1480 unsigned int selector
= crm
<< 3 | op2
;
1483 unallocated_encoding(s
);
1488 case 0b00000: /* NOP */
1490 case 0b00011: /* WFI */
1491 s
->base
.is_jmp
= DISAS_WFI
;
1493 case 0b00001: /* YIELD */
1494 /* When running in MTTCG we don't generate jumps to the yield and
1495 * WFE helpers as it won't affect the scheduling of other vCPUs.
1496 * If we wanted to more completely model WFE/SEV so we don't busy
1497 * spin unnecessarily we would need to do something more involved.
1499 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1500 s
->base
.is_jmp
= DISAS_YIELD
;
1503 case 0b00010: /* WFE */
1504 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1505 s
->base
.is_jmp
= DISAS_WFE
;
1508 case 0b00100: /* SEV */
1509 case 0b00101: /* SEVL */
1510 case 0b00110: /* DGH */
1511 /* we treat all as NOP at least for now */
1513 case 0b00111: /* XPACLRI */
1514 if (s
->pauth_active
) {
1515 gen_helper_xpaci(cpu_X
[30], cpu_env
, cpu_X
[30]);
1518 case 0b01000: /* PACIA1716 */
1519 if (s
->pauth_active
) {
1520 gen_helper_pacia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1523 case 0b01010: /* PACIB1716 */
1524 if (s
->pauth_active
) {
1525 gen_helper_pacib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1528 case 0b01100: /* AUTIA1716 */
1529 if (s
->pauth_active
) {
1530 gen_helper_autia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1533 case 0b01110: /* AUTIB1716 */
1534 if (s
->pauth_active
) {
1535 gen_helper_autib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1538 case 0b10000: /* ESB */
1539 /* Without RAS, we must implement this as NOP. */
1540 if (dc_isar_feature(aa64_ras
, s
)) {
1542 * QEMU does not have a source of physical SErrors,
1543 * so we are only concerned with virtual SErrors.
1544 * The pseudocode in the ARM for this case is
1545 * if PSTATE.EL IN {EL0, EL1} && EL2Enabled() then
1546 * AArch64.vESBOperation();
1547 * Most of the condition can be evaluated at translation time.
1548 * Test for EL2 present, and defer test for SEL2 to runtime.
1550 if (s
->current_el
<= 1 && arm_dc_feature(s
, ARM_FEATURE_EL2
)) {
1551 gen_helper_vesb(cpu_env
);
1555 case 0b11000: /* PACIAZ */
1556 if (s
->pauth_active
) {
1557 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30],
1558 new_tmp_a64_zero(s
));
1561 case 0b11001: /* PACIASP */
1562 if (s
->pauth_active
) {
1563 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1566 case 0b11010: /* PACIBZ */
1567 if (s
->pauth_active
) {
1568 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30],
1569 new_tmp_a64_zero(s
));
1572 case 0b11011: /* PACIBSP */
1573 if (s
->pauth_active
) {
1574 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1577 case 0b11100: /* AUTIAZ */
1578 if (s
->pauth_active
) {
1579 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30],
1580 new_tmp_a64_zero(s
));
1583 case 0b11101: /* AUTIASP */
1584 if (s
->pauth_active
) {
1585 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1588 case 0b11110: /* AUTIBZ */
1589 if (s
->pauth_active
) {
1590 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30],
1591 new_tmp_a64_zero(s
));
1594 case 0b11111: /* AUTIBSP */
1595 if (s
->pauth_active
) {
1596 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1600 /* default specified as NOP equivalent */
1605 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1607 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1610 /* CLREX, DSB, DMB, ISB */
1611 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1612 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1617 unallocated_encoding(s
);
1628 case 1: /* MBReqTypes_Reads */
1629 bar
= TCG_BAR_SC
| TCG_MO_LD_LD
| TCG_MO_LD_ST
;
1631 case 2: /* MBReqTypes_Writes */
1632 bar
= TCG_BAR_SC
| TCG_MO_ST_ST
;
1634 default: /* MBReqTypes_All */
1635 bar
= TCG_BAR_SC
| TCG_MO_ALL
;
1641 /* We need to break the TB after this insn to execute
1642 * a self-modified code correctly and also to take
1643 * any pending interrupts immediately.
1646 gen_goto_tb(s
, 0, 4);
1650 if (crm
!= 0 || !dc_isar_feature(aa64_sb
, s
)) {
1651 goto do_unallocated
;
1654 * TODO: There is no speculation barrier opcode for TCG;
1655 * MB and end the TB instead.
1657 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
1658 gen_goto_tb(s
, 0, 4);
1663 unallocated_encoding(s
);
1668 static void gen_xaflag(void)
1670 TCGv_i32 z
= tcg_temp_new_i32();
1672 tcg_gen_setcondi_i32(TCG_COND_EQ
, z
, cpu_ZF
, 0);
1681 tcg_gen_or_i32(cpu_NF
, cpu_CF
, z
);
1682 tcg_gen_subi_i32(cpu_NF
, cpu_NF
, 1);
1685 tcg_gen_and_i32(cpu_ZF
, z
, cpu_CF
);
1686 tcg_gen_xori_i32(cpu_ZF
, cpu_ZF
, 1);
1688 /* (!C & Z) << 31 -> -(Z & ~C) */
1689 tcg_gen_andc_i32(cpu_VF
, z
, cpu_CF
);
1690 tcg_gen_neg_i32(cpu_VF
, cpu_VF
);
1693 tcg_gen_or_i32(cpu_CF
, cpu_CF
, z
);
1695 tcg_temp_free_i32(z
);
1698 static void gen_axflag(void)
1700 tcg_gen_sari_i32(cpu_VF
, cpu_VF
, 31); /* V ? -1 : 0 */
1701 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, cpu_VF
); /* C & !V */
1703 /* !(Z | V) -> !(!ZF | V) -> ZF & !V -> ZF & ~VF */
1704 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, cpu_VF
);
1706 tcg_gen_movi_i32(cpu_NF
, 0);
1707 tcg_gen_movi_i32(cpu_VF
, 0);
1710 /* MSR (immediate) - move immediate to processor state field */
1711 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1712 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1714 int op
= op1
<< 3 | op2
;
1716 /* End the TB by default, chaining is ok. */
1717 s
->base
.is_jmp
= DISAS_TOO_MANY
;
1720 case 0x00: /* CFINV */
1721 if (crm
!= 0 || !dc_isar_feature(aa64_condm_4
, s
)) {
1722 goto do_unallocated
;
1724 tcg_gen_xori_i32(cpu_CF
, cpu_CF
, 1);
1725 s
->base
.is_jmp
= DISAS_NEXT
;
1728 case 0x01: /* XAFlag */
1729 if (crm
!= 0 || !dc_isar_feature(aa64_condm_5
, s
)) {
1730 goto do_unallocated
;
1733 s
->base
.is_jmp
= DISAS_NEXT
;
1736 case 0x02: /* AXFlag */
1737 if (crm
!= 0 || !dc_isar_feature(aa64_condm_5
, s
)) {
1738 goto do_unallocated
;
1741 s
->base
.is_jmp
= DISAS_NEXT
;
1744 case 0x03: /* UAO */
1745 if (!dc_isar_feature(aa64_uao
, s
) || s
->current_el
== 0) {
1746 goto do_unallocated
;
1749 set_pstate_bits(PSTATE_UAO
);
1751 clear_pstate_bits(PSTATE_UAO
);
1753 gen_rebuild_hflags(s
);
1756 case 0x04: /* PAN */
1757 if (!dc_isar_feature(aa64_pan
, s
) || s
->current_el
== 0) {
1758 goto do_unallocated
;
1761 set_pstate_bits(PSTATE_PAN
);
1763 clear_pstate_bits(PSTATE_PAN
);
1765 gen_rebuild_hflags(s
);
1768 case 0x05: /* SPSel */
1769 if (s
->current_el
== 0) {
1770 goto do_unallocated
;
1772 gen_helper_msr_i_spsel(cpu_env
, tcg_constant_i32(crm
& PSTATE_SP
));
1775 case 0x19: /* SSBS */
1776 if (!dc_isar_feature(aa64_ssbs
, s
)) {
1777 goto do_unallocated
;
1780 set_pstate_bits(PSTATE_SSBS
);
1782 clear_pstate_bits(PSTATE_SSBS
);
1784 /* Don't need to rebuild hflags since SSBS is a nop */
1787 case 0x1a: /* DIT */
1788 if (!dc_isar_feature(aa64_dit
, s
)) {
1789 goto do_unallocated
;
1792 set_pstate_bits(PSTATE_DIT
);
1794 clear_pstate_bits(PSTATE_DIT
);
1796 /* There's no need to rebuild hflags because DIT is a nop */
1799 case 0x1e: /* DAIFSet */
1800 gen_helper_msr_i_daifset(cpu_env
, tcg_constant_i32(crm
));
1803 case 0x1f: /* DAIFClear */
1804 gen_helper_msr_i_daifclear(cpu_env
, tcg_constant_i32(crm
));
1805 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1806 s
->base
.is_jmp
= DISAS_UPDATE_EXIT
;
1809 case 0x1c: /* TCO */
1810 if (dc_isar_feature(aa64_mte
, s
)) {
1811 /* Full MTE is enabled -- set the TCO bit as directed. */
1813 set_pstate_bits(PSTATE_TCO
);
1815 clear_pstate_bits(PSTATE_TCO
);
1817 gen_rebuild_hflags(s
);
1818 /* Many factors, including TCO, go into MTE_ACTIVE. */
1819 s
->base
.is_jmp
= DISAS_UPDATE_NOCHAIN
;
1820 } else if (dc_isar_feature(aa64_mte_insn_reg
, s
)) {
1821 /* Only "instructions accessible at EL0" -- PSTATE.TCO is WI. */
1822 s
->base
.is_jmp
= DISAS_NEXT
;
1824 goto do_unallocated
;
1828 case 0x1b: /* SVCR* */
1829 if (!dc_isar_feature(aa64_sme
, s
) || crm
< 2 || crm
> 7) {
1830 goto do_unallocated
;
1832 if (sme_access_check(s
)) {
1833 int old
= s
->pstate_sm
| (s
->pstate_za
<< 1);
1834 int new = (crm
& 1) * 3;
1835 int msk
= (crm
>> 1) & 3;
1837 if ((old
^ new) & msk
) {
1838 /* At least one bit changes. */
1839 gen_helper_set_svcr(cpu_env
, tcg_constant_i32(new),
1840 tcg_constant_i32(msk
));
1842 s
->base
.is_jmp
= DISAS_NEXT
;
1849 unallocated_encoding(s
);
1854 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1856 TCGv_i32 tmp
= tcg_temp_new_i32();
1857 TCGv_i32 nzcv
= tcg_temp_new_i32();
1859 /* build bit 31, N */
1860 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1861 /* build bit 30, Z */
1862 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1863 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1864 /* build bit 29, C */
1865 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1866 /* build bit 28, V */
1867 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1868 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1869 /* generate result */
1870 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1872 tcg_temp_free_i32(nzcv
);
1873 tcg_temp_free_i32(tmp
);
1876 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1878 TCGv_i32 nzcv
= tcg_temp_new_i32();
1880 /* take NZCV from R[t] */
1881 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1884 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1886 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1887 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1889 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1890 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1892 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1893 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1894 tcg_temp_free_i32(nzcv
);
1897 static void gen_sysreg_undef(DisasContext
*s
, bool isread
,
1898 uint8_t op0
, uint8_t op1
, uint8_t op2
,
1899 uint8_t crn
, uint8_t crm
, uint8_t rt
)
1902 * Generate code to emit an UNDEF with correct syndrome
1903 * information for a failed system register access.
1904 * This is EC_UNCATEGORIZED (ie a standard UNDEF) in most cases,
1905 * but if FEAT_IDST is implemented then read accesses to registers
1906 * in the feature ID space are reported with the EC_SYSTEMREGISTERTRAP
1911 if (isread
&& dc_isar_feature(aa64_ids
, s
) &&
1912 arm_cpreg_encoding_in_idspace(op0
, op1
, op2
, crn
, crm
)) {
1913 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1915 syndrome
= syn_uncategorized();
1917 gen_exception_insn(s
, 0, EXCP_UDEF
, syndrome
);
1920 /* MRS - move from system register
1921 * MSR (register) - move to system register
1924 * These are all essentially the same insn in 'read' and 'write'
1925 * versions, with varying op0 fields.
1927 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1928 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1929 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1931 uint32_t key
= ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1932 crn
, crm
, op0
, op1
, op2
);
1933 const ARMCPRegInfo
*ri
= get_arm_cp_reginfo(s
->cp_regs
, key
);
1934 TCGv_ptr tcg_ri
= NULL
;
1938 /* Unknown register; this might be a guest error or a QEMU
1939 * unimplemented feature.
1941 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1942 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1943 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1944 gen_sysreg_undef(s
, isread
, op0
, op1
, op2
, crn
, crm
, rt
);
1948 /* Check access permissions */
1949 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1950 gen_sysreg_undef(s
, isread
, op0
, op1
, op2
, crn
, crm
, rt
);
1954 if (ri
->accessfn
|| (ri
->fgt
&& s
->fgt_active
)) {
1955 /* Emit code to perform further access permissions checks at
1956 * runtime; this may result in an exception.
1960 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1961 gen_a64_update_pc(s
, 0);
1962 tcg_ri
= tcg_temp_new_ptr();
1963 gen_helper_access_check_cp_reg(tcg_ri
, cpu_env
,
1964 tcg_constant_i32(key
),
1965 tcg_constant_i32(syndrome
),
1966 tcg_constant_i32(isread
));
1967 } else if (ri
->type
& ARM_CP_RAISES_EXC
) {
1969 * The readfn or writefn might raise an exception;
1970 * synchronize the CPU state in case it does.
1972 gen_a64_update_pc(s
, 0);
1975 /* Handle special cases first */
1976 switch (ri
->type
& ARM_CP_SPECIAL_MASK
) {
1982 tcg_rt
= cpu_reg(s
, rt
);
1984 gen_get_nzcv(tcg_rt
);
1986 gen_set_nzcv(tcg_rt
);
1989 case ARM_CP_CURRENTEL
:
1990 /* Reads as current EL value from pstate, which is
1991 * guaranteed to be constant by the tb flags.
1993 tcg_rt
= cpu_reg(s
, rt
);
1994 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1997 /* Writes clear the aligned block of memory which rt points into. */
1998 if (s
->mte_active
[0]) {
2001 desc
= FIELD_DP32(desc
, MTEDESC
, MIDX
, get_mem_index(s
));
2002 desc
= FIELD_DP32(desc
, MTEDESC
, TBI
, s
->tbid
);
2003 desc
= FIELD_DP32(desc
, MTEDESC
, TCMA
, s
->tcma
);
2005 tcg_rt
= new_tmp_a64(s
);
2006 gen_helper_mte_check_zva(tcg_rt
, cpu_env
,
2007 tcg_constant_i32(desc
), cpu_reg(s
, rt
));
2009 tcg_rt
= clean_data_tbi(s
, cpu_reg(s
, rt
));
2011 gen_helper_dc_zva(cpu_env
, tcg_rt
);
2015 TCGv_i64 clean_addr
, tag
;
2018 * DC_GVA, like DC_ZVA, requires that we supply the original
2019 * pointer for an invalid page. Probe that address first.
2021 tcg_rt
= cpu_reg(s
, rt
);
2022 clean_addr
= clean_data_tbi(s
, tcg_rt
);
2023 gen_probe_access(s
, clean_addr
, MMU_DATA_STORE
, MO_8
);
2026 /* Extract the tag from the register to match STZGM. */
2027 tag
= tcg_temp_new_i64();
2028 tcg_gen_shri_i64(tag
, tcg_rt
, 56);
2029 gen_helper_stzgm_tags(cpu_env
, clean_addr
, tag
);
2030 tcg_temp_free_i64(tag
);
2034 case ARM_CP_DC_GZVA
:
2036 TCGv_i64 clean_addr
, tag
;
2038 /* For DC_GZVA, we can rely on DC_ZVA for the proper fault. */
2039 tcg_rt
= cpu_reg(s
, rt
);
2040 clean_addr
= clean_data_tbi(s
, tcg_rt
);
2041 gen_helper_dc_zva(cpu_env
, clean_addr
);
2044 /* Extract the tag from the register to match STZGM. */
2045 tag
= tcg_temp_new_i64();
2046 tcg_gen_shri_i64(tag
, tcg_rt
, 56);
2047 gen_helper_stzgm_tags(cpu_env
, clean_addr
, tag
);
2048 tcg_temp_free_i64(tag
);
2053 g_assert_not_reached();
2055 if ((ri
->type
& ARM_CP_FPU
) && !fp_access_check_only(s
)) {
2057 } else if ((ri
->type
& ARM_CP_SVE
) && !sve_access_check(s
)) {
2059 } else if ((ri
->type
& ARM_CP_SME
) && !sme_access_check(s
)) {
2063 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
2067 tcg_rt
= cpu_reg(s
, rt
);
2070 if (ri
->type
& ARM_CP_CONST
) {
2071 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
2072 } else if (ri
->readfn
) {
2074 tcg_ri
= gen_lookup_cp_reg(key
);
2076 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tcg_ri
);
2078 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
2081 if (ri
->type
& ARM_CP_CONST
) {
2082 /* If not forbidden by access permissions, treat as WI */
2084 } else if (ri
->writefn
) {
2086 tcg_ri
= gen_lookup_cp_reg(key
);
2088 gen_helper_set_cp_reg64(cpu_env
, tcg_ri
, tcg_rt
);
2090 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
2094 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
2095 /* I/O operations must end the TB here (whether read or write) */
2096 s
->base
.is_jmp
= DISAS_UPDATE_EXIT
;
2098 if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
2100 * A write to any coprocessor regiser that ends a TB
2101 * must rebuild the hflags for the next TB.
2103 gen_rebuild_hflags(s
);
2105 * We default to ending the TB on a coprocessor register write,
2106 * but allow this to be suppressed by the register definition
2107 * (usually only necessary to work around guest bugs).
2109 s
->base
.is_jmp
= DISAS_UPDATE_EXIT
;
2114 tcg_temp_free_ptr(tcg_ri
);
2119 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
2120 * +---------------------+---+-----+-----+-------+-------+-----+------+
2121 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
2122 * +---------------------+---+-----+-----+-------+-------+-----+------+
2124 static void disas_system(DisasContext
*s
, uint32_t insn
)
2126 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
2127 l
= extract32(insn
, 21, 1);
2128 op0
= extract32(insn
, 19, 2);
2129 op1
= extract32(insn
, 16, 3);
2130 crn
= extract32(insn
, 12, 4);
2131 crm
= extract32(insn
, 8, 4);
2132 op2
= extract32(insn
, 5, 3);
2133 rt
= extract32(insn
, 0, 5);
2136 if (l
|| rt
!= 31) {
2137 unallocated_encoding(s
);
2141 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
2142 handle_hint(s
, insn
, op1
, op2
, crm
);
2144 case 3: /* CLREX, DSB, DMB, ISB */
2145 handle_sync(s
, insn
, op1
, op2
, crm
);
2147 case 4: /* MSR (immediate) */
2148 handle_msr_i(s
, insn
, op1
, op2
, crm
);
2151 unallocated_encoding(s
);
2156 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
2159 /* Exception generation
2161 * 31 24 23 21 20 5 4 2 1 0
2162 * +-----------------+-----+------------------------+-----+----+
2163 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
2164 * +-----------------------+------------------------+----------+
2166 static void disas_exc(DisasContext
*s
, uint32_t insn
)
2168 int opc
= extract32(insn
, 21, 3);
2169 int op2_ll
= extract32(insn
, 0, 5);
2170 int imm16
= extract32(insn
, 5, 16);
2175 /* For SVC, HVC and SMC we advance the single-step state
2176 * machine before taking the exception. This is architecturally
2177 * mandated, to ensure that single-stepping a system call
2178 * instruction works properly.
2182 syndrome
= syn_aa64_svc(imm16
);
2184 gen_exception_insn_el(s
, 0, EXCP_UDEF
, syndrome
, 2);
2188 gen_exception_insn(s
, 4, EXCP_SWI
, syndrome
);
2191 if (s
->current_el
== 0) {
2192 unallocated_encoding(s
);
2195 /* The pre HVC helper handles cases when HVC gets trapped
2196 * as an undefined insn by runtime configuration.
2198 gen_a64_update_pc(s
, 0);
2199 gen_helper_pre_hvc(cpu_env
);
2201 gen_exception_insn_el(s
, 4, EXCP_HVC
, syn_aa64_hvc(imm16
), 2);
2204 if (s
->current_el
== 0) {
2205 unallocated_encoding(s
);
2208 gen_a64_update_pc(s
, 0);
2209 gen_helper_pre_smc(cpu_env
, tcg_constant_i32(syn_aa64_smc(imm16
)));
2211 gen_exception_insn_el(s
, 4, EXCP_SMC
, syn_aa64_smc(imm16
), 3);
2214 unallocated_encoding(s
);
2220 unallocated_encoding(s
);
2224 gen_exception_bkpt_insn(s
, syn_aa64_bkpt(imm16
));
2228 unallocated_encoding(s
);
2231 /* HLT. This has two purposes.
2232 * Architecturally, it is an external halting debug instruction.
2233 * Since QEMU doesn't implement external debug, we treat this as
2234 * it is required for halting debug disabled: it will UNDEF.
2235 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
2237 if (semihosting_enabled(s
->current_el
== 0) && imm16
== 0xf000) {
2238 gen_exception_internal_insn(s
, EXCP_SEMIHOST
);
2240 unallocated_encoding(s
);
2244 if (op2_ll
< 1 || op2_ll
> 3) {
2245 unallocated_encoding(s
);
2248 /* DCPS1, DCPS2, DCPS3 */
2249 unallocated_encoding(s
);
2252 unallocated_encoding(s
);
2257 /* Unconditional branch (register)
2258 * 31 25 24 21 20 16 15 10 9 5 4 0
2259 * +---------------+-------+-------+-------+------+-------+
2260 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
2261 * +---------------+-------+-------+-------+------+-------+
2263 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
2265 unsigned int opc
, op2
, op3
, rn
, op4
;
2266 unsigned btype_mod
= 2; /* 0: BR, 1: BLR, 2: other */
2270 opc
= extract32(insn
, 21, 4);
2271 op2
= extract32(insn
, 16, 5);
2272 op3
= extract32(insn
, 10, 6);
2273 rn
= extract32(insn
, 5, 5);
2274 op4
= extract32(insn
, 0, 5);
2277 goto do_unallocated
;
2289 goto do_unallocated
;
2291 dst
= cpu_reg(s
, rn
);
2296 if (!dc_isar_feature(aa64_pauth
, s
)) {
2297 goto do_unallocated
;
2301 if (rn
!= 0x1f || op4
!= 0x1f) {
2302 goto do_unallocated
;
2305 modifier
= cpu_X
[31];
2307 /* BRAAZ, BRABZ, BLRAAZ, BLRABZ */
2309 goto do_unallocated
;
2311 modifier
= new_tmp_a64_zero(s
);
2313 if (s
->pauth_active
) {
2314 dst
= new_tmp_a64(s
);
2316 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2318 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2321 dst
= cpu_reg(s
, rn
);
2326 goto do_unallocated
;
2328 /* BLR also needs to load return address */
2330 TCGv_i64 lr
= cpu_reg(s
, 30);
2332 TCGv_i64 tmp
= new_tmp_a64(s
);
2333 tcg_gen_mov_i64(tmp
, dst
);
2336 gen_pc_plus_diff(s
, lr
, curr_insn_len(s
));
2338 gen_a64_set_pc(s
, dst
);
2343 if (!dc_isar_feature(aa64_pauth
, s
)) {
2344 goto do_unallocated
;
2346 if ((op3
& ~1) != 2) {
2347 goto do_unallocated
;
2349 btype_mod
= opc
& 1;
2350 if (s
->pauth_active
) {
2351 dst
= new_tmp_a64(s
);
2352 modifier
= cpu_reg_sp(s
, op4
);
2354 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2356 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2359 dst
= cpu_reg(s
, rn
);
2361 /* BLRAA also needs to load return address */
2363 TCGv_i64 lr
= cpu_reg(s
, 30);
2365 TCGv_i64 tmp
= new_tmp_a64(s
);
2366 tcg_gen_mov_i64(tmp
, dst
);
2369 gen_pc_plus_diff(s
, lr
, curr_insn_len(s
));
2371 gen_a64_set_pc(s
, dst
);
2375 if (s
->current_el
== 0) {
2376 goto do_unallocated
;
2381 goto do_unallocated
;
2384 gen_exception_insn_el(s
, 0, EXCP_UDEF
, syn_erettrap(op3
), 2);
2387 dst
= tcg_temp_new_i64();
2388 tcg_gen_ld_i64(dst
, cpu_env
,
2389 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2392 case 2: /* ERETAA */
2393 case 3: /* ERETAB */
2394 if (!dc_isar_feature(aa64_pauth
, s
)) {
2395 goto do_unallocated
;
2397 if (rn
!= 0x1f || op4
!= 0x1f) {
2398 goto do_unallocated
;
2400 /* The FGT trap takes precedence over an auth trap. */
2402 gen_exception_insn_el(s
, 0, EXCP_UDEF
, syn_erettrap(op3
), 2);
2405 dst
= tcg_temp_new_i64();
2406 tcg_gen_ld_i64(dst
, cpu_env
,
2407 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2408 if (s
->pauth_active
) {
2409 modifier
= cpu_X
[31];
2411 gen_helper_autia(dst
, cpu_env
, dst
, modifier
);
2413 gen_helper_autib(dst
, cpu_env
, dst
, modifier
);
2419 goto do_unallocated
;
2421 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
2425 gen_helper_exception_return(cpu_env
, dst
);
2426 tcg_temp_free_i64(dst
);
2427 /* Must exit loop to check un-masked IRQs */
2428 s
->base
.is_jmp
= DISAS_EXIT
;
2432 if (op3
!= 0 || op4
!= 0 || rn
!= 0x1f) {
2433 goto do_unallocated
;
2435 unallocated_encoding(s
);
2441 unallocated_encoding(s
);
2445 switch (btype_mod
) {
2447 if (dc_isar_feature(aa64_bti
, s
)) {
2448 /* BR to {x16,x17} or !guard -> 1, else 3. */
2449 set_btype(s
, rn
== 16 || rn
== 17 || !s
->guarded_page
? 1 : 3);
2454 if (dc_isar_feature(aa64_bti
, s
)) {
2455 /* BLR sets BTYPE to 2, regardless of source guarded page. */
2460 default: /* RET or none of the above. */
2461 /* BTYPE will be set to 0 by normal end-of-insn processing. */
2465 s
->base
.is_jmp
= DISAS_JUMP
;
2468 /* Branches, exception generating and system instructions */
2469 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
2471 switch (extract32(insn
, 25, 7)) {
2472 case 0x0a: case 0x0b:
2473 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
2474 disas_uncond_b_imm(s
, insn
);
2476 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
2477 disas_comp_b_imm(s
, insn
);
2479 case 0x1b: case 0x5b: /* Test & branch (immediate) */
2480 disas_test_b_imm(s
, insn
);
2482 case 0x2a: /* Conditional branch (immediate) */
2483 disas_cond_b_imm(s
, insn
);
2485 case 0x6a: /* Exception generation / System */
2486 if (insn
& (1 << 24)) {
2487 if (extract32(insn
, 22, 2) == 0) {
2488 disas_system(s
, insn
);
2490 unallocated_encoding(s
);
2496 case 0x6b: /* Unconditional branch (register) */
2497 disas_uncond_b_reg(s
, insn
);
2500 unallocated_encoding(s
);
2506 * Load/Store exclusive instructions are implemented by remembering
2507 * the value/address loaded, and seeing if these are the same
2508 * when the store is performed. This is not actually the architecturally
2509 * mandated semantics, but it works for typical guest code sequences
2510 * and avoids having to monitor regular stores.
2512 * The store exclusive uses the atomic cmpxchg primitives to avoid
2513 * races in multi-threaded linux-user and when MTTCG softmmu is
2516 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
2517 TCGv_i64 addr
, int size
, bool is_pair
)
2519 int idx
= get_mem_index(s
);
2520 MemOp memop
= s
->be_data
;
2522 g_assert(size
<= 3);
2524 g_assert(size
>= 2);
2526 /* The pair must be single-copy atomic for the doubleword. */
2527 memop
|= MO_64
| MO_ALIGN
;
2528 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2529 if (s
->be_data
== MO_LE
) {
2530 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 0, 32);
2531 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 32, 32);
2533 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 32, 32);
2534 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 0, 32);
2537 /* The pair must be single-copy atomic for *each* doubleword, not
2538 the entire quadword, however it must be quadword aligned. */
2540 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
,
2541 memop
| MO_ALIGN_16
);
2543 TCGv_i64 addr2
= tcg_temp_new_i64();
2544 tcg_gen_addi_i64(addr2
, addr
, 8);
2545 tcg_gen_qemu_ld_i64(cpu_exclusive_high
, addr2
, idx
, memop
);
2546 tcg_temp_free_i64(addr2
);
2548 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2549 tcg_gen_mov_i64(cpu_reg(s
, rt2
), cpu_exclusive_high
);
2552 memop
|= size
| MO_ALIGN
;
2553 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2554 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2556 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
2559 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
2560 TCGv_i64 addr
, int size
, int is_pair
)
2562 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
2563 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
2566 * [addr + datasize] = {Rt2};
2572 * env->exclusive_addr = -1;
2574 TCGLabel
*fail_label
= gen_new_label();
2575 TCGLabel
*done_label
= gen_new_label();
2578 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
2580 tmp
= tcg_temp_new_i64();
2583 if (s
->be_data
== MO_LE
) {
2584 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2586 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt2
), cpu_reg(s
, rt
));
2588 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
,
2589 cpu_exclusive_val
, tmp
,
2591 MO_64
| MO_ALIGN
| s
->be_data
);
2592 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2594 TCGv_i128 t16
= tcg_temp_new_i128();
2595 TCGv_i128 c16
= tcg_temp_new_i128();
2598 if (s
->be_data
== MO_LE
) {
2599 tcg_gen_concat_i64_i128(t16
, cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2600 tcg_gen_concat_i64_i128(c16
, cpu_exclusive_val
,
2601 cpu_exclusive_high
);
2603 tcg_gen_concat_i64_i128(t16
, cpu_reg(s
, rt2
), cpu_reg(s
, rt
));
2604 tcg_gen_concat_i64_i128(c16
, cpu_exclusive_high
,
2608 tcg_gen_atomic_cmpxchg_i128(t16
, cpu_exclusive_addr
, c16
, t16
,
2610 MO_128
| MO_ALIGN
| s
->be_data
);
2611 tcg_temp_free_i128(c16
);
2613 a
= tcg_temp_new_i64();
2614 b
= tcg_temp_new_i64();
2615 if (s
->be_data
== MO_LE
) {
2616 tcg_gen_extr_i128_i64(a
, b
, t16
);
2618 tcg_gen_extr_i128_i64(b
, a
, t16
);
2621 tcg_gen_xor_i64(a
, a
, cpu_exclusive_val
);
2622 tcg_gen_xor_i64(b
, b
, cpu_exclusive_high
);
2623 tcg_gen_or_i64(tmp
, a
, b
);
2624 tcg_temp_free_i64(a
);
2625 tcg_temp_free_i64(b
);
2626 tcg_temp_free_i128(t16
);
2628 tcg_gen_setcondi_i64(TCG_COND_NE
, tmp
, tmp
, 0);
2631 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
, cpu_exclusive_val
,
2632 cpu_reg(s
, rt
), get_mem_index(s
),
2633 size
| MO_ALIGN
| s
->be_data
);
2634 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2636 tcg_gen_mov_i64(cpu_reg(s
, rd
), tmp
);
2637 tcg_temp_free_i64(tmp
);
2638 tcg_gen_br(done_label
);
2640 gen_set_label(fail_label
);
2641 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
2642 gen_set_label(done_label
);
2643 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
2646 static void gen_compare_and_swap(DisasContext
*s
, int rs
, int rt
,
2649 TCGv_i64 tcg_rs
= cpu_reg(s
, rs
);
2650 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2651 int memidx
= get_mem_index(s
);
2652 TCGv_i64 clean_addr
;
2655 gen_check_sp_alignment(s
);
2657 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
), true, rn
!= 31, size
);
2658 tcg_gen_atomic_cmpxchg_i64(tcg_rs
, clean_addr
, tcg_rs
, tcg_rt
, memidx
,
2659 size
| MO_ALIGN
| s
->be_data
);
2662 static void gen_compare_and_swap_pair(DisasContext
*s
, int rs
, int rt
,
2665 TCGv_i64 s1
= cpu_reg(s
, rs
);
2666 TCGv_i64 s2
= cpu_reg(s
, rs
+ 1);
2667 TCGv_i64 t1
= cpu_reg(s
, rt
);
2668 TCGv_i64 t2
= cpu_reg(s
, rt
+ 1);
2669 TCGv_i64 clean_addr
;
2670 int memidx
= get_mem_index(s
);
2673 gen_check_sp_alignment(s
);
2676 /* This is a single atomic access, despite the "pair". */
2677 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
), true, rn
!= 31, size
+ 1);
2680 TCGv_i64 cmp
= tcg_temp_new_i64();
2681 TCGv_i64 val
= tcg_temp_new_i64();
2683 if (s
->be_data
== MO_LE
) {
2684 tcg_gen_concat32_i64(val
, t1
, t2
);
2685 tcg_gen_concat32_i64(cmp
, s1
, s2
);
2687 tcg_gen_concat32_i64(val
, t2
, t1
);
2688 tcg_gen_concat32_i64(cmp
, s2
, s1
);
2691 tcg_gen_atomic_cmpxchg_i64(cmp
, clean_addr
, cmp
, val
, memidx
,
2692 MO_64
| MO_ALIGN
| s
->be_data
);
2693 tcg_temp_free_i64(val
);
2695 if (s
->be_data
== MO_LE
) {
2696 tcg_gen_extr32_i64(s1
, s2
, cmp
);
2698 tcg_gen_extr32_i64(s2
, s1
, cmp
);
2700 tcg_temp_free_i64(cmp
);
2702 TCGv_i128 cmp
= tcg_temp_new_i128();
2703 TCGv_i128 val
= tcg_temp_new_i128();
2705 if (s
->be_data
== MO_LE
) {
2706 tcg_gen_concat_i64_i128(val
, t1
, t2
);
2707 tcg_gen_concat_i64_i128(cmp
, s1
, s2
);
2709 tcg_gen_concat_i64_i128(val
, t2
, t1
);
2710 tcg_gen_concat_i64_i128(cmp
, s2
, s1
);
2713 tcg_gen_atomic_cmpxchg_i128(cmp
, clean_addr
, cmp
, val
, memidx
,
2714 MO_128
| MO_ALIGN
| s
->be_data
);
2715 tcg_temp_free_i128(val
);
2717 if (s
->be_data
== MO_LE
) {
2718 tcg_gen_extr_i128_i64(s1
, s2
, cmp
);
2720 tcg_gen_extr_i128_i64(s2
, s1
, cmp
);
2722 tcg_temp_free_i128(cmp
);
2726 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2727 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2729 static bool disas_ldst_compute_iss_sf(int size
, bool is_signed
, int opc
)
2731 int opc0
= extract32(opc
, 0, 1);
2735 regsize
= opc0
? 32 : 64;
2737 regsize
= size
== 3 ? 64 : 32;
2739 return regsize
== 64;
2742 /* Load/store exclusive
2744 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2745 * +-----+-------------+----+---+----+------+----+-------+------+------+
2746 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2747 * +-----+-------------+----+---+----+------+----+-------+------+------+
2749 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2750 * L: 0 -> store, 1 -> load
2751 * o2: 0 -> exclusive, 1 -> not
2752 * o1: 0 -> single register, 1 -> register pair
2753 * o0: 1 -> load-acquire/store-release, 0 -> not
2755 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
2757 int rt
= extract32(insn
, 0, 5);
2758 int rn
= extract32(insn
, 5, 5);
2759 int rt2
= extract32(insn
, 10, 5);
2760 int rs
= extract32(insn
, 16, 5);
2761 int is_lasr
= extract32(insn
, 15, 1);
2762 int o2_L_o1_o0
= extract32(insn
, 21, 3) * 2 | is_lasr
;
2763 int size
= extract32(insn
, 30, 2);
2764 TCGv_i64 clean_addr
;
2766 switch (o2_L_o1_o0
) {
2767 case 0x0: /* STXR */
2768 case 0x1: /* STLXR */
2770 gen_check_sp_alignment(s
);
2773 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2775 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2776 true, rn
!= 31, size
);
2777 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, false);
2780 case 0x4: /* LDXR */
2781 case 0x5: /* LDAXR */
2783 gen_check_sp_alignment(s
);
2785 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2786 false, rn
!= 31, size
);
2788 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, false);
2790 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2794 case 0x8: /* STLLR */
2795 if (!dc_isar_feature(aa64_lor
, s
)) {
2798 /* StoreLORelease is the same as Store-Release for QEMU. */
2800 case 0x9: /* STLR */
2801 /* Generate ISS for non-exclusive accesses including LASR. */
2803 gen_check_sp_alignment(s
);
2805 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2806 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2807 true, rn
!= 31, size
);
2808 /* TODO: ARMv8.4-LSE SCTLR.nAA */
2809 do_gpr_st(s
, cpu_reg(s
, rt
), clean_addr
, size
| MO_ALIGN
, true, rt
,
2810 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2813 case 0xc: /* LDLAR */
2814 if (!dc_isar_feature(aa64_lor
, s
)) {
2817 /* LoadLOAcquire is the same as Load-Acquire for QEMU. */
2819 case 0xd: /* LDAR */
2820 /* Generate ISS for non-exclusive accesses including LASR. */
2822 gen_check_sp_alignment(s
);
2824 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2825 false, rn
!= 31, size
);
2826 /* TODO: ARMv8.4-LSE SCTLR.nAA */
2827 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, size
| MO_ALIGN
, false, true,
2828 rt
, disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2829 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2832 case 0x2: case 0x3: /* CASP / STXP */
2833 if (size
& 2) { /* STXP / STLXP */
2835 gen_check_sp_alignment(s
);
2838 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2840 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2841 true, rn
!= 31, size
);
2842 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, true);
2846 && ((rt
| rs
) & 1) == 0
2847 && dc_isar_feature(aa64_atomics
, s
)) {
2849 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2854 case 0x6: case 0x7: /* CASPA / LDXP */
2855 if (size
& 2) { /* LDXP / LDAXP */
2857 gen_check_sp_alignment(s
);
2859 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
),
2860 false, rn
!= 31, size
);
2862 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, true);
2864 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2869 && ((rt
| rs
) & 1) == 0
2870 && dc_isar_feature(aa64_atomics
, s
)) {
2871 /* CASPA / CASPAL */
2872 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2878 case 0xb: /* CASL */
2879 case 0xe: /* CASA */
2880 case 0xf: /* CASAL */
2881 if (rt2
== 31 && dc_isar_feature(aa64_atomics
, s
)) {
2882 gen_compare_and_swap(s
, rs
, rt
, rn
, size
);
2887 unallocated_encoding(s
);
2891 * Load register (literal)
2893 * 31 30 29 27 26 25 24 23 5 4 0
2894 * +-----+-------+---+-----+-------------------+-------+
2895 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2896 * +-----+-------+---+-----+-------------------+-------+
2898 * V: 1 -> vector (simd/fp)
2899 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2900 * 10-> 32 bit signed, 11 -> prefetch
2901 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2903 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
2905 int rt
= extract32(insn
, 0, 5);
2906 int64_t imm
= sextract32(insn
, 5, 19) << 2;
2907 bool is_vector
= extract32(insn
, 26, 1);
2908 int opc
= extract32(insn
, 30, 2);
2909 bool is_signed
= false;
2911 TCGv_i64 tcg_rt
, clean_addr
;
2915 unallocated_encoding(s
);
2919 if (!fp_access_check(s
)) {
2924 /* PRFM (literal) : prefetch */
2927 size
= 2 + extract32(opc
, 0, 1);
2928 is_signed
= extract32(opc
, 1, 1);
2931 tcg_rt
= cpu_reg(s
, rt
);
2933 clean_addr
= new_tmp_a64(s
);
2934 gen_pc_plus_diff(s
, clean_addr
, imm
);
2936 do_fp_ld(s
, rt
, clean_addr
, size
);
2938 /* Only unsigned 32bit loads target 32bit registers. */
2939 bool iss_sf
= opc
!= 0;
2941 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
+ is_signed
* MO_SIGN
,
2942 false, true, rt
, iss_sf
, false);
2947 * LDNP (Load Pair - non-temporal hint)
2948 * LDP (Load Pair - non vector)
2949 * LDPSW (Load Pair Signed Word - non vector)
2950 * STNP (Store Pair - non-temporal hint)
2951 * STP (Store Pair - non vector)
2952 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2953 * LDP (Load Pair of SIMD&FP)
2954 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2955 * STP (Store Pair of SIMD&FP)
2957 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2958 * +-----+-------+---+---+-------+---+-----------------------------+
2959 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2960 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2962 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2964 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2965 * V: 0 -> GPR, 1 -> Vector
2966 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2967 * 10 -> signed offset, 11 -> pre-index
2968 * L: 0 -> Store 1 -> Load
2970 * Rt, Rt2 = GPR or SIMD registers to be stored
2971 * Rn = general purpose register containing address
2972 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2974 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
2976 int rt
= extract32(insn
, 0, 5);
2977 int rn
= extract32(insn
, 5, 5);
2978 int rt2
= extract32(insn
, 10, 5);
2979 uint64_t offset
= sextract64(insn
, 15, 7);
2980 int index
= extract32(insn
, 23, 2);
2981 bool is_vector
= extract32(insn
, 26, 1);
2982 bool is_load
= extract32(insn
, 22, 1);
2983 int opc
= extract32(insn
, 30, 2);
2985 bool is_signed
= false;
2986 bool postindex
= false;
2988 bool set_tag
= false;
2990 TCGv_i64 clean_addr
, dirty_addr
;
2995 unallocated_encoding(s
);
3001 } else if (opc
== 1 && !is_load
) {
3003 if (!dc_isar_feature(aa64_mte_insn_reg
, s
) || index
== 0) {
3004 unallocated_encoding(s
);
3010 size
= 2 + extract32(opc
, 1, 1);
3011 is_signed
= extract32(opc
, 0, 1);
3012 if (!is_load
&& is_signed
) {
3013 unallocated_encoding(s
);
3019 case 1: /* post-index */
3024 /* signed offset with "non-temporal" hint. Since we don't emulate
3025 * caches we don't care about hints to the cache system about
3026 * data access patterns, and handle this identically to plain
3030 /* There is no non-temporal-hint version of LDPSW */
3031 unallocated_encoding(s
);
3036 case 2: /* signed offset, rn not updated */
3039 case 3: /* pre-index */
3045 if (is_vector
&& !fp_access_check(s
)) {
3049 offset
<<= (set_tag
? LOG2_TAG_GRANULE
: size
);
3052 gen_check_sp_alignment(s
);
3055 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3057 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3063 * TODO: We could rely on the stores below, at least for
3064 * system mode, if we arrange to add MO_ALIGN_16.
3066 gen_helper_stg_stub(cpu_env
, dirty_addr
);
3067 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
3068 gen_helper_stg_parallel(cpu_env
, dirty_addr
, dirty_addr
);
3070 gen_helper_stg(cpu_env
, dirty_addr
, dirty_addr
);
3074 clean_addr
= gen_mte_checkN(s
, dirty_addr
, !is_load
,
3075 (wback
|| rn
!= 31) && !set_tag
, 2 << size
);
3079 do_fp_ld(s
, rt
, clean_addr
, size
);
3081 do_fp_st(s
, rt
, clean_addr
, size
);
3083 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
3085 do_fp_ld(s
, rt2
, clean_addr
, size
);
3087 do_fp_st(s
, rt2
, clean_addr
, size
);
3090 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3091 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
3094 TCGv_i64 tmp
= tcg_temp_new_i64();
3096 /* Do not modify tcg_rt before recognizing any exception
3097 * from the second load.
3099 do_gpr_ld(s
, tmp
, clean_addr
, size
+ is_signed
* MO_SIGN
,
3100 false, false, 0, false, false);
3101 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
3102 do_gpr_ld(s
, tcg_rt2
, clean_addr
, size
+ is_signed
* MO_SIGN
,
3103 false, false, 0, false, false);
3105 tcg_gen_mov_i64(tcg_rt
, tmp
);
3106 tcg_temp_free_i64(tmp
);
3108 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3109 false, 0, false, false);
3110 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
3111 do_gpr_st(s
, tcg_rt2
, clean_addr
, size
,
3112 false, 0, false, false);
3118 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3120 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
3125 * Load/store (immediate post-indexed)
3126 * Load/store (immediate pre-indexed)
3127 * Load/store (unscaled immediate)
3129 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
3130 * +----+-------+---+-----+-----+---+--------+-----+------+------+
3131 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
3132 * +----+-------+---+-----+-----+---+--------+-----+------+------+
3134 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
3136 * V = 0 -> non-vector
3137 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
3138 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
3140 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
3146 int rn
= extract32(insn
, 5, 5);
3147 int imm9
= sextract32(insn
, 12, 9);
3148 int idx
= extract32(insn
, 10, 2);
3149 bool is_signed
= false;
3150 bool is_store
= false;
3151 bool is_extended
= false;
3152 bool is_unpriv
= (idx
== 2);
3158 TCGv_i64 clean_addr
, dirty_addr
;
3161 size
|= (opc
& 2) << 1;
3162 if (size
> 4 || is_unpriv
) {
3163 unallocated_encoding(s
);
3166 is_store
= ((opc
& 1) == 0);
3167 if (!fp_access_check(s
)) {
3171 if (size
== 3 && opc
== 2) {
3172 /* PRFM - prefetch */
3174 unallocated_encoding(s
);
3179 if (opc
== 3 && size
> 1) {
3180 unallocated_encoding(s
);
3183 is_store
= (opc
== 0);
3184 is_signed
= extract32(opc
, 1, 1);
3185 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3203 g_assert_not_reached();
3206 iss_valid
= !is_vector
&& !writeback
;
3209 gen_check_sp_alignment(s
);
3212 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3214 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
3217 memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
3218 clean_addr
= gen_mte_check1_mmuidx(s
, dirty_addr
, is_store
,
3219 writeback
|| rn
!= 31,
3220 size
, is_unpriv
, memidx
);
3224 do_fp_st(s
, rt
, clean_addr
, size
);
3226 do_fp_ld(s
, rt
, clean_addr
, size
);
3229 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3230 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3233 do_gpr_st_memidx(s
, tcg_rt
, clean_addr
, size
, memidx
,
3234 iss_valid
, rt
, iss_sf
, false);
3236 do_gpr_ld_memidx(s
, tcg_rt
, clean_addr
, size
+ is_signed
* MO_SIGN
,
3237 is_extended
, memidx
,
3238 iss_valid
, rt
, iss_sf
, false);
3243 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
3245 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
3247 tcg_gen_mov_i64(tcg_rn
, dirty_addr
);
3252 * Load/store (register offset)
3254 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3255 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
3256 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
3257 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
3260 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
3261 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
3263 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
3264 * opc<0>: 0 -> store, 1 -> load
3265 * V: 1 -> vector/simd
3266 * opt: extend encoding (see DecodeRegExtend)
3267 * S: if S=1 then scale (essentially index by sizeof(size))
3268 * Rt: register to transfer into/out of
3269 * Rn: address register or SP for base
3270 * Rm: offset register or ZR for offset
3272 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
3278 int rn
= extract32(insn
, 5, 5);
3279 int shift
= extract32(insn
, 12, 1);
3280 int rm
= extract32(insn
, 16, 5);
3281 int opt
= extract32(insn
, 13, 3);
3282 bool is_signed
= false;
3283 bool is_store
= false;
3284 bool is_extended
= false;
3286 TCGv_i64 tcg_rm
, clean_addr
, dirty_addr
;
3288 if (extract32(opt
, 1, 1) == 0) {
3289 unallocated_encoding(s
);
3294 size
|= (opc
& 2) << 1;
3296 unallocated_encoding(s
);
3299 is_store
= !extract32(opc
, 0, 1);
3300 if (!fp_access_check(s
)) {
3304 if (size
== 3 && opc
== 2) {
3305 /* PRFM - prefetch */
3308 if (opc
== 3 && size
> 1) {
3309 unallocated_encoding(s
);
3312 is_store
= (opc
== 0);
3313 is_signed
= extract32(opc
, 1, 1);
3314 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3318 gen_check_sp_alignment(s
);
3320 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3322 tcg_rm
= read_cpu_reg(s
, rm
, 1);
3323 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
3325 tcg_gen_add_i64(dirty_addr
, dirty_addr
, tcg_rm
);
3326 clean_addr
= gen_mte_check1(s
, dirty_addr
, is_store
, true, size
);
3330 do_fp_st(s
, rt
, clean_addr
, size
);
3332 do_fp_ld(s
, rt
, clean_addr
, size
);
3335 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3336 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3338 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3339 true, rt
, iss_sf
, false);
3341 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
+ is_signed
* MO_SIGN
,
3342 is_extended
, true, rt
, iss_sf
, false);
3348 * Load/store (unsigned immediate)
3350 * 31 30 29 27 26 25 24 23 22 21 10 9 5
3351 * +----+-------+---+-----+-----+------------+-------+------+
3352 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
3353 * +----+-------+---+-----+-----+------------+-------+------+
3356 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
3357 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
3359 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
3360 * opc<0>: 0 -> store, 1 -> load
3361 * Rn: base address register (inc SP)
3362 * Rt: target register
3364 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
3370 int rn
= extract32(insn
, 5, 5);
3371 unsigned int imm12
= extract32(insn
, 10, 12);
3372 unsigned int offset
;
3374 TCGv_i64 clean_addr
, dirty_addr
;
3377 bool is_signed
= false;
3378 bool is_extended
= false;
3381 size
|= (opc
& 2) << 1;
3383 unallocated_encoding(s
);
3386 is_store
= !extract32(opc
, 0, 1);
3387 if (!fp_access_check(s
)) {
3391 if (size
== 3 && opc
== 2) {
3392 /* PRFM - prefetch */
3395 if (opc
== 3 && size
> 1) {
3396 unallocated_encoding(s
);
3399 is_store
= (opc
== 0);
3400 is_signed
= extract32(opc
, 1, 1);
3401 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3405 gen_check_sp_alignment(s
);
3407 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3408 offset
= imm12
<< size
;
3409 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3410 clean_addr
= gen_mte_check1(s
, dirty_addr
, is_store
, rn
!= 31, size
);
3414 do_fp_st(s
, rt
, clean_addr
, size
);
3416 do_fp_ld(s
, rt
, clean_addr
, size
);
3419 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3420 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3422 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3423 true, rt
, iss_sf
, false);
3425 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
+ is_signed
* MO_SIGN
,
3426 is_extended
, true, rt
, iss_sf
, false);
3431 /* Atomic memory operations
3433 * 31 30 27 26 24 22 21 16 15 12 10 5 0
3434 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
3435 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
3436 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
3438 * Rt: the result register
3439 * Rn: base address or SP
3440 * Rs: the source register for the operation
3441 * V: vector flag (always 0 as of v8.3)
3445 static void disas_ldst_atomic(DisasContext
*s
, uint32_t insn
,
3446 int size
, int rt
, bool is_vector
)
3448 int rs
= extract32(insn
, 16, 5);
3449 int rn
= extract32(insn
, 5, 5);
3450 int o3_opc
= extract32(insn
, 12, 4);
3451 bool r
= extract32(insn
, 22, 1);
3452 bool a
= extract32(insn
, 23, 1);
3453 TCGv_i64 tcg_rs
, tcg_rt
, clean_addr
;
3454 AtomicThreeOpFn
*fn
= NULL
;
3455 MemOp mop
= s
->be_data
| size
| MO_ALIGN
;
3457 if (is_vector
|| !dc_isar_feature(aa64_atomics
, s
)) {
3458 unallocated_encoding(s
);
3462 case 000: /* LDADD */
3463 fn
= tcg_gen_atomic_fetch_add_i64
;
3465 case 001: /* LDCLR */
3466 fn
= tcg_gen_atomic_fetch_and_i64
;
3468 case 002: /* LDEOR */
3469 fn
= tcg_gen_atomic_fetch_xor_i64
;
3471 case 003: /* LDSET */
3472 fn
= tcg_gen_atomic_fetch_or_i64
;
3474 case 004: /* LDSMAX */
3475 fn
= tcg_gen_atomic_fetch_smax_i64
;
3478 case 005: /* LDSMIN */
3479 fn
= tcg_gen_atomic_fetch_smin_i64
;
3482 case 006: /* LDUMAX */
3483 fn
= tcg_gen_atomic_fetch_umax_i64
;
3485 case 007: /* LDUMIN */
3486 fn
= tcg_gen_atomic_fetch_umin_i64
;
3489 fn
= tcg_gen_atomic_xchg_i64
;
3491 case 014: /* LDAPR, LDAPRH, LDAPRB */
3492 if (!dc_isar_feature(aa64_rcpc_8_3
, s
) ||
3493 rs
!= 31 || a
!= 1 || r
!= 0) {
3494 unallocated_encoding(s
);
3499 unallocated_encoding(s
);
3504 gen_check_sp_alignment(s
);
3506 clean_addr
= gen_mte_check1(s
, cpu_reg_sp(s
, rn
), false, rn
!= 31, size
);
3508 if (o3_opc
== 014) {
3510 * LDAPR* are a special case because they are a simple load, not a
3511 * fetch-and-do-something op.
3512 * The architectural consistency requirements here are weaker than
3513 * full load-acquire (we only need "load-acquire processor consistent"),
3514 * but we choose to implement them as full LDAQ.
3516 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, size
, false,
3517 true, rt
, disas_ldst_compute_iss_sf(size
, false, 0), true);
3518 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
3522 tcg_rs
= read_cpu_reg(s
, rs
, true);
3523 tcg_rt
= cpu_reg(s
, rt
);
3525 if (o3_opc
== 1) { /* LDCLR */
3526 tcg_gen_not_i64(tcg_rs
, tcg_rs
);
3529 /* The tcg atomic primitives are all full barriers. Therefore we
3530 * can ignore the Acquire and Release bits of this instruction.
3532 fn(tcg_rt
, clean_addr
, tcg_rs
, get_mem_index(s
), mop
);
3534 if ((mop
& MO_SIGN
) && size
!= MO_64
) {
3535 tcg_gen_ext32u_i64(tcg_rt
, tcg_rt
);
3540 * PAC memory operations
3542 * 31 30 27 26 24 22 21 12 11 10 5 0
3543 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3544 * | size | 1 1 1 | V | 0 0 | M S | 1 | imm9 | W | 1 | Rn | Rt |
3545 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3547 * Rt: the result register
3548 * Rn: base address or SP
3549 * V: vector flag (always 0 as of v8.3)
3550 * M: clear for key DA, set for key DB
3551 * W: pre-indexing flag
3554 static void disas_ldst_pac(DisasContext
*s
, uint32_t insn
,
3555 int size
, int rt
, bool is_vector
)
3557 int rn
= extract32(insn
, 5, 5);
3558 bool is_wback
= extract32(insn
, 11, 1);
3559 bool use_key_a
= !extract32(insn
, 23, 1);
3561 TCGv_i64 clean_addr
, dirty_addr
, tcg_rt
;
3563 if (size
!= 3 || is_vector
|| !dc_isar_feature(aa64_pauth
, s
)) {
3564 unallocated_encoding(s
);
3569 gen_check_sp_alignment(s
);
3571 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3573 if (s
->pauth_active
) {
3575 gen_helper_autda(dirty_addr
, cpu_env
, dirty_addr
,
3576 new_tmp_a64_zero(s
));
3578 gen_helper_autdb(dirty_addr
, cpu_env
, dirty_addr
,
3579 new_tmp_a64_zero(s
));
3583 /* Form the 10-bit signed, scaled offset. */
3584 offset
= (extract32(insn
, 22, 1) << 9) | extract32(insn
, 12, 9);
3585 offset
= sextract32(offset
<< size
, 0, 10 + size
);
3586 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3588 /* Note that "clean" and "dirty" here refer to TBI not PAC. */
3589 clean_addr
= gen_mte_check1(s
, dirty_addr
, false,
3590 is_wback
|| rn
!= 31, size
);
3592 tcg_rt
= cpu_reg(s
, rt
);
3593 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
,
3594 /* extend */ false, /* iss_valid */ !is_wback
,
3595 /* iss_srt */ rt
, /* iss_sf */ true, /* iss_ar */ false);
3598 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
3603 * LDAPR/STLR (unscaled immediate)
3605 * 31 30 24 22 21 12 10 5 0
3606 * +------+-------------+-----+---+--------+-----+----+-----+
3607 * | size | 0 1 1 0 0 1 | opc | 0 | imm9 | 0 0 | Rn | Rt |
3608 * +------+-------------+-----+---+--------+-----+----+-----+
3610 * Rt: source or destination register
3612 * imm9: unscaled immediate offset
3613 * opc: 00: STLUR*, 01/10/11: various LDAPUR*
3614 * size: size of load/store
3616 static void disas_ldst_ldapr_stlr(DisasContext
*s
, uint32_t insn
)
3618 int rt
= extract32(insn
, 0, 5);
3619 int rn
= extract32(insn
, 5, 5);
3620 int offset
= sextract32(insn
, 12, 9);
3621 int opc
= extract32(insn
, 22, 2);
3622 int size
= extract32(insn
, 30, 2);
3623 TCGv_i64 clean_addr
, dirty_addr
;
3624 bool is_store
= false;
3625 bool extend
= false;
3629 if (!dc_isar_feature(aa64_rcpc_8_4
, s
)) {
3630 unallocated_encoding(s
);
3634 /* TODO: ARMv8.4-LSE SCTLR.nAA */
3635 mop
= size
| MO_ALIGN
;
3638 case 0: /* STLURB */
3641 case 1: /* LDAPUR* */
3643 case 2: /* LDAPURS* 64-bit variant */
3645 unallocated_encoding(s
);
3650 case 3: /* LDAPURS* 32-bit variant */
3652 unallocated_encoding(s
);
3656 extend
= true; /* zero-extend 32->64 after signed load */
3659 g_assert_not_reached();
3662 iss_sf
= disas_ldst_compute_iss_sf(size
, (mop
& MO_SIGN
) != 0, opc
);
3665 gen_check_sp_alignment(s
);
3668 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3669 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3670 clean_addr
= clean_data_tbi(s
, dirty_addr
);
3673 /* Store-Release semantics */
3674 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
3675 do_gpr_st(s
, cpu_reg(s
, rt
), clean_addr
, mop
, true, rt
, iss_sf
, true);
3678 * Load-AcquirePC semantics; we implement as the slightly more
3679 * restrictive Load-Acquire.
3681 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, mop
,
3682 extend
, true, rt
, iss_sf
, true);
3683 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
3687 /* Load/store register (all forms) */
3688 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
3690 int rt
= extract32(insn
, 0, 5);
3691 int opc
= extract32(insn
, 22, 2);
3692 bool is_vector
= extract32(insn
, 26, 1);
3693 int size
= extract32(insn
, 30, 2);
3695 switch (extract32(insn
, 24, 2)) {
3697 if (extract32(insn
, 21, 1) == 0) {
3698 /* Load/store register (unscaled immediate)
3699 * Load/store immediate pre/post-indexed
3700 * Load/store register unprivileged
3702 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
3705 switch (extract32(insn
, 10, 2)) {
3707 disas_ldst_atomic(s
, insn
, size
, rt
, is_vector
);
3710 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
3713 disas_ldst_pac(s
, insn
, size
, rt
, is_vector
);
3718 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
3721 unallocated_encoding(s
);
3724 /* AdvSIMD load/store multiple structures
3726 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
3727 * +---+---+---------------+---+-------------+--------+------+------+------+
3728 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
3729 * +---+---+---------------+---+-------------+--------+------+------+------+
3731 * AdvSIMD load/store multiple structures (post-indexed)
3733 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
3734 * +---+---+---------------+---+---+---------+--------+------+------+------+
3735 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
3736 * +---+---+---------------+---+---+---------+--------+------+------+------+
3738 * Rt: first (or only) SIMD&FP register to be transferred
3739 * Rn: base address or SP
3740 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3742 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
3744 int rt
= extract32(insn
, 0, 5);
3745 int rn
= extract32(insn
, 5, 5);
3746 int rm
= extract32(insn
, 16, 5);
3747 int size
= extract32(insn
, 10, 2);
3748 int opcode
= extract32(insn
, 12, 4);
3749 bool is_store
= !extract32(insn
, 22, 1);
3750 bool is_postidx
= extract32(insn
, 23, 1);
3751 bool is_q
= extract32(insn
, 30, 1);
3752 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3753 MemOp endian
, align
, mop
;
3755 int total
; /* total bytes */
3756 int elements
; /* elements per vector */
3757 int rpt
; /* num iterations */
3758 int selem
; /* structure elements */
3761 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
3762 unallocated_encoding(s
);
3766 if (!is_postidx
&& rm
!= 0) {
3767 unallocated_encoding(s
);
3771 /* From the shared decode logic */
3802 unallocated_encoding(s
);
3806 if (size
== 3 && !is_q
&& selem
!= 1) {
3808 unallocated_encoding(s
);
3812 if (!fp_access_check(s
)) {
3817 gen_check_sp_alignment(s
);
3820 /* For our purposes, bytes are always little-endian. */
3821 endian
= s
->be_data
;
3826 total
= rpt
* selem
* (is_q
? 16 : 8);
3827 tcg_rn
= cpu_reg_sp(s
, rn
);
3830 * Issue the MTE check vs the logical repeat count, before we
3831 * promote consecutive little-endian elements below.
3833 clean_addr
= gen_mte_checkN(s
, tcg_rn
, is_store
, is_postidx
|| rn
!= 31,
3837 * Consecutive little-endian elements from a single register
3838 * can be promoted to a larger little-endian operation.
3841 if (selem
== 1 && endian
== MO_LE
) {
3842 align
= pow2_align(size
);
3845 if (!s
->align_mem
) {
3848 mop
= endian
| size
| align
;
3850 elements
= (is_q
? 16 : 8) >> size
;
3851 tcg_ebytes
= tcg_constant_i64(1 << size
);
3852 for (r
= 0; r
< rpt
; r
++) {
3854 for (e
= 0; e
< elements
; e
++) {
3856 for (xs
= 0; xs
< selem
; xs
++) {
3857 int tt
= (rt
+ r
+ xs
) % 32;
3859 do_vec_st(s
, tt
, e
, clean_addr
, mop
);
3861 do_vec_ld(s
, tt
, e
, clean_addr
, mop
);
3863 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
3869 /* For non-quad operations, setting a slice of the low
3870 * 64 bits of the register clears the high 64 bits (in
3871 * the ARM ARM pseudocode this is implicit in the fact
3872 * that 'rval' is a 64 bit wide variable).
3873 * For quad operations, we might still need to zero the
3876 for (r
= 0; r
< rpt
* selem
; r
++) {
3877 int tt
= (rt
+ r
) % 32;
3878 clear_vec_high(s
, is_q
, tt
);
3884 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, total
);
3886 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3891 /* AdvSIMD load/store single structure
3893 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3894 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3895 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3896 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3898 * AdvSIMD load/store single structure (post-indexed)
3900 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3901 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3902 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3903 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3905 * Rt: first (or only) SIMD&FP register to be transferred
3906 * Rn: base address or SP
3907 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3908 * index = encoded in Q:S:size dependent on size
3910 * lane_size = encoded in R, opc
3911 * transfer width = encoded in opc, S, size
3913 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
3915 int rt
= extract32(insn
, 0, 5);
3916 int rn
= extract32(insn
, 5, 5);
3917 int rm
= extract32(insn
, 16, 5);
3918 int size
= extract32(insn
, 10, 2);
3919 int S
= extract32(insn
, 12, 1);
3920 int opc
= extract32(insn
, 13, 3);
3921 int R
= extract32(insn
, 21, 1);
3922 int is_load
= extract32(insn
, 22, 1);
3923 int is_postidx
= extract32(insn
, 23, 1);
3924 int is_q
= extract32(insn
, 30, 1);
3926 int scale
= extract32(opc
, 1, 2);
3927 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
3928 bool replicate
= false;
3929 int index
= is_q
<< 3 | S
<< 2 | size
;
3931 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3934 if (extract32(insn
, 31, 1)) {
3935 unallocated_encoding(s
);
3938 if (!is_postidx
&& rm
!= 0) {
3939 unallocated_encoding(s
);
3945 if (!is_load
|| S
) {
3946 unallocated_encoding(s
);
3955 if (extract32(size
, 0, 1)) {
3956 unallocated_encoding(s
);
3962 if (extract32(size
, 1, 1)) {
3963 unallocated_encoding(s
);
3966 if (!extract32(size
, 0, 1)) {
3970 unallocated_encoding(s
);
3978 g_assert_not_reached();
3981 if (!fp_access_check(s
)) {
3986 gen_check_sp_alignment(s
);
3989 total
= selem
<< scale
;
3990 tcg_rn
= cpu_reg_sp(s
, rn
);
3992 clean_addr
= gen_mte_checkN(s
, tcg_rn
, !is_load
, is_postidx
|| rn
!= 31,
3994 mop
= finalize_memop(s
, scale
);
3996 tcg_ebytes
= tcg_constant_i64(1 << scale
);
3997 for (xs
= 0; xs
< selem
; xs
++) {
3999 /* Load and replicate to all elements */
4000 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4002 tcg_gen_qemu_ld_i64(tcg_tmp
, clean_addr
, get_mem_index(s
), mop
);
4003 tcg_gen_gvec_dup_i64(scale
, vec_full_reg_offset(s
, rt
),
4004 (is_q
+ 1) * 8, vec_full_reg_size(s
),
4006 tcg_temp_free_i64(tcg_tmp
);
4008 /* Load/store one element per register */
4010 do_vec_ld(s
, rt
, index
, clean_addr
, mop
);
4012 do_vec_st(s
, rt
, index
, clean_addr
, mop
);
4015 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
4021 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, total
);
4023 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
4029 * Load/Store memory tags
4031 * 31 30 29 24 22 21 12 10 5 0
4032 * +-----+-------------+-----+---+------+-----+------+------+
4033 * | 1 1 | 0 1 1 0 0 1 | op1 | 1 | imm9 | op2 | Rn | Rt |
4034 * +-----+-------------+-----+---+------+-----+------+------+
4036 static void disas_ldst_tag(DisasContext
*s
, uint32_t insn
)
4038 int rt
= extract32(insn
, 0, 5);
4039 int rn
= extract32(insn
, 5, 5);
4040 uint64_t offset
= sextract64(insn
, 12, 9) << LOG2_TAG_GRANULE
;
4041 int op2
= extract32(insn
, 10, 2);
4042 int op1
= extract32(insn
, 22, 2);
4043 bool is_load
= false, is_pair
= false, is_zero
= false, is_mult
= false;
4045 TCGv_i64 addr
, clean_addr
, tcg_rt
;
4047 /* We checked insn bits [29:24,21] in the caller. */
4048 if (extract32(insn
, 30, 2) != 3) {
4049 goto do_unallocated
;
4053 * @index is a tri-state variable which has 3 states:
4054 * < 0 : post-index, writeback
4055 * = 0 : signed offset
4056 * > 0 : pre-index, writeback
4065 if (s
->current_el
== 0 || offset
!= 0) {
4066 goto do_unallocated
;
4068 is_mult
= is_zero
= true;
4088 if (s
->current_el
== 0 || offset
!= 0) {
4089 goto do_unallocated
;
4097 is_pair
= is_zero
= true;
4101 if (s
->current_el
== 0 || offset
!= 0) {
4102 goto do_unallocated
;
4104 is_mult
= is_load
= true;
4110 unallocated_encoding(s
);
4115 ? !dc_isar_feature(aa64_mte
, s
)
4116 : !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
4117 goto do_unallocated
;
4121 gen_check_sp_alignment(s
);
4124 addr
= read_cpu_reg_sp(s
, rn
, true);
4126 /* pre-index or signed offset */
4127 tcg_gen_addi_i64(addr
, addr
, offset
);
4131 tcg_rt
= cpu_reg(s
, rt
);
4134 int size
= 4 << s
->dcz_blocksize
;
4137 gen_helper_stzgm_tags(cpu_env
, addr
, tcg_rt
);
4140 * The non-tags portion of STZGM is mostly like DC_ZVA,
4141 * except the alignment happens before the access.
4143 clean_addr
= clean_data_tbi(s
, addr
);
4144 tcg_gen_andi_i64(clean_addr
, clean_addr
, -size
);
4145 gen_helper_dc_zva(cpu_env
, clean_addr
);
4146 } else if (s
->ata
) {
4148 gen_helper_ldgm(tcg_rt
, cpu_env
, addr
);
4150 gen_helper_stgm(cpu_env
, addr
, tcg_rt
);
4153 MMUAccessType acc
= is_load
? MMU_DATA_LOAD
: MMU_DATA_STORE
;
4154 int size
= 4 << GMID_EL1_BS
;
4156 clean_addr
= clean_data_tbi(s
, addr
);
4157 tcg_gen_andi_i64(clean_addr
, clean_addr
, -size
);
4158 gen_probe_access(s
, clean_addr
, acc
, size
);
4161 /* The result tags are zeros. */
4162 tcg_gen_movi_i64(tcg_rt
, 0);
4169 tcg_gen_andi_i64(addr
, addr
, -TAG_GRANULE
);
4170 tcg_rt
= cpu_reg(s
, rt
);
4172 gen_helper_ldg(tcg_rt
, cpu_env
, addr
, tcg_rt
);
4174 clean_addr
= clean_data_tbi(s
, addr
);
4175 gen_probe_access(s
, clean_addr
, MMU_DATA_LOAD
, MO_8
);
4176 gen_address_with_allocation_tag0(tcg_rt
, addr
);
4179 tcg_rt
= cpu_reg_sp(s
, rt
);
4182 * For STG and ST2G, we need to check alignment and probe memory.
4183 * TODO: For STZG and STZ2G, we could rely on the stores below,
4184 * at least for system mode; user-only won't enforce alignment.
4187 gen_helper_st2g_stub(cpu_env
, addr
);
4189 gen_helper_stg_stub(cpu_env
, addr
);
4191 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
4193 gen_helper_st2g_parallel(cpu_env
, addr
, tcg_rt
);
4195 gen_helper_stg_parallel(cpu_env
, addr
, tcg_rt
);
4199 gen_helper_st2g(cpu_env
, addr
, tcg_rt
);
4201 gen_helper_stg(cpu_env
, addr
, tcg_rt
);
4207 TCGv_i64 clean_addr
= clean_data_tbi(s
, addr
);
4208 TCGv_i64 tcg_zero
= tcg_constant_i64(0);
4209 int mem_index
= get_mem_index(s
);
4210 int i
, n
= (1 + is_pair
) << LOG2_TAG_GRANULE
;
4212 tcg_gen_qemu_st_i64(tcg_zero
, clean_addr
, mem_index
,
4213 MO_UQ
| MO_ALIGN_16
);
4214 for (i
= 8; i
< n
; i
+= 8) {
4215 tcg_gen_addi_i64(clean_addr
, clean_addr
, 8);
4216 tcg_gen_qemu_st_i64(tcg_zero
, clean_addr
, mem_index
, MO_UQ
);
4221 /* pre-index or post-index */
4224 tcg_gen_addi_i64(addr
, addr
, offset
);
4226 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), addr
);
4230 /* Loads and stores */
4231 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
4233 switch (extract32(insn
, 24, 6)) {
4234 case 0x08: /* Load/store exclusive */
4235 disas_ldst_excl(s
, insn
);
4237 case 0x18: case 0x1c: /* Load register (literal) */
4238 disas_ld_lit(s
, insn
);
4240 case 0x28: case 0x29:
4241 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
4242 disas_ldst_pair(s
, insn
);
4244 case 0x38: case 0x39:
4245 case 0x3c: case 0x3d: /* Load/store register (all forms) */
4246 disas_ldst_reg(s
, insn
);
4248 case 0x0c: /* AdvSIMD load/store multiple structures */
4249 disas_ldst_multiple_struct(s
, insn
);
4251 case 0x0d: /* AdvSIMD load/store single structure */
4252 disas_ldst_single_struct(s
, insn
);
4255 if (extract32(insn
, 21, 1) != 0) {
4256 disas_ldst_tag(s
, insn
);
4257 } else if (extract32(insn
, 10, 2) == 0) {
4258 disas_ldst_ldapr_stlr(s
, insn
);
4260 unallocated_encoding(s
);
4264 unallocated_encoding(s
);
4269 /* PC-rel. addressing
4270 * 31 30 29 28 24 23 5 4 0
4271 * +----+-------+-----------+-------------------+------+
4272 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
4273 * +----+-------+-----------+-------------------+------+
4275 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
4277 unsigned int page
, rd
;
4280 page
= extract32(insn
, 31, 1);
4281 /* SignExtend(immhi:immlo) -> offset */
4282 offset
= sextract64(insn
, 5, 19);
4283 offset
= offset
<< 2 | extract32(insn
, 29, 2);
4284 rd
= extract32(insn
, 0, 5);
4287 /* ADRP (page based) */
4289 /* The page offset is ok for CF_PCREL. */
4290 offset
-= s
->pc_curr
& 0xfff;
4293 gen_pc_plus_diff(s
, cpu_reg(s
, rd
), offset
);
4297 * Add/subtract (immediate)
4299 * 31 30 29 28 23 22 21 10 9 5 4 0
4300 * +--+--+--+-------------+--+-------------+-----+-----+
4301 * |sf|op| S| 1 0 0 0 1 0 |sh| imm12 | Rn | Rd |
4302 * +--+--+--+-------------+--+-------------+-----+-----+
4304 * sf: 0 -> 32bit, 1 -> 64bit
4305 * op: 0 -> add , 1 -> sub
4307 * sh: 1 -> LSL imm by 12
4309 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
4311 int rd
= extract32(insn
, 0, 5);
4312 int rn
= extract32(insn
, 5, 5);
4313 uint64_t imm
= extract32(insn
, 10, 12);
4314 bool shift
= extract32(insn
, 22, 1);
4315 bool setflags
= extract32(insn
, 29, 1);
4316 bool sub_op
= extract32(insn
, 30, 1);
4317 bool is_64bit
= extract32(insn
, 31, 1);
4319 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
4320 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
4321 TCGv_i64 tcg_result
;
4327 tcg_result
= tcg_temp_new_i64();
4330 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
4332 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
4335 TCGv_i64 tcg_imm
= tcg_constant_i64(imm
);
4337 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
4339 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
4344 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4346 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4349 tcg_temp_free_i64(tcg_result
);
4353 * Add/subtract (immediate, with tags)
4355 * 31 30 29 28 23 22 21 16 14 10 9 5 4 0
4356 * +--+--+--+-------------+--+---------+--+-------+-----+-----+
4357 * |sf|op| S| 1 0 0 0 1 1 |o2| uimm6 |o3| uimm4 | Rn | Rd |
4358 * +--+--+--+-------------+--+---------+--+-------+-----+-----+
4360 * op: 0 -> add, 1 -> sub
4362 static void disas_add_sub_imm_with_tags(DisasContext
*s
, uint32_t insn
)
4364 int rd
= extract32(insn
, 0, 5);
4365 int rn
= extract32(insn
, 5, 5);
4366 int uimm4
= extract32(insn
, 10, 4);
4367 int uimm6
= extract32(insn
, 16, 6);
4368 bool sub_op
= extract32(insn
, 30, 1);
4369 TCGv_i64 tcg_rn
, tcg_rd
;
4372 /* Test all of sf=1, S=0, o2=0, o3=0. */
4373 if ((insn
& 0xa040c000u
) != 0x80000000u
||
4374 !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
4375 unallocated_encoding(s
);
4379 imm
= uimm6
<< LOG2_TAG_GRANULE
;
4384 tcg_rn
= cpu_reg_sp(s
, rn
);
4385 tcg_rd
= cpu_reg_sp(s
, rd
);
4388 gen_helper_addsubg(tcg_rd
, cpu_env
, tcg_rn
,
4389 tcg_constant_i32(imm
),
4390 tcg_constant_i32(uimm4
));
4392 tcg_gen_addi_i64(tcg_rd
, tcg_rn
, imm
);
4393 gen_address_with_allocation_tag0(tcg_rd
, tcg_rd
);
4397 /* The input should be a value in the bottom e bits (with higher
4398 * bits zero); returns that value replicated into every element
4399 * of size e in a 64 bit integer.
4401 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
4411 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
4412 static inline uint64_t bitmask64(unsigned int length
)
4414 assert(length
> 0 && length
<= 64);
4415 return ~0ULL >> (64 - length
);
4418 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
4419 * only require the wmask. Returns false if the imms/immr/immn are a reserved
4420 * value (ie should cause a guest UNDEF exception), and true if they are
4421 * valid, in which case the decoded bit pattern is written to result.
4423 bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
4424 unsigned int imms
, unsigned int immr
)
4427 unsigned e
, levels
, s
, r
;
4430 assert(immn
< 2 && imms
< 64 && immr
< 64);
4432 /* The bit patterns we create here are 64 bit patterns which
4433 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
4434 * 64 bits each. Each element contains the same value: a run
4435 * of between 1 and e-1 non-zero bits, rotated within the
4436 * element by between 0 and e-1 bits.
4438 * The element size and run length are encoded into immn (1 bit)
4439 * and imms (6 bits) as follows:
4440 * 64 bit elements: immn = 1, imms = <length of run - 1>
4441 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
4442 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
4443 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
4444 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
4445 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
4446 * Notice that immn = 0, imms = 11111x is the only combination
4447 * not covered by one of the above options; this is reserved.
4448 * Further, <length of run - 1> all-ones is a reserved pattern.
4450 * In all cases the rotation is by immr % e (and immr is 6 bits).
4453 /* First determine the element size */
4454 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
4456 /* This is the immn == 0, imms == 0x11111x case */
4466 /* <length of run - 1> mustn't be all-ones. */
4470 /* Create the value of one element: s+1 set bits rotated
4471 * by r within the element (which is e bits wide)...
4473 mask
= bitmask64(s
+ 1);
4475 mask
= (mask
>> r
) | (mask
<< (e
- r
));
4476 mask
&= bitmask64(e
);
4478 /* ...then replicate the element over the whole 64 bit value */
4479 mask
= bitfield_replicate(mask
, e
);
4484 /* Logical (immediate)
4485 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
4486 * +----+-----+-------------+---+------+------+------+------+
4487 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
4488 * +----+-----+-------------+---+------+------+------+------+
4490 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
4492 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
4493 TCGv_i64 tcg_rd
, tcg_rn
;
4495 bool is_and
= false;
4497 sf
= extract32(insn
, 31, 1);
4498 opc
= extract32(insn
, 29, 2);
4499 is_n
= extract32(insn
, 22, 1);
4500 immr
= extract32(insn
, 16, 6);
4501 imms
= extract32(insn
, 10, 6);
4502 rn
= extract32(insn
, 5, 5);
4503 rd
= extract32(insn
, 0, 5);
4506 unallocated_encoding(s
);
4510 if (opc
== 0x3) { /* ANDS */
4511 tcg_rd
= cpu_reg(s
, rd
);
4513 tcg_rd
= cpu_reg_sp(s
, rd
);
4515 tcg_rn
= cpu_reg(s
, rn
);
4517 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
4518 /* some immediate field values are reserved */
4519 unallocated_encoding(s
);
4524 wmask
&= 0xffffffff;
4528 case 0x3: /* ANDS */
4530 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
4534 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
4537 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
4540 assert(FALSE
); /* must handle all above */
4544 if (!sf
&& !is_and
) {
4545 /* zero extend final result; we know we can skip this for AND
4546 * since the immediate had the high 32 bits clear.
4548 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4551 if (opc
== 3) { /* ANDS */
4552 gen_logic_CC(sf
, tcg_rd
);
4557 * Move wide (immediate)
4559 * 31 30 29 28 23 22 21 20 5 4 0
4560 * +--+-----+-------------+-----+----------------+------+
4561 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
4562 * +--+-----+-------------+-----+----------------+------+
4564 * sf: 0 -> 32 bit, 1 -> 64 bit
4565 * opc: 00 -> N, 10 -> Z, 11 -> K
4566 * hw: shift/16 (0,16, and sf only 32, 48)
4568 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
4570 int rd
= extract32(insn
, 0, 5);
4571 uint64_t imm
= extract32(insn
, 5, 16);
4572 int sf
= extract32(insn
, 31, 1);
4573 int opc
= extract32(insn
, 29, 2);
4574 int pos
= extract32(insn
, 21, 2) << 4;
4575 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4577 if (!sf
&& (pos
>= 32)) {
4578 unallocated_encoding(s
);
4592 tcg_gen_movi_i64(tcg_rd
, imm
);
4595 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_constant_i64(imm
), pos
, 16);
4597 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4601 unallocated_encoding(s
);
4607 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
4608 * +----+-----+-------------+---+------+------+------+------+
4609 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
4610 * +----+-----+-------------+---+------+------+------+------+
4612 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
4614 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
4615 TCGv_i64 tcg_rd
, tcg_tmp
;
4617 sf
= extract32(insn
, 31, 1);
4618 opc
= extract32(insn
, 29, 2);
4619 n
= extract32(insn
, 22, 1);
4620 ri
= extract32(insn
, 16, 6);
4621 si
= extract32(insn
, 10, 6);
4622 rn
= extract32(insn
, 5, 5);
4623 rd
= extract32(insn
, 0, 5);
4624 bitsize
= sf
? 64 : 32;
4626 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
4627 unallocated_encoding(s
);
4631 tcg_rd
= cpu_reg(s
, rd
);
4633 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
4634 to be smaller than bitsize, we'll never reference data outside the
4635 low 32-bits anyway. */
4636 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
4638 /* Recognize simple(r) extractions. */
4640 /* Wd<s-r:0> = Wn<s:r> */
4641 len
= (si
- ri
) + 1;
4642 if (opc
== 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
4643 tcg_gen_sextract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
4645 } else if (opc
== 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
4646 tcg_gen_extract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
4649 /* opc == 1, BFXIL fall through to deposit */
4650 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
4653 /* Handle the ri > si case with a deposit
4654 * Wd<32+s-r,32-r> = Wn<s:0>
4657 pos
= (bitsize
- ri
) & (bitsize
- 1);
4660 if (opc
== 0 && len
< ri
) {
4661 /* SBFM: sign extend the destination field from len to fill
4662 the balance of the word. Let the deposit below insert all
4663 of those sign bits. */
4664 tcg_gen_sextract_i64(tcg_tmp
, tcg_tmp
, 0, len
);
4668 if (opc
== 1) { /* BFM, BFXIL */
4669 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
4671 /* SBFM or UBFM: We start with zero, and we haven't modified
4672 any bits outside bitsize, therefore the zero-extension
4673 below is unneeded. */
4674 tcg_gen_deposit_z_i64(tcg_rd
, tcg_tmp
, pos
, len
);
4679 if (!sf
) { /* zero extend final result */
4680 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4685 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
4686 * +----+------+-------------+---+----+------+--------+------+------+
4687 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
4688 * +----+------+-------------+---+----+------+--------+------+------+
4690 static void disas_extract(DisasContext
*s
, uint32_t insn
)
4692 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
4694 sf
= extract32(insn
, 31, 1);
4695 n
= extract32(insn
, 22, 1);
4696 rm
= extract32(insn
, 16, 5);
4697 imm
= extract32(insn
, 10, 6);
4698 rn
= extract32(insn
, 5, 5);
4699 rd
= extract32(insn
, 0, 5);
4700 op21
= extract32(insn
, 29, 2);
4701 op0
= extract32(insn
, 21, 1);
4702 bitsize
= sf
? 64 : 32;
4704 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
4705 unallocated_encoding(s
);
4707 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
4709 tcg_rd
= cpu_reg(s
, rd
);
4711 if (unlikely(imm
== 0)) {
4712 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
4713 * so an extract from bit 0 is a special case.
4716 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
4718 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
4721 tcg_rm
= cpu_reg(s
, rm
);
4722 tcg_rn
= cpu_reg(s
, rn
);
4725 /* Specialization to ROR happens in EXTRACT2. */
4726 tcg_gen_extract2_i64(tcg_rd
, tcg_rm
, tcg_rn
, imm
);
4728 TCGv_i32 t0
= tcg_temp_new_i32();
4730 tcg_gen_extrl_i64_i32(t0
, tcg_rm
);
4732 tcg_gen_rotri_i32(t0
, t0
, imm
);
4734 TCGv_i32 t1
= tcg_temp_new_i32();
4735 tcg_gen_extrl_i64_i32(t1
, tcg_rn
);
4736 tcg_gen_extract2_i32(t0
, t0
, t1
, imm
);
4737 tcg_temp_free_i32(t1
);
4739 tcg_gen_extu_i32_i64(tcg_rd
, t0
);
4740 tcg_temp_free_i32(t0
);
4746 /* Data processing - immediate */
4747 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
4749 switch (extract32(insn
, 23, 6)) {
4750 case 0x20: case 0x21: /* PC-rel. addressing */
4751 disas_pc_rel_adr(s
, insn
);
4753 case 0x22: /* Add/subtract (immediate) */
4754 disas_add_sub_imm(s
, insn
);
4756 case 0x23: /* Add/subtract (immediate, with tags) */
4757 disas_add_sub_imm_with_tags(s
, insn
);
4759 case 0x24: /* Logical (immediate) */
4760 disas_logic_imm(s
, insn
);
4762 case 0x25: /* Move wide (immediate) */
4763 disas_movw_imm(s
, insn
);
4765 case 0x26: /* Bitfield */
4766 disas_bitfield(s
, insn
);
4768 case 0x27: /* Extract */
4769 disas_extract(s
, insn
);
4772 unallocated_encoding(s
);
4777 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
4778 * Note that it is the caller's responsibility to ensure that the
4779 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
4780 * mandated semantics for out of range shifts.
4782 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4783 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
4785 switch (shift_type
) {
4786 case A64_SHIFT_TYPE_LSL
:
4787 tcg_gen_shl_i64(dst
, src
, shift_amount
);
4789 case A64_SHIFT_TYPE_LSR
:
4790 tcg_gen_shr_i64(dst
, src
, shift_amount
);
4792 case A64_SHIFT_TYPE_ASR
:
4794 tcg_gen_ext32s_i64(dst
, src
);
4796 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
4798 case A64_SHIFT_TYPE_ROR
:
4800 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
4803 t0
= tcg_temp_new_i32();
4804 t1
= tcg_temp_new_i32();
4805 tcg_gen_extrl_i64_i32(t0
, src
);
4806 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
4807 tcg_gen_rotr_i32(t0
, t0
, t1
);
4808 tcg_gen_extu_i32_i64(dst
, t0
);
4809 tcg_temp_free_i32(t0
);
4810 tcg_temp_free_i32(t1
);
4814 assert(FALSE
); /* all shift types should be handled */
4818 if (!sf
) { /* zero extend final result */
4819 tcg_gen_ext32u_i64(dst
, dst
);
4823 /* Shift a TCGv src by immediate, put result in dst.
4824 * The shift amount must be in range (this should always be true as the
4825 * relevant instructions will UNDEF on bad shift immediates).
4827 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4828 enum a64_shift_type shift_type
, unsigned int shift_i
)
4830 assert(shift_i
< (sf
? 64 : 32));
4833 tcg_gen_mov_i64(dst
, src
);
4835 shift_reg(dst
, src
, sf
, shift_type
, tcg_constant_i64(shift_i
));
4839 /* Logical (shifted register)
4840 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4841 * +----+-----+-----------+-------+---+------+--------+------+------+
4842 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
4843 * +----+-----+-----------+-------+---+------+--------+------+------+
4845 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
4847 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
4848 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
4850 sf
= extract32(insn
, 31, 1);
4851 opc
= extract32(insn
, 29, 2);
4852 shift_type
= extract32(insn
, 22, 2);
4853 invert
= extract32(insn
, 21, 1);
4854 rm
= extract32(insn
, 16, 5);
4855 shift_amount
= extract32(insn
, 10, 6);
4856 rn
= extract32(insn
, 5, 5);
4857 rd
= extract32(insn
, 0, 5);
4859 if (!sf
&& (shift_amount
& (1 << 5))) {
4860 unallocated_encoding(s
);
4864 tcg_rd
= cpu_reg(s
, rd
);
4866 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
4867 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
4868 * register-register MOV and MVN, so it is worth special casing.
4870 tcg_rm
= cpu_reg(s
, rm
);
4872 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
4874 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4878 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
4880 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
4886 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4889 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
4892 tcg_rn
= cpu_reg(s
, rn
);
4894 switch (opc
| (invert
<< 2)) {
4897 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4900 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4903 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4907 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4910 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4913 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4921 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4925 gen_logic_CC(sf
, tcg_rd
);
4930 * Add/subtract (extended register)
4932 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
4933 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4934 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
4935 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4937 * sf: 0 -> 32bit, 1 -> 64bit
4938 * op: 0 -> add , 1 -> sub
4941 * option: extension type (see DecodeRegExtend)
4942 * imm3: optional shift to Rm
4944 * Rd = Rn + LSL(extend(Rm), amount)
4946 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
4948 int rd
= extract32(insn
, 0, 5);
4949 int rn
= extract32(insn
, 5, 5);
4950 int imm3
= extract32(insn
, 10, 3);
4951 int option
= extract32(insn
, 13, 3);
4952 int rm
= extract32(insn
, 16, 5);
4953 int opt
= extract32(insn
, 22, 2);
4954 bool setflags
= extract32(insn
, 29, 1);
4955 bool sub_op
= extract32(insn
, 30, 1);
4956 bool sf
= extract32(insn
, 31, 1);
4958 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
4960 TCGv_i64 tcg_result
;
4962 if (imm3
> 4 || opt
!= 0) {
4963 unallocated_encoding(s
);
4967 /* non-flag setting ops may use SP */
4969 tcg_rd
= cpu_reg_sp(s
, rd
);
4971 tcg_rd
= cpu_reg(s
, rd
);
4973 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
4975 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4976 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
4978 tcg_result
= tcg_temp_new_i64();
4982 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4984 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4988 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4990 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4995 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4997 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
5000 tcg_temp_free_i64(tcg_result
);
5004 * Add/subtract (shifted register)
5006 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
5007 * +--+--+--+-----------+-----+--+-------+---------+------+------+
5008 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
5009 * +--+--+--+-----------+-----+--+-------+---------+------+------+
5011 * sf: 0 -> 32bit, 1 -> 64bit
5012 * op: 0 -> add , 1 -> sub
5014 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
5015 * imm6: Shift amount to apply to Rm before the add/sub
5017 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
5019 int rd
= extract32(insn
, 0, 5);
5020 int rn
= extract32(insn
, 5, 5);
5021 int imm6
= extract32(insn
, 10, 6);
5022 int rm
= extract32(insn
, 16, 5);
5023 int shift_type
= extract32(insn
, 22, 2);
5024 bool setflags
= extract32(insn
, 29, 1);
5025 bool sub_op
= extract32(insn
, 30, 1);
5026 bool sf
= extract32(insn
, 31, 1);
5028 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5029 TCGv_i64 tcg_rn
, tcg_rm
;
5030 TCGv_i64 tcg_result
;
5032 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
5033 unallocated_encoding(s
);
5037 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
5038 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
5040 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
5042 tcg_result
= tcg_temp_new_i64();
5046 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
5048 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
5052 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
5054 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
5059 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
5061 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
5064 tcg_temp_free_i64(tcg_result
);
5067 /* Data-processing (3 source)
5069 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
5070 * +--+------+-----------+------+------+----+------+------+------+
5071 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
5072 * +--+------+-----------+------+------+----+------+------+------+
5074 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
5076 int rd
= extract32(insn
, 0, 5);
5077 int rn
= extract32(insn
, 5, 5);
5078 int ra
= extract32(insn
, 10, 5);
5079 int rm
= extract32(insn
, 16, 5);
5080 int op_id
= (extract32(insn
, 29, 3) << 4) |
5081 (extract32(insn
, 21, 3) << 1) |
5082 extract32(insn
, 15, 1);
5083 bool sf
= extract32(insn
, 31, 1);
5084 bool is_sub
= extract32(op_id
, 0, 1);
5085 bool is_high
= extract32(op_id
, 2, 1);
5086 bool is_signed
= false;
5091 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
5093 case 0x42: /* SMADDL */
5094 case 0x43: /* SMSUBL */
5095 case 0x44: /* SMULH */
5098 case 0x0: /* MADD (32bit) */
5099 case 0x1: /* MSUB (32bit) */
5100 case 0x40: /* MADD (64bit) */
5101 case 0x41: /* MSUB (64bit) */
5102 case 0x4a: /* UMADDL */
5103 case 0x4b: /* UMSUBL */
5104 case 0x4c: /* UMULH */
5107 unallocated_encoding(s
);
5112 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
5113 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5114 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
5115 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
5118 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
5120 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
5123 tcg_temp_free_i64(low_bits
);
5127 tcg_op1
= tcg_temp_new_i64();
5128 tcg_op2
= tcg_temp_new_i64();
5129 tcg_tmp
= tcg_temp_new_i64();
5132 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
5133 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
5136 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
5137 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
5139 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
5140 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
5144 if (ra
== 31 && !is_sub
) {
5145 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
5146 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
5148 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
5150 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
5152 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
5157 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
5160 tcg_temp_free_i64(tcg_op1
);
5161 tcg_temp_free_i64(tcg_op2
);
5162 tcg_temp_free_i64(tcg_tmp
);
5165 /* Add/subtract (with carry)
5166 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
5167 * +--+--+--+------------------------+------+-------------+------+-----+
5168 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | 0 0 0 0 0 0 | Rn | Rd |
5169 * +--+--+--+------------------------+------+-------------+------+-----+
5172 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
5174 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
5175 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
5177 sf
= extract32(insn
, 31, 1);
5178 op
= extract32(insn
, 30, 1);
5179 setflags
= extract32(insn
, 29, 1);
5180 rm
= extract32(insn
, 16, 5);
5181 rn
= extract32(insn
, 5, 5);
5182 rd
= extract32(insn
, 0, 5);
5184 tcg_rd
= cpu_reg(s
, rd
);
5185 tcg_rn
= cpu_reg(s
, rn
);
5188 tcg_y
= new_tmp_a64(s
);
5189 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
5191 tcg_y
= cpu_reg(s
, rm
);
5195 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
5197 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
5202 * Rotate right into flags
5203 * 31 30 29 21 15 10 5 4 0
5204 * +--+--+--+-----------------+--------+-----------+------+--+------+
5205 * |sf|op| S| 1 1 0 1 0 0 0 0 | imm6 | 0 0 0 0 1 | Rn |o2| mask |
5206 * +--+--+--+-----------------+--------+-----------+------+--+------+
5208 static void disas_rotate_right_into_flags(DisasContext
*s
, uint32_t insn
)
5210 int mask
= extract32(insn
, 0, 4);
5211 int o2
= extract32(insn
, 4, 1);
5212 int rn
= extract32(insn
, 5, 5);
5213 int imm6
= extract32(insn
, 15, 6);
5214 int sf_op_s
= extract32(insn
, 29, 3);
5218 if (sf_op_s
!= 5 || o2
!= 0 || !dc_isar_feature(aa64_condm_4
, s
)) {
5219 unallocated_encoding(s
);
5223 tcg_rn
= read_cpu_reg(s
, rn
, 1);
5224 tcg_gen_rotri_i64(tcg_rn
, tcg_rn
, imm6
);
5226 nzcv
= tcg_temp_new_i32();
5227 tcg_gen_extrl_i64_i32(nzcv
, tcg_rn
);
5229 if (mask
& 8) { /* N */
5230 tcg_gen_shli_i32(cpu_NF
, nzcv
, 31 - 3);
5232 if (mask
& 4) { /* Z */
5233 tcg_gen_not_i32(cpu_ZF
, nzcv
);
5234 tcg_gen_andi_i32(cpu_ZF
, cpu_ZF
, 4);
5236 if (mask
& 2) { /* C */
5237 tcg_gen_extract_i32(cpu_CF
, nzcv
, 1, 1);
5239 if (mask
& 1) { /* V */
5240 tcg_gen_shli_i32(cpu_VF
, nzcv
, 31 - 0);
5243 tcg_temp_free_i32(nzcv
);
5247 * Evaluate into flags
5248 * 31 30 29 21 15 14 10 5 4 0
5249 * +--+--+--+-----------------+---------+----+---------+------+--+------+
5250 * |sf|op| S| 1 1 0 1 0 0 0 0 | opcode2 | sz | 0 0 1 0 | Rn |o3| mask |
5251 * +--+--+--+-----------------+---------+----+---------+------+--+------+
5253 static void disas_evaluate_into_flags(DisasContext
*s
, uint32_t insn
)
5255 int o3_mask
= extract32(insn
, 0, 5);
5256 int rn
= extract32(insn
, 5, 5);
5257 int o2
= extract32(insn
, 15, 6);
5258 int sz
= extract32(insn
, 14, 1);
5259 int sf_op_s
= extract32(insn
, 29, 3);
5263 if (sf_op_s
!= 1 || o2
!= 0 || o3_mask
!= 0xd ||
5264 !dc_isar_feature(aa64_condm_4
, s
)) {
5265 unallocated_encoding(s
);
5268 shift
= sz
? 16 : 24; /* SETF16 or SETF8 */
5270 tmp
= tcg_temp_new_i32();
5271 tcg_gen_extrl_i64_i32(tmp
, cpu_reg(s
, rn
));
5272 tcg_gen_shli_i32(cpu_NF
, tmp
, shift
);
5273 tcg_gen_shli_i32(cpu_VF
, tmp
, shift
- 1);
5274 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
5275 tcg_gen_xor_i32(cpu_VF
, cpu_VF
, cpu_NF
);
5276 tcg_temp_free_i32(tmp
);
5279 /* Conditional compare (immediate / register)
5280 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
5281 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
5282 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
5283 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
5286 static void disas_cc(DisasContext
*s
, uint32_t insn
)
5288 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
5289 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
5290 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
5293 if (!extract32(insn
, 29, 1)) {
5294 unallocated_encoding(s
);
5297 if (insn
& (1 << 10 | 1 << 4)) {
5298 unallocated_encoding(s
);
5301 sf
= extract32(insn
, 31, 1);
5302 op
= extract32(insn
, 30, 1);
5303 is_imm
= extract32(insn
, 11, 1);
5304 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
5305 cond
= extract32(insn
, 12, 4);
5306 rn
= extract32(insn
, 5, 5);
5307 nzcv
= extract32(insn
, 0, 4);
5309 /* Set T0 = !COND. */
5310 tcg_t0
= tcg_temp_new_i32();
5311 arm_test_cc(&c
, cond
);
5312 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
5314 /* Load the arguments for the new comparison. */
5316 tcg_y
= new_tmp_a64(s
);
5317 tcg_gen_movi_i64(tcg_y
, y
);
5319 tcg_y
= cpu_reg(s
, y
);
5321 tcg_rn
= cpu_reg(s
, rn
);
5323 /* Set the flags for the new comparison. */
5324 tcg_tmp
= tcg_temp_new_i64();
5326 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
5328 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
5330 tcg_temp_free_i64(tcg_tmp
);
5332 /* If COND was false, force the flags to #nzcv. Compute two masks
5333 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
5334 * For tcg hosts that support ANDC, we can make do with just T1.
5335 * In either case, allow the tcg optimizer to delete any unused mask.
5337 tcg_t1
= tcg_temp_new_i32();
5338 tcg_t2
= tcg_temp_new_i32();
5339 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
5340 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
5342 if (nzcv
& 8) { /* N */
5343 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
5345 if (TCG_TARGET_HAS_andc_i32
) {
5346 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
5348 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
5351 if (nzcv
& 4) { /* Z */
5352 if (TCG_TARGET_HAS_andc_i32
) {
5353 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
5355 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
5358 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
5360 if (nzcv
& 2) { /* C */
5361 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
5363 if (TCG_TARGET_HAS_andc_i32
) {
5364 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
5366 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
5369 if (nzcv
& 1) { /* V */
5370 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
5372 if (TCG_TARGET_HAS_andc_i32
) {
5373 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
5375 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
5378 tcg_temp_free_i32(tcg_t0
);
5379 tcg_temp_free_i32(tcg_t1
);
5380 tcg_temp_free_i32(tcg_t2
);
5383 /* Conditional select
5384 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
5385 * +----+----+---+-----------------+------+------+-----+------+------+
5386 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
5387 * +----+----+---+-----------------+------+------+-----+------+------+
5389 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
5391 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
5392 TCGv_i64 tcg_rd
, zero
;
5395 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
5396 /* S == 1 or op2<1> == 1 */
5397 unallocated_encoding(s
);
5400 sf
= extract32(insn
, 31, 1);
5401 else_inv
= extract32(insn
, 30, 1);
5402 rm
= extract32(insn
, 16, 5);
5403 cond
= extract32(insn
, 12, 4);
5404 else_inc
= extract32(insn
, 10, 1);
5405 rn
= extract32(insn
, 5, 5);
5406 rd
= extract32(insn
, 0, 5);
5408 tcg_rd
= cpu_reg(s
, rd
);
5410 a64_test_cc(&c
, cond
);
5411 zero
= tcg_constant_i64(0);
5413 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
5415 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
5417 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
5420 TCGv_i64 t_true
= cpu_reg(s
, rn
);
5421 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
5422 if (else_inv
&& else_inc
) {
5423 tcg_gen_neg_i64(t_false
, t_false
);
5424 } else if (else_inv
) {
5425 tcg_gen_not_i64(t_false
, t_false
);
5426 } else if (else_inc
) {
5427 tcg_gen_addi_i64(t_false
, t_false
, 1);
5429 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
5433 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5437 static void handle_clz(DisasContext
*s
, unsigned int sf
,
5438 unsigned int rn
, unsigned int rd
)
5440 TCGv_i64 tcg_rd
, tcg_rn
;
5441 tcg_rd
= cpu_reg(s
, rd
);
5442 tcg_rn
= cpu_reg(s
, rn
);
5445 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
5447 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
5448 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
5449 tcg_gen_clzi_i32(tcg_tmp32
, tcg_tmp32
, 32);
5450 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
5451 tcg_temp_free_i32(tcg_tmp32
);
5455 static void handle_cls(DisasContext
*s
, unsigned int sf
,
5456 unsigned int rn
, unsigned int rd
)
5458 TCGv_i64 tcg_rd
, tcg_rn
;
5459 tcg_rd
= cpu_reg(s
, rd
);
5460 tcg_rn
= cpu_reg(s
, rn
);
5463 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
5465 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
5466 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
5467 tcg_gen_clrsb_i32(tcg_tmp32
, tcg_tmp32
);
5468 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
5469 tcg_temp_free_i32(tcg_tmp32
);
5473 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
5474 unsigned int rn
, unsigned int rd
)
5476 TCGv_i64 tcg_rd
, tcg_rn
;
5477 tcg_rd
= cpu_reg(s
, rd
);
5478 tcg_rn
= cpu_reg(s
, rn
);
5481 gen_helper_rbit64(tcg_rd
, tcg_rn
);
5483 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
5484 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
5485 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
5486 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
5487 tcg_temp_free_i32(tcg_tmp32
);
5491 /* REV with sf==1, opcode==3 ("REV64") */
5492 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
5493 unsigned int rn
, unsigned int rd
)
5496 unallocated_encoding(s
);
5499 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
5502 /* REV with sf==0, opcode==2
5503 * REV32 (sf==1, opcode==2)
5505 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
5506 unsigned int rn
, unsigned int rd
)
5508 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5509 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
5512 tcg_gen_bswap64_i64(tcg_rd
, tcg_rn
);
5513 tcg_gen_rotri_i64(tcg_rd
, tcg_rd
, 32);
5515 tcg_gen_bswap32_i64(tcg_rd
, tcg_rn
, TCG_BSWAP_OZ
);
5519 /* REV16 (opcode==1) */
5520 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
5521 unsigned int rn
, unsigned int rd
)
5523 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5524 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5525 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
5526 TCGv_i64 mask
= tcg_constant_i64(sf
? 0x00ff00ff00ff00ffull
: 0x00ff00ff);
5528 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 8);
5529 tcg_gen_and_i64(tcg_rd
, tcg_rn
, mask
);
5530 tcg_gen_and_i64(tcg_tmp
, tcg_tmp
, mask
);
5531 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 8);
5532 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
5534 tcg_temp_free_i64(tcg_tmp
);
5537 /* Data-processing (1 source)
5538 * 31 30 29 28 21 20 16 15 10 9 5 4 0
5539 * +----+---+---+-----------------+---------+--------+------+------+
5540 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
5541 * +----+---+---+-----------------+---------+--------+------+------+
5543 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
5545 unsigned int sf
, opcode
, opcode2
, rn
, rd
;
5548 if (extract32(insn
, 29, 1)) {
5549 unallocated_encoding(s
);
5553 sf
= extract32(insn
, 31, 1);
5554 opcode
= extract32(insn
, 10, 6);
5555 opcode2
= extract32(insn
, 16, 5);
5556 rn
= extract32(insn
, 5, 5);
5557 rd
= extract32(insn
, 0, 5);
5559 #define MAP(SF, O2, O1) ((SF) | (O1 << 1) | (O2 << 7))
5561 switch (MAP(sf
, opcode2
, opcode
)) {
5562 case MAP(0, 0x00, 0x00): /* RBIT */
5563 case MAP(1, 0x00, 0x00):
5564 handle_rbit(s
, sf
, rn
, rd
);
5566 case MAP(0, 0x00, 0x01): /* REV16 */
5567 case MAP(1, 0x00, 0x01):
5568 handle_rev16(s
, sf
, rn
, rd
);
5570 case MAP(0, 0x00, 0x02): /* REV/REV32 */
5571 case MAP(1, 0x00, 0x02):
5572 handle_rev32(s
, sf
, rn
, rd
);
5574 case MAP(1, 0x00, 0x03): /* REV64 */
5575 handle_rev64(s
, sf
, rn
, rd
);
5577 case MAP(0, 0x00, 0x04): /* CLZ */
5578 case MAP(1, 0x00, 0x04):
5579 handle_clz(s
, sf
, rn
, rd
);
5581 case MAP(0, 0x00, 0x05): /* CLS */
5582 case MAP(1, 0x00, 0x05):
5583 handle_cls(s
, sf
, rn
, rd
);
5585 case MAP(1, 0x01, 0x00): /* PACIA */
5586 if (s
->pauth_active
) {
5587 tcg_rd
= cpu_reg(s
, rd
);
5588 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5589 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5590 goto do_unallocated
;
5593 case MAP(1, 0x01, 0x01): /* PACIB */
5594 if (s
->pauth_active
) {
5595 tcg_rd
= cpu_reg(s
, rd
);
5596 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5597 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5598 goto do_unallocated
;
5601 case MAP(1, 0x01, 0x02): /* PACDA */
5602 if (s
->pauth_active
) {
5603 tcg_rd
= cpu_reg(s
, rd
);
5604 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5605 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5606 goto do_unallocated
;
5609 case MAP(1, 0x01, 0x03): /* PACDB */
5610 if (s
->pauth_active
) {
5611 tcg_rd
= cpu_reg(s
, rd
);
5612 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5613 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5614 goto do_unallocated
;
5617 case MAP(1, 0x01, 0x04): /* AUTIA */
5618 if (s
->pauth_active
) {
5619 tcg_rd
= cpu_reg(s
, rd
);
5620 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5621 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5622 goto do_unallocated
;
5625 case MAP(1, 0x01, 0x05): /* AUTIB */
5626 if (s
->pauth_active
) {
5627 tcg_rd
= cpu_reg(s
, rd
);
5628 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5629 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5630 goto do_unallocated
;
5633 case MAP(1, 0x01, 0x06): /* AUTDA */
5634 if (s
->pauth_active
) {
5635 tcg_rd
= cpu_reg(s
, rd
);
5636 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5637 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5638 goto do_unallocated
;
5641 case MAP(1, 0x01, 0x07): /* AUTDB */
5642 if (s
->pauth_active
) {
5643 tcg_rd
= cpu_reg(s
, rd
);
5644 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
5645 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
5646 goto do_unallocated
;
5649 case MAP(1, 0x01, 0x08): /* PACIZA */
5650 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5651 goto do_unallocated
;
5652 } else if (s
->pauth_active
) {
5653 tcg_rd
= cpu_reg(s
, rd
);
5654 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5657 case MAP(1, 0x01, 0x09): /* PACIZB */
5658 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5659 goto do_unallocated
;
5660 } else if (s
->pauth_active
) {
5661 tcg_rd
= cpu_reg(s
, rd
);
5662 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5665 case MAP(1, 0x01, 0x0a): /* PACDZA */
5666 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5667 goto do_unallocated
;
5668 } else if (s
->pauth_active
) {
5669 tcg_rd
= cpu_reg(s
, rd
);
5670 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5673 case MAP(1, 0x01, 0x0b): /* PACDZB */
5674 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5675 goto do_unallocated
;
5676 } else if (s
->pauth_active
) {
5677 tcg_rd
= cpu_reg(s
, rd
);
5678 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5681 case MAP(1, 0x01, 0x0c): /* AUTIZA */
5682 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5683 goto do_unallocated
;
5684 } else if (s
->pauth_active
) {
5685 tcg_rd
= cpu_reg(s
, rd
);
5686 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5689 case MAP(1, 0x01, 0x0d): /* AUTIZB */
5690 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5691 goto do_unallocated
;
5692 } else if (s
->pauth_active
) {
5693 tcg_rd
= cpu_reg(s
, rd
);
5694 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5697 case MAP(1, 0x01, 0x0e): /* AUTDZA */
5698 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5699 goto do_unallocated
;
5700 } else if (s
->pauth_active
) {
5701 tcg_rd
= cpu_reg(s
, rd
);
5702 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5705 case MAP(1, 0x01, 0x0f): /* AUTDZB */
5706 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5707 goto do_unallocated
;
5708 } else if (s
->pauth_active
) {
5709 tcg_rd
= cpu_reg(s
, rd
);
5710 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5713 case MAP(1, 0x01, 0x10): /* XPACI */
5714 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5715 goto do_unallocated
;
5716 } else if (s
->pauth_active
) {
5717 tcg_rd
= cpu_reg(s
, rd
);
5718 gen_helper_xpaci(tcg_rd
, cpu_env
, tcg_rd
);
5721 case MAP(1, 0x01, 0x11): /* XPACD */
5722 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5723 goto do_unallocated
;
5724 } else if (s
->pauth_active
) {
5725 tcg_rd
= cpu_reg(s
, rd
);
5726 gen_helper_xpacd(tcg_rd
, cpu_env
, tcg_rd
);
5731 unallocated_encoding(s
);
5738 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
5739 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5741 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
5742 tcg_rd
= cpu_reg(s
, rd
);
5744 if (!sf
&& is_signed
) {
5745 tcg_n
= new_tmp_a64(s
);
5746 tcg_m
= new_tmp_a64(s
);
5747 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
5748 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
5750 tcg_n
= read_cpu_reg(s
, rn
, sf
);
5751 tcg_m
= read_cpu_reg(s
, rm
, sf
);
5755 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
5757 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
5760 if (!sf
) { /* zero extend final result */
5761 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5765 /* LSLV, LSRV, ASRV, RORV */
5766 static void handle_shift_reg(DisasContext
*s
,
5767 enum a64_shift_type shift_type
, unsigned int sf
,
5768 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5770 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
5771 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5772 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
5774 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
5775 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
5776 tcg_temp_free_i64(tcg_shift
);
5779 /* CRC32[BHWX], CRC32C[BHWX] */
5780 static void handle_crc32(DisasContext
*s
,
5781 unsigned int sf
, unsigned int sz
, bool crc32c
,
5782 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5784 TCGv_i64 tcg_acc
, tcg_val
;
5787 if (!dc_isar_feature(aa64_crc32
, s
)
5788 || (sf
== 1 && sz
!= 3)
5789 || (sf
== 0 && sz
== 3)) {
5790 unallocated_encoding(s
);
5795 tcg_val
= cpu_reg(s
, rm
);
5809 g_assert_not_reached();
5811 tcg_val
= new_tmp_a64(s
);
5812 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
5815 tcg_acc
= cpu_reg(s
, rn
);
5816 tcg_bytes
= tcg_constant_i32(1 << sz
);
5819 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5821 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5825 /* Data-processing (2 source)
5826 * 31 30 29 28 21 20 16 15 10 9 5 4 0
5827 * +----+---+---+-----------------+------+--------+------+------+
5828 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
5829 * +----+---+---+-----------------+------+--------+------+------+
5831 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
5833 unsigned int sf
, rm
, opcode
, rn
, rd
, setflag
;
5834 sf
= extract32(insn
, 31, 1);
5835 setflag
= extract32(insn
, 29, 1);
5836 rm
= extract32(insn
, 16, 5);
5837 opcode
= extract32(insn
, 10, 6);
5838 rn
= extract32(insn
, 5, 5);
5839 rd
= extract32(insn
, 0, 5);
5841 if (setflag
&& opcode
!= 0) {
5842 unallocated_encoding(s
);
5847 case 0: /* SUBP(S) */
5848 if (sf
== 0 || !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
5849 goto do_unallocated
;
5851 TCGv_i64 tcg_n
, tcg_m
, tcg_d
;
5853 tcg_n
= read_cpu_reg_sp(s
, rn
, true);
5854 tcg_m
= read_cpu_reg_sp(s
, rm
, true);
5855 tcg_gen_sextract_i64(tcg_n
, tcg_n
, 0, 56);
5856 tcg_gen_sextract_i64(tcg_m
, tcg_m
, 0, 56);
5857 tcg_d
= cpu_reg(s
, rd
);
5860 gen_sub_CC(true, tcg_d
, tcg_n
, tcg_m
);
5862 tcg_gen_sub_i64(tcg_d
, tcg_n
, tcg_m
);
5867 handle_div(s
, false, sf
, rm
, rn
, rd
);
5870 handle_div(s
, true, sf
, rm
, rn
, rd
);
5873 if (sf
== 0 || !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
5874 goto do_unallocated
;
5877 gen_helper_irg(cpu_reg_sp(s
, rd
), cpu_env
,
5878 cpu_reg_sp(s
, rn
), cpu_reg(s
, rm
));
5880 gen_address_with_allocation_tag0(cpu_reg_sp(s
, rd
),
5885 if (sf
== 0 || !dc_isar_feature(aa64_mte_insn_reg
, s
)) {
5886 goto do_unallocated
;
5888 TCGv_i64 t
= tcg_temp_new_i64();
5890 tcg_gen_extract_i64(t
, cpu_reg_sp(s
, rn
), 56, 4);
5891 tcg_gen_shl_i64(t
, tcg_constant_i64(1), t
);
5892 tcg_gen_or_i64(cpu_reg(s
, rd
), cpu_reg(s
, rm
), t
);
5894 tcg_temp_free_i64(t
);
5898 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
5901 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
5904 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
5907 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
5909 case 12: /* PACGA */
5910 if (sf
== 0 || !dc_isar_feature(aa64_pauth
, s
)) {
5911 goto do_unallocated
;
5913 gen_helper_pacga(cpu_reg(s
, rd
), cpu_env
,
5914 cpu_reg(s
, rn
), cpu_reg_sp(s
, rm
));
5923 case 23: /* CRC32 */
5925 int sz
= extract32(opcode
, 0, 2);
5926 bool crc32c
= extract32(opcode
, 2, 1);
5927 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
5932 unallocated_encoding(s
);
5938 * Data processing - register
5939 * 31 30 29 28 25 21 20 16 10 0
5940 * +--+---+--+---+-------+-----+-------+-------+---------+
5941 * | |op0| |op1| 1 0 1 | op2 | | op3 | |
5942 * +--+---+--+---+-------+-----+-------+-------+---------+
5944 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
5946 int op0
= extract32(insn
, 30, 1);
5947 int op1
= extract32(insn
, 28, 1);
5948 int op2
= extract32(insn
, 21, 4);
5949 int op3
= extract32(insn
, 10, 6);
5954 /* Add/sub (extended register) */
5955 disas_add_sub_ext_reg(s
, insn
);
5957 /* Add/sub (shifted register) */
5958 disas_add_sub_reg(s
, insn
);
5961 /* Logical (shifted register) */
5962 disas_logic_reg(s
, insn
);
5970 case 0x00: /* Add/subtract (with carry) */
5971 disas_adc_sbc(s
, insn
);
5974 case 0x01: /* Rotate right into flags */
5976 disas_rotate_right_into_flags(s
, insn
);
5979 case 0x02: /* Evaluate into flags */
5983 disas_evaluate_into_flags(s
, insn
);
5987 goto do_unallocated
;
5991 case 0x2: /* Conditional compare */
5992 disas_cc(s
, insn
); /* both imm and reg forms */
5995 case 0x4: /* Conditional select */
5996 disas_cond_select(s
, insn
);
5999 case 0x6: /* Data-processing */
6000 if (op0
) { /* (1 source) */
6001 disas_data_proc_1src(s
, insn
);
6002 } else { /* (2 source) */
6003 disas_data_proc_2src(s
, insn
);
6006 case 0x8 ... 0xf: /* (3 source) */
6007 disas_data_proc_3src(s
, insn
);
6012 unallocated_encoding(s
);
6017 static void handle_fp_compare(DisasContext
*s
, int size
,
6018 unsigned int rn
, unsigned int rm
,
6019 bool cmp_with_zero
, bool signal_all_nans
)
6021 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
6022 TCGv_ptr fpst
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
6024 if (size
== MO_64
) {
6025 TCGv_i64 tcg_vn
, tcg_vm
;
6027 tcg_vn
= read_fp_dreg(s
, rn
);
6028 if (cmp_with_zero
) {
6029 tcg_vm
= tcg_constant_i64(0);
6031 tcg_vm
= read_fp_dreg(s
, rm
);
6033 if (signal_all_nans
) {
6034 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
6036 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
6038 tcg_temp_free_i64(tcg_vn
);
6039 tcg_temp_free_i64(tcg_vm
);
6041 TCGv_i32 tcg_vn
= tcg_temp_new_i32();
6042 TCGv_i32 tcg_vm
= tcg_temp_new_i32();
6044 read_vec_element_i32(s
, tcg_vn
, rn
, 0, size
);
6045 if (cmp_with_zero
) {
6046 tcg_gen_movi_i32(tcg_vm
, 0);
6048 read_vec_element_i32(s
, tcg_vm
, rm
, 0, size
);
6053 if (signal_all_nans
) {
6054 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
6056 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
6060 if (signal_all_nans
) {
6061 gen_helper_vfp_cmpeh_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
6063 gen_helper_vfp_cmph_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
6067 g_assert_not_reached();
6070 tcg_temp_free_i32(tcg_vn
);
6071 tcg_temp_free_i32(tcg_vm
);
6074 tcg_temp_free_ptr(fpst
);
6076 gen_set_nzcv(tcg_flags
);
6078 tcg_temp_free_i64(tcg_flags
);
6081 /* Floating point compare
6082 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
6083 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
6084 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
6085 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
6087 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
6089 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
6092 mos
= extract32(insn
, 29, 3);
6093 type
= extract32(insn
, 22, 2);
6094 rm
= extract32(insn
, 16, 5);
6095 op
= extract32(insn
, 14, 2);
6096 rn
= extract32(insn
, 5, 5);
6097 opc
= extract32(insn
, 3, 2);
6098 op2r
= extract32(insn
, 0, 3);
6100 if (mos
|| op
|| op2r
) {
6101 unallocated_encoding(s
);
6114 if (dc_isar_feature(aa64_fp16
, s
)) {
6119 unallocated_encoding(s
);
6123 if (!fp_access_check(s
)) {
6127 handle_fp_compare(s
, size
, rn
, rm
, opc
& 1, opc
& 2);
6130 /* Floating point conditional compare
6131 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
6132 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
6133 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
6134 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
6136 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
6138 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
6139 TCGLabel
*label_continue
= NULL
;
6142 mos
= extract32(insn
, 29, 3);
6143 type
= extract32(insn
, 22, 2);
6144 rm
= extract32(insn
, 16, 5);
6145 cond
= extract32(insn
, 12, 4);
6146 rn
= extract32(insn
, 5, 5);
6147 op
= extract32(insn
, 4, 1);
6148 nzcv
= extract32(insn
, 0, 4);
6151 unallocated_encoding(s
);
6164 if (dc_isar_feature(aa64_fp16
, s
)) {
6169 unallocated_encoding(s
);
6173 if (!fp_access_check(s
)) {
6177 if (cond
< 0x0e) { /* not always */
6178 TCGLabel
*label_match
= gen_new_label();
6179 label_continue
= gen_new_label();
6180 arm_gen_test_cc(cond
, label_match
);
6182 gen_set_nzcv(tcg_constant_i64(nzcv
<< 28));
6183 tcg_gen_br(label_continue
);
6184 gen_set_label(label_match
);
6187 handle_fp_compare(s
, size
, rn
, rm
, false, op
);
6190 gen_set_label(label_continue
);
6194 /* Floating point conditional select
6195 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6196 * +---+---+---+-----------+------+---+------+------+-----+------+------+
6197 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
6198 * +---+---+---+-----------+------+---+------+------+-----+------+------+
6200 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
6202 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
6203 TCGv_i64 t_true
, t_false
;
6207 mos
= extract32(insn
, 29, 3);
6208 type
= extract32(insn
, 22, 2);
6209 rm
= extract32(insn
, 16, 5);
6210 cond
= extract32(insn
, 12, 4);
6211 rn
= extract32(insn
, 5, 5);
6212 rd
= extract32(insn
, 0, 5);
6215 unallocated_encoding(s
);
6228 if (dc_isar_feature(aa64_fp16
, s
)) {
6233 unallocated_encoding(s
);
6237 if (!fp_access_check(s
)) {
6241 /* Zero extend sreg & hreg inputs to 64 bits now. */
6242 t_true
= tcg_temp_new_i64();
6243 t_false
= tcg_temp_new_i64();
6244 read_vec_element(s
, t_true
, rn
, 0, sz
);
6245 read_vec_element(s
, t_false
, rm
, 0, sz
);
6247 a64_test_cc(&c
, cond
);
6248 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, tcg_constant_i64(0),
6250 tcg_temp_free_i64(t_false
);
6252 /* Note that sregs & hregs write back zeros to the high bits,
6253 and we've already done the zero-extension. */
6254 write_fp_dreg(s
, rd
, t_true
);
6255 tcg_temp_free_i64(t_true
);
6258 /* Floating-point data-processing (1 source) - half precision */
6259 static void handle_fp_1src_half(DisasContext
*s
, int opcode
, int rd
, int rn
)
6261 TCGv_ptr fpst
= NULL
;
6262 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
6263 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6266 case 0x0: /* FMOV */
6267 tcg_gen_mov_i32(tcg_res
, tcg_op
);
6269 case 0x1: /* FABS */
6270 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
6272 case 0x2: /* FNEG */
6273 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
6275 case 0x3: /* FSQRT */
6276 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6277 gen_helper_sqrt_f16(tcg_res
, tcg_op
, fpst
);
6279 case 0x8: /* FRINTN */
6280 case 0x9: /* FRINTP */
6281 case 0xa: /* FRINTM */
6282 case 0xb: /* FRINTZ */
6283 case 0xc: /* FRINTA */
6285 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
6286 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6288 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6289 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
6291 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6292 tcg_temp_free_i32(tcg_rmode
);
6295 case 0xe: /* FRINTX */
6296 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6297 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, fpst
);
6299 case 0xf: /* FRINTI */
6300 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6301 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
6304 g_assert_not_reached();
6307 write_fp_sreg(s
, rd
, tcg_res
);
6310 tcg_temp_free_ptr(fpst
);
6312 tcg_temp_free_i32(tcg_op
);
6313 tcg_temp_free_i32(tcg_res
);
6316 /* Floating-point data-processing (1 source) - single precision */
6317 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
6319 void (*gen_fpst
)(TCGv_i32
, TCGv_i32
, TCGv_ptr
);
6320 TCGv_i32 tcg_op
, tcg_res
;
6324 tcg_op
= read_fp_sreg(s
, rn
);
6325 tcg_res
= tcg_temp_new_i32();
6328 case 0x0: /* FMOV */
6329 tcg_gen_mov_i32(tcg_res
, tcg_op
);
6331 case 0x1: /* FABS */
6332 gen_helper_vfp_abss(tcg_res
, tcg_op
);
6334 case 0x2: /* FNEG */
6335 gen_helper_vfp_negs(tcg_res
, tcg_op
);
6337 case 0x3: /* FSQRT */
6338 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
6340 case 0x6: /* BFCVT */
6341 gen_fpst
= gen_helper_bfcvt
;
6343 case 0x8: /* FRINTN */
6344 case 0x9: /* FRINTP */
6345 case 0xa: /* FRINTM */
6346 case 0xb: /* FRINTZ */
6347 case 0xc: /* FRINTA */
6348 rmode
= arm_rmode_to_sf(opcode
& 7);
6349 gen_fpst
= gen_helper_rints
;
6351 case 0xe: /* FRINTX */
6352 gen_fpst
= gen_helper_rints_exact
;
6354 case 0xf: /* FRINTI */
6355 gen_fpst
= gen_helper_rints
;
6357 case 0x10: /* FRINT32Z */
6358 rmode
= float_round_to_zero
;
6359 gen_fpst
= gen_helper_frint32_s
;
6361 case 0x11: /* FRINT32X */
6362 gen_fpst
= gen_helper_frint32_s
;
6364 case 0x12: /* FRINT64Z */
6365 rmode
= float_round_to_zero
;
6366 gen_fpst
= gen_helper_frint64_s
;
6368 case 0x13: /* FRINT64X */
6369 gen_fpst
= gen_helper_frint64_s
;
6372 g_assert_not_reached();
6375 fpst
= fpstatus_ptr(FPST_FPCR
);
6377 TCGv_i32 tcg_rmode
= tcg_const_i32(rmode
);
6378 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6379 gen_fpst(tcg_res
, tcg_op
, fpst
);
6380 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6381 tcg_temp_free_i32(tcg_rmode
);
6383 gen_fpst(tcg_res
, tcg_op
, fpst
);
6385 tcg_temp_free_ptr(fpst
);
6388 write_fp_sreg(s
, rd
, tcg_res
);
6389 tcg_temp_free_i32(tcg_op
);
6390 tcg_temp_free_i32(tcg_res
);
6393 /* Floating-point data-processing (1 source) - double precision */
6394 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
6396 void (*gen_fpst
)(TCGv_i64
, TCGv_i64
, TCGv_ptr
);
6397 TCGv_i64 tcg_op
, tcg_res
;
6402 case 0x0: /* FMOV */
6403 gen_gvec_fn2(s
, false, rd
, rn
, tcg_gen_gvec_mov
, 0);
6407 tcg_op
= read_fp_dreg(s
, rn
);
6408 tcg_res
= tcg_temp_new_i64();
6411 case 0x1: /* FABS */
6412 gen_helper_vfp_absd(tcg_res
, tcg_op
);
6414 case 0x2: /* FNEG */
6415 gen_helper_vfp_negd(tcg_res
, tcg_op
);
6417 case 0x3: /* FSQRT */
6418 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
6420 case 0x8: /* FRINTN */
6421 case 0x9: /* FRINTP */
6422 case 0xa: /* FRINTM */
6423 case 0xb: /* FRINTZ */
6424 case 0xc: /* FRINTA */
6425 rmode
= arm_rmode_to_sf(opcode
& 7);
6426 gen_fpst
= gen_helper_rintd
;
6428 case 0xe: /* FRINTX */
6429 gen_fpst
= gen_helper_rintd_exact
;
6431 case 0xf: /* FRINTI */
6432 gen_fpst
= gen_helper_rintd
;
6434 case 0x10: /* FRINT32Z */
6435 rmode
= float_round_to_zero
;
6436 gen_fpst
= gen_helper_frint32_d
;
6438 case 0x11: /* FRINT32X */
6439 gen_fpst
= gen_helper_frint32_d
;
6441 case 0x12: /* FRINT64Z */
6442 rmode
= float_round_to_zero
;
6443 gen_fpst
= gen_helper_frint64_d
;
6445 case 0x13: /* FRINT64X */
6446 gen_fpst
= gen_helper_frint64_d
;
6449 g_assert_not_reached();
6452 fpst
= fpstatus_ptr(FPST_FPCR
);
6454 TCGv_i32 tcg_rmode
= tcg_const_i32(rmode
);
6455 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6456 gen_fpst(tcg_res
, tcg_op
, fpst
);
6457 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
6458 tcg_temp_free_i32(tcg_rmode
);
6460 gen_fpst(tcg_res
, tcg_op
, fpst
);
6462 tcg_temp_free_ptr(fpst
);
6465 write_fp_dreg(s
, rd
, tcg_res
);
6466 tcg_temp_free_i64(tcg_op
);
6467 tcg_temp_free_i64(tcg_res
);
6470 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
6471 int rd
, int rn
, int dtype
, int ntype
)
6476 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
6478 /* Single to double */
6479 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
6480 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
6481 write_fp_dreg(s
, rd
, tcg_rd
);
6482 tcg_temp_free_i64(tcg_rd
);
6484 /* Single to half */
6485 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
6486 TCGv_i32 ahp
= get_ahp_flag();
6487 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
6489 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
6490 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
6491 write_fp_sreg(s
, rd
, tcg_rd
);
6492 tcg_temp_free_i32(tcg_rd
);
6493 tcg_temp_free_i32(ahp
);
6494 tcg_temp_free_ptr(fpst
);
6496 tcg_temp_free_i32(tcg_rn
);
6501 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
6502 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
6504 /* Double to single */
6505 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
6507 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
6508 TCGv_i32 ahp
= get_ahp_flag();
6509 /* Double to half */
6510 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
6511 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
6512 tcg_temp_free_ptr(fpst
);
6513 tcg_temp_free_i32(ahp
);
6515 write_fp_sreg(s
, rd
, tcg_rd
);
6516 tcg_temp_free_i32(tcg_rd
);
6517 tcg_temp_free_i64(tcg_rn
);
6522 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
6523 TCGv_ptr tcg_fpst
= fpstatus_ptr(FPST_FPCR
);
6524 TCGv_i32 tcg_ahp
= get_ahp_flag();
6525 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
6527 /* Half to single */
6528 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
6529 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
6530 write_fp_sreg(s
, rd
, tcg_rd
);
6531 tcg_temp_free_i32(tcg_rd
);
6533 /* Half to double */
6534 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
6535 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
6536 write_fp_dreg(s
, rd
, tcg_rd
);
6537 tcg_temp_free_i64(tcg_rd
);
6539 tcg_temp_free_i32(tcg_rn
);
6540 tcg_temp_free_ptr(tcg_fpst
);
6541 tcg_temp_free_i32(tcg_ahp
);
6545 g_assert_not_reached();
6549 /* Floating point data-processing (1 source)
6550 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
6551 * +---+---+---+-----------+------+---+--------+-----------+------+------+
6552 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
6553 * +---+---+---+-----------+------+---+--------+-----------+------+------+
6555 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
6557 int mos
= extract32(insn
, 29, 3);
6558 int type
= extract32(insn
, 22, 2);
6559 int opcode
= extract32(insn
, 15, 6);
6560 int rn
= extract32(insn
, 5, 5);
6561 int rd
= extract32(insn
, 0, 5);
6564 goto do_unallocated
;
6568 case 0x4: case 0x5: case 0x7:
6570 /* FCVT between half, single and double precision */
6571 int dtype
= extract32(opcode
, 0, 2);
6572 if (type
== 2 || dtype
== type
) {
6573 goto do_unallocated
;
6575 if (!fp_access_check(s
)) {
6579 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
6583 case 0x10 ... 0x13: /* FRINT{32,64}{X,Z} */
6584 if (type
> 1 || !dc_isar_feature(aa64_frint
, s
)) {
6585 goto do_unallocated
;
6591 /* 32-to-32 and 64-to-64 ops */
6594 if (!fp_access_check(s
)) {
6597 handle_fp_1src_single(s
, opcode
, rd
, rn
);
6600 if (!fp_access_check(s
)) {
6603 handle_fp_1src_double(s
, opcode
, rd
, rn
);
6606 if (!dc_isar_feature(aa64_fp16
, s
)) {
6607 goto do_unallocated
;
6610 if (!fp_access_check(s
)) {
6613 handle_fp_1src_half(s
, opcode
, rd
, rn
);
6616 goto do_unallocated
;
6623 if (!dc_isar_feature(aa64_bf16
, s
)) {
6624 goto do_unallocated
;
6626 if (!fp_access_check(s
)) {
6629 handle_fp_1src_single(s
, opcode
, rd
, rn
);
6632 goto do_unallocated
;
6638 unallocated_encoding(s
);
6643 /* Floating-point data-processing (2 source) - single precision */
6644 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
6645 int rd
, int rn
, int rm
)
6652 tcg_res
= tcg_temp_new_i32();
6653 fpst
= fpstatus_ptr(FPST_FPCR
);
6654 tcg_op1
= read_fp_sreg(s
, rn
);
6655 tcg_op2
= read_fp_sreg(s
, rm
);
6658 case 0x0: /* FMUL */
6659 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6661 case 0x1: /* FDIV */
6662 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6664 case 0x2: /* FADD */
6665 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6667 case 0x3: /* FSUB */
6668 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6670 case 0x4: /* FMAX */
6671 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6673 case 0x5: /* FMIN */
6674 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6676 case 0x6: /* FMAXNM */
6677 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6679 case 0x7: /* FMINNM */
6680 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6682 case 0x8: /* FNMUL */
6683 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6684 gen_helper_vfp_negs(tcg_res
, tcg_res
);
6688 write_fp_sreg(s
, rd
, tcg_res
);
6690 tcg_temp_free_ptr(fpst
);
6691 tcg_temp_free_i32(tcg_op1
);
6692 tcg_temp_free_i32(tcg_op2
);
6693 tcg_temp_free_i32(tcg_res
);
6696 /* Floating-point data-processing (2 source) - double precision */
6697 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
6698 int rd
, int rn
, int rm
)
6705 tcg_res
= tcg_temp_new_i64();
6706 fpst
= fpstatus_ptr(FPST_FPCR
);
6707 tcg_op1
= read_fp_dreg(s
, rn
);
6708 tcg_op2
= read_fp_dreg(s
, rm
);
6711 case 0x0: /* FMUL */
6712 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6714 case 0x1: /* FDIV */
6715 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6717 case 0x2: /* FADD */
6718 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6720 case 0x3: /* FSUB */
6721 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6723 case 0x4: /* FMAX */
6724 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6726 case 0x5: /* FMIN */
6727 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6729 case 0x6: /* FMAXNM */
6730 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6732 case 0x7: /* FMINNM */
6733 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6735 case 0x8: /* FNMUL */
6736 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6737 gen_helper_vfp_negd(tcg_res
, tcg_res
);
6741 write_fp_dreg(s
, rd
, tcg_res
);
6743 tcg_temp_free_ptr(fpst
);
6744 tcg_temp_free_i64(tcg_op1
);
6745 tcg_temp_free_i64(tcg_op2
);
6746 tcg_temp_free_i64(tcg_res
);
6749 /* Floating-point data-processing (2 source) - half precision */
6750 static void handle_fp_2src_half(DisasContext
*s
, int opcode
,
6751 int rd
, int rn
, int rm
)
6758 tcg_res
= tcg_temp_new_i32();
6759 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6760 tcg_op1
= read_fp_hreg(s
, rn
);
6761 tcg_op2
= read_fp_hreg(s
, rm
);
6764 case 0x0: /* FMUL */
6765 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6767 case 0x1: /* FDIV */
6768 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6770 case 0x2: /* FADD */
6771 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6773 case 0x3: /* FSUB */
6774 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6776 case 0x4: /* FMAX */
6777 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6779 case 0x5: /* FMIN */
6780 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6782 case 0x6: /* FMAXNM */
6783 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6785 case 0x7: /* FMINNM */
6786 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6788 case 0x8: /* FNMUL */
6789 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6790 tcg_gen_xori_i32(tcg_res
, tcg_res
, 0x8000);
6793 g_assert_not_reached();
6796 write_fp_sreg(s
, rd
, tcg_res
);
6798 tcg_temp_free_ptr(fpst
);
6799 tcg_temp_free_i32(tcg_op1
);
6800 tcg_temp_free_i32(tcg_op2
);
6801 tcg_temp_free_i32(tcg_res
);
6804 /* Floating point data-processing (2 source)
6805 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6806 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6807 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
6808 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6810 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
6812 int mos
= extract32(insn
, 29, 3);
6813 int type
= extract32(insn
, 22, 2);
6814 int rd
= extract32(insn
, 0, 5);
6815 int rn
= extract32(insn
, 5, 5);
6816 int rm
= extract32(insn
, 16, 5);
6817 int opcode
= extract32(insn
, 12, 4);
6819 if (opcode
> 8 || mos
) {
6820 unallocated_encoding(s
);
6826 if (!fp_access_check(s
)) {
6829 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
6832 if (!fp_access_check(s
)) {
6835 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
6838 if (!dc_isar_feature(aa64_fp16
, s
)) {
6839 unallocated_encoding(s
);
6842 if (!fp_access_check(s
)) {
6845 handle_fp_2src_half(s
, opcode
, rd
, rn
, rm
);
6848 unallocated_encoding(s
);
6852 /* Floating-point data-processing (3 source) - single precision */
6853 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
6854 int rd
, int rn
, int rm
, int ra
)
6856 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
6857 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6858 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
6860 tcg_op1
= read_fp_sreg(s
, rn
);
6861 tcg_op2
= read_fp_sreg(s
, rm
);
6862 tcg_op3
= read_fp_sreg(s
, ra
);
6864 /* These are fused multiply-add, and must be done as one
6865 * floating point operation with no rounding between the
6866 * multiplication and addition steps.
6867 * NB that doing the negations here as separate steps is
6868 * correct : an input NaN should come out with its sign bit
6869 * flipped if it is a negated-input.
6872 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
6876 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
6879 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6881 write_fp_sreg(s
, rd
, tcg_res
);
6883 tcg_temp_free_ptr(fpst
);
6884 tcg_temp_free_i32(tcg_op1
);
6885 tcg_temp_free_i32(tcg_op2
);
6886 tcg_temp_free_i32(tcg_op3
);
6887 tcg_temp_free_i32(tcg_res
);
6890 /* Floating-point data-processing (3 source) - double precision */
6891 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
6892 int rd
, int rn
, int rm
, int ra
)
6894 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
6895 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6896 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
6898 tcg_op1
= read_fp_dreg(s
, rn
);
6899 tcg_op2
= read_fp_dreg(s
, rm
);
6900 tcg_op3
= read_fp_dreg(s
, ra
);
6902 /* These are fused multiply-add, and must be done as one
6903 * floating point operation with no rounding between the
6904 * multiplication and addition steps.
6905 * NB that doing the negations here as separate steps is
6906 * correct : an input NaN should come out with its sign bit
6907 * flipped if it is a negated-input.
6910 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
6914 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
6917 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6919 write_fp_dreg(s
, rd
, tcg_res
);
6921 tcg_temp_free_ptr(fpst
);
6922 tcg_temp_free_i64(tcg_op1
);
6923 tcg_temp_free_i64(tcg_op2
);
6924 tcg_temp_free_i64(tcg_op3
);
6925 tcg_temp_free_i64(tcg_res
);
6928 /* Floating-point data-processing (3 source) - half precision */
6929 static void handle_fp_3src_half(DisasContext
*s
, bool o0
, bool o1
,
6930 int rd
, int rn
, int rm
, int ra
)
6932 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
6933 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6934 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR_F16
);
6936 tcg_op1
= read_fp_hreg(s
, rn
);
6937 tcg_op2
= read_fp_hreg(s
, rm
);
6938 tcg_op3
= read_fp_hreg(s
, ra
);
6940 /* These are fused multiply-add, and must be done as one
6941 * floating point operation with no rounding between the
6942 * multiplication and addition steps.
6943 * NB that doing the negations here as separate steps is
6944 * correct : an input NaN should come out with its sign bit
6945 * flipped if it is a negated-input.
6948 tcg_gen_xori_i32(tcg_op3
, tcg_op3
, 0x8000);
6952 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
6955 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6957 write_fp_sreg(s
, rd
, tcg_res
);
6959 tcg_temp_free_ptr(fpst
);
6960 tcg_temp_free_i32(tcg_op1
);
6961 tcg_temp_free_i32(tcg_op2
);
6962 tcg_temp_free_i32(tcg_op3
);
6963 tcg_temp_free_i32(tcg_res
);
6966 /* Floating point data-processing (3 source)
6967 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
6968 * +---+---+---+-----------+------+----+------+----+------+------+------+
6969 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
6970 * +---+---+---+-----------+------+----+------+----+------+------+------+
6972 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
6974 int mos
= extract32(insn
, 29, 3);
6975 int type
= extract32(insn
, 22, 2);
6976 int rd
= extract32(insn
, 0, 5);
6977 int rn
= extract32(insn
, 5, 5);
6978 int ra
= extract32(insn
, 10, 5);
6979 int rm
= extract32(insn
, 16, 5);
6980 bool o0
= extract32(insn
, 15, 1);
6981 bool o1
= extract32(insn
, 21, 1);
6984 unallocated_encoding(s
);
6990 if (!fp_access_check(s
)) {
6993 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6996 if (!fp_access_check(s
)) {
6999 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
7002 if (!dc_isar_feature(aa64_fp16
, s
)) {
7003 unallocated_encoding(s
);
7006 if (!fp_access_check(s
)) {
7009 handle_fp_3src_half(s
, o0
, o1
, rd
, rn
, rm
, ra
);
7012 unallocated_encoding(s
);
7016 /* Floating point immediate
7017 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
7018 * +---+---+---+-----------+------+---+------------+-------+------+------+
7019 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
7020 * +---+---+---+-----------+------+---+------------+-------+------+------+
7022 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
7024 int rd
= extract32(insn
, 0, 5);
7025 int imm5
= extract32(insn
, 5, 5);
7026 int imm8
= extract32(insn
, 13, 8);
7027 int type
= extract32(insn
, 22, 2);
7028 int mos
= extract32(insn
, 29, 3);
7033 unallocated_encoding(s
);
7046 if (dc_isar_feature(aa64_fp16
, s
)) {
7051 unallocated_encoding(s
);
7055 if (!fp_access_check(s
)) {
7059 imm
= vfp_expand_imm(sz
, imm8
);
7060 write_fp_dreg(s
, rd
, tcg_constant_i64(imm
));
7063 /* Handle floating point <=> fixed point conversions. Note that we can
7064 * also deal with fp <=> integer conversions as a special case (scale == 64)
7065 * OPTME: consider handling that special case specially or at least skipping
7066 * the call to scalbn in the helpers for zero shifts.
7068 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
7069 bool itof
, int rmode
, int scale
, int sf
, int type
)
7071 bool is_signed
= !(opcode
& 1);
7072 TCGv_ptr tcg_fpstatus
;
7073 TCGv_i32 tcg_shift
, tcg_single
;
7074 TCGv_i64 tcg_double
;
7076 tcg_fpstatus
= fpstatus_ptr(type
== 3 ? FPST_FPCR_F16
: FPST_FPCR
);
7078 tcg_shift
= tcg_constant_i32(64 - scale
);
7081 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
7083 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
7086 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
7088 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
7091 tcg_int
= tcg_extend
;
7095 case 1: /* float64 */
7096 tcg_double
= tcg_temp_new_i64();
7098 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
7099 tcg_shift
, tcg_fpstatus
);
7101 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
7102 tcg_shift
, tcg_fpstatus
);
7104 write_fp_dreg(s
, rd
, tcg_double
);
7105 tcg_temp_free_i64(tcg_double
);
7108 case 0: /* float32 */
7109 tcg_single
= tcg_temp_new_i32();
7111 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
7112 tcg_shift
, tcg_fpstatus
);
7114 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
7115 tcg_shift
, tcg_fpstatus
);
7117 write_fp_sreg(s
, rd
, tcg_single
);
7118 tcg_temp_free_i32(tcg_single
);
7121 case 3: /* float16 */
7122 tcg_single
= tcg_temp_new_i32();
7124 gen_helper_vfp_sqtoh(tcg_single
, tcg_int
,
7125 tcg_shift
, tcg_fpstatus
);
7127 gen_helper_vfp_uqtoh(tcg_single
, tcg_int
,
7128 tcg_shift
, tcg_fpstatus
);
7130 write_fp_sreg(s
, rd
, tcg_single
);
7131 tcg_temp_free_i32(tcg_single
);
7135 g_assert_not_reached();
7138 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
7141 if (extract32(opcode
, 2, 1)) {
7142 /* There are too many rounding modes to all fit into rmode,
7143 * so FCVTA[US] is a special case.
7145 rmode
= FPROUNDING_TIEAWAY
;
7148 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
7150 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7153 case 1: /* float64 */
7154 tcg_double
= read_fp_dreg(s
, rn
);
7157 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
7158 tcg_shift
, tcg_fpstatus
);
7160 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
7161 tcg_shift
, tcg_fpstatus
);
7165 gen_helper_vfp_tould(tcg_int
, tcg_double
,
7166 tcg_shift
, tcg_fpstatus
);
7168 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
7169 tcg_shift
, tcg_fpstatus
);
7173 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
7175 tcg_temp_free_i64(tcg_double
);
7178 case 0: /* float32 */
7179 tcg_single
= read_fp_sreg(s
, rn
);
7182 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
7183 tcg_shift
, tcg_fpstatus
);
7185 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
7186 tcg_shift
, tcg_fpstatus
);
7189 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
7191 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
7192 tcg_shift
, tcg_fpstatus
);
7194 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
7195 tcg_shift
, tcg_fpstatus
);
7197 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
7198 tcg_temp_free_i32(tcg_dest
);
7200 tcg_temp_free_i32(tcg_single
);
7203 case 3: /* float16 */
7204 tcg_single
= read_fp_sreg(s
, rn
);
7207 gen_helper_vfp_tosqh(tcg_int
, tcg_single
,
7208 tcg_shift
, tcg_fpstatus
);
7210 gen_helper_vfp_touqh(tcg_int
, tcg_single
,
7211 tcg_shift
, tcg_fpstatus
);
7214 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
7216 gen_helper_vfp_toslh(tcg_dest
, tcg_single
,
7217 tcg_shift
, tcg_fpstatus
);
7219 gen_helper_vfp_toulh(tcg_dest
, tcg_single
,
7220 tcg_shift
, tcg_fpstatus
);
7222 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
7223 tcg_temp_free_i32(tcg_dest
);
7225 tcg_temp_free_i32(tcg_single
);
7229 g_assert_not_reached();
7232 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7233 tcg_temp_free_i32(tcg_rmode
);
7236 tcg_temp_free_ptr(tcg_fpstatus
);
7239 /* Floating point <-> fixed point conversions
7240 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
7241 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
7242 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
7243 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
7245 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
7247 int rd
= extract32(insn
, 0, 5);
7248 int rn
= extract32(insn
, 5, 5);
7249 int scale
= extract32(insn
, 10, 6);
7250 int opcode
= extract32(insn
, 16, 3);
7251 int rmode
= extract32(insn
, 19, 2);
7252 int type
= extract32(insn
, 22, 2);
7253 bool sbit
= extract32(insn
, 29, 1);
7254 bool sf
= extract32(insn
, 31, 1);
7257 if (sbit
|| (!sf
&& scale
< 32)) {
7258 unallocated_encoding(s
);
7263 case 0: /* float32 */
7264 case 1: /* float64 */
7266 case 3: /* float16 */
7267 if (dc_isar_feature(aa64_fp16
, s
)) {
7272 unallocated_encoding(s
);
7276 switch ((rmode
<< 3) | opcode
) {
7277 case 0x2: /* SCVTF */
7278 case 0x3: /* UCVTF */
7281 case 0x18: /* FCVTZS */
7282 case 0x19: /* FCVTZU */
7286 unallocated_encoding(s
);
7290 if (!fp_access_check(s
)) {
7294 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
7297 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
7299 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
7300 * without conversion.
7304 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
7310 tmp
= tcg_temp_new_i64();
7311 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
7312 write_fp_dreg(s
, rd
, tmp
);
7313 tcg_temp_free_i64(tmp
);
7317 write_fp_dreg(s
, rd
, tcg_rn
);
7320 /* 64 bit to top half. */
7321 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
7322 clear_vec_high(s
, true, rd
);
7326 tmp
= tcg_temp_new_i64();
7327 tcg_gen_ext16u_i64(tmp
, tcg_rn
);
7328 write_fp_dreg(s
, rd
, tmp
);
7329 tcg_temp_free_i64(tmp
);
7332 g_assert_not_reached();
7335 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
7340 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
7344 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
7347 /* 64 bits from top half */
7348 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
7352 tcg_gen_ld16u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_16
));
7355 g_assert_not_reached();
7360 static void handle_fjcvtzs(DisasContext
*s
, int rd
, int rn
)
7362 TCGv_i64 t
= read_fp_dreg(s
, rn
);
7363 TCGv_ptr fpstatus
= fpstatus_ptr(FPST_FPCR
);
7365 gen_helper_fjcvtzs(t
, t
, fpstatus
);
7367 tcg_temp_free_ptr(fpstatus
);
7369 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), t
);
7370 tcg_gen_extrh_i64_i32(cpu_ZF
, t
);
7371 tcg_gen_movi_i32(cpu_CF
, 0);
7372 tcg_gen_movi_i32(cpu_NF
, 0);
7373 tcg_gen_movi_i32(cpu_VF
, 0);
7375 tcg_temp_free_i64(t
);
7378 /* Floating point <-> integer conversions
7379 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
7380 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
7381 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
7382 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
7384 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
7386 int rd
= extract32(insn
, 0, 5);
7387 int rn
= extract32(insn
, 5, 5);
7388 int opcode
= extract32(insn
, 16, 3);
7389 int rmode
= extract32(insn
, 19, 2);
7390 int type
= extract32(insn
, 22, 2);
7391 bool sbit
= extract32(insn
, 29, 1);
7392 bool sf
= extract32(insn
, 31, 1);
7396 goto do_unallocated
;
7404 case 4: /* FCVTAS */
7405 case 5: /* FCVTAU */
7407 goto do_unallocated
;
7410 case 0: /* FCVT[NPMZ]S */
7411 case 1: /* FCVT[NPMZ]U */
7413 case 0: /* float32 */
7414 case 1: /* float64 */
7416 case 3: /* float16 */
7417 if (!dc_isar_feature(aa64_fp16
, s
)) {
7418 goto do_unallocated
;
7422 goto do_unallocated
;
7424 if (!fp_access_check(s
)) {
7427 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
7431 switch (sf
<< 7 | type
<< 5 | rmode
<< 3 | opcode
) {
7432 case 0b01100110: /* FMOV half <-> 32-bit int */
7434 case 0b11100110: /* FMOV half <-> 64-bit int */
7436 if (!dc_isar_feature(aa64_fp16
, s
)) {
7437 goto do_unallocated
;
7440 case 0b00000110: /* FMOV 32-bit */
7442 case 0b10100110: /* FMOV 64-bit */
7444 case 0b11001110: /* FMOV top half of 128-bit */
7446 if (!fp_access_check(s
)) {
7450 handle_fmov(s
, rd
, rn
, type
, itof
);
7453 case 0b00111110: /* FJCVTZS */
7454 if (!dc_isar_feature(aa64_jscvt
, s
)) {
7455 goto do_unallocated
;
7456 } else if (fp_access_check(s
)) {
7457 handle_fjcvtzs(s
, rd
, rn
);
7463 unallocated_encoding(s
);
7470 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
7471 * 31 30 29 28 25 24 0
7472 * +---+---+---+---------+-----------------------------+
7473 * | | 0 | | 1 1 1 1 | |
7474 * +---+---+---+---------+-----------------------------+
7476 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
7478 if (extract32(insn
, 24, 1)) {
7479 /* Floating point data-processing (3 source) */
7480 disas_fp_3src(s
, insn
);
7481 } else if (extract32(insn
, 21, 1) == 0) {
7482 /* Floating point to fixed point conversions */
7483 disas_fp_fixed_conv(s
, insn
);
7485 switch (extract32(insn
, 10, 2)) {
7487 /* Floating point conditional compare */
7488 disas_fp_ccomp(s
, insn
);
7491 /* Floating point data-processing (2 source) */
7492 disas_fp_2src(s
, insn
);
7495 /* Floating point conditional select */
7496 disas_fp_csel(s
, insn
);
7499 switch (ctz32(extract32(insn
, 12, 4))) {
7500 case 0: /* [15:12] == xxx1 */
7501 /* Floating point immediate */
7502 disas_fp_imm(s
, insn
);
7504 case 1: /* [15:12] == xx10 */
7505 /* Floating point compare */
7506 disas_fp_compare(s
, insn
);
7508 case 2: /* [15:12] == x100 */
7509 /* Floating point data-processing (1 source) */
7510 disas_fp_1src(s
, insn
);
7512 case 3: /* [15:12] == 1000 */
7513 unallocated_encoding(s
);
7515 default: /* [15:12] == 0000 */
7516 /* Floating point <-> integer conversions */
7517 disas_fp_int_conv(s
, insn
);
7525 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
7528 /* Extract 64 bits from the middle of two concatenated 64 bit
7529 * vector register slices left:right. The extracted bits start
7530 * at 'pos' bits into the right (least significant) side.
7531 * We return the result in tcg_right, and guarantee not to
7534 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
7535 assert(pos
> 0 && pos
< 64);
7537 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
7538 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
7539 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
7541 tcg_temp_free_i64(tcg_tmp
);
7545 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
7546 * +---+---+-------------+-----+---+------+---+------+---+------+------+
7547 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
7548 * +---+---+-------------+-----+---+------+---+------+---+------+------+
7550 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
7552 int is_q
= extract32(insn
, 30, 1);
7553 int op2
= extract32(insn
, 22, 2);
7554 int imm4
= extract32(insn
, 11, 4);
7555 int rm
= extract32(insn
, 16, 5);
7556 int rn
= extract32(insn
, 5, 5);
7557 int rd
= extract32(insn
, 0, 5);
7558 int pos
= imm4
<< 3;
7559 TCGv_i64 tcg_resl
, tcg_resh
;
7561 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
7562 unallocated_encoding(s
);
7566 if (!fp_access_check(s
)) {
7570 tcg_resh
= tcg_temp_new_i64();
7571 tcg_resl
= tcg_temp_new_i64();
7573 /* Vd gets bits starting at pos bits into Vm:Vn. This is
7574 * either extracting 128 bits from a 128:128 concatenation, or
7575 * extracting 64 bits from a 64:64 concatenation.
7578 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
7580 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
7581 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
7589 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
7590 EltPosns
*elt
= eltposns
;
7597 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
7599 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
7602 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
7603 tcg_hh
= tcg_temp_new_i64();
7604 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
7605 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
7606 tcg_temp_free_i64(tcg_hh
);
7610 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
7611 tcg_temp_free_i64(tcg_resl
);
7613 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
7615 tcg_temp_free_i64(tcg_resh
);
7616 clear_vec_high(s
, is_q
, rd
);
7620 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
7621 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
7622 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
7623 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
7625 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
7627 int op2
= extract32(insn
, 22, 2);
7628 int is_q
= extract32(insn
, 30, 1);
7629 int rm
= extract32(insn
, 16, 5);
7630 int rn
= extract32(insn
, 5, 5);
7631 int rd
= extract32(insn
, 0, 5);
7632 int is_tbx
= extract32(insn
, 12, 1);
7633 int len
= (extract32(insn
, 13, 2) + 1) * 16;
7636 unallocated_encoding(s
);
7640 if (!fp_access_check(s
)) {
7644 tcg_gen_gvec_2_ptr(vec_full_reg_offset(s
, rd
),
7645 vec_full_reg_offset(s
, rm
), cpu_env
,
7646 is_q
? 16 : 8, vec_full_reg_size(s
),
7647 (len
<< 6) | (is_tbx
<< 5) | rn
,
7648 gen_helper_simd_tblx
);
7652 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
7653 * +---+---+-------------+------+---+------+---+------------------+------+
7654 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
7655 * +---+---+-------------+------+---+------+---+------------------+------+
7657 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
7659 int rd
= extract32(insn
, 0, 5);
7660 int rn
= extract32(insn
, 5, 5);
7661 int rm
= extract32(insn
, 16, 5);
7662 int size
= extract32(insn
, 22, 2);
7663 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
7664 * bit 2 indicates 1 vs 2 variant of the insn.
7666 int opcode
= extract32(insn
, 12, 2);
7667 bool part
= extract32(insn
, 14, 1);
7668 bool is_q
= extract32(insn
, 30, 1);
7669 int esize
= 8 << size
;
7671 int datasize
= is_q
? 128 : 64;
7672 int elements
= datasize
/ esize
;
7673 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
7675 if (opcode
== 0 || (size
== 3 && !is_q
)) {
7676 unallocated_encoding(s
);
7680 if (!fp_access_check(s
)) {
7684 tcg_resl
= tcg_const_i64(0);
7685 tcg_resh
= is_q
? tcg_const_i64(0) : NULL
;
7686 tcg_res
= tcg_temp_new_i64();
7688 for (i
= 0; i
< elements
; i
++) {
7690 case 1: /* UZP1/2 */
7692 int midpoint
= elements
/ 2;
7694 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
7696 read_vec_element(s
, tcg_res
, rm
,
7697 2 * (i
- midpoint
) + part
, size
);
7701 case 2: /* TRN1/2 */
7703 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
7705 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
7708 case 3: /* ZIP1/2 */
7710 int base
= part
* elements
/ 2;
7712 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
7714 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
7719 g_assert_not_reached();
7724 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
7725 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
7727 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
7728 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
7732 tcg_temp_free_i64(tcg_res
);
7734 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
7735 tcg_temp_free_i64(tcg_resl
);
7738 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
7739 tcg_temp_free_i64(tcg_resh
);
7741 clear_vec_high(s
, is_q
, rd
);
7745 * do_reduction_op helper
7747 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
7748 * important for correct NaN propagation that we do these
7749 * operations in exactly the order specified by the pseudocode.
7751 * This is a recursive function, TCG temps should be freed by the
7752 * calling function once it is done with the values.
7754 static TCGv_i32
do_reduction_op(DisasContext
*s
, int fpopcode
, int rn
,
7755 int esize
, int size
, int vmap
, TCGv_ptr fpst
)
7757 if (esize
== size
) {
7759 MemOp msize
= esize
== 16 ? MO_16
: MO_32
;
7762 /* We should have one register left here */
7763 assert(ctpop8(vmap
) == 1);
7764 element
= ctz32(vmap
);
7765 assert(element
< 8);
7767 tcg_elem
= tcg_temp_new_i32();
7768 read_vec_element_i32(s
, tcg_elem
, rn
, element
, msize
);
7771 int bits
= size
/ 2;
7772 int shift
= ctpop8(vmap
) / 2;
7773 int vmap_lo
= (vmap
>> shift
) & vmap
;
7774 int vmap_hi
= (vmap
& ~vmap_lo
);
7775 TCGv_i32 tcg_hi
, tcg_lo
, tcg_res
;
7777 tcg_hi
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_hi
, fpst
);
7778 tcg_lo
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_lo
, fpst
);
7779 tcg_res
= tcg_temp_new_i32();
7782 case 0x0c: /* fmaxnmv half-precision */
7783 gen_helper_advsimd_maxnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7785 case 0x0f: /* fmaxv half-precision */
7786 gen_helper_advsimd_maxh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7788 case 0x1c: /* fminnmv half-precision */
7789 gen_helper_advsimd_minnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7791 case 0x1f: /* fminv half-precision */
7792 gen_helper_advsimd_minh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7794 case 0x2c: /* fmaxnmv */
7795 gen_helper_vfp_maxnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7797 case 0x2f: /* fmaxv */
7798 gen_helper_vfp_maxs(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7800 case 0x3c: /* fminnmv */
7801 gen_helper_vfp_minnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7803 case 0x3f: /* fminv */
7804 gen_helper_vfp_mins(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7807 g_assert_not_reached();
7810 tcg_temp_free_i32(tcg_hi
);
7811 tcg_temp_free_i32(tcg_lo
);
7816 /* AdvSIMD across lanes
7817 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7818 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7819 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7820 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7822 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
7824 int rd
= extract32(insn
, 0, 5);
7825 int rn
= extract32(insn
, 5, 5);
7826 int size
= extract32(insn
, 22, 2);
7827 int opcode
= extract32(insn
, 12, 5);
7828 bool is_q
= extract32(insn
, 30, 1);
7829 bool is_u
= extract32(insn
, 29, 1);
7831 bool is_min
= false;
7835 TCGv_i64 tcg_res
, tcg_elt
;
7838 case 0x1b: /* ADDV */
7840 unallocated_encoding(s
);
7844 case 0x3: /* SADDLV, UADDLV */
7845 case 0xa: /* SMAXV, UMAXV */
7846 case 0x1a: /* SMINV, UMINV */
7847 if (size
== 3 || (size
== 2 && !is_q
)) {
7848 unallocated_encoding(s
);
7852 case 0xc: /* FMAXNMV, FMINNMV */
7853 case 0xf: /* FMAXV, FMINV */
7854 /* Bit 1 of size field encodes min vs max and the actual size
7855 * depends on the encoding of the U bit. If not set (and FP16
7856 * enabled) then we do half-precision float instead of single
7859 is_min
= extract32(size
, 1, 1);
7861 if (!is_u
&& dc_isar_feature(aa64_fp16
, s
)) {
7863 } else if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
7864 unallocated_encoding(s
);
7871 unallocated_encoding(s
);
7875 if (!fp_access_check(s
)) {
7880 elements
= (is_q
? 128 : 64) / esize
;
7882 tcg_res
= tcg_temp_new_i64();
7883 tcg_elt
= tcg_temp_new_i64();
7885 /* These instructions operate across all lanes of a vector
7886 * to produce a single result. We can guarantee that a 64
7887 * bit intermediate is sufficient:
7888 * + for [US]ADDLV the maximum element size is 32 bits, and
7889 * the result type is 64 bits
7890 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
7891 * same as the element size, which is 32 bits at most
7892 * For the integer operations we can choose to work at 64
7893 * or 32 bits and truncate at the end; for simplicity
7894 * we use 64 bits always. The floating point
7895 * ops do require 32 bit intermediates, though.
7898 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
7900 for (i
= 1; i
< elements
; i
++) {
7901 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
7904 case 0x03: /* SADDLV / UADDLV */
7905 case 0x1b: /* ADDV */
7906 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
7908 case 0x0a: /* SMAXV / UMAXV */
7910 tcg_gen_umax_i64(tcg_res
, tcg_res
, tcg_elt
);
7912 tcg_gen_smax_i64(tcg_res
, tcg_res
, tcg_elt
);
7915 case 0x1a: /* SMINV / UMINV */
7917 tcg_gen_umin_i64(tcg_res
, tcg_res
, tcg_elt
);
7919 tcg_gen_smin_i64(tcg_res
, tcg_res
, tcg_elt
);
7923 g_assert_not_reached();
7928 /* Floating point vector reduction ops which work across 32
7929 * bit (single) or 16 bit (half-precision) intermediates.
7930 * Note that correct NaN propagation requires that we do these
7931 * operations in exactly the order specified by the pseudocode.
7933 TCGv_ptr fpst
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
7934 int fpopcode
= opcode
| is_min
<< 4 | is_u
<< 5;
7935 int vmap
= (1 << elements
) - 1;
7936 TCGv_i32 tcg_res32
= do_reduction_op(s
, fpopcode
, rn
, esize
,
7937 (is_q
? 128 : 64), vmap
, fpst
);
7938 tcg_gen_extu_i32_i64(tcg_res
, tcg_res32
);
7939 tcg_temp_free_i32(tcg_res32
);
7940 tcg_temp_free_ptr(fpst
);
7943 tcg_temp_free_i64(tcg_elt
);
7945 /* Now truncate the result to the width required for the final output */
7946 if (opcode
== 0x03) {
7947 /* SADDLV, UADDLV: result is 2*esize */
7953 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
7956 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
7959 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
7964 g_assert_not_reached();
7967 write_fp_dreg(s
, rd
, tcg_res
);
7968 tcg_temp_free_i64(tcg_res
);
7971 /* DUP (Element, Vector)
7973 * 31 30 29 21 20 16 15 10 9 5 4 0
7974 * +---+---+-------------------+--------+-------------+------+------+
7975 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7976 * +---+---+-------------------+--------+-------------+------+------+
7978 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7980 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
7983 int size
= ctz32(imm5
);
7986 if (size
> 3 || (size
== 3 && !is_q
)) {
7987 unallocated_encoding(s
);
7991 if (!fp_access_check(s
)) {
7995 index
= imm5
>> (size
+ 1);
7996 tcg_gen_gvec_dup_mem(size
, vec_full_reg_offset(s
, rd
),
7997 vec_reg_offset(s
, rn
, index
, size
),
7998 is_q
? 16 : 8, vec_full_reg_size(s
));
8001 /* DUP (element, scalar)
8002 * 31 21 20 16 15 10 9 5 4 0
8003 * +-----------------------+--------+-------------+------+------+
8004 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
8005 * +-----------------------+--------+-------------+------+------+
8007 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
8010 int size
= ctz32(imm5
);
8015 unallocated_encoding(s
);
8019 if (!fp_access_check(s
)) {
8023 index
= imm5
>> (size
+ 1);
8025 /* This instruction just extracts the specified element and
8026 * zero-extends it into the bottom of the destination register.
8028 tmp
= tcg_temp_new_i64();
8029 read_vec_element(s
, tmp
, rn
, index
, size
);
8030 write_fp_dreg(s
, rd
, tmp
);
8031 tcg_temp_free_i64(tmp
);
8036 * 31 30 29 21 20 16 15 10 9 5 4 0
8037 * +---+---+-------------------+--------+-------------+------+------+
8038 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
8039 * +---+---+-------------------+--------+-------------+------+------+
8041 * size: encoded in imm5 (see ARM ARM LowestSetBit())
8043 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
8046 int size
= ctz32(imm5
);
8047 uint32_t dofs
, oprsz
, maxsz
;
8049 if (size
> 3 || ((size
== 3) && !is_q
)) {
8050 unallocated_encoding(s
);
8054 if (!fp_access_check(s
)) {
8058 dofs
= vec_full_reg_offset(s
, rd
);
8059 oprsz
= is_q
? 16 : 8;
8060 maxsz
= vec_full_reg_size(s
);
8062 tcg_gen_gvec_dup_i64(size
, dofs
, oprsz
, maxsz
, cpu_reg(s
, rn
));
8067 * 31 21 20 16 15 14 11 10 9 5 4 0
8068 * +-----------------------+--------+------------+---+------+------+
8069 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
8070 * +-----------------------+--------+------------+---+------+------+
8072 * size: encoded in imm5 (see ARM ARM LowestSetBit())
8073 * index: encoded in imm5<4:size+1>
8075 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
8078 int size
= ctz32(imm5
);
8079 int src_index
, dst_index
;
8083 unallocated_encoding(s
);
8087 if (!fp_access_check(s
)) {
8091 dst_index
= extract32(imm5
, 1+size
, 5);
8092 src_index
= extract32(imm4
, size
, 4);
8094 tmp
= tcg_temp_new_i64();
8096 read_vec_element(s
, tmp
, rn
, src_index
, size
);
8097 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
8099 tcg_temp_free_i64(tmp
);
8101 /* INS is considered a 128-bit write for SVE. */
8102 clear_vec_high(s
, true, rd
);
8108 * 31 21 20 16 15 10 9 5 4 0
8109 * +-----------------------+--------+-------------+------+------+
8110 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
8111 * +-----------------------+--------+-------------+------+------+
8113 * size: encoded in imm5 (see ARM ARM LowestSetBit())
8114 * index: encoded in imm5<4:size+1>
8116 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
8118 int size
= ctz32(imm5
);
8122 unallocated_encoding(s
);
8126 if (!fp_access_check(s
)) {
8130 idx
= extract32(imm5
, 1 + size
, 4 - size
);
8131 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
8133 /* INS is considered a 128-bit write for SVE. */
8134 clear_vec_high(s
, true, rd
);
8141 * 31 30 29 21 20 16 15 12 10 9 5 4 0
8142 * +---+---+-------------------+--------+-------------+------+------+
8143 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
8144 * +---+---+-------------------+--------+-------------+------+------+
8146 * U: unsigned when set
8147 * size: encoded in imm5 (see ARM ARM LowestSetBit())
8149 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
8150 int rn
, int rd
, int imm5
)
8152 int size
= ctz32(imm5
);
8156 /* Check for UnallocatedEncodings */
8158 if (size
> 2 || (size
== 2 && !is_q
)) {
8159 unallocated_encoding(s
);
8164 || (size
< 3 && is_q
)
8165 || (size
== 3 && !is_q
)) {
8166 unallocated_encoding(s
);
8171 if (!fp_access_check(s
)) {
8175 element
= extract32(imm5
, 1+size
, 4);
8177 tcg_rd
= cpu_reg(s
, rd
);
8178 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
8179 if (is_signed
&& !is_q
) {
8180 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
8185 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
8186 * +---+---+----+-----------------+------+---+------+---+------+------+
8187 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
8188 * +---+---+----+-----------------+------+---+------+---+------+------+
8190 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
8192 int rd
= extract32(insn
, 0, 5);
8193 int rn
= extract32(insn
, 5, 5);
8194 int imm4
= extract32(insn
, 11, 4);
8195 int op
= extract32(insn
, 29, 1);
8196 int is_q
= extract32(insn
, 30, 1);
8197 int imm5
= extract32(insn
, 16, 5);
8202 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
8204 unallocated_encoding(s
);
8209 /* DUP (element - vector) */
8210 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
8214 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
8219 handle_simd_insg(s
, rd
, rn
, imm5
);
8221 unallocated_encoding(s
);
8226 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
8227 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
8230 unallocated_encoding(s
);
8236 /* AdvSIMD modified immediate
8237 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
8238 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
8239 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
8240 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
8242 * There are a number of operations that can be carried out here:
8243 * MOVI - move (shifted) imm into register
8244 * MVNI - move inverted (shifted) imm into register
8245 * ORR - bitwise OR of (shifted) imm with register
8246 * BIC - bitwise clear of (shifted) imm with register
8247 * With ARMv8.2 we also have:
8248 * FMOV half-precision
8250 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
8252 int rd
= extract32(insn
, 0, 5);
8253 int cmode
= extract32(insn
, 12, 4);
8254 int o2
= extract32(insn
, 11, 1);
8255 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
8256 bool is_neg
= extract32(insn
, 29, 1);
8257 bool is_q
= extract32(insn
, 30, 1);
8260 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
8261 /* Check for FMOV (vector, immediate) - half-precision */
8262 if (!(dc_isar_feature(aa64_fp16
, s
) && o2
&& cmode
== 0xf)) {
8263 unallocated_encoding(s
);
8268 if (!fp_access_check(s
)) {
8272 if (cmode
== 15 && o2
&& !is_neg
) {
8273 /* FMOV (vector, immediate) - half-precision */
8274 imm
= vfp_expand_imm(MO_16
, abcdefgh
);
8275 /* now duplicate across the lanes */
8276 imm
= dup_const(MO_16
, imm
);
8278 imm
= asimd_imm_const(abcdefgh
, cmode
, is_neg
);
8281 if (!((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9)) {
8282 /* MOVI or MVNI, with MVNI negation handled above. */
8283 tcg_gen_gvec_dup_imm(MO_64
, vec_full_reg_offset(s
, rd
), is_q
? 16 : 8,
8284 vec_full_reg_size(s
), imm
);
8286 /* ORR or BIC, with BIC negation to AND handled above. */
8288 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_andi
, MO_64
);
8290 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_ori
, MO_64
);
8295 /* AdvSIMD scalar copy
8296 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
8297 * +-----+----+-----------------+------+---+------+---+------+------+
8298 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
8299 * +-----+----+-----------------+------+---+------+---+------+------+
8301 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
8303 int rd
= extract32(insn
, 0, 5);
8304 int rn
= extract32(insn
, 5, 5);
8305 int imm4
= extract32(insn
, 11, 4);
8306 int imm5
= extract32(insn
, 16, 5);
8307 int op
= extract32(insn
, 29, 1);
8309 if (op
!= 0 || imm4
!= 0) {
8310 unallocated_encoding(s
);
8314 /* DUP (element, scalar) */
8315 handle_simd_dupes(s
, rd
, rn
, imm5
);
8318 /* AdvSIMD scalar pairwise
8319 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
8320 * +-----+---+-----------+------+-----------+--------+-----+------+------+
8321 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
8322 * +-----+---+-----------+------+-----------+--------+-----+------+------+
8324 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
8326 int u
= extract32(insn
, 29, 1);
8327 int size
= extract32(insn
, 22, 2);
8328 int opcode
= extract32(insn
, 12, 5);
8329 int rn
= extract32(insn
, 5, 5);
8330 int rd
= extract32(insn
, 0, 5);
8333 /* For some ops (the FP ones), size[1] is part of the encoding.
8334 * For ADDP strictly it is not but size[1] is always 1 for valid
8337 opcode
|= (extract32(size
, 1, 1) << 5);
8340 case 0x3b: /* ADDP */
8341 if (u
|| size
!= 3) {
8342 unallocated_encoding(s
);
8345 if (!fp_access_check(s
)) {
8351 case 0xc: /* FMAXNMP */
8352 case 0xd: /* FADDP */
8353 case 0xf: /* FMAXP */
8354 case 0x2c: /* FMINNMP */
8355 case 0x2f: /* FMINP */
8356 /* FP op, size[0] is 32 or 64 bit*/
8358 if (!dc_isar_feature(aa64_fp16
, s
)) {
8359 unallocated_encoding(s
);
8365 size
= extract32(size
, 0, 1) ? MO_64
: MO_32
;
8368 if (!fp_access_check(s
)) {
8372 fpst
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
8375 unallocated_encoding(s
);
8379 if (size
== MO_64
) {
8380 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8381 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8382 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8384 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
8385 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
8388 case 0x3b: /* ADDP */
8389 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
8391 case 0xc: /* FMAXNMP */
8392 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8394 case 0xd: /* FADDP */
8395 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8397 case 0xf: /* FMAXP */
8398 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8400 case 0x2c: /* FMINNMP */
8401 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8403 case 0x2f: /* FMINP */
8404 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8407 g_assert_not_reached();
8410 write_fp_dreg(s
, rd
, tcg_res
);
8412 tcg_temp_free_i64(tcg_op1
);
8413 tcg_temp_free_i64(tcg_op2
);
8414 tcg_temp_free_i64(tcg_res
);
8416 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8417 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8418 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8420 read_vec_element_i32(s
, tcg_op1
, rn
, 0, size
);
8421 read_vec_element_i32(s
, tcg_op2
, rn
, 1, size
);
8423 if (size
== MO_16
) {
8425 case 0xc: /* FMAXNMP */
8426 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8428 case 0xd: /* FADDP */
8429 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8431 case 0xf: /* FMAXP */
8432 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8434 case 0x2c: /* FMINNMP */
8435 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8437 case 0x2f: /* FMINP */
8438 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8441 g_assert_not_reached();
8445 case 0xc: /* FMAXNMP */
8446 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8448 case 0xd: /* FADDP */
8449 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8451 case 0xf: /* FMAXP */
8452 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8454 case 0x2c: /* FMINNMP */
8455 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8457 case 0x2f: /* FMINP */
8458 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8461 g_assert_not_reached();
8465 write_fp_sreg(s
, rd
, tcg_res
);
8467 tcg_temp_free_i32(tcg_op1
);
8468 tcg_temp_free_i32(tcg_op2
);
8469 tcg_temp_free_i32(tcg_res
);
8473 tcg_temp_free_ptr(fpst
);
8478 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
8480 * This code is handles the common shifting code and is used by both
8481 * the vector and scalar code.
8483 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
8484 TCGv_i64 tcg_rnd
, bool accumulate
,
8485 bool is_u
, int size
, int shift
)
8487 bool extended_result
= false;
8488 bool round
= tcg_rnd
!= NULL
;
8490 TCGv_i64 tcg_src_hi
;
8492 if (round
&& size
== 3) {
8493 extended_result
= true;
8494 ext_lshift
= 64 - shift
;
8495 tcg_src_hi
= tcg_temp_new_i64();
8496 } else if (shift
== 64) {
8497 if (!accumulate
&& is_u
) {
8498 /* result is zero */
8499 tcg_gen_movi_i64(tcg_res
, 0);
8504 /* Deal with the rounding step */
8506 if (extended_result
) {
8507 TCGv_i64 tcg_zero
= tcg_constant_i64(0);
8509 /* take care of sign extending tcg_res */
8510 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
8511 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
8512 tcg_src
, tcg_src_hi
,
8515 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
8520 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
8524 /* Now do the shift right */
8525 if (round
&& extended_result
) {
8526 /* extended case, >64 bit precision required */
8527 if (ext_lshift
== 0) {
8528 /* special case, only high bits matter */
8529 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
8531 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
8532 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
8533 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
8538 /* essentially shifting in 64 zeros */
8539 tcg_gen_movi_i64(tcg_src
, 0);
8541 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
8545 /* effectively extending the sign-bit */
8546 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
8548 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
8554 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
8556 tcg_gen_mov_i64(tcg_res
, tcg_src
);
8559 if (extended_result
) {
8560 tcg_temp_free_i64(tcg_src_hi
);
8564 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
8565 static void handle_scalar_simd_shri(DisasContext
*s
,
8566 bool is_u
, int immh
, int immb
,
8567 int opcode
, int rn
, int rd
)
8570 int immhb
= immh
<< 3 | immb
;
8571 int shift
= 2 * (8 << size
) - immhb
;
8572 bool accumulate
= false;
8574 bool insert
= false;
8579 if (!extract32(immh
, 3, 1)) {
8580 unallocated_encoding(s
);
8584 if (!fp_access_check(s
)) {
8589 case 0x02: /* SSRA / USRA (accumulate) */
8592 case 0x04: /* SRSHR / URSHR (rounding) */
8595 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8596 accumulate
= round
= true;
8598 case 0x08: /* SRI */
8604 tcg_round
= tcg_constant_i64(1ULL << (shift
- 1));
8609 tcg_rn
= read_fp_dreg(s
, rn
);
8610 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
8613 /* shift count same as element size is valid but does nothing;
8614 * special case to avoid potential shift by 64.
8616 int esize
= 8 << size
;
8617 if (shift
!= esize
) {
8618 tcg_gen_shri_i64(tcg_rn
, tcg_rn
, shift
);
8619 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, 0, esize
- shift
);
8622 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8623 accumulate
, is_u
, size
, shift
);
8626 write_fp_dreg(s
, rd
, tcg_rd
);
8628 tcg_temp_free_i64(tcg_rn
);
8629 tcg_temp_free_i64(tcg_rd
);
8632 /* SHL/SLI - Scalar shift left */
8633 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
8634 int immh
, int immb
, int opcode
,
8637 int size
= 32 - clz32(immh
) - 1;
8638 int immhb
= immh
<< 3 | immb
;
8639 int shift
= immhb
- (8 << size
);
8643 if (!extract32(immh
, 3, 1)) {
8644 unallocated_encoding(s
);
8648 if (!fp_access_check(s
)) {
8652 tcg_rn
= read_fp_dreg(s
, rn
);
8653 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
8656 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, shift
, 64 - shift
);
8658 tcg_gen_shli_i64(tcg_rd
, tcg_rn
, shift
);
8661 write_fp_dreg(s
, rd
, tcg_rd
);
8663 tcg_temp_free_i64(tcg_rn
);
8664 tcg_temp_free_i64(tcg_rd
);
8667 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
8668 * (signed/unsigned) narrowing */
8669 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
8670 bool is_u_shift
, bool is_u_narrow
,
8671 int immh
, int immb
, int opcode
,
8674 int immhb
= immh
<< 3 | immb
;
8675 int size
= 32 - clz32(immh
) - 1;
8676 int esize
= 8 << size
;
8677 int shift
= (2 * esize
) - immhb
;
8678 int elements
= is_scalar
? 1 : (64 / esize
);
8679 bool round
= extract32(opcode
, 0, 1);
8680 MemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
8681 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
8682 TCGv_i32 tcg_rd_narrowed
;
8685 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
8686 { gen_helper_neon_narrow_sat_s8
,
8687 gen_helper_neon_unarrow_sat8
},
8688 { gen_helper_neon_narrow_sat_s16
,
8689 gen_helper_neon_unarrow_sat16
},
8690 { gen_helper_neon_narrow_sat_s32
,
8691 gen_helper_neon_unarrow_sat32
},
8694 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
8695 gen_helper_neon_narrow_sat_u8
,
8696 gen_helper_neon_narrow_sat_u16
,
8697 gen_helper_neon_narrow_sat_u32
,
8700 NeonGenNarrowEnvFn
*narrowfn
;
8706 if (extract32(immh
, 3, 1)) {
8707 unallocated_encoding(s
);
8711 if (!fp_access_check(s
)) {
8716 narrowfn
= unsigned_narrow_fns
[size
];
8718 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
8721 tcg_rn
= tcg_temp_new_i64();
8722 tcg_rd
= tcg_temp_new_i64();
8723 tcg_rd_narrowed
= tcg_temp_new_i32();
8724 tcg_final
= tcg_const_i64(0);
8727 tcg_round
= tcg_constant_i64(1ULL << (shift
- 1));
8732 for (i
= 0; i
< elements
; i
++) {
8733 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
8734 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8735 false, is_u_shift
, size
+1, shift
);
8736 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
8737 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
8738 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8742 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8744 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8747 tcg_temp_free_i64(tcg_rn
);
8748 tcg_temp_free_i64(tcg_rd
);
8749 tcg_temp_free_i32(tcg_rd_narrowed
);
8750 tcg_temp_free_i64(tcg_final
);
8752 clear_vec_high(s
, is_q
, rd
);
8755 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
8756 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
8757 bool src_unsigned
, bool dst_unsigned
,
8758 int immh
, int immb
, int rn
, int rd
)
8760 int immhb
= immh
<< 3 | immb
;
8761 int size
= 32 - clz32(immh
) - 1;
8762 int shift
= immhb
- (8 << size
);
8766 assert(!(scalar
&& is_q
));
8769 if (!is_q
&& extract32(immh
, 3, 1)) {
8770 unallocated_encoding(s
);
8774 /* Since we use the variable-shift helpers we must
8775 * replicate the shift count into each element of
8776 * the tcg_shift value.
8780 shift
|= shift
<< 8;
8783 shift
|= shift
<< 16;
8789 g_assert_not_reached();
8793 if (!fp_access_check(s
)) {
8798 TCGv_i64 tcg_shift
= tcg_constant_i64(shift
);
8799 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
8800 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
8801 { NULL
, gen_helper_neon_qshl_u64
},
8803 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
8804 int maxpass
= is_q
? 2 : 1;
8806 for (pass
= 0; pass
< maxpass
; pass
++) {
8807 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8809 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8810 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8811 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
8813 tcg_temp_free_i64(tcg_op
);
8815 clear_vec_high(s
, is_q
, rd
);
8817 TCGv_i32 tcg_shift
= tcg_constant_i32(shift
);
8818 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
8820 { gen_helper_neon_qshl_s8
,
8821 gen_helper_neon_qshl_s16
,
8822 gen_helper_neon_qshl_s32
},
8823 { gen_helper_neon_qshlu_s8
,
8824 gen_helper_neon_qshlu_s16
,
8825 gen_helper_neon_qshlu_s32
}
8827 { NULL
, NULL
, NULL
},
8828 { gen_helper_neon_qshl_u8
,
8829 gen_helper_neon_qshl_u16
,
8830 gen_helper_neon_qshl_u32
}
8833 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
8834 MemOp memop
= scalar
? size
: MO_32
;
8835 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
8837 for (pass
= 0; pass
< maxpass
; pass
++) {
8838 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8840 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
8841 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8845 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
8848 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
8853 g_assert_not_reached();
8855 write_fp_sreg(s
, rd
, tcg_op
);
8857 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
8860 tcg_temp_free_i32(tcg_op
);
8864 clear_vec_high(s
, is_q
, rd
);
8869 /* Common vector code for handling integer to FP conversion */
8870 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
8871 int elements
, int is_signed
,
8872 int fracbits
, int size
)
8874 TCGv_ptr tcg_fpst
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
8875 TCGv_i32 tcg_shift
= NULL
;
8877 MemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
8880 if (fracbits
|| size
== MO_64
) {
8881 tcg_shift
= tcg_constant_i32(fracbits
);
8884 if (size
== MO_64
) {
8885 TCGv_i64 tcg_int64
= tcg_temp_new_i64();
8886 TCGv_i64 tcg_double
= tcg_temp_new_i64();
8888 for (pass
= 0; pass
< elements
; pass
++) {
8889 read_vec_element(s
, tcg_int64
, rn
, pass
, mop
);
8892 gen_helper_vfp_sqtod(tcg_double
, tcg_int64
,
8893 tcg_shift
, tcg_fpst
);
8895 gen_helper_vfp_uqtod(tcg_double
, tcg_int64
,
8896 tcg_shift
, tcg_fpst
);
8898 if (elements
== 1) {
8899 write_fp_dreg(s
, rd
, tcg_double
);
8901 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
8905 tcg_temp_free_i64(tcg_int64
);
8906 tcg_temp_free_i64(tcg_double
);
8909 TCGv_i32 tcg_int32
= tcg_temp_new_i32();
8910 TCGv_i32 tcg_float
= tcg_temp_new_i32();
8912 for (pass
= 0; pass
< elements
; pass
++) {
8913 read_vec_element_i32(s
, tcg_int32
, rn
, pass
, mop
);
8919 gen_helper_vfp_sltos(tcg_float
, tcg_int32
,
8920 tcg_shift
, tcg_fpst
);
8922 gen_helper_vfp_ultos(tcg_float
, tcg_int32
,
8923 tcg_shift
, tcg_fpst
);
8927 gen_helper_vfp_sitos(tcg_float
, tcg_int32
, tcg_fpst
);
8929 gen_helper_vfp_uitos(tcg_float
, tcg_int32
, tcg_fpst
);
8936 gen_helper_vfp_sltoh(tcg_float
, tcg_int32
,
8937 tcg_shift
, tcg_fpst
);
8939 gen_helper_vfp_ultoh(tcg_float
, tcg_int32
,
8940 tcg_shift
, tcg_fpst
);
8944 gen_helper_vfp_sitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8946 gen_helper_vfp_uitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8951 g_assert_not_reached();
8954 if (elements
== 1) {
8955 write_fp_sreg(s
, rd
, tcg_float
);
8957 write_vec_element_i32(s
, tcg_float
, rd
, pass
, size
);
8961 tcg_temp_free_i32(tcg_int32
);
8962 tcg_temp_free_i32(tcg_float
);
8965 tcg_temp_free_ptr(tcg_fpst
);
8967 clear_vec_high(s
, elements
<< size
== 16, rd
);
8970 /* UCVTF/SCVTF - Integer to FP conversion */
8971 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
8972 bool is_q
, bool is_u
,
8973 int immh
, int immb
, int opcode
,
8976 int size
, elements
, fracbits
;
8977 int immhb
= immh
<< 3 | immb
;
8981 if (!is_scalar
&& !is_q
) {
8982 unallocated_encoding(s
);
8985 } else if (immh
& 4) {
8987 } else if (immh
& 2) {
8989 if (!dc_isar_feature(aa64_fp16
, s
)) {
8990 unallocated_encoding(s
);
8994 /* immh == 0 would be a failure of the decode logic */
8995 g_assert(immh
== 1);
8996 unallocated_encoding(s
);
9003 elements
= (8 << is_q
) >> size
;
9005 fracbits
= (16 << size
) - immhb
;
9007 if (!fp_access_check(s
)) {
9011 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
9014 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
9015 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
9016 bool is_q
, bool is_u
,
9017 int immh
, int immb
, int rn
, int rd
)
9019 int immhb
= immh
<< 3 | immb
;
9020 int pass
, size
, fracbits
;
9021 TCGv_ptr tcg_fpstatus
;
9022 TCGv_i32 tcg_rmode
, tcg_shift
;
9026 if (!is_scalar
&& !is_q
) {
9027 unallocated_encoding(s
);
9030 } else if (immh
& 0x4) {
9032 } else if (immh
& 0x2) {
9034 if (!dc_isar_feature(aa64_fp16
, s
)) {
9035 unallocated_encoding(s
);
9039 /* Should have split out AdvSIMD modified immediate earlier. */
9041 unallocated_encoding(s
);
9045 if (!fp_access_check(s
)) {
9049 assert(!(is_scalar
&& is_q
));
9051 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
9052 tcg_fpstatus
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
9053 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9054 fracbits
= (16 << size
) - immhb
;
9055 tcg_shift
= tcg_constant_i32(fracbits
);
9057 if (size
== MO_64
) {
9058 int maxpass
= is_scalar
? 1 : 2;
9060 for (pass
= 0; pass
< maxpass
; pass
++) {
9061 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9063 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9065 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
9067 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
9069 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
9070 tcg_temp_free_i64(tcg_op
);
9072 clear_vec_high(s
, is_q
, rd
);
9074 void (*fn
)(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
9075 int maxpass
= is_scalar
? 1 : ((8 << is_q
) >> size
);
9080 fn
= gen_helper_vfp_touhh
;
9082 fn
= gen_helper_vfp_toshh
;
9087 fn
= gen_helper_vfp_touls
;
9089 fn
= gen_helper_vfp_tosls
;
9093 g_assert_not_reached();
9096 for (pass
= 0; pass
< maxpass
; pass
++) {
9097 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9099 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
9100 fn(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
9102 write_fp_sreg(s
, rd
, tcg_op
);
9104 write_vec_element_i32(s
, tcg_op
, rd
, pass
, size
);
9106 tcg_temp_free_i32(tcg_op
);
9109 clear_vec_high(s
, is_q
, rd
);
9113 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9114 tcg_temp_free_ptr(tcg_fpstatus
);
9115 tcg_temp_free_i32(tcg_rmode
);
9118 /* AdvSIMD scalar shift by immediate
9119 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
9120 * +-----+---+-------------+------+------+--------+---+------+------+
9121 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
9122 * +-----+---+-------------+------+------+--------+---+------+------+
9124 * This is the scalar version so it works on a fixed sized registers
9126 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
9128 int rd
= extract32(insn
, 0, 5);
9129 int rn
= extract32(insn
, 5, 5);
9130 int opcode
= extract32(insn
, 11, 5);
9131 int immb
= extract32(insn
, 16, 3);
9132 int immh
= extract32(insn
, 19, 4);
9133 bool is_u
= extract32(insn
, 29, 1);
9136 unallocated_encoding(s
);
9141 case 0x08: /* SRI */
9143 unallocated_encoding(s
);
9147 case 0x00: /* SSHR / USHR */
9148 case 0x02: /* SSRA / USRA */
9149 case 0x04: /* SRSHR / URSHR */
9150 case 0x06: /* SRSRA / URSRA */
9151 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9153 case 0x0a: /* SHL / SLI */
9154 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9156 case 0x1c: /* SCVTF, UCVTF */
9157 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
9160 case 0x10: /* SQSHRUN, SQSHRUN2 */
9161 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
9163 unallocated_encoding(s
);
9166 handle_vec_simd_sqshrn(s
, true, false, false, true,
9167 immh
, immb
, opcode
, rn
, rd
);
9169 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
9170 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
9171 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
9172 immh
, immb
, opcode
, rn
, rd
);
9174 case 0xc: /* SQSHLU */
9176 unallocated_encoding(s
);
9179 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
9181 case 0xe: /* SQSHL, UQSHL */
9182 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
9184 case 0x1f: /* FCVTZS, FCVTZU */
9185 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
9188 unallocated_encoding(s
);
9193 /* AdvSIMD scalar three different
9194 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
9195 * +-----+---+-----------+------+---+------+--------+-----+------+------+
9196 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
9197 * +-----+---+-----------+------+---+------+--------+-----+------+------+
9199 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
9201 bool is_u
= extract32(insn
, 29, 1);
9202 int size
= extract32(insn
, 22, 2);
9203 int opcode
= extract32(insn
, 12, 4);
9204 int rm
= extract32(insn
, 16, 5);
9205 int rn
= extract32(insn
, 5, 5);
9206 int rd
= extract32(insn
, 0, 5);
9209 unallocated_encoding(s
);
9214 case 0x9: /* SQDMLAL, SQDMLAL2 */
9215 case 0xb: /* SQDMLSL, SQDMLSL2 */
9216 case 0xd: /* SQDMULL, SQDMULL2 */
9217 if (size
== 0 || size
== 3) {
9218 unallocated_encoding(s
);
9223 unallocated_encoding(s
);
9227 if (!fp_access_check(s
)) {
9232 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9233 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9234 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9236 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
9237 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
9239 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
9240 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
9243 case 0xd: /* SQDMULL, SQDMULL2 */
9245 case 0xb: /* SQDMLSL, SQDMLSL2 */
9246 tcg_gen_neg_i64(tcg_res
, tcg_res
);
9248 case 0x9: /* SQDMLAL, SQDMLAL2 */
9249 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
9250 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
9254 g_assert_not_reached();
9257 write_fp_dreg(s
, rd
, tcg_res
);
9259 tcg_temp_free_i64(tcg_op1
);
9260 tcg_temp_free_i64(tcg_op2
);
9261 tcg_temp_free_i64(tcg_res
);
9263 TCGv_i32 tcg_op1
= read_fp_hreg(s
, rn
);
9264 TCGv_i32 tcg_op2
= read_fp_hreg(s
, rm
);
9265 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9267 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
9268 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
9271 case 0xd: /* SQDMULL, SQDMULL2 */
9273 case 0xb: /* SQDMLSL, SQDMLSL2 */
9274 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
9276 case 0x9: /* SQDMLAL, SQDMLAL2 */
9278 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
9279 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
9280 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
9282 tcg_temp_free_i64(tcg_op3
);
9286 g_assert_not_reached();
9289 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
9290 write_fp_dreg(s
, rd
, tcg_res
);
9292 tcg_temp_free_i32(tcg_op1
);
9293 tcg_temp_free_i32(tcg_op2
);
9294 tcg_temp_free_i64(tcg_res
);
9298 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
9299 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
9301 /* Handle 64x64->64 opcodes which are shared between the scalar
9302 * and vector 3-same groups. We cover every opcode where size == 3
9303 * is valid in either the three-reg-same (integer, not pairwise)
9304 * or scalar-three-reg-same groups.
9309 case 0x1: /* SQADD */
9311 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9313 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9316 case 0x5: /* SQSUB */
9318 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9320 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9323 case 0x6: /* CMGT, CMHI */
9324 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
9325 * We implement this using setcond (test) and then negating.
9327 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
9329 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
9330 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
9332 case 0x7: /* CMGE, CMHS */
9333 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
9335 case 0x11: /* CMTST, CMEQ */
9340 gen_cmtst_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9342 case 0x8: /* SSHL, USHL */
9344 gen_ushl_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9346 gen_sshl_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9349 case 0x9: /* SQSHL, UQSHL */
9351 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9353 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9356 case 0xa: /* SRSHL, URSHL */
9358 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
9360 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
9363 case 0xb: /* SQRSHL, UQRSHL */
9365 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9367 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
9370 case 0x10: /* ADD, SUB */
9372 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9374 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
9378 g_assert_not_reached();
9382 /* Handle the 3-same-operands float operations; shared by the scalar
9383 * and vector encodings. The caller must filter out any encodings
9384 * not allocated for the encoding it is dealing with.
9386 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
9387 int fpopcode
, int rd
, int rn
, int rm
)
9390 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
9392 for (pass
= 0; pass
< elements
; pass
++) {
9395 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9396 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9397 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9399 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9400 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9403 case 0x39: /* FMLS */
9404 /* As usual for ARM, separate negation for fused multiply-add */
9405 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
9407 case 0x19: /* FMLA */
9408 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9409 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
9412 case 0x18: /* FMAXNM */
9413 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9415 case 0x1a: /* FADD */
9416 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9418 case 0x1b: /* FMULX */
9419 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9421 case 0x1c: /* FCMEQ */
9422 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9424 case 0x1e: /* FMAX */
9425 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9427 case 0x1f: /* FRECPS */
9428 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9430 case 0x38: /* FMINNM */
9431 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9433 case 0x3a: /* FSUB */
9434 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9436 case 0x3e: /* FMIN */
9437 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9439 case 0x3f: /* FRSQRTS */
9440 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9442 case 0x5b: /* FMUL */
9443 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9445 case 0x5c: /* FCMGE */
9446 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9448 case 0x5d: /* FACGE */
9449 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9451 case 0x5f: /* FDIV */
9452 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9454 case 0x7a: /* FABD */
9455 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9456 gen_helper_vfp_absd(tcg_res
, tcg_res
);
9458 case 0x7c: /* FCMGT */
9459 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9461 case 0x7d: /* FACGT */
9462 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9465 g_assert_not_reached();
9468 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9470 tcg_temp_free_i64(tcg_res
);
9471 tcg_temp_free_i64(tcg_op1
);
9472 tcg_temp_free_i64(tcg_op2
);
9475 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9476 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9477 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9479 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
9480 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
9483 case 0x39: /* FMLS */
9484 /* As usual for ARM, separate negation for fused multiply-add */
9485 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
9487 case 0x19: /* FMLA */
9488 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9489 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
9492 case 0x1a: /* FADD */
9493 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9495 case 0x1b: /* FMULX */
9496 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9498 case 0x1c: /* FCMEQ */
9499 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9501 case 0x1e: /* FMAX */
9502 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9504 case 0x1f: /* FRECPS */
9505 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9507 case 0x18: /* FMAXNM */
9508 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9510 case 0x38: /* FMINNM */
9511 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9513 case 0x3a: /* FSUB */
9514 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9516 case 0x3e: /* FMIN */
9517 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9519 case 0x3f: /* FRSQRTS */
9520 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9522 case 0x5b: /* FMUL */
9523 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9525 case 0x5c: /* FCMGE */
9526 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9528 case 0x5d: /* FACGE */
9529 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9531 case 0x5f: /* FDIV */
9532 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9534 case 0x7a: /* FABD */
9535 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9536 gen_helper_vfp_abss(tcg_res
, tcg_res
);
9538 case 0x7c: /* FCMGT */
9539 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9541 case 0x7d: /* FACGT */
9542 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9545 g_assert_not_reached();
9548 if (elements
== 1) {
9549 /* scalar single so clear high part */
9550 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9552 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
9553 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
9554 tcg_temp_free_i64(tcg_tmp
);
9556 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9559 tcg_temp_free_i32(tcg_res
);
9560 tcg_temp_free_i32(tcg_op1
);
9561 tcg_temp_free_i32(tcg_op2
);
9565 tcg_temp_free_ptr(fpst
);
9567 clear_vec_high(s
, elements
* (size
? 8 : 4) > 8, rd
);
9570 /* AdvSIMD scalar three same
9571 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
9572 * +-----+---+-----------+------+---+------+--------+---+------+------+
9573 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
9574 * +-----+---+-----------+------+---+------+--------+---+------+------+
9576 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
9578 int rd
= extract32(insn
, 0, 5);
9579 int rn
= extract32(insn
, 5, 5);
9580 int opcode
= extract32(insn
, 11, 5);
9581 int rm
= extract32(insn
, 16, 5);
9582 int size
= extract32(insn
, 22, 2);
9583 bool u
= extract32(insn
, 29, 1);
9586 if (opcode
>= 0x18) {
9587 /* Floating point: U, size[1] and opcode indicate operation */
9588 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
9590 case 0x1b: /* FMULX */
9591 case 0x1f: /* FRECPS */
9592 case 0x3f: /* FRSQRTS */
9593 case 0x5d: /* FACGE */
9594 case 0x7d: /* FACGT */
9595 case 0x1c: /* FCMEQ */
9596 case 0x5c: /* FCMGE */
9597 case 0x7c: /* FCMGT */
9598 case 0x7a: /* FABD */
9601 unallocated_encoding(s
);
9605 if (!fp_access_check(s
)) {
9609 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
9614 case 0x1: /* SQADD, UQADD */
9615 case 0x5: /* SQSUB, UQSUB */
9616 case 0x9: /* SQSHL, UQSHL */
9617 case 0xb: /* SQRSHL, UQRSHL */
9619 case 0x8: /* SSHL, USHL */
9620 case 0xa: /* SRSHL, URSHL */
9621 case 0x6: /* CMGT, CMHI */
9622 case 0x7: /* CMGE, CMHS */
9623 case 0x11: /* CMTST, CMEQ */
9624 case 0x10: /* ADD, SUB (vector) */
9626 unallocated_encoding(s
);
9630 case 0x16: /* SQDMULH, SQRDMULH (vector) */
9631 if (size
!= 1 && size
!= 2) {
9632 unallocated_encoding(s
);
9637 unallocated_encoding(s
);
9641 if (!fp_access_check(s
)) {
9645 tcg_rd
= tcg_temp_new_i64();
9648 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
9649 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
9651 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
9652 tcg_temp_free_i64(tcg_rn
);
9653 tcg_temp_free_i64(tcg_rm
);
9655 /* Do a single operation on the lowest element in the vector.
9656 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
9657 * no side effects for all these operations.
9658 * OPTME: special-purpose helpers would avoid doing some
9659 * unnecessary work in the helper for the 8 and 16 bit cases.
9661 NeonGenTwoOpEnvFn
*genenvfn
;
9662 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9663 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
9664 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
9666 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
9667 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
9670 case 0x1: /* SQADD, UQADD */
9672 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9673 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9674 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9675 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9677 genenvfn
= fns
[size
][u
];
9680 case 0x5: /* SQSUB, UQSUB */
9682 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9683 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9684 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9685 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9687 genenvfn
= fns
[size
][u
];
9690 case 0x9: /* SQSHL, UQSHL */
9692 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9693 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9694 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9695 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9697 genenvfn
= fns
[size
][u
];
9700 case 0xb: /* SQRSHL, UQRSHL */
9702 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9703 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9704 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9705 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9707 genenvfn
= fns
[size
][u
];
9710 case 0x16: /* SQDMULH, SQRDMULH */
9712 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9713 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9714 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9716 assert(size
== 1 || size
== 2);
9717 genenvfn
= fns
[size
- 1][u
];
9721 g_assert_not_reached();
9724 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
9725 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
9726 tcg_temp_free_i32(tcg_rd32
);
9727 tcg_temp_free_i32(tcg_rn
);
9728 tcg_temp_free_i32(tcg_rm
);
9731 write_fp_dreg(s
, rd
, tcg_rd
);
9733 tcg_temp_free_i64(tcg_rd
);
9736 /* AdvSIMD scalar three same FP16
9737 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
9738 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9739 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
9740 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9741 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
9742 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
9744 static void disas_simd_scalar_three_reg_same_fp16(DisasContext
*s
,
9747 int rd
= extract32(insn
, 0, 5);
9748 int rn
= extract32(insn
, 5, 5);
9749 int opcode
= extract32(insn
, 11, 3);
9750 int rm
= extract32(insn
, 16, 5);
9751 bool u
= extract32(insn
, 29, 1);
9752 bool a
= extract32(insn
, 23, 1);
9753 int fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
9760 case 0x03: /* FMULX */
9761 case 0x04: /* FCMEQ (reg) */
9762 case 0x07: /* FRECPS */
9763 case 0x0f: /* FRSQRTS */
9764 case 0x14: /* FCMGE (reg) */
9765 case 0x15: /* FACGE */
9766 case 0x1a: /* FABD */
9767 case 0x1c: /* FCMGT (reg) */
9768 case 0x1d: /* FACGT */
9771 unallocated_encoding(s
);
9775 if (!dc_isar_feature(aa64_fp16
, s
)) {
9776 unallocated_encoding(s
);
9779 if (!fp_access_check(s
)) {
9783 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
9785 tcg_op1
= read_fp_hreg(s
, rn
);
9786 tcg_op2
= read_fp_hreg(s
, rm
);
9787 tcg_res
= tcg_temp_new_i32();
9790 case 0x03: /* FMULX */
9791 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9793 case 0x04: /* FCMEQ (reg) */
9794 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9796 case 0x07: /* FRECPS */
9797 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9799 case 0x0f: /* FRSQRTS */
9800 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9802 case 0x14: /* FCMGE (reg) */
9803 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9805 case 0x15: /* FACGE */
9806 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9808 case 0x1a: /* FABD */
9809 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9810 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
9812 case 0x1c: /* FCMGT (reg) */
9813 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9815 case 0x1d: /* FACGT */
9816 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9819 g_assert_not_reached();
9822 write_fp_sreg(s
, rd
, tcg_res
);
9825 tcg_temp_free_i32(tcg_res
);
9826 tcg_temp_free_i32(tcg_op1
);
9827 tcg_temp_free_i32(tcg_op2
);
9828 tcg_temp_free_ptr(fpst
);
9831 /* AdvSIMD scalar three same extra
9832 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
9833 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9834 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
9835 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9837 static void disas_simd_scalar_three_reg_same_extra(DisasContext
*s
,
9840 int rd
= extract32(insn
, 0, 5);
9841 int rn
= extract32(insn
, 5, 5);
9842 int opcode
= extract32(insn
, 11, 4);
9843 int rm
= extract32(insn
, 16, 5);
9844 int size
= extract32(insn
, 22, 2);
9845 bool u
= extract32(insn
, 29, 1);
9846 TCGv_i32 ele1
, ele2
, ele3
;
9850 switch (u
* 16 + opcode
) {
9851 case 0x10: /* SQRDMLAH (vector) */
9852 case 0x11: /* SQRDMLSH (vector) */
9853 if (size
!= 1 && size
!= 2) {
9854 unallocated_encoding(s
);
9857 feature
= dc_isar_feature(aa64_rdm
, s
);
9860 unallocated_encoding(s
);
9864 unallocated_encoding(s
);
9867 if (!fp_access_check(s
)) {
9871 /* Do a single operation on the lowest element in the vector.
9872 * We use the standard Neon helpers and rely on 0 OP 0 == 0
9873 * with no side effects for all these operations.
9874 * OPTME: special-purpose helpers would avoid doing some
9875 * unnecessary work in the helper for the 16 bit cases.
9877 ele1
= tcg_temp_new_i32();
9878 ele2
= tcg_temp_new_i32();
9879 ele3
= tcg_temp_new_i32();
9881 read_vec_element_i32(s
, ele1
, rn
, 0, size
);
9882 read_vec_element_i32(s
, ele2
, rm
, 0, size
);
9883 read_vec_element_i32(s
, ele3
, rd
, 0, size
);
9886 case 0x0: /* SQRDMLAH */
9888 gen_helper_neon_qrdmlah_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9890 gen_helper_neon_qrdmlah_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9893 case 0x1: /* SQRDMLSH */
9895 gen_helper_neon_qrdmlsh_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9897 gen_helper_neon_qrdmlsh_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9901 g_assert_not_reached();
9903 tcg_temp_free_i32(ele1
);
9904 tcg_temp_free_i32(ele2
);
9906 res
= tcg_temp_new_i64();
9907 tcg_gen_extu_i32_i64(res
, ele3
);
9908 tcg_temp_free_i32(ele3
);
9910 write_fp_dreg(s
, rd
, res
);
9911 tcg_temp_free_i64(res
);
9914 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
9915 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
9916 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
9918 /* Handle 64->64 opcodes which are shared between the scalar and
9919 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
9920 * is valid in either group and also the double-precision fp ops.
9921 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
9927 case 0x4: /* CLS, CLZ */
9929 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
9931 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
9935 /* This opcode is shared with CNT and RBIT but we have earlier
9936 * enforced that size == 3 if and only if this is the NOT insn.
9938 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
9940 case 0x7: /* SQABS, SQNEG */
9942 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
9944 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
9947 case 0xa: /* CMLT */
9948 /* 64 bit integer comparison against zero, result is
9949 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
9954 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
9955 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
9957 case 0x8: /* CMGT, CMGE */
9958 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
9960 case 0x9: /* CMEQ, CMLE */
9961 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
9963 case 0xb: /* ABS, NEG */
9965 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
9967 tcg_gen_abs_i64(tcg_rd
, tcg_rn
);
9970 case 0x2f: /* FABS */
9971 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
9973 case 0x6f: /* FNEG */
9974 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
9976 case 0x7f: /* FSQRT */
9977 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
9979 case 0x1a: /* FCVTNS */
9980 case 0x1b: /* FCVTMS */
9981 case 0x1c: /* FCVTAS */
9982 case 0x3a: /* FCVTPS */
9983 case 0x3b: /* FCVTZS */
9984 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_constant_i32(0), tcg_fpstatus
);
9986 case 0x5a: /* FCVTNU */
9987 case 0x5b: /* FCVTMU */
9988 case 0x5c: /* FCVTAU */
9989 case 0x7a: /* FCVTPU */
9990 case 0x7b: /* FCVTZU */
9991 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_constant_i32(0), tcg_fpstatus
);
9993 case 0x18: /* FRINTN */
9994 case 0x19: /* FRINTM */
9995 case 0x38: /* FRINTP */
9996 case 0x39: /* FRINTZ */
9997 case 0x58: /* FRINTA */
9998 case 0x79: /* FRINTI */
9999 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
10001 case 0x59: /* FRINTX */
10002 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
10004 case 0x1e: /* FRINT32Z */
10005 case 0x5e: /* FRINT32X */
10006 gen_helper_frint32_d(tcg_rd
, tcg_rn
, tcg_fpstatus
);
10008 case 0x1f: /* FRINT64Z */
10009 case 0x5f: /* FRINT64X */
10010 gen_helper_frint64_d(tcg_rd
, tcg_rn
, tcg_fpstatus
);
10013 g_assert_not_reached();
10017 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
10018 bool is_scalar
, bool is_u
, bool is_q
,
10019 int size
, int rn
, int rd
)
10021 bool is_double
= (size
== MO_64
);
10024 if (!fp_access_check(s
)) {
10028 fpst
= fpstatus_ptr(size
== MO_16
? FPST_FPCR_F16
: FPST_FPCR
);
10031 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10032 TCGv_i64 tcg_zero
= tcg_constant_i64(0);
10033 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10034 NeonGenTwoDoubleOpFn
*genfn
;
10039 case 0x2e: /* FCMLT (zero) */
10042 case 0x2c: /* FCMGT (zero) */
10043 genfn
= gen_helper_neon_cgt_f64
;
10045 case 0x2d: /* FCMEQ (zero) */
10046 genfn
= gen_helper_neon_ceq_f64
;
10048 case 0x6d: /* FCMLE (zero) */
10051 case 0x6c: /* FCMGE (zero) */
10052 genfn
= gen_helper_neon_cge_f64
;
10055 g_assert_not_reached();
10058 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10059 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10061 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
10063 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
10065 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10067 tcg_temp_free_i64(tcg_res
);
10068 tcg_temp_free_i64(tcg_op
);
10070 clear_vec_high(s
, !is_scalar
, rd
);
10072 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10073 TCGv_i32 tcg_zero
= tcg_constant_i32(0);
10074 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10075 NeonGenTwoSingleOpFn
*genfn
;
10077 int pass
, maxpasses
;
10079 if (size
== MO_16
) {
10081 case 0x2e: /* FCMLT (zero) */
10084 case 0x2c: /* FCMGT (zero) */
10085 genfn
= gen_helper_advsimd_cgt_f16
;
10087 case 0x2d: /* FCMEQ (zero) */
10088 genfn
= gen_helper_advsimd_ceq_f16
;
10090 case 0x6d: /* FCMLE (zero) */
10093 case 0x6c: /* FCMGE (zero) */
10094 genfn
= gen_helper_advsimd_cge_f16
;
10097 g_assert_not_reached();
10101 case 0x2e: /* FCMLT (zero) */
10104 case 0x2c: /* FCMGT (zero) */
10105 genfn
= gen_helper_neon_cgt_f32
;
10107 case 0x2d: /* FCMEQ (zero) */
10108 genfn
= gen_helper_neon_ceq_f32
;
10110 case 0x6d: /* FCMLE (zero) */
10113 case 0x6c: /* FCMGE (zero) */
10114 genfn
= gen_helper_neon_cge_f32
;
10117 g_assert_not_reached();
10124 int vector_size
= 8 << is_q
;
10125 maxpasses
= vector_size
>> size
;
10128 for (pass
= 0; pass
< maxpasses
; pass
++) {
10129 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10131 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
10133 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
10136 write_fp_sreg(s
, rd
, tcg_res
);
10138 write_vec_element_i32(s
, tcg_res
, rd
, pass
, size
);
10141 tcg_temp_free_i32(tcg_res
);
10142 tcg_temp_free_i32(tcg_op
);
10144 clear_vec_high(s
, is_q
, rd
);
10148 tcg_temp_free_ptr(fpst
);
10151 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
10152 bool is_scalar
, bool is_u
, bool is_q
,
10153 int size
, int rn
, int rd
)
10155 bool is_double
= (size
== 3);
10156 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
10159 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10160 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10163 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10164 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10166 case 0x3d: /* FRECPE */
10167 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
10169 case 0x3f: /* FRECPX */
10170 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
10172 case 0x7d: /* FRSQRTE */
10173 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
10176 g_assert_not_reached();
10178 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10180 tcg_temp_free_i64(tcg_res
);
10181 tcg_temp_free_i64(tcg_op
);
10182 clear_vec_high(s
, !is_scalar
, rd
);
10184 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10185 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10186 int pass
, maxpasses
;
10191 maxpasses
= is_q
? 4 : 2;
10194 for (pass
= 0; pass
< maxpasses
; pass
++) {
10195 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
10198 case 0x3c: /* URECPE */
10199 gen_helper_recpe_u32(tcg_res
, tcg_op
);
10201 case 0x3d: /* FRECPE */
10202 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
10204 case 0x3f: /* FRECPX */
10205 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
10207 case 0x7d: /* FRSQRTE */
10208 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
10211 g_assert_not_reached();
10215 write_fp_sreg(s
, rd
, tcg_res
);
10217 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10220 tcg_temp_free_i32(tcg_res
);
10221 tcg_temp_free_i32(tcg_op
);
10223 clear_vec_high(s
, is_q
, rd
);
10226 tcg_temp_free_ptr(fpst
);
10229 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
10230 int opcode
, bool u
, bool is_q
,
10231 int size
, int rn
, int rd
)
10233 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
10234 * in the source becomes a size element in the destination).
10237 TCGv_i32 tcg_res
[2];
10238 int destelt
= is_q
? 2 : 0;
10239 int passes
= scalar
? 1 : 2;
10242 tcg_res
[1] = tcg_constant_i32(0);
10245 for (pass
= 0; pass
< passes
; pass
++) {
10246 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10247 NeonGenNarrowFn
*genfn
= NULL
;
10248 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
10251 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
10253 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10255 tcg_res
[pass
] = tcg_temp_new_i32();
10258 case 0x12: /* XTN, SQXTUN */
10260 static NeonGenNarrowFn
* const xtnfns
[3] = {
10261 gen_helper_neon_narrow_u8
,
10262 gen_helper_neon_narrow_u16
,
10263 tcg_gen_extrl_i64_i32
,
10265 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
10266 gen_helper_neon_unarrow_sat8
,
10267 gen_helper_neon_unarrow_sat16
,
10268 gen_helper_neon_unarrow_sat32
,
10271 genenvfn
= sqxtunfns
[size
];
10273 genfn
= xtnfns
[size
];
10277 case 0x14: /* SQXTN, UQXTN */
10279 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
10280 { gen_helper_neon_narrow_sat_s8
,
10281 gen_helper_neon_narrow_sat_u8
},
10282 { gen_helper_neon_narrow_sat_s16
,
10283 gen_helper_neon_narrow_sat_u16
},
10284 { gen_helper_neon_narrow_sat_s32
,
10285 gen_helper_neon_narrow_sat_u32
},
10287 genenvfn
= fns
[size
][u
];
10290 case 0x16: /* FCVTN, FCVTN2 */
10291 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
10293 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
10295 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
10296 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
10297 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
10298 TCGv_i32 ahp
= get_ahp_flag();
10300 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
10301 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, fpst
, ahp
);
10302 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, fpst
, ahp
);
10303 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
10304 tcg_temp_free_i32(tcg_lo
);
10305 tcg_temp_free_i32(tcg_hi
);
10306 tcg_temp_free_ptr(fpst
);
10307 tcg_temp_free_i32(ahp
);
10310 case 0x36: /* BFCVTN, BFCVTN2 */
10312 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
10313 gen_helper_bfcvt_pair(tcg_res
[pass
], tcg_op
, fpst
);
10314 tcg_temp_free_ptr(fpst
);
10317 case 0x56: /* FCVTXN, FCVTXN2 */
10318 /* 64 bit to 32 bit float conversion
10319 * with von Neumann rounding (round to odd)
10322 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
10325 g_assert_not_reached();
10329 genfn(tcg_res
[pass
], tcg_op
);
10330 } else if (genenvfn
) {
10331 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
10334 tcg_temp_free_i64(tcg_op
);
10337 for (pass
= 0; pass
< 2; pass
++) {
10338 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
10339 tcg_temp_free_i32(tcg_res
[pass
]);
10341 clear_vec_high(s
, is_q
, rd
);
10344 /* Remaining saturating accumulating ops */
10345 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
10346 bool is_q
, int size
, int rn
, int rd
)
10348 bool is_double
= (size
== 3);
10351 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
10352 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
10355 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10356 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
10357 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
10359 if (is_u
) { /* USQADD */
10360 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10361 } else { /* SUQADD */
10362 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10364 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
10366 tcg_temp_free_i64(tcg_rd
);
10367 tcg_temp_free_i64(tcg_rn
);
10368 clear_vec_high(s
, !is_scalar
, rd
);
10370 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
10371 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
10372 int pass
, maxpasses
;
10377 maxpasses
= is_q
? 4 : 2;
10380 for (pass
= 0; pass
< maxpasses
; pass
++) {
10382 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
10383 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
10385 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
10386 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
10389 if (is_u
) { /* USQADD */
10392 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10395 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10398 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10401 g_assert_not_reached();
10403 } else { /* SUQADD */
10406 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10409 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10412 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
10415 g_assert_not_reached();
10420 write_vec_element(s
, tcg_constant_i64(0), rd
, 0, MO_64
);
10422 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
10424 tcg_temp_free_i32(tcg_rd
);
10425 tcg_temp_free_i32(tcg_rn
);
10426 clear_vec_high(s
, is_q
, rd
);
10430 /* AdvSIMD scalar two reg misc
10431 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
10432 * +-----+---+-----------+------+-----------+--------+-----+------+------+
10433 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
10434 * +-----+---+-----------+------+-----------+--------+-----+------+------+
10436 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
10438 int rd
= extract32(insn
, 0, 5);
10439 int rn
= extract32(insn
, 5, 5);
10440 int opcode
= extract32(insn
, 12, 5);
10441 int size
= extract32(insn
, 22, 2);
10442 bool u
= extract32(insn
, 29, 1);
10443 bool is_fcvt
= false;
10445 TCGv_i32 tcg_rmode
;
10446 TCGv_ptr tcg_fpstatus
;
10449 case 0x3: /* USQADD / SUQADD*/
10450 if (!fp_access_check(s
)) {
10453 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
10455 case 0x7: /* SQABS / SQNEG */
10457 case 0xa: /* CMLT */
10459 unallocated_encoding(s
);
10463 case 0x8: /* CMGT, CMGE */
10464 case 0x9: /* CMEQ, CMLE */
10465 case 0xb: /* ABS, NEG */
10467 unallocated_encoding(s
);
10471 case 0x12: /* SQXTUN */
10473 unallocated_encoding(s
);
10477 case 0x14: /* SQXTN, UQXTN */
10479 unallocated_encoding(s
);
10482 if (!fp_access_check(s
)) {
10485 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
10488 case 0x16 ... 0x1d:
10490 /* Floating point: U, size[1] and opcode indicate operation;
10491 * size[0] indicates single or double precision.
10493 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
10494 size
= extract32(size
, 0, 1) ? 3 : 2;
10496 case 0x2c: /* FCMGT (zero) */
10497 case 0x2d: /* FCMEQ (zero) */
10498 case 0x2e: /* FCMLT (zero) */
10499 case 0x6c: /* FCMGE (zero) */
10500 case 0x6d: /* FCMLE (zero) */
10501 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
10503 case 0x1d: /* SCVTF */
10504 case 0x5d: /* UCVTF */
10506 bool is_signed
= (opcode
== 0x1d);
10507 if (!fp_access_check(s
)) {
10510 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
10513 case 0x3d: /* FRECPE */
10514 case 0x3f: /* FRECPX */
10515 case 0x7d: /* FRSQRTE */
10516 if (!fp_access_check(s
)) {
10519 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
10521 case 0x1a: /* FCVTNS */
10522 case 0x1b: /* FCVTMS */
10523 case 0x3a: /* FCVTPS */
10524 case 0x3b: /* FCVTZS */
10525 case 0x5a: /* FCVTNU */
10526 case 0x5b: /* FCVTMU */
10527 case 0x7a: /* FCVTPU */
10528 case 0x7b: /* FCVTZU */
10530 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
10532 case 0x1c: /* FCVTAS */
10533 case 0x5c: /* FCVTAU */
10534 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
10536 rmode
= FPROUNDING_TIEAWAY
;
10538 case 0x56: /* FCVTXN, FCVTXN2 */
10540 unallocated_encoding(s
);
10543 if (!fp_access_check(s
)) {
10546 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
10549 unallocated_encoding(s
);
10554 unallocated_encoding(s
);
10558 if (!fp_access_check(s
)) {
10563 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
10564 tcg_fpstatus
= fpstatus_ptr(FPST_FPCR
);
10565 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
10568 tcg_fpstatus
= NULL
;
10572 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
10573 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
10575 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
10576 write_fp_dreg(s
, rd
, tcg_rd
);
10577 tcg_temp_free_i64(tcg_rd
);
10578 tcg_temp_free_i64(tcg_rn
);
10580 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
10581 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
10583 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
10586 case 0x7: /* SQABS, SQNEG */
10588 NeonGenOneOpEnvFn
*genfn
;
10589 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
10590 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
10591 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
10592 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
10594 genfn
= fns
[size
][u
];
10595 genfn(tcg_rd
, cpu_env
, tcg_rn
);
10598 case 0x1a: /* FCVTNS */
10599 case 0x1b: /* FCVTMS */
10600 case 0x1c: /* FCVTAS */
10601 case 0x3a: /* FCVTPS */
10602 case 0x3b: /* FCVTZS */
10603 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_constant_i32(0),
10606 case 0x5a: /* FCVTNU */
10607 case 0x5b: /* FCVTMU */
10608 case 0x5c: /* FCVTAU */
10609 case 0x7a: /* FCVTPU */
10610 case 0x7b: /* FCVTZU */
10611 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_constant_i32(0),
10615 g_assert_not_reached();
10618 write_fp_sreg(s
, rd
, tcg_rd
);
10619 tcg_temp_free_i32(tcg_rd
);
10620 tcg_temp_free_i32(tcg_rn
);
10624 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
10625 tcg_temp_free_i32(tcg_rmode
);
10626 tcg_temp_free_ptr(tcg_fpstatus
);
10630 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
10631 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
10632 int immh
, int immb
, int opcode
, int rn
, int rd
)
10634 int size
= 32 - clz32(immh
) - 1;
10635 int immhb
= immh
<< 3 | immb
;
10636 int shift
= 2 * (8 << size
) - immhb
;
10637 GVecGen2iFn
*gvec_fn
;
10639 if (extract32(immh
, 3, 1) && !is_q
) {
10640 unallocated_encoding(s
);
10643 tcg_debug_assert(size
<= 3);
10645 if (!fp_access_check(s
)) {
10650 case 0x02: /* SSRA / USRA (accumulate) */
10651 gvec_fn
= is_u
? gen_gvec_usra
: gen_gvec_ssra
;
10654 case 0x08: /* SRI */
10655 gvec_fn
= gen_gvec_sri
;
10658 case 0x00: /* SSHR / USHR */
10660 if (shift
== 8 << size
) {
10661 /* Shift count the same size as element size produces zero. */
10662 tcg_gen_gvec_dup_imm(size
, vec_full_reg_offset(s
, rd
),
10663 is_q
? 16 : 8, vec_full_reg_size(s
), 0);
10666 gvec_fn
= tcg_gen_gvec_shri
;
10668 /* Shift count the same size as element size produces all sign. */
10669 if (shift
== 8 << size
) {
10672 gvec_fn
= tcg_gen_gvec_sari
;
10676 case 0x04: /* SRSHR / URSHR (rounding) */
10677 gvec_fn
= is_u
? gen_gvec_urshr
: gen_gvec_srshr
;
10680 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10681 gvec_fn
= is_u
? gen_gvec_ursra
: gen_gvec_srsra
;
10685 g_assert_not_reached();
10688 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, gvec_fn
, size
);
10691 /* SHL/SLI - Vector shift left */
10692 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
10693 int immh
, int immb
, int opcode
, int rn
, int rd
)
10695 int size
= 32 - clz32(immh
) - 1;
10696 int immhb
= immh
<< 3 | immb
;
10697 int shift
= immhb
- (8 << size
);
10699 /* Range of size is limited by decode: immh is a non-zero 4 bit field */
10700 assert(size
>= 0 && size
<= 3);
10702 if (extract32(immh
, 3, 1) && !is_q
) {
10703 unallocated_encoding(s
);
10707 if (!fp_access_check(s
)) {
10712 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, gen_gvec_sli
, size
);
10714 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shli
, size
);
10718 /* USHLL/SHLL - Vector shift left with widening */
10719 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
10720 int immh
, int immb
, int opcode
, int rn
, int rd
)
10722 int size
= 32 - clz32(immh
) - 1;
10723 int immhb
= immh
<< 3 | immb
;
10724 int shift
= immhb
- (8 << size
);
10726 int esize
= 8 << size
;
10727 int elements
= dsize
/esize
;
10728 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
10729 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
10733 unallocated_encoding(s
);
10737 if (!fp_access_check(s
)) {
10741 /* For the LL variants the store is larger than the load,
10742 * so if rd == rn we would overwrite parts of our input.
10743 * So load everything right now and use shifts in the main loop.
10745 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
10747 for (i
= 0; i
< elements
; i
++) {
10748 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
10749 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
10750 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
10751 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
10755 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
10756 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
10757 int immh
, int immb
, int opcode
, int rn
, int rd
)
10759 int immhb
= immh
<< 3 | immb
;
10760 int size
= 32 - clz32(immh
) - 1;
10762 int esize
= 8 << size
;
10763 int elements
= dsize
/esize
;
10764 int shift
= (2 * esize
) - immhb
;
10765 bool round
= extract32(opcode
, 0, 1);
10766 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
10767 TCGv_i64 tcg_round
;
10770 if (extract32(immh
, 3, 1)) {
10771 unallocated_encoding(s
);
10775 if (!fp_access_check(s
)) {
10779 tcg_rn
= tcg_temp_new_i64();
10780 tcg_rd
= tcg_temp_new_i64();
10781 tcg_final
= tcg_temp_new_i64();
10782 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
10785 tcg_round
= tcg_constant_i64(1ULL << (shift
- 1));
10790 for (i
= 0; i
< elements
; i
++) {
10791 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
10792 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
10793 false, true, size
+1, shift
);
10795 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
10799 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
10801 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
10803 tcg_temp_free_i64(tcg_rn
);
10804 tcg_temp_free_i64(tcg_rd
);
10805 tcg_temp_free_i64(tcg_final
);
10807 clear_vec_high(s
, is_q
, rd
);
10811 /* AdvSIMD shift by immediate
10812 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
10813 * +---+---+---+-------------+------+------+--------+---+------+------+
10814 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
10815 * +---+---+---+-------------+------+------+--------+---+------+------+
10817 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
10819 int rd
= extract32(insn
, 0, 5);
10820 int rn
= extract32(insn
, 5, 5);
10821 int opcode
= extract32(insn
, 11, 5);
10822 int immb
= extract32(insn
, 16, 3);
10823 int immh
= extract32(insn
, 19, 4);
10824 bool is_u
= extract32(insn
, 29, 1);
10825 bool is_q
= extract32(insn
, 30, 1);
10827 /* data_proc_simd[] has sent immh == 0 to disas_simd_mod_imm. */
10831 case 0x08: /* SRI */
10833 unallocated_encoding(s
);
10837 case 0x00: /* SSHR / USHR */
10838 case 0x02: /* SSRA / USRA (accumulate) */
10839 case 0x04: /* SRSHR / URSHR (rounding) */
10840 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10841 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10843 case 0x0a: /* SHL / SLI */
10844 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10846 case 0x10: /* SHRN */
10847 case 0x11: /* RSHRN / SQRSHRUN */
10849 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
10852 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
10855 case 0x12: /* SQSHRN / UQSHRN */
10856 case 0x13: /* SQRSHRN / UQRSHRN */
10857 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
10860 case 0x14: /* SSHLL / USHLL */
10861 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10863 case 0x1c: /* SCVTF / UCVTF */
10864 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
10867 case 0xc: /* SQSHLU */
10869 unallocated_encoding(s
);
10872 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
10874 case 0xe: /* SQSHL, UQSHL */
10875 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
10877 case 0x1f: /* FCVTZS/ FCVTZU */
10878 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
10881 unallocated_encoding(s
);
10886 /* Generate code to do a "long" addition or subtraction, ie one done in
10887 * TCGv_i64 on vector lanes twice the width specified by size.
10889 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
10890 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
10892 static NeonGenTwo64OpFn
* const fns
[3][2] = {
10893 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
10894 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
10895 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
10897 NeonGenTwo64OpFn
*genfn
;
10900 genfn
= fns
[size
][is_sub
];
10901 genfn(tcg_res
, tcg_op1
, tcg_op2
);
10904 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
10905 int opcode
, int rd
, int rn
, int rm
)
10907 /* 3-reg-different widening insns: 64 x 64 -> 128 */
10908 TCGv_i64 tcg_res
[2];
10911 tcg_res
[0] = tcg_temp_new_i64();
10912 tcg_res
[1] = tcg_temp_new_i64();
10914 /* Does this op do an adding accumulate, a subtracting accumulate,
10915 * or no accumulate at all?
10933 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10934 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10937 /* size == 2 means two 32x32->64 operations; this is worth special
10938 * casing because we can generally handle it inline.
10941 for (pass
= 0; pass
< 2; pass
++) {
10942 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10943 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10944 TCGv_i64 tcg_passres
;
10945 MemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
10947 int elt
= pass
+ is_q
* 2;
10949 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
10950 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
10953 tcg_passres
= tcg_res
[pass
];
10955 tcg_passres
= tcg_temp_new_i64();
10959 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10960 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10962 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10963 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10965 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10966 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10968 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
10969 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
10971 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
10972 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
10973 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
10975 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
10976 tcg_temp_free_i64(tcg_tmp1
);
10977 tcg_temp_free_i64(tcg_tmp2
);
10980 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10981 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10982 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10983 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10985 case 9: /* SQDMLAL, SQDMLAL2 */
10986 case 11: /* SQDMLSL, SQDMLSL2 */
10987 case 13: /* SQDMULL, SQDMULL2 */
10988 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10989 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10990 tcg_passres
, tcg_passres
);
10993 g_assert_not_reached();
10996 if (opcode
== 9 || opcode
== 11) {
10997 /* saturating accumulate ops */
10999 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
11001 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
11002 tcg_res
[pass
], tcg_passres
);
11003 } else if (accop
> 0) {
11004 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
11005 } else if (accop
< 0) {
11006 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
11010 tcg_temp_free_i64(tcg_passres
);
11013 tcg_temp_free_i64(tcg_op1
);
11014 tcg_temp_free_i64(tcg_op2
);
11017 /* size 0 or 1, generally helper functions */
11018 for (pass
= 0; pass
< 2; pass
++) {
11019 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11020 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11021 TCGv_i64 tcg_passres
;
11022 int elt
= pass
+ is_q
* 2;
11024 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
11025 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
11028 tcg_passres
= tcg_res
[pass
];
11030 tcg_passres
= tcg_temp_new_i64();
11034 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
11035 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
11037 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
11038 static NeonGenWidenFn
* const widenfns
[2][2] = {
11039 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
11040 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
11042 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
11044 widenfn(tcg_op2_64
, tcg_op2
);
11045 widenfn(tcg_passres
, tcg_op1
);
11046 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
11047 tcg_passres
, tcg_op2_64
);
11048 tcg_temp_free_i64(tcg_op2_64
);
11051 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
11052 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
11055 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
11057 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
11061 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
11063 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
11067 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
11068 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
11069 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
11072 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
11074 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
11078 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
11080 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
11084 case 9: /* SQDMLAL, SQDMLAL2 */
11085 case 11: /* SQDMLSL, SQDMLSL2 */
11086 case 13: /* SQDMULL, SQDMULL2 */
11088 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
11089 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
11090 tcg_passres
, tcg_passres
);
11093 g_assert_not_reached();
11095 tcg_temp_free_i32(tcg_op1
);
11096 tcg_temp_free_i32(tcg_op2
);
11099 if (opcode
== 9 || opcode
== 11) {
11100 /* saturating accumulate ops */
11102 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
11104 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
11108 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
11109 tcg_res
[pass
], tcg_passres
);
11111 tcg_temp_free_i64(tcg_passres
);
11116 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
11117 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
11118 tcg_temp_free_i64(tcg_res
[0]);
11119 tcg_temp_free_i64(tcg_res
[1]);
11122 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
11123 int opcode
, int rd
, int rn
, int rm
)
11125 TCGv_i64 tcg_res
[2];
11126 int part
= is_q
? 2 : 0;
11129 for (pass
= 0; pass
< 2; pass
++) {
11130 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11131 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11132 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
11133 static NeonGenWidenFn
* const widenfns
[3][2] = {
11134 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
11135 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
11136 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
11138 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
11140 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11141 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
11142 widenfn(tcg_op2_wide
, tcg_op2
);
11143 tcg_temp_free_i32(tcg_op2
);
11144 tcg_res
[pass
] = tcg_temp_new_i64();
11145 gen_neon_addl(size
, (opcode
== 3),
11146 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
11147 tcg_temp_free_i64(tcg_op1
);
11148 tcg_temp_free_i64(tcg_op2_wide
);
11151 for (pass
= 0; pass
< 2; pass
++) {
11152 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11153 tcg_temp_free_i64(tcg_res
[pass
]);
11157 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
11159 tcg_gen_addi_i64(in
, in
, 1U << 31);
11160 tcg_gen_extrh_i64_i32(res
, in
);
11163 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
11164 int opcode
, int rd
, int rn
, int rm
)
11166 TCGv_i32 tcg_res
[2];
11167 int part
= is_q
? 2 : 0;
11170 for (pass
= 0; pass
< 2; pass
++) {
11171 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11172 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11173 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
11174 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
11175 { gen_helper_neon_narrow_high_u8
,
11176 gen_helper_neon_narrow_round_high_u8
},
11177 { gen_helper_neon_narrow_high_u16
,
11178 gen_helper_neon_narrow_round_high_u16
},
11179 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
11181 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
11183 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11184 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
11186 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
11188 tcg_temp_free_i64(tcg_op1
);
11189 tcg_temp_free_i64(tcg_op2
);
11191 tcg_res
[pass
] = tcg_temp_new_i32();
11192 gennarrow(tcg_res
[pass
], tcg_wideres
);
11193 tcg_temp_free_i64(tcg_wideres
);
11196 for (pass
= 0; pass
< 2; pass
++) {
11197 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
11198 tcg_temp_free_i32(tcg_res
[pass
]);
11200 clear_vec_high(s
, is_q
, rd
);
11203 /* AdvSIMD three different
11204 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
11205 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
11206 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
11207 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
11209 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
11211 /* Instructions in this group fall into three basic classes
11212 * (in each case with the operation working on each element in
11213 * the input vectors):
11214 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
11216 * (2) wide 64 x 128 -> 128
11217 * (3) narrowing 128 x 128 -> 64
11218 * Here we do initial decode, catch unallocated cases and
11219 * dispatch to separate functions for each class.
11221 int is_q
= extract32(insn
, 30, 1);
11222 int is_u
= extract32(insn
, 29, 1);
11223 int size
= extract32(insn
, 22, 2);
11224 int opcode
= extract32(insn
, 12, 4);
11225 int rm
= extract32(insn
, 16, 5);
11226 int rn
= extract32(insn
, 5, 5);
11227 int rd
= extract32(insn
, 0, 5);
11230 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
11231 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
11232 /* 64 x 128 -> 128 */
11234 unallocated_encoding(s
);
11237 if (!fp_access_check(s
)) {
11240 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
11242 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
11243 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
11244 /* 128 x 128 -> 64 */
11246 unallocated_encoding(s
);
11249 if (!fp_access_check(s
)) {
11252 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
11254 case 14: /* PMULL, PMULL2 */
11256 unallocated_encoding(s
);
11260 case 0: /* PMULL.P8 */
11261 if (!fp_access_check(s
)) {
11264 /* The Q field specifies lo/hi half input for this insn. */
11265 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, is_q
,
11266 gen_helper_neon_pmull_h
);
11269 case 3: /* PMULL.P64 */
11270 if (!dc_isar_feature(aa64_pmull
, s
)) {
11271 unallocated_encoding(s
);
11274 if (!fp_access_check(s
)) {
11277 /* The Q field specifies lo/hi half input for this insn. */
11278 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, is_q
,
11279 gen_helper_gvec_pmull_q
);
11283 unallocated_encoding(s
);
11287 case 9: /* SQDMLAL, SQDMLAL2 */
11288 case 11: /* SQDMLSL, SQDMLSL2 */
11289 case 13: /* SQDMULL, SQDMULL2 */
11290 if (is_u
|| size
== 0) {
11291 unallocated_encoding(s
);
11295 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
11296 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
11297 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
11298 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
11299 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
11300 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
11301 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
11302 /* 64 x 64 -> 128 */
11304 unallocated_encoding(s
);
11307 if (!fp_access_check(s
)) {
11311 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
11314 /* opcode 15 not allocated */
11315 unallocated_encoding(s
);
11320 /* Logic op (opcode == 3) subgroup of C3.6.16. */
11321 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
11323 int rd
= extract32(insn
, 0, 5);
11324 int rn
= extract32(insn
, 5, 5);
11325 int rm
= extract32(insn
, 16, 5);
11326 int size
= extract32(insn
, 22, 2);
11327 bool is_u
= extract32(insn
, 29, 1);
11328 bool is_q
= extract32(insn
, 30, 1);
11330 if (!fp_access_check(s
)) {
11334 switch (size
+ 4 * is_u
) {
11336 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_and
, 0);
11339 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_andc
, 0);
11342 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_or
, 0);
11345 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_orc
, 0);
11348 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_xor
, 0);
11351 case 5: /* BSL bitwise select */
11352 gen_gvec_fn4(s
, is_q
, rd
, rd
, rn
, rm
, tcg_gen_gvec_bitsel
, 0);
11354 case 6: /* BIT, bitwise insert if true */
11355 gen_gvec_fn4(s
, is_q
, rd
, rm
, rn
, rd
, tcg_gen_gvec_bitsel
, 0);
11357 case 7: /* BIF, bitwise insert if false */
11358 gen_gvec_fn4(s
, is_q
, rd
, rm
, rd
, rn
, tcg_gen_gvec_bitsel
, 0);
11362 g_assert_not_reached();
11366 /* Pairwise op subgroup of C3.6.16.
11368 * This is called directly or via the handle_3same_float for float pairwise
11369 * operations where the opcode and size are calculated differently.
11371 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
11372 int size
, int rn
, int rm
, int rd
)
11377 /* Floating point operations need fpst */
11378 if (opcode
>= 0x58) {
11379 fpst
= fpstatus_ptr(FPST_FPCR
);
11384 if (!fp_access_check(s
)) {
11388 /* These operations work on the concatenated rm:rn, with each pair of
11389 * adjacent elements being operated on to produce an element in the result.
11392 TCGv_i64 tcg_res
[2];
11394 for (pass
= 0; pass
< 2; pass
++) {
11395 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11396 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11397 int passreg
= (pass
== 0) ? rn
: rm
;
11399 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
11400 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
11401 tcg_res
[pass
] = tcg_temp_new_i64();
11404 case 0x17: /* ADDP */
11405 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11407 case 0x58: /* FMAXNMP */
11408 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11410 case 0x5a: /* FADDP */
11411 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11413 case 0x5e: /* FMAXP */
11414 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11416 case 0x78: /* FMINNMP */
11417 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11419 case 0x7e: /* FMINP */
11420 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11423 g_assert_not_reached();
11426 tcg_temp_free_i64(tcg_op1
);
11427 tcg_temp_free_i64(tcg_op2
);
11430 for (pass
= 0; pass
< 2; pass
++) {
11431 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11432 tcg_temp_free_i64(tcg_res
[pass
]);
11435 int maxpass
= is_q
? 4 : 2;
11436 TCGv_i32 tcg_res
[4];
11438 for (pass
= 0; pass
< maxpass
; pass
++) {
11439 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11440 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11441 NeonGenTwoOpFn
*genfn
= NULL
;
11442 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
11443 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
11445 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
11446 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
11447 tcg_res
[pass
] = tcg_temp_new_i32();
11450 case 0x17: /* ADDP */
11452 static NeonGenTwoOpFn
* const fns
[3] = {
11453 gen_helper_neon_padd_u8
,
11454 gen_helper_neon_padd_u16
,
11460 case 0x14: /* SMAXP, UMAXP */
11462 static NeonGenTwoOpFn
* const fns
[3][2] = {
11463 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
11464 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
11465 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
11467 genfn
= fns
[size
][u
];
11470 case 0x15: /* SMINP, UMINP */
11472 static NeonGenTwoOpFn
* const fns
[3][2] = {
11473 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
11474 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
11475 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
11477 genfn
= fns
[size
][u
];
11480 /* The FP operations are all on single floats (32 bit) */
11481 case 0x58: /* FMAXNMP */
11482 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11484 case 0x5a: /* FADDP */
11485 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11487 case 0x5e: /* FMAXP */
11488 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11490 case 0x78: /* FMINNMP */
11491 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11493 case 0x7e: /* FMINP */
11494 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11497 g_assert_not_reached();
11500 /* FP ops called directly, otherwise call now */
11502 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11505 tcg_temp_free_i32(tcg_op1
);
11506 tcg_temp_free_i32(tcg_op2
);
11509 for (pass
= 0; pass
< maxpass
; pass
++) {
11510 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
11511 tcg_temp_free_i32(tcg_res
[pass
]);
11513 clear_vec_high(s
, is_q
, rd
);
11517 tcg_temp_free_ptr(fpst
);
11521 /* Floating point op subgroup of C3.6.16. */
11522 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
11524 /* For floating point ops, the U, size[1] and opcode bits
11525 * together indicate the operation. size[0] indicates single
11528 int fpopcode
= extract32(insn
, 11, 5)
11529 | (extract32(insn
, 23, 1) << 5)
11530 | (extract32(insn
, 29, 1) << 6);
11531 int is_q
= extract32(insn
, 30, 1);
11532 int size
= extract32(insn
, 22, 1);
11533 int rm
= extract32(insn
, 16, 5);
11534 int rn
= extract32(insn
, 5, 5);
11535 int rd
= extract32(insn
, 0, 5);
11537 int datasize
= is_q
? 128 : 64;
11538 int esize
= 32 << size
;
11539 int elements
= datasize
/ esize
;
11541 if (size
== 1 && !is_q
) {
11542 unallocated_encoding(s
);
11546 switch (fpopcode
) {
11547 case 0x58: /* FMAXNMP */
11548 case 0x5a: /* FADDP */
11549 case 0x5e: /* FMAXP */
11550 case 0x78: /* FMINNMP */
11551 case 0x7e: /* FMINP */
11552 if (size
&& !is_q
) {
11553 unallocated_encoding(s
);
11556 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
11559 case 0x1b: /* FMULX */
11560 case 0x1f: /* FRECPS */
11561 case 0x3f: /* FRSQRTS */
11562 case 0x5d: /* FACGE */
11563 case 0x7d: /* FACGT */
11564 case 0x19: /* FMLA */
11565 case 0x39: /* FMLS */
11566 case 0x18: /* FMAXNM */
11567 case 0x1a: /* FADD */
11568 case 0x1c: /* FCMEQ */
11569 case 0x1e: /* FMAX */
11570 case 0x38: /* FMINNM */
11571 case 0x3a: /* FSUB */
11572 case 0x3e: /* FMIN */
11573 case 0x5b: /* FMUL */
11574 case 0x5c: /* FCMGE */
11575 case 0x5f: /* FDIV */
11576 case 0x7a: /* FABD */
11577 case 0x7c: /* FCMGT */
11578 if (!fp_access_check(s
)) {
11581 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
11584 case 0x1d: /* FMLAL */
11585 case 0x3d: /* FMLSL */
11586 case 0x59: /* FMLAL2 */
11587 case 0x79: /* FMLSL2 */
11588 if (size
& 1 || !dc_isar_feature(aa64_fhm
, s
)) {
11589 unallocated_encoding(s
);
11592 if (fp_access_check(s
)) {
11593 int is_s
= extract32(insn
, 23, 1);
11594 int is_2
= extract32(insn
, 29, 1);
11595 int data
= (is_2
<< 1) | is_s
;
11596 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
11597 vec_full_reg_offset(s
, rn
),
11598 vec_full_reg_offset(s
, rm
), cpu_env
,
11599 is_q
? 16 : 8, vec_full_reg_size(s
),
11600 data
, gen_helper_gvec_fmlal_a64
);
11605 unallocated_encoding(s
);
11610 /* Integer op subgroup of C3.6.16. */
11611 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
11613 int is_q
= extract32(insn
, 30, 1);
11614 int u
= extract32(insn
, 29, 1);
11615 int size
= extract32(insn
, 22, 2);
11616 int opcode
= extract32(insn
, 11, 5);
11617 int rm
= extract32(insn
, 16, 5);
11618 int rn
= extract32(insn
, 5, 5);
11619 int rd
= extract32(insn
, 0, 5);
11624 case 0x13: /* MUL, PMUL */
11625 if (u
&& size
!= 0) {
11626 unallocated_encoding(s
);
11630 case 0x0: /* SHADD, UHADD */
11631 case 0x2: /* SRHADD, URHADD */
11632 case 0x4: /* SHSUB, UHSUB */
11633 case 0xc: /* SMAX, UMAX */
11634 case 0xd: /* SMIN, UMIN */
11635 case 0xe: /* SABD, UABD */
11636 case 0xf: /* SABA, UABA */
11637 case 0x12: /* MLA, MLS */
11639 unallocated_encoding(s
);
11643 case 0x16: /* SQDMULH, SQRDMULH */
11644 if (size
== 0 || size
== 3) {
11645 unallocated_encoding(s
);
11650 if (size
== 3 && !is_q
) {
11651 unallocated_encoding(s
);
11657 if (!fp_access_check(s
)) {
11662 case 0x01: /* SQADD, UQADD */
11664 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uqadd_qc
, size
);
11666 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqadd_qc
, size
);
11669 case 0x05: /* SQSUB, UQSUB */
11671 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uqsub_qc
, size
);
11673 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqsub_qc
, size
);
11676 case 0x08: /* SSHL, USHL */
11678 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_ushl
, size
);
11680 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sshl
, size
);
11683 case 0x0c: /* SMAX, UMAX */
11685 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umax
, size
);
11687 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smax
, size
);
11690 case 0x0d: /* SMIN, UMIN */
11692 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umin
, size
);
11694 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smin
, size
);
11697 case 0xe: /* SABD, UABD */
11699 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uabd
, size
);
11701 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sabd
, size
);
11704 case 0xf: /* SABA, UABA */
11706 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_uaba
, size
);
11708 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_saba
, size
);
11711 case 0x10: /* ADD, SUB */
11713 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_sub
, size
);
11715 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_add
, size
);
11718 case 0x13: /* MUL, PMUL */
11719 if (!u
) { /* MUL */
11720 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_mul
, size
);
11721 } else { /* PMUL */
11722 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, 0, gen_helper_gvec_pmul_b
);
11725 case 0x12: /* MLA, MLS */
11727 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_mls
, size
);
11729 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_mla
, size
);
11732 case 0x16: /* SQDMULH, SQRDMULH */
11734 static gen_helper_gvec_3_ptr
* const fns
[2][2] = {
11735 { gen_helper_neon_sqdmulh_h
, gen_helper_neon_sqrdmulh_h
},
11736 { gen_helper_neon_sqdmulh_s
, gen_helper_neon_sqrdmulh_s
},
11738 gen_gvec_op3_qc(s
, is_q
, rd
, rn
, rm
, fns
[size
- 1][u
]);
11742 if (!u
) { /* CMTST */
11743 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_cmtst
, size
);
11747 cond
= TCG_COND_EQ
;
11749 case 0x06: /* CMGT, CMHI */
11750 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
11752 case 0x07: /* CMGE, CMHS */
11753 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
11755 tcg_gen_gvec_cmp(cond
, size
, vec_full_reg_offset(s
, rd
),
11756 vec_full_reg_offset(s
, rn
),
11757 vec_full_reg_offset(s
, rm
),
11758 is_q
? 16 : 8, vec_full_reg_size(s
));
11764 for (pass
= 0; pass
< 2; pass
++) {
11765 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11766 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11767 TCGv_i64 tcg_res
= tcg_temp_new_i64();
11769 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11770 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
11772 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
11774 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
11776 tcg_temp_free_i64(tcg_res
);
11777 tcg_temp_free_i64(tcg_op1
);
11778 tcg_temp_free_i64(tcg_op2
);
11781 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
11782 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11783 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11784 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11785 NeonGenTwoOpFn
*genfn
= NULL
;
11786 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
11788 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
11789 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
11792 case 0x0: /* SHADD, UHADD */
11794 static NeonGenTwoOpFn
* const fns
[3][2] = {
11795 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
11796 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
11797 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
11799 genfn
= fns
[size
][u
];
11802 case 0x2: /* SRHADD, URHADD */
11804 static NeonGenTwoOpFn
* const fns
[3][2] = {
11805 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
11806 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
11807 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
11809 genfn
= fns
[size
][u
];
11812 case 0x4: /* SHSUB, UHSUB */
11814 static NeonGenTwoOpFn
* const fns
[3][2] = {
11815 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
11816 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
11817 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
11819 genfn
= fns
[size
][u
];
11822 case 0x9: /* SQSHL, UQSHL */
11824 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11825 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
11826 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
11827 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
11829 genenvfn
= fns
[size
][u
];
11832 case 0xa: /* SRSHL, URSHL */
11834 static NeonGenTwoOpFn
* const fns
[3][2] = {
11835 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
11836 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
11837 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
11839 genfn
= fns
[size
][u
];
11842 case 0xb: /* SQRSHL, UQRSHL */
11844 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11845 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
11846 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
11847 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
11849 genenvfn
= fns
[size
][u
];
11853 g_assert_not_reached();
11857 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
11859 genfn(tcg_res
, tcg_op1
, tcg_op2
);
11862 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
11864 tcg_temp_free_i32(tcg_res
);
11865 tcg_temp_free_i32(tcg_op1
);
11866 tcg_temp_free_i32(tcg_op2
);
11869 clear_vec_high(s
, is_q
, rd
);
11872 /* AdvSIMD three same
11873 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11874 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11875 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11876 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11878 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
11880 int opcode
= extract32(insn
, 11, 5);
11883 case 0x3: /* logic ops */
11884 disas_simd_3same_logic(s
, insn
);
11886 case 0x17: /* ADDP */
11887 case 0x14: /* SMAXP, UMAXP */
11888 case 0x15: /* SMINP, UMINP */
11890 /* Pairwise operations */
11891 int is_q
= extract32(insn
, 30, 1);
11892 int u
= extract32(insn
, 29, 1);
11893 int size
= extract32(insn
, 22, 2);
11894 int rm
= extract32(insn
, 16, 5);
11895 int rn
= extract32(insn
, 5, 5);
11896 int rd
= extract32(insn
, 0, 5);
11897 if (opcode
== 0x17) {
11898 if (u
|| (size
== 3 && !is_q
)) {
11899 unallocated_encoding(s
);
11904 unallocated_encoding(s
);
11908 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
11911 case 0x18 ... 0x31:
11912 /* floating point ops, sz[1] and U are part of opcode */
11913 disas_simd_3same_float(s
, insn
);
11916 disas_simd_3same_int(s
, insn
);
11922 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11924 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11925 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11926 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11927 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11929 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11930 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11933 static void disas_simd_three_reg_same_fp16(DisasContext
*s
, uint32_t insn
)
11935 int opcode
= extract32(insn
, 11, 3);
11936 int u
= extract32(insn
, 29, 1);
11937 int a
= extract32(insn
, 23, 1);
11938 int is_q
= extract32(insn
, 30, 1);
11939 int rm
= extract32(insn
, 16, 5);
11940 int rn
= extract32(insn
, 5, 5);
11941 int rd
= extract32(insn
, 0, 5);
11943 * For these floating point ops, the U, a and opcode bits
11944 * together indicate the operation.
11946 int fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
11947 int datasize
= is_q
? 128 : 64;
11948 int elements
= datasize
/ 16;
11953 switch (fpopcode
) {
11954 case 0x0: /* FMAXNM */
11955 case 0x1: /* FMLA */
11956 case 0x2: /* FADD */
11957 case 0x3: /* FMULX */
11958 case 0x4: /* FCMEQ */
11959 case 0x6: /* FMAX */
11960 case 0x7: /* FRECPS */
11961 case 0x8: /* FMINNM */
11962 case 0x9: /* FMLS */
11963 case 0xa: /* FSUB */
11964 case 0xe: /* FMIN */
11965 case 0xf: /* FRSQRTS */
11966 case 0x13: /* FMUL */
11967 case 0x14: /* FCMGE */
11968 case 0x15: /* FACGE */
11969 case 0x17: /* FDIV */
11970 case 0x1a: /* FABD */
11971 case 0x1c: /* FCMGT */
11972 case 0x1d: /* FACGT */
11975 case 0x10: /* FMAXNMP */
11976 case 0x12: /* FADDP */
11977 case 0x16: /* FMAXP */
11978 case 0x18: /* FMINNMP */
11979 case 0x1e: /* FMINP */
11983 unallocated_encoding(s
);
11987 if (!dc_isar_feature(aa64_fp16
, s
)) {
11988 unallocated_encoding(s
);
11992 if (!fp_access_check(s
)) {
11996 fpst
= fpstatus_ptr(FPST_FPCR_F16
);
11999 int maxpass
= is_q
? 8 : 4;
12000 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
12001 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
12002 TCGv_i32 tcg_res
[8];
12004 for (pass
= 0; pass
< maxpass
; pass
++) {
12005 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
12006 int passelt
= (pass
<< 1) & (maxpass
- 1);
12008 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_16
);
12009 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_16
);
12010 tcg_res
[pass
] = tcg_temp_new_i32();
12012 switch (fpopcode
) {
12013 case 0x10: /* FMAXNMP */
12014 gen_helper_advsimd_maxnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
12017 case 0x12: /* FADDP */
12018 gen_helper_advsimd_addh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
12020 case 0x16: /* FMAXP */
12021 gen_helper_advsimd_maxh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
12023 case 0x18: /* FMINNMP */
12024 gen_helper_advsimd_minnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
12027 case 0x1e: /* FMINP */
12028 gen_helper_advsimd_minh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
12031 g_assert_not_reached();
12035 for (pass
= 0; pass
< maxpass
; pass
++) {
12036 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_16
);
12037 tcg_temp_free_i32(tcg_res
[pass
]);
12040 tcg_temp_free_i32(tcg_op1
);
12041 tcg_temp_free_i32(tcg_op2
);
12044 for (pass
= 0; pass
< elements
; pass
++) {
12045 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
12046 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
12047 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12049 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_16
);
12050 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_16
);
12052 switch (fpopcode
) {
12053 case 0x0: /* FMAXNM */
12054 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12056 case 0x1: /* FMLA */
12057 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12058 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
12061 case 0x2: /* FADD */
12062 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12064 case 0x3: /* FMULX */
12065 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12067 case 0x4: /* FCMEQ */
12068 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12070 case 0x6: /* FMAX */
12071 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12073 case 0x7: /* FRECPS */
12074 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12076 case 0x8: /* FMINNM */
12077 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12079 case 0x9: /* FMLS */
12080 /* As usual for ARM, separate negation for fused multiply-add */
12081 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
12082 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12083 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
12086 case 0xa: /* FSUB */
12087 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12089 case 0xe: /* FMIN */
12090 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12092 case 0xf: /* FRSQRTS */
12093 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12095 case 0x13: /* FMUL */
12096 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12098 case 0x14: /* FCMGE */
12099 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12101 case 0x15: /* FACGE */
12102 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12104 case 0x17: /* FDIV */
12105 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12107 case 0x1a: /* FABD */
12108 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12109 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
12111 case 0x1c: /* FCMGT */
12112 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12114 case 0x1d: /* FACGT */
12115 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
12118 g_assert_not_reached();
12121 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12122 tcg_temp_free_i32(tcg_res
);
12123 tcg_temp_free_i32(tcg_op1
);
12124 tcg_temp_free_i32(tcg_op2
);
12128 tcg_temp_free_ptr(fpst
);
12130 clear_vec_high(s
, is_q
, rd
);
12133 /* AdvSIMD three same extra
12134 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
12135 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
12136 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
12137 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
12139 static void disas_simd_three_reg_same_extra(DisasContext
*s
, uint32_t insn
)
12141 int rd
= extract32(insn
, 0, 5);
12142 int rn
= extract32(insn
, 5, 5);
12143 int opcode
= extract32(insn
, 11, 4);
12144 int rm
= extract32(insn
, 16, 5);
12145 int size
= extract32(insn
, 22, 2);
12146 bool u
= extract32(insn
, 29, 1);
12147 bool is_q
= extract32(insn
, 30, 1);
12151 switch (u
* 16 + opcode
) {
12152 case 0x10: /* SQRDMLAH (vector) */
12153 case 0x11: /* SQRDMLSH (vector) */
12154 if (size
!= 1 && size
!= 2) {
12155 unallocated_encoding(s
);
12158 feature
= dc_isar_feature(aa64_rdm
, s
);
12160 case 0x02: /* SDOT (vector) */
12161 case 0x12: /* UDOT (vector) */
12162 if (size
!= MO_32
) {
12163 unallocated_encoding(s
);
12166 feature
= dc_isar_feature(aa64_dp
, s
);
12168 case 0x03: /* USDOT */
12169 if (size
!= MO_32
) {
12170 unallocated_encoding(s
);
12173 feature
= dc_isar_feature(aa64_i8mm
, s
);
12175 case 0x04: /* SMMLA */
12176 case 0x14: /* UMMLA */
12177 case 0x05: /* USMMLA */
12178 if (!is_q
|| size
!= MO_32
) {
12179 unallocated_encoding(s
);
12182 feature
= dc_isar_feature(aa64_i8mm
, s
);
12184 case 0x18: /* FCMLA, #0 */
12185 case 0x19: /* FCMLA, #90 */
12186 case 0x1a: /* FCMLA, #180 */
12187 case 0x1b: /* FCMLA, #270 */
12188 case 0x1c: /* FCADD, #90 */
12189 case 0x1e: /* FCADD, #270 */
12191 || (size
== 1 && !dc_isar_feature(aa64_fp16
, s
))
12192 || (size
== 3 && !is_q
)) {
12193 unallocated_encoding(s
);
12196 feature
= dc_isar_feature(aa64_fcma
, s
);
12198 case 0x1d: /* BFMMLA */
12199 if (size
!= MO_16
|| !is_q
) {
12200 unallocated_encoding(s
);
12203 feature
= dc_isar_feature(aa64_bf16
, s
);
12207 case 1: /* BFDOT */
12208 case 3: /* BFMLAL{B,T} */
12209 feature
= dc_isar_feature(aa64_bf16
, s
);
12212 unallocated_encoding(s
);
12217 unallocated_encoding(s
);
12221 unallocated_encoding(s
);
12224 if (!fp_access_check(s
)) {
12229 case 0x0: /* SQRDMLAH (vector) */
12230 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqrdmlah_qc
, size
);
12233 case 0x1: /* SQRDMLSH (vector) */
12234 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, gen_gvec_sqrdmlsh_qc
, size
);
12237 case 0x2: /* SDOT / UDOT */
12238 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, 0,
12239 u
? gen_helper_gvec_udot_b
: gen_helper_gvec_sdot_b
);
12242 case 0x3: /* USDOT */
12243 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, 0, gen_helper_gvec_usdot_b
);
12246 case 0x04: /* SMMLA, UMMLA */
12247 gen_gvec_op4_ool(s
, 1, rd
, rn
, rm
, rd
, 0,
12248 u
? gen_helper_gvec_ummla_b
12249 : gen_helper_gvec_smmla_b
);
12251 case 0x05: /* USMMLA */
12252 gen_gvec_op4_ool(s
, 1, rd
, rn
, rm
, rd
, 0, gen_helper_gvec_usmmla_b
);
12255 case 0x8: /* FCMLA, #0 */
12256 case 0x9: /* FCMLA, #90 */
12257 case 0xa: /* FCMLA, #180 */
12258 case 0xb: /* FCMLA, #270 */
12259 rot
= extract32(opcode
, 0, 2);
12262 gen_gvec_op4_fpst(s
, is_q
, rd
, rn
, rm
, rd
, true, rot
,
12263 gen_helper_gvec_fcmlah
);
12266 gen_gvec_op4_fpst(s
, is_q
, rd
, rn
, rm
, rd
, false, rot
,
12267 gen_helper_gvec_fcmlas
);
12270 gen_gvec_op4_fpst(s
, is_q
, rd
, rn
, rm
, rd
, false, rot
,
12271 gen_helper_gvec_fcmlad
);
12274 g_assert_not_reached();
12278 case 0xc: /* FCADD, #90 */
12279 case 0xe: /* FCADD, #270 */
12280 rot
= extract32(opcode
, 1, 1);
12283 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
12284 gen_helper_gvec_fcaddh
);
12287 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
12288 gen_helper_gvec_fcadds
);
12291 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
12292 gen_helper_gvec_fcaddd
);
12295 g_assert_not_reached();
12299 case 0xd: /* BFMMLA */
12300 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, 0, gen_helper_gvec_bfmmla
);
12304 case 1: /* BFDOT */
12305 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, 0, gen_helper_gvec_bfdot
);
12307 case 3: /* BFMLAL{B,T} */
12308 gen_gvec_op4_fpst(s
, 1, rd
, rn
, rm
, rd
, false, is_q
,
12309 gen_helper_gvec_bfmlal
);
12312 g_assert_not_reached();
12317 g_assert_not_reached();
12321 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
12322 int size
, int rn
, int rd
)
12324 /* Handle 2-reg-misc ops which are widening (so each size element
12325 * in the source becomes a 2*size element in the destination.
12326 * The only instruction like this is FCVTL.
12331 /* 32 -> 64 bit fp conversion */
12332 TCGv_i64 tcg_res
[2];
12333 int srcelt
= is_q
? 2 : 0;
12335 for (pass
= 0; pass
< 2; pass
++) {
12336 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12337 tcg_res
[pass
] = tcg_temp_new_i64();
12339 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
12340 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
12341 tcg_temp_free_i32(tcg_op
);
12343 for (pass
= 0; pass
< 2; pass
++) {
12344 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
12345 tcg_temp_free_i64(tcg_res
[pass
]);
12348 /* 16 -> 32 bit fp conversion */
12349 int srcelt
= is_q
? 4 : 0;
12350 TCGv_i32 tcg_res
[4];
12351 TCGv_ptr fpst
= fpstatus_ptr(FPST_FPCR
);
12352 TCGv_i32 ahp
= get_ahp_flag();
12354 for (pass
= 0; pass
< 4; pass
++) {
12355 tcg_res
[pass
] = tcg_temp_new_i32();
12357 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
12358 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
12361 for (pass
= 0; pass
< 4; pass
++) {
12362 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
12363 tcg_temp_free_i32(tcg_res
[pass
]);
12366 tcg_temp_free_ptr(fpst
);
12367 tcg_temp_free_i32(ahp
);
12371 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
12372 bool is_q
, int size
, int rn
, int rd
)
12374 int op
= (opcode
<< 1) | u
;
12375 int opsz
= op
+ size
;
12376 int grp_size
= 3 - opsz
;
12377 int dsize
= is_q
? 128 : 64;
12381 unallocated_encoding(s
);
12385 if (!fp_access_check(s
)) {
12390 /* Special case bytes, use bswap op on each group of elements */
12391 int groups
= dsize
/ (8 << grp_size
);
12393 for (i
= 0; i
< groups
; i
++) {
12394 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
12396 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
12397 switch (grp_size
) {
12399 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
, TCG_BSWAP_IZ
);
12402 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
, TCG_BSWAP_IZ
);
12405 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
12408 g_assert_not_reached();
12410 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
12411 tcg_temp_free_i64(tcg_tmp
);
12413 clear_vec_high(s
, is_q
, rd
);
12415 int revmask
= (1 << grp_size
) - 1;
12416 int esize
= 8 << size
;
12417 int elements
= dsize
/ esize
;
12418 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
12419 TCGv_i64 tcg_rd
= tcg_const_i64(0);
12420 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
12422 for (i
= 0; i
< elements
; i
++) {
12423 int e_rev
= (i
& 0xf) ^ revmask
;
12424 int off
= e_rev
* esize
;
12425 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
12427 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
12428 tcg_rn
, off
- 64, esize
);
12430 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
12433 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
12434 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
12436 tcg_temp_free_i64(tcg_rd_hi
);
12437 tcg_temp_free_i64(tcg_rd
);
12438 tcg_temp_free_i64(tcg_rn
);
12442 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
12443 bool is_q
, int size
, int rn
, int rd
)
12445 /* Implement the pairwise operations from 2-misc:
12446 * SADDLP, UADDLP, SADALP, UADALP.
12447 * These all add pairs of elements in the input to produce a
12448 * double-width result element in the output (possibly accumulating).
12450 bool accum
= (opcode
== 0x6);
12451 int maxpass
= is_q
? 2 : 1;
12453 TCGv_i64 tcg_res
[2];
12456 /* 32 + 32 -> 64 op */
12457 MemOp memop
= size
+ (u
? 0 : MO_SIGN
);
12459 for (pass
= 0; pass
< maxpass
; pass
++) {
12460 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
12461 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
12463 tcg_res
[pass
] = tcg_temp_new_i64();
12465 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
12466 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
12467 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
12469 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
12470 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
12473 tcg_temp_free_i64(tcg_op1
);
12474 tcg_temp_free_i64(tcg_op2
);
12477 for (pass
= 0; pass
< maxpass
; pass
++) {
12478 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12479 NeonGenOne64OpFn
*genfn
;
12480 static NeonGenOne64OpFn
* const fns
[2][2] = {
12481 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
12482 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
12485 genfn
= fns
[size
][u
];
12487 tcg_res
[pass
] = tcg_temp_new_i64();
12489 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12490 genfn(tcg_res
[pass
], tcg_op
);
12493 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
12495 gen_helper_neon_addl_u16(tcg_res
[pass
],
12496 tcg_res
[pass
], tcg_op
);
12498 gen_helper_neon_addl_u32(tcg_res
[pass
],
12499 tcg_res
[pass
], tcg_op
);
12502 tcg_temp_free_i64(tcg_op
);
12506 tcg_res
[1] = tcg_constant_i64(0);
12508 for (pass
= 0; pass
< 2; pass
++) {
12509 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
12510 tcg_temp_free_i64(tcg_res
[pass
]);
12514 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
12516 /* Implement SHLL and SHLL2 */
12518 int part
= is_q
? 2 : 0;
12519 TCGv_i64 tcg_res
[2];
12521 for (pass
= 0; pass
< 2; pass
++) {
12522 static NeonGenWidenFn
* const widenfns
[3] = {
12523 gen_helper_neon_widen_u8
,
12524 gen_helper_neon_widen_u16
,
12525 tcg_gen_extu_i32_i64
,
12527 NeonGenWidenFn
*widenfn
= widenfns
[size
];
12528 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12530 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
12531 tcg_res
[pass
] = tcg_temp_new_i64();
12532 widenfn(tcg_res
[pass
], tcg_op
);
12533 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
12535 tcg_temp_free_i32(tcg_op
);
12538 for (pass
= 0; pass
< 2; pass
++) {
12539 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
12540 tcg_temp_free_i64(tcg_res
[pass
]);
12544 /* AdvSIMD two reg misc
12545 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
12546 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
12547 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
12548 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
12550 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
12552 int size
= extract32(insn
, 22, 2);
12553 int opcode
= extract32(insn
, 12, 5);
12554 bool u
= extract32(insn
, 29, 1);
12555 bool is_q
= extract32(insn
, 30, 1);
12556 int rn
= extract32(insn
, 5, 5);
12557 int rd
= extract32(insn
, 0, 5);
12558 bool need_fpstatus
= false;
12559 bool need_rmode
= false;
12561 TCGv_i32 tcg_rmode
;
12562 TCGv_ptr tcg_fpstatus
;
12565 case 0x0: /* REV64, REV32 */
12566 case 0x1: /* REV16 */
12567 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
12569 case 0x5: /* CNT, NOT, RBIT */
12570 if (u
&& size
== 0) {
12573 } else if (u
&& size
== 1) {
12576 } else if (!u
&& size
== 0) {
12580 unallocated_encoding(s
);
12582 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
12583 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
12585 unallocated_encoding(s
);
12588 if (!fp_access_check(s
)) {
12592 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
12594 case 0x4: /* CLS, CLZ */
12596 unallocated_encoding(s
);
12600 case 0x2: /* SADDLP, UADDLP */
12601 case 0x6: /* SADALP, UADALP */
12603 unallocated_encoding(s
);
12606 if (!fp_access_check(s
)) {
12609 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
12611 case 0x13: /* SHLL, SHLL2 */
12612 if (u
== 0 || size
== 3) {
12613 unallocated_encoding(s
);
12616 if (!fp_access_check(s
)) {
12619 handle_shll(s
, is_q
, size
, rn
, rd
);
12621 case 0xa: /* CMLT */
12623 unallocated_encoding(s
);
12627 case 0x8: /* CMGT, CMGE */
12628 case 0x9: /* CMEQ, CMLE */
12629 case 0xb: /* ABS, NEG */
12630 if (size
== 3 && !is_q
) {
12631 unallocated_encoding(s
);
12635 case 0x3: /* SUQADD, USQADD */
12636 if (size
== 3 && !is_q
) {
12637 unallocated_encoding(s
);
12640 if (!fp_access_check(s
)) {
12643 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
12645 case 0x7: /* SQABS, SQNEG */
12646 if (size
== 3 && !is_q
) {
12647 unallocated_encoding(s
);
12652 case 0x16 ... 0x1f:
12654 /* Floating point: U, size[1] and opcode indicate operation;
12655 * size[0] indicates single or double precision.
12657 int is_double
= extract32(size
, 0, 1);
12658 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
12659 size
= is_double
? 3 : 2;
12661 case 0x2f: /* FABS */
12662 case 0x6f: /* FNEG */
12663 if (size
== 3 && !is_q
) {
12664 unallocated_encoding(s
);
12668 case 0x1d: /* SCVTF */
12669 case 0x5d: /* UCVTF */
12671 bool is_signed
= (opcode
== 0x1d) ? true : false;
12672 int elements
= is_double
? 2 : is_q
? 4 : 2;
12673 if (is_double
&& !is_q
) {
12674 unallocated_encoding(s
);
12677 if (!fp_access_check(s
)) {
12680 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
12683 case 0x2c: /* FCMGT (zero) */
12684 case 0x2d: /* FCMEQ (zero) */
12685 case 0x2e: /* FCMLT (zero) */
12686 case 0x6c: /* FCMGE (zero) */
12687 case 0x6d: /* FCMLE (zero) */
12688 if (size
== 3 && !is_q
) {
12689 unallocated_encoding(s
);
12692 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
12694 case 0x7f: /* FSQRT */
12695 if (size
== 3 && !is_q
) {
12696 unallocated_encoding(s
);
12700 case 0x1a: /* FCVTNS */
12701 case 0x1b: /* FCVTMS */
12702 case 0x3a: /* FCVTPS */
12703 case 0x3b: /* FCVTZS */
12704 case 0x5a: /* FCVTNU */
12705 case 0x5b: /* FCVTMU */
12706 case 0x7a: /* FCVTPU */
12707 case 0x7b: /* FCVTZU */
12708 need_fpstatus
= true;
12710 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12711 if (size
== 3 && !is_q
) {
12712 unallocated_encoding(s
);
12716 case 0x5c: /* FCVTAU */
12717 case 0x1c: /* FCVTAS */
12718 need_fpstatus
= true;
12720 rmode
= FPROUNDING_TIEAWAY
;
12721 if (size
== 3 && !is_q
) {
12722 unallocated_encoding(s
);
12726 case 0x3c: /* URECPE */
12728 unallocated_encoding(s
);
12732 case 0x3d: /* FRECPE */
12733 case 0x7d: /* FRSQRTE */
12734 if (size
== 3 && !is_q
) {
12735 unallocated_encoding(s
);
12738 if (!fp_access_check(s
)) {
12741 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
12743 case 0x56: /* FCVTXN, FCVTXN2 */
12745 unallocated_encoding(s
);
12749 case 0x16: /* FCVTN, FCVTN2 */
12750 /* handle_2misc_narrow does a 2*size -> size operation, but these
12751 * instructions encode the source size rather than dest size.
12753 if (!fp_access_check(s
)) {
12756 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
12758 case 0x36: /* BFCVTN, BFCVTN2 */
12759 if (!dc_isar_feature(aa64_bf16
, s
) || size
!= 2) {
12760 unallocated_encoding(s
);
12763 if (!fp_access_check(s
)) {
12766 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
12768 case 0x17: /* FCVTL, FCVTL2 */
12769 if (!fp_access_check(s
)) {
12772 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
12774 case 0x18: /* FRINTN */
12775 case 0x19: /* FRINTM */
12776 case 0x38: /* FRINTP */
12777 case 0x39: /* FRINTZ */
12779 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12781 case 0x59: /* FRINTX */
12782 case 0x79: /* FRINTI */
12783 need_fpstatus
= true;
12784 if (size
== 3 && !is_q
) {
12785 unallocated_encoding(s
);
12789 case 0x58: /* FRINTA */
12791 rmode
= FPROUNDING_TIEAWAY
;
12792 need_fpstatus
= true;
12793 if (size
== 3 && !is_q
) {
12794 unallocated_encoding(s
);
12798 case 0x7c: /* URSQRTE */
12800 unallocated_encoding(s
);
12804 case 0x1e: /* FRINT32Z */
12805 case 0x1f: /* FRINT64Z */
12807 rmode
= FPROUNDING_ZERO
;
12809 case 0x5e: /* FRINT32X */
12810 case 0x5f: /* FRINT64X */
12811 need_fpstatus
= true;
12812 if ((size
== 3 && !is_q
) || !dc_isar_feature(aa64_frint
, s
)) {
12813 unallocated_encoding(s
);
12818 unallocated_encoding(s
);
12824 unallocated_encoding(s
);
12828 if (!fp_access_check(s
)) {
12832 if (need_fpstatus
|| need_rmode
) {
12833 tcg_fpstatus
= fpstatus_ptr(FPST_FPCR
);
12835 tcg_fpstatus
= NULL
;
12838 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12839 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12846 if (u
&& size
== 0) { /* NOT */
12847 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_not
, 0);
12851 case 0x8: /* CMGT, CMGE */
12853 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_cge0
, size
);
12855 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_cgt0
, size
);
12858 case 0x9: /* CMEQ, CMLE */
12860 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_cle0
, size
);
12862 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_ceq0
, size
);
12865 case 0xa: /* CMLT */
12866 gen_gvec_fn2(s
, is_q
, rd
, rn
, gen_gvec_clt0
, size
);
12869 if (u
) { /* ABS, NEG */
12870 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_neg
, size
);
12872 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_abs
, size
);
12878 /* All 64-bit element operations can be shared with scalar 2misc */
12881 /* Coverity claims (size == 3 && !is_q) has been eliminated
12882 * from all paths leading to here.
12884 tcg_debug_assert(is_q
);
12885 for (pass
= 0; pass
< 2; pass
++) {
12886 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12887 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12889 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12891 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
12892 tcg_rmode
, tcg_fpstatus
);
12894 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12896 tcg_temp_free_i64(tcg_res
);
12897 tcg_temp_free_i64(tcg_op
);
12902 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
12903 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12904 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12906 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
12909 /* Special cases for 32 bit elements */
12911 case 0x4: /* CLS */
12913 tcg_gen_clzi_i32(tcg_res
, tcg_op
, 32);
12915 tcg_gen_clrsb_i32(tcg_res
, tcg_op
);
12918 case 0x7: /* SQABS, SQNEG */
12920 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
12922 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
12925 case 0x2f: /* FABS */
12926 gen_helper_vfp_abss(tcg_res
, tcg_op
);
12928 case 0x6f: /* FNEG */
12929 gen_helper_vfp_negs(tcg_res
, tcg_op
);
12931 case 0x7f: /* FSQRT */
12932 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
12934 case 0x1a: /* FCVTNS */
12935 case 0x1b: /* FCVTMS */
12936 case 0x1c: /* FCVTAS */
12937 case 0x3a: /* FCVTPS */
12938 case 0x3b: /* FCVTZS */
12939 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
12940 tcg_constant_i32(0), tcg_fpstatus
);
12942 case 0x5a: /* FCVTNU */
12943 case 0x5b: /* FCVTMU */
12944 case 0x5c: /* FCVTAU */
12945 case 0x7a: /* FCVTPU */
12946 case 0x7b: /* FCVTZU */
12947 gen_helper_vfp_touls(tcg_res
, tcg_op
,
12948 tcg_constant_i32(0), tcg_fpstatus
);
12950 case 0x18: /* FRINTN */
12951 case 0x19: /* FRINTM */
12952 case 0x38: /* FRINTP */
12953 case 0x39: /* FRINTZ */
12954 case 0x58: /* FRINTA */
12955 case 0x79: /* FRINTI */
12956 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
12958 case 0x59: /* FRINTX */
12959 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12961 case 0x7c: /* URSQRTE */
12962 gen_helper_rsqrte_u32(tcg_res
, tcg_op
);
12964 case 0x1e: /* FRINT32Z */
12965 case 0x5e: /* FRINT32X */
12966 gen_helper_frint32_s(tcg_res
, tcg_op
, tcg_fpstatus
);
12968 case 0x1f: /* FRINT64Z */
12969 case 0x5f: /* FRINT64X */
12970 gen_helper_frint64_s(tcg_res
, tcg_op
, tcg_fpstatus
);
12973 g_assert_not_reached();
12976 /* Use helpers for 8 and 16 bit elements */
12978 case 0x5: /* CNT, RBIT */
12979 /* For these two insns size is part of the opcode specifier
12980 * (handled earlier); they always operate on byte elements.
12983 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
12985 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
12988 case 0x7: /* SQABS, SQNEG */
12990 NeonGenOneOpEnvFn
*genfn
;
12991 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
12992 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
12993 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
12995 genfn
= fns
[size
][u
];
12996 genfn(tcg_res
, cpu_env
, tcg_op
);
12999 case 0x4: /* CLS, CLZ */
13002 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
13004 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
13008 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
13010 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
13015 g_assert_not_reached();
13019 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
13021 tcg_temp_free_i32(tcg_res
);
13022 tcg_temp_free_i32(tcg_op
);
13025 clear_vec_high(s
, is_q
, rd
);
13028 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
13029 tcg_temp_free_i32(tcg_rmode
);
13031 if (need_fpstatus
) {
13032 tcg_temp_free_ptr(tcg_fpstatus
);
13036 /* AdvSIMD [scalar] two register miscellaneous (FP16)
13038 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
13039 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
13040 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
13041 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
13042 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
13043 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
13045 * This actually covers two groups where scalar access is governed by
13046 * bit 28. A bunch of the instructions (float to integral) only exist
13047 * in the vector form and are un-allocated for the scalar decode. Also
13048 * in the scalar decode Q is always 1.
13050 static void disas_simd_two_reg_misc_fp16(DisasContext
*s
, uint32_t insn
)
13052 int fpop
, opcode
, a
, u
;
13056 bool only_in_vector
= false;
13059 TCGv_i32 tcg_rmode
= NULL
;
13060 TCGv_ptr tcg_fpstatus
= NULL
;
13061 bool need_rmode
= false;
13062 bool need_fpst
= true;
13065 if (!dc_isar_feature(aa64_fp16
, s
)) {
13066 unallocated_encoding(s
);
13070 rd
= extract32(insn
, 0, 5);
13071 rn
= extract32(insn
, 5, 5);
13073 a
= extract32(insn
, 23, 1);
13074 u
= extract32(insn
, 29, 1);
13075 is_scalar
= extract32(insn
, 28, 1);
13076 is_q
= extract32(insn
, 30, 1);
13078 opcode
= extract32(insn
, 12, 5);
13079 fpop
= deposit32(opcode
, 5, 1, a
);
13080 fpop
= deposit32(fpop
, 6, 1, u
);
13083 case 0x1d: /* SCVTF */
13084 case 0x5d: /* UCVTF */
13091 elements
= (is_q
? 8 : 4);
13094 if (!fp_access_check(s
)) {
13097 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !u
, 0, MO_16
);
13101 case 0x2c: /* FCMGT (zero) */
13102 case 0x2d: /* FCMEQ (zero) */
13103 case 0x2e: /* FCMLT (zero) */
13104 case 0x6c: /* FCMGE (zero) */
13105 case 0x6d: /* FCMLE (zero) */
13106 handle_2misc_fcmp_zero(s
, fpop
, is_scalar
, 0, is_q
, MO_16
, rn
, rd
);
13108 case 0x3d: /* FRECPE */
13109 case 0x3f: /* FRECPX */
13111 case 0x18: /* FRINTN */
13113 only_in_vector
= true;
13114 rmode
= FPROUNDING_TIEEVEN
;
13116 case 0x19: /* FRINTM */
13118 only_in_vector
= true;
13119 rmode
= FPROUNDING_NEGINF
;
13121 case 0x38: /* FRINTP */
13123 only_in_vector
= true;
13124 rmode
= FPROUNDING_POSINF
;
13126 case 0x39: /* FRINTZ */
13128 only_in_vector
= true;
13129 rmode
= FPROUNDING_ZERO
;
13131 case 0x58: /* FRINTA */
13133 only_in_vector
= true;
13134 rmode
= FPROUNDING_TIEAWAY
;
13136 case 0x59: /* FRINTX */
13137 case 0x79: /* FRINTI */
13138 only_in_vector
= true;
13139 /* current rounding mode */
13141 case 0x1a: /* FCVTNS */
13143 rmode
= FPROUNDING_TIEEVEN
;
13145 case 0x1b: /* FCVTMS */
13147 rmode
= FPROUNDING_NEGINF
;
13149 case 0x1c: /* FCVTAS */
13151 rmode
= FPROUNDING_TIEAWAY
;
13153 case 0x3a: /* FCVTPS */
13155 rmode
= FPROUNDING_POSINF
;
13157 case 0x3b: /* FCVTZS */
13159 rmode
= FPROUNDING_ZERO
;
13161 case 0x5a: /* FCVTNU */
13163 rmode
= FPROUNDING_TIEEVEN
;
13165 case 0x5b: /* FCVTMU */
13167 rmode
= FPROUNDING_NEGINF
;
13169 case 0x5c: /* FCVTAU */
13171 rmode
= FPROUNDING_TIEAWAY
;
13173 case 0x7a: /* FCVTPU */
13175 rmode
= FPROUNDING_POSINF
;
13177 case 0x7b: /* FCVTZU */
13179 rmode
= FPROUNDING_ZERO
;
13181 case 0x2f: /* FABS */
13182 case 0x6f: /* FNEG */
13185 case 0x7d: /* FRSQRTE */
13186 case 0x7f: /* FSQRT (vector) */
13189 unallocated_encoding(s
);
13194 /* Check additional constraints for the scalar encoding */
13197 unallocated_encoding(s
);
13200 /* FRINTxx is only in the vector form */
13201 if (only_in_vector
) {
13202 unallocated_encoding(s
);
13207 if (!fp_access_check(s
)) {
13211 if (need_rmode
|| need_fpst
) {
13212 tcg_fpstatus
= fpstatus_ptr(FPST_FPCR_F16
);
13216 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
13217 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
13221 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
13222 TCGv_i32 tcg_res
= tcg_temp_new_i32();
13225 case 0x1a: /* FCVTNS */
13226 case 0x1b: /* FCVTMS */
13227 case 0x1c: /* FCVTAS */
13228 case 0x3a: /* FCVTPS */
13229 case 0x3b: /* FCVTZS */
13230 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13232 case 0x3d: /* FRECPE */
13233 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13235 case 0x3f: /* FRECPX */
13236 gen_helper_frecpx_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13238 case 0x5a: /* FCVTNU */
13239 case 0x5b: /* FCVTMU */
13240 case 0x5c: /* FCVTAU */
13241 case 0x7a: /* FCVTPU */
13242 case 0x7b: /* FCVTZU */
13243 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13245 case 0x6f: /* FNEG */
13246 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
13248 case 0x7d: /* FRSQRTE */
13249 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13252 g_assert_not_reached();
13255 /* limit any sign extension going on */
13256 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0xffff);
13257 write_fp_sreg(s
, rd
, tcg_res
);
13259 tcg_temp_free_i32(tcg_res
);
13260 tcg_temp_free_i32(tcg_op
);
13262 for (pass
= 0; pass
< (is_q
? 8 : 4); pass
++) {
13263 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13264 TCGv_i32 tcg_res
= tcg_temp_new_i32();
13266 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_16
);
13269 case 0x1a: /* FCVTNS */
13270 case 0x1b: /* FCVTMS */
13271 case 0x1c: /* FCVTAS */
13272 case 0x3a: /* FCVTPS */
13273 case 0x3b: /* FCVTZS */
13274 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13276 case 0x3d: /* FRECPE */
13277 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13279 case 0x5a: /* FCVTNU */
13280 case 0x5b: /* FCVTMU */
13281 case 0x5c: /* FCVTAU */
13282 case 0x7a: /* FCVTPU */
13283 case 0x7b: /* FCVTZU */
13284 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13286 case 0x18: /* FRINTN */
13287 case 0x19: /* FRINTM */
13288 case 0x38: /* FRINTP */
13289 case 0x39: /* FRINTZ */
13290 case 0x58: /* FRINTA */
13291 case 0x79: /* FRINTI */
13292 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, tcg_fpstatus
);
13294 case 0x59: /* FRINTX */
13295 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
13297 case 0x2f: /* FABS */
13298 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
13300 case 0x6f: /* FNEG */
13301 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
13303 case 0x7d: /* FRSQRTE */
13304 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13306 case 0x7f: /* FSQRT */
13307 gen_helper_sqrt_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
13310 g_assert_not_reached();
13313 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
13315 tcg_temp_free_i32(tcg_res
);
13316 tcg_temp_free_i32(tcg_op
);
13319 clear_vec_high(s
, is_q
, rd
);
13323 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
13324 tcg_temp_free_i32(tcg_rmode
);
13327 if (tcg_fpstatus
) {
13328 tcg_temp_free_ptr(tcg_fpstatus
);
13332 /* AdvSIMD scalar x indexed element
13333 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
13334 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
13335 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
13336 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
13337 * AdvSIMD vector x indexed element
13338 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
13339 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
13340 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
13341 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
13343 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
13345 /* This encoding has two kinds of instruction:
13346 * normal, where we perform elt x idxelt => elt for each
13347 * element in the vector
13348 * long, where we perform elt x idxelt and generate a result of
13349 * double the width of the input element
13350 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
13352 bool is_scalar
= extract32(insn
, 28, 1);
13353 bool is_q
= extract32(insn
, 30, 1);
13354 bool u
= extract32(insn
, 29, 1);
13355 int size
= extract32(insn
, 22, 2);
13356 int l
= extract32(insn
, 21, 1);
13357 int m
= extract32(insn
, 20, 1);
13358 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
13359 int rm
= extract32(insn
, 16, 4);
13360 int opcode
= extract32(insn
, 12, 4);
13361 int h
= extract32(insn
, 11, 1);
13362 int rn
= extract32(insn
, 5, 5);
13363 int rd
= extract32(insn
, 0, 5);
13364 bool is_long
= false;
13366 bool is_fp16
= false;
13370 switch (16 * u
+ opcode
) {
13371 case 0x08: /* MUL */
13372 case 0x10: /* MLA */
13373 case 0x14: /* MLS */
13375 unallocated_encoding(s
);
13379 case 0x02: /* SMLAL, SMLAL2 */
13380 case 0x12: /* UMLAL, UMLAL2 */
13381 case 0x06: /* SMLSL, SMLSL2 */
13382 case 0x16: /* UMLSL, UMLSL2 */
13383 case 0x0a: /* SMULL, SMULL2 */
13384 case 0x1a: /* UMULL, UMULL2 */
13386 unallocated_encoding(s
);
13391 case 0x03: /* SQDMLAL, SQDMLAL2 */
13392 case 0x07: /* SQDMLSL, SQDMLSL2 */
13393 case 0x0b: /* SQDMULL, SQDMULL2 */
13396 case 0x0c: /* SQDMULH */
13397 case 0x0d: /* SQRDMULH */
13399 case 0x01: /* FMLA */
13400 case 0x05: /* FMLS */
13401 case 0x09: /* FMUL */
13402 case 0x19: /* FMULX */
13405 case 0x1d: /* SQRDMLAH */
13406 case 0x1f: /* SQRDMLSH */
13407 if (!dc_isar_feature(aa64_rdm
, s
)) {
13408 unallocated_encoding(s
);
13412 case 0x0e: /* SDOT */
13413 case 0x1e: /* UDOT */
13414 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_dp
, s
)) {
13415 unallocated_encoding(s
);
13421 case 0: /* SUDOT */
13422 case 2: /* USDOT */
13423 if (is_scalar
|| !dc_isar_feature(aa64_i8mm
, s
)) {
13424 unallocated_encoding(s
);
13429 case 1: /* BFDOT */
13430 if (is_scalar
|| !dc_isar_feature(aa64_bf16
, s
)) {
13431 unallocated_encoding(s
);
13436 case 3: /* BFMLAL{B,T} */
13437 if (is_scalar
|| !dc_isar_feature(aa64_bf16
, s
)) {
13438 unallocated_encoding(s
);
13441 /* can't set is_fp without other incorrect size checks */
13445 unallocated_encoding(s
);
13449 case 0x11: /* FCMLA #0 */
13450 case 0x13: /* FCMLA #90 */
13451 case 0x15: /* FCMLA #180 */
13452 case 0x17: /* FCMLA #270 */
13453 if (is_scalar
|| !dc_isar_feature(aa64_fcma
, s
)) {
13454 unallocated_encoding(s
);
13459 case 0x00: /* FMLAL */
13460 case 0x04: /* FMLSL */
13461 case 0x18: /* FMLAL2 */
13462 case 0x1c: /* FMLSL2 */
13463 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_fhm
, s
)) {
13464 unallocated_encoding(s
);
13468 /* is_fp, but we pass cpu_env not fp_status. */
13471 unallocated_encoding(s
);
13476 case 1: /* normal fp */
13477 /* convert insn encoded size to MemOp size */
13479 case 0: /* half-precision */
13483 case MO_32
: /* single precision */
13484 case MO_64
: /* double precision */
13487 unallocated_encoding(s
);
13492 case 2: /* complex fp */
13493 /* Each indexable element is a complex pair. */
13498 unallocated_encoding(s
);
13506 unallocated_encoding(s
);
13511 default: /* integer */
13515 unallocated_encoding(s
);
13520 if (is_fp16
&& !dc_isar_feature(aa64_fp16
, s
)) {
13521 unallocated_encoding(s
);
13525 /* Given MemOp size, adjust register and indexing. */
13528 index
= h
<< 2 | l
<< 1 | m
;
13531 index
= h
<< 1 | l
;
13536 unallocated_encoding(s
);
13543 g_assert_not_reached();
13546 if (!fp_access_check(s
)) {
13551 fpst
= fpstatus_ptr(is_fp16
? FPST_FPCR_F16
: FPST_FPCR
);
13556 switch (16 * u
+ opcode
) {
13557 case 0x0e: /* SDOT */
13558 case 0x1e: /* UDOT */
13559 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, index
,
13560 u
? gen_helper_gvec_udot_idx_b
13561 : gen_helper_gvec_sdot_idx_b
);
13564 switch (extract32(insn
, 22, 2)) {
13565 case 0: /* SUDOT */
13566 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, index
,
13567 gen_helper_gvec_sudot_idx_b
);
13569 case 1: /* BFDOT */
13570 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, index
,
13571 gen_helper_gvec_bfdot_idx
);
13573 case 2: /* USDOT */
13574 gen_gvec_op4_ool(s
, is_q
, rd
, rn
, rm
, rd
, index
,
13575 gen_helper_gvec_usdot_idx_b
);
13577 case 3: /* BFMLAL{B,T} */
13578 gen_gvec_op4_fpst(s
, 1, rd
, rn
, rm
, rd
, 0, (index
<< 1) | is_q
,
13579 gen_helper_gvec_bfmlal_idx
);
13582 g_assert_not_reached();
13583 case 0x11: /* FCMLA #0 */
13584 case 0x13: /* FCMLA #90 */
13585 case 0x15: /* FCMLA #180 */
13586 case 0x17: /* FCMLA #270 */
13588 int rot
= extract32(insn
, 13, 2);
13589 int data
= (index
<< 2) | rot
;
13590 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s
, rd
),
13591 vec_full_reg_offset(s
, rn
),
13592 vec_full_reg_offset(s
, rm
),
13593 vec_full_reg_offset(s
, rd
), fpst
,
13594 is_q
? 16 : 8, vec_full_reg_size(s
), data
,
13596 ? gen_helper_gvec_fcmlas_idx
13597 : gen_helper_gvec_fcmlah_idx
);
13598 tcg_temp_free_ptr(fpst
);
13602 case 0x00: /* FMLAL */
13603 case 0x04: /* FMLSL */
13604 case 0x18: /* FMLAL2 */
13605 case 0x1c: /* FMLSL2 */
13607 int is_s
= extract32(opcode
, 2, 1);
13609 int data
= (index
<< 2) | (is_2
<< 1) | is_s
;
13610 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
13611 vec_full_reg_offset(s
, rn
),
13612 vec_full_reg_offset(s
, rm
), cpu_env
,
13613 is_q
? 16 : 8, vec_full_reg_size(s
),
13614 data
, gen_helper_gvec_fmlal_idx_a64
);
13618 case 0x08: /* MUL */
13619 if (!is_long
&& !is_scalar
) {
13620 static gen_helper_gvec_3
* const fns
[3] = {
13621 gen_helper_gvec_mul_idx_h
,
13622 gen_helper_gvec_mul_idx_s
,
13623 gen_helper_gvec_mul_idx_d
,
13625 tcg_gen_gvec_3_ool(vec_full_reg_offset(s
, rd
),
13626 vec_full_reg_offset(s
, rn
),
13627 vec_full_reg_offset(s
, rm
),
13628 is_q
? 16 : 8, vec_full_reg_size(s
),
13629 index
, fns
[size
- 1]);
13634 case 0x10: /* MLA */
13635 if (!is_long
&& !is_scalar
) {
13636 static gen_helper_gvec_4
* const fns
[3] = {
13637 gen_helper_gvec_mla_idx_h
,
13638 gen_helper_gvec_mla_idx_s
,
13639 gen_helper_gvec_mla_idx_d
,
13641 tcg_gen_gvec_4_ool(vec_full_reg_offset(s
, rd
),
13642 vec_full_reg_offset(s
, rn
),
13643 vec_full_reg_offset(s
, rm
),
13644 vec_full_reg_offset(s
, rd
),
13645 is_q
? 16 : 8, vec_full_reg_size(s
),
13646 index
, fns
[size
- 1]);
13651 case 0x14: /* MLS */
13652 if (!is_long
&& !is_scalar
) {
13653 static gen_helper_gvec_4
* const fns
[3] = {
13654 gen_helper_gvec_mls_idx_h
,
13655 gen_helper_gvec_mls_idx_s
,
13656 gen_helper_gvec_mls_idx_d
,
13658 tcg_gen_gvec_4_ool(vec_full_reg_offset(s
, rd
),
13659 vec_full_reg_offset(s
, rn
),
13660 vec_full_reg_offset(s
, rm
),
13661 vec_full_reg_offset(s
, rd
),
13662 is_q
? 16 : 8, vec_full_reg_size(s
),
13663 index
, fns
[size
- 1]);
13670 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
13673 assert(is_fp
&& is_q
&& !is_long
);
13675 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
13677 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13678 TCGv_i64 tcg_op
= tcg_temp_new_i64();
13679 TCGv_i64 tcg_res
= tcg_temp_new_i64();
13681 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
13683 switch (16 * u
+ opcode
) {
13684 case 0x05: /* FMLS */
13685 /* As usual for ARM, separate negation for fused multiply-add */
13686 gen_helper_vfp_negd(tcg_op
, tcg_op
);
13688 case 0x01: /* FMLA */
13689 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
13690 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
13692 case 0x09: /* FMUL */
13693 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13695 case 0x19: /* FMULX */
13696 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13699 g_assert_not_reached();
13702 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
13703 tcg_temp_free_i64(tcg_op
);
13704 tcg_temp_free_i64(tcg_res
);
13707 tcg_temp_free_i64(tcg_idx
);
13708 clear_vec_high(s
, !is_scalar
, rd
);
13709 } else if (!is_long
) {
13710 /* 32 bit floating point, or 16 or 32 bit integer.
13711 * For the 16 bit scalar case we use the usual Neon helpers and
13712 * rely on the fact that 0 op 0 == 0 with no side effects.
13714 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13715 int pass
, maxpasses
;
13720 maxpasses
= is_q
? 4 : 2;
13723 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13725 if (size
== 1 && !is_scalar
) {
13726 /* The simplest way to handle the 16x16 indexed ops is to duplicate
13727 * the index into both halves of the 32 bit tcg_idx and then use
13728 * the usual Neon helpers.
13730 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13733 for (pass
= 0; pass
< maxpasses
; pass
++) {
13734 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13735 TCGv_i32 tcg_res
= tcg_temp_new_i32();
13737 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
13739 switch (16 * u
+ opcode
) {
13740 case 0x08: /* MUL */
13741 case 0x10: /* MLA */
13742 case 0x14: /* MLS */
13744 static NeonGenTwoOpFn
* const fns
[2][2] = {
13745 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
13746 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
13748 NeonGenTwoOpFn
*genfn
;
13749 bool is_sub
= opcode
== 0x4;
13752 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
13754 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
13756 if (opcode
== 0x8) {
13759 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
13760 genfn
= fns
[size
- 1][is_sub
];
13761 genfn(tcg_res
, tcg_op
, tcg_res
);
13764 case 0x05: /* FMLS */
13765 case 0x01: /* FMLA */
13766 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13767 is_scalar
? size
: MO_32
);
13770 if (opcode
== 0x5) {
13771 /* As usual for ARM, separate negation for fused
13773 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80008000);
13776 gen_helper_advsimd_muladdh(tcg_res
, tcg_op
, tcg_idx
,
13779 gen_helper_advsimd_muladd2h(tcg_res
, tcg_op
, tcg_idx
,
13784 if (opcode
== 0x5) {
13785 /* As usual for ARM, separate negation for
13786 * fused multiply-add */
13787 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80000000);
13789 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
,
13793 g_assert_not_reached();
13796 case 0x09: /* FMUL */
13800 gen_helper_advsimd_mulh(tcg_res
, tcg_op
,
13803 gen_helper_advsimd_mul2h(tcg_res
, tcg_op
,
13808 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13811 g_assert_not_reached();
13814 case 0x19: /* FMULX */
13818 gen_helper_advsimd_mulxh(tcg_res
, tcg_op
,
13821 gen_helper_advsimd_mulx2h(tcg_res
, tcg_op
,
13826 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13829 g_assert_not_reached();
13832 case 0x0c: /* SQDMULH */
13834 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
13837 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
13841 case 0x0d: /* SQRDMULH */
13843 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
13846 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
13850 case 0x1d: /* SQRDMLAH */
13851 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13852 is_scalar
? size
: MO_32
);
13854 gen_helper_neon_qrdmlah_s16(tcg_res
, cpu_env
,
13855 tcg_op
, tcg_idx
, tcg_res
);
13857 gen_helper_neon_qrdmlah_s32(tcg_res
, cpu_env
,
13858 tcg_op
, tcg_idx
, tcg_res
);
13861 case 0x1f: /* SQRDMLSH */
13862 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13863 is_scalar
? size
: MO_32
);
13865 gen_helper_neon_qrdmlsh_s16(tcg_res
, cpu_env
,
13866 tcg_op
, tcg_idx
, tcg_res
);
13868 gen_helper_neon_qrdmlsh_s32(tcg_res
, cpu_env
,
13869 tcg_op
, tcg_idx
, tcg_res
);
13873 g_assert_not_reached();
13877 write_fp_sreg(s
, rd
, tcg_res
);
13879 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
13882 tcg_temp_free_i32(tcg_op
);
13883 tcg_temp_free_i32(tcg_res
);
13886 tcg_temp_free_i32(tcg_idx
);
13887 clear_vec_high(s
, is_q
, rd
);
13889 /* long ops: 16x16->32 or 32x32->64 */
13890 TCGv_i64 tcg_res
[2];
13892 bool satop
= extract32(opcode
, 0, 1);
13893 MemOp memop
= MO_32
;
13900 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
13902 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
13904 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13905 TCGv_i64 tcg_op
= tcg_temp_new_i64();
13906 TCGv_i64 tcg_passres
;
13912 passelt
= pass
+ (is_q
* 2);
13915 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
13917 tcg_res
[pass
] = tcg_temp_new_i64();
13919 if (opcode
== 0xa || opcode
== 0xb) {
13920 /* Non-accumulating ops */
13921 tcg_passres
= tcg_res
[pass
];
13923 tcg_passres
= tcg_temp_new_i64();
13926 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
13927 tcg_temp_free_i64(tcg_op
);
13930 /* saturating, doubling */
13931 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
13932 tcg_passres
, tcg_passres
);
13935 if (opcode
== 0xa || opcode
== 0xb) {
13939 /* Accumulating op: handle accumulate step */
13940 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13943 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13944 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13946 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13947 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13949 case 0x7: /* SQDMLSL, SQDMLSL2 */
13950 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
13952 case 0x3: /* SQDMLAL, SQDMLAL2 */
13953 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
13958 g_assert_not_reached();
13960 tcg_temp_free_i64(tcg_passres
);
13962 tcg_temp_free_i64(tcg_idx
);
13964 clear_vec_high(s
, !is_scalar
, rd
);
13966 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13969 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13972 /* The simplest way to handle the 16x16 indexed ops is to
13973 * duplicate the index into both halves of the 32 bit tcg_idx
13974 * and then use the usual Neon helpers.
13976 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13979 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13980 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13981 TCGv_i64 tcg_passres
;
13984 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
13986 read_vec_element_i32(s
, tcg_op
, rn
,
13987 pass
+ (is_q
* 2), MO_32
);
13990 tcg_res
[pass
] = tcg_temp_new_i64();
13992 if (opcode
== 0xa || opcode
== 0xb) {
13993 /* Non-accumulating ops */
13994 tcg_passres
= tcg_res
[pass
];
13996 tcg_passres
= tcg_temp_new_i64();
13999 if (memop
& MO_SIGN
) {
14000 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
14002 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
14005 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
14006 tcg_passres
, tcg_passres
);
14008 tcg_temp_free_i32(tcg_op
);
14010 if (opcode
== 0xa || opcode
== 0xb) {
14014 /* Accumulating op: handle accumulate step */
14015 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
14018 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
14019 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
14022 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
14023 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
14026 case 0x7: /* SQDMLSL, SQDMLSL2 */
14027 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
14029 case 0x3: /* SQDMLAL, SQDMLAL2 */
14030 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
14035 g_assert_not_reached();
14037 tcg_temp_free_i64(tcg_passres
);
14039 tcg_temp_free_i32(tcg_idx
);
14042 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
14047 tcg_res
[1] = tcg_constant_i64(0);
14050 for (pass
= 0; pass
< 2; pass
++) {
14051 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
14052 tcg_temp_free_i64(tcg_res
[pass
]);
14057 tcg_temp_free_ptr(fpst
);
14062 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
14063 * +-----------------+------+-----------+--------+-----+------+------+
14064 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
14065 * +-----------------+------+-----------+--------+-----+------+------+
14067 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
14069 int size
= extract32(insn
, 22, 2);
14070 int opcode
= extract32(insn
, 12, 5);
14071 int rn
= extract32(insn
, 5, 5);
14072 int rd
= extract32(insn
, 0, 5);
14074 gen_helper_gvec_2
*genfn2
= NULL
;
14075 gen_helper_gvec_3
*genfn3
= NULL
;
14077 if (!dc_isar_feature(aa64_aes
, s
) || size
!= 0) {
14078 unallocated_encoding(s
);
14083 case 0x4: /* AESE */
14085 genfn3
= gen_helper_crypto_aese
;
14087 case 0x6: /* AESMC */
14089 genfn2
= gen_helper_crypto_aesmc
;
14091 case 0x5: /* AESD */
14093 genfn3
= gen_helper_crypto_aese
;
14095 case 0x7: /* AESIMC */
14097 genfn2
= gen_helper_crypto_aesmc
;
14100 unallocated_encoding(s
);
14104 if (!fp_access_check(s
)) {
14108 gen_gvec_op2_ool(s
, true, rd
, rn
, decrypt
, genfn2
);
14110 gen_gvec_op3_ool(s
, true, rd
, rd
, rn
, decrypt
, genfn3
);
14114 /* Crypto three-reg SHA
14115 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
14116 * +-----------------+------+---+------+---+--------+-----+------+------+
14117 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
14118 * +-----------------+------+---+------+---+--------+-----+------+------+
14120 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
14122 int size
= extract32(insn
, 22, 2);
14123 int opcode
= extract32(insn
, 12, 3);
14124 int rm
= extract32(insn
, 16, 5);
14125 int rn
= extract32(insn
, 5, 5);
14126 int rd
= extract32(insn
, 0, 5);
14127 gen_helper_gvec_3
*genfn
;
14131 unallocated_encoding(s
);
14136 case 0: /* SHA1C */
14137 genfn
= gen_helper_crypto_sha1c
;
14138 feature
= dc_isar_feature(aa64_sha1
, s
);
14140 case 1: /* SHA1P */
14141 genfn
= gen_helper_crypto_sha1p
;
14142 feature
= dc_isar_feature(aa64_sha1
, s
);
14144 case 2: /* SHA1M */
14145 genfn
= gen_helper_crypto_sha1m
;
14146 feature
= dc_isar_feature(aa64_sha1
, s
);
14148 case 3: /* SHA1SU0 */
14149 genfn
= gen_helper_crypto_sha1su0
;
14150 feature
= dc_isar_feature(aa64_sha1
, s
);
14152 case 4: /* SHA256H */
14153 genfn
= gen_helper_crypto_sha256h
;
14154 feature
= dc_isar_feature(aa64_sha256
, s
);
14156 case 5: /* SHA256H2 */
14157 genfn
= gen_helper_crypto_sha256h2
;
14158 feature
= dc_isar_feature(aa64_sha256
, s
);
14160 case 6: /* SHA256SU1 */
14161 genfn
= gen_helper_crypto_sha256su1
;
14162 feature
= dc_isar_feature(aa64_sha256
, s
);
14165 unallocated_encoding(s
);
14170 unallocated_encoding(s
);
14174 if (!fp_access_check(s
)) {
14177 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, 0, genfn
);
14180 /* Crypto two-reg SHA
14181 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
14182 * +-----------------+------+-----------+--------+-----+------+------+
14183 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
14184 * +-----------------+------+-----------+--------+-----+------+------+
14186 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
14188 int size
= extract32(insn
, 22, 2);
14189 int opcode
= extract32(insn
, 12, 5);
14190 int rn
= extract32(insn
, 5, 5);
14191 int rd
= extract32(insn
, 0, 5);
14192 gen_helper_gvec_2
*genfn
;
14196 unallocated_encoding(s
);
14201 case 0: /* SHA1H */
14202 feature
= dc_isar_feature(aa64_sha1
, s
);
14203 genfn
= gen_helper_crypto_sha1h
;
14205 case 1: /* SHA1SU1 */
14206 feature
= dc_isar_feature(aa64_sha1
, s
);
14207 genfn
= gen_helper_crypto_sha1su1
;
14209 case 2: /* SHA256SU0 */
14210 feature
= dc_isar_feature(aa64_sha256
, s
);
14211 genfn
= gen_helper_crypto_sha256su0
;
14214 unallocated_encoding(s
);
14219 unallocated_encoding(s
);
14223 if (!fp_access_check(s
)) {
14226 gen_gvec_op2_ool(s
, true, rd
, rn
, 0, genfn
);
14229 static void gen_rax1_i64(TCGv_i64 d
, TCGv_i64 n
, TCGv_i64 m
)
14231 tcg_gen_rotli_i64(d
, m
, 1);
14232 tcg_gen_xor_i64(d
, d
, n
);
14235 static void gen_rax1_vec(unsigned vece
, TCGv_vec d
, TCGv_vec n
, TCGv_vec m
)
14237 tcg_gen_rotli_vec(vece
, d
, m
, 1);
14238 tcg_gen_xor_vec(vece
, d
, d
, n
);
14241 void gen_gvec_rax1(unsigned vece
, uint32_t rd_ofs
, uint32_t rn_ofs
,
14242 uint32_t rm_ofs
, uint32_t opr_sz
, uint32_t max_sz
)
14244 static const TCGOpcode vecop_list
[] = { INDEX_op_rotli_vec
, 0 };
14245 static const GVecGen3 op
= {
14246 .fni8
= gen_rax1_i64
,
14247 .fniv
= gen_rax1_vec
,
14248 .opt_opc
= vecop_list
,
14249 .fno
= gen_helper_crypto_rax1
,
14252 tcg_gen_gvec_3(rd_ofs
, rn_ofs
, rm_ofs
, opr_sz
, max_sz
, &op
);
14255 /* Crypto three-reg SHA512
14256 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
14257 * +-----------------------+------+---+---+-----+--------+------+------+
14258 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
14259 * +-----------------------+------+---+---+-----+--------+------+------+
14261 static void disas_crypto_three_reg_sha512(DisasContext
*s
, uint32_t insn
)
14263 int opcode
= extract32(insn
, 10, 2);
14264 int o
= extract32(insn
, 14, 1);
14265 int rm
= extract32(insn
, 16, 5);
14266 int rn
= extract32(insn
, 5, 5);
14267 int rd
= extract32(insn
, 0, 5);
14269 gen_helper_gvec_3
*oolfn
= NULL
;
14270 GVecGen3Fn
*gvecfn
= NULL
;
14274 case 0: /* SHA512H */
14275 feature
= dc_isar_feature(aa64_sha512
, s
);
14276 oolfn
= gen_helper_crypto_sha512h
;
14278 case 1: /* SHA512H2 */
14279 feature
= dc_isar_feature(aa64_sha512
, s
);
14280 oolfn
= gen_helper_crypto_sha512h2
;
14282 case 2: /* SHA512SU1 */
14283 feature
= dc_isar_feature(aa64_sha512
, s
);
14284 oolfn
= gen_helper_crypto_sha512su1
;
14287 feature
= dc_isar_feature(aa64_sha3
, s
);
14288 gvecfn
= gen_gvec_rax1
;
14291 g_assert_not_reached();
14295 case 0: /* SM3PARTW1 */
14296 feature
= dc_isar_feature(aa64_sm3
, s
);
14297 oolfn
= gen_helper_crypto_sm3partw1
;
14299 case 1: /* SM3PARTW2 */
14300 feature
= dc_isar_feature(aa64_sm3
, s
);
14301 oolfn
= gen_helper_crypto_sm3partw2
;
14303 case 2: /* SM4EKEY */
14304 feature
= dc_isar_feature(aa64_sm4
, s
);
14305 oolfn
= gen_helper_crypto_sm4ekey
;
14308 unallocated_encoding(s
);
14314 unallocated_encoding(s
);
14318 if (!fp_access_check(s
)) {
14323 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, 0, oolfn
);
14325 gen_gvec_fn3(s
, true, rd
, rn
, rm
, gvecfn
, MO_64
);
14329 /* Crypto two-reg SHA512
14330 * 31 12 11 10 9 5 4 0
14331 * +-----------------------------------------+--------+------+------+
14332 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
14333 * +-----------------------------------------+--------+------+------+
14335 static void disas_crypto_two_reg_sha512(DisasContext
*s
, uint32_t insn
)
14337 int opcode
= extract32(insn
, 10, 2);
14338 int rn
= extract32(insn
, 5, 5);
14339 int rd
= extract32(insn
, 0, 5);
14343 case 0: /* SHA512SU0 */
14344 feature
= dc_isar_feature(aa64_sha512
, s
);
14347 feature
= dc_isar_feature(aa64_sm4
, s
);
14350 unallocated_encoding(s
);
14355 unallocated_encoding(s
);
14359 if (!fp_access_check(s
)) {
14364 case 0: /* SHA512SU0 */
14365 gen_gvec_op2_ool(s
, true, rd
, rn
, 0, gen_helper_crypto_sha512su0
);
14368 gen_gvec_op3_ool(s
, true, rd
, rd
, rn
, 0, gen_helper_crypto_sm4e
);
14371 g_assert_not_reached();
14375 /* Crypto four-register
14376 * 31 23 22 21 20 16 15 14 10 9 5 4 0
14377 * +-------------------+-----+------+---+------+------+------+
14378 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
14379 * +-------------------+-----+------+---+------+------+------+
14381 static void disas_crypto_four_reg(DisasContext
*s
, uint32_t insn
)
14383 int op0
= extract32(insn
, 21, 2);
14384 int rm
= extract32(insn
, 16, 5);
14385 int ra
= extract32(insn
, 10, 5);
14386 int rn
= extract32(insn
, 5, 5);
14387 int rd
= extract32(insn
, 0, 5);
14393 feature
= dc_isar_feature(aa64_sha3
, s
);
14395 case 2: /* SM3SS1 */
14396 feature
= dc_isar_feature(aa64_sm3
, s
);
14399 unallocated_encoding(s
);
14404 unallocated_encoding(s
);
14408 if (!fp_access_check(s
)) {
14413 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
[2];
14416 tcg_op1
= tcg_temp_new_i64();
14417 tcg_op2
= tcg_temp_new_i64();
14418 tcg_op3
= tcg_temp_new_i64();
14419 tcg_res
[0] = tcg_temp_new_i64();
14420 tcg_res
[1] = tcg_temp_new_i64();
14422 for (pass
= 0; pass
< 2; pass
++) {
14423 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
14424 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
14425 read_vec_element(s
, tcg_op3
, ra
, pass
, MO_64
);
14429 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
14432 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
14434 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
14436 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
14437 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
14439 tcg_temp_free_i64(tcg_op1
);
14440 tcg_temp_free_i64(tcg_op2
);
14441 tcg_temp_free_i64(tcg_op3
);
14442 tcg_temp_free_i64(tcg_res
[0]);
14443 tcg_temp_free_i64(tcg_res
[1]);
14445 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
, tcg_zero
;
14447 tcg_op1
= tcg_temp_new_i32();
14448 tcg_op2
= tcg_temp_new_i32();
14449 tcg_op3
= tcg_temp_new_i32();
14450 tcg_res
= tcg_temp_new_i32();
14451 tcg_zero
= tcg_constant_i32(0);
14453 read_vec_element_i32(s
, tcg_op1
, rn
, 3, MO_32
);
14454 read_vec_element_i32(s
, tcg_op2
, rm
, 3, MO_32
);
14455 read_vec_element_i32(s
, tcg_op3
, ra
, 3, MO_32
);
14457 tcg_gen_rotri_i32(tcg_res
, tcg_op1
, 20);
14458 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op2
);
14459 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op3
);
14460 tcg_gen_rotri_i32(tcg_res
, tcg_res
, 25);
14462 write_vec_element_i32(s
, tcg_zero
, rd
, 0, MO_32
);
14463 write_vec_element_i32(s
, tcg_zero
, rd
, 1, MO_32
);
14464 write_vec_element_i32(s
, tcg_zero
, rd
, 2, MO_32
);
14465 write_vec_element_i32(s
, tcg_res
, rd
, 3, MO_32
);
14467 tcg_temp_free_i32(tcg_op1
);
14468 tcg_temp_free_i32(tcg_op2
);
14469 tcg_temp_free_i32(tcg_op3
);
14470 tcg_temp_free_i32(tcg_res
);
14475 * 31 21 20 16 15 10 9 5 4 0
14476 * +-----------------------+------+--------+------+------+
14477 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
14478 * +-----------------------+------+--------+------+------+
14480 static void disas_crypto_xar(DisasContext
*s
, uint32_t insn
)
14482 int rm
= extract32(insn
, 16, 5);
14483 int imm6
= extract32(insn
, 10, 6);
14484 int rn
= extract32(insn
, 5, 5);
14485 int rd
= extract32(insn
, 0, 5);
14487 if (!dc_isar_feature(aa64_sha3
, s
)) {
14488 unallocated_encoding(s
);
14492 if (!fp_access_check(s
)) {
14496 gen_gvec_xar(MO_64
, vec_full_reg_offset(s
, rd
),
14497 vec_full_reg_offset(s
, rn
),
14498 vec_full_reg_offset(s
, rm
), imm6
, 16,
14499 vec_full_reg_size(s
));
14502 /* Crypto three-reg imm2
14503 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
14504 * +-----------------------+------+-----+------+--------+------+------+
14505 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
14506 * +-----------------------+------+-----+------+--------+------+------+
14508 static void disas_crypto_three_reg_imm2(DisasContext
*s
, uint32_t insn
)
14510 static gen_helper_gvec_3
* const fns
[4] = {
14511 gen_helper_crypto_sm3tt1a
, gen_helper_crypto_sm3tt1b
,
14512 gen_helper_crypto_sm3tt2a
, gen_helper_crypto_sm3tt2b
,
14514 int opcode
= extract32(insn
, 10, 2);
14515 int imm2
= extract32(insn
, 12, 2);
14516 int rm
= extract32(insn
, 16, 5);
14517 int rn
= extract32(insn
, 5, 5);
14518 int rd
= extract32(insn
, 0, 5);
14520 if (!dc_isar_feature(aa64_sm3
, s
)) {
14521 unallocated_encoding(s
);
14525 if (!fp_access_check(s
)) {
14529 gen_gvec_op3_ool(s
, true, rd
, rn
, rm
, imm2
, fns
[opcode
]);
14532 /* C3.6 Data processing - SIMD, inc Crypto
14534 * As the decode gets a little complex we are using a table based
14535 * approach for this part of the decode.
14537 static const AArch64DecodeTable data_proc_simd
[] = {
14538 /* pattern , mask , fn */
14539 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
14540 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra
},
14541 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
14542 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
14543 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
14544 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
14545 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
14546 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
14547 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
14548 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
14549 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
14550 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
14551 { 0x2e000000, 0xbf208400, disas_simd_ext
},
14552 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
14553 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra
},
14554 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
14555 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
14556 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
14557 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
14558 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
14559 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
14560 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
14561 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
14562 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
14563 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512
},
14564 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512
},
14565 { 0xce000000, 0xff808000, disas_crypto_four_reg
},
14566 { 0xce800000, 0xffe00000, disas_crypto_xar
},
14567 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2
},
14568 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16
},
14569 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16
},
14570 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16
},
14571 { 0x00000000, 0x00000000, NULL
}
14574 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
14576 /* Note that this is called with all non-FP cases from
14577 * table C3-6 so it must UNDEF for entries not specifically
14578 * allocated to instructions in that table.
14580 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
14584 unallocated_encoding(s
);
14588 /* C3.6 Data processing - SIMD and floating point */
14589 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
14591 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
14592 disas_data_proc_fp(s
, insn
);
14594 /* SIMD, including crypto */
14595 disas_data_proc_simd(s
, insn
);
14600 * Include the generated SME FA64 decoder.
14603 #include "decode-sme-fa64.c.inc"
14605 static bool trans_OK(DisasContext
*s
, arg_OK
*a
)
14610 static bool trans_FAIL(DisasContext
*s
, arg_OK
*a
)
14612 s
->is_nonstreaming
= true;
14618 * @env: The cpu environment
14619 * @s: The DisasContext
14621 * Return true if the page is guarded.
14623 static bool is_guarded_page(CPUARMState
*env
, DisasContext
*s
)
14625 uint64_t addr
= s
->base
.pc_first
;
14626 #ifdef CONFIG_USER_ONLY
14627 return page_get_flags(addr
) & PAGE_BTI
;
14629 CPUTLBEntryFull
*full
;
14631 int mmu_idx
= arm_to_core_mmu_idx(s
->mmu_idx
);
14635 * We test this immediately after reading an insn, which means
14636 * that the TLB entry must be present and valid, and thus this
14637 * access will never raise an exception.
14639 flags
= probe_access_full(env
, addr
, 0, MMU_INST_FETCH
, mmu_idx
,
14640 false, &host
, &full
, 0);
14641 assert(!(flags
& TLB_INVALID_MASK
));
14643 return full
->guarded
;
14648 * btype_destination_ok:
14649 * @insn: The instruction at the branch destination
14650 * @bt: SCTLR_ELx.BT
14651 * @btype: PSTATE.BTYPE, and is non-zero
14653 * On a guarded page, there are a limited number of insns
14654 * that may be present at the branch target:
14655 * - branch target identifiers,
14656 * - paciasp, pacibsp,
14659 * Anything else causes a Branch Target Exception.
14661 * Return true if the branch is compatible, false to raise BTITRAP.
14663 static bool btype_destination_ok(uint32_t insn
, bool bt
, int btype
)
14665 if ((insn
& 0xfffff01fu
) == 0xd503201fu
) {
14667 switch (extract32(insn
, 5, 7)) {
14668 case 0b011001: /* PACIASP */
14669 case 0b011011: /* PACIBSP */
14671 * If SCTLR_ELx.BT, then PACI*SP are not compatible
14672 * with btype == 3. Otherwise all btype are ok.
14674 return !bt
|| btype
!= 3;
14675 case 0b100000: /* BTI */
14676 /* Not compatible with any btype. */
14678 case 0b100010: /* BTI c */
14679 /* Not compatible with btype == 3 */
14681 case 0b100100: /* BTI j */
14682 /* Not compatible with btype == 2 */
14684 case 0b100110: /* BTI jc */
14685 /* Compatible with any btype. */
14689 switch (insn
& 0xffe0001fu
) {
14690 case 0xd4200000u
: /* BRK */
14691 case 0xd4400000u
: /* HLT */
14692 /* Give priority to the breakpoint exception. */
14699 static void aarch64_tr_init_disas_context(DisasContextBase
*dcbase
,
14702 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14703 CPUARMState
*env
= cpu
->env_ptr
;
14704 ARMCPU
*arm_cpu
= env_archcpu(env
);
14705 CPUARMTBFlags tb_flags
= arm_tbflags_from_tb(dc
->base
.tb
);
14706 int bound
, core_mmu_idx
;
14708 dc
->isar
= &arm_cpu
->isar
;
14710 dc
->pc_save
= dc
->base
.pc_first
;
14711 dc
->aarch64
= true;
14714 dc
->be_data
= EX_TBFLAG_ANY(tb_flags
, BE_DATA
) ? MO_BE
: MO_LE
;
14715 dc
->condexec_mask
= 0;
14716 dc
->condexec_cond
= 0;
14717 core_mmu_idx
= EX_TBFLAG_ANY(tb_flags
, MMUIDX
);
14718 dc
->mmu_idx
= core_to_aa64_mmu_idx(core_mmu_idx
);
14719 dc
->tbii
= EX_TBFLAG_A64(tb_flags
, TBII
);
14720 dc
->tbid
= EX_TBFLAG_A64(tb_flags
, TBID
);
14721 dc
->tcma
= EX_TBFLAG_A64(tb_flags
, TCMA
);
14722 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
14723 #if !defined(CONFIG_USER_ONLY)
14724 dc
->user
= (dc
->current_el
== 0);
14726 dc
->fp_excp_el
= EX_TBFLAG_ANY(tb_flags
, FPEXC_EL
);
14727 dc
->align_mem
= EX_TBFLAG_ANY(tb_flags
, ALIGN_MEM
);
14728 dc
->pstate_il
= EX_TBFLAG_ANY(tb_flags
, PSTATE__IL
);
14729 dc
->fgt_active
= EX_TBFLAG_ANY(tb_flags
, FGT_ACTIVE
);
14730 dc
->fgt_svc
= EX_TBFLAG_ANY(tb_flags
, FGT_SVC
);
14731 dc
->fgt_eret
= EX_TBFLAG_A64(tb_flags
, FGT_ERET
);
14732 dc
->sve_excp_el
= EX_TBFLAG_A64(tb_flags
, SVEEXC_EL
);
14733 dc
->sme_excp_el
= EX_TBFLAG_A64(tb_flags
, SMEEXC_EL
);
14734 dc
->vl
= (EX_TBFLAG_A64(tb_flags
, VL
) + 1) * 16;
14735 dc
->svl
= (EX_TBFLAG_A64(tb_flags
, SVL
) + 1) * 16;
14736 dc
->pauth_active
= EX_TBFLAG_A64(tb_flags
, PAUTH_ACTIVE
);
14737 dc
->bt
= EX_TBFLAG_A64(tb_flags
, BT
);
14738 dc
->btype
= EX_TBFLAG_A64(tb_flags
, BTYPE
);
14739 dc
->unpriv
= EX_TBFLAG_A64(tb_flags
, UNPRIV
);
14740 dc
->ata
= EX_TBFLAG_A64(tb_flags
, ATA
);
14741 dc
->mte_active
[0] = EX_TBFLAG_A64(tb_flags
, MTE_ACTIVE
);
14742 dc
->mte_active
[1] = EX_TBFLAG_A64(tb_flags
, MTE0_ACTIVE
);
14743 dc
->pstate_sm
= EX_TBFLAG_A64(tb_flags
, PSTATE_SM
);
14744 dc
->pstate_za
= EX_TBFLAG_A64(tb_flags
, PSTATE_ZA
);
14745 dc
->sme_trap_nonstreaming
= EX_TBFLAG_A64(tb_flags
, SME_TRAP_NONSTREAMING
);
14747 dc
->vec_stride
= 0;
14748 dc
->cp_regs
= arm_cpu
->cp_regs
;
14749 dc
->features
= env
->features
;
14750 dc
->dcz_blocksize
= arm_cpu
->dcz_blocksize
;
14752 #ifdef CONFIG_USER_ONLY
14753 /* In sve_probe_page, we assume TBI is enabled. */
14754 tcg_debug_assert(dc
->tbid
& 1);
14757 /* Single step state. The code-generation logic here is:
14759 * generate code with no special handling for single-stepping (except
14760 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
14761 * this happens anyway because those changes are all system register or
14763 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
14764 * emit code for one insn
14765 * emit code to clear PSTATE.SS
14766 * emit code to generate software step exception for completed step
14767 * end TB (as usual for having generated an exception)
14768 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
14769 * emit code to generate a software step exception
14772 dc
->ss_active
= EX_TBFLAG_ANY(tb_flags
, SS_ACTIVE
);
14773 dc
->pstate_ss
= EX_TBFLAG_ANY(tb_flags
, PSTATE__SS
);
14774 dc
->is_ldex
= false;
14776 /* Bound the number of insns to execute to those left on the page. */
14777 bound
= -(dc
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
14779 /* If architectural single step active, limit to 1. */
14780 if (dc
->ss_active
) {
14783 dc
->base
.max_insns
= MIN(dc
->base
.max_insns
, bound
);
14785 init_tmp_a64_array(dc
);
14788 static void aarch64_tr_tb_start(DisasContextBase
*db
, CPUState
*cpu
)
14792 static void aarch64_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
14794 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14795 target_ulong pc_arg
= dc
->base
.pc_next
;
14797 if (tb_cflags(dcbase
->tb
) & CF_PCREL
) {
14798 pc_arg
&= ~TARGET_PAGE_MASK
;
14800 tcg_gen_insn_start(pc_arg
, 0, 0);
14801 dc
->insn_start
= tcg_last_op();
14804 static void aarch64_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
14806 DisasContext
*s
= container_of(dcbase
, DisasContext
, base
);
14807 CPUARMState
*env
= cpu
->env_ptr
;
14808 uint64_t pc
= s
->base
.pc_next
;
14811 /* Singlestep exceptions have the highest priority. */
14812 if (s
->ss_active
&& !s
->pstate_ss
) {
14813 /* Singlestep state is Active-pending.
14814 * If we're in this state at the start of a TB then either
14815 * a) we just took an exception to an EL which is being debugged
14816 * and this is the first insn in the exception handler
14817 * b) debug exceptions were masked and we just unmasked them
14818 * without changing EL (eg by clearing PSTATE.D)
14819 * In either case we're going to take a swstep exception in the
14820 * "did not step an insn" case, and so the syndrome ISV and EX
14821 * bits should be zero.
14823 assert(s
->base
.num_insns
== 1);
14824 gen_swstep_exception(s
, 0, 0);
14825 s
->base
.is_jmp
= DISAS_NORETURN
;
14826 s
->base
.pc_next
= pc
+ 4;
14832 * PC alignment fault. This has priority over the instruction abort
14833 * that we would receive from a translation fault via arm_ldl_code.
14834 * This should only be possible after an indirect branch, at the
14837 assert(s
->base
.num_insns
== 1);
14838 gen_helper_exception_pc_alignment(cpu_env
, tcg_constant_tl(pc
));
14839 s
->base
.is_jmp
= DISAS_NORETURN
;
14840 s
->base
.pc_next
= QEMU_ALIGN_UP(pc
, 4);
14845 insn
= arm_ldl_code(env
, &s
->base
, pc
, s
->sctlr_b
);
14847 s
->base
.pc_next
= pc
+ 4;
14849 s
->fp_access_checked
= false;
14850 s
->sve_access_checked
= false;
14852 if (s
->pstate_il
) {
14854 * Illegal execution state. This has priority over BTI
14855 * exceptions, but comes after instruction abort exceptions.
14857 gen_exception_insn(s
, 0, EXCP_UDEF
, syn_illegalstate());
14861 if (dc_isar_feature(aa64_bti
, s
)) {
14862 if (s
->base
.num_insns
== 1) {
14864 * At the first insn of the TB, compute s->guarded_page.
14865 * We delayed computing this until successfully reading
14866 * the first insn of the TB, above. This (mostly) ensures
14867 * that the softmmu tlb entry has been populated, and the
14868 * page table GP bit is available.
14870 * Note that we need to compute this even if btype == 0,
14871 * because this value is used for BR instructions later
14872 * where ENV is not available.
14874 s
->guarded_page
= is_guarded_page(env
, s
);
14876 /* First insn can have btype set to non-zero. */
14877 tcg_debug_assert(s
->btype
>= 0);
14880 * Note that the Branch Target Exception has fairly high
14881 * priority -- below debugging exceptions but above most
14882 * everything else. This allows us to handle this now
14883 * instead of waiting until the insn is otherwise decoded.
14887 && !btype_destination_ok(insn
, s
->bt
, s
->btype
)) {
14888 gen_exception_insn(s
, 0, EXCP_UDEF
, syn_btitrap(s
->btype
));
14892 /* Not the first insn: btype must be 0. */
14893 tcg_debug_assert(s
->btype
== 0);
14897 s
->is_nonstreaming
= false;
14898 if (s
->sme_trap_nonstreaming
) {
14899 disas_sme_fa64(s
, insn
);
14902 switch (extract32(insn
, 25, 4)) {
14904 if (!extract32(insn
, 31, 1) || !disas_sme(s
, insn
)) {
14905 unallocated_encoding(s
);
14908 case 0x1: case 0x3: /* UNALLOCATED */
14909 unallocated_encoding(s
);
14912 if (!disas_sve(s
, insn
)) {
14913 unallocated_encoding(s
);
14916 case 0x8: case 0x9: /* Data processing - immediate */
14917 disas_data_proc_imm(s
, insn
);
14919 case 0xa: case 0xb: /* Branch, exception generation and system insns */
14920 disas_b_exc_sys(s
, insn
);
14925 case 0xe: /* Loads and stores */
14926 disas_ldst(s
, insn
);
14929 case 0xd: /* Data processing - register */
14930 disas_data_proc_reg(s
, insn
);
14933 case 0xf: /* Data processing - SIMD and floating point */
14934 disas_data_proc_simd_fp(s
, insn
);
14937 assert(FALSE
); /* all 15 cases should be handled above */
14941 /* if we allocated any temporaries, free them here */
14945 * After execution of most insns, btype is reset to 0.
14946 * Note that we set btype == -1 when the insn sets btype.
14948 if (s
->btype
> 0 && s
->base
.is_jmp
!= DISAS_NORETURN
) {
14953 static void aarch64_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
14955 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14957 if (unlikely(dc
->ss_active
)) {
14958 /* Note that this means single stepping WFI doesn't halt the CPU.
14959 * For conditional branch insns this is harmless unreachable code as
14960 * gen_goto_tb() has already handled emitting the debug exception
14961 * (and thus a tb-jump is not possible when singlestepping).
14963 switch (dc
->base
.is_jmp
) {
14965 gen_a64_update_pc(dc
, 4);
14969 gen_step_complete_exception(dc
);
14971 case DISAS_NORETURN
:
14975 switch (dc
->base
.is_jmp
) {
14977 case DISAS_TOO_MANY
:
14978 gen_goto_tb(dc
, 1, 4);
14981 case DISAS_UPDATE_EXIT
:
14982 gen_a64_update_pc(dc
, 4);
14985 tcg_gen_exit_tb(NULL
, 0);
14987 case DISAS_UPDATE_NOCHAIN
:
14988 gen_a64_update_pc(dc
, 4);
14991 tcg_gen_lookup_and_goto_ptr();
14993 case DISAS_NORETURN
:
14997 gen_a64_update_pc(dc
, 4);
14998 gen_helper_wfe(cpu_env
);
15001 gen_a64_update_pc(dc
, 4);
15002 gen_helper_yield(cpu_env
);
15006 * This is a special case because we don't want to just halt
15007 * the CPU if trying to debug across a WFI.
15009 gen_a64_update_pc(dc
, 4);
15010 gen_helper_wfi(cpu_env
, tcg_constant_i32(4));
15012 * The helper doesn't necessarily throw an exception, but we
15013 * must go back to the main loop to check for interrupts anyway.
15015 tcg_gen_exit_tb(NULL
, 0);
15021 static void aarch64_tr_disas_log(const DisasContextBase
*dcbase
,
15022 CPUState
*cpu
, FILE *logfile
)
15024 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
15026 fprintf(logfile
, "IN: %s\n", lookup_symbol(dc
->base
.pc_first
));
15027 target_disas(logfile
, cpu
, dc
->base
.pc_first
, dc
->base
.tb
->size
);
15030 const TranslatorOps aarch64_translator_ops
= {
15031 .init_disas_context
= aarch64_tr_init_disas_context
,
15032 .tb_start
= aarch64_tr_tb_start
,
15033 .insn_start
= aarch64_tr_insn_start
,
15034 .translate_insn
= aarch64_tr_translate_insn
,
15035 .tb_stop
= aarch64_tr_tb_stop
,
15036 .disas_log
= aarch64_tr_disas_log
,