4 * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
22 #include "exec/exec-all.h"
24 #include "tcg-op-gvec.h"
27 #include "translate.h"
28 #include "internals.h"
29 #include "qemu/host-utils.h"
31 #include "hw/semihosting/semihost.h"
32 #include "exec/gen-icount.h"
34 #include "exec/helper-proto.h"
35 #include "exec/helper-gen.h"
38 #include "trace-tcg.h"
39 #include "translate-a64.h"
40 #include "qemu/atomic128.h"
42 static TCGv_i64 cpu_X
[32];
43 static TCGv_i64 cpu_pc
;
45 /* Load/store exclusive handling */
46 static TCGv_i64 cpu_exclusive_high
;
48 static const char *regnames
[] = {
49 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
50 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
51 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
52 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
56 A64_SHIFT_TYPE_LSL
= 0,
57 A64_SHIFT_TYPE_LSR
= 1,
58 A64_SHIFT_TYPE_ASR
= 2,
59 A64_SHIFT_TYPE_ROR
= 3
62 /* Table based decoder typedefs - used when the relevant bits for decode
63 * are too awkwardly scattered across the instruction (eg SIMD).
65 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
67 typedef struct AArch64DecodeTable
{
70 AArch64DecodeFn
*disas_fn
;
73 /* Function prototype for gen_ functions for calling Neon helpers */
74 typedef void NeonGenOneOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
);
75 typedef void NeonGenTwoOpFn(TCGv_i32
, TCGv_i32
, TCGv_i32
);
76 typedef void NeonGenTwoOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
, TCGv_i32
);
77 typedef void NeonGenTwo64OpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
);
78 typedef void NeonGenTwo64OpEnvFn(TCGv_i64
, TCGv_ptr
, TCGv_i64
, TCGv_i64
);
79 typedef void NeonGenNarrowFn(TCGv_i32
, TCGv_i64
);
80 typedef void NeonGenNarrowEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i64
);
81 typedef void NeonGenWidenFn(TCGv_i64
, TCGv_i32
);
82 typedef void NeonGenTwoSingleOPFn(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
83 typedef void NeonGenTwoDoubleOPFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGv_ptr
);
84 typedef void NeonGenOneOpFn(TCGv_i64
, TCGv_i64
);
85 typedef void CryptoTwoOpFn(TCGv_ptr
, TCGv_ptr
);
86 typedef void CryptoThreeOpIntFn(TCGv_ptr
, TCGv_ptr
, TCGv_i32
);
87 typedef void CryptoThreeOpFn(TCGv_ptr
, TCGv_ptr
, TCGv_ptr
);
88 typedef void AtomicThreeOpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGArg
, TCGMemOp
);
90 /* initialize TCG globals. */
91 void a64_translate_init(void)
95 cpu_pc
= tcg_global_mem_new_i64(cpu_env
,
96 offsetof(CPUARMState
, pc
),
98 for (i
= 0; i
< 32; i
++) {
99 cpu_X
[i
] = tcg_global_mem_new_i64(cpu_env
,
100 offsetof(CPUARMState
, xregs
[i
]),
104 cpu_exclusive_high
= tcg_global_mem_new_i64(cpu_env
,
105 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
108 static inline int get_a64_user_mem_index(DisasContext
*s
)
110 /* Return the core mmu_idx to use for A64 "unprivileged load/store" insns:
111 * if EL1, access as if EL0; otherwise access at current EL
115 switch (s
->mmu_idx
) {
116 case ARMMMUIdx_S12NSE1
:
117 useridx
= ARMMMUIdx_S12NSE0
;
119 case ARMMMUIdx_S1SE1
:
120 useridx
= ARMMMUIdx_S1SE0
;
123 g_assert_not_reached();
125 useridx
= s
->mmu_idx
;
128 return arm_to_core_mmu_idx(useridx
);
131 static void reset_btype(DisasContext
*s
)
134 TCGv_i32 zero
= tcg_const_i32(0);
135 tcg_gen_st_i32(zero
, cpu_env
, offsetof(CPUARMState
, btype
));
136 tcg_temp_free_i32(zero
);
141 static void set_btype(DisasContext
*s
, int val
)
145 /* BTYPE is a 2-bit field, and 0 should be done with reset_btype. */
146 tcg_debug_assert(val
>= 1 && val
<= 3);
148 tcg_val
= tcg_const_i32(val
);
149 tcg_gen_st_i32(tcg_val
, cpu_env
, offsetof(CPUARMState
, btype
));
150 tcg_temp_free_i32(tcg_val
);
154 void gen_a64_set_pc_im(uint64_t val
)
156 tcg_gen_movi_i64(cpu_pc
, val
);
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 (s
->current_el
>= 2) {
179 /* FIXME: ARMv8.1-VHE S2 translation regime. */
180 /* Force tag byte to all zero */
181 tcg_gen_extract_i64(dst
, src
, 0, 56);
183 /* Sign-extend from bit 55. */
184 tcg_gen_sextract_i64(dst
, src
, 0, 56);
187 TCGv_i64 tcg_zero
= tcg_const_i64(0);
190 * The two TBI bits differ.
191 * If tbi0, then !tbi1: only use the extension if positive.
192 * if !tbi0, then tbi1: only use the extension if negative.
194 tcg_gen_movcond_i64(tbi
== 1 ? TCG_COND_GE
: TCG_COND_LT
,
195 dst
, dst
, tcg_zero
, dst
, src
);
196 tcg_temp_free_i64(tcg_zero
);
201 static void gen_a64_set_pc(DisasContext
*s
, TCGv_i64 src
)
204 * If address tagging is enabled for instructions via the TCR TBI bits,
205 * then loading an address into the PC will clear out any tag.
207 gen_top_byte_ignore(s
, cpu_pc
, src
, s
->tbii
);
211 * Return a "clean" address for ADDR according to TBID.
212 * This is always a fresh temporary, as we need to be able to
213 * increment this independently of a dirty write-back address.
215 static TCGv_i64
clean_data_tbi(DisasContext
*s
, TCGv_i64 addr
)
217 TCGv_i64 clean
= new_tmp_a64(s
);
218 gen_top_byte_ignore(s
, clean
, addr
, s
->tbid
);
222 typedef struct DisasCompare64
{
227 static void a64_test_cc(DisasCompare64
*c64
, int cc
)
231 arm_test_cc(&c32
, cc
);
233 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
234 * properly. The NE/EQ comparisons are also fine with this choice. */
235 c64
->cond
= c32
.cond
;
236 c64
->value
= tcg_temp_new_i64();
237 tcg_gen_ext_i32_i64(c64
->value
, c32
.value
);
242 static void a64_free_cc(DisasCompare64
*c64
)
244 tcg_temp_free_i64(c64
->value
);
247 static void gen_exception_internal(int excp
)
249 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
251 assert(excp_is_internal(excp
));
252 gen_helper_exception_internal(cpu_env
, tcg_excp
);
253 tcg_temp_free_i32(tcg_excp
);
256 static void gen_exception_internal_insn(DisasContext
*s
, uint64_t pc
, int excp
)
258 gen_a64_set_pc_im(pc
);
259 gen_exception_internal(excp
);
260 s
->base
.is_jmp
= DISAS_NORETURN
;
263 static void gen_exception_insn(DisasContext
*s
, uint64_t pc
, int excp
,
264 uint32_t syndrome
, uint32_t target_el
)
266 gen_a64_set_pc_im(pc
);
267 gen_exception(excp
, syndrome
, target_el
);
268 s
->base
.is_jmp
= DISAS_NORETURN
;
271 static void gen_exception_bkpt_insn(DisasContext
*s
, uint32_t syndrome
)
275 gen_a64_set_pc_im(s
->pc_curr
);
276 tcg_syn
= tcg_const_i32(syndrome
);
277 gen_helper_exception_bkpt_insn(cpu_env
, tcg_syn
);
278 tcg_temp_free_i32(tcg_syn
);
279 s
->base
.is_jmp
= DISAS_NORETURN
;
282 static void gen_step_complete_exception(DisasContext
*s
)
284 /* We just completed step of an insn. Move from Active-not-pending
285 * to Active-pending, and then also take the swstep exception.
286 * This corresponds to making the (IMPDEF) choice to prioritize
287 * swstep exceptions over asynchronous exceptions taken to an exception
288 * level where debug is disabled. This choice has the advantage that
289 * we do not need to maintain internal state corresponding to the
290 * ISV/EX syndrome bits between completion of the step and generation
291 * of the exception, and our syndrome information is always correct.
294 gen_swstep_exception(s
, 1, s
->is_ldex
);
295 s
->base
.is_jmp
= DISAS_NORETURN
;
298 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
300 /* No direct tb linking with singlestep (either QEMU's or the ARM
301 * debug architecture kind) or deterministic io
303 if (s
->base
.singlestep_enabled
|| s
->ss_active
||
304 (tb_cflags(s
->base
.tb
) & CF_LAST_IO
)) {
308 #ifndef CONFIG_USER_ONLY
309 /* Only link tbs from inside the same guest page */
310 if ((s
->base
.tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
318 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
320 TranslationBlock
*tb
;
323 if (use_goto_tb(s
, n
, dest
)) {
325 gen_a64_set_pc_im(dest
);
326 tcg_gen_exit_tb(tb
, n
);
327 s
->base
.is_jmp
= DISAS_NORETURN
;
329 gen_a64_set_pc_im(dest
);
331 gen_step_complete_exception(s
);
332 } else if (s
->base
.singlestep_enabled
) {
333 gen_exception_internal(EXCP_DEBUG
);
335 tcg_gen_lookup_and_goto_ptr();
336 s
->base
.is_jmp
= DISAS_NORETURN
;
341 static void init_tmp_a64_array(DisasContext
*s
)
343 #ifdef CONFIG_DEBUG_TCG
344 memset(s
->tmp_a64
, 0, sizeof(s
->tmp_a64
));
346 s
->tmp_a64_count
= 0;
349 static void free_tmp_a64(DisasContext
*s
)
352 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
353 tcg_temp_free_i64(s
->tmp_a64
[i
]);
355 init_tmp_a64_array(s
);
358 TCGv_i64
new_tmp_a64(DisasContext
*s
)
360 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
361 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
364 TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
366 TCGv_i64 t
= new_tmp_a64(s
);
367 tcg_gen_movi_i64(t
, 0);
372 * Register access functions
374 * These functions are used for directly accessing a register in where
375 * changes to the final register value are likely to be made. If you
376 * need to use a register for temporary calculation (e.g. index type
377 * operations) use the read_* form.
379 * B1.2.1 Register mappings
381 * In instruction register encoding 31 can refer to ZR (zero register) or
382 * the SP (stack pointer) depending on context. In QEMU's case we map SP
383 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
384 * This is the point of the _sp forms.
386 TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
389 return new_tmp_a64_zero(s
);
395 /* register access for when 31 == SP */
396 TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
401 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
402 * representing the register contents. This TCGv is an auto-freed
403 * temporary so it need not be explicitly freed, and may be modified.
405 TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
407 TCGv_i64 v
= new_tmp_a64(s
);
410 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
412 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
415 tcg_gen_movi_i64(v
, 0);
420 TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
422 TCGv_i64 v
= new_tmp_a64(s
);
424 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
426 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
431 /* Return the offset into CPUARMState of a slice (from
432 * the least significant end) of FP register Qn (ie
434 * (Note that this is not the same mapping as for A32; see cpu.h)
436 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
438 return vec_reg_offset(s
, regno
, 0, size
);
441 /* Offset of the high half of the 128 bit vector Qn */
442 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
444 return vec_reg_offset(s
, regno
, 1, MO_64
);
447 /* Convenience accessors for reading and writing single and double
448 * FP registers. Writing clears the upper parts of the associated
449 * 128 bit vector register, as required by the architecture.
450 * Note that unlike the GP register accessors, the values returned
451 * by the read functions must be manually freed.
453 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
455 TCGv_i64 v
= tcg_temp_new_i64();
457 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
461 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
463 TCGv_i32 v
= tcg_temp_new_i32();
465 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
469 static TCGv_i32
read_fp_hreg(DisasContext
*s
, int reg
)
471 TCGv_i32 v
= tcg_temp_new_i32();
473 tcg_gen_ld16u_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_16
));
477 /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64).
478 * If SVE is not enabled, then there are only 128 bits in the vector.
480 static void clear_vec_high(DisasContext
*s
, bool is_q
, int rd
)
482 unsigned ofs
= fp_reg_offset(s
, rd
, MO_64
);
483 unsigned vsz
= vec_full_reg_size(s
);
486 TCGv_i64 tcg_zero
= tcg_const_i64(0);
487 tcg_gen_st_i64(tcg_zero
, cpu_env
, ofs
+ 8);
488 tcg_temp_free_i64(tcg_zero
);
491 tcg_gen_gvec_dup8i(ofs
+ 16, vsz
- 16, vsz
- 16, 0);
495 void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
497 unsigned ofs
= fp_reg_offset(s
, reg
, MO_64
);
499 tcg_gen_st_i64(v
, cpu_env
, ofs
);
500 clear_vec_high(s
, false, reg
);
503 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
505 TCGv_i64 tmp
= tcg_temp_new_i64();
507 tcg_gen_extu_i32_i64(tmp
, v
);
508 write_fp_dreg(s
, reg
, tmp
);
509 tcg_temp_free_i64(tmp
);
512 TCGv_ptr
get_fpstatus_ptr(bool is_f16
)
514 TCGv_ptr statusptr
= tcg_temp_new_ptr();
517 /* In A64 all instructions (both FP and Neon) use the FPCR; there
518 * is no equivalent of the A32 Neon "standard FPSCR value".
519 * However half-precision operations operate under a different
520 * FZ16 flag and use vfp.fp_status_f16 instead of vfp.fp_status.
523 offset
= offsetof(CPUARMState
, vfp
.fp_status_f16
);
525 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
527 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
531 /* Expand a 2-operand AdvSIMD vector operation using an expander function. */
532 static void gen_gvec_fn2(DisasContext
*s
, bool is_q
, int rd
, int rn
,
533 GVecGen2Fn
*gvec_fn
, int vece
)
535 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
536 is_q
? 16 : 8, vec_full_reg_size(s
));
539 /* Expand a 2-operand + immediate AdvSIMD vector operation using
540 * an expander function.
542 static void gen_gvec_fn2i(DisasContext
*s
, bool is_q
, int rd
, int rn
,
543 int64_t imm
, GVecGen2iFn
*gvec_fn
, int vece
)
545 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
546 imm
, is_q
? 16 : 8, vec_full_reg_size(s
));
549 /* Expand a 3-operand AdvSIMD vector operation using an expander function. */
550 static void gen_gvec_fn3(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
551 GVecGen3Fn
*gvec_fn
, int vece
)
553 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
554 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8, vec_full_reg_size(s
));
557 /* Expand a 4-operand AdvSIMD vector operation using an expander function. */
558 static void gen_gvec_fn4(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
559 int rx
, GVecGen4Fn
*gvec_fn
, int vece
)
561 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
562 vec_full_reg_offset(s
, rm
), vec_full_reg_offset(s
, rx
),
563 is_q
? 16 : 8, vec_full_reg_size(s
));
566 /* Expand a 2-operand + immediate AdvSIMD vector operation using
569 static void gen_gvec_op2i(DisasContext
*s
, bool is_q
, int rd
,
570 int rn
, int64_t imm
, const GVecGen2i
*gvec_op
)
572 tcg_gen_gvec_2i(vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
573 is_q
? 16 : 8, vec_full_reg_size(s
), imm
, gvec_op
);
576 /* Expand a 3-operand AdvSIMD vector operation using an op descriptor. */
577 static void gen_gvec_op3(DisasContext
*s
, bool is_q
, int rd
,
578 int rn
, int rm
, const GVecGen3
*gvec_op
)
580 tcg_gen_gvec_3(vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
581 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8,
582 vec_full_reg_size(s
), gvec_op
);
585 /* Expand a 3-operand operation using an out-of-line helper. */
586 static void gen_gvec_op3_ool(DisasContext
*s
, bool is_q
, int rd
,
587 int rn
, int rm
, int data
, gen_helper_gvec_3
*fn
)
589 tcg_gen_gvec_3_ool(vec_full_reg_offset(s
, rd
),
590 vec_full_reg_offset(s
, rn
),
591 vec_full_reg_offset(s
, rm
),
592 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
595 /* Expand a 3-operand + env pointer operation using
596 * an out-of-line helper.
598 static void gen_gvec_op3_env(DisasContext
*s
, bool is_q
, int rd
,
599 int rn
, int rm
, gen_helper_gvec_3_ptr
*fn
)
601 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
602 vec_full_reg_offset(s
, rn
),
603 vec_full_reg_offset(s
, rm
), cpu_env
,
604 is_q
? 16 : 8, vec_full_reg_size(s
), 0, fn
);
607 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
608 * an out-of-line helper.
610 static void gen_gvec_op3_fpst(DisasContext
*s
, bool is_q
, int rd
, int rn
,
611 int rm
, bool is_fp16
, int data
,
612 gen_helper_gvec_3_ptr
*fn
)
614 TCGv_ptr fpst
= get_fpstatus_ptr(is_fp16
);
615 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
616 vec_full_reg_offset(s
, rn
),
617 vec_full_reg_offset(s
, rm
), fpst
,
618 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
619 tcg_temp_free_ptr(fpst
);
622 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
623 * than the 32 bit equivalent.
625 static inline void gen_set_NZ64(TCGv_i64 result
)
627 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
628 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
631 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
632 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
635 gen_set_NZ64(result
);
637 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
638 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
640 tcg_gen_movi_i32(cpu_CF
, 0);
641 tcg_gen_movi_i32(cpu_VF
, 0);
644 /* dest = T0 + T1; compute C, N, V and Z flags */
645 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
648 TCGv_i64 result
, flag
, tmp
;
649 result
= tcg_temp_new_i64();
650 flag
= tcg_temp_new_i64();
651 tmp
= tcg_temp_new_i64();
653 tcg_gen_movi_i64(tmp
, 0);
654 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
656 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
658 gen_set_NZ64(result
);
660 tcg_gen_xor_i64(flag
, result
, t0
);
661 tcg_gen_xor_i64(tmp
, t0
, t1
);
662 tcg_gen_andc_i64(flag
, flag
, tmp
);
663 tcg_temp_free_i64(tmp
);
664 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
666 tcg_gen_mov_i64(dest
, result
);
667 tcg_temp_free_i64(result
);
668 tcg_temp_free_i64(flag
);
670 /* 32 bit arithmetic */
671 TCGv_i32 t0_32
= tcg_temp_new_i32();
672 TCGv_i32 t1_32
= tcg_temp_new_i32();
673 TCGv_i32 tmp
= tcg_temp_new_i32();
675 tcg_gen_movi_i32(tmp
, 0);
676 tcg_gen_extrl_i64_i32(t0_32
, t0
);
677 tcg_gen_extrl_i64_i32(t1_32
, t1
);
678 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
679 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
680 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
681 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
682 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
683 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
685 tcg_temp_free_i32(tmp
);
686 tcg_temp_free_i32(t0_32
);
687 tcg_temp_free_i32(t1_32
);
691 /* dest = T0 - T1; compute C, N, V and Z flags */
692 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
695 /* 64 bit arithmetic */
696 TCGv_i64 result
, flag
, tmp
;
698 result
= tcg_temp_new_i64();
699 flag
= tcg_temp_new_i64();
700 tcg_gen_sub_i64(result
, t0
, t1
);
702 gen_set_NZ64(result
);
704 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
705 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
707 tcg_gen_xor_i64(flag
, result
, t0
);
708 tmp
= tcg_temp_new_i64();
709 tcg_gen_xor_i64(tmp
, t0
, t1
);
710 tcg_gen_and_i64(flag
, flag
, tmp
);
711 tcg_temp_free_i64(tmp
);
712 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
713 tcg_gen_mov_i64(dest
, result
);
714 tcg_temp_free_i64(flag
);
715 tcg_temp_free_i64(result
);
717 /* 32 bit arithmetic */
718 TCGv_i32 t0_32
= tcg_temp_new_i32();
719 TCGv_i32 t1_32
= tcg_temp_new_i32();
722 tcg_gen_extrl_i64_i32(t0_32
, t0
);
723 tcg_gen_extrl_i64_i32(t1_32
, t1
);
724 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
725 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
726 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
727 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
728 tmp
= tcg_temp_new_i32();
729 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
730 tcg_temp_free_i32(t0_32
);
731 tcg_temp_free_i32(t1_32
);
732 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
733 tcg_temp_free_i32(tmp
);
734 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
738 /* dest = T0 + T1 + CF; do not compute flags. */
739 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
741 TCGv_i64 flag
= tcg_temp_new_i64();
742 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
743 tcg_gen_add_i64(dest
, t0
, t1
);
744 tcg_gen_add_i64(dest
, dest
, flag
);
745 tcg_temp_free_i64(flag
);
748 tcg_gen_ext32u_i64(dest
, dest
);
752 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
753 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
756 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
757 result
= tcg_temp_new_i64();
758 cf_64
= tcg_temp_new_i64();
759 vf_64
= tcg_temp_new_i64();
760 tmp
= tcg_const_i64(0);
762 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
763 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
764 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
765 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
766 gen_set_NZ64(result
);
768 tcg_gen_xor_i64(vf_64
, result
, t0
);
769 tcg_gen_xor_i64(tmp
, t0
, t1
);
770 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
771 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
773 tcg_gen_mov_i64(dest
, result
);
775 tcg_temp_free_i64(tmp
);
776 tcg_temp_free_i64(vf_64
);
777 tcg_temp_free_i64(cf_64
);
778 tcg_temp_free_i64(result
);
780 TCGv_i32 t0_32
, t1_32
, tmp
;
781 t0_32
= tcg_temp_new_i32();
782 t1_32
= tcg_temp_new_i32();
783 tmp
= tcg_const_i32(0);
785 tcg_gen_extrl_i64_i32(t0_32
, t0
);
786 tcg_gen_extrl_i64_i32(t1_32
, t1
);
787 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
788 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
790 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
791 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
792 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
793 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
794 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
796 tcg_temp_free_i32(tmp
);
797 tcg_temp_free_i32(t1_32
);
798 tcg_temp_free_i32(t0_32
);
803 * Load/Store generators
807 * Store from GPR register to memory.
809 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
810 TCGv_i64 tcg_addr
, int size
, int memidx
,
812 unsigned int iss_srt
,
813 bool iss_sf
, bool iss_ar
)
816 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, s
->be_data
+ size
);
821 syn
= syn_data_abort_with_iss(0,
827 0, 0, 0, 0, 0, false);
828 disas_set_insn_syndrome(s
, syn
);
832 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
833 TCGv_i64 tcg_addr
, int size
,
835 unsigned int iss_srt
,
836 bool iss_sf
, bool iss_ar
)
838 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
),
839 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
843 * Load from memory to GPR register
845 static void do_gpr_ld_memidx(DisasContext
*s
,
846 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
847 int size
, bool is_signed
,
848 bool extend
, int memidx
,
849 bool iss_valid
, unsigned int iss_srt
,
850 bool iss_sf
, bool iss_ar
)
852 TCGMemOp memop
= s
->be_data
+ size
;
860 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
862 if (extend
&& is_signed
) {
864 tcg_gen_ext32u_i64(dest
, dest
);
870 syn
= syn_data_abort_with_iss(0,
876 0, 0, 0, 0, 0, false);
877 disas_set_insn_syndrome(s
, syn
);
881 static void do_gpr_ld(DisasContext
*s
,
882 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
883 int size
, bool is_signed
, bool extend
,
884 bool iss_valid
, unsigned int iss_srt
,
885 bool iss_sf
, bool iss_ar
)
887 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
889 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
893 * Store from FP register to memory
895 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
897 /* This writes the bottom N bits of a 128 bit wide vector to memory */
898 TCGv_i64 tmp
= tcg_temp_new_i64();
899 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
901 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
),
904 bool be
= s
->be_data
== MO_BE
;
905 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
907 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
908 tcg_gen_qemu_st_i64(tmp
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
910 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
911 tcg_gen_qemu_st_i64(tmp
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
913 tcg_temp_free_i64(tcg_hiaddr
);
916 tcg_temp_free_i64(tmp
);
920 * Load from memory to FP register
922 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
924 /* This always zero-extends and writes to a full 128 bit wide vector */
925 TCGv_i64 tmplo
= tcg_temp_new_i64();
929 TCGMemOp memop
= s
->be_data
+ size
;
930 tmphi
= tcg_const_i64(0);
931 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
933 bool be
= s
->be_data
== MO_BE
;
936 tmphi
= tcg_temp_new_i64();
937 tcg_hiaddr
= tcg_temp_new_i64();
939 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
940 tcg_gen_qemu_ld_i64(tmplo
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
942 tcg_gen_qemu_ld_i64(tmphi
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
944 tcg_temp_free_i64(tcg_hiaddr
);
947 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
948 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
950 tcg_temp_free_i64(tmplo
);
951 tcg_temp_free_i64(tmphi
);
953 clear_vec_high(s
, true, destidx
);
957 * Vector load/store helpers.
959 * The principal difference between this and a FP load is that we don't
960 * zero extend as we are filling a partial chunk of the vector register.
961 * These functions don't support 128 bit loads/stores, which would be
962 * normal load/store operations.
964 * The _i32 versions are useful when operating on 32 bit quantities
965 * (eg for floating point single or using Neon helper functions).
968 /* Get value of an element within a vector register */
969 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
970 int element
, TCGMemOp memop
)
972 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
975 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
978 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
981 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
984 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
987 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
990 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
994 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
997 g_assert_not_reached();
1001 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
1002 int element
, TCGMemOp memop
)
1004 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1007 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
1010 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
1013 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
1016 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
1020 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
1023 g_assert_not_reached();
1027 /* Set value of an element within a vector register */
1028 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
1029 int element
, TCGMemOp memop
)
1031 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1034 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
1037 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
1040 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
1043 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
1046 g_assert_not_reached();
1050 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
1051 int destidx
, int element
, TCGMemOp memop
)
1053 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1056 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
1059 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
1062 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
1065 g_assert_not_reached();
1069 /* Store from vector register to memory */
1070 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
1071 TCGv_i64 tcg_addr
, int size
, TCGMemOp endian
)
1073 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1075 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
1076 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), endian
| size
);
1078 tcg_temp_free_i64(tcg_tmp
);
1081 /* Load from memory to vector register */
1082 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
1083 TCGv_i64 tcg_addr
, int size
, TCGMemOp endian
)
1085 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1087 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), endian
| size
);
1088 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
1090 tcg_temp_free_i64(tcg_tmp
);
1093 /* Check that FP/Neon access is enabled. If it is, return
1094 * true. If not, emit code to generate an appropriate exception,
1095 * and return false; the caller should not emit any code for
1096 * the instruction. Note that this check must happen after all
1097 * unallocated-encoding checks (otherwise the syndrome information
1098 * for the resulting exception will be incorrect).
1100 static inline bool fp_access_check(DisasContext
*s
)
1102 assert(!s
->fp_access_checked
);
1103 s
->fp_access_checked
= true;
1105 if (!s
->fp_excp_el
) {
1109 gen_exception_insn(s
, s
->pc_curr
, EXCP_UDEF
,
1110 syn_fp_access_trap(1, 0xe, false), s
->fp_excp_el
);
1114 /* Check that SVE access is enabled. If it is, return true.
1115 * If not, emit code to generate an appropriate exception and return false.
1117 bool sve_access_check(DisasContext
*s
)
1119 if (s
->sve_excp_el
) {
1120 gen_exception_insn(s
, s
->pc_curr
, EXCP_UDEF
, syn_sve_access_trap(),
1124 return fp_access_check(s
);
1128 * This utility function is for doing register extension with an
1129 * optional shift. You will likely want to pass a temporary for the
1130 * destination register. See DecodeRegExtend() in the ARM ARM.
1132 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1133 int option
, unsigned int shift
)
1135 int extsize
= extract32(option
, 0, 2);
1136 bool is_signed
= extract32(option
, 2, 1);
1141 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1144 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1147 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1150 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1156 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1159 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1162 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1165 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1171 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1175 static inline void gen_check_sp_alignment(DisasContext
*s
)
1177 /* The AArch64 architecture mandates that (if enabled via PSTATE
1178 * or SCTLR bits) there is a check that SP is 16-aligned on every
1179 * SP-relative load or store (with an exception generated if it is not).
1180 * In line with general QEMU practice regarding misaligned accesses,
1181 * we omit these checks for the sake of guest program performance.
1182 * This function is provided as a hook so we can more easily add these
1183 * checks in future (possibly as a "favour catching guest program bugs
1184 * over speed" user selectable option).
1189 * This provides a simple table based table lookup decoder. It is
1190 * intended to be used when the relevant bits for decode are too
1191 * awkwardly placed and switch/if based logic would be confusing and
1192 * deeply nested. Since it's a linear search through the table, tables
1193 * should be kept small.
1195 * It returns the first handler where insn & mask == pattern, or
1196 * NULL if there is no match.
1197 * The table is terminated by an empty mask (i.e. 0)
1199 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1202 const AArch64DecodeTable
*tptr
= table
;
1204 while (tptr
->mask
) {
1205 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1206 return tptr
->disas_fn
;
1214 * The instruction disassembly implemented here matches
1215 * the instruction encoding classifications in chapter C4
1216 * of the ARM Architecture Reference Manual (DDI0487B_a);
1217 * classification names and decode diagrams here should generally
1218 * match up with those in the manual.
1221 /* Unconditional branch (immediate)
1223 * +----+-----------+-------------------------------------+
1224 * | op | 0 0 1 0 1 | imm26 |
1225 * +----+-----------+-------------------------------------+
1227 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1229 uint64_t addr
= s
->pc_curr
+ sextract32(insn
, 0, 26) * 4;
1231 if (insn
& (1U << 31)) {
1232 /* BL Branch with link */
1233 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->base
.pc_next
);
1236 /* B Branch / BL Branch with link */
1238 gen_goto_tb(s
, 0, addr
);
1241 /* Compare and branch (immediate)
1242 * 31 30 25 24 23 5 4 0
1243 * +----+-------------+----+---------------------+--------+
1244 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1245 * +----+-------------+----+---------------------+--------+
1247 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1249 unsigned int sf
, op
, rt
;
1251 TCGLabel
*label_match
;
1254 sf
= extract32(insn
, 31, 1);
1255 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1256 rt
= extract32(insn
, 0, 5);
1257 addr
= s
->pc_curr
+ sextract32(insn
, 5, 19) * 4;
1259 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1260 label_match
= gen_new_label();
1263 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1264 tcg_cmp
, 0, label_match
);
1266 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1267 gen_set_label(label_match
);
1268 gen_goto_tb(s
, 1, addr
);
1271 /* Test and branch (immediate)
1272 * 31 30 25 24 23 19 18 5 4 0
1273 * +----+-------------+----+-------+-------------+------+
1274 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1275 * +----+-------------+----+-------+-------------+------+
1277 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1279 unsigned int bit_pos
, op
, rt
;
1281 TCGLabel
*label_match
;
1284 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1285 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1286 addr
= s
->pc_curr
+ sextract32(insn
, 5, 14) * 4;
1287 rt
= extract32(insn
, 0, 5);
1289 tcg_cmp
= tcg_temp_new_i64();
1290 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1291 label_match
= gen_new_label();
1294 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1295 tcg_cmp
, 0, label_match
);
1296 tcg_temp_free_i64(tcg_cmp
);
1297 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1298 gen_set_label(label_match
);
1299 gen_goto_tb(s
, 1, addr
);
1302 /* Conditional branch (immediate)
1303 * 31 25 24 23 5 4 3 0
1304 * +---------------+----+---------------------+----+------+
1305 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1306 * +---------------+----+---------------------+----+------+
1308 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1313 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1314 unallocated_encoding(s
);
1317 addr
= s
->pc_curr
+ sextract32(insn
, 5, 19) * 4;
1318 cond
= extract32(insn
, 0, 4);
1322 /* genuinely conditional branches */
1323 TCGLabel
*label_match
= gen_new_label();
1324 arm_gen_test_cc(cond
, label_match
);
1325 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1326 gen_set_label(label_match
);
1327 gen_goto_tb(s
, 1, addr
);
1329 /* 0xe and 0xf are both "always" conditions */
1330 gen_goto_tb(s
, 0, addr
);
1334 /* HINT instruction group, including various allocated HINTs */
1335 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1336 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1338 unsigned int selector
= crm
<< 3 | op2
;
1341 unallocated_encoding(s
);
1346 case 0b00000: /* NOP */
1348 case 0b00011: /* WFI */
1349 s
->base
.is_jmp
= DISAS_WFI
;
1351 case 0b00001: /* YIELD */
1352 /* When running in MTTCG we don't generate jumps to the yield and
1353 * WFE helpers as it won't affect the scheduling of other vCPUs.
1354 * If we wanted to more completely model WFE/SEV so we don't busy
1355 * spin unnecessarily we would need to do something more involved.
1357 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1358 s
->base
.is_jmp
= DISAS_YIELD
;
1361 case 0b00010: /* WFE */
1362 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1363 s
->base
.is_jmp
= DISAS_WFE
;
1366 case 0b00100: /* SEV */
1367 case 0b00101: /* SEVL */
1368 /* we treat all as NOP at least for now */
1370 case 0b00111: /* XPACLRI */
1371 if (s
->pauth_active
) {
1372 gen_helper_xpaci(cpu_X
[30], cpu_env
, cpu_X
[30]);
1375 case 0b01000: /* PACIA1716 */
1376 if (s
->pauth_active
) {
1377 gen_helper_pacia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1380 case 0b01010: /* PACIB1716 */
1381 if (s
->pauth_active
) {
1382 gen_helper_pacib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1385 case 0b01100: /* AUTIA1716 */
1386 if (s
->pauth_active
) {
1387 gen_helper_autia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1390 case 0b01110: /* AUTIB1716 */
1391 if (s
->pauth_active
) {
1392 gen_helper_autib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1395 case 0b11000: /* PACIAZ */
1396 if (s
->pauth_active
) {
1397 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30],
1398 new_tmp_a64_zero(s
));
1401 case 0b11001: /* PACIASP */
1402 if (s
->pauth_active
) {
1403 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1406 case 0b11010: /* PACIBZ */
1407 if (s
->pauth_active
) {
1408 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30],
1409 new_tmp_a64_zero(s
));
1412 case 0b11011: /* PACIBSP */
1413 if (s
->pauth_active
) {
1414 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1417 case 0b11100: /* AUTIAZ */
1418 if (s
->pauth_active
) {
1419 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30],
1420 new_tmp_a64_zero(s
));
1423 case 0b11101: /* AUTIASP */
1424 if (s
->pauth_active
) {
1425 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1428 case 0b11110: /* AUTIBZ */
1429 if (s
->pauth_active
) {
1430 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30],
1431 new_tmp_a64_zero(s
));
1434 case 0b11111: /* AUTIBSP */
1435 if (s
->pauth_active
) {
1436 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1440 /* default specified as NOP equivalent */
1445 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1447 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1450 /* CLREX, DSB, DMB, ISB */
1451 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1452 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1457 unallocated_encoding(s
);
1468 case 1: /* MBReqTypes_Reads */
1469 bar
= TCG_BAR_SC
| TCG_MO_LD_LD
| TCG_MO_LD_ST
;
1471 case 2: /* MBReqTypes_Writes */
1472 bar
= TCG_BAR_SC
| TCG_MO_ST_ST
;
1474 default: /* MBReqTypes_All */
1475 bar
= TCG_BAR_SC
| TCG_MO_ALL
;
1481 /* We need to break the TB after this insn to execute
1482 * a self-modified code correctly and also to take
1483 * any pending interrupts immediately.
1486 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1490 if (crm
!= 0 || !dc_isar_feature(aa64_sb
, s
)) {
1491 goto do_unallocated
;
1494 * TODO: There is no speculation barrier opcode for TCG;
1495 * MB and end the TB instead.
1497 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
1498 gen_goto_tb(s
, 0, s
->base
.pc_next
);
1503 unallocated_encoding(s
);
1508 static void gen_xaflag(void)
1510 TCGv_i32 z
= tcg_temp_new_i32();
1512 tcg_gen_setcondi_i32(TCG_COND_EQ
, z
, cpu_ZF
, 0);
1521 tcg_gen_or_i32(cpu_NF
, cpu_CF
, z
);
1522 tcg_gen_subi_i32(cpu_NF
, cpu_NF
, 1);
1525 tcg_gen_and_i32(cpu_ZF
, z
, cpu_CF
);
1526 tcg_gen_xori_i32(cpu_ZF
, cpu_ZF
, 1);
1528 /* (!C & Z) << 31 -> -(Z & ~C) */
1529 tcg_gen_andc_i32(cpu_VF
, z
, cpu_CF
);
1530 tcg_gen_neg_i32(cpu_VF
, cpu_VF
);
1533 tcg_gen_or_i32(cpu_CF
, cpu_CF
, z
);
1535 tcg_temp_free_i32(z
);
1538 static void gen_axflag(void)
1540 tcg_gen_sari_i32(cpu_VF
, cpu_VF
, 31); /* V ? -1 : 0 */
1541 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, cpu_VF
); /* C & !V */
1543 /* !(Z | V) -> !(!ZF | V) -> ZF & !V -> ZF & ~VF */
1544 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, cpu_VF
);
1546 tcg_gen_movi_i32(cpu_NF
, 0);
1547 tcg_gen_movi_i32(cpu_VF
, 0);
1550 /* MSR (immediate) - move immediate to processor state field */
1551 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1552 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1555 int op
= op1
<< 3 | op2
;
1557 /* End the TB by default, chaining is ok. */
1558 s
->base
.is_jmp
= DISAS_TOO_MANY
;
1561 case 0x00: /* CFINV */
1562 if (crm
!= 0 || !dc_isar_feature(aa64_condm_4
, s
)) {
1563 goto do_unallocated
;
1565 tcg_gen_xori_i32(cpu_CF
, cpu_CF
, 1);
1566 s
->base
.is_jmp
= DISAS_NEXT
;
1569 case 0x01: /* XAFlag */
1570 if (crm
!= 0 || !dc_isar_feature(aa64_condm_5
, s
)) {
1571 goto do_unallocated
;
1574 s
->base
.is_jmp
= DISAS_NEXT
;
1577 case 0x02: /* AXFlag */
1578 if (crm
!= 0 || !dc_isar_feature(aa64_condm_5
, s
)) {
1579 goto do_unallocated
;
1582 s
->base
.is_jmp
= DISAS_NEXT
;
1585 case 0x05: /* SPSel */
1586 if (s
->current_el
== 0) {
1587 goto do_unallocated
;
1589 t1
= tcg_const_i32(crm
& PSTATE_SP
);
1590 gen_helper_msr_i_spsel(cpu_env
, t1
);
1591 tcg_temp_free_i32(t1
);
1594 case 0x1e: /* DAIFSet */
1595 t1
= tcg_const_i32(crm
);
1596 gen_helper_msr_i_daifset(cpu_env
, t1
);
1597 tcg_temp_free_i32(t1
);
1600 case 0x1f: /* DAIFClear */
1601 t1
= tcg_const_i32(crm
);
1602 gen_helper_msr_i_daifclear(cpu_env
, t1
);
1603 tcg_temp_free_i32(t1
);
1604 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1605 s
->base
.is_jmp
= DISAS_UPDATE
;
1610 unallocated_encoding(s
);
1615 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1617 TCGv_i32 tmp
= tcg_temp_new_i32();
1618 TCGv_i32 nzcv
= tcg_temp_new_i32();
1620 /* build bit 31, N */
1621 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1622 /* build bit 30, Z */
1623 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1624 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1625 /* build bit 29, C */
1626 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1627 /* build bit 28, V */
1628 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1629 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1630 /* generate result */
1631 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1633 tcg_temp_free_i32(nzcv
);
1634 tcg_temp_free_i32(tmp
);
1637 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1639 TCGv_i32 nzcv
= tcg_temp_new_i32();
1641 /* take NZCV from R[t] */
1642 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1645 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1647 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1648 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1650 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1651 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1653 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1654 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1655 tcg_temp_free_i32(nzcv
);
1658 /* MRS - move from system register
1659 * MSR (register) - move to system register
1662 * These are all essentially the same insn in 'read' and 'write'
1663 * versions, with varying op0 fields.
1665 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1666 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1667 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1669 const ARMCPRegInfo
*ri
;
1672 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1673 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1674 crn
, crm
, op0
, op1
, op2
));
1677 /* Unknown register; this might be a guest error or a QEMU
1678 * unimplemented feature.
1680 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1681 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1682 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1683 unallocated_encoding(s
);
1687 /* Check access permissions */
1688 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1689 unallocated_encoding(s
);
1694 /* Emit code to perform further access permissions checks at
1695 * runtime; this may result in an exception.
1698 TCGv_i32 tcg_syn
, tcg_isread
;
1701 gen_a64_set_pc_im(s
->pc_curr
);
1702 tmpptr
= tcg_const_ptr(ri
);
1703 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1704 tcg_syn
= tcg_const_i32(syndrome
);
1705 tcg_isread
= tcg_const_i32(isread
);
1706 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
, tcg_isread
);
1707 tcg_temp_free_ptr(tmpptr
);
1708 tcg_temp_free_i32(tcg_syn
);
1709 tcg_temp_free_i32(tcg_isread
);
1712 /* Handle special cases first */
1713 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1717 tcg_rt
= cpu_reg(s
, rt
);
1719 gen_get_nzcv(tcg_rt
);
1721 gen_set_nzcv(tcg_rt
);
1724 case ARM_CP_CURRENTEL
:
1725 /* Reads as current EL value from pstate, which is
1726 * guaranteed to be constant by the tb flags.
1728 tcg_rt
= cpu_reg(s
, rt
);
1729 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1732 /* Writes clear the aligned block of memory which rt points into. */
1733 tcg_rt
= cpu_reg(s
, rt
);
1734 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1739 if ((ri
->type
& ARM_CP_FPU
) && !fp_access_check(s
)) {
1741 } else if ((ri
->type
& ARM_CP_SVE
) && !sve_access_check(s
)) {
1745 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1749 tcg_rt
= cpu_reg(s
, rt
);
1752 if (ri
->type
& ARM_CP_CONST
) {
1753 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1754 } else if (ri
->readfn
) {
1756 tmpptr
= tcg_const_ptr(ri
);
1757 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1758 tcg_temp_free_ptr(tmpptr
);
1760 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1763 if (ri
->type
& ARM_CP_CONST
) {
1764 /* If not forbidden by access permissions, treat as WI */
1766 } else if (ri
->writefn
) {
1768 tmpptr
= tcg_const_ptr(ri
);
1769 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1770 tcg_temp_free_ptr(tmpptr
);
1772 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1776 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1777 /* I/O operations must end the TB here (whether read or write) */
1779 s
->base
.is_jmp
= DISAS_UPDATE
;
1780 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1781 /* We default to ending the TB on a coprocessor register write,
1782 * but allow this to be suppressed by the register definition
1783 * (usually only necessary to work around guest bugs).
1785 s
->base
.is_jmp
= DISAS_UPDATE
;
1790 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1791 * +---------------------+---+-----+-----+-------+-------+-----+------+
1792 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1793 * +---------------------+---+-----+-----+-------+-------+-----+------+
1795 static void disas_system(DisasContext
*s
, uint32_t insn
)
1797 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1798 l
= extract32(insn
, 21, 1);
1799 op0
= extract32(insn
, 19, 2);
1800 op1
= extract32(insn
, 16, 3);
1801 crn
= extract32(insn
, 12, 4);
1802 crm
= extract32(insn
, 8, 4);
1803 op2
= extract32(insn
, 5, 3);
1804 rt
= extract32(insn
, 0, 5);
1807 if (l
|| rt
!= 31) {
1808 unallocated_encoding(s
);
1812 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
1813 handle_hint(s
, insn
, op1
, op2
, crm
);
1815 case 3: /* CLREX, DSB, DMB, ISB */
1816 handle_sync(s
, insn
, op1
, op2
, crm
);
1818 case 4: /* MSR (immediate) */
1819 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1822 unallocated_encoding(s
);
1827 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1830 /* Exception generation
1832 * 31 24 23 21 20 5 4 2 1 0
1833 * +-----------------+-----+------------------------+-----+----+
1834 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1835 * +-----------------------+------------------------+----------+
1837 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1839 int opc
= extract32(insn
, 21, 3);
1840 int op2_ll
= extract32(insn
, 0, 5);
1841 int imm16
= extract32(insn
, 5, 16);
1846 /* For SVC, HVC and SMC we advance the single-step state
1847 * machine before taking the exception. This is architecturally
1848 * mandated, to ensure that single-stepping a system call
1849 * instruction works properly.
1854 gen_exception_insn(s
, s
->base
.pc_next
, EXCP_SWI
,
1855 syn_aa64_svc(imm16
), default_exception_el(s
));
1858 if (s
->current_el
== 0) {
1859 unallocated_encoding(s
);
1862 /* The pre HVC helper handles cases when HVC gets trapped
1863 * as an undefined insn by runtime configuration.
1865 gen_a64_set_pc_im(s
->pc_curr
);
1866 gen_helper_pre_hvc(cpu_env
);
1868 gen_exception_insn(s
, s
->base
.pc_next
, EXCP_HVC
,
1869 syn_aa64_hvc(imm16
), 2);
1872 if (s
->current_el
== 0) {
1873 unallocated_encoding(s
);
1876 gen_a64_set_pc_im(s
->pc_curr
);
1877 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1878 gen_helper_pre_smc(cpu_env
, tmp
);
1879 tcg_temp_free_i32(tmp
);
1881 gen_exception_insn(s
, s
->base
.pc_next
, EXCP_SMC
,
1882 syn_aa64_smc(imm16
), 3);
1885 unallocated_encoding(s
);
1891 unallocated_encoding(s
);
1895 gen_exception_bkpt_insn(s
, syn_aa64_bkpt(imm16
));
1899 unallocated_encoding(s
);
1902 /* HLT. This has two purposes.
1903 * Architecturally, it is an external halting debug instruction.
1904 * Since QEMU doesn't implement external debug, we treat this as
1905 * it is required for halting debug disabled: it will UNDEF.
1906 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1908 if (semihosting_enabled() && imm16
== 0xf000) {
1909 #ifndef CONFIG_USER_ONLY
1910 /* In system mode, don't allow userspace access to semihosting,
1911 * to provide some semblance of security (and for consistency
1912 * with our 32-bit semihosting).
1914 if (s
->current_el
== 0) {
1915 unsupported_encoding(s
, insn
);
1919 gen_exception_internal_insn(s
, s
->base
.pc_next
, EXCP_SEMIHOST
);
1921 unsupported_encoding(s
, insn
);
1925 if (op2_ll
< 1 || op2_ll
> 3) {
1926 unallocated_encoding(s
);
1929 /* DCPS1, DCPS2, DCPS3 */
1930 unsupported_encoding(s
, insn
);
1933 unallocated_encoding(s
);
1938 /* Unconditional branch (register)
1939 * 31 25 24 21 20 16 15 10 9 5 4 0
1940 * +---------------+-------+-------+-------+------+-------+
1941 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1942 * +---------------+-------+-------+-------+------+-------+
1944 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1946 unsigned int opc
, op2
, op3
, rn
, op4
;
1947 unsigned btype_mod
= 2; /* 0: BR, 1: BLR, 2: other */
1951 opc
= extract32(insn
, 21, 4);
1952 op2
= extract32(insn
, 16, 5);
1953 op3
= extract32(insn
, 10, 6);
1954 rn
= extract32(insn
, 5, 5);
1955 op4
= extract32(insn
, 0, 5);
1958 goto do_unallocated
;
1970 goto do_unallocated
;
1972 dst
= cpu_reg(s
, rn
);
1977 if (!dc_isar_feature(aa64_pauth
, s
)) {
1978 goto do_unallocated
;
1982 if (rn
!= 0x1f || op4
!= 0x1f) {
1983 goto do_unallocated
;
1986 modifier
= cpu_X
[31];
1988 /* BRAAZ, BRABZ, BLRAAZ, BLRABZ */
1990 goto do_unallocated
;
1992 modifier
= new_tmp_a64_zero(s
);
1994 if (s
->pauth_active
) {
1995 dst
= new_tmp_a64(s
);
1997 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
1999 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2002 dst
= cpu_reg(s
, rn
);
2007 goto do_unallocated
;
2009 gen_a64_set_pc(s
, dst
);
2010 /* BLR also needs to load return address */
2012 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->base
.pc_next
);
2018 if (!dc_isar_feature(aa64_pauth
, s
)) {
2019 goto do_unallocated
;
2021 if ((op3
& ~1) != 2) {
2022 goto do_unallocated
;
2024 btype_mod
= opc
& 1;
2025 if (s
->pauth_active
) {
2026 dst
= new_tmp_a64(s
);
2027 modifier
= cpu_reg_sp(s
, op4
);
2029 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2031 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2034 dst
= cpu_reg(s
, rn
);
2036 gen_a64_set_pc(s
, dst
);
2037 /* BLRAA also needs to load return address */
2039 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->base
.pc_next
);
2044 if (s
->current_el
== 0) {
2045 goto do_unallocated
;
2050 goto do_unallocated
;
2052 dst
= tcg_temp_new_i64();
2053 tcg_gen_ld_i64(dst
, cpu_env
,
2054 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2057 case 2: /* ERETAA */
2058 case 3: /* ERETAB */
2059 if (!dc_isar_feature(aa64_pauth
, s
)) {
2060 goto do_unallocated
;
2062 if (rn
!= 0x1f || op4
!= 0x1f) {
2063 goto do_unallocated
;
2065 dst
= tcg_temp_new_i64();
2066 tcg_gen_ld_i64(dst
, cpu_env
,
2067 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2068 if (s
->pauth_active
) {
2069 modifier
= cpu_X
[31];
2071 gen_helper_autia(dst
, cpu_env
, dst
, modifier
);
2073 gen_helper_autib(dst
, cpu_env
, dst
, modifier
);
2079 goto do_unallocated
;
2081 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
2085 gen_helper_exception_return(cpu_env
, dst
);
2086 tcg_temp_free_i64(dst
);
2087 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
2090 /* Must exit loop to check un-masked IRQs */
2091 s
->base
.is_jmp
= DISAS_EXIT
;
2095 if (op3
!= 0 || op4
!= 0 || rn
!= 0x1f) {
2096 goto do_unallocated
;
2098 unsupported_encoding(s
, insn
);
2104 unallocated_encoding(s
);
2108 switch (btype_mod
) {
2110 if (dc_isar_feature(aa64_bti
, s
)) {
2111 /* BR to {x16,x17} or !guard -> 1, else 3. */
2112 set_btype(s
, rn
== 16 || rn
== 17 || !s
->guarded_page
? 1 : 3);
2117 if (dc_isar_feature(aa64_bti
, s
)) {
2118 /* BLR sets BTYPE to 2, regardless of source guarded page. */
2123 default: /* RET or none of the above. */
2124 /* BTYPE will be set to 0 by normal end-of-insn processing. */
2128 s
->base
.is_jmp
= DISAS_JUMP
;
2131 /* Branches, exception generating and system instructions */
2132 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
2134 switch (extract32(insn
, 25, 7)) {
2135 case 0x0a: case 0x0b:
2136 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
2137 disas_uncond_b_imm(s
, insn
);
2139 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
2140 disas_comp_b_imm(s
, insn
);
2142 case 0x1b: case 0x5b: /* Test & branch (immediate) */
2143 disas_test_b_imm(s
, insn
);
2145 case 0x2a: /* Conditional branch (immediate) */
2146 disas_cond_b_imm(s
, insn
);
2148 case 0x6a: /* Exception generation / System */
2149 if (insn
& (1 << 24)) {
2150 if (extract32(insn
, 22, 2) == 0) {
2151 disas_system(s
, insn
);
2153 unallocated_encoding(s
);
2159 case 0x6b: /* Unconditional branch (register) */
2160 disas_uncond_b_reg(s
, insn
);
2163 unallocated_encoding(s
);
2169 * Load/Store exclusive instructions are implemented by remembering
2170 * the value/address loaded, and seeing if these are the same
2171 * when the store is performed. This is not actually the architecturally
2172 * mandated semantics, but it works for typical guest code sequences
2173 * and avoids having to monitor regular stores.
2175 * The store exclusive uses the atomic cmpxchg primitives to avoid
2176 * races in multi-threaded linux-user and when MTTCG softmmu is
2179 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
2180 TCGv_i64 addr
, int size
, bool is_pair
)
2182 int idx
= get_mem_index(s
);
2183 TCGMemOp memop
= s
->be_data
;
2185 g_assert(size
<= 3);
2187 g_assert(size
>= 2);
2189 /* The pair must be single-copy atomic for the doubleword. */
2190 memop
|= MO_64
| MO_ALIGN
;
2191 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2192 if (s
->be_data
== MO_LE
) {
2193 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 0, 32);
2194 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 32, 32);
2196 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 32, 32);
2197 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 0, 32);
2200 /* The pair must be single-copy atomic for *each* doubleword, not
2201 the entire quadword, however it must be quadword aligned. */
2203 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
,
2204 memop
| MO_ALIGN_16
);
2206 TCGv_i64 addr2
= tcg_temp_new_i64();
2207 tcg_gen_addi_i64(addr2
, addr
, 8);
2208 tcg_gen_qemu_ld_i64(cpu_exclusive_high
, addr2
, idx
, memop
);
2209 tcg_temp_free_i64(addr2
);
2211 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2212 tcg_gen_mov_i64(cpu_reg(s
, rt2
), cpu_exclusive_high
);
2215 memop
|= size
| MO_ALIGN
;
2216 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2217 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2219 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
2222 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
2223 TCGv_i64 addr
, int size
, int is_pair
)
2225 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
2226 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
2229 * [addr + datasize] = {Rt2};
2235 * env->exclusive_addr = -1;
2237 TCGLabel
*fail_label
= gen_new_label();
2238 TCGLabel
*done_label
= gen_new_label();
2241 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
2243 tmp
= tcg_temp_new_i64();
2246 if (s
->be_data
== MO_LE
) {
2247 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2249 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt2
), cpu_reg(s
, rt
));
2251 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
,
2252 cpu_exclusive_val
, tmp
,
2254 MO_64
| MO_ALIGN
| s
->be_data
);
2255 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2256 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2257 if (!HAVE_CMPXCHG128
) {
2258 gen_helper_exit_atomic(cpu_env
);
2259 s
->base
.is_jmp
= DISAS_NORETURN
;
2260 } else if (s
->be_data
== MO_LE
) {
2261 gen_helper_paired_cmpxchg64_le_parallel(tmp
, cpu_env
,
2266 gen_helper_paired_cmpxchg64_be_parallel(tmp
, cpu_env
,
2271 } else if (s
->be_data
== MO_LE
) {
2272 gen_helper_paired_cmpxchg64_le(tmp
, cpu_env
, cpu_exclusive_addr
,
2273 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2275 gen_helper_paired_cmpxchg64_be(tmp
, cpu_env
, cpu_exclusive_addr
,
2276 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2279 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
, cpu_exclusive_val
,
2280 cpu_reg(s
, rt
), get_mem_index(s
),
2281 size
| MO_ALIGN
| s
->be_data
);
2282 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2284 tcg_gen_mov_i64(cpu_reg(s
, rd
), tmp
);
2285 tcg_temp_free_i64(tmp
);
2286 tcg_gen_br(done_label
);
2288 gen_set_label(fail_label
);
2289 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
2290 gen_set_label(done_label
);
2291 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
2294 static void gen_compare_and_swap(DisasContext
*s
, int rs
, int rt
,
2297 TCGv_i64 tcg_rs
= cpu_reg(s
, rs
);
2298 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2299 int memidx
= get_mem_index(s
);
2300 TCGv_i64 clean_addr
;
2303 gen_check_sp_alignment(s
);
2305 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2306 tcg_gen_atomic_cmpxchg_i64(tcg_rs
, clean_addr
, tcg_rs
, tcg_rt
, memidx
,
2307 size
| MO_ALIGN
| s
->be_data
);
2310 static void gen_compare_and_swap_pair(DisasContext
*s
, int rs
, int rt
,
2313 TCGv_i64 s1
= cpu_reg(s
, rs
);
2314 TCGv_i64 s2
= cpu_reg(s
, rs
+ 1);
2315 TCGv_i64 t1
= cpu_reg(s
, rt
);
2316 TCGv_i64 t2
= cpu_reg(s
, rt
+ 1);
2317 TCGv_i64 clean_addr
;
2318 int memidx
= get_mem_index(s
);
2321 gen_check_sp_alignment(s
);
2323 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2326 TCGv_i64 cmp
= tcg_temp_new_i64();
2327 TCGv_i64 val
= tcg_temp_new_i64();
2329 if (s
->be_data
== MO_LE
) {
2330 tcg_gen_concat32_i64(val
, t1
, t2
);
2331 tcg_gen_concat32_i64(cmp
, s1
, s2
);
2333 tcg_gen_concat32_i64(val
, t2
, t1
);
2334 tcg_gen_concat32_i64(cmp
, s2
, s1
);
2337 tcg_gen_atomic_cmpxchg_i64(cmp
, clean_addr
, cmp
, val
, memidx
,
2338 MO_64
| MO_ALIGN
| s
->be_data
);
2339 tcg_temp_free_i64(val
);
2341 if (s
->be_data
== MO_LE
) {
2342 tcg_gen_extr32_i64(s1
, s2
, cmp
);
2344 tcg_gen_extr32_i64(s2
, s1
, cmp
);
2346 tcg_temp_free_i64(cmp
);
2347 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2348 if (HAVE_CMPXCHG128
) {
2349 TCGv_i32 tcg_rs
= tcg_const_i32(rs
);
2350 if (s
->be_data
== MO_LE
) {
2351 gen_helper_casp_le_parallel(cpu_env
, tcg_rs
,
2352 clean_addr
, t1
, t2
);
2354 gen_helper_casp_be_parallel(cpu_env
, tcg_rs
,
2355 clean_addr
, t1
, t2
);
2357 tcg_temp_free_i32(tcg_rs
);
2359 gen_helper_exit_atomic(cpu_env
);
2360 s
->base
.is_jmp
= DISAS_NORETURN
;
2363 TCGv_i64 d1
= tcg_temp_new_i64();
2364 TCGv_i64 d2
= tcg_temp_new_i64();
2365 TCGv_i64 a2
= tcg_temp_new_i64();
2366 TCGv_i64 c1
= tcg_temp_new_i64();
2367 TCGv_i64 c2
= tcg_temp_new_i64();
2368 TCGv_i64 zero
= tcg_const_i64(0);
2370 /* Load the two words, in memory order. */
2371 tcg_gen_qemu_ld_i64(d1
, clean_addr
, memidx
,
2372 MO_64
| MO_ALIGN_16
| s
->be_data
);
2373 tcg_gen_addi_i64(a2
, clean_addr
, 8);
2374 tcg_gen_qemu_ld_i64(d2
, a2
, memidx
, MO_64
| s
->be_data
);
2376 /* Compare the two words, also in memory order. */
2377 tcg_gen_setcond_i64(TCG_COND_EQ
, c1
, d1
, s1
);
2378 tcg_gen_setcond_i64(TCG_COND_EQ
, c2
, d2
, s2
);
2379 tcg_gen_and_i64(c2
, c2
, c1
);
2381 /* If compare equal, write back new data, else write back old data. */
2382 tcg_gen_movcond_i64(TCG_COND_NE
, c1
, c2
, zero
, t1
, d1
);
2383 tcg_gen_movcond_i64(TCG_COND_NE
, c2
, c2
, zero
, t2
, d2
);
2384 tcg_gen_qemu_st_i64(c1
, clean_addr
, memidx
, MO_64
| s
->be_data
);
2385 tcg_gen_qemu_st_i64(c2
, a2
, memidx
, MO_64
| s
->be_data
);
2386 tcg_temp_free_i64(a2
);
2387 tcg_temp_free_i64(c1
);
2388 tcg_temp_free_i64(c2
);
2389 tcg_temp_free_i64(zero
);
2391 /* Write back the data from memory to Rs. */
2392 tcg_gen_mov_i64(s1
, d1
);
2393 tcg_gen_mov_i64(s2
, d2
);
2394 tcg_temp_free_i64(d1
);
2395 tcg_temp_free_i64(d2
);
2399 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2400 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2402 static bool disas_ldst_compute_iss_sf(int size
, bool is_signed
, int opc
)
2404 int opc0
= extract32(opc
, 0, 1);
2408 regsize
= opc0
? 32 : 64;
2410 regsize
= size
== 3 ? 64 : 32;
2412 return regsize
== 64;
2415 /* Load/store exclusive
2417 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2418 * +-----+-------------+----+---+----+------+----+-------+------+------+
2419 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2420 * +-----+-------------+----+---+----+------+----+-------+------+------+
2422 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2423 * L: 0 -> store, 1 -> load
2424 * o2: 0 -> exclusive, 1 -> not
2425 * o1: 0 -> single register, 1 -> register pair
2426 * o0: 1 -> load-acquire/store-release, 0 -> not
2428 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
2430 int rt
= extract32(insn
, 0, 5);
2431 int rn
= extract32(insn
, 5, 5);
2432 int rt2
= extract32(insn
, 10, 5);
2433 int rs
= extract32(insn
, 16, 5);
2434 int is_lasr
= extract32(insn
, 15, 1);
2435 int o2_L_o1_o0
= extract32(insn
, 21, 3) * 2 | is_lasr
;
2436 int size
= extract32(insn
, 30, 2);
2437 TCGv_i64 clean_addr
;
2439 switch (o2_L_o1_o0
) {
2440 case 0x0: /* STXR */
2441 case 0x1: /* STLXR */
2443 gen_check_sp_alignment(s
);
2446 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2448 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2449 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, false);
2452 case 0x4: /* LDXR */
2453 case 0x5: /* LDAXR */
2455 gen_check_sp_alignment(s
);
2457 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2459 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, false);
2461 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2465 case 0x8: /* STLLR */
2466 if (!dc_isar_feature(aa64_lor
, s
)) {
2469 /* StoreLORelease is the same as Store-Release for QEMU. */
2471 case 0x9: /* STLR */
2472 /* Generate ISS for non-exclusive accesses including LASR. */
2474 gen_check_sp_alignment(s
);
2476 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2477 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2478 do_gpr_st(s
, cpu_reg(s
, rt
), clean_addr
, size
, true, rt
,
2479 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2482 case 0xc: /* LDLAR */
2483 if (!dc_isar_feature(aa64_lor
, s
)) {
2486 /* LoadLOAcquire is the same as Load-Acquire for QEMU. */
2488 case 0xd: /* LDAR */
2489 /* Generate ISS for non-exclusive accesses including LASR. */
2491 gen_check_sp_alignment(s
);
2493 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2494 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, size
, false, false, true, rt
,
2495 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2496 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2499 case 0x2: case 0x3: /* CASP / STXP */
2500 if (size
& 2) { /* STXP / STLXP */
2502 gen_check_sp_alignment(s
);
2505 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2507 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2508 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, true);
2512 && ((rt
| rs
) & 1) == 0
2513 && dc_isar_feature(aa64_atomics
, s
)) {
2515 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2520 case 0x6: case 0x7: /* CASPA / LDXP */
2521 if (size
& 2) { /* LDXP / LDAXP */
2523 gen_check_sp_alignment(s
);
2525 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2527 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, true);
2529 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2534 && ((rt
| rs
) & 1) == 0
2535 && dc_isar_feature(aa64_atomics
, s
)) {
2536 /* CASPA / CASPAL */
2537 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2543 case 0xb: /* CASL */
2544 case 0xe: /* CASA */
2545 case 0xf: /* CASAL */
2546 if (rt2
== 31 && dc_isar_feature(aa64_atomics
, s
)) {
2547 gen_compare_and_swap(s
, rs
, rt
, rn
, size
);
2552 unallocated_encoding(s
);
2556 * Load register (literal)
2558 * 31 30 29 27 26 25 24 23 5 4 0
2559 * +-----+-------+---+-----+-------------------+-------+
2560 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2561 * +-----+-------+---+-----+-------------------+-------+
2563 * V: 1 -> vector (simd/fp)
2564 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2565 * 10-> 32 bit signed, 11 -> prefetch
2566 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2568 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
2570 int rt
= extract32(insn
, 0, 5);
2571 int64_t imm
= sextract32(insn
, 5, 19) << 2;
2572 bool is_vector
= extract32(insn
, 26, 1);
2573 int opc
= extract32(insn
, 30, 2);
2574 bool is_signed
= false;
2576 TCGv_i64 tcg_rt
, clean_addr
;
2580 unallocated_encoding(s
);
2584 if (!fp_access_check(s
)) {
2589 /* PRFM (literal) : prefetch */
2592 size
= 2 + extract32(opc
, 0, 1);
2593 is_signed
= extract32(opc
, 1, 1);
2596 tcg_rt
= cpu_reg(s
, rt
);
2598 clean_addr
= tcg_const_i64(s
->pc_curr
+ imm
);
2600 do_fp_ld(s
, rt
, clean_addr
, size
);
2602 /* Only unsigned 32bit loads target 32bit registers. */
2603 bool iss_sf
= opc
!= 0;
2605 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, is_signed
, false,
2606 true, rt
, iss_sf
, false);
2608 tcg_temp_free_i64(clean_addr
);
2612 * LDNP (Load Pair - non-temporal hint)
2613 * LDP (Load Pair - non vector)
2614 * LDPSW (Load Pair Signed Word - non vector)
2615 * STNP (Store Pair - non-temporal hint)
2616 * STP (Store Pair - non vector)
2617 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2618 * LDP (Load Pair of SIMD&FP)
2619 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2620 * STP (Store Pair of SIMD&FP)
2622 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2623 * +-----+-------+---+---+-------+---+-----------------------------+
2624 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2625 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2627 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2629 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2630 * V: 0 -> GPR, 1 -> Vector
2631 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2632 * 10 -> signed offset, 11 -> pre-index
2633 * L: 0 -> Store 1 -> Load
2635 * Rt, Rt2 = GPR or SIMD registers to be stored
2636 * Rn = general purpose register containing address
2637 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2639 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
2641 int rt
= extract32(insn
, 0, 5);
2642 int rn
= extract32(insn
, 5, 5);
2643 int rt2
= extract32(insn
, 10, 5);
2644 uint64_t offset
= sextract64(insn
, 15, 7);
2645 int index
= extract32(insn
, 23, 2);
2646 bool is_vector
= extract32(insn
, 26, 1);
2647 bool is_load
= extract32(insn
, 22, 1);
2648 int opc
= extract32(insn
, 30, 2);
2650 bool is_signed
= false;
2651 bool postindex
= false;
2654 TCGv_i64 clean_addr
, dirty_addr
;
2659 unallocated_encoding(s
);
2666 size
= 2 + extract32(opc
, 1, 1);
2667 is_signed
= extract32(opc
, 0, 1);
2668 if (!is_load
&& is_signed
) {
2669 unallocated_encoding(s
);
2675 case 1: /* post-index */
2680 /* signed offset with "non-temporal" hint. Since we don't emulate
2681 * caches we don't care about hints to the cache system about
2682 * data access patterns, and handle this identically to plain
2686 /* There is no non-temporal-hint version of LDPSW */
2687 unallocated_encoding(s
);
2692 case 2: /* signed offset, rn not updated */
2695 case 3: /* pre-index */
2701 if (is_vector
&& !fp_access_check(s
)) {
2708 gen_check_sp_alignment(s
);
2711 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
2713 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
2715 clean_addr
= clean_data_tbi(s
, dirty_addr
);
2719 do_fp_ld(s
, rt
, clean_addr
, size
);
2721 do_fp_st(s
, rt
, clean_addr
, size
);
2723 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2725 do_fp_ld(s
, rt2
, clean_addr
, size
);
2727 do_fp_st(s
, rt2
, clean_addr
, size
);
2730 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2731 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2734 TCGv_i64 tmp
= tcg_temp_new_i64();
2736 /* Do not modify tcg_rt before recognizing any exception
2737 * from the second load.
2739 do_gpr_ld(s
, tmp
, clean_addr
, size
, is_signed
, false,
2740 false, 0, false, false);
2741 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2742 do_gpr_ld(s
, tcg_rt2
, clean_addr
, size
, is_signed
, false,
2743 false, 0, false, false);
2745 tcg_gen_mov_i64(tcg_rt
, tmp
);
2746 tcg_temp_free_i64(tmp
);
2748 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
2749 false, 0, false, false);
2750 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2751 do_gpr_st(s
, tcg_rt2
, clean_addr
, size
,
2752 false, 0, false, false);
2758 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
2760 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
2765 * Load/store (immediate post-indexed)
2766 * Load/store (immediate pre-indexed)
2767 * Load/store (unscaled immediate)
2769 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2770 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2771 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2772 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2774 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2776 * V = 0 -> non-vector
2777 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2778 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2780 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
2786 int rn
= extract32(insn
, 5, 5);
2787 int imm9
= sextract32(insn
, 12, 9);
2788 int idx
= extract32(insn
, 10, 2);
2789 bool is_signed
= false;
2790 bool is_store
= false;
2791 bool is_extended
= false;
2792 bool is_unpriv
= (idx
== 2);
2793 bool iss_valid
= !is_vector
;
2797 TCGv_i64 clean_addr
, dirty_addr
;
2800 size
|= (opc
& 2) << 1;
2801 if (size
> 4 || is_unpriv
) {
2802 unallocated_encoding(s
);
2805 is_store
= ((opc
& 1) == 0);
2806 if (!fp_access_check(s
)) {
2810 if (size
== 3 && opc
== 2) {
2811 /* PRFM - prefetch */
2813 unallocated_encoding(s
);
2818 if (opc
== 3 && size
> 1) {
2819 unallocated_encoding(s
);
2822 is_store
= (opc
== 0);
2823 is_signed
= extract32(opc
, 1, 1);
2824 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2842 g_assert_not_reached();
2846 gen_check_sp_alignment(s
);
2849 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
2851 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
2853 clean_addr
= clean_data_tbi(s
, dirty_addr
);
2857 do_fp_st(s
, rt
, clean_addr
, size
);
2859 do_fp_ld(s
, rt
, clean_addr
, size
);
2862 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2863 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2864 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2867 do_gpr_st_memidx(s
, tcg_rt
, clean_addr
, size
, memidx
,
2868 iss_valid
, rt
, iss_sf
, false);
2870 do_gpr_ld_memidx(s
, tcg_rt
, clean_addr
, size
,
2871 is_signed
, is_extended
, memidx
,
2872 iss_valid
, rt
, iss_sf
, false);
2877 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2879 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
2881 tcg_gen_mov_i64(tcg_rn
, dirty_addr
);
2886 * Load/store (register offset)
2888 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2889 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2890 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2891 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2894 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2895 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2897 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2898 * opc<0>: 0 -> store, 1 -> load
2899 * V: 1 -> vector/simd
2900 * opt: extend encoding (see DecodeRegExtend)
2901 * S: if S=1 then scale (essentially index by sizeof(size))
2902 * Rt: register to transfer into/out of
2903 * Rn: address register or SP for base
2904 * Rm: offset register or ZR for offset
2906 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
2912 int rn
= extract32(insn
, 5, 5);
2913 int shift
= extract32(insn
, 12, 1);
2914 int rm
= extract32(insn
, 16, 5);
2915 int opt
= extract32(insn
, 13, 3);
2916 bool is_signed
= false;
2917 bool is_store
= false;
2918 bool is_extended
= false;
2920 TCGv_i64 tcg_rm
, clean_addr
, dirty_addr
;
2922 if (extract32(opt
, 1, 1) == 0) {
2923 unallocated_encoding(s
);
2928 size
|= (opc
& 2) << 1;
2930 unallocated_encoding(s
);
2933 is_store
= !extract32(opc
, 0, 1);
2934 if (!fp_access_check(s
)) {
2938 if (size
== 3 && opc
== 2) {
2939 /* PRFM - prefetch */
2942 if (opc
== 3 && size
> 1) {
2943 unallocated_encoding(s
);
2946 is_store
= (opc
== 0);
2947 is_signed
= extract32(opc
, 1, 1);
2948 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2952 gen_check_sp_alignment(s
);
2954 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
2956 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2957 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2959 tcg_gen_add_i64(dirty_addr
, dirty_addr
, tcg_rm
);
2960 clean_addr
= clean_data_tbi(s
, dirty_addr
);
2964 do_fp_st(s
, rt
, clean_addr
, size
);
2966 do_fp_ld(s
, rt
, clean_addr
, size
);
2969 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2970 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2972 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
2973 true, rt
, iss_sf
, false);
2975 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
,
2976 is_signed
, is_extended
,
2977 true, rt
, iss_sf
, false);
2983 * Load/store (unsigned immediate)
2985 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2986 * +----+-------+---+-----+-----+------------+-------+------+
2987 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2988 * +----+-------+---+-----+-----+------------+-------+------+
2991 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2992 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2994 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2995 * opc<0>: 0 -> store, 1 -> load
2996 * Rn: base address register (inc SP)
2997 * Rt: target register
2999 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
3005 int rn
= extract32(insn
, 5, 5);
3006 unsigned int imm12
= extract32(insn
, 10, 12);
3007 unsigned int offset
;
3009 TCGv_i64 clean_addr
, dirty_addr
;
3012 bool is_signed
= false;
3013 bool is_extended
= false;
3016 size
|= (opc
& 2) << 1;
3018 unallocated_encoding(s
);
3021 is_store
= !extract32(opc
, 0, 1);
3022 if (!fp_access_check(s
)) {
3026 if (size
== 3 && opc
== 2) {
3027 /* PRFM - prefetch */
3030 if (opc
== 3 && size
> 1) {
3031 unallocated_encoding(s
);
3034 is_store
= (opc
== 0);
3035 is_signed
= extract32(opc
, 1, 1);
3036 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3040 gen_check_sp_alignment(s
);
3042 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3043 offset
= imm12
<< size
;
3044 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3045 clean_addr
= clean_data_tbi(s
, dirty_addr
);
3049 do_fp_st(s
, rt
, clean_addr
, size
);
3051 do_fp_ld(s
, rt
, clean_addr
, size
);
3054 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3055 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3057 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3058 true, rt
, iss_sf
, false);
3060 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, is_signed
, is_extended
,
3061 true, rt
, iss_sf
, false);
3066 /* Atomic memory operations
3068 * 31 30 27 26 24 22 21 16 15 12 10 5 0
3069 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
3070 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
3071 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
3073 * Rt: the result register
3074 * Rn: base address or SP
3075 * Rs: the source register for the operation
3076 * V: vector flag (always 0 as of v8.3)
3080 static void disas_ldst_atomic(DisasContext
*s
, uint32_t insn
,
3081 int size
, int rt
, bool is_vector
)
3083 int rs
= extract32(insn
, 16, 5);
3084 int rn
= extract32(insn
, 5, 5);
3085 int o3_opc
= extract32(insn
, 12, 4);
3086 TCGv_i64 tcg_rs
, clean_addr
;
3087 AtomicThreeOpFn
*fn
;
3089 if (is_vector
|| !dc_isar_feature(aa64_atomics
, s
)) {
3090 unallocated_encoding(s
);
3094 case 000: /* LDADD */
3095 fn
= tcg_gen_atomic_fetch_add_i64
;
3097 case 001: /* LDCLR */
3098 fn
= tcg_gen_atomic_fetch_and_i64
;
3100 case 002: /* LDEOR */
3101 fn
= tcg_gen_atomic_fetch_xor_i64
;
3103 case 003: /* LDSET */
3104 fn
= tcg_gen_atomic_fetch_or_i64
;
3106 case 004: /* LDSMAX */
3107 fn
= tcg_gen_atomic_fetch_smax_i64
;
3109 case 005: /* LDSMIN */
3110 fn
= tcg_gen_atomic_fetch_smin_i64
;
3112 case 006: /* LDUMAX */
3113 fn
= tcg_gen_atomic_fetch_umax_i64
;
3115 case 007: /* LDUMIN */
3116 fn
= tcg_gen_atomic_fetch_umin_i64
;
3119 fn
= tcg_gen_atomic_xchg_i64
;
3122 unallocated_encoding(s
);
3127 gen_check_sp_alignment(s
);
3129 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
3130 tcg_rs
= read_cpu_reg(s
, rs
, true);
3132 if (o3_opc
== 1) { /* LDCLR */
3133 tcg_gen_not_i64(tcg_rs
, tcg_rs
);
3136 /* The tcg atomic primitives are all full barriers. Therefore we
3137 * can ignore the Acquire and Release bits of this instruction.
3139 fn(cpu_reg(s
, rt
), clean_addr
, tcg_rs
, get_mem_index(s
),
3140 s
->be_data
| size
| MO_ALIGN
);
3144 * PAC memory operations
3146 * 31 30 27 26 24 22 21 12 11 10 5 0
3147 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3148 * | size | 1 1 1 | V | 0 0 | M S | 1 | imm9 | W | 1 | Rn | Rt |
3149 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3151 * Rt: the result register
3152 * Rn: base address or SP
3153 * V: vector flag (always 0 as of v8.3)
3154 * M: clear for key DA, set for key DB
3155 * W: pre-indexing flag
3158 static void disas_ldst_pac(DisasContext
*s
, uint32_t insn
,
3159 int size
, int rt
, bool is_vector
)
3161 int rn
= extract32(insn
, 5, 5);
3162 bool is_wback
= extract32(insn
, 11, 1);
3163 bool use_key_a
= !extract32(insn
, 23, 1);
3165 TCGv_i64 clean_addr
, dirty_addr
, tcg_rt
;
3167 if (size
!= 3 || is_vector
|| !dc_isar_feature(aa64_pauth
, s
)) {
3168 unallocated_encoding(s
);
3173 gen_check_sp_alignment(s
);
3175 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3177 if (s
->pauth_active
) {
3179 gen_helper_autda(dirty_addr
, cpu_env
, dirty_addr
, cpu_X
[31]);
3181 gen_helper_autdb(dirty_addr
, cpu_env
, dirty_addr
, cpu_X
[31]);
3185 /* Form the 10-bit signed, scaled offset. */
3186 offset
= (extract32(insn
, 22, 1) << 9) | extract32(insn
, 12, 9);
3187 offset
= sextract32(offset
<< size
, 0, 10 + size
);
3188 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3190 /* Note that "clean" and "dirty" here refer to TBI not PAC. */
3191 clean_addr
= clean_data_tbi(s
, dirty_addr
);
3193 tcg_rt
= cpu_reg(s
, rt
);
3194 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, /* is_signed */ false,
3195 /* extend */ false, /* iss_valid */ !is_wback
,
3196 /* iss_srt */ rt
, /* iss_sf */ true, /* iss_ar */ false);
3199 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
3203 /* Load/store register (all forms) */
3204 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
3206 int rt
= extract32(insn
, 0, 5);
3207 int opc
= extract32(insn
, 22, 2);
3208 bool is_vector
= extract32(insn
, 26, 1);
3209 int size
= extract32(insn
, 30, 2);
3211 switch (extract32(insn
, 24, 2)) {
3213 if (extract32(insn
, 21, 1) == 0) {
3214 /* Load/store register (unscaled immediate)
3215 * Load/store immediate pre/post-indexed
3216 * Load/store register unprivileged
3218 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
3221 switch (extract32(insn
, 10, 2)) {
3223 disas_ldst_atomic(s
, insn
, size
, rt
, is_vector
);
3226 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
3229 disas_ldst_pac(s
, insn
, size
, rt
, is_vector
);
3234 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
3237 unallocated_encoding(s
);
3240 /* AdvSIMD load/store multiple structures
3242 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
3243 * +---+---+---------------+---+-------------+--------+------+------+------+
3244 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
3245 * +---+---+---------------+---+-------------+--------+------+------+------+
3247 * AdvSIMD load/store multiple structures (post-indexed)
3249 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
3250 * +---+---+---------------+---+---+---------+--------+------+------+------+
3251 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
3252 * +---+---+---------------+---+---+---------+--------+------+------+------+
3254 * Rt: first (or only) SIMD&FP register to be transferred
3255 * Rn: base address or SP
3256 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3258 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
3260 int rt
= extract32(insn
, 0, 5);
3261 int rn
= extract32(insn
, 5, 5);
3262 int rm
= extract32(insn
, 16, 5);
3263 int size
= extract32(insn
, 10, 2);
3264 int opcode
= extract32(insn
, 12, 4);
3265 bool is_store
= !extract32(insn
, 22, 1);
3266 bool is_postidx
= extract32(insn
, 23, 1);
3267 bool is_q
= extract32(insn
, 30, 1);
3268 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3269 TCGMemOp endian
= s
->be_data
;
3271 int ebytes
; /* bytes per element */
3272 int elements
; /* elements per vector */
3273 int rpt
; /* num iterations */
3274 int selem
; /* structure elements */
3277 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
3278 unallocated_encoding(s
);
3282 if (!is_postidx
&& rm
!= 0) {
3283 unallocated_encoding(s
);
3287 /* From the shared decode logic */
3318 unallocated_encoding(s
);
3322 if (size
== 3 && !is_q
&& selem
!= 1) {
3324 unallocated_encoding(s
);
3328 if (!fp_access_check(s
)) {
3333 gen_check_sp_alignment(s
);
3336 /* For our purposes, bytes are always little-endian. */
3341 /* Consecutive little-endian elements from a single register
3342 * can be promoted to a larger little-endian operation.
3344 if (selem
== 1 && endian
== MO_LE
) {
3348 elements
= (is_q
? 16 : 8) / ebytes
;
3350 tcg_rn
= cpu_reg_sp(s
, rn
);
3351 clean_addr
= clean_data_tbi(s
, tcg_rn
);
3352 tcg_ebytes
= tcg_const_i64(ebytes
);
3354 for (r
= 0; r
< rpt
; r
++) {
3356 for (e
= 0; e
< elements
; e
++) {
3358 for (xs
= 0; xs
< selem
; xs
++) {
3359 int tt
= (rt
+ r
+ xs
) % 32;
3361 do_vec_st(s
, tt
, e
, clean_addr
, size
, endian
);
3363 do_vec_ld(s
, tt
, e
, clean_addr
, size
, endian
);
3365 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
3369 tcg_temp_free_i64(tcg_ebytes
);
3372 /* For non-quad operations, setting a slice of the low
3373 * 64 bits of the register clears the high 64 bits (in
3374 * the ARM ARM pseudocode this is implicit in the fact
3375 * that 'rval' is a 64 bit wide variable).
3376 * For quad operations, we might still need to zero the
3379 for (r
= 0; r
< rpt
* selem
; r
++) {
3380 int tt
= (rt
+ r
) % 32;
3381 clear_vec_high(s
, is_q
, tt
);
3387 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, rpt
* elements
* selem
* ebytes
);
3389 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3394 /* AdvSIMD load/store single structure
3396 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3397 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3398 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3399 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3401 * AdvSIMD load/store single structure (post-indexed)
3403 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3404 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3405 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3406 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3408 * Rt: first (or only) SIMD&FP register to be transferred
3409 * Rn: base address or SP
3410 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3411 * index = encoded in Q:S:size dependent on size
3413 * lane_size = encoded in R, opc
3414 * transfer width = encoded in opc, S, size
3416 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
3418 int rt
= extract32(insn
, 0, 5);
3419 int rn
= extract32(insn
, 5, 5);
3420 int rm
= extract32(insn
, 16, 5);
3421 int size
= extract32(insn
, 10, 2);
3422 int S
= extract32(insn
, 12, 1);
3423 int opc
= extract32(insn
, 13, 3);
3424 int R
= extract32(insn
, 21, 1);
3425 int is_load
= extract32(insn
, 22, 1);
3426 int is_postidx
= extract32(insn
, 23, 1);
3427 int is_q
= extract32(insn
, 30, 1);
3429 int scale
= extract32(opc
, 1, 2);
3430 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
3431 bool replicate
= false;
3432 int index
= is_q
<< 3 | S
<< 2 | size
;
3434 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3436 if (extract32(insn
, 31, 1)) {
3437 unallocated_encoding(s
);
3440 if (!is_postidx
&& rm
!= 0) {
3441 unallocated_encoding(s
);
3447 if (!is_load
|| S
) {
3448 unallocated_encoding(s
);
3457 if (extract32(size
, 0, 1)) {
3458 unallocated_encoding(s
);
3464 if (extract32(size
, 1, 1)) {
3465 unallocated_encoding(s
);
3468 if (!extract32(size
, 0, 1)) {
3472 unallocated_encoding(s
);
3480 g_assert_not_reached();
3483 if (!fp_access_check(s
)) {
3487 ebytes
= 1 << scale
;
3490 gen_check_sp_alignment(s
);
3493 tcg_rn
= cpu_reg_sp(s
, rn
);
3494 clean_addr
= clean_data_tbi(s
, tcg_rn
);
3495 tcg_ebytes
= tcg_const_i64(ebytes
);
3497 for (xs
= 0; xs
< selem
; xs
++) {
3499 /* Load and replicate to all elements */
3500 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3502 tcg_gen_qemu_ld_i64(tcg_tmp
, clean_addr
,
3503 get_mem_index(s
), s
->be_data
+ scale
);
3504 tcg_gen_gvec_dup_i64(scale
, vec_full_reg_offset(s
, rt
),
3505 (is_q
+ 1) * 8, vec_full_reg_size(s
),
3507 tcg_temp_free_i64(tcg_tmp
);
3509 /* Load/store one element per register */
3511 do_vec_ld(s
, rt
, index
, clean_addr
, scale
, s
->be_data
);
3513 do_vec_st(s
, rt
, index
, clean_addr
, scale
, s
->be_data
);
3516 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
3519 tcg_temp_free_i64(tcg_ebytes
);
3523 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, selem
* ebytes
);
3525 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3530 /* Loads and stores */
3531 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
3533 switch (extract32(insn
, 24, 6)) {
3534 case 0x08: /* Load/store exclusive */
3535 disas_ldst_excl(s
, insn
);
3537 case 0x18: case 0x1c: /* Load register (literal) */
3538 disas_ld_lit(s
, insn
);
3540 case 0x28: case 0x29:
3541 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
3542 disas_ldst_pair(s
, insn
);
3544 case 0x38: case 0x39:
3545 case 0x3c: case 0x3d: /* Load/store register (all forms) */
3546 disas_ldst_reg(s
, insn
);
3548 case 0x0c: /* AdvSIMD load/store multiple structures */
3549 disas_ldst_multiple_struct(s
, insn
);
3551 case 0x0d: /* AdvSIMD load/store single structure */
3552 disas_ldst_single_struct(s
, insn
);
3555 unallocated_encoding(s
);
3560 /* PC-rel. addressing
3561 * 31 30 29 28 24 23 5 4 0
3562 * +----+-------+-----------+-------------------+------+
3563 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
3564 * +----+-------+-----------+-------------------+------+
3566 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
3568 unsigned int page
, rd
;
3572 page
= extract32(insn
, 31, 1);
3573 /* SignExtend(immhi:immlo) -> offset */
3574 offset
= sextract64(insn
, 5, 19);
3575 offset
= offset
<< 2 | extract32(insn
, 29, 2);
3576 rd
= extract32(insn
, 0, 5);
3580 /* ADRP (page based) */
3585 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
3589 * Add/subtract (immediate)
3591 * 31 30 29 28 24 23 22 21 10 9 5 4 0
3592 * +--+--+--+-----------+-----+-------------+-----+-----+
3593 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
3594 * +--+--+--+-----------+-----+-------------+-----+-----+
3596 * sf: 0 -> 32bit, 1 -> 64bit
3597 * op: 0 -> add , 1 -> sub
3599 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
3601 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
3603 int rd
= extract32(insn
, 0, 5);
3604 int rn
= extract32(insn
, 5, 5);
3605 uint64_t imm
= extract32(insn
, 10, 12);
3606 int shift
= extract32(insn
, 22, 2);
3607 bool setflags
= extract32(insn
, 29, 1);
3608 bool sub_op
= extract32(insn
, 30, 1);
3609 bool is_64bit
= extract32(insn
, 31, 1);
3611 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
3612 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
3613 TCGv_i64 tcg_result
;
3622 unallocated_encoding(s
);
3626 tcg_result
= tcg_temp_new_i64();
3629 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
3631 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
3634 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
3636 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3638 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3640 tcg_temp_free_i64(tcg_imm
);
3644 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3646 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3649 tcg_temp_free_i64(tcg_result
);
3652 /* The input should be a value in the bottom e bits (with higher
3653 * bits zero); returns that value replicated into every element
3654 * of size e in a 64 bit integer.
3656 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
3666 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
3667 static inline uint64_t bitmask64(unsigned int length
)
3669 assert(length
> 0 && length
<= 64);
3670 return ~0ULL >> (64 - length
);
3673 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
3674 * only require the wmask. Returns false if the imms/immr/immn are a reserved
3675 * value (ie should cause a guest UNDEF exception), and true if they are
3676 * valid, in which case the decoded bit pattern is written to result.
3678 bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
3679 unsigned int imms
, unsigned int immr
)
3682 unsigned e
, levels
, s
, r
;
3685 assert(immn
< 2 && imms
< 64 && immr
< 64);
3687 /* The bit patterns we create here are 64 bit patterns which
3688 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
3689 * 64 bits each. Each element contains the same value: a run
3690 * of between 1 and e-1 non-zero bits, rotated within the
3691 * element by between 0 and e-1 bits.
3693 * The element size and run length are encoded into immn (1 bit)
3694 * and imms (6 bits) as follows:
3695 * 64 bit elements: immn = 1, imms = <length of run - 1>
3696 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
3697 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
3698 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
3699 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
3700 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
3701 * Notice that immn = 0, imms = 11111x is the only combination
3702 * not covered by one of the above options; this is reserved.
3703 * Further, <length of run - 1> all-ones is a reserved pattern.
3705 * In all cases the rotation is by immr % e (and immr is 6 bits).
3708 /* First determine the element size */
3709 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
3711 /* This is the immn == 0, imms == 0x11111x case */
3721 /* <length of run - 1> mustn't be all-ones. */
3725 /* Create the value of one element: s+1 set bits rotated
3726 * by r within the element (which is e bits wide)...
3728 mask
= bitmask64(s
+ 1);
3730 mask
= (mask
>> r
) | (mask
<< (e
- r
));
3731 mask
&= bitmask64(e
);
3733 /* ...then replicate the element over the whole 64 bit value */
3734 mask
= bitfield_replicate(mask
, e
);
3739 /* Logical (immediate)
3740 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3741 * +----+-----+-------------+---+------+------+------+------+
3742 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
3743 * +----+-----+-------------+---+------+------+------+------+
3745 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
3747 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
3748 TCGv_i64 tcg_rd
, tcg_rn
;
3750 bool is_and
= false;
3752 sf
= extract32(insn
, 31, 1);
3753 opc
= extract32(insn
, 29, 2);
3754 is_n
= extract32(insn
, 22, 1);
3755 immr
= extract32(insn
, 16, 6);
3756 imms
= extract32(insn
, 10, 6);
3757 rn
= extract32(insn
, 5, 5);
3758 rd
= extract32(insn
, 0, 5);
3761 unallocated_encoding(s
);
3765 if (opc
== 0x3) { /* ANDS */
3766 tcg_rd
= cpu_reg(s
, rd
);
3768 tcg_rd
= cpu_reg_sp(s
, rd
);
3770 tcg_rn
= cpu_reg(s
, rn
);
3772 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
3773 /* some immediate field values are reserved */
3774 unallocated_encoding(s
);
3779 wmask
&= 0xffffffff;
3783 case 0x3: /* ANDS */
3785 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
3789 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
3792 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
3795 assert(FALSE
); /* must handle all above */
3799 if (!sf
&& !is_and
) {
3800 /* zero extend final result; we know we can skip this for AND
3801 * since the immediate had the high 32 bits clear.
3803 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3806 if (opc
== 3) { /* ANDS */
3807 gen_logic_CC(sf
, tcg_rd
);
3812 * Move wide (immediate)
3814 * 31 30 29 28 23 22 21 20 5 4 0
3815 * +--+-----+-------------+-----+----------------+------+
3816 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
3817 * +--+-----+-------------+-----+----------------+------+
3819 * sf: 0 -> 32 bit, 1 -> 64 bit
3820 * opc: 00 -> N, 10 -> Z, 11 -> K
3821 * hw: shift/16 (0,16, and sf only 32, 48)
3823 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
3825 int rd
= extract32(insn
, 0, 5);
3826 uint64_t imm
= extract32(insn
, 5, 16);
3827 int sf
= extract32(insn
, 31, 1);
3828 int opc
= extract32(insn
, 29, 2);
3829 int pos
= extract32(insn
, 21, 2) << 4;
3830 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3833 if (!sf
&& (pos
>= 32)) {
3834 unallocated_encoding(s
);
3848 tcg_gen_movi_i64(tcg_rd
, imm
);
3851 tcg_imm
= tcg_const_i64(imm
);
3852 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
3853 tcg_temp_free_i64(tcg_imm
);
3855 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3859 unallocated_encoding(s
);
3865 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3866 * +----+-----+-------------+---+------+------+------+------+
3867 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3868 * +----+-----+-------------+---+------+------+------+------+
3870 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
3872 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
3873 TCGv_i64 tcg_rd
, tcg_tmp
;
3875 sf
= extract32(insn
, 31, 1);
3876 opc
= extract32(insn
, 29, 2);
3877 n
= extract32(insn
, 22, 1);
3878 ri
= extract32(insn
, 16, 6);
3879 si
= extract32(insn
, 10, 6);
3880 rn
= extract32(insn
, 5, 5);
3881 rd
= extract32(insn
, 0, 5);
3882 bitsize
= sf
? 64 : 32;
3884 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
3885 unallocated_encoding(s
);
3889 tcg_rd
= cpu_reg(s
, rd
);
3891 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3892 to be smaller than bitsize, we'll never reference data outside the
3893 low 32-bits anyway. */
3894 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
3896 /* Recognize simple(r) extractions. */
3898 /* Wd<s-r:0> = Wn<s:r> */
3899 len
= (si
- ri
) + 1;
3900 if (opc
== 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
3901 tcg_gen_sextract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3903 } else if (opc
== 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
3904 tcg_gen_extract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3907 /* opc == 1, BFXIL fall through to deposit */
3908 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
3911 /* Handle the ri > si case with a deposit
3912 * Wd<32+s-r,32-r> = Wn<s:0>
3915 pos
= (bitsize
- ri
) & (bitsize
- 1);
3918 if (opc
== 0 && len
< ri
) {
3919 /* SBFM: sign extend the destination field from len to fill
3920 the balance of the word. Let the deposit below insert all
3921 of those sign bits. */
3922 tcg_gen_sextract_i64(tcg_tmp
, tcg_tmp
, 0, len
);
3926 if (opc
== 1) { /* BFM, BFXIL */
3927 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
3929 /* SBFM or UBFM: We start with zero, and we haven't modified
3930 any bits outside bitsize, therefore the zero-extension
3931 below is unneeded. */
3932 tcg_gen_deposit_z_i64(tcg_rd
, tcg_tmp
, pos
, len
);
3937 if (!sf
) { /* zero extend final result */
3938 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3943 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3944 * +----+------+-------------+---+----+------+--------+------+------+
3945 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3946 * +----+------+-------------+---+----+------+--------+------+------+
3948 static void disas_extract(DisasContext
*s
, uint32_t insn
)
3950 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
3952 sf
= extract32(insn
, 31, 1);
3953 n
= extract32(insn
, 22, 1);
3954 rm
= extract32(insn
, 16, 5);
3955 imm
= extract32(insn
, 10, 6);
3956 rn
= extract32(insn
, 5, 5);
3957 rd
= extract32(insn
, 0, 5);
3958 op21
= extract32(insn
, 29, 2);
3959 op0
= extract32(insn
, 21, 1);
3960 bitsize
= sf
? 64 : 32;
3962 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
3963 unallocated_encoding(s
);
3965 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
3967 tcg_rd
= cpu_reg(s
, rd
);
3969 if (unlikely(imm
== 0)) {
3970 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3971 * so an extract from bit 0 is a special case.
3974 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
3976 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
3979 tcg_rm
= cpu_reg(s
, rm
);
3980 tcg_rn
= cpu_reg(s
, rn
);
3983 /* Specialization to ROR happens in EXTRACT2. */
3984 tcg_gen_extract2_i64(tcg_rd
, tcg_rm
, tcg_rn
, imm
);
3986 TCGv_i32 t0
= tcg_temp_new_i32();
3988 tcg_gen_extrl_i64_i32(t0
, tcg_rm
);
3990 tcg_gen_rotri_i32(t0
, t0
, imm
);
3992 TCGv_i32 t1
= tcg_temp_new_i32();
3993 tcg_gen_extrl_i64_i32(t1
, tcg_rn
);
3994 tcg_gen_extract2_i32(t0
, t0
, t1
, imm
);
3995 tcg_temp_free_i32(t1
);
3997 tcg_gen_extu_i32_i64(tcg_rd
, t0
);
3998 tcg_temp_free_i32(t0
);
4004 /* Data processing - immediate */
4005 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
4007 switch (extract32(insn
, 23, 6)) {
4008 case 0x20: case 0x21: /* PC-rel. addressing */
4009 disas_pc_rel_adr(s
, insn
);
4011 case 0x22: case 0x23: /* Add/subtract (immediate) */
4012 disas_add_sub_imm(s
, insn
);
4014 case 0x24: /* Logical (immediate) */
4015 disas_logic_imm(s
, insn
);
4017 case 0x25: /* Move wide (immediate) */
4018 disas_movw_imm(s
, insn
);
4020 case 0x26: /* Bitfield */
4021 disas_bitfield(s
, insn
);
4023 case 0x27: /* Extract */
4024 disas_extract(s
, insn
);
4027 unallocated_encoding(s
);
4032 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
4033 * Note that it is the caller's responsibility to ensure that the
4034 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
4035 * mandated semantics for out of range shifts.
4037 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4038 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
4040 switch (shift_type
) {
4041 case A64_SHIFT_TYPE_LSL
:
4042 tcg_gen_shl_i64(dst
, src
, shift_amount
);
4044 case A64_SHIFT_TYPE_LSR
:
4045 tcg_gen_shr_i64(dst
, src
, shift_amount
);
4047 case A64_SHIFT_TYPE_ASR
:
4049 tcg_gen_ext32s_i64(dst
, src
);
4051 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
4053 case A64_SHIFT_TYPE_ROR
:
4055 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
4058 t0
= tcg_temp_new_i32();
4059 t1
= tcg_temp_new_i32();
4060 tcg_gen_extrl_i64_i32(t0
, src
);
4061 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
4062 tcg_gen_rotr_i32(t0
, t0
, t1
);
4063 tcg_gen_extu_i32_i64(dst
, t0
);
4064 tcg_temp_free_i32(t0
);
4065 tcg_temp_free_i32(t1
);
4069 assert(FALSE
); /* all shift types should be handled */
4073 if (!sf
) { /* zero extend final result */
4074 tcg_gen_ext32u_i64(dst
, dst
);
4078 /* Shift a TCGv src by immediate, put result in dst.
4079 * The shift amount must be in range (this should always be true as the
4080 * relevant instructions will UNDEF on bad shift immediates).
4082 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4083 enum a64_shift_type shift_type
, unsigned int shift_i
)
4085 assert(shift_i
< (sf
? 64 : 32));
4088 tcg_gen_mov_i64(dst
, src
);
4090 TCGv_i64 shift_const
;
4092 shift_const
= tcg_const_i64(shift_i
);
4093 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
4094 tcg_temp_free_i64(shift_const
);
4098 /* Logical (shifted register)
4099 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4100 * +----+-----+-----------+-------+---+------+--------+------+------+
4101 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
4102 * +----+-----+-----------+-------+---+------+--------+------+------+
4104 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
4106 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
4107 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
4109 sf
= extract32(insn
, 31, 1);
4110 opc
= extract32(insn
, 29, 2);
4111 shift_type
= extract32(insn
, 22, 2);
4112 invert
= extract32(insn
, 21, 1);
4113 rm
= extract32(insn
, 16, 5);
4114 shift_amount
= extract32(insn
, 10, 6);
4115 rn
= extract32(insn
, 5, 5);
4116 rd
= extract32(insn
, 0, 5);
4118 if (!sf
&& (shift_amount
& (1 << 5))) {
4119 unallocated_encoding(s
);
4123 tcg_rd
= cpu_reg(s
, rd
);
4125 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
4126 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
4127 * register-register MOV and MVN, so it is worth special casing.
4129 tcg_rm
= cpu_reg(s
, rm
);
4131 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
4133 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4137 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
4139 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
4145 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4148 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
4151 tcg_rn
= cpu_reg(s
, rn
);
4153 switch (opc
| (invert
<< 2)) {
4156 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4159 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4162 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4166 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4169 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4172 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4180 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4184 gen_logic_CC(sf
, tcg_rd
);
4189 * Add/subtract (extended register)
4191 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
4192 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4193 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
4194 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4196 * sf: 0 -> 32bit, 1 -> 64bit
4197 * op: 0 -> add , 1 -> sub
4200 * option: extension type (see DecodeRegExtend)
4201 * imm3: optional shift to Rm
4203 * Rd = Rn + LSL(extend(Rm), amount)
4205 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
4207 int rd
= extract32(insn
, 0, 5);
4208 int rn
= extract32(insn
, 5, 5);
4209 int imm3
= extract32(insn
, 10, 3);
4210 int option
= extract32(insn
, 13, 3);
4211 int rm
= extract32(insn
, 16, 5);
4212 int opt
= extract32(insn
, 22, 2);
4213 bool setflags
= extract32(insn
, 29, 1);
4214 bool sub_op
= extract32(insn
, 30, 1);
4215 bool sf
= extract32(insn
, 31, 1);
4217 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
4219 TCGv_i64 tcg_result
;
4221 if (imm3
> 4 || opt
!= 0) {
4222 unallocated_encoding(s
);
4226 /* non-flag setting ops may use SP */
4228 tcg_rd
= cpu_reg_sp(s
, rd
);
4230 tcg_rd
= cpu_reg(s
, rd
);
4232 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
4234 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4235 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
4237 tcg_result
= tcg_temp_new_i64();
4241 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4243 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4247 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4249 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4254 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4256 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4259 tcg_temp_free_i64(tcg_result
);
4263 * Add/subtract (shifted register)
4265 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4266 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4267 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
4268 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4270 * sf: 0 -> 32bit, 1 -> 64bit
4271 * op: 0 -> add , 1 -> sub
4273 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
4274 * imm6: Shift amount to apply to Rm before the add/sub
4276 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
4278 int rd
= extract32(insn
, 0, 5);
4279 int rn
= extract32(insn
, 5, 5);
4280 int imm6
= extract32(insn
, 10, 6);
4281 int rm
= extract32(insn
, 16, 5);
4282 int shift_type
= extract32(insn
, 22, 2);
4283 bool setflags
= extract32(insn
, 29, 1);
4284 bool sub_op
= extract32(insn
, 30, 1);
4285 bool sf
= extract32(insn
, 31, 1);
4287 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4288 TCGv_i64 tcg_rn
, tcg_rm
;
4289 TCGv_i64 tcg_result
;
4291 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
4292 unallocated_encoding(s
);
4296 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4297 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4299 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
4301 tcg_result
= tcg_temp_new_i64();
4305 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4307 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4311 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4313 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4318 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4320 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4323 tcg_temp_free_i64(tcg_result
);
4326 /* Data-processing (3 source)
4328 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
4329 * +--+------+-----------+------+------+----+------+------+------+
4330 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
4331 * +--+------+-----------+------+------+----+------+------+------+
4333 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
4335 int rd
= extract32(insn
, 0, 5);
4336 int rn
= extract32(insn
, 5, 5);
4337 int ra
= extract32(insn
, 10, 5);
4338 int rm
= extract32(insn
, 16, 5);
4339 int op_id
= (extract32(insn
, 29, 3) << 4) |
4340 (extract32(insn
, 21, 3) << 1) |
4341 extract32(insn
, 15, 1);
4342 bool sf
= extract32(insn
, 31, 1);
4343 bool is_sub
= extract32(op_id
, 0, 1);
4344 bool is_high
= extract32(op_id
, 2, 1);
4345 bool is_signed
= false;
4350 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
4352 case 0x42: /* SMADDL */
4353 case 0x43: /* SMSUBL */
4354 case 0x44: /* SMULH */
4357 case 0x0: /* MADD (32bit) */
4358 case 0x1: /* MSUB (32bit) */
4359 case 0x40: /* MADD (64bit) */
4360 case 0x41: /* MSUB (64bit) */
4361 case 0x4a: /* UMADDL */
4362 case 0x4b: /* UMSUBL */
4363 case 0x4c: /* UMULH */
4366 unallocated_encoding(s
);
4371 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
4372 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4373 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4374 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
4377 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4379 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4382 tcg_temp_free_i64(low_bits
);
4386 tcg_op1
= tcg_temp_new_i64();
4387 tcg_op2
= tcg_temp_new_i64();
4388 tcg_tmp
= tcg_temp_new_i64();
4391 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
4392 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
4395 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
4396 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
4398 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
4399 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
4403 if (ra
== 31 && !is_sub
) {
4404 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
4405 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
4407 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
4409 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4411 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4416 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
4419 tcg_temp_free_i64(tcg_op1
);
4420 tcg_temp_free_i64(tcg_op2
);
4421 tcg_temp_free_i64(tcg_tmp
);
4424 /* Add/subtract (with carry)
4425 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
4426 * +--+--+--+------------------------+------+-------------+------+-----+
4427 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | 0 0 0 0 0 0 | Rn | Rd |
4428 * +--+--+--+------------------------+------+-------------+------+-----+
4431 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
4433 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
4434 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
4436 sf
= extract32(insn
, 31, 1);
4437 op
= extract32(insn
, 30, 1);
4438 setflags
= extract32(insn
, 29, 1);
4439 rm
= extract32(insn
, 16, 5);
4440 rn
= extract32(insn
, 5, 5);
4441 rd
= extract32(insn
, 0, 5);
4443 tcg_rd
= cpu_reg(s
, rd
);
4444 tcg_rn
= cpu_reg(s
, rn
);
4447 tcg_y
= new_tmp_a64(s
);
4448 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
4450 tcg_y
= cpu_reg(s
, rm
);
4454 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4456 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4461 * Rotate right into flags
4462 * 31 30 29 21 15 10 5 4 0
4463 * +--+--+--+-----------------+--------+-----------+------+--+------+
4464 * |sf|op| S| 1 1 0 1 0 0 0 0 | imm6 | 0 0 0 0 1 | Rn |o2| mask |
4465 * +--+--+--+-----------------+--------+-----------+------+--+------+
4467 static void disas_rotate_right_into_flags(DisasContext
*s
, uint32_t insn
)
4469 int mask
= extract32(insn
, 0, 4);
4470 int o2
= extract32(insn
, 4, 1);
4471 int rn
= extract32(insn
, 5, 5);
4472 int imm6
= extract32(insn
, 15, 6);
4473 int sf_op_s
= extract32(insn
, 29, 3);
4477 if (sf_op_s
!= 5 || o2
!= 0 || !dc_isar_feature(aa64_condm_4
, s
)) {
4478 unallocated_encoding(s
);
4482 tcg_rn
= read_cpu_reg(s
, rn
, 1);
4483 tcg_gen_rotri_i64(tcg_rn
, tcg_rn
, imm6
);
4485 nzcv
= tcg_temp_new_i32();
4486 tcg_gen_extrl_i64_i32(nzcv
, tcg_rn
);
4488 if (mask
& 8) { /* N */
4489 tcg_gen_shli_i32(cpu_NF
, nzcv
, 31 - 3);
4491 if (mask
& 4) { /* Z */
4492 tcg_gen_not_i32(cpu_ZF
, nzcv
);
4493 tcg_gen_andi_i32(cpu_ZF
, cpu_ZF
, 4);
4495 if (mask
& 2) { /* C */
4496 tcg_gen_extract_i32(cpu_CF
, nzcv
, 1, 1);
4498 if (mask
& 1) { /* V */
4499 tcg_gen_shli_i32(cpu_VF
, nzcv
, 31 - 0);
4502 tcg_temp_free_i32(nzcv
);
4506 * Evaluate into flags
4507 * 31 30 29 21 15 14 10 5 4 0
4508 * +--+--+--+-----------------+---------+----+---------+------+--+------+
4509 * |sf|op| S| 1 1 0 1 0 0 0 0 | opcode2 | sz | 0 0 1 0 | Rn |o3| mask |
4510 * +--+--+--+-----------------+---------+----+---------+------+--+------+
4512 static void disas_evaluate_into_flags(DisasContext
*s
, uint32_t insn
)
4514 int o3_mask
= extract32(insn
, 0, 5);
4515 int rn
= extract32(insn
, 5, 5);
4516 int o2
= extract32(insn
, 15, 6);
4517 int sz
= extract32(insn
, 14, 1);
4518 int sf_op_s
= extract32(insn
, 29, 3);
4522 if (sf_op_s
!= 1 || o2
!= 0 || o3_mask
!= 0xd ||
4523 !dc_isar_feature(aa64_condm_4
, s
)) {
4524 unallocated_encoding(s
);
4527 shift
= sz
? 16 : 24; /* SETF16 or SETF8 */
4529 tmp
= tcg_temp_new_i32();
4530 tcg_gen_extrl_i64_i32(tmp
, cpu_reg(s
, rn
));
4531 tcg_gen_shli_i32(cpu_NF
, tmp
, shift
);
4532 tcg_gen_shli_i32(cpu_VF
, tmp
, shift
- 1);
4533 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
4534 tcg_gen_xor_i32(cpu_VF
, cpu_VF
, cpu_NF
);
4535 tcg_temp_free_i32(tmp
);
4538 /* Conditional compare (immediate / register)
4539 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4540 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4541 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
4542 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4545 static void disas_cc(DisasContext
*s
, uint32_t insn
)
4547 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
4548 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
4549 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
4552 if (!extract32(insn
, 29, 1)) {
4553 unallocated_encoding(s
);
4556 if (insn
& (1 << 10 | 1 << 4)) {
4557 unallocated_encoding(s
);
4560 sf
= extract32(insn
, 31, 1);
4561 op
= extract32(insn
, 30, 1);
4562 is_imm
= extract32(insn
, 11, 1);
4563 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
4564 cond
= extract32(insn
, 12, 4);
4565 rn
= extract32(insn
, 5, 5);
4566 nzcv
= extract32(insn
, 0, 4);
4568 /* Set T0 = !COND. */
4569 tcg_t0
= tcg_temp_new_i32();
4570 arm_test_cc(&c
, cond
);
4571 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
4574 /* Load the arguments for the new comparison. */
4576 tcg_y
= new_tmp_a64(s
);
4577 tcg_gen_movi_i64(tcg_y
, y
);
4579 tcg_y
= cpu_reg(s
, y
);
4581 tcg_rn
= cpu_reg(s
, rn
);
4583 /* Set the flags for the new comparison. */
4584 tcg_tmp
= tcg_temp_new_i64();
4586 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4588 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4590 tcg_temp_free_i64(tcg_tmp
);
4592 /* If COND was false, force the flags to #nzcv. Compute two masks
4593 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
4594 * For tcg hosts that support ANDC, we can make do with just T1.
4595 * In either case, allow the tcg optimizer to delete any unused mask.
4597 tcg_t1
= tcg_temp_new_i32();
4598 tcg_t2
= tcg_temp_new_i32();
4599 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
4600 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
4602 if (nzcv
& 8) { /* N */
4603 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4605 if (TCG_TARGET_HAS_andc_i32
) {
4606 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4608 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
4611 if (nzcv
& 4) { /* Z */
4612 if (TCG_TARGET_HAS_andc_i32
) {
4613 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
4615 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
4618 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
4620 if (nzcv
& 2) { /* C */
4621 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
4623 if (TCG_TARGET_HAS_andc_i32
) {
4624 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
4626 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
4629 if (nzcv
& 1) { /* V */
4630 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4632 if (TCG_TARGET_HAS_andc_i32
) {
4633 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4635 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
4638 tcg_temp_free_i32(tcg_t0
);
4639 tcg_temp_free_i32(tcg_t1
);
4640 tcg_temp_free_i32(tcg_t2
);
4643 /* Conditional select
4644 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
4645 * +----+----+---+-----------------+------+------+-----+------+------+
4646 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
4647 * +----+----+---+-----------------+------+------+-----+------+------+
4649 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
4651 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
4652 TCGv_i64 tcg_rd
, zero
;
4655 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
4656 /* S == 1 or op2<1> == 1 */
4657 unallocated_encoding(s
);
4660 sf
= extract32(insn
, 31, 1);
4661 else_inv
= extract32(insn
, 30, 1);
4662 rm
= extract32(insn
, 16, 5);
4663 cond
= extract32(insn
, 12, 4);
4664 else_inc
= extract32(insn
, 10, 1);
4665 rn
= extract32(insn
, 5, 5);
4666 rd
= extract32(insn
, 0, 5);
4668 tcg_rd
= cpu_reg(s
, rd
);
4670 a64_test_cc(&c
, cond
);
4671 zero
= tcg_const_i64(0);
4673 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
4675 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
4677 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
4680 TCGv_i64 t_true
= cpu_reg(s
, rn
);
4681 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
4682 if (else_inv
&& else_inc
) {
4683 tcg_gen_neg_i64(t_false
, t_false
);
4684 } else if (else_inv
) {
4685 tcg_gen_not_i64(t_false
, t_false
);
4686 } else if (else_inc
) {
4687 tcg_gen_addi_i64(t_false
, t_false
, 1);
4689 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
4692 tcg_temp_free_i64(zero
);
4696 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4700 static void handle_clz(DisasContext
*s
, unsigned int sf
,
4701 unsigned int rn
, unsigned int rd
)
4703 TCGv_i64 tcg_rd
, tcg_rn
;
4704 tcg_rd
= cpu_reg(s
, rd
);
4705 tcg_rn
= cpu_reg(s
, rn
);
4708 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
4710 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4711 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4712 tcg_gen_clzi_i32(tcg_tmp32
, tcg_tmp32
, 32);
4713 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4714 tcg_temp_free_i32(tcg_tmp32
);
4718 static void handle_cls(DisasContext
*s
, unsigned int sf
,
4719 unsigned int rn
, unsigned int rd
)
4721 TCGv_i64 tcg_rd
, tcg_rn
;
4722 tcg_rd
= cpu_reg(s
, rd
);
4723 tcg_rn
= cpu_reg(s
, rn
);
4726 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
4728 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4729 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4730 tcg_gen_clrsb_i32(tcg_tmp32
, tcg_tmp32
);
4731 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4732 tcg_temp_free_i32(tcg_tmp32
);
4736 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
4737 unsigned int rn
, unsigned int rd
)
4739 TCGv_i64 tcg_rd
, tcg_rn
;
4740 tcg_rd
= cpu_reg(s
, rd
);
4741 tcg_rn
= cpu_reg(s
, rn
);
4744 gen_helper_rbit64(tcg_rd
, tcg_rn
);
4746 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4747 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4748 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
4749 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4750 tcg_temp_free_i32(tcg_tmp32
);
4754 /* REV with sf==1, opcode==3 ("REV64") */
4755 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
4756 unsigned int rn
, unsigned int rd
)
4759 unallocated_encoding(s
);
4762 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
4765 /* REV with sf==0, opcode==2
4766 * REV32 (sf==1, opcode==2)
4768 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
4769 unsigned int rn
, unsigned int rd
)
4771 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4774 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4775 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4777 /* bswap32_i64 requires zero high word */
4778 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
4779 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
4780 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
4781 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
4782 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4784 tcg_temp_free_i64(tcg_tmp
);
4786 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
4787 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
4791 /* REV16 (opcode==1) */
4792 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
4793 unsigned int rn
, unsigned int rd
)
4795 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4796 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4797 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4798 TCGv_i64 mask
= tcg_const_i64(sf
? 0x00ff00ff00ff00ffull
: 0x00ff00ff);
4800 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 8);
4801 tcg_gen_and_i64(tcg_rd
, tcg_rn
, mask
);
4802 tcg_gen_and_i64(tcg_tmp
, tcg_tmp
, mask
);
4803 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 8);
4804 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4806 tcg_temp_free_i64(mask
);
4807 tcg_temp_free_i64(tcg_tmp
);
4810 /* Data-processing (1 source)
4811 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4812 * +----+---+---+-----------------+---------+--------+------+------+
4813 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
4814 * +----+---+---+-----------------+---------+--------+------+------+
4816 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
4818 unsigned int sf
, opcode
, opcode2
, rn
, rd
;
4821 if (extract32(insn
, 29, 1)) {
4822 unallocated_encoding(s
);
4826 sf
= extract32(insn
, 31, 1);
4827 opcode
= extract32(insn
, 10, 6);
4828 opcode2
= extract32(insn
, 16, 5);
4829 rn
= extract32(insn
, 5, 5);
4830 rd
= extract32(insn
, 0, 5);
4832 #define MAP(SF, O2, O1) ((SF) | (O1 << 1) | (O2 << 7))
4834 switch (MAP(sf
, opcode2
, opcode
)) {
4835 case MAP(0, 0x00, 0x00): /* RBIT */
4836 case MAP(1, 0x00, 0x00):
4837 handle_rbit(s
, sf
, rn
, rd
);
4839 case MAP(0, 0x00, 0x01): /* REV16 */
4840 case MAP(1, 0x00, 0x01):
4841 handle_rev16(s
, sf
, rn
, rd
);
4843 case MAP(0, 0x00, 0x02): /* REV/REV32 */
4844 case MAP(1, 0x00, 0x02):
4845 handle_rev32(s
, sf
, rn
, rd
);
4847 case MAP(1, 0x00, 0x03): /* REV64 */
4848 handle_rev64(s
, sf
, rn
, rd
);
4850 case MAP(0, 0x00, 0x04): /* CLZ */
4851 case MAP(1, 0x00, 0x04):
4852 handle_clz(s
, sf
, rn
, rd
);
4854 case MAP(0, 0x00, 0x05): /* CLS */
4855 case MAP(1, 0x00, 0x05):
4856 handle_cls(s
, sf
, rn
, rd
);
4858 case MAP(1, 0x01, 0x00): /* PACIA */
4859 if (s
->pauth_active
) {
4860 tcg_rd
= cpu_reg(s
, rd
);
4861 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4862 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4863 goto do_unallocated
;
4866 case MAP(1, 0x01, 0x01): /* PACIB */
4867 if (s
->pauth_active
) {
4868 tcg_rd
= cpu_reg(s
, rd
);
4869 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4870 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4871 goto do_unallocated
;
4874 case MAP(1, 0x01, 0x02): /* PACDA */
4875 if (s
->pauth_active
) {
4876 tcg_rd
= cpu_reg(s
, rd
);
4877 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4878 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4879 goto do_unallocated
;
4882 case MAP(1, 0x01, 0x03): /* PACDB */
4883 if (s
->pauth_active
) {
4884 tcg_rd
= cpu_reg(s
, rd
);
4885 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4886 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4887 goto do_unallocated
;
4890 case MAP(1, 0x01, 0x04): /* AUTIA */
4891 if (s
->pauth_active
) {
4892 tcg_rd
= cpu_reg(s
, rd
);
4893 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4894 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4895 goto do_unallocated
;
4898 case MAP(1, 0x01, 0x05): /* AUTIB */
4899 if (s
->pauth_active
) {
4900 tcg_rd
= cpu_reg(s
, rd
);
4901 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4902 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4903 goto do_unallocated
;
4906 case MAP(1, 0x01, 0x06): /* AUTDA */
4907 if (s
->pauth_active
) {
4908 tcg_rd
= cpu_reg(s
, rd
);
4909 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4910 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4911 goto do_unallocated
;
4914 case MAP(1, 0x01, 0x07): /* AUTDB */
4915 if (s
->pauth_active
) {
4916 tcg_rd
= cpu_reg(s
, rd
);
4917 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4918 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4919 goto do_unallocated
;
4922 case MAP(1, 0x01, 0x08): /* PACIZA */
4923 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4924 goto do_unallocated
;
4925 } else if (s
->pauth_active
) {
4926 tcg_rd
= cpu_reg(s
, rd
);
4927 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4930 case MAP(1, 0x01, 0x09): /* PACIZB */
4931 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4932 goto do_unallocated
;
4933 } else if (s
->pauth_active
) {
4934 tcg_rd
= cpu_reg(s
, rd
);
4935 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4938 case MAP(1, 0x01, 0x0a): /* PACDZA */
4939 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4940 goto do_unallocated
;
4941 } else if (s
->pauth_active
) {
4942 tcg_rd
= cpu_reg(s
, rd
);
4943 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4946 case MAP(1, 0x01, 0x0b): /* PACDZB */
4947 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4948 goto do_unallocated
;
4949 } else if (s
->pauth_active
) {
4950 tcg_rd
= cpu_reg(s
, rd
);
4951 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4954 case MAP(1, 0x01, 0x0c): /* AUTIZA */
4955 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4956 goto do_unallocated
;
4957 } else if (s
->pauth_active
) {
4958 tcg_rd
= cpu_reg(s
, rd
);
4959 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4962 case MAP(1, 0x01, 0x0d): /* AUTIZB */
4963 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4964 goto do_unallocated
;
4965 } else if (s
->pauth_active
) {
4966 tcg_rd
= cpu_reg(s
, rd
);
4967 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4970 case MAP(1, 0x01, 0x0e): /* AUTDZA */
4971 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4972 goto do_unallocated
;
4973 } else if (s
->pauth_active
) {
4974 tcg_rd
= cpu_reg(s
, rd
);
4975 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4978 case MAP(1, 0x01, 0x0f): /* AUTDZB */
4979 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4980 goto do_unallocated
;
4981 } else if (s
->pauth_active
) {
4982 tcg_rd
= cpu_reg(s
, rd
);
4983 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4986 case MAP(1, 0x01, 0x10): /* XPACI */
4987 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4988 goto do_unallocated
;
4989 } else if (s
->pauth_active
) {
4990 tcg_rd
= cpu_reg(s
, rd
);
4991 gen_helper_xpaci(tcg_rd
, cpu_env
, tcg_rd
);
4994 case MAP(1, 0x01, 0x11): /* XPACD */
4995 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4996 goto do_unallocated
;
4997 } else if (s
->pauth_active
) {
4998 tcg_rd
= cpu_reg(s
, rd
);
4999 gen_helper_xpacd(tcg_rd
, cpu_env
, tcg_rd
);
5004 unallocated_encoding(s
);
5011 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
5012 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5014 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
5015 tcg_rd
= cpu_reg(s
, rd
);
5017 if (!sf
&& is_signed
) {
5018 tcg_n
= new_tmp_a64(s
);
5019 tcg_m
= new_tmp_a64(s
);
5020 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
5021 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
5023 tcg_n
= read_cpu_reg(s
, rn
, sf
);
5024 tcg_m
= read_cpu_reg(s
, rm
, sf
);
5028 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
5030 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
5033 if (!sf
) { /* zero extend final result */
5034 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5038 /* LSLV, LSRV, ASRV, RORV */
5039 static void handle_shift_reg(DisasContext
*s
,
5040 enum a64_shift_type shift_type
, unsigned int sf
,
5041 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5043 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
5044 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5045 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
5047 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
5048 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
5049 tcg_temp_free_i64(tcg_shift
);
5052 /* CRC32[BHWX], CRC32C[BHWX] */
5053 static void handle_crc32(DisasContext
*s
,
5054 unsigned int sf
, unsigned int sz
, bool crc32c
,
5055 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5057 TCGv_i64 tcg_acc
, tcg_val
;
5060 if (!dc_isar_feature(aa64_crc32
, s
)
5061 || (sf
== 1 && sz
!= 3)
5062 || (sf
== 0 && sz
== 3)) {
5063 unallocated_encoding(s
);
5068 tcg_val
= cpu_reg(s
, rm
);
5082 g_assert_not_reached();
5084 tcg_val
= new_tmp_a64(s
);
5085 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
5088 tcg_acc
= cpu_reg(s
, rn
);
5089 tcg_bytes
= tcg_const_i32(1 << sz
);
5092 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5094 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5097 tcg_temp_free_i32(tcg_bytes
);
5100 /* Data-processing (2 source)
5101 * 31 30 29 28 21 20 16 15 10 9 5 4 0
5102 * +----+---+---+-----------------+------+--------+------+------+
5103 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
5104 * +----+---+---+-----------------+------+--------+------+------+
5106 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
5108 unsigned int sf
, rm
, opcode
, rn
, rd
;
5109 sf
= extract32(insn
, 31, 1);
5110 rm
= extract32(insn
, 16, 5);
5111 opcode
= extract32(insn
, 10, 6);
5112 rn
= extract32(insn
, 5, 5);
5113 rd
= extract32(insn
, 0, 5);
5115 if (extract32(insn
, 29, 1)) {
5116 unallocated_encoding(s
);
5122 handle_div(s
, false, sf
, rm
, rn
, rd
);
5125 handle_div(s
, true, sf
, rm
, rn
, rd
);
5128 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
5131 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
5134 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
5137 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
5139 case 12: /* PACGA */
5140 if (sf
== 0 || !dc_isar_feature(aa64_pauth
, s
)) {
5141 goto do_unallocated
;
5143 gen_helper_pacga(cpu_reg(s
, rd
), cpu_env
,
5144 cpu_reg(s
, rn
), cpu_reg_sp(s
, rm
));
5153 case 23: /* CRC32 */
5155 int sz
= extract32(opcode
, 0, 2);
5156 bool crc32c
= extract32(opcode
, 2, 1);
5157 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
5162 unallocated_encoding(s
);
5168 * Data processing - register
5169 * 31 30 29 28 25 21 20 16 10 0
5170 * +--+---+--+---+-------+-----+-------+-------+---------+
5171 * | |op0| |op1| 1 0 1 | op2 | | op3 | |
5172 * +--+---+--+---+-------+-----+-------+-------+---------+
5174 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
5176 int op0
= extract32(insn
, 30, 1);
5177 int op1
= extract32(insn
, 28, 1);
5178 int op2
= extract32(insn
, 21, 4);
5179 int op3
= extract32(insn
, 10, 6);
5184 /* Add/sub (extended register) */
5185 disas_add_sub_ext_reg(s
, insn
);
5187 /* Add/sub (shifted register) */
5188 disas_add_sub_reg(s
, insn
);
5191 /* Logical (shifted register) */
5192 disas_logic_reg(s
, insn
);
5200 case 0x00: /* Add/subtract (with carry) */
5201 disas_adc_sbc(s
, insn
);
5204 case 0x01: /* Rotate right into flags */
5206 disas_rotate_right_into_flags(s
, insn
);
5209 case 0x02: /* Evaluate into flags */
5213 disas_evaluate_into_flags(s
, insn
);
5217 goto do_unallocated
;
5221 case 0x2: /* Conditional compare */
5222 disas_cc(s
, insn
); /* both imm and reg forms */
5225 case 0x4: /* Conditional select */
5226 disas_cond_select(s
, insn
);
5229 case 0x6: /* Data-processing */
5230 if (op0
) { /* (1 source) */
5231 disas_data_proc_1src(s
, insn
);
5232 } else { /* (2 source) */
5233 disas_data_proc_2src(s
, insn
);
5236 case 0x8 ... 0xf: /* (3 source) */
5237 disas_data_proc_3src(s
, insn
);
5242 unallocated_encoding(s
);
5247 static void handle_fp_compare(DisasContext
*s
, int size
,
5248 unsigned int rn
, unsigned int rm
,
5249 bool cmp_with_zero
, bool signal_all_nans
)
5251 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
5252 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
5254 if (size
== MO_64
) {
5255 TCGv_i64 tcg_vn
, tcg_vm
;
5257 tcg_vn
= read_fp_dreg(s
, rn
);
5258 if (cmp_with_zero
) {
5259 tcg_vm
= tcg_const_i64(0);
5261 tcg_vm
= read_fp_dreg(s
, rm
);
5263 if (signal_all_nans
) {
5264 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5266 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5268 tcg_temp_free_i64(tcg_vn
);
5269 tcg_temp_free_i64(tcg_vm
);
5271 TCGv_i32 tcg_vn
= tcg_temp_new_i32();
5272 TCGv_i32 tcg_vm
= tcg_temp_new_i32();
5274 read_vec_element_i32(s
, tcg_vn
, rn
, 0, size
);
5275 if (cmp_with_zero
) {
5276 tcg_gen_movi_i32(tcg_vm
, 0);
5278 read_vec_element_i32(s
, tcg_vm
, rm
, 0, size
);
5283 if (signal_all_nans
) {
5284 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5286 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5290 if (signal_all_nans
) {
5291 gen_helper_vfp_cmpeh_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5293 gen_helper_vfp_cmph_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5297 g_assert_not_reached();
5300 tcg_temp_free_i32(tcg_vn
);
5301 tcg_temp_free_i32(tcg_vm
);
5304 tcg_temp_free_ptr(fpst
);
5306 gen_set_nzcv(tcg_flags
);
5308 tcg_temp_free_i64(tcg_flags
);
5311 /* Floating point compare
5312 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
5313 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5314 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
5315 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5317 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
5319 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
5322 mos
= extract32(insn
, 29, 3);
5323 type
= extract32(insn
, 22, 2);
5324 rm
= extract32(insn
, 16, 5);
5325 op
= extract32(insn
, 14, 2);
5326 rn
= extract32(insn
, 5, 5);
5327 opc
= extract32(insn
, 3, 2);
5328 op2r
= extract32(insn
, 0, 3);
5330 if (mos
|| op
|| op2r
) {
5331 unallocated_encoding(s
);
5344 if (dc_isar_feature(aa64_fp16
, s
)) {
5349 unallocated_encoding(s
);
5353 if (!fp_access_check(s
)) {
5357 handle_fp_compare(s
, size
, rn
, rm
, opc
& 1, opc
& 2);
5360 /* Floating point conditional compare
5361 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
5362 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5363 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
5364 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5366 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
5368 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
5370 TCGLabel
*label_continue
= NULL
;
5373 mos
= extract32(insn
, 29, 3);
5374 type
= extract32(insn
, 22, 2);
5375 rm
= extract32(insn
, 16, 5);
5376 cond
= extract32(insn
, 12, 4);
5377 rn
= extract32(insn
, 5, 5);
5378 op
= extract32(insn
, 4, 1);
5379 nzcv
= extract32(insn
, 0, 4);
5382 unallocated_encoding(s
);
5395 if (dc_isar_feature(aa64_fp16
, s
)) {
5400 unallocated_encoding(s
);
5404 if (!fp_access_check(s
)) {
5408 if (cond
< 0x0e) { /* not always */
5409 TCGLabel
*label_match
= gen_new_label();
5410 label_continue
= gen_new_label();
5411 arm_gen_test_cc(cond
, label_match
);
5413 tcg_flags
= tcg_const_i64(nzcv
<< 28);
5414 gen_set_nzcv(tcg_flags
);
5415 tcg_temp_free_i64(tcg_flags
);
5416 tcg_gen_br(label_continue
);
5417 gen_set_label(label_match
);
5420 handle_fp_compare(s
, size
, rn
, rm
, false, op
);
5423 gen_set_label(label_continue
);
5427 /* Floating point conditional select
5428 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5429 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5430 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
5431 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5433 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
5435 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
5436 TCGv_i64 t_true
, t_false
, t_zero
;
5440 mos
= extract32(insn
, 29, 3);
5441 type
= extract32(insn
, 22, 2);
5442 rm
= extract32(insn
, 16, 5);
5443 cond
= extract32(insn
, 12, 4);
5444 rn
= extract32(insn
, 5, 5);
5445 rd
= extract32(insn
, 0, 5);
5448 unallocated_encoding(s
);
5461 if (dc_isar_feature(aa64_fp16
, s
)) {
5466 unallocated_encoding(s
);
5470 if (!fp_access_check(s
)) {
5474 /* Zero extend sreg & hreg inputs to 64 bits now. */
5475 t_true
= tcg_temp_new_i64();
5476 t_false
= tcg_temp_new_i64();
5477 read_vec_element(s
, t_true
, rn
, 0, sz
);
5478 read_vec_element(s
, t_false
, rm
, 0, sz
);
5480 a64_test_cc(&c
, cond
);
5481 t_zero
= tcg_const_i64(0);
5482 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, t_zero
, t_true
, t_false
);
5483 tcg_temp_free_i64(t_zero
);
5484 tcg_temp_free_i64(t_false
);
5487 /* Note that sregs & hregs write back zeros to the high bits,
5488 and we've already done the zero-extension. */
5489 write_fp_dreg(s
, rd
, t_true
);
5490 tcg_temp_free_i64(t_true
);
5493 /* Floating-point data-processing (1 source) - half precision */
5494 static void handle_fp_1src_half(DisasContext
*s
, int opcode
, int rd
, int rn
)
5496 TCGv_ptr fpst
= NULL
;
5497 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
5498 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5501 case 0x0: /* FMOV */
5502 tcg_gen_mov_i32(tcg_res
, tcg_op
);
5504 case 0x1: /* FABS */
5505 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
5507 case 0x2: /* FNEG */
5508 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
5510 case 0x3: /* FSQRT */
5511 fpst
= get_fpstatus_ptr(true);
5512 gen_helper_sqrt_f16(tcg_res
, tcg_op
, fpst
);
5514 case 0x8: /* FRINTN */
5515 case 0x9: /* FRINTP */
5516 case 0xa: /* FRINTM */
5517 case 0xb: /* FRINTZ */
5518 case 0xc: /* FRINTA */
5520 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
5521 fpst
= get_fpstatus_ptr(true);
5523 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5524 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
5526 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5527 tcg_temp_free_i32(tcg_rmode
);
5530 case 0xe: /* FRINTX */
5531 fpst
= get_fpstatus_ptr(true);
5532 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, fpst
);
5534 case 0xf: /* FRINTI */
5535 fpst
= get_fpstatus_ptr(true);
5536 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
5542 write_fp_sreg(s
, rd
, tcg_res
);
5545 tcg_temp_free_ptr(fpst
);
5547 tcg_temp_free_i32(tcg_op
);
5548 tcg_temp_free_i32(tcg_res
);
5551 /* Floating-point data-processing (1 source) - single precision */
5552 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
5554 void (*gen_fpst
)(TCGv_i32
, TCGv_i32
, TCGv_ptr
);
5555 TCGv_i32 tcg_op
, tcg_res
;
5559 tcg_op
= read_fp_sreg(s
, rn
);
5560 tcg_res
= tcg_temp_new_i32();
5563 case 0x0: /* FMOV */
5564 tcg_gen_mov_i32(tcg_res
, tcg_op
);
5566 case 0x1: /* FABS */
5567 gen_helper_vfp_abss(tcg_res
, tcg_op
);
5569 case 0x2: /* FNEG */
5570 gen_helper_vfp_negs(tcg_res
, tcg_op
);
5572 case 0x3: /* FSQRT */
5573 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
5575 case 0x8: /* FRINTN */
5576 case 0x9: /* FRINTP */
5577 case 0xa: /* FRINTM */
5578 case 0xb: /* FRINTZ */
5579 case 0xc: /* FRINTA */
5580 rmode
= arm_rmode_to_sf(opcode
& 7);
5581 gen_fpst
= gen_helper_rints
;
5583 case 0xe: /* FRINTX */
5584 gen_fpst
= gen_helper_rints_exact
;
5586 case 0xf: /* FRINTI */
5587 gen_fpst
= gen_helper_rints
;
5589 case 0x10: /* FRINT32Z */
5590 rmode
= float_round_to_zero
;
5591 gen_fpst
= gen_helper_frint32_s
;
5593 case 0x11: /* FRINT32X */
5594 gen_fpst
= gen_helper_frint32_s
;
5596 case 0x12: /* FRINT64Z */
5597 rmode
= float_round_to_zero
;
5598 gen_fpst
= gen_helper_frint64_s
;
5600 case 0x13: /* FRINT64X */
5601 gen_fpst
= gen_helper_frint64_s
;
5604 g_assert_not_reached();
5607 fpst
= get_fpstatus_ptr(false);
5609 TCGv_i32 tcg_rmode
= tcg_const_i32(rmode
);
5610 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5611 gen_fpst(tcg_res
, tcg_op
, fpst
);
5612 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5613 tcg_temp_free_i32(tcg_rmode
);
5615 gen_fpst(tcg_res
, tcg_op
, fpst
);
5617 tcg_temp_free_ptr(fpst
);
5620 write_fp_sreg(s
, rd
, tcg_res
);
5621 tcg_temp_free_i32(tcg_op
);
5622 tcg_temp_free_i32(tcg_res
);
5625 /* Floating-point data-processing (1 source) - double precision */
5626 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
5628 void (*gen_fpst
)(TCGv_i64
, TCGv_i64
, TCGv_ptr
);
5629 TCGv_i64 tcg_op
, tcg_res
;
5634 case 0x0: /* FMOV */
5635 gen_gvec_fn2(s
, false, rd
, rn
, tcg_gen_gvec_mov
, 0);
5639 tcg_op
= read_fp_dreg(s
, rn
);
5640 tcg_res
= tcg_temp_new_i64();
5643 case 0x1: /* FABS */
5644 gen_helper_vfp_absd(tcg_res
, tcg_op
);
5646 case 0x2: /* FNEG */
5647 gen_helper_vfp_negd(tcg_res
, tcg_op
);
5649 case 0x3: /* FSQRT */
5650 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
5652 case 0x8: /* FRINTN */
5653 case 0x9: /* FRINTP */
5654 case 0xa: /* FRINTM */
5655 case 0xb: /* FRINTZ */
5656 case 0xc: /* FRINTA */
5657 rmode
= arm_rmode_to_sf(opcode
& 7);
5658 gen_fpst
= gen_helper_rintd
;
5660 case 0xe: /* FRINTX */
5661 gen_fpst
= gen_helper_rintd_exact
;
5663 case 0xf: /* FRINTI */
5664 gen_fpst
= gen_helper_rintd
;
5666 case 0x10: /* FRINT32Z */
5667 rmode
= float_round_to_zero
;
5668 gen_fpst
= gen_helper_frint32_d
;
5670 case 0x11: /* FRINT32X */
5671 gen_fpst
= gen_helper_frint32_d
;
5673 case 0x12: /* FRINT64Z */
5674 rmode
= float_round_to_zero
;
5675 gen_fpst
= gen_helper_frint64_d
;
5677 case 0x13: /* FRINT64X */
5678 gen_fpst
= gen_helper_frint64_d
;
5681 g_assert_not_reached();
5684 fpst
= get_fpstatus_ptr(false);
5686 TCGv_i32 tcg_rmode
= tcg_const_i32(rmode
);
5687 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5688 gen_fpst(tcg_res
, tcg_op
, fpst
);
5689 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5690 tcg_temp_free_i32(tcg_rmode
);
5692 gen_fpst(tcg_res
, tcg_op
, fpst
);
5694 tcg_temp_free_ptr(fpst
);
5697 write_fp_dreg(s
, rd
, tcg_res
);
5698 tcg_temp_free_i64(tcg_op
);
5699 tcg_temp_free_i64(tcg_res
);
5702 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
5703 int rd
, int rn
, int dtype
, int ntype
)
5708 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5710 /* Single to double */
5711 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5712 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
5713 write_fp_dreg(s
, rd
, tcg_rd
);
5714 tcg_temp_free_i64(tcg_rd
);
5716 /* Single to half */
5717 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5718 TCGv_i32 ahp
= get_ahp_flag();
5719 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5721 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5722 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5723 write_fp_sreg(s
, rd
, tcg_rd
);
5724 tcg_temp_free_i32(tcg_rd
);
5725 tcg_temp_free_i32(ahp
);
5726 tcg_temp_free_ptr(fpst
);
5728 tcg_temp_free_i32(tcg_rn
);
5733 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
5734 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5736 /* Double to single */
5737 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
5739 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5740 TCGv_i32 ahp
= get_ahp_flag();
5741 /* Double to half */
5742 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5743 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5744 tcg_temp_free_ptr(fpst
);
5745 tcg_temp_free_i32(ahp
);
5747 write_fp_sreg(s
, rd
, tcg_rd
);
5748 tcg_temp_free_i32(tcg_rd
);
5749 tcg_temp_free_i64(tcg_rn
);
5754 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5755 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(false);
5756 TCGv_i32 tcg_ahp
= get_ahp_flag();
5757 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
5759 /* Half to single */
5760 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5761 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5762 write_fp_sreg(s
, rd
, tcg_rd
);
5763 tcg_temp_free_ptr(tcg_fpst
);
5764 tcg_temp_free_i32(tcg_ahp
);
5765 tcg_temp_free_i32(tcg_rd
);
5767 /* Half to double */
5768 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5769 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5770 write_fp_dreg(s
, rd
, tcg_rd
);
5771 tcg_temp_free_i64(tcg_rd
);
5773 tcg_temp_free_i32(tcg_rn
);
5781 /* Floating point data-processing (1 source)
5782 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
5783 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5784 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
5785 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5787 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
5789 int mos
= extract32(insn
, 29, 3);
5790 int type
= extract32(insn
, 22, 2);
5791 int opcode
= extract32(insn
, 15, 6);
5792 int rn
= extract32(insn
, 5, 5);
5793 int rd
= extract32(insn
, 0, 5);
5796 unallocated_encoding(s
);
5801 case 0x4: case 0x5: case 0x7:
5803 /* FCVT between half, single and double precision */
5804 int dtype
= extract32(opcode
, 0, 2);
5805 if (type
== 2 || dtype
== type
) {
5806 unallocated_encoding(s
);
5809 if (!fp_access_check(s
)) {
5813 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
5817 case 0x10 ... 0x13: /* FRINT{32,64}{X,Z} */
5818 if (type
> 1 || !dc_isar_feature(aa64_frint
, s
)) {
5819 unallocated_encoding(s
);
5826 /* 32-to-32 and 64-to-64 ops */
5829 if (!fp_access_check(s
)) {
5832 handle_fp_1src_single(s
, opcode
, rd
, rn
);
5835 if (!fp_access_check(s
)) {
5838 handle_fp_1src_double(s
, opcode
, rd
, rn
);
5841 if (!dc_isar_feature(aa64_fp16
, s
)) {
5842 unallocated_encoding(s
);
5846 if (!fp_access_check(s
)) {
5849 handle_fp_1src_half(s
, opcode
, rd
, rn
);
5852 unallocated_encoding(s
);
5857 unallocated_encoding(s
);
5862 /* Floating-point data-processing (2 source) - single precision */
5863 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
5864 int rd
, int rn
, int rm
)
5871 tcg_res
= tcg_temp_new_i32();
5872 fpst
= get_fpstatus_ptr(false);
5873 tcg_op1
= read_fp_sreg(s
, rn
);
5874 tcg_op2
= read_fp_sreg(s
, rm
);
5877 case 0x0: /* FMUL */
5878 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5880 case 0x1: /* FDIV */
5881 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5883 case 0x2: /* FADD */
5884 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5886 case 0x3: /* FSUB */
5887 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5889 case 0x4: /* FMAX */
5890 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5892 case 0x5: /* FMIN */
5893 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5895 case 0x6: /* FMAXNM */
5896 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5898 case 0x7: /* FMINNM */
5899 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5901 case 0x8: /* FNMUL */
5902 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5903 gen_helper_vfp_negs(tcg_res
, tcg_res
);
5907 write_fp_sreg(s
, rd
, tcg_res
);
5909 tcg_temp_free_ptr(fpst
);
5910 tcg_temp_free_i32(tcg_op1
);
5911 tcg_temp_free_i32(tcg_op2
);
5912 tcg_temp_free_i32(tcg_res
);
5915 /* Floating-point data-processing (2 source) - double precision */
5916 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
5917 int rd
, int rn
, int rm
)
5924 tcg_res
= tcg_temp_new_i64();
5925 fpst
= get_fpstatus_ptr(false);
5926 tcg_op1
= read_fp_dreg(s
, rn
);
5927 tcg_op2
= read_fp_dreg(s
, rm
);
5930 case 0x0: /* FMUL */
5931 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5933 case 0x1: /* FDIV */
5934 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5936 case 0x2: /* FADD */
5937 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5939 case 0x3: /* FSUB */
5940 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5942 case 0x4: /* FMAX */
5943 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5945 case 0x5: /* FMIN */
5946 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5948 case 0x6: /* FMAXNM */
5949 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5951 case 0x7: /* FMINNM */
5952 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5954 case 0x8: /* FNMUL */
5955 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5956 gen_helper_vfp_negd(tcg_res
, tcg_res
);
5960 write_fp_dreg(s
, rd
, tcg_res
);
5962 tcg_temp_free_ptr(fpst
);
5963 tcg_temp_free_i64(tcg_op1
);
5964 tcg_temp_free_i64(tcg_op2
);
5965 tcg_temp_free_i64(tcg_res
);
5968 /* Floating-point data-processing (2 source) - half precision */
5969 static void handle_fp_2src_half(DisasContext
*s
, int opcode
,
5970 int rd
, int rn
, int rm
)
5977 tcg_res
= tcg_temp_new_i32();
5978 fpst
= get_fpstatus_ptr(true);
5979 tcg_op1
= read_fp_hreg(s
, rn
);
5980 tcg_op2
= read_fp_hreg(s
, rm
);
5983 case 0x0: /* FMUL */
5984 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5986 case 0x1: /* FDIV */
5987 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5989 case 0x2: /* FADD */
5990 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5992 case 0x3: /* FSUB */
5993 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5995 case 0x4: /* FMAX */
5996 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5998 case 0x5: /* FMIN */
5999 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6001 case 0x6: /* FMAXNM */
6002 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6004 case 0x7: /* FMINNM */
6005 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6007 case 0x8: /* FNMUL */
6008 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6009 tcg_gen_xori_i32(tcg_res
, tcg_res
, 0x8000);
6012 g_assert_not_reached();
6015 write_fp_sreg(s
, rd
, tcg_res
);
6017 tcg_temp_free_ptr(fpst
);
6018 tcg_temp_free_i32(tcg_op1
);
6019 tcg_temp_free_i32(tcg_op2
);
6020 tcg_temp_free_i32(tcg_res
);
6023 /* Floating point data-processing (2 source)
6024 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6025 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6026 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
6027 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6029 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
6031 int mos
= extract32(insn
, 29, 3);
6032 int type
= extract32(insn
, 22, 2);
6033 int rd
= extract32(insn
, 0, 5);
6034 int rn
= extract32(insn
, 5, 5);
6035 int rm
= extract32(insn
, 16, 5);
6036 int opcode
= extract32(insn
, 12, 4);
6038 if (opcode
> 8 || mos
) {
6039 unallocated_encoding(s
);
6045 if (!fp_access_check(s
)) {
6048 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
6051 if (!fp_access_check(s
)) {
6054 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
6057 if (!dc_isar_feature(aa64_fp16
, s
)) {
6058 unallocated_encoding(s
);
6061 if (!fp_access_check(s
)) {
6064 handle_fp_2src_half(s
, opcode
, rd
, rn
, rm
);
6067 unallocated_encoding(s
);
6071 /* Floating-point data-processing (3 source) - single precision */
6072 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
6073 int rd
, int rn
, int rm
, int ra
)
6075 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
6076 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6077 TCGv_ptr fpst
= get_fpstatus_ptr(false);
6079 tcg_op1
= read_fp_sreg(s
, rn
);
6080 tcg_op2
= read_fp_sreg(s
, rm
);
6081 tcg_op3
= read_fp_sreg(s
, ra
);
6083 /* These are fused multiply-add, and must be done as one
6084 * floating point operation with no rounding between the
6085 * multiplication and addition steps.
6086 * NB that doing the negations here as separate steps is
6087 * correct : an input NaN should come out with its sign bit
6088 * flipped if it is a negated-input.
6091 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
6095 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
6098 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6100 write_fp_sreg(s
, rd
, tcg_res
);
6102 tcg_temp_free_ptr(fpst
);
6103 tcg_temp_free_i32(tcg_op1
);
6104 tcg_temp_free_i32(tcg_op2
);
6105 tcg_temp_free_i32(tcg_op3
);
6106 tcg_temp_free_i32(tcg_res
);
6109 /* Floating-point data-processing (3 source) - double precision */
6110 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
6111 int rd
, int rn
, int rm
, int ra
)
6113 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
6114 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6115 TCGv_ptr fpst
= get_fpstatus_ptr(false);
6117 tcg_op1
= read_fp_dreg(s
, rn
);
6118 tcg_op2
= read_fp_dreg(s
, rm
);
6119 tcg_op3
= read_fp_dreg(s
, ra
);
6121 /* These are fused multiply-add, and must be done as one
6122 * floating point operation with no rounding between the
6123 * multiplication and addition steps.
6124 * NB that doing the negations here as separate steps is
6125 * correct : an input NaN should come out with its sign bit
6126 * flipped if it is a negated-input.
6129 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
6133 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
6136 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6138 write_fp_dreg(s
, rd
, tcg_res
);
6140 tcg_temp_free_ptr(fpst
);
6141 tcg_temp_free_i64(tcg_op1
);
6142 tcg_temp_free_i64(tcg_op2
);
6143 tcg_temp_free_i64(tcg_op3
);
6144 tcg_temp_free_i64(tcg_res
);
6147 /* Floating-point data-processing (3 source) - half precision */
6148 static void handle_fp_3src_half(DisasContext
*s
, bool o0
, bool o1
,
6149 int rd
, int rn
, int rm
, int ra
)
6151 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
6152 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6153 TCGv_ptr fpst
= get_fpstatus_ptr(true);
6155 tcg_op1
= read_fp_hreg(s
, rn
);
6156 tcg_op2
= read_fp_hreg(s
, rm
);
6157 tcg_op3
= read_fp_hreg(s
, ra
);
6159 /* These are fused multiply-add, and must be done as one
6160 * floating point operation with no rounding between the
6161 * multiplication and addition steps.
6162 * NB that doing the negations here as separate steps is
6163 * correct : an input NaN should come out with its sign bit
6164 * flipped if it is a negated-input.
6167 tcg_gen_xori_i32(tcg_op3
, tcg_op3
, 0x8000);
6171 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
6174 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6176 write_fp_sreg(s
, rd
, tcg_res
);
6178 tcg_temp_free_ptr(fpst
);
6179 tcg_temp_free_i32(tcg_op1
);
6180 tcg_temp_free_i32(tcg_op2
);
6181 tcg_temp_free_i32(tcg_op3
);
6182 tcg_temp_free_i32(tcg_res
);
6185 /* Floating point data-processing (3 source)
6186 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
6187 * +---+---+---+-----------+------+----+------+----+------+------+------+
6188 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
6189 * +---+---+---+-----------+------+----+------+----+------+------+------+
6191 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
6193 int mos
= extract32(insn
, 29, 3);
6194 int type
= extract32(insn
, 22, 2);
6195 int rd
= extract32(insn
, 0, 5);
6196 int rn
= extract32(insn
, 5, 5);
6197 int ra
= extract32(insn
, 10, 5);
6198 int rm
= extract32(insn
, 16, 5);
6199 bool o0
= extract32(insn
, 15, 1);
6200 bool o1
= extract32(insn
, 21, 1);
6203 unallocated_encoding(s
);
6209 if (!fp_access_check(s
)) {
6212 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6215 if (!fp_access_check(s
)) {
6218 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6221 if (!dc_isar_feature(aa64_fp16
, s
)) {
6222 unallocated_encoding(s
);
6225 if (!fp_access_check(s
)) {
6228 handle_fp_3src_half(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6231 unallocated_encoding(s
);
6235 /* Floating point immediate
6236 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
6237 * +---+---+---+-----------+------+---+------------+-------+------+------+
6238 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
6239 * +---+---+---+-----------+------+---+------------+-------+------+------+
6241 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
6243 int rd
= extract32(insn
, 0, 5);
6244 int imm5
= extract32(insn
, 5, 5);
6245 int imm8
= extract32(insn
, 13, 8);
6246 int type
= extract32(insn
, 22, 2);
6247 int mos
= extract32(insn
, 29, 3);
6253 unallocated_encoding(s
);
6266 if (dc_isar_feature(aa64_fp16
, s
)) {
6271 unallocated_encoding(s
);
6275 if (!fp_access_check(s
)) {
6279 imm
= vfp_expand_imm(sz
, imm8
);
6281 tcg_res
= tcg_const_i64(imm
);
6282 write_fp_dreg(s
, rd
, tcg_res
);
6283 tcg_temp_free_i64(tcg_res
);
6286 /* Handle floating point <=> fixed point conversions. Note that we can
6287 * also deal with fp <=> integer conversions as a special case (scale == 64)
6288 * OPTME: consider handling that special case specially or at least skipping
6289 * the call to scalbn in the helpers for zero shifts.
6291 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
6292 bool itof
, int rmode
, int scale
, int sf
, int type
)
6294 bool is_signed
= !(opcode
& 1);
6295 TCGv_ptr tcg_fpstatus
;
6296 TCGv_i32 tcg_shift
, tcg_single
;
6297 TCGv_i64 tcg_double
;
6299 tcg_fpstatus
= get_fpstatus_ptr(type
== 3);
6301 tcg_shift
= tcg_const_i32(64 - scale
);
6304 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
6306 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
6309 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
6311 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
6314 tcg_int
= tcg_extend
;
6318 case 1: /* float64 */
6319 tcg_double
= tcg_temp_new_i64();
6321 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6322 tcg_shift
, tcg_fpstatus
);
6324 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6325 tcg_shift
, tcg_fpstatus
);
6327 write_fp_dreg(s
, rd
, tcg_double
);
6328 tcg_temp_free_i64(tcg_double
);
6331 case 0: /* float32 */
6332 tcg_single
= tcg_temp_new_i32();
6334 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6335 tcg_shift
, tcg_fpstatus
);
6337 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6338 tcg_shift
, tcg_fpstatus
);
6340 write_fp_sreg(s
, rd
, tcg_single
);
6341 tcg_temp_free_i32(tcg_single
);
6344 case 3: /* float16 */
6345 tcg_single
= tcg_temp_new_i32();
6347 gen_helper_vfp_sqtoh(tcg_single
, tcg_int
,
6348 tcg_shift
, tcg_fpstatus
);
6350 gen_helper_vfp_uqtoh(tcg_single
, tcg_int
,
6351 tcg_shift
, tcg_fpstatus
);
6353 write_fp_sreg(s
, rd
, tcg_single
);
6354 tcg_temp_free_i32(tcg_single
);
6358 g_assert_not_reached();
6361 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
6364 if (extract32(opcode
, 2, 1)) {
6365 /* There are too many rounding modes to all fit into rmode,
6366 * so FCVTA[US] is a special case.
6368 rmode
= FPROUNDING_TIEAWAY
;
6371 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
6373 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
6376 case 1: /* float64 */
6377 tcg_double
= read_fp_dreg(s
, rn
);
6380 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
6381 tcg_shift
, tcg_fpstatus
);
6383 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
6384 tcg_shift
, tcg_fpstatus
);
6388 gen_helper_vfp_tould(tcg_int
, tcg_double
,
6389 tcg_shift
, tcg_fpstatus
);
6391 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
6392 tcg_shift
, tcg_fpstatus
);
6396 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
6398 tcg_temp_free_i64(tcg_double
);
6401 case 0: /* float32 */
6402 tcg_single
= read_fp_sreg(s
, rn
);
6405 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
6406 tcg_shift
, tcg_fpstatus
);
6408 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
6409 tcg_shift
, tcg_fpstatus
);
6412 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
6414 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
6415 tcg_shift
, tcg_fpstatus
);
6417 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
6418 tcg_shift
, tcg_fpstatus
);
6420 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
6421 tcg_temp_free_i32(tcg_dest
);
6423 tcg_temp_free_i32(tcg_single
);
6426 case 3: /* float16 */
6427 tcg_single
= read_fp_sreg(s
, rn
);
6430 gen_helper_vfp_tosqh(tcg_int
, tcg_single
,
6431 tcg_shift
, tcg_fpstatus
);
6433 gen_helper_vfp_touqh(tcg_int
, tcg_single
,
6434 tcg_shift
, tcg_fpstatus
);
6437 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
6439 gen_helper_vfp_toslh(tcg_dest
, tcg_single
,
6440 tcg_shift
, tcg_fpstatus
);
6442 gen_helper_vfp_toulh(tcg_dest
, tcg_single
,
6443 tcg_shift
, tcg_fpstatus
);
6445 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
6446 tcg_temp_free_i32(tcg_dest
);
6448 tcg_temp_free_i32(tcg_single
);
6452 g_assert_not_reached();
6455 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
6456 tcg_temp_free_i32(tcg_rmode
);
6459 tcg_temp_free_ptr(tcg_fpstatus
);
6460 tcg_temp_free_i32(tcg_shift
);
6463 /* Floating point <-> fixed point conversions
6464 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6465 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6466 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
6467 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6469 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
6471 int rd
= extract32(insn
, 0, 5);
6472 int rn
= extract32(insn
, 5, 5);
6473 int scale
= extract32(insn
, 10, 6);
6474 int opcode
= extract32(insn
, 16, 3);
6475 int rmode
= extract32(insn
, 19, 2);
6476 int type
= extract32(insn
, 22, 2);
6477 bool sbit
= extract32(insn
, 29, 1);
6478 bool sf
= extract32(insn
, 31, 1);
6481 if (sbit
|| (!sf
&& scale
< 32)) {
6482 unallocated_encoding(s
);
6487 case 0: /* float32 */
6488 case 1: /* float64 */
6490 case 3: /* float16 */
6491 if (dc_isar_feature(aa64_fp16
, s
)) {
6496 unallocated_encoding(s
);
6500 switch ((rmode
<< 3) | opcode
) {
6501 case 0x2: /* SCVTF */
6502 case 0x3: /* UCVTF */
6505 case 0x18: /* FCVTZS */
6506 case 0x19: /* FCVTZU */
6510 unallocated_encoding(s
);
6514 if (!fp_access_check(s
)) {
6518 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
6521 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
6523 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
6524 * without conversion.
6528 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
6534 tmp
= tcg_temp_new_i64();
6535 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
6536 write_fp_dreg(s
, rd
, tmp
);
6537 tcg_temp_free_i64(tmp
);
6541 write_fp_dreg(s
, rd
, tcg_rn
);
6544 /* 64 bit to top half. */
6545 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
6546 clear_vec_high(s
, true, rd
);
6550 tmp
= tcg_temp_new_i64();
6551 tcg_gen_ext16u_i64(tmp
, tcg_rn
);
6552 write_fp_dreg(s
, rd
, tmp
);
6553 tcg_temp_free_i64(tmp
);
6556 g_assert_not_reached();
6559 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
6564 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
6568 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
6571 /* 64 bits from top half */
6572 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
6576 tcg_gen_ld16u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_16
));
6579 g_assert_not_reached();
6584 static void handle_fjcvtzs(DisasContext
*s
, int rd
, int rn
)
6586 TCGv_i64 t
= read_fp_dreg(s
, rn
);
6587 TCGv_ptr fpstatus
= get_fpstatus_ptr(false);
6589 gen_helper_fjcvtzs(t
, t
, fpstatus
);
6591 tcg_temp_free_ptr(fpstatus
);
6593 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), t
);
6594 tcg_gen_extrh_i64_i32(cpu_ZF
, t
);
6595 tcg_gen_movi_i32(cpu_CF
, 0);
6596 tcg_gen_movi_i32(cpu_NF
, 0);
6597 tcg_gen_movi_i32(cpu_VF
, 0);
6599 tcg_temp_free_i64(t
);
6602 /* Floating point <-> integer conversions
6603 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6604 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6605 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
6606 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6608 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
6610 int rd
= extract32(insn
, 0, 5);
6611 int rn
= extract32(insn
, 5, 5);
6612 int opcode
= extract32(insn
, 16, 3);
6613 int rmode
= extract32(insn
, 19, 2);
6614 int type
= extract32(insn
, 22, 2);
6615 bool sbit
= extract32(insn
, 29, 1);
6616 bool sf
= extract32(insn
, 31, 1);
6620 goto do_unallocated
;
6628 case 4: /* FCVTAS */
6629 case 5: /* FCVTAU */
6631 goto do_unallocated
;
6634 case 0: /* FCVT[NPMZ]S */
6635 case 1: /* FCVT[NPMZ]U */
6637 case 0: /* float32 */
6638 case 1: /* float64 */
6640 case 3: /* float16 */
6641 if (!dc_isar_feature(aa64_fp16
, s
)) {
6642 goto do_unallocated
;
6646 goto do_unallocated
;
6648 if (!fp_access_check(s
)) {
6651 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
6655 switch (sf
<< 7 | type
<< 5 | rmode
<< 3 | opcode
) {
6656 case 0b01100110: /* FMOV half <-> 32-bit int */
6658 case 0b11100110: /* FMOV half <-> 64-bit int */
6660 if (!dc_isar_feature(aa64_fp16
, s
)) {
6661 goto do_unallocated
;
6664 case 0b00000110: /* FMOV 32-bit */
6666 case 0b10100110: /* FMOV 64-bit */
6668 case 0b11001110: /* FMOV top half of 128-bit */
6670 if (!fp_access_check(s
)) {
6674 handle_fmov(s
, rd
, rn
, type
, itof
);
6677 case 0b00111110: /* FJCVTZS */
6678 if (!dc_isar_feature(aa64_jscvt
, s
)) {
6679 goto do_unallocated
;
6680 } else if (fp_access_check(s
)) {
6681 handle_fjcvtzs(s
, rd
, rn
);
6687 unallocated_encoding(s
);
6694 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
6695 * 31 30 29 28 25 24 0
6696 * +---+---+---+---------+-----------------------------+
6697 * | | 0 | | 1 1 1 1 | |
6698 * +---+---+---+---------+-----------------------------+
6700 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
6702 if (extract32(insn
, 24, 1)) {
6703 /* Floating point data-processing (3 source) */
6704 disas_fp_3src(s
, insn
);
6705 } else if (extract32(insn
, 21, 1) == 0) {
6706 /* Floating point to fixed point conversions */
6707 disas_fp_fixed_conv(s
, insn
);
6709 switch (extract32(insn
, 10, 2)) {
6711 /* Floating point conditional compare */
6712 disas_fp_ccomp(s
, insn
);
6715 /* Floating point data-processing (2 source) */
6716 disas_fp_2src(s
, insn
);
6719 /* Floating point conditional select */
6720 disas_fp_csel(s
, insn
);
6723 switch (ctz32(extract32(insn
, 12, 4))) {
6724 case 0: /* [15:12] == xxx1 */
6725 /* Floating point immediate */
6726 disas_fp_imm(s
, insn
);
6728 case 1: /* [15:12] == xx10 */
6729 /* Floating point compare */
6730 disas_fp_compare(s
, insn
);
6732 case 2: /* [15:12] == x100 */
6733 /* Floating point data-processing (1 source) */
6734 disas_fp_1src(s
, insn
);
6736 case 3: /* [15:12] == 1000 */
6737 unallocated_encoding(s
);
6739 default: /* [15:12] == 0000 */
6740 /* Floating point <-> integer conversions */
6741 disas_fp_int_conv(s
, insn
);
6749 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
6752 /* Extract 64 bits from the middle of two concatenated 64 bit
6753 * vector register slices left:right. The extracted bits start
6754 * at 'pos' bits into the right (least significant) side.
6755 * We return the result in tcg_right, and guarantee not to
6758 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
6759 assert(pos
> 0 && pos
< 64);
6761 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
6762 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
6763 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
6765 tcg_temp_free_i64(tcg_tmp
);
6769 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
6770 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6771 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
6772 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6774 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
6776 int is_q
= extract32(insn
, 30, 1);
6777 int op2
= extract32(insn
, 22, 2);
6778 int imm4
= extract32(insn
, 11, 4);
6779 int rm
= extract32(insn
, 16, 5);
6780 int rn
= extract32(insn
, 5, 5);
6781 int rd
= extract32(insn
, 0, 5);
6782 int pos
= imm4
<< 3;
6783 TCGv_i64 tcg_resl
, tcg_resh
;
6785 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
6786 unallocated_encoding(s
);
6790 if (!fp_access_check(s
)) {
6794 tcg_resh
= tcg_temp_new_i64();
6795 tcg_resl
= tcg_temp_new_i64();
6797 /* Vd gets bits starting at pos bits into Vm:Vn. This is
6798 * either extracting 128 bits from a 128:128 concatenation, or
6799 * extracting 64 bits from a 64:64 concatenation.
6802 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
6804 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
6805 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6807 tcg_gen_movi_i64(tcg_resh
, 0);
6814 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
6815 EltPosns
*elt
= eltposns
;
6822 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
6824 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
6827 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6828 tcg_hh
= tcg_temp_new_i64();
6829 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
6830 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
6831 tcg_temp_free_i64(tcg_hh
);
6835 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6836 tcg_temp_free_i64(tcg_resl
);
6837 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6838 tcg_temp_free_i64(tcg_resh
);
6842 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
6843 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6844 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
6845 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6847 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
6849 int op2
= extract32(insn
, 22, 2);
6850 int is_q
= extract32(insn
, 30, 1);
6851 int rm
= extract32(insn
, 16, 5);
6852 int rn
= extract32(insn
, 5, 5);
6853 int rd
= extract32(insn
, 0, 5);
6854 int is_tblx
= extract32(insn
, 12, 1);
6855 int len
= extract32(insn
, 13, 2);
6856 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
6857 TCGv_i32 tcg_regno
, tcg_numregs
;
6860 unallocated_encoding(s
);
6864 if (!fp_access_check(s
)) {
6868 /* This does a table lookup: for every byte element in the input
6869 * we index into a table formed from up to four vector registers,
6870 * and then the output is the result of the lookups. Our helper
6871 * function does the lookup operation for a single 64 bit part of
6874 tcg_resl
= tcg_temp_new_i64();
6875 tcg_resh
= tcg_temp_new_i64();
6878 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6880 tcg_gen_movi_i64(tcg_resl
, 0);
6882 if (is_tblx
&& is_q
) {
6883 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6885 tcg_gen_movi_i64(tcg_resh
, 0);
6888 tcg_idx
= tcg_temp_new_i64();
6889 tcg_regno
= tcg_const_i32(rn
);
6890 tcg_numregs
= tcg_const_i32(len
+ 1);
6891 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
6892 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
6893 tcg_regno
, tcg_numregs
);
6895 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
6896 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
6897 tcg_regno
, tcg_numregs
);
6899 tcg_temp_free_i64(tcg_idx
);
6900 tcg_temp_free_i32(tcg_regno
);
6901 tcg_temp_free_i32(tcg_numregs
);
6903 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6904 tcg_temp_free_i64(tcg_resl
);
6905 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6906 tcg_temp_free_i64(tcg_resh
);
6910 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
6911 * +---+---+-------------+------+---+------+---+------------------+------+
6912 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
6913 * +---+---+-------------+------+---+------+---+------------------+------+
6915 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
6917 int rd
= extract32(insn
, 0, 5);
6918 int rn
= extract32(insn
, 5, 5);
6919 int rm
= extract32(insn
, 16, 5);
6920 int size
= extract32(insn
, 22, 2);
6921 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
6922 * bit 2 indicates 1 vs 2 variant of the insn.
6924 int opcode
= extract32(insn
, 12, 2);
6925 bool part
= extract32(insn
, 14, 1);
6926 bool is_q
= extract32(insn
, 30, 1);
6927 int esize
= 8 << size
;
6929 int datasize
= is_q
? 128 : 64;
6930 int elements
= datasize
/ esize
;
6931 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
6933 if (opcode
== 0 || (size
== 3 && !is_q
)) {
6934 unallocated_encoding(s
);
6938 if (!fp_access_check(s
)) {
6942 tcg_resl
= tcg_const_i64(0);
6943 tcg_resh
= tcg_const_i64(0);
6944 tcg_res
= tcg_temp_new_i64();
6946 for (i
= 0; i
< elements
; i
++) {
6948 case 1: /* UZP1/2 */
6950 int midpoint
= elements
/ 2;
6952 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
6954 read_vec_element(s
, tcg_res
, rm
,
6955 2 * (i
- midpoint
) + part
, size
);
6959 case 2: /* TRN1/2 */
6961 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
6963 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
6966 case 3: /* ZIP1/2 */
6968 int base
= part
* elements
/ 2;
6970 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
6972 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
6977 g_assert_not_reached();
6982 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
6983 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
6985 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
6986 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
6990 tcg_temp_free_i64(tcg_res
);
6992 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6993 tcg_temp_free_i64(tcg_resl
);
6994 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6995 tcg_temp_free_i64(tcg_resh
);
6999 * do_reduction_op helper
7001 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
7002 * important for correct NaN propagation that we do these
7003 * operations in exactly the order specified by the pseudocode.
7005 * This is a recursive function, TCG temps should be freed by the
7006 * calling function once it is done with the values.
7008 static TCGv_i32
do_reduction_op(DisasContext
*s
, int fpopcode
, int rn
,
7009 int esize
, int size
, int vmap
, TCGv_ptr fpst
)
7011 if (esize
== size
) {
7013 TCGMemOp msize
= esize
== 16 ? MO_16
: MO_32
;
7016 /* We should have one register left here */
7017 assert(ctpop8(vmap
) == 1);
7018 element
= ctz32(vmap
);
7019 assert(element
< 8);
7021 tcg_elem
= tcg_temp_new_i32();
7022 read_vec_element_i32(s
, tcg_elem
, rn
, element
, msize
);
7025 int bits
= size
/ 2;
7026 int shift
= ctpop8(vmap
) / 2;
7027 int vmap_lo
= (vmap
>> shift
) & vmap
;
7028 int vmap_hi
= (vmap
& ~vmap_lo
);
7029 TCGv_i32 tcg_hi
, tcg_lo
, tcg_res
;
7031 tcg_hi
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_hi
, fpst
);
7032 tcg_lo
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_lo
, fpst
);
7033 tcg_res
= tcg_temp_new_i32();
7036 case 0x0c: /* fmaxnmv half-precision */
7037 gen_helper_advsimd_maxnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7039 case 0x0f: /* fmaxv half-precision */
7040 gen_helper_advsimd_maxh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7042 case 0x1c: /* fminnmv half-precision */
7043 gen_helper_advsimd_minnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7045 case 0x1f: /* fminv half-precision */
7046 gen_helper_advsimd_minh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7048 case 0x2c: /* fmaxnmv */
7049 gen_helper_vfp_maxnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7051 case 0x2f: /* fmaxv */
7052 gen_helper_vfp_maxs(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7054 case 0x3c: /* fminnmv */
7055 gen_helper_vfp_minnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7057 case 0x3f: /* fminv */
7058 gen_helper_vfp_mins(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7061 g_assert_not_reached();
7064 tcg_temp_free_i32(tcg_hi
);
7065 tcg_temp_free_i32(tcg_lo
);
7070 /* AdvSIMD across lanes
7071 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7072 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7073 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7074 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7076 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
7078 int rd
= extract32(insn
, 0, 5);
7079 int rn
= extract32(insn
, 5, 5);
7080 int size
= extract32(insn
, 22, 2);
7081 int opcode
= extract32(insn
, 12, 5);
7082 bool is_q
= extract32(insn
, 30, 1);
7083 bool is_u
= extract32(insn
, 29, 1);
7085 bool is_min
= false;
7089 TCGv_i64 tcg_res
, tcg_elt
;
7092 case 0x1b: /* ADDV */
7094 unallocated_encoding(s
);
7098 case 0x3: /* SADDLV, UADDLV */
7099 case 0xa: /* SMAXV, UMAXV */
7100 case 0x1a: /* SMINV, UMINV */
7101 if (size
== 3 || (size
== 2 && !is_q
)) {
7102 unallocated_encoding(s
);
7106 case 0xc: /* FMAXNMV, FMINNMV */
7107 case 0xf: /* FMAXV, FMINV */
7108 /* Bit 1 of size field encodes min vs max and the actual size
7109 * depends on the encoding of the U bit. If not set (and FP16
7110 * enabled) then we do half-precision float instead of single
7113 is_min
= extract32(size
, 1, 1);
7115 if (!is_u
&& dc_isar_feature(aa64_fp16
, s
)) {
7117 } else if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
7118 unallocated_encoding(s
);
7125 unallocated_encoding(s
);
7129 if (!fp_access_check(s
)) {
7134 elements
= (is_q
? 128 : 64) / esize
;
7136 tcg_res
= tcg_temp_new_i64();
7137 tcg_elt
= tcg_temp_new_i64();
7139 /* These instructions operate across all lanes of a vector
7140 * to produce a single result. We can guarantee that a 64
7141 * bit intermediate is sufficient:
7142 * + for [US]ADDLV the maximum element size is 32 bits, and
7143 * the result type is 64 bits
7144 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
7145 * same as the element size, which is 32 bits at most
7146 * For the integer operations we can choose to work at 64
7147 * or 32 bits and truncate at the end; for simplicity
7148 * we use 64 bits always. The floating point
7149 * ops do require 32 bit intermediates, though.
7152 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
7154 for (i
= 1; i
< elements
; i
++) {
7155 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
7158 case 0x03: /* SADDLV / UADDLV */
7159 case 0x1b: /* ADDV */
7160 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
7162 case 0x0a: /* SMAXV / UMAXV */
7164 tcg_gen_umax_i64(tcg_res
, tcg_res
, tcg_elt
);
7166 tcg_gen_smax_i64(tcg_res
, tcg_res
, tcg_elt
);
7169 case 0x1a: /* SMINV / UMINV */
7171 tcg_gen_umin_i64(tcg_res
, tcg_res
, tcg_elt
);
7173 tcg_gen_smin_i64(tcg_res
, tcg_res
, tcg_elt
);
7177 g_assert_not_reached();
7182 /* Floating point vector reduction ops which work across 32
7183 * bit (single) or 16 bit (half-precision) intermediates.
7184 * Note that correct NaN propagation requires that we do these
7185 * operations in exactly the order specified by the pseudocode.
7187 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
7188 int fpopcode
= opcode
| is_min
<< 4 | is_u
<< 5;
7189 int vmap
= (1 << elements
) - 1;
7190 TCGv_i32 tcg_res32
= do_reduction_op(s
, fpopcode
, rn
, esize
,
7191 (is_q
? 128 : 64), vmap
, fpst
);
7192 tcg_gen_extu_i32_i64(tcg_res
, tcg_res32
);
7193 tcg_temp_free_i32(tcg_res32
);
7194 tcg_temp_free_ptr(fpst
);
7197 tcg_temp_free_i64(tcg_elt
);
7199 /* Now truncate the result to the width required for the final output */
7200 if (opcode
== 0x03) {
7201 /* SADDLV, UADDLV: result is 2*esize */
7207 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
7210 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
7213 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
7218 g_assert_not_reached();
7221 write_fp_dreg(s
, rd
, tcg_res
);
7222 tcg_temp_free_i64(tcg_res
);
7225 /* DUP (Element, Vector)
7227 * 31 30 29 21 20 16 15 10 9 5 4 0
7228 * +---+---+-------------------+--------+-------------+------+------+
7229 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7230 * +---+---+-------------------+--------+-------------+------+------+
7232 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7234 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
7237 int size
= ctz32(imm5
);
7238 int index
= imm5
>> (size
+ 1);
7240 if (size
> 3 || (size
== 3 && !is_q
)) {
7241 unallocated_encoding(s
);
7245 if (!fp_access_check(s
)) {
7249 tcg_gen_gvec_dup_mem(size
, vec_full_reg_offset(s
, rd
),
7250 vec_reg_offset(s
, rn
, index
, size
),
7251 is_q
? 16 : 8, vec_full_reg_size(s
));
7254 /* DUP (element, scalar)
7255 * 31 21 20 16 15 10 9 5 4 0
7256 * +-----------------------+--------+-------------+------+------+
7257 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7258 * +-----------------------+--------+-------------+------+------+
7260 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
7263 int size
= ctz32(imm5
);
7268 unallocated_encoding(s
);
7272 if (!fp_access_check(s
)) {
7276 index
= imm5
>> (size
+ 1);
7278 /* This instruction just extracts the specified element and
7279 * zero-extends it into the bottom of the destination register.
7281 tmp
= tcg_temp_new_i64();
7282 read_vec_element(s
, tmp
, rn
, index
, size
);
7283 write_fp_dreg(s
, rd
, tmp
);
7284 tcg_temp_free_i64(tmp
);
7289 * 31 30 29 21 20 16 15 10 9 5 4 0
7290 * +---+---+-------------------+--------+-------------+------+------+
7291 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
7292 * +---+---+-------------------+--------+-------------+------+------+
7294 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7296 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
7299 int size
= ctz32(imm5
);
7300 uint32_t dofs
, oprsz
, maxsz
;
7302 if (size
> 3 || ((size
== 3) && !is_q
)) {
7303 unallocated_encoding(s
);
7307 if (!fp_access_check(s
)) {
7311 dofs
= vec_full_reg_offset(s
, rd
);
7312 oprsz
= is_q
? 16 : 8;
7313 maxsz
= vec_full_reg_size(s
);
7315 tcg_gen_gvec_dup_i64(size
, dofs
, oprsz
, maxsz
, cpu_reg(s
, rn
));
7320 * 31 21 20 16 15 14 11 10 9 5 4 0
7321 * +-----------------------+--------+------------+---+------+------+
7322 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7323 * +-----------------------+--------+------------+---+------+------+
7325 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7326 * index: encoded in imm5<4:size+1>
7328 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
7331 int size
= ctz32(imm5
);
7332 int src_index
, dst_index
;
7336 unallocated_encoding(s
);
7340 if (!fp_access_check(s
)) {
7344 dst_index
= extract32(imm5
, 1+size
, 5);
7345 src_index
= extract32(imm4
, size
, 4);
7347 tmp
= tcg_temp_new_i64();
7349 read_vec_element(s
, tmp
, rn
, src_index
, size
);
7350 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
7352 tcg_temp_free_i64(tmp
);
7358 * 31 21 20 16 15 10 9 5 4 0
7359 * +-----------------------+--------+-------------+------+------+
7360 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
7361 * +-----------------------+--------+-------------+------+------+
7363 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7364 * index: encoded in imm5<4:size+1>
7366 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
7368 int size
= ctz32(imm5
);
7372 unallocated_encoding(s
);
7376 if (!fp_access_check(s
)) {
7380 idx
= extract32(imm5
, 1 + size
, 4 - size
);
7381 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
7388 * 31 30 29 21 20 16 15 12 10 9 5 4 0
7389 * +---+---+-------------------+--------+-------------+------+------+
7390 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
7391 * +---+---+-------------------+--------+-------------+------+------+
7393 * U: unsigned when set
7394 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7396 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
7397 int rn
, int rd
, int imm5
)
7399 int size
= ctz32(imm5
);
7403 /* Check for UnallocatedEncodings */
7405 if (size
> 2 || (size
== 2 && !is_q
)) {
7406 unallocated_encoding(s
);
7411 || (size
< 3 && is_q
)
7412 || (size
== 3 && !is_q
)) {
7413 unallocated_encoding(s
);
7418 if (!fp_access_check(s
)) {
7422 element
= extract32(imm5
, 1+size
, 4);
7424 tcg_rd
= cpu_reg(s
, rd
);
7425 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
7426 if (is_signed
&& !is_q
) {
7427 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
7432 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7433 * +---+---+----+-----------------+------+---+------+---+------+------+
7434 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7435 * +---+---+----+-----------------+------+---+------+---+------+------+
7437 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
7439 int rd
= extract32(insn
, 0, 5);
7440 int rn
= extract32(insn
, 5, 5);
7441 int imm4
= extract32(insn
, 11, 4);
7442 int op
= extract32(insn
, 29, 1);
7443 int is_q
= extract32(insn
, 30, 1);
7444 int imm5
= extract32(insn
, 16, 5);
7449 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
7451 unallocated_encoding(s
);
7456 /* DUP (element - vector) */
7457 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
7461 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
7466 handle_simd_insg(s
, rd
, rn
, imm5
);
7468 unallocated_encoding(s
);
7473 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
7474 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
7477 unallocated_encoding(s
);
7483 /* AdvSIMD modified immediate
7484 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
7485 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7486 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
7487 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7489 * There are a number of operations that can be carried out here:
7490 * MOVI - move (shifted) imm into register
7491 * MVNI - move inverted (shifted) imm into register
7492 * ORR - bitwise OR of (shifted) imm with register
7493 * BIC - bitwise clear of (shifted) imm with register
7494 * With ARMv8.2 we also have:
7495 * FMOV half-precision
7497 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
7499 int rd
= extract32(insn
, 0, 5);
7500 int cmode
= extract32(insn
, 12, 4);
7501 int cmode_3_1
= extract32(cmode
, 1, 3);
7502 int cmode_0
= extract32(cmode
, 0, 1);
7503 int o2
= extract32(insn
, 11, 1);
7504 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
7505 bool is_neg
= extract32(insn
, 29, 1);
7506 bool is_q
= extract32(insn
, 30, 1);
7509 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
7510 /* Check for FMOV (vector, immediate) - half-precision */
7511 if (!(dc_isar_feature(aa64_fp16
, s
) && o2
&& cmode
== 0xf)) {
7512 unallocated_encoding(s
);
7517 if (!fp_access_check(s
)) {
7521 /* See AdvSIMDExpandImm() in ARM ARM */
7522 switch (cmode_3_1
) {
7523 case 0: /* Replicate(Zeros(24):imm8, 2) */
7524 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
7525 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
7526 case 3: /* Replicate(imm8:Zeros(24), 2) */
7528 int shift
= cmode_3_1
* 8;
7529 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
7532 case 4: /* Replicate(Zeros(8):imm8, 4) */
7533 case 5: /* Replicate(imm8:Zeros(8), 4) */
7535 int shift
= (cmode_3_1
& 0x1) * 8;
7536 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
7541 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
7542 imm
= (abcdefgh
<< 16) | 0xffff;
7544 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
7545 imm
= (abcdefgh
<< 8) | 0xff;
7547 imm
= bitfield_replicate(imm
, 32);
7550 if (!cmode_0
&& !is_neg
) {
7551 imm
= bitfield_replicate(abcdefgh
, 8);
7552 } else if (!cmode_0
&& is_neg
) {
7555 for (i
= 0; i
< 8; i
++) {
7556 if ((abcdefgh
) & (1 << i
)) {
7557 imm
|= 0xffULL
<< (i
* 8);
7560 } else if (cmode_0
) {
7562 imm
= (abcdefgh
& 0x3f) << 48;
7563 if (abcdefgh
& 0x80) {
7564 imm
|= 0x8000000000000000ULL
;
7566 if (abcdefgh
& 0x40) {
7567 imm
|= 0x3fc0000000000000ULL
;
7569 imm
|= 0x4000000000000000ULL
;
7573 /* FMOV (vector, immediate) - half-precision */
7574 imm
= vfp_expand_imm(MO_16
, abcdefgh
);
7575 /* now duplicate across the lanes */
7576 imm
= bitfield_replicate(imm
, 16);
7578 imm
= (abcdefgh
& 0x3f) << 19;
7579 if (abcdefgh
& 0x80) {
7582 if (abcdefgh
& 0x40) {
7593 fprintf(stderr
, "%s: cmode_3_1: %x\n", __func__
, cmode_3_1
);
7594 g_assert_not_reached();
7597 if (cmode_3_1
!= 7 && is_neg
) {
7601 if (!((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9)) {
7602 /* MOVI or MVNI, with MVNI negation handled above. */
7603 tcg_gen_gvec_dup64i(vec_full_reg_offset(s
, rd
), is_q
? 16 : 8,
7604 vec_full_reg_size(s
), imm
);
7606 /* ORR or BIC, with BIC negation to AND handled above. */
7608 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_andi
, MO_64
);
7610 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_ori
, MO_64
);
7615 /* AdvSIMD scalar copy
7616 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7617 * +-----+----+-----------------+------+---+------+---+------+------+
7618 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7619 * +-----+----+-----------------+------+---+------+---+------+------+
7621 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
7623 int rd
= extract32(insn
, 0, 5);
7624 int rn
= extract32(insn
, 5, 5);
7625 int imm4
= extract32(insn
, 11, 4);
7626 int imm5
= extract32(insn
, 16, 5);
7627 int op
= extract32(insn
, 29, 1);
7629 if (op
!= 0 || imm4
!= 0) {
7630 unallocated_encoding(s
);
7634 /* DUP (element, scalar) */
7635 handle_simd_dupes(s
, rd
, rn
, imm5
);
7638 /* AdvSIMD scalar pairwise
7639 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7640 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7641 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7642 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7644 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
7646 int u
= extract32(insn
, 29, 1);
7647 int size
= extract32(insn
, 22, 2);
7648 int opcode
= extract32(insn
, 12, 5);
7649 int rn
= extract32(insn
, 5, 5);
7650 int rd
= extract32(insn
, 0, 5);
7653 /* For some ops (the FP ones), size[1] is part of the encoding.
7654 * For ADDP strictly it is not but size[1] is always 1 for valid
7657 opcode
|= (extract32(size
, 1, 1) << 5);
7660 case 0x3b: /* ADDP */
7661 if (u
|| size
!= 3) {
7662 unallocated_encoding(s
);
7665 if (!fp_access_check(s
)) {
7671 case 0xc: /* FMAXNMP */
7672 case 0xd: /* FADDP */
7673 case 0xf: /* FMAXP */
7674 case 0x2c: /* FMINNMP */
7675 case 0x2f: /* FMINP */
7676 /* FP op, size[0] is 32 or 64 bit*/
7678 if (!dc_isar_feature(aa64_fp16
, s
)) {
7679 unallocated_encoding(s
);
7685 size
= extract32(size
, 0, 1) ? MO_64
: MO_32
;
7688 if (!fp_access_check(s
)) {
7692 fpst
= get_fpstatus_ptr(size
== MO_16
);
7695 unallocated_encoding(s
);
7699 if (size
== MO_64
) {
7700 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7701 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7702 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7704 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
7705 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
7708 case 0x3b: /* ADDP */
7709 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
7711 case 0xc: /* FMAXNMP */
7712 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7714 case 0xd: /* FADDP */
7715 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7717 case 0xf: /* FMAXP */
7718 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7720 case 0x2c: /* FMINNMP */
7721 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7723 case 0x2f: /* FMINP */
7724 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7727 g_assert_not_reached();
7730 write_fp_dreg(s
, rd
, tcg_res
);
7732 tcg_temp_free_i64(tcg_op1
);
7733 tcg_temp_free_i64(tcg_op2
);
7734 tcg_temp_free_i64(tcg_res
);
7736 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7737 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7738 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7740 read_vec_element_i32(s
, tcg_op1
, rn
, 0, size
);
7741 read_vec_element_i32(s
, tcg_op2
, rn
, 1, size
);
7743 if (size
== MO_16
) {
7745 case 0xc: /* FMAXNMP */
7746 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7748 case 0xd: /* FADDP */
7749 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7751 case 0xf: /* FMAXP */
7752 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7754 case 0x2c: /* FMINNMP */
7755 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7757 case 0x2f: /* FMINP */
7758 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7761 g_assert_not_reached();
7765 case 0xc: /* FMAXNMP */
7766 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7768 case 0xd: /* FADDP */
7769 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7771 case 0xf: /* FMAXP */
7772 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7774 case 0x2c: /* FMINNMP */
7775 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7777 case 0x2f: /* FMINP */
7778 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7781 g_assert_not_reached();
7785 write_fp_sreg(s
, rd
, tcg_res
);
7787 tcg_temp_free_i32(tcg_op1
);
7788 tcg_temp_free_i32(tcg_op2
);
7789 tcg_temp_free_i32(tcg_res
);
7793 tcg_temp_free_ptr(fpst
);
7798 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
7800 * This code is handles the common shifting code and is used by both
7801 * the vector and scalar code.
7803 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
7804 TCGv_i64 tcg_rnd
, bool accumulate
,
7805 bool is_u
, int size
, int shift
)
7807 bool extended_result
= false;
7808 bool round
= tcg_rnd
!= NULL
;
7810 TCGv_i64 tcg_src_hi
;
7812 if (round
&& size
== 3) {
7813 extended_result
= true;
7814 ext_lshift
= 64 - shift
;
7815 tcg_src_hi
= tcg_temp_new_i64();
7816 } else if (shift
== 64) {
7817 if (!accumulate
&& is_u
) {
7818 /* result is zero */
7819 tcg_gen_movi_i64(tcg_res
, 0);
7824 /* Deal with the rounding step */
7826 if (extended_result
) {
7827 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7829 /* take care of sign extending tcg_res */
7830 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
7831 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7832 tcg_src
, tcg_src_hi
,
7835 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7839 tcg_temp_free_i64(tcg_zero
);
7841 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
7845 /* Now do the shift right */
7846 if (round
&& extended_result
) {
7847 /* extended case, >64 bit precision required */
7848 if (ext_lshift
== 0) {
7849 /* special case, only high bits matter */
7850 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
7852 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7853 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
7854 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
7859 /* essentially shifting in 64 zeros */
7860 tcg_gen_movi_i64(tcg_src
, 0);
7862 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7866 /* effectively extending the sign-bit */
7867 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
7869 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
7875 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
7877 tcg_gen_mov_i64(tcg_res
, tcg_src
);
7880 if (extended_result
) {
7881 tcg_temp_free_i64(tcg_src_hi
);
7885 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
7886 static void handle_scalar_simd_shri(DisasContext
*s
,
7887 bool is_u
, int immh
, int immb
,
7888 int opcode
, int rn
, int rd
)
7891 int immhb
= immh
<< 3 | immb
;
7892 int shift
= 2 * (8 << size
) - immhb
;
7893 bool accumulate
= false;
7895 bool insert
= false;
7900 if (!extract32(immh
, 3, 1)) {
7901 unallocated_encoding(s
);
7905 if (!fp_access_check(s
)) {
7910 case 0x02: /* SSRA / USRA (accumulate) */
7913 case 0x04: /* SRSHR / URSHR (rounding) */
7916 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7917 accumulate
= round
= true;
7919 case 0x08: /* SRI */
7925 uint64_t round_const
= 1ULL << (shift
- 1);
7926 tcg_round
= tcg_const_i64(round_const
);
7931 tcg_rn
= read_fp_dreg(s
, rn
);
7932 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
7935 /* shift count same as element size is valid but does nothing;
7936 * special case to avoid potential shift by 64.
7938 int esize
= 8 << size
;
7939 if (shift
!= esize
) {
7940 tcg_gen_shri_i64(tcg_rn
, tcg_rn
, shift
);
7941 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, 0, esize
- shift
);
7944 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
7945 accumulate
, is_u
, size
, shift
);
7948 write_fp_dreg(s
, rd
, tcg_rd
);
7950 tcg_temp_free_i64(tcg_rn
);
7951 tcg_temp_free_i64(tcg_rd
);
7953 tcg_temp_free_i64(tcg_round
);
7957 /* SHL/SLI - Scalar shift left */
7958 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
7959 int immh
, int immb
, int opcode
,
7962 int size
= 32 - clz32(immh
) - 1;
7963 int immhb
= immh
<< 3 | immb
;
7964 int shift
= immhb
- (8 << size
);
7965 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
7966 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
7968 if (!extract32(immh
, 3, 1)) {
7969 unallocated_encoding(s
);
7973 if (!fp_access_check(s
)) {
7977 tcg_rn
= read_fp_dreg(s
, rn
);
7978 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
7981 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, shift
, 64 - shift
);
7983 tcg_gen_shli_i64(tcg_rd
, tcg_rn
, shift
);
7986 write_fp_dreg(s
, rd
, tcg_rd
);
7988 tcg_temp_free_i64(tcg_rn
);
7989 tcg_temp_free_i64(tcg_rd
);
7992 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
7993 * (signed/unsigned) narrowing */
7994 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
7995 bool is_u_shift
, bool is_u_narrow
,
7996 int immh
, int immb
, int opcode
,
7999 int immhb
= immh
<< 3 | immb
;
8000 int size
= 32 - clz32(immh
) - 1;
8001 int esize
= 8 << size
;
8002 int shift
= (2 * esize
) - immhb
;
8003 int elements
= is_scalar
? 1 : (64 / esize
);
8004 bool round
= extract32(opcode
, 0, 1);
8005 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
8006 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
8007 TCGv_i32 tcg_rd_narrowed
;
8010 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
8011 { gen_helper_neon_narrow_sat_s8
,
8012 gen_helper_neon_unarrow_sat8
},
8013 { gen_helper_neon_narrow_sat_s16
,
8014 gen_helper_neon_unarrow_sat16
},
8015 { gen_helper_neon_narrow_sat_s32
,
8016 gen_helper_neon_unarrow_sat32
},
8019 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
8020 gen_helper_neon_narrow_sat_u8
,
8021 gen_helper_neon_narrow_sat_u16
,
8022 gen_helper_neon_narrow_sat_u32
,
8025 NeonGenNarrowEnvFn
*narrowfn
;
8031 if (extract32(immh
, 3, 1)) {
8032 unallocated_encoding(s
);
8036 if (!fp_access_check(s
)) {
8041 narrowfn
= unsigned_narrow_fns
[size
];
8043 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
8046 tcg_rn
= tcg_temp_new_i64();
8047 tcg_rd
= tcg_temp_new_i64();
8048 tcg_rd_narrowed
= tcg_temp_new_i32();
8049 tcg_final
= tcg_const_i64(0);
8052 uint64_t round_const
= 1ULL << (shift
- 1);
8053 tcg_round
= tcg_const_i64(round_const
);
8058 for (i
= 0; i
< elements
; i
++) {
8059 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
8060 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8061 false, is_u_shift
, size
+1, shift
);
8062 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
8063 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
8064 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8068 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8070 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8074 tcg_temp_free_i64(tcg_round
);
8076 tcg_temp_free_i64(tcg_rn
);
8077 tcg_temp_free_i64(tcg_rd
);
8078 tcg_temp_free_i32(tcg_rd_narrowed
);
8079 tcg_temp_free_i64(tcg_final
);
8081 clear_vec_high(s
, is_q
, rd
);
8084 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
8085 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
8086 bool src_unsigned
, bool dst_unsigned
,
8087 int immh
, int immb
, int rn
, int rd
)
8089 int immhb
= immh
<< 3 | immb
;
8090 int size
= 32 - clz32(immh
) - 1;
8091 int shift
= immhb
- (8 << size
);
8095 assert(!(scalar
&& is_q
));
8098 if (!is_q
&& extract32(immh
, 3, 1)) {
8099 unallocated_encoding(s
);
8103 /* Since we use the variable-shift helpers we must
8104 * replicate the shift count into each element of
8105 * the tcg_shift value.
8109 shift
|= shift
<< 8;
8112 shift
|= shift
<< 16;
8118 g_assert_not_reached();
8122 if (!fp_access_check(s
)) {
8127 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
8128 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
8129 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
8130 { NULL
, gen_helper_neon_qshl_u64
},
8132 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
8133 int maxpass
= is_q
? 2 : 1;
8135 for (pass
= 0; pass
< maxpass
; pass
++) {
8136 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8138 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8139 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8140 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
8142 tcg_temp_free_i64(tcg_op
);
8144 tcg_temp_free_i64(tcg_shift
);
8145 clear_vec_high(s
, is_q
, rd
);
8147 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
8148 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
8150 { gen_helper_neon_qshl_s8
,
8151 gen_helper_neon_qshl_s16
,
8152 gen_helper_neon_qshl_s32
},
8153 { gen_helper_neon_qshlu_s8
,
8154 gen_helper_neon_qshlu_s16
,
8155 gen_helper_neon_qshlu_s32
}
8157 { NULL
, NULL
, NULL
},
8158 { gen_helper_neon_qshl_u8
,
8159 gen_helper_neon_qshl_u16
,
8160 gen_helper_neon_qshl_u32
}
8163 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
8164 TCGMemOp memop
= scalar
? size
: MO_32
;
8165 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
8167 for (pass
= 0; pass
< maxpass
; pass
++) {
8168 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8170 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
8171 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8175 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
8178 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
8183 g_assert_not_reached();
8185 write_fp_sreg(s
, rd
, tcg_op
);
8187 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
8190 tcg_temp_free_i32(tcg_op
);
8192 tcg_temp_free_i32(tcg_shift
);
8195 clear_vec_high(s
, is_q
, rd
);
8200 /* Common vector code for handling integer to FP conversion */
8201 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
8202 int elements
, int is_signed
,
8203 int fracbits
, int size
)
8205 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(size
== MO_16
);
8206 TCGv_i32 tcg_shift
= NULL
;
8208 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
8211 if (fracbits
|| size
== MO_64
) {
8212 tcg_shift
= tcg_const_i32(fracbits
);
8215 if (size
== MO_64
) {
8216 TCGv_i64 tcg_int64
= tcg_temp_new_i64();
8217 TCGv_i64 tcg_double
= tcg_temp_new_i64();
8219 for (pass
= 0; pass
< elements
; pass
++) {
8220 read_vec_element(s
, tcg_int64
, rn
, pass
, mop
);
8223 gen_helper_vfp_sqtod(tcg_double
, tcg_int64
,
8224 tcg_shift
, tcg_fpst
);
8226 gen_helper_vfp_uqtod(tcg_double
, tcg_int64
,
8227 tcg_shift
, tcg_fpst
);
8229 if (elements
== 1) {
8230 write_fp_dreg(s
, rd
, tcg_double
);
8232 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
8236 tcg_temp_free_i64(tcg_int64
);
8237 tcg_temp_free_i64(tcg_double
);
8240 TCGv_i32 tcg_int32
= tcg_temp_new_i32();
8241 TCGv_i32 tcg_float
= tcg_temp_new_i32();
8243 for (pass
= 0; pass
< elements
; pass
++) {
8244 read_vec_element_i32(s
, tcg_int32
, rn
, pass
, mop
);
8250 gen_helper_vfp_sltos(tcg_float
, tcg_int32
,
8251 tcg_shift
, tcg_fpst
);
8253 gen_helper_vfp_ultos(tcg_float
, tcg_int32
,
8254 tcg_shift
, tcg_fpst
);
8258 gen_helper_vfp_sitos(tcg_float
, tcg_int32
, tcg_fpst
);
8260 gen_helper_vfp_uitos(tcg_float
, tcg_int32
, tcg_fpst
);
8267 gen_helper_vfp_sltoh(tcg_float
, tcg_int32
,
8268 tcg_shift
, tcg_fpst
);
8270 gen_helper_vfp_ultoh(tcg_float
, tcg_int32
,
8271 tcg_shift
, tcg_fpst
);
8275 gen_helper_vfp_sitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8277 gen_helper_vfp_uitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8282 g_assert_not_reached();
8285 if (elements
== 1) {
8286 write_fp_sreg(s
, rd
, tcg_float
);
8288 write_vec_element_i32(s
, tcg_float
, rd
, pass
, size
);
8292 tcg_temp_free_i32(tcg_int32
);
8293 tcg_temp_free_i32(tcg_float
);
8296 tcg_temp_free_ptr(tcg_fpst
);
8298 tcg_temp_free_i32(tcg_shift
);
8301 clear_vec_high(s
, elements
<< size
== 16, rd
);
8304 /* UCVTF/SCVTF - Integer to FP conversion */
8305 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
8306 bool is_q
, bool is_u
,
8307 int immh
, int immb
, int opcode
,
8310 int size
, elements
, fracbits
;
8311 int immhb
= immh
<< 3 | immb
;
8315 if (!is_scalar
&& !is_q
) {
8316 unallocated_encoding(s
);
8319 } else if (immh
& 4) {
8321 } else if (immh
& 2) {
8323 if (!dc_isar_feature(aa64_fp16
, s
)) {
8324 unallocated_encoding(s
);
8328 /* immh == 0 would be a failure of the decode logic */
8329 g_assert(immh
== 1);
8330 unallocated_encoding(s
);
8337 elements
= (8 << is_q
) >> size
;
8339 fracbits
= (16 << size
) - immhb
;
8341 if (!fp_access_check(s
)) {
8345 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
8348 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
8349 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
8350 bool is_q
, bool is_u
,
8351 int immh
, int immb
, int rn
, int rd
)
8353 int immhb
= immh
<< 3 | immb
;
8354 int pass
, size
, fracbits
;
8355 TCGv_ptr tcg_fpstatus
;
8356 TCGv_i32 tcg_rmode
, tcg_shift
;
8360 if (!is_scalar
&& !is_q
) {
8361 unallocated_encoding(s
);
8364 } else if (immh
& 0x4) {
8366 } else if (immh
& 0x2) {
8368 if (!dc_isar_feature(aa64_fp16
, s
)) {
8369 unallocated_encoding(s
);
8373 /* Should have split out AdvSIMD modified immediate earlier. */
8375 unallocated_encoding(s
);
8379 if (!fp_access_check(s
)) {
8383 assert(!(is_scalar
&& is_q
));
8385 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
8386 tcg_fpstatus
= get_fpstatus_ptr(size
== MO_16
);
8387 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
8388 fracbits
= (16 << size
) - immhb
;
8389 tcg_shift
= tcg_const_i32(fracbits
);
8391 if (size
== MO_64
) {
8392 int maxpass
= is_scalar
? 1 : 2;
8394 for (pass
= 0; pass
< maxpass
; pass
++) {
8395 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8397 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8399 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8401 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8403 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
8404 tcg_temp_free_i64(tcg_op
);
8406 clear_vec_high(s
, is_q
, rd
);
8408 void (*fn
)(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
8409 int maxpass
= is_scalar
? 1 : ((8 << is_q
) >> size
);
8414 fn
= gen_helper_vfp_touhh
;
8416 fn
= gen_helper_vfp_toshh
;
8421 fn
= gen_helper_vfp_touls
;
8423 fn
= gen_helper_vfp_tosls
;
8427 g_assert_not_reached();
8430 for (pass
= 0; pass
< maxpass
; pass
++) {
8431 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8433 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
8434 fn(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8436 write_fp_sreg(s
, rd
, tcg_op
);
8438 write_vec_element_i32(s
, tcg_op
, rd
, pass
, size
);
8440 tcg_temp_free_i32(tcg_op
);
8443 clear_vec_high(s
, is_q
, rd
);
8447 tcg_temp_free_ptr(tcg_fpstatus
);
8448 tcg_temp_free_i32(tcg_shift
);
8449 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
8450 tcg_temp_free_i32(tcg_rmode
);
8453 /* AdvSIMD scalar shift by immediate
8454 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8455 * +-----+---+-------------+------+------+--------+---+------+------+
8456 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8457 * +-----+---+-------------+------+------+--------+---+------+------+
8459 * This is the scalar version so it works on a fixed sized registers
8461 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
8463 int rd
= extract32(insn
, 0, 5);
8464 int rn
= extract32(insn
, 5, 5);
8465 int opcode
= extract32(insn
, 11, 5);
8466 int immb
= extract32(insn
, 16, 3);
8467 int immh
= extract32(insn
, 19, 4);
8468 bool is_u
= extract32(insn
, 29, 1);
8471 unallocated_encoding(s
);
8476 case 0x08: /* SRI */
8478 unallocated_encoding(s
);
8482 case 0x00: /* SSHR / USHR */
8483 case 0x02: /* SSRA / USRA */
8484 case 0x04: /* SRSHR / URSHR */
8485 case 0x06: /* SRSRA / URSRA */
8486 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8488 case 0x0a: /* SHL / SLI */
8489 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8491 case 0x1c: /* SCVTF, UCVTF */
8492 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
8495 case 0x10: /* SQSHRUN, SQSHRUN2 */
8496 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
8498 unallocated_encoding(s
);
8501 handle_vec_simd_sqshrn(s
, true, false, false, true,
8502 immh
, immb
, opcode
, rn
, rd
);
8504 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
8505 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
8506 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
8507 immh
, immb
, opcode
, rn
, rd
);
8509 case 0xc: /* SQSHLU */
8511 unallocated_encoding(s
);
8514 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
8516 case 0xe: /* SQSHL, UQSHL */
8517 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
8519 case 0x1f: /* FCVTZS, FCVTZU */
8520 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
8523 unallocated_encoding(s
);
8528 /* AdvSIMD scalar three different
8529 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8530 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8531 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8532 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8534 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8536 bool is_u
= extract32(insn
, 29, 1);
8537 int size
= extract32(insn
, 22, 2);
8538 int opcode
= extract32(insn
, 12, 4);
8539 int rm
= extract32(insn
, 16, 5);
8540 int rn
= extract32(insn
, 5, 5);
8541 int rd
= extract32(insn
, 0, 5);
8544 unallocated_encoding(s
);
8549 case 0x9: /* SQDMLAL, SQDMLAL2 */
8550 case 0xb: /* SQDMLSL, SQDMLSL2 */
8551 case 0xd: /* SQDMULL, SQDMULL2 */
8552 if (size
== 0 || size
== 3) {
8553 unallocated_encoding(s
);
8558 unallocated_encoding(s
);
8562 if (!fp_access_check(s
)) {
8567 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8568 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8569 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8571 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
8572 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
8574 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
8575 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
8578 case 0xd: /* SQDMULL, SQDMULL2 */
8580 case 0xb: /* SQDMLSL, SQDMLSL2 */
8581 tcg_gen_neg_i64(tcg_res
, tcg_res
);
8583 case 0x9: /* SQDMLAL, SQDMLAL2 */
8584 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
8585 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
8589 g_assert_not_reached();
8592 write_fp_dreg(s
, rd
, tcg_res
);
8594 tcg_temp_free_i64(tcg_op1
);
8595 tcg_temp_free_i64(tcg_op2
);
8596 tcg_temp_free_i64(tcg_res
);
8598 TCGv_i32 tcg_op1
= read_fp_hreg(s
, rn
);
8599 TCGv_i32 tcg_op2
= read_fp_hreg(s
, rm
);
8600 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8602 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
8603 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
8606 case 0xd: /* SQDMULL, SQDMULL2 */
8608 case 0xb: /* SQDMLSL, SQDMLSL2 */
8609 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
8611 case 0x9: /* SQDMLAL, SQDMLAL2 */
8613 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
8614 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
8615 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
8617 tcg_temp_free_i64(tcg_op3
);
8621 g_assert_not_reached();
8624 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
8625 write_fp_dreg(s
, rd
, tcg_res
);
8627 tcg_temp_free_i32(tcg_op1
);
8628 tcg_temp_free_i32(tcg_op2
);
8629 tcg_temp_free_i64(tcg_res
);
8633 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
8634 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
8636 /* Handle 64x64->64 opcodes which are shared between the scalar
8637 * and vector 3-same groups. We cover every opcode where size == 3
8638 * is valid in either the three-reg-same (integer, not pairwise)
8639 * or scalar-three-reg-same groups.
8644 case 0x1: /* SQADD */
8646 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8648 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8651 case 0x5: /* SQSUB */
8653 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8655 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8658 case 0x6: /* CMGT, CMHI */
8659 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
8660 * We implement this using setcond (test) and then negating.
8662 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
8664 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
8665 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
8667 case 0x7: /* CMGE, CMHS */
8668 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
8670 case 0x11: /* CMTST, CMEQ */
8675 gen_cmtst_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8677 case 0x8: /* SSHL, USHL */
8679 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8681 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8684 case 0x9: /* SQSHL, UQSHL */
8686 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8688 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8691 case 0xa: /* SRSHL, URSHL */
8693 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8695 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8698 case 0xb: /* SQRSHL, UQRSHL */
8700 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8702 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8705 case 0x10: /* ADD, SUB */
8707 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8709 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8713 g_assert_not_reached();
8717 /* Handle the 3-same-operands float operations; shared by the scalar
8718 * and vector encodings. The caller must filter out any encodings
8719 * not allocated for the encoding it is dealing with.
8721 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
8722 int fpopcode
, int rd
, int rn
, int rm
)
8725 TCGv_ptr fpst
= get_fpstatus_ptr(false);
8727 for (pass
= 0; pass
< elements
; pass
++) {
8730 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8731 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8732 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8734 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8735 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8738 case 0x39: /* FMLS */
8739 /* As usual for ARM, separate negation for fused multiply-add */
8740 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
8742 case 0x19: /* FMLA */
8743 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8744 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
8747 case 0x18: /* FMAXNM */
8748 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8750 case 0x1a: /* FADD */
8751 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8753 case 0x1b: /* FMULX */
8754 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8756 case 0x1c: /* FCMEQ */
8757 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8759 case 0x1e: /* FMAX */
8760 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8762 case 0x1f: /* FRECPS */
8763 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8765 case 0x38: /* FMINNM */
8766 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8768 case 0x3a: /* FSUB */
8769 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8771 case 0x3e: /* FMIN */
8772 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8774 case 0x3f: /* FRSQRTS */
8775 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8777 case 0x5b: /* FMUL */
8778 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8780 case 0x5c: /* FCMGE */
8781 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8783 case 0x5d: /* FACGE */
8784 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8786 case 0x5f: /* FDIV */
8787 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8789 case 0x7a: /* FABD */
8790 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8791 gen_helper_vfp_absd(tcg_res
, tcg_res
);
8793 case 0x7c: /* FCMGT */
8794 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8796 case 0x7d: /* FACGT */
8797 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8800 g_assert_not_reached();
8803 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8805 tcg_temp_free_i64(tcg_res
);
8806 tcg_temp_free_i64(tcg_op1
);
8807 tcg_temp_free_i64(tcg_op2
);
8810 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8811 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8812 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8814 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
8815 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
8818 case 0x39: /* FMLS */
8819 /* As usual for ARM, separate negation for fused multiply-add */
8820 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
8822 case 0x19: /* FMLA */
8823 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8824 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
8827 case 0x1a: /* FADD */
8828 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8830 case 0x1b: /* FMULX */
8831 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8833 case 0x1c: /* FCMEQ */
8834 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8836 case 0x1e: /* FMAX */
8837 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8839 case 0x1f: /* FRECPS */
8840 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8842 case 0x18: /* FMAXNM */
8843 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8845 case 0x38: /* FMINNM */
8846 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8848 case 0x3a: /* FSUB */
8849 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8851 case 0x3e: /* FMIN */
8852 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8854 case 0x3f: /* FRSQRTS */
8855 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8857 case 0x5b: /* FMUL */
8858 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8860 case 0x5c: /* FCMGE */
8861 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8863 case 0x5d: /* FACGE */
8864 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8866 case 0x5f: /* FDIV */
8867 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8869 case 0x7a: /* FABD */
8870 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8871 gen_helper_vfp_abss(tcg_res
, tcg_res
);
8873 case 0x7c: /* FCMGT */
8874 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8876 case 0x7d: /* FACGT */
8877 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8880 g_assert_not_reached();
8883 if (elements
== 1) {
8884 /* scalar single so clear high part */
8885 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
8887 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
8888 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
8889 tcg_temp_free_i64(tcg_tmp
);
8891 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8894 tcg_temp_free_i32(tcg_res
);
8895 tcg_temp_free_i32(tcg_op1
);
8896 tcg_temp_free_i32(tcg_op2
);
8900 tcg_temp_free_ptr(fpst
);
8902 clear_vec_high(s
, elements
* (size
? 8 : 4) > 8, rd
);
8905 /* AdvSIMD scalar three same
8906 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8907 * +-----+---+-----------+------+---+------+--------+---+------+------+
8908 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8909 * +-----+---+-----------+------+---+------+--------+---+------+------+
8911 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
8913 int rd
= extract32(insn
, 0, 5);
8914 int rn
= extract32(insn
, 5, 5);
8915 int opcode
= extract32(insn
, 11, 5);
8916 int rm
= extract32(insn
, 16, 5);
8917 int size
= extract32(insn
, 22, 2);
8918 bool u
= extract32(insn
, 29, 1);
8921 if (opcode
>= 0x18) {
8922 /* Floating point: U, size[1] and opcode indicate operation */
8923 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
8925 case 0x1b: /* FMULX */
8926 case 0x1f: /* FRECPS */
8927 case 0x3f: /* FRSQRTS */
8928 case 0x5d: /* FACGE */
8929 case 0x7d: /* FACGT */
8930 case 0x1c: /* FCMEQ */
8931 case 0x5c: /* FCMGE */
8932 case 0x7c: /* FCMGT */
8933 case 0x7a: /* FABD */
8936 unallocated_encoding(s
);
8940 if (!fp_access_check(s
)) {
8944 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
8949 case 0x1: /* SQADD, UQADD */
8950 case 0x5: /* SQSUB, UQSUB */
8951 case 0x9: /* SQSHL, UQSHL */
8952 case 0xb: /* SQRSHL, UQRSHL */
8954 case 0x8: /* SSHL, USHL */
8955 case 0xa: /* SRSHL, URSHL */
8956 case 0x6: /* CMGT, CMHI */
8957 case 0x7: /* CMGE, CMHS */
8958 case 0x11: /* CMTST, CMEQ */
8959 case 0x10: /* ADD, SUB (vector) */
8961 unallocated_encoding(s
);
8965 case 0x16: /* SQDMULH, SQRDMULH (vector) */
8966 if (size
!= 1 && size
!= 2) {
8967 unallocated_encoding(s
);
8972 unallocated_encoding(s
);
8976 if (!fp_access_check(s
)) {
8980 tcg_rd
= tcg_temp_new_i64();
8983 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
8984 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
8986 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
8987 tcg_temp_free_i64(tcg_rn
);
8988 tcg_temp_free_i64(tcg_rm
);
8990 /* Do a single operation on the lowest element in the vector.
8991 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
8992 * no side effects for all these operations.
8993 * OPTME: special-purpose helpers would avoid doing some
8994 * unnecessary work in the helper for the 8 and 16 bit cases.
8996 NeonGenTwoOpEnvFn
*genenvfn
;
8997 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
8998 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
8999 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
9001 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
9002 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
9005 case 0x1: /* SQADD, UQADD */
9007 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9008 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9009 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9010 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9012 genenvfn
= fns
[size
][u
];
9015 case 0x5: /* SQSUB, UQSUB */
9017 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9018 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9019 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9020 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9022 genenvfn
= fns
[size
][u
];
9025 case 0x9: /* SQSHL, UQSHL */
9027 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9028 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9029 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9030 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9032 genenvfn
= fns
[size
][u
];
9035 case 0xb: /* SQRSHL, UQRSHL */
9037 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9038 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9039 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9040 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9042 genenvfn
= fns
[size
][u
];
9045 case 0x16: /* SQDMULH, SQRDMULH */
9047 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9048 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9049 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9051 assert(size
== 1 || size
== 2);
9052 genenvfn
= fns
[size
- 1][u
];
9056 g_assert_not_reached();
9059 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
9060 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
9061 tcg_temp_free_i32(tcg_rd32
);
9062 tcg_temp_free_i32(tcg_rn
);
9063 tcg_temp_free_i32(tcg_rm
);
9066 write_fp_dreg(s
, rd
, tcg_rd
);
9068 tcg_temp_free_i64(tcg_rd
);
9071 /* AdvSIMD scalar three same FP16
9072 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
9073 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9074 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
9075 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9076 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
9077 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
9079 static void disas_simd_scalar_three_reg_same_fp16(DisasContext
*s
,
9082 int rd
= extract32(insn
, 0, 5);
9083 int rn
= extract32(insn
, 5, 5);
9084 int opcode
= extract32(insn
, 11, 3);
9085 int rm
= extract32(insn
, 16, 5);
9086 bool u
= extract32(insn
, 29, 1);
9087 bool a
= extract32(insn
, 23, 1);
9088 int fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
9095 case 0x03: /* FMULX */
9096 case 0x04: /* FCMEQ (reg) */
9097 case 0x07: /* FRECPS */
9098 case 0x0f: /* FRSQRTS */
9099 case 0x14: /* FCMGE (reg) */
9100 case 0x15: /* FACGE */
9101 case 0x1a: /* FABD */
9102 case 0x1c: /* FCMGT (reg) */
9103 case 0x1d: /* FACGT */
9106 unallocated_encoding(s
);
9110 if (!dc_isar_feature(aa64_fp16
, s
)) {
9111 unallocated_encoding(s
);
9114 if (!fp_access_check(s
)) {
9118 fpst
= get_fpstatus_ptr(true);
9120 tcg_op1
= read_fp_hreg(s
, rn
);
9121 tcg_op2
= read_fp_hreg(s
, rm
);
9122 tcg_res
= tcg_temp_new_i32();
9125 case 0x03: /* FMULX */
9126 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9128 case 0x04: /* FCMEQ (reg) */
9129 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9131 case 0x07: /* FRECPS */
9132 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9134 case 0x0f: /* FRSQRTS */
9135 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9137 case 0x14: /* FCMGE (reg) */
9138 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9140 case 0x15: /* FACGE */
9141 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9143 case 0x1a: /* FABD */
9144 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9145 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
9147 case 0x1c: /* FCMGT (reg) */
9148 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9150 case 0x1d: /* FACGT */
9151 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9154 g_assert_not_reached();
9157 write_fp_sreg(s
, rd
, tcg_res
);
9160 tcg_temp_free_i32(tcg_res
);
9161 tcg_temp_free_i32(tcg_op1
);
9162 tcg_temp_free_i32(tcg_op2
);
9163 tcg_temp_free_ptr(fpst
);
9166 /* AdvSIMD scalar three same extra
9167 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
9168 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9169 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
9170 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9172 static void disas_simd_scalar_three_reg_same_extra(DisasContext
*s
,
9175 int rd
= extract32(insn
, 0, 5);
9176 int rn
= extract32(insn
, 5, 5);
9177 int opcode
= extract32(insn
, 11, 4);
9178 int rm
= extract32(insn
, 16, 5);
9179 int size
= extract32(insn
, 22, 2);
9180 bool u
= extract32(insn
, 29, 1);
9181 TCGv_i32 ele1
, ele2
, ele3
;
9185 switch (u
* 16 + opcode
) {
9186 case 0x10: /* SQRDMLAH (vector) */
9187 case 0x11: /* SQRDMLSH (vector) */
9188 if (size
!= 1 && size
!= 2) {
9189 unallocated_encoding(s
);
9192 feature
= dc_isar_feature(aa64_rdm
, s
);
9195 unallocated_encoding(s
);
9199 unallocated_encoding(s
);
9202 if (!fp_access_check(s
)) {
9206 /* Do a single operation on the lowest element in the vector.
9207 * We use the standard Neon helpers and rely on 0 OP 0 == 0
9208 * with no side effects for all these operations.
9209 * OPTME: special-purpose helpers would avoid doing some
9210 * unnecessary work in the helper for the 16 bit cases.
9212 ele1
= tcg_temp_new_i32();
9213 ele2
= tcg_temp_new_i32();
9214 ele3
= tcg_temp_new_i32();
9216 read_vec_element_i32(s
, ele1
, rn
, 0, size
);
9217 read_vec_element_i32(s
, ele2
, rm
, 0, size
);
9218 read_vec_element_i32(s
, ele3
, rd
, 0, size
);
9221 case 0x0: /* SQRDMLAH */
9223 gen_helper_neon_qrdmlah_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9225 gen_helper_neon_qrdmlah_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9228 case 0x1: /* SQRDMLSH */
9230 gen_helper_neon_qrdmlsh_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9232 gen_helper_neon_qrdmlsh_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9236 g_assert_not_reached();
9238 tcg_temp_free_i32(ele1
);
9239 tcg_temp_free_i32(ele2
);
9241 res
= tcg_temp_new_i64();
9242 tcg_gen_extu_i32_i64(res
, ele3
);
9243 tcg_temp_free_i32(ele3
);
9245 write_fp_dreg(s
, rd
, res
);
9246 tcg_temp_free_i64(res
);
9249 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
9250 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
9251 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
9253 /* Handle 64->64 opcodes which are shared between the scalar and
9254 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
9255 * is valid in either group and also the double-precision fp ops.
9256 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
9262 case 0x4: /* CLS, CLZ */
9264 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
9266 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
9270 /* This opcode is shared with CNT and RBIT but we have earlier
9271 * enforced that size == 3 if and only if this is the NOT insn.
9273 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
9275 case 0x7: /* SQABS, SQNEG */
9277 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
9279 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
9282 case 0xa: /* CMLT */
9283 /* 64 bit integer comparison against zero, result is
9284 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
9289 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
9290 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
9292 case 0x8: /* CMGT, CMGE */
9293 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
9295 case 0x9: /* CMEQ, CMLE */
9296 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
9298 case 0xb: /* ABS, NEG */
9300 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
9302 tcg_gen_abs_i64(tcg_rd
, tcg_rn
);
9305 case 0x2f: /* FABS */
9306 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
9308 case 0x6f: /* FNEG */
9309 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
9311 case 0x7f: /* FSQRT */
9312 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
9314 case 0x1a: /* FCVTNS */
9315 case 0x1b: /* FCVTMS */
9316 case 0x1c: /* FCVTAS */
9317 case 0x3a: /* FCVTPS */
9318 case 0x3b: /* FCVTZS */
9320 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9321 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9322 tcg_temp_free_i32(tcg_shift
);
9325 case 0x5a: /* FCVTNU */
9326 case 0x5b: /* FCVTMU */
9327 case 0x5c: /* FCVTAU */
9328 case 0x7a: /* FCVTPU */
9329 case 0x7b: /* FCVTZU */
9331 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9332 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9333 tcg_temp_free_i32(tcg_shift
);
9336 case 0x18: /* FRINTN */
9337 case 0x19: /* FRINTM */
9338 case 0x38: /* FRINTP */
9339 case 0x39: /* FRINTZ */
9340 case 0x58: /* FRINTA */
9341 case 0x79: /* FRINTI */
9342 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9344 case 0x59: /* FRINTX */
9345 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9347 case 0x1e: /* FRINT32Z */
9348 case 0x5e: /* FRINT32X */
9349 gen_helper_frint32_d(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9351 case 0x1f: /* FRINT64Z */
9352 case 0x5f: /* FRINT64X */
9353 gen_helper_frint64_d(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9356 g_assert_not_reached();
9360 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
9361 bool is_scalar
, bool is_u
, bool is_q
,
9362 int size
, int rn
, int rd
)
9364 bool is_double
= (size
== MO_64
);
9367 if (!fp_access_check(s
)) {
9371 fpst
= get_fpstatus_ptr(size
== MO_16
);
9374 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9375 TCGv_i64 tcg_zero
= tcg_const_i64(0);
9376 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9377 NeonGenTwoDoubleOPFn
*genfn
;
9382 case 0x2e: /* FCMLT (zero) */
9385 case 0x2c: /* FCMGT (zero) */
9386 genfn
= gen_helper_neon_cgt_f64
;
9388 case 0x2d: /* FCMEQ (zero) */
9389 genfn
= gen_helper_neon_ceq_f64
;
9391 case 0x6d: /* FCMLE (zero) */
9394 case 0x6c: /* FCMGE (zero) */
9395 genfn
= gen_helper_neon_cge_f64
;
9398 g_assert_not_reached();
9401 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9402 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9404 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
9406 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
9408 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9410 tcg_temp_free_i64(tcg_res
);
9411 tcg_temp_free_i64(tcg_zero
);
9412 tcg_temp_free_i64(tcg_op
);
9414 clear_vec_high(s
, !is_scalar
, rd
);
9416 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9417 TCGv_i32 tcg_zero
= tcg_const_i32(0);
9418 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9419 NeonGenTwoSingleOPFn
*genfn
;
9421 int pass
, maxpasses
;
9423 if (size
== MO_16
) {
9425 case 0x2e: /* FCMLT (zero) */
9428 case 0x2c: /* FCMGT (zero) */
9429 genfn
= gen_helper_advsimd_cgt_f16
;
9431 case 0x2d: /* FCMEQ (zero) */
9432 genfn
= gen_helper_advsimd_ceq_f16
;
9434 case 0x6d: /* FCMLE (zero) */
9437 case 0x6c: /* FCMGE (zero) */
9438 genfn
= gen_helper_advsimd_cge_f16
;
9441 g_assert_not_reached();
9445 case 0x2e: /* FCMLT (zero) */
9448 case 0x2c: /* FCMGT (zero) */
9449 genfn
= gen_helper_neon_cgt_f32
;
9451 case 0x2d: /* FCMEQ (zero) */
9452 genfn
= gen_helper_neon_ceq_f32
;
9454 case 0x6d: /* FCMLE (zero) */
9457 case 0x6c: /* FCMGE (zero) */
9458 genfn
= gen_helper_neon_cge_f32
;
9461 g_assert_not_reached();
9468 int vector_size
= 8 << is_q
;
9469 maxpasses
= vector_size
>> size
;
9472 for (pass
= 0; pass
< maxpasses
; pass
++) {
9473 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
9475 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
9477 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
9480 write_fp_sreg(s
, rd
, tcg_res
);
9482 write_vec_element_i32(s
, tcg_res
, rd
, pass
, size
);
9485 tcg_temp_free_i32(tcg_res
);
9486 tcg_temp_free_i32(tcg_zero
);
9487 tcg_temp_free_i32(tcg_op
);
9489 clear_vec_high(s
, is_q
, rd
);
9493 tcg_temp_free_ptr(fpst
);
9496 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
9497 bool is_scalar
, bool is_u
, bool is_q
,
9498 int size
, int rn
, int rd
)
9500 bool is_double
= (size
== 3);
9501 TCGv_ptr fpst
= get_fpstatus_ptr(false);
9504 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9505 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9508 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9509 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9511 case 0x3d: /* FRECPE */
9512 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
9514 case 0x3f: /* FRECPX */
9515 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
9517 case 0x7d: /* FRSQRTE */
9518 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
9521 g_assert_not_reached();
9523 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9525 tcg_temp_free_i64(tcg_res
);
9526 tcg_temp_free_i64(tcg_op
);
9527 clear_vec_high(s
, !is_scalar
, rd
);
9529 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9530 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9531 int pass
, maxpasses
;
9536 maxpasses
= is_q
? 4 : 2;
9539 for (pass
= 0; pass
< maxpasses
; pass
++) {
9540 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
9543 case 0x3c: /* URECPE */
9544 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
9546 case 0x3d: /* FRECPE */
9547 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
9549 case 0x3f: /* FRECPX */
9550 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
9552 case 0x7d: /* FRSQRTE */
9553 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
9556 g_assert_not_reached();
9560 write_fp_sreg(s
, rd
, tcg_res
);
9562 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9565 tcg_temp_free_i32(tcg_res
);
9566 tcg_temp_free_i32(tcg_op
);
9568 clear_vec_high(s
, is_q
, rd
);
9571 tcg_temp_free_ptr(fpst
);
9574 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
9575 int opcode
, bool u
, bool is_q
,
9576 int size
, int rn
, int rd
)
9578 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
9579 * in the source becomes a size element in the destination).
9582 TCGv_i32 tcg_res
[2];
9583 int destelt
= is_q
? 2 : 0;
9584 int passes
= scalar
? 1 : 2;
9587 tcg_res
[1] = tcg_const_i32(0);
9590 for (pass
= 0; pass
< passes
; pass
++) {
9591 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9592 NeonGenNarrowFn
*genfn
= NULL
;
9593 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
9596 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
9598 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9600 tcg_res
[pass
] = tcg_temp_new_i32();
9603 case 0x12: /* XTN, SQXTUN */
9605 static NeonGenNarrowFn
* const xtnfns
[3] = {
9606 gen_helper_neon_narrow_u8
,
9607 gen_helper_neon_narrow_u16
,
9608 tcg_gen_extrl_i64_i32
,
9610 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
9611 gen_helper_neon_unarrow_sat8
,
9612 gen_helper_neon_unarrow_sat16
,
9613 gen_helper_neon_unarrow_sat32
,
9616 genenvfn
= sqxtunfns
[size
];
9618 genfn
= xtnfns
[size
];
9622 case 0x14: /* SQXTN, UQXTN */
9624 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
9625 { gen_helper_neon_narrow_sat_s8
,
9626 gen_helper_neon_narrow_sat_u8
},
9627 { gen_helper_neon_narrow_sat_s16
,
9628 gen_helper_neon_narrow_sat_u16
},
9629 { gen_helper_neon_narrow_sat_s32
,
9630 gen_helper_neon_narrow_sat_u32
},
9632 genenvfn
= fns
[size
][u
];
9635 case 0x16: /* FCVTN, FCVTN2 */
9636 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
9638 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
9640 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
9641 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
9642 TCGv_ptr fpst
= get_fpstatus_ptr(false);
9643 TCGv_i32 ahp
= get_ahp_flag();
9645 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
9646 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, fpst
, ahp
);
9647 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, fpst
, ahp
);
9648 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
9649 tcg_temp_free_i32(tcg_lo
);
9650 tcg_temp_free_i32(tcg_hi
);
9651 tcg_temp_free_ptr(fpst
);
9652 tcg_temp_free_i32(ahp
);
9655 case 0x56: /* FCVTXN, FCVTXN2 */
9656 /* 64 bit to 32 bit float conversion
9657 * with von Neumann rounding (round to odd)
9660 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
9663 g_assert_not_reached();
9667 genfn(tcg_res
[pass
], tcg_op
);
9668 } else if (genenvfn
) {
9669 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
9672 tcg_temp_free_i64(tcg_op
);
9675 for (pass
= 0; pass
< 2; pass
++) {
9676 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
9677 tcg_temp_free_i32(tcg_res
[pass
]);
9679 clear_vec_high(s
, is_q
, rd
);
9682 /* Remaining saturating accumulating ops */
9683 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
9684 bool is_q
, int size
, int rn
, int rd
)
9686 bool is_double
= (size
== 3);
9689 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9690 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9693 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9694 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
9695 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9697 if (is_u
) { /* USQADD */
9698 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9699 } else { /* SUQADD */
9700 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9702 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9704 tcg_temp_free_i64(tcg_rd
);
9705 tcg_temp_free_i64(tcg_rn
);
9706 clear_vec_high(s
, !is_scalar
, rd
);
9708 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9709 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9710 int pass
, maxpasses
;
9715 maxpasses
= is_q
? 4 : 2;
9718 for (pass
= 0; pass
< maxpasses
; pass
++) {
9720 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
9721 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
9723 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
9724 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9727 if (is_u
) { /* USQADD */
9730 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9733 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9736 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9739 g_assert_not_reached();
9741 } else { /* SUQADD */
9744 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9747 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9750 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9753 g_assert_not_reached();
9758 TCGv_i64 tcg_zero
= tcg_const_i64(0);
9759 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
9760 tcg_temp_free_i64(tcg_zero
);
9762 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9764 tcg_temp_free_i32(tcg_rd
);
9765 tcg_temp_free_i32(tcg_rn
);
9766 clear_vec_high(s
, is_q
, rd
);
9770 /* AdvSIMD scalar two reg misc
9771 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9772 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9773 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9774 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9776 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9778 int rd
= extract32(insn
, 0, 5);
9779 int rn
= extract32(insn
, 5, 5);
9780 int opcode
= extract32(insn
, 12, 5);
9781 int size
= extract32(insn
, 22, 2);
9782 bool u
= extract32(insn
, 29, 1);
9783 bool is_fcvt
= false;
9786 TCGv_ptr tcg_fpstatus
;
9789 case 0x3: /* USQADD / SUQADD*/
9790 if (!fp_access_check(s
)) {
9793 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
9795 case 0x7: /* SQABS / SQNEG */
9797 case 0xa: /* CMLT */
9799 unallocated_encoding(s
);
9803 case 0x8: /* CMGT, CMGE */
9804 case 0x9: /* CMEQ, CMLE */
9805 case 0xb: /* ABS, NEG */
9807 unallocated_encoding(s
);
9811 case 0x12: /* SQXTUN */
9813 unallocated_encoding(s
);
9817 case 0x14: /* SQXTN, UQXTN */
9819 unallocated_encoding(s
);
9822 if (!fp_access_check(s
)) {
9825 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
9830 /* Floating point: U, size[1] and opcode indicate operation;
9831 * size[0] indicates single or double precision.
9833 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9834 size
= extract32(size
, 0, 1) ? 3 : 2;
9836 case 0x2c: /* FCMGT (zero) */
9837 case 0x2d: /* FCMEQ (zero) */
9838 case 0x2e: /* FCMLT (zero) */
9839 case 0x6c: /* FCMGE (zero) */
9840 case 0x6d: /* FCMLE (zero) */
9841 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
9843 case 0x1d: /* SCVTF */
9844 case 0x5d: /* UCVTF */
9846 bool is_signed
= (opcode
== 0x1d);
9847 if (!fp_access_check(s
)) {
9850 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
9853 case 0x3d: /* FRECPE */
9854 case 0x3f: /* FRECPX */
9855 case 0x7d: /* FRSQRTE */
9856 if (!fp_access_check(s
)) {
9859 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
9861 case 0x1a: /* FCVTNS */
9862 case 0x1b: /* FCVTMS */
9863 case 0x3a: /* FCVTPS */
9864 case 0x3b: /* FCVTZS */
9865 case 0x5a: /* FCVTNU */
9866 case 0x5b: /* FCVTMU */
9867 case 0x7a: /* FCVTPU */
9868 case 0x7b: /* FCVTZU */
9870 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9872 case 0x1c: /* FCVTAS */
9873 case 0x5c: /* FCVTAU */
9874 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
9876 rmode
= FPROUNDING_TIEAWAY
;
9878 case 0x56: /* FCVTXN, FCVTXN2 */
9880 unallocated_encoding(s
);
9883 if (!fp_access_check(s
)) {
9886 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
9889 unallocated_encoding(s
);
9894 unallocated_encoding(s
);
9898 if (!fp_access_check(s
)) {
9903 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
9904 tcg_fpstatus
= get_fpstatus_ptr(false);
9905 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9908 tcg_fpstatus
= NULL
;
9912 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
9913 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9915 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
9916 write_fp_dreg(s
, rd
, tcg_rd
);
9917 tcg_temp_free_i64(tcg_rd
);
9918 tcg_temp_free_i64(tcg_rn
);
9920 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9921 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9923 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
9926 case 0x7: /* SQABS, SQNEG */
9928 NeonGenOneOpEnvFn
*genfn
;
9929 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
9930 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
9931 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
9932 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
9934 genfn
= fns
[size
][u
];
9935 genfn(tcg_rd
, cpu_env
, tcg_rn
);
9938 case 0x1a: /* FCVTNS */
9939 case 0x1b: /* FCVTMS */
9940 case 0x1c: /* FCVTAS */
9941 case 0x3a: /* FCVTPS */
9942 case 0x3b: /* FCVTZS */
9944 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9945 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9946 tcg_temp_free_i32(tcg_shift
);
9949 case 0x5a: /* FCVTNU */
9950 case 0x5b: /* FCVTMU */
9951 case 0x5c: /* FCVTAU */
9952 case 0x7a: /* FCVTPU */
9953 case 0x7b: /* FCVTZU */
9955 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9956 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9957 tcg_temp_free_i32(tcg_shift
);
9961 g_assert_not_reached();
9964 write_fp_sreg(s
, rd
, tcg_rd
);
9965 tcg_temp_free_i32(tcg_rd
);
9966 tcg_temp_free_i32(tcg_rn
);
9970 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9971 tcg_temp_free_i32(tcg_rmode
);
9972 tcg_temp_free_ptr(tcg_fpstatus
);
9976 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
9977 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
9978 int immh
, int immb
, int opcode
, int rn
, int rd
)
9980 int size
= 32 - clz32(immh
) - 1;
9981 int immhb
= immh
<< 3 | immb
;
9982 int shift
= 2 * (8 << size
) - immhb
;
9983 bool accumulate
= false;
9984 int dsize
= is_q
? 128 : 64;
9985 int esize
= 8 << size
;
9986 int elements
= dsize
/esize
;
9987 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
9988 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
9989 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
9991 uint64_t round_const
;
9994 if (extract32(immh
, 3, 1) && !is_q
) {
9995 unallocated_encoding(s
);
9998 tcg_debug_assert(size
<= 3);
10000 if (!fp_access_check(s
)) {
10005 case 0x02: /* SSRA / USRA (accumulate) */
10007 /* Shift count same as element size produces zero to add. */
10008 if (shift
== 8 << size
) {
10011 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &usra_op
[size
]);
10013 /* Shift count same as element size produces all sign to add. */
10014 if (shift
== 8 << size
) {
10017 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &ssra_op
[size
]);
10020 case 0x08: /* SRI */
10021 /* Shift count same as element size is valid but does nothing. */
10022 if (shift
== 8 << size
) {
10025 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &sri_op
[size
]);
10028 case 0x00: /* SSHR / USHR */
10030 if (shift
== 8 << size
) {
10031 /* Shift count the same size as element size produces zero. */
10032 tcg_gen_gvec_dup8i(vec_full_reg_offset(s
, rd
),
10033 is_q
? 16 : 8, vec_full_reg_size(s
), 0);
10035 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shri
, size
);
10038 /* Shift count the same size as element size produces all sign. */
10039 if (shift
== 8 << size
) {
10042 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_sari
, size
);
10046 case 0x04: /* SRSHR / URSHR (rounding) */
10048 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10052 g_assert_not_reached();
10055 round_const
= 1ULL << (shift
- 1);
10056 tcg_round
= tcg_const_i64(round_const
);
10058 for (i
= 0; i
< elements
; i
++) {
10059 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
10061 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
10064 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
10065 accumulate
, is_u
, size
, shift
);
10067 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
10069 tcg_temp_free_i64(tcg_round
);
10072 clear_vec_high(s
, is_q
, rd
);
10075 /* SHL/SLI - Vector shift left */
10076 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
10077 int immh
, int immb
, int opcode
, int rn
, int rd
)
10079 int size
= 32 - clz32(immh
) - 1;
10080 int immhb
= immh
<< 3 | immb
;
10081 int shift
= immhb
- (8 << size
);
10083 /* Range of size is limited by decode: immh is a non-zero 4 bit field */
10084 assert(size
>= 0 && size
<= 3);
10086 if (extract32(immh
, 3, 1) && !is_q
) {
10087 unallocated_encoding(s
);
10091 if (!fp_access_check(s
)) {
10096 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &sli_op
[size
]);
10098 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shli
, size
);
10102 /* USHLL/SHLL - Vector shift left with widening */
10103 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
10104 int immh
, int immb
, int opcode
, int rn
, int rd
)
10106 int size
= 32 - clz32(immh
) - 1;
10107 int immhb
= immh
<< 3 | immb
;
10108 int shift
= immhb
- (8 << size
);
10110 int esize
= 8 << size
;
10111 int elements
= dsize
/esize
;
10112 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
10113 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
10117 unallocated_encoding(s
);
10121 if (!fp_access_check(s
)) {
10125 /* For the LL variants the store is larger than the load,
10126 * so if rd == rn we would overwrite parts of our input.
10127 * So load everything right now and use shifts in the main loop.
10129 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
10131 for (i
= 0; i
< elements
; i
++) {
10132 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
10133 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
10134 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
10135 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
10139 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
10140 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
10141 int immh
, int immb
, int opcode
, int rn
, int rd
)
10143 int immhb
= immh
<< 3 | immb
;
10144 int size
= 32 - clz32(immh
) - 1;
10146 int esize
= 8 << size
;
10147 int elements
= dsize
/esize
;
10148 int shift
= (2 * esize
) - immhb
;
10149 bool round
= extract32(opcode
, 0, 1);
10150 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
10151 TCGv_i64 tcg_round
;
10154 if (extract32(immh
, 3, 1)) {
10155 unallocated_encoding(s
);
10159 if (!fp_access_check(s
)) {
10163 tcg_rn
= tcg_temp_new_i64();
10164 tcg_rd
= tcg_temp_new_i64();
10165 tcg_final
= tcg_temp_new_i64();
10166 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
10169 uint64_t round_const
= 1ULL << (shift
- 1);
10170 tcg_round
= tcg_const_i64(round_const
);
10175 for (i
= 0; i
< elements
; i
++) {
10176 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
10177 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
10178 false, true, size
+1, shift
);
10180 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
10184 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
10186 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
10189 tcg_temp_free_i64(tcg_round
);
10191 tcg_temp_free_i64(tcg_rn
);
10192 tcg_temp_free_i64(tcg_rd
);
10193 tcg_temp_free_i64(tcg_final
);
10195 clear_vec_high(s
, is_q
, rd
);
10199 /* AdvSIMD shift by immediate
10200 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
10201 * +---+---+---+-------------+------+------+--------+---+------+------+
10202 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
10203 * +---+---+---+-------------+------+------+--------+---+------+------+
10205 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
10207 int rd
= extract32(insn
, 0, 5);
10208 int rn
= extract32(insn
, 5, 5);
10209 int opcode
= extract32(insn
, 11, 5);
10210 int immb
= extract32(insn
, 16, 3);
10211 int immh
= extract32(insn
, 19, 4);
10212 bool is_u
= extract32(insn
, 29, 1);
10213 bool is_q
= extract32(insn
, 30, 1);
10216 case 0x08: /* SRI */
10218 unallocated_encoding(s
);
10222 case 0x00: /* SSHR / USHR */
10223 case 0x02: /* SSRA / USRA (accumulate) */
10224 case 0x04: /* SRSHR / URSHR (rounding) */
10225 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10226 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10228 case 0x0a: /* SHL / SLI */
10229 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10231 case 0x10: /* SHRN */
10232 case 0x11: /* RSHRN / SQRSHRUN */
10234 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
10237 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
10240 case 0x12: /* SQSHRN / UQSHRN */
10241 case 0x13: /* SQRSHRN / UQRSHRN */
10242 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
10245 case 0x14: /* SSHLL / USHLL */
10246 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10248 case 0x1c: /* SCVTF / UCVTF */
10249 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
10252 case 0xc: /* SQSHLU */
10254 unallocated_encoding(s
);
10257 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
10259 case 0xe: /* SQSHL, UQSHL */
10260 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
10262 case 0x1f: /* FCVTZS/ FCVTZU */
10263 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
10266 unallocated_encoding(s
);
10271 /* Generate code to do a "long" addition or subtraction, ie one done in
10272 * TCGv_i64 on vector lanes twice the width specified by size.
10274 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
10275 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
10277 static NeonGenTwo64OpFn
* const fns
[3][2] = {
10278 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
10279 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
10280 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
10282 NeonGenTwo64OpFn
*genfn
;
10285 genfn
= fns
[size
][is_sub
];
10286 genfn(tcg_res
, tcg_op1
, tcg_op2
);
10289 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
10290 int opcode
, int rd
, int rn
, int rm
)
10292 /* 3-reg-different widening insns: 64 x 64 -> 128 */
10293 TCGv_i64 tcg_res
[2];
10296 tcg_res
[0] = tcg_temp_new_i64();
10297 tcg_res
[1] = tcg_temp_new_i64();
10299 /* Does this op do an adding accumulate, a subtracting accumulate,
10300 * or no accumulate at all?
10318 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10319 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10322 /* size == 2 means two 32x32->64 operations; this is worth special
10323 * casing because we can generally handle it inline.
10326 for (pass
= 0; pass
< 2; pass
++) {
10327 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10328 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10329 TCGv_i64 tcg_passres
;
10330 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
10332 int elt
= pass
+ is_q
* 2;
10334 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
10335 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
10338 tcg_passres
= tcg_res
[pass
];
10340 tcg_passres
= tcg_temp_new_i64();
10344 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10345 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10347 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10348 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10350 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10351 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10353 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
10354 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
10356 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
10357 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
10358 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
10360 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
10361 tcg_temp_free_i64(tcg_tmp1
);
10362 tcg_temp_free_i64(tcg_tmp2
);
10365 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10366 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10367 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10368 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10370 case 9: /* SQDMLAL, SQDMLAL2 */
10371 case 11: /* SQDMLSL, SQDMLSL2 */
10372 case 13: /* SQDMULL, SQDMULL2 */
10373 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10374 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10375 tcg_passres
, tcg_passres
);
10378 g_assert_not_reached();
10381 if (opcode
== 9 || opcode
== 11) {
10382 /* saturating accumulate ops */
10384 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10386 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10387 tcg_res
[pass
], tcg_passres
);
10388 } else if (accop
> 0) {
10389 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10390 } else if (accop
< 0) {
10391 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10395 tcg_temp_free_i64(tcg_passres
);
10398 tcg_temp_free_i64(tcg_op1
);
10399 tcg_temp_free_i64(tcg_op2
);
10402 /* size 0 or 1, generally helper functions */
10403 for (pass
= 0; pass
< 2; pass
++) {
10404 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10405 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10406 TCGv_i64 tcg_passres
;
10407 int elt
= pass
+ is_q
* 2;
10409 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
10410 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
10413 tcg_passres
= tcg_res
[pass
];
10415 tcg_passres
= tcg_temp_new_i64();
10419 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10420 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10422 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
10423 static NeonGenWidenFn
* const widenfns
[2][2] = {
10424 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10425 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10427 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10429 widenfn(tcg_op2_64
, tcg_op2
);
10430 widenfn(tcg_passres
, tcg_op1
);
10431 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
10432 tcg_passres
, tcg_op2_64
);
10433 tcg_temp_free_i64(tcg_op2_64
);
10436 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10437 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10440 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10442 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10446 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
10448 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
10452 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10453 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10454 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10457 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
10459 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
10463 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10465 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10469 case 9: /* SQDMLAL, SQDMLAL2 */
10470 case 11: /* SQDMLSL, SQDMLSL2 */
10471 case 13: /* SQDMULL, SQDMULL2 */
10473 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10474 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10475 tcg_passres
, tcg_passres
);
10477 case 14: /* PMULL */
10479 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
10482 g_assert_not_reached();
10484 tcg_temp_free_i32(tcg_op1
);
10485 tcg_temp_free_i32(tcg_op2
);
10488 if (opcode
== 9 || opcode
== 11) {
10489 /* saturating accumulate ops */
10491 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10493 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10497 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
10498 tcg_res
[pass
], tcg_passres
);
10500 tcg_temp_free_i64(tcg_passres
);
10505 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10506 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10507 tcg_temp_free_i64(tcg_res
[0]);
10508 tcg_temp_free_i64(tcg_res
[1]);
10511 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
10512 int opcode
, int rd
, int rn
, int rm
)
10514 TCGv_i64 tcg_res
[2];
10515 int part
= is_q
? 2 : 0;
10518 for (pass
= 0; pass
< 2; pass
++) {
10519 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10520 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10521 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
10522 static NeonGenWidenFn
* const widenfns
[3][2] = {
10523 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10524 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10525 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
10527 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10529 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10530 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
10531 widenfn(tcg_op2_wide
, tcg_op2
);
10532 tcg_temp_free_i32(tcg_op2
);
10533 tcg_res
[pass
] = tcg_temp_new_i64();
10534 gen_neon_addl(size
, (opcode
== 3),
10535 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
10536 tcg_temp_free_i64(tcg_op1
);
10537 tcg_temp_free_i64(tcg_op2_wide
);
10540 for (pass
= 0; pass
< 2; pass
++) {
10541 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10542 tcg_temp_free_i64(tcg_res
[pass
]);
10546 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
10548 tcg_gen_addi_i64(in
, in
, 1U << 31);
10549 tcg_gen_extrh_i64_i32(res
, in
);
10552 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
10553 int opcode
, int rd
, int rn
, int rm
)
10555 TCGv_i32 tcg_res
[2];
10556 int part
= is_q
? 2 : 0;
10559 for (pass
= 0; pass
< 2; pass
++) {
10560 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10561 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10562 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
10563 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
10564 { gen_helper_neon_narrow_high_u8
,
10565 gen_helper_neon_narrow_round_high_u8
},
10566 { gen_helper_neon_narrow_high_u16
,
10567 gen_helper_neon_narrow_round_high_u16
},
10568 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
10570 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
10572 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10573 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
10575 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
10577 tcg_temp_free_i64(tcg_op1
);
10578 tcg_temp_free_i64(tcg_op2
);
10580 tcg_res
[pass
] = tcg_temp_new_i32();
10581 gennarrow(tcg_res
[pass
], tcg_wideres
);
10582 tcg_temp_free_i64(tcg_wideres
);
10585 for (pass
= 0; pass
< 2; pass
++) {
10586 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
10587 tcg_temp_free_i32(tcg_res
[pass
]);
10589 clear_vec_high(s
, is_q
, rd
);
10592 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
10594 /* PMULL of 64 x 64 -> 128 is an odd special case because it
10595 * is the only three-reg-diff instruction which produces a
10596 * 128-bit wide result from a single operation. However since
10597 * it's possible to calculate the two halves more or less
10598 * separately we just use two helper calls.
10600 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10601 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10602 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10604 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
10605 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
10606 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
10607 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
10608 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
10609 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
10611 tcg_temp_free_i64(tcg_op1
);
10612 tcg_temp_free_i64(tcg_op2
);
10613 tcg_temp_free_i64(tcg_res
);
10616 /* AdvSIMD three different
10617 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
10618 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10619 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
10620 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10622 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
10624 /* Instructions in this group fall into three basic classes
10625 * (in each case with the operation working on each element in
10626 * the input vectors):
10627 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
10629 * (2) wide 64 x 128 -> 128
10630 * (3) narrowing 128 x 128 -> 64
10631 * Here we do initial decode, catch unallocated cases and
10632 * dispatch to separate functions for each class.
10634 int is_q
= extract32(insn
, 30, 1);
10635 int is_u
= extract32(insn
, 29, 1);
10636 int size
= extract32(insn
, 22, 2);
10637 int opcode
= extract32(insn
, 12, 4);
10638 int rm
= extract32(insn
, 16, 5);
10639 int rn
= extract32(insn
, 5, 5);
10640 int rd
= extract32(insn
, 0, 5);
10643 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
10644 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
10645 /* 64 x 128 -> 128 */
10647 unallocated_encoding(s
);
10650 if (!fp_access_check(s
)) {
10653 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10655 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
10656 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
10657 /* 128 x 128 -> 64 */
10659 unallocated_encoding(s
);
10662 if (!fp_access_check(s
)) {
10665 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10667 case 14: /* PMULL, PMULL2 */
10668 if (is_u
|| size
== 1 || size
== 2) {
10669 unallocated_encoding(s
);
10673 if (!dc_isar_feature(aa64_pmull
, s
)) {
10674 unallocated_encoding(s
);
10677 if (!fp_access_check(s
)) {
10680 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
10684 case 9: /* SQDMLAL, SQDMLAL2 */
10685 case 11: /* SQDMLSL, SQDMLSL2 */
10686 case 13: /* SQDMULL, SQDMULL2 */
10687 if (is_u
|| size
== 0) {
10688 unallocated_encoding(s
);
10692 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10693 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10694 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10695 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10696 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10697 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10698 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
10699 /* 64 x 64 -> 128 */
10701 unallocated_encoding(s
);
10705 if (!fp_access_check(s
)) {
10709 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10712 /* opcode 15 not allocated */
10713 unallocated_encoding(s
);
10718 /* Logic op (opcode == 3) subgroup of C3.6.16. */
10719 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
10721 int rd
= extract32(insn
, 0, 5);
10722 int rn
= extract32(insn
, 5, 5);
10723 int rm
= extract32(insn
, 16, 5);
10724 int size
= extract32(insn
, 22, 2);
10725 bool is_u
= extract32(insn
, 29, 1);
10726 bool is_q
= extract32(insn
, 30, 1);
10728 if (!fp_access_check(s
)) {
10732 switch (size
+ 4 * is_u
) {
10734 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_and
, 0);
10737 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_andc
, 0);
10740 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_or
, 0);
10743 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_orc
, 0);
10746 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_xor
, 0);
10749 case 5: /* BSL bitwise select */
10750 gen_gvec_fn4(s
, is_q
, rd
, rd
, rn
, rm
, tcg_gen_gvec_bitsel
, 0);
10752 case 6: /* BIT, bitwise insert if true */
10753 gen_gvec_fn4(s
, is_q
, rd
, rm
, rn
, rd
, tcg_gen_gvec_bitsel
, 0);
10755 case 7: /* BIF, bitwise insert if false */
10756 gen_gvec_fn4(s
, is_q
, rd
, rm
, rd
, rn
, tcg_gen_gvec_bitsel
, 0);
10760 g_assert_not_reached();
10764 /* Pairwise op subgroup of C3.6.16.
10766 * This is called directly or via the handle_3same_float for float pairwise
10767 * operations where the opcode and size are calculated differently.
10769 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
10770 int size
, int rn
, int rm
, int rd
)
10775 /* Floating point operations need fpst */
10776 if (opcode
>= 0x58) {
10777 fpst
= get_fpstatus_ptr(false);
10782 if (!fp_access_check(s
)) {
10786 /* These operations work on the concatenated rm:rn, with each pair of
10787 * adjacent elements being operated on to produce an element in the result.
10790 TCGv_i64 tcg_res
[2];
10792 for (pass
= 0; pass
< 2; pass
++) {
10793 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10794 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10795 int passreg
= (pass
== 0) ? rn
: rm
;
10797 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
10798 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
10799 tcg_res
[pass
] = tcg_temp_new_i64();
10802 case 0x17: /* ADDP */
10803 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10805 case 0x58: /* FMAXNMP */
10806 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10808 case 0x5a: /* FADDP */
10809 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10811 case 0x5e: /* FMAXP */
10812 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10814 case 0x78: /* FMINNMP */
10815 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10817 case 0x7e: /* FMINP */
10818 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10821 g_assert_not_reached();
10824 tcg_temp_free_i64(tcg_op1
);
10825 tcg_temp_free_i64(tcg_op2
);
10828 for (pass
= 0; pass
< 2; pass
++) {
10829 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10830 tcg_temp_free_i64(tcg_res
[pass
]);
10833 int maxpass
= is_q
? 4 : 2;
10834 TCGv_i32 tcg_res
[4];
10836 for (pass
= 0; pass
< maxpass
; pass
++) {
10837 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10838 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10839 NeonGenTwoOpFn
*genfn
= NULL
;
10840 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
10841 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
10843 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
10844 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
10845 tcg_res
[pass
] = tcg_temp_new_i32();
10848 case 0x17: /* ADDP */
10850 static NeonGenTwoOpFn
* const fns
[3] = {
10851 gen_helper_neon_padd_u8
,
10852 gen_helper_neon_padd_u16
,
10858 case 0x14: /* SMAXP, UMAXP */
10860 static NeonGenTwoOpFn
* const fns
[3][2] = {
10861 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
10862 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
10863 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
10865 genfn
= fns
[size
][u
];
10868 case 0x15: /* SMINP, UMINP */
10870 static NeonGenTwoOpFn
* const fns
[3][2] = {
10871 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
10872 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
10873 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
10875 genfn
= fns
[size
][u
];
10878 /* The FP operations are all on single floats (32 bit) */
10879 case 0x58: /* FMAXNMP */
10880 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10882 case 0x5a: /* FADDP */
10883 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10885 case 0x5e: /* FMAXP */
10886 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10888 case 0x78: /* FMINNMP */
10889 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10891 case 0x7e: /* FMINP */
10892 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10895 g_assert_not_reached();
10898 /* FP ops called directly, otherwise call now */
10900 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10903 tcg_temp_free_i32(tcg_op1
);
10904 tcg_temp_free_i32(tcg_op2
);
10907 for (pass
= 0; pass
< maxpass
; pass
++) {
10908 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
10909 tcg_temp_free_i32(tcg_res
[pass
]);
10911 clear_vec_high(s
, is_q
, rd
);
10915 tcg_temp_free_ptr(fpst
);
10919 /* Floating point op subgroup of C3.6.16. */
10920 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
10922 /* For floating point ops, the U, size[1] and opcode bits
10923 * together indicate the operation. size[0] indicates single
10926 int fpopcode
= extract32(insn
, 11, 5)
10927 | (extract32(insn
, 23, 1) << 5)
10928 | (extract32(insn
, 29, 1) << 6);
10929 int is_q
= extract32(insn
, 30, 1);
10930 int size
= extract32(insn
, 22, 1);
10931 int rm
= extract32(insn
, 16, 5);
10932 int rn
= extract32(insn
, 5, 5);
10933 int rd
= extract32(insn
, 0, 5);
10935 int datasize
= is_q
? 128 : 64;
10936 int esize
= 32 << size
;
10937 int elements
= datasize
/ esize
;
10939 if (size
== 1 && !is_q
) {
10940 unallocated_encoding(s
);
10944 switch (fpopcode
) {
10945 case 0x58: /* FMAXNMP */
10946 case 0x5a: /* FADDP */
10947 case 0x5e: /* FMAXP */
10948 case 0x78: /* FMINNMP */
10949 case 0x7e: /* FMINP */
10950 if (size
&& !is_q
) {
10951 unallocated_encoding(s
);
10954 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
10957 case 0x1b: /* FMULX */
10958 case 0x1f: /* FRECPS */
10959 case 0x3f: /* FRSQRTS */
10960 case 0x5d: /* FACGE */
10961 case 0x7d: /* FACGT */
10962 case 0x19: /* FMLA */
10963 case 0x39: /* FMLS */
10964 case 0x18: /* FMAXNM */
10965 case 0x1a: /* FADD */
10966 case 0x1c: /* FCMEQ */
10967 case 0x1e: /* FMAX */
10968 case 0x38: /* FMINNM */
10969 case 0x3a: /* FSUB */
10970 case 0x3e: /* FMIN */
10971 case 0x5b: /* FMUL */
10972 case 0x5c: /* FCMGE */
10973 case 0x5f: /* FDIV */
10974 case 0x7a: /* FABD */
10975 case 0x7c: /* FCMGT */
10976 if (!fp_access_check(s
)) {
10979 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
10982 case 0x1d: /* FMLAL */
10983 case 0x3d: /* FMLSL */
10984 case 0x59: /* FMLAL2 */
10985 case 0x79: /* FMLSL2 */
10986 if (size
& 1 || !dc_isar_feature(aa64_fhm
, s
)) {
10987 unallocated_encoding(s
);
10990 if (fp_access_check(s
)) {
10991 int is_s
= extract32(insn
, 23, 1);
10992 int is_2
= extract32(insn
, 29, 1);
10993 int data
= (is_2
<< 1) | is_s
;
10994 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
10995 vec_full_reg_offset(s
, rn
),
10996 vec_full_reg_offset(s
, rm
), cpu_env
,
10997 is_q
? 16 : 8, vec_full_reg_size(s
),
10998 data
, gen_helper_gvec_fmlal_a64
);
11003 unallocated_encoding(s
);
11008 /* Integer op subgroup of C3.6.16. */
11009 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
11011 int is_q
= extract32(insn
, 30, 1);
11012 int u
= extract32(insn
, 29, 1);
11013 int size
= extract32(insn
, 22, 2);
11014 int opcode
= extract32(insn
, 11, 5);
11015 int rm
= extract32(insn
, 16, 5);
11016 int rn
= extract32(insn
, 5, 5);
11017 int rd
= extract32(insn
, 0, 5);
11022 case 0x13: /* MUL, PMUL */
11023 if (u
&& size
!= 0) {
11024 unallocated_encoding(s
);
11028 case 0x0: /* SHADD, UHADD */
11029 case 0x2: /* SRHADD, URHADD */
11030 case 0x4: /* SHSUB, UHSUB */
11031 case 0xc: /* SMAX, UMAX */
11032 case 0xd: /* SMIN, UMIN */
11033 case 0xe: /* SABD, UABD */
11034 case 0xf: /* SABA, UABA */
11035 case 0x12: /* MLA, MLS */
11037 unallocated_encoding(s
);
11041 case 0x16: /* SQDMULH, SQRDMULH */
11042 if (size
== 0 || size
== 3) {
11043 unallocated_encoding(s
);
11048 if (size
== 3 && !is_q
) {
11049 unallocated_encoding(s
);
11055 if (!fp_access_check(s
)) {
11060 case 0x01: /* SQADD, UQADD */
11061 tcg_gen_gvec_4(vec_full_reg_offset(s
, rd
),
11062 offsetof(CPUARMState
, vfp
.qc
),
11063 vec_full_reg_offset(s
, rn
),
11064 vec_full_reg_offset(s
, rm
),
11065 is_q
? 16 : 8, vec_full_reg_size(s
),
11066 (u
? uqadd_op
: sqadd_op
) + size
);
11068 case 0x05: /* SQSUB, UQSUB */
11069 tcg_gen_gvec_4(vec_full_reg_offset(s
, rd
),
11070 offsetof(CPUARMState
, vfp
.qc
),
11071 vec_full_reg_offset(s
, rn
),
11072 vec_full_reg_offset(s
, rm
),
11073 is_q
? 16 : 8, vec_full_reg_size(s
),
11074 (u
? uqsub_op
: sqsub_op
) + size
);
11076 case 0x0c: /* SMAX, UMAX */
11078 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umax
, size
);
11080 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smax
, size
);
11083 case 0x0d: /* SMIN, UMIN */
11085 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umin
, size
);
11087 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smin
, size
);
11090 case 0x10: /* ADD, SUB */
11092 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_sub
, size
);
11094 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_add
, size
);
11097 case 0x13: /* MUL, PMUL */
11098 if (!u
) { /* MUL */
11099 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_mul
, size
);
11103 case 0x12: /* MLA, MLS */
11105 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mls_op
[size
]);
11107 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mla_op
[size
]);
11111 if (!u
) { /* CMTST */
11112 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &cmtst_op
[size
]);
11116 cond
= TCG_COND_EQ
;
11118 case 0x06: /* CMGT, CMHI */
11119 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
11121 case 0x07: /* CMGE, CMHS */
11122 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
11124 tcg_gen_gvec_cmp(cond
, size
, vec_full_reg_offset(s
, rd
),
11125 vec_full_reg_offset(s
, rn
),
11126 vec_full_reg_offset(s
, rm
),
11127 is_q
? 16 : 8, vec_full_reg_size(s
));
11133 for (pass
= 0; pass
< 2; pass
++) {
11134 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11135 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11136 TCGv_i64 tcg_res
= tcg_temp_new_i64();
11138 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11139 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
11141 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
11143 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
11145 tcg_temp_free_i64(tcg_res
);
11146 tcg_temp_free_i64(tcg_op1
);
11147 tcg_temp_free_i64(tcg_op2
);
11150 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
11151 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11152 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11153 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11154 NeonGenTwoOpFn
*genfn
= NULL
;
11155 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
11157 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
11158 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
11161 case 0x0: /* SHADD, UHADD */
11163 static NeonGenTwoOpFn
* const fns
[3][2] = {
11164 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
11165 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
11166 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
11168 genfn
= fns
[size
][u
];
11171 case 0x2: /* SRHADD, URHADD */
11173 static NeonGenTwoOpFn
* const fns
[3][2] = {
11174 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
11175 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
11176 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
11178 genfn
= fns
[size
][u
];
11181 case 0x4: /* SHSUB, UHSUB */
11183 static NeonGenTwoOpFn
* const fns
[3][2] = {
11184 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
11185 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
11186 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
11188 genfn
= fns
[size
][u
];
11191 case 0x8: /* SSHL, USHL */
11193 static NeonGenTwoOpFn
* const fns
[3][2] = {
11194 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
11195 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
11196 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
11198 genfn
= fns
[size
][u
];
11201 case 0x9: /* SQSHL, UQSHL */
11203 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11204 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
11205 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
11206 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
11208 genenvfn
= fns
[size
][u
];
11211 case 0xa: /* SRSHL, URSHL */
11213 static NeonGenTwoOpFn
* const fns
[3][2] = {
11214 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
11215 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
11216 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
11218 genfn
= fns
[size
][u
];
11221 case 0xb: /* SQRSHL, UQRSHL */
11223 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11224 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
11225 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
11226 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
11228 genenvfn
= fns
[size
][u
];
11231 case 0xe: /* SABD, UABD */
11232 case 0xf: /* SABA, UABA */
11234 static NeonGenTwoOpFn
* const fns
[3][2] = {
11235 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
11236 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
11237 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
11239 genfn
= fns
[size
][u
];
11242 case 0x13: /* MUL, PMUL */
11243 assert(u
); /* PMUL */
11245 genfn
= gen_helper_neon_mul_p8
;
11247 case 0x16: /* SQDMULH, SQRDMULH */
11249 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
11250 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
11251 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
11253 assert(size
== 1 || size
== 2);
11254 genenvfn
= fns
[size
- 1][u
];
11258 g_assert_not_reached();
11262 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
11264 genfn(tcg_res
, tcg_op1
, tcg_op2
);
11267 if (opcode
== 0xf) {
11268 /* SABA, UABA: accumulating ops */
11269 static NeonGenTwoOpFn
* const fns
[3] = {
11270 gen_helper_neon_add_u8
,
11271 gen_helper_neon_add_u16
,
11275 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
11276 fns
[size
](tcg_res
, tcg_op1
, tcg_res
);
11279 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
11281 tcg_temp_free_i32(tcg_res
);
11282 tcg_temp_free_i32(tcg_op1
);
11283 tcg_temp_free_i32(tcg_op2
);
11286 clear_vec_high(s
, is_q
, rd
);
11289 /* AdvSIMD three same
11290 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11291 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11292 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11293 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11295 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
11297 int opcode
= extract32(insn
, 11, 5);
11300 case 0x3: /* logic ops */
11301 disas_simd_3same_logic(s
, insn
);
11303 case 0x17: /* ADDP */
11304 case 0x14: /* SMAXP, UMAXP */
11305 case 0x15: /* SMINP, UMINP */
11307 /* Pairwise operations */
11308 int is_q
= extract32(insn
, 30, 1);
11309 int u
= extract32(insn
, 29, 1);
11310 int size
= extract32(insn
, 22, 2);
11311 int rm
= extract32(insn
, 16, 5);
11312 int rn
= extract32(insn
, 5, 5);
11313 int rd
= extract32(insn
, 0, 5);
11314 if (opcode
== 0x17) {
11315 if (u
|| (size
== 3 && !is_q
)) {
11316 unallocated_encoding(s
);
11321 unallocated_encoding(s
);
11325 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
11328 case 0x18 ... 0x31:
11329 /* floating point ops, sz[1] and U are part of opcode */
11330 disas_simd_3same_float(s
, insn
);
11333 disas_simd_3same_int(s
, insn
);
11339 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11341 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11342 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11343 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11344 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11346 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11347 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11350 static void disas_simd_three_reg_same_fp16(DisasContext
*s
, uint32_t insn
)
11352 int opcode
, fpopcode
;
11353 int is_q
, u
, a
, rm
, rn
, rd
;
11354 int datasize
, elements
;
11357 bool pairwise
= false;
11359 if (!dc_isar_feature(aa64_fp16
, s
)) {
11360 unallocated_encoding(s
);
11364 if (!fp_access_check(s
)) {
11368 /* For these floating point ops, the U, a and opcode bits
11369 * together indicate the operation.
11371 opcode
= extract32(insn
, 11, 3);
11372 u
= extract32(insn
, 29, 1);
11373 a
= extract32(insn
, 23, 1);
11374 is_q
= extract32(insn
, 30, 1);
11375 rm
= extract32(insn
, 16, 5);
11376 rn
= extract32(insn
, 5, 5);
11377 rd
= extract32(insn
, 0, 5);
11379 fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
11380 datasize
= is_q
? 128 : 64;
11381 elements
= datasize
/ 16;
11383 switch (fpopcode
) {
11384 case 0x10: /* FMAXNMP */
11385 case 0x12: /* FADDP */
11386 case 0x16: /* FMAXP */
11387 case 0x18: /* FMINNMP */
11388 case 0x1e: /* FMINP */
11393 fpst
= get_fpstatus_ptr(true);
11396 int maxpass
= is_q
? 8 : 4;
11397 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11398 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11399 TCGv_i32 tcg_res
[8];
11401 for (pass
= 0; pass
< maxpass
; pass
++) {
11402 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
11403 int passelt
= (pass
<< 1) & (maxpass
- 1);
11405 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_16
);
11406 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_16
);
11407 tcg_res
[pass
] = tcg_temp_new_i32();
11409 switch (fpopcode
) {
11410 case 0x10: /* FMAXNMP */
11411 gen_helper_advsimd_maxnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11414 case 0x12: /* FADDP */
11415 gen_helper_advsimd_addh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11417 case 0x16: /* FMAXP */
11418 gen_helper_advsimd_maxh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11420 case 0x18: /* FMINNMP */
11421 gen_helper_advsimd_minnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11424 case 0x1e: /* FMINP */
11425 gen_helper_advsimd_minh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11428 g_assert_not_reached();
11432 for (pass
= 0; pass
< maxpass
; pass
++) {
11433 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_16
);
11434 tcg_temp_free_i32(tcg_res
[pass
]);
11437 tcg_temp_free_i32(tcg_op1
);
11438 tcg_temp_free_i32(tcg_op2
);
11441 for (pass
= 0; pass
< elements
; pass
++) {
11442 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11443 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11444 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11446 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_16
);
11447 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_16
);
11449 switch (fpopcode
) {
11450 case 0x0: /* FMAXNM */
11451 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11453 case 0x1: /* FMLA */
11454 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11455 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11458 case 0x2: /* FADD */
11459 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11461 case 0x3: /* FMULX */
11462 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11464 case 0x4: /* FCMEQ */
11465 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11467 case 0x6: /* FMAX */
11468 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11470 case 0x7: /* FRECPS */
11471 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11473 case 0x8: /* FMINNM */
11474 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11476 case 0x9: /* FMLS */
11477 /* As usual for ARM, separate negation for fused multiply-add */
11478 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
11479 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11480 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11483 case 0xa: /* FSUB */
11484 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11486 case 0xe: /* FMIN */
11487 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11489 case 0xf: /* FRSQRTS */
11490 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11492 case 0x13: /* FMUL */
11493 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11495 case 0x14: /* FCMGE */
11496 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11498 case 0x15: /* FACGE */
11499 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11501 case 0x17: /* FDIV */
11502 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11504 case 0x1a: /* FABD */
11505 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11506 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
11508 case 0x1c: /* FCMGT */
11509 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11511 case 0x1d: /* FACGT */
11512 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11515 fprintf(stderr
, "%s: insn %#04x, fpop %#2x @ %#" PRIx64
"\n",
11516 __func__
, insn
, fpopcode
, s
->pc_curr
);
11517 g_assert_not_reached();
11520 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11521 tcg_temp_free_i32(tcg_res
);
11522 tcg_temp_free_i32(tcg_op1
);
11523 tcg_temp_free_i32(tcg_op2
);
11527 tcg_temp_free_ptr(fpst
);
11529 clear_vec_high(s
, is_q
, rd
);
11532 /* AdvSIMD three same extra
11533 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
11534 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11535 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
11536 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11538 static void disas_simd_three_reg_same_extra(DisasContext
*s
, uint32_t insn
)
11540 int rd
= extract32(insn
, 0, 5);
11541 int rn
= extract32(insn
, 5, 5);
11542 int opcode
= extract32(insn
, 11, 4);
11543 int rm
= extract32(insn
, 16, 5);
11544 int size
= extract32(insn
, 22, 2);
11545 bool u
= extract32(insn
, 29, 1);
11546 bool is_q
= extract32(insn
, 30, 1);
11550 switch (u
* 16 + opcode
) {
11551 case 0x10: /* SQRDMLAH (vector) */
11552 case 0x11: /* SQRDMLSH (vector) */
11553 if (size
!= 1 && size
!= 2) {
11554 unallocated_encoding(s
);
11557 feature
= dc_isar_feature(aa64_rdm
, s
);
11559 case 0x02: /* SDOT (vector) */
11560 case 0x12: /* UDOT (vector) */
11561 if (size
!= MO_32
) {
11562 unallocated_encoding(s
);
11565 feature
= dc_isar_feature(aa64_dp
, s
);
11567 case 0x18: /* FCMLA, #0 */
11568 case 0x19: /* FCMLA, #90 */
11569 case 0x1a: /* FCMLA, #180 */
11570 case 0x1b: /* FCMLA, #270 */
11571 case 0x1c: /* FCADD, #90 */
11572 case 0x1e: /* FCADD, #270 */
11574 || (size
== 1 && !dc_isar_feature(aa64_fp16
, s
))
11575 || (size
== 3 && !is_q
)) {
11576 unallocated_encoding(s
);
11579 feature
= dc_isar_feature(aa64_fcma
, s
);
11582 unallocated_encoding(s
);
11586 unallocated_encoding(s
);
11589 if (!fp_access_check(s
)) {
11594 case 0x0: /* SQRDMLAH (vector) */
11597 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s16
);
11600 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s32
);
11603 g_assert_not_reached();
11607 case 0x1: /* SQRDMLSH (vector) */
11610 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s16
);
11613 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s32
);
11616 g_assert_not_reached();
11620 case 0x2: /* SDOT / UDOT */
11621 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, 0,
11622 u
? gen_helper_gvec_udot_b
: gen_helper_gvec_sdot_b
);
11625 case 0x8: /* FCMLA, #0 */
11626 case 0x9: /* FCMLA, #90 */
11627 case 0xa: /* FCMLA, #180 */
11628 case 0xb: /* FCMLA, #270 */
11629 rot
= extract32(opcode
, 0, 2);
11632 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, true, rot
,
11633 gen_helper_gvec_fcmlah
);
11636 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11637 gen_helper_gvec_fcmlas
);
11640 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11641 gen_helper_gvec_fcmlad
);
11644 g_assert_not_reached();
11648 case 0xc: /* FCADD, #90 */
11649 case 0xe: /* FCADD, #270 */
11650 rot
= extract32(opcode
, 1, 1);
11653 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11654 gen_helper_gvec_fcaddh
);
11657 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11658 gen_helper_gvec_fcadds
);
11661 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11662 gen_helper_gvec_fcaddd
);
11665 g_assert_not_reached();
11670 g_assert_not_reached();
11674 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
11675 int size
, int rn
, int rd
)
11677 /* Handle 2-reg-misc ops which are widening (so each size element
11678 * in the source becomes a 2*size element in the destination.
11679 * The only instruction like this is FCVTL.
11684 /* 32 -> 64 bit fp conversion */
11685 TCGv_i64 tcg_res
[2];
11686 int srcelt
= is_q
? 2 : 0;
11688 for (pass
= 0; pass
< 2; pass
++) {
11689 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11690 tcg_res
[pass
] = tcg_temp_new_i64();
11692 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
11693 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
11694 tcg_temp_free_i32(tcg_op
);
11696 for (pass
= 0; pass
< 2; pass
++) {
11697 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11698 tcg_temp_free_i64(tcg_res
[pass
]);
11701 /* 16 -> 32 bit fp conversion */
11702 int srcelt
= is_q
? 4 : 0;
11703 TCGv_i32 tcg_res
[4];
11704 TCGv_ptr fpst
= get_fpstatus_ptr(false);
11705 TCGv_i32 ahp
= get_ahp_flag();
11707 for (pass
= 0; pass
< 4; pass
++) {
11708 tcg_res
[pass
] = tcg_temp_new_i32();
11710 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
11711 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
11714 for (pass
= 0; pass
< 4; pass
++) {
11715 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
11716 tcg_temp_free_i32(tcg_res
[pass
]);
11719 tcg_temp_free_ptr(fpst
);
11720 tcg_temp_free_i32(ahp
);
11724 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
11725 bool is_q
, int size
, int rn
, int rd
)
11727 int op
= (opcode
<< 1) | u
;
11728 int opsz
= op
+ size
;
11729 int grp_size
= 3 - opsz
;
11730 int dsize
= is_q
? 128 : 64;
11734 unallocated_encoding(s
);
11738 if (!fp_access_check(s
)) {
11743 /* Special case bytes, use bswap op on each group of elements */
11744 int groups
= dsize
/ (8 << grp_size
);
11746 for (i
= 0; i
< groups
; i
++) {
11747 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
11749 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
11750 switch (grp_size
) {
11752 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
11755 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
11758 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
11761 g_assert_not_reached();
11763 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
11764 tcg_temp_free_i64(tcg_tmp
);
11766 clear_vec_high(s
, is_q
, rd
);
11768 int revmask
= (1 << grp_size
) - 1;
11769 int esize
= 8 << size
;
11770 int elements
= dsize
/ esize
;
11771 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
11772 TCGv_i64 tcg_rd
= tcg_const_i64(0);
11773 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
11775 for (i
= 0; i
< elements
; i
++) {
11776 int e_rev
= (i
& 0xf) ^ revmask
;
11777 int off
= e_rev
* esize
;
11778 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
11780 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
11781 tcg_rn
, off
- 64, esize
);
11783 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
11786 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
11787 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
11789 tcg_temp_free_i64(tcg_rd_hi
);
11790 tcg_temp_free_i64(tcg_rd
);
11791 tcg_temp_free_i64(tcg_rn
);
11795 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
11796 bool is_q
, int size
, int rn
, int rd
)
11798 /* Implement the pairwise operations from 2-misc:
11799 * SADDLP, UADDLP, SADALP, UADALP.
11800 * These all add pairs of elements in the input to produce a
11801 * double-width result element in the output (possibly accumulating).
11803 bool accum
= (opcode
== 0x6);
11804 int maxpass
= is_q
? 2 : 1;
11806 TCGv_i64 tcg_res
[2];
11809 /* 32 + 32 -> 64 op */
11810 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
11812 for (pass
= 0; pass
< maxpass
; pass
++) {
11813 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11814 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11816 tcg_res
[pass
] = tcg_temp_new_i64();
11818 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
11819 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
11820 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11822 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
11823 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
11826 tcg_temp_free_i64(tcg_op1
);
11827 tcg_temp_free_i64(tcg_op2
);
11830 for (pass
= 0; pass
< maxpass
; pass
++) {
11831 TCGv_i64 tcg_op
= tcg_temp_new_i64();
11832 NeonGenOneOpFn
*genfn
;
11833 static NeonGenOneOpFn
* const fns
[2][2] = {
11834 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
11835 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
11838 genfn
= fns
[size
][u
];
11840 tcg_res
[pass
] = tcg_temp_new_i64();
11842 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
11843 genfn(tcg_res
[pass
], tcg_op
);
11846 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
11848 gen_helper_neon_addl_u16(tcg_res
[pass
],
11849 tcg_res
[pass
], tcg_op
);
11851 gen_helper_neon_addl_u32(tcg_res
[pass
],
11852 tcg_res
[pass
], tcg_op
);
11855 tcg_temp_free_i64(tcg_op
);
11859 tcg_res
[1] = tcg_const_i64(0);
11861 for (pass
= 0; pass
< 2; pass
++) {
11862 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11863 tcg_temp_free_i64(tcg_res
[pass
]);
11867 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
11869 /* Implement SHLL and SHLL2 */
11871 int part
= is_q
? 2 : 0;
11872 TCGv_i64 tcg_res
[2];
11874 for (pass
= 0; pass
< 2; pass
++) {
11875 static NeonGenWidenFn
* const widenfns
[3] = {
11876 gen_helper_neon_widen_u8
,
11877 gen_helper_neon_widen_u16
,
11878 tcg_gen_extu_i32_i64
,
11880 NeonGenWidenFn
*widenfn
= widenfns
[size
];
11881 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11883 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
11884 tcg_res
[pass
] = tcg_temp_new_i64();
11885 widenfn(tcg_res
[pass
], tcg_op
);
11886 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
11888 tcg_temp_free_i32(tcg_op
);
11891 for (pass
= 0; pass
< 2; pass
++) {
11892 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11893 tcg_temp_free_i64(tcg_res
[pass
]);
11897 /* AdvSIMD two reg misc
11898 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
11899 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11900 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
11901 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11903 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
11905 int size
= extract32(insn
, 22, 2);
11906 int opcode
= extract32(insn
, 12, 5);
11907 bool u
= extract32(insn
, 29, 1);
11908 bool is_q
= extract32(insn
, 30, 1);
11909 int rn
= extract32(insn
, 5, 5);
11910 int rd
= extract32(insn
, 0, 5);
11911 bool need_fpstatus
= false;
11912 bool need_rmode
= false;
11914 TCGv_i32 tcg_rmode
;
11915 TCGv_ptr tcg_fpstatus
;
11918 case 0x0: /* REV64, REV32 */
11919 case 0x1: /* REV16 */
11920 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
11922 case 0x5: /* CNT, NOT, RBIT */
11923 if (u
&& size
== 0) {
11926 } else if (u
&& size
== 1) {
11929 } else if (!u
&& size
== 0) {
11933 unallocated_encoding(s
);
11935 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
11936 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
11938 unallocated_encoding(s
);
11941 if (!fp_access_check(s
)) {
11945 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
11947 case 0x4: /* CLS, CLZ */
11949 unallocated_encoding(s
);
11953 case 0x2: /* SADDLP, UADDLP */
11954 case 0x6: /* SADALP, UADALP */
11956 unallocated_encoding(s
);
11959 if (!fp_access_check(s
)) {
11962 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
11964 case 0x13: /* SHLL, SHLL2 */
11965 if (u
== 0 || size
== 3) {
11966 unallocated_encoding(s
);
11969 if (!fp_access_check(s
)) {
11972 handle_shll(s
, is_q
, size
, rn
, rd
);
11974 case 0xa: /* CMLT */
11976 unallocated_encoding(s
);
11980 case 0x8: /* CMGT, CMGE */
11981 case 0x9: /* CMEQ, CMLE */
11982 case 0xb: /* ABS, NEG */
11983 if (size
== 3 && !is_q
) {
11984 unallocated_encoding(s
);
11988 case 0x3: /* SUQADD, USQADD */
11989 if (size
== 3 && !is_q
) {
11990 unallocated_encoding(s
);
11993 if (!fp_access_check(s
)) {
11996 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
11998 case 0x7: /* SQABS, SQNEG */
11999 if (size
== 3 && !is_q
) {
12000 unallocated_encoding(s
);
12005 case 0x16 ... 0x1f:
12007 /* Floating point: U, size[1] and opcode indicate operation;
12008 * size[0] indicates single or double precision.
12010 int is_double
= extract32(size
, 0, 1);
12011 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
12012 size
= is_double
? 3 : 2;
12014 case 0x2f: /* FABS */
12015 case 0x6f: /* FNEG */
12016 if (size
== 3 && !is_q
) {
12017 unallocated_encoding(s
);
12021 case 0x1d: /* SCVTF */
12022 case 0x5d: /* UCVTF */
12024 bool is_signed
= (opcode
== 0x1d) ? true : false;
12025 int elements
= is_double
? 2 : is_q
? 4 : 2;
12026 if (is_double
&& !is_q
) {
12027 unallocated_encoding(s
);
12030 if (!fp_access_check(s
)) {
12033 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
12036 case 0x2c: /* FCMGT (zero) */
12037 case 0x2d: /* FCMEQ (zero) */
12038 case 0x2e: /* FCMLT (zero) */
12039 case 0x6c: /* FCMGE (zero) */
12040 case 0x6d: /* FCMLE (zero) */
12041 if (size
== 3 && !is_q
) {
12042 unallocated_encoding(s
);
12045 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
12047 case 0x7f: /* FSQRT */
12048 if (size
== 3 && !is_q
) {
12049 unallocated_encoding(s
);
12053 case 0x1a: /* FCVTNS */
12054 case 0x1b: /* FCVTMS */
12055 case 0x3a: /* FCVTPS */
12056 case 0x3b: /* FCVTZS */
12057 case 0x5a: /* FCVTNU */
12058 case 0x5b: /* FCVTMU */
12059 case 0x7a: /* FCVTPU */
12060 case 0x7b: /* FCVTZU */
12061 need_fpstatus
= true;
12063 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12064 if (size
== 3 && !is_q
) {
12065 unallocated_encoding(s
);
12069 case 0x5c: /* FCVTAU */
12070 case 0x1c: /* FCVTAS */
12071 need_fpstatus
= true;
12073 rmode
= FPROUNDING_TIEAWAY
;
12074 if (size
== 3 && !is_q
) {
12075 unallocated_encoding(s
);
12079 case 0x3c: /* URECPE */
12081 unallocated_encoding(s
);
12085 case 0x3d: /* FRECPE */
12086 case 0x7d: /* FRSQRTE */
12087 if (size
== 3 && !is_q
) {
12088 unallocated_encoding(s
);
12091 if (!fp_access_check(s
)) {
12094 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
12096 case 0x56: /* FCVTXN, FCVTXN2 */
12098 unallocated_encoding(s
);
12102 case 0x16: /* FCVTN, FCVTN2 */
12103 /* handle_2misc_narrow does a 2*size -> size operation, but these
12104 * instructions encode the source size rather than dest size.
12106 if (!fp_access_check(s
)) {
12109 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
12111 case 0x17: /* FCVTL, FCVTL2 */
12112 if (!fp_access_check(s
)) {
12115 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
12117 case 0x18: /* FRINTN */
12118 case 0x19: /* FRINTM */
12119 case 0x38: /* FRINTP */
12120 case 0x39: /* FRINTZ */
12122 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12124 case 0x59: /* FRINTX */
12125 case 0x79: /* FRINTI */
12126 need_fpstatus
= true;
12127 if (size
== 3 && !is_q
) {
12128 unallocated_encoding(s
);
12132 case 0x58: /* FRINTA */
12134 rmode
= FPROUNDING_TIEAWAY
;
12135 need_fpstatus
= true;
12136 if (size
== 3 && !is_q
) {
12137 unallocated_encoding(s
);
12141 case 0x7c: /* URSQRTE */
12143 unallocated_encoding(s
);
12146 need_fpstatus
= true;
12148 case 0x1e: /* FRINT32Z */
12149 case 0x1f: /* FRINT64Z */
12151 rmode
= FPROUNDING_ZERO
;
12153 case 0x5e: /* FRINT32X */
12154 case 0x5f: /* FRINT64X */
12155 need_fpstatus
= true;
12156 if ((size
== 3 && !is_q
) || !dc_isar_feature(aa64_frint
, s
)) {
12157 unallocated_encoding(s
);
12162 unallocated_encoding(s
);
12168 unallocated_encoding(s
);
12172 if (!fp_access_check(s
)) {
12176 if (need_fpstatus
|| need_rmode
) {
12177 tcg_fpstatus
= get_fpstatus_ptr(false);
12179 tcg_fpstatus
= NULL
;
12182 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12183 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12190 if (u
&& size
== 0) { /* NOT */
12191 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_not
, 0);
12196 if (u
) { /* ABS, NEG */
12197 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_neg
, size
);
12199 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_abs
, size
);
12205 /* All 64-bit element operations can be shared with scalar 2misc */
12208 /* Coverity claims (size == 3 && !is_q) has been eliminated
12209 * from all paths leading to here.
12211 tcg_debug_assert(is_q
);
12212 for (pass
= 0; pass
< 2; pass
++) {
12213 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12214 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12216 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12218 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
12219 tcg_rmode
, tcg_fpstatus
);
12221 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12223 tcg_temp_free_i64(tcg_res
);
12224 tcg_temp_free_i64(tcg_op
);
12229 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
12230 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12231 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12234 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
12237 /* Special cases for 32 bit elements */
12239 case 0xa: /* CMLT */
12240 /* 32 bit integer comparison against zero, result is
12241 * test ? (2^32 - 1) : 0. We implement via setcond(test)
12244 cond
= TCG_COND_LT
;
12246 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
12247 tcg_gen_neg_i32(tcg_res
, tcg_res
);
12249 case 0x8: /* CMGT, CMGE */
12250 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
12252 case 0x9: /* CMEQ, CMLE */
12253 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
12255 case 0x4: /* CLS */
12257 tcg_gen_clzi_i32(tcg_res
, tcg_op
, 32);
12259 tcg_gen_clrsb_i32(tcg_res
, tcg_op
);
12262 case 0x7: /* SQABS, SQNEG */
12264 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
12266 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
12269 case 0x2f: /* FABS */
12270 gen_helper_vfp_abss(tcg_res
, tcg_op
);
12272 case 0x6f: /* FNEG */
12273 gen_helper_vfp_negs(tcg_res
, tcg_op
);
12275 case 0x7f: /* FSQRT */
12276 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
12278 case 0x1a: /* FCVTNS */
12279 case 0x1b: /* FCVTMS */
12280 case 0x1c: /* FCVTAS */
12281 case 0x3a: /* FCVTPS */
12282 case 0x3b: /* FCVTZS */
12284 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12285 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
12286 tcg_shift
, tcg_fpstatus
);
12287 tcg_temp_free_i32(tcg_shift
);
12290 case 0x5a: /* FCVTNU */
12291 case 0x5b: /* FCVTMU */
12292 case 0x5c: /* FCVTAU */
12293 case 0x7a: /* FCVTPU */
12294 case 0x7b: /* FCVTZU */
12296 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12297 gen_helper_vfp_touls(tcg_res
, tcg_op
,
12298 tcg_shift
, tcg_fpstatus
);
12299 tcg_temp_free_i32(tcg_shift
);
12302 case 0x18: /* FRINTN */
12303 case 0x19: /* FRINTM */
12304 case 0x38: /* FRINTP */
12305 case 0x39: /* FRINTZ */
12306 case 0x58: /* FRINTA */
12307 case 0x79: /* FRINTI */
12308 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
12310 case 0x59: /* FRINTX */
12311 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12313 case 0x7c: /* URSQRTE */
12314 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
12316 case 0x1e: /* FRINT32Z */
12317 case 0x5e: /* FRINT32X */
12318 gen_helper_frint32_s(tcg_res
, tcg_op
, tcg_fpstatus
);
12320 case 0x1f: /* FRINT64Z */
12321 case 0x5f: /* FRINT64X */
12322 gen_helper_frint64_s(tcg_res
, tcg_op
, tcg_fpstatus
);
12325 g_assert_not_reached();
12328 /* Use helpers for 8 and 16 bit elements */
12330 case 0x5: /* CNT, RBIT */
12331 /* For these two insns size is part of the opcode specifier
12332 * (handled earlier); they always operate on byte elements.
12335 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
12337 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
12340 case 0x7: /* SQABS, SQNEG */
12342 NeonGenOneOpEnvFn
*genfn
;
12343 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
12344 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
12345 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
12347 genfn
= fns
[size
][u
];
12348 genfn(tcg_res
, cpu_env
, tcg_op
);
12351 case 0x8: /* CMGT, CMGE */
12352 case 0x9: /* CMEQ, CMLE */
12353 case 0xa: /* CMLT */
12355 static NeonGenTwoOpFn
* const fns
[3][2] = {
12356 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
12357 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
12358 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
12360 NeonGenTwoOpFn
*genfn
;
12363 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12365 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
12366 comp
= (opcode
- 0x8) * 2 + u
;
12367 /* ...but LE, LT are implemented as reverse GE, GT */
12368 reverse
= (comp
> 2);
12372 genfn
= fns
[comp
][size
];
12374 genfn(tcg_res
, tcg_zero
, tcg_op
);
12376 genfn(tcg_res
, tcg_op
, tcg_zero
);
12378 tcg_temp_free_i32(tcg_zero
);
12381 case 0x4: /* CLS, CLZ */
12384 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
12386 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
12390 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
12392 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
12397 g_assert_not_reached();
12401 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
12403 tcg_temp_free_i32(tcg_res
);
12404 tcg_temp_free_i32(tcg_op
);
12407 clear_vec_high(s
, is_q
, rd
);
12410 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12411 tcg_temp_free_i32(tcg_rmode
);
12413 if (need_fpstatus
) {
12414 tcg_temp_free_ptr(tcg_fpstatus
);
12418 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12420 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12421 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12422 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12423 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12424 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12425 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12427 * This actually covers two groups where scalar access is governed by
12428 * bit 28. A bunch of the instructions (float to integral) only exist
12429 * in the vector form and are un-allocated for the scalar decode. Also
12430 * in the scalar decode Q is always 1.
12432 static void disas_simd_two_reg_misc_fp16(DisasContext
*s
, uint32_t insn
)
12434 int fpop
, opcode
, a
, u
;
12438 bool only_in_vector
= false;
12441 TCGv_i32 tcg_rmode
= NULL
;
12442 TCGv_ptr tcg_fpstatus
= NULL
;
12443 bool need_rmode
= false;
12444 bool need_fpst
= true;
12447 if (!dc_isar_feature(aa64_fp16
, s
)) {
12448 unallocated_encoding(s
);
12452 rd
= extract32(insn
, 0, 5);
12453 rn
= extract32(insn
, 5, 5);
12455 a
= extract32(insn
, 23, 1);
12456 u
= extract32(insn
, 29, 1);
12457 is_scalar
= extract32(insn
, 28, 1);
12458 is_q
= extract32(insn
, 30, 1);
12460 opcode
= extract32(insn
, 12, 5);
12461 fpop
= deposit32(opcode
, 5, 1, a
);
12462 fpop
= deposit32(fpop
, 6, 1, u
);
12464 rd
= extract32(insn
, 0, 5);
12465 rn
= extract32(insn
, 5, 5);
12468 case 0x1d: /* SCVTF */
12469 case 0x5d: /* UCVTF */
12476 elements
= (is_q
? 8 : 4);
12479 if (!fp_access_check(s
)) {
12482 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !u
, 0, MO_16
);
12486 case 0x2c: /* FCMGT (zero) */
12487 case 0x2d: /* FCMEQ (zero) */
12488 case 0x2e: /* FCMLT (zero) */
12489 case 0x6c: /* FCMGE (zero) */
12490 case 0x6d: /* FCMLE (zero) */
12491 handle_2misc_fcmp_zero(s
, fpop
, is_scalar
, 0, is_q
, MO_16
, rn
, rd
);
12493 case 0x3d: /* FRECPE */
12494 case 0x3f: /* FRECPX */
12496 case 0x18: /* FRINTN */
12498 only_in_vector
= true;
12499 rmode
= FPROUNDING_TIEEVEN
;
12501 case 0x19: /* FRINTM */
12503 only_in_vector
= true;
12504 rmode
= FPROUNDING_NEGINF
;
12506 case 0x38: /* FRINTP */
12508 only_in_vector
= true;
12509 rmode
= FPROUNDING_POSINF
;
12511 case 0x39: /* FRINTZ */
12513 only_in_vector
= true;
12514 rmode
= FPROUNDING_ZERO
;
12516 case 0x58: /* FRINTA */
12518 only_in_vector
= true;
12519 rmode
= FPROUNDING_TIEAWAY
;
12521 case 0x59: /* FRINTX */
12522 case 0x79: /* FRINTI */
12523 only_in_vector
= true;
12524 /* current rounding mode */
12526 case 0x1a: /* FCVTNS */
12528 rmode
= FPROUNDING_TIEEVEN
;
12530 case 0x1b: /* FCVTMS */
12532 rmode
= FPROUNDING_NEGINF
;
12534 case 0x1c: /* FCVTAS */
12536 rmode
= FPROUNDING_TIEAWAY
;
12538 case 0x3a: /* FCVTPS */
12540 rmode
= FPROUNDING_POSINF
;
12542 case 0x3b: /* FCVTZS */
12544 rmode
= FPROUNDING_ZERO
;
12546 case 0x5a: /* FCVTNU */
12548 rmode
= FPROUNDING_TIEEVEN
;
12550 case 0x5b: /* FCVTMU */
12552 rmode
= FPROUNDING_NEGINF
;
12554 case 0x5c: /* FCVTAU */
12556 rmode
= FPROUNDING_TIEAWAY
;
12558 case 0x7a: /* FCVTPU */
12560 rmode
= FPROUNDING_POSINF
;
12562 case 0x7b: /* FCVTZU */
12564 rmode
= FPROUNDING_ZERO
;
12566 case 0x2f: /* FABS */
12567 case 0x6f: /* FNEG */
12570 case 0x7d: /* FRSQRTE */
12571 case 0x7f: /* FSQRT (vector) */
12574 fprintf(stderr
, "%s: insn %#04x fpop %#2x\n", __func__
, insn
, fpop
);
12575 g_assert_not_reached();
12579 /* Check additional constraints for the scalar encoding */
12582 unallocated_encoding(s
);
12585 /* FRINTxx is only in the vector form */
12586 if (only_in_vector
) {
12587 unallocated_encoding(s
);
12592 if (!fp_access_check(s
)) {
12596 if (need_rmode
|| need_fpst
) {
12597 tcg_fpstatus
= get_fpstatus_ptr(true);
12601 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12602 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12606 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
12607 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12610 case 0x1a: /* FCVTNS */
12611 case 0x1b: /* FCVTMS */
12612 case 0x1c: /* FCVTAS */
12613 case 0x3a: /* FCVTPS */
12614 case 0x3b: /* FCVTZS */
12615 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12617 case 0x3d: /* FRECPE */
12618 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12620 case 0x3f: /* FRECPX */
12621 gen_helper_frecpx_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12623 case 0x5a: /* FCVTNU */
12624 case 0x5b: /* FCVTMU */
12625 case 0x5c: /* FCVTAU */
12626 case 0x7a: /* FCVTPU */
12627 case 0x7b: /* FCVTZU */
12628 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12630 case 0x6f: /* FNEG */
12631 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12633 case 0x7d: /* FRSQRTE */
12634 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12637 g_assert_not_reached();
12640 /* limit any sign extension going on */
12641 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0xffff);
12642 write_fp_sreg(s
, rd
, tcg_res
);
12644 tcg_temp_free_i32(tcg_res
);
12645 tcg_temp_free_i32(tcg_op
);
12647 for (pass
= 0; pass
< (is_q
? 8 : 4); pass
++) {
12648 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12649 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12651 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_16
);
12654 case 0x1a: /* FCVTNS */
12655 case 0x1b: /* FCVTMS */
12656 case 0x1c: /* FCVTAS */
12657 case 0x3a: /* FCVTPS */
12658 case 0x3b: /* FCVTZS */
12659 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12661 case 0x3d: /* FRECPE */
12662 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12664 case 0x5a: /* FCVTNU */
12665 case 0x5b: /* FCVTMU */
12666 case 0x5c: /* FCVTAU */
12667 case 0x7a: /* FCVTPU */
12668 case 0x7b: /* FCVTZU */
12669 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12671 case 0x18: /* FRINTN */
12672 case 0x19: /* FRINTM */
12673 case 0x38: /* FRINTP */
12674 case 0x39: /* FRINTZ */
12675 case 0x58: /* FRINTA */
12676 case 0x79: /* FRINTI */
12677 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12679 case 0x59: /* FRINTX */
12680 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12682 case 0x2f: /* FABS */
12683 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
12685 case 0x6f: /* FNEG */
12686 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12688 case 0x7d: /* FRSQRTE */
12689 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12691 case 0x7f: /* FSQRT */
12692 gen_helper_sqrt_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12695 g_assert_not_reached();
12698 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12700 tcg_temp_free_i32(tcg_res
);
12701 tcg_temp_free_i32(tcg_op
);
12704 clear_vec_high(s
, is_q
, rd
);
12708 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12709 tcg_temp_free_i32(tcg_rmode
);
12712 if (tcg_fpstatus
) {
12713 tcg_temp_free_ptr(tcg_fpstatus
);
12717 /* AdvSIMD scalar x indexed element
12718 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12719 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12720 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12721 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12722 * AdvSIMD vector x indexed element
12723 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12724 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12725 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12726 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12728 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
12730 /* This encoding has two kinds of instruction:
12731 * normal, where we perform elt x idxelt => elt for each
12732 * element in the vector
12733 * long, where we perform elt x idxelt and generate a result of
12734 * double the width of the input element
12735 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
12737 bool is_scalar
= extract32(insn
, 28, 1);
12738 bool is_q
= extract32(insn
, 30, 1);
12739 bool u
= extract32(insn
, 29, 1);
12740 int size
= extract32(insn
, 22, 2);
12741 int l
= extract32(insn
, 21, 1);
12742 int m
= extract32(insn
, 20, 1);
12743 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
12744 int rm
= extract32(insn
, 16, 4);
12745 int opcode
= extract32(insn
, 12, 4);
12746 int h
= extract32(insn
, 11, 1);
12747 int rn
= extract32(insn
, 5, 5);
12748 int rd
= extract32(insn
, 0, 5);
12749 bool is_long
= false;
12751 bool is_fp16
= false;
12755 switch (16 * u
+ opcode
) {
12756 case 0x08: /* MUL */
12757 case 0x10: /* MLA */
12758 case 0x14: /* MLS */
12760 unallocated_encoding(s
);
12764 case 0x02: /* SMLAL, SMLAL2 */
12765 case 0x12: /* UMLAL, UMLAL2 */
12766 case 0x06: /* SMLSL, SMLSL2 */
12767 case 0x16: /* UMLSL, UMLSL2 */
12768 case 0x0a: /* SMULL, SMULL2 */
12769 case 0x1a: /* UMULL, UMULL2 */
12771 unallocated_encoding(s
);
12776 case 0x03: /* SQDMLAL, SQDMLAL2 */
12777 case 0x07: /* SQDMLSL, SQDMLSL2 */
12778 case 0x0b: /* SQDMULL, SQDMULL2 */
12781 case 0x0c: /* SQDMULH */
12782 case 0x0d: /* SQRDMULH */
12784 case 0x01: /* FMLA */
12785 case 0x05: /* FMLS */
12786 case 0x09: /* FMUL */
12787 case 0x19: /* FMULX */
12790 case 0x1d: /* SQRDMLAH */
12791 case 0x1f: /* SQRDMLSH */
12792 if (!dc_isar_feature(aa64_rdm
, s
)) {
12793 unallocated_encoding(s
);
12797 case 0x0e: /* SDOT */
12798 case 0x1e: /* UDOT */
12799 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_dp
, s
)) {
12800 unallocated_encoding(s
);
12804 case 0x11: /* FCMLA #0 */
12805 case 0x13: /* FCMLA #90 */
12806 case 0x15: /* FCMLA #180 */
12807 case 0x17: /* FCMLA #270 */
12808 if (is_scalar
|| !dc_isar_feature(aa64_fcma
, s
)) {
12809 unallocated_encoding(s
);
12814 case 0x00: /* FMLAL */
12815 case 0x04: /* FMLSL */
12816 case 0x18: /* FMLAL2 */
12817 case 0x1c: /* FMLSL2 */
12818 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_fhm
, s
)) {
12819 unallocated_encoding(s
);
12823 /* is_fp, but we pass cpu_env not fp_status. */
12826 unallocated_encoding(s
);
12831 case 1: /* normal fp */
12832 /* convert insn encoded size to TCGMemOp size */
12834 case 0: /* half-precision */
12838 case MO_32
: /* single precision */
12839 case MO_64
: /* double precision */
12842 unallocated_encoding(s
);
12847 case 2: /* complex fp */
12848 /* Each indexable element is a complex pair. */
12853 unallocated_encoding(s
);
12861 unallocated_encoding(s
);
12866 default: /* integer */
12870 unallocated_encoding(s
);
12875 if (is_fp16
&& !dc_isar_feature(aa64_fp16
, s
)) {
12876 unallocated_encoding(s
);
12880 /* Given TCGMemOp size, adjust register and indexing. */
12883 index
= h
<< 2 | l
<< 1 | m
;
12886 index
= h
<< 1 | l
;
12891 unallocated_encoding(s
);
12898 g_assert_not_reached();
12901 if (!fp_access_check(s
)) {
12906 fpst
= get_fpstatus_ptr(is_fp16
);
12911 switch (16 * u
+ opcode
) {
12912 case 0x0e: /* SDOT */
12913 case 0x1e: /* UDOT */
12914 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, index
,
12915 u
? gen_helper_gvec_udot_idx_b
12916 : gen_helper_gvec_sdot_idx_b
);
12918 case 0x11: /* FCMLA #0 */
12919 case 0x13: /* FCMLA #90 */
12920 case 0x15: /* FCMLA #180 */
12921 case 0x17: /* FCMLA #270 */
12923 int rot
= extract32(insn
, 13, 2);
12924 int data
= (index
<< 2) | rot
;
12925 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
12926 vec_full_reg_offset(s
, rn
),
12927 vec_full_reg_offset(s
, rm
), fpst
,
12928 is_q
? 16 : 8, vec_full_reg_size(s
), data
,
12930 ? gen_helper_gvec_fcmlas_idx
12931 : gen_helper_gvec_fcmlah_idx
);
12932 tcg_temp_free_ptr(fpst
);
12936 case 0x00: /* FMLAL */
12937 case 0x04: /* FMLSL */
12938 case 0x18: /* FMLAL2 */
12939 case 0x1c: /* FMLSL2 */
12941 int is_s
= extract32(opcode
, 2, 1);
12943 int data
= (index
<< 2) | (is_2
<< 1) | is_s
;
12944 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
12945 vec_full_reg_offset(s
, rn
),
12946 vec_full_reg_offset(s
, rm
), cpu_env
,
12947 is_q
? 16 : 8, vec_full_reg_size(s
),
12948 data
, gen_helper_gvec_fmlal_idx_a64
);
12954 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
12957 assert(is_fp
&& is_q
&& !is_long
);
12959 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
12961 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
12962 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12963 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12965 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12967 switch (16 * u
+ opcode
) {
12968 case 0x05: /* FMLS */
12969 /* As usual for ARM, separate negation for fused multiply-add */
12970 gen_helper_vfp_negd(tcg_op
, tcg_op
);
12972 case 0x01: /* FMLA */
12973 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12974 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
12976 case 0x09: /* FMUL */
12977 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12979 case 0x19: /* FMULX */
12980 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12983 g_assert_not_reached();
12986 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12987 tcg_temp_free_i64(tcg_op
);
12988 tcg_temp_free_i64(tcg_res
);
12991 tcg_temp_free_i64(tcg_idx
);
12992 clear_vec_high(s
, !is_scalar
, rd
);
12993 } else if (!is_long
) {
12994 /* 32 bit floating point, or 16 or 32 bit integer.
12995 * For the 16 bit scalar case we use the usual Neon helpers and
12996 * rely on the fact that 0 op 0 == 0 with no side effects.
12998 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
12999 int pass
, maxpasses
;
13004 maxpasses
= is_q
? 4 : 2;
13007 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13009 if (size
== 1 && !is_scalar
) {
13010 /* The simplest way to handle the 16x16 indexed ops is to duplicate
13011 * the index into both halves of the 32 bit tcg_idx and then use
13012 * the usual Neon helpers.
13014 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13017 for (pass
= 0; pass
< maxpasses
; pass
++) {
13018 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13019 TCGv_i32 tcg_res
= tcg_temp_new_i32();
13021 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
13023 switch (16 * u
+ opcode
) {
13024 case 0x08: /* MUL */
13025 case 0x10: /* MLA */
13026 case 0x14: /* MLS */
13028 static NeonGenTwoOpFn
* const fns
[2][2] = {
13029 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
13030 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
13032 NeonGenTwoOpFn
*genfn
;
13033 bool is_sub
= opcode
== 0x4;
13036 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
13038 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
13040 if (opcode
== 0x8) {
13043 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
13044 genfn
= fns
[size
- 1][is_sub
];
13045 genfn(tcg_res
, tcg_op
, tcg_res
);
13048 case 0x05: /* FMLS */
13049 case 0x01: /* FMLA */
13050 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13051 is_scalar
? size
: MO_32
);
13054 if (opcode
== 0x5) {
13055 /* As usual for ARM, separate negation for fused
13057 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80008000);
13060 gen_helper_advsimd_muladdh(tcg_res
, tcg_op
, tcg_idx
,
13063 gen_helper_advsimd_muladd2h(tcg_res
, tcg_op
, tcg_idx
,
13068 if (opcode
== 0x5) {
13069 /* As usual for ARM, separate negation for
13070 * fused multiply-add */
13071 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80000000);
13073 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
,
13077 g_assert_not_reached();
13080 case 0x09: /* FMUL */
13084 gen_helper_advsimd_mulh(tcg_res
, tcg_op
,
13087 gen_helper_advsimd_mul2h(tcg_res
, tcg_op
,
13092 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13095 g_assert_not_reached();
13098 case 0x19: /* FMULX */
13102 gen_helper_advsimd_mulxh(tcg_res
, tcg_op
,
13105 gen_helper_advsimd_mulx2h(tcg_res
, tcg_op
,
13110 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13113 g_assert_not_reached();
13116 case 0x0c: /* SQDMULH */
13118 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
13121 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
13125 case 0x0d: /* SQRDMULH */
13127 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
13130 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
13134 case 0x1d: /* SQRDMLAH */
13135 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13136 is_scalar
? size
: MO_32
);
13138 gen_helper_neon_qrdmlah_s16(tcg_res
, cpu_env
,
13139 tcg_op
, tcg_idx
, tcg_res
);
13141 gen_helper_neon_qrdmlah_s32(tcg_res
, cpu_env
,
13142 tcg_op
, tcg_idx
, tcg_res
);
13145 case 0x1f: /* SQRDMLSH */
13146 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13147 is_scalar
? size
: MO_32
);
13149 gen_helper_neon_qrdmlsh_s16(tcg_res
, cpu_env
,
13150 tcg_op
, tcg_idx
, tcg_res
);
13152 gen_helper_neon_qrdmlsh_s32(tcg_res
, cpu_env
,
13153 tcg_op
, tcg_idx
, tcg_res
);
13157 g_assert_not_reached();
13161 write_fp_sreg(s
, rd
, tcg_res
);
13163 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
13166 tcg_temp_free_i32(tcg_op
);
13167 tcg_temp_free_i32(tcg_res
);
13170 tcg_temp_free_i32(tcg_idx
);
13171 clear_vec_high(s
, is_q
, rd
);
13173 /* long ops: 16x16->32 or 32x32->64 */
13174 TCGv_i64 tcg_res
[2];
13176 bool satop
= extract32(opcode
, 0, 1);
13177 TCGMemOp memop
= MO_32
;
13184 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
13186 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
13188 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13189 TCGv_i64 tcg_op
= tcg_temp_new_i64();
13190 TCGv_i64 tcg_passres
;
13196 passelt
= pass
+ (is_q
* 2);
13199 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
13201 tcg_res
[pass
] = tcg_temp_new_i64();
13203 if (opcode
== 0xa || opcode
== 0xb) {
13204 /* Non-accumulating ops */
13205 tcg_passres
= tcg_res
[pass
];
13207 tcg_passres
= tcg_temp_new_i64();
13210 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
13211 tcg_temp_free_i64(tcg_op
);
13214 /* saturating, doubling */
13215 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
13216 tcg_passres
, tcg_passres
);
13219 if (opcode
== 0xa || opcode
== 0xb) {
13223 /* Accumulating op: handle accumulate step */
13224 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13227 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13228 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13230 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13231 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13233 case 0x7: /* SQDMLSL, SQDMLSL2 */
13234 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
13236 case 0x3: /* SQDMLAL, SQDMLAL2 */
13237 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
13242 g_assert_not_reached();
13244 tcg_temp_free_i64(tcg_passres
);
13246 tcg_temp_free_i64(tcg_idx
);
13248 clear_vec_high(s
, !is_scalar
, rd
);
13250 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13253 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13256 /* The simplest way to handle the 16x16 indexed ops is to
13257 * duplicate the index into both halves of the 32 bit tcg_idx
13258 * and then use the usual Neon helpers.
13260 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13263 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13264 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13265 TCGv_i64 tcg_passres
;
13268 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
13270 read_vec_element_i32(s
, tcg_op
, rn
,
13271 pass
+ (is_q
* 2), MO_32
);
13274 tcg_res
[pass
] = tcg_temp_new_i64();
13276 if (opcode
== 0xa || opcode
== 0xb) {
13277 /* Non-accumulating ops */
13278 tcg_passres
= tcg_res
[pass
];
13280 tcg_passres
= tcg_temp_new_i64();
13283 if (memop
& MO_SIGN
) {
13284 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
13286 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
13289 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
13290 tcg_passres
, tcg_passres
);
13292 tcg_temp_free_i32(tcg_op
);
13294 if (opcode
== 0xa || opcode
== 0xb) {
13298 /* Accumulating op: handle accumulate step */
13299 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13302 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13303 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
13306 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13307 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
13310 case 0x7: /* SQDMLSL, SQDMLSL2 */
13311 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
13313 case 0x3: /* SQDMLAL, SQDMLAL2 */
13314 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
13319 g_assert_not_reached();
13321 tcg_temp_free_i64(tcg_passres
);
13323 tcg_temp_free_i32(tcg_idx
);
13326 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
13331 tcg_res
[1] = tcg_const_i64(0);
13334 for (pass
= 0; pass
< 2; pass
++) {
13335 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13336 tcg_temp_free_i64(tcg_res
[pass
]);
13341 tcg_temp_free_ptr(fpst
);
13346 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13347 * +-----------------+------+-----------+--------+-----+------+------+
13348 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13349 * +-----------------+------+-----------+--------+-----+------+------+
13351 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
13353 int size
= extract32(insn
, 22, 2);
13354 int opcode
= extract32(insn
, 12, 5);
13355 int rn
= extract32(insn
, 5, 5);
13356 int rd
= extract32(insn
, 0, 5);
13358 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13359 TCGv_i32 tcg_decrypt
;
13360 CryptoThreeOpIntFn
*genfn
;
13362 if (!dc_isar_feature(aa64_aes
, s
) || size
!= 0) {
13363 unallocated_encoding(s
);
13368 case 0x4: /* AESE */
13370 genfn
= gen_helper_crypto_aese
;
13372 case 0x6: /* AESMC */
13374 genfn
= gen_helper_crypto_aesmc
;
13376 case 0x5: /* AESD */
13378 genfn
= gen_helper_crypto_aese
;
13380 case 0x7: /* AESIMC */
13382 genfn
= gen_helper_crypto_aesmc
;
13385 unallocated_encoding(s
);
13389 if (!fp_access_check(s
)) {
13393 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13394 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13395 tcg_decrypt
= tcg_const_i32(decrypt
);
13397 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_decrypt
);
13399 tcg_temp_free_ptr(tcg_rd_ptr
);
13400 tcg_temp_free_ptr(tcg_rn_ptr
);
13401 tcg_temp_free_i32(tcg_decrypt
);
13404 /* Crypto three-reg SHA
13405 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
13406 * +-----------------+------+---+------+---+--------+-----+------+------+
13407 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
13408 * +-----------------+------+---+------+---+--------+-----+------+------+
13410 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
13412 int size
= extract32(insn
, 22, 2);
13413 int opcode
= extract32(insn
, 12, 3);
13414 int rm
= extract32(insn
, 16, 5);
13415 int rn
= extract32(insn
, 5, 5);
13416 int rd
= extract32(insn
, 0, 5);
13417 CryptoThreeOpFn
*genfn
;
13418 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13422 unallocated_encoding(s
);
13427 case 0: /* SHA1C */
13428 case 1: /* SHA1P */
13429 case 2: /* SHA1M */
13430 case 3: /* SHA1SU0 */
13432 feature
= dc_isar_feature(aa64_sha1
, s
);
13434 case 4: /* SHA256H */
13435 genfn
= gen_helper_crypto_sha256h
;
13436 feature
= dc_isar_feature(aa64_sha256
, s
);
13438 case 5: /* SHA256H2 */
13439 genfn
= gen_helper_crypto_sha256h2
;
13440 feature
= dc_isar_feature(aa64_sha256
, s
);
13442 case 6: /* SHA256SU1 */
13443 genfn
= gen_helper_crypto_sha256su1
;
13444 feature
= dc_isar_feature(aa64_sha256
, s
);
13447 unallocated_encoding(s
);
13452 unallocated_encoding(s
);
13456 if (!fp_access_check(s
)) {
13460 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13461 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13462 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13465 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13467 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
13469 gen_helper_crypto_sha1_3reg(tcg_rd_ptr
, tcg_rn_ptr
,
13470 tcg_rm_ptr
, tcg_opcode
);
13471 tcg_temp_free_i32(tcg_opcode
);
13474 tcg_temp_free_ptr(tcg_rd_ptr
);
13475 tcg_temp_free_ptr(tcg_rn_ptr
);
13476 tcg_temp_free_ptr(tcg_rm_ptr
);
13479 /* Crypto two-reg SHA
13480 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13481 * +-----------------+------+-----------+--------+-----+------+------+
13482 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13483 * +-----------------+------+-----------+--------+-----+------+------+
13485 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
13487 int size
= extract32(insn
, 22, 2);
13488 int opcode
= extract32(insn
, 12, 5);
13489 int rn
= extract32(insn
, 5, 5);
13490 int rd
= extract32(insn
, 0, 5);
13491 CryptoTwoOpFn
*genfn
;
13493 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13496 unallocated_encoding(s
);
13501 case 0: /* SHA1H */
13502 feature
= dc_isar_feature(aa64_sha1
, s
);
13503 genfn
= gen_helper_crypto_sha1h
;
13505 case 1: /* SHA1SU1 */
13506 feature
= dc_isar_feature(aa64_sha1
, s
);
13507 genfn
= gen_helper_crypto_sha1su1
;
13509 case 2: /* SHA256SU0 */
13510 feature
= dc_isar_feature(aa64_sha256
, s
);
13511 genfn
= gen_helper_crypto_sha256su0
;
13514 unallocated_encoding(s
);
13519 unallocated_encoding(s
);
13523 if (!fp_access_check(s
)) {
13527 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13528 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13530 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13532 tcg_temp_free_ptr(tcg_rd_ptr
);
13533 tcg_temp_free_ptr(tcg_rn_ptr
);
13536 /* Crypto three-reg SHA512
13537 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13538 * +-----------------------+------+---+---+-----+--------+------+------+
13539 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
13540 * +-----------------------+------+---+---+-----+--------+------+------+
13542 static void disas_crypto_three_reg_sha512(DisasContext
*s
, uint32_t insn
)
13544 int opcode
= extract32(insn
, 10, 2);
13545 int o
= extract32(insn
, 14, 1);
13546 int rm
= extract32(insn
, 16, 5);
13547 int rn
= extract32(insn
, 5, 5);
13548 int rd
= extract32(insn
, 0, 5);
13550 CryptoThreeOpFn
*genfn
;
13554 case 0: /* SHA512H */
13555 feature
= dc_isar_feature(aa64_sha512
, s
);
13556 genfn
= gen_helper_crypto_sha512h
;
13558 case 1: /* SHA512H2 */
13559 feature
= dc_isar_feature(aa64_sha512
, s
);
13560 genfn
= gen_helper_crypto_sha512h2
;
13562 case 2: /* SHA512SU1 */
13563 feature
= dc_isar_feature(aa64_sha512
, s
);
13564 genfn
= gen_helper_crypto_sha512su1
;
13567 feature
= dc_isar_feature(aa64_sha3
, s
);
13573 case 0: /* SM3PARTW1 */
13574 feature
= dc_isar_feature(aa64_sm3
, s
);
13575 genfn
= gen_helper_crypto_sm3partw1
;
13577 case 1: /* SM3PARTW2 */
13578 feature
= dc_isar_feature(aa64_sm3
, s
);
13579 genfn
= gen_helper_crypto_sm3partw2
;
13581 case 2: /* SM4EKEY */
13582 feature
= dc_isar_feature(aa64_sm4
, s
);
13583 genfn
= gen_helper_crypto_sm4ekey
;
13586 unallocated_encoding(s
);
13592 unallocated_encoding(s
);
13596 if (!fp_access_check(s
)) {
13601 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13603 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13604 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13605 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13607 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13609 tcg_temp_free_ptr(tcg_rd_ptr
);
13610 tcg_temp_free_ptr(tcg_rn_ptr
);
13611 tcg_temp_free_ptr(tcg_rm_ptr
);
13613 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13616 tcg_op1
= tcg_temp_new_i64();
13617 tcg_op2
= tcg_temp_new_i64();
13618 tcg_res
[0] = tcg_temp_new_i64();
13619 tcg_res
[1] = tcg_temp_new_i64();
13621 for (pass
= 0; pass
< 2; pass
++) {
13622 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13623 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13625 tcg_gen_rotli_i64(tcg_res
[pass
], tcg_op2
, 1);
13626 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13628 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13629 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13631 tcg_temp_free_i64(tcg_op1
);
13632 tcg_temp_free_i64(tcg_op2
);
13633 tcg_temp_free_i64(tcg_res
[0]);
13634 tcg_temp_free_i64(tcg_res
[1]);
13638 /* Crypto two-reg SHA512
13639 * 31 12 11 10 9 5 4 0
13640 * +-----------------------------------------+--------+------+------+
13641 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
13642 * +-----------------------------------------+--------+------+------+
13644 static void disas_crypto_two_reg_sha512(DisasContext
*s
, uint32_t insn
)
13646 int opcode
= extract32(insn
, 10, 2);
13647 int rn
= extract32(insn
, 5, 5);
13648 int rd
= extract32(insn
, 0, 5);
13649 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13651 CryptoTwoOpFn
*genfn
;
13654 case 0: /* SHA512SU0 */
13655 feature
= dc_isar_feature(aa64_sha512
, s
);
13656 genfn
= gen_helper_crypto_sha512su0
;
13659 feature
= dc_isar_feature(aa64_sm4
, s
);
13660 genfn
= gen_helper_crypto_sm4e
;
13663 unallocated_encoding(s
);
13668 unallocated_encoding(s
);
13672 if (!fp_access_check(s
)) {
13676 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13677 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13679 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13681 tcg_temp_free_ptr(tcg_rd_ptr
);
13682 tcg_temp_free_ptr(tcg_rn_ptr
);
13685 /* Crypto four-register
13686 * 31 23 22 21 20 16 15 14 10 9 5 4 0
13687 * +-------------------+-----+------+---+------+------+------+
13688 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
13689 * +-------------------+-----+------+---+------+------+------+
13691 static void disas_crypto_four_reg(DisasContext
*s
, uint32_t insn
)
13693 int op0
= extract32(insn
, 21, 2);
13694 int rm
= extract32(insn
, 16, 5);
13695 int ra
= extract32(insn
, 10, 5);
13696 int rn
= extract32(insn
, 5, 5);
13697 int rd
= extract32(insn
, 0, 5);
13703 feature
= dc_isar_feature(aa64_sha3
, s
);
13705 case 2: /* SM3SS1 */
13706 feature
= dc_isar_feature(aa64_sm3
, s
);
13709 unallocated_encoding(s
);
13714 unallocated_encoding(s
);
13718 if (!fp_access_check(s
)) {
13723 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
[2];
13726 tcg_op1
= tcg_temp_new_i64();
13727 tcg_op2
= tcg_temp_new_i64();
13728 tcg_op3
= tcg_temp_new_i64();
13729 tcg_res
[0] = tcg_temp_new_i64();
13730 tcg_res
[1] = tcg_temp_new_i64();
13732 for (pass
= 0; pass
< 2; pass
++) {
13733 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13734 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13735 read_vec_element(s
, tcg_op3
, ra
, pass
, MO_64
);
13739 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13742 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13744 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13746 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13747 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13749 tcg_temp_free_i64(tcg_op1
);
13750 tcg_temp_free_i64(tcg_op2
);
13751 tcg_temp_free_i64(tcg_op3
);
13752 tcg_temp_free_i64(tcg_res
[0]);
13753 tcg_temp_free_i64(tcg_res
[1]);
13755 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
, tcg_zero
;
13757 tcg_op1
= tcg_temp_new_i32();
13758 tcg_op2
= tcg_temp_new_i32();
13759 tcg_op3
= tcg_temp_new_i32();
13760 tcg_res
= tcg_temp_new_i32();
13761 tcg_zero
= tcg_const_i32(0);
13763 read_vec_element_i32(s
, tcg_op1
, rn
, 3, MO_32
);
13764 read_vec_element_i32(s
, tcg_op2
, rm
, 3, MO_32
);
13765 read_vec_element_i32(s
, tcg_op3
, ra
, 3, MO_32
);
13767 tcg_gen_rotri_i32(tcg_res
, tcg_op1
, 20);
13768 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op2
);
13769 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op3
);
13770 tcg_gen_rotri_i32(tcg_res
, tcg_res
, 25);
13772 write_vec_element_i32(s
, tcg_zero
, rd
, 0, MO_32
);
13773 write_vec_element_i32(s
, tcg_zero
, rd
, 1, MO_32
);
13774 write_vec_element_i32(s
, tcg_zero
, rd
, 2, MO_32
);
13775 write_vec_element_i32(s
, tcg_res
, rd
, 3, MO_32
);
13777 tcg_temp_free_i32(tcg_op1
);
13778 tcg_temp_free_i32(tcg_op2
);
13779 tcg_temp_free_i32(tcg_op3
);
13780 tcg_temp_free_i32(tcg_res
);
13781 tcg_temp_free_i32(tcg_zero
);
13786 * 31 21 20 16 15 10 9 5 4 0
13787 * +-----------------------+------+--------+------+------+
13788 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
13789 * +-----------------------+------+--------+------+------+
13791 static void disas_crypto_xar(DisasContext
*s
, uint32_t insn
)
13793 int rm
= extract32(insn
, 16, 5);
13794 int imm6
= extract32(insn
, 10, 6);
13795 int rn
= extract32(insn
, 5, 5);
13796 int rd
= extract32(insn
, 0, 5);
13797 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13800 if (!dc_isar_feature(aa64_sha3
, s
)) {
13801 unallocated_encoding(s
);
13805 if (!fp_access_check(s
)) {
13809 tcg_op1
= tcg_temp_new_i64();
13810 tcg_op2
= tcg_temp_new_i64();
13811 tcg_res
[0] = tcg_temp_new_i64();
13812 tcg_res
[1] = tcg_temp_new_i64();
13814 for (pass
= 0; pass
< 2; pass
++) {
13815 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13816 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13818 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
13819 tcg_gen_rotri_i64(tcg_res
[pass
], tcg_res
[pass
], imm6
);
13821 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13822 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13824 tcg_temp_free_i64(tcg_op1
);
13825 tcg_temp_free_i64(tcg_op2
);
13826 tcg_temp_free_i64(tcg_res
[0]);
13827 tcg_temp_free_i64(tcg_res
[1]);
13830 /* Crypto three-reg imm2
13831 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13832 * +-----------------------+------+-----+------+--------+------+------+
13833 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
13834 * +-----------------------+------+-----+------+--------+------+------+
13836 static void disas_crypto_three_reg_imm2(DisasContext
*s
, uint32_t insn
)
13838 int opcode
= extract32(insn
, 10, 2);
13839 int imm2
= extract32(insn
, 12, 2);
13840 int rm
= extract32(insn
, 16, 5);
13841 int rn
= extract32(insn
, 5, 5);
13842 int rd
= extract32(insn
, 0, 5);
13843 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13844 TCGv_i32 tcg_imm2
, tcg_opcode
;
13846 if (!dc_isar_feature(aa64_sm3
, s
)) {
13847 unallocated_encoding(s
);
13851 if (!fp_access_check(s
)) {
13855 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13856 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13857 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13858 tcg_imm2
= tcg_const_i32(imm2
);
13859 tcg_opcode
= tcg_const_i32(opcode
);
13861 gen_helper_crypto_sm3tt(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
, tcg_imm2
,
13864 tcg_temp_free_ptr(tcg_rd_ptr
);
13865 tcg_temp_free_ptr(tcg_rn_ptr
);
13866 tcg_temp_free_ptr(tcg_rm_ptr
);
13867 tcg_temp_free_i32(tcg_imm2
);
13868 tcg_temp_free_i32(tcg_opcode
);
13871 /* C3.6 Data processing - SIMD, inc Crypto
13873 * As the decode gets a little complex we are using a table based
13874 * approach for this part of the decode.
13876 static const AArch64DecodeTable data_proc_simd
[] = {
13877 /* pattern , mask , fn */
13878 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
13879 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra
},
13880 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
13881 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
13882 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
13883 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
13884 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
13885 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
13886 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
13887 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
13888 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
13889 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
13890 { 0x2e000000, 0xbf208400, disas_simd_ext
},
13891 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
13892 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra
},
13893 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
13894 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
13895 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
13896 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
13897 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
13898 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
13899 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
13900 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
13901 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
13902 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512
},
13903 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512
},
13904 { 0xce000000, 0xff808000, disas_crypto_four_reg
},
13905 { 0xce800000, 0xffe00000, disas_crypto_xar
},
13906 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2
},
13907 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16
},
13908 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16
},
13909 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16
},
13910 { 0x00000000, 0x00000000, NULL
}
13913 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
13915 /* Note that this is called with all non-FP cases from
13916 * table C3-6 so it must UNDEF for entries not specifically
13917 * allocated to instructions in that table.
13919 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
13923 unallocated_encoding(s
);
13927 /* C3.6 Data processing - SIMD and floating point */
13928 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
13930 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
13931 disas_data_proc_fp(s
, insn
);
13933 /* SIMD, including crypto */
13934 disas_data_proc_simd(s
, insn
);
13940 * @env: The cpu environment
13941 * @s: The DisasContext
13943 * Return true if the page is guarded.
13945 static bool is_guarded_page(CPUARMState
*env
, DisasContext
*s
)
13947 #ifdef CONFIG_USER_ONLY
13948 return false; /* FIXME */
13950 uint64_t addr
= s
->base
.pc_first
;
13951 int mmu_idx
= arm_to_core_mmu_idx(s
->mmu_idx
);
13952 unsigned int index
= tlb_index(env
, mmu_idx
, addr
);
13953 CPUTLBEntry
*entry
= tlb_entry(env
, mmu_idx
, addr
);
13956 * We test this immediately after reading an insn, which means
13957 * that any normal page must be in the TLB. The only exception
13958 * would be for executing from flash or device memory, which
13959 * does not retain the TLB entry.
13961 * FIXME: Assume false for those, for now. We could use
13962 * arm_cpu_get_phys_page_attrs_debug to re-read the page
13963 * table entry even for that case.
13965 return (tlb_hit(entry
->addr_code
, addr
) &&
13966 env_tlb(env
)->d
[mmu_idx
].iotlb
[index
].attrs
.target_tlb_bit0
);
13971 * btype_destination_ok:
13972 * @insn: The instruction at the branch destination
13973 * @bt: SCTLR_ELx.BT
13974 * @btype: PSTATE.BTYPE, and is non-zero
13976 * On a guarded page, there are a limited number of insns
13977 * that may be present at the branch target:
13978 * - branch target identifiers,
13979 * - paciasp, pacibsp,
13982 * Anything else causes a Branch Target Exception.
13984 * Return true if the branch is compatible, false to raise BTITRAP.
13986 static bool btype_destination_ok(uint32_t insn
, bool bt
, int btype
)
13988 if ((insn
& 0xfffff01fu
) == 0xd503201fu
) {
13990 switch (extract32(insn
, 5, 7)) {
13991 case 0b011001: /* PACIASP */
13992 case 0b011011: /* PACIBSP */
13994 * If SCTLR_ELx.BT, then PACI*SP are not compatible
13995 * with btype == 3. Otherwise all btype are ok.
13997 return !bt
|| btype
!= 3;
13998 case 0b100000: /* BTI */
13999 /* Not compatible with any btype. */
14001 case 0b100010: /* BTI c */
14002 /* Not compatible with btype == 3 */
14004 case 0b100100: /* BTI j */
14005 /* Not compatible with btype == 2 */
14007 case 0b100110: /* BTI jc */
14008 /* Compatible with any btype. */
14012 switch (insn
& 0xffe0001fu
) {
14013 case 0xd4200000u
: /* BRK */
14014 case 0xd4400000u
: /* HLT */
14015 /* Give priority to the breakpoint exception. */
14022 /* C3.1 A64 instruction index by encoding */
14023 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
14027 s
->pc_curr
= s
->base
.pc_next
;
14028 insn
= arm_ldl_code(env
, s
->base
.pc_next
, s
->sctlr_b
);
14030 s
->base
.pc_next
+= 4;
14032 s
->fp_access_checked
= false;
14034 if (dc_isar_feature(aa64_bti
, s
)) {
14035 if (s
->base
.num_insns
== 1) {
14037 * At the first insn of the TB, compute s->guarded_page.
14038 * We delayed computing this until successfully reading
14039 * the first insn of the TB, above. This (mostly) ensures
14040 * that the softmmu tlb entry has been populated, and the
14041 * page table GP bit is available.
14043 * Note that we need to compute this even if btype == 0,
14044 * because this value is used for BR instructions later
14045 * where ENV is not available.
14047 s
->guarded_page
= is_guarded_page(env
, s
);
14049 /* First insn can have btype set to non-zero. */
14050 tcg_debug_assert(s
->btype
>= 0);
14053 * Note that the Branch Target Exception has fairly high
14054 * priority -- below debugging exceptions but above most
14055 * everything else. This allows us to handle this now
14056 * instead of waiting until the insn is otherwise decoded.
14060 && !btype_destination_ok(insn
, s
->bt
, s
->btype
)) {
14061 gen_exception_insn(s
, s
->pc_curr
, EXCP_UDEF
,
14062 syn_btitrap(s
->btype
),
14063 default_exception_el(s
));
14067 /* Not the first insn: btype must be 0. */
14068 tcg_debug_assert(s
->btype
== 0);
14072 switch (extract32(insn
, 25, 4)) {
14073 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
14074 unallocated_encoding(s
);
14077 if (!dc_isar_feature(aa64_sve
, s
) || !disas_sve(s
, insn
)) {
14078 unallocated_encoding(s
);
14081 case 0x8: case 0x9: /* Data processing - immediate */
14082 disas_data_proc_imm(s
, insn
);
14084 case 0xa: case 0xb: /* Branch, exception generation and system insns */
14085 disas_b_exc_sys(s
, insn
);
14090 case 0xe: /* Loads and stores */
14091 disas_ldst(s
, insn
);
14094 case 0xd: /* Data processing - register */
14095 disas_data_proc_reg(s
, insn
);
14098 case 0xf: /* Data processing - SIMD and floating point */
14099 disas_data_proc_simd_fp(s
, insn
);
14102 assert(FALSE
); /* all 15 cases should be handled above */
14106 /* if we allocated any temporaries, free them here */
14110 * After execution of most insns, btype is reset to 0.
14111 * Note that we set btype == -1 when the insn sets btype.
14113 if (s
->btype
> 0 && s
->base
.is_jmp
!= DISAS_NORETURN
) {
14118 static void aarch64_tr_init_disas_context(DisasContextBase
*dcbase
,
14121 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14122 CPUARMState
*env
= cpu
->env_ptr
;
14123 ARMCPU
*arm_cpu
= env_archcpu(env
);
14124 uint32_t tb_flags
= dc
->base
.tb
->flags
;
14125 int bound
, core_mmu_idx
;
14127 dc
->isar
= &arm_cpu
->isar
;
14131 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
14132 * there is no secure EL1, so we route exceptions to EL3.
14134 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
14135 !arm_el_is_aa64(env
, 3);
14138 dc
->be_data
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, BE_DATA
) ? MO_BE
: MO_LE
;
14139 dc
->condexec_mask
= 0;
14140 dc
->condexec_cond
= 0;
14141 core_mmu_idx
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, MMUIDX
);
14142 dc
->mmu_idx
= core_to_arm_mmu_idx(env
, core_mmu_idx
);
14143 dc
->tbii
= FIELD_EX32(tb_flags
, TBFLAG_A64
, TBII
);
14144 dc
->tbid
= FIELD_EX32(tb_flags
, TBFLAG_A64
, TBID
);
14145 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
14146 #if !defined(CONFIG_USER_ONLY)
14147 dc
->user
= (dc
->current_el
== 0);
14149 dc
->fp_excp_el
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, FPEXC_EL
);
14150 dc
->sve_excp_el
= FIELD_EX32(tb_flags
, TBFLAG_A64
, SVEEXC_EL
);
14151 dc
->sve_len
= (FIELD_EX32(tb_flags
, TBFLAG_A64
, ZCR_LEN
) + 1) * 16;
14152 dc
->pauth_active
= FIELD_EX32(tb_flags
, TBFLAG_A64
, PAUTH_ACTIVE
);
14153 dc
->bt
= FIELD_EX32(tb_flags
, TBFLAG_A64
, BT
);
14154 dc
->btype
= FIELD_EX32(tb_flags
, TBFLAG_A64
, BTYPE
);
14156 dc
->vec_stride
= 0;
14157 dc
->cp_regs
= arm_cpu
->cp_regs
;
14158 dc
->features
= env
->features
;
14160 /* Single step state. The code-generation logic here is:
14162 * generate code with no special handling for single-stepping (except
14163 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
14164 * this happens anyway because those changes are all system register or
14166 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
14167 * emit code for one insn
14168 * emit code to clear PSTATE.SS
14169 * emit code to generate software step exception for completed step
14170 * end TB (as usual for having generated an exception)
14171 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
14172 * emit code to generate a software step exception
14175 dc
->ss_active
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, SS_ACTIVE
);
14176 dc
->pstate_ss
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, PSTATE_SS
);
14177 dc
->is_ldex
= false;
14178 dc
->debug_target_el
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, DEBUG_TARGET_EL
);
14180 /* Bound the number of insns to execute to those left on the page. */
14181 bound
= -(dc
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
14183 /* If architectural single step active, limit to 1. */
14184 if (dc
->ss_active
) {
14187 dc
->base
.max_insns
= MIN(dc
->base
.max_insns
, bound
);
14189 init_tmp_a64_array(dc
);
14192 static void aarch64_tr_tb_start(DisasContextBase
*db
, CPUState
*cpu
)
14196 static void aarch64_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
14198 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14200 tcg_gen_insn_start(dc
->base
.pc_next
, 0, 0);
14201 dc
->insn_start
= tcg_last_op();
14204 static bool aarch64_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cpu
,
14205 const CPUBreakpoint
*bp
)
14207 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14209 if (bp
->flags
& BP_CPU
) {
14210 gen_a64_set_pc_im(dc
->base
.pc_next
);
14211 gen_helper_check_breakpoints(cpu_env
);
14212 /* End the TB early; it likely won't be executed */
14213 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
14215 gen_exception_internal_insn(dc
, dc
->base
.pc_next
, EXCP_DEBUG
);
14216 /* The address covered by the breakpoint must be
14217 included in [tb->pc, tb->pc + tb->size) in order
14218 to for it to be properly cleared -- thus we
14219 increment the PC here so that the logic setting
14220 tb->size below does the right thing. */
14221 dc
->base
.pc_next
+= 4;
14222 dc
->base
.is_jmp
= DISAS_NORETURN
;
14228 static void aarch64_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
14230 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14231 CPUARMState
*env
= cpu
->env_ptr
;
14233 if (dc
->ss_active
&& !dc
->pstate_ss
) {
14234 /* Singlestep state is Active-pending.
14235 * If we're in this state at the start of a TB then either
14236 * a) we just took an exception to an EL which is being debugged
14237 * and this is the first insn in the exception handler
14238 * b) debug exceptions were masked and we just unmasked them
14239 * without changing EL (eg by clearing PSTATE.D)
14240 * In either case we're going to take a swstep exception in the
14241 * "did not step an insn" case, and so the syndrome ISV and EX
14242 * bits should be zero.
14244 assert(dc
->base
.num_insns
== 1);
14245 gen_swstep_exception(dc
, 0, 0);
14246 dc
->base
.is_jmp
= DISAS_NORETURN
;
14248 disas_a64_insn(env
, dc
);
14251 translator_loop_temp_check(&dc
->base
);
14254 static void aarch64_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
14256 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14258 if (unlikely(dc
->base
.singlestep_enabled
|| dc
->ss_active
)) {
14259 /* Note that this means single stepping WFI doesn't halt the CPU.
14260 * For conditional branch insns this is harmless unreachable code as
14261 * gen_goto_tb() has already handled emitting the debug exception
14262 * (and thus a tb-jump is not possible when singlestepping).
14264 switch (dc
->base
.is_jmp
) {
14266 gen_a64_set_pc_im(dc
->base
.pc_next
);
14270 if (dc
->base
.singlestep_enabled
) {
14271 gen_exception_internal(EXCP_DEBUG
);
14273 gen_step_complete_exception(dc
);
14276 case DISAS_NORETURN
:
14280 switch (dc
->base
.is_jmp
) {
14282 case DISAS_TOO_MANY
:
14283 gen_goto_tb(dc
, 1, dc
->base
.pc_next
);
14287 gen_a64_set_pc_im(dc
->base
.pc_next
);
14290 tcg_gen_exit_tb(NULL
, 0);
14293 tcg_gen_lookup_and_goto_ptr();
14295 case DISAS_NORETURN
:
14299 gen_a64_set_pc_im(dc
->base
.pc_next
);
14300 gen_helper_wfe(cpu_env
);
14303 gen_a64_set_pc_im(dc
->base
.pc_next
);
14304 gen_helper_yield(cpu_env
);
14308 /* This is a special case because we don't want to just halt the CPU
14309 * if trying to debug across a WFI.
14311 TCGv_i32 tmp
= tcg_const_i32(4);
14313 gen_a64_set_pc_im(dc
->base
.pc_next
);
14314 gen_helper_wfi(cpu_env
, tmp
);
14315 tcg_temp_free_i32(tmp
);
14316 /* The helper doesn't necessarily throw an exception, but we
14317 * must go back to the main loop to check for interrupts anyway.
14319 tcg_gen_exit_tb(NULL
, 0);
14326 static void aarch64_tr_disas_log(const DisasContextBase
*dcbase
,
14329 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14331 qemu_log("IN: %s\n", lookup_symbol(dc
->base
.pc_first
));
14332 log_target_disas(cpu
, dc
->base
.pc_first
, dc
->base
.tb
->size
);
14335 const TranslatorOps aarch64_translator_ops
= {
14336 .init_disas_context
= aarch64_tr_init_disas_context
,
14337 .tb_start
= aarch64_tr_tb_start
,
14338 .insn_start
= aarch64_tr_insn_start
,
14339 .breakpoint_check
= aarch64_tr_breakpoint_check
,
14340 .translate_insn
= aarch64_tr_translate_insn
,
14341 .tb_stop
= aarch64_tr_tb_stop
,
14342 .disas_log
= aarch64_tr_disas_log
,