4 * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "qemu/osdep.h"
22 #include "exec/exec-all.h"
24 #include "tcg-op-gvec.h"
27 #include "translate.h"
28 #include "internals.h"
29 #include "qemu/host-utils.h"
31 #include "exec/semihost.h"
32 #include "exec/gen-icount.h"
34 #include "exec/helper-proto.h"
35 #include "exec/helper-gen.h"
38 #include "trace-tcg.h"
39 #include "translate-a64.h"
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 aarch64_cpu_dump_state(CPUState
*cs
, FILE *f
,
155 fprintf_function cpu_fprintf
, int flags
)
157 ARMCPU
*cpu
= ARM_CPU(cs
);
158 CPUARMState
*env
= &cpu
->env
;
159 uint32_t psr
= pstate_read(env
);
161 int el
= arm_current_el(env
);
162 const char *ns_status
;
164 cpu_fprintf(f
, " PC=%016" PRIx64
" ", env
->pc
);
165 for (i
= 0; i
< 32; i
++) {
167 cpu_fprintf(f
, " SP=%016" PRIx64
"\n", env
->xregs
[i
]);
169 cpu_fprintf(f
, "X%02d=%016" PRIx64
"%s", i
, env
->xregs
[i
],
170 (i
+ 2) % 3 ? " " : "\n");
174 if (arm_feature(env
, ARM_FEATURE_EL3
) && el
!= 3) {
175 ns_status
= env
->cp15
.scr_el3
& SCR_NS
? "NS " : "S ";
179 cpu_fprintf(f
, "PSTATE=%08x %c%c%c%c %sEL%d%c",
181 psr
& PSTATE_N
? 'N' : '-',
182 psr
& PSTATE_Z
? 'Z' : '-',
183 psr
& PSTATE_C
? 'C' : '-',
184 psr
& PSTATE_V
? 'V' : '-',
187 psr
& PSTATE_SP
? 'h' : 't');
189 if (cpu_isar_feature(aa64_bti
, cpu
)) {
190 cpu_fprintf(f
, " BTYPE=%d", (psr
& PSTATE_BTYPE
) >> 10);
192 if (!(flags
& CPU_DUMP_FPU
)) {
193 cpu_fprintf(f
, "\n");
196 if (fp_exception_el(env
, el
) != 0) {
197 cpu_fprintf(f
, " FPU disabled\n");
200 cpu_fprintf(f
, " FPCR=%08x FPSR=%08x\n",
201 vfp_get_fpcr(env
), vfp_get_fpsr(env
));
203 if (cpu_isar_feature(aa64_sve
, cpu
) && sve_exception_el(env
, el
) == 0) {
204 int j
, zcr_len
= sve_zcr_len_for_el(env
, el
);
206 for (i
= 0; i
<= FFR_PRED_NUM
; i
++) {
208 if (i
== FFR_PRED_NUM
) {
209 cpu_fprintf(f
, "FFR=");
210 /* It's last, so end the line. */
213 cpu_fprintf(f
, "P%02d=", i
);
226 /* More than one quadword per predicate. */
231 for (j
= zcr_len
/ 4; j
>= 0; j
--) {
233 if (j
* 4 + 4 <= zcr_len
+ 1) {
236 digits
= (zcr_len
% 4 + 1) * 4;
238 cpu_fprintf(f
, "%0*" PRIx64
"%s", digits
,
239 env
->vfp
.pregs
[i
].p
[j
],
240 j
? ":" : eol
? "\n" : " ");
244 for (i
= 0; i
< 32; i
++) {
246 cpu_fprintf(f
, "Z%02d=%016" PRIx64
":%016" PRIx64
"%s",
247 i
, env
->vfp
.zregs
[i
].d
[1],
248 env
->vfp
.zregs
[i
].d
[0], i
& 1 ? "\n" : " ");
249 } else if (zcr_len
== 1) {
250 cpu_fprintf(f
, "Z%02d=%016" PRIx64
":%016" PRIx64
251 ":%016" PRIx64
":%016" PRIx64
"\n",
252 i
, env
->vfp
.zregs
[i
].d
[3], env
->vfp
.zregs
[i
].d
[2],
253 env
->vfp
.zregs
[i
].d
[1], env
->vfp
.zregs
[i
].d
[0]);
255 for (j
= zcr_len
; j
>= 0; j
--) {
256 bool odd
= (zcr_len
- j
) % 2 != 0;
258 cpu_fprintf(f
, "Z%02d[%x-%x]=", i
, j
, j
- 1);
261 cpu_fprintf(f
, " [%x-%x]=", j
, j
- 1);
263 cpu_fprintf(f
, " [%x]=", j
);
266 cpu_fprintf(f
, "%016" PRIx64
":%016" PRIx64
"%s",
267 env
->vfp
.zregs
[i
].d
[j
* 2 + 1],
268 env
->vfp
.zregs
[i
].d
[j
* 2],
269 odd
|| j
== 0 ? "\n" : ":");
274 for (i
= 0; i
< 32; i
++) {
275 uint64_t *q
= aa64_vfp_qreg(env
, i
);
276 cpu_fprintf(f
, "Q%02d=%016" PRIx64
":%016" PRIx64
"%s",
277 i
, q
[1], q
[0], (i
& 1 ? "\n" : " "));
282 void gen_a64_set_pc_im(uint64_t val
)
284 tcg_gen_movi_i64(cpu_pc
, val
);
288 * Handle Top Byte Ignore (TBI) bits.
290 * If address tagging is enabled via the TCR TBI bits:
291 * + for EL2 and EL3 there is only one TBI bit, and if it is set
292 * then the address is zero-extended, clearing bits [63:56]
293 * + for EL0 and EL1, TBI0 controls addresses with bit 55 == 0
294 * and TBI1 controls addressses with bit 55 == 1.
295 * If the appropriate TBI bit is set for the address then
296 * the address is sign-extended from bit 55 into bits [63:56]
298 * Here We have concatenated TBI{1,0} into tbi.
300 static void gen_top_byte_ignore(DisasContext
*s
, TCGv_i64 dst
,
301 TCGv_i64 src
, int tbi
)
304 /* Load unmodified address */
305 tcg_gen_mov_i64(dst
, src
);
306 } else if (s
->current_el
>= 2) {
307 /* FIXME: ARMv8.1-VHE S2 translation regime. */
308 /* Force tag byte to all zero */
309 tcg_gen_extract_i64(dst
, src
, 0, 56);
311 /* Sign-extend from bit 55. */
312 tcg_gen_sextract_i64(dst
, src
, 0, 56);
315 TCGv_i64 tcg_zero
= tcg_const_i64(0);
318 * The two TBI bits differ.
319 * If tbi0, then !tbi1: only use the extension if positive.
320 * if !tbi0, then tbi1: only use the extension if negative.
322 tcg_gen_movcond_i64(tbi
== 1 ? TCG_COND_GE
: TCG_COND_LT
,
323 dst
, dst
, tcg_zero
, dst
, src
);
324 tcg_temp_free_i64(tcg_zero
);
329 static void gen_a64_set_pc(DisasContext
*s
, TCGv_i64 src
)
332 * If address tagging is enabled for instructions via the TCR TBI bits,
333 * then loading an address into the PC will clear out any tag.
335 gen_top_byte_ignore(s
, cpu_pc
, src
, s
->tbii
);
339 * Return a "clean" address for ADDR according to TBID.
340 * This is always a fresh temporary, as we need to be able to
341 * increment this independently of a dirty write-back address.
343 static TCGv_i64
clean_data_tbi(DisasContext
*s
, TCGv_i64 addr
)
345 TCGv_i64 clean
= new_tmp_a64(s
);
346 gen_top_byte_ignore(s
, clean
, addr
, s
->tbid
);
350 typedef struct DisasCompare64
{
355 static void a64_test_cc(DisasCompare64
*c64
, int cc
)
359 arm_test_cc(&c32
, cc
);
361 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
362 * properly. The NE/EQ comparisons are also fine with this choice. */
363 c64
->cond
= c32
.cond
;
364 c64
->value
= tcg_temp_new_i64();
365 tcg_gen_ext_i32_i64(c64
->value
, c32
.value
);
370 static void a64_free_cc(DisasCompare64
*c64
)
372 tcg_temp_free_i64(c64
->value
);
375 static void gen_exception_internal(int excp
)
377 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
379 assert(excp_is_internal(excp
));
380 gen_helper_exception_internal(cpu_env
, tcg_excp
);
381 tcg_temp_free_i32(tcg_excp
);
384 static void gen_exception(int excp
, uint32_t syndrome
, uint32_t target_el
)
386 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
387 TCGv_i32 tcg_syn
= tcg_const_i32(syndrome
);
388 TCGv_i32 tcg_el
= tcg_const_i32(target_el
);
390 gen_helper_exception_with_syndrome(cpu_env
, tcg_excp
,
392 tcg_temp_free_i32(tcg_el
);
393 tcg_temp_free_i32(tcg_syn
);
394 tcg_temp_free_i32(tcg_excp
);
397 static void gen_exception_internal_insn(DisasContext
*s
, int offset
, int excp
)
399 gen_a64_set_pc_im(s
->pc
- offset
);
400 gen_exception_internal(excp
);
401 s
->base
.is_jmp
= DISAS_NORETURN
;
404 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
,
405 uint32_t syndrome
, uint32_t target_el
)
407 gen_a64_set_pc_im(s
->pc
- offset
);
408 gen_exception(excp
, syndrome
, target_el
);
409 s
->base
.is_jmp
= DISAS_NORETURN
;
412 static void gen_exception_bkpt_insn(DisasContext
*s
, int offset
,
417 gen_a64_set_pc_im(s
->pc
- offset
);
418 tcg_syn
= tcg_const_i32(syndrome
);
419 gen_helper_exception_bkpt_insn(cpu_env
, tcg_syn
);
420 tcg_temp_free_i32(tcg_syn
);
421 s
->base
.is_jmp
= DISAS_NORETURN
;
424 static void gen_step_complete_exception(DisasContext
*s
)
426 /* We just completed step of an insn. Move from Active-not-pending
427 * to Active-pending, and then also take the swstep exception.
428 * This corresponds to making the (IMPDEF) choice to prioritize
429 * swstep exceptions over asynchronous exceptions taken to an exception
430 * level where debug is disabled. This choice has the advantage that
431 * we do not need to maintain internal state corresponding to the
432 * ISV/EX syndrome bits between completion of the step and generation
433 * of the exception, and our syndrome information is always correct.
436 gen_exception(EXCP_UDEF
, syn_swstep(s
->ss_same_el
, 1, s
->is_ldex
),
437 default_exception_el(s
));
438 s
->base
.is_jmp
= DISAS_NORETURN
;
441 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
443 /* No direct tb linking with singlestep (either QEMU's or the ARM
444 * debug architecture kind) or deterministic io
446 if (s
->base
.singlestep_enabled
|| s
->ss_active
||
447 (tb_cflags(s
->base
.tb
) & CF_LAST_IO
)) {
451 #ifndef CONFIG_USER_ONLY
452 /* Only link tbs from inside the same guest page */
453 if ((s
->base
.tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
461 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
463 TranslationBlock
*tb
;
466 if (use_goto_tb(s
, n
, dest
)) {
468 gen_a64_set_pc_im(dest
);
469 tcg_gen_exit_tb(tb
, n
);
470 s
->base
.is_jmp
= DISAS_NORETURN
;
472 gen_a64_set_pc_im(dest
);
474 gen_step_complete_exception(s
);
475 } else if (s
->base
.singlestep_enabled
) {
476 gen_exception_internal(EXCP_DEBUG
);
478 tcg_gen_lookup_and_goto_ptr();
479 s
->base
.is_jmp
= DISAS_NORETURN
;
484 void unallocated_encoding(DisasContext
*s
)
486 /* Unallocated and reserved encodings are uncategorized */
487 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized(),
488 default_exception_el(s
));
491 static void init_tmp_a64_array(DisasContext
*s
)
493 #ifdef CONFIG_DEBUG_TCG
494 memset(s
->tmp_a64
, 0, sizeof(s
->tmp_a64
));
496 s
->tmp_a64_count
= 0;
499 static void free_tmp_a64(DisasContext
*s
)
502 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
503 tcg_temp_free_i64(s
->tmp_a64
[i
]);
505 init_tmp_a64_array(s
);
508 TCGv_i64
new_tmp_a64(DisasContext
*s
)
510 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
511 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
514 TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
516 TCGv_i64 t
= new_tmp_a64(s
);
517 tcg_gen_movi_i64(t
, 0);
522 * Register access functions
524 * These functions are used for directly accessing a register in where
525 * changes to the final register value are likely to be made. If you
526 * need to use a register for temporary calculation (e.g. index type
527 * operations) use the read_* form.
529 * B1.2.1 Register mappings
531 * In instruction register encoding 31 can refer to ZR (zero register) or
532 * the SP (stack pointer) depending on context. In QEMU's case we map SP
533 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
534 * This is the point of the _sp forms.
536 TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
539 return new_tmp_a64_zero(s
);
545 /* register access for when 31 == SP */
546 TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
551 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
552 * representing the register contents. This TCGv is an auto-freed
553 * temporary so it need not be explicitly freed, and may be modified.
555 TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
557 TCGv_i64 v
= new_tmp_a64(s
);
560 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
562 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
565 tcg_gen_movi_i64(v
, 0);
570 TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
572 TCGv_i64 v
= new_tmp_a64(s
);
574 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
576 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
581 /* Return the offset into CPUARMState of a slice (from
582 * the least significant end) of FP register Qn (ie
584 * (Note that this is not the same mapping as for A32; see cpu.h)
586 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
588 return vec_reg_offset(s
, regno
, 0, size
);
591 /* Offset of the high half of the 128 bit vector Qn */
592 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
594 return vec_reg_offset(s
, regno
, 1, MO_64
);
597 /* Convenience accessors for reading and writing single and double
598 * FP registers. Writing clears the upper parts of the associated
599 * 128 bit vector register, as required by the architecture.
600 * Note that unlike the GP register accessors, the values returned
601 * by the read functions must be manually freed.
603 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
605 TCGv_i64 v
= tcg_temp_new_i64();
607 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
611 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
613 TCGv_i32 v
= tcg_temp_new_i32();
615 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
619 static TCGv_i32
read_fp_hreg(DisasContext
*s
, int reg
)
621 TCGv_i32 v
= tcg_temp_new_i32();
623 tcg_gen_ld16u_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_16
));
627 /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64).
628 * If SVE is not enabled, then there are only 128 bits in the vector.
630 static void clear_vec_high(DisasContext
*s
, bool is_q
, int rd
)
632 unsigned ofs
= fp_reg_offset(s
, rd
, MO_64
);
633 unsigned vsz
= vec_full_reg_size(s
);
636 TCGv_i64 tcg_zero
= tcg_const_i64(0);
637 tcg_gen_st_i64(tcg_zero
, cpu_env
, ofs
+ 8);
638 tcg_temp_free_i64(tcg_zero
);
641 tcg_gen_gvec_dup8i(ofs
+ 16, vsz
- 16, vsz
- 16, 0);
645 void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
647 unsigned ofs
= fp_reg_offset(s
, reg
, MO_64
);
649 tcg_gen_st_i64(v
, cpu_env
, ofs
);
650 clear_vec_high(s
, false, reg
);
653 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
655 TCGv_i64 tmp
= tcg_temp_new_i64();
657 tcg_gen_extu_i32_i64(tmp
, v
);
658 write_fp_dreg(s
, reg
, tmp
);
659 tcg_temp_free_i64(tmp
);
662 TCGv_ptr
get_fpstatus_ptr(bool is_f16
)
664 TCGv_ptr statusptr
= tcg_temp_new_ptr();
667 /* In A64 all instructions (both FP and Neon) use the FPCR; there
668 * is no equivalent of the A32 Neon "standard FPSCR value".
669 * However half-precision operations operate under a different
670 * FZ16 flag and use vfp.fp_status_f16 instead of vfp.fp_status.
673 offset
= offsetof(CPUARMState
, vfp
.fp_status_f16
);
675 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
677 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
681 /* Expand a 2-operand AdvSIMD vector operation using an expander function. */
682 static void gen_gvec_fn2(DisasContext
*s
, bool is_q
, int rd
, int rn
,
683 GVecGen2Fn
*gvec_fn
, int vece
)
685 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
686 is_q
? 16 : 8, vec_full_reg_size(s
));
689 /* Expand a 2-operand + immediate AdvSIMD vector operation using
690 * an expander function.
692 static void gen_gvec_fn2i(DisasContext
*s
, bool is_q
, int rd
, int rn
,
693 int64_t imm
, GVecGen2iFn
*gvec_fn
, int vece
)
695 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
696 imm
, is_q
? 16 : 8, vec_full_reg_size(s
));
699 /* Expand a 3-operand AdvSIMD vector operation using an expander function. */
700 static void gen_gvec_fn3(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
701 GVecGen3Fn
*gvec_fn
, int vece
)
703 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
704 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8, vec_full_reg_size(s
));
707 /* Expand a 2-operand + immediate AdvSIMD vector operation using
710 static void gen_gvec_op2i(DisasContext
*s
, bool is_q
, int rd
,
711 int rn
, int64_t imm
, const GVecGen2i
*gvec_op
)
713 tcg_gen_gvec_2i(vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
714 is_q
? 16 : 8, vec_full_reg_size(s
), imm
, gvec_op
);
717 /* Expand a 3-operand AdvSIMD vector operation using an op descriptor. */
718 static void gen_gvec_op3(DisasContext
*s
, bool is_q
, int rd
,
719 int rn
, int rm
, const GVecGen3
*gvec_op
)
721 tcg_gen_gvec_3(vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
722 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8,
723 vec_full_reg_size(s
), gvec_op
);
726 /* Expand a 3-operand operation using an out-of-line helper. */
727 static void gen_gvec_op3_ool(DisasContext
*s
, bool is_q
, int rd
,
728 int rn
, int rm
, int data
, gen_helper_gvec_3
*fn
)
730 tcg_gen_gvec_3_ool(vec_full_reg_offset(s
, rd
),
731 vec_full_reg_offset(s
, rn
),
732 vec_full_reg_offset(s
, rm
),
733 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
736 /* Expand a 3-operand + env pointer operation using
737 * an out-of-line helper.
739 static void gen_gvec_op3_env(DisasContext
*s
, bool is_q
, int rd
,
740 int rn
, int rm
, gen_helper_gvec_3_ptr
*fn
)
742 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
743 vec_full_reg_offset(s
, rn
),
744 vec_full_reg_offset(s
, rm
), cpu_env
,
745 is_q
? 16 : 8, vec_full_reg_size(s
), 0, fn
);
748 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
749 * an out-of-line helper.
751 static void gen_gvec_op3_fpst(DisasContext
*s
, bool is_q
, int rd
, int rn
,
752 int rm
, bool is_fp16
, int data
,
753 gen_helper_gvec_3_ptr
*fn
)
755 TCGv_ptr fpst
= get_fpstatus_ptr(is_fp16
);
756 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
757 vec_full_reg_offset(s
, rn
),
758 vec_full_reg_offset(s
, rm
), fpst
,
759 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
760 tcg_temp_free_ptr(fpst
);
763 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
764 * than the 32 bit equivalent.
766 static inline void gen_set_NZ64(TCGv_i64 result
)
768 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
769 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
772 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
773 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
776 gen_set_NZ64(result
);
778 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
779 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
781 tcg_gen_movi_i32(cpu_CF
, 0);
782 tcg_gen_movi_i32(cpu_VF
, 0);
785 /* dest = T0 + T1; compute C, N, V and Z flags */
786 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
789 TCGv_i64 result
, flag
, tmp
;
790 result
= tcg_temp_new_i64();
791 flag
= tcg_temp_new_i64();
792 tmp
= tcg_temp_new_i64();
794 tcg_gen_movi_i64(tmp
, 0);
795 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
797 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
799 gen_set_NZ64(result
);
801 tcg_gen_xor_i64(flag
, result
, t0
);
802 tcg_gen_xor_i64(tmp
, t0
, t1
);
803 tcg_gen_andc_i64(flag
, flag
, tmp
);
804 tcg_temp_free_i64(tmp
);
805 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
807 tcg_gen_mov_i64(dest
, result
);
808 tcg_temp_free_i64(result
);
809 tcg_temp_free_i64(flag
);
811 /* 32 bit arithmetic */
812 TCGv_i32 t0_32
= tcg_temp_new_i32();
813 TCGv_i32 t1_32
= tcg_temp_new_i32();
814 TCGv_i32 tmp
= tcg_temp_new_i32();
816 tcg_gen_movi_i32(tmp
, 0);
817 tcg_gen_extrl_i64_i32(t0_32
, t0
);
818 tcg_gen_extrl_i64_i32(t1_32
, t1
);
819 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
820 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
821 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
822 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
823 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
824 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
826 tcg_temp_free_i32(tmp
);
827 tcg_temp_free_i32(t0_32
);
828 tcg_temp_free_i32(t1_32
);
832 /* dest = T0 - T1; compute C, N, V and Z flags */
833 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
836 /* 64 bit arithmetic */
837 TCGv_i64 result
, flag
, tmp
;
839 result
= tcg_temp_new_i64();
840 flag
= tcg_temp_new_i64();
841 tcg_gen_sub_i64(result
, t0
, t1
);
843 gen_set_NZ64(result
);
845 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
846 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
848 tcg_gen_xor_i64(flag
, result
, t0
);
849 tmp
= tcg_temp_new_i64();
850 tcg_gen_xor_i64(tmp
, t0
, t1
);
851 tcg_gen_and_i64(flag
, flag
, tmp
);
852 tcg_temp_free_i64(tmp
);
853 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
854 tcg_gen_mov_i64(dest
, result
);
855 tcg_temp_free_i64(flag
);
856 tcg_temp_free_i64(result
);
858 /* 32 bit arithmetic */
859 TCGv_i32 t0_32
= tcg_temp_new_i32();
860 TCGv_i32 t1_32
= tcg_temp_new_i32();
863 tcg_gen_extrl_i64_i32(t0_32
, t0
);
864 tcg_gen_extrl_i64_i32(t1_32
, t1
);
865 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
866 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
867 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
868 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
869 tmp
= tcg_temp_new_i32();
870 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
871 tcg_temp_free_i32(t0_32
);
872 tcg_temp_free_i32(t1_32
);
873 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
874 tcg_temp_free_i32(tmp
);
875 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
879 /* dest = T0 + T1 + CF; do not compute flags. */
880 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
882 TCGv_i64 flag
= tcg_temp_new_i64();
883 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
884 tcg_gen_add_i64(dest
, t0
, t1
);
885 tcg_gen_add_i64(dest
, dest
, flag
);
886 tcg_temp_free_i64(flag
);
889 tcg_gen_ext32u_i64(dest
, dest
);
893 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
894 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
897 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
898 result
= tcg_temp_new_i64();
899 cf_64
= tcg_temp_new_i64();
900 vf_64
= tcg_temp_new_i64();
901 tmp
= tcg_const_i64(0);
903 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
904 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
905 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
906 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
907 gen_set_NZ64(result
);
909 tcg_gen_xor_i64(vf_64
, result
, t0
);
910 tcg_gen_xor_i64(tmp
, t0
, t1
);
911 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
912 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
914 tcg_gen_mov_i64(dest
, result
);
916 tcg_temp_free_i64(tmp
);
917 tcg_temp_free_i64(vf_64
);
918 tcg_temp_free_i64(cf_64
);
919 tcg_temp_free_i64(result
);
921 TCGv_i32 t0_32
, t1_32
, tmp
;
922 t0_32
= tcg_temp_new_i32();
923 t1_32
= tcg_temp_new_i32();
924 tmp
= tcg_const_i32(0);
926 tcg_gen_extrl_i64_i32(t0_32
, t0
);
927 tcg_gen_extrl_i64_i32(t1_32
, t1
);
928 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
929 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
931 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
932 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
933 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
934 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
935 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
937 tcg_temp_free_i32(tmp
);
938 tcg_temp_free_i32(t1_32
);
939 tcg_temp_free_i32(t0_32
);
944 * Load/Store generators
948 * Store from GPR register to memory.
950 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
951 TCGv_i64 tcg_addr
, int size
, int memidx
,
953 unsigned int iss_srt
,
954 bool iss_sf
, bool iss_ar
)
957 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, s
->be_data
+ size
);
962 syn
= syn_data_abort_with_iss(0,
968 0, 0, 0, 0, 0, false);
969 disas_set_insn_syndrome(s
, syn
);
973 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
974 TCGv_i64 tcg_addr
, int size
,
976 unsigned int iss_srt
,
977 bool iss_sf
, bool iss_ar
)
979 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
),
980 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
984 * Load from memory to GPR register
986 static void do_gpr_ld_memidx(DisasContext
*s
,
987 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
988 int size
, bool is_signed
,
989 bool extend
, int memidx
,
990 bool iss_valid
, unsigned int iss_srt
,
991 bool iss_sf
, bool iss_ar
)
993 TCGMemOp memop
= s
->be_data
+ size
;
1001 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
1003 if (extend
&& is_signed
) {
1005 tcg_gen_ext32u_i64(dest
, dest
);
1011 syn
= syn_data_abort_with_iss(0,
1017 0, 0, 0, 0, 0, false);
1018 disas_set_insn_syndrome(s
, syn
);
1022 static void do_gpr_ld(DisasContext
*s
,
1023 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
1024 int size
, bool is_signed
, bool extend
,
1025 bool iss_valid
, unsigned int iss_srt
,
1026 bool iss_sf
, bool iss_ar
)
1028 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
1030 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
1034 * Store from FP register to memory
1036 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
1038 /* This writes the bottom N bits of a 128 bit wide vector to memory */
1039 TCGv_i64 tmp
= tcg_temp_new_i64();
1040 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
1042 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
),
1045 bool be
= s
->be_data
== MO_BE
;
1046 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
1048 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
1049 tcg_gen_qemu_st_i64(tmp
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
1051 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
1052 tcg_gen_qemu_st_i64(tmp
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
1054 tcg_temp_free_i64(tcg_hiaddr
);
1057 tcg_temp_free_i64(tmp
);
1061 * Load from memory to FP register
1063 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
1065 /* This always zero-extends and writes to a full 128 bit wide vector */
1066 TCGv_i64 tmplo
= tcg_temp_new_i64();
1070 TCGMemOp memop
= s
->be_data
+ size
;
1071 tmphi
= tcg_const_i64(0);
1072 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
1074 bool be
= s
->be_data
== MO_BE
;
1075 TCGv_i64 tcg_hiaddr
;
1077 tmphi
= tcg_temp_new_i64();
1078 tcg_hiaddr
= tcg_temp_new_i64();
1080 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
1081 tcg_gen_qemu_ld_i64(tmplo
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
1083 tcg_gen_qemu_ld_i64(tmphi
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
1085 tcg_temp_free_i64(tcg_hiaddr
);
1088 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
1089 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
1091 tcg_temp_free_i64(tmplo
);
1092 tcg_temp_free_i64(tmphi
);
1094 clear_vec_high(s
, true, destidx
);
1098 * Vector load/store helpers.
1100 * The principal difference between this and a FP load is that we don't
1101 * zero extend as we are filling a partial chunk of the vector register.
1102 * These functions don't support 128 bit loads/stores, which would be
1103 * normal load/store operations.
1105 * The _i32 versions are useful when operating on 32 bit quantities
1106 * (eg for floating point single or using Neon helper functions).
1109 /* Get value of an element within a vector register */
1110 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
1111 int element
, TCGMemOp memop
)
1113 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1116 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
1119 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
1122 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
1125 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
1128 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
1131 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
1135 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
1138 g_assert_not_reached();
1142 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
1143 int element
, TCGMemOp memop
)
1145 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1148 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
1151 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
1154 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
1157 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
1161 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
1164 g_assert_not_reached();
1168 /* Set value of an element within a vector register */
1169 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
1170 int element
, TCGMemOp memop
)
1172 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1175 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
1178 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
1181 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
1184 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
1187 g_assert_not_reached();
1191 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
1192 int destidx
, int element
, TCGMemOp memop
)
1194 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1197 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
1200 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
1203 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
1206 g_assert_not_reached();
1210 /* Store from vector register to memory */
1211 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
1212 TCGv_i64 tcg_addr
, int size
, TCGMemOp endian
)
1214 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1216 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
1217 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), endian
| size
);
1219 tcg_temp_free_i64(tcg_tmp
);
1222 /* Load from memory to vector register */
1223 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
1224 TCGv_i64 tcg_addr
, int size
, TCGMemOp endian
)
1226 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1228 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), endian
| size
);
1229 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
1231 tcg_temp_free_i64(tcg_tmp
);
1234 /* Check that FP/Neon access is enabled. If it is, return
1235 * true. If not, emit code to generate an appropriate exception,
1236 * and return false; the caller should not emit any code for
1237 * the instruction. Note that this check must happen after all
1238 * unallocated-encoding checks (otherwise the syndrome information
1239 * for the resulting exception will be incorrect).
1241 static inline bool fp_access_check(DisasContext
*s
)
1243 assert(!s
->fp_access_checked
);
1244 s
->fp_access_checked
= true;
1246 if (!s
->fp_excp_el
) {
1250 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false),
1255 /* Check that SVE access is enabled. If it is, return true.
1256 * If not, emit code to generate an appropriate exception and return false.
1258 bool sve_access_check(DisasContext
*s
)
1260 if (s
->sve_excp_el
) {
1261 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_sve_access_trap(),
1265 return fp_access_check(s
);
1269 * This utility function is for doing register extension with an
1270 * optional shift. You will likely want to pass a temporary for the
1271 * destination register. See DecodeRegExtend() in the ARM ARM.
1273 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1274 int option
, unsigned int shift
)
1276 int extsize
= extract32(option
, 0, 2);
1277 bool is_signed
= extract32(option
, 2, 1);
1282 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1285 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1288 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1291 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1297 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1300 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1303 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1306 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1312 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1316 static inline void gen_check_sp_alignment(DisasContext
*s
)
1318 /* The AArch64 architecture mandates that (if enabled via PSTATE
1319 * or SCTLR bits) there is a check that SP is 16-aligned on every
1320 * SP-relative load or store (with an exception generated if it is not).
1321 * In line with general QEMU practice regarding misaligned accesses,
1322 * we omit these checks for the sake of guest program performance.
1323 * This function is provided as a hook so we can more easily add these
1324 * checks in future (possibly as a "favour catching guest program bugs
1325 * over speed" user selectable option).
1330 * This provides a simple table based table lookup decoder. It is
1331 * intended to be used when the relevant bits for decode are too
1332 * awkwardly placed and switch/if based logic would be confusing and
1333 * deeply nested. Since it's a linear search through the table, tables
1334 * should be kept small.
1336 * It returns the first handler where insn & mask == pattern, or
1337 * NULL if there is no match.
1338 * The table is terminated by an empty mask (i.e. 0)
1340 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1343 const AArch64DecodeTable
*tptr
= table
;
1345 while (tptr
->mask
) {
1346 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1347 return tptr
->disas_fn
;
1355 * The instruction disassembly implemented here matches
1356 * the instruction encoding classifications in chapter C4
1357 * of the ARM Architecture Reference Manual (DDI0487B_a);
1358 * classification names and decode diagrams here should generally
1359 * match up with those in the manual.
1362 /* Unconditional branch (immediate)
1364 * +----+-----------+-------------------------------------+
1365 * | op | 0 0 1 0 1 | imm26 |
1366 * +----+-----------+-------------------------------------+
1368 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1370 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1372 if (insn
& (1U << 31)) {
1373 /* BL Branch with link */
1374 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1377 /* B Branch / BL Branch with link */
1379 gen_goto_tb(s
, 0, addr
);
1382 /* Compare and branch (immediate)
1383 * 31 30 25 24 23 5 4 0
1384 * +----+-------------+----+---------------------+--------+
1385 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1386 * +----+-------------+----+---------------------+--------+
1388 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1390 unsigned int sf
, op
, rt
;
1392 TCGLabel
*label_match
;
1395 sf
= extract32(insn
, 31, 1);
1396 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1397 rt
= extract32(insn
, 0, 5);
1398 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1400 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1401 label_match
= gen_new_label();
1404 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1405 tcg_cmp
, 0, label_match
);
1407 gen_goto_tb(s
, 0, s
->pc
);
1408 gen_set_label(label_match
);
1409 gen_goto_tb(s
, 1, addr
);
1412 /* Test and branch (immediate)
1413 * 31 30 25 24 23 19 18 5 4 0
1414 * +----+-------------+----+-------+-------------+------+
1415 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1416 * +----+-------------+----+-------+-------------+------+
1418 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1420 unsigned int bit_pos
, op
, rt
;
1422 TCGLabel
*label_match
;
1425 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1426 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1427 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1428 rt
= extract32(insn
, 0, 5);
1430 tcg_cmp
= tcg_temp_new_i64();
1431 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1432 label_match
= gen_new_label();
1435 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1436 tcg_cmp
, 0, label_match
);
1437 tcg_temp_free_i64(tcg_cmp
);
1438 gen_goto_tb(s
, 0, s
->pc
);
1439 gen_set_label(label_match
);
1440 gen_goto_tb(s
, 1, addr
);
1443 /* Conditional branch (immediate)
1444 * 31 25 24 23 5 4 3 0
1445 * +---------------+----+---------------------+----+------+
1446 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1447 * +---------------+----+---------------------+----+------+
1449 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1454 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1455 unallocated_encoding(s
);
1458 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1459 cond
= extract32(insn
, 0, 4);
1463 /* genuinely conditional branches */
1464 TCGLabel
*label_match
= gen_new_label();
1465 arm_gen_test_cc(cond
, label_match
);
1466 gen_goto_tb(s
, 0, s
->pc
);
1467 gen_set_label(label_match
);
1468 gen_goto_tb(s
, 1, addr
);
1470 /* 0xe and 0xf are both "always" conditions */
1471 gen_goto_tb(s
, 0, addr
);
1475 /* HINT instruction group, including various allocated HINTs */
1476 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1477 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1479 unsigned int selector
= crm
<< 3 | op2
;
1482 unallocated_encoding(s
);
1487 case 0b00000: /* NOP */
1489 case 0b00011: /* WFI */
1490 s
->base
.is_jmp
= DISAS_WFI
;
1492 case 0b00001: /* YIELD */
1493 /* When running in MTTCG we don't generate jumps to the yield and
1494 * WFE helpers as it won't affect the scheduling of other vCPUs.
1495 * If we wanted to more completely model WFE/SEV so we don't busy
1496 * spin unnecessarily we would need to do something more involved.
1498 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1499 s
->base
.is_jmp
= DISAS_YIELD
;
1502 case 0b00010: /* WFE */
1503 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1504 s
->base
.is_jmp
= DISAS_WFE
;
1507 case 0b00100: /* SEV */
1508 case 0b00101: /* SEVL */
1509 /* we treat all as NOP at least for now */
1511 case 0b00111: /* XPACLRI */
1512 if (s
->pauth_active
) {
1513 gen_helper_xpaci(cpu_X
[30], cpu_env
, cpu_X
[30]);
1516 case 0b01000: /* PACIA1716 */
1517 if (s
->pauth_active
) {
1518 gen_helper_pacia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1521 case 0b01010: /* PACIB1716 */
1522 if (s
->pauth_active
) {
1523 gen_helper_pacib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1526 case 0b01100: /* AUTIA1716 */
1527 if (s
->pauth_active
) {
1528 gen_helper_autia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1531 case 0b01110: /* AUTIB1716 */
1532 if (s
->pauth_active
) {
1533 gen_helper_autib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1536 case 0b11000: /* PACIAZ */
1537 if (s
->pauth_active
) {
1538 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30],
1539 new_tmp_a64_zero(s
));
1542 case 0b11001: /* PACIASP */
1543 if (s
->pauth_active
) {
1544 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1547 case 0b11010: /* PACIBZ */
1548 if (s
->pauth_active
) {
1549 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30],
1550 new_tmp_a64_zero(s
));
1553 case 0b11011: /* PACIBSP */
1554 if (s
->pauth_active
) {
1555 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1558 case 0b11100: /* AUTIAZ */
1559 if (s
->pauth_active
) {
1560 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30],
1561 new_tmp_a64_zero(s
));
1564 case 0b11101: /* AUTIASP */
1565 if (s
->pauth_active
) {
1566 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1569 case 0b11110: /* AUTIBZ */
1570 if (s
->pauth_active
) {
1571 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30],
1572 new_tmp_a64_zero(s
));
1575 case 0b11111: /* AUTIBSP */
1576 if (s
->pauth_active
) {
1577 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1581 /* default specified as NOP equivalent */
1586 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1588 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1591 /* CLREX, DSB, DMB, ISB */
1592 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1593 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1598 unallocated_encoding(s
);
1609 case 1: /* MBReqTypes_Reads */
1610 bar
= TCG_BAR_SC
| TCG_MO_LD_LD
| TCG_MO_LD_ST
;
1612 case 2: /* MBReqTypes_Writes */
1613 bar
= TCG_BAR_SC
| TCG_MO_ST_ST
;
1615 default: /* MBReqTypes_All */
1616 bar
= TCG_BAR_SC
| TCG_MO_ALL
;
1622 /* We need to break the TB after this insn to execute
1623 * a self-modified code correctly and also to take
1624 * any pending interrupts immediately.
1627 gen_goto_tb(s
, 0, s
->pc
);
1631 if (crm
!= 0 || !dc_isar_feature(aa64_sb
, s
)) {
1632 goto do_unallocated
;
1635 * TODO: There is no speculation barrier opcode for TCG;
1636 * MB and end the TB instead.
1638 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
1639 gen_goto_tb(s
, 0, s
->pc
);
1644 unallocated_encoding(s
);
1649 /* MSR (immediate) - move immediate to processor state field */
1650 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1651 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1654 int op
= op1
<< 3 | op2
;
1656 /* End the TB by default, chaining is ok. */
1657 s
->base
.is_jmp
= DISAS_TOO_MANY
;
1660 case 0x00: /* CFINV */
1661 if (crm
!= 0 || !dc_isar_feature(aa64_condm_4
, s
)) {
1662 goto do_unallocated
;
1664 tcg_gen_xori_i32(cpu_CF
, cpu_CF
, 1);
1665 s
->base
.is_jmp
= DISAS_NEXT
;
1668 case 0x05: /* SPSel */
1669 if (s
->current_el
== 0) {
1670 goto do_unallocated
;
1672 t1
= tcg_const_i32(crm
& PSTATE_SP
);
1673 gen_helper_msr_i_spsel(cpu_env
, t1
);
1674 tcg_temp_free_i32(t1
);
1677 case 0x1e: /* DAIFSet */
1678 t1
= tcg_const_i32(crm
);
1679 gen_helper_msr_i_daifset(cpu_env
, t1
);
1680 tcg_temp_free_i32(t1
);
1683 case 0x1f: /* DAIFClear */
1684 t1
= tcg_const_i32(crm
);
1685 gen_helper_msr_i_daifclear(cpu_env
, t1
);
1686 tcg_temp_free_i32(t1
);
1687 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1688 s
->base
.is_jmp
= DISAS_UPDATE
;
1693 unallocated_encoding(s
);
1698 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1700 TCGv_i32 tmp
= tcg_temp_new_i32();
1701 TCGv_i32 nzcv
= tcg_temp_new_i32();
1703 /* build bit 31, N */
1704 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1705 /* build bit 30, Z */
1706 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1707 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1708 /* build bit 29, C */
1709 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1710 /* build bit 28, V */
1711 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1712 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1713 /* generate result */
1714 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1716 tcg_temp_free_i32(nzcv
);
1717 tcg_temp_free_i32(tmp
);
1720 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1722 TCGv_i32 nzcv
= tcg_temp_new_i32();
1724 /* take NZCV from R[t] */
1725 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1728 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1730 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1731 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1733 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1734 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1736 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1737 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1738 tcg_temp_free_i32(nzcv
);
1741 /* MRS - move from system register
1742 * MSR (register) - move to system register
1745 * These are all essentially the same insn in 'read' and 'write'
1746 * versions, with varying op0 fields.
1748 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1749 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1750 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1752 const ARMCPRegInfo
*ri
;
1755 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1756 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1757 crn
, crm
, op0
, op1
, op2
));
1760 /* Unknown register; this might be a guest error or a QEMU
1761 * unimplemented feature.
1763 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1764 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1765 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1766 unallocated_encoding(s
);
1770 /* Check access permissions */
1771 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1772 unallocated_encoding(s
);
1777 /* Emit code to perform further access permissions checks at
1778 * runtime; this may result in an exception.
1781 TCGv_i32 tcg_syn
, tcg_isread
;
1784 gen_a64_set_pc_im(s
->pc
- 4);
1785 tmpptr
= tcg_const_ptr(ri
);
1786 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1787 tcg_syn
= tcg_const_i32(syndrome
);
1788 tcg_isread
= tcg_const_i32(isread
);
1789 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
, tcg_isread
);
1790 tcg_temp_free_ptr(tmpptr
);
1791 tcg_temp_free_i32(tcg_syn
);
1792 tcg_temp_free_i32(tcg_isread
);
1795 /* Handle special cases first */
1796 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1800 tcg_rt
= cpu_reg(s
, rt
);
1802 gen_get_nzcv(tcg_rt
);
1804 gen_set_nzcv(tcg_rt
);
1807 case ARM_CP_CURRENTEL
:
1808 /* Reads as current EL value from pstate, which is
1809 * guaranteed to be constant by the tb flags.
1811 tcg_rt
= cpu_reg(s
, rt
);
1812 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1815 /* Writes clear the aligned block of memory which rt points into. */
1816 tcg_rt
= cpu_reg(s
, rt
);
1817 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1822 if ((ri
->type
& ARM_CP_FPU
) && !fp_access_check(s
)) {
1824 } else if ((ri
->type
& ARM_CP_SVE
) && !sve_access_check(s
)) {
1828 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1832 tcg_rt
= cpu_reg(s
, rt
);
1835 if (ri
->type
& ARM_CP_CONST
) {
1836 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1837 } else if (ri
->readfn
) {
1839 tmpptr
= tcg_const_ptr(ri
);
1840 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1841 tcg_temp_free_ptr(tmpptr
);
1843 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1846 if (ri
->type
& ARM_CP_CONST
) {
1847 /* If not forbidden by access permissions, treat as WI */
1849 } else if (ri
->writefn
) {
1851 tmpptr
= tcg_const_ptr(ri
);
1852 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1853 tcg_temp_free_ptr(tmpptr
);
1855 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1859 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1860 /* I/O operations must end the TB here (whether read or write) */
1862 s
->base
.is_jmp
= DISAS_UPDATE
;
1863 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1864 /* We default to ending the TB on a coprocessor register write,
1865 * but allow this to be suppressed by the register definition
1866 * (usually only necessary to work around guest bugs).
1868 s
->base
.is_jmp
= DISAS_UPDATE
;
1873 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1874 * +---------------------+---+-----+-----+-------+-------+-----+------+
1875 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1876 * +---------------------+---+-----+-----+-------+-------+-----+------+
1878 static void disas_system(DisasContext
*s
, uint32_t insn
)
1880 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1881 l
= extract32(insn
, 21, 1);
1882 op0
= extract32(insn
, 19, 2);
1883 op1
= extract32(insn
, 16, 3);
1884 crn
= extract32(insn
, 12, 4);
1885 crm
= extract32(insn
, 8, 4);
1886 op2
= extract32(insn
, 5, 3);
1887 rt
= extract32(insn
, 0, 5);
1890 if (l
|| rt
!= 31) {
1891 unallocated_encoding(s
);
1895 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
1896 handle_hint(s
, insn
, op1
, op2
, crm
);
1898 case 3: /* CLREX, DSB, DMB, ISB */
1899 handle_sync(s
, insn
, op1
, op2
, crm
);
1901 case 4: /* MSR (immediate) */
1902 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1905 unallocated_encoding(s
);
1910 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1913 /* Exception generation
1915 * 31 24 23 21 20 5 4 2 1 0
1916 * +-----------------+-----+------------------------+-----+----+
1917 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1918 * +-----------------------+------------------------+----------+
1920 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1922 int opc
= extract32(insn
, 21, 3);
1923 int op2_ll
= extract32(insn
, 0, 5);
1924 int imm16
= extract32(insn
, 5, 16);
1929 /* For SVC, HVC and SMC we advance the single-step state
1930 * machine before taking the exception. This is architecturally
1931 * mandated, to ensure that single-stepping a system call
1932 * instruction works properly.
1937 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
),
1938 default_exception_el(s
));
1941 if (s
->current_el
== 0) {
1942 unallocated_encoding(s
);
1945 /* The pre HVC helper handles cases when HVC gets trapped
1946 * as an undefined insn by runtime configuration.
1948 gen_a64_set_pc_im(s
->pc
- 4);
1949 gen_helper_pre_hvc(cpu_env
);
1951 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
), 2);
1954 if (s
->current_el
== 0) {
1955 unallocated_encoding(s
);
1958 gen_a64_set_pc_im(s
->pc
- 4);
1959 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1960 gen_helper_pre_smc(cpu_env
, tmp
);
1961 tcg_temp_free_i32(tmp
);
1963 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
), 3);
1966 unallocated_encoding(s
);
1972 unallocated_encoding(s
);
1976 gen_exception_bkpt_insn(s
, 4, syn_aa64_bkpt(imm16
));
1980 unallocated_encoding(s
);
1983 /* HLT. This has two purposes.
1984 * Architecturally, it is an external halting debug instruction.
1985 * Since QEMU doesn't implement external debug, we treat this as
1986 * it is required for halting debug disabled: it will UNDEF.
1987 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1989 if (semihosting_enabled() && imm16
== 0xf000) {
1990 #ifndef CONFIG_USER_ONLY
1991 /* In system mode, don't allow userspace access to semihosting,
1992 * to provide some semblance of security (and for consistency
1993 * with our 32-bit semihosting).
1995 if (s
->current_el
== 0) {
1996 unsupported_encoding(s
, insn
);
2000 gen_exception_internal_insn(s
, 0, EXCP_SEMIHOST
);
2002 unsupported_encoding(s
, insn
);
2006 if (op2_ll
< 1 || op2_ll
> 3) {
2007 unallocated_encoding(s
);
2010 /* DCPS1, DCPS2, DCPS3 */
2011 unsupported_encoding(s
, insn
);
2014 unallocated_encoding(s
);
2019 /* Unconditional branch (register)
2020 * 31 25 24 21 20 16 15 10 9 5 4 0
2021 * +---------------+-------+-------+-------+------+-------+
2022 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
2023 * +---------------+-------+-------+-------+------+-------+
2025 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
2027 unsigned int opc
, op2
, op3
, rn
, op4
;
2028 unsigned btype_mod
= 2; /* 0: BR, 1: BLR, 2: other */
2032 opc
= extract32(insn
, 21, 4);
2033 op2
= extract32(insn
, 16, 5);
2034 op3
= extract32(insn
, 10, 6);
2035 rn
= extract32(insn
, 5, 5);
2036 op4
= extract32(insn
, 0, 5);
2039 goto do_unallocated
;
2051 goto do_unallocated
;
2053 dst
= cpu_reg(s
, rn
);
2058 if (!dc_isar_feature(aa64_pauth
, s
)) {
2059 goto do_unallocated
;
2063 if (rn
!= 0x1f || op4
!= 0x1f) {
2064 goto do_unallocated
;
2067 modifier
= cpu_X
[31];
2069 /* BRAAZ, BRABZ, BLRAAZ, BLRABZ */
2071 goto do_unallocated
;
2073 modifier
= new_tmp_a64_zero(s
);
2075 if (s
->pauth_active
) {
2076 dst
= new_tmp_a64(s
);
2078 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2080 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2083 dst
= cpu_reg(s
, rn
);
2088 goto do_unallocated
;
2090 gen_a64_set_pc(s
, dst
);
2091 /* BLR also needs to load return address */
2093 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
2099 if (!dc_isar_feature(aa64_pauth
, s
)) {
2100 goto do_unallocated
;
2102 if ((op3
& ~1) != 2) {
2103 goto do_unallocated
;
2105 btype_mod
= opc
& 1;
2106 if (s
->pauth_active
) {
2107 dst
= new_tmp_a64(s
);
2108 modifier
= cpu_reg_sp(s
, op4
);
2110 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2112 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2115 dst
= cpu_reg(s
, rn
);
2117 gen_a64_set_pc(s
, dst
);
2118 /* BLRAA also needs to load return address */
2120 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
2125 if (s
->current_el
== 0) {
2126 goto do_unallocated
;
2131 goto do_unallocated
;
2133 dst
= tcg_temp_new_i64();
2134 tcg_gen_ld_i64(dst
, cpu_env
,
2135 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2138 case 2: /* ERETAA */
2139 case 3: /* ERETAB */
2140 if (!dc_isar_feature(aa64_pauth
, s
)) {
2141 goto do_unallocated
;
2143 if (rn
!= 0x1f || op4
!= 0x1f) {
2144 goto do_unallocated
;
2146 dst
= tcg_temp_new_i64();
2147 tcg_gen_ld_i64(dst
, cpu_env
,
2148 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2149 if (s
->pauth_active
) {
2150 modifier
= cpu_X
[31];
2152 gen_helper_autia(dst
, cpu_env
, dst
, modifier
);
2154 gen_helper_autib(dst
, cpu_env
, dst
, modifier
);
2160 goto do_unallocated
;
2162 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
2166 gen_helper_exception_return(cpu_env
, dst
);
2167 tcg_temp_free_i64(dst
);
2168 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
2171 /* Must exit loop to check un-masked IRQs */
2172 s
->base
.is_jmp
= DISAS_EXIT
;
2176 if (op3
!= 0 || op4
!= 0 || rn
!= 0x1f) {
2177 goto do_unallocated
;
2179 unsupported_encoding(s
, insn
);
2185 unallocated_encoding(s
);
2189 switch (btype_mod
) {
2191 if (dc_isar_feature(aa64_bti
, s
)) {
2192 /* BR to {x16,x17} or !guard -> 1, else 3. */
2193 set_btype(s
, rn
== 16 || rn
== 17 || !s
->guarded_page
? 1 : 3);
2198 if (dc_isar_feature(aa64_bti
, s
)) {
2199 /* BLR sets BTYPE to 2, regardless of source guarded page. */
2204 default: /* RET or none of the above. */
2205 /* BTYPE will be set to 0 by normal end-of-insn processing. */
2209 s
->base
.is_jmp
= DISAS_JUMP
;
2212 /* Branches, exception generating and system instructions */
2213 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
2215 switch (extract32(insn
, 25, 7)) {
2216 case 0x0a: case 0x0b:
2217 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
2218 disas_uncond_b_imm(s
, insn
);
2220 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
2221 disas_comp_b_imm(s
, insn
);
2223 case 0x1b: case 0x5b: /* Test & branch (immediate) */
2224 disas_test_b_imm(s
, insn
);
2226 case 0x2a: /* Conditional branch (immediate) */
2227 disas_cond_b_imm(s
, insn
);
2229 case 0x6a: /* Exception generation / System */
2230 if (insn
& (1 << 24)) {
2231 if (extract32(insn
, 22, 2) == 0) {
2232 disas_system(s
, insn
);
2234 unallocated_encoding(s
);
2240 case 0x6b: /* Unconditional branch (register) */
2241 disas_uncond_b_reg(s
, insn
);
2244 unallocated_encoding(s
);
2250 * Load/Store exclusive instructions are implemented by remembering
2251 * the value/address loaded, and seeing if these are the same
2252 * when the store is performed. This is not actually the architecturally
2253 * mandated semantics, but it works for typical guest code sequences
2254 * and avoids having to monitor regular stores.
2256 * The store exclusive uses the atomic cmpxchg primitives to avoid
2257 * races in multi-threaded linux-user and when MTTCG softmmu is
2260 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
2261 TCGv_i64 addr
, int size
, bool is_pair
)
2263 int idx
= get_mem_index(s
);
2264 TCGMemOp memop
= s
->be_data
;
2266 g_assert(size
<= 3);
2268 g_assert(size
>= 2);
2270 /* The pair must be single-copy atomic for the doubleword. */
2271 memop
|= MO_64
| MO_ALIGN
;
2272 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2273 if (s
->be_data
== MO_LE
) {
2274 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 0, 32);
2275 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 32, 32);
2277 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 32, 32);
2278 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 0, 32);
2281 /* The pair must be single-copy atomic for *each* doubleword, not
2282 the entire quadword, however it must be quadword aligned. */
2284 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
,
2285 memop
| MO_ALIGN_16
);
2287 TCGv_i64 addr2
= tcg_temp_new_i64();
2288 tcg_gen_addi_i64(addr2
, addr
, 8);
2289 tcg_gen_qemu_ld_i64(cpu_exclusive_high
, addr2
, idx
, memop
);
2290 tcg_temp_free_i64(addr2
);
2292 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2293 tcg_gen_mov_i64(cpu_reg(s
, rt2
), cpu_exclusive_high
);
2296 memop
|= size
| MO_ALIGN
;
2297 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2298 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2300 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
2303 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
2304 TCGv_i64 addr
, int size
, int is_pair
)
2306 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
2307 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
2310 * [addr + datasize] = {Rt2};
2316 * env->exclusive_addr = -1;
2318 TCGLabel
*fail_label
= gen_new_label();
2319 TCGLabel
*done_label
= gen_new_label();
2322 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
2324 tmp
= tcg_temp_new_i64();
2327 if (s
->be_data
== MO_LE
) {
2328 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2330 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt2
), cpu_reg(s
, rt
));
2332 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
,
2333 cpu_exclusive_val
, tmp
,
2335 MO_64
| MO_ALIGN
| s
->be_data
);
2336 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2337 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2338 if (!HAVE_CMPXCHG128
) {
2339 gen_helper_exit_atomic(cpu_env
);
2340 s
->base
.is_jmp
= DISAS_NORETURN
;
2341 } else if (s
->be_data
== MO_LE
) {
2342 gen_helper_paired_cmpxchg64_le_parallel(tmp
, cpu_env
,
2347 gen_helper_paired_cmpxchg64_be_parallel(tmp
, cpu_env
,
2352 } else if (s
->be_data
== MO_LE
) {
2353 gen_helper_paired_cmpxchg64_le(tmp
, cpu_env
, cpu_exclusive_addr
,
2354 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2356 gen_helper_paired_cmpxchg64_be(tmp
, cpu_env
, cpu_exclusive_addr
,
2357 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2360 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
, cpu_exclusive_val
,
2361 cpu_reg(s
, rt
), get_mem_index(s
),
2362 size
| MO_ALIGN
| s
->be_data
);
2363 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2365 tcg_gen_mov_i64(cpu_reg(s
, rd
), tmp
);
2366 tcg_temp_free_i64(tmp
);
2367 tcg_gen_br(done_label
);
2369 gen_set_label(fail_label
);
2370 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
2371 gen_set_label(done_label
);
2372 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
2375 static void gen_compare_and_swap(DisasContext
*s
, int rs
, int rt
,
2378 TCGv_i64 tcg_rs
= cpu_reg(s
, rs
);
2379 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2380 int memidx
= get_mem_index(s
);
2381 TCGv_i64 clean_addr
;
2384 gen_check_sp_alignment(s
);
2386 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2387 tcg_gen_atomic_cmpxchg_i64(tcg_rs
, clean_addr
, tcg_rs
, tcg_rt
, memidx
,
2388 size
| MO_ALIGN
| s
->be_data
);
2391 static void gen_compare_and_swap_pair(DisasContext
*s
, int rs
, int rt
,
2394 TCGv_i64 s1
= cpu_reg(s
, rs
);
2395 TCGv_i64 s2
= cpu_reg(s
, rs
+ 1);
2396 TCGv_i64 t1
= cpu_reg(s
, rt
);
2397 TCGv_i64 t2
= cpu_reg(s
, rt
+ 1);
2398 TCGv_i64 clean_addr
;
2399 int memidx
= get_mem_index(s
);
2402 gen_check_sp_alignment(s
);
2404 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2407 TCGv_i64 cmp
= tcg_temp_new_i64();
2408 TCGv_i64 val
= tcg_temp_new_i64();
2410 if (s
->be_data
== MO_LE
) {
2411 tcg_gen_concat32_i64(val
, t1
, t2
);
2412 tcg_gen_concat32_i64(cmp
, s1
, s2
);
2414 tcg_gen_concat32_i64(val
, t2
, t1
);
2415 tcg_gen_concat32_i64(cmp
, s2
, s1
);
2418 tcg_gen_atomic_cmpxchg_i64(cmp
, clean_addr
, cmp
, val
, memidx
,
2419 MO_64
| MO_ALIGN
| s
->be_data
);
2420 tcg_temp_free_i64(val
);
2422 if (s
->be_data
== MO_LE
) {
2423 tcg_gen_extr32_i64(s1
, s2
, cmp
);
2425 tcg_gen_extr32_i64(s2
, s1
, cmp
);
2427 tcg_temp_free_i64(cmp
);
2428 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2429 if (HAVE_CMPXCHG128
) {
2430 TCGv_i32 tcg_rs
= tcg_const_i32(rs
);
2431 if (s
->be_data
== MO_LE
) {
2432 gen_helper_casp_le_parallel(cpu_env
, tcg_rs
,
2433 clean_addr
, t1
, t2
);
2435 gen_helper_casp_be_parallel(cpu_env
, tcg_rs
,
2436 clean_addr
, t1
, t2
);
2438 tcg_temp_free_i32(tcg_rs
);
2440 gen_helper_exit_atomic(cpu_env
);
2441 s
->base
.is_jmp
= DISAS_NORETURN
;
2444 TCGv_i64 d1
= tcg_temp_new_i64();
2445 TCGv_i64 d2
= tcg_temp_new_i64();
2446 TCGv_i64 a2
= tcg_temp_new_i64();
2447 TCGv_i64 c1
= tcg_temp_new_i64();
2448 TCGv_i64 c2
= tcg_temp_new_i64();
2449 TCGv_i64 zero
= tcg_const_i64(0);
2451 /* Load the two words, in memory order. */
2452 tcg_gen_qemu_ld_i64(d1
, clean_addr
, memidx
,
2453 MO_64
| MO_ALIGN_16
| s
->be_data
);
2454 tcg_gen_addi_i64(a2
, clean_addr
, 8);
2455 tcg_gen_qemu_ld_i64(d2
, clean_addr
, memidx
, MO_64
| s
->be_data
);
2457 /* Compare the two words, also in memory order. */
2458 tcg_gen_setcond_i64(TCG_COND_EQ
, c1
, d1
, s1
);
2459 tcg_gen_setcond_i64(TCG_COND_EQ
, c2
, d2
, s2
);
2460 tcg_gen_and_i64(c2
, c2
, c1
);
2462 /* If compare equal, write back new data, else write back old data. */
2463 tcg_gen_movcond_i64(TCG_COND_NE
, c1
, c2
, zero
, t1
, d1
);
2464 tcg_gen_movcond_i64(TCG_COND_NE
, c2
, c2
, zero
, t2
, d2
);
2465 tcg_gen_qemu_st_i64(c1
, clean_addr
, memidx
, MO_64
| s
->be_data
);
2466 tcg_gen_qemu_st_i64(c2
, a2
, memidx
, MO_64
| s
->be_data
);
2467 tcg_temp_free_i64(a2
);
2468 tcg_temp_free_i64(c1
);
2469 tcg_temp_free_i64(c2
);
2470 tcg_temp_free_i64(zero
);
2472 /* Write back the data from memory to Rs. */
2473 tcg_gen_mov_i64(s1
, d1
);
2474 tcg_gen_mov_i64(s2
, d2
);
2475 tcg_temp_free_i64(d1
);
2476 tcg_temp_free_i64(d2
);
2480 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2481 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2483 static bool disas_ldst_compute_iss_sf(int size
, bool is_signed
, int opc
)
2485 int opc0
= extract32(opc
, 0, 1);
2489 regsize
= opc0
? 32 : 64;
2491 regsize
= size
== 3 ? 64 : 32;
2493 return regsize
== 64;
2496 /* Load/store exclusive
2498 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2499 * +-----+-------------+----+---+----+------+----+-------+------+------+
2500 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2501 * +-----+-------------+----+---+----+------+----+-------+------+------+
2503 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2504 * L: 0 -> store, 1 -> load
2505 * o2: 0 -> exclusive, 1 -> not
2506 * o1: 0 -> single register, 1 -> register pair
2507 * o0: 1 -> load-acquire/store-release, 0 -> not
2509 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
2511 int rt
= extract32(insn
, 0, 5);
2512 int rn
= extract32(insn
, 5, 5);
2513 int rt2
= extract32(insn
, 10, 5);
2514 int rs
= extract32(insn
, 16, 5);
2515 int is_lasr
= extract32(insn
, 15, 1);
2516 int o2_L_o1_o0
= extract32(insn
, 21, 3) * 2 | is_lasr
;
2517 int size
= extract32(insn
, 30, 2);
2518 TCGv_i64 clean_addr
;
2520 switch (o2_L_o1_o0
) {
2521 case 0x0: /* STXR */
2522 case 0x1: /* STLXR */
2524 gen_check_sp_alignment(s
);
2527 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2529 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2530 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, false);
2533 case 0x4: /* LDXR */
2534 case 0x5: /* LDAXR */
2536 gen_check_sp_alignment(s
);
2538 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2540 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, false);
2542 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2546 case 0x8: /* STLLR */
2547 if (!dc_isar_feature(aa64_lor
, s
)) {
2550 /* StoreLORelease is the same as Store-Release for QEMU. */
2552 case 0x9: /* STLR */
2553 /* Generate ISS for non-exclusive accesses including LASR. */
2555 gen_check_sp_alignment(s
);
2557 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2558 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2559 do_gpr_st(s
, cpu_reg(s
, rt
), clean_addr
, size
, true, rt
,
2560 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2563 case 0xc: /* LDLAR */
2564 if (!dc_isar_feature(aa64_lor
, s
)) {
2567 /* LoadLOAcquire is the same as Load-Acquire for QEMU. */
2569 case 0xd: /* LDAR */
2570 /* Generate ISS for non-exclusive accesses including LASR. */
2572 gen_check_sp_alignment(s
);
2574 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2575 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, size
, false, false, true, rt
,
2576 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2577 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2580 case 0x2: case 0x3: /* CASP / STXP */
2581 if (size
& 2) { /* STXP / STLXP */
2583 gen_check_sp_alignment(s
);
2586 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2588 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2589 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, true);
2593 && ((rt
| rs
) & 1) == 0
2594 && dc_isar_feature(aa64_atomics
, s
)) {
2596 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2601 case 0x6: case 0x7: /* CASPA / LDXP */
2602 if (size
& 2) { /* LDXP / LDAXP */
2604 gen_check_sp_alignment(s
);
2606 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2608 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, true);
2610 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2615 && ((rt
| rs
) & 1) == 0
2616 && dc_isar_feature(aa64_atomics
, s
)) {
2617 /* CASPA / CASPAL */
2618 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2624 case 0xb: /* CASL */
2625 case 0xe: /* CASA */
2626 case 0xf: /* CASAL */
2627 if (rt2
== 31 && dc_isar_feature(aa64_atomics
, s
)) {
2628 gen_compare_and_swap(s
, rs
, rt
, rn
, size
);
2633 unallocated_encoding(s
);
2637 * Load register (literal)
2639 * 31 30 29 27 26 25 24 23 5 4 0
2640 * +-----+-------+---+-----+-------------------+-------+
2641 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2642 * +-----+-------+---+-----+-------------------+-------+
2644 * V: 1 -> vector (simd/fp)
2645 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2646 * 10-> 32 bit signed, 11 -> prefetch
2647 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2649 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
2651 int rt
= extract32(insn
, 0, 5);
2652 int64_t imm
= sextract32(insn
, 5, 19) << 2;
2653 bool is_vector
= extract32(insn
, 26, 1);
2654 int opc
= extract32(insn
, 30, 2);
2655 bool is_signed
= false;
2657 TCGv_i64 tcg_rt
, clean_addr
;
2661 unallocated_encoding(s
);
2665 if (!fp_access_check(s
)) {
2670 /* PRFM (literal) : prefetch */
2673 size
= 2 + extract32(opc
, 0, 1);
2674 is_signed
= extract32(opc
, 1, 1);
2677 tcg_rt
= cpu_reg(s
, rt
);
2679 clean_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
2681 do_fp_ld(s
, rt
, clean_addr
, size
);
2683 /* Only unsigned 32bit loads target 32bit registers. */
2684 bool iss_sf
= opc
!= 0;
2686 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, is_signed
, false,
2687 true, rt
, iss_sf
, false);
2689 tcg_temp_free_i64(clean_addr
);
2693 * LDNP (Load Pair - non-temporal hint)
2694 * LDP (Load Pair - non vector)
2695 * LDPSW (Load Pair Signed Word - non vector)
2696 * STNP (Store Pair - non-temporal hint)
2697 * STP (Store Pair - non vector)
2698 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2699 * LDP (Load Pair of SIMD&FP)
2700 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2701 * STP (Store Pair of SIMD&FP)
2703 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2704 * +-----+-------+---+---+-------+---+-----------------------------+
2705 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2706 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2708 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2710 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2711 * V: 0 -> GPR, 1 -> Vector
2712 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2713 * 10 -> signed offset, 11 -> pre-index
2714 * L: 0 -> Store 1 -> Load
2716 * Rt, Rt2 = GPR or SIMD registers to be stored
2717 * Rn = general purpose register containing address
2718 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2720 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
2722 int rt
= extract32(insn
, 0, 5);
2723 int rn
= extract32(insn
, 5, 5);
2724 int rt2
= extract32(insn
, 10, 5);
2725 uint64_t offset
= sextract64(insn
, 15, 7);
2726 int index
= extract32(insn
, 23, 2);
2727 bool is_vector
= extract32(insn
, 26, 1);
2728 bool is_load
= extract32(insn
, 22, 1);
2729 int opc
= extract32(insn
, 30, 2);
2731 bool is_signed
= false;
2732 bool postindex
= false;
2735 TCGv_i64 clean_addr
, dirty_addr
;
2740 unallocated_encoding(s
);
2747 size
= 2 + extract32(opc
, 1, 1);
2748 is_signed
= extract32(opc
, 0, 1);
2749 if (!is_load
&& is_signed
) {
2750 unallocated_encoding(s
);
2756 case 1: /* post-index */
2761 /* signed offset with "non-temporal" hint. Since we don't emulate
2762 * caches we don't care about hints to the cache system about
2763 * data access patterns, and handle this identically to plain
2767 /* There is no non-temporal-hint version of LDPSW */
2768 unallocated_encoding(s
);
2773 case 2: /* signed offset, rn not updated */
2776 case 3: /* pre-index */
2782 if (is_vector
&& !fp_access_check(s
)) {
2789 gen_check_sp_alignment(s
);
2792 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
2794 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
2796 clean_addr
= clean_data_tbi(s
, dirty_addr
);
2800 do_fp_ld(s
, rt
, clean_addr
, size
);
2802 do_fp_st(s
, rt
, clean_addr
, size
);
2804 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2806 do_fp_ld(s
, rt2
, clean_addr
, size
);
2808 do_fp_st(s
, rt2
, clean_addr
, size
);
2811 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2812 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2815 TCGv_i64 tmp
= tcg_temp_new_i64();
2817 /* Do not modify tcg_rt before recognizing any exception
2818 * from the second load.
2820 do_gpr_ld(s
, tmp
, clean_addr
, size
, is_signed
, false,
2821 false, 0, false, false);
2822 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2823 do_gpr_ld(s
, tcg_rt2
, clean_addr
, size
, is_signed
, false,
2824 false, 0, false, false);
2826 tcg_gen_mov_i64(tcg_rt
, tmp
);
2827 tcg_temp_free_i64(tmp
);
2829 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
2830 false, 0, false, false);
2831 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2832 do_gpr_st(s
, tcg_rt2
, clean_addr
, size
,
2833 false, 0, false, false);
2839 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
2841 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
2846 * Load/store (immediate post-indexed)
2847 * Load/store (immediate pre-indexed)
2848 * Load/store (unscaled immediate)
2850 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2851 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2852 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2853 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2855 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2857 * V = 0 -> non-vector
2858 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2859 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2861 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
2867 int rn
= extract32(insn
, 5, 5);
2868 int imm9
= sextract32(insn
, 12, 9);
2869 int idx
= extract32(insn
, 10, 2);
2870 bool is_signed
= false;
2871 bool is_store
= false;
2872 bool is_extended
= false;
2873 bool is_unpriv
= (idx
== 2);
2874 bool iss_valid
= !is_vector
;
2878 TCGv_i64 clean_addr
, dirty_addr
;
2881 size
|= (opc
& 2) << 1;
2882 if (size
> 4 || is_unpriv
) {
2883 unallocated_encoding(s
);
2886 is_store
= ((opc
& 1) == 0);
2887 if (!fp_access_check(s
)) {
2891 if (size
== 3 && opc
== 2) {
2892 /* PRFM - prefetch */
2894 unallocated_encoding(s
);
2899 if (opc
== 3 && size
> 1) {
2900 unallocated_encoding(s
);
2903 is_store
= (opc
== 0);
2904 is_signed
= extract32(opc
, 1, 1);
2905 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2923 g_assert_not_reached();
2927 gen_check_sp_alignment(s
);
2930 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
2932 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
2934 clean_addr
= clean_data_tbi(s
, dirty_addr
);
2938 do_fp_st(s
, rt
, clean_addr
, size
);
2940 do_fp_ld(s
, rt
, clean_addr
, size
);
2943 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2944 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2945 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2948 do_gpr_st_memidx(s
, tcg_rt
, clean_addr
, size
, memidx
,
2949 iss_valid
, rt
, iss_sf
, false);
2951 do_gpr_ld_memidx(s
, tcg_rt
, clean_addr
, size
,
2952 is_signed
, is_extended
, memidx
,
2953 iss_valid
, rt
, iss_sf
, false);
2958 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2960 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
2962 tcg_gen_mov_i64(tcg_rn
, dirty_addr
);
2967 * Load/store (register offset)
2969 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2970 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2971 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2972 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2975 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2976 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2978 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2979 * opc<0>: 0 -> store, 1 -> load
2980 * V: 1 -> vector/simd
2981 * opt: extend encoding (see DecodeRegExtend)
2982 * S: if S=1 then scale (essentially index by sizeof(size))
2983 * Rt: register to transfer into/out of
2984 * Rn: address register or SP for base
2985 * Rm: offset register or ZR for offset
2987 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
2993 int rn
= extract32(insn
, 5, 5);
2994 int shift
= extract32(insn
, 12, 1);
2995 int rm
= extract32(insn
, 16, 5);
2996 int opt
= extract32(insn
, 13, 3);
2997 bool is_signed
= false;
2998 bool is_store
= false;
2999 bool is_extended
= false;
3001 TCGv_i64 tcg_rm
, clean_addr
, dirty_addr
;
3003 if (extract32(opt
, 1, 1) == 0) {
3004 unallocated_encoding(s
);
3009 size
|= (opc
& 2) << 1;
3011 unallocated_encoding(s
);
3014 is_store
= !extract32(opc
, 0, 1);
3015 if (!fp_access_check(s
)) {
3019 if (size
== 3 && opc
== 2) {
3020 /* PRFM - prefetch */
3023 if (opc
== 3 && size
> 1) {
3024 unallocated_encoding(s
);
3027 is_store
= (opc
== 0);
3028 is_signed
= extract32(opc
, 1, 1);
3029 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3033 gen_check_sp_alignment(s
);
3035 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3037 tcg_rm
= read_cpu_reg(s
, rm
, 1);
3038 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
3040 tcg_gen_add_i64(dirty_addr
, dirty_addr
, tcg_rm
);
3041 clean_addr
= clean_data_tbi(s
, dirty_addr
);
3045 do_fp_st(s
, rt
, clean_addr
, size
);
3047 do_fp_ld(s
, rt
, clean_addr
, size
);
3050 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3051 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3053 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3054 true, rt
, iss_sf
, false);
3056 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
,
3057 is_signed
, is_extended
,
3058 true, rt
, iss_sf
, false);
3064 * Load/store (unsigned immediate)
3066 * 31 30 29 27 26 25 24 23 22 21 10 9 5
3067 * +----+-------+---+-----+-----+------------+-------+------+
3068 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
3069 * +----+-------+---+-----+-----+------------+-------+------+
3072 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
3073 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
3075 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
3076 * opc<0>: 0 -> store, 1 -> load
3077 * Rn: base address register (inc SP)
3078 * Rt: target register
3080 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
3086 int rn
= extract32(insn
, 5, 5);
3087 unsigned int imm12
= extract32(insn
, 10, 12);
3088 unsigned int offset
;
3090 TCGv_i64 clean_addr
, dirty_addr
;
3093 bool is_signed
= false;
3094 bool is_extended
= false;
3097 size
|= (opc
& 2) << 1;
3099 unallocated_encoding(s
);
3102 is_store
= !extract32(opc
, 0, 1);
3103 if (!fp_access_check(s
)) {
3107 if (size
== 3 && opc
== 2) {
3108 /* PRFM - prefetch */
3111 if (opc
== 3 && size
> 1) {
3112 unallocated_encoding(s
);
3115 is_store
= (opc
== 0);
3116 is_signed
= extract32(opc
, 1, 1);
3117 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3121 gen_check_sp_alignment(s
);
3123 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3124 offset
= imm12
<< size
;
3125 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3126 clean_addr
= clean_data_tbi(s
, dirty_addr
);
3130 do_fp_st(s
, rt
, clean_addr
, size
);
3132 do_fp_ld(s
, rt
, clean_addr
, size
);
3135 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3136 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3138 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3139 true, rt
, iss_sf
, false);
3141 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, is_signed
, is_extended
,
3142 true, rt
, iss_sf
, false);
3147 /* Atomic memory operations
3149 * 31 30 27 26 24 22 21 16 15 12 10 5 0
3150 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
3151 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
3152 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
3154 * Rt: the result register
3155 * Rn: base address or SP
3156 * Rs: the source register for the operation
3157 * V: vector flag (always 0 as of v8.3)
3161 static void disas_ldst_atomic(DisasContext
*s
, uint32_t insn
,
3162 int size
, int rt
, bool is_vector
)
3164 int rs
= extract32(insn
, 16, 5);
3165 int rn
= extract32(insn
, 5, 5);
3166 int o3_opc
= extract32(insn
, 12, 4);
3167 TCGv_i64 tcg_rs
, clean_addr
;
3168 AtomicThreeOpFn
*fn
;
3170 if (is_vector
|| !dc_isar_feature(aa64_atomics
, s
)) {
3171 unallocated_encoding(s
);
3175 case 000: /* LDADD */
3176 fn
= tcg_gen_atomic_fetch_add_i64
;
3178 case 001: /* LDCLR */
3179 fn
= tcg_gen_atomic_fetch_and_i64
;
3181 case 002: /* LDEOR */
3182 fn
= tcg_gen_atomic_fetch_xor_i64
;
3184 case 003: /* LDSET */
3185 fn
= tcg_gen_atomic_fetch_or_i64
;
3187 case 004: /* LDSMAX */
3188 fn
= tcg_gen_atomic_fetch_smax_i64
;
3190 case 005: /* LDSMIN */
3191 fn
= tcg_gen_atomic_fetch_smin_i64
;
3193 case 006: /* LDUMAX */
3194 fn
= tcg_gen_atomic_fetch_umax_i64
;
3196 case 007: /* LDUMIN */
3197 fn
= tcg_gen_atomic_fetch_umin_i64
;
3200 fn
= tcg_gen_atomic_xchg_i64
;
3203 unallocated_encoding(s
);
3208 gen_check_sp_alignment(s
);
3210 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
3211 tcg_rs
= read_cpu_reg(s
, rs
, true);
3213 if (o3_opc
== 1) { /* LDCLR */
3214 tcg_gen_not_i64(tcg_rs
, tcg_rs
);
3217 /* The tcg atomic primitives are all full barriers. Therefore we
3218 * can ignore the Acquire and Release bits of this instruction.
3220 fn(cpu_reg(s
, rt
), clean_addr
, tcg_rs
, get_mem_index(s
),
3221 s
->be_data
| size
| MO_ALIGN
);
3225 * PAC memory operations
3227 * 31 30 27 26 24 22 21 12 11 10 5 0
3228 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3229 * | size | 1 1 1 | V | 0 0 | M S | 1 | imm9 | W | 1 | Rn | Rt |
3230 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3232 * Rt: the result register
3233 * Rn: base address or SP
3234 * V: vector flag (always 0 as of v8.3)
3235 * M: clear for key DA, set for key DB
3236 * W: pre-indexing flag
3239 static void disas_ldst_pac(DisasContext
*s
, uint32_t insn
,
3240 int size
, int rt
, bool is_vector
)
3242 int rn
= extract32(insn
, 5, 5);
3243 bool is_wback
= extract32(insn
, 11, 1);
3244 bool use_key_a
= !extract32(insn
, 23, 1);
3246 TCGv_i64 clean_addr
, dirty_addr
, tcg_rt
;
3248 if (size
!= 3 || is_vector
|| !dc_isar_feature(aa64_pauth
, s
)) {
3249 unallocated_encoding(s
);
3254 gen_check_sp_alignment(s
);
3256 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3258 if (s
->pauth_active
) {
3260 gen_helper_autda(dirty_addr
, cpu_env
, dirty_addr
, cpu_X
[31]);
3262 gen_helper_autdb(dirty_addr
, cpu_env
, dirty_addr
, cpu_X
[31]);
3266 /* Form the 10-bit signed, scaled offset. */
3267 offset
= (extract32(insn
, 22, 1) << 9) | extract32(insn
, 12, 9);
3268 offset
= sextract32(offset
<< size
, 0, 10 + size
);
3269 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3271 /* Note that "clean" and "dirty" here refer to TBI not PAC. */
3272 clean_addr
= clean_data_tbi(s
, dirty_addr
);
3274 tcg_rt
= cpu_reg(s
, rt
);
3275 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, /* is_signed */ false,
3276 /* extend */ false, /* iss_valid */ !is_wback
,
3277 /* iss_srt */ rt
, /* iss_sf */ true, /* iss_ar */ false);
3280 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
3284 /* Load/store register (all forms) */
3285 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
3287 int rt
= extract32(insn
, 0, 5);
3288 int opc
= extract32(insn
, 22, 2);
3289 bool is_vector
= extract32(insn
, 26, 1);
3290 int size
= extract32(insn
, 30, 2);
3292 switch (extract32(insn
, 24, 2)) {
3294 if (extract32(insn
, 21, 1) == 0) {
3295 /* Load/store register (unscaled immediate)
3296 * Load/store immediate pre/post-indexed
3297 * Load/store register unprivileged
3299 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
3302 switch (extract32(insn
, 10, 2)) {
3304 disas_ldst_atomic(s
, insn
, size
, rt
, is_vector
);
3307 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
3310 disas_ldst_pac(s
, insn
, size
, rt
, is_vector
);
3315 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
3318 unallocated_encoding(s
);
3321 /* AdvSIMD load/store multiple structures
3323 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
3324 * +---+---+---------------+---+-------------+--------+------+------+------+
3325 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
3326 * +---+---+---------------+---+-------------+--------+------+------+------+
3328 * AdvSIMD load/store multiple structures (post-indexed)
3330 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
3331 * +---+---+---------------+---+---+---------+--------+------+------+------+
3332 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
3333 * +---+---+---------------+---+---+---------+--------+------+------+------+
3335 * Rt: first (or only) SIMD&FP register to be transferred
3336 * Rn: base address or SP
3337 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3339 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
3341 int rt
= extract32(insn
, 0, 5);
3342 int rn
= extract32(insn
, 5, 5);
3343 int rm
= extract32(insn
, 16, 5);
3344 int size
= extract32(insn
, 10, 2);
3345 int opcode
= extract32(insn
, 12, 4);
3346 bool is_store
= !extract32(insn
, 22, 1);
3347 bool is_postidx
= extract32(insn
, 23, 1);
3348 bool is_q
= extract32(insn
, 30, 1);
3349 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3350 TCGMemOp endian
= s
->be_data
;
3352 int ebytes
; /* bytes per element */
3353 int elements
; /* elements per vector */
3354 int rpt
; /* num iterations */
3355 int selem
; /* structure elements */
3358 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
3359 unallocated_encoding(s
);
3363 if (!is_postidx
&& rm
!= 0) {
3364 unallocated_encoding(s
);
3368 /* From the shared decode logic */
3399 unallocated_encoding(s
);
3403 if (size
== 3 && !is_q
&& selem
!= 1) {
3405 unallocated_encoding(s
);
3409 if (!fp_access_check(s
)) {
3414 gen_check_sp_alignment(s
);
3417 /* For our purposes, bytes are always little-endian. */
3422 /* Consecutive little-endian elements from a single register
3423 * can be promoted to a larger little-endian operation.
3425 if (selem
== 1 && endian
== MO_LE
) {
3429 elements
= (is_q
? 16 : 8) / ebytes
;
3431 tcg_rn
= cpu_reg_sp(s
, rn
);
3432 clean_addr
= clean_data_tbi(s
, tcg_rn
);
3433 tcg_ebytes
= tcg_const_i64(ebytes
);
3435 for (r
= 0; r
< rpt
; r
++) {
3437 for (e
= 0; e
< elements
; e
++) {
3439 for (xs
= 0; xs
< selem
; xs
++) {
3440 int tt
= (rt
+ r
+ xs
) % 32;
3442 do_vec_st(s
, tt
, e
, clean_addr
, size
, endian
);
3444 do_vec_ld(s
, tt
, e
, clean_addr
, size
, endian
);
3446 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
3450 tcg_temp_free_i64(tcg_ebytes
);
3453 /* For non-quad operations, setting a slice of the low
3454 * 64 bits of the register clears the high 64 bits (in
3455 * the ARM ARM pseudocode this is implicit in the fact
3456 * that 'rval' is a 64 bit wide variable).
3457 * For quad operations, we might still need to zero the
3460 for (r
= 0; r
< rpt
* selem
; r
++) {
3461 int tt
= (rt
+ r
) % 32;
3462 clear_vec_high(s
, is_q
, tt
);
3468 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, rpt
* elements
* selem
* ebytes
);
3470 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3475 /* AdvSIMD load/store single structure
3477 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3478 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3479 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3480 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3482 * AdvSIMD load/store single structure (post-indexed)
3484 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3485 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3486 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3487 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3489 * Rt: first (or only) SIMD&FP register to be transferred
3490 * Rn: base address or SP
3491 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3492 * index = encoded in Q:S:size dependent on size
3494 * lane_size = encoded in R, opc
3495 * transfer width = encoded in opc, S, size
3497 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
3499 int rt
= extract32(insn
, 0, 5);
3500 int rn
= extract32(insn
, 5, 5);
3501 int rm
= extract32(insn
, 16, 5);
3502 int size
= extract32(insn
, 10, 2);
3503 int S
= extract32(insn
, 12, 1);
3504 int opc
= extract32(insn
, 13, 3);
3505 int R
= extract32(insn
, 21, 1);
3506 int is_load
= extract32(insn
, 22, 1);
3507 int is_postidx
= extract32(insn
, 23, 1);
3508 int is_q
= extract32(insn
, 30, 1);
3510 int scale
= extract32(opc
, 1, 2);
3511 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
3512 bool replicate
= false;
3513 int index
= is_q
<< 3 | S
<< 2 | size
;
3515 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3517 if (extract32(insn
, 31, 1)) {
3518 unallocated_encoding(s
);
3521 if (!is_postidx
&& rm
!= 0) {
3522 unallocated_encoding(s
);
3528 if (!is_load
|| S
) {
3529 unallocated_encoding(s
);
3538 if (extract32(size
, 0, 1)) {
3539 unallocated_encoding(s
);
3545 if (extract32(size
, 1, 1)) {
3546 unallocated_encoding(s
);
3549 if (!extract32(size
, 0, 1)) {
3553 unallocated_encoding(s
);
3561 g_assert_not_reached();
3564 if (!fp_access_check(s
)) {
3568 ebytes
= 1 << scale
;
3571 gen_check_sp_alignment(s
);
3574 tcg_rn
= cpu_reg_sp(s
, rn
);
3575 clean_addr
= clean_data_tbi(s
, tcg_rn
);
3576 tcg_ebytes
= tcg_const_i64(ebytes
);
3578 for (xs
= 0; xs
< selem
; xs
++) {
3580 /* Load and replicate to all elements */
3581 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3583 tcg_gen_qemu_ld_i64(tcg_tmp
, clean_addr
,
3584 get_mem_index(s
), s
->be_data
+ scale
);
3585 tcg_gen_gvec_dup_i64(scale
, vec_full_reg_offset(s
, rt
),
3586 (is_q
+ 1) * 8, vec_full_reg_size(s
),
3588 tcg_temp_free_i64(tcg_tmp
);
3590 /* Load/store one element per register */
3592 do_vec_ld(s
, rt
, index
, clean_addr
, scale
, s
->be_data
);
3594 do_vec_st(s
, rt
, index
, clean_addr
, scale
, s
->be_data
);
3597 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
3600 tcg_temp_free_i64(tcg_ebytes
);
3604 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, selem
* ebytes
);
3606 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3611 /* Loads and stores */
3612 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
3614 switch (extract32(insn
, 24, 6)) {
3615 case 0x08: /* Load/store exclusive */
3616 disas_ldst_excl(s
, insn
);
3618 case 0x18: case 0x1c: /* Load register (literal) */
3619 disas_ld_lit(s
, insn
);
3621 case 0x28: case 0x29:
3622 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
3623 disas_ldst_pair(s
, insn
);
3625 case 0x38: case 0x39:
3626 case 0x3c: case 0x3d: /* Load/store register (all forms) */
3627 disas_ldst_reg(s
, insn
);
3629 case 0x0c: /* AdvSIMD load/store multiple structures */
3630 disas_ldst_multiple_struct(s
, insn
);
3632 case 0x0d: /* AdvSIMD load/store single structure */
3633 disas_ldst_single_struct(s
, insn
);
3636 unallocated_encoding(s
);
3641 /* PC-rel. addressing
3642 * 31 30 29 28 24 23 5 4 0
3643 * +----+-------+-----------+-------------------+------+
3644 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
3645 * +----+-------+-----------+-------------------+------+
3647 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
3649 unsigned int page
, rd
;
3653 page
= extract32(insn
, 31, 1);
3654 /* SignExtend(immhi:immlo) -> offset */
3655 offset
= sextract64(insn
, 5, 19);
3656 offset
= offset
<< 2 | extract32(insn
, 29, 2);
3657 rd
= extract32(insn
, 0, 5);
3661 /* ADRP (page based) */
3666 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
3670 * Add/subtract (immediate)
3672 * 31 30 29 28 24 23 22 21 10 9 5 4 0
3673 * +--+--+--+-----------+-----+-------------+-----+-----+
3674 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
3675 * +--+--+--+-----------+-----+-------------+-----+-----+
3677 * sf: 0 -> 32bit, 1 -> 64bit
3678 * op: 0 -> add , 1 -> sub
3680 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
3682 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
3684 int rd
= extract32(insn
, 0, 5);
3685 int rn
= extract32(insn
, 5, 5);
3686 uint64_t imm
= extract32(insn
, 10, 12);
3687 int shift
= extract32(insn
, 22, 2);
3688 bool setflags
= extract32(insn
, 29, 1);
3689 bool sub_op
= extract32(insn
, 30, 1);
3690 bool is_64bit
= extract32(insn
, 31, 1);
3692 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
3693 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
3694 TCGv_i64 tcg_result
;
3703 unallocated_encoding(s
);
3707 tcg_result
= tcg_temp_new_i64();
3710 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
3712 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
3715 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
3717 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3719 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3721 tcg_temp_free_i64(tcg_imm
);
3725 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3727 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3730 tcg_temp_free_i64(tcg_result
);
3733 /* The input should be a value in the bottom e bits (with higher
3734 * bits zero); returns that value replicated into every element
3735 * of size e in a 64 bit integer.
3737 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
3747 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
3748 static inline uint64_t bitmask64(unsigned int length
)
3750 assert(length
> 0 && length
<= 64);
3751 return ~0ULL >> (64 - length
);
3754 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
3755 * only require the wmask. Returns false if the imms/immr/immn are a reserved
3756 * value (ie should cause a guest UNDEF exception), and true if they are
3757 * valid, in which case the decoded bit pattern is written to result.
3759 bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
3760 unsigned int imms
, unsigned int immr
)
3763 unsigned e
, levels
, s
, r
;
3766 assert(immn
< 2 && imms
< 64 && immr
< 64);
3768 /* The bit patterns we create here are 64 bit patterns which
3769 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
3770 * 64 bits each. Each element contains the same value: a run
3771 * of between 1 and e-1 non-zero bits, rotated within the
3772 * element by between 0 and e-1 bits.
3774 * The element size and run length are encoded into immn (1 bit)
3775 * and imms (6 bits) as follows:
3776 * 64 bit elements: immn = 1, imms = <length of run - 1>
3777 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
3778 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
3779 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
3780 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
3781 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
3782 * Notice that immn = 0, imms = 11111x is the only combination
3783 * not covered by one of the above options; this is reserved.
3784 * Further, <length of run - 1> all-ones is a reserved pattern.
3786 * In all cases the rotation is by immr % e (and immr is 6 bits).
3789 /* First determine the element size */
3790 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
3792 /* This is the immn == 0, imms == 0x11111x case */
3802 /* <length of run - 1> mustn't be all-ones. */
3806 /* Create the value of one element: s+1 set bits rotated
3807 * by r within the element (which is e bits wide)...
3809 mask
= bitmask64(s
+ 1);
3811 mask
= (mask
>> r
) | (mask
<< (e
- r
));
3812 mask
&= bitmask64(e
);
3814 /* ...then replicate the element over the whole 64 bit value */
3815 mask
= bitfield_replicate(mask
, e
);
3820 /* Logical (immediate)
3821 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3822 * +----+-----+-------------+---+------+------+------+------+
3823 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
3824 * +----+-----+-------------+---+------+------+------+------+
3826 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
3828 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
3829 TCGv_i64 tcg_rd
, tcg_rn
;
3831 bool is_and
= false;
3833 sf
= extract32(insn
, 31, 1);
3834 opc
= extract32(insn
, 29, 2);
3835 is_n
= extract32(insn
, 22, 1);
3836 immr
= extract32(insn
, 16, 6);
3837 imms
= extract32(insn
, 10, 6);
3838 rn
= extract32(insn
, 5, 5);
3839 rd
= extract32(insn
, 0, 5);
3842 unallocated_encoding(s
);
3846 if (opc
== 0x3) { /* ANDS */
3847 tcg_rd
= cpu_reg(s
, rd
);
3849 tcg_rd
= cpu_reg_sp(s
, rd
);
3851 tcg_rn
= cpu_reg(s
, rn
);
3853 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
3854 /* some immediate field values are reserved */
3855 unallocated_encoding(s
);
3860 wmask
&= 0xffffffff;
3864 case 0x3: /* ANDS */
3866 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
3870 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
3873 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
3876 assert(FALSE
); /* must handle all above */
3880 if (!sf
&& !is_and
) {
3881 /* zero extend final result; we know we can skip this for AND
3882 * since the immediate had the high 32 bits clear.
3884 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3887 if (opc
== 3) { /* ANDS */
3888 gen_logic_CC(sf
, tcg_rd
);
3893 * Move wide (immediate)
3895 * 31 30 29 28 23 22 21 20 5 4 0
3896 * +--+-----+-------------+-----+----------------+------+
3897 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
3898 * +--+-----+-------------+-----+----------------+------+
3900 * sf: 0 -> 32 bit, 1 -> 64 bit
3901 * opc: 00 -> N, 10 -> Z, 11 -> K
3902 * hw: shift/16 (0,16, and sf only 32, 48)
3904 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
3906 int rd
= extract32(insn
, 0, 5);
3907 uint64_t imm
= extract32(insn
, 5, 16);
3908 int sf
= extract32(insn
, 31, 1);
3909 int opc
= extract32(insn
, 29, 2);
3910 int pos
= extract32(insn
, 21, 2) << 4;
3911 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3914 if (!sf
&& (pos
>= 32)) {
3915 unallocated_encoding(s
);
3929 tcg_gen_movi_i64(tcg_rd
, imm
);
3932 tcg_imm
= tcg_const_i64(imm
);
3933 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
3934 tcg_temp_free_i64(tcg_imm
);
3936 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3940 unallocated_encoding(s
);
3946 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3947 * +----+-----+-------------+---+------+------+------+------+
3948 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3949 * +----+-----+-------------+---+------+------+------+------+
3951 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
3953 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
3954 TCGv_i64 tcg_rd
, tcg_tmp
;
3956 sf
= extract32(insn
, 31, 1);
3957 opc
= extract32(insn
, 29, 2);
3958 n
= extract32(insn
, 22, 1);
3959 ri
= extract32(insn
, 16, 6);
3960 si
= extract32(insn
, 10, 6);
3961 rn
= extract32(insn
, 5, 5);
3962 rd
= extract32(insn
, 0, 5);
3963 bitsize
= sf
? 64 : 32;
3965 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
3966 unallocated_encoding(s
);
3970 tcg_rd
= cpu_reg(s
, rd
);
3972 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3973 to be smaller than bitsize, we'll never reference data outside the
3974 low 32-bits anyway. */
3975 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
3977 /* Recognize simple(r) extractions. */
3979 /* Wd<s-r:0> = Wn<s:r> */
3980 len
= (si
- ri
) + 1;
3981 if (opc
== 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
3982 tcg_gen_sextract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3984 } else if (opc
== 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
3985 tcg_gen_extract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3988 /* opc == 1, BXFIL fall through to deposit */
3989 tcg_gen_extract_i64(tcg_tmp
, tcg_tmp
, ri
, len
);
3992 /* Handle the ri > si case with a deposit
3993 * Wd<32+s-r,32-r> = Wn<s:0>
3996 pos
= (bitsize
- ri
) & (bitsize
- 1);
3999 if (opc
== 0 && len
< ri
) {
4000 /* SBFM: sign extend the destination field from len to fill
4001 the balance of the word. Let the deposit below insert all
4002 of those sign bits. */
4003 tcg_gen_sextract_i64(tcg_tmp
, tcg_tmp
, 0, len
);
4007 if (opc
== 1) { /* BFM, BXFIL */
4008 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
4010 /* SBFM or UBFM: We start with zero, and we haven't modified
4011 any bits outside bitsize, therefore the zero-extension
4012 below is unneeded. */
4013 tcg_gen_deposit_z_i64(tcg_rd
, tcg_tmp
, pos
, len
);
4018 if (!sf
) { /* zero extend final result */
4019 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4024 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
4025 * +----+------+-------------+---+----+------+--------+------+------+
4026 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
4027 * +----+------+-------------+---+----+------+--------+------+------+
4029 static void disas_extract(DisasContext
*s
, uint32_t insn
)
4031 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
4033 sf
= extract32(insn
, 31, 1);
4034 n
= extract32(insn
, 22, 1);
4035 rm
= extract32(insn
, 16, 5);
4036 imm
= extract32(insn
, 10, 6);
4037 rn
= extract32(insn
, 5, 5);
4038 rd
= extract32(insn
, 0, 5);
4039 op21
= extract32(insn
, 29, 2);
4040 op0
= extract32(insn
, 21, 1);
4041 bitsize
= sf
? 64 : 32;
4043 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
4044 unallocated_encoding(s
);
4046 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
4048 tcg_rd
= cpu_reg(s
, rd
);
4050 if (unlikely(imm
== 0)) {
4051 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
4052 * so an extract from bit 0 is a special case.
4055 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
4057 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
4059 } else if (rm
== rn
) { /* ROR */
4060 tcg_rm
= cpu_reg(s
, rm
);
4062 tcg_gen_rotri_i64(tcg_rd
, tcg_rm
, imm
);
4064 TCGv_i32 tmp
= tcg_temp_new_i32();
4065 tcg_gen_extrl_i64_i32(tmp
, tcg_rm
);
4066 tcg_gen_rotri_i32(tmp
, tmp
, imm
);
4067 tcg_gen_extu_i32_i64(tcg_rd
, tmp
);
4068 tcg_temp_free_i32(tmp
);
4071 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4072 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4073 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
4074 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
4075 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
4077 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4083 /* Data processing - immediate */
4084 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
4086 switch (extract32(insn
, 23, 6)) {
4087 case 0x20: case 0x21: /* PC-rel. addressing */
4088 disas_pc_rel_adr(s
, insn
);
4090 case 0x22: case 0x23: /* Add/subtract (immediate) */
4091 disas_add_sub_imm(s
, insn
);
4093 case 0x24: /* Logical (immediate) */
4094 disas_logic_imm(s
, insn
);
4096 case 0x25: /* Move wide (immediate) */
4097 disas_movw_imm(s
, insn
);
4099 case 0x26: /* Bitfield */
4100 disas_bitfield(s
, insn
);
4102 case 0x27: /* Extract */
4103 disas_extract(s
, insn
);
4106 unallocated_encoding(s
);
4111 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
4112 * Note that it is the caller's responsibility to ensure that the
4113 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
4114 * mandated semantics for out of range shifts.
4116 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4117 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
4119 switch (shift_type
) {
4120 case A64_SHIFT_TYPE_LSL
:
4121 tcg_gen_shl_i64(dst
, src
, shift_amount
);
4123 case A64_SHIFT_TYPE_LSR
:
4124 tcg_gen_shr_i64(dst
, src
, shift_amount
);
4126 case A64_SHIFT_TYPE_ASR
:
4128 tcg_gen_ext32s_i64(dst
, src
);
4130 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
4132 case A64_SHIFT_TYPE_ROR
:
4134 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
4137 t0
= tcg_temp_new_i32();
4138 t1
= tcg_temp_new_i32();
4139 tcg_gen_extrl_i64_i32(t0
, src
);
4140 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
4141 tcg_gen_rotr_i32(t0
, t0
, t1
);
4142 tcg_gen_extu_i32_i64(dst
, t0
);
4143 tcg_temp_free_i32(t0
);
4144 tcg_temp_free_i32(t1
);
4148 assert(FALSE
); /* all shift types should be handled */
4152 if (!sf
) { /* zero extend final result */
4153 tcg_gen_ext32u_i64(dst
, dst
);
4157 /* Shift a TCGv src by immediate, put result in dst.
4158 * The shift amount must be in range (this should always be true as the
4159 * relevant instructions will UNDEF on bad shift immediates).
4161 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4162 enum a64_shift_type shift_type
, unsigned int shift_i
)
4164 assert(shift_i
< (sf
? 64 : 32));
4167 tcg_gen_mov_i64(dst
, src
);
4169 TCGv_i64 shift_const
;
4171 shift_const
= tcg_const_i64(shift_i
);
4172 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
4173 tcg_temp_free_i64(shift_const
);
4177 /* Logical (shifted register)
4178 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4179 * +----+-----+-----------+-------+---+------+--------+------+------+
4180 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
4181 * +----+-----+-----------+-------+---+------+--------+------+------+
4183 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
4185 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
4186 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
4188 sf
= extract32(insn
, 31, 1);
4189 opc
= extract32(insn
, 29, 2);
4190 shift_type
= extract32(insn
, 22, 2);
4191 invert
= extract32(insn
, 21, 1);
4192 rm
= extract32(insn
, 16, 5);
4193 shift_amount
= extract32(insn
, 10, 6);
4194 rn
= extract32(insn
, 5, 5);
4195 rd
= extract32(insn
, 0, 5);
4197 if (!sf
&& (shift_amount
& (1 << 5))) {
4198 unallocated_encoding(s
);
4202 tcg_rd
= cpu_reg(s
, rd
);
4204 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
4205 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
4206 * register-register MOV and MVN, so it is worth special casing.
4208 tcg_rm
= cpu_reg(s
, rm
);
4210 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
4212 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4216 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
4218 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
4224 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4227 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
4230 tcg_rn
= cpu_reg(s
, rn
);
4232 switch (opc
| (invert
<< 2)) {
4235 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4238 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4241 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4245 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4248 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4251 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4259 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4263 gen_logic_CC(sf
, tcg_rd
);
4268 * Add/subtract (extended register)
4270 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
4271 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4272 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
4273 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4275 * sf: 0 -> 32bit, 1 -> 64bit
4276 * op: 0 -> add , 1 -> sub
4279 * option: extension type (see DecodeRegExtend)
4280 * imm3: optional shift to Rm
4282 * Rd = Rn + LSL(extend(Rm), amount)
4284 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
4286 int rd
= extract32(insn
, 0, 5);
4287 int rn
= extract32(insn
, 5, 5);
4288 int imm3
= extract32(insn
, 10, 3);
4289 int option
= extract32(insn
, 13, 3);
4290 int rm
= extract32(insn
, 16, 5);
4291 int opt
= extract32(insn
, 22, 2);
4292 bool setflags
= extract32(insn
, 29, 1);
4293 bool sub_op
= extract32(insn
, 30, 1);
4294 bool sf
= extract32(insn
, 31, 1);
4296 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
4298 TCGv_i64 tcg_result
;
4300 if (imm3
> 4 || opt
!= 0) {
4301 unallocated_encoding(s
);
4305 /* non-flag setting ops may use SP */
4307 tcg_rd
= cpu_reg_sp(s
, rd
);
4309 tcg_rd
= cpu_reg(s
, rd
);
4311 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
4313 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4314 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
4316 tcg_result
= tcg_temp_new_i64();
4320 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4322 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4326 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4328 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4333 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4335 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4338 tcg_temp_free_i64(tcg_result
);
4342 * Add/subtract (shifted register)
4344 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4345 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4346 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
4347 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4349 * sf: 0 -> 32bit, 1 -> 64bit
4350 * op: 0 -> add , 1 -> sub
4352 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
4353 * imm6: Shift amount to apply to Rm before the add/sub
4355 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
4357 int rd
= extract32(insn
, 0, 5);
4358 int rn
= extract32(insn
, 5, 5);
4359 int imm6
= extract32(insn
, 10, 6);
4360 int rm
= extract32(insn
, 16, 5);
4361 int shift_type
= extract32(insn
, 22, 2);
4362 bool setflags
= extract32(insn
, 29, 1);
4363 bool sub_op
= extract32(insn
, 30, 1);
4364 bool sf
= extract32(insn
, 31, 1);
4366 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4367 TCGv_i64 tcg_rn
, tcg_rm
;
4368 TCGv_i64 tcg_result
;
4370 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
4371 unallocated_encoding(s
);
4375 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4376 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4378 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
4380 tcg_result
= tcg_temp_new_i64();
4384 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4386 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4390 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4392 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4397 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4399 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4402 tcg_temp_free_i64(tcg_result
);
4405 /* Data-processing (3 source)
4407 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
4408 * +--+------+-----------+------+------+----+------+------+------+
4409 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
4410 * +--+------+-----------+------+------+----+------+------+------+
4412 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
4414 int rd
= extract32(insn
, 0, 5);
4415 int rn
= extract32(insn
, 5, 5);
4416 int ra
= extract32(insn
, 10, 5);
4417 int rm
= extract32(insn
, 16, 5);
4418 int op_id
= (extract32(insn
, 29, 3) << 4) |
4419 (extract32(insn
, 21, 3) << 1) |
4420 extract32(insn
, 15, 1);
4421 bool sf
= extract32(insn
, 31, 1);
4422 bool is_sub
= extract32(op_id
, 0, 1);
4423 bool is_high
= extract32(op_id
, 2, 1);
4424 bool is_signed
= false;
4429 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
4431 case 0x42: /* SMADDL */
4432 case 0x43: /* SMSUBL */
4433 case 0x44: /* SMULH */
4436 case 0x0: /* MADD (32bit) */
4437 case 0x1: /* MSUB (32bit) */
4438 case 0x40: /* MADD (64bit) */
4439 case 0x41: /* MSUB (64bit) */
4440 case 0x4a: /* UMADDL */
4441 case 0x4b: /* UMSUBL */
4442 case 0x4c: /* UMULH */
4445 unallocated_encoding(s
);
4450 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
4451 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4452 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4453 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
4456 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4458 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4461 tcg_temp_free_i64(low_bits
);
4465 tcg_op1
= tcg_temp_new_i64();
4466 tcg_op2
= tcg_temp_new_i64();
4467 tcg_tmp
= tcg_temp_new_i64();
4470 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
4471 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
4474 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
4475 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
4477 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
4478 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
4482 if (ra
== 31 && !is_sub
) {
4483 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
4484 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
4486 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
4488 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4490 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4495 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
4498 tcg_temp_free_i64(tcg_op1
);
4499 tcg_temp_free_i64(tcg_op2
);
4500 tcg_temp_free_i64(tcg_tmp
);
4503 /* Add/subtract (with carry)
4504 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
4505 * +--+--+--+------------------------+------+-------------+------+-----+
4506 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | 0 0 0 0 0 0 | Rn | Rd |
4507 * +--+--+--+------------------------+------+-------------+------+-----+
4510 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
4512 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
4513 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
4515 sf
= extract32(insn
, 31, 1);
4516 op
= extract32(insn
, 30, 1);
4517 setflags
= extract32(insn
, 29, 1);
4518 rm
= extract32(insn
, 16, 5);
4519 rn
= extract32(insn
, 5, 5);
4520 rd
= extract32(insn
, 0, 5);
4522 tcg_rd
= cpu_reg(s
, rd
);
4523 tcg_rn
= cpu_reg(s
, rn
);
4526 tcg_y
= new_tmp_a64(s
);
4527 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
4529 tcg_y
= cpu_reg(s
, rm
);
4533 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4535 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4540 * Rotate right into flags
4541 * 31 30 29 21 15 10 5 4 0
4542 * +--+--+--+-----------------+--------+-----------+------+--+------+
4543 * |sf|op| S| 1 1 0 1 0 0 0 0 | imm6 | 0 0 0 0 1 | Rn |o2| mask |
4544 * +--+--+--+-----------------+--------+-----------+------+--+------+
4546 static void disas_rotate_right_into_flags(DisasContext
*s
, uint32_t insn
)
4548 int mask
= extract32(insn
, 0, 4);
4549 int o2
= extract32(insn
, 4, 1);
4550 int rn
= extract32(insn
, 5, 5);
4551 int imm6
= extract32(insn
, 15, 6);
4552 int sf_op_s
= extract32(insn
, 29, 3);
4556 if (sf_op_s
!= 5 || o2
!= 0 || !dc_isar_feature(aa64_condm_4
, s
)) {
4557 unallocated_encoding(s
);
4561 tcg_rn
= read_cpu_reg(s
, rn
, 1);
4562 tcg_gen_rotri_i64(tcg_rn
, tcg_rn
, imm6
);
4564 nzcv
= tcg_temp_new_i32();
4565 tcg_gen_extrl_i64_i32(nzcv
, tcg_rn
);
4567 if (mask
& 8) { /* N */
4568 tcg_gen_shli_i32(cpu_NF
, nzcv
, 31 - 3);
4570 if (mask
& 4) { /* Z */
4571 tcg_gen_not_i32(cpu_ZF
, nzcv
);
4572 tcg_gen_andi_i32(cpu_ZF
, cpu_ZF
, 4);
4574 if (mask
& 2) { /* C */
4575 tcg_gen_extract_i32(cpu_CF
, nzcv
, 1, 1);
4577 if (mask
& 1) { /* V */
4578 tcg_gen_shli_i32(cpu_VF
, nzcv
, 31 - 0);
4581 tcg_temp_free_i32(nzcv
);
4585 * Evaluate into flags
4586 * 31 30 29 21 15 14 10 5 4 0
4587 * +--+--+--+-----------------+---------+----+---------+------+--+------+
4588 * |sf|op| S| 1 1 0 1 0 0 0 0 | opcode2 | sz | 0 0 1 0 | Rn |o3| mask |
4589 * +--+--+--+-----------------+---------+----+---------+------+--+------+
4591 static void disas_evaluate_into_flags(DisasContext
*s
, uint32_t insn
)
4593 int o3_mask
= extract32(insn
, 0, 5);
4594 int rn
= extract32(insn
, 5, 5);
4595 int o2
= extract32(insn
, 15, 6);
4596 int sz
= extract32(insn
, 14, 1);
4597 int sf_op_s
= extract32(insn
, 29, 3);
4601 if (sf_op_s
!= 1 || o2
!= 0 || o3_mask
!= 0xd ||
4602 !dc_isar_feature(aa64_condm_4
, s
)) {
4603 unallocated_encoding(s
);
4606 shift
= sz
? 16 : 24; /* SETF16 or SETF8 */
4608 tmp
= tcg_temp_new_i32();
4609 tcg_gen_extrl_i64_i32(tmp
, cpu_reg(s
, rn
));
4610 tcg_gen_shli_i32(cpu_NF
, tmp
, shift
);
4611 tcg_gen_shli_i32(cpu_VF
, tmp
, shift
- 1);
4612 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
4613 tcg_gen_xor_i32(cpu_VF
, cpu_VF
, cpu_NF
);
4614 tcg_temp_free_i32(tmp
);
4617 /* Conditional compare (immediate / register)
4618 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4619 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4620 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
4621 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4624 static void disas_cc(DisasContext
*s
, uint32_t insn
)
4626 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
4627 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
4628 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
4631 if (!extract32(insn
, 29, 1)) {
4632 unallocated_encoding(s
);
4635 if (insn
& (1 << 10 | 1 << 4)) {
4636 unallocated_encoding(s
);
4639 sf
= extract32(insn
, 31, 1);
4640 op
= extract32(insn
, 30, 1);
4641 is_imm
= extract32(insn
, 11, 1);
4642 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
4643 cond
= extract32(insn
, 12, 4);
4644 rn
= extract32(insn
, 5, 5);
4645 nzcv
= extract32(insn
, 0, 4);
4647 /* Set T0 = !COND. */
4648 tcg_t0
= tcg_temp_new_i32();
4649 arm_test_cc(&c
, cond
);
4650 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
4653 /* Load the arguments for the new comparison. */
4655 tcg_y
= new_tmp_a64(s
);
4656 tcg_gen_movi_i64(tcg_y
, y
);
4658 tcg_y
= cpu_reg(s
, y
);
4660 tcg_rn
= cpu_reg(s
, rn
);
4662 /* Set the flags for the new comparison. */
4663 tcg_tmp
= tcg_temp_new_i64();
4665 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4667 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4669 tcg_temp_free_i64(tcg_tmp
);
4671 /* If COND was false, force the flags to #nzcv. Compute two masks
4672 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
4673 * For tcg hosts that support ANDC, we can make do with just T1.
4674 * In either case, allow the tcg optimizer to delete any unused mask.
4676 tcg_t1
= tcg_temp_new_i32();
4677 tcg_t2
= tcg_temp_new_i32();
4678 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
4679 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
4681 if (nzcv
& 8) { /* N */
4682 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4684 if (TCG_TARGET_HAS_andc_i32
) {
4685 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4687 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
4690 if (nzcv
& 4) { /* Z */
4691 if (TCG_TARGET_HAS_andc_i32
) {
4692 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
4694 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
4697 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
4699 if (nzcv
& 2) { /* C */
4700 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
4702 if (TCG_TARGET_HAS_andc_i32
) {
4703 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
4705 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
4708 if (nzcv
& 1) { /* V */
4709 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4711 if (TCG_TARGET_HAS_andc_i32
) {
4712 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4714 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
4717 tcg_temp_free_i32(tcg_t0
);
4718 tcg_temp_free_i32(tcg_t1
);
4719 tcg_temp_free_i32(tcg_t2
);
4722 /* Conditional select
4723 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
4724 * +----+----+---+-----------------+------+------+-----+------+------+
4725 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
4726 * +----+----+---+-----------------+------+------+-----+------+------+
4728 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
4730 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
4731 TCGv_i64 tcg_rd
, zero
;
4734 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
4735 /* S == 1 or op2<1> == 1 */
4736 unallocated_encoding(s
);
4739 sf
= extract32(insn
, 31, 1);
4740 else_inv
= extract32(insn
, 30, 1);
4741 rm
= extract32(insn
, 16, 5);
4742 cond
= extract32(insn
, 12, 4);
4743 else_inc
= extract32(insn
, 10, 1);
4744 rn
= extract32(insn
, 5, 5);
4745 rd
= extract32(insn
, 0, 5);
4747 tcg_rd
= cpu_reg(s
, rd
);
4749 a64_test_cc(&c
, cond
);
4750 zero
= tcg_const_i64(0);
4752 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
4754 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
4756 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
4759 TCGv_i64 t_true
= cpu_reg(s
, rn
);
4760 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
4761 if (else_inv
&& else_inc
) {
4762 tcg_gen_neg_i64(t_false
, t_false
);
4763 } else if (else_inv
) {
4764 tcg_gen_not_i64(t_false
, t_false
);
4765 } else if (else_inc
) {
4766 tcg_gen_addi_i64(t_false
, t_false
, 1);
4768 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
4771 tcg_temp_free_i64(zero
);
4775 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4779 static void handle_clz(DisasContext
*s
, unsigned int sf
,
4780 unsigned int rn
, unsigned int rd
)
4782 TCGv_i64 tcg_rd
, tcg_rn
;
4783 tcg_rd
= cpu_reg(s
, rd
);
4784 tcg_rn
= cpu_reg(s
, rn
);
4787 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
4789 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4790 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4791 tcg_gen_clzi_i32(tcg_tmp32
, tcg_tmp32
, 32);
4792 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4793 tcg_temp_free_i32(tcg_tmp32
);
4797 static void handle_cls(DisasContext
*s
, unsigned int sf
,
4798 unsigned int rn
, unsigned int rd
)
4800 TCGv_i64 tcg_rd
, tcg_rn
;
4801 tcg_rd
= cpu_reg(s
, rd
);
4802 tcg_rn
= cpu_reg(s
, rn
);
4805 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
4807 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4808 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4809 tcg_gen_clrsb_i32(tcg_tmp32
, tcg_tmp32
);
4810 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4811 tcg_temp_free_i32(tcg_tmp32
);
4815 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
4816 unsigned int rn
, unsigned int rd
)
4818 TCGv_i64 tcg_rd
, tcg_rn
;
4819 tcg_rd
= cpu_reg(s
, rd
);
4820 tcg_rn
= cpu_reg(s
, rn
);
4823 gen_helper_rbit64(tcg_rd
, tcg_rn
);
4825 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4826 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4827 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
4828 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4829 tcg_temp_free_i32(tcg_tmp32
);
4833 /* REV with sf==1, opcode==3 ("REV64") */
4834 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
4835 unsigned int rn
, unsigned int rd
)
4838 unallocated_encoding(s
);
4841 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
4844 /* REV with sf==0, opcode==2
4845 * REV32 (sf==1, opcode==2)
4847 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
4848 unsigned int rn
, unsigned int rd
)
4850 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4853 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4854 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4856 /* bswap32_i64 requires zero high word */
4857 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
4858 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
4859 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
4860 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
4861 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4863 tcg_temp_free_i64(tcg_tmp
);
4865 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
4866 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
4870 /* REV16 (opcode==1) */
4871 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
4872 unsigned int rn
, unsigned int rd
)
4874 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4875 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4876 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4877 TCGv_i64 mask
= tcg_const_i64(sf
? 0x00ff00ff00ff00ffull
: 0x00ff00ff);
4879 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 8);
4880 tcg_gen_and_i64(tcg_rd
, tcg_rn
, mask
);
4881 tcg_gen_and_i64(tcg_tmp
, tcg_tmp
, mask
);
4882 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 8);
4883 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4885 tcg_temp_free_i64(mask
);
4886 tcg_temp_free_i64(tcg_tmp
);
4889 /* Data-processing (1 source)
4890 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4891 * +----+---+---+-----------------+---------+--------+------+------+
4892 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
4893 * +----+---+---+-----------------+---------+--------+------+------+
4895 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
4897 unsigned int sf
, opcode
, opcode2
, rn
, rd
;
4900 if (extract32(insn
, 29, 1)) {
4901 unallocated_encoding(s
);
4905 sf
= extract32(insn
, 31, 1);
4906 opcode
= extract32(insn
, 10, 6);
4907 opcode2
= extract32(insn
, 16, 5);
4908 rn
= extract32(insn
, 5, 5);
4909 rd
= extract32(insn
, 0, 5);
4911 #define MAP(SF, O2, O1) ((SF) | (O1 << 1) | (O2 << 7))
4913 switch (MAP(sf
, opcode2
, opcode
)) {
4914 case MAP(0, 0x00, 0x00): /* RBIT */
4915 case MAP(1, 0x00, 0x00):
4916 handle_rbit(s
, sf
, rn
, rd
);
4918 case MAP(0, 0x00, 0x01): /* REV16 */
4919 case MAP(1, 0x00, 0x01):
4920 handle_rev16(s
, sf
, rn
, rd
);
4922 case MAP(0, 0x00, 0x02): /* REV/REV32 */
4923 case MAP(1, 0x00, 0x02):
4924 handle_rev32(s
, sf
, rn
, rd
);
4926 case MAP(1, 0x00, 0x03): /* REV64 */
4927 handle_rev64(s
, sf
, rn
, rd
);
4929 case MAP(0, 0x00, 0x04): /* CLZ */
4930 case MAP(1, 0x00, 0x04):
4931 handle_clz(s
, sf
, rn
, rd
);
4933 case MAP(0, 0x00, 0x05): /* CLS */
4934 case MAP(1, 0x00, 0x05):
4935 handle_cls(s
, sf
, rn
, rd
);
4937 case MAP(1, 0x01, 0x00): /* PACIA */
4938 if (s
->pauth_active
) {
4939 tcg_rd
= cpu_reg(s
, rd
);
4940 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4941 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4942 goto do_unallocated
;
4945 case MAP(1, 0x01, 0x01): /* PACIB */
4946 if (s
->pauth_active
) {
4947 tcg_rd
= cpu_reg(s
, rd
);
4948 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4949 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4950 goto do_unallocated
;
4953 case MAP(1, 0x01, 0x02): /* PACDA */
4954 if (s
->pauth_active
) {
4955 tcg_rd
= cpu_reg(s
, rd
);
4956 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4957 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4958 goto do_unallocated
;
4961 case MAP(1, 0x01, 0x03): /* PACDB */
4962 if (s
->pauth_active
) {
4963 tcg_rd
= cpu_reg(s
, rd
);
4964 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4965 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4966 goto do_unallocated
;
4969 case MAP(1, 0x01, 0x04): /* AUTIA */
4970 if (s
->pauth_active
) {
4971 tcg_rd
= cpu_reg(s
, rd
);
4972 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4973 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4974 goto do_unallocated
;
4977 case MAP(1, 0x01, 0x05): /* AUTIB */
4978 if (s
->pauth_active
) {
4979 tcg_rd
= cpu_reg(s
, rd
);
4980 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4981 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4982 goto do_unallocated
;
4985 case MAP(1, 0x01, 0x06): /* AUTDA */
4986 if (s
->pauth_active
) {
4987 tcg_rd
= cpu_reg(s
, rd
);
4988 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4989 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4990 goto do_unallocated
;
4993 case MAP(1, 0x01, 0x07): /* AUTDB */
4994 if (s
->pauth_active
) {
4995 tcg_rd
= cpu_reg(s
, rd
);
4996 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4997 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4998 goto do_unallocated
;
5001 case MAP(1, 0x01, 0x08): /* PACIZA */
5002 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5003 goto do_unallocated
;
5004 } else if (s
->pauth_active
) {
5005 tcg_rd
= cpu_reg(s
, rd
);
5006 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5009 case MAP(1, 0x01, 0x09): /* PACIZB */
5010 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5011 goto do_unallocated
;
5012 } else if (s
->pauth_active
) {
5013 tcg_rd
= cpu_reg(s
, rd
);
5014 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5017 case MAP(1, 0x01, 0x0a): /* PACDZA */
5018 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5019 goto do_unallocated
;
5020 } else if (s
->pauth_active
) {
5021 tcg_rd
= cpu_reg(s
, rd
);
5022 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5025 case MAP(1, 0x01, 0x0b): /* PACDZB */
5026 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5027 goto do_unallocated
;
5028 } else if (s
->pauth_active
) {
5029 tcg_rd
= cpu_reg(s
, rd
);
5030 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5033 case MAP(1, 0x01, 0x0c): /* AUTIZA */
5034 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5035 goto do_unallocated
;
5036 } else if (s
->pauth_active
) {
5037 tcg_rd
= cpu_reg(s
, rd
);
5038 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5041 case MAP(1, 0x01, 0x0d): /* AUTIZB */
5042 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5043 goto do_unallocated
;
5044 } else if (s
->pauth_active
) {
5045 tcg_rd
= cpu_reg(s
, rd
);
5046 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5049 case MAP(1, 0x01, 0x0e): /* AUTDZA */
5050 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5051 goto do_unallocated
;
5052 } else if (s
->pauth_active
) {
5053 tcg_rd
= cpu_reg(s
, rd
);
5054 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5057 case MAP(1, 0x01, 0x0f): /* AUTDZB */
5058 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5059 goto do_unallocated
;
5060 } else if (s
->pauth_active
) {
5061 tcg_rd
= cpu_reg(s
, rd
);
5062 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
5065 case MAP(1, 0x01, 0x10): /* XPACI */
5066 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5067 goto do_unallocated
;
5068 } else if (s
->pauth_active
) {
5069 tcg_rd
= cpu_reg(s
, rd
);
5070 gen_helper_xpaci(tcg_rd
, cpu_env
, tcg_rd
);
5073 case MAP(1, 0x01, 0x11): /* XPACD */
5074 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
5075 goto do_unallocated
;
5076 } else if (s
->pauth_active
) {
5077 tcg_rd
= cpu_reg(s
, rd
);
5078 gen_helper_xpacd(tcg_rd
, cpu_env
, tcg_rd
);
5083 unallocated_encoding(s
);
5090 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
5091 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5093 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
5094 tcg_rd
= cpu_reg(s
, rd
);
5096 if (!sf
&& is_signed
) {
5097 tcg_n
= new_tmp_a64(s
);
5098 tcg_m
= new_tmp_a64(s
);
5099 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
5100 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
5102 tcg_n
= read_cpu_reg(s
, rn
, sf
);
5103 tcg_m
= read_cpu_reg(s
, rm
, sf
);
5107 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
5109 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
5112 if (!sf
) { /* zero extend final result */
5113 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5117 /* LSLV, LSRV, ASRV, RORV */
5118 static void handle_shift_reg(DisasContext
*s
,
5119 enum a64_shift_type shift_type
, unsigned int sf
,
5120 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5122 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
5123 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5124 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
5126 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
5127 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
5128 tcg_temp_free_i64(tcg_shift
);
5131 /* CRC32[BHWX], CRC32C[BHWX] */
5132 static void handle_crc32(DisasContext
*s
,
5133 unsigned int sf
, unsigned int sz
, bool crc32c
,
5134 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5136 TCGv_i64 tcg_acc
, tcg_val
;
5139 if (!dc_isar_feature(aa64_crc32
, s
)
5140 || (sf
== 1 && sz
!= 3)
5141 || (sf
== 0 && sz
== 3)) {
5142 unallocated_encoding(s
);
5147 tcg_val
= cpu_reg(s
, rm
);
5161 g_assert_not_reached();
5163 tcg_val
= new_tmp_a64(s
);
5164 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
5167 tcg_acc
= cpu_reg(s
, rn
);
5168 tcg_bytes
= tcg_const_i32(1 << sz
);
5171 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5173 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5176 tcg_temp_free_i32(tcg_bytes
);
5179 /* Data-processing (2 source)
5180 * 31 30 29 28 21 20 16 15 10 9 5 4 0
5181 * +----+---+---+-----------------+------+--------+------+------+
5182 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
5183 * +----+---+---+-----------------+------+--------+------+------+
5185 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
5187 unsigned int sf
, rm
, opcode
, rn
, rd
;
5188 sf
= extract32(insn
, 31, 1);
5189 rm
= extract32(insn
, 16, 5);
5190 opcode
= extract32(insn
, 10, 6);
5191 rn
= extract32(insn
, 5, 5);
5192 rd
= extract32(insn
, 0, 5);
5194 if (extract32(insn
, 29, 1)) {
5195 unallocated_encoding(s
);
5201 handle_div(s
, false, sf
, rm
, rn
, rd
);
5204 handle_div(s
, true, sf
, rm
, rn
, rd
);
5207 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
5210 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
5213 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
5216 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
5218 case 12: /* PACGA */
5219 if (sf
== 0 || !dc_isar_feature(aa64_pauth
, s
)) {
5220 goto do_unallocated
;
5222 gen_helper_pacga(cpu_reg(s
, rd
), cpu_env
,
5223 cpu_reg(s
, rn
), cpu_reg_sp(s
, rm
));
5232 case 23: /* CRC32 */
5234 int sz
= extract32(opcode
, 0, 2);
5235 bool crc32c
= extract32(opcode
, 2, 1);
5236 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
5241 unallocated_encoding(s
);
5247 * Data processing - register
5248 * 31 30 29 28 25 21 20 16 10 0
5249 * +--+---+--+---+-------+-----+-------+-------+---------+
5250 * | |op0| |op1| 1 0 1 | op2 | | op3 | |
5251 * +--+---+--+---+-------+-----+-------+-------+---------+
5253 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
5255 int op0
= extract32(insn
, 30, 1);
5256 int op1
= extract32(insn
, 28, 1);
5257 int op2
= extract32(insn
, 21, 4);
5258 int op3
= extract32(insn
, 10, 6);
5263 /* Add/sub (extended register) */
5264 disas_add_sub_ext_reg(s
, insn
);
5266 /* Add/sub (shifted register) */
5267 disas_add_sub_reg(s
, insn
);
5270 /* Logical (shifted register) */
5271 disas_logic_reg(s
, insn
);
5279 case 0x00: /* Add/subtract (with carry) */
5280 disas_adc_sbc(s
, insn
);
5283 case 0x01: /* Rotate right into flags */
5285 disas_rotate_right_into_flags(s
, insn
);
5288 case 0x02: /* Evaluate into flags */
5292 disas_evaluate_into_flags(s
, insn
);
5296 goto do_unallocated
;
5300 case 0x2: /* Conditional compare */
5301 disas_cc(s
, insn
); /* both imm and reg forms */
5304 case 0x4: /* Conditional select */
5305 disas_cond_select(s
, insn
);
5308 case 0x6: /* Data-processing */
5309 if (op0
) { /* (1 source) */
5310 disas_data_proc_1src(s
, insn
);
5311 } else { /* (2 source) */
5312 disas_data_proc_2src(s
, insn
);
5315 case 0x8 ... 0xf: /* (3 source) */
5316 disas_data_proc_3src(s
, insn
);
5321 unallocated_encoding(s
);
5326 static void handle_fp_compare(DisasContext
*s
, int size
,
5327 unsigned int rn
, unsigned int rm
,
5328 bool cmp_with_zero
, bool signal_all_nans
)
5330 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
5331 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
5333 if (size
== MO_64
) {
5334 TCGv_i64 tcg_vn
, tcg_vm
;
5336 tcg_vn
= read_fp_dreg(s
, rn
);
5337 if (cmp_with_zero
) {
5338 tcg_vm
= tcg_const_i64(0);
5340 tcg_vm
= read_fp_dreg(s
, rm
);
5342 if (signal_all_nans
) {
5343 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5345 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5347 tcg_temp_free_i64(tcg_vn
);
5348 tcg_temp_free_i64(tcg_vm
);
5350 TCGv_i32 tcg_vn
= tcg_temp_new_i32();
5351 TCGv_i32 tcg_vm
= tcg_temp_new_i32();
5353 read_vec_element_i32(s
, tcg_vn
, rn
, 0, size
);
5354 if (cmp_with_zero
) {
5355 tcg_gen_movi_i32(tcg_vm
, 0);
5357 read_vec_element_i32(s
, tcg_vm
, rm
, 0, size
);
5362 if (signal_all_nans
) {
5363 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5365 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5369 if (signal_all_nans
) {
5370 gen_helper_vfp_cmpeh_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5372 gen_helper_vfp_cmph_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5376 g_assert_not_reached();
5379 tcg_temp_free_i32(tcg_vn
);
5380 tcg_temp_free_i32(tcg_vm
);
5383 tcg_temp_free_ptr(fpst
);
5385 gen_set_nzcv(tcg_flags
);
5387 tcg_temp_free_i64(tcg_flags
);
5390 /* Floating point compare
5391 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
5392 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5393 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
5394 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5396 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
5398 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
5401 mos
= extract32(insn
, 29, 3);
5402 type
= extract32(insn
, 22, 2);
5403 rm
= extract32(insn
, 16, 5);
5404 op
= extract32(insn
, 14, 2);
5405 rn
= extract32(insn
, 5, 5);
5406 opc
= extract32(insn
, 3, 2);
5407 op2r
= extract32(insn
, 0, 3);
5409 if (mos
|| op
|| op2r
) {
5410 unallocated_encoding(s
);
5423 if (dc_isar_feature(aa64_fp16
, s
)) {
5428 unallocated_encoding(s
);
5432 if (!fp_access_check(s
)) {
5436 handle_fp_compare(s
, size
, rn
, rm
, opc
& 1, opc
& 2);
5439 /* Floating point conditional compare
5440 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
5441 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5442 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
5443 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5445 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
5447 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
5449 TCGLabel
*label_continue
= NULL
;
5452 mos
= extract32(insn
, 29, 3);
5453 type
= extract32(insn
, 22, 2);
5454 rm
= extract32(insn
, 16, 5);
5455 cond
= extract32(insn
, 12, 4);
5456 rn
= extract32(insn
, 5, 5);
5457 op
= extract32(insn
, 4, 1);
5458 nzcv
= extract32(insn
, 0, 4);
5461 unallocated_encoding(s
);
5474 if (dc_isar_feature(aa64_fp16
, s
)) {
5479 unallocated_encoding(s
);
5483 if (!fp_access_check(s
)) {
5487 if (cond
< 0x0e) { /* not always */
5488 TCGLabel
*label_match
= gen_new_label();
5489 label_continue
= gen_new_label();
5490 arm_gen_test_cc(cond
, label_match
);
5492 tcg_flags
= tcg_const_i64(nzcv
<< 28);
5493 gen_set_nzcv(tcg_flags
);
5494 tcg_temp_free_i64(tcg_flags
);
5495 tcg_gen_br(label_continue
);
5496 gen_set_label(label_match
);
5499 handle_fp_compare(s
, size
, rn
, rm
, false, op
);
5502 gen_set_label(label_continue
);
5506 /* Floating point conditional select
5507 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5508 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5509 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
5510 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5512 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
5514 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
5515 TCGv_i64 t_true
, t_false
, t_zero
;
5519 mos
= extract32(insn
, 29, 3);
5520 type
= extract32(insn
, 22, 2);
5521 rm
= extract32(insn
, 16, 5);
5522 cond
= extract32(insn
, 12, 4);
5523 rn
= extract32(insn
, 5, 5);
5524 rd
= extract32(insn
, 0, 5);
5527 unallocated_encoding(s
);
5540 if (dc_isar_feature(aa64_fp16
, s
)) {
5545 unallocated_encoding(s
);
5549 if (!fp_access_check(s
)) {
5553 /* Zero extend sreg & hreg inputs to 64 bits now. */
5554 t_true
= tcg_temp_new_i64();
5555 t_false
= tcg_temp_new_i64();
5556 read_vec_element(s
, t_true
, rn
, 0, sz
);
5557 read_vec_element(s
, t_false
, rm
, 0, sz
);
5559 a64_test_cc(&c
, cond
);
5560 t_zero
= tcg_const_i64(0);
5561 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, t_zero
, t_true
, t_false
);
5562 tcg_temp_free_i64(t_zero
);
5563 tcg_temp_free_i64(t_false
);
5566 /* Note that sregs & hregs write back zeros to the high bits,
5567 and we've already done the zero-extension. */
5568 write_fp_dreg(s
, rd
, t_true
);
5569 tcg_temp_free_i64(t_true
);
5572 /* Floating-point data-processing (1 source) - half precision */
5573 static void handle_fp_1src_half(DisasContext
*s
, int opcode
, int rd
, int rn
)
5575 TCGv_ptr fpst
= NULL
;
5576 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
5577 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5580 case 0x0: /* FMOV */
5581 tcg_gen_mov_i32(tcg_res
, tcg_op
);
5583 case 0x1: /* FABS */
5584 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
5586 case 0x2: /* FNEG */
5587 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
5589 case 0x3: /* FSQRT */
5590 fpst
= get_fpstatus_ptr(true);
5591 gen_helper_sqrt_f16(tcg_res
, tcg_op
, fpst
);
5593 case 0x8: /* FRINTN */
5594 case 0x9: /* FRINTP */
5595 case 0xa: /* FRINTM */
5596 case 0xb: /* FRINTZ */
5597 case 0xc: /* FRINTA */
5599 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
5600 fpst
= get_fpstatus_ptr(true);
5602 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5603 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
5605 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5606 tcg_temp_free_i32(tcg_rmode
);
5609 case 0xe: /* FRINTX */
5610 fpst
= get_fpstatus_ptr(true);
5611 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, fpst
);
5613 case 0xf: /* FRINTI */
5614 fpst
= get_fpstatus_ptr(true);
5615 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
5621 write_fp_sreg(s
, rd
, tcg_res
);
5624 tcg_temp_free_ptr(fpst
);
5626 tcg_temp_free_i32(tcg_op
);
5627 tcg_temp_free_i32(tcg_res
);
5630 /* Floating-point data-processing (1 source) - single precision */
5631 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
5637 fpst
= get_fpstatus_ptr(false);
5638 tcg_op
= read_fp_sreg(s
, rn
);
5639 tcg_res
= tcg_temp_new_i32();
5642 case 0x0: /* FMOV */
5643 tcg_gen_mov_i32(tcg_res
, tcg_op
);
5645 case 0x1: /* FABS */
5646 gen_helper_vfp_abss(tcg_res
, tcg_op
);
5648 case 0x2: /* FNEG */
5649 gen_helper_vfp_negs(tcg_res
, tcg_op
);
5651 case 0x3: /* FSQRT */
5652 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
5654 case 0x8: /* FRINTN */
5655 case 0x9: /* FRINTP */
5656 case 0xa: /* FRINTM */
5657 case 0xb: /* FRINTZ */
5658 case 0xc: /* FRINTA */
5660 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
5662 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5663 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
5665 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5666 tcg_temp_free_i32(tcg_rmode
);
5669 case 0xe: /* FRINTX */
5670 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
5672 case 0xf: /* FRINTI */
5673 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
5679 write_fp_sreg(s
, rd
, tcg_res
);
5681 tcg_temp_free_ptr(fpst
);
5682 tcg_temp_free_i32(tcg_op
);
5683 tcg_temp_free_i32(tcg_res
);
5686 /* Floating-point data-processing (1 source) - double precision */
5687 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
5694 case 0x0: /* FMOV */
5695 gen_gvec_fn2(s
, false, rd
, rn
, tcg_gen_gvec_mov
, 0);
5699 fpst
= get_fpstatus_ptr(false);
5700 tcg_op
= read_fp_dreg(s
, rn
);
5701 tcg_res
= tcg_temp_new_i64();
5704 case 0x1: /* FABS */
5705 gen_helper_vfp_absd(tcg_res
, tcg_op
);
5707 case 0x2: /* FNEG */
5708 gen_helper_vfp_negd(tcg_res
, tcg_op
);
5710 case 0x3: /* FSQRT */
5711 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
5713 case 0x8: /* FRINTN */
5714 case 0x9: /* FRINTP */
5715 case 0xa: /* FRINTM */
5716 case 0xb: /* FRINTZ */
5717 case 0xc: /* FRINTA */
5719 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
5721 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5722 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
5724 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5725 tcg_temp_free_i32(tcg_rmode
);
5728 case 0xe: /* FRINTX */
5729 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
5731 case 0xf: /* FRINTI */
5732 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
5738 write_fp_dreg(s
, rd
, tcg_res
);
5740 tcg_temp_free_ptr(fpst
);
5741 tcg_temp_free_i64(tcg_op
);
5742 tcg_temp_free_i64(tcg_res
);
5745 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
5746 int rd
, int rn
, int dtype
, int ntype
)
5751 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5753 /* Single to double */
5754 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5755 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
5756 write_fp_dreg(s
, rd
, tcg_rd
);
5757 tcg_temp_free_i64(tcg_rd
);
5759 /* Single to half */
5760 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5761 TCGv_i32 ahp
= get_ahp_flag();
5762 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5764 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5765 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5766 write_fp_sreg(s
, rd
, tcg_rd
);
5767 tcg_temp_free_i32(tcg_rd
);
5768 tcg_temp_free_i32(ahp
);
5769 tcg_temp_free_ptr(fpst
);
5771 tcg_temp_free_i32(tcg_rn
);
5776 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
5777 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5779 /* Double to single */
5780 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
5782 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5783 TCGv_i32 ahp
= get_ahp_flag();
5784 /* Double to half */
5785 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5786 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5787 tcg_temp_free_ptr(fpst
);
5788 tcg_temp_free_i32(ahp
);
5790 write_fp_sreg(s
, rd
, tcg_rd
);
5791 tcg_temp_free_i32(tcg_rd
);
5792 tcg_temp_free_i64(tcg_rn
);
5797 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5798 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(false);
5799 TCGv_i32 tcg_ahp
= get_ahp_flag();
5800 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
5802 /* Half to single */
5803 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5804 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5805 write_fp_sreg(s
, rd
, tcg_rd
);
5806 tcg_temp_free_ptr(tcg_fpst
);
5807 tcg_temp_free_i32(tcg_ahp
);
5808 tcg_temp_free_i32(tcg_rd
);
5810 /* Half to double */
5811 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5812 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5813 write_fp_dreg(s
, rd
, tcg_rd
);
5814 tcg_temp_free_i64(tcg_rd
);
5816 tcg_temp_free_i32(tcg_rn
);
5824 /* Floating point data-processing (1 source)
5825 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
5826 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5827 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
5828 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5830 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
5832 int mos
= extract32(insn
, 29, 3);
5833 int type
= extract32(insn
, 22, 2);
5834 int opcode
= extract32(insn
, 15, 6);
5835 int rn
= extract32(insn
, 5, 5);
5836 int rd
= extract32(insn
, 0, 5);
5839 unallocated_encoding(s
);
5844 case 0x4: case 0x5: case 0x7:
5846 /* FCVT between half, single and double precision */
5847 int dtype
= extract32(opcode
, 0, 2);
5848 if (type
== 2 || dtype
== type
) {
5849 unallocated_encoding(s
);
5852 if (!fp_access_check(s
)) {
5856 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
5862 /* 32-to-32 and 64-to-64 ops */
5865 if (!fp_access_check(s
)) {
5869 handle_fp_1src_single(s
, opcode
, rd
, rn
);
5872 if (!fp_access_check(s
)) {
5876 handle_fp_1src_double(s
, opcode
, rd
, rn
);
5879 if (!dc_isar_feature(aa64_fp16
, s
)) {
5880 unallocated_encoding(s
);
5884 if (!fp_access_check(s
)) {
5888 handle_fp_1src_half(s
, opcode
, rd
, rn
);
5891 unallocated_encoding(s
);
5895 unallocated_encoding(s
);
5900 /* Floating-point data-processing (2 source) - single precision */
5901 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
5902 int rd
, int rn
, int rm
)
5909 tcg_res
= tcg_temp_new_i32();
5910 fpst
= get_fpstatus_ptr(false);
5911 tcg_op1
= read_fp_sreg(s
, rn
);
5912 tcg_op2
= read_fp_sreg(s
, rm
);
5915 case 0x0: /* FMUL */
5916 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5918 case 0x1: /* FDIV */
5919 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5921 case 0x2: /* FADD */
5922 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5924 case 0x3: /* FSUB */
5925 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5927 case 0x4: /* FMAX */
5928 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5930 case 0x5: /* FMIN */
5931 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5933 case 0x6: /* FMAXNM */
5934 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5936 case 0x7: /* FMINNM */
5937 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5939 case 0x8: /* FNMUL */
5940 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5941 gen_helper_vfp_negs(tcg_res
, tcg_res
);
5945 write_fp_sreg(s
, rd
, tcg_res
);
5947 tcg_temp_free_ptr(fpst
);
5948 tcg_temp_free_i32(tcg_op1
);
5949 tcg_temp_free_i32(tcg_op2
);
5950 tcg_temp_free_i32(tcg_res
);
5953 /* Floating-point data-processing (2 source) - double precision */
5954 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
5955 int rd
, int rn
, int rm
)
5962 tcg_res
= tcg_temp_new_i64();
5963 fpst
= get_fpstatus_ptr(false);
5964 tcg_op1
= read_fp_dreg(s
, rn
);
5965 tcg_op2
= read_fp_dreg(s
, rm
);
5968 case 0x0: /* FMUL */
5969 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5971 case 0x1: /* FDIV */
5972 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5974 case 0x2: /* FADD */
5975 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5977 case 0x3: /* FSUB */
5978 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5980 case 0x4: /* FMAX */
5981 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5983 case 0x5: /* FMIN */
5984 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5986 case 0x6: /* FMAXNM */
5987 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5989 case 0x7: /* FMINNM */
5990 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5992 case 0x8: /* FNMUL */
5993 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5994 gen_helper_vfp_negd(tcg_res
, tcg_res
);
5998 write_fp_dreg(s
, rd
, tcg_res
);
6000 tcg_temp_free_ptr(fpst
);
6001 tcg_temp_free_i64(tcg_op1
);
6002 tcg_temp_free_i64(tcg_op2
);
6003 tcg_temp_free_i64(tcg_res
);
6006 /* Floating-point data-processing (2 source) - half precision */
6007 static void handle_fp_2src_half(DisasContext
*s
, int opcode
,
6008 int rd
, int rn
, int rm
)
6015 tcg_res
= tcg_temp_new_i32();
6016 fpst
= get_fpstatus_ptr(true);
6017 tcg_op1
= read_fp_hreg(s
, rn
);
6018 tcg_op2
= read_fp_hreg(s
, rm
);
6021 case 0x0: /* FMUL */
6022 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6024 case 0x1: /* FDIV */
6025 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6027 case 0x2: /* FADD */
6028 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6030 case 0x3: /* FSUB */
6031 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6033 case 0x4: /* FMAX */
6034 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6036 case 0x5: /* FMIN */
6037 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6039 case 0x6: /* FMAXNM */
6040 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6042 case 0x7: /* FMINNM */
6043 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6045 case 0x8: /* FNMUL */
6046 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6047 tcg_gen_xori_i32(tcg_res
, tcg_res
, 0x8000);
6050 g_assert_not_reached();
6053 write_fp_sreg(s
, rd
, tcg_res
);
6055 tcg_temp_free_ptr(fpst
);
6056 tcg_temp_free_i32(tcg_op1
);
6057 tcg_temp_free_i32(tcg_op2
);
6058 tcg_temp_free_i32(tcg_res
);
6061 /* Floating point data-processing (2 source)
6062 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6063 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6064 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
6065 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
6067 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
6069 int mos
= extract32(insn
, 29, 3);
6070 int type
= extract32(insn
, 22, 2);
6071 int rd
= extract32(insn
, 0, 5);
6072 int rn
= extract32(insn
, 5, 5);
6073 int rm
= extract32(insn
, 16, 5);
6074 int opcode
= extract32(insn
, 12, 4);
6076 if (opcode
> 8 || mos
) {
6077 unallocated_encoding(s
);
6083 if (!fp_access_check(s
)) {
6086 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
6089 if (!fp_access_check(s
)) {
6092 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
6095 if (!dc_isar_feature(aa64_fp16
, s
)) {
6096 unallocated_encoding(s
);
6099 if (!fp_access_check(s
)) {
6102 handle_fp_2src_half(s
, opcode
, rd
, rn
, rm
);
6105 unallocated_encoding(s
);
6109 /* Floating-point data-processing (3 source) - single precision */
6110 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
6111 int rd
, int rn
, int rm
, int ra
)
6113 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
6114 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6115 TCGv_ptr fpst
= get_fpstatus_ptr(false);
6117 tcg_op1
= read_fp_sreg(s
, rn
);
6118 tcg_op2
= read_fp_sreg(s
, rm
);
6119 tcg_op3
= read_fp_sreg(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_negs(tcg_op3
, tcg_op3
);
6133 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
6136 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6138 write_fp_sreg(s
, rd
, tcg_res
);
6140 tcg_temp_free_ptr(fpst
);
6141 tcg_temp_free_i32(tcg_op1
);
6142 tcg_temp_free_i32(tcg_op2
);
6143 tcg_temp_free_i32(tcg_op3
);
6144 tcg_temp_free_i32(tcg_res
);
6147 /* Floating-point data-processing (3 source) - double precision */
6148 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
6149 int rd
, int rn
, int rm
, int ra
)
6151 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
6152 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6153 TCGv_ptr fpst
= get_fpstatus_ptr(false);
6155 tcg_op1
= read_fp_dreg(s
, rn
);
6156 tcg_op2
= read_fp_dreg(s
, rm
);
6157 tcg_op3
= read_fp_dreg(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 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
6171 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
6174 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6176 write_fp_dreg(s
, rd
, tcg_res
);
6178 tcg_temp_free_ptr(fpst
);
6179 tcg_temp_free_i64(tcg_op1
);
6180 tcg_temp_free_i64(tcg_op2
);
6181 tcg_temp_free_i64(tcg_op3
);
6182 tcg_temp_free_i64(tcg_res
);
6185 /* Floating-point data-processing (3 source) - half precision */
6186 static void handle_fp_3src_half(DisasContext
*s
, bool o0
, bool o1
,
6187 int rd
, int rn
, int rm
, int ra
)
6189 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
6190 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6191 TCGv_ptr fpst
= get_fpstatus_ptr(true);
6193 tcg_op1
= read_fp_hreg(s
, rn
);
6194 tcg_op2
= read_fp_hreg(s
, rm
);
6195 tcg_op3
= read_fp_hreg(s
, ra
);
6197 /* These are fused multiply-add, and must be done as one
6198 * floating point operation with no rounding between the
6199 * multiplication and addition steps.
6200 * NB that doing the negations here as separate steps is
6201 * correct : an input NaN should come out with its sign bit
6202 * flipped if it is a negated-input.
6205 tcg_gen_xori_i32(tcg_op3
, tcg_op3
, 0x8000);
6209 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
6212 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6214 write_fp_sreg(s
, rd
, tcg_res
);
6216 tcg_temp_free_ptr(fpst
);
6217 tcg_temp_free_i32(tcg_op1
);
6218 tcg_temp_free_i32(tcg_op2
);
6219 tcg_temp_free_i32(tcg_op3
);
6220 tcg_temp_free_i32(tcg_res
);
6223 /* Floating point data-processing (3 source)
6224 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
6225 * +---+---+---+-----------+------+----+------+----+------+------+------+
6226 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
6227 * +---+---+---+-----------+------+----+------+----+------+------+------+
6229 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
6231 int mos
= extract32(insn
, 29, 3);
6232 int type
= extract32(insn
, 22, 2);
6233 int rd
= extract32(insn
, 0, 5);
6234 int rn
= extract32(insn
, 5, 5);
6235 int ra
= extract32(insn
, 10, 5);
6236 int rm
= extract32(insn
, 16, 5);
6237 bool o0
= extract32(insn
, 15, 1);
6238 bool o1
= extract32(insn
, 21, 1);
6241 unallocated_encoding(s
);
6247 if (!fp_access_check(s
)) {
6250 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6253 if (!fp_access_check(s
)) {
6256 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6259 if (!dc_isar_feature(aa64_fp16
, s
)) {
6260 unallocated_encoding(s
);
6263 if (!fp_access_check(s
)) {
6266 handle_fp_3src_half(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6269 unallocated_encoding(s
);
6273 /* The imm8 encodes the sign bit, enough bits to represent an exponent in
6274 * the range 01....1xx to 10....0xx, and the most significant 4 bits of
6275 * the mantissa; see VFPExpandImm() in the v8 ARM ARM.
6277 uint64_t vfp_expand_imm(int size
, uint8_t imm8
)
6283 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
6284 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
6285 extract32(imm8
, 0, 6);
6289 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
6290 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
6291 (extract32(imm8
, 0, 6) << 3);
6295 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
6296 (extract32(imm8
, 6, 1) ? 0x3000 : 0x4000) |
6297 (extract32(imm8
, 0, 6) << 6);
6300 g_assert_not_reached();
6305 /* Floating point immediate
6306 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
6307 * +---+---+---+-----------+------+---+------------+-------+------+------+
6308 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
6309 * +---+---+---+-----------+------+---+------------+-------+------+------+
6311 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
6313 int rd
= extract32(insn
, 0, 5);
6314 int imm5
= extract32(insn
, 5, 5);
6315 int imm8
= extract32(insn
, 13, 8);
6316 int type
= extract32(insn
, 22, 2);
6317 int mos
= extract32(insn
, 29, 3);
6323 unallocated_encoding(s
);
6336 if (dc_isar_feature(aa64_fp16
, s
)) {
6341 unallocated_encoding(s
);
6345 if (!fp_access_check(s
)) {
6349 imm
= vfp_expand_imm(sz
, imm8
);
6351 tcg_res
= tcg_const_i64(imm
);
6352 write_fp_dreg(s
, rd
, tcg_res
);
6353 tcg_temp_free_i64(tcg_res
);
6356 /* Handle floating point <=> fixed point conversions. Note that we can
6357 * also deal with fp <=> integer conversions as a special case (scale == 64)
6358 * OPTME: consider handling that special case specially or at least skipping
6359 * the call to scalbn in the helpers for zero shifts.
6361 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
6362 bool itof
, int rmode
, int scale
, int sf
, int type
)
6364 bool is_signed
= !(opcode
& 1);
6365 TCGv_ptr tcg_fpstatus
;
6366 TCGv_i32 tcg_shift
, tcg_single
;
6367 TCGv_i64 tcg_double
;
6369 tcg_fpstatus
= get_fpstatus_ptr(type
== 3);
6371 tcg_shift
= tcg_const_i32(64 - scale
);
6374 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
6376 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
6379 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
6381 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
6384 tcg_int
= tcg_extend
;
6388 case 1: /* float64 */
6389 tcg_double
= tcg_temp_new_i64();
6391 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6392 tcg_shift
, tcg_fpstatus
);
6394 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6395 tcg_shift
, tcg_fpstatus
);
6397 write_fp_dreg(s
, rd
, tcg_double
);
6398 tcg_temp_free_i64(tcg_double
);
6401 case 0: /* float32 */
6402 tcg_single
= tcg_temp_new_i32();
6404 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6405 tcg_shift
, tcg_fpstatus
);
6407 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6408 tcg_shift
, tcg_fpstatus
);
6410 write_fp_sreg(s
, rd
, tcg_single
);
6411 tcg_temp_free_i32(tcg_single
);
6414 case 3: /* float16 */
6415 tcg_single
= tcg_temp_new_i32();
6417 gen_helper_vfp_sqtoh(tcg_single
, tcg_int
,
6418 tcg_shift
, tcg_fpstatus
);
6420 gen_helper_vfp_uqtoh(tcg_single
, tcg_int
,
6421 tcg_shift
, tcg_fpstatus
);
6423 write_fp_sreg(s
, rd
, tcg_single
);
6424 tcg_temp_free_i32(tcg_single
);
6428 g_assert_not_reached();
6431 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
6434 if (extract32(opcode
, 2, 1)) {
6435 /* There are too many rounding modes to all fit into rmode,
6436 * so FCVTA[US] is a special case.
6438 rmode
= FPROUNDING_TIEAWAY
;
6441 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
6443 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
6446 case 1: /* float64 */
6447 tcg_double
= read_fp_dreg(s
, rn
);
6450 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
6451 tcg_shift
, tcg_fpstatus
);
6453 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
6454 tcg_shift
, tcg_fpstatus
);
6458 gen_helper_vfp_tould(tcg_int
, tcg_double
,
6459 tcg_shift
, tcg_fpstatus
);
6461 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
6462 tcg_shift
, tcg_fpstatus
);
6466 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
6468 tcg_temp_free_i64(tcg_double
);
6471 case 0: /* float32 */
6472 tcg_single
= read_fp_sreg(s
, rn
);
6475 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
6476 tcg_shift
, tcg_fpstatus
);
6478 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
6479 tcg_shift
, tcg_fpstatus
);
6482 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
6484 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
6485 tcg_shift
, tcg_fpstatus
);
6487 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
6488 tcg_shift
, tcg_fpstatus
);
6490 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
6491 tcg_temp_free_i32(tcg_dest
);
6493 tcg_temp_free_i32(tcg_single
);
6496 case 3: /* float16 */
6497 tcg_single
= read_fp_sreg(s
, rn
);
6500 gen_helper_vfp_tosqh(tcg_int
, tcg_single
,
6501 tcg_shift
, tcg_fpstatus
);
6503 gen_helper_vfp_touqh(tcg_int
, tcg_single
,
6504 tcg_shift
, tcg_fpstatus
);
6507 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
6509 gen_helper_vfp_toslh(tcg_dest
, tcg_single
,
6510 tcg_shift
, tcg_fpstatus
);
6512 gen_helper_vfp_toulh(tcg_dest
, tcg_single
,
6513 tcg_shift
, tcg_fpstatus
);
6515 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
6516 tcg_temp_free_i32(tcg_dest
);
6518 tcg_temp_free_i32(tcg_single
);
6522 g_assert_not_reached();
6525 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
6526 tcg_temp_free_i32(tcg_rmode
);
6529 tcg_temp_free_ptr(tcg_fpstatus
);
6530 tcg_temp_free_i32(tcg_shift
);
6533 /* Floating point <-> fixed point conversions
6534 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6535 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6536 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
6537 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6539 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
6541 int rd
= extract32(insn
, 0, 5);
6542 int rn
= extract32(insn
, 5, 5);
6543 int scale
= extract32(insn
, 10, 6);
6544 int opcode
= extract32(insn
, 16, 3);
6545 int rmode
= extract32(insn
, 19, 2);
6546 int type
= extract32(insn
, 22, 2);
6547 bool sbit
= extract32(insn
, 29, 1);
6548 bool sf
= extract32(insn
, 31, 1);
6551 if (sbit
|| (!sf
&& scale
< 32)) {
6552 unallocated_encoding(s
);
6557 case 0: /* float32 */
6558 case 1: /* float64 */
6560 case 3: /* float16 */
6561 if (dc_isar_feature(aa64_fp16
, s
)) {
6566 unallocated_encoding(s
);
6570 switch ((rmode
<< 3) | opcode
) {
6571 case 0x2: /* SCVTF */
6572 case 0x3: /* UCVTF */
6575 case 0x18: /* FCVTZS */
6576 case 0x19: /* FCVTZU */
6580 unallocated_encoding(s
);
6584 if (!fp_access_check(s
)) {
6588 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
6591 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
6593 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
6594 * without conversion.
6598 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
6604 tmp
= tcg_temp_new_i64();
6605 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
6606 write_fp_dreg(s
, rd
, tmp
);
6607 tcg_temp_free_i64(tmp
);
6611 write_fp_dreg(s
, rd
, tcg_rn
);
6614 /* 64 bit to top half. */
6615 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
6616 clear_vec_high(s
, true, rd
);
6620 tmp
= tcg_temp_new_i64();
6621 tcg_gen_ext16u_i64(tmp
, tcg_rn
);
6622 write_fp_dreg(s
, rd
, tmp
);
6623 tcg_temp_free_i64(tmp
);
6626 g_assert_not_reached();
6629 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
6634 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
6638 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
6641 /* 64 bits from top half */
6642 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
6646 tcg_gen_ld16u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_16
));
6649 g_assert_not_reached();
6654 static void handle_fjcvtzs(DisasContext
*s
, int rd
, int rn
)
6656 TCGv_i64 t
= read_fp_dreg(s
, rn
);
6657 TCGv_ptr fpstatus
= get_fpstatus_ptr(false);
6659 gen_helper_fjcvtzs(t
, t
, fpstatus
);
6661 tcg_temp_free_ptr(fpstatus
);
6663 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), t
);
6664 tcg_gen_extrh_i64_i32(cpu_ZF
, t
);
6665 tcg_gen_movi_i32(cpu_CF
, 0);
6666 tcg_gen_movi_i32(cpu_NF
, 0);
6667 tcg_gen_movi_i32(cpu_VF
, 0);
6669 tcg_temp_free_i64(t
);
6672 /* Floating point <-> integer conversions
6673 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6674 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6675 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
6676 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6678 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
6680 int rd
= extract32(insn
, 0, 5);
6681 int rn
= extract32(insn
, 5, 5);
6682 int opcode
= extract32(insn
, 16, 3);
6683 int rmode
= extract32(insn
, 19, 2);
6684 int type
= extract32(insn
, 22, 2);
6685 bool sbit
= extract32(insn
, 29, 1);
6686 bool sf
= extract32(insn
, 31, 1);
6690 goto do_unallocated
;
6698 case 4: /* FCVTAS */
6699 case 5: /* FCVTAU */
6701 goto do_unallocated
;
6704 case 0: /* FCVT[NPMZ]S */
6705 case 1: /* FCVT[NPMZ]U */
6707 case 0: /* float32 */
6708 case 1: /* float64 */
6710 case 3: /* float16 */
6711 if (!dc_isar_feature(aa64_fp16
, s
)) {
6712 goto do_unallocated
;
6716 goto do_unallocated
;
6718 if (!fp_access_check(s
)) {
6721 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
6725 switch (sf
<< 7 | type
<< 5 | rmode
<< 3 | opcode
) {
6726 case 0b01100110: /* FMOV half <-> 32-bit int */
6728 case 0b11100110: /* FMOV half <-> 64-bit int */
6730 if (!dc_isar_feature(aa64_fp16
, s
)) {
6731 goto do_unallocated
;
6734 case 0b00000110: /* FMOV 32-bit */
6736 case 0b10100110: /* FMOV 64-bit */
6738 case 0b11001110: /* FMOV top half of 128-bit */
6740 if (!fp_access_check(s
)) {
6744 handle_fmov(s
, rd
, rn
, type
, itof
);
6747 case 0b00111110: /* FJCVTZS */
6748 if (!dc_isar_feature(aa64_jscvt
, s
)) {
6749 goto do_unallocated
;
6750 } else if (fp_access_check(s
)) {
6751 handle_fjcvtzs(s
, rd
, rn
);
6757 unallocated_encoding(s
);
6764 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
6765 * 31 30 29 28 25 24 0
6766 * +---+---+---+---------+-----------------------------+
6767 * | | 0 | | 1 1 1 1 | |
6768 * +---+---+---+---------+-----------------------------+
6770 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
6772 if (extract32(insn
, 24, 1)) {
6773 /* Floating point data-processing (3 source) */
6774 disas_fp_3src(s
, insn
);
6775 } else if (extract32(insn
, 21, 1) == 0) {
6776 /* Floating point to fixed point conversions */
6777 disas_fp_fixed_conv(s
, insn
);
6779 switch (extract32(insn
, 10, 2)) {
6781 /* Floating point conditional compare */
6782 disas_fp_ccomp(s
, insn
);
6785 /* Floating point data-processing (2 source) */
6786 disas_fp_2src(s
, insn
);
6789 /* Floating point conditional select */
6790 disas_fp_csel(s
, insn
);
6793 switch (ctz32(extract32(insn
, 12, 4))) {
6794 case 0: /* [15:12] == xxx1 */
6795 /* Floating point immediate */
6796 disas_fp_imm(s
, insn
);
6798 case 1: /* [15:12] == xx10 */
6799 /* Floating point compare */
6800 disas_fp_compare(s
, insn
);
6802 case 2: /* [15:12] == x100 */
6803 /* Floating point data-processing (1 source) */
6804 disas_fp_1src(s
, insn
);
6806 case 3: /* [15:12] == 1000 */
6807 unallocated_encoding(s
);
6809 default: /* [15:12] == 0000 */
6810 /* Floating point <-> integer conversions */
6811 disas_fp_int_conv(s
, insn
);
6819 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
6822 /* Extract 64 bits from the middle of two concatenated 64 bit
6823 * vector register slices left:right. The extracted bits start
6824 * at 'pos' bits into the right (least significant) side.
6825 * We return the result in tcg_right, and guarantee not to
6828 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
6829 assert(pos
> 0 && pos
< 64);
6831 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
6832 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
6833 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
6835 tcg_temp_free_i64(tcg_tmp
);
6839 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
6840 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6841 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
6842 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6844 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
6846 int is_q
= extract32(insn
, 30, 1);
6847 int op2
= extract32(insn
, 22, 2);
6848 int imm4
= extract32(insn
, 11, 4);
6849 int rm
= extract32(insn
, 16, 5);
6850 int rn
= extract32(insn
, 5, 5);
6851 int rd
= extract32(insn
, 0, 5);
6852 int pos
= imm4
<< 3;
6853 TCGv_i64 tcg_resl
, tcg_resh
;
6855 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
6856 unallocated_encoding(s
);
6860 if (!fp_access_check(s
)) {
6864 tcg_resh
= tcg_temp_new_i64();
6865 tcg_resl
= tcg_temp_new_i64();
6867 /* Vd gets bits starting at pos bits into Vm:Vn. This is
6868 * either extracting 128 bits from a 128:128 concatenation, or
6869 * extracting 64 bits from a 64:64 concatenation.
6872 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
6874 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
6875 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6877 tcg_gen_movi_i64(tcg_resh
, 0);
6884 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
6885 EltPosns
*elt
= eltposns
;
6892 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
6894 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
6897 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6898 tcg_hh
= tcg_temp_new_i64();
6899 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
6900 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
6901 tcg_temp_free_i64(tcg_hh
);
6905 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6906 tcg_temp_free_i64(tcg_resl
);
6907 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6908 tcg_temp_free_i64(tcg_resh
);
6912 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
6913 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6914 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
6915 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6917 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
6919 int op2
= extract32(insn
, 22, 2);
6920 int is_q
= extract32(insn
, 30, 1);
6921 int rm
= extract32(insn
, 16, 5);
6922 int rn
= extract32(insn
, 5, 5);
6923 int rd
= extract32(insn
, 0, 5);
6924 int is_tblx
= extract32(insn
, 12, 1);
6925 int len
= extract32(insn
, 13, 2);
6926 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
6927 TCGv_i32 tcg_regno
, tcg_numregs
;
6930 unallocated_encoding(s
);
6934 if (!fp_access_check(s
)) {
6938 /* This does a table lookup: for every byte element in the input
6939 * we index into a table formed from up to four vector registers,
6940 * and then the output is the result of the lookups. Our helper
6941 * function does the lookup operation for a single 64 bit part of
6944 tcg_resl
= tcg_temp_new_i64();
6945 tcg_resh
= tcg_temp_new_i64();
6948 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6950 tcg_gen_movi_i64(tcg_resl
, 0);
6952 if (is_tblx
&& is_q
) {
6953 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6955 tcg_gen_movi_i64(tcg_resh
, 0);
6958 tcg_idx
= tcg_temp_new_i64();
6959 tcg_regno
= tcg_const_i32(rn
);
6960 tcg_numregs
= tcg_const_i32(len
+ 1);
6961 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
6962 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
6963 tcg_regno
, tcg_numregs
);
6965 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
6966 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
6967 tcg_regno
, tcg_numregs
);
6969 tcg_temp_free_i64(tcg_idx
);
6970 tcg_temp_free_i32(tcg_regno
);
6971 tcg_temp_free_i32(tcg_numregs
);
6973 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6974 tcg_temp_free_i64(tcg_resl
);
6975 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6976 tcg_temp_free_i64(tcg_resh
);
6980 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
6981 * +---+---+-------------+------+---+------+---+------------------+------+
6982 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
6983 * +---+---+-------------+------+---+------+---+------------------+------+
6985 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
6987 int rd
= extract32(insn
, 0, 5);
6988 int rn
= extract32(insn
, 5, 5);
6989 int rm
= extract32(insn
, 16, 5);
6990 int size
= extract32(insn
, 22, 2);
6991 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
6992 * bit 2 indicates 1 vs 2 variant of the insn.
6994 int opcode
= extract32(insn
, 12, 2);
6995 bool part
= extract32(insn
, 14, 1);
6996 bool is_q
= extract32(insn
, 30, 1);
6997 int esize
= 8 << size
;
6999 int datasize
= is_q
? 128 : 64;
7000 int elements
= datasize
/ esize
;
7001 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
7003 if (opcode
== 0 || (size
== 3 && !is_q
)) {
7004 unallocated_encoding(s
);
7008 if (!fp_access_check(s
)) {
7012 tcg_resl
= tcg_const_i64(0);
7013 tcg_resh
= tcg_const_i64(0);
7014 tcg_res
= tcg_temp_new_i64();
7016 for (i
= 0; i
< elements
; i
++) {
7018 case 1: /* UZP1/2 */
7020 int midpoint
= elements
/ 2;
7022 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
7024 read_vec_element(s
, tcg_res
, rm
,
7025 2 * (i
- midpoint
) + part
, size
);
7029 case 2: /* TRN1/2 */
7031 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
7033 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
7036 case 3: /* ZIP1/2 */
7038 int base
= part
* elements
/ 2;
7040 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
7042 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
7047 g_assert_not_reached();
7052 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
7053 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
7055 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
7056 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
7060 tcg_temp_free_i64(tcg_res
);
7062 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
7063 tcg_temp_free_i64(tcg_resl
);
7064 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
7065 tcg_temp_free_i64(tcg_resh
);
7069 * do_reduction_op helper
7071 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
7072 * important for correct NaN propagation that we do these
7073 * operations in exactly the order specified by the pseudocode.
7075 * This is a recursive function, TCG temps should be freed by the
7076 * calling function once it is done with the values.
7078 static TCGv_i32
do_reduction_op(DisasContext
*s
, int fpopcode
, int rn
,
7079 int esize
, int size
, int vmap
, TCGv_ptr fpst
)
7081 if (esize
== size
) {
7083 TCGMemOp msize
= esize
== 16 ? MO_16
: MO_32
;
7086 /* We should have one register left here */
7087 assert(ctpop8(vmap
) == 1);
7088 element
= ctz32(vmap
);
7089 assert(element
< 8);
7091 tcg_elem
= tcg_temp_new_i32();
7092 read_vec_element_i32(s
, tcg_elem
, rn
, element
, msize
);
7095 int bits
= size
/ 2;
7096 int shift
= ctpop8(vmap
) / 2;
7097 int vmap_lo
= (vmap
>> shift
) & vmap
;
7098 int vmap_hi
= (vmap
& ~vmap_lo
);
7099 TCGv_i32 tcg_hi
, tcg_lo
, tcg_res
;
7101 tcg_hi
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_hi
, fpst
);
7102 tcg_lo
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_lo
, fpst
);
7103 tcg_res
= tcg_temp_new_i32();
7106 case 0x0c: /* fmaxnmv half-precision */
7107 gen_helper_advsimd_maxnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7109 case 0x0f: /* fmaxv half-precision */
7110 gen_helper_advsimd_maxh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7112 case 0x1c: /* fminnmv half-precision */
7113 gen_helper_advsimd_minnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7115 case 0x1f: /* fminv half-precision */
7116 gen_helper_advsimd_minh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7118 case 0x2c: /* fmaxnmv */
7119 gen_helper_vfp_maxnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7121 case 0x2f: /* fmaxv */
7122 gen_helper_vfp_maxs(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7124 case 0x3c: /* fminnmv */
7125 gen_helper_vfp_minnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7127 case 0x3f: /* fminv */
7128 gen_helper_vfp_mins(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7131 g_assert_not_reached();
7134 tcg_temp_free_i32(tcg_hi
);
7135 tcg_temp_free_i32(tcg_lo
);
7140 /* AdvSIMD across lanes
7141 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7142 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7143 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7144 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7146 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
7148 int rd
= extract32(insn
, 0, 5);
7149 int rn
= extract32(insn
, 5, 5);
7150 int size
= extract32(insn
, 22, 2);
7151 int opcode
= extract32(insn
, 12, 5);
7152 bool is_q
= extract32(insn
, 30, 1);
7153 bool is_u
= extract32(insn
, 29, 1);
7155 bool is_min
= false;
7159 TCGv_i64 tcg_res
, tcg_elt
;
7162 case 0x1b: /* ADDV */
7164 unallocated_encoding(s
);
7168 case 0x3: /* SADDLV, UADDLV */
7169 case 0xa: /* SMAXV, UMAXV */
7170 case 0x1a: /* SMINV, UMINV */
7171 if (size
== 3 || (size
== 2 && !is_q
)) {
7172 unallocated_encoding(s
);
7176 case 0xc: /* FMAXNMV, FMINNMV */
7177 case 0xf: /* FMAXV, FMINV */
7178 /* Bit 1 of size field encodes min vs max and the actual size
7179 * depends on the encoding of the U bit. If not set (and FP16
7180 * enabled) then we do half-precision float instead of single
7183 is_min
= extract32(size
, 1, 1);
7185 if (!is_u
&& dc_isar_feature(aa64_fp16
, s
)) {
7187 } else if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
7188 unallocated_encoding(s
);
7195 unallocated_encoding(s
);
7199 if (!fp_access_check(s
)) {
7204 elements
= (is_q
? 128 : 64) / esize
;
7206 tcg_res
= tcg_temp_new_i64();
7207 tcg_elt
= tcg_temp_new_i64();
7209 /* These instructions operate across all lanes of a vector
7210 * to produce a single result. We can guarantee that a 64
7211 * bit intermediate is sufficient:
7212 * + for [US]ADDLV the maximum element size is 32 bits, and
7213 * the result type is 64 bits
7214 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
7215 * same as the element size, which is 32 bits at most
7216 * For the integer operations we can choose to work at 64
7217 * or 32 bits and truncate at the end; for simplicity
7218 * we use 64 bits always. The floating point
7219 * ops do require 32 bit intermediates, though.
7222 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
7224 for (i
= 1; i
< elements
; i
++) {
7225 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
7228 case 0x03: /* SADDLV / UADDLV */
7229 case 0x1b: /* ADDV */
7230 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
7232 case 0x0a: /* SMAXV / UMAXV */
7234 tcg_gen_umax_i64(tcg_res
, tcg_res
, tcg_elt
);
7236 tcg_gen_smax_i64(tcg_res
, tcg_res
, tcg_elt
);
7239 case 0x1a: /* SMINV / UMINV */
7241 tcg_gen_umin_i64(tcg_res
, tcg_res
, tcg_elt
);
7243 tcg_gen_smin_i64(tcg_res
, tcg_res
, tcg_elt
);
7247 g_assert_not_reached();
7252 /* Floating point vector reduction ops which work across 32
7253 * bit (single) or 16 bit (half-precision) intermediates.
7254 * Note that correct NaN propagation requires that we do these
7255 * operations in exactly the order specified by the pseudocode.
7257 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
7258 int fpopcode
= opcode
| is_min
<< 4 | is_u
<< 5;
7259 int vmap
= (1 << elements
) - 1;
7260 TCGv_i32 tcg_res32
= do_reduction_op(s
, fpopcode
, rn
, esize
,
7261 (is_q
? 128 : 64), vmap
, fpst
);
7262 tcg_gen_extu_i32_i64(tcg_res
, tcg_res32
);
7263 tcg_temp_free_i32(tcg_res32
);
7264 tcg_temp_free_ptr(fpst
);
7267 tcg_temp_free_i64(tcg_elt
);
7269 /* Now truncate the result to the width required for the final output */
7270 if (opcode
== 0x03) {
7271 /* SADDLV, UADDLV: result is 2*esize */
7277 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
7280 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
7283 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
7288 g_assert_not_reached();
7291 write_fp_dreg(s
, rd
, tcg_res
);
7292 tcg_temp_free_i64(tcg_res
);
7295 /* DUP (Element, Vector)
7297 * 31 30 29 21 20 16 15 10 9 5 4 0
7298 * +---+---+-------------------+--------+-------------+------+------+
7299 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7300 * +---+---+-------------------+--------+-------------+------+------+
7302 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7304 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
7307 int size
= ctz32(imm5
);
7308 int index
= imm5
>> (size
+ 1);
7310 if (size
> 3 || (size
== 3 && !is_q
)) {
7311 unallocated_encoding(s
);
7315 if (!fp_access_check(s
)) {
7319 tcg_gen_gvec_dup_mem(size
, vec_full_reg_offset(s
, rd
),
7320 vec_reg_offset(s
, rn
, index
, size
),
7321 is_q
? 16 : 8, vec_full_reg_size(s
));
7324 /* DUP (element, scalar)
7325 * 31 21 20 16 15 10 9 5 4 0
7326 * +-----------------------+--------+-------------+------+------+
7327 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7328 * +-----------------------+--------+-------------+------+------+
7330 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
7333 int size
= ctz32(imm5
);
7338 unallocated_encoding(s
);
7342 if (!fp_access_check(s
)) {
7346 index
= imm5
>> (size
+ 1);
7348 /* This instruction just extracts the specified element and
7349 * zero-extends it into the bottom of the destination register.
7351 tmp
= tcg_temp_new_i64();
7352 read_vec_element(s
, tmp
, rn
, index
, size
);
7353 write_fp_dreg(s
, rd
, tmp
);
7354 tcg_temp_free_i64(tmp
);
7359 * 31 30 29 21 20 16 15 10 9 5 4 0
7360 * +---+---+-------------------+--------+-------------+------+------+
7361 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
7362 * +---+---+-------------------+--------+-------------+------+------+
7364 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7366 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
7369 int size
= ctz32(imm5
);
7370 uint32_t dofs
, oprsz
, maxsz
;
7372 if (size
> 3 || ((size
== 3) && !is_q
)) {
7373 unallocated_encoding(s
);
7377 if (!fp_access_check(s
)) {
7381 dofs
= vec_full_reg_offset(s
, rd
);
7382 oprsz
= is_q
? 16 : 8;
7383 maxsz
= vec_full_reg_size(s
);
7385 tcg_gen_gvec_dup_i64(size
, dofs
, oprsz
, maxsz
, cpu_reg(s
, rn
));
7390 * 31 21 20 16 15 14 11 10 9 5 4 0
7391 * +-----------------------+--------+------------+---+------+------+
7392 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7393 * +-----------------------+--------+------------+---+------+------+
7395 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7396 * index: encoded in imm5<4:size+1>
7398 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
7401 int size
= ctz32(imm5
);
7402 int src_index
, dst_index
;
7406 unallocated_encoding(s
);
7410 if (!fp_access_check(s
)) {
7414 dst_index
= extract32(imm5
, 1+size
, 5);
7415 src_index
= extract32(imm4
, size
, 4);
7417 tmp
= tcg_temp_new_i64();
7419 read_vec_element(s
, tmp
, rn
, src_index
, size
);
7420 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
7422 tcg_temp_free_i64(tmp
);
7428 * 31 21 20 16 15 10 9 5 4 0
7429 * +-----------------------+--------+-------------+------+------+
7430 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
7431 * +-----------------------+--------+-------------+------+------+
7433 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7434 * index: encoded in imm5<4:size+1>
7436 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
7438 int size
= ctz32(imm5
);
7442 unallocated_encoding(s
);
7446 if (!fp_access_check(s
)) {
7450 idx
= extract32(imm5
, 1 + size
, 4 - size
);
7451 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
7458 * 31 30 29 21 20 16 15 12 10 9 5 4 0
7459 * +---+---+-------------------+--------+-------------+------+------+
7460 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
7461 * +---+---+-------------------+--------+-------------+------+------+
7463 * U: unsigned when set
7464 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7466 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
7467 int rn
, int rd
, int imm5
)
7469 int size
= ctz32(imm5
);
7473 /* Check for UnallocatedEncodings */
7475 if (size
> 2 || (size
== 2 && !is_q
)) {
7476 unallocated_encoding(s
);
7481 || (size
< 3 && is_q
)
7482 || (size
== 3 && !is_q
)) {
7483 unallocated_encoding(s
);
7488 if (!fp_access_check(s
)) {
7492 element
= extract32(imm5
, 1+size
, 4);
7494 tcg_rd
= cpu_reg(s
, rd
);
7495 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
7496 if (is_signed
&& !is_q
) {
7497 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
7502 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7503 * +---+---+----+-----------------+------+---+------+---+------+------+
7504 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7505 * +---+---+----+-----------------+------+---+------+---+------+------+
7507 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
7509 int rd
= extract32(insn
, 0, 5);
7510 int rn
= extract32(insn
, 5, 5);
7511 int imm4
= extract32(insn
, 11, 4);
7512 int op
= extract32(insn
, 29, 1);
7513 int is_q
= extract32(insn
, 30, 1);
7514 int imm5
= extract32(insn
, 16, 5);
7519 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
7521 unallocated_encoding(s
);
7526 /* DUP (element - vector) */
7527 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
7531 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
7536 handle_simd_insg(s
, rd
, rn
, imm5
);
7538 unallocated_encoding(s
);
7543 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
7544 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
7547 unallocated_encoding(s
);
7553 /* AdvSIMD modified immediate
7554 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
7555 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7556 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
7557 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7559 * There are a number of operations that can be carried out here:
7560 * MOVI - move (shifted) imm into register
7561 * MVNI - move inverted (shifted) imm into register
7562 * ORR - bitwise OR of (shifted) imm with register
7563 * BIC - bitwise clear of (shifted) imm with register
7564 * With ARMv8.2 we also have:
7565 * FMOV half-precision
7567 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
7569 int rd
= extract32(insn
, 0, 5);
7570 int cmode
= extract32(insn
, 12, 4);
7571 int cmode_3_1
= extract32(cmode
, 1, 3);
7572 int cmode_0
= extract32(cmode
, 0, 1);
7573 int o2
= extract32(insn
, 11, 1);
7574 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
7575 bool is_neg
= extract32(insn
, 29, 1);
7576 bool is_q
= extract32(insn
, 30, 1);
7579 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
7580 /* Check for FMOV (vector, immediate) - half-precision */
7581 if (!(dc_isar_feature(aa64_fp16
, s
) && o2
&& cmode
== 0xf)) {
7582 unallocated_encoding(s
);
7587 if (!fp_access_check(s
)) {
7591 /* See AdvSIMDExpandImm() in ARM ARM */
7592 switch (cmode_3_1
) {
7593 case 0: /* Replicate(Zeros(24):imm8, 2) */
7594 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
7595 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
7596 case 3: /* Replicate(imm8:Zeros(24), 2) */
7598 int shift
= cmode_3_1
* 8;
7599 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
7602 case 4: /* Replicate(Zeros(8):imm8, 4) */
7603 case 5: /* Replicate(imm8:Zeros(8), 4) */
7605 int shift
= (cmode_3_1
& 0x1) * 8;
7606 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
7611 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
7612 imm
= (abcdefgh
<< 16) | 0xffff;
7614 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
7615 imm
= (abcdefgh
<< 8) | 0xff;
7617 imm
= bitfield_replicate(imm
, 32);
7620 if (!cmode_0
&& !is_neg
) {
7621 imm
= bitfield_replicate(abcdefgh
, 8);
7622 } else if (!cmode_0
&& is_neg
) {
7625 for (i
= 0; i
< 8; i
++) {
7626 if ((abcdefgh
) & (1 << i
)) {
7627 imm
|= 0xffULL
<< (i
* 8);
7630 } else if (cmode_0
) {
7632 imm
= (abcdefgh
& 0x3f) << 48;
7633 if (abcdefgh
& 0x80) {
7634 imm
|= 0x8000000000000000ULL
;
7636 if (abcdefgh
& 0x40) {
7637 imm
|= 0x3fc0000000000000ULL
;
7639 imm
|= 0x4000000000000000ULL
;
7643 /* FMOV (vector, immediate) - half-precision */
7644 imm
= vfp_expand_imm(MO_16
, abcdefgh
);
7645 /* now duplicate across the lanes */
7646 imm
= bitfield_replicate(imm
, 16);
7648 imm
= (abcdefgh
& 0x3f) << 19;
7649 if (abcdefgh
& 0x80) {
7652 if (abcdefgh
& 0x40) {
7663 fprintf(stderr
, "%s: cmode_3_1: %x\n", __func__
, cmode_3_1
);
7664 g_assert_not_reached();
7667 if (cmode_3_1
!= 7 && is_neg
) {
7671 if (!((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9)) {
7672 /* MOVI or MVNI, with MVNI negation handled above. */
7673 tcg_gen_gvec_dup64i(vec_full_reg_offset(s
, rd
), is_q
? 16 : 8,
7674 vec_full_reg_size(s
), imm
);
7676 /* ORR or BIC, with BIC negation to AND handled above. */
7678 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_andi
, MO_64
);
7680 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_ori
, MO_64
);
7685 /* AdvSIMD scalar copy
7686 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7687 * +-----+----+-----------------+------+---+------+---+------+------+
7688 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7689 * +-----+----+-----------------+------+---+------+---+------+------+
7691 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
7693 int rd
= extract32(insn
, 0, 5);
7694 int rn
= extract32(insn
, 5, 5);
7695 int imm4
= extract32(insn
, 11, 4);
7696 int imm5
= extract32(insn
, 16, 5);
7697 int op
= extract32(insn
, 29, 1);
7699 if (op
!= 0 || imm4
!= 0) {
7700 unallocated_encoding(s
);
7704 /* DUP (element, scalar) */
7705 handle_simd_dupes(s
, rd
, rn
, imm5
);
7708 /* AdvSIMD scalar pairwise
7709 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7710 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7711 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7712 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7714 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
7716 int u
= extract32(insn
, 29, 1);
7717 int size
= extract32(insn
, 22, 2);
7718 int opcode
= extract32(insn
, 12, 5);
7719 int rn
= extract32(insn
, 5, 5);
7720 int rd
= extract32(insn
, 0, 5);
7723 /* For some ops (the FP ones), size[1] is part of the encoding.
7724 * For ADDP strictly it is not but size[1] is always 1 for valid
7727 opcode
|= (extract32(size
, 1, 1) << 5);
7730 case 0x3b: /* ADDP */
7731 if (u
|| size
!= 3) {
7732 unallocated_encoding(s
);
7735 if (!fp_access_check(s
)) {
7741 case 0xc: /* FMAXNMP */
7742 case 0xd: /* FADDP */
7743 case 0xf: /* FMAXP */
7744 case 0x2c: /* FMINNMP */
7745 case 0x2f: /* FMINP */
7746 /* FP op, size[0] is 32 or 64 bit*/
7748 if (!dc_isar_feature(aa64_fp16
, s
)) {
7749 unallocated_encoding(s
);
7755 size
= extract32(size
, 0, 1) ? MO_64
: MO_32
;
7758 if (!fp_access_check(s
)) {
7762 fpst
= get_fpstatus_ptr(size
== MO_16
);
7765 unallocated_encoding(s
);
7769 if (size
== MO_64
) {
7770 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7771 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7772 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7774 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
7775 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
7778 case 0x3b: /* ADDP */
7779 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
7781 case 0xc: /* FMAXNMP */
7782 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7784 case 0xd: /* FADDP */
7785 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7787 case 0xf: /* FMAXP */
7788 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7790 case 0x2c: /* FMINNMP */
7791 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7793 case 0x2f: /* FMINP */
7794 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7797 g_assert_not_reached();
7800 write_fp_dreg(s
, rd
, tcg_res
);
7802 tcg_temp_free_i64(tcg_op1
);
7803 tcg_temp_free_i64(tcg_op2
);
7804 tcg_temp_free_i64(tcg_res
);
7806 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7807 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7808 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7810 read_vec_element_i32(s
, tcg_op1
, rn
, 0, size
);
7811 read_vec_element_i32(s
, tcg_op2
, rn
, 1, size
);
7813 if (size
== MO_16
) {
7815 case 0xc: /* FMAXNMP */
7816 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7818 case 0xd: /* FADDP */
7819 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7821 case 0xf: /* FMAXP */
7822 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7824 case 0x2c: /* FMINNMP */
7825 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7827 case 0x2f: /* FMINP */
7828 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7831 g_assert_not_reached();
7835 case 0xc: /* FMAXNMP */
7836 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7838 case 0xd: /* FADDP */
7839 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7841 case 0xf: /* FMAXP */
7842 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7844 case 0x2c: /* FMINNMP */
7845 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7847 case 0x2f: /* FMINP */
7848 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7851 g_assert_not_reached();
7855 write_fp_sreg(s
, rd
, tcg_res
);
7857 tcg_temp_free_i32(tcg_op1
);
7858 tcg_temp_free_i32(tcg_op2
);
7859 tcg_temp_free_i32(tcg_res
);
7863 tcg_temp_free_ptr(fpst
);
7868 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
7870 * This code is handles the common shifting code and is used by both
7871 * the vector and scalar code.
7873 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
7874 TCGv_i64 tcg_rnd
, bool accumulate
,
7875 bool is_u
, int size
, int shift
)
7877 bool extended_result
= false;
7878 bool round
= tcg_rnd
!= NULL
;
7880 TCGv_i64 tcg_src_hi
;
7882 if (round
&& size
== 3) {
7883 extended_result
= true;
7884 ext_lshift
= 64 - shift
;
7885 tcg_src_hi
= tcg_temp_new_i64();
7886 } else if (shift
== 64) {
7887 if (!accumulate
&& is_u
) {
7888 /* result is zero */
7889 tcg_gen_movi_i64(tcg_res
, 0);
7894 /* Deal with the rounding step */
7896 if (extended_result
) {
7897 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7899 /* take care of sign extending tcg_res */
7900 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
7901 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7902 tcg_src
, tcg_src_hi
,
7905 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7909 tcg_temp_free_i64(tcg_zero
);
7911 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
7915 /* Now do the shift right */
7916 if (round
&& extended_result
) {
7917 /* extended case, >64 bit precision required */
7918 if (ext_lshift
== 0) {
7919 /* special case, only high bits matter */
7920 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
7922 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7923 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
7924 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
7929 /* essentially shifting in 64 zeros */
7930 tcg_gen_movi_i64(tcg_src
, 0);
7932 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7936 /* effectively extending the sign-bit */
7937 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
7939 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
7945 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
7947 tcg_gen_mov_i64(tcg_res
, tcg_src
);
7950 if (extended_result
) {
7951 tcg_temp_free_i64(tcg_src_hi
);
7955 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
7956 static void handle_scalar_simd_shri(DisasContext
*s
,
7957 bool is_u
, int immh
, int immb
,
7958 int opcode
, int rn
, int rd
)
7961 int immhb
= immh
<< 3 | immb
;
7962 int shift
= 2 * (8 << size
) - immhb
;
7963 bool accumulate
= false;
7965 bool insert
= false;
7970 if (!extract32(immh
, 3, 1)) {
7971 unallocated_encoding(s
);
7975 if (!fp_access_check(s
)) {
7980 case 0x02: /* SSRA / USRA (accumulate) */
7983 case 0x04: /* SRSHR / URSHR (rounding) */
7986 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7987 accumulate
= round
= true;
7989 case 0x08: /* SRI */
7995 uint64_t round_const
= 1ULL << (shift
- 1);
7996 tcg_round
= tcg_const_i64(round_const
);
8001 tcg_rn
= read_fp_dreg(s
, rn
);
8002 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
8005 /* shift count same as element size is valid but does nothing;
8006 * special case to avoid potential shift by 64.
8008 int esize
= 8 << size
;
8009 if (shift
!= esize
) {
8010 tcg_gen_shri_i64(tcg_rn
, tcg_rn
, shift
);
8011 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, 0, esize
- shift
);
8014 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8015 accumulate
, is_u
, size
, shift
);
8018 write_fp_dreg(s
, rd
, tcg_rd
);
8020 tcg_temp_free_i64(tcg_rn
);
8021 tcg_temp_free_i64(tcg_rd
);
8023 tcg_temp_free_i64(tcg_round
);
8027 /* SHL/SLI - Scalar shift left */
8028 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
8029 int immh
, int immb
, int opcode
,
8032 int size
= 32 - clz32(immh
) - 1;
8033 int immhb
= immh
<< 3 | immb
;
8034 int shift
= immhb
- (8 << size
);
8035 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8036 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8038 if (!extract32(immh
, 3, 1)) {
8039 unallocated_encoding(s
);
8043 if (!fp_access_check(s
)) {
8047 tcg_rn
= read_fp_dreg(s
, rn
);
8048 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
8051 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, shift
, 64 - shift
);
8053 tcg_gen_shli_i64(tcg_rd
, tcg_rn
, shift
);
8056 write_fp_dreg(s
, rd
, tcg_rd
);
8058 tcg_temp_free_i64(tcg_rn
);
8059 tcg_temp_free_i64(tcg_rd
);
8062 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
8063 * (signed/unsigned) narrowing */
8064 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
8065 bool is_u_shift
, bool is_u_narrow
,
8066 int immh
, int immb
, int opcode
,
8069 int immhb
= immh
<< 3 | immb
;
8070 int size
= 32 - clz32(immh
) - 1;
8071 int esize
= 8 << size
;
8072 int shift
= (2 * esize
) - immhb
;
8073 int elements
= is_scalar
? 1 : (64 / esize
);
8074 bool round
= extract32(opcode
, 0, 1);
8075 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
8076 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
8077 TCGv_i32 tcg_rd_narrowed
;
8080 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
8081 { gen_helper_neon_narrow_sat_s8
,
8082 gen_helper_neon_unarrow_sat8
},
8083 { gen_helper_neon_narrow_sat_s16
,
8084 gen_helper_neon_unarrow_sat16
},
8085 { gen_helper_neon_narrow_sat_s32
,
8086 gen_helper_neon_unarrow_sat32
},
8089 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
8090 gen_helper_neon_narrow_sat_u8
,
8091 gen_helper_neon_narrow_sat_u16
,
8092 gen_helper_neon_narrow_sat_u32
,
8095 NeonGenNarrowEnvFn
*narrowfn
;
8101 if (extract32(immh
, 3, 1)) {
8102 unallocated_encoding(s
);
8106 if (!fp_access_check(s
)) {
8111 narrowfn
= unsigned_narrow_fns
[size
];
8113 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
8116 tcg_rn
= tcg_temp_new_i64();
8117 tcg_rd
= tcg_temp_new_i64();
8118 tcg_rd_narrowed
= tcg_temp_new_i32();
8119 tcg_final
= tcg_const_i64(0);
8122 uint64_t round_const
= 1ULL << (shift
- 1);
8123 tcg_round
= tcg_const_i64(round_const
);
8128 for (i
= 0; i
< elements
; i
++) {
8129 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
8130 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8131 false, is_u_shift
, size
+1, shift
);
8132 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
8133 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
8134 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8138 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8140 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8144 tcg_temp_free_i64(tcg_round
);
8146 tcg_temp_free_i64(tcg_rn
);
8147 tcg_temp_free_i64(tcg_rd
);
8148 tcg_temp_free_i32(tcg_rd_narrowed
);
8149 tcg_temp_free_i64(tcg_final
);
8151 clear_vec_high(s
, is_q
, rd
);
8154 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
8155 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
8156 bool src_unsigned
, bool dst_unsigned
,
8157 int immh
, int immb
, int rn
, int rd
)
8159 int immhb
= immh
<< 3 | immb
;
8160 int size
= 32 - clz32(immh
) - 1;
8161 int shift
= immhb
- (8 << size
);
8165 assert(!(scalar
&& is_q
));
8168 if (!is_q
&& extract32(immh
, 3, 1)) {
8169 unallocated_encoding(s
);
8173 /* Since we use the variable-shift helpers we must
8174 * replicate the shift count into each element of
8175 * the tcg_shift value.
8179 shift
|= shift
<< 8;
8182 shift
|= shift
<< 16;
8188 g_assert_not_reached();
8192 if (!fp_access_check(s
)) {
8197 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
8198 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
8199 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
8200 { NULL
, gen_helper_neon_qshl_u64
},
8202 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
8203 int maxpass
= is_q
? 2 : 1;
8205 for (pass
= 0; pass
< maxpass
; pass
++) {
8206 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8208 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8209 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8210 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
8212 tcg_temp_free_i64(tcg_op
);
8214 tcg_temp_free_i64(tcg_shift
);
8215 clear_vec_high(s
, is_q
, rd
);
8217 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
8218 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
8220 { gen_helper_neon_qshl_s8
,
8221 gen_helper_neon_qshl_s16
,
8222 gen_helper_neon_qshl_s32
},
8223 { gen_helper_neon_qshlu_s8
,
8224 gen_helper_neon_qshlu_s16
,
8225 gen_helper_neon_qshlu_s32
}
8227 { NULL
, NULL
, NULL
},
8228 { gen_helper_neon_qshl_u8
,
8229 gen_helper_neon_qshl_u16
,
8230 gen_helper_neon_qshl_u32
}
8233 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
8234 TCGMemOp memop
= scalar
? size
: MO_32
;
8235 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
8237 for (pass
= 0; pass
< maxpass
; pass
++) {
8238 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8240 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
8241 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8245 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
8248 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
8253 g_assert_not_reached();
8255 write_fp_sreg(s
, rd
, tcg_op
);
8257 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
8260 tcg_temp_free_i32(tcg_op
);
8262 tcg_temp_free_i32(tcg_shift
);
8265 clear_vec_high(s
, is_q
, rd
);
8270 /* Common vector code for handling integer to FP conversion */
8271 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
8272 int elements
, int is_signed
,
8273 int fracbits
, int size
)
8275 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(size
== MO_16
);
8276 TCGv_i32 tcg_shift
= NULL
;
8278 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
8281 if (fracbits
|| size
== MO_64
) {
8282 tcg_shift
= tcg_const_i32(fracbits
);
8285 if (size
== MO_64
) {
8286 TCGv_i64 tcg_int64
= tcg_temp_new_i64();
8287 TCGv_i64 tcg_double
= tcg_temp_new_i64();
8289 for (pass
= 0; pass
< elements
; pass
++) {
8290 read_vec_element(s
, tcg_int64
, rn
, pass
, mop
);
8293 gen_helper_vfp_sqtod(tcg_double
, tcg_int64
,
8294 tcg_shift
, tcg_fpst
);
8296 gen_helper_vfp_uqtod(tcg_double
, tcg_int64
,
8297 tcg_shift
, tcg_fpst
);
8299 if (elements
== 1) {
8300 write_fp_dreg(s
, rd
, tcg_double
);
8302 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
8306 tcg_temp_free_i64(tcg_int64
);
8307 tcg_temp_free_i64(tcg_double
);
8310 TCGv_i32 tcg_int32
= tcg_temp_new_i32();
8311 TCGv_i32 tcg_float
= tcg_temp_new_i32();
8313 for (pass
= 0; pass
< elements
; pass
++) {
8314 read_vec_element_i32(s
, tcg_int32
, rn
, pass
, mop
);
8320 gen_helper_vfp_sltos(tcg_float
, tcg_int32
,
8321 tcg_shift
, tcg_fpst
);
8323 gen_helper_vfp_ultos(tcg_float
, tcg_int32
,
8324 tcg_shift
, tcg_fpst
);
8328 gen_helper_vfp_sitos(tcg_float
, tcg_int32
, tcg_fpst
);
8330 gen_helper_vfp_uitos(tcg_float
, tcg_int32
, tcg_fpst
);
8337 gen_helper_vfp_sltoh(tcg_float
, tcg_int32
,
8338 tcg_shift
, tcg_fpst
);
8340 gen_helper_vfp_ultoh(tcg_float
, tcg_int32
,
8341 tcg_shift
, tcg_fpst
);
8345 gen_helper_vfp_sitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8347 gen_helper_vfp_uitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8352 g_assert_not_reached();
8355 if (elements
== 1) {
8356 write_fp_sreg(s
, rd
, tcg_float
);
8358 write_vec_element_i32(s
, tcg_float
, rd
, pass
, size
);
8362 tcg_temp_free_i32(tcg_int32
);
8363 tcg_temp_free_i32(tcg_float
);
8366 tcg_temp_free_ptr(tcg_fpst
);
8368 tcg_temp_free_i32(tcg_shift
);
8371 clear_vec_high(s
, elements
<< size
== 16, rd
);
8374 /* UCVTF/SCVTF - Integer to FP conversion */
8375 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
8376 bool is_q
, bool is_u
,
8377 int immh
, int immb
, int opcode
,
8380 int size
, elements
, fracbits
;
8381 int immhb
= immh
<< 3 | immb
;
8385 if (!is_scalar
&& !is_q
) {
8386 unallocated_encoding(s
);
8389 } else if (immh
& 4) {
8391 } else if (immh
& 2) {
8393 if (!dc_isar_feature(aa64_fp16
, s
)) {
8394 unallocated_encoding(s
);
8398 /* immh == 0 would be a failure of the decode logic */
8399 g_assert(immh
== 1);
8400 unallocated_encoding(s
);
8407 elements
= (8 << is_q
) >> size
;
8409 fracbits
= (16 << size
) - immhb
;
8411 if (!fp_access_check(s
)) {
8415 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
8418 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
8419 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
8420 bool is_q
, bool is_u
,
8421 int immh
, int immb
, int rn
, int rd
)
8423 int immhb
= immh
<< 3 | immb
;
8424 int pass
, size
, fracbits
;
8425 TCGv_ptr tcg_fpstatus
;
8426 TCGv_i32 tcg_rmode
, tcg_shift
;
8430 if (!is_scalar
&& !is_q
) {
8431 unallocated_encoding(s
);
8434 } else if (immh
& 0x4) {
8436 } else if (immh
& 0x2) {
8438 if (!dc_isar_feature(aa64_fp16
, s
)) {
8439 unallocated_encoding(s
);
8443 /* Should have split out AdvSIMD modified immediate earlier. */
8445 unallocated_encoding(s
);
8449 if (!fp_access_check(s
)) {
8453 assert(!(is_scalar
&& is_q
));
8455 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
8456 tcg_fpstatus
= get_fpstatus_ptr(size
== MO_16
);
8457 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
8458 fracbits
= (16 << size
) - immhb
;
8459 tcg_shift
= tcg_const_i32(fracbits
);
8461 if (size
== MO_64
) {
8462 int maxpass
= is_scalar
? 1 : 2;
8464 for (pass
= 0; pass
< maxpass
; pass
++) {
8465 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8467 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8469 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8471 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8473 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
8474 tcg_temp_free_i64(tcg_op
);
8476 clear_vec_high(s
, is_q
, rd
);
8478 void (*fn
)(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
8479 int maxpass
= is_scalar
? 1 : ((8 << is_q
) >> size
);
8484 fn
= gen_helper_vfp_touhh
;
8486 fn
= gen_helper_vfp_toshh
;
8491 fn
= gen_helper_vfp_touls
;
8493 fn
= gen_helper_vfp_tosls
;
8497 g_assert_not_reached();
8500 for (pass
= 0; pass
< maxpass
; pass
++) {
8501 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8503 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
8504 fn(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8506 write_fp_sreg(s
, rd
, tcg_op
);
8508 write_vec_element_i32(s
, tcg_op
, rd
, pass
, size
);
8510 tcg_temp_free_i32(tcg_op
);
8513 clear_vec_high(s
, is_q
, rd
);
8517 tcg_temp_free_ptr(tcg_fpstatus
);
8518 tcg_temp_free_i32(tcg_shift
);
8519 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
8520 tcg_temp_free_i32(tcg_rmode
);
8523 /* AdvSIMD scalar shift by immediate
8524 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8525 * +-----+---+-------------+------+------+--------+---+------+------+
8526 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8527 * +-----+---+-------------+------+------+--------+---+------+------+
8529 * This is the scalar version so it works on a fixed sized registers
8531 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
8533 int rd
= extract32(insn
, 0, 5);
8534 int rn
= extract32(insn
, 5, 5);
8535 int opcode
= extract32(insn
, 11, 5);
8536 int immb
= extract32(insn
, 16, 3);
8537 int immh
= extract32(insn
, 19, 4);
8538 bool is_u
= extract32(insn
, 29, 1);
8541 unallocated_encoding(s
);
8546 case 0x08: /* SRI */
8548 unallocated_encoding(s
);
8552 case 0x00: /* SSHR / USHR */
8553 case 0x02: /* SSRA / USRA */
8554 case 0x04: /* SRSHR / URSHR */
8555 case 0x06: /* SRSRA / URSRA */
8556 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8558 case 0x0a: /* SHL / SLI */
8559 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8561 case 0x1c: /* SCVTF, UCVTF */
8562 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
8565 case 0x10: /* SQSHRUN, SQSHRUN2 */
8566 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
8568 unallocated_encoding(s
);
8571 handle_vec_simd_sqshrn(s
, true, false, false, true,
8572 immh
, immb
, opcode
, rn
, rd
);
8574 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
8575 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
8576 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
8577 immh
, immb
, opcode
, rn
, rd
);
8579 case 0xc: /* SQSHLU */
8581 unallocated_encoding(s
);
8584 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
8586 case 0xe: /* SQSHL, UQSHL */
8587 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
8589 case 0x1f: /* FCVTZS, FCVTZU */
8590 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
8593 unallocated_encoding(s
);
8598 /* AdvSIMD scalar three different
8599 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8600 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8601 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8602 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8604 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8606 bool is_u
= extract32(insn
, 29, 1);
8607 int size
= extract32(insn
, 22, 2);
8608 int opcode
= extract32(insn
, 12, 4);
8609 int rm
= extract32(insn
, 16, 5);
8610 int rn
= extract32(insn
, 5, 5);
8611 int rd
= extract32(insn
, 0, 5);
8614 unallocated_encoding(s
);
8619 case 0x9: /* SQDMLAL, SQDMLAL2 */
8620 case 0xb: /* SQDMLSL, SQDMLSL2 */
8621 case 0xd: /* SQDMULL, SQDMULL2 */
8622 if (size
== 0 || size
== 3) {
8623 unallocated_encoding(s
);
8628 unallocated_encoding(s
);
8632 if (!fp_access_check(s
)) {
8637 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8638 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8639 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8641 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
8642 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
8644 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
8645 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
8648 case 0xd: /* SQDMULL, SQDMULL2 */
8650 case 0xb: /* SQDMLSL, SQDMLSL2 */
8651 tcg_gen_neg_i64(tcg_res
, tcg_res
);
8653 case 0x9: /* SQDMLAL, SQDMLAL2 */
8654 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
8655 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
8659 g_assert_not_reached();
8662 write_fp_dreg(s
, rd
, tcg_res
);
8664 tcg_temp_free_i64(tcg_op1
);
8665 tcg_temp_free_i64(tcg_op2
);
8666 tcg_temp_free_i64(tcg_res
);
8668 TCGv_i32 tcg_op1
= read_fp_hreg(s
, rn
);
8669 TCGv_i32 tcg_op2
= read_fp_hreg(s
, rm
);
8670 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8672 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
8673 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
8676 case 0xd: /* SQDMULL, SQDMULL2 */
8678 case 0xb: /* SQDMLSL, SQDMLSL2 */
8679 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
8681 case 0x9: /* SQDMLAL, SQDMLAL2 */
8683 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
8684 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
8685 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
8687 tcg_temp_free_i64(tcg_op3
);
8691 g_assert_not_reached();
8694 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
8695 write_fp_dreg(s
, rd
, tcg_res
);
8697 tcg_temp_free_i32(tcg_op1
);
8698 tcg_temp_free_i32(tcg_op2
);
8699 tcg_temp_free_i64(tcg_res
);
8703 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
8704 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
8706 /* Handle 64x64->64 opcodes which are shared between the scalar
8707 * and vector 3-same groups. We cover every opcode where size == 3
8708 * is valid in either the three-reg-same (integer, not pairwise)
8709 * or scalar-three-reg-same groups.
8714 case 0x1: /* SQADD */
8716 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8718 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8721 case 0x5: /* SQSUB */
8723 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8725 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8728 case 0x6: /* CMGT, CMHI */
8729 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
8730 * We implement this using setcond (test) and then negating.
8732 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
8734 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
8735 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
8737 case 0x7: /* CMGE, CMHS */
8738 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
8740 case 0x11: /* CMTST, CMEQ */
8745 gen_cmtst_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8747 case 0x8: /* SSHL, USHL */
8749 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8751 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8754 case 0x9: /* SQSHL, UQSHL */
8756 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8758 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8761 case 0xa: /* SRSHL, URSHL */
8763 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8765 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8768 case 0xb: /* SQRSHL, UQRSHL */
8770 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8772 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8775 case 0x10: /* ADD, SUB */
8777 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8779 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8783 g_assert_not_reached();
8787 /* Handle the 3-same-operands float operations; shared by the scalar
8788 * and vector encodings. The caller must filter out any encodings
8789 * not allocated for the encoding it is dealing with.
8791 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
8792 int fpopcode
, int rd
, int rn
, int rm
)
8795 TCGv_ptr fpst
= get_fpstatus_ptr(false);
8797 for (pass
= 0; pass
< elements
; pass
++) {
8800 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8801 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8802 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8804 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8805 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8808 case 0x39: /* FMLS */
8809 /* As usual for ARM, separate negation for fused multiply-add */
8810 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
8812 case 0x19: /* FMLA */
8813 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8814 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
8817 case 0x18: /* FMAXNM */
8818 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8820 case 0x1a: /* FADD */
8821 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8823 case 0x1b: /* FMULX */
8824 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8826 case 0x1c: /* FCMEQ */
8827 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8829 case 0x1e: /* FMAX */
8830 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8832 case 0x1f: /* FRECPS */
8833 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8835 case 0x38: /* FMINNM */
8836 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8838 case 0x3a: /* FSUB */
8839 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8841 case 0x3e: /* FMIN */
8842 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8844 case 0x3f: /* FRSQRTS */
8845 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8847 case 0x5b: /* FMUL */
8848 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8850 case 0x5c: /* FCMGE */
8851 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8853 case 0x5d: /* FACGE */
8854 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8856 case 0x5f: /* FDIV */
8857 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8859 case 0x7a: /* FABD */
8860 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8861 gen_helper_vfp_absd(tcg_res
, tcg_res
);
8863 case 0x7c: /* FCMGT */
8864 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8866 case 0x7d: /* FACGT */
8867 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8870 g_assert_not_reached();
8873 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8875 tcg_temp_free_i64(tcg_res
);
8876 tcg_temp_free_i64(tcg_op1
);
8877 tcg_temp_free_i64(tcg_op2
);
8880 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8881 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8882 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8884 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
8885 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
8888 case 0x39: /* FMLS */
8889 /* As usual for ARM, separate negation for fused multiply-add */
8890 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
8892 case 0x19: /* FMLA */
8893 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8894 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
8897 case 0x1a: /* FADD */
8898 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8900 case 0x1b: /* FMULX */
8901 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8903 case 0x1c: /* FCMEQ */
8904 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8906 case 0x1e: /* FMAX */
8907 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8909 case 0x1f: /* FRECPS */
8910 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8912 case 0x18: /* FMAXNM */
8913 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8915 case 0x38: /* FMINNM */
8916 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8918 case 0x3a: /* FSUB */
8919 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8921 case 0x3e: /* FMIN */
8922 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8924 case 0x3f: /* FRSQRTS */
8925 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8927 case 0x5b: /* FMUL */
8928 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8930 case 0x5c: /* FCMGE */
8931 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8933 case 0x5d: /* FACGE */
8934 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8936 case 0x5f: /* FDIV */
8937 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8939 case 0x7a: /* FABD */
8940 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8941 gen_helper_vfp_abss(tcg_res
, tcg_res
);
8943 case 0x7c: /* FCMGT */
8944 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8946 case 0x7d: /* FACGT */
8947 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8950 g_assert_not_reached();
8953 if (elements
== 1) {
8954 /* scalar single so clear high part */
8955 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
8957 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
8958 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
8959 tcg_temp_free_i64(tcg_tmp
);
8961 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8964 tcg_temp_free_i32(tcg_res
);
8965 tcg_temp_free_i32(tcg_op1
);
8966 tcg_temp_free_i32(tcg_op2
);
8970 tcg_temp_free_ptr(fpst
);
8972 clear_vec_high(s
, elements
* (size
? 8 : 4) > 8, rd
);
8975 /* AdvSIMD scalar three same
8976 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8977 * +-----+---+-----------+------+---+------+--------+---+------+------+
8978 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8979 * +-----+---+-----------+------+---+------+--------+---+------+------+
8981 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
8983 int rd
= extract32(insn
, 0, 5);
8984 int rn
= extract32(insn
, 5, 5);
8985 int opcode
= extract32(insn
, 11, 5);
8986 int rm
= extract32(insn
, 16, 5);
8987 int size
= extract32(insn
, 22, 2);
8988 bool u
= extract32(insn
, 29, 1);
8991 if (opcode
>= 0x18) {
8992 /* Floating point: U, size[1] and opcode indicate operation */
8993 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
8995 case 0x1b: /* FMULX */
8996 case 0x1f: /* FRECPS */
8997 case 0x3f: /* FRSQRTS */
8998 case 0x5d: /* FACGE */
8999 case 0x7d: /* FACGT */
9000 case 0x1c: /* FCMEQ */
9001 case 0x5c: /* FCMGE */
9002 case 0x7c: /* FCMGT */
9003 case 0x7a: /* FABD */
9006 unallocated_encoding(s
);
9010 if (!fp_access_check(s
)) {
9014 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
9019 case 0x1: /* SQADD, UQADD */
9020 case 0x5: /* SQSUB, UQSUB */
9021 case 0x9: /* SQSHL, UQSHL */
9022 case 0xb: /* SQRSHL, UQRSHL */
9024 case 0x8: /* SSHL, USHL */
9025 case 0xa: /* SRSHL, URSHL */
9026 case 0x6: /* CMGT, CMHI */
9027 case 0x7: /* CMGE, CMHS */
9028 case 0x11: /* CMTST, CMEQ */
9029 case 0x10: /* ADD, SUB (vector) */
9031 unallocated_encoding(s
);
9035 case 0x16: /* SQDMULH, SQRDMULH (vector) */
9036 if (size
!= 1 && size
!= 2) {
9037 unallocated_encoding(s
);
9042 unallocated_encoding(s
);
9046 if (!fp_access_check(s
)) {
9050 tcg_rd
= tcg_temp_new_i64();
9053 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
9054 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
9056 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
9057 tcg_temp_free_i64(tcg_rn
);
9058 tcg_temp_free_i64(tcg_rm
);
9060 /* Do a single operation on the lowest element in the vector.
9061 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
9062 * no side effects for all these operations.
9063 * OPTME: special-purpose helpers would avoid doing some
9064 * unnecessary work in the helper for the 8 and 16 bit cases.
9066 NeonGenTwoOpEnvFn
*genenvfn
;
9067 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9068 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
9069 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
9071 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
9072 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
9075 case 0x1: /* SQADD, UQADD */
9077 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9078 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9079 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9080 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9082 genenvfn
= fns
[size
][u
];
9085 case 0x5: /* SQSUB, UQSUB */
9087 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9088 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9089 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9090 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9092 genenvfn
= fns
[size
][u
];
9095 case 0x9: /* SQSHL, UQSHL */
9097 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9098 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9099 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9100 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9102 genenvfn
= fns
[size
][u
];
9105 case 0xb: /* SQRSHL, UQRSHL */
9107 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9108 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9109 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9110 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9112 genenvfn
= fns
[size
][u
];
9115 case 0x16: /* SQDMULH, SQRDMULH */
9117 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9118 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9119 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9121 assert(size
== 1 || size
== 2);
9122 genenvfn
= fns
[size
- 1][u
];
9126 g_assert_not_reached();
9129 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
9130 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
9131 tcg_temp_free_i32(tcg_rd32
);
9132 tcg_temp_free_i32(tcg_rn
);
9133 tcg_temp_free_i32(tcg_rm
);
9136 write_fp_dreg(s
, rd
, tcg_rd
);
9138 tcg_temp_free_i64(tcg_rd
);
9141 /* AdvSIMD scalar three same FP16
9142 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
9143 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9144 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
9145 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9146 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
9147 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
9149 static void disas_simd_scalar_three_reg_same_fp16(DisasContext
*s
,
9152 int rd
= extract32(insn
, 0, 5);
9153 int rn
= extract32(insn
, 5, 5);
9154 int opcode
= extract32(insn
, 11, 3);
9155 int rm
= extract32(insn
, 16, 5);
9156 bool u
= extract32(insn
, 29, 1);
9157 bool a
= extract32(insn
, 23, 1);
9158 int fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
9165 case 0x03: /* FMULX */
9166 case 0x04: /* FCMEQ (reg) */
9167 case 0x07: /* FRECPS */
9168 case 0x0f: /* FRSQRTS */
9169 case 0x14: /* FCMGE (reg) */
9170 case 0x15: /* FACGE */
9171 case 0x1a: /* FABD */
9172 case 0x1c: /* FCMGT (reg) */
9173 case 0x1d: /* FACGT */
9176 unallocated_encoding(s
);
9180 if (!dc_isar_feature(aa64_fp16
, s
)) {
9181 unallocated_encoding(s
);
9184 if (!fp_access_check(s
)) {
9188 fpst
= get_fpstatus_ptr(true);
9190 tcg_op1
= read_fp_hreg(s
, rn
);
9191 tcg_op2
= read_fp_hreg(s
, rm
);
9192 tcg_res
= tcg_temp_new_i32();
9195 case 0x03: /* FMULX */
9196 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9198 case 0x04: /* FCMEQ (reg) */
9199 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9201 case 0x07: /* FRECPS */
9202 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9204 case 0x0f: /* FRSQRTS */
9205 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9207 case 0x14: /* FCMGE (reg) */
9208 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9210 case 0x15: /* FACGE */
9211 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9213 case 0x1a: /* FABD */
9214 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9215 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
9217 case 0x1c: /* FCMGT (reg) */
9218 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9220 case 0x1d: /* FACGT */
9221 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9224 g_assert_not_reached();
9227 write_fp_sreg(s
, rd
, tcg_res
);
9230 tcg_temp_free_i32(tcg_res
);
9231 tcg_temp_free_i32(tcg_op1
);
9232 tcg_temp_free_i32(tcg_op2
);
9233 tcg_temp_free_ptr(fpst
);
9236 /* AdvSIMD scalar three same extra
9237 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
9238 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9239 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
9240 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9242 static void disas_simd_scalar_three_reg_same_extra(DisasContext
*s
,
9245 int rd
= extract32(insn
, 0, 5);
9246 int rn
= extract32(insn
, 5, 5);
9247 int opcode
= extract32(insn
, 11, 4);
9248 int rm
= extract32(insn
, 16, 5);
9249 int size
= extract32(insn
, 22, 2);
9250 bool u
= extract32(insn
, 29, 1);
9251 TCGv_i32 ele1
, ele2
, ele3
;
9255 switch (u
* 16 + opcode
) {
9256 case 0x10: /* SQRDMLAH (vector) */
9257 case 0x11: /* SQRDMLSH (vector) */
9258 if (size
!= 1 && size
!= 2) {
9259 unallocated_encoding(s
);
9262 feature
= dc_isar_feature(aa64_rdm
, s
);
9265 unallocated_encoding(s
);
9269 unallocated_encoding(s
);
9272 if (!fp_access_check(s
)) {
9276 /* Do a single operation on the lowest element in the vector.
9277 * We use the standard Neon helpers and rely on 0 OP 0 == 0
9278 * with no side effects for all these operations.
9279 * OPTME: special-purpose helpers would avoid doing some
9280 * unnecessary work in the helper for the 16 bit cases.
9282 ele1
= tcg_temp_new_i32();
9283 ele2
= tcg_temp_new_i32();
9284 ele3
= tcg_temp_new_i32();
9286 read_vec_element_i32(s
, ele1
, rn
, 0, size
);
9287 read_vec_element_i32(s
, ele2
, rm
, 0, size
);
9288 read_vec_element_i32(s
, ele3
, rd
, 0, size
);
9291 case 0x0: /* SQRDMLAH */
9293 gen_helper_neon_qrdmlah_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9295 gen_helper_neon_qrdmlah_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9298 case 0x1: /* SQRDMLSH */
9300 gen_helper_neon_qrdmlsh_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9302 gen_helper_neon_qrdmlsh_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9306 g_assert_not_reached();
9308 tcg_temp_free_i32(ele1
);
9309 tcg_temp_free_i32(ele2
);
9311 res
= tcg_temp_new_i64();
9312 tcg_gen_extu_i32_i64(res
, ele3
);
9313 tcg_temp_free_i32(ele3
);
9315 write_fp_dreg(s
, rd
, res
);
9316 tcg_temp_free_i64(res
);
9319 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
9320 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
9321 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
9323 /* Handle 64->64 opcodes which are shared between the scalar and
9324 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
9325 * is valid in either group and also the double-precision fp ops.
9326 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
9332 case 0x4: /* CLS, CLZ */
9334 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
9336 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
9340 /* This opcode is shared with CNT and RBIT but we have earlier
9341 * enforced that size == 3 if and only if this is the NOT insn.
9343 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
9345 case 0x7: /* SQABS, SQNEG */
9347 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
9349 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
9352 case 0xa: /* CMLT */
9353 /* 64 bit integer comparison against zero, result is
9354 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
9359 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
9360 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
9362 case 0x8: /* CMGT, CMGE */
9363 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
9365 case 0x9: /* CMEQ, CMLE */
9366 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
9368 case 0xb: /* ABS, NEG */
9370 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
9372 TCGv_i64 tcg_zero
= tcg_const_i64(0);
9373 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
9374 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
9376 tcg_temp_free_i64(tcg_zero
);
9379 case 0x2f: /* FABS */
9380 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
9382 case 0x6f: /* FNEG */
9383 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
9385 case 0x7f: /* FSQRT */
9386 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
9388 case 0x1a: /* FCVTNS */
9389 case 0x1b: /* FCVTMS */
9390 case 0x1c: /* FCVTAS */
9391 case 0x3a: /* FCVTPS */
9392 case 0x3b: /* FCVTZS */
9394 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9395 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9396 tcg_temp_free_i32(tcg_shift
);
9399 case 0x5a: /* FCVTNU */
9400 case 0x5b: /* FCVTMU */
9401 case 0x5c: /* FCVTAU */
9402 case 0x7a: /* FCVTPU */
9403 case 0x7b: /* FCVTZU */
9405 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9406 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9407 tcg_temp_free_i32(tcg_shift
);
9410 case 0x18: /* FRINTN */
9411 case 0x19: /* FRINTM */
9412 case 0x38: /* FRINTP */
9413 case 0x39: /* FRINTZ */
9414 case 0x58: /* FRINTA */
9415 case 0x79: /* FRINTI */
9416 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9418 case 0x59: /* FRINTX */
9419 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9422 g_assert_not_reached();
9426 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
9427 bool is_scalar
, bool is_u
, bool is_q
,
9428 int size
, int rn
, int rd
)
9430 bool is_double
= (size
== MO_64
);
9433 if (!fp_access_check(s
)) {
9437 fpst
= get_fpstatus_ptr(size
== MO_16
);
9440 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9441 TCGv_i64 tcg_zero
= tcg_const_i64(0);
9442 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9443 NeonGenTwoDoubleOPFn
*genfn
;
9448 case 0x2e: /* FCMLT (zero) */
9451 case 0x2c: /* FCMGT (zero) */
9452 genfn
= gen_helper_neon_cgt_f64
;
9454 case 0x2d: /* FCMEQ (zero) */
9455 genfn
= gen_helper_neon_ceq_f64
;
9457 case 0x6d: /* FCMLE (zero) */
9460 case 0x6c: /* FCMGE (zero) */
9461 genfn
= gen_helper_neon_cge_f64
;
9464 g_assert_not_reached();
9467 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9468 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9470 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
9472 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
9474 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9476 tcg_temp_free_i64(tcg_res
);
9477 tcg_temp_free_i64(tcg_zero
);
9478 tcg_temp_free_i64(tcg_op
);
9480 clear_vec_high(s
, !is_scalar
, rd
);
9482 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9483 TCGv_i32 tcg_zero
= tcg_const_i32(0);
9484 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9485 NeonGenTwoSingleOPFn
*genfn
;
9487 int pass
, maxpasses
;
9489 if (size
== MO_16
) {
9491 case 0x2e: /* FCMLT (zero) */
9494 case 0x2c: /* FCMGT (zero) */
9495 genfn
= gen_helper_advsimd_cgt_f16
;
9497 case 0x2d: /* FCMEQ (zero) */
9498 genfn
= gen_helper_advsimd_ceq_f16
;
9500 case 0x6d: /* FCMLE (zero) */
9503 case 0x6c: /* FCMGE (zero) */
9504 genfn
= gen_helper_advsimd_cge_f16
;
9507 g_assert_not_reached();
9511 case 0x2e: /* FCMLT (zero) */
9514 case 0x2c: /* FCMGT (zero) */
9515 genfn
= gen_helper_neon_cgt_f32
;
9517 case 0x2d: /* FCMEQ (zero) */
9518 genfn
= gen_helper_neon_ceq_f32
;
9520 case 0x6d: /* FCMLE (zero) */
9523 case 0x6c: /* FCMGE (zero) */
9524 genfn
= gen_helper_neon_cge_f32
;
9527 g_assert_not_reached();
9534 int vector_size
= 8 << is_q
;
9535 maxpasses
= vector_size
>> size
;
9538 for (pass
= 0; pass
< maxpasses
; pass
++) {
9539 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
9541 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
9543 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
9546 write_fp_sreg(s
, rd
, tcg_res
);
9548 write_vec_element_i32(s
, tcg_res
, rd
, pass
, size
);
9551 tcg_temp_free_i32(tcg_res
);
9552 tcg_temp_free_i32(tcg_zero
);
9553 tcg_temp_free_i32(tcg_op
);
9555 clear_vec_high(s
, is_q
, rd
);
9559 tcg_temp_free_ptr(fpst
);
9562 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
9563 bool is_scalar
, bool is_u
, bool is_q
,
9564 int size
, int rn
, int rd
)
9566 bool is_double
= (size
== 3);
9567 TCGv_ptr fpst
= get_fpstatus_ptr(false);
9570 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9571 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9574 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9575 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9577 case 0x3d: /* FRECPE */
9578 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
9580 case 0x3f: /* FRECPX */
9581 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
9583 case 0x7d: /* FRSQRTE */
9584 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
9587 g_assert_not_reached();
9589 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9591 tcg_temp_free_i64(tcg_res
);
9592 tcg_temp_free_i64(tcg_op
);
9593 clear_vec_high(s
, !is_scalar
, rd
);
9595 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9596 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9597 int pass
, maxpasses
;
9602 maxpasses
= is_q
? 4 : 2;
9605 for (pass
= 0; pass
< maxpasses
; pass
++) {
9606 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
9609 case 0x3c: /* URECPE */
9610 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
9612 case 0x3d: /* FRECPE */
9613 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
9615 case 0x3f: /* FRECPX */
9616 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
9618 case 0x7d: /* FRSQRTE */
9619 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
9622 g_assert_not_reached();
9626 write_fp_sreg(s
, rd
, tcg_res
);
9628 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9631 tcg_temp_free_i32(tcg_res
);
9632 tcg_temp_free_i32(tcg_op
);
9634 clear_vec_high(s
, is_q
, rd
);
9637 tcg_temp_free_ptr(fpst
);
9640 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
9641 int opcode
, bool u
, bool is_q
,
9642 int size
, int rn
, int rd
)
9644 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
9645 * in the source becomes a size element in the destination).
9648 TCGv_i32 tcg_res
[2];
9649 int destelt
= is_q
? 2 : 0;
9650 int passes
= scalar
? 1 : 2;
9653 tcg_res
[1] = tcg_const_i32(0);
9656 for (pass
= 0; pass
< passes
; pass
++) {
9657 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9658 NeonGenNarrowFn
*genfn
= NULL
;
9659 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
9662 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
9664 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9666 tcg_res
[pass
] = tcg_temp_new_i32();
9669 case 0x12: /* XTN, SQXTUN */
9671 static NeonGenNarrowFn
* const xtnfns
[3] = {
9672 gen_helper_neon_narrow_u8
,
9673 gen_helper_neon_narrow_u16
,
9674 tcg_gen_extrl_i64_i32
,
9676 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
9677 gen_helper_neon_unarrow_sat8
,
9678 gen_helper_neon_unarrow_sat16
,
9679 gen_helper_neon_unarrow_sat32
,
9682 genenvfn
= sqxtunfns
[size
];
9684 genfn
= xtnfns
[size
];
9688 case 0x14: /* SQXTN, UQXTN */
9690 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
9691 { gen_helper_neon_narrow_sat_s8
,
9692 gen_helper_neon_narrow_sat_u8
},
9693 { gen_helper_neon_narrow_sat_s16
,
9694 gen_helper_neon_narrow_sat_u16
},
9695 { gen_helper_neon_narrow_sat_s32
,
9696 gen_helper_neon_narrow_sat_u32
},
9698 genenvfn
= fns
[size
][u
];
9701 case 0x16: /* FCVTN, FCVTN2 */
9702 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
9704 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
9706 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
9707 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
9708 TCGv_ptr fpst
= get_fpstatus_ptr(false);
9709 TCGv_i32 ahp
= get_ahp_flag();
9711 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
9712 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, fpst
, ahp
);
9713 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, fpst
, ahp
);
9714 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
9715 tcg_temp_free_i32(tcg_lo
);
9716 tcg_temp_free_i32(tcg_hi
);
9717 tcg_temp_free_ptr(fpst
);
9718 tcg_temp_free_i32(ahp
);
9721 case 0x56: /* FCVTXN, FCVTXN2 */
9722 /* 64 bit to 32 bit float conversion
9723 * with von Neumann rounding (round to odd)
9726 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
9729 g_assert_not_reached();
9733 genfn(tcg_res
[pass
], tcg_op
);
9734 } else if (genenvfn
) {
9735 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
9738 tcg_temp_free_i64(tcg_op
);
9741 for (pass
= 0; pass
< 2; pass
++) {
9742 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
9743 tcg_temp_free_i32(tcg_res
[pass
]);
9745 clear_vec_high(s
, is_q
, rd
);
9748 /* Remaining saturating accumulating ops */
9749 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
9750 bool is_q
, int size
, int rn
, int rd
)
9752 bool is_double
= (size
== 3);
9755 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9756 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9759 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9760 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
9761 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9763 if (is_u
) { /* USQADD */
9764 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9765 } else { /* SUQADD */
9766 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9768 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9770 tcg_temp_free_i64(tcg_rd
);
9771 tcg_temp_free_i64(tcg_rn
);
9772 clear_vec_high(s
, !is_scalar
, rd
);
9774 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9775 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9776 int pass
, maxpasses
;
9781 maxpasses
= is_q
? 4 : 2;
9784 for (pass
= 0; pass
< maxpasses
; pass
++) {
9786 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
9787 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
9789 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
9790 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9793 if (is_u
) { /* USQADD */
9796 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9799 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9802 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9805 g_assert_not_reached();
9807 } else { /* SUQADD */
9810 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9813 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9816 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9819 g_assert_not_reached();
9824 TCGv_i64 tcg_zero
= tcg_const_i64(0);
9825 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
9826 tcg_temp_free_i64(tcg_zero
);
9828 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9830 tcg_temp_free_i32(tcg_rd
);
9831 tcg_temp_free_i32(tcg_rn
);
9832 clear_vec_high(s
, is_q
, rd
);
9836 /* AdvSIMD scalar two reg misc
9837 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9838 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9839 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9840 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9842 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9844 int rd
= extract32(insn
, 0, 5);
9845 int rn
= extract32(insn
, 5, 5);
9846 int opcode
= extract32(insn
, 12, 5);
9847 int size
= extract32(insn
, 22, 2);
9848 bool u
= extract32(insn
, 29, 1);
9849 bool is_fcvt
= false;
9852 TCGv_ptr tcg_fpstatus
;
9855 case 0x3: /* USQADD / SUQADD*/
9856 if (!fp_access_check(s
)) {
9859 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
9861 case 0x7: /* SQABS / SQNEG */
9863 case 0xa: /* CMLT */
9865 unallocated_encoding(s
);
9869 case 0x8: /* CMGT, CMGE */
9870 case 0x9: /* CMEQ, CMLE */
9871 case 0xb: /* ABS, NEG */
9873 unallocated_encoding(s
);
9877 case 0x12: /* SQXTUN */
9879 unallocated_encoding(s
);
9883 case 0x14: /* SQXTN, UQXTN */
9885 unallocated_encoding(s
);
9888 if (!fp_access_check(s
)) {
9891 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
9896 /* Floating point: U, size[1] and opcode indicate operation;
9897 * size[0] indicates single or double precision.
9899 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9900 size
= extract32(size
, 0, 1) ? 3 : 2;
9902 case 0x2c: /* FCMGT (zero) */
9903 case 0x2d: /* FCMEQ (zero) */
9904 case 0x2e: /* FCMLT (zero) */
9905 case 0x6c: /* FCMGE (zero) */
9906 case 0x6d: /* FCMLE (zero) */
9907 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
9909 case 0x1d: /* SCVTF */
9910 case 0x5d: /* UCVTF */
9912 bool is_signed
= (opcode
== 0x1d);
9913 if (!fp_access_check(s
)) {
9916 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
9919 case 0x3d: /* FRECPE */
9920 case 0x3f: /* FRECPX */
9921 case 0x7d: /* FRSQRTE */
9922 if (!fp_access_check(s
)) {
9925 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
9927 case 0x1a: /* FCVTNS */
9928 case 0x1b: /* FCVTMS */
9929 case 0x3a: /* FCVTPS */
9930 case 0x3b: /* FCVTZS */
9931 case 0x5a: /* FCVTNU */
9932 case 0x5b: /* FCVTMU */
9933 case 0x7a: /* FCVTPU */
9934 case 0x7b: /* FCVTZU */
9936 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9938 case 0x1c: /* FCVTAS */
9939 case 0x5c: /* FCVTAU */
9940 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
9942 rmode
= FPROUNDING_TIEAWAY
;
9944 case 0x56: /* FCVTXN, FCVTXN2 */
9946 unallocated_encoding(s
);
9949 if (!fp_access_check(s
)) {
9952 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
9955 unallocated_encoding(s
);
9960 unallocated_encoding(s
);
9964 if (!fp_access_check(s
)) {
9969 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
9970 tcg_fpstatus
= get_fpstatus_ptr(false);
9971 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9974 tcg_fpstatus
= NULL
;
9978 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
9979 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9981 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
9982 write_fp_dreg(s
, rd
, tcg_rd
);
9983 tcg_temp_free_i64(tcg_rd
);
9984 tcg_temp_free_i64(tcg_rn
);
9986 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9987 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9989 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
9992 case 0x7: /* SQABS, SQNEG */
9994 NeonGenOneOpEnvFn
*genfn
;
9995 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
9996 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
9997 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
9998 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
10000 genfn
= fns
[size
][u
];
10001 genfn(tcg_rd
, cpu_env
, tcg_rn
);
10004 case 0x1a: /* FCVTNS */
10005 case 0x1b: /* FCVTMS */
10006 case 0x1c: /* FCVTAS */
10007 case 0x3a: /* FCVTPS */
10008 case 0x3b: /* FCVTZS */
10010 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10011 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
10012 tcg_temp_free_i32(tcg_shift
);
10015 case 0x5a: /* FCVTNU */
10016 case 0x5b: /* FCVTMU */
10017 case 0x5c: /* FCVTAU */
10018 case 0x7a: /* FCVTPU */
10019 case 0x7b: /* FCVTZU */
10021 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10022 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
10023 tcg_temp_free_i32(tcg_shift
);
10027 g_assert_not_reached();
10030 write_fp_sreg(s
, rd
, tcg_rd
);
10031 tcg_temp_free_i32(tcg_rd
);
10032 tcg_temp_free_i32(tcg_rn
);
10036 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
10037 tcg_temp_free_i32(tcg_rmode
);
10038 tcg_temp_free_ptr(tcg_fpstatus
);
10042 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
10043 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
10044 int immh
, int immb
, int opcode
, int rn
, int rd
)
10046 int size
= 32 - clz32(immh
) - 1;
10047 int immhb
= immh
<< 3 | immb
;
10048 int shift
= 2 * (8 << size
) - immhb
;
10049 bool accumulate
= false;
10050 int dsize
= is_q
? 128 : 64;
10051 int esize
= 8 << size
;
10052 int elements
= dsize
/esize
;
10053 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
10054 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
10055 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
10056 TCGv_i64 tcg_round
;
10057 uint64_t round_const
;
10060 if (extract32(immh
, 3, 1) && !is_q
) {
10061 unallocated_encoding(s
);
10064 tcg_debug_assert(size
<= 3);
10066 if (!fp_access_check(s
)) {
10071 case 0x02: /* SSRA / USRA (accumulate) */
10073 /* Shift count same as element size produces zero to add. */
10074 if (shift
== 8 << size
) {
10077 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &usra_op
[size
]);
10079 /* Shift count same as element size produces all sign to add. */
10080 if (shift
== 8 << size
) {
10083 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &ssra_op
[size
]);
10086 case 0x08: /* SRI */
10087 /* Shift count same as element size is valid but does nothing. */
10088 if (shift
== 8 << size
) {
10091 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &sri_op
[size
]);
10094 case 0x00: /* SSHR / USHR */
10096 if (shift
== 8 << size
) {
10097 /* Shift count the same size as element size produces zero. */
10098 tcg_gen_gvec_dup8i(vec_full_reg_offset(s
, rd
),
10099 is_q
? 16 : 8, vec_full_reg_size(s
), 0);
10101 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shri
, size
);
10104 /* Shift count the same size as element size produces all sign. */
10105 if (shift
== 8 << size
) {
10108 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_sari
, size
);
10112 case 0x04: /* SRSHR / URSHR (rounding) */
10114 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10118 g_assert_not_reached();
10121 round_const
= 1ULL << (shift
- 1);
10122 tcg_round
= tcg_const_i64(round_const
);
10124 for (i
= 0; i
< elements
; i
++) {
10125 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
10127 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
10130 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
10131 accumulate
, is_u
, size
, shift
);
10133 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
10135 tcg_temp_free_i64(tcg_round
);
10138 clear_vec_high(s
, is_q
, rd
);
10141 /* SHL/SLI - Vector shift left */
10142 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
10143 int immh
, int immb
, int opcode
, int rn
, int rd
)
10145 int size
= 32 - clz32(immh
) - 1;
10146 int immhb
= immh
<< 3 | immb
;
10147 int shift
= immhb
- (8 << size
);
10149 /* Range of size is limited by decode: immh is a non-zero 4 bit field */
10150 assert(size
>= 0 && size
<= 3);
10152 if (extract32(immh
, 3, 1) && !is_q
) {
10153 unallocated_encoding(s
);
10157 if (!fp_access_check(s
)) {
10162 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &sli_op
[size
]);
10164 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shli
, size
);
10168 /* USHLL/SHLL - Vector shift left with widening */
10169 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
10170 int immh
, int immb
, int opcode
, int rn
, int rd
)
10172 int size
= 32 - clz32(immh
) - 1;
10173 int immhb
= immh
<< 3 | immb
;
10174 int shift
= immhb
- (8 << size
);
10176 int esize
= 8 << size
;
10177 int elements
= dsize
/esize
;
10178 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
10179 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
10183 unallocated_encoding(s
);
10187 if (!fp_access_check(s
)) {
10191 /* For the LL variants the store is larger than the load,
10192 * so if rd == rn we would overwrite parts of our input.
10193 * So load everything right now and use shifts in the main loop.
10195 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
10197 for (i
= 0; i
< elements
; i
++) {
10198 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
10199 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
10200 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
10201 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
10205 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
10206 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
10207 int immh
, int immb
, int opcode
, int rn
, int rd
)
10209 int immhb
= immh
<< 3 | immb
;
10210 int size
= 32 - clz32(immh
) - 1;
10212 int esize
= 8 << size
;
10213 int elements
= dsize
/esize
;
10214 int shift
= (2 * esize
) - immhb
;
10215 bool round
= extract32(opcode
, 0, 1);
10216 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
10217 TCGv_i64 tcg_round
;
10220 if (extract32(immh
, 3, 1)) {
10221 unallocated_encoding(s
);
10225 if (!fp_access_check(s
)) {
10229 tcg_rn
= tcg_temp_new_i64();
10230 tcg_rd
= tcg_temp_new_i64();
10231 tcg_final
= tcg_temp_new_i64();
10232 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
10235 uint64_t round_const
= 1ULL << (shift
- 1);
10236 tcg_round
= tcg_const_i64(round_const
);
10241 for (i
= 0; i
< elements
; i
++) {
10242 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
10243 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
10244 false, true, size
+1, shift
);
10246 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
10250 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
10252 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
10255 tcg_temp_free_i64(tcg_round
);
10257 tcg_temp_free_i64(tcg_rn
);
10258 tcg_temp_free_i64(tcg_rd
);
10259 tcg_temp_free_i64(tcg_final
);
10261 clear_vec_high(s
, is_q
, rd
);
10265 /* AdvSIMD shift by immediate
10266 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
10267 * +---+---+---+-------------+------+------+--------+---+------+------+
10268 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
10269 * +---+---+---+-------------+------+------+--------+---+------+------+
10271 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
10273 int rd
= extract32(insn
, 0, 5);
10274 int rn
= extract32(insn
, 5, 5);
10275 int opcode
= extract32(insn
, 11, 5);
10276 int immb
= extract32(insn
, 16, 3);
10277 int immh
= extract32(insn
, 19, 4);
10278 bool is_u
= extract32(insn
, 29, 1);
10279 bool is_q
= extract32(insn
, 30, 1);
10282 case 0x08: /* SRI */
10284 unallocated_encoding(s
);
10288 case 0x00: /* SSHR / USHR */
10289 case 0x02: /* SSRA / USRA (accumulate) */
10290 case 0x04: /* SRSHR / URSHR (rounding) */
10291 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10292 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10294 case 0x0a: /* SHL / SLI */
10295 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10297 case 0x10: /* SHRN */
10298 case 0x11: /* RSHRN / SQRSHRUN */
10300 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
10303 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
10306 case 0x12: /* SQSHRN / UQSHRN */
10307 case 0x13: /* SQRSHRN / UQRSHRN */
10308 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
10311 case 0x14: /* SSHLL / USHLL */
10312 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10314 case 0x1c: /* SCVTF / UCVTF */
10315 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
10318 case 0xc: /* SQSHLU */
10320 unallocated_encoding(s
);
10323 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
10325 case 0xe: /* SQSHL, UQSHL */
10326 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
10328 case 0x1f: /* FCVTZS/ FCVTZU */
10329 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
10332 unallocated_encoding(s
);
10337 /* Generate code to do a "long" addition or subtraction, ie one done in
10338 * TCGv_i64 on vector lanes twice the width specified by size.
10340 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
10341 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
10343 static NeonGenTwo64OpFn
* const fns
[3][2] = {
10344 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
10345 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
10346 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
10348 NeonGenTwo64OpFn
*genfn
;
10351 genfn
= fns
[size
][is_sub
];
10352 genfn(tcg_res
, tcg_op1
, tcg_op2
);
10355 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
10356 int opcode
, int rd
, int rn
, int rm
)
10358 /* 3-reg-different widening insns: 64 x 64 -> 128 */
10359 TCGv_i64 tcg_res
[2];
10362 tcg_res
[0] = tcg_temp_new_i64();
10363 tcg_res
[1] = tcg_temp_new_i64();
10365 /* Does this op do an adding accumulate, a subtracting accumulate,
10366 * or no accumulate at all?
10384 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10385 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10388 /* size == 2 means two 32x32->64 operations; this is worth special
10389 * casing because we can generally handle it inline.
10392 for (pass
= 0; pass
< 2; pass
++) {
10393 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10394 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10395 TCGv_i64 tcg_passres
;
10396 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
10398 int elt
= pass
+ is_q
* 2;
10400 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
10401 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
10404 tcg_passres
= tcg_res
[pass
];
10406 tcg_passres
= tcg_temp_new_i64();
10410 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10411 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10413 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10414 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10416 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10417 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10419 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
10420 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
10422 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
10423 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
10424 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
10426 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
10427 tcg_temp_free_i64(tcg_tmp1
);
10428 tcg_temp_free_i64(tcg_tmp2
);
10431 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10432 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10433 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10434 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10436 case 9: /* SQDMLAL, SQDMLAL2 */
10437 case 11: /* SQDMLSL, SQDMLSL2 */
10438 case 13: /* SQDMULL, SQDMULL2 */
10439 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10440 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10441 tcg_passres
, tcg_passres
);
10444 g_assert_not_reached();
10447 if (opcode
== 9 || opcode
== 11) {
10448 /* saturating accumulate ops */
10450 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10452 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10453 tcg_res
[pass
], tcg_passres
);
10454 } else if (accop
> 0) {
10455 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10456 } else if (accop
< 0) {
10457 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10461 tcg_temp_free_i64(tcg_passres
);
10464 tcg_temp_free_i64(tcg_op1
);
10465 tcg_temp_free_i64(tcg_op2
);
10468 /* size 0 or 1, generally helper functions */
10469 for (pass
= 0; pass
< 2; pass
++) {
10470 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10471 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10472 TCGv_i64 tcg_passres
;
10473 int elt
= pass
+ is_q
* 2;
10475 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
10476 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
10479 tcg_passres
= tcg_res
[pass
];
10481 tcg_passres
= tcg_temp_new_i64();
10485 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10486 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10488 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
10489 static NeonGenWidenFn
* const widenfns
[2][2] = {
10490 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10491 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10493 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10495 widenfn(tcg_op2_64
, tcg_op2
);
10496 widenfn(tcg_passres
, tcg_op1
);
10497 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
10498 tcg_passres
, tcg_op2_64
);
10499 tcg_temp_free_i64(tcg_op2_64
);
10502 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10503 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10506 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10508 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10512 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
10514 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
10518 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10519 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10520 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10523 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
10525 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
10529 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10531 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10535 case 9: /* SQDMLAL, SQDMLAL2 */
10536 case 11: /* SQDMLSL, SQDMLSL2 */
10537 case 13: /* SQDMULL, SQDMULL2 */
10539 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10540 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10541 tcg_passres
, tcg_passres
);
10543 case 14: /* PMULL */
10545 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
10548 g_assert_not_reached();
10550 tcg_temp_free_i32(tcg_op1
);
10551 tcg_temp_free_i32(tcg_op2
);
10554 if (opcode
== 9 || opcode
== 11) {
10555 /* saturating accumulate ops */
10557 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10559 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10563 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
10564 tcg_res
[pass
], tcg_passres
);
10566 tcg_temp_free_i64(tcg_passres
);
10571 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10572 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10573 tcg_temp_free_i64(tcg_res
[0]);
10574 tcg_temp_free_i64(tcg_res
[1]);
10577 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
10578 int opcode
, int rd
, int rn
, int rm
)
10580 TCGv_i64 tcg_res
[2];
10581 int part
= is_q
? 2 : 0;
10584 for (pass
= 0; pass
< 2; pass
++) {
10585 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10586 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10587 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
10588 static NeonGenWidenFn
* const widenfns
[3][2] = {
10589 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10590 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10591 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
10593 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10595 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10596 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
10597 widenfn(tcg_op2_wide
, tcg_op2
);
10598 tcg_temp_free_i32(tcg_op2
);
10599 tcg_res
[pass
] = tcg_temp_new_i64();
10600 gen_neon_addl(size
, (opcode
== 3),
10601 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
10602 tcg_temp_free_i64(tcg_op1
);
10603 tcg_temp_free_i64(tcg_op2_wide
);
10606 for (pass
= 0; pass
< 2; pass
++) {
10607 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10608 tcg_temp_free_i64(tcg_res
[pass
]);
10612 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
10614 tcg_gen_addi_i64(in
, in
, 1U << 31);
10615 tcg_gen_extrh_i64_i32(res
, in
);
10618 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
10619 int opcode
, int rd
, int rn
, int rm
)
10621 TCGv_i32 tcg_res
[2];
10622 int part
= is_q
? 2 : 0;
10625 for (pass
= 0; pass
< 2; pass
++) {
10626 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10627 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10628 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
10629 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
10630 { gen_helper_neon_narrow_high_u8
,
10631 gen_helper_neon_narrow_round_high_u8
},
10632 { gen_helper_neon_narrow_high_u16
,
10633 gen_helper_neon_narrow_round_high_u16
},
10634 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
10636 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
10638 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10639 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
10641 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
10643 tcg_temp_free_i64(tcg_op1
);
10644 tcg_temp_free_i64(tcg_op2
);
10646 tcg_res
[pass
] = tcg_temp_new_i32();
10647 gennarrow(tcg_res
[pass
], tcg_wideres
);
10648 tcg_temp_free_i64(tcg_wideres
);
10651 for (pass
= 0; pass
< 2; pass
++) {
10652 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
10653 tcg_temp_free_i32(tcg_res
[pass
]);
10655 clear_vec_high(s
, is_q
, rd
);
10658 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
10660 /* PMULL of 64 x 64 -> 128 is an odd special case because it
10661 * is the only three-reg-diff instruction which produces a
10662 * 128-bit wide result from a single operation. However since
10663 * it's possible to calculate the two halves more or less
10664 * separately we just use two helper calls.
10666 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10667 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10668 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10670 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
10671 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
10672 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
10673 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
10674 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
10675 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
10677 tcg_temp_free_i64(tcg_op1
);
10678 tcg_temp_free_i64(tcg_op2
);
10679 tcg_temp_free_i64(tcg_res
);
10682 /* AdvSIMD three different
10683 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
10684 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10685 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
10686 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10688 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
10690 /* Instructions in this group fall into three basic classes
10691 * (in each case with the operation working on each element in
10692 * the input vectors):
10693 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
10695 * (2) wide 64 x 128 -> 128
10696 * (3) narrowing 128 x 128 -> 64
10697 * Here we do initial decode, catch unallocated cases and
10698 * dispatch to separate functions for each class.
10700 int is_q
= extract32(insn
, 30, 1);
10701 int is_u
= extract32(insn
, 29, 1);
10702 int size
= extract32(insn
, 22, 2);
10703 int opcode
= extract32(insn
, 12, 4);
10704 int rm
= extract32(insn
, 16, 5);
10705 int rn
= extract32(insn
, 5, 5);
10706 int rd
= extract32(insn
, 0, 5);
10709 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
10710 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
10711 /* 64 x 128 -> 128 */
10713 unallocated_encoding(s
);
10716 if (!fp_access_check(s
)) {
10719 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10721 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
10722 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
10723 /* 128 x 128 -> 64 */
10725 unallocated_encoding(s
);
10728 if (!fp_access_check(s
)) {
10731 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10733 case 14: /* PMULL, PMULL2 */
10734 if (is_u
|| size
== 1 || size
== 2) {
10735 unallocated_encoding(s
);
10739 if (!dc_isar_feature(aa64_pmull
, s
)) {
10740 unallocated_encoding(s
);
10743 if (!fp_access_check(s
)) {
10746 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
10750 case 9: /* SQDMLAL, SQDMLAL2 */
10751 case 11: /* SQDMLSL, SQDMLSL2 */
10752 case 13: /* SQDMULL, SQDMULL2 */
10753 if (is_u
|| size
== 0) {
10754 unallocated_encoding(s
);
10758 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10759 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10760 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10761 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10762 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10763 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10764 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
10765 /* 64 x 64 -> 128 */
10767 unallocated_encoding(s
);
10771 if (!fp_access_check(s
)) {
10775 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10778 /* opcode 15 not allocated */
10779 unallocated_encoding(s
);
10784 /* Logic op (opcode == 3) subgroup of C3.6.16. */
10785 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
10787 int rd
= extract32(insn
, 0, 5);
10788 int rn
= extract32(insn
, 5, 5);
10789 int rm
= extract32(insn
, 16, 5);
10790 int size
= extract32(insn
, 22, 2);
10791 bool is_u
= extract32(insn
, 29, 1);
10792 bool is_q
= extract32(insn
, 30, 1);
10794 if (!fp_access_check(s
)) {
10798 switch (size
+ 4 * is_u
) {
10800 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_and
, 0);
10803 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_andc
, 0);
10806 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_or
, 0);
10809 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_orc
, 0);
10812 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_xor
, 0);
10815 case 5: /* BSL bitwise select */
10816 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bsl_op
);
10818 case 6: /* BIT, bitwise insert if true */
10819 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bit_op
);
10821 case 7: /* BIF, bitwise insert if false */
10822 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bif_op
);
10826 g_assert_not_reached();
10830 /* Pairwise op subgroup of C3.6.16.
10832 * This is called directly or via the handle_3same_float for float pairwise
10833 * operations where the opcode and size are calculated differently.
10835 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
10836 int size
, int rn
, int rm
, int rd
)
10841 /* Floating point operations need fpst */
10842 if (opcode
>= 0x58) {
10843 fpst
= get_fpstatus_ptr(false);
10848 if (!fp_access_check(s
)) {
10852 /* These operations work on the concatenated rm:rn, with each pair of
10853 * adjacent elements being operated on to produce an element in the result.
10856 TCGv_i64 tcg_res
[2];
10858 for (pass
= 0; pass
< 2; pass
++) {
10859 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10860 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10861 int passreg
= (pass
== 0) ? rn
: rm
;
10863 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
10864 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
10865 tcg_res
[pass
] = tcg_temp_new_i64();
10868 case 0x17: /* ADDP */
10869 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10871 case 0x58: /* FMAXNMP */
10872 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10874 case 0x5a: /* FADDP */
10875 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10877 case 0x5e: /* FMAXP */
10878 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10880 case 0x78: /* FMINNMP */
10881 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10883 case 0x7e: /* FMINP */
10884 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10887 g_assert_not_reached();
10890 tcg_temp_free_i64(tcg_op1
);
10891 tcg_temp_free_i64(tcg_op2
);
10894 for (pass
= 0; pass
< 2; pass
++) {
10895 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10896 tcg_temp_free_i64(tcg_res
[pass
]);
10899 int maxpass
= is_q
? 4 : 2;
10900 TCGv_i32 tcg_res
[4];
10902 for (pass
= 0; pass
< maxpass
; pass
++) {
10903 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10904 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10905 NeonGenTwoOpFn
*genfn
= NULL
;
10906 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
10907 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
10909 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
10910 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
10911 tcg_res
[pass
] = tcg_temp_new_i32();
10914 case 0x17: /* ADDP */
10916 static NeonGenTwoOpFn
* const fns
[3] = {
10917 gen_helper_neon_padd_u8
,
10918 gen_helper_neon_padd_u16
,
10924 case 0x14: /* SMAXP, UMAXP */
10926 static NeonGenTwoOpFn
* const fns
[3][2] = {
10927 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
10928 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
10929 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
10931 genfn
= fns
[size
][u
];
10934 case 0x15: /* SMINP, UMINP */
10936 static NeonGenTwoOpFn
* const fns
[3][2] = {
10937 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
10938 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
10939 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
10941 genfn
= fns
[size
][u
];
10944 /* The FP operations are all on single floats (32 bit) */
10945 case 0x58: /* FMAXNMP */
10946 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10948 case 0x5a: /* FADDP */
10949 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10951 case 0x5e: /* FMAXP */
10952 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10954 case 0x78: /* FMINNMP */
10955 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10957 case 0x7e: /* FMINP */
10958 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10961 g_assert_not_reached();
10964 /* FP ops called directly, otherwise call now */
10966 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10969 tcg_temp_free_i32(tcg_op1
);
10970 tcg_temp_free_i32(tcg_op2
);
10973 for (pass
= 0; pass
< maxpass
; pass
++) {
10974 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
10975 tcg_temp_free_i32(tcg_res
[pass
]);
10977 clear_vec_high(s
, is_q
, rd
);
10981 tcg_temp_free_ptr(fpst
);
10985 /* Floating point op subgroup of C3.6.16. */
10986 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
10988 /* For floating point ops, the U, size[1] and opcode bits
10989 * together indicate the operation. size[0] indicates single
10992 int fpopcode
= extract32(insn
, 11, 5)
10993 | (extract32(insn
, 23, 1) << 5)
10994 | (extract32(insn
, 29, 1) << 6);
10995 int is_q
= extract32(insn
, 30, 1);
10996 int size
= extract32(insn
, 22, 1);
10997 int rm
= extract32(insn
, 16, 5);
10998 int rn
= extract32(insn
, 5, 5);
10999 int rd
= extract32(insn
, 0, 5);
11001 int datasize
= is_q
? 128 : 64;
11002 int esize
= 32 << size
;
11003 int elements
= datasize
/ esize
;
11005 if (size
== 1 && !is_q
) {
11006 unallocated_encoding(s
);
11010 switch (fpopcode
) {
11011 case 0x58: /* FMAXNMP */
11012 case 0x5a: /* FADDP */
11013 case 0x5e: /* FMAXP */
11014 case 0x78: /* FMINNMP */
11015 case 0x7e: /* FMINP */
11016 if (size
&& !is_q
) {
11017 unallocated_encoding(s
);
11020 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
11023 case 0x1b: /* FMULX */
11024 case 0x1f: /* FRECPS */
11025 case 0x3f: /* FRSQRTS */
11026 case 0x5d: /* FACGE */
11027 case 0x7d: /* FACGT */
11028 case 0x19: /* FMLA */
11029 case 0x39: /* FMLS */
11030 case 0x18: /* FMAXNM */
11031 case 0x1a: /* FADD */
11032 case 0x1c: /* FCMEQ */
11033 case 0x1e: /* FMAX */
11034 case 0x38: /* FMINNM */
11035 case 0x3a: /* FSUB */
11036 case 0x3e: /* FMIN */
11037 case 0x5b: /* FMUL */
11038 case 0x5c: /* FCMGE */
11039 case 0x5f: /* FDIV */
11040 case 0x7a: /* FABD */
11041 case 0x7c: /* FCMGT */
11042 if (!fp_access_check(s
)) {
11045 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
11048 case 0x1d: /* FMLAL */
11049 case 0x3d: /* FMLSL */
11050 case 0x59: /* FMLAL2 */
11051 case 0x79: /* FMLSL2 */
11052 if (size
& 1 || !dc_isar_feature(aa64_fhm
, s
)) {
11053 unallocated_encoding(s
);
11056 if (fp_access_check(s
)) {
11057 int is_s
= extract32(insn
, 23, 1);
11058 int is_2
= extract32(insn
, 29, 1);
11059 int data
= (is_2
<< 1) | is_s
;
11060 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
11061 vec_full_reg_offset(s
, rn
),
11062 vec_full_reg_offset(s
, rm
), cpu_env
,
11063 is_q
? 16 : 8, vec_full_reg_size(s
),
11064 data
, gen_helper_gvec_fmlal_a64
);
11069 unallocated_encoding(s
);
11074 /* Integer op subgroup of C3.6.16. */
11075 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
11077 int is_q
= extract32(insn
, 30, 1);
11078 int u
= extract32(insn
, 29, 1);
11079 int size
= extract32(insn
, 22, 2);
11080 int opcode
= extract32(insn
, 11, 5);
11081 int rm
= extract32(insn
, 16, 5);
11082 int rn
= extract32(insn
, 5, 5);
11083 int rd
= extract32(insn
, 0, 5);
11088 case 0x13: /* MUL, PMUL */
11089 if (u
&& size
!= 0) {
11090 unallocated_encoding(s
);
11094 case 0x0: /* SHADD, UHADD */
11095 case 0x2: /* SRHADD, URHADD */
11096 case 0x4: /* SHSUB, UHSUB */
11097 case 0xc: /* SMAX, UMAX */
11098 case 0xd: /* SMIN, UMIN */
11099 case 0xe: /* SABD, UABD */
11100 case 0xf: /* SABA, UABA */
11101 case 0x12: /* MLA, MLS */
11103 unallocated_encoding(s
);
11107 case 0x16: /* SQDMULH, SQRDMULH */
11108 if (size
== 0 || size
== 3) {
11109 unallocated_encoding(s
);
11114 if (size
== 3 && !is_q
) {
11115 unallocated_encoding(s
);
11121 if (!fp_access_check(s
)) {
11126 case 0x01: /* SQADD, UQADD */
11127 tcg_gen_gvec_4(vec_full_reg_offset(s
, rd
),
11128 offsetof(CPUARMState
, vfp
.qc
),
11129 vec_full_reg_offset(s
, rn
),
11130 vec_full_reg_offset(s
, rm
),
11131 is_q
? 16 : 8, vec_full_reg_size(s
),
11132 (u
? uqadd_op
: sqadd_op
) + size
);
11134 case 0x05: /* SQSUB, UQSUB */
11135 tcg_gen_gvec_4(vec_full_reg_offset(s
, rd
),
11136 offsetof(CPUARMState
, vfp
.qc
),
11137 vec_full_reg_offset(s
, rn
),
11138 vec_full_reg_offset(s
, rm
),
11139 is_q
? 16 : 8, vec_full_reg_size(s
),
11140 (u
? uqsub_op
: sqsub_op
) + size
);
11142 case 0x0c: /* SMAX, UMAX */
11144 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umax
, size
);
11146 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smax
, size
);
11149 case 0x0d: /* SMIN, UMIN */
11151 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umin
, size
);
11153 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smin
, size
);
11156 case 0x10: /* ADD, SUB */
11158 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_sub
, size
);
11160 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_add
, size
);
11163 case 0x13: /* MUL, PMUL */
11164 if (!u
) { /* MUL */
11165 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_mul
, size
);
11169 case 0x12: /* MLA, MLS */
11171 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mls_op
[size
]);
11173 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mla_op
[size
]);
11177 if (!u
) { /* CMTST */
11178 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &cmtst_op
[size
]);
11182 cond
= TCG_COND_EQ
;
11184 case 0x06: /* CMGT, CMHI */
11185 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
11187 case 0x07: /* CMGE, CMHS */
11188 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
11190 tcg_gen_gvec_cmp(cond
, size
, vec_full_reg_offset(s
, rd
),
11191 vec_full_reg_offset(s
, rn
),
11192 vec_full_reg_offset(s
, rm
),
11193 is_q
? 16 : 8, vec_full_reg_size(s
));
11199 for (pass
= 0; pass
< 2; pass
++) {
11200 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11201 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11202 TCGv_i64 tcg_res
= tcg_temp_new_i64();
11204 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11205 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
11207 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
11209 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
11211 tcg_temp_free_i64(tcg_res
);
11212 tcg_temp_free_i64(tcg_op1
);
11213 tcg_temp_free_i64(tcg_op2
);
11216 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
11217 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11218 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11219 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11220 NeonGenTwoOpFn
*genfn
= NULL
;
11221 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
11223 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
11224 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
11227 case 0x0: /* SHADD, UHADD */
11229 static NeonGenTwoOpFn
* const fns
[3][2] = {
11230 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
11231 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
11232 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
11234 genfn
= fns
[size
][u
];
11237 case 0x2: /* SRHADD, URHADD */
11239 static NeonGenTwoOpFn
* const fns
[3][2] = {
11240 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
11241 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
11242 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
11244 genfn
= fns
[size
][u
];
11247 case 0x4: /* SHSUB, UHSUB */
11249 static NeonGenTwoOpFn
* const fns
[3][2] = {
11250 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
11251 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
11252 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
11254 genfn
= fns
[size
][u
];
11257 case 0x8: /* SSHL, USHL */
11259 static NeonGenTwoOpFn
* const fns
[3][2] = {
11260 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
11261 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
11262 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
11264 genfn
= fns
[size
][u
];
11267 case 0x9: /* SQSHL, UQSHL */
11269 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11270 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
11271 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
11272 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
11274 genenvfn
= fns
[size
][u
];
11277 case 0xa: /* SRSHL, URSHL */
11279 static NeonGenTwoOpFn
* const fns
[3][2] = {
11280 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
11281 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
11282 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
11284 genfn
= fns
[size
][u
];
11287 case 0xb: /* SQRSHL, UQRSHL */
11289 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11290 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
11291 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
11292 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
11294 genenvfn
= fns
[size
][u
];
11297 case 0xe: /* SABD, UABD */
11298 case 0xf: /* SABA, UABA */
11300 static NeonGenTwoOpFn
* const fns
[3][2] = {
11301 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
11302 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
11303 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
11305 genfn
= fns
[size
][u
];
11308 case 0x13: /* MUL, PMUL */
11309 assert(u
); /* PMUL */
11311 genfn
= gen_helper_neon_mul_p8
;
11313 case 0x16: /* SQDMULH, SQRDMULH */
11315 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
11316 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
11317 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
11319 assert(size
== 1 || size
== 2);
11320 genenvfn
= fns
[size
- 1][u
];
11324 g_assert_not_reached();
11328 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
11330 genfn(tcg_res
, tcg_op1
, tcg_op2
);
11333 if (opcode
== 0xf) {
11334 /* SABA, UABA: accumulating ops */
11335 static NeonGenTwoOpFn
* const fns
[3] = {
11336 gen_helper_neon_add_u8
,
11337 gen_helper_neon_add_u16
,
11341 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
11342 fns
[size
](tcg_res
, tcg_op1
, tcg_res
);
11345 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
11347 tcg_temp_free_i32(tcg_res
);
11348 tcg_temp_free_i32(tcg_op1
);
11349 tcg_temp_free_i32(tcg_op2
);
11352 clear_vec_high(s
, is_q
, rd
);
11355 /* AdvSIMD three same
11356 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11357 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11358 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11359 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11361 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
11363 int opcode
= extract32(insn
, 11, 5);
11366 case 0x3: /* logic ops */
11367 disas_simd_3same_logic(s
, insn
);
11369 case 0x17: /* ADDP */
11370 case 0x14: /* SMAXP, UMAXP */
11371 case 0x15: /* SMINP, UMINP */
11373 /* Pairwise operations */
11374 int is_q
= extract32(insn
, 30, 1);
11375 int u
= extract32(insn
, 29, 1);
11376 int size
= extract32(insn
, 22, 2);
11377 int rm
= extract32(insn
, 16, 5);
11378 int rn
= extract32(insn
, 5, 5);
11379 int rd
= extract32(insn
, 0, 5);
11380 if (opcode
== 0x17) {
11381 if (u
|| (size
== 3 && !is_q
)) {
11382 unallocated_encoding(s
);
11387 unallocated_encoding(s
);
11391 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
11394 case 0x18 ... 0x31:
11395 /* floating point ops, sz[1] and U are part of opcode */
11396 disas_simd_3same_float(s
, insn
);
11399 disas_simd_3same_int(s
, insn
);
11405 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11407 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11408 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11409 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11410 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11412 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11413 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11416 static void disas_simd_three_reg_same_fp16(DisasContext
*s
, uint32_t insn
)
11418 int opcode
, fpopcode
;
11419 int is_q
, u
, a
, rm
, rn
, rd
;
11420 int datasize
, elements
;
11423 bool pairwise
= false;
11425 if (!dc_isar_feature(aa64_fp16
, s
)) {
11426 unallocated_encoding(s
);
11430 if (!fp_access_check(s
)) {
11434 /* For these floating point ops, the U, a and opcode bits
11435 * together indicate the operation.
11437 opcode
= extract32(insn
, 11, 3);
11438 u
= extract32(insn
, 29, 1);
11439 a
= extract32(insn
, 23, 1);
11440 is_q
= extract32(insn
, 30, 1);
11441 rm
= extract32(insn
, 16, 5);
11442 rn
= extract32(insn
, 5, 5);
11443 rd
= extract32(insn
, 0, 5);
11445 fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
11446 datasize
= is_q
? 128 : 64;
11447 elements
= datasize
/ 16;
11449 switch (fpopcode
) {
11450 case 0x10: /* FMAXNMP */
11451 case 0x12: /* FADDP */
11452 case 0x16: /* FMAXP */
11453 case 0x18: /* FMINNMP */
11454 case 0x1e: /* FMINP */
11459 fpst
= get_fpstatus_ptr(true);
11462 int maxpass
= is_q
? 8 : 4;
11463 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11464 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11465 TCGv_i32 tcg_res
[8];
11467 for (pass
= 0; pass
< maxpass
; pass
++) {
11468 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
11469 int passelt
= (pass
<< 1) & (maxpass
- 1);
11471 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_16
);
11472 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_16
);
11473 tcg_res
[pass
] = tcg_temp_new_i32();
11475 switch (fpopcode
) {
11476 case 0x10: /* FMAXNMP */
11477 gen_helper_advsimd_maxnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11480 case 0x12: /* FADDP */
11481 gen_helper_advsimd_addh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11483 case 0x16: /* FMAXP */
11484 gen_helper_advsimd_maxh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11486 case 0x18: /* FMINNMP */
11487 gen_helper_advsimd_minnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11490 case 0x1e: /* FMINP */
11491 gen_helper_advsimd_minh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11494 g_assert_not_reached();
11498 for (pass
= 0; pass
< maxpass
; pass
++) {
11499 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_16
);
11500 tcg_temp_free_i32(tcg_res
[pass
]);
11503 tcg_temp_free_i32(tcg_op1
);
11504 tcg_temp_free_i32(tcg_op2
);
11507 for (pass
= 0; pass
< elements
; pass
++) {
11508 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11509 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11510 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11512 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_16
);
11513 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_16
);
11515 switch (fpopcode
) {
11516 case 0x0: /* FMAXNM */
11517 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11519 case 0x1: /* FMLA */
11520 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11521 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11524 case 0x2: /* FADD */
11525 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11527 case 0x3: /* FMULX */
11528 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11530 case 0x4: /* FCMEQ */
11531 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11533 case 0x6: /* FMAX */
11534 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11536 case 0x7: /* FRECPS */
11537 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11539 case 0x8: /* FMINNM */
11540 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11542 case 0x9: /* FMLS */
11543 /* As usual for ARM, separate negation for fused multiply-add */
11544 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
11545 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11546 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11549 case 0xa: /* FSUB */
11550 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11552 case 0xe: /* FMIN */
11553 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11555 case 0xf: /* FRSQRTS */
11556 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11558 case 0x13: /* FMUL */
11559 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11561 case 0x14: /* FCMGE */
11562 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11564 case 0x15: /* FACGE */
11565 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11567 case 0x17: /* FDIV */
11568 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11570 case 0x1a: /* FABD */
11571 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11572 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
11574 case 0x1c: /* FCMGT */
11575 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11577 case 0x1d: /* FACGT */
11578 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11581 fprintf(stderr
, "%s: insn %#04x, fpop %#2x @ %#" PRIx64
"\n",
11582 __func__
, insn
, fpopcode
, s
->pc
);
11583 g_assert_not_reached();
11586 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11587 tcg_temp_free_i32(tcg_res
);
11588 tcg_temp_free_i32(tcg_op1
);
11589 tcg_temp_free_i32(tcg_op2
);
11593 tcg_temp_free_ptr(fpst
);
11595 clear_vec_high(s
, is_q
, rd
);
11598 /* AdvSIMD three same extra
11599 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
11600 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11601 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
11602 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11604 static void disas_simd_three_reg_same_extra(DisasContext
*s
, uint32_t insn
)
11606 int rd
= extract32(insn
, 0, 5);
11607 int rn
= extract32(insn
, 5, 5);
11608 int opcode
= extract32(insn
, 11, 4);
11609 int rm
= extract32(insn
, 16, 5);
11610 int size
= extract32(insn
, 22, 2);
11611 bool u
= extract32(insn
, 29, 1);
11612 bool is_q
= extract32(insn
, 30, 1);
11616 switch (u
* 16 + opcode
) {
11617 case 0x10: /* SQRDMLAH (vector) */
11618 case 0x11: /* SQRDMLSH (vector) */
11619 if (size
!= 1 && size
!= 2) {
11620 unallocated_encoding(s
);
11623 feature
= dc_isar_feature(aa64_rdm
, s
);
11625 case 0x02: /* SDOT (vector) */
11626 case 0x12: /* UDOT (vector) */
11627 if (size
!= MO_32
) {
11628 unallocated_encoding(s
);
11631 feature
= dc_isar_feature(aa64_dp
, s
);
11633 case 0x18: /* FCMLA, #0 */
11634 case 0x19: /* FCMLA, #90 */
11635 case 0x1a: /* FCMLA, #180 */
11636 case 0x1b: /* FCMLA, #270 */
11637 case 0x1c: /* FCADD, #90 */
11638 case 0x1e: /* FCADD, #270 */
11640 || (size
== 1 && !dc_isar_feature(aa64_fp16
, s
))
11641 || (size
== 3 && !is_q
)) {
11642 unallocated_encoding(s
);
11645 feature
= dc_isar_feature(aa64_fcma
, s
);
11648 unallocated_encoding(s
);
11652 unallocated_encoding(s
);
11655 if (!fp_access_check(s
)) {
11660 case 0x0: /* SQRDMLAH (vector) */
11663 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s16
);
11666 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s32
);
11669 g_assert_not_reached();
11673 case 0x1: /* SQRDMLSH (vector) */
11676 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s16
);
11679 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s32
);
11682 g_assert_not_reached();
11686 case 0x2: /* SDOT / UDOT */
11687 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, 0,
11688 u
? gen_helper_gvec_udot_b
: gen_helper_gvec_sdot_b
);
11691 case 0x8: /* FCMLA, #0 */
11692 case 0x9: /* FCMLA, #90 */
11693 case 0xa: /* FCMLA, #180 */
11694 case 0xb: /* FCMLA, #270 */
11695 rot
= extract32(opcode
, 0, 2);
11698 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, true, rot
,
11699 gen_helper_gvec_fcmlah
);
11702 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11703 gen_helper_gvec_fcmlas
);
11706 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11707 gen_helper_gvec_fcmlad
);
11710 g_assert_not_reached();
11714 case 0xc: /* FCADD, #90 */
11715 case 0xe: /* FCADD, #270 */
11716 rot
= extract32(opcode
, 1, 1);
11719 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11720 gen_helper_gvec_fcaddh
);
11723 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11724 gen_helper_gvec_fcadds
);
11727 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11728 gen_helper_gvec_fcaddd
);
11731 g_assert_not_reached();
11736 g_assert_not_reached();
11740 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
11741 int size
, int rn
, int rd
)
11743 /* Handle 2-reg-misc ops which are widening (so each size element
11744 * in the source becomes a 2*size element in the destination.
11745 * The only instruction like this is FCVTL.
11750 /* 32 -> 64 bit fp conversion */
11751 TCGv_i64 tcg_res
[2];
11752 int srcelt
= is_q
? 2 : 0;
11754 for (pass
= 0; pass
< 2; pass
++) {
11755 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11756 tcg_res
[pass
] = tcg_temp_new_i64();
11758 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
11759 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
11760 tcg_temp_free_i32(tcg_op
);
11762 for (pass
= 0; pass
< 2; pass
++) {
11763 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11764 tcg_temp_free_i64(tcg_res
[pass
]);
11767 /* 16 -> 32 bit fp conversion */
11768 int srcelt
= is_q
? 4 : 0;
11769 TCGv_i32 tcg_res
[4];
11770 TCGv_ptr fpst
= get_fpstatus_ptr(false);
11771 TCGv_i32 ahp
= get_ahp_flag();
11773 for (pass
= 0; pass
< 4; pass
++) {
11774 tcg_res
[pass
] = tcg_temp_new_i32();
11776 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
11777 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
11780 for (pass
= 0; pass
< 4; pass
++) {
11781 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
11782 tcg_temp_free_i32(tcg_res
[pass
]);
11785 tcg_temp_free_ptr(fpst
);
11786 tcg_temp_free_i32(ahp
);
11790 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
11791 bool is_q
, int size
, int rn
, int rd
)
11793 int op
= (opcode
<< 1) | u
;
11794 int opsz
= op
+ size
;
11795 int grp_size
= 3 - opsz
;
11796 int dsize
= is_q
? 128 : 64;
11800 unallocated_encoding(s
);
11804 if (!fp_access_check(s
)) {
11809 /* Special case bytes, use bswap op on each group of elements */
11810 int groups
= dsize
/ (8 << grp_size
);
11812 for (i
= 0; i
< groups
; i
++) {
11813 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
11815 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
11816 switch (grp_size
) {
11818 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
11821 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
11824 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
11827 g_assert_not_reached();
11829 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
11830 tcg_temp_free_i64(tcg_tmp
);
11832 clear_vec_high(s
, is_q
, rd
);
11834 int revmask
= (1 << grp_size
) - 1;
11835 int esize
= 8 << size
;
11836 int elements
= dsize
/ esize
;
11837 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
11838 TCGv_i64 tcg_rd
= tcg_const_i64(0);
11839 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
11841 for (i
= 0; i
< elements
; i
++) {
11842 int e_rev
= (i
& 0xf) ^ revmask
;
11843 int off
= e_rev
* esize
;
11844 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
11846 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
11847 tcg_rn
, off
- 64, esize
);
11849 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
11852 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
11853 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
11855 tcg_temp_free_i64(tcg_rd_hi
);
11856 tcg_temp_free_i64(tcg_rd
);
11857 tcg_temp_free_i64(tcg_rn
);
11861 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
11862 bool is_q
, int size
, int rn
, int rd
)
11864 /* Implement the pairwise operations from 2-misc:
11865 * SADDLP, UADDLP, SADALP, UADALP.
11866 * These all add pairs of elements in the input to produce a
11867 * double-width result element in the output (possibly accumulating).
11869 bool accum
= (opcode
== 0x6);
11870 int maxpass
= is_q
? 2 : 1;
11872 TCGv_i64 tcg_res
[2];
11875 /* 32 + 32 -> 64 op */
11876 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
11878 for (pass
= 0; pass
< maxpass
; pass
++) {
11879 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11880 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11882 tcg_res
[pass
] = tcg_temp_new_i64();
11884 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
11885 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
11886 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11888 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
11889 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
11892 tcg_temp_free_i64(tcg_op1
);
11893 tcg_temp_free_i64(tcg_op2
);
11896 for (pass
= 0; pass
< maxpass
; pass
++) {
11897 TCGv_i64 tcg_op
= tcg_temp_new_i64();
11898 NeonGenOneOpFn
*genfn
;
11899 static NeonGenOneOpFn
* const fns
[2][2] = {
11900 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
11901 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
11904 genfn
= fns
[size
][u
];
11906 tcg_res
[pass
] = tcg_temp_new_i64();
11908 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
11909 genfn(tcg_res
[pass
], tcg_op
);
11912 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
11914 gen_helper_neon_addl_u16(tcg_res
[pass
],
11915 tcg_res
[pass
], tcg_op
);
11917 gen_helper_neon_addl_u32(tcg_res
[pass
],
11918 tcg_res
[pass
], tcg_op
);
11921 tcg_temp_free_i64(tcg_op
);
11925 tcg_res
[1] = tcg_const_i64(0);
11927 for (pass
= 0; pass
< 2; pass
++) {
11928 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11929 tcg_temp_free_i64(tcg_res
[pass
]);
11933 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
11935 /* Implement SHLL and SHLL2 */
11937 int part
= is_q
? 2 : 0;
11938 TCGv_i64 tcg_res
[2];
11940 for (pass
= 0; pass
< 2; pass
++) {
11941 static NeonGenWidenFn
* const widenfns
[3] = {
11942 gen_helper_neon_widen_u8
,
11943 gen_helper_neon_widen_u16
,
11944 tcg_gen_extu_i32_i64
,
11946 NeonGenWidenFn
*widenfn
= widenfns
[size
];
11947 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11949 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
11950 tcg_res
[pass
] = tcg_temp_new_i64();
11951 widenfn(tcg_res
[pass
], tcg_op
);
11952 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
11954 tcg_temp_free_i32(tcg_op
);
11957 for (pass
= 0; pass
< 2; pass
++) {
11958 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11959 tcg_temp_free_i64(tcg_res
[pass
]);
11963 /* AdvSIMD two reg misc
11964 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
11965 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11966 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
11967 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11969 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
11971 int size
= extract32(insn
, 22, 2);
11972 int opcode
= extract32(insn
, 12, 5);
11973 bool u
= extract32(insn
, 29, 1);
11974 bool is_q
= extract32(insn
, 30, 1);
11975 int rn
= extract32(insn
, 5, 5);
11976 int rd
= extract32(insn
, 0, 5);
11977 bool need_fpstatus
= false;
11978 bool need_rmode
= false;
11980 TCGv_i32 tcg_rmode
;
11981 TCGv_ptr tcg_fpstatus
;
11984 case 0x0: /* REV64, REV32 */
11985 case 0x1: /* REV16 */
11986 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
11988 case 0x5: /* CNT, NOT, RBIT */
11989 if (u
&& size
== 0) {
11992 } else if (u
&& size
== 1) {
11995 } else if (!u
&& size
== 0) {
11999 unallocated_encoding(s
);
12001 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
12002 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
12004 unallocated_encoding(s
);
12007 if (!fp_access_check(s
)) {
12011 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
12013 case 0x4: /* CLS, CLZ */
12015 unallocated_encoding(s
);
12019 case 0x2: /* SADDLP, UADDLP */
12020 case 0x6: /* SADALP, UADALP */
12022 unallocated_encoding(s
);
12025 if (!fp_access_check(s
)) {
12028 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
12030 case 0x13: /* SHLL, SHLL2 */
12031 if (u
== 0 || size
== 3) {
12032 unallocated_encoding(s
);
12035 if (!fp_access_check(s
)) {
12038 handle_shll(s
, is_q
, size
, rn
, rd
);
12040 case 0xa: /* CMLT */
12042 unallocated_encoding(s
);
12046 case 0x8: /* CMGT, CMGE */
12047 case 0x9: /* CMEQ, CMLE */
12048 case 0xb: /* ABS, NEG */
12049 if (size
== 3 && !is_q
) {
12050 unallocated_encoding(s
);
12054 case 0x3: /* SUQADD, USQADD */
12055 if (size
== 3 && !is_q
) {
12056 unallocated_encoding(s
);
12059 if (!fp_access_check(s
)) {
12062 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
12064 case 0x7: /* SQABS, SQNEG */
12065 if (size
== 3 && !is_q
) {
12066 unallocated_encoding(s
);
12071 case 0x16 ... 0x1d:
12074 /* Floating point: U, size[1] and opcode indicate operation;
12075 * size[0] indicates single or double precision.
12077 int is_double
= extract32(size
, 0, 1);
12078 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
12079 size
= is_double
? 3 : 2;
12081 case 0x2f: /* FABS */
12082 case 0x6f: /* FNEG */
12083 if (size
== 3 && !is_q
) {
12084 unallocated_encoding(s
);
12088 case 0x1d: /* SCVTF */
12089 case 0x5d: /* UCVTF */
12091 bool is_signed
= (opcode
== 0x1d) ? true : false;
12092 int elements
= is_double
? 2 : is_q
? 4 : 2;
12093 if (is_double
&& !is_q
) {
12094 unallocated_encoding(s
);
12097 if (!fp_access_check(s
)) {
12100 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
12103 case 0x2c: /* FCMGT (zero) */
12104 case 0x2d: /* FCMEQ (zero) */
12105 case 0x2e: /* FCMLT (zero) */
12106 case 0x6c: /* FCMGE (zero) */
12107 case 0x6d: /* FCMLE (zero) */
12108 if (size
== 3 && !is_q
) {
12109 unallocated_encoding(s
);
12112 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
12114 case 0x7f: /* FSQRT */
12115 if (size
== 3 && !is_q
) {
12116 unallocated_encoding(s
);
12120 case 0x1a: /* FCVTNS */
12121 case 0x1b: /* FCVTMS */
12122 case 0x3a: /* FCVTPS */
12123 case 0x3b: /* FCVTZS */
12124 case 0x5a: /* FCVTNU */
12125 case 0x5b: /* FCVTMU */
12126 case 0x7a: /* FCVTPU */
12127 case 0x7b: /* FCVTZU */
12128 need_fpstatus
= true;
12130 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12131 if (size
== 3 && !is_q
) {
12132 unallocated_encoding(s
);
12136 case 0x5c: /* FCVTAU */
12137 case 0x1c: /* FCVTAS */
12138 need_fpstatus
= true;
12140 rmode
= FPROUNDING_TIEAWAY
;
12141 if (size
== 3 && !is_q
) {
12142 unallocated_encoding(s
);
12146 case 0x3c: /* URECPE */
12148 unallocated_encoding(s
);
12152 case 0x3d: /* FRECPE */
12153 case 0x7d: /* FRSQRTE */
12154 if (size
== 3 && !is_q
) {
12155 unallocated_encoding(s
);
12158 if (!fp_access_check(s
)) {
12161 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
12163 case 0x56: /* FCVTXN, FCVTXN2 */
12165 unallocated_encoding(s
);
12169 case 0x16: /* FCVTN, FCVTN2 */
12170 /* handle_2misc_narrow does a 2*size -> size operation, but these
12171 * instructions encode the source size rather than dest size.
12173 if (!fp_access_check(s
)) {
12176 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
12178 case 0x17: /* FCVTL, FCVTL2 */
12179 if (!fp_access_check(s
)) {
12182 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
12184 case 0x18: /* FRINTN */
12185 case 0x19: /* FRINTM */
12186 case 0x38: /* FRINTP */
12187 case 0x39: /* FRINTZ */
12189 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12191 case 0x59: /* FRINTX */
12192 case 0x79: /* FRINTI */
12193 need_fpstatus
= true;
12194 if (size
== 3 && !is_q
) {
12195 unallocated_encoding(s
);
12199 case 0x58: /* FRINTA */
12201 rmode
= FPROUNDING_TIEAWAY
;
12202 need_fpstatus
= true;
12203 if (size
== 3 && !is_q
) {
12204 unallocated_encoding(s
);
12208 case 0x7c: /* URSQRTE */
12210 unallocated_encoding(s
);
12213 need_fpstatus
= true;
12216 unallocated_encoding(s
);
12222 unallocated_encoding(s
);
12226 if (!fp_access_check(s
)) {
12230 if (need_fpstatus
|| need_rmode
) {
12231 tcg_fpstatus
= get_fpstatus_ptr(false);
12233 tcg_fpstatus
= NULL
;
12236 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12237 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12244 if (u
&& size
== 0) { /* NOT */
12245 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_not
, 0);
12251 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_neg
, size
);
12258 /* All 64-bit element operations can be shared with scalar 2misc */
12261 /* Coverity claims (size == 3 && !is_q) has been eliminated
12262 * from all paths leading to here.
12264 tcg_debug_assert(is_q
);
12265 for (pass
= 0; pass
< 2; pass
++) {
12266 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12267 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12269 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12271 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
12272 tcg_rmode
, tcg_fpstatus
);
12274 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12276 tcg_temp_free_i64(tcg_res
);
12277 tcg_temp_free_i64(tcg_op
);
12282 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
12283 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12284 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12287 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
12290 /* Special cases for 32 bit elements */
12292 case 0xa: /* CMLT */
12293 /* 32 bit integer comparison against zero, result is
12294 * test ? (2^32 - 1) : 0. We implement via setcond(test)
12297 cond
= TCG_COND_LT
;
12299 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
12300 tcg_gen_neg_i32(tcg_res
, tcg_res
);
12302 case 0x8: /* CMGT, CMGE */
12303 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
12305 case 0x9: /* CMEQ, CMLE */
12306 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
12308 case 0x4: /* CLS */
12310 tcg_gen_clzi_i32(tcg_res
, tcg_op
, 32);
12312 tcg_gen_clrsb_i32(tcg_res
, tcg_op
);
12315 case 0x7: /* SQABS, SQNEG */
12317 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
12319 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
12322 case 0xb: /* ABS, NEG */
12324 tcg_gen_neg_i32(tcg_res
, tcg_op
);
12326 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12327 tcg_gen_neg_i32(tcg_res
, tcg_op
);
12328 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
12329 tcg_zero
, tcg_op
, tcg_res
);
12330 tcg_temp_free_i32(tcg_zero
);
12333 case 0x2f: /* FABS */
12334 gen_helper_vfp_abss(tcg_res
, tcg_op
);
12336 case 0x6f: /* FNEG */
12337 gen_helper_vfp_negs(tcg_res
, tcg_op
);
12339 case 0x7f: /* FSQRT */
12340 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
12342 case 0x1a: /* FCVTNS */
12343 case 0x1b: /* FCVTMS */
12344 case 0x1c: /* FCVTAS */
12345 case 0x3a: /* FCVTPS */
12346 case 0x3b: /* FCVTZS */
12348 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12349 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
12350 tcg_shift
, tcg_fpstatus
);
12351 tcg_temp_free_i32(tcg_shift
);
12354 case 0x5a: /* FCVTNU */
12355 case 0x5b: /* FCVTMU */
12356 case 0x5c: /* FCVTAU */
12357 case 0x7a: /* FCVTPU */
12358 case 0x7b: /* FCVTZU */
12360 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12361 gen_helper_vfp_touls(tcg_res
, tcg_op
,
12362 tcg_shift
, tcg_fpstatus
);
12363 tcg_temp_free_i32(tcg_shift
);
12366 case 0x18: /* FRINTN */
12367 case 0x19: /* FRINTM */
12368 case 0x38: /* FRINTP */
12369 case 0x39: /* FRINTZ */
12370 case 0x58: /* FRINTA */
12371 case 0x79: /* FRINTI */
12372 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
12374 case 0x59: /* FRINTX */
12375 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12377 case 0x7c: /* URSQRTE */
12378 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
12381 g_assert_not_reached();
12384 /* Use helpers for 8 and 16 bit elements */
12386 case 0x5: /* CNT, RBIT */
12387 /* For these two insns size is part of the opcode specifier
12388 * (handled earlier); they always operate on byte elements.
12391 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
12393 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
12396 case 0x7: /* SQABS, SQNEG */
12398 NeonGenOneOpEnvFn
*genfn
;
12399 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
12400 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
12401 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
12403 genfn
= fns
[size
][u
];
12404 genfn(tcg_res
, cpu_env
, tcg_op
);
12407 case 0x8: /* CMGT, CMGE */
12408 case 0x9: /* CMEQ, CMLE */
12409 case 0xa: /* CMLT */
12411 static NeonGenTwoOpFn
* const fns
[3][2] = {
12412 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
12413 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
12414 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
12416 NeonGenTwoOpFn
*genfn
;
12419 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12421 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
12422 comp
= (opcode
- 0x8) * 2 + u
;
12423 /* ...but LE, LT are implemented as reverse GE, GT */
12424 reverse
= (comp
> 2);
12428 genfn
= fns
[comp
][size
];
12430 genfn(tcg_res
, tcg_zero
, tcg_op
);
12432 genfn(tcg_res
, tcg_op
, tcg_zero
);
12434 tcg_temp_free_i32(tcg_zero
);
12437 case 0xb: /* ABS, NEG */
12439 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12441 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
12443 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
12445 tcg_temp_free_i32(tcg_zero
);
12448 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
12450 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
12454 case 0x4: /* CLS, CLZ */
12457 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
12459 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
12463 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
12465 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
12470 g_assert_not_reached();
12474 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
12476 tcg_temp_free_i32(tcg_res
);
12477 tcg_temp_free_i32(tcg_op
);
12480 clear_vec_high(s
, is_q
, rd
);
12483 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12484 tcg_temp_free_i32(tcg_rmode
);
12486 if (need_fpstatus
) {
12487 tcg_temp_free_ptr(tcg_fpstatus
);
12491 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12493 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12494 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12495 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12496 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12497 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12498 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12500 * This actually covers two groups where scalar access is governed by
12501 * bit 28. A bunch of the instructions (float to integral) only exist
12502 * in the vector form and are un-allocated for the scalar decode. Also
12503 * in the scalar decode Q is always 1.
12505 static void disas_simd_two_reg_misc_fp16(DisasContext
*s
, uint32_t insn
)
12507 int fpop
, opcode
, a
, u
;
12511 bool only_in_vector
= false;
12514 TCGv_i32 tcg_rmode
= NULL
;
12515 TCGv_ptr tcg_fpstatus
= NULL
;
12516 bool need_rmode
= false;
12517 bool need_fpst
= true;
12520 if (!dc_isar_feature(aa64_fp16
, s
)) {
12521 unallocated_encoding(s
);
12525 rd
= extract32(insn
, 0, 5);
12526 rn
= extract32(insn
, 5, 5);
12528 a
= extract32(insn
, 23, 1);
12529 u
= extract32(insn
, 29, 1);
12530 is_scalar
= extract32(insn
, 28, 1);
12531 is_q
= extract32(insn
, 30, 1);
12533 opcode
= extract32(insn
, 12, 5);
12534 fpop
= deposit32(opcode
, 5, 1, a
);
12535 fpop
= deposit32(fpop
, 6, 1, u
);
12537 rd
= extract32(insn
, 0, 5);
12538 rn
= extract32(insn
, 5, 5);
12541 case 0x1d: /* SCVTF */
12542 case 0x5d: /* UCVTF */
12549 elements
= (is_q
? 8 : 4);
12552 if (!fp_access_check(s
)) {
12555 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !u
, 0, MO_16
);
12559 case 0x2c: /* FCMGT (zero) */
12560 case 0x2d: /* FCMEQ (zero) */
12561 case 0x2e: /* FCMLT (zero) */
12562 case 0x6c: /* FCMGE (zero) */
12563 case 0x6d: /* FCMLE (zero) */
12564 handle_2misc_fcmp_zero(s
, fpop
, is_scalar
, 0, is_q
, MO_16
, rn
, rd
);
12566 case 0x3d: /* FRECPE */
12567 case 0x3f: /* FRECPX */
12569 case 0x18: /* FRINTN */
12571 only_in_vector
= true;
12572 rmode
= FPROUNDING_TIEEVEN
;
12574 case 0x19: /* FRINTM */
12576 only_in_vector
= true;
12577 rmode
= FPROUNDING_NEGINF
;
12579 case 0x38: /* FRINTP */
12581 only_in_vector
= true;
12582 rmode
= FPROUNDING_POSINF
;
12584 case 0x39: /* FRINTZ */
12586 only_in_vector
= true;
12587 rmode
= FPROUNDING_ZERO
;
12589 case 0x58: /* FRINTA */
12591 only_in_vector
= true;
12592 rmode
= FPROUNDING_TIEAWAY
;
12594 case 0x59: /* FRINTX */
12595 case 0x79: /* FRINTI */
12596 only_in_vector
= true;
12597 /* current rounding mode */
12599 case 0x1a: /* FCVTNS */
12601 rmode
= FPROUNDING_TIEEVEN
;
12603 case 0x1b: /* FCVTMS */
12605 rmode
= FPROUNDING_NEGINF
;
12607 case 0x1c: /* FCVTAS */
12609 rmode
= FPROUNDING_TIEAWAY
;
12611 case 0x3a: /* FCVTPS */
12613 rmode
= FPROUNDING_POSINF
;
12615 case 0x3b: /* FCVTZS */
12617 rmode
= FPROUNDING_ZERO
;
12619 case 0x5a: /* FCVTNU */
12621 rmode
= FPROUNDING_TIEEVEN
;
12623 case 0x5b: /* FCVTMU */
12625 rmode
= FPROUNDING_NEGINF
;
12627 case 0x5c: /* FCVTAU */
12629 rmode
= FPROUNDING_TIEAWAY
;
12631 case 0x7a: /* FCVTPU */
12633 rmode
= FPROUNDING_POSINF
;
12635 case 0x7b: /* FCVTZU */
12637 rmode
= FPROUNDING_ZERO
;
12639 case 0x2f: /* FABS */
12640 case 0x6f: /* FNEG */
12643 case 0x7d: /* FRSQRTE */
12644 case 0x7f: /* FSQRT (vector) */
12647 fprintf(stderr
, "%s: insn %#04x fpop %#2x\n", __func__
, insn
, fpop
);
12648 g_assert_not_reached();
12652 /* Check additional constraints for the scalar encoding */
12655 unallocated_encoding(s
);
12658 /* FRINTxx is only in the vector form */
12659 if (only_in_vector
) {
12660 unallocated_encoding(s
);
12665 if (!fp_access_check(s
)) {
12669 if (need_rmode
|| need_fpst
) {
12670 tcg_fpstatus
= get_fpstatus_ptr(true);
12674 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12675 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12679 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
12680 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12683 case 0x1a: /* FCVTNS */
12684 case 0x1b: /* FCVTMS */
12685 case 0x1c: /* FCVTAS */
12686 case 0x3a: /* FCVTPS */
12687 case 0x3b: /* FCVTZS */
12688 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12690 case 0x3d: /* FRECPE */
12691 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12693 case 0x3f: /* FRECPX */
12694 gen_helper_frecpx_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12696 case 0x5a: /* FCVTNU */
12697 case 0x5b: /* FCVTMU */
12698 case 0x5c: /* FCVTAU */
12699 case 0x7a: /* FCVTPU */
12700 case 0x7b: /* FCVTZU */
12701 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12703 case 0x6f: /* FNEG */
12704 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12706 case 0x7d: /* FRSQRTE */
12707 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12710 g_assert_not_reached();
12713 /* limit any sign extension going on */
12714 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0xffff);
12715 write_fp_sreg(s
, rd
, tcg_res
);
12717 tcg_temp_free_i32(tcg_res
);
12718 tcg_temp_free_i32(tcg_op
);
12720 for (pass
= 0; pass
< (is_q
? 8 : 4); pass
++) {
12721 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12722 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12724 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_16
);
12727 case 0x1a: /* FCVTNS */
12728 case 0x1b: /* FCVTMS */
12729 case 0x1c: /* FCVTAS */
12730 case 0x3a: /* FCVTPS */
12731 case 0x3b: /* FCVTZS */
12732 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12734 case 0x3d: /* FRECPE */
12735 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12737 case 0x5a: /* FCVTNU */
12738 case 0x5b: /* FCVTMU */
12739 case 0x5c: /* FCVTAU */
12740 case 0x7a: /* FCVTPU */
12741 case 0x7b: /* FCVTZU */
12742 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12744 case 0x18: /* FRINTN */
12745 case 0x19: /* FRINTM */
12746 case 0x38: /* FRINTP */
12747 case 0x39: /* FRINTZ */
12748 case 0x58: /* FRINTA */
12749 case 0x79: /* FRINTI */
12750 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12752 case 0x59: /* FRINTX */
12753 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12755 case 0x2f: /* FABS */
12756 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
12758 case 0x6f: /* FNEG */
12759 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12761 case 0x7d: /* FRSQRTE */
12762 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12764 case 0x7f: /* FSQRT */
12765 gen_helper_sqrt_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12768 g_assert_not_reached();
12771 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12773 tcg_temp_free_i32(tcg_res
);
12774 tcg_temp_free_i32(tcg_op
);
12777 clear_vec_high(s
, is_q
, rd
);
12781 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12782 tcg_temp_free_i32(tcg_rmode
);
12785 if (tcg_fpstatus
) {
12786 tcg_temp_free_ptr(tcg_fpstatus
);
12790 /* AdvSIMD scalar x indexed element
12791 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12792 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12793 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12794 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12795 * AdvSIMD vector x indexed element
12796 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12797 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12798 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12799 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12801 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
12803 /* This encoding has two kinds of instruction:
12804 * normal, where we perform elt x idxelt => elt for each
12805 * element in the vector
12806 * long, where we perform elt x idxelt and generate a result of
12807 * double the width of the input element
12808 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
12810 bool is_scalar
= extract32(insn
, 28, 1);
12811 bool is_q
= extract32(insn
, 30, 1);
12812 bool u
= extract32(insn
, 29, 1);
12813 int size
= extract32(insn
, 22, 2);
12814 int l
= extract32(insn
, 21, 1);
12815 int m
= extract32(insn
, 20, 1);
12816 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
12817 int rm
= extract32(insn
, 16, 4);
12818 int opcode
= extract32(insn
, 12, 4);
12819 int h
= extract32(insn
, 11, 1);
12820 int rn
= extract32(insn
, 5, 5);
12821 int rd
= extract32(insn
, 0, 5);
12822 bool is_long
= false;
12824 bool is_fp16
= false;
12828 switch (16 * u
+ opcode
) {
12829 case 0x08: /* MUL */
12830 case 0x10: /* MLA */
12831 case 0x14: /* MLS */
12833 unallocated_encoding(s
);
12837 case 0x02: /* SMLAL, SMLAL2 */
12838 case 0x12: /* UMLAL, UMLAL2 */
12839 case 0x06: /* SMLSL, SMLSL2 */
12840 case 0x16: /* UMLSL, UMLSL2 */
12841 case 0x0a: /* SMULL, SMULL2 */
12842 case 0x1a: /* UMULL, UMULL2 */
12844 unallocated_encoding(s
);
12849 case 0x03: /* SQDMLAL, SQDMLAL2 */
12850 case 0x07: /* SQDMLSL, SQDMLSL2 */
12851 case 0x0b: /* SQDMULL, SQDMULL2 */
12854 case 0x0c: /* SQDMULH */
12855 case 0x0d: /* SQRDMULH */
12857 case 0x01: /* FMLA */
12858 case 0x05: /* FMLS */
12859 case 0x09: /* FMUL */
12860 case 0x19: /* FMULX */
12863 case 0x1d: /* SQRDMLAH */
12864 case 0x1f: /* SQRDMLSH */
12865 if (!dc_isar_feature(aa64_rdm
, s
)) {
12866 unallocated_encoding(s
);
12870 case 0x0e: /* SDOT */
12871 case 0x1e: /* UDOT */
12872 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_dp
, s
)) {
12873 unallocated_encoding(s
);
12877 case 0x11: /* FCMLA #0 */
12878 case 0x13: /* FCMLA #90 */
12879 case 0x15: /* FCMLA #180 */
12880 case 0x17: /* FCMLA #270 */
12881 if (is_scalar
|| !dc_isar_feature(aa64_fcma
, s
)) {
12882 unallocated_encoding(s
);
12887 case 0x00: /* FMLAL */
12888 case 0x04: /* FMLSL */
12889 case 0x18: /* FMLAL2 */
12890 case 0x1c: /* FMLSL2 */
12891 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_fhm
, s
)) {
12892 unallocated_encoding(s
);
12896 /* is_fp, but we pass cpu_env not fp_status. */
12899 unallocated_encoding(s
);
12904 case 1: /* normal fp */
12905 /* convert insn encoded size to TCGMemOp size */
12907 case 0: /* half-precision */
12911 case MO_32
: /* single precision */
12912 case MO_64
: /* double precision */
12915 unallocated_encoding(s
);
12920 case 2: /* complex fp */
12921 /* Each indexable element is a complex pair. */
12926 unallocated_encoding(s
);
12934 unallocated_encoding(s
);
12939 default: /* integer */
12943 unallocated_encoding(s
);
12948 if (is_fp16
&& !dc_isar_feature(aa64_fp16
, s
)) {
12949 unallocated_encoding(s
);
12953 /* Given TCGMemOp size, adjust register and indexing. */
12956 index
= h
<< 2 | l
<< 1 | m
;
12959 index
= h
<< 1 | l
;
12964 unallocated_encoding(s
);
12971 g_assert_not_reached();
12974 if (!fp_access_check(s
)) {
12979 fpst
= get_fpstatus_ptr(is_fp16
);
12984 switch (16 * u
+ opcode
) {
12985 case 0x0e: /* SDOT */
12986 case 0x1e: /* UDOT */
12987 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, index
,
12988 u
? gen_helper_gvec_udot_idx_b
12989 : gen_helper_gvec_sdot_idx_b
);
12991 case 0x11: /* FCMLA #0 */
12992 case 0x13: /* FCMLA #90 */
12993 case 0x15: /* FCMLA #180 */
12994 case 0x17: /* FCMLA #270 */
12996 int rot
= extract32(insn
, 13, 2);
12997 int data
= (index
<< 2) | rot
;
12998 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
12999 vec_full_reg_offset(s
, rn
),
13000 vec_full_reg_offset(s
, rm
), fpst
,
13001 is_q
? 16 : 8, vec_full_reg_size(s
), data
,
13003 ? gen_helper_gvec_fcmlas_idx
13004 : gen_helper_gvec_fcmlah_idx
);
13005 tcg_temp_free_ptr(fpst
);
13009 case 0x00: /* FMLAL */
13010 case 0x04: /* FMLSL */
13011 case 0x18: /* FMLAL2 */
13012 case 0x1c: /* FMLSL2 */
13014 int is_s
= extract32(opcode
, 2, 1);
13016 int data
= (index
<< 2) | (is_2
<< 1) | is_s
;
13017 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
13018 vec_full_reg_offset(s
, rn
),
13019 vec_full_reg_offset(s
, rm
), cpu_env
,
13020 is_q
? 16 : 8, vec_full_reg_size(s
),
13021 data
, gen_helper_gvec_fmlal_idx_a64
);
13027 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
13030 assert(is_fp
&& is_q
&& !is_long
);
13032 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
13034 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13035 TCGv_i64 tcg_op
= tcg_temp_new_i64();
13036 TCGv_i64 tcg_res
= tcg_temp_new_i64();
13038 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
13040 switch (16 * u
+ opcode
) {
13041 case 0x05: /* FMLS */
13042 /* As usual for ARM, separate negation for fused multiply-add */
13043 gen_helper_vfp_negd(tcg_op
, tcg_op
);
13045 case 0x01: /* FMLA */
13046 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
13047 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
13049 case 0x09: /* FMUL */
13050 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13052 case 0x19: /* FMULX */
13053 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13056 g_assert_not_reached();
13059 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
13060 tcg_temp_free_i64(tcg_op
);
13061 tcg_temp_free_i64(tcg_res
);
13064 tcg_temp_free_i64(tcg_idx
);
13065 clear_vec_high(s
, !is_scalar
, rd
);
13066 } else if (!is_long
) {
13067 /* 32 bit floating point, or 16 or 32 bit integer.
13068 * For the 16 bit scalar case we use the usual Neon helpers and
13069 * rely on the fact that 0 op 0 == 0 with no side effects.
13071 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13072 int pass
, maxpasses
;
13077 maxpasses
= is_q
? 4 : 2;
13080 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13082 if (size
== 1 && !is_scalar
) {
13083 /* The simplest way to handle the 16x16 indexed ops is to duplicate
13084 * the index into both halves of the 32 bit tcg_idx and then use
13085 * the usual Neon helpers.
13087 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13090 for (pass
= 0; pass
< maxpasses
; pass
++) {
13091 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13092 TCGv_i32 tcg_res
= tcg_temp_new_i32();
13094 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
13096 switch (16 * u
+ opcode
) {
13097 case 0x08: /* MUL */
13098 case 0x10: /* MLA */
13099 case 0x14: /* MLS */
13101 static NeonGenTwoOpFn
* const fns
[2][2] = {
13102 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
13103 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
13105 NeonGenTwoOpFn
*genfn
;
13106 bool is_sub
= opcode
== 0x4;
13109 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
13111 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
13113 if (opcode
== 0x8) {
13116 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
13117 genfn
= fns
[size
- 1][is_sub
];
13118 genfn(tcg_res
, tcg_op
, tcg_res
);
13121 case 0x05: /* FMLS */
13122 case 0x01: /* FMLA */
13123 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13124 is_scalar
? size
: MO_32
);
13127 if (opcode
== 0x5) {
13128 /* As usual for ARM, separate negation for fused
13130 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80008000);
13133 gen_helper_advsimd_muladdh(tcg_res
, tcg_op
, tcg_idx
,
13136 gen_helper_advsimd_muladd2h(tcg_res
, tcg_op
, tcg_idx
,
13141 if (opcode
== 0x5) {
13142 /* As usual for ARM, separate negation for
13143 * fused multiply-add */
13144 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80000000);
13146 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
,
13150 g_assert_not_reached();
13153 case 0x09: /* FMUL */
13157 gen_helper_advsimd_mulh(tcg_res
, tcg_op
,
13160 gen_helper_advsimd_mul2h(tcg_res
, tcg_op
,
13165 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13168 g_assert_not_reached();
13171 case 0x19: /* FMULX */
13175 gen_helper_advsimd_mulxh(tcg_res
, tcg_op
,
13178 gen_helper_advsimd_mulx2h(tcg_res
, tcg_op
,
13183 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13186 g_assert_not_reached();
13189 case 0x0c: /* SQDMULH */
13191 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
13194 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
13198 case 0x0d: /* SQRDMULH */
13200 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
13203 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
13207 case 0x1d: /* SQRDMLAH */
13208 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13209 is_scalar
? size
: MO_32
);
13211 gen_helper_neon_qrdmlah_s16(tcg_res
, cpu_env
,
13212 tcg_op
, tcg_idx
, tcg_res
);
13214 gen_helper_neon_qrdmlah_s32(tcg_res
, cpu_env
,
13215 tcg_op
, tcg_idx
, tcg_res
);
13218 case 0x1f: /* SQRDMLSH */
13219 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13220 is_scalar
? size
: MO_32
);
13222 gen_helper_neon_qrdmlsh_s16(tcg_res
, cpu_env
,
13223 tcg_op
, tcg_idx
, tcg_res
);
13225 gen_helper_neon_qrdmlsh_s32(tcg_res
, cpu_env
,
13226 tcg_op
, tcg_idx
, tcg_res
);
13230 g_assert_not_reached();
13234 write_fp_sreg(s
, rd
, tcg_res
);
13236 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
13239 tcg_temp_free_i32(tcg_op
);
13240 tcg_temp_free_i32(tcg_res
);
13243 tcg_temp_free_i32(tcg_idx
);
13244 clear_vec_high(s
, is_q
, rd
);
13246 /* long ops: 16x16->32 or 32x32->64 */
13247 TCGv_i64 tcg_res
[2];
13249 bool satop
= extract32(opcode
, 0, 1);
13250 TCGMemOp memop
= MO_32
;
13257 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
13259 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
13261 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13262 TCGv_i64 tcg_op
= tcg_temp_new_i64();
13263 TCGv_i64 tcg_passres
;
13269 passelt
= pass
+ (is_q
* 2);
13272 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
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 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
13284 tcg_temp_free_i64(tcg_op
);
13287 /* saturating, doubling */
13288 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
13289 tcg_passres
, tcg_passres
);
13292 if (opcode
== 0xa || opcode
== 0xb) {
13296 /* Accumulating op: handle accumulate step */
13297 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13300 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13301 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13303 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13304 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13306 case 0x7: /* SQDMLSL, SQDMLSL2 */
13307 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
13309 case 0x3: /* SQDMLAL, SQDMLAL2 */
13310 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
13315 g_assert_not_reached();
13317 tcg_temp_free_i64(tcg_passres
);
13319 tcg_temp_free_i64(tcg_idx
);
13321 clear_vec_high(s
, !is_scalar
, rd
);
13323 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13326 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13329 /* The simplest way to handle the 16x16 indexed ops is to
13330 * duplicate the index into both halves of the 32 bit tcg_idx
13331 * and then use the usual Neon helpers.
13333 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13336 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13337 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13338 TCGv_i64 tcg_passres
;
13341 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
13343 read_vec_element_i32(s
, tcg_op
, rn
,
13344 pass
+ (is_q
* 2), MO_32
);
13347 tcg_res
[pass
] = tcg_temp_new_i64();
13349 if (opcode
== 0xa || opcode
== 0xb) {
13350 /* Non-accumulating ops */
13351 tcg_passres
= tcg_res
[pass
];
13353 tcg_passres
= tcg_temp_new_i64();
13356 if (memop
& MO_SIGN
) {
13357 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
13359 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
13362 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
13363 tcg_passres
, tcg_passres
);
13365 tcg_temp_free_i32(tcg_op
);
13367 if (opcode
== 0xa || opcode
== 0xb) {
13371 /* Accumulating op: handle accumulate step */
13372 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13375 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13376 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
13379 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13380 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
13383 case 0x7: /* SQDMLSL, SQDMLSL2 */
13384 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
13386 case 0x3: /* SQDMLAL, SQDMLAL2 */
13387 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
13392 g_assert_not_reached();
13394 tcg_temp_free_i64(tcg_passres
);
13396 tcg_temp_free_i32(tcg_idx
);
13399 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
13404 tcg_res
[1] = tcg_const_i64(0);
13407 for (pass
= 0; pass
< 2; pass
++) {
13408 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13409 tcg_temp_free_i64(tcg_res
[pass
]);
13414 tcg_temp_free_ptr(fpst
);
13419 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13420 * +-----------------+------+-----------+--------+-----+------+------+
13421 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13422 * +-----------------+------+-----------+--------+-----+------+------+
13424 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
13426 int size
= extract32(insn
, 22, 2);
13427 int opcode
= extract32(insn
, 12, 5);
13428 int rn
= extract32(insn
, 5, 5);
13429 int rd
= extract32(insn
, 0, 5);
13431 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13432 TCGv_i32 tcg_decrypt
;
13433 CryptoThreeOpIntFn
*genfn
;
13435 if (!dc_isar_feature(aa64_aes
, s
) || size
!= 0) {
13436 unallocated_encoding(s
);
13441 case 0x4: /* AESE */
13443 genfn
= gen_helper_crypto_aese
;
13445 case 0x6: /* AESMC */
13447 genfn
= gen_helper_crypto_aesmc
;
13449 case 0x5: /* AESD */
13451 genfn
= gen_helper_crypto_aese
;
13453 case 0x7: /* AESIMC */
13455 genfn
= gen_helper_crypto_aesmc
;
13458 unallocated_encoding(s
);
13462 if (!fp_access_check(s
)) {
13466 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13467 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13468 tcg_decrypt
= tcg_const_i32(decrypt
);
13470 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_decrypt
);
13472 tcg_temp_free_ptr(tcg_rd_ptr
);
13473 tcg_temp_free_ptr(tcg_rn_ptr
);
13474 tcg_temp_free_i32(tcg_decrypt
);
13477 /* Crypto three-reg SHA
13478 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
13479 * +-----------------+------+---+------+---+--------+-----+------+------+
13480 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
13481 * +-----------------+------+---+------+---+--------+-----+------+------+
13483 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
13485 int size
= extract32(insn
, 22, 2);
13486 int opcode
= extract32(insn
, 12, 3);
13487 int rm
= extract32(insn
, 16, 5);
13488 int rn
= extract32(insn
, 5, 5);
13489 int rd
= extract32(insn
, 0, 5);
13490 CryptoThreeOpFn
*genfn
;
13491 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13495 unallocated_encoding(s
);
13500 case 0: /* SHA1C */
13501 case 1: /* SHA1P */
13502 case 2: /* SHA1M */
13503 case 3: /* SHA1SU0 */
13505 feature
= dc_isar_feature(aa64_sha1
, s
);
13507 case 4: /* SHA256H */
13508 genfn
= gen_helper_crypto_sha256h
;
13509 feature
= dc_isar_feature(aa64_sha256
, s
);
13511 case 5: /* SHA256H2 */
13512 genfn
= gen_helper_crypto_sha256h2
;
13513 feature
= dc_isar_feature(aa64_sha256
, s
);
13515 case 6: /* SHA256SU1 */
13516 genfn
= gen_helper_crypto_sha256su1
;
13517 feature
= dc_isar_feature(aa64_sha256
, s
);
13520 unallocated_encoding(s
);
13525 unallocated_encoding(s
);
13529 if (!fp_access_check(s
)) {
13533 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13534 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13535 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13538 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13540 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
13542 gen_helper_crypto_sha1_3reg(tcg_rd_ptr
, tcg_rn_ptr
,
13543 tcg_rm_ptr
, tcg_opcode
);
13544 tcg_temp_free_i32(tcg_opcode
);
13547 tcg_temp_free_ptr(tcg_rd_ptr
);
13548 tcg_temp_free_ptr(tcg_rn_ptr
);
13549 tcg_temp_free_ptr(tcg_rm_ptr
);
13552 /* Crypto two-reg SHA
13553 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13554 * +-----------------+------+-----------+--------+-----+------+------+
13555 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13556 * +-----------------+------+-----------+--------+-----+------+------+
13558 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
13560 int size
= extract32(insn
, 22, 2);
13561 int opcode
= extract32(insn
, 12, 5);
13562 int rn
= extract32(insn
, 5, 5);
13563 int rd
= extract32(insn
, 0, 5);
13564 CryptoTwoOpFn
*genfn
;
13566 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13569 unallocated_encoding(s
);
13574 case 0: /* SHA1H */
13575 feature
= dc_isar_feature(aa64_sha1
, s
);
13576 genfn
= gen_helper_crypto_sha1h
;
13578 case 1: /* SHA1SU1 */
13579 feature
= dc_isar_feature(aa64_sha1
, s
);
13580 genfn
= gen_helper_crypto_sha1su1
;
13582 case 2: /* SHA256SU0 */
13583 feature
= dc_isar_feature(aa64_sha256
, s
);
13584 genfn
= gen_helper_crypto_sha256su0
;
13587 unallocated_encoding(s
);
13592 unallocated_encoding(s
);
13596 if (!fp_access_check(s
)) {
13600 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13601 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13603 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13605 tcg_temp_free_ptr(tcg_rd_ptr
);
13606 tcg_temp_free_ptr(tcg_rn_ptr
);
13609 /* Crypto three-reg SHA512
13610 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13611 * +-----------------------+------+---+---+-----+--------+------+------+
13612 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
13613 * +-----------------------+------+---+---+-----+--------+------+------+
13615 static void disas_crypto_three_reg_sha512(DisasContext
*s
, uint32_t insn
)
13617 int opcode
= extract32(insn
, 10, 2);
13618 int o
= extract32(insn
, 14, 1);
13619 int rm
= extract32(insn
, 16, 5);
13620 int rn
= extract32(insn
, 5, 5);
13621 int rd
= extract32(insn
, 0, 5);
13623 CryptoThreeOpFn
*genfn
;
13627 case 0: /* SHA512H */
13628 feature
= dc_isar_feature(aa64_sha512
, s
);
13629 genfn
= gen_helper_crypto_sha512h
;
13631 case 1: /* SHA512H2 */
13632 feature
= dc_isar_feature(aa64_sha512
, s
);
13633 genfn
= gen_helper_crypto_sha512h2
;
13635 case 2: /* SHA512SU1 */
13636 feature
= dc_isar_feature(aa64_sha512
, s
);
13637 genfn
= gen_helper_crypto_sha512su1
;
13640 feature
= dc_isar_feature(aa64_sha3
, s
);
13646 case 0: /* SM3PARTW1 */
13647 feature
= dc_isar_feature(aa64_sm3
, s
);
13648 genfn
= gen_helper_crypto_sm3partw1
;
13650 case 1: /* SM3PARTW2 */
13651 feature
= dc_isar_feature(aa64_sm3
, s
);
13652 genfn
= gen_helper_crypto_sm3partw2
;
13654 case 2: /* SM4EKEY */
13655 feature
= dc_isar_feature(aa64_sm4
, s
);
13656 genfn
= gen_helper_crypto_sm4ekey
;
13659 unallocated_encoding(s
);
13665 unallocated_encoding(s
);
13669 if (!fp_access_check(s
)) {
13674 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13676 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13677 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13678 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13680 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13682 tcg_temp_free_ptr(tcg_rd_ptr
);
13683 tcg_temp_free_ptr(tcg_rn_ptr
);
13684 tcg_temp_free_ptr(tcg_rm_ptr
);
13686 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13689 tcg_op1
= tcg_temp_new_i64();
13690 tcg_op2
= tcg_temp_new_i64();
13691 tcg_res
[0] = tcg_temp_new_i64();
13692 tcg_res
[1] = tcg_temp_new_i64();
13694 for (pass
= 0; pass
< 2; pass
++) {
13695 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13696 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13698 tcg_gen_rotli_i64(tcg_res
[pass
], tcg_op2
, 1);
13699 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13701 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13702 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13704 tcg_temp_free_i64(tcg_op1
);
13705 tcg_temp_free_i64(tcg_op2
);
13706 tcg_temp_free_i64(tcg_res
[0]);
13707 tcg_temp_free_i64(tcg_res
[1]);
13711 /* Crypto two-reg SHA512
13712 * 31 12 11 10 9 5 4 0
13713 * +-----------------------------------------+--------+------+------+
13714 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
13715 * +-----------------------------------------+--------+------+------+
13717 static void disas_crypto_two_reg_sha512(DisasContext
*s
, uint32_t insn
)
13719 int opcode
= extract32(insn
, 10, 2);
13720 int rn
= extract32(insn
, 5, 5);
13721 int rd
= extract32(insn
, 0, 5);
13722 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13724 CryptoTwoOpFn
*genfn
;
13727 case 0: /* SHA512SU0 */
13728 feature
= dc_isar_feature(aa64_sha512
, s
);
13729 genfn
= gen_helper_crypto_sha512su0
;
13732 feature
= dc_isar_feature(aa64_sm4
, s
);
13733 genfn
= gen_helper_crypto_sm4e
;
13736 unallocated_encoding(s
);
13741 unallocated_encoding(s
);
13745 if (!fp_access_check(s
)) {
13749 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13750 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13752 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13754 tcg_temp_free_ptr(tcg_rd_ptr
);
13755 tcg_temp_free_ptr(tcg_rn_ptr
);
13758 /* Crypto four-register
13759 * 31 23 22 21 20 16 15 14 10 9 5 4 0
13760 * +-------------------+-----+------+---+------+------+------+
13761 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
13762 * +-------------------+-----+------+---+------+------+------+
13764 static void disas_crypto_four_reg(DisasContext
*s
, uint32_t insn
)
13766 int op0
= extract32(insn
, 21, 2);
13767 int rm
= extract32(insn
, 16, 5);
13768 int ra
= extract32(insn
, 10, 5);
13769 int rn
= extract32(insn
, 5, 5);
13770 int rd
= extract32(insn
, 0, 5);
13776 feature
= dc_isar_feature(aa64_sha3
, s
);
13778 case 2: /* SM3SS1 */
13779 feature
= dc_isar_feature(aa64_sm3
, s
);
13782 unallocated_encoding(s
);
13787 unallocated_encoding(s
);
13791 if (!fp_access_check(s
)) {
13796 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
[2];
13799 tcg_op1
= tcg_temp_new_i64();
13800 tcg_op2
= tcg_temp_new_i64();
13801 tcg_op3
= tcg_temp_new_i64();
13802 tcg_res
[0] = tcg_temp_new_i64();
13803 tcg_res
[1] = tcg_temp_new_i64();
13805 for (pass
= 0; pass
< 2; pass
++) {
13806 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13807 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13808 read_vec_element(s
, tcg_op3
, ra
, pass
, MO_64
);
13812 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13815 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13817 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13819 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13820 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13822 tcg_temp_free_i64(tcg_op1
);
13823 tcg_temp_free_i64(tcg_op2
);
13824 tcg_temp_free_i64(tcg_op3
);
13825 tcg_temp_free_i64(tcg_res
[0]);
13826 tcg_temp_free_i64(tcg_res
[1]);
13828 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
, tcg_zero
;
13830 tcg_op1
= tcg_temp_new_i32();
13831 tcg_op2
= tcg_temp_new_i32();
13832 tcg_op3
= tcg_temp_new_i32();
13833 tcg_res
= tcg_temp_new_i32();
13834 tcg_zero
= tcg_const_i32(0);
13836 read_vec_element_i32(s
, tcg_op1
, rn
, 3, MO_32
);
13837 read_vec_element_i32(s
, tcg_op2
, rm
, 3, MO_32
);
13838 read_vec_element_i32(s
, tcg_op3
, ra
, 3, MO_32
);
13840 tcg_gen_rotri_i32(tcg_res
, tcg_op1
, 20);
13841 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op2
);
13842 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op3
);
13843 tcg_gen_rotri_i32(tcg_res
, tcg_res
, 25);
13845 write_vec_element_i32(s
, tcg_zero
, rd
, 0, MO_32
);
13846 write_vec_element_i32(s
, tcg_zero
, rd
, 1, MO_32
);
13847 write_vec_element_i32(s
, tcg_zero
, rd
, 2, MO_32
);
13848 write_vec_element_i32(s
, tcg_res
, rd
, 3, MO_32
);
13850 tcg_temp_free_i32(tcg_op1
);
13851 tcg_temp_free_i32(tcg_op2
);
13852 tcg_temp_free_i32(tcg_op3
);
13853 tcg_temp_free_i32(tcg_res
);
13854 tcg_temp_free_i32(tcg_zero
);
13859 * 31 21 20 16 15 10 9 5 4 0
13860 * +-----------------------+------+--------+------+------+
13861 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
13862 * +-----------------------+------+--------+------+------+
13864 static void disas_crypto_xar(DisasContext
*s
, uint32_t insn
)
13866 int rm
= extract32(insn
, 16, 5);
13867 int imm6
= extract32(insn
, 10, 6);
13868 int rn
= extract32(insn
, 5, 5);
13869 int rd
= extract32(insn
, 0, 5);
13870 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13873 if (!dc_isar_feature(aa64_sha3
, s
)) {
13874 unallocated_encoding(s
);
13878 if (!fp_access_check(s
)) {
13882 tcg_op1
= tcg_temp_new_i64();
13883 tcg_op2
= tcg_temp_new_i64();
13884 tcg_res
[0] = tcg_temp_new_i64();
13885 tcg_res
[1] = tcg_temp_new_i64();
13887 for (pass
= 0; pass
< 2; pass
++) {
13888 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13889 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13891 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
13892 tcg_gen_rotri_i64(tcg_res
[pass
], tcg_res
[pass
], imm6
);
13894 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13895 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13897 tcg_temp_free_i64(tcg_op1
);
13898 tcg_temp_free_i64(tcg_op2
);
13899 tcg_temp_free_i64(tcg_res
[0]);
13900 tcg_temp_free_i64(tcg_res
[1]);
13903 /* Crypto three-reg imm2
13904 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13905 * +-----------------------+------+-----+------+--------+------+------+
13906 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
13907 * +-----------------------+------+-----+------+--------+------+------+
13909 static void disas_crypto_three_reg_imm2(DisasContext
*s
, uint32_t insn
)
13911 int opcode
= extract32(insn
, 10, 2);
13912 int imm2
= extract32(insn
, 12, 2);
13913 int rm
= extract32(insn
, 16, 5);
13914 int rn
= extract32(insn
, 5, 5);
13915 int rd
= extract32(insn
, 0, 5);
13916 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13917 TCGv_i32 tcg_imm2
, tcg_opcode
;
13919 if (!dc_isar_feature(aa64_sm3
, s
)) {
13920 unallocated_encoding(s
);
13924 if (!fp_access_check(s
)) {
13928 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13929 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13930 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13931 tcg_imm2
= tcg_const_i32(imm2
);
13932 tcg_opcode
= tcg_const_i32(opcode
);
13934 gen_helper_crypto_sm3tt(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
, tcg_imm2
,
13937 tcg_temp_free_ptr(tcg_rd_ptr
);
13938 tcg_temp_free_ptr(tcg_rn_ptr
);
13939 tcg_temp_free_ptr(tcg_rm_ptr
);
13940 tcg_temp_free_i32(tcg_imm2
);
13941 tcg_temp_free_i32(tcg_opcode
);
13944 /* C3.6 Data processing - SIMD, inc Crypto
13946 * As the decode gets a little complex we are using a table based
13947 * approach for this part of the decode.
13949 static const AArch64DecodeTable data_proc_simd
[] = {
13950 /* pattern , mask , fn */
13951 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
13952 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra
},
13953 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
13954 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
13955 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
13956 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
13957 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
13958 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
13959 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
13960 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
13961 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
13962 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
13963 { 0x2e000000, 0xbf208400, disas_simd_ext
},
13964 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
13965 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra
},
13966 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
13967 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
13968 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
13969 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
13970 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
13971 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
13972 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
13973 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
13974 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
13975 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512
},
13976 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512
},
13977 { 0xce000000, 0xff808000, disas_crypto_four_reg
},
13978 { 0xce800000, 0xffe00000, disas_crypto_xar
},
13979 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2
},
13980 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16
},
13981 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16
},
13982 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16
},
13983 { 0x00000000, 0x00000000, NULL
}
13986 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
13988 /* Note that this is called with all non-FP cases from
13989 * table C3-6 so it must UNDEF for entries not specifically
13990 * allocated to instructions in that table.
13992 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
13996 unallocated_encoding(s
);
14000 /* C3.6 Data processing - SIMD and floating point */
14001 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
14003 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
14004 disas_data_proc_fp(s
, insn
);
14006 /* SIMD, including crypto */
14007 disas_data_proc_simd(s
, insn
);
14013 * @env: The cpu environment
14014 * @s: The DisasContext
14016 * Return true if the page is guarded.
14018 static bool is_guarded_page(CPUARMState
*env
, DisasContext
*s
)
14020 #ifdef CONFIG_USER_ONLY
14021 return false; /* FIXME */
14023 uint64_t addr
= s
->base
.pc_first
;
14024 int mmu_idx
= arm_to_core_mmu_idx(s
->mmu_idx
);
14025 unsigned int index
= tlb_index(env
, mmu_idx
, addr
);
14026 CPUTLBEntry
*entry
= tlb_entry(env
, mmu_idx
, addr
);
14029 * We test this immediately after reading an insn, which means
14030 * that any normal page must be in the TLB. The only exception
14031 * would be for executing from flash or device memory, which
14032 * does not retain the TLB entry.
14034 * FIXME: Assume false for those, for now. We could use
14035 * arm_cpu_get_phys_page_attrs_debug to re-read the page
14036 * table entry even for that case.
14038 return (tlb_hit(entry
->addr_code
, addr
) &&
14039 env
->iotlb
[mmu_idx
][index
].attrs
.target_tlb_bit0
);
14044 * btype_destination_ok:
14045 * @insn: The instruction at the branch destination
14046 * @bt: SCTLR_ELx.BT
14047 * @btype: PSTATE.BTYPE, and is non-zero
14049 * On a guarded page, there are a limited number of insns
14050 * that may be present at the branch target:
14051 * - branch target identifiers,
14052 * - paciasp, pacibsp,
14055 * Anything else causes a Branch Target Exception.
14057 * Return true if the branch is compatible, false to raise BTITRAP.
14059 static bool btype_destination_ok(uint32_t insn
, bool bt
, int btype
)
14061 if ((insn
& 0xfffff01fu
) == 0xd503201fu
) {
14063 switch (extract32(insn
, 5, 7)) {
14064 case 0b011001: /* PACIASP */
14065 case 0b011011: /* PACIBSP */
14067 * If SCTLR_ELx.BT, then PACI*SP are not compatible
14068 * with btype == 3. Otherwise all btype are ok.
14070 return !bt
|| btype
!= 3;
14071 case 0b100000: /* BTI */
14072 /* Not compatible with any btype. */
14074 case 0b100010: /* BTI c */
14075 /* Not compatible with btype == 3 */
14077 case 0b100100: /* BTI j */
14078 /* Not compatible with btype == 2 */
14080 case 0b100110: /* BTI jc */
14081 /* Compatible with any btype. */
14085 switch (insn
& 0xffe0001fu
) {
14086 case 0xd4200000u
: /* BRK */
14087 case 0xd4400000u
: /* HLT */
14088 /* Give priority to the breakpoint exception. */
14095 /* C3.1 A64 instruction index by encoding */
14096 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
14100 insn
= arm_ldl_code(env
, s
->pc
, s
->sctlr_b
);
14104 s
->fp_access_checked
= false;
14106 if (dc_isar_feature(aa64_bti
, s
)) {
14107 if (s
->base
.num_insns
== 1) {
14109 * At the first insn of the TB, compute s->guarded_page.
14110 * We delayed computing this until successfully reading
14111 * the first insn of the TB, above. This (mostly) ensures
14112 * that the softmmu tlb entry has been populated, and the
14113 * page table GP bit is available.
14115 * Note that we need to compute this even if btype == 0,
14116 * because this value is used for BR instructions later
14117 * where ENV is not available.
14119 s
->guarded_page
= is_guarded_page(env
, s
);
14121 /* First insn can have btype set to non-zero. */
14122 tcg_debug_assert(s
->btype
>= 0);
14125 * Note that the Branch Target Exception has fairly high
14126 * priority -- below debugging exceptions but above most
14127 * everything else. This allows us to handle this now
14128 * instead of waiting until the insn is otherwise decoded.
14132 && !btype_destination_ok(insn
, s
->bt
, s
->btype
)) {
14133 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_btitrap(s
->btype
),
14134 default_exception_el(s
));
14138 /* Not the first insn: btype must be 0. */
14139 tcg_debug_assert(s
->btype
== 0);
14143 switch (extract32(insn
, 25, 4)) {
14144 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
14145 unallocated_encoding(s
);
14148 if (!dc_isar_feature(aa64_sve
, s
) || !disas_sve(s
, insn
)) {
14149 unallocated_encoding(s
);
14152 case 0x8: case 0x9: /* Data processing - immediate */
14153 disas_data_proc_imm(s
, insn
);
14155 case 0xa: case 0xb: /* Branch, exception generation and system insns */
14156 disas_b_exc_sys(s
, insn
);
14161 case 0xe: /* Loads and stores */
14162 disas_ldst(s
, insn
);
14165 case 0xd: /* Data processing - register */
14166 disas_data_proc_reg(s
, insn
);
14169 case 0xf: /* Data processing - SIMD and floating point */
14170 disas_data_proc_simd_fp(s
, insn
);
14173 assert(FALSE
); /* all 15 cases should be handled above */
14177 /* if we allocated any temporaries, free them here */
14181 * After execution of most insns, btype is reset to 0.
14182 * Note that we set btype == -1 when the insn sets btype.
14184 if (s
->btype
> 0 && s
->base
.is_jmp
!= DISAS_NORETURN
) {
14189 static void aarch64_tr_init_disas_context(DisasContextBase
*dcbase
,
14192 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14193 CPUARMState
*env
= cpu
->env_ptr
;
14194 ARMCPU
*arm_cpu
= arm_env_get_cpu(env
);
14195 uint32_t tb_flags
= dc
->base
.tb
->flags
;
14196 int bound
, core_mmu_idx
;
14198 dc
->isar
= &arm_cpu
->isar
;
14199 dc
->pc
= dc
->base
.pc_first
;
14203 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
14204 * there is no secure EL1, so we route exceptions to EL3.
14206 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
14207 !arm_el_is_aa64(env
, 3);
14210 dc
->be_data
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, BE_DATA
) ? MO_BE
: MO_LE
;
14211 dc
->condexec_mask
= 0;
14212 dc
->condexec_cond
= 0;
14213 core_mmu_idx
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, MMUIDX
);
14214 dc
->mmu_idx
= core_to_arm_mmu_idx(env
, core_mmu_idx
);
14215 dc
->tbii
= FIELD_EX32(tb_flags
, TBFLAG_A64
, TBII
);
14216 dc
->tbid
= FIELD_EX32(tb_flags
, TBFLAG_A64
, TBID
);
14217 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
14218 #if !defined(CONFIG_USER_ONLY)
14219 dc
->user
= (dc
->current_el
== 0);
14221 dc
->fp_excp_el
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, FPEXC_EL
);
14222 dc
->sve_excp_el
= FIELD_EX32(tb_flags
, TBFLAG_A64
, SVEEXC_EL
);
14223 dc
->sve_len
= (FIELD_EX32(tb_flags
, TBFLAG_A64
, ZCR_LEN
) + 1) * 16;
14224 dc
->pauth_active
= FIELD_EX32(tb_flags
, TBFLAG_A64
, PAUTH_ACTIVE
);
14225 dc
->bt
= FIELD_EX32(tb_flags
, TBFLAG_A64
, BT
);
14226 dc
->btype
= FIELD_EX32(tb_flags
, TBFLAG_A64
, BTYPE
);
14228 dc
->vec_stride
= 0;
14229 dc
->cp_regs
= arm_cpu
->cp_regs
;
14230 dc
->features
= env
->features
;
14232 /* Single step state. The code-generation logic here is:
14234 * generate code with no special handling for single-stepping (except
14235 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
14236 * this happens anyway because those changes are all system register or
14238 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
14239 * emit code for one insn
14240 * emit code to clear PSTATE.SS
14241 * emit code to generate software step exception for completed step
14242 * end TB (as usual for having generated an exception)
14243 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
14244 * emit code to generate a software step exception
14247 dc
->ss_active
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, SS_ACTIVE
);
14248 dc
->pstate_ss
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, PSTATE_SS
);
14249 dc
->is_ldex
= false;
14250 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
14252 /* Bound the number of insns to execute to those left on the page. */
14253 bound
= -(dc
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
14255 /* If architectural single step active, limit to 1. */
14256 if (dc
->ss_active
) {
14259 dc
->base
.max_insns
= MIN(dc
->base
.max_insns
, bound
);
14261 init_tmp_a64_array(dc
);
14264 static void aarch64_tr_tb_start(DisasContextBase
*db
, CPUState
*cpu
)
14268 static void aarch64_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
14270 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14272 tcg_gen_insn_start(dc
->pc
, 0, 0);
14273 dc
->insn_start
= tcg_last_op();
14276 static bool aarch64_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cpu
,
14277 const CPUBreakpoint
*bp
)
14279 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14281 if (bp
->flags
& BP_CPU
) {
14282 gen_a64_set_pc_im(dc
->pc
);
14283 gen_helper_check_breakpoints(cpu_env
);
14284 /* End the TB early; it likely won't be executed */
14285 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
14287 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
14288 /* The address covered by the breakpoint must be
14289 included in [tb->pc, tb->pc + tb->size) in order
14290 to for it to be properly cleared -- thus we
14291 increment the PC here so that the logic setting
14292 tb->size below does the right thing. */
14294 dc
->base
.is_jmp
= DISAS_NORETURN
;
14300 static void aarch64_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
14302 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14303 CPUARMState
*env
= cpu
->env_ptr
;
14305 if (dc
->ss_active
&& !dc
->pstate_ss
) {
14306 /* Singlestep state is Active-pending.
14307 * If we're in this state at the start of a TB then either
14308 * a) we just took an exception to an EL which is being debugged
14309 * and this is the first insn in the exception handler
14310 * b) debug exceptions were masked and we just unmasked them
14311 * without changing EL (eg by clearing PSTATE.D)
14312 * In either case we're going to take a swstep exception in the
14313 * "did not step an insn" case, and so the syndrome ISV and EX
14314 * bits should be zero.
14316 assert(dc
->base
.num_insns
== 1);
14317 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0),
14318 default_exception_el(dc
));
14319 dc
->base
.is_jmp
= DISAS_NORETURN
;
14321 disas_a64_insn(env
, dc
);
14324 dc
->base
.pc_next
= dc
->pc
;
14325 translator_loop_temp_check(&dc
->base
);
14328 static void aarch64_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
14330 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14332 if (unlikely(dc
->base
.singlestep_enabled
|| dc
->ss_active
)) {
14333 /* Note that this means single stepping WFI doesn't halt the CPU.
14334 * For conditional branch insns this is harmless unreachable code as
14335 * gen_goto_tb() has already handled emitting the debug exception
14336 * (and thus a tb-jump is not possible when singlestepping).
14338 switch (dc
->base
.is_jmp
) {
14340 gen_a64_set_pc_im(dc
->pc
);
14344 if (dc
->base
.singlestep_enabled
) {
14345 gen_exception_internal(EXCP_DEBUG
);
14347 gen_step_complete_exception(dc
);
14350 case DISAS_NORETURN
:
14354 switch (dc
->base
.is_jmp
) {
14356 case DISAS_TOO_MANY
:
14357 gen_goto_tb(dc
, 1, dc
->pc
);
14361 gen_a64_set_pc_im(dc
->pc
);
14364 tcg_gen_exit_tb(NULL
, 0);
14367 tcg_gen_lookup_and_goto_ptr();
14369 case DISAS_NORETURN
:
14373 gen_a64_set_pc_im(dc
->pc
);
14374 gen_helper_wfe(cpu_env
);
14377 gen_a64_set_pc_im(dc
->pc
);
14378 gen_helper_yield(cpu_env
);
14382 /* This is a special case because we don't want to just halt the CPU
14383 * if trying to debug across a WFI.
14385 TCGv_i32 tmp
= tcg_const_i32(4);
14387 gen_a64_set_pc_im(dc
->pc
);
14388 gen_helper_wfi(cpu_env
, tmp
);
14389 tcg_temp_free_i32(tmp
);
14390 /* The helper doesn't necessarily throw an exception, but we
14391 * must go back to the main loop to check for interrupts anyway.
14393 tcg_gen_exit_tb(NULL
, 0);
14399 /* Functions above can change dc->pc, so re-align db->pc_next */
14400 dc
->base
.pc_next
= dc
->pc
;
14403 static void aarch64_tr_disas_log(const DisasContextBase
*dcbase
,
14406 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14408 qemu_log("IN: %s\n", lookup_symbol(dc
->base
.pc_first
));
14409 log_target_disas(cpu
, dc
->base
.pc_first
, dc
->base
.tb
->size
);
14412 const TranslatorOps aarch64_translator_ops
= {
14413 .init_disas_context
= aarch64_tr_init_disas_context
,
14414 .tb_start
= aarch64_tr_tb_start
,
14415 .insn_start
= aarch64_tr_insn_start
,
14416 .breakpoint_check
= aarch64_tr_breakpoint_check
,
14417 .translate_insn
= aarch64_tr_translate_insn
,
14418 .tb_stop
= aarch64_tr_tb_stop
,
14419 .disas_log
= aarch64_tr_disas_log
,