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_ss_advance(DisasContext
*s
)
426 /* If the singlestep state is Active-not-pending, advance to
431 gen_helper_clear_pstate_ss(cpu_env
);
435 static void gen_step_complete_exception(DisasContext
*s
)
437 /* We just completed step of an insn. Move from Active-not-pending
438 * to Active-pending, and then also take the swstep exception.
439 * This corresponds to making the (IMPDEF) choice to prioritize
440 * swstep exceptions over asynchronous exceptions taken to an exception
441 * level where debug is disabled. This choice has the advantage that
442 * we do not need to maintain internal state corresponding to the
443 * ISV/EX syndrome bits between completion of the step and generation
444 * of the exception, and our syndrome information is always correct.
447 gen_exception(EXCP_UDEF
, syn_swstep(s
->ss_same_el
, 1, s
->is_ldex
),
448 default_exception_el(s
));
449 s
->base
.is_jmp
= DISAS_NORETURN
;
452 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
454 /* No direct tb linking with singlestep (either QEMU's or the ARM
455 * debug architecture kind) or deterministic io
457 if (s
->base
.singlestep_enabled
|| s
->ss_active
||
458 (tb_cflags(s
->base
.tb
) & CF_LAST_IO
)) {
462 #ifndef CONFIG_USER_ONLY
463 /* Only link tbs from inside the same guest page */
464 if ((s
->base
.tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
472 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
474 TranslationBlock
*tb
;
477 if (use_goto_tb(s
, n
, dest
)) {
479 gen_a64_set_pc_im(dest
);
480 tcg_gen_exit_tb(tb
, n
);
481 s
->base
.is_jmp
= DISAS_NORETURN
;
483 gen_a64_set_pc_im(dest
);
485 gen_step_complete_exception(s
);
486 } else if (s
->base
.singlestep_enabled
) {
487 gen_exception_internal(EXCP_DEBUG
);
489 tcg_gen_lookup_and_goto_ptr();
490 s
->base
.is_jmp
= DISAS_NORETURN
;
495 void unallocated_encoding(DisasContext
*s
)
497 /* Unallocated and reserved encodings are uncategorized */
498 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized(),
499 default_exception_el(s
));
502 static void init_tmp_a64_array(DisasContext
*s
)
504 #ifdef CONFIG_DEBUG_TCG
505 memset(s
->tmp_a64
, 0, sizeof(s
->tmp_a64
));
507 s
->tmp_a64_count
= 0;
510 static void free_tmp_a64(DisasContext
*s
)
513 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
514 tcg_temp_free_i64(s
->tmp_a64
[i
]);
516 init_tmp_a64_array(s
);
519 TCGv_i64
new_tmp_a64(DisasContext
*s
)
521 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
522 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
525 TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
527 TCGv_i64 t
= new_tmp_a64(s
);
528 tcg_gen_movi_i64(t
, 0);
533 * Register access functions
535 * These functions are used for directly accessing a register in where
536 * changes to the final register value are likely to be made. If you
537 * need to use a register for temporary calculation (e.g. index type
538 * operations) use the read_* form.
540 * B1.2.1 Register mappings
542 * In instruction register encoding 31 can refer to ZR (zero register) or
543 * the SP (stack pointer) depending on context. In QEMU's case we map SP
544 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
545 * This is the point of the _sp forms.
547 TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
550 return new_tmp_a64_zero(s
);
556 /* register access for when 31 == SP */
557 TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
562 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
563 * representing the register contents. This TCGv is an auto-freed
564 * temporary so it need not be explicitly freed, and may be modified.
566 TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
568 TCGv_i64 v
= new_tmp_a64(s
);
571 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
573 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
576 tcg_gen_movi_i64(v
, 0);
581 TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
583 TCGv_i64 v
= new_tmp_a64(s
);
585 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
587 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
592 /* Return the offset into CPUARMState of a slice (from
593 * the least significant end) of FP register Qn (ie
595 * (Note that this is not the same mapping as for A32; see cpu.h)
597 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
599 return vec_reg_offset(s
, regno
, 0, size
);
602 /* Offset of the high half of the 128 bit vector Qn */
603 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
605 return vec_reg_offset(s
, regno
, 1, MO_64
);
608 /* Convenience accessors for reading and writing single and double
609 * FP registers. Writing clears the upper parts of the associated
610 * 128 bit vector register, as required by the architecture.
611 * Note that unlike the GP register accessors, the values returned
612 * by the read functions must be manually freed.
614 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
616 TCGv_i64 v
= tcg_temp_new_i64();
618 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
622 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
624 TCGv_i32 v
= tcg_temp_new_i32();
626 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
630 static TCGv_i32
read_fp_hreg(DisasContext
*s
, int reg
)
632 TCGv_i32 v
= tcg_temp_new_i32();
634 tcg_gen_ld16u_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_16
));
638 /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64).
639 * If SVE is not enabled, then there are only 128 bits in the vector.
641 static void clear_vec_high(DisasContext
*s
, bool is_q
, int rd
)
643 unsigned ofs
= fp_reg_offset(s
, rd
, MO_64
);
644 unsigned vsz
= vec_full_reg_size(s
);
647 TCGv_i64 tcg_zero
= tcg_const_i64(0);
648 tcg_gen_st_i64(tcg_zero
, cpu_env
, ofs
+ 8);
649 tcg_temp_free_i64(tcg_zero
);
652 tcg_gen_gvec_dup8i(ofs
+ 16, vsz
- 16, vsz
- 16, 0);
656 void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
658 unsigned ofs
= fp_reg_offset(s
, reg
, MO_64
);
660 tcg_gen_st_i64(v
, cpu_env
, ofs
);
661 clear_vec_high(s
, false, reg
);
664 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
666 TCGv_i64 tmp
= tcg_temp_new_i64();
668 tcg_gen_extu_i32_i64(tmp
, v
);
669 write_fp_dreg(s
, reg
, tmp
);
670 tcg_temp_free_i64(tmp
);
673 TCGv_ptr
get_fpstatus_ptr(bool is_f16
)
675 TCGv_ptr statusptr
= tcg_temp_new_ptr();
678 /* In A64 all instructions (both FP and Neon) use the FPCR; there
679 * is no equivalent of the A32 Neon "standard FPSCR value".
680 * However half-precision operations operate under a different
681 * FZ16 flag and use vfp.fp_status_f16 instead of vfp.fp_status.
684 offset
= offsetof(CPUARMState
, vfp
.fp_status_f16
);
686 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
688 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
692 /* Expand a 2-operand AdvSIMD vector operation using an expander function. */
693 static void gen_gvec_fn2(DisasContext
*s
, bool is_q
, int rd
, int rn
,
694 GVecGen2Fn
*gvec_fn
, int vece
)
696 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
697 is_q
? 16 : 8, vec_full_reg_size(s
));
700 /* Expand a 2-operand + immediate AdvSIMD vector operation using
701 * an expander function.
703 static void gen_gvec_fn2i(DisasContext
*s
, bool is_q
, int rd
, int rn
,
704 int64_t imm
, GVecGen2iFn
*gvec_fn
, int vece
)
706 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
707 imm
, is_q
? 16 : 8, vec_full_reg_size(s
));
710 /* Expand a 3-operand AdvSIMD vector operation using an expander function. */
711 static void gen_gvec_fn3(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
712 GVecGen3Fn
*gvec_fn
, int vece
)
714 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
715 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8, vec_full_reg_size(s
));
718 /* Expand a 2-operand + immediate AdvSIMD vector operation using
721 static void gen_gvec_op2i(DisasContext
*s
, bool is_q
, int rd
,
722 int rn
, int64_t imm
, const GVecGen2i
*gvec_op
)
724 tcg_gen_gvec_2i(vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
725 is_q
? 16 : 8, vec_full_reg_size(s
), imm
, gvec_op
);
728 /* Expand a 3-operand AdvSIMD vector operation using an op descriptor. */
729 static void gen_gvec_op3(DisasContext
*s
, bool is_q
, int rd
,
730 int rn
, int rm
, const GVecGen3
*gvec_op
)
732 tcg_gen_gvec_3(vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
733 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8,
734 vec_full_reg_size(s
), gvec_op
);
737 /* Expand a 3-operand operation using an out-of-line helper. */
738 static void gen_gvec_op3_ool(DisasContext
*s
, bool is_q
, int rd
,
739 int rn
, int rm
, int data
, gen_helper_gvec_3
*fn
)
741 tcg_gen_gvec_3_ool(vec_full_reg_offset(s
, rd
),
742 vec_full_reg_offset(s
, rn
),
743 vec_full_reg_offset(s
, rm
),
744 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
747 /* Expand a 3-operand + env pointer operation using
748 * an out-of-line helper.
750 static void gen_gvec_op3_env(DisasContext
*s
, bool is_q
, int rd
,
751 int rn
, int rm
, gen_helper_gvec_3_ptr
*fn
)
753 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
754 vec_full_reg_offset(s
, rn
),
755 vec_full_reg_offset(s
, rm
), cpu_env
,
756 is_q
? 16 : 8, vec_full_reg_size(s
), 0, fn
);
759 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
760 * an out-of-line helper.
762 static void gen_gvec_op3_fpst(DisasContext
*s
, bool is_q
, int rd
, int rn
,
763 int rm
, bool is_fp16
, int data
,
764 gen_helper_gvec_3_ptr
*fn
)
766 TCGv_ptr fpst
= get_fpstatus_ptr(is_fp16
);
767 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
768 vec_full_reg_offset(s
, rn
),
769 vec_full_reg_offset(s
, rm
), fpst
,
770 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
771 tcg_temp_free_ptr(fpst
);
774 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
775 * than the 32 bit equivalent.
777 static inline void gen_set_NZ64(TCGv_i64 result
)
779 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
780 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
783 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
784 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
787 gen_set_NZ64(result
);
789 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
790 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
792 tcg_gen_movi_i32(cpu_CF
, 0);
793 tcg_gen_movi_i32(cpu_VF
, 0);
796 /* dest = T0 + T1; compute C, N, V and Z flags */
797 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
800 TCGv_i64 result
, flag
, tmp
;
801 result
= tcg_temp_new_i64();
802 flag
= tcg_temp_new_i64();
803 tmp
= tcg_temp_new_i64();
805 tcg_gen_movi_i64(tmp
, 0);
806 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
808 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
810 gen_set_NZ64(result
);
812 tcg_gen_xor_i64(flag
, result
, t0
);
813 tcg_gen_xor_i64(tmp
, t0
, t1
);
814 tcg_gen_andc_i64(flag
, flag
, tmp
);
815 tcg_temp_free_i64(tmp
);
816 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
818 tcg_gen_mov_i64(dest
, result
);
819 tcg_temp_free_i64(result
);
820 tcg_temp_free_i64(flag
);
822 /* 32 bit arithmetic */
823 TCGv_i32 t0_32
= tcg_temp_new_i32();
824 TCGv_i32 t1_32
= tcg_temp_new_i32();
825 TCGv_i32 tmp
= tcg_temp_new_i32();
827 tcg_gen_movi_i32(tmp
, 0);
828 tcg_gen_extrl_i64_i32(t0_32
, t0
);
829 tcg_gen_extrl_i64_i32(t1_32
, t1
);
830 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
831 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
832 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
833 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
834 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
835 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
837 tcg_temp_free_i32(tmp
);
838 tcg_temp_free_i32(t0_32
);
839 tcg_temp_free_i32(t1_32
);
843 /* dest = T0 - T1; compute C, N, V and Z flags */
844 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
847 /* 64 bit arithmetic */
848 TCGv_i64 result
, flag
, tmp
;
850 result
= tcg_temp_new_i64();
851 flag
= tcg_temp_new_i64();
852 tcg_gen_sub_i64(result
, t0
, t1
);
854 gen_set_NZ64(result
);
856 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
857 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
859 tcg_gen_xor_i64(flag
, result
, t0
);
860 tmp
= tcg_temp_new_i64();
861 tcg_gen_xor_i64(tmp
, t0
, t1
);
862 tcg_gen_and_i64(flag
, flag
, tmp
);
863 tcg_temp_free_i64(tmp
);
864 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
865 tcg_gen_mov_i64(dest
, result
);
866 tcg_temp_free_i64(flag
);
867 tcg_temp_free_i64(result
);
869 /* 32 bit arithmetic */
870 TCGv_i32 t0_32
= tcg_temp_new_i32();
871 TCGv_i32 t1_32
= tcg_temp_new_i32();
874 tcg_gen_extrl_i64_i32(t0_32
, t0
);
875 tcg_gen_extrl_i64_i32(t1_32
, t1
);
876 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
877 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
878 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
879 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
880 tmp
= tcg_temp_new_i32();
881 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
882 tcg_temp_free_i32(t0_32
);
883 tcg_temp_free_i32(t1_32
);
884 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
885 tcg_temp_free_i32(tmp
);
886 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
890 /* dest = T0 + T1 + CF; do not compute flags. */
891 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
893 TCGv_i64 flag
= tcg_temp_new_i64();
894 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
895 tcg_gen_add_i64(dest
, t0
, t1
);
896 tcg_gen_add_i64(dest
, dest
, flag
);
897 tcg_temp_free_i64(flag
);
900 tcg_gen_ext32u_i64(dest
, dest
);
904 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
905 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
908 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
909 result
= tcg_temp_new_i64();
910 cf_64
= tcg_temp_new_i64();
911 vf_64
= tcg_temp_new_i64();
912 tmp
= tcg_const_i64(0);
914 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
915 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
916 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
917 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
918 gen_set_NZ64(result
);
920 tcg_gen_xor_i64(vf_64
, result
, t0
);
921 tcg_gen_xor_i64(tmp
, t0
, t1
);
922 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
923 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
925 tcg_gen_mov_i64(dest
, result
);
927 tcg_temp_free_i64(tmp
);
928 tcg_temp_free_i64(vf_64
);
929 tcg_temp_free_i64(cf_64
);
930 tcg_temp_free_i64(result
);
932 TCGv_i32 t0_32
, t1_32
, tmp
;
933 t0_32
= tcg_temp_new_i32();
934 t1_32
= tcg_temp_new_i32();
935 tmp
= tcg_const_i32(0);
937 tcg_gen_extrl_i64_i32(t0_32
, t0
);
938 tcg_gen_extrl_i64_i32(t1_32
, t1
);
939 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
940 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
942 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
943 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
944 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
945 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
946 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
948 tcg_temp_free_i32(tmp
);
949 tcg_temp_free_i32(t1_32
);
950 tcg_temp_free_i32(t0_32
);
955 * Load/Store generators
959 * Store from GPR register to memory.
961 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
962 TCGv_i64 tcg_addr
, int size
, int memidx
,
964 unsigned int iss_srt
,
965 bool iss_sf
, bool iss_ar
)
968 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, s
->be_data
+ size
);
973 syn
= syn_data_abort_with_iss(0,
979 0, 0, 0, 0, 0, false);
980 disas_set_insn_syndrome(s
, syn
);
984 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
985 TCGv_i64 tcg_addr
, int size
,
987 unsigned int iss_srt
,
988 bool iss_sf
, bool iss_ar
)
990 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
),
991 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
995 * Load from memory to GPR register
997 static void do_gpr_ld_memidx(DisasContext
*s
,
998 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
999 int size
, bool is_signed
,
1000 bool extend
, int memidx
,
1001 bool iss_valid
, unsigned int iss_srt
,
1002 bool iss_sf
, bool iss_ar
)
1004 TCGMemOp memop
= s
->be_data
+ size
;
1006 g_assert(size
<= 3);
1012 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
1014 if (extend
&& is_signed
) {
1016 tcg_gen_ext32u_i64(dest
, dest
);
1022 syn
= syn_data_abort_with_iss(0,
1028 0, 0, 0, 0, 0, false);
1029 disas_set_insn_syndrome(s
, syn
);
1033 static void do_gpr_ld(DisasContext
*s
,
1034 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
1035 int size
, bool is_signed
, bool extend
,
1036 bool iss_valid
, unsigned int iss_srt
,
1037 bool iss_sf
, bool iss_ar
)
1039 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
1041 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
1045 * Store from FP register to memory
1047 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
1049 /* This writes the bottom N bits of a 128 bit wide vector to memory */
1050 TCGv_i64 tmp
= tcg_temp_new_i64();
1051 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
1053 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
),
1056 bool be
= s
->be_data
== MO_BE
;
1057 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
1059 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
1060 tcg_gen_qemu_st_i64(tmp
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
1062 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
1063 tcg_gen_qemu_st_i64(tmp
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
1065 tcg_temp_free_i64(tcg_hiaddr
);
1068 tcg_temp_free_i64(tmp
);
1072 * Load from memory to FP register
1074 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
1076 /* This always zero-extends and writes to a full 128 bit wide vector */
1077 TCGv_i64 tmplo
= tcg_temp_new_i64();
1081 TCGMemOp memop
= s
->be_data
+ size
;
1082 tmphi
= tcg_const_i64(0);
1083 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
1085 bool be
= s
->be_data
== MO_BE
;
1086 TCGv_i64 tcg_hiaddr
;
1088 tmphi
= tcg_temp_new_i64();
1089 tcg_hiaddr
= tcg_temp_new_i64();
1091 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
1092 tcg_gen_qemu_ld_i64(tmplo
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
1094 tcg_gen_qemu_ld_i64(tmphi
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
1096 tcg_temp_free_i64(tcg_hiaddr
);
1099 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
1100 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
1102 tcg_temp_free_i64(tmplo
);
1103 tcg_temp_free_i64(tmphi
);
1105 clear_vec_high(s
, true, destidx
);
1109 * Vector load/store helpers.
1111 * The principal difference between this and a FP load is that we don't
1112 * zero extend as we are filling a partial chunk of the vector register.
1113 * These functions don't support 128 bit loads/stores, which would be
1114 * normal load/store operations.
1116 * The _i32 versions are useful when operating on 32 bit quantities
1117 * (eg for floating point single or using Neon helper functions).
1120 /* Get value of an element within a vector register */
1121 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
1122 int element
, TCGMemOp memop
)
1124 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1127 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
1130 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
1133 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
1136 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
1139 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
1142 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
1146 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
1149 g_assert_not_reached();
1153 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
1154 int element
, TCGMemOp memop
)
1156 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1159 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
1162 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
1165 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
1168 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
1172 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
1175 g_assert_not_reached();
1179 /* Set value of an element within a vector register */
1180 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
1181 int element
, TCGMemOp memop
)
1183 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1186 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
1189 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
1192 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
1195 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
1198 g_assert_not_reached();
1202 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
1203 int destidx
, int element
, TCGMemOp memop
)
1205 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1208 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
1211 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
1214 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
1217 g_assert_not_reached();
1221 /* Store from vector register to memory */
1222 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
1223 TCGv_i64 tcg_addr
, int size
, TCGMemOp endian
)
1225 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1227 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
1228 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), endian
| size
);
1230 tcg_temp_free_i64(tcg_tmp
);
1233 /* Load from memory to vector register */
1234 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
1235 TCGv_i64 tcg_addr
, int size
, TCGMemOp endian
)
1237 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1239 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), endian
| size
);
1240 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
1242 tcg_temp_free_i64(tcg_tmp
);
1245 /* Check that FP/Neon access is enabled. If it is, return
1246 * true. If not, emit code to generate an appropriate exception,
1247 * and return false; the caller should not emit any code for
1248 * the instruction. Note that this check must happen after all
1249 * unallocated-encoding checks (otherwise the syndrome information
1250 * for the resulting exception will be incorrect).
1252 static inline bool fp_access_check(DisasContext
*s
)
1254 assert(!s
->fp_access_checked
);
1255 s
->fp_access_checked
= true;
1257 if (!s
->fp_excp_el
) {
1261 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false),
1266 /* Check that SVE access is enabled. If it is, return true.
1267 * If not, emit code to generate an appropriate exception and return false.
1269 bool sve_access_check(DisasContext
*s
)
1271 if (s
->sve_excp_el
) {
1272 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_sve_access_trap(),
1276 return fp_access_check(s
);
1280 * This utility function is for doing register extension with an
1281 * optional shift. You will likely want to pass a temporary for the
1282 * destination register. See DecodeRegExtend() in the ARM ARM.
1284 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1285 int option
, unsigned int shift
)
1287 int extsize
= extract32(option
, 0, 2);
1288 bool is_signed
= extract32(option
, 2, 1);
1293 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1296 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1299 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1302 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1308 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1311 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1314 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1317 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1323 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1327 static inline void gen_check_sp_alignment(DisasContext
*s
)
1329 /* The AArch64 architecture mandates that (if enabled via PSTATE
1330 * or SCTLR bits) there is a check that SP is 16-aligned on every
1331 * SP-relative load or store (with an exception generated if it is not).
1332 * In line with general QEMU practice regarding misaligned accesses,
1333 * we omit these checks for the sake of guest program performance.
1334 * This function is provided as a hook so we can more easily add these
1335 * checks in future (possibly as a "favour catching guest program bugs
1336 * over speed" user selectable option).
1341 * This provides a simple table based table lookup decoder. It is
1342 * intended to be used when the relevant bits for decode are too
1343 * awkwardly placed and switch/if based logic would be confusing and
1344 * deeply nested. Since it's a linear search through the table, tables
1345 * should be kept small.
1347 * It returns the first handler where insn & mask == pattern, or
1348 * NULL if there is no match.
1349 * The table is terminated by an empty mask (i.e. 0)
1351 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1354 const AArch64DecodeTable
*tptr
= table
;
1356 while (tptr
->mask
) {
1357 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1358 return tptr
->disas_fn
;
1366 * The instruction disassembly implemented here matches
1367 * the instruction encoding classifications in chapter C4
1368 * of the ARM Architecture Reference Manual (DDI0487B_a);
1369 * classification names and decode diagrams here should generally
1370 * match up with those in the manual.
1373 /* Unconditional branch (immediate)
1375 * +----+-----------+-------------------------------------+
1376 * | op | 0 0 1 0 1 | imm26 |
1377 * +----+-----------+-------------------------------------+
1379 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1381 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1383 if (insn
& (1U << 31)) {
1384 /* BL Branch with link */
1385 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1388 /* B Branch / BL Branch with link */
1390 gen_goto_tb(s
, 0, addr
);
1393 /* Compare and branch (immediate)
1394 * 31 30 25 24 23 5 4 0
1395 * +----+-------------+----+---------------------+--------+
1396 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1397 * +----+-------------+----+---------------------+--------+
1399 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1401 unsigned int sf
, op
, rt
;
1403 TCGLabel
*label_match
;
1406 sf
= extract32(insn
, 31, 1);
1407 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1408 rt
= extract32(insn
, 0, 5);
1409 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1411 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1412 label_match
= gen_new_label();
1415 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1416 tcg_cmp
, 0, label_match
);
1418 gen_goto_tb(s
, 0, s
->pc
);
1419 gen_set_label(label_match
);
1420 gen_goto_tb(s
, 1, addr
);
1423 /* Test and branch (immediate)
1424 * 31 30 25 24 23 19 18 5 4 0
1425 * +----+-------------+----+-------+-------------+------+
1426 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1427 * +----+-------------+----+-------+-------------+------+
1429 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1431 unsigned int bit_pos
, op
, rt
;
1433 TCGLabel
*label_match
;
1436 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1437 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1438 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1439 rt
= extract32(insn
, 0, 5);
1441 tcg_cmp
= tcg_temp_new_i64();
1442 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1443 label_match
= gen_new_label();
1446 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1447 tcg_cmp
, 0, label_match
);
1448 tcg_temp_free_i64(tcg_cmp
);
1449 gen_goto_tb(s
, 0, s
->pc
);
1450 gen_set_label(label_match
);
1451 gen_goto_tb(s
, 1, addr
);
1454 /* Conditional branch (immediate)
1455 * 31 25 24 23 5 4 3 0
1456 * +---------------+----+---------------------+----+------+
1457 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1458 * +---------------+----+---------------------+----+------+
1460 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1465 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1466 unallocated_encoding(s
);
1469 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1470 cond
= extract32(insn
, 0, 4);
1474 /* genuinely conditional branches */
1475 TCGLabel
*label_match
= gen_new_label();
1476 arm_gen_test_cc(cond
, label_match
);
1477 gen_goto_tb(s
, 0, s
->pc
);
1478 gen_set_label(label_match
);
1479 gen_goto_tb(s
, 1, addr
);
1481 /* 0xe and 0xf are both "always" conditions */
1482 gen_goto_tb(s
, 0, addr
);
1486 /* HINT instruction group, including various allocated HINTs */
1487 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1488 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1490 unsigned int selector
= crm
<< 3 | op2
;
1493 unallocated_encoding(s
);
1498 case 0b00000: /* NOP */
1500 case 0b00011: /* WFI */
1501 s
->base
.is_jmp
= DISAS_WFI
;
1503 case 0b00001: /* YIELD */
1504 /* When running in MTTCG we don't generate jumps to the yield and
1505 * WFE helpers as it won't affect the scheduling of other vCPUs.
1506 * If we wanted to more completely model WFE/SEV so we don't busy
1507 * spin unnecessarily we would need to do something more involved.
1509 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1510 s
->base
.is_jmp
= DISAS_YIELD
;
1513 case 0b00010: /* WFE */
1514 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1515 s
->base
.is_jmp
= DISAS_WFE
;
1518 case 0b00100: /* SEV */
1519 case 0b00101: /* SEVL */
1520 /* we treat all as NOP at least for now */
1522 case 0b00111: /* XPACLRI */
1523 if (s
->pauth_active
) {
1524 gen_helper_xpaci(cpu_X
[30], cpu_env
, cpu_X
[30]);
1527 case 0b01000: /* PACIA1716 */
1528 if (s
->pauth_active
) {
1529 gen_helper_pacia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1532 case 0b01010: /* PACIB1716 */
1533 if (s
->pauth_active
) {
1534 gen_helper_pacib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1537 case 0b01100: /* AUTIA1716 */
1538 if (s
->pauth_active
) {
1539 gen_helper_autia(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1542 case 0b01110: /* AUTIB1716 */
1543 if (s
->pauth_active
) {
1544 gen_helper_autib(cpu_X
[17], cpu_env
, cpu_X
[17], cpu_X
[16]);
1547 case 0b11000: /* PACIAZ */
1548 if (s
->pauth_active
) {
1549 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30],
1550 new_tmp_a64_zero(s
));
1553 case 0b11001: /* PACIASP */
1554 if (s
->pauth_active
) {
1555 gen_helper_pacia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1558 case 0b11010: /* PACIBZ */
1559 if (s
->pauth_active
) {
1560 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30],
1561 new_tmp_a64_zero(s
));
1564 case 0b11011: /* PACIBSP */
1565 if (s
->pauth_active
) {
1566 gen_helper_pacib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1569 case 0b11100: /* AUTIAZ */
1570 if (s
->pauth_active
) {
1571 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30],
1572 new_tmp_a64_zero(s
));
1575 case 0b11101: /* AUTIASP */
1576 if (s
->pauth_active
) {
1577 gen_helper_autia(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1580 case 0b11110: /* AUTIBZ */
1581 if (s
->pauth_active
) {
1582 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30],
1583 new_tmp_a64_zero(s
));
1586 case 0b11111: /* AUTIBSP */
1587 if (s
->pauth_active
) {
1588 gen_helper_autib(cpu_X
[30], cpu_env
, cpu_X
[30], cpu_X
[31]);
1592 /* default specified as NOP equivalent */
1597 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1599 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1602 /* CLREX, DSB, DMB, ISB */
1603 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1604 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1609 unallocated_encoding(s
);
1620 case 1: /* MBReqTypes_Reads */
1621 bar
= TCG_BAR_SC
| TCG_MO_LD_LD
| TCG_MO_LD_ST
;
1623 case 2: /* MBReqTypes_Writes */
1624 bar
= TCG_BAR_SC
| TCG_MO_ST_ST
;
1626 default: /* MBReqTypes_All */
1627 bar
= TCG_BAR_SC
| TCG_MO_ALL
;
1633 /* We need to break the TB after this insn to execute
1634 * a self-modified code correctly and also to take
1635 * any pending interrupts immediately.
1638 gen_goto_tb(s
, 0, s
->pc
);
1641 unallocated_encoding(s
);
1646 /* MSR (immediate) - move immediate to processor state field */
1647 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1648 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1650 int op
= op1
<< 3 | op2
;
1652 case 0x05: /* SPSel */
1653 if (s
->current_el
== 0) {
1654 unallocated_encoding(s
);
1658 case 0x1e: /* DAIFSet */
1659 case 0x1f: /* DAIFClear */
1661 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1662 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1663 gen_a64_set_pc_im(s
->pc
- 4);
1664 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1665 tcg_temp_free_i32(tcg_imm
);
1666 tcg_temp_free_i32(tcg_op
);
1667 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1668 gen_a64_set_pc_im(s
->pc
);
1669 s
->base
.is_jmp
= (op
== 0x1f ? DISAS_EXIT
: DISAS_JUMP
);
1673 unallocated_encoding(s
);
1678 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1680 TCGv_i32 tmp
= tcg_temp_new_i32();
1681 TCGv_i32 nzcv
= tcg_temp_new_i32();
1683 /* build bit 31, N */
1684 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1685 /* build bit 30, Z */
1686 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1687 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1688 /* build bit 29, C */
1689 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1690 /* build bit 28, V */
1691 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1692 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1693 /* generate result */
1694 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1696 tcg_temp_free_i32(nzcv
);
1697 tcg_temp_free_i32(tmp
);
1700 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1703 TCGv_i32 nzcv
= tcg_temp_new_i32();
1705 /* take NZCV from R[t] */
1706 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1709 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1711 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1712 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1714 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1715 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1717 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1718 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1719 tcg_temp_free_i32(nzcv
);
1722 /* MRS - move from system register
1723 * MSR (register) - move to system register
1726 * These are all essentially the same insn in 'read' and 'write'
1727 * versions, with varying op0 fields.
1729 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1730 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1731 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1733 const ARMCPRegInfo
*ri
;
1736 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1737 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1738 crn
, crm
, op0
, op1
, op2
));
1741 /* Unknown register; this might be a guest error or a QEMU
1742 * unimplemented feature.
1744 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1745 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1746 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1747 unallocated_encoding(s
);
1751 /* Check access permissions */
1752 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1753 unallocated_encoding(s
);
1758 /* Emit code to perform further access permissions checks at
1759 * runtime; this may result in an exception.
1762 TCGv_i32 tcg_syn
, tcg_isread
;
1765 gen_a64_set_pc_im(s
->pc
- 4);
1766 tmpptr
= tcg_const_ptr(ri
);
1767 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1768 tcg_syn
= tcg_const_i32(syndrome
);
1769 tcg_isread
= tcg_const_i32(isread
);
1770 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
, tcg_isread
);
1771 tcg_temp_free_ptr(tmpptr
);
1772 tcg_temp_free_i32(tcg_syn
);
1773 tcg_temp_free_i32(tcg_isread
);
1776 /* Handle special cases first */
1777 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1781 tcg_rt
= cpu_reg(s
, rt
);
1783 gen_get_nzcv(tcg_rt
);
1785 gen_set_nzcv(tcg_rt
);
1788 case ARM_CP_CURRENTEL
:
1789 /* Reads as current EL value from pstate, which is
1790 * guaranteed to be constant by the tb flags.
1792 tcg_rt
= cpu_reg(s
, rt
);
1793 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1796 /* Writes clear the aligned block of memory which rt points into. */
1797 tcg_rt
= cpu_reg(s
, rt
);
1798 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1803 if ((ri
->type
& ARM_CP_FPU
) && !fp_access_check(s
)) {
1805 } else if ((ri
->type
& ARM_CP_SVE
) && !sve_access_check(s
)) {
1809 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1813 tcg_rt
= cpu_reg(s
, rt
);
1816 if (ri
->type
& ARM_CP_CONST
) {
1817 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1818 } else if (ri
->readfn
) {
1820 tmpptr
= tcg_const_ptr(ri
);
1821 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1822 tcg_temp_free_ptr(tmpptr
);
1824 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1827 if (ri
->type
& ARM_CP_CONST
) {
1828 /* If not forbidden by access permissions, treat as WI */
1830 } else if (ri
->writefn
) {
1832 tmpptr
= tcg_const_ptr(ri
);
1833 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1834 tcg_temp_free_ptr(tmpptr
);
1836 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1840 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1841 /* I/O operations must end the TB here (whether read or write) */
1843 s
->base
.is_jmp
= DISAS_UPDATE
;
1844 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1845 /* We default to ending the TB on a coprocessor register write,
1846 * but allow this to be suppressed by the register definition
1847 * (usually only necessary to work around guest bugs).
1849 s
->base
.is_jmp
= DISAS_UPDATE
;
1854 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1855 * +---------------------+---+-----+-----+-------+-------+-----+------+
1856 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1857 * +---------------------+---+-----+-----+-------+-------+-----+------+
1859 static void disas_system(DisasContext
*s
, uint32_t insn
)
1861 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1862 l
= extract32(insn
, 21, 1);
1863 op0
= extract32(insn
, 19, 2);
1864 op1
= extract32(insn
, 16, 3);
1865 crn
= extract32(insn
, 12, 4);
1866 crm
= extract32(insn
, 8, 4);
1867 op2
= extract32(insn
, 5, 3);
1868 rt
= extract32(insn
, 0, 5);
1871 if (l
|| rt
!= 31) {
1872 unallocated_encoding(s
);
1876 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
1877 handle_hint(s
, insn
, op1
, op2
, crm
);
1879 case 3: /* CLREX, DSB, DMB, ISB */
1880 handle_sync(s
, insn
, op1
, op2
, crm
);
1882 case 4: /* MSR (immediate) */
1883 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1886 unallocated_encoding(s
);
1891 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1894 /* Exception generation
1896 * 31 24 23 21 20 5 4 2 1 0
1897 * +-----------------+-----+------------------------+-----+----+
1898 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1899 * +-----------------------+------------------------+----------+
1901 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1903 int opc
= extract32(insn
, 21, 3);
1904 int op2_ll
= extract32(insn
, 0, 5);
1905 int imm16
= extract32(insn
, 5, 16);
1910 /* For SVC, HVC and SMC we advance the single-step state
1911 * machine before taking the exception. This is architecturally
1912 * mandated, to ensure that single-stepping a system call
1913 * instruction works properly.
1918 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
),
1919 default_exception_el(s
));
1922 if (s
->current_el
== 0) {
1923 unallocated_encoding(s
);
1926 /* The pre HVC helper handles cases when HVC gets trapped
1927 * as an undefined insn by runtime configuration.
1929 gen_a64_set_pc_im(s
->pc
- 4);
1930 gen_helper_pre_hvc(cpu_env
);
1932 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
), 2);
1935 if (s
->current_el
== 0) {
1936 unallocated_encoding(s
);
1939 gen_a64_set_pc_im(s
->pc
- 4);
1940 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1941 gen_helper_pre_smc(cpu_env
, tmp
);
1942 tcg_temp_free_i32(tmp
);
1944 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
), 3);
1947 unallocated_encoding(s
);
1953 unallocated_encoding(s
);
1957 gen_exception_bkpt_insn(s
, 4, syn_aa64_bkpt(imm16
));
1961 unallocated_encoding(s
);
1964 /* HLT. This has two purposes.
1965 * Architecturally, it is an external halting debug instruction.
1966 * Since QEMU doesn't implement external debug, we treat this as
1967 * it is required for halting debug disabled: it will UNDEF.
1968 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1970 if (semihosting_enabled() && imm16
== 0xf000) {
1971 #ifndef CONFIG_USER_ONLY
1972 /* In system mode, don't allow userspace access to semihosting,
1973 * to provide some semblance of security (and for consistency
1974 * with our 32-bit semihosting).
1976 if (s
->current_el
== 0) {
1977 unsupported_encoding(s
, insn
);
1981 gen_exception_internal_insn(s
, 0, EXCP_SEMIHOST
);
1983 unsupported_encoding(s
, insn
);
1987 if (op2_ll
< 1 || op2_ll
> 3) {
1988 unallocated_encoding(s
);
1991 /* DCPS1, DCPS2, DCPS3 */
1992 unsupported_encoding(s
, insn
);
1995 unallocated_encoding(s
);
2000 /* Unconditional branch (register)
2001 * 31 25 24 21 20 16 15 10 9 5 4 0
2002 * +---------------+-------+-------+-------+------+-------+
2003 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
2004 * +---------------+-------+-------+-------+------+-------+
2006 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
2008 unsigned int opc
, op2
, op3
, rn
, op4
;
2009 unsigned btype_mod
= 2; /* 0: BR, 1: BLR, 2: other */
2013 opc
= extract32(insn
, 21, 4);
2014 op2
= extract32(insn
, 16, 5);
2015 op3
= extract32(insn
, 10, 6);
2016 rn
= extract32(insn
, 5, 5);
2017 op4
= extract32(insn
, 0, 5);
2020 goto do_unallocated
;
2032 goto do_unallocated
;
2034 dst
= cpu_reg(s
, rn
);
2039 if (!dc_isar_feature(aa64_pauth
, s
)) {
2040 goto do_unallocated
;
2044 if (rn
!= 0x1f || op4
!= 0x1f) {
2045 goto do_unallocated
;
2048 modifier
= cpu_X
[31];
2050 /* BRAAZ, BRABZ, BLRAAZ, BLRABZ */
2052 goto do_unallocated
;
2054 modifier
= new_tmp_a64_zero(s
);
2056 if (s
->pauth_active
) {
2057 dst
= new_tmp_a64(s
);
2059 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2061 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2064 dst
= cpu_reg(s
, rn
);
2069 goto do_unallocated
;
2071 gen_a64_set_pc(s
, dst
);
2072 /* BLR also needs to load return address */
2074 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
2080 if (!dc_isar_feature(aa64_pauth
, s
)) {
2081 goto do_unallocated
;
2083 if ((op3
& ~1) != 2) {
2084 goto do_unallocated
;
2086 btype_mod
= opc
& 1;
2087 if (s
->pauth_active
) {
2088 dst
= new_tmp_a64(s
);
2089 modifier
= cpu_reg_sp(s
, op4
);
2091 gen_helper_autia(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2093 gen_helper_autib(dst
, cpu_env
, cpu_reg(s
, rn
), modifier
);
2096 dst
= cpu_reg(s
, rn
);
2098 gen_a64_set_pc(s
, dst
);
2099 /* BLRAA also needs to load return address */
2101 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
2106 if (s
->current_el
== 0) {
2107 goto do_unallocated
;
2112 goto do_unallocated
;
2114 dst
= tcg_temp_new_i64();
2115 tcg_gen_ld_i64(dst
, cpu_env
,
2116 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2119 case 2: /* ERETAA */
2120 case 3: /* ERETAB */
2121 if (!dc_isar_feature(aa64_pauth
, s
)) {
2122 goto do_unallocated
;
2124 if (rn
!= 0x1f || op4
!= 0x1f) {
2125 goto do_unallocated
;
2127 dst
= tcg_temp_new_i64();
2128 tcg_gen_ld_i64(dst
, cpu_env
,
2129 offsetof(CPUARMState
, elr_el
[s
->current_el
]));
2130 if (s
->pauth_active
) {
2131 modifier
= cpu_X
[31];
2133 gen_helper_autia(dst
, cpu_env
, dst
, modifier
);
2135 gen_helper_autib(dst
, cpu_env
, dst
, modifier
);
2141 goto do_unallocated
;
2143 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
2147 gen_helper_exception_return(cpu_env
, dst
);
2148 tcg_temp_free_i64(dst
);
2149 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
2152 /* Must exit loop to check un-masked IRQs */
2153 s
->base
.is_jmp
= DISAS_EXIT
;
2157 if (op3
!= 0 || op4
!= 0 || rn
!= 0x1f) {
2158 goto do_unallocated
;
2160 unsupported_encoding(s
, insn
);
2166 unallocated_encoding(s
);
2170 switch (btype_mod
) {
2172 if (dc_isar_feature(aa64_bti
, s
)) {
2173 /* BR to {x16,x17} or !guard -> 1, else 3. */
2174 set_btype(s
, rn
== 16 || rn
== 17 || !s
->guarded_page
? 1 : 3);
2179 if (dc_isar_feature(aa64_bti
, s
)) {
2180 /* BLR sets BTYPE to 2, regardless of source guarded page. */
2185 default: /* RET or none of the above. */
2186 /* BTYPE will be set to 0 by normal end-of-insn processing. */
2190 s
->base
.is_jmp
= DISAS_JUMP
;
2193 /* Branches, exception generating and system instructions */
2194 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
2196 switch (extract32(insn
, 25, 7)) {
2197 case 0x0a: case 0x0b:
2198 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
2199 disas_uncond_b_imm(s
, insn
);
2201 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
2202 disas_comp_b_imm(s
, insn
);
2204 case 0x1b: case 0x5b: /* Test & branch (immediate) */
2205 disas_test_b_imm(s
, insn
);
2207 case 0x2a: /* Conditional branch (immediate) */
2208 disas_cond_b_imm(s
, insn
);
2210 case 0x6a: /* Exception generation / System */
2211 if (insn
& (1 << 24)) {
2212 if (extract32(insn
, 22, 2) == 0) {
2213 disas_system(s
, insn
);
2215 unallocated_encoding(s
);
2221 case 0x6b: /* Unconditional branch (register) */
2222 disas_uncond_b_reg(s
, insn
);
2225 unallocated_encoding(s
);
2231 * Load/Store exclusive instructions are implemented by remembering
2232 * the value/address loaded, and seeing if these are the same
2233 * when the store is performed. This is not actually the architecturally
2234 * mandated semantics, but it works for typical guest code sequences
2235 * and avoids having to monitor regular stores.
2237 * The store exclusive uses the atomic cmpxchg primitives to avoid
2238 * races in multi-threaded linux-user and when MTTCG softmmu is
2241 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
2242 TCGv_i64 addr
, int size
, bool is_pair
)
2244 int idx
= get_mem_index(s
);
2245 TCGMemOp memop
= s
->be_data
;
2247 g_assert(size
<= 3);
2249 g_assert(size
>= 2);
2251 /* The pair must be single-copy atomic for the doubleword. */
2252 memop
|= MO_64
| MO_ALIGN
;
2253 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2254 if (s
->be_data
== MO_LE
) {
2255 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 0, 32);
2256 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 32, 32);
2258 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 32, 32);
2259 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 0, 32);
2262 /* The pair must be single-copy atomic for *each* doubleword, not
2263 the entire quadword, however it must be quadword aligned. */
2265 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
,
2266 memop
| MO_ALIGN_16
);
2268 TCGv_i64 addr2
= tcg_temp_new_i64();
2269 tcg_gen_addi_i64(addr2
, addr
, 8);
2270 tcg_gen_qemu_ld_i64(cpu_exclusive_high
, addr2
, idx
, memop
);
2271 tcg_temp_free_i64(addr2
);
2273 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2274 tcg_gen_mov_i64(cpu_reg(s
, rt2
), cpu_exclusive_high
);
2277 memop
|= size
| MO_ALIGN
;
2278 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2279 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2281 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
2284 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
2285 TCGv_i64 addr
, int size
, int is_pair
)
2287 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
2288 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
2291 * [addr + datasize] = {Rt2};
2297 * env->exclusive_addr = -1;
2299 TCGLabel
*fail_label
= gen_new_label();
2300 TCGLabel
*done_label
= gen_new_label();
2303 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
2305 tmp
= tcg_temp_new_i64();
2308 if (s
->be_data
== MO_LE
) {
2309 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2311 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt2
), cpu_reg(s
, rt
));
2313 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
,
2314 cpu_exclusive_val
, tmp
,
2316 MO_64
| MO_ALIGN
| s
->be_data
);
2317 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2318 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2319 if (!HAVE_CMPXCHG128
) {
2320 gen_helper_exit_atomic(cpu_env
);
2321 s
->base
.is_jmp
= DISAS_NORETURN
;
2322 } else if (s
->be_data
== MO_LE
) {
2323 gen_helper_paired_cmpxchg64_le_parallel(tmp
, cpu_env
,
2328 gen_helper_paired_cmpxchg64_be_parallel(tmp
, cpu_env
,
2333 } else if (s
->be_data
== MO_LE
) {
2334 gen_helper_paired_cmpxchg64_le(tmp
, cpu_env
, cpu_exclusive_addr
,
2335 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2337 gen_helper_paired_cmpxchg64_be(tmp
, cpu_env
, cpu_exclusive_addr
,
2338 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2341 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
, cpu_exclusive_val
,
2342 cpu_reg(s
, rt
), get_mem_index(s
),
2343 size
| MO_ALIGN
| s
->be_data
);
2344 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2346 tcg_gen_mov_i64(cpu_reg(s
, rd
), tmp
);
2347 tcg_temp_free_i64(tmp
);
2348 tcg_gen_br(done_label
);
2350 gen_set_label(fail_label
);
2351 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
2352 gen_set_label(done_label
);
2353 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
2356 static void gen_compare_and_swap(DisasContext
*s
, int rs
, int rt
,
2359 TCGv_i64 tcg_rs
= cpu_reg(s
, rs
);
2360 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2361 int memidx
= get_mem_index(s
);
2362 TCGv_i64 clean_addr
;
2365 gen_check_sp_alignment(s
);
2367 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2368 tcg_gen_atomic_cmpxchg_i64(tcg_rs
, clean_addr
, tcg_rs
, tcg_rt
, memidx
,
2369 size
| MO_ALIGN
| s
->be_data
);
2372 static void gen_compare_and_swap_pair(DisasContext
*s
, int rs
, int rt
,
2375 TCGv_i64 s1
= cpu_reg(s
, rs
);
2376 TCGv_i64 s2
= cpu_reg(s
, rs
+ 1);
2377 TCGv_i64 t1
= cpu_reg(s
, rt
);
2378 TCGv_i64 t2
= cpu_reg(s
, rt
+ 1);
2379 TCGv_i64 clean_addr
;
2380 int memidx
= get_mem_index(s
);
2383 gen_check_sp_alignment(s
);
2385 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2388 TCGv_i64 cmp
= tcg_temp_new_i64();
2389 TCGv_i64 val
= tcg_temp_new_i64();
2391 if (s
->be_data
== MO_LE
) {
2392 tcg_gen_concat32_i64(val
, t1
, t2
);
2393 tcg_gen_concat32_i64(cmp
, s1
, s2
);
2395 tcg_gen_concat32_i64(val
, t2
, t1
);
2396 tcg_gen_concat32_i64(cmp
, s2
, s1
);
2399 tcg_gen_atomic_cmpxchg_i64(cmp
, clean_addr
, cmp
, val
, memidx
,
2400 MO_64
| MO_ALIGN
| s
->be_data
);
2401 tcg_temp_free_i64(val
);
2403 if (s
->be_data
== MO_LE
) {
2404 tcg_gen_extr32_i64(s1
, s2
, cmp
);
2406 tcg_gen_extr32_i64(s2
, s1
, cmp
);
2408 tcg_temp_free_i64(cmp
);
2409 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2410 if (HAVE_CMPXCHG128
) {
2411 TCGv_i32 tcg_rs
= tcg_const_i32(rs
);
2412 if (s
->be_data
== MO_LE
) {
2413 gen_helper_casp_le_parallel(cpu_env
, tcg_rs
,
2414 clean_addr
, t1
, t2
);
2416 gen_helper_casp_be_parallel(cpu_env
, tcg_rs
,
2417 clean_addr
, t1
, t2
);
2419 tcg_temp_free_i32(tcg_rs
);
2421 gen_helper_exit_atomic(cpu_env
);
2422 s
->base
.is_jmp
= DISAS_NORETURN
;
2425 TCGv_i64 d1
= tcg_temp_new_i64();
2426 TCGv_i64 d2
= tcg_temp_new_i64();
2427 TCGv_i64 a2
= tcg_temp_new_i64();
2428 TCGv_i64 c1
= tcg_temp_new_i64();
2429 TCGv_i64 c2
= tcg_temp_new_i64();
2430 TCGv_i64 zero
= tcg_const_i64(0);
2432 /* Load the two words, in memory order. */
2433 tcg_gen_qemu_ld_i64(d1
, clean_addr
, memidx
,
2434 MO_64
| MO_ALIGN_16
| s
->be_data
);
2435 tcg_gen_addi_i64(a2
, clean_addr
, 8);
2436 tcg_gen_qemu_ld_i64(d2
, clean_addr
, memidx
, MO_64
| s
->be_data
);
2438 /* Compare the two words, also in memory order. */
2439 tcg_gen_setcond_i64(TCG_COND_EQ
, c1
, d1
, s1
);
2440 tcg_gen_setcond_i64(TCG_COND_EQ
, c2
, d2
, s2
);
2441 tcg_gen_and_i64(c2
, c2
, c1
);
2443 /* If compare equal, write back new data, else write back old data. */
2444 tcg_gen_movcond_i64(TCG_COND_NE
, c1
, c2
, zero
, t1
, d1
);
2445 tcg_gen_movcond_i64(TCG_COND_NE
, c2
, c2
, zero
, t2
, d2
);
2446 tcg_gen_qemu_st_i64(c1
, clean_addr
, memidx
, MO_64
| s
->be_data
);
2447 tcg_gen_qemu_st_i64(c2
, a2
, memidx
, MO_64
| s
->be_data
);
2448 tcg_temp_free_i64(a2
);
2449 tcg_temp_free_i64(c1
);
2450 tcg_temp_free_i64(c2
);
2451 tcg_temp_free_i64(zero
);
2453 /* Write back the data from memory to Rs. */
2454 tcg_gen_mov_i64(s1
, d1
);
2455 tcg_gen_mov_i64(s2
, d2
);
2456 tcg_temp_free_i64(d1
);
2457 tcg_temp_free_i64(d2
);
2461 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2462 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2464 static bool disas_ldst_compute_iss_sf(int size
, bool is_signed
, int opc
)
2466 int opc0
= extract32(opc
, 0, 1);
2470 regsize
= opc0
? 32 : 64;
2472 regsize
= size
== 3 ? 64 : 32;
2474 return regsize
== 64;
2477 /* Load/store exclusive
2479 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2480 * +-----+-------------+----+---+----+------+----+-------+------+------+
2481 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2482 * +-----+-------------+----+---+----+------+----+-------+------+------+
2484 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2485 * L: 0 -> store, 1 -> load
2486 * o2: 0 -> exclusive, 1 -> not
2487 * o1: 0 -> single register, 1 -> register pair
2488 * o0: 1 -> load-acquire/store-release, 0 -> not
2490 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
2492 int rt
= extract32(insn
, 0, 5);
2493 int rn
= extract32(insn
, 5, 5);
2494 int rt2
= extract32(insn
, 10, 5);
2495 int rs
= extract32(insn
, 16, 5);
2496 int is_lasr
= extract32(insn
, 15, 1);
2497 int o2_L_o1_o0
= extract32(insn
, 21, 3) * 2 | is_lasr
;
2498 int size
= extract32(insn
, 30, 2);
2499 TCGv_i64 clean_addr
;
2501 switch (o2_L_o1_o0
) {
2502 case 0x0: /* STXR */
2503 case 0x1: /* STLXR */
2505 gen_check_sp_alignment(s
);
2508 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2510 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2511 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, false);
2514 case 0x4: /* LDXR */
2515 case 0x5: /* LDAXR */
2517 gen_check_sp_alignment(s
);
2519 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2521 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, false);
2523 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2527 case 0x8: /* STLLR */
2528 if (!dc_isar_feature(aa64_lor
, s
)) {
2531 /* StoreLORelease is the same as Store-Release for QEMU. */
2533 case 0x9: /* STLR */
2534 /* Generate ISS for non-exclusive accesses including LASR. */
2536 gen_check_sp_alignment(s
);
2538 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2539 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2540 do_gpr_st(s
, cpu_reg(s
, rt
), clean_addr
, size
, true, rt
,
2541 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2544 case 0xc: /* LDLAR */
2545 if (!dc_isar_feature(aa64_lor
, s
)) {
2548 /* LoadLOAcquire is the same as Load-Acquire for QEMU. */
2550 case 0xd: /* LDAR */
2551 /* Generate ISS for non-exclusive accesses including LASR. */
2553 gen_check_sp_alignment(s
);
2555 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2556 do_gpr_ld(s
, cpu_reg(s
, rt
), clean_addr
, size
, false, false, true, rt
,
2557 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2558 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2561 case 0x2: case 0x3: /* CASP / STXP */
2562 if (size
& 2) { /* STXP / STLXP */
2564 gen_check_sp_alignment(s
);
2567 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2569 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2570 gen_store_exclusive(s
, rs
, rt
, rt2
, clean_addr
, size
, true);
2574 && ((rt
| rs
) & 1) == 0
2575 && dc_isar_feature(aa64_atomics
, s
)) {
2577 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2582 case 0x6: case 0x7: /* CASPA / LDXP */
2583 if (size
& 2) { /* LDXP / LDAXP */
2585 gen_check_sp_alignment(s
);
2587 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
2589 gen_load_exclusive(s
, rt
, rt2
, clean_addr
, size
, true);
2591 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2596 && ((rt
| rs
) & 1) == 0
2597 && dc_isar_feature(aa64_atomics
, s
)) {
2598 /* CASPA / CASPAL */
2599 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2605 case 0xb: /* CASL */
2606 case 0xe: /* CASA */
2607 case 0xf: /* CASAL */
2608 if (rt2
== 31 && dc_isar_feature(aa64_atomics
, s
)) {
2609 gen_compare_and_swap(s
, rs
, rt
, rn
, size
);
2614 unallocated_encoding(s
);
2618 * Load register (literal)
2620 * 31 30 29 27 26 25 24 23 5 4 0
2621 * +-----+-------+---+-----+-------------------+-------+
2622 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2623 * +-----+-------+---+-----+-------------------+-------+
2625 * V: 1 -> vector (simd/fp)
2626 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2627 * 10-> 32 bit signed, 11 -> prefetch
2628 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2630 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
2632 int rt
= extract32(insn
, 0, 5);
2633 int64_t imm
= sextract32(insn
, 5, 19) << 2;
2634 bool is_vector
= extract32(insn
, 26, 1);
2635 int opc
= extract32(insn
, 30, 2);
2636 bool is_signed
= false;
2638 TCGv_i64 tcg_rt
, clean_addr
;
2642 unallocated_encoding(s
);
2646 if (!fp_access_check(s
)) {
2651 /* PRFM (literal) : prefetch */
2654 size
= 2 + extract32(opc
, 0, 1);
2655 is_signed
= extract32(opc
, 1, 1);
2658 tcg_rt
= cpu_reg(s
, rt
);
2660 clean_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
2662 do_fp_ld(s
, rt
, clean_addr
, size
);
2664 /* Only unsigned 32bit loads target 32bit registers. */
2665 bool iss_sf
= opc
!= 0;
2667 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, is_signed
, false,
2668 true, rt
, iss_sf
, false);
2670 tcg_temp_free_i64(clean_addr
);
2674 * LDNP (Load Pair - non-temporal hint)
2675 * LDP (Load Pair - non vector)
2676 * LDPSW (Load Pair Signed Word - non vector)
2677 * STNP (Store Pair - non-temporal hint)
2678 * STP (Store Pair - non vector)
2679 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2680 * LDP (Load Pair of SIMD&FP)
2681 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2682 * STP (Store Pair of SIMD&FP)
2684 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2685 * +-----+-------+---+---+-------+---+-----------------------------+
2686 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2687 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2689 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2691 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2692 * V: 0 -> GPR, 1 -> Vector
2693 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2694 * 10 -> signed offset, 11 -> pre-index
2695 * L: 0 -> Store 1 -> Load
2697 * Rt, Rt2 = GPR or SIMD registers to be stored
2698 * Rn = general purpose register containing address
2699 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2701 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
2703 int rt
= extract32(insn
, 0, 5);
2704 int rn
= extract32(insn
, 5, 5);
2705 int rt2
= extract32(insn
, 10, 5);
2706 uint64_t offset
= sextract64(insn
, 15, 7);
2707 int index
= extract32(insn
, 23, 2);
2708 bool is_vector
= extract32(insn
, 26, 1);
2709 bool is_load
= extract32(insn
, 22, 1);
2710 int opc
= extract32(insn
, 30, 2);
2712 bool is_signed
= false;
2713 bool postindex
= false;
2716 TCGv_i64 clean_addr
, dirty_addr
;
2721 unallocated_encoding(s
);
2728 size
= 2 + extract32(opc
, 1, 1);
2729 is_signed
= extract32(opc
, 0, 1);
2730 if (!is_load
&& is_signed
) {
2731 unallocated_encoding(s
);
2737 case 1: /* post-index */
2742 /* signed offset with "non-temporal" hint. Since we don't emulate
2743 * caches we don't care about hints to the cache system about
2744 * data access patterns, and handle this identically to plain
2748 /* There is no non-temporal-hint version of LDPSW */
2749 unallocated_encoding(s
);
2754 case 2: /* signed offset, rn not updated */
2757 case 3: /* pre-index */
2763 if (is_vector
&& !fp_access_check(s
)) {
2770 gen_check_sp_alignment(s
);
2773 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
2775 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
2777 clean_addr
= clean_data_tbi(s
, dirty_addr
);
2781 do_fp_ld(s
, rt
, clean_addr
, size
);
2783 do_fp_st(s
, rt
, clean_addr
, size
);
2785 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2787 do_fp_ld(s
, rt2
, clean_addr
, size
);
2789 do_fp_st(s
, rt2
, clean_addr
, size
);
2792 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2793 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2796 TCGv_i64 tmp
= tcg_temp_new_i64();
2798 /* Do not modify tcg_rt before recognizing any exception
2799 * from the second load.
2801 do_gpr_ld(s
, tmp
, clean_addr
, size
, is_signed
, false,
2802 false, 0, false, false);
2803 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2804 do_gpr_ld(s
, tcg_rt2
, clean_addr
, size
, is_signed
, false,
2805 false, 0, false, false);
2807 tcg_gen_mov_i64(tcg_rt
, tmp
);
2808 tcg_temp_free_i64(tmp
);
2810 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
2811 false, 0, false, false);
2812 tcg_gen_addi_i64(clean_addr
, clean_addr
, 1 << size
);
2813 do_gpr_st(s
, tcg_rt2
, clean_addr
, size
,
2814 false, 0, false, false);
2820 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
2822 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
2827 * Load/store (immediate post-indexed)
2828 * Load/store (immediate pre-indexed)
2829 * Load/store (unscaled immediate)
2831 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2832 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2833 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2834 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2836 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2838 * V = 0 -> non-vector
2839 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2840 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2842 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
2848 int rn
= extract32(insn
, 5, 5);
2849 int imm9
= sextract32(insn
, 12, 9);
2850 int idx
= extract32(insn
, 10, 2);
2851 bool is_signed
= false;
2852 bool is_store
= false;
2853 bool is_extended
= false;
2854 bool is_unpriv
= (idx
== 2);
2855 bool iss_valid
= !is_vector
;
2859 TCGv_i64 clean_addr
, dirty_addr
;
2862 size
|= (opc
& 2) << 1;
2863 if (size
> 4 || is_unpriv
) {
2864 unallocated_encoding(s
);
2867 is_store
= ((opc
& 1) == 0);
2868 if (!fp_access_check(s
)) {
2872 if (size
== 3 && opc
== 2) {
2873 /* PRFM - prefetch */
2875 unallocated_encoding(s
);
2880 if (opc
== 3 && size
> 1) {
2881 unallocated_encoding(s
);
2884 is_store
= (opc
== 0);
2885 is_signed
= extract32(opc
, 1, 1);
2886 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2904 g_assert_not_reached();
2908 gen_check_sp_alignment(s
);
2911 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
2913 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
2915 clean_addr
= clean_data_tbi(s
, dirty_addr
);
2919 do_fp_st(s
, rt
, clean_addr
, size
);
2921 do_fp_ld(s
, rt
, clean_addr
, size
);
2924 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2925 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2926 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2929 do_gpr_st_memidx(s
, tcg_rt
, clean_addr
, size
, memidx
,
2930 iss_valid
, rt
, iss_sf
, false);
2932 do_gpr_ld_memidx(s
, tcg_rt
, clean_addr
, size
,
2933 is_signed
, is_extended
, memidx
,
2934 iss_valid
, rt
, iss_sf
, false);
2939 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2941 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, imm9
);
2943 tcg_gen_mov_i64(tcg_rn
, dirty_addr
);
2948 * Load/store (register offset)
2950 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2951 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2952 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2953 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2956 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2957 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2959 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2960 * opc<0>: 0 -> store, 1 -> load
2961 * V: 1 -> vector/simd
2962 * opt: extend encoding (see DecodeRegExtend)
2963 * S: if S=1 then scale (essentially index by sizeof(size))
2964 * Rt: register to transfer into/out of
2965 * Rn: address register or SP for base
2966 * Rm: offset register or ZR for offset
2968 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
2974 int rn
= extract32(insn
, 5, 5);
2975 int shift
= extract32(insn
, 12, 1);
2976 int rm
= extract32(insn
, 16, 5);
2977 int opt
= extract32(insn
, 13, 3);
2978 bool is_signed
= false;
2979 bool is_store
= false;
2980 bool is_extended
= false;
2982 TCGv_i64 tcg_rm
, clean_addr
, dirty_addr
;
2984 if (extract32(opt
, 1, 1) == 0) {
2985 unallocated_encoding(s
);
2990 size
|= (opc
& 2) << 1;
2992 unallocated_encoding(s
);
2995 is_store
= !extract32(opc
, 0, 1);
2996 if (!fp_access_check(s
)) {
3000 if (size
== 3 && opc
== 2) {
3001 /* PRFM - prefetch */
3004 if (opc
== 3 && size
> 1) {
3005 unallocated_encoding(s
);
3008 is_store
= (opc
== 0);
3009 is_signed
= extract32(opc
, 1, 1);
3010 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3014 gen_check_sp_alignment(s
);
3016 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3018 tcg_rm
= read_cpu_reg(s
, rm
, 1);
3019 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
3021 tcg_gen_add_i64(dirty_addr
, dirty_addr
, tcg_rm
);
3022 clean_addr
= clean_data_tbi(s
, dirty_addr
);
3026 do_fp_st(s
, rt
, clean_addr
, size
);
3028 do_fp_ld(s
, rt
, clean_addr
, size
);
3031 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3032 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3034 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3035 true, rt
, iss_sf
, false);
3037 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
,
3038 is_signed
, is_extended
,
3039 true, rt
, iss_sf
, false);
3045 * Load/store (unsigned immediate)
3047 * 31 30 29 27 26 25 24 23 22 21 10 9 5
3048 * +----+-------+---+-----+-----+------------+-------+------+
3049 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
3050 * +----+-------+---+-----+-----+------------+-------+------+
3053 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
3054 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
3056 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
3057 * opc<0>: 0 -> store, 1 -> load
3058 * Rn: base address register (inc SP)
3059 * Rt: target register
3061 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
3067 int rn
= extract32(insn
, 5, 5);
3068 unsigned int imm12
= extract32(insn
, 10, 12);
3069 unsigned int offset
;
3071 TCGv_i64 clean_addr
, dirty_addr
;
3074 bool is_signed
= false;
3075 bool is_extended
= false;
3078 size
|= (opc
& 2) << 1;
3080 unallocated_encoding(s
);
3083 is_store
= !extract32(opc
, 0, 1);
3084 if (!fp_access_check(s
)) {
3088 if (size
== 3 && opc
== 2) {
3089 /* PRFM - prefetch */
3092 if (opc
== 3 && size
> 1) {
3093 unallocated_encoding(s
);
3096 is_store
= (opc
== 0);
3097 is_signed
= extract32(opc
, 1, 1);
3098 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
3102 gen_check_sp_alignment(s
);
3104 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3105 offset
= imm12
<< size
;
3106 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3107 clean_addr
= clean_data_tbi(s
, dirty_addr
);
3111 do_fp_st(s
, rt
, clean_addr
, size
);
3113 do_fp_ld(s
, rt
, clean_addr
, size
);
3116 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
3117 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
3119 do_gpr_st(s
, tcg_rt
, clean_addr
, size
,
3120 true, rt
, iss_sf
, false);
3122 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, is_signed
, is_extended
,
3123 true, rt
, iss_sf
, false);
3128 /* Atomic memory operations
3130 * 31 30 27 26 24 22 21 16 15 12 10 5 0
3131 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
3132 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
3133 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
3135 * Rt: the result register
3136 * Rn: base address or SP
3137 * Rs: the source register for the operation
3138 * V: vector flag (always 0 as of v8.3)
3142 static void disas_ldst_atomic(DisasContext
*s
, uint32_t insn
,
3143 int size
, int rt
, bool is_vector
)
3145 int rs
= extract32(insn
, 16, 5);
3146 int rn
= extract32(insn
, 5, 5);
3147 int o3_opc
= extract32(insn
, 12, 4);
3148 TCGv_i64 tcg_rs
, clean_addr
;
3149 AtomicThreeOpFn
*fn
;
3151 if (is_vector
|| !dc_isar_feature(aa64_atomics
, s
)) {
3152 unallocated_encoding(s
);
3156 case 000: /* LDADD */
3157 fn
= tcg_gen_atomic_fetch_add_i64
;
3159 case 001: /* LDCLR */
3160 fn
= tcg_gen_atomic_fetch_and_i64
;
3162 case 002: /* LDEOR */
3163 fn
= tcg_gen_atomic_fetch_xor_i64
;
3165 case 003: /* LDSET */
3166 fn
= tcg_gen_atomic_fetch_or_i64
;
3168 case 004: /* LDSMAX */
3169 fn
= tcg_gen_atomic_fetch_smax_i64
;
3171 case 005: /* LDSMIN */
3172 fn
= tcg_gen_atomic_fetch_smin_i64
;
3174 case 006: /* LDUMAX */
3175 fn
= tcg_gen_atomic_fetch_umax_i64
;
3177 case 007: /* LDUMIN */
3178 fn
= tcg_gen_atomic_fetch_umin_i64
;
3181 fn
= tcg_gen_atomic_xchg_i64
;
3184 unallocated_encoding(s
);
3189 gen_check_sp_alignment(s
);
3191 clean_addr
= clean_data_tbi(s
, cpu_reg_sp(s
, rn
));
3192 tcg_rs
= read_cpu_reg(s
, rs
, true);
3194 if (o3_opc
== 1) { /* LDCLR */
3195 tcg_gen_not_i64(tcg_rs
, tcg_rs
);
3198 /* The tcg atomic primitives are all full barriers. Therefore we
3199 * can ignore the Acquire and Release bits of this instruction.
3201 fn(cpu_reg(s
, rt
), clean_addr
, tcg_rs
, get_mem_index(s
),
3202 s
->be_data
| size
| MO_ALIGN
);
3206 * PAC memory operations
3208 * 31 30 27 26 24 22 21 12 11 10 5 0
3209 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3210 * | size | 1 1 1 | V | 0 0 | M S | 1 | imm9 | W | 1 | Rn | Rt |
3211 * +------+-------+---+-----+-----+---+--------+---+---+----+-----+
3213 * Rt: the result register
3214 * Rn: base address or SP
3215 * V: vector flag (always 0 as of v8.3)
3216 * M: clear for key DA, set for key DB
3217 * W: pre-indexing flag
3220 static void disas_ldst_pac(DisasContext
*s
, uint32_t insn
,
3221 int size
, int rt
, bool is_vector
)
3223 int rn
= extract32(insn
, 5, 5);
3224 bool is_wback
= extract32(insn
, 11, 1);
3225 bool use_key_a
= !extract32(insn
, 23, 1);
3227 TCGv_i64 clean_addr
, dirty_addr
, tcg_rt
;
3229 if (size
!= 3 || is_vector
|| !dc_isar_feature(aa64_pauth
, s
)) {
3230 unallocated_encoding(s
);
3235 gen_check_sp_alignment(s
);
3237 dirty_addr
= read_cpu_reg_sp(s
, rn
, 1);
3239 if (s
->pauth_active
) {
3241 gen_helper_autda(dirty_addr
, cpu_env
, dirty_addr
, cpu_X
[31]);
3243 gen_helper_autdb(dirty_addr
, cpu_env
, dirty_addr
, cpu_X
[31]);
3247 /* Form the 10-bit signed, scaled offset. */
3248 offset
= (extract32(insn
, 22, 1) << 9) | extract32(insn
, 12, 9);
3249 offset
= sextract32(offset
<< size
, 0, 10 + size
);
3250 tcg_gen_addi_i64(dirty_addr
, dirty_addr
, offset
);
3252 /* Note that "clean" and "dirty" here refer to TBI not PAC. */
3253 clean_addr
= clean_data_tbi(s
, dirty_addr
);
3255 tcg_rt
= cpu_reg(s
, rt
);
3256 do_gpr_ld(s
, tcg_rt
, clean_addr
, size
, /* is_signed */ false,
3257 /* extend */ false, /* iss_valid */ !is_wback
,
3258 /* iss_srt */ rt
, /* iss_sf */ true, /* iss_ar */ false);
3261 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), dirty_addr
);
3265 /* Load/store register (all forms) */
3266 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
3268 int rt
= extract32(insn
, 0, 5);
3269 int opc
= extract32(insn
, 22, 2);
3270 bool is_vector
= extract32(insn
, 26, 1);
3271 int size
= extract32(insn
, 30, 2);
3273 switch (extract32(insn
, 24, 2)) {
3275 if (extract32(insn
, 21, 1) == 0) {
3276 /* Load/store register (unscaled immediate)
3277 * Load/store immediate pre/post-indexed
3278 * Load/store register unprivileged
3280 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
3283 switch (extract32(insn
, 10, 2)) {
3285 disas_ldst_atomic(s
, insn
, size
, rt
, is_vector
);
3288 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
3291 disas_ldst_pac(s
, insn
, size
, rt
, is_vector
);
3296 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
3299 unallocated_encoding(s
);
3302 /* AdvSIMD load/store multiple structures
3304 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
3305 * +---+---+---------------+---+-------------+--------+------+------+------+
3306 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
3307 * +---+---+---------------+---+-------------+--------+------+------+------+
3309 * AdvSIMD load/store multiple structures (post-indexed)
3311 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
3312 * +---+---+---------------+---+---+---------+--------+------+------+------+
3313 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
3314 * +---+---+---------------+---+---+---------+--------+------+------+------+
3316 * Rt: first (or only) SIMD&FP register to be transferred
3317 * Rn: base address or SP
3318 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3320 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
3322 int rt
= extract32(insn
, 0, 5);
3323 int rn
= extract32(insn
, 5, 5);
3324 int rm
= extract32(insn
, 16, 5);
3325 int size
= extract32(insn
, 10, 2);
3326 int opcode
= extract32(insn
, 12, 4);
3327 bool is_store
= !extract32(insn
, 22, 1);
3328 bool is_postidx
= extract32(insn
, 23, 1);
3329 bool is_q
= extract32(insn
, 30, 1);
3330 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3331 TCGMemOp endian
= s
->be_data
;
3333 int ebytes
; /* bytes per element */
3334 int elements
; /* elements per vector */
3335 int rpt
; /* num iterations */
3336 int selem
; /* structure elements */
3339 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
3340 unallocated_encoding(s
);
3344 if (!is_postidx
&& rm
!= 0) {
3345 unallocated_encoding(s
);
3349 /* From the shared decode logic */
3380 unallocated_encoding(s
);
3384 if (size
== 3 && !is_q
&& selem
!= 1) {
3386 unallocated_encoding(s
);
3390 if (!fp_access_check(s
)) {
3395 gen_check_sp_alignment(s
);
3398 /* For our purposes, bytes are always little-endian. */
3403 /* Consecutive little-endian elements from a single register
3404 * can be promoted to a larger little-endian operation.
3406 if (selem
== 1 && endian
== MO_LE
) {
3410 elements
= (is_q
? 16 : 8) / ebytes
;
3412 tcg_rn
= cpu_reg_sp(s
, rn
);
3413 clean_addr
= clean_data_tbi(s
, tcg_rn
);
3414 tcg_ebytes
= tcg_const_i64(ebytes
);
3416 for (r
= 0; r
< rpt
; r
++) {
3418 for (e
= 0; e
< elements
; e
++) {
3420 for (xs
= 0; xs
< selem
; xs
++) {
3421 int tt
= (rt
+ r
+ xs
) % 32;
3423 do_vec_st(s
, tt
, e
, clean_addr
, size
, endian
);
3425 do_vec_ld(s
, tt
, e
, clean_addr
, size
, endian
);
3427 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
3431 tcg_temp_free_i64(tcg_ebytes
);
3434 /* For non-quad operations, setting a slice of the low
3435 * 64 bits of the register clears the high 64 bits (in
3436 * the ARM ARM pseudocode this is implicit in the fact
3437 * that 'rval' is a 64 bit wide variable).
3438 * For quad operations, we might still need to zero the
3441 for (r
= 0; r
< rpt
* selem
; r
++) {
3442 int tt
= (rt
+ r
) % 32;
3443 clear_vec_high(s
, is_q
, tt
);
3449 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, rpt
* elements
* selem
* ebytes
);
3451 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3456 /* AdvSIMD load/store single structure
3458 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3459 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3460 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3461 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3463 * AdvSIMD load/store single structure (post-indexed)
3465 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3466 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3467 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3468 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3470 * Rt: first (or only) SIMD&FP register to be transferred
3471 * Rn: base address or SP
3472 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3473 * index = encoded in Q:S:size dependent on size
3475 * lane_size = encoded in R, opc
3476 * transfer width = encoded in opc, S, size
3478 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
3480 int rt
= extract32(insn
, 0, 5);
3481 int rn
= extract32(insn
, 5, 5);
3482 int rm
= extract32(insn
, 16, 5);
3483 int size
= extract32(insn
, 10, 2);
3484 int S
= extract32(insn
, 12, 1);
3485 int opc
= extract32(insn
, 13, 3);
3486 int R
= extract32(insn
, 21, 1);
3487 int is_load
= extract32(insn
, 22, 1);
3488 int is_postidx
= extract32(insn
, 23, 1);
3489 int is_q
= extract32(insn
, 30, 1);
3491 int scale
= extract32(opc
, 1, 2);
3492 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
3493 bool replicate
= false;
3494 int index
= is_q
<< 3 | S
<< 2 | size
;
3496 TCGv_i64 clean_addr
, tcg_rn
, tcg_ebytes
;
3498 if (extract32(insn
, 31, 1)) {
3499 unallocated_encoding(s
);
3502 if (!is_postidx
&& rm
!= 0) {
3503 unallocated_encoding(s
);
3509 if (!is_load
|| S
) {
3510 unallocated_encoding(s
);
3519 if (extract32(size
, 0, 1)) {
3520 unallocated_encoding(s
);
3526 if (extract32(size
, 1, 1)) {
3527 unallocated_encoding(s
);
3530 if (!extract32(size
, 0, 1)) {
3534 unallocated_encoding(s
);
3542 g_assert_not_reached();
3545 if (!fp_access_check(s
)) {
3549 ebytes
= 1 << scale
;
3552 gen_check_sp_alignment(s
);
3555 tcg_rn
= cpu_reg_sp(s
, rn
);
3556 clean_addr
= clean_data_tbi(s
, tcg_rn
);
3557 tcg_ebytes
= tcg_const_i64(ebytes
);
3559 for (xs
= 0; xs
< selem
; xs
++) {
3561 /* Load and replicate to all elements */
3562 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3564 tcg_gen_qemu_ld_i64(tcg_tmp
, clean_addr
,
3565 get_mem_index(s
), s
->be_data
+ scale
);
3566 tcg_gen_gvec_dup_i64(scale
, vec_full_reg_offset(s
, rt
),
3567 (is_q
+ 1) * 8, vec_full_reg_size(s
),
3569 tcg_temp_free_i64(tcg_tmp
);
3571 /* Load/store one element per register */
3573 do_vec_ld(s
, rt
, index
, clean_addr
, scale
, s
->be_data
);
3575 do_vec_st(s
, rt
, index
, clean_addr
, scale
, s
->be_data
);
3578 tcg_gen_add_i64(clean_addr
, clean_addr
, tcg_ebytes
);
3581 tcg_temp_free_i64(tcg_ebytes
);
3585 tcg_gen_addi_i64(tcg_rn
, tcg_rn
, selem
* ebytes
);
3587 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3592 /* Loads and stores */
3593 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
3595 switch (extract32(insn
, 24, 6)) {
3596 case 0x08: /* Load/store exclusive */
3597 disas_ldst_excl(s
, insn
);
3599 case 0x18: case 0x1c: /* Load register (literal) */
3600 disas_ld_lit(s
, insn
);
3602 case 0x28: case 0x29:
3603 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
3604 disas_ldst_pair(s
, insn
);
3606 case 0x38: case 0x39:
3607 case 0x3c: case 0x3d: /* Load/store register (all forms) */
3608 disas_ldst_reg(s
, insn
);
3610 case 0x0c: /* AdvSIMD load/store multiple structures */
3611 disas_ldst_multiple_struct(s
, insn
);
3613 case 0x0d: /* AdvSIMD load/store single structure */
3614 disas_ldst_single_struct(s
, insn
);
3617 unallocated_encoding(s
);
3622 /* PC-rel. addressing
3623 * 31 30 29 28 24 23 5 4 0
3624 * +----+-------+-----------+-------------------+------+
3625 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
3626 * +----+-------+-----------+-------------------+------+
3628 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
3630 unsigned int page
, rd
;
3634 page
= extract32(insn
, 31, 1);
3635 /* SignExtend(immhi:immlo) -> offset */
3636 offset
= sextract64(insn
, 5, 19);
3637 offset
= offset
<< 2 | extract32(insn
, 29, 2);
3638 rd
= extract32(insn
, 0, 5);
3642 /* ADRP (page based) */
3647 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
3651 * Add/subtract (immediate)
3653 * 31 30 29 28 24 23 22 21 10 9 5 4 0
3654 * +--+--+--+-----------+-----+-------------+-----+-----+
3655 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
3656 * +--+--+--+-----------+-----+-------------+-----+-----+
3658 * sf: 0 -> 32bit, 1 -> 64bit
3659 * op: 0 -> add , 1 -> sub
3661 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
3663 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
3665 int rd
= extract32(insn
, 0, 5);
3666 int rn
= extract32(insn
, 5, 5);
3667 uint64_t imm
= extract32(insn
, 10, 12);
3668 int shift
= extract32(insn
, 22, 2);
3669 bool setflags
= extract32(insn
, 29, 1);
3670 bool sub_op
= extract32(insn
, 30, 1);
3671 bool is_64bit
= extract32(insn
, 31, 1);
3673 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
3674 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
3675 TCGv_i64 tcg_result
;
3684 unallocated_encoding(s
);
3688 tcg_result
= tcg_temp_new_i64();
3691 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
3693 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
3696 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
3698 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3700 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3702 tcg_temp_free_i64(tcg_imm
);
3706 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3708 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3711 tcg_temp_free_i64(tcg_result
);
3714 /* The input should be a value in the bottom e bits (with higher
3715 * bits zero); returns that value replicated into every element
3716 * of size e in a 64 bit integer.
3718 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
3728 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
3729 static inline uint64_t bitmask64(unsigned int length
)
3731 assert(length
> 0 && length
<= 64);
3732 return ~0ULL >> (64 - length
);
3735 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
3736 * only require the wmask. Returns false if the imms/immr/immn are a reserved
3737 * value (ie should cause a guest UNDEF exception), and true if they are
3738 * valid, in which case the decoded bit pattern is written to result.
3740 bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
3741 unsigned int imms
, unsigned int immr
)
3744 unsigned e
, levels
, s
, r
;
3747 assert(immn
< 2 && imms
< 64 && immr
< 64);
3749 /* The bit patterns we create here are 64 bit patterns which
3750 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
3751 * 64 bits each. Each element contains the same value: a run
3752 * of between 1 and e-1 non-zero bits, rotated within the
3753 * element by between 0 and e-1 bits.
3755 * The element size and run length are encoded into immn (1 bit)
3756 * and imms (6 bits) as follows:
3757 * 64 bit elements: immn = 1, imms = <length of run - 1>
3758 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
3759 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
3760 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
3761 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
3762 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
3763 * Notice that immn = 0, imms = 11111x is the only combination
3764 * not covered by one of the above options; this is reserved.
3765 * Further, <length of run - 1> all-ones is a reserved pattern.
3767 * In all cases the rotation is by immr % e (and immr is 6 bits).
3770 /* First determine the element size */
3771 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
3773 /* This is the immn == 0, imms == 0x11111x case */
3783 /* <length of run - 1> mustn't be all-ones. */
3787 /* Create the value of one element: s+1 set bits rotated
3788 * by r within the element (which is e bits wide)...
3790 mask
= bitmask64(s
+ 1);
3792 mask
= (mask
>> r
) | (mask
<< (e
- r
));
3793 mask
&= bitmask64(e
);
3795 /* ...then replicate the element over the whole 64 bit value */
3796 mask
= bitfield_replicate(mask
, e
);
3801 /* Logical (immediate)
3802 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3803 * +----+-----+-------------+---+------+------+------+------+
3804 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
3805 * +----+-----+-------------+---+------+------+------+------+
3807 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
3809 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
3810 TCGv_i64 tcg_rd
, tcg_rn
;
3812 bool is_and
= false;
3814 sf
= extract32(insn
, 31, 1);
3815 opc
= extract32(insn
, 29, 2);
3816 is_n
= extract32(insn
, 22, 1);
3817 immr
= extract32(insn
, 16, 6);
3818 imms
= extract32(insn
, 10, 6);
3819 rn
= extract32(insn
, 5, 5);
3820 rd
= extract32(insn
, 0, 5);
3823 unallocated_encoding(s
);
3827 if (opc
== 0x3) { /* ANDS */
3828 tcg_rd
= cpu_reg(s
, rd
);
3830 tcg_rd
= cpu_reg_sp(s
, rd
);
3832 tcg_rn
= cpu_reg(s
, rn
);
3834 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
3835 /* some immediate field values are reserved */
3836 unallocated_encoding(s
);
3841 wmask
&= 0xffffffff;
3845 case 0x3: /* ANDS */
3847 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
3851 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
3854 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
3857 assert(FALSE
); /* must handle all above */
3861 if (!sf
&& !is_and
) {
3862 /* zero extend final result; we know we can skip this for AND
3863 * since the immediate had the high 32 bits clear.
3865 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3868 if (opc
== 3) { /* ANDS */
3869 gen_logic_CC(sf
, tcg_rd
);
3874 * Move wide (immediate)
3876 * 31 30 29 28 23 22 21 20 5 4 0
3877 * +--+-----+-------------+-----+----------------+------+
3878 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
3879 * +--+-----+-------------+-----+----------------+------+
3881 * sf: 0 -> 32 bit, 1 -> 64 bit
3882 * opc: 00 -> N, 10 -> Z, 11 -> K
3883 * hw: shift/16 (0,16, and sf only 32, 48)
3885 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
3887 int rd
= extract32(insn
, 0, 5);
3888 uint64_t imm
= extract32(insn
, 5, 16);
3889 int sf
= extract32(insn
, 31, 1);
3890 int opc
= extract32(insn
, 29, 2);
3891 int pos
= extract32(insn
, 21, 2) << 4;
3892 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3895 if (!sf
&& (pos
>= 32)) {
3896 unallocated_encoding(s
);
3910 tcg_gen_movi_i64(tcg_rd
, imm
);
3913 tcg_imm
= tcg_const_i64(imm
);
3914 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
3915 tcg_temp_free_i64(tcg_imm
);
3917 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3921 unallocated_encoding(s
);
3927 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3928 * +----+-----+-------------+---+------+------+------+------+
3929 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3930 * +----+-----+-------------+---+------+------+------+------+
3932 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
3934 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
3935 TCGv_i64 tcg_rd
, tcg_tmp
;
3937 sf
= extract32(insn
, 31, 1);
3938 opc
= extract32(insn
, 29, 2);
3939 n
= extract32(insn
, 22, 1);
3940 ri
= extract32(insn
, 16, 6);
3941 si
= extract32(insn
, 10, 6);
3942 rn
= extract32(insn
, 5, 5);
3943 rd
= extract32(insn
, 0, 5);
3944 bitsize
= sf
? 64 : 32;
3946 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
3947 unallocated_encoding(s
);
3951 tcg_rd
= cpu_reg(s
, rd
);
3953 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3954 to be smaller than bitsize, we'll never reference data outside the
3955 low 32-bits anyway. */
3956 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
3958 /* Recognize simple(r) extractions. */
3960 /* Wd<s-r:0> = Wn<s:r> */
3961 len
= (si
- ri
) + 1;
3962 if (opc
== 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
3963 tcg_gen_sextract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3965 } else if (opc
== 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
3966 tcg_gen_extract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3969 /* opc == 1, BXFIL fall through to deposit */
3970 tcg_gen_extract_i64(tcg_tmp
, tcg_tmp
, ri
, len
);
3973 /* Handle the ri > si case with a deposit
3974 * Wd<32+s-r,32-r> = Wn<s:0>
3977 pos
= (bitsize
- ri
) & (bitsize
- 1);
3980 if (opc
== 0 && len
< ri
) {
3981 /* SBFM: sign extend the destination field from len to fill
3982 the balance of the word. Let the deposit below insert all
3983 of those sign bits. */
3984 tcg_gen_sextract_i64(tcg_tmp
, tcg_tmp
, 0, len
);
3988 if (opc
== 1) { /* BFM, BXFIL */
3989 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
3991 /* SBFM or UBFM: We start with zero, and we haven't modified
3992 any bits outside bitsize, therefore the zero-extension
3993 below is unneeded. */
3994 tcg_gen_deposit_z_i64(tcg_rd
, tcg_tmp
, pos
, len
);
3999 if (!sf
) { /* zero extend final result */
4000 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4005 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
4006 * +----+------+-------------+---+----+------+--------+------+------+
4007 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
4008 * +----+------+-------------+---+----+------+--------+------+------+
4010 static void disas_extract(DisasContext
*s
, uint32_t insn
)
4012 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
4014 sf
= extract32(insn
, 31, 1);
4015 n
= extract32(insn
, 22, 1);
4016 rm
= extract32(insn
, 16, 5);
4017 imm
= extract32(insn
, 10, 6);
4018 rn
= extract32(insn
, 5, 5);
4019 rd
= extract32(insn
, 0, 5);
4020 op21
= extract32(insn
, 29, 2);
4021 op0
= extract32(insn
, 21, 1);
4022 bitsize
= sf
? 64 : 32;
4024 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
4025 unallocated_encoding(s
);
4027 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
4029 tcg_rd
= cpu_reg(s
, rd
);
4031 if (unlikely(imm
== 0)) {
4032 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
4033 * so an extract from bit 0 is a special case.
4036 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
4038 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
4040 } else if (rm
== rn
) { /* ROR */
4041 tcg_rm
= cpu_reg(s
, rm
);
4043 tcg_gen_rotri_i64(tcg_rd
, tcg_rm
, imm
);
4045 TCGv_i32 tmp
= tcg_temp_new_i32();
4046 tcg_gen_extrl_i64_i32(tmp
, tcg_rm
);
4047 tcg_gen_rotri_i32(tmp
, tmp
, imm
);
4048 tcg_gen_extu_i32_i64(tcg_rd
, tmp
);
4049 tcg_temp_free_i32(tmp
);
4052 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4053 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4054 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
4055 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
4056 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
4058 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4064 /* Data processing - immediate */
4065 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
4067 switch (extract32(insn
, 23, 6)) {
4068 case 0x20: case 0x21: /* PC-rel. addressing */
4069 disas_pc_rel_adr(s
, insn
);
4071 case 0x22: case 0x23: /* Add/subtract (immediate) */
4072 disas_add_sub_imm(s
, insn
);
4074 case 0x24: /* Logical (immediate) */
4075 disas_logic_imm(s
, insn
);
4077 case 0x25: /* Move wide (immediate) */
4078 disas_movw_imm(s
, insn
);
4080 case 0x26: /* Bitfield */
4081 disas_bitfield(s
, insn
);
4083 case 0x27: /* Extract */
4084 disas_extract(s
, insn
);
4087 unallocated_encoding(s
);
4092 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
4093 * Note that it is the caller's responsibility to ensure that the
4094 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
4095 * mandated semantics for out of range shifts.
4097 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4098 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
4100 switch (shift_type
) {
4101 case A64_SHIFT_TYPE_LSL
:
4102 tcg_gen_shl_i64(dst
, src
, shift_amount
);
4104 case A64_SHIFT_TYPE_LSR
:
4105 tcg_gen_shr_i64(dst
, src
, shift_amount
);
4107 case A64_SHIFT_TYPE_ASR
:
4109 tcg_gen_ext32s_i64(dst
, src
);
4111 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
4113 case A64_SHIFT_TYPE_ROR
:
4115 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
4118 t0
= tcg_temp_new_i32();
4119 t1
= tcg_temp_new_i32();
4120 tcg_gen_extrl_i64_i32(t0
, src
);
4121 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
4122 tcg_gen_rotr_i32(t0
, t0
, t1
);
4123 tcg_gen_extu_i32_i64(dst
, t0
);
4124 tcg_temp_free_i32(t0
);
4125 tcg_temp_free_i32(t1
);
4129 assert(FALSE
); /* all shift types should be handled */
4133 if (!sf
) { /* zero extend final result */
4134 tcg_gen_ext32u_i64(dst
, dst
);
4138 /* Shift a TCGv src by immediate, put result in dst.
4139 * The shift amount must be in range (this should always be true as the
4140 * relevant instructions will UNDEF on bad shift immediates).
4142 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
4143 enum a64_shift_type shift_type
, unsigned int shift_i
)
4145 assert(shift_i
< (sf
? 64 : 32));
4148 tcg_gen_mov_i64(dst
, src
);
4150 TCGv_i64 shift_const
;
4152 shift_const
= tcg_const_i64(shift_i
);
4153 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
4154 tcg_temp_free_i64(shift_const
);
4158 /* Logical (shifted register)
4159 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4160 * +----+-----+-----------+-------+---+------+--------+------+------+
4161 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
4162 * +----+-----+-----------+-------+---+------+--------+------+------+
4164 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
4166 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
4167 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
4169 sf
= extract32(insn
, 31, 1);
4170 opc
= extract32(insn
, 29, 2);
4171 shift_type
= extract32(insn
, 22, 2);
4172 invert
= extract32(insn
, 21, 1);
4173 rm
= extract32(insn
, 16, 5);
4174 shift_amount
= extract32(insn
, 10, 6);
4175 rn
= extract32(insn
, 5, 5);
4176 rd
= extract32(insn
, 0, 5);
4178 if (!sf
&& (shift_amount
& (1 << 5))) {
4179 unallocated_encoding(s
);
4183 tcg_rd
= cpu_reg(s
, rd
);
4185 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
4186 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
4187 * register-register MOV and MVN, so it is worth special casing.
4189 tcg_rm
= cpu_reg(s
, rm
);
4191 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
4193 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4197 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
4199 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
4205 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4208 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
4211 tcg_rn
= cpu_reg(s
, rn
);
4213 switch (opc
| (invert
<< 2)) {
4216 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4219 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4222 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4226 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4229 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4232 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
4240 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4244 gen_logic_CC(sf
, tcg_rd
);
4249 * Add/subtract (extended register)
4251 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
4252 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4253 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
4254 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
4256 * sf: 0 -> 32bit, 1 -> 64bit
4257 * op: 0 -> add , 1 -> sub
4260 * option: extension type (see DecodeRegExtend)
4261 * imm3: optional shift to Rm
4263 * Rd = Rn + LSL(extend(Rm), amount)
4265 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
4267 int rd
= extract32(insn
, 0, 5);
4268 int rn
= extract32(insn
, 5, 5);
4269 int imm3
= extract32(insn
, 10, 3);
4270 int option
= extract32(insn
, 13, 3);
4271 int rm
= extract32(insn
, 16, 5);
4272 int opt
= extract32(insn
, 22, 2);
4273 bool setflags
= extract32(insn
, 29, 1);
4274 bool sub_op
= extract32(insn
, 30, 1);
4275 bool sf
= extract32(insn
, 31, 1);
4277 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
4279 TCGv_i64 tcg_result
;
4281 if (imm3
> 4 || opt
!= 0) {
4282 unallocated_encoding(s
);
4286 /* non-flag setting ops may use SP */
4288 tcg_rd
= cpu_reg_sp(s
, rd
);
4290 tcg_rd
= cpu_reg(s
, rd
);
4292 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
4294 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4295 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
4297 tcg_result
= tcg_temp_new_i64();
4301 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4303 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4307 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4309 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4314 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4316 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4319 tcg_temp_free_i64(tcg_result
);
4323 * Add/subtract (shifted register)
4325 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4326 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4327 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
4328 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4330 * sf: 0 -> 32bit, 1 -> 64bit
4331 * op: 0 -> add , 1 -> sub
4333 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
4334 * imm6: Shift amount to apply to Rm before the add/sub
4336 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
4338 int rd
= extract32(insn
, 0, 5);
4339 int rn
= extract32(insn
, 5, 5);
4340 int imm6
= extract32(insn
, 10, 6);
4341 int rm
= extract32(insn
, 16, 5);
4342 int shift_type
= extract32(insn
, 22, 2);
4343 bool setflags
= extract32(insn
, 29, 1);
4344 bool sub_op
= extract32(insn
, 30, 1);
4345 bool sf
= extract32(insn
, 31, 1);
4347 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4348 TCGv_i64 tcg_rn
, tcg_rm
;
4349 TCGv_i64 tcg_result
;
4351 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
4352 unallocated_encoding(s
);
4356 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4357 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4359 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
4361 tcg_result
= tcg_temp_new_i64();
4365 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4367 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4371 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4373 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4378 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4380 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4383 tcg_temp_free_i64(tcg_result
);
4386 /* Data-processing (3 source)
4388 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
4389 * +--+------+-----------+------+------+----+------+------+------+
4390 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
4391 * +--+------+-----------+------+------+----+------+------+------+
4393 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
4395 int rd
= extract32(insn
, 0, 5);
4396 int rn
= extract32(insn
, 5, 5);
4397 int ra
= extract32(insn
, 10, 5);
4398 int rm
= extract32(insn
, 16, 5);
4399 int op_id
= (extract32(insn
, 29, 3) << 4) |
4400 (extract32(insn
, 21, 3) << 1) |
4401 extract32(insn
, 15, 1);
4402 bool sf
= extract32(insn
, 31, 1);
4403 bool is_sub
= extract32(op_id
, 0, 1);
4404 bool is_high
= extract32(op_id
, 2, 1);
4405 bool is_signed
= false;
4410 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
4412 case 0x42: /* SMADDL */
4413 case 0x43: /* SMSUBL */
4414 case 0x44: /* SMULH */
4417 case 0x0: /* MADD (32bit) */
4418 case 0x1: /* MSUB (32bit) */
4419 case 0x40: /* MADD (64bit) */
4420 case 0x41: /* MSUB (64bit) */
4421 case 0x4a: /* UMADDL */
4422 case 0x4b: /* UMSUBL */
4423 case 0x4c: /* UMULH */
4426 unallocated_encoding(s
);
4431 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
4432 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4433 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4434 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
4437 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4439 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4442 tcg_temp_free_i64(low_bits
);
4446 tcg_op1
= tcg_temp_new_i64();
4447 tcg_op2
= tcg_temp_new_i64();
4448 tcg_tmp
= tcg_temp_new_i64();
4451 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
4452 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
4455 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
4456 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
4458 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
4459 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
4463 if (ra
== 31 && !is_sub
) {
4464 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
4465 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
4467 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
4469 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4471 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4476 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
4479 tcg_temp_free_i64(tcg_op1
);
4480 tcg_temp_free_i64(tcg_op2
);
4481 tcg_temp_free_i64(tcg_tmp
);
4484 /* Add/subtract (with carry)
4485 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
4486 * +--+--+--+------------------------+------+---------+------+-----+
4487 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
4488 * +--+--+--+------------------------+------+---------+------+-----+
4492 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
4494 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
4495 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
4497 if (extract32(insn
, 10, 6) != 0) {
4498 unallocated_encoding(s
);
4502 sf
= extract32(insn
, 31, 1);
4503 op
= extract32(insn
, 30, 1);
4504 setflags
= extract32(insn
, 29, 1);
4505 rm
= extract32(insn
, 16, 5);
4506 rn
= extract32(insn
, 5, 5);
4507 rd
= extract32(insn
, 0, 5);
4509 tcg_rd
= cpu_reg(s
, rd
);
4510 tcg_rn
= cpu_reg(s
, rn
);
4513 tcg_y
= new_tmp_a64(s
);
4514 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
4516 tcg_y
= cpu_reg(s
, rm
);
4520 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4522 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4526 /* Conditional compare (immediate / register)
4527 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4528 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4529 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
4530 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4533 static void disas_cc(DisasContext
*s
, uint32_t insn
)
4535 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
4536 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
4537 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
4540 if (!extract32(insn
, 29, 1)) {
4541 unallocated_encoding(s
);
4544 if (insn
& (1 << 10 | 1 << 4)) {
4545 unallocated_encoding(s
);
4548 sf
= extract32(insn
, 31, 1);
4549 op
= extract32(insn
, 30, 1);
4550 is_imm
= extract32(insn
, 11, 1);
4551 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
4552 cond
= extract32(insn
, 12, 4);
4553 rn
= extract32(insn
, 5, 5);
4554 nzcv
= extract32(insn
, 0, 4);
4556 /* Set T0 = !COND. */
4557 tcg_t0
= tcg_temp_new_i32();
4558 arm_test_cc(&c
, cond
);
4559 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
4562 /* Load the arguments for the new comparison. */
4564 tcg_y
= new_tmp_a64(s
);
4565 tcg_gen_movi_i64(tcg_y
, y
);
4567 tcg_y
= cpu_reg(s
, y
);
4569 tcg_rn
= cpu_reg(s
, rn
);
4571 /* Set the flags for the new comparison. */
4572 tcg_tmp
= tcg_temp_new_i64();
4574 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4576 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4578 tcg_temp_free_i64(tcg_tmp
);
4580 /* If COND was false, force the flags to #nzcv. Compute two masks
4581 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
4582 * For tcg hosts that support ANDC, we can make do with just T1.
4583 * In either case, allow the tcg optimizer to delete any unused mask.
4585 tcg_t1
= tcg_temp_new_i32();
4586 tcg_t2
= tcg_temp_new_i32();
4587 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
4588 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
4590 if (nzcv
& 8) { /* N */
4591 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4593 if (TCG_TARGET_HAS_andc_i32
) {
4594 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4596 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
4599 if (nzcv
& 4) { /* Z */
4600 if (TCG_TARGET_HAS_andc_i32
) {
4601 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
4603 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
4606 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
4608 if (nzcv
& 2) { /* C */
4609 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
4611 if (TCG_TARGET_HAS_andc_i32
) {
4612 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
4614 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
4617 if (nzcv
& 1) { /* V */
4618 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4620 if (TCG_TARGET_HAS_andc_i32
) {
4621 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4623 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
4626 tcg_temp_free_i32(tcg_t0
);
4627 tcg_temp_free_i32(tcg_t1
);
4628 tcg_temp_free_i32(tcg_t2
);
4631 /* Conditional select
4632 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
4633 * +----+----+---+-----------------+------+------+-----+------+------+
4634 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
4635 * +----+----+---+-----------------+------+------+-----+------+------+
4637 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
4639 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
4640 TCGv_i64 tcg_rd
, zero
;
4643 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
4644 /* S == 1 or op2<1> == 1 */
4645 unallocated_encoding(s
);
4648 sf
= extract32(insn
, 31, 1);
4649 else_inv
= extract32(insn
, 30, 1);
4650 rm
= extract32(insn
, 16, 5);
4651 cond
= extract32(insn
, 12, 4);
4652 else_inc
= extract32(insn
, 10, 1);
4653 rn
= extract32(insn
, 5, 5);
4654 rd
= extract32(insn
, 0, 5);
4656 tcg_rd
= cpu_reg(s
, rd
);
4658 a64_test_cc(&c
, cond
);
4659 zero
= tcg_const_i64(0);
4661 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
4663 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
4665 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
4668 TCGv_i64 t_true
= cpu_reg(s
, rn
);
4669 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
4670 if (else_inv
&& else_inc
) {
4671 tcg_gen_neg_i64(t_false
, t_false
);
4672 } else if (else_inv
) {
4673 tcg_gen_not_i64(t_false
, t_false
);
4674 } else if (else_inc
) {
4675 tcg_gen_addi_i64(t_false
, t_false
, 1);
4677 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
4680 tcg_temp_free_i64(zero
);
4684 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4688 static void handle_clz(DisasContext
*s
, unsigned int sf
,
4689 unsigned int rn
, unsigned int rd
)
4691 TCGv_i64 tcg_rd
, tcg_rn
;
4692 tcg_rd
= cpu_reg(s
, rd
);
4693 tcg_rn
= cpu_reg(s
, rn
);
4696 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
4698 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4699 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4700 tcg_gen_clzi_i32(tcg_tmp32
, tcg_tmp32
, 32);
4701 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4702 tcg_temp_free_i32(tcg_tmp32
);
4706 static void handle_cls(DisasContext
*s
, unsigned int sf
,
4707 unsigned int rn
, unsigned int rd
)
4709 TCGv_i64 tcg_rd
, tcg_rn
;
4710 tcg_rd
= cpu_reg(s
, rd
);
4711 tcg_rn
= cpu_reg(s
, rn
);
4714 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
4716 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4717 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4718 tcg_gen_clrsb_i32(tcg_tmp32
, tcg_tmp32
);
4719 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4720 tcg_temp_free_i32(tcg_tmp32
);
4724 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
4725 unsigned int rn
, unsigned int rd
)
4727 TCGv_i64 tcg_rd
, tcg_rn
;
4728 tcg_rd
= cpu_reg(s
, rd
);
4729 tcg_rn
= cpu_reg(s
, rn
);
4732 gen_helper_rbit64(tcg_rd
, tcg_rn
);
4734 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4735 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4736 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
4737 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4738 tcg_temp_free_i32(tcg_tmp32
);
4742 /* REV with sf==1, opcode==3 ("REV64") */
4743 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
4744 unsigned int rn
, unsigned int rd
)
4747 unallocated_encoding(s
);
4750 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
4753 /* REV with sf==0, opcode==2
4754 * REV32 (sf==1, opcode==2)
4756 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
4757 unsigned int rn
, unsigned int rd
)
4759 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4762 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4763 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4765 /* bswap32_i64 requires zero high word */
4766 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
4767 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
4768 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
4769 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
4770 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4772 tcg_temp_free_i64(tcg_tmp
);
4774 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
4775 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
4779 /* REV16 (opcode==1) */
4780 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
4781 unsigned int rn
, unsigned int rd
)
4783 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4784 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4785 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4786 TCGv_i64 mask
= tcg_const_i64(sf
? 0x00ff00ff00ff00ffull
: 0x00ff00ff);
4788 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 8);
4789 tcg_gen_and_i64(tcg_rd
, tcg_rn
, mask
);
4790 tcg_gen_and_i64(tcg_tmp
, tcg_tmp
, mask
);
4791 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 8);
4792 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4794 tcg_temp_free_i64(mask
);
4795 tcg_temp_free_i64(tcg_tmp
);
4798 /* Data-processing (1 source)
4799 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4800 * +----+---+---+-----------------+---------+--------+------+------+
4801 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
4802 * +----+---+---+-----------------+---------+--------+------+------+
4804 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
4806 unsigned int sf
, opcode
, opcode2
, rn
, rd
;
4809 if (extract32(insn
, 29, 1)) {
4810 unallocated_encoding(s
);
4814 sf
= extract32(insn
, 31, 1);
4815 opcode
= extract32(insn
, 10, 6);
4816 opcode2
= extract32(insn
, 16, 5);
4817 rn
= extract32(insn
, 5, 5);
4818 rd
= extract32(insn
, 0, 5);
4820 #define MAP(SF, O2, O1) ((SF) | (O1 << 1) | (O2 << 7))
4822 switch (MAP(sf
, opcode2
, opcode
)) {
4823 case MAP(0, 0x00, 0x00): /* RBIT */
4824 case MAP(1, 0x00, 0x00):
4825 handle_rbit(s
, sf
, rn
, rd
);
4827 case MAP(0, 0x00, 0x01): /* REV16 */
4828 case MAP(1, 0x00, 0x01):
4829 handle_rev16(s
, sf
, rn
, rd
);
4831 case MAP(0, 0x00, 0x02): /* REV/REV32 */
4832 case MAP(1, 0x00, 0x02):
4833 handle_rev32(s
, sf
, rn
, rd
);
4835 case MAP(1, 0x00, 0x03): /* REV64 */
4836 handle_rev64(s
, sf
, rn
, rd
);
4838 case MAP(0, 0x00, 0x04): /* CLZ */
4839 case MAP(1, 0x00, 0x04):
4840 handle_clz(s
, sf
, rn
, rd
);
4842 case MAP(0, 0x00, 0x05): /* CLS */
4843 case MAP(1, 0x00, 0x05):
4844 handle_cls(s
, sf
, rn
, rd
);
4846 case MAP(1, 0x01, 0x00): /* PACIA */
4847 if (s
->pauth_active
) {
4848 tcg_rd
= cpu_reg(s
, rd
);
4849 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4850 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4851 goto do_unallocated
;
4854 case MAP(1, 0x01, 0x01): /* PACIB */
4855 if (s
->pauth_active
) {
4856 tcg_rd
= cpu_reg(s
, rd
);
4857 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4858 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4859 goto do_unallocated
;
4862 case MAP(1, 0x01, 0x02): /* PACDA */
4863 if (s
->pauth_active
) {
4864 tcg_rd
= cpu_reg(s
, rd
);
4865 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4866 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4867 goto do_unallocated
;
4870 case MAP(1, 0x01, 0x03): /* PACDB */
4871 if (s
->pauth_active
) {
4872 tcg_rd
= cpu_reg(s
, rd
);
4873 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4874 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4875 goto do_unallocated
;
4878 case MAP(1, 0x01, 0x04): /* AUTIA */
4879 if (s
->pauth_active
) {
4880 tcg_rd
= cpu_reg(s
, rd
);
4881 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4882 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4883 goto do_unallocated
;
4886 case MAP(1, 0x01, 0x05): /* AUTIB */
4887 if (s
->pauth_active
) {
4888 tcg_rd
= cpu_reg(s
, rd
);
4889 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4890 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4891 goto do_unallocated
;
4894 case MAP(1, 0x01, 0x06): /* AUTDA */
4895 if (s
->pauth_active
) {
4896 tcg_rd
= cpu_reg(s
, rd
);
4897 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4898 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4899 goto do_unallocated
;
4902 case MAP(1, 0x01, 0x07): /* AUTDB */
4903 if (s
->pauth_active
) {
4904 tcg_rd
= cpu_reg(s
, rd
);
4905 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, cpu_reg_sp(s
, rn
));
4906 } else if (!dc_isar_feature(aa64_pauth
, s
)) {
4907 goto do_unallocated
;
4910 case MAP(1, 0x01, 0x08): /* PACIZA */
4911 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4912 goto do_unallocated
;
4913 } else if (s
->pauth_active
) {
4914 tcg_rd
= cpu_reg(s
, rd
);
4915 gen_helper_pacia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4918 case MAP(1, 0x01, 0x09): /* PACIZB */
4919 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4920 goto do_unallocated
;
4921 } else if (s
->pauth_active
) {
4922 tcg_rd
= cpu_reg(s
, rd
);
4923 gen_helper_pacib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4926 case MAP(1, 0x01, 0x0a): /* PACDZA */
4927 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4928 goto do_unallocated
;
4929 } else if (s
->pauth_active
) {
4930 tcg_rd
= cpu_reg(s
, rd
);
4931 gen_helper_pacda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4934 case MAP(1, 0x01, 0x0b): /* PACDZB */
4935 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4936 goto do_unallocated
;
4937 } else if (s
->pauth_active
) {
4938 tcg_rd
= cpu_reg(s
, rd
);
4939 gen_helper_pacdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4942 case MAP(1, 0x01, 0x0c): /* AUTIZA */
4943 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4944 goto do_unallocated
;
4945 } else if (s
->pauth_active
) {
4946 tcg_rd
= cpu_reg(s
, rd
);
4947 gen_helper_autia(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4950 case MAP(1, 0x01, 0x0d): /* AUTIZB */
4951 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4952 goto do_unallocated
;
4953 } else if (s
->pauth_active
) {
4954 tcg_rd
= cpu_reg(s
, rd
);
4955 gen_helper_autib(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4958 case MAP(1, 0x01, 0x0e): /* AUTDZA */
4959 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4960 goto do_unallocated
;
4961 } else if (s
->pauth_active
) {
4962 tcg_rd
= cpu_reg(s
, rd
);
4963 gen_helper_autda(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4966 case MAP(1, 0x01, 0x0f): /* AUTDZB */
4967 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4968 goto do_unallocated
;
4969 } else if (s
->pauth_active
) {
4970 tcg_rd
= cpu_reg(s
, rd
);
4971 gen_helper_autdb(tcg_rd
, cpu_env
, tcg_rd
, new_tmp_a64_zero(s
));
4974 case MAP(1, 0x01, 0x10): /* XPACI */
4975 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4976 goto do_unallocated
;
4977 } else if (s
->pauth_active
) {
4978 tcg_rd
= cpu_reg(s
, rd
);
4979 gen_helper_xpaci(tcg_rd
, cpu_env
, tcg_rd
);
4982 case MAP(1, 0x01, 0x11): /* XPACD */
4983 if (!dc_isar_feature(aa64_pauth
, s
) || rn
!= 31) {
4984 goto do_unallocated
;
4985 } else if (s
->pauth_active
) {
4986 tcg_rd
= cpu_reg(s
, rd
);
4987 gen_helper_xpacd(tcg_rd
, cpu_env
, tcg_rd
);
4992 unallocated_encoding(s
);
4999 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
5000 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5002 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
5003 tcg_rd
= cpu_reg(s
, rd
);
5005 if (!sf
&& is_signed
) {
5006 tcg_n
= new_tmp_a64(s
);
5007 tcg_m
= new_tmp_a64(s
);
5008 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
5009 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
5011 tcg_n
= read_cpu_reg(s
, rn
, sf
);
5012 tcg_m
= read_cpu_reg(s
, rm
, sf
);
5016 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
5018 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
5021 if (!sf
) { /* zero extend final result */
5022 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5026 /* LSLV, LSRV, ASRV, RORV */
5027 static void handle_shift_reg(DisasContext
*s
,
5028 enum a64_shift_type shift_type
, unsigned int sf
,
5029 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5031 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
5032 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5033 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
5035 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
5036 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
5037 tcg_temp_free_i64(tcg_shift
);
5040 /* CRC32[BHWX], CRC32C[BHWX] */
5041 static void handle_crc32(DisasContext
*s
,
5042 unsigned int sf
, unsigned int sz
, bool crc32c
,
5043 unsigned int rm
, unsigned int rn
, unsigned int rd
)
5045 TCGv_i64 tcg_acc
, tcg_val
;
5048 if (!dc_isar_feature(aa64_crc32
, s
)
5049 || (sf
== 1 && sz
!= 3)
5050 || (sf
== 0 && sz
== 3)) {
5051 unallocated_encoding(s
);
5056 tcg_val
= cpu_reg(s
, rm
);
5070 g_assert_not_reached();
5072 tcg_val
= new_tmp_a64(s
);
5073 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
5076 tcg_acc
= cpu_reg(s
, rn
);
5077 tcg_bytes
= tcg_const_i32(1 << sz
);
5080 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5082 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
5085 tcg_temp_free_i32(tcg_bytes
);
5088 /* Data-processing (2 source)
5089 * 31 30 29 28 21 20 16 15 10 9 5 4 0
5090 * +----+---+---+-----------------+------+--------+------+------+
5091 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
5092 * +----+---+---+-----------------+------+--------+------+------+
5094 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
5096 unsigned int sf
, rm
, opcode
, rn
, rd
;
5097 sf
= extract32(insn
, 31, 1);
5098 rm
= extract32(insn
, 16, 5);
5099 opcode
= extract32(insn
, 10, 6);
5100 rn
= extract32(insn
, 5, 5);
5101 rd
= extract32(insn
, 0, 5);
5103 if (extract32(insn
, 29, 1)) {
5104 unallocated_encoding(s
);
5110 handle_div(s
, false, sf
, rm
, rn
, rd
);
5113 handle_div(s
, true, sf
, rm
, rn
, rd
);
5116 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
5119 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
5122 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
5125 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
5127 case 12: /* PACGA */
5128 if (sf
== 0 || !dc_isar_feature(aa64_pauth
, s
)) {
5129 goto do_unallocated
;
5131 gen_helper_pacga(cpu_reg(s
, rd
), cpu_env
,
5132 cpu_reg(s
, rn
), cpu_reg_sp(s
, rm
));
5141 case 23: /* CRC32 */
5143 int sz
= extract32(opcode
, 0, 2);
5144 bool crc32c
= extract32(opcode
, 2, 1);
5145 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
5150 unallocated_encoding(s
);
5155 /* Data processing - register */
5156 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
5158 switch (extract32(insn
, 24, 5)) {
5159 case 0x0a: /* Logical (shifted register) */
5160 disas_logic_reg(s
, insn
);
5162 case 0x0b: /* Add/subtract */
5163 if (insn
& (1 << 21)) { /* (extended register) */
5164 disas_add_sub_ext_reg(s
, insn
);
5166 disas_add_sub_reg(s
, insn
);
5169 case 0x1b: /* Data-processing (3 source) */
5170 disas_data_proc_3src(s
, insn
);
5173 switch (extract32(insn
, 21, 3)) {
5174 case 0x0: /* Add/subtract (with carry) */
5175 disas_adc_sbc(s
, insn
);
5177 case 0x2: /* Conditional compare */
5178 disas_cc(s
, insn
); /* both imm and reg forms */
5180 case 0x4: /* Conditional select */
5181 disas_cond_select(s
, insn
);
5183 case 0x6: /* Data-processing */
5184 if (insn
& (1 << 30)) { /* (1 source) */
5185 disas_data_proc_1src(s
, insn
);
5186 } else { /* (2 source) */
5187 disas_data_proc_2src(s
, insn
);
5191 unallocated_encoding(s
);
5196 unallocated_encoding(s
);
5201 static void handle_fp_compare(DisasContext
*s
, int size
,
5202 unsigned int rn
, unsigned int rm
,
5203 bool cmp_with_zero
, bool signal_all_nans
)
5205 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
5206 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
5208 if (size
== MO_64
) {
5209 TCGv_i64 tcg_vn
, tcg_vm
;
5211 tcg_vn
= read_fp_dreg(s
, rn
);
5212 if (cmp_with_zero
) {
5213 tcg_vm
= tcg_const_i64(0);
5215 tcg_vm
= read_fp_dreg(s
, rm
);
5217 if (signal_all_nans
) {
5218 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5220 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5222 tcg_temp_free_i64(tcg_vn
);
5223 tcg_temp_free_i64(tcg_vm
);
5225 TCGv_i32 tcg_vn
= tcg_temp_new_i32();
5226 TCGv_i32 tcg_vm
= tcg_temp_new_i32();
5228 read_vec_element_i32(s
, tcg_vn
, rn
, 0, size
);
5229 if (cmp_with_zero
) {
5230 tcg_gen_movi_i32(tcg_vm
, 0);
5232 read_vec_element_i32(s
, tcg_vm
, rm
, 0, size
);
5237 if (signal_all_nans
) {
5238 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5240 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5244 if (signal_all_nans
) {
5245 gen_helper_vfp_cmpeh_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5247 gen_helper_vfp_cmph_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
5251 g_assert_not_reached();
5254 tcg_temp_free_i32(tcg_vn
);
5255 tcg_temp_free_i32(tcg_vm
);
5258 tcg_temp_free_ptr(fpst
);
5260 gen_set_nzcv(tcg_flags
);
5262 tcg_temp_free_i64(tcg_flags
);
5265 /* Floating point compare
5266 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
5267 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5268 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
5269 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
5271 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
5273 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
5276 mos
= extract32(insn
, 29, 3);
5277 type
= extract32(insn
, 22, 2);
5278 rm
= extract32(insn
, 16, 5);
5279 op
= extract32(insn
, 14, 2);
5280 rn
= extract32(insn
, 5, 5);
5281 opc
= extract32(insn
, 3, 2);
5282 op2r
= extract32(insn
, 0, 3);
5284 if (mos
|| op
|| op2r
) {
5285 unallocated_encoding(s
);
5298 if (dc_isar_feature(aa64_fp16
, s
)) {
5303 unallocated_encoding(s
);
5307 if (!fp_access_check(s
)) {
5311 handle_fp_compare(s
, size
, rn
, rm
, opc
& 1, opc
& 2);
5314 /* Floating point conditional compare
5315 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
5316 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5317 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
5318 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
5320 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
5322 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
5324 TCGLabel
*label_continue
= NULL
;
5327 mos
= extract32(insn
, 29, 3);
5328 type
= extract32(insn
, 22, 2);
5329 rm
= extract32(insn
, 16, 5);
5330 cond
= extract32(insn
, 12, 4);
5331 rn
= extract32(insn
, 5, 5);
5332 op
= extract32(insn
, 4, 1);
5333 nzcv
= extract32(insn
, 0, 4);
5336 unallocated_encoding(s
);
5349 if (dc_isar_feature(aa64_fp16
, s
)) {
5354 unallocated_encoding(s
);
5358 if (!fp_access_check(s
)) {
5362 if (cond
< 0x0e) { /* not always */
5363 TCGLabel
*label_match
= gen_new_label();
5364 label_continue
= gen_new_label();
5365 arm_gen_test_cc(cond
, label_match
);
5367 tcg_flags
= tcg_const_i64(nzcv
<< 28);
5368 gen_set_nzcv(tcg_flags
);
5369 tcg_temp_free_i64(tcg_flags
);
5370 tcg_gen_br(label_continue
);
5371 gen_set_label(label_match
);
5374 handle_fp_compare(s
, size
, rn
, rm
, false, op
);
5377 gen_set_label(label_continue
);
5381 /* Floating point conditional select
5382 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5383 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5384 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
5385 * +---+---+---+-----------+------+---+------+------+-----+------+------+
5387 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
5389 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
5390 TCGv_i64 t_true
, t_false
, t_zero
;
5394 mos
= extract32(insn
, 29, 3);
5395 type
= extract32(insn
, 22, 2);
5396 rm
= extract32(insn
, 16, 5);
5397 cond
= extract32(insn
, 12, 4);
5398 rn
= extract32(insn
, 5, 5);
5399 rd
= extract32(insn
, 0, 5);
5402 unallocated_encoding(s
);
5415 if (dc_isar_feature(aa64_fp16
, s
)) {
5420 unallocated_encoding(s
);
5424 if (!fp_access_check(s
)) {
5428 /* Zero extend sreg & hreg inputs to 64 bits now. */
5429 t_true
= tcg_temp_new_i64();
5430 t_false
= tcg_temp_new_i64();
5431 read_vec_element(s
, t_true
, rn
, 0, sz
);
5432 read_vec_element(s
, t_false
, rm
, 0, sz
);
5434 a64_test_cc(&c
, cond
);
5435 t_zero
= tcg_const_i64(0);
5436 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, t_zero
, t_true
, t_false
);
5437 tcg_temp_free_i64(t_zero
);
5438 tcg_temp_free_i64(t_false
);
5441 /* Note that sregs & hregs write back zeros to the high bits,
5442 and we've already done the zero-extension. */
5443 write_fp_dreg(s
, rd
, t_true
);
5444 tcg_temp_free_i64(t_true
);
5447 /* Floating-point data-processing (1 source) - half precision */
5448 static void handle_fp_1src_half(DisasContext
*s
, int opcode
, int rd
, int rn
)
5450 TCGv_ptr fpst
= NULL
;
5451 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
5452 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5455 case 0x0: /* FMOV */
5456 tcg_gen_mov_i32(tcg_res
, tcg_op
);
5458 case 0x1: /* FABS */
5459 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
5461 case 0x2: /* FNEG */
5462 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
5464 case 0x3: /* FSQRT */
5465 fpst
= get_fpstatus_ptr(true);
5466 gen_helper_sqrt_f16(tcg_res
, tcg_op
, fpst
);
5468 case 0x8: /* FRINTN */
5469 case 0x9: /* FRINTP */
5470 case 0xa: /* FRINTM */
5471 case 0xb: /* FRINTZ */
5472 case 0xc: /* FRINTA */
5474 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
5475 fpst
= get_fpstatus_ptr(true);
5477 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5478 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
5480 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5481 tcg_temp_free_i32(tcg_rmode
);
5484 case 0xe: /* FRINTX */
5485 fpst
= get_fpstatus_ptr(true);
5486 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, fpst
);
5488 case 0xf: /* FRINTI */
5489 fpst
= get_fpstatus_ptr(true);
5490 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
5496 write_fp_sreg(s
, rd
, tcg_res
);
5499 tcg_temp_free_ptr(fpst
);
5501 tcg_temp_free_i32(tcg_op
);
5502 tcg_temp_free_i32(tcg_res
);
5505 /* Floating-point data-processing (1 source) - single precision */
5506 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
5512 fpst
= get_fpstatus_ptr(false);
5513 tcg_op
= read_fp_sreg(s
, rn
);
5514 tcg_res
= tcg_temp_new_i32();
5517 case 0x0: /* FMOV */
5518 tcg_gen_mov_i32(tcg_res
, tcg_op
);
5520 case 0x1: /* FABS */
5521 gen_helper_vfp_abss(tcg_res
, tcg_op
);
5523 case 0x2: /* FNEG */
5524 gen_helper_vfp_negs(tcg_res
, tcg_op
);
5526 case 0x3: /* FSQRT */
5527 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
5529 case 0x8: /* FRINTN */
5530 case 0x9: /* FRINTP */
5531 case 0xa: /* FRINTM */
5532 case 0xb: /* FRINTZ */
5533 case 0xc: /* FRINTA */
5535 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
5537 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5538 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
5540 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5541 tcg_temp_free_i32(tcg_rmode
);
5544 case 0xe: /* FRINTX */
5545 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
5547 case 0xf: /* FRINTI */
5548 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
5554 write_fp_sreg(s
, rd
, tcg_res
);
5556 tcg_temp_free_ptr(fpst
);
5557 tcg_temp_free_i32(tcg_op
);
5558 tcg_temp_free_i32(tcg_res
);
5561 /* Floating-point data-processing (1 source) - double precision */
5562 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
5569 case 0x0: /* FMOV */
5570 gen_gvec_fn2(s
, false, rd
, rn
, tcg_gen_gvec_mov
, 0);
5574 fpst
= get_fpstatus_ptr(false);
5575 tcg_op
= read_fp_dreg(s
, rn
);
5576 tcg_res
= tcg_temp_new_i64();
5579 case 0x1: /* FABS */
5580 gen_helper_vfp_absd(tcg_res
, tcg_op
);
5582 case 0x2: /* FNEG */
5583 gen_helper_vfp_negd(tcg_res
, tcg_op
);
5585 case 0x3: /* FSQRT */
5586 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
5588 case 0x8: /* FRINTN */
5589 case 0x9: /* FRINTP */
5590 case 0xa: /* FRINTM */
5591 case 0xb: /* FRINTZ */
5592 case 0xc: /* FRINTA */
5594 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
5596 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5597 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
5599 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5600 tcg_temp_free_i32(tcg_rmode
);
5603 case 0xe: /* FRINTX */
5604 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
5606 case 0xf: /* FRINTI */
5607 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
5613 write_fp_dreg(s
, rd
, tcg_res
);
5615 tcg_temp_free_ptr(fpst
);
5616 tcg_temp_free_i64(tcg_op
);
5617 tcg_temp_free_i64(tcg_res
);
5620 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
5621 int rd
, int rn
, int dtype
, int ntype
)
5626 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5628 /* Single to double */
5629 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5630 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
5631 write_fp_dreg(s
, rd
, tcg_rd
);
5632 tcg_temp_free_i64(tcg_rd
);
5634 /* Single to half */
5635 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5636 TCGv_i32 ahp
= get_ahp_flag();
5637 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5639 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5640 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5641 write_fp_sreg(s
, rd
, tcg_rd
);
5642 tcg_temp_free_i32(tcg_rd
);
5643 tcg_temp_free_i32(ahp
);
5644 tcg_temp_free_ptr(fpst
);
5646 tcg_temp_free_i32(tcg_rn
);
5651 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
5652 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5654 /* Double to single */
5655 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
5657 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5658 TCGv_i32 ahp
= get_ahp_flag();
5659 /* Double to half */
5660 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5661 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5662 tcg_temp_free_ptr(fpst
);
5663 tcg_temp_free_i32(ahp
);
5665 write_fp_sreg(s
, rd
, tcg_rd
);
5666 tcg_temp_free_i32(tcg_rd
);
5667 tcg_temp_free_i64(tcg_rn
);
5672 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5673 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(false);
5674 TCGv_i32 tcg_ahp
= get_ahp_flag();
5675 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
5677 /* Half to single */
5678 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5679 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5680 write_fp_sreg(s
, rd
, tcg_rd
);
5681 tcg_temp_free_ptr(tcg_fpst
);
5682 tcg_temp_free_i32(tcg_ahp
);
5683 tcg_temp_free_i32(tcg_rd
);
5685 /* Half to double */
5686 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5687 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5688 write_fp_dreg(s
, rd
, tcg_rd
);
5689 tcg_temp_free_i64(tcg_rd
);
5691 tcg_temp_free_i32(tcg_rn
);
5699 /* Floating point data-processing (1 source)
5700 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
5701 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5702 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
5703 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5705 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
5707 int mos
= extract32(insn
, 29, 3);
5708 int type
= extract32(insn
, 22, 2);
5709 int opcode
= extract32(insn
, 15, 6);
5710 int rn
= extract32(insn
, 5, 5);
5711 int rd
= extract32(insn
, 0, 5);
5714 unallocated_encoding(s
);
5719 case 0x4: case 0x5: case 0x7:
5721 /* FCVT between half, single and double precision */
5722 int dtype
= extract32(opcode
, 0, 2);
5723 if (type
== 2 || dtype
== type
) {
5724 unallocated_encoding(s
);
5727 if (!fp_access_check(s
)) {
5731 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
5737 /* 32-to-32 and 64-to-64 ops */
5740 if (!fp_access_check(s
)) {
5744 handle_fp_1src_single(s
, opcode
, rd
, rn
);
5747 if (!fp_access_check(s
)) {
5751 handle_fp_1src_double(s
, opcode
, rd
, rn
);
5754 if (!dc_isar_feature(aa64_fp16
, s
)) {
5755 unallocated_encoding(s
);
5759 if (!fp_access_check(s
)) {
5763 handle_fp_1src_half(s
, opcode
, rd
, rn
);
5766 unallocated_encoding(s
);
5770 unallocated_encoding(s
);
5775 /* Floating-point data-processing (2 source) - single precision */
5776 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
5777 int rd
, int rn
, int rm
)
5784 tcg_res
= tcg_temp_new_i32();
5785 fpst
= get_fpstatus_ptr(false);
5786 tcg_op1
= read_fp_sreg(s
, rn
);
5787 tcg_op2
= read_fp_sreg(s
, rm
);
5790 case 0x0: /* FMUL */
5791 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5793 case 0x1: /* FDIV */
5794 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5796 case 0x2: /* FADD */
5797 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5799 case 0x3: /* FSUB */
5800 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5802 case 0x4: /* FMAX */
5803 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5805 case 0x5: /* FMIN */
5806 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5808 case 0x6: /* FMAXNM */
5809 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5811 case 0x7: /* FMINNM */
5812 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5814 case 0x8: /* FNMUL */
5815 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5816 gen_helper_vfp_negs(tcg_res
, tcg_res
);
5820 write_fp_sreg(s
, rd
, tcg_res
);
5822 tcg_temp_free_ptr(fpst
);
5823 tcg_temp_free_i32(tcg_op1
);
5824 tcg_temp_free_i32(tcg_op2
);
5825 tcg_temp_free_i32(tcg_res
);
5828 /* Floating-point data-processing (2 source) - double precision */
5829 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
5830 int rd
, int rn
, int rm
)
5837 tcg_res
= tcg_temp_new_i64();
5838 fpst
= get_fpstatus_ptr(false);
5839 tcg_op1
= read_fp_dreg(s
, rn
);
5840 tcg_op2
= read_fp_dreg(s
, rm
);
5843 case 0x0: /* FMUL */
5844 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5846 case 0x1: /* FDIV */
5847 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5849 case 0x2: /* FADD */
5850 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5852 case 0x3: /* FSUB */
5853 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5855 case 0x4: /* FMAX */
5856 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5858 case 0x5: /* FMIN */
5859 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5861 case 0x6: /* FMAXNM */
5862 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5864 case 0x7: /* FMINNM */
5865 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5867 case 0x8: /* FNMUL */
5868 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5869 gen_helper_vfp_negd(tcg_res
, tcg_res
);
5873 write_fp_dreg(s
, rd
, tcg_res
);
5875 tcg_temp_free_ptr(fpst
);
5876 tcg_temp_free_i64(tcg_op1
);
5877 tcg_temp_free_i64(tcg_op2
);
5878 tcg_temp_free_i64(tcg_res
);
5881 /* Floating-point data-processing (2 source) - half precision */
5882 static void handle_fp_2src_half(DisasContext
*s
, int opcode
,
5883 int rd
, int rn
, int rm
)
5890 tcg_res
= tcg_temp_new_i32();
5891 fpst
= get_fpstatus_ptr(true);
5892 tcg_op1
= read_fp_hreg(s
, rn
);
5893 tcg_op2
= read_fp_hreg(s
, rm
);
5896 case 0x0: /* FMUL */
5897 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5899 case 0x1: /* FDIV */
5900 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5902 case 0x2: /* FADD */
5903 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5905 case 0x3: /* FSUB */
5906 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5908 case 0x4: /* FMAX */
5909 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5911 case 0x5: /* FMIN */
5912 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5914 case 0x6: /* FMAXNM */
5915 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5917 case 0x7: /* FMINNM */
5918 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5920 case 0x8: /* FNMUL */
5921 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5922 tcg_gen_xori_i32(tcg_res
, tcg_res
, 0x8000);
5925 g_assert_not_reached();
5928 write_fp_sreg(s
, rd
, tcg_res
);
5930 tcg_temp_free_ptr(fpst
);
5931 tcg_temp_free_i32(tcg_op1
);
5932 tcg_temp_free_i32(tcg_op2
);
5933 tcg_temp_free_i32(tcg_res
);
5936 /* Floating point data-processing (2 source)
5937 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5938 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5939 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
5940 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5942 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
5944 int mos
= extract32(insn
, 29, 3);
5945 int type
= extract32(insn
, 22, 2);
5946 int rd
= extract32(insn
, 0, 5);
5947 int rn
= extract32(insn
, 5, 5);
5948 int rm
= extract32(insn
, 16, 5);
5949 int opcode
= extract32(insn
, 12, 4);
5951 if (opcode
> 8 || mos
) {
5952 unallocated_encoding(s
);
5958 if (!fp_access_check(s
)) {
5961 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
5964 if (!fp_access_check(s
)) {
5967 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
5970 if (!dc_isar_feature(aa64_fp16
, s
)) {
5971 unallocated_encoding(s
);
5974 if (!fp_access_check(s
)) {
5977 handle_fp_2src_half(s
, opcode
, rd
, rn
, rm
);
5980 unallocated_encoding(s
);
5984 /* Floating-point data-processing (3 source) - single precision */
5985 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
5986 int rd
, int rn
, int rm
, int ra
)
5988 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
5989 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5990 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5992 tcg_op1
= read_fp_sreg(s
, rn
);
5993 tcg_op2
= read_fp_sreg(s
, rm
);
5994 tcg_op3
= read_fp_sreg(s
, ra
);
5996 /* These are fused multiply-add, and must be done as one
5997 * floating point operation with no rounding between the
5998 * multiplication and addition steps.
5999 * NB that doing the negations here as separate steps is
6000 * correct : an input NaN should come out with its sign bit
6001 * flipped if it is a negated-input.
6004 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
6008 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
6011 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6013 write_fp_sreg(s
, rd
, tcg_res
);
6015 tcg_temp_free_ptr(fpst
);
6016 tcg_temp_free_i32(tcg_op1
);
6017 tcg_temp_free_i32(tcg_op2
);
6018 tcg_temp_free_i32(tcg_op3
);
6019 tcg_temp_free_i32(tcg_res
);
6022 /* Floating-point data-processing (3 source) - double precision */
6023 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
6024 int rd
, int rn
, int rm
, int ra
)
6026 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
6027 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6028 TCGv_ptr fpst
= get_fpstatus_ptr(false);
6030 tcg_op1
= read_fp_dreg(s
, rn
);
6031 tcg_op2
= read_fp_dreg(s
, rm
);
6032 tcg_op3
= read_fp_dreg(s
, ra
);
6034 /* These are fused multiply-add, and must be done as one
6035 * floating point operation with no rounding between the
6036 * multiplication and addition steps.
6037 * NB that doing the negations here as separate steps is
6038 * correct : an input NaN should come out with its sign bit
6039 * flipped if it is a negated-input.
6042 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
6046 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
6049 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6051 write_fp_dreg(s
, rd
, tcg_res
);
6053 tcg_temp_free_ptr(fpst
);
6054 tcg_temp_free_i64(tcg_op1
);
6055 tcg_temp_free_i64(tcg_op2
);
6056 tcg_temp_free_i64(tcg_op3
);
6057 tcg_temp_free_i64(tcg_res
);
6060 /* Floating-point data-processing (3 source) - half precision */
6061 static void handle_fp_3src_half(DisasContext
*s
, bool o0
, bool o1
,
6062 int rd
, int rn
, int rm
, int ra
)
6064 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
6065 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6066 TCGv_ptr fpst
= get_fpstatus_ptr(true);
6068 tcg_op1
= read_fp_hreg(s
, rn
);
6069 tcg_op2
= read_fp_hreg(s
, rm
);
6070 tcg_op3
= read_fp_hreg(s
, ra
);
6072 /* These are fused multiply-add, and must be done as one
6073 * floating point operation with no rounding between the
6074 * multiplication and addition steps.
6075 * NB that doing the negations here as separate steps is
6076 * correct : an input NaN should come out with its sign bit
6077 * flipped if it is a negated-input.
6080 tcg_gen_xori_i32(tcg_op3
, tcg_op3
, 0x8000);
6084 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
6087 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
6089 write_fp_sreg(s
, rd
, tcg_res
);
6091 tcg_temp_free_ptr(fpst
);
6092 tcg_temp_free_i32(tcg_op1
);
6093 tcg_temp_free_i32(tcg_op2
);
6094 tcg_temp_free_i32(tcg_op3
);
6095 tcg_temp_free_i32(tcg_res
);
6098 /* Floating point data-processing (3 source)
6099 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
6100 * +---+---+---+-----------+------+----+------+----+------+------+------+
6101 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
6102 * +---+---+---+-----------+------+----+------+----+------+------+------+
6104 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
6106 int mos
= extract32(insn
, 29, 3);
6107 int type
= extract32(insn
, 22, 2);
6108 int rd
= extract32(insn
, 0, 5);
6109 int rn
= extract32(insn
, 5, 5);
6110 int ra
= extract32(insn
, 10, 5);
6111 int rm
= extract32(insn
, 16, 5);
6112 bool o0
= extract32(insn
, 15, 1);
6113 bool o1
= extract32(insn
, 21, 1);
6116 unallocated_encoding(s
);
6122 if (!fp_access_check(s
)) {
6125 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6128 if (!fp_access_check(s
)) {
6131 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6134 if (!dc_isar_feature(aa64_fp16
, s
)) {
6135 unallocated_encoding(s
);
6138 if (!fp_access_check(s
)) {
6141 handle_fp_3src_half(s
, o0
, o1
, rd
, rn
, rm
, ra
);
6144 unallocated_encoding(s
);
6148 /* The imm8 encodes the sign bit, enough bits to represent an exponent in
6149 * the range 01....1xx to 10....0xx, and the most significant 4 bits of
6150 * the mantissa; see VFPExpandImm() in the v8 ARM ARM.
6152 uint64_t vfp_expand_imm(int size
, uint8_t imm8
)
6158 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
6159 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
6160 extract32(imm8
, 0, 6);
6164 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
6165 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
6166 (extract32(imm8
, 0, 6) << 3);
6170 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
6171 (extract32(imm8
, 6, 1) ? 0x3000 : 0x4000) |
6172 (extract32(imm8
, 0, 6) << 6);
6175 g_assert_not_reached();
6180 /* Floating point immediate
6181 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
6182 * +---+---+---+-----------+------+---+------------+-------+------+------+
6183 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
6184 * +---+---+---+-----------+------+---+------------+-------+------+------+
6186 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
6188 int rd
= extract32(insn
, 0, 5);
6189 int imm5
= extract32(insn
, 5, 5);
6190 int imm8
= extract32(insn
, 13, 8);
6191 int type
= extract32(insn
, 22, 2);
6192 int mos
= extract32(insn
, 29, 3);
6198 unallocated_encoding(s
);
6211 if (dc_isar_feature(aa64_fp16
, s
)) {
6216 unallocated_encoding(s
);
6220 if (!fp_access_check(s
)) {
6224 imm
= vfp_expand_imm(sz
, imm8
);
6226 tcg_res
= tcg_const_i64(imm
);
6227 write_fp_dreg(s
, rd
, tcg_res
);
6228 tcg_temp_free_i64(tcg_res
);
6231 /* Handle floating point <=> fixed point conversions. Note that we can
6232 * also deal with fp <=> integer conversions as a special case (scale == 64)
6233 * OPTME: consider handling that special case specially or at least skipping
6234 * the call to scalbn in the helpers for zero shifts.
6236 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
6237 bool itof
, int rmode
, int scale
, int sf
, int type
)
6239 bool is_signed
= !(opcode
& 1);
6240 TCGv_ptr tcg_fpstatus
;
6241 TCGv_i32 tcg_shift
, tcg_single
;
6242 TCGv_i64 tcg_double
;
6244 tcg_fpstatus
= get_fpstatus_ptr(type
== 3);
6246 tcg_shift
= tcg_const_i32(64 - scale
);
6249 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
6251 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
6254 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
6256 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
6259 tcg_int
= tcg_extend
;
6263 case 1: /* float64 */
6264 tcg_double
= tcg_temp_new_i64();
6266 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6267 tcg_shift
, tcg_fpstatus
);
6269 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6270 tcg_shift
, tcg_fpstatus
);
6272 write_fp_dreg(s
, rd
, tcg_double
);
6273 tcg_temp_free_i64(tcg_double
);
6276 case 0: /* float32 */
6277 tcg_single
= tcg_temp_new_i32();
6279 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6280 tcg_shift
, tcg_fpstatus
);
6282 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6283 tcg_shift
, tcg_fpstatus
);
6285 write_fp_sreg(s
, rd
, tcg_single
);
6286 tcg_temp_free_i32(tcg_single
);
6289 case 3: /* float16 */
6290 tcg_single
= tcg_temp_new_i32();
6292 gen_helper_vfp_sqtoh(tcg_single
, tcg_int
,
6293 tcg_shift
, tcg_fpstatus
);
6295 gen_helper_vfp_uqtoh(tcg_single
, tcg_int
,
6296 tcg_shift
, tcg_fpstatus
);
6298 write_fp_sreg(s
, rd
, tcg_single
);
6299 tcg_temp_free_i32(tcg_single
);
6303 g_assert_not_reached();
6306 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
6309 if (extract32(opcode
, 2, 1)) {
6310 /* There are too many rounding modes to all fit into rmode,
6311 * so FCVTA[US] is a special case.
6313 rmode
= FPROUNDING_TIEAWAY
;
6316 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
6318 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
6321 case 1: /* float64 */
6322 tcg_double
= read_fp_dreg(s
, rn
);
6325 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
6326 tcg_shift
, tcg_fpstatus
);
6328 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
6329 tcg_shift
, tcg_fpstatus
);
6333 gen_helper_vfp_tould(tcg_int
, tcg_double
,
6334 tcg_shift
, tcg_fpstatus
);
6336 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
6337 tcg_shift
, tcg_fpstatus
);
6341 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
6343 tcg_temp_free_i64(tcg_double
);
6346 case 0: /* float32 */
6347 tcg_single
= read_fp_sreg(s
, rn
);
6350 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
6351 tcg_shift
, tcg_fpstatus
);
6353 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
6354 tcg_shift
, tcg_fpstatus
);
6357 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
6359 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
6360 tcg_shift
, tcg_fpstatus
);
6362 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
6363 tcg_shift
, tcg_fpstatus
);
6365 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
6366 tcg_temp_free_i32(tcg_dest
);
6368 tcg_temp_free_i32(tcg_single
);
6371 case 3: /* float16 */
6372 tcg_single
= read_fp_sreg(s
, rn
);
6375 gen_helper_vfp_tosqh(tcg_int
, tcg_single
,
6376 tcg_shift
, tcg_fpstatus
);
6378 gen_helper_vfp_touqh(tcg_int
, tcg_single
,
6379 tcg_shift
, tcg_fpstatus
);
6382 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
6384 gen_helper_vfp_toslh(tcg_dest
, tcg_single
,
6385 tcg_shift
, tcg_fpstatus
);
6387 gen_helper_vfp_toulh(tcg_dest
, tcg_single
,
6388 tcg_shift
, tcg_fpstatus
);
6390 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
6391 tcg_temp_free_i32(tcg_dest
);
6393 tcg_temp_free_i32(tcg_single
);
6397 g_assert_not_reached();
6400 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
6401 tcg_temp_free_i32(tcg_rmode
);
6404 tcg_temp_free_ptr(tcg_fpstatus
);
6405 tcg_temp_free_i32(tcg_shift
);
6408 /* Floating point <-> fixed point conversions
6409 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6410 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6411 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
6412 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
6414 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
6416 int rd
= extract32(insn
, 0, 5);
6417 int rn
= extract32(insn
, 5, 5);
6418 int scale
= extract32(insn
, 10, 6);
6419 int opcode
= extract32(insn
, 16, 3);
6420 int rmode
= extract32(insn
, 19, 2);
6421 int type
= extract32(insn
, 22, 2);
6422 bool sbit
= extract32(insn
, 29, 1);
6423 bool sf
= extract32(insn
, 31, 1);
6426 if (sbit
|| (!sf
&& scale
< 32)) {
6427 unallocated_encoding(s
);
6432 case 0: /* float32 */
6433 case 1: /* float64 */
6435 case 3: /* float16 */
6436 if (dc_isar_feature(aa64_fp16
, s
)) {
6441 unallocated_encoding(s
);
6445 switch ((rmode
<< 3) | opcode
) {
6446 case 0x2: /* SCVTF */
6447 case 0x3: /* UCVTF */
6450 case 0x18: /* FCVTZS */
6451 case 0x19: /* FCVTZU */
6455 unallocated_encoding(s
);
6459 if (!fp_access_check(s
)) {
6463 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
6466 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
6468 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
6469 * without conversion.
6473 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
6479 tmp
= tcg_temp_new_i64();
6480 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
6481 write_fp_dreg(s
, rd
, tmp
);
6482 tcg_temp_free_i64(tmp
);
6486 write_fp_dreg(s
, rd
, tcg_rn
);
6489 /* 64 bit to top half. */
6490 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
6491 clear_vec_high(s
, true, rd
);
6495 tmp
= tcg_temp_new_i64();
6496 tcg_gen_ext16u_i64(tmp
, tcg_rn
);
6497 write_fp_dreg(s
, rd
, tmp
);
6498 tcg_temp_free_i64(tmp
);
6501 g_assert_not_reached();
6504 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
6509 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
6513 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
6516 /* 64 bits from top half */
6517 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
6521 tcg_gen_ld16u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_16
));
6524 g_assert_not_reached();
6529 static void handle_fjcvtzs(DisasContext
*s
, int rd
, int rn
)
6531 TCGv_i64 t
= read_fp_dreg(s
, rn
);
6532 TCGv_ptr fpstatus
= get_fpstatus_ptr(false);
6534 gen_helper_fjcvtzs(t
, t
, fpstatus
);
6536 tcg_temp_free_ptr(fpstatus
);
6538 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), t
);
6539 tcg_gen_extrh_i64_i32(cpu_ZF
, t
);
6540 tcg_gen_movi_i32(cpu_CF
, 0);
6541 tcg_gen_movi_i32(cpu_NF
, 0);
6542 tcg_gen_movi_i32(cpu_VF
, 0);
6544 tcg_temp_free_i64(t
);
6547 /* Floating point <-> integer conversions
6548 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6549 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6550 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
6551 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6553 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
6555 int rd
= extract32(insn
, 0, 5);
6556 int rn
= extract32(insn
, 5, 5);
6557 int opcode
= extract32(insn
, 16, 3);
6558 int rmode
= extract32(insn
, 19, 2);
6559 int type
= extract32(insn
, 22, 2);
6560 bool sbit
= extract32(insn
, 29, 1);
6561 bool sf
= extract32(insn
, 31, 1);
6565 goto do_unallocated
;
6573 case 4: /* FCVTAS */
6574 case 5: /* FCVTAU */
6576 goto do_unallocated
;
6579 case 0: /* FCVT[NPMZ]S */
6580 case 1: /* FCVT[NPMZ]U */
6582 case 0: /* float32 */
6583 case 1: /* float64 */
6585 case 3: /* float16 */
6586 if (!dc_isar_feature(aa64_fp16
, s
)) {
6587 goto do_unallocated
;
6591 goto do_unallocated
;
6593 if (!fp_access_check(s
)) {
6596 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
6600 switch (sf
<< 7 | type
<< 5 | rmode
<< 3 | opcode
) {
6601 case 0b01100110: /* FMOV half <-> 32-bit int */
6603 case 0b11100110: /* FMOV half <-> 64-bit int */
6605 if (!dc_isar_feature(aa64_fp16
, s
)) {
6606 goto do_unallocated
;
6609 case 0b00000110: /* FMOV 32-bit */
6611 case 0b10100110: /* FMOV 64-bit */
6613 case 0b11001110: /* FMOV top half of 128-bit */
6615 if (!fp_access_check(s
)) {
6619 handle_fmov(s
, rd
, rn
, type
, itof
);
6622 case 0b00111110: /* FJCVTZS */
6623 if (!dc_isar_feature(aa64_jscvt
, s
)) {
6624 goto do_unallocated
;
6625 } else if (fp_access_check(s
)) {
6626 handle_fjcvtzs(s
, rd
, rn
);
6632 unallocated_encoding(s
);
6639 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
6640 * 31 30 29 28 25 24 0
6641 * +---+---+---+---------+-----------------------------+
6642 * | | 0 | | 1 1 1 1 | |
6643 * +---+---+---+---------+-----------------------------+
6645 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
6647 if (extract32(insn
, 24, 1)) {
6648 /* Floating point data-processing (3 source) */
6649 disas_fp_3src(s
, insn
);
6650 } else if (extract32(insn
, 21, 1) == 0) {
6651 /* Floating point to fixed point conversions */
6652 disas_fp_fixed_conv(s
, insn
);
6654 switch (extract32(insn
, 10, 2)) {
6656 /* Floating point conditional compare */
6657 disas_fp_ccomp(s
, insn
);
6660 /* Floating point data-processing (2 source) */
6661 disas_fp_2src(s
, insn
);
6664 /* Floating point conditional select */
6665 disas_fp_csel(s
, insn
);
6668 switch (ctz32(extract32(insn
, 12, 4))) {
6669 case 0: /* [15:12] == xxx1 */
6670 /* Floating point immediate */
6671 disas_fp_imm(s
, insn
);
6673 case 1: /* [15:12] == xx10 */
6674 /* Floating point compare */
6675 disas_fp_compare(s
, insn
);
6677 case 2: /* [15:12] == x100 */
6678 /* Floating point data-processing (1 source) */
6679 disas_fp_1src(s
, insn
);
6681 case 3: /* [15:12] == 1000 */
6682 unallocated_encoding(s
);
6684 default: /* [15:12] == 0000 */
6685 /* Floating point <-> integer conversions */
6686 disas_fp_int_conv(s
, insn
);
6694 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
6697 /* Extract 64 bits from the middle of two concatenated 64 bit
6698 * vector register slices left:right. The extracted bits start
6699 * at 'pos' bits into the right (least significant) side.
6700 * We return the result in tcg_right, and guarantee not to
6703 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
6704 assert(pos
> 0 && pos
< 64);
6706 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
6707 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
6708 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
6710 tcg_temp_free_i64(tcg_tmp
);
6714 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
6715 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6716 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
6717 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6719 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
6721 int is_q
= extract32(insn
, 30, 1);
6722 int op2
= extract32(insn
, 22, 2);
6723 int imm4
= extract32(insn
, 11, 4);
6724 int rm
= extract32(insn
, 16, 5);
6725 int rn
= extract32(insn
, 5, 5);
6726 int rd
= extract32(insn
, 0, 5);
6727 int pos
= imm4
<< 3;
6728 TCGv_i64 tcg_resl
, tcg_resh
;
6730 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
6731 unallocated_encoding(s
);
6735 if (!fp_access_check(s
)) {
6739 tcg_resh
= tcg_temp_new_i64();
6740 tcg_resl
= tcg_temp_new_i64();
6742 /* Vd gets bits starting at pos bits into Vm:Vn. This is
6743 * either extracting 128 bits from a 128:128 concatenation, or
6744 * extracting 64 bits from a 64:64 concatenation.
6747 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
6749 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
6750 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6752 tcg_gen_movi_i64(tcg_resh
, 0);
6759 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
6760 EltPosns
*elt
= eltposns
;
6767 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
6769 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
6772 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6773 tcg_hh
= tcg_temp_new_i64();
6774 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
6775 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
6776 tcg_temp_free_i64(tcg_hh
);
6780 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6781 tcg_temp_free_i64(tcg_resl
);
6782 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6783 tcg_temp_free_i64(tcg_resh
);
6787 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
6788 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6789 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
6790 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6792 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
6794 int op2
= extract32(insn
, 22, 2);
6795 int is_q
= extract32(insn
, 30, 1);
6796 int rm
= extract32(insn
, 16, 5);
6797 int rn
= extract32(insn
, 5, 5);
6798 int rd
= extract32(insn
, 0, 5);
6799 int is_tblx
= extract32(insn
, 12, 1);
6800 int len
= extract32(insn
, 13, 2);
6801 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
6802 TCGv_i32 tcg_regno
, tcg_numregs
;
6805 unallocated_encoding(s
);
6809 if (!fp_access_check(s
)) {
6813 /* This does a table lookup: for every byte element in the input
6814 * we index into a table formed from up to four vector registers,
6815 * and then the output is the result of the lookups. Our helper
6816 * function does the lookup operation for a single 64 bit part of
6819 tcg_resl
= tcg_temp_new_i64();
6820 tcg_resh
= tcg_temp_new_i64();
6823 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6825 tcg_gen_movi_i64(tcg_resl
, 0);
6827 if (is_tblx
&& is_q
) {
6828 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6830 tcg_gen_movi_i64(tcg_resh
, 0);
6833 tcg_idx
= tcg_temp_new_i64();
6834 tcg_regno
= tcg_const_i32(rn
);
6835 tcg_numregs
= tcg_const_i32(len
+ 1);
6836 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
6837 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
6838 tcg_regno
, tcg_numregs
);
6840 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
6841 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
6842 tcg_regno
, tcg_numregs
);
6844 tcg_temp_free_i64(tcg_idx
);
6845 tcg_temp_free_i32(tcg_regno
);
6846 tcg_temp_free_i32(tcg_numregs
);
6848 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6849 tcg_temp_free_i64(tcg_resl
);
6850 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6851 tcg_temp_free_i64(tcg_resh
);
6855 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
6856 * +---+---+-------------+------+---+------+---+------------------+------+
6857 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
6858 * +---+---+-------------+------+---+------+---+------------------+------+
6860 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
6862 int rd
= extract32(insn
, 0, 5);
6863 int rn
= extract32(insn
, 5, 5);
6864 int rm
= extract32(insn
, 16, 5);
6865 int size
= extract32(insn
, 22, 2);
6866 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
6867 * bit 2 indicates 1 vs 2 variant of the insn.
6869 int opcode
= extract32(insn
, 12, 2);
6870 bool part
= extract32(insn
, 14, 1);
6871 bool is_q
= extract32(insn
, 30, 1);
6872 int esize
= 8 << size
;
6874 int datasize
= is_q
? 128 : 64;
6875 int elements
= datasize
/ esize
;
6876 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
6878 if (opcode
== 0 || (size
== 3 && !is_q
)) {
6879 unallocated_encoding(s
);
6883 if (!fp_access_check(s
)) {
6887 tcg_resl
= tcg_const_i64(0);
6888 tcg_resh
= tcg_const_i64(0);
6889 tcg_res
= tcg_temp_new_i64();
6891 for (i
= 0; i
< elements
; i
++) {
6893 case 1: /* UZP1/2 */
6895 int midpoint
= elements
/ 2;
6897 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
6899 read_vec_element(s
, tcg_res
, rm
,
6900 2 * (i
- midpoint
) + part
, size
);
6904 case 2: /* TRN1/2 */
6906 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
6908 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
6911 case 3: /* ZIP1/2 */
6913 int base
= part
* elements
/ 2;
6915 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
6917 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
6922 g_assert_not_reached();
6927 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
6928 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
6930 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
6931 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
6935 tcg_temp_free_i64(tcg_res
);
6937 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6938 tcg_temp_free_i64(tcg_resl
);
6939 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6940 tcg_temp_free_i64(tcg_resh
);
6944 * do_reduction_op helper
6946 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
6947 * important for correct NaN propagation that we do these
6948 * operations in exactly the order specified by the pseudocode.
6950 * This is a recursive function, TCG temps should be freed by the
6951 * calling function once it is done with the values.
6953 static TCGv_i32
do_reduction_op(DisasContext
*s
, int fpopcode
, int rn
,
6954 int esize
, int size
, int vmap
, TCGv_ptr fpst
)
6956 if (esize
== size
) {
6958 TCGMemOp msize
= esize
== 16 ? MO_16
: MO_32
;
6961 /* We should have one register left here */
6962 assert(ctpop8(vmap
) == 1);
6963 element
= ctz32(vmap
);
6964 assert(element
< 8);
6966 tcg_elem
= tcg_temp_new_i32();
6967 read_vec_element_i32(s
, tcg_elem
, rn
, element
, msize
);
6970 int bits
= size
/ 2;
6971 int shift
= ctpop8(vmap
) / 2;
6972 int vmap_lo
= (vmap
>> shift
) & vmap
;
6973 int vmap_hi
= (vmap
& ~vmap_lo
);
6974 TCGv_i32 tcg_hi
, tcg_lo
, tcg_res
;
6976 tcg_hi
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_hi
, fpst
);
6977 tcg_lo
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_lo
, fpst
);
6978 tcg_res
= tcg_temp_new_i32();
6981 case 0x0c: /* fmaxnmv half-precision */
6982 gen_helper_advsimd_maxnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6984 case 0x0f: /* fmaxv half-precision */
6985 gen_helper_advsimd_maxh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6987 case 0x1c: /* fminnmv half-precision */
6988 gen_helper_advsimd_minnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6990 case 0x1f: /* fminv half-precision */
6991 gen_helper_advsimd_minh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6993 case 0x2c: /* fmaxnmv */
6994 gen_helper_vfp_maxnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6996 case 0x2f: /* fmaxv */
6997 gen_helper_vfp_maxs(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6999 case 0x3c: /* fminnmv */
7000 gen_helper_vfp_minnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7002 case 0x3f: /* fminv */
7003 gen_helper_vfp_mins(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
7006 g_assert_not_reached();
7009 tcg_temp_free_i32(tcg_hi
);
7010 tcg_temp_free_i32(tcg_lo
);
7015 /* AdvSIMD across lanes
7016 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7017 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7018 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7019 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
7021 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
7023 int rd
= extract32(insn
, 0, 5);
7024 int rn
= extract32(insn
, 5, 5);
7025 int size
= extract32(insn
, 22, 2);
7026 int opcode
= extract32(insn
, 12, 5);
7027 bool is_q
= extract32(insn
, 30, 1);
7028 bool is_u
= extract32(insn
, 29, 1);
7030 bool is_min
= false;
7034 TCGv_i64 tcg_res
, tcg_elt
;
7037 case 0x1b: /* ADDV */
7039 unallocated_encoding(s
);
7043 case 0x3: /* SADDLV, UADDLV */
7044 case 0xa: /* SMAXV, UMAXV */
7045 case 0x1a: /* SMINV, UMINV */
7046 if (size
== 3 || (size
== 2 && !is_q
)) {
7047 unallocated_encoding(s
);
7051 case 0xc: /* FMAXNMV, FMINNMV */
7052 case 0xf: /* FMAXV, FMINV */
7053 /* Bit 1 of size field encodes min vs max and the actual size
7054 * depends on the encoding of the U bit. If not set (and FP16
7055 * enabled) then we do half-precision float instead of single
7058 is_min
= extract32(size
, 1, 1);
7060 if (!is_u
&& dc_isar_feature(aa64_fp16
, s
)) {
7062 } else if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
7063 unallocated_encoding(s
);
7070 unallocated_encoding(s
);
7074 if (!fp_access_check(s
)) {
7079 elements
= (is_q
? 128 : 64) / esize
;
7081 tcg_res
= tcg_temp_new_i64();
7082 tcg_elt
= tcg_temp_new_i64();
7084 /* These instructions operate across all lanes of a vector
7085 * to produce a single result. We can guarantee that a 64
7086 * bit intermediate is sufficient:
7087 * + for [US]ADDLV the maximum element size is 32 bits, and
7088 * the result type is 64 bits
7089 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
7090 * same as the element size, which is 32 bits at most
7091 * For the integer operations we can choose to work at 64
7092 * or 32 bits and truncate at the end; for simplicity
7093 * we use 64 bits always. The floating point
7094 * ops do require 32 bit intermediates, though.
7097 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
7099 for (i
= 1; i
< elements
; i
++) {
7100 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
7103 case 0x03: /* SADDLV / UADDLV */
7104 case 0x1b: /* ADDV */
7105 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
7107 case 0x0a: /* SMAXV / UMAXV */
7109 tcg_gen_umax_i64(tcg_res
, tcg_res
, tcg_elt
);
7111 tcg_gen_smax_i64(tcg_res
, tcg_res
, tcg_elt
);
7114 case 0x1a: /* SMINV / UMINV */
7116 tcg_gen_umin_i64(tcg_res
, tcg_res
, tcg_elt
);
7118 tcg_gen_smin_i64(tcg_res
, tcg_res
, tcg_elt
);
7122 g_assert_not_reached();
7127 /* Floating point vector reduction ops which work across 32
7128 * bit (single) or 16 bit (half-precision) intermediates.
7129 * Note that correct NaN propagation requires that we do these
7130 * operations in exactly the order specified by the pseudocode.
7132 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
7133 int fpopcode
= opcode
| is_min
<< 4 | is_u
<< 5;
7134 int vmap
= (1 << elements
) - 1;
7135 TCGv_i32 tcg_res32
= do_reduction_op(s
, fpopcode
, rn
, esize
,
7136 (is_q
? 128 : 64), vmap
, fpst
);
7137 tcg_gen_extu_i32_i64(tcg_res
, tcg_res32
);
7138 tcg_temp_free_i32(tcg_res32
);
7139 tcg_temp_free_ptr(fpst
);
7142 tcg_temp_free_i64(tcg_elt
);
7144 /* Now truncate the result to the width required for the final output */
7145 if (opcode
== 0x03) {
7146 /* SADDLV, UADDLV: result is 2*esize */
7152 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
7155 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
7158 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
7163 g_assert_not_reached();
7166 write_fp_dreg(s
, rd
, tcg_res
);
7167 tcg_temp_free_i64(tcg_res
);
7170 /* DUP (Element, Vector)
7172 * 31 30 29 21 20 16 15 10 9 5 4 0
7173 * +---+---+-------------------+--------+-------------+------+------+
7174 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7175 * +---+---+-------------------+--------+-------------+------+------+
7177 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7179 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
7182 int size
= ctz32(imm5
);
7183 int index
= imm5
>> (size
+ 1);
7185 if (size
> 3 || (size
== 3 && !is_q
)) {
7186 unallocated_encoding(s
);
7190 if (!fp_access_check(s
)) {
7194 tcg_gen_gvec_dup_mem(size
, vec_full_reg_offset(s
, rd
),
7195 vec_reg_offset(s
, rn
, index
, size
),
7196 is_q
? 16 : 8, vec_full_reg_size(s
));
7199 /* DUP (element, scalar)
7200 * 31 21 20 16 15 10 9 5 4 0
7201 * +-----------------------+--------+-------------+------+------+
7202 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
7203 * +-----------------------+--------+-------------+------+------+
7205 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
7208 int size
= ctz32(imm5
);
7213 unallocated_encoding(s
);
7217 if (!fp_access_check(s
)) {
7221 index
= imm5
>> (size
+ 1);
7223 /* This instruction just extracts the specified element and
7224 * zero-extends it into the bottom of the destination register.
7226 tmp
= tcg_temp_new_i64();
7227 read_vec_element(s
, tmp
, rn
, index
, size
);
7228 write_fp_dreg(s
, rd
, tmp
);
7229 tcg_temp_free_i64(tmp
);
7234 * 31 30 29 21 20 16 15 10 9 5 4 0
7235 * +---+---+-------------------+--------+-------------+------+------+
7236 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
7237 * +---+---+-------------------+--------+-------------+------+------+
7239 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7241 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
7244 int size
= ctz32(imm5
);
7245 uint32_t dofs
, oprsz
, maxsz
;
7247 if (size
> 3 || ((size
== 3) && !is_q
)) {
7248 unallocated_encoding(s
);
7252 if (!fp_access_check(s
)) {
7256 dofs
= vec_full_reg_offset(s
, rd
);
7257 oprsz
= is_q
? 16 : 8;
7258 maxsz
= vec_full_reg_size(s
);
7260 tcg_gen_gvec_dup_i64(size
, dofs
, oprsz
, maxsz
, cpu_reg(s
, rn
));
7265 * 31 21 20 16 15 14 11 10 9 5 4 0
7266 * +-----------------------+--------+------------+---+------+------+
7267 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7268 * +-----------------------+--------+------------+---+------+------+
7270 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7271 * index: encoded in imm5<4:size+1>
7273 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
7276 int size
= ctz32(imm5
);
7277 int src_index
, dst_index
;
7281 unallocated_encoding(s
);
7285 if (!fp_access_check(s
)) {
7289 dst_index
= extract32(imm5
, 1+size
, 5);
7290 src_index
= extract32(imm4
, size
, 4);
7292 tmp
= tcg_temp_new_i64();
7294 read_vec_element(s
, tmp
, rn
, src_index
, size
);
7295 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
7297 tcg_temp_free_i64(tmp
);
7303 * 31 21 20 16 15 10 9 5 4 0
7304 * +-----------------------+--------+-------------+------+------+
7305 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
7306 * +-----------------------+--------+-------------+------+------+
7308 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7309 * index: encoded in imm5<4:size+1>
7311 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
7313 int size
= ctz32(imm5
);
7317 unallocated_encoding(s
);
7321 if (!fp_access_check(s
)) {
7325 idx
= extract32(imm5
, 1 + size
, 4 - size
);
7326 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
7333 * 31 30 29 21 20 16 15 12 10 9 5 4 0
7334 * +---+---+-------------------+--------+-------------+------+------+
7335 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
7336 * +---+---+-------------------+--------+-------------+------+------+
7338 * U: unsigned when set
7339 * size: encoded in imm5 (see ARM ARM LowestSetBit())
7341 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
7342 int rn
, int rd
, int imm5
)
7344 int size
= ctz32(imm5
);
7348 /* Check for UnallocatedEncodings */
7350 if (size
> 2 || (size
== 2 && !is_q
)) {
7351 unallocated_encoding(s
);
7356 || (size
< 3 && is_q
)
7357 || (size
== 3 && !is_q
)) {
7358 unallocated_encoding(s
);
7363 if (!fp_access_check(s
)) {
7367 element
= extract32(imm5
, 1+size
, 4);
7369 tcg_rd
= cpu_reg(s
, rd
);
7370 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
7371 if (is_signed
&& !is_q
) {
7372 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
7377 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7378 * +---+---+----+-----------------+------+---+------+---+------+------+
7379 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7380 * +---+---+----+-----------------+------+---+------+---+------+------+
7382 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
7384 int rd
= extract32(insn
, 0, 5);
7385 int rn
= extract32(insn
, 5, 5);
7386 int imm4
= extract32(insn
, 11, 4);
7387 int op
= extract32(insn
, 29, 1);
7388 int is_q
= extract32(insn
, 30, 1);
7389 int imm5
= extract32(insn
, 16, 5);
7394 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
7396 unallocated_encoding(s
);
7401 /* DUP (element - vector) */
7402 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
7406 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
7411 handle_simd_insg(s
, rd
, rn
, imm5
);
7413 unallocated_encoding(s
);
7418 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
7419 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
7422 unallocated_encoding(s
);
7428 /* AdvSIMD modified immediate
7429 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
7430 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7431 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
7432 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
7434 * There are a number of operations that can be carried out here:
7435 * MOVI - move (shifted) imm into register
7436 * MVNI - move inverted (shifted) imm into register
7437 * ORR - bitwise OR of (shifted) imm with register
7438 * BIC - bitwise clear of (shifted) imm with register
7439 * With ARMv8.2 we also have:
7440 * FMOV half-precision
7442 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
7444 int rd
= extract32(insn
, 0, 5);
7445 int cmode
= extract32(insn
, 12, 4);
7446 int cmode_3_1
= extract32(cmode
, 1, 3);
7447 int cmode_0
= extract32(cmode
, 0, 1);
7448 int o2
= extract32(insn
, 11, 1);
7449 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
7450 bool is_neg
= extract32(insn
, 29, 1);
7451 bool is_q
= extract32(insn
, 30, 1);
7454 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
7455 /* Check for FMOV (vector, immediate) - half-precision */
7456 if (!(dc_isar_feature(aa64_fp16
, s
) && o2
&& cmode
== 0xf)) {
7457 unallocated_encoding(s
);
7462 if (!fp_access_check(s
)) {
7466 /* See AdvSIMDExpandImm() in ARM ARM */
7467 switch (cmode_3_1
) {
7468 case 0: /* Replicate(Zeros(24):imm8, 2) */
7469 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
7470 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
7471 case 3: /* Replicate(imm8:Zeros(24), 2) */
7473 int shift
= cmode_3_1
* 8;
7474 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
7477 case 4: /* Replicate(Zeros(8):imm8, 4) */
7478 case 5: /* Replicate(imm8:Zeros(8), 4) */
7480 int shift
= (cmode_3_1
& 0x1) * 8;
7481 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
7486 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
7487 imm
= (abcdefgh
<< 16) | 0xffff;
7489 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
7490 imm
= (abcdefgh
<< 8) | 0xff;
7492 imm
= bitfield_replicate(imm
, 32);
7495 if (!cmode_0
&& !is_neg
) {
7496 imm
= bitfield_replicate(abcdefgh
, 8);
7497 } else if (!cmode_0
&& is_neg
) {
7500 for (i
= 0; i
< 8; i
++) {
7501 if ((abcdefgh
) & (1 << i
)) {
7502 imm
|= 0xffULL
<< (i
* 8);
7505 } else if (cmode_0
) {
7507 imm
= (abcdefgh
& 0x3f) << 48;
7508 if (abcdefgh
& 0x80) {
7509 imm
|= 0x8000000000000000ULL
;
7511 if (abcdefgh
& 0x40) {
7512 imm
|= 0x3fc0000000000000ULL
;
7514 imm
|= 0x4000000000000000ULL
;
7518 /* FMOV (vector, immediate) - half-precision */
7519 imm
= vfp_expand_imm(MO_16
, abcdefgh
);
7520 /* now duplicate across the lanes */
7521 imm
= bitfield_replicate(imm
, 16);
7523 imm
= (abcdefgh
& 0x3f) << 19;
7524 if (abcdefgh
& 0x80) {
7527 if (abcdefgh
& 0x40) {
7538 fprintf(stderr
, "%s: cmode_3_1: %x\n", __func__
, cmode_3_1
);
7539 g_assert_not_reached();
7542 if (cmode_3_1
!= 7 && is_neg
) {
7546 if (!((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9)) {
7547 /* MOVI or MVNI, with MVNI negation handled above. */
7548 tcg_gen_gvec_dup64i(vec_full_reg_offset(s
, rd
), is_q
? 16 : 8,
7549 vec_full_reg_size(s
), imm
);
7551 /* ORR or BIC, with BIC negation to AND handled above. */
7553 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_andi
, MO_64
);
7555 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_ori
, MO_64
);
7560 /* AdvSIMD scalar copy
7561 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7562 * +-----+----+-----------------+------+---+------+---+------+------+
7563 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7564 * +-----+----+-----------------+------+---+------+---+------+------+
7566 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
7568 int rd
= extract32(insn
, 0, 5);
7569 int rn
= extract32(insn
, 5, 5);
7570 int imm4
= extract32(insn
, 11, 4);
7571 int imm5
= extract32(insn
, 16, 5);
7572 int op
= extract32(insn
, 29, 1);
7574 if (op
!= 0 || imm4
!= 0) {
7575 unallocated_encoding(s
);
7579 /* DUP (element, scalar) */
7580 handle_simd_dupes(s
, rd
, rn
, imm5
);
7583 /* AdvSIMD scalar pairwise
7584 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7585 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7586 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7587 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7589 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
7591 int u
= extract32(insn
, 29, 1);
7592 int size
= extract32(insn
, 22, 2);
7593 int opcode
= extract32(insn
, 12, 5);
7594 int rn
= extract32(insn
, 5, 5);
7595 int rd
= extract32(insn
, 0, 5);
7598 /* For some ops (the FP ones), size[1] is part of the encoding.
7599 * For ADDP strictly it is not but size[1] is always 1 for valid
7602 opcode
|= (extract32(size
, 1, 1) << 5);
7605 case 0x3b: /* ADDP */
7606 if (u
|| size
!= 3) {
7607 unallocated_encoding(s
);
7610 if (!fp_access_check(s
)) {
7616 case 0xc: /* FMAXNMP */
7617 case 0xd: /* FADDP */
7618 case 0xf: /* FMAXP */
7619 case 0x2c: /* FMINNMP */
7620 case 0x2f: /* FMINP */
7621 /* FP op, size[0] is 32 or 64 bit*/
7623 if (!dc_isar_feature(aa64_fp16
, s
)) {
7624 unallocated_encoding(s
);
7630 size
= extract32(size
, 0, 1) ? MO_64
: MO_32
;
7633 if (!fp_access_check(s
)) {
7637 fpst
= get_fpstatus_ptr(size
== MO_16
);
7640 unallocated_encoding(s
);
7644 if (size
== MO_64
) {
7645 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7646 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7647 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7649 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
7650 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
7653 case 0x3b: /* ADDP */
7654 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
7656 case 0xc: /* FMAXNMP */
7657 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7659 case 0xd: /* FADDP */
7660 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7662 case 0xf: /* FMAXP */
7663 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7665 case 0x2c: /* FMINNMP */
7666 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7668 case 0x2f: /* FMINP */
7669 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7672 g_assert_not_reached();
7675 write_fp_dreg(s
, rd
, tcg_res
);
7677 tcg_temp_free_i64(tcg_op1
);
7678 tcg_temp_free_i64(tcg_op2
);
7679 tcg_temp_free_i64(tcg_res
);
7681 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7682 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7683 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7685 read_vec_element_i32(s
, tcg_op1
, rn
, 0, size
);
7686 read_vec_element_i32(s
, tcg_op2
, rn
, 1, size
);
7688 if (size
== MO_16
) {
7690 case 0xc: /* FMAXNMP */
7691 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7693 case 0xd: /* FADDP */
7694 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7696 case 0xf: /* FMAXP */
7697 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7699 case 0x2c: /* FMINNMP */
7700 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7702 case 0x2f: /* FMINP */
7703 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7706 g_assert_not_reached();
7710 case 0xc: /* FMAXNMP */
7711 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7713 case 0xd: /* FADDP */
7714 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7716 case 0xf: /* FMAXP */
7717 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7719 case 0x2c: /* FMINNMP */
7720 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7722 case 0x2f: /* FMINP */
7723 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7726 g_assert_not_reached();
7730 write_fp_sreg(s
, rd
, tcg_res
);
7732 tcg_temp_free_i32(tcg_op1
);
7733 tcg_temp_free_i32(tcg_op2
);
7734 tcg_temp_free_i32(tcg_res
);
7738 tcg_temp_free_ptr(fpst
);
7743 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
7745 * This code is handles the common shifting code and is used by both
7746 * the vector and scalar code.
7748 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
7749 TCGv_i64 tcg_rnd
, bool accumulate
,
7750 bool is_u
, int size
, int shift
)
7752 bool extended_result
= false;
7753 bool round
= tcg_rnd
!= NULL
;
7755 TCGv_i64 tcg_src_hi
;
7757 if (round
&& size
== 3) {
7758 extended_result
= true;
7759 ext_lshift
= 64 - shift
;
7760 tcg_src_hi
= tcg_temp_new_i64();
7761 } else if (shift
== 64) {
7762 if (!accumulate
&& is_u
) {
7763 /* result is zero */
7764 tcg_gen_movi_i64(tcg_res
, 0);
7769 /* Deal with the rounding step */
7771 if (extended_result
) {
7772 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7774 /* take care of sign extending tcg_res */
7775 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
7776 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7777 tcg_src
, tcg_src_hi
,
7780 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7784 tcg_temp_free_i64(tcg_zero
);
7786 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
7790 /* Now do the shift right */
7791 if (round
&& extended_result
) {
7792 /* extended case, >64 bit precision required */
7793 if (ext_lshift
== 0) {
7794 /* special case, only high bits matter */
7795 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
7797 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7798 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
7799 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
7804 /* essentially shifting in 64 zeros */
7805 tcg_gen_movi_i64(tcg_src
, 0);
7807 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7811 /* effectively extending the sign-bit */
7812 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
7814 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
7820 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
7822 tcg_gen_mov_i64(tcg_res
, tcg_src
);
7825 if (extended_result
) {
7826 tcg_temp_free_i64(tcg_src_hi
);
7830 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
7831 static void handle_scalar_simd_shri(DisasContext
*s
,
7832 bool is_u
, int immh
, int immb
,
7833 int opcode
, int rn
, int rd
)
7836 int immhb
= immh
<< 3 | immb
;
7837 int shift
= 2 * (8 << size
) - immhb
;
7838 bool accumulate
= false;
7840 bool insert
= false;
7845 if (!extract32(immh
, 3, 1)) {
7846 unallocated_encoding(s
);
7850 if (!fp_access_check(s
)) {
7855 case 0x02: /* SSRA / USRA (accumulate) */
7858 case 0x04: /* SRSHR / URSHR (rounding) */
7861 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7862 accumulate
= round
= true;
7864 case 0x08: /* SRI */
7870 uint64_t round_const
= 1ULL << (shift
- 1);
7871 tcg_round
= tcg_const_i64(round_const
);
7876 tcg_rn
= read_fp_dreg(s
, rn
);
7877 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
7880 /* shift count same as element size is valid but does nothing;
7881 * special case to avoid potential shift by 64.
7883 int esize
= 8 << size
;
7884 if (shift
!= esize
) {
7885 tcg_gen_shri_i64(tcg_rn
, tcg_rn
, shift
);
7886 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, 0, esize
- shift
);
7889 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
7890 accumulate
, is_u
, size
, shift
);
7893 write_fp_dreg(s
, rd
, tcg_rd
);
7895 tcg_temp_free_i64(tcg_rn
);
7896 tcg_temp_free_i64(tcg_rd
);
7898 tcg_temp_free_i64(tcg_round
);
7902 /* SHL/SLI - Scalar shift left */
7903 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
7904 int immh
, int immb
, int opcode
,
7907 int size
= 32 - clz32(immh
) - 1;
7908 int immhb
= immh
<< 3 | immb
;
7909 int shift
= immhb
- (8 << size
);
7910 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
7911 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
7913 if (!extract32(immh
, 3, 1)) {
7914 unallocated_encoding(s
);
7918 if (!fp_access_check(s
)) {
7922 tcg_rn
= read_fp_dreg(s
, rn
);
7923 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
7926 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, shift
, 64 - shift
);
7928 tcg_gen_shli_i64(tcg_rd
, tcg_rn
, shift
);
7931 write_fp_dreg(s
, rd
, tcg_rd
);
7933 tcg_temp_free_i64(tcg_rn
);
7934 tcg_temp_free_i64(tcg_rd
);
7937 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
7938 * (signed/unsigned) narrowing */
7939 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
7940 bool is_u_shift
, bool is_u_narrow
,
7941 int immh
, int immb
, int opcode
,
7944 int immhb
= immh
<< 3 | immb
;
7945 int size
= 32 - clz32(immh
) - 1;
7946 int esize
= 8 << size
;
7947 int shift
= (2 * esize
) - immhb
;
7948 int elements
= is_scalar
? 1 : (64 / esize
);
7949 bool round
= extract32(opcode
, 0, 1);
7950 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
7951 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
7952 TCGv_i32 tcg_rd_narrowed
;
7955 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
7956 { gen_helper_neon_narrow_sat_s8
,
7957 gen_helper_neon_unarrow_sat8
},
7958 { gen_helper_neon_narrow_sat_s16
,
7959 gen_helper_neon_unarrow_sat16
},
7960 { gen_helper_neon_narrow_sat_s32
,
7961 gen_helper_neon_unarrow_sat32
},
7964 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
7965 gen_helper_neon_narrow_sat_u8
,
7966 gen_helper_neon_narrow_sat_u16
,
7967 gen_helper_neon_narrow_sat_u32
,
7970 NeonGenNarrowEnvFn
*narrowfn
;
7976 if (extract32(immh
, 3, 1)) {
7977 unallocated_encoding(s
);
7981 if (!fp_access_check(s
)) {
7986 narrowfn
= unsigned_narrow_fns
[size
];
7988 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
7991 tcg_rn
= tcg_temp_new_i64();
7992 tcg_rd
= tcg_temp_new_i64();
7993 tcg_rd_narrowed
= tcg_temp_new_i32();
7994 tcg_final
= tcg_const_i64(0);
7997 uint64_t round_const
= 1ULL << (shift
- 1);
7998 tcg_round
= tcg_const_i64(round_const
);
8003 for (i
= 0; i
< elements
; i
++) {
8004 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
8005 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8006 false, is_u_shift
, size
+1, shift
);
8007 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
8008 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
8009 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8013 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8015 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8019 tcg_temp_free_i64(tcg_round
);
8021 tcg_temp_free_i64(tcg_rn
);
8022 tcg_temp_free_i64(tcg_rd
);
8023 tcg_temp_free_i32(tcg_rd_narrowed
);
8024 tcg_temp_free_i64(tcg_final
);
8026 clear_vec_high(s
, is_q
, rd
);
8029 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
8030 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
8031 bool src_unsigned
, bool dst_unsigned
,
8032 int immh
, int immb
, int rn
, int rd
)
8034 int immhb
= immh
<< 3 | immb
;
8035 int size
= 32 - clz32(immh
) - 1;
8036 int shift
= immhb
- (8 << size
);
8040 assert(!(scalar
&& is_q
));
8043 if (!is_q
&& extract32(immh
, 3, 1)) {
8044 unallocated_encoding(s
);
8048 /* Since we use the variable-shift helpers we must
8049 * replicate the shift count into each element of
8050 * the tcg_shift value.
8054 shift
|= shift
<< 8;
8057 shift
|= shift
<< 16;
8063 g_assert_not_reached();
8067 if (!fp_access_check(s
)) {
8072 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
8073 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
8074 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
8075 { NULL
, gen_helper_neon_qshl_u64
},
8077 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
8078 int maxpass
= is_q
? 2 : 1;
8080 for (pass
= 0; pass
< maxpass
; pass
++) {
8081 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8083 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8084 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8085 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
8087 tcg_temp_free_i64(tcg_op
);
8089 tcg_temp_free_i64(tcg_shift
);
8090 clear_vec_high(s
, is_q
, rd
);
8092 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
8093 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
8095 { gen_helper_neon_qshl_s8
,
8096 gen_helper_neon_qshl_s16
,
8097 gen_helper_neon_qshl_s32
},
8098 { gen_helper_neon_qshlu_s8
,
8099 gen_helper_neon_qshlu_s16
,
8100 gen_helper_neon_qshlu_s32
}
8102 { NULL
, NULL
, NULL
},
8103 { gen_helper_neon_qshl_u8
,
8104 gen_helper_neon_qshl_u16
,
8105 gen_helper_neon_qshl_u32
}
8108 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
8109 TCGMemOp memop
= scalar
? size
: MO_32
;
8110 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
8112 for (pass
= 0; pass
< maxpass
; pass
++) {
8113 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8115 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
8116 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
8120 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
8123 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
8128 g_assert_not_reached();
8130 write_fp_sreg(s
, rd
, tcg_op
);
8132 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
8135 tcg_temp_free_i32(tcg_op
);
8137 tcg_temp_free_i32(tcg_shift
);
8140 clear_vec_high(s
, is_q
, rd
);
8145 /* Common vector code for handling integer to FP conversion */
8146 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
8147 int elements
, int is_signed
,
8148 int fracbits
, int size
)
8150 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(size
== MO_16
);
8151 TCGv_i32 tcg_shift
= NULL
;
8153 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
8156 if (fracbits
|| size
== MO_64
) {
8157 tcg_shift
= tcg_const_i32(fracbits
);
8160 if (size
== MO_64
) {
8161 TCGv_i64 tcg_int64
= tcg_temp_new_i64();
8162 TCGv_i64 tcg_double
= tcg_temp_new_i64();
8164 for (pass
= 0; pass
< elements
; pass
++) {
8165 read_vec_element(s
, tcg_int64
, rn
, pass
, mop
);
8168 gen_helper_vfp_sqtod(tcg_double
, tcg_int64
,
8169 tcg_shift
, tcg_fpst
);
8171 gen_helper_vfp_uqtod(tcg_double
, tcg_int64
,
8172 tcg_shift
, tcg_fpst
);
8174 if (elements
== 1) {
8175 write_fp_dreg(s
, rd
, tcg_double
);
8177 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
8181 tcg_temp_free_i64(tcg_int64
);
8182 tcg_temp_free_i64(tcg_double
);
8185 TCGv_i32 tcg_int32
= tcg_temp_new_i32();
8186 TCGv_i32 tcg_float
= tcg_temp_new_i32();
8188 for (pass
= 0; pass
< elements
; pass
++) {
8189 read_vec_element_i32(s
, tcg_int32
, rn
, pass
, mop
);
8195 gen_helper_vfp_sltos(tcg_float
, tcg_int32
,
8196 tcg_shift
, tcg_fpst
);
8198 gen_helper_vfp_ultos(tcg_float
, tcg_int32
,
8199 tcg_shift
, tcg_fpst
);
8203 gen_helper_vfp_sitos(tcg_float
, tcg_int32
, tcg_fpst
);
8205 gen_helper_vfp_uitos(tcg_float
, tcg_int32
, tcg_fpst
);
8212 gen_helper_vfp_sltoh(tcg_float
, tcg_int32
,
8213 tcg_shift
, tcg_fpst
);
8215 gen_helper_vfp_ultoh(tcg_float
, tcg_int32
,
8216 tcg_shift
, tcg_fpst
);
8220 gen_helper_vfp_sitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8222 gen_helper_vfp_uitoh(tcg_float
, tcg_int32
, tcg_fpst
);
8227 g_assert_not_reached();
8230 if (elements
== 1) {
8231 write_fp_sreg(s
, rd
, tcg_float
);
8233 write_vec_element_i32(s
, tcg_float
, rd
, pass
, size
);
8237 tcg_temp_free_i32(tcg_int32
);
8238 tcg_temp_free_i32(tcg_float
);
8241 tcg_temp_free_ptr(tcg_fpst
);
8243 tcg_temp_free_i32(tcg_shift
);
8246 clear_vec_high(s
, elements
<< size
== 16, rd
);
8249 /* UCVTF/SCVTF - Integer to FP conversion */
8250 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
8251 bool is_q
, bool is_u
,
8252 int immh
, int immb
, int opcode
,
8255 int size
, elements
, fracbits
;
8256 int immhb
= immh
<< 3 | immb
;
8260 if (!is_scalar
&& !is_q
) {
8261 unallocated_encoding(s
);
8264 } else if (immh
& 4) {
8266 } else if (immh
& 2) {
8268 if (!dc_isar_feature(aa64_fp16
, s
)) {
8269 unallocated_encoding(s
);
8273 /* immh == 0 would be a failure of the decode logic */
8274 g_assert(immh
== 1);
8275 unallocated_encoding(s
);
8282 elements
= (8 << is_q
) >> size
;
8284 fracbits
= (16 << size
) - immhb
;
8286 if (!fp_access_check(s
)) {
8290 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
8293 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
8294 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
8295 bool is_q
, bool is_u
,
8296 int immh
, int immb
, int rn
, int rd
)
8298 int immhb
= immh
<< 3 | immb
;
8299 int pass
, size
, fracbits
;
8300 TCGv_ptr tcg_fpstatus
;
8301 TCGv_i32 tcg_rmode
, tcg_shift
;
8305 if (!is_scalar
&& !is_q
) {
8306 unallocated_encoding(s
);
8309 } else if (immh
& 0x4) {
8311 } else if (immh
& 0x2) {
8313 if (!dc_isar_feature(aa64_fp16
, s
)) {
8314 unallocated_encoding(s
);
8318 /* Should have split out AdvSIMD modified immediate earlier. */
8320 unallocated_encoding(s
);
8324 if (!fp_access_check(s
)) {
8328 assert(!(is_scalar
&& is_q
));
8330 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
8331 tcg_fpstatus
= get_fpstatus_ptr(size
== MO_16
);
8332 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
8333 fracbits
= (16 << size
) - immhb
;
8334 tcg_shift
= tcg_const_i32(fracbits
);
8336 if (size
== MO_64
) {
8337 int maxpass
= is_scalar
? 1 : 2;
8339 for (pass
= 0; pass
< maxpass
; pass
++) {
8340 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8342 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8344 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8346 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8348 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
8349 tcg_temp_free_i64(tcg_op
);
8351 clear_vec_high(s
, is_q
, rd
);
8353 void (*fn
)(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
8354 int maxpass
= is_scalar
? 1 : ((8 << is_q
) >> size
);
8359 fn
= gen_helper_vfp_touhh
;
8361 fn
= gen_helper_vfp_toshh
;
8366 fn
= gen_helper_vfp_touls
;
8368 fn
= gen_helper_vfp_tosls
;
8372 g_assert_not_reached();
8375 for (pass
= 0; pass
< maxpass
; pass
++) {
8376 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8378 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
8379 fn(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
8381 write_fp_sreg(s
, rd
, tcg_op
);
8383 write_vec_element_i32(s
, tcg_op
, rd
, pass
, size
);
8385 tcg_temp_free_i32(tcg_op
);
8388 clear_vec_high(s
, is_q
, rd
);
8392 tcg_temp_free_ptr(tcg_fpstatus
);
8393 tcg_temp_free_i32(tcg_shift
);
8394 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
8395 tcg_temp_free_i32(tcg_rmode
);
8398 /* AdvSIMD scalar shift by immediate
8399 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8400 * +-----+---+-------------+------+------+--------+---+------+------+
8401 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8402 * +-----+---+-------------+------+------+--------+---+------+------+
8404 * This is the scalar version so it works on a fixed sized registers
8406 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
8408 int rd
= extract32(insn
, 0, 5);
8409 int rn
= extract32(insn
, 5, 5);
8410 int opcode
= extract32(insn
, 11, 5);
8411 int immb
= extract32(insn
, 16, 3);
8412 int immh
= extract32(insn
, 19, 4);
8413 bool is_u
= extract32(insn
, 29, 1);
8416 unallocated_encoding(s
);
8421 case 0x08: /* SRI */
8423 unallocated_encoding(s
);
8427 case 0x00: /* SSHR / USHR */
8428 case 0x02: /* SSRA / USRA */
8429 case 0x04: /* SRSHR / URSHR */
8430 case 0x06: /* SRSRA / URSRA */
8431 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8433 case 0x0a: /* SHL / SLI */
8434 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8436 case 0x1c: /* SCVTF, UCVTF */
8437 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
8440 case 0x10: /* SQSHRUN, SQSHRUN2 */
8441 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
8443 unallocated_encoding(s
);
8446 handle_vec_simd_sqshrn(s
, true, false, false, true,
8447 immh
, immb
, opcode
, rn
, rd
);
8449 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
8450 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
8451 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
8452 immh
, immb
, opcode
, rn
, rd
);
8454 case 0xc: /* SQSHLU */
8456 unallocated_encoding(s
);
8459 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
8461 case 0xe: /* SQSHL, UQSHL */
8462 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
8464 case 0x1f: /* FCVTZS, FCVTZU */
8465 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
8468 unallocated_encoding(s
);
8473 /* AdvSIMD scalar three different
8474 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8475 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8476 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8477 * +-----+---+-----------+------+---+------+--------+-----+------+------+
8479 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8481 bool is_u
= extract32(insn
, 29, 1);
8482 int size
= extract32(insn
, 22, 2);
8483 int opcode
= extract32(insn
, 12, 4);
8484 int rm
= extract32(insn
, 16, 5);
8485 int rn
= extract32(insn
, 5, 5);
8486 int rd
= extract32(insn
, 0, 5);
8489 unallocated_encoding(s
);
8494 case 0x9: /* SQDMLAL, SQDMLAL2 */
8495 case 0xb: /* SQDMLSL, SQDMLSL2 */
8496 case 0xd: /* SQDMULL, SQDMULL2 */
8497 if (size
== 0 || size
== 3) {
8498 unallocated_encoding(s
);
8503 unallocated_encoding(s
);
8507 if (!fp_access_check(s
)) {
8512 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8513 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8514 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8516 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
8517 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
8519 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
8520 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
8523 case 0xd: /* SQDMULL, SQDMULL2 */
8525 case 0xb: /* SQDMLSL, SQDMLSL2 */
8526 tcg_gen_neg_i64(tcg_res
, tcg_res
);
8528 case 0x9: /* SQDMLAL, SQDMLAL2 */
8529 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
8530 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
8534 g_assert_not_reached();
8537 write_fp_dreg(s
, rd
, tcg_res
);
8539 tcg_temp_free_i64(tcg_op1
);
8540 tcg_temp_free_i64(tcg_op2
);
8541 tcg_temp_free_i64(tcg_res
);
8543 TCGv_i32 tcg_op1
= read_fp_hreg(s
, rn
);
8544 TCGv_i32 tcg_op2
= read_fp_hreg(s
, rm
);
8545 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8547 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
8548 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
8551 case 0xd: /* SQDMULL, SQDMULL2 */
8553 case 0xb: /* SQDMLSL, SQDMLSL2 */
8554 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
8556 case 0x9: /* SQDMLAL, SQDMLAL2 */
8558 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
8559 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
8560 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
8562 tcg_temp_free_i64(tcg_op3
);
8566 g_assert_not_reached();
8569 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
8570 write_fp_dreg(s
, rd
, tcg_res
);
8572 tcg_temp_free_i32(tcg_op1
);
8573 tcg_temp_free_i32(tcg_op2
);
8574 tcg_temp_free_i64(tcg_res
);
8578 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
8579 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
8581 /* Handle 64x64->64 opcodes which are shared between the scalar
8582 * and vector 3-same groups. We cover every opcode where size == 3
8583 * is valid in either the three-reg-same (integer, not pairwise)
8584 * or scalar-three-reg-same groups.
8589 case 0x1: /* SQADD */
8591 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8593 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8596 case 0x5: /* SQSUB */
8598 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8600 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8603 case 0x6: /* CMGT, CMHI */
8604 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
8605 * We implement this using setcond (test) and then negating.
8607 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
8609 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
8610 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
8612 case 0x7: /* CMGE, CMHS */
8613 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
8615 case 0x11: /* CMTST, CMEQ */
8620 gen_cmtst_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8622 case 0x8: /* SSHL, USHL */
8624 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8626 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8629 case 0x9: /* SQSHL, UQSHL */
8631 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8633 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8636 case 0xa: /* SRSHL, URSHL */
8638 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8640 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8643 case 0xb: /* SQRSHL, UQRSHL */
8645 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8647 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8650 case 0x10: /* ADD, SUB */
8652 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8654 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8658 g_assert_not_reached();
8662 /* Handle the 3-same-operands float operations; shared by the scalar
8663 * and vector encodings. The caller must filter out any encodings
8664 * not allocated for the encoding it is dealing with.
8666 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
8667 int fpopcode
, int rd
, int rn
, int rm
)
8670 TCGv_ptr fpst
= get_fpstatus_ptr(false);
8672 for (pass
= 0; pass
< elements
; pass
++) {
8675 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8676 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8677 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8679 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8680 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8683 case 0x39: /* FMLS */
8684 /* As usual for ARM, separate negation for fused multiply-add */
8685 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
8687 case 0x19: /* FMLA */
8688 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8689 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
8692 case 0x18: /* FMAXNM */
8693 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8695 case 0x1a: /* FADD */
8696 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8698 case 0x1b: /* FMULX */
8699 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8701 case 0x1c: /* FCMEQ */
8702 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8704 case 0x1e: /* FMAX */
8705 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8707 case 0x1f: /* FRECPS */
8708 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8710 case 0x38: /* FMINNM */
8711 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8713 case 0x3a: /* FSUB */
8714 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8716 case 0x3e: /* FMIN */
8717 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8719 case 0x3f: /* FRSQRTS */
8720 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8722 case 0x5b: /* FMUL */
8723 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8725 case 0x5c: /* FCMGE */
8726 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8728 case 0x5d: /* FACGE */
8729 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8731 case 0x5f: /* FDIV */
8732 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8734 case 0x7a: /* FABD */
8735 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8736 gen_helper_vfp_absd(tcg_res
, tcg_res
);
8738 case 0x7c: /* FCMGT */
8739 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8741 case 0x7d: /* FACGT */
8742 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8745 g_assert_not_reached();
8748 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8750 tcg_temp_free_i64(tcg_res
);
8751 tcg_temp_free_i64(tcg_op1
);
8752 tcg_temp_free_i64(tcg_op2
);
8755 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8756 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8757 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8759 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
8760 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
8763 case 0x39: /* FMLS */
8764 /* As usual for ARM, separate negation for fused multiply-add */
8765 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
8767 case 0x19: /* FMLA */
8768 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8769 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
8772 case 0x1a: /* FADD */
8773 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8775 case 0x1b: /* FMULX */
8776 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8778 case 0x1c: /* FCMEQ */
8779 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8781 case 0x1e: /* FMAX */
8782 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8784 case 0x1f: /* FRECPS */
8785 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8787 case 0x18: /* FMAXNM */
8788 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8790 case 0x38: /* FMINNM */
8791 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8793 case 0x3a: /* FSUB */
8794 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8796 case 0x3e: /* FMIN */
8797 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8799 case 0x3f: /* FRSQRTS */
8800 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8802 case 0x5b: /* FMUL */
8803 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8805 case 0x5c: /* FCMGE */
8806 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8808 case 0x5d: /* FACGE */
8809 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8811 case 0x5f: /* FDIV */
8812 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8814 case 0x7a: /* FABD */
8815 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8816 gen_helper_vfp_abss(tcg_res
, tcg_res
);
8818 case 0x7c: /* FCMGT */
8819 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8821 case 0x7d: /* FACGT */
8822 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8825 g_assert_not_reached();
8828 if (elements
== 1) {
8829 /* scalar single so clear high part */
8830 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
8832 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
8833 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
8834 tcg_temp_free_i64(tcg_tmp
);
8836 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8839 tcg_temp_free_i32(tcg_res
);
8840 tcg_temp_free_i32(tcg_op1
);
8841 tcg_temp_free_i32(tcg_op2
);
8845 tcg_temp_free_ptr(fpst
);
8847 clear_vec_high(s
, elements
* (size
? 8 : 4) > 8, rd
);
8850 /* AdvSIMD scalar three same
8851 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8852 * +-----+---+-----------+------+---+------+--------+---+------+------+
8853 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8854 * +-----+---+-----------+------+---+------+--------+---+------+------+
8856 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
8858 int rd
= extract32(insn
, 0, 5);
8859 int rn
= extract32(insn
, 5, 5);
8860 int opcode
= extract32(insn
, 11, 5);
8861 int rm
= extract32(insn
, 16, 5);
8862 int size
= extract32(insn
, 22, 2);
8863 bool u
= extract32(insn
, 29, 1);
8866 if (opcode
>= 0x18) {
8867 /* Floating point: U, size[1] and opcode indicate operation */
8868 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
8870 case 0x1b: /* FMULX */
8871 case 0x1f: /* FRECPS */
8872 case 0x3f: /* FRSQRTS */
8873 case 0x5d: /* FACGE */
8874 case 0x7d: /* FACGT */
8875 case 0x1c: /* FCMEQ */
8876 case 0x5c: /* FCMGE */
8877 case 0x7c: /* FCMGT */
8878 case 0x7a: /* FABD */
8881 unallocated_encoding(s
);
8885 if (!fp_access_check(s
)) {
8889 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
8894 case 0x1: /* SQADD, UQADD */
8895 case 0x5: /* SQSUB, UQSUB */
8896 case 0x9: /* SQSHL, UQSHL */
8897 case 0xb: /* SQRSHL, UQRSHL */
8899 case 0x8: /* SSHL, USHL */
8900 case 0xa: /* SRSHL, URSHL */
8901 case 0x6: /* CMGT, CMHI */
8902 case 0x7: /* CMGE, CMHS */
8903 case 0x11: /* CMTST, CMEQ */
8904 case 0x10: /* ADD, SUB (vector) */
8906 unallocated_encoding(s
);
8910 case 0x16: /* SQDMULH, SQRDMULH (vector) */
8911 if (size
!= 1 && size
!= 2) {
8912 unallocated_encoding(s
);
8917 unallocated_encoding(s
);
8921 if (!fp_access_check(s
)) {
8925 tcg_rd
= tcg_temp_new_i64();
8928 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
8929 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
8931 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
8932 tcg_temp_free_i64(tcg_rn
);
8933 tcg_temp_free_i64(tcg_rm
);
8935 /* Do a single operation on the lowest element in the vector.
8936 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
8937 * no side effects for all these operations.
8938 * OPTME: special-purpose helpers would avoid doing some
8939 * unnecessary work in the helper for the 8 and 16 bit cases.
8941 NeonGenTwoOpEnvFn
*genenvfn
;
8942 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
8943 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
8944 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
8946 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
8947 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
8950 case 0x1: /* SQADD, UQADD */
8952 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8953 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
8954 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
8955 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
8957 genenvfn
= fns
[size
][u
];
8960 case 0x5: /* SQSUB, UQSUB */
8962 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8963 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
8964 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
8965 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
8967 genenvfn
= fns
[size
][u
];
8970 case 0x9: /* SQSHL, UQSHL */
8972 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8973 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
8974 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
8975 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
8977 genenvfn
= fns
[size
][u
];
8980 case 0xb: /* SQRSHL, UQRSHL */
8982 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8983 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
8984 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
8985 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
8987 genenvfn
= fns
[size
][u
];
8990 case 0x16: /* SQDMULH, SQRDMULH */
8992 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
8993 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
8994 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
8996 assert(size
== 1 || size
== 2);
8997 genenvfn
= fns
[size
- 1][u
];
9001 g_assert_not_reached();
9004 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
9005 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
9006 tcg_temp_free_i32(tcg_rd32
);
9007 tcg_temp_free_i32(tcg_rn
);
9008 tcg_temp_free_i32(tcg_rm
);
9011 write_fp_dreg(s
, rd
, tcg_rd
);
9013 tcg_temp_free_i64(tcg_rd
);
9016 /* AdvSIMD scalar three same FP16
9017 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
9018 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9019 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
9020 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
9021 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
9022 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
9024 static void disas_simd_scalar_three_reg_same_fp16(DisasContext
*s
,
9027 int rd
= extract32(insn
, 0, 5);
9028 int rn
= extract32(insn
, 5, 5);
9029 int opcode
= extract32(insn
, 11, 3);
9030 int rm
= extract32(insn
, 16, 5);
9031 bool u
= extract32(insn
, 29, 1);
9032 bool a
= extract32(insn
, 23, 1);
9033 int fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
9040 case 0x03: /* FMULX */
9041 case 0x04: /* FCMEQ (reg) */
9042 case 0x07: /* FRECPS */
9043 case 0x0f: /* FRSQRTS */
9044 case 0x14: /* FCMGE (reg) */
9045 case 0x15: /* FACGE */
9046 case 0x1a: /* FABD */
9047 case 0x1c: /* FCMGT (reg) */
9048 case 0x1d: /* FACGT */
9051 unallocated_encoding(s
);
9055 if (!dc_isar_feature(aa64_fp16
, s
)) {
9056 unallocated_encoding(s
);
9059 if (!fp_access_check(s
)) {
9063 fpst
= get_fpstatus_ptr(true);
9065 tcg_op1
= read_fp_hreg(s
, rn
);
9066 tcg_op2
= read_fp_hreg(s
, rm
);
9067 tcg_res
= tcg_temp_new_i32();
9070 case 0x03: /* FMULX */
9071 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9073 case 0x04: /* FCMEQ (reg) */
9074 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9076 case 0x07: /* FRECPS */
9077 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9079 case 0x0f: /* FRSQRTS */
9080 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9082 case 0x14: /* FCMGE (reg) */
9083 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9085 case 0x15: /* FACGE */
9086 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9088 case 0x1a: /* FABD */
9089 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9090 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
9092 case 0x1c: /* FCMGT (reg) */
9093 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9095 case 0x1d: /* FACGT */
9096 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
9099 g_assert_not_reached();
9102 write_fp_sreg(s
, rd
, tcg_res
);
9105 tcg_temp_free_i32(tcg_res
);
9106 tcg_temp_free_i32(tcg_op1
);
9107 tcg_temp_free_i32(tcg_op2
);
9108 tcg_temp_free_ptr(fpst
);
9111 /* AdvSIMD scalar three same extra
9112 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
9113 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9114 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
9115 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
9117 static void disas_simd_scalar_three_reg_same_extra(DisasContext
*s
,
9120 int rd
= extract32(insn
, 0, 5);
9121 int rn
= extract32(insn
, 5, 5);
9122 int opcode
= extract32(insn
, 11, 4);
9123 int rm
= extract32(insn
, 16, 5);
9124 int size
= extract32(insn
, 22, 2);
9125 bool u
= extract32(insn
, 29, 1);
9126 TCGv_i32 ele1
, ele2
, ele3
;
9130 switch (u
* 16 + opcode
) {
9131 case 0x10: /* SQRDMLAH (vector) */
9132 case 0x11: /* SQRDMLSH (vector) */
9133 if (size
!= 1 && size
!= 2) {
9134 unallocated_encoding(s
);
9137 feature
= dc_isar_feature(aa64_rdm
, s
);
9140 unallocated_encoding(s
);
9144 unallocated_encoding(s
);
9147 if (!fp_access_check(s
)) {
9151 /* Do a single operation on the lowest element in the vector.
9152 * We use the standard Neon helpers and rely on 0 OP 0 == 0
9153 * with no side effects for all these operations.
9154 * OPTME: special-purpose helpers would avoid doing some
9155 * unnecessary work in the helper for the 16 bit cases.
9157 ele1
= tcg_temp_new_i32();
9158 ele2
= tcg_temp_new_i32();
9159 ele3
= tcg_temp_new_i32();
9161 read_vec_element_i32(s
, ele1
, rn
, 0, size
);
9162 read_vec_element_i32(s
, ele2
, rm
, 0, size
);
9163 read_vec_element_i32(s
, ele3
, rd
, 0, size
);
9166 case 0x0: /* SQRDMLAH */
9168 gen_helper_neon_qrdmlah_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9170 gen_helper_neon_qrdmlah_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9173 case 0x1: /* SQRDMLSH */
9175 gen_helper_neon_qrdmlsh_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9177 gen_helper_neon_qrdmlsh_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
9181 g_assert_not_reached();
9183 tcg_temp_free_i32(ele1
);
9184 tcg_temp_free_i32(ele2
);
9186 res
= tcg_temp_new_i64();
9187 tcg_gen_extu_i32_i64(res
, ele3
);
9188 tcg_temp_free_i32(ele3
);
9190 write_fp_dreg(s
, rd
, res
);
9191 tcg_temp_free_i64(res
);
9194 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
9195 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
9196 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
9198 /* Handle 64->64 opcodes which are shared between the scalar and
9199 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
9200 * is valid in either group and also the double-precision fp ops.
9201 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
9207 case 0x4: /* CLS, CLZ */
9209 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
9211 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
9215 /* This opcode is shared with CNT and RBIT but we have earlier
9216 * enforced that size == 3 if and only if this is the NOT insn.
9218 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
9220 case 0x7: /* SQABS, SQNEG */
9222 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
9224 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
9227 case 0xa: /* CMLT */
9228 /* 64 bit integer comparison against zero, result is
9229 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
9234 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
9235 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
9237 case 0x8: /* CMGT, CMGE */
9238 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
9240 case 0x9: /* CMEQ, CMLE */
9241 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
9243 case 0xb: /* ABS, NEG */
9245 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
9247 TCGv_i64 tcg_zero
= tcg_const_i64(0);
9248 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
9249 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
9251 tcg_temp_free_i64(tcg_zero
);
9254 case 0x2f: /* FABS */
9255 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
9257 case 0x6f: /* FNEG */
9258 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
9260 case 0x7f: /* FSQRT */
9261 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
9263 case 0x1a: /* FCVTNS */
9264 case 0x1b: /* FCVTMS */
9265 case 0x1c: /* FCVTAS */
9266 case 0x3a: /* FCVTPS */
9267 case 0x3b: /* FCVTZS */
9269 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9270 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9271 tcg_temp_free_i32(tcg_shift
);
9274 case 0x5a: /* FCVTNU */
9275 case 0x5b: /* FCVTMU */
9276 case 0x5c: /* FCVTAU */
9277 case 0x7a: /* FCVTPU */
9278 case 0x7b: /* FCVTZU */
9280 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9281 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9282 tcg_temp_free_i32(tcg_shift
);
9285 case 0x18: /* FRINTN */
9286 case 0x19: /* FRINTM */
9287 case 0x38: /* FRINTP */
9288 case 0x39: /* FRINTZ */
9289 case 0x58: /* FRINTA */
9290 case 0x79: /* FRINTI */
9291 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9293 case 0x59: /* FRINTX */
9294 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
9297 g_assert_not_reached();
9301 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
9302 bool is_scalar
, bool is_u
, bool is_q
,
9303 int size
, int rn
, int rd
)
9305 bool is_double
= (size
== MO_64
);
9308 if (!fp_access_check(s
)) {
9312 fpst
= get_fpstatus_ptr(size
== MO_16
);
9315 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9316 TCGv_i64 tcg_zero
= tcg_const_i64(0);
9317 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9318 NeonGenTwoDoubleOPFn
*genfn
;
9323 case 0x2e: /* FCMLT (zero) */
9326 case 0x2c: /* FCMGT (zero) */
9327 genfn
= gen_helper_neon_cgt_f64
;
9329 case 0x2d: /* FCMEQ (zero) */
9330 genfn
= gen_helper_neon_ceq_f64
;
9332 case 0x6d: /* FCMLE (zero) */
9335 case 0x6c: /* FCMGE (zero) */
9336 genfn
= gen_helper_neon_cge_f64
;
9339 g_assert_not_reached();
9342 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9343 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9345 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
9347 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
9349 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9351 tcg_temp_free_i64(tcg_res
);
9352 tcg_temp_free_i64(tcg_zero
);
9353 tcg_temp_free_i64(tcg_op
);
9355 clear_vec_high(s
, !is_scalar
, rd
);
9357 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9358 TCGv_i32 tcg_zero
= tcg_const_i32(0);
9359 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9360 NeonGenTwoSingleOPFn
*genfn
;
9362 int pass
, maxpasses
;
9364 if (size
== MO_16
) {
9366 case 0x2e: /* FCMLT (zero) */
9369 case 0x2c: /* FCMGT (zero) */
9370 genfn
= gen_helper_advsimd_cgt_f16
;
9372 case 0x2d: /* FCMEQ (zero) */
9373 genfn
= gen_helper_advsimd_ceq_f16
;
9375 case 0x6d: /* FCMLE (zero) */
9378 case 0x6c: /* FCMGE (zero) */
9379 genfn
= gen_helper_advsimd_cge_f16
;
9382 g_assert_not_reached();
9386 case 0x2e: /* FCMLT (zero) */
9389 case 0x2c: /* FCMGT (zero) */
9390 genfn
= gen_helper_neon_cgt_f32
;
9392 case 0x2d: /* FCMEQ (zero) */
9393 genfn
= gen_helper_neon_ceq_f32
;
9395 case 0x6d: /* FCMLE (zero) */
9398 case 0x6c: /* FCMGE (zero) */
9399 genfn
= gen_helper_neon_cge_f32
;
9402 g_assert_not_reached();
9409 int vector_size
= 8 << is_q
;
9410 maxpasses
= vector_size
>> size
;
9413 for (pass
= 0; pass
< maxpasses
; pass
++) {
9414 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
9416 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
9418 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
9421 write_fp_sreg(s
, rd
, tcg_res
);
9423 write_vec_element_i32(s
, tcg_res
, rd
, pass
, size
);
9426 tcg_temp_free_i32(tcg_res
);
9427 tcg_temp_free_i32(tcg_zero
);
9428 tcg_temp_free_i32(tcg_op
);
9430 clear_vec_high(s
, is_q
, rd
);
9434 tcg_temp_free_ptr(fpst
);
9437 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
9438 bool is_scalar
, bool is_u
, bool is_q
,
9439 int size
, int rn
, int rd
)
9441 bool is_double
= (size
== 3);
9442 TCGv_ptr fpst
= get_fpstatus_ptr(false);
9445 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9446 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9449 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9450 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9452 case 0x3d: /* FRECPE */
9453 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
9455 case 0x3f: /* FRECPX */
9456 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
9458 case 0x7d: /* FRSQRTE */
9459 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
9462 g_assert_not_reached();
9464 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9466 tcg_temp_free_i64(tcg_res
);
9467 tcg_temp_free_i64(tcg_op
);
9468 clear_vec_high(s
, !is_scalar
, rd
);
9470 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9471 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9472 int pass
, maxpasses
;
9477 maxpasses
= is_q
? 4 : 2;
9480 for (pass
= 0; pass
< maxpasses
; pass
++) {
9481 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
9484 case 0x3c: /* URECPE */
9485 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
9487 case 0x3d: /* FRECPE */
9488 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
9490 case 0x3f: /* FRECPX */
9491 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
9493 case 0x7d: /* FRSQRTE */
9494 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
9497 g_assert_not_reached();
9501 write_fp_sreg(s
, rd
, tcg_res
);
9503 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9506 tcg_temp_free_i32(tcg_res
);
9507 tcg_temp_free_i32(tcg_op
);
9509 clear_vec_high(s
, is_q
, rd
);
9512 tcg_temp_free_ptr(fpst
);
9515 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
9516 int opcode
, bool u
, bool is_q
,
9517 int size
, int rn
, int rd
)
9519 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
9520 * in the source becomes a size element in the destination).
9523 TCGv_i32 tcg_res
[2];
9524 int destelt
= is_q
? 2 : 0;
9525 int passes
= scalar
? 1 : 2;
9528 tcg_res
[1] = tcg_const_i32(0);
9531 for (pass
= 0; pass
< passes
; pass
++) {
9532 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9533 NeonGenNarrowFn
*genfn
= NULL
;
9534 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
9537 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
9539 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9541 tcg_res
[pass
] = tcg_temp_new_i32();
9544 case 0x12: /* XTN, SQXTUN */
9546 static NeonGenNarrowFn
* const xtnfns
[3] = {
9547 gen_helper_neon_narrow_u8
,
9548 gen_helper_neon_narrow_u16
,
9549 tcg_gen_extrl_i64_i32
,
9551 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
9552 gen_helper_neon_unarrow_sat8
,
9553 gen_helper_neon_unarrow_sat16
,
9554 gen_helper_neon_unarrow_sat32
,
9557 genenvfn
= sqxtunfns
[size
];
9559 genfn
= xtnfns
[size
];
9563 case 0x14: /* SQXTN, UQXTN */
9565 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
9566 { gen_helper_neon_narrow_sat_s8
,
9567 gen_helper_neon_narrow_sat_u8
},
9568 { gen_helper_neon_narrow_sat_s16
,
9569 gen_helper_neon_narrow_sat_u16
},
9570 { gen_helper_neon_narrow_sat_s32
,
9571 gen_helper_neon_narrow_sat_u32
},
9573 genenvfn
= fns
[size
][u
];
9576 case 0x16: /* FCVTN, FCVTN2 */
9577 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
9579 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
9581 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
9582 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
9583 TCGv_ptr fpst
= get_fpstatus_ptr(false);
9584 TCGv_i32 ahp
= get_ahp_flag();
9586 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
9587 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, fpst
, ahp
);
9588 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, fpst
, ahp
);
9589 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
9590 tcg_temp_free_i32(tcg_lo
);
9591 tcg_temp_free_i32(tcg_hi
);
9592 tcg_temp_free_ptr(fpst
);
9593 tcg_temp_free_i32(ahp
);
9596 case 0x56: /* FCVTXN, FCVTXN2 */
9597 /* 64 bit to 32 bit float conversion
9598 * with von Neumann rounding (round to odd)
9601 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
9604 g_assert_not_reached();
9608 genfn(tcg_res
[pass
], tcg_op
);
9609 } else if (genenvfn
) {
9610 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
9613 tcg_temp_free_i64(tcg_op
);
9616 for (pass
= 0; pass
< 2; pass
++) {
9617 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
9618 tcg_temp_free_i32(tcg_res
[pass
]);
9620 clear_vec_high(s
, is_q
, rd
);
9623 /* Remaining saturating accumulating ops */
9624 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
9625 bool is_q
, int size
, int rn
, int rd
)
9627 bool is_double
= (size
== 3);
9630 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9631 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9634 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9635 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
9636 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9638 if (is_u
) { /* USQADD */
9639 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9640 } else { /* SUQADD */
9641 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9643 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9645 tcg_temp_free_i64(tcg_rd
);
9646 tcg_temp_free_i64(tcg_rn
);
9647 clear_vec_high(s
, !is_scalar
, rd
);
9649 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9650 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9651 int pass
, maxpasses
;
9656 maxpasses
= is_q
? 4 : 2;
9659 for (pass
= 0; pass
< maxpasses
; pass
++) {
9661 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
9662 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
9664 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
9665 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9668 if (is_u
) { /* USQADD */
9671 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9674 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9677 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9680 g_assert_not_reached();
9682 } else { /* SUQADD */
9685 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9688 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9691 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9694 g_assert_not_reached();
9699 TCGv_i64 tcg_zero
= tcg_const_i64(0);
9700 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
9701 tcg_temp_free_i64(tcg_zero
);
9703 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9705 tcg_temp_free_i32(tcg_rd
);
9706 tcg_temp_free_i32(tcg_rn
);
9707 clear_vec_high(s
, is_q
, rd
);
9711 /* AdvSIMD scalar two reg misc
9712 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9713 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9714 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9715 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9717 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9719 int rd
= extract32(insn
, 0, 5);
9720 int rn
= extract32(insn
, 5, 5);
9721 int opcode
= extract32(insn
, 12, 5);
9722 int size
= extract32(insn
, 22, 2);
9723 bool u
= extract32(insn
, 29, 1);
9724 bool is_fcvt
= false;
9727 TCGv_ptr tcg_fpstatus
;
9730 case 0x3: /* USQADD / SUQADD*/
9731 if (!fp_access_check(s
)) {
9734 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
9736 case 0x7: /* SQABS / SQNEG */
9738 case 0xa: /* CMLT */
9740 unallocated_encoding(s
);
9744 case 0x8: /* CMGT, CMGE */
9745 case 0x9: /* CMEQ, CMLE */
9746 case 0xb: /* ABS, NEG */
9748 unallocated_encoding(s
);
9752 case 0x12: /* SQXTUN */
9754 unallocated_encoding(s
);
9758 case 0x14: /* SQXTN, UQXTN */
9760 unallocated_encoding(s
);
9763 if (!fp_access_check(s
)) {
9766 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
9771 /* Floating point: U, size[1] and opcode indicate operation;
9772 * size[0] indicates single or double precision.
9774 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9775 size
= extract32(size
, 0, 1) ? 3 : 2;
9777 case 0x2c: /* FCMGT (zero) */
9778 case 0x2d: /* FCMEQ (zero) */
9779 case 0x2e: /* FCMLT (zero) */
9780 case 0x6c: /* FCMGE (zero) */
9781 case 0x6d: /* FCMLE (zero) */
9782 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
9784 case 0x1d: /* SCVTF */
9785 case 0x5d: /* UCVTF */
9787 bool is_signed
= (opcode
== 0x1d);
9788 if (!fp_access_check(s
)) {
9791 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
9794 case 0x3d: /* FRECPE */
9795 case 0x3f: /* FRECPX */
9796 case 0x7d: /* FRSQRTE */
9797 if (!fp_access_check(s
)) {
9800 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
9802 case 0x1a: /* FCVTNS */
9803 case 0x1b: /* FCVTMS */
9804 case 0x3a: /* FCVTPS */
9805 case 0x3b: /* FCVTZS */
9806 case 0x5a: /* FCVTNU */
9807 case 0x5b: /* FCVTMU */
9808 case 0x7a: /* FCVTPU */
9809 case 0x7b: /* FCVTZU */
9811 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9813 case 0x1c: /* FCVTAS */
9814 case 0x5c: /* FCVTAU */
9815 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
9817 rmode
= FPROUNDING_TIEAWAY
;
9819 case 0x56: /* FCVTXN, FCVTXN2 */
9821 unallocated_encoding(s
);
9824 if (!fp_access_check(s
)) {
9827 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
9830 unallocated_encoding(s
);
9835 unallocated_encoding(s
);
9839 if (!fp_access_check(s
)) {
9844 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
9845 tcg_fpstatus
= get_fpstatus_ptr(false);
9846 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9849 tcg_fpstatus
= NULL
;
9853 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
9854 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9856 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
9857 write_fp_dreg(s
, rd
, tcg_rd
);
9858 tcg_temp_free_i64(tcg_rd
);
9859 tcg_temp_free_i64(tcg_rn
);
9861 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9862 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9864 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
9867 case 0x7: /* SQABS, SQNEG */
9869 NeonGenOneOpEnvFn
*genfn
;
9870 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
9871 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
9872 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
9873 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
9875 genfn
= fns
[size
][u
];
9876 genfn(tcg_rd
, cpu_env
, tcg_rn
);
9879 case 0x1a: /* FCVTNS */
9880 case 0x1b: /* FCVTMS */
9881 case 0x1c: /* FCVTAS */
9882 case 0x3a: /* FCVTPS */
9883 case 0x3b: /* FCVTZS */
9885 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9886 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9887 tcg_temp_free_i32(tcg_shift
);
9890 case 0x5a: /* FCVTNU */
9891 case 0x5b: /* FCVTMU */
9892 case 0x5c: /* FCVTAU */
9893 case 0x7a: /* FCVTPU */
9894 case 0x7b: /* FCVTZU */
9896 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9897 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9898 tcg_temp_free_i32(tcg_shift
);
9902 g_assert_not_reached();
9905 write_fp_sreg(s
, rd
, tcg_rd
);
9906 tcg_temp_free_i32(tcg_rd
);
9907 tcg_temp_free_i32(tcg_rn
);
9911 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9912 tcg_temp_free_i32(tcg_rmode
);
9913 tcg_temp_free_ptr(tcg_fpstatus
);
9917 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
9918 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
9919 int immh
, int immb
, int opcode
, int rn
, int rd
)
9921 int size
= 32 - clz32(immh
) - 1;
9922 int immhb
= immh
<< 3 | immb
;
9923 int shift
= 2 * (8 << size
) - immhb
;
9924 bool accumulate
= false;
9925 int dsize
= is_q
? 128 : 64;
9926 int esize
= 8 << size
;
9927 int elements
= dsize
/esize
;
9928 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
9929 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
9930 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
9932 uint64_t round_const
;
9935 if (extract32(immh
, 3, 1) && !is_q
) {
9936 unallocated_encoding(s
);
9939 tcg_debug_assert(size
<= 3);
9941 if (!fp_access_check(s
)) {
9946 case 0x02: /* SSRA / USRA (accumulate) */
9948 /* Shift count same as element size produces zero to add. */
9949 if (shift
== 8 << size
) {
9952 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &usra_op
[size
]);
9954 /* Shift count same as element size produces all sign to add. */
9955 if (shift
== 8 << size
) {
9958 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &ssra_op
[size
]);
9961 case 0x08: /* SRI */
9962 /* Shift count same as element size is valid but does nothing. */
9963 if (shift
== 8 << size
) {
9966 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &sri_op
[size
]);
9969 case 0x00: /* SSHR / USHR */
9971 if (shift
== 8 << size
) {
9972 /* Shift count the same size as element size produces zero. */
9973 tcg_gen_gvec_dup8i(vec_full_reg_offset(s
, rd
),
9974 is_q
? 16 : 8, vec_full_reg_size(s
), 0);
9976 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shri
, size
);
9979 /* Shift count the same size as element size produces all sign. */
9980 if (shift
== 8 << size
) {
9983 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_sari
, size
);
9987 case 0x04: /* SRSHR / URSHR (rounding) */
9989 case 0x06: /* SRSRA / URSRA (accum + rounding) */
9993 g_assert_not_reached();
9996 round_const
= 1ULL << (shift
- 1);
9997 tcg_round
= tcg_const_i64(round_const
);
9999 for (i
= 0; i
< elements
; i
++) {
10000 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
10002 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
10005 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
10006 accumulate
, is_u
, size
, shift
);
10008 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
10010 tcg_temp_free_i64(tcg_round
);
10013 clear_vec_high(s
, is_q
, rd
);
10016 /* SHL/SLI - Vector shift left */
10017 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
10018 int immh
, int immb
, int opcode
, int rn
, int rd
)
10020 int size
= 32 - clz32(immh
) - 1;
10021 int immhb
= immh
<< 3 | immb
;
10022 int shift
= immhb
- (8 << size
);
10024 /* Range of size is limited by decode: immh is a non-zero 4 bit field */
10025 assert(size
>= 0 && size
<= 3);
10027 if (extract32(immh
, 3, 1) && !is_q
) {
10028 unallocated_encoding(s
);
10032 if (!fp_access_check(s
)) {
10037 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &sli_op
[size
]);
10039 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shli
, size
);
10043 /* USHLL/SHLL - Vector shift left with widening */
10044 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
10045 int immh
, int immb
, int opcode
, int rn
, int rd
)
10047 int size
= 32 - clz32(immh
) - 1;
10048 int immhb
= immh
<< 3 | immb
;
10049 int shift
= immhb
- (8 << size
);
10051 int esize
= 8 << size
;
10052 int elements
= dsize
/esize
;
10053 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
10054 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
10058 unallocated_encoding(s
);
10062 if (!fp_access_check(s
)) {
10066 /* For the LL variants the store is larger than the load,
10067 * so if rd == rn we would overwrite parts of our input.
10068 * So load everything right now and use shifts in the main loop.
10070 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
10072 for (i
= 0; i
< elements
; i
++) {
10073 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
10074 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
10075 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
10076 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
10080 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
10081 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
10082 int immh
, int immb
, int opcode
, int rn
, int rd
)
10084 int immhb
= immh
<< 3 | immb
;
10085 int size
= 32 - clz32(immh
) - 1;
10087 int esize
= 8 << size
;
10088 int elements
= dsize
/esize
;
10089 int shift
= (2 * esize
) - immhb
;
10090 bool round
= extract32(opcode
, 0, 1);
10091 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
10092 TCGv_i64 tcg_round
;
10095 if (extract32(immh
, 3, 1)) {
10096 unallocated_encoding(s
);
10100 if (!fp_access_check(s
)) {
10104 tcg_rn
= tcg_temp_new_i64();
10105 tcg_rd
= tcg_temp_new_i64();
10106 tcg_final
= tcg_temp_new_i64();
10107 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
10110 uint64_t round_const
= 1ULL << (shift
- 1);
10111 tcg_round
= tcg_const_i64(round_const
);
10116 for (i
= 0; i
< elements
; i
++) {
10117 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
10118 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
10119 false, true, size
+1, shift
);
10121 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
10125 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
10127 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
10130 tcg_temp_free_i64(tcg_round
);
10132 tcg_temp_free_i64(tcg_rn
);
10133 tcg_temp_free_i64(tcg_rd
);
10134 tcg_temp_free_i64(tcg_final
);
10136 clear_vec_high(s
, is_q
, rd
);
10140 /* AdvSIMD shift by immediate
10141 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
10142 * +---+---+---+-------------+------+------+--------+---+------+------+
10143 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
10144 * +---+---+---+-------------+------+------+--------+---+------+------+
10146 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
10148 int rd
= extract32(insn
, 0, 5);
10149 int rn
= extract32(insn
, 5, 5);
10150 int opcode
= extract32(insn
, 11, 5);
10151 int immb
= extract32(insn
, 16, 3);
10152 int immh
= extract32(insn
, 19, 4);
10153 bool is_u
= extract32(insn
, 29, 1);
10154 bool is_q
= extract32(insn
, 30, 1);
10157 case 0x08: /* SRI */
10159 unallocated_encoding(s
);
10163 case 0x00: /* SSHR / USHR */
10164 case 0x02: /* SSRA / USRA (accumulate) */
10165 case 0x04: /* SRSHR / URSHR (rounding) */
10166 case 0x06: /* SRSRA / URSRA (accum + rounding) */
10167 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10169 case 0x0a: /* SHL / SLI */
10170 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10172 case 0x10: /* SHRN */
10173 case 0x11: /* RSHRN / SQRSHRUN */
10175 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
10178 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
10181 case 0x12: /* SQSHRN / UQSHRN */
10182 case 0x13: /* SQRSHRN / UQRSHRN */
10183 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
10186 case 0x14: /* SSHLL / USHLL */
10187 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
10189 case 0x1c: /* SCVTF / UCVTF */
10190 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
10193 case 0xc: /* SQSHLU */
10195 unallocated_encoding(s
);
10198 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
10200 case 0xe: /* SQSHL, UQSHL */
10201 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
10203 case 0x1f: /* FCVTZS/ FCVTZU */
10204 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
10207 unallocated_encoding(s
);
10212 /* Generate code to do a "long" addition or subtraction, ie one done in
10213 * TCGv_i64 on vector lanes twice the width specified by size.
10215 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
10216 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
10218 static NeonGenTwo64OpFn
* const fns
[3][2] = {
10219 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
10220 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
10221 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
10223 NeonGenTwo64OpFn
*genfn
;
10226 genfn
= fns
[size
][is_sub
];
10227 genfn(tcg_res
, tcg_op1
, tcg_op2
);
10230 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
10231 int opcode
, int rd
, int rn
, int rm
)
10233 /* 3-reg-different widening insns: 64 x 64 -> 128 */
10234 TCGv_i64 tcg_res
[2];
10237 tcg_res
[0] = tcg_temp_new_i64();
10238 tcg_res
[1] = tcg_temp_new_i64();
10240 /* Does this op do an adding accumulate, a subtracting accumulate,
10241 * or no accumulate at all?
10259 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10260 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10263 /* size == 2 means two 32x32->64 operations; this is worth special
10264 * casing because we can generally handle it inline.
10267 for (pass
= 0; pass
< 2; pass
++) {
10268 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10269 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10270 TCGv_i64 tcg_passres
;
10271 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
10273 int elt
= pass
+ is_q
* 2;
10275 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
10276 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
10279 tcg_passres
= tcg_res
[pass
];
10281 tcg_passres
= tcg_temp_new_i64();
10285 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10286 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10288 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10289 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10291 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10292 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10294 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
10295 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
10297 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
10298 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
10299 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
10301 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
10302 tcg_temp_free_i64(tcg_tmp1
);
10303 tcg_temp_free_i64(tcg_tmp2
);
10306 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10307 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10308 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10309 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10311 case 9: /* SQDMLAL, SQDMLAL2 */
10312 case 11: /* SQDMLSL, SQDMLSL2 */
10313 case 13: /* SQDMULL, SQDMULL2 */
10314 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10315 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10316 tcg_passres
, tcg_passres
);
10319 g_assert_not_reached();
10322 if (opcode
== 9 || opcode
== 11) {
10323 /* saturating accumulate ops */
10325 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10327 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10328 tcg_res
[pass
], tcg_passres
);
10329 } else if (accop
> 0) {
10330 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10331 } else if (accop
< 0) {
10332 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10336 tcg_temp_free_i64(tcg_passres
);
10339 tcg_temp_free_i64(tcg_op1
);
10340 tcg_temp_free_i64(tcg_op2
);
10343 /* size 0 or 1, generally helper functions */
10344 for (pass
= 0; pass
< 2; pass
++) {
10345 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10346 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10347 TCGv_i64 tcg_passres
;
10348 int elt
= pass
+ is_q
* 2;
10350 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
10351 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
10354 tcg_passres
= tcg_res
[pass
];
10356 tcg_passres
= tcg_temp_new_i64();
10360 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10361 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10363 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
10364 static NeonGenWidenFn
* const widenfns
[2][2] = {
10365 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10366 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10368 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10370 widenfn(tcg_op2_64
, tcg_op2
);
10371 widenfn(tcg_passres
, tcg_op1
);
10372 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
10373 tcg_passres
, tcg_op2_64
);
10374 tcg_temp_free_i64(tcg_op2_64
);
10377 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10378 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10381 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10383 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10387 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
10389 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
10393 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10394 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10395 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10398 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
10400 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
10404 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10406 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10410 case 9: /* SQDMLAL, SQDMLAL2 */
10411 case 11: /* SQDMLSL, SQDMLSL2 */
10412 case 13: /* SQDMULL, SQDMULL2 */
10414 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10415 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10416 tcg_passres
, tcg_passres
);
10418 case 14: /* PMULL */
10420 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
10423 g_assert_not_reached();
10425 tcg_temp_free_i32(tcg_op1
);
10426 tcg_temp_free_i32(tcg_op2
);
10429 if (opcode
== 9 || opcode
== 11) {
10430 /* saturating accumulate ops */
10432 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10434 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10438 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
10439 tcg_res
[pass
], tcg_passres
);
10441 tcg_temp_free_i64(tcg_passres
);
10446 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10447 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10448 tcg_temp_free_i64(tcg_res
[0]);
10449 tcg_temp_free_i64(tcg_res
[1]);
10452 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
10453 int opcode
, int rd
, int rn
, int rm
)
10455 TCGv_i64 tcg_res
[2];
10456 int part
= is_q
? 2 : 0;
10459 for (pass
= 0; pass
< 2; pass
++) {
10460 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10461 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10462 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
10463 static NeonGenWidenFn
* const widenfns
[3][2] = {
10464 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10465 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10466 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
10468 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10470 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10471 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
10472 widenfn(tcg_op2_wide
, tcg_op2
);
10473 tcg_temp_free_i32(tcg_op2
);
10474 tcg_res
[pass
] = tcg_temp_new_i64();
10475 gen_neon_addl(size
, (opcode
== 3),
10476 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
10477 tcg_temp_free_i64(tcg_op1
);
10478 tcg_temp_free_i64(tcg_op2_wide
);
10481 for (pass
= 0; pass
< 2; pass
++) {
10482 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10483 tcg_temp_free_i64(tcg_res
[pass
]);
10487 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
10489 tcg_gen_addi_i64(in
, in
, 1U << 31);
10490 tcg_gen_extrh_i64_i32(res
, in
);
10493 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
10494 int opcode
, int rd
, int rn
, int rm
)
10496 TCGv_i32 tcg_res
[2];
10497 int part
= is_q
? 2 : 0;
10500 for (pass
= 0; pass
< 2; pass
++) {
10501 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10502 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10503 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
10504 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
10505 { gen_helper_neon_narrow_high_u8
,
10506 gen_helper_neon_narrow_round_high_u8
},
10507 { gen_helper_neon_narrow_high_u16
,
10508 gen_helper_neon_narrow_round_high_u16
},
10509 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
10511 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
10513 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10514 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
10516 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
10518 tcg_temp_free_i64(tcg_op1
);
10519 tcg_temp_free_i64(tcg_op2
);
10521 tcg_res
[pass
] = tcg_temp_new_i32();
10522 gennarrow(tcg_res
[pass
], tcg_wideres
);
10523 tcg_temp_free_i64(tcg_wideres
);
10526 for (pass
= 0; pass
< 2; pass
++) {
10527 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
10528 tcg_temp_free_i32(tcg_res
[pass
]);
10530 clear_vec_high(s
, is_q
, rd
);
10533 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
10535 /* PMULL of 64 x 64 -> 128 is an odd special case because it
10536 * is the only three-reg-diff instruction which produces a
10537 * 128-bit wide result from a single operation. However since
10538 * it's possible to calculate the two halves more or less
10539 * separately we just use two helper calls.
10541 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10542 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10543 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10545 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
10546 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
10547 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
10548 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
10549 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
10550 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
10552 tcg_temp_free_i64(tcg_op1
);
10553 tcg_temp_free_i64(tcg_op2
);
10554 tcg_temp_free_i64(tcg_res
);
10557 /* AdvSIMD three different
10558 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
10559 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10560 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
10561 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10563 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
10565 /* Instructions in this group fall into three basic classes
10566 * (in each case with the operation working on each element in
10567 * the input vectors):
10568 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
10570 * (2) wide 64 x 128 -> 128
10571 * (3) narrowing 128 x 128 -> 64
10572 * Here we do initial decode, catch unallocated cases and
10573 * dispatch to separate functions for each class.
10575 int is_q
= extract32(insn
, 30, 1);
10576 int is_u
= extract32(insn
, 29, 1);
10577 int size
= extract32(insn
, 22, 2);
10578 int opcode
= extract32(insn
, 12, 4);
10579 int rm
= extract32(insn
, 16, 5);
10580 int rn
= extract32(insn
, 5, 5);
10581 int rd
= extract32(insn
, 0, 5);
10584 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
10585 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
10586 /* 64 x 128 -> 128 */
10588 unallocated_encoding(s
);
10591 if (!fp_access_check(s
)) {
10594 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10596 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
10597 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
10598 /* 128 x 128 -> 64 */
10600 unallocated_encoding(s
);
10603 if (!fp_access_check(s
)) {
10606 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10608 case 14: /* PMULL, PMULL2 */
10609 if (is_u
|| size
== 1 || size
== 2) {
10610 unallocated_encoding(s
);
10614 if (!dc_isar_feature(aa64_pmull
, s
)) {
10615 unallocated_encoding(s
);
10618 if (!fp_access_check(s
)) {
10621 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
10625 case 9: /* SQDMLAL, SQDMLAL2 */
10626 case 11: /* SQDMLSL, SQDMLSL2 */
10627 case 13: /* SQDMULL, SQDMULL2 */
10628 if (is_u
|| size
== 0) {
10629 unallocated_encoding(s
);
10633 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10634 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10635 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10636 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10637 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10638 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10639 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
10640 /* 64 x 64 -> 128 */
10642 unallocated_encoding(s
);
10646 if (!fp_access_check(s
)) {
10650 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10653 /* opcode 15 not allocated */
10654 unallocated_encoding(s
);
10659 /* Logic op (opcode == 3) subgroup of C3.6.16. */
10660 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
10662 int rd
= extract32(insn
, 0, 5);
10663 int rn
= extract32(insn
, 5, 5);
10664 int rm
= extract32(insn
, 16, 5);
10665 int size
= extract32(insn
, 22, 2);
10666 bool is_u
= extract32(insn
, 29, 1);
10667 bool is_q
= extract32(insn
, 30, 1);
10669 if (!fp_access_check(s
)) {
10673 switch (size
+ 4 * is_u
) {
10675 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_and
, 0);
10678 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_andc
, 0);
10681 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_or
, 0);
10684 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_orc
, 0);
10687 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_xor
, 0);
10690 case 5: /* BSL bitwise select */
10691 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bsl_op
);
10693 case 6: /* BIT, bitwise insert if true */
10694 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bit_op
);
10696 case 7: /* BIF, bitwise insert if false */
10697 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bif_op
);
10701 g_assert_not_reached();
10705 /* Pairwise op subgroup of C3.6.16.
10707 * This is called directly or via the handle_3same_float for float pairwise
10708 * operations where the opcode and size are calculated differently.
10710 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
10711 int size
, int rn
, int rm
, int rd
)
10716 /* Floating point operations need fpst */
10717 if (opcode
>= 0x58) {
10718 fpst
= get_fpstatus_ptr(false);
10723 if (!fp_access_check(s
)) {
10727 /* These operations work on the concatenated rm:rn, with each pair of
10728 * adjacent elements being operated on to produce an element in the result.
10731 TCGv_i64 tcg_res
[2];
10733 for (pass
= 0; pass
< 2; pass
++) {
10734 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10735 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10736 int passreg
= (pass
== 0) ? rn
: rm
;
10738 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
10739 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
10740 tcg_res
[pass
] = tcg_temp_new_i64();
10743 case 0x17: /* ADDP */
10744 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10746 case 0x58: /* FMAXNMP */
10747 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10749 case 0x5a: /* FADDP */
10750 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10752 case 0x5e: /* FMAXP */
10753 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10755 case 0x78: /* FMINNMP */
10756 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10758 case 0x7e: /* FMINP */
10759 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10762 g_assert_not_reached();
10765 tcg_temp_free_i64(tcg_op1
);
10766 tcg_temp_free_i64(tcg_op2
);
10769 for (pass
= 0; pass
< 2; pass
++) {
10770 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10771 tcg_temp_free_i64(tcg_res
[pass
]);
10774 int maxpass
= is_q
? 4 : 2;
10775 TCGv_i32 tcg_res
[4];
10777 for (pass
= 0; pass
< maxpass
; pass
++) {
10778 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10779 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10780 NeonGenTwoOpFn
*genfn
= NULL
;
10781 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
10782 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
10784 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
10785 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
10786 tcg_res
[pass
] = tcg_temp_new_i32();
10789 case 0x17: /* ADDP */
10791 static NeonGenTwoOpFn
* const fns
[3] = {
10792 gen_helper_neon_padd_u8
,
10793 gen_helper_neon_padd_u16
,
10799 case 0x14: /* SMAXP, UMAXP */
10801 static NeonGenTwoOpFn
* const fns
[3][2] = {
10802 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
10803 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
10804 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
10806 genfn
= fns
[size
][u
];
10809 case 0x15: /* SMINP, UMINP */
10811 static NeonGenTwoOpFn
* const fns
[3][2] = {
10812 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
10813 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
10814 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
10816 genfn
= fns
[size
][u
];
10819 /* The FP operations are all on single floats (32 bit) */
10820 case 0x58: /* FMAXNMP */
10821 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10823 case 0x5a: /* FADDP */
10824 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10826 case 0x5e: /* FMAXP */
10827 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10829 case 0x78: /* FMINNMP */
10830 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10832 case 0x7e: /* FMINP */
10833 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10836 g_assert_not_reached();
10839 /* FP ops called directly, otherwise call now */
10841 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10844 tcg_temp_free_i32(tcg_op1
);
10845 tcg_temp_free_i32(tcg_op2
);
10848 for (pass
= 0; pass
< maxpass
; pass
++) {
10849 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
10850 tcg_temp_free_i32(tcg_res
[pass
]);
10852 clear_vec_high(s
, is_q
, rd
);
10856 tcg_temp_free_ptr(fpst
);
10860 /* Floating point op subgroup of C3.6.16. */
10861 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
10863 /* For floating point ops, the U, size[1] and opcode bits
10864 * together indicate the operation. size[0] indicates single
10867 int fpopcode
= extract32(insn
, 11, 5)
10868 | (extract32(insn
, 23, 1) << 5)
10869 | (extract32(insn
, 29, 1) << 6);
10870 int is_q
= extract32(insn
, 30, 1);
10871 int size
= extract32(insn
, 22, 1);
10872 int rm
= extract32(insn
, 16, 5);
10873 int rn
= extract32(insn
, 5, 5);
10874 int rd
= extract32(insn
, 0, 5);
10876 int datasize
= is_q
? 128 : 64;
10877 int esize
= 32 << size
;
10878 int elements
= datasize
/ esize
;
10880 if (size
== 1 && !is_q
) {
10881 unallocated_encoding(s
);
10885 switch (fpopcode
) {
10886 case 0x58: /* FMAXNMP */
10887 case 0x5a: /* FADDP */
10888 case 0x5e: /* FMAXP */
10889 case 0x78: /* FMINNMP */
10890 case 0x7e: /* FMINP */
10891 if (size
&& !is_q
) {
10892 unallocated_encoding(s
);
10895 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
10898 case 0x1b: /* FMULX */
10899 case 0x1f: /* FRECPS */
10900 case 0x3f: /* FRSQRTS */
10901 case 0x5d: /* FACGE */
10902 case 0x7d: /* FACGT */
10903 case 0x19: /* FMLA */
10904 case 0x39: /* FMLS */
10905 case 0x18: /* FMAXNM */
10906 case 0x1a: /* FADD */
10907 case 0x1c: /* FCMEQ */
10908 case 0x1e: /* FMAX */
10909 case 0x38: /* FMINNM */
10910 case 0x3a: /* FSUB */
10911 case 0x3e: /* FMIN */
10912 case 0x5b: /* FMUL */
10913 case 0x5c: /* FCMGE */
10914 case 0x5f: /* FDIV */
10915 case 0x7a: /* FABD */
10916 case 0x7c: /* FCMGT */
10917 if (!fp_access_check(s
)) {
10920 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
10923 case 0x1d: /* FMLAL */
10924 case 0x3d: /* FMLSL */
10925 case 0x59: /* FMLAL2 */
10926 case 0x79: /* FMLSL2 */
10927 if (size
& 1 || !dc_isar_feature(aa64_fhm
, s
)) {
10928 unallocated_encoding(s
);
10931 if (fp_access_check(s
)) {
10932 int is_s
= extract32(insn
, 23, 1);
10933 int is_2
= extract32(insn
, 29, 1);
10934 int data
= (is_2
<< 1) | is_s
;
10935 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
10936 vec_full_reg_offset(s
, rn
),
10937 vec_full_reg_offset(s
, rm
), cpu_env
,
10938 is_q
? 16 : 8, vec_full_reg_size(s
),
10939 data
, gen_helper_gvec_fmlal_a64
);
10944 unallocated_encoding(s
);
10949 /* Integer op subgroup of C3.6.16. */
10950 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
10952 int is_q
= extract32(insn
, 30, 1);
10953 int u
= extract32(insn
, 29, 1);
10954 int size
= extract32(insn
, 22, 2);
10955 int opcode
= extract32(insn
, 11, 5);
10956 int rm
= extract32(insn
, 16, 5);
10957 int rn
= extract32(insn
, 5, 5);
10958 int rd
= extract32(insn
, 0, 5);
10963 case 0x13: /* MUL, PMUL */
10964 if (u
&& size
!= 0) {
10965 unallocated_encoding(s
);
10969 case 0x0: /* SHADD, UHADD */
10970 case 0x2: /* SRHADD, URHADD */
10971 case 0x4: /* SHSUB, UHSUB */
10972 case 0xc: /* SMAX, UMAX */
10973 case 0xd: /* SMIN, UMIN */
10974 case 0xe: /* SABD, UABD */
10975 case 0xf: /* SABA, UABA */
10976 case 0x12: /* MLA, MLS */
10978 unallocated_encoding(s
);
10982 case 0x16: /* SQDMULH, SQRDMULH */
10983 if (size
== 0 || size
== 3) {
10984 unallocated_encoding(s
);
10989 if (size
== 3 && !is_q
) {
10990 unallocated_encoding(s
);
10996 if (!fp_access_check(s
)) {
11001 case 0x01: /* SQADD, UQADD */
11002 tcg_gen_gvec_4(vec_full_reg_offset(s
, rd
),
11003 offsetof(CPUARMState
, vfp
.qc
),
11004 vec_full_reg_offset(s
, rn
),
11005 vec_full_reg_offset(s
, rm
),
11006 is_q
? 16 : 8, vec_full_reg_size(s
),
11007 (u
? uqadd_op
: sqadd_op
) + size
);
11009 case 0x05: /* SQSUB, UQSUB */
11010 tcg_gen_gvec_4(vec_full_reg_offset(s
, rd
),
11011 offsetof(CPUARMState
, vfp
.qc
),
11012 vec_full_reg_offset(s
, rn
),
11013 vec_full_reg_offset(s
, rm
),
11014 is_q
? 16 : 8, vec_full_reg_size(s
),
11015 (u
? uqsub_op
: sqsub_op
) + size
);
11017 case 0x0c: /* SMAX, UMAX */
11019 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umax
, size
);
11021 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smax
, size
);
11024 case 0x0d: /* SMIN, UMIN */
11026 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_umin
, size
);
11028 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_smin
, size
);
11031 case 0x10: /* ADD, SUB */
11033 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_sub
, size
);
11035 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_add
, size
);
11038 case 0x13: /* MUL, PMUL */
11039 if (!u
) { /* MUL */
11040 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_mul
, size
);
11044 case 0x12: /* MLA, MLS */
11046 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mls_op
[size
]);
11048 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mla_op
[size
]);
11052 if (!u
) { /* CMTST */
11053 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &cmtst_op
[size
]);
11057 cond
= TCG_COND_EQ
;
11059 case 0x06: /* CMGT, CMHI */
11060 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
11062 case 0x07: /* CMGE, CMHS */
11063 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
11065 tcg_gen_gvec_cmp(cond
, size
, vec_full_reg_offset(s
, rd
),
11066 vec_full_reg_offset(s
, rn
),
11067 vec_full_reg_offset(s
, rm
),
11068 is_q
? 16 : 8, vec_full_reg_size(s
));
11074 for (pass
= 0; pass
< 2; pass
++) {
11075 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11076 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11077 TCGv_i64 tcg_res
= tcg_temp_new_i64();
11079 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
11080 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
11082 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
11084 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
11086 tcg_temp_free_i64(tcg_res
);
11087 tcg_temp_free_i64(tcg_op1
);
11088 tcg_temp_free_i64(tcg_op2
);
11091 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
11092 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11093 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11094 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11095 NeonGenTwoOpFn
*genfn
= NULL
;
11096 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
11098 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
11099 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
11102 case 0x0: /* SHADD, UHADD */
11104 static NeonGenTwoOpFn
* const fns
[3][2] = {
11105 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
11106 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
11107 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
11109 genfn
= fns
[size
][u
];
11112 case 0x2: /* SRHADD, URHADD */
11114 static NeonGenTwoOpFn
* const fns
[3][2] = {
11115 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
11116 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
11117 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
11119 genfn
= fns
[size
][u
];
11122 case 0x4: /* SHSUB, UHSUB */
11124 static NeonGenTwoOpFn
* const fns
[3][2] = {
11125 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
11126 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
11127 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
11129 genfn
= fns
[size
][u
];
11132 case 0x8: /* SSHL, USHL */
11134 static NeonGenTwoOpFn
* const fns
[3][2] = {
11135 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
11136 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
11137 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
11139 genfn
= fns
[size
][u
];
11142 case 0x9: /* SQSHL, UQSHL */
11144 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11145 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
11146 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
11147 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
11149 genenvfn
= fns
[size
][u
];
11152 case 0xa: /* SRSHL, URSHL */
11154 static NeonGenTwoOpFn
* const fns
[3][2] = {
11155 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
11156 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
11157 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
11159 genfn
= fns
[size
][u
];
11162 case 0xb: /* SQRSHL, UQRSHL */
11164 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11165 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
11166 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
11167 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
11169 genenvfn
= fns
[size
][u
];
11172 case 0xe: /* SABD, UABD */
11173 case 0xf: /* SABA, UABA */
11175 static NeonGenTwoOpFn
* const fns
[3][2] = {
11176 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
11177 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
11178 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
11180 genfn
= fns
[size
][u
];
11183 case 0x13: /* MUL, PMUL */
11184 assert(u
); /* PMUL */
11186 genfn
= gen_helper_neon_mul_p8
;
11188 case 0x16: /* SQDMULH, SQRDMULH */
11190 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
11191 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
11192 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
11194 assert(size
== 1 || size
== 2);
11195 genenvfn
= fns
[size
- 1][u
];
11199 g_assert_not_reached();
11203 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
11205 genfn(tcg_res
, tcg_op1
, tcg_op2
);
11208 if (opcode
== 0xf) {
11209 /* SABA, UABA: accumulating ops */
11210 static NeonGenTwoOpFn
* const fns
[3] = {
11211 gen_helper_neon_add_u8
,
11212 gen_helper_neon_add_u16
,
11216 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
11217 fns
[size
](tcg_res
, tcg_op1
, tcg_res
);
11220 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
11222 tcg_temp_free_i32(tcg_res
);
11223 tcg_temp_free_i32(tcg_op1
);
11224 tcg_temp_free_i32(tcg_op2
);
11227 clear_vec_high(s
, is_q
, rd
);
11230 /* AdvSIMD three same
11231 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11232 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11233 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11234 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11236 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
11238 int opcode
= extract32(insn
, 11, 5);
11241 case 0x3: /* logic ops */
11242 disas_simd_3same_logic(s
, insn
);
11244 case 0x17: /* ADDP */
11245 case 0x14: /* SMAXP, UMAXP */
11246 case 0x15: /* SMINP, UMINP */
11248 /* Pairwise operations */
11249 int is_q
= extract32(insn
, 30, 1);
11250 int u
= extract32(insn
, 29, 1);
11251 int size
= extract32(insn
, 22, 2);
11252 int rm
= extract32(insn
, 16, 5);
11253 int rn
= extract32(insn
, 5, 5);
11254 int rd
= extract32(insn
, 0, 5);
11255 if (opcode
== 0x17) {
11256 if (u
|| (size
== 3 && !is_q
)) {
11257 unallocated_encoding(s
);
11262 unallocated_encoding(s
);
11266 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
11269 case 0x18 ... 0x31:
11270 /* floating point ops, sz[1] and U are part of opcode */
11271 disas_simd_3same_float(s
, insn
);
11274 disas_simd_3same_int(s
, insn
);
11280 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11282 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11283 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11284 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11285 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11287 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11288 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11291 static void disas_simd_three_reg_same_fp16(DisasContext
*s
, uint32_t insn
)
11293 int opcode
, fpopcode
;
11294 int is_q
, u
, a
, rm
, rn
, rd
;
11295 int datasize
, elements
;
11298 bool pairwise
= false;
11300 if (!dc_isar_feature(aa64_fp16
, s
)) {
11301 unallocated_encoding(s
);
11305 if (!fp_access_check(s
)) {
11309 /* For these floating point ops, the U, a and opcode bits
11310 * together indicate the operation.
11312 opcode
= extract32(insn
, 11, 3);
11313 u
= extract32(insn
, 29, 1);
11314 a
= extract32(insn
, 23, 1);
11315 is_q
= extract32(insn
, 30, 1);
11316 rm
= extract32(insn
, 16, 5);
11317 rn
= extract32(insn
, 5, 5);
11318 rd
= extract32(insn
, 0, 5);
11320 fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
11321 datasize
= is_q
? 128 : 64;
11322 elements
= datasize
/ 16;
11324 switch (fpopcode
) {
11325 case 0x10: /* FMAXNMP */
11326 case 0x12: /* FADDP */
11327 case 0x16: /* FMAXP */
11328 case 0x18: /* FMINNMP */
11329 case 0x1e: /* FMINP */
11334 fpst
= get_fpstatus_ptr(true);
11337 int maxpass
= is_q
? 8 : 4;
11338 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11339 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11340 TCGv_i32 tcg_res
[8];
11342 for (pass
= 0; pass
< maxpass
; pass
++) {
11343 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
11344 int passelt
= (pass
<< 1) & (maxpass
- 1);
11346 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_16
);
11347 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_16
);
11348 tcg_res
[pass
] = tcg_temp_new_i32();
11350 switch (fpopcode
) {
11351 case 0x10: /* FMAXNMP */
11352 gen_helper_advsimd_maxnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11355 case 0x12: /* FADDP */
11356 gen_helper_advsimd_addh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11358 case 0x16: /* FMAXP */
11359 gen_helper_advsimd_maxh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11361 case 0x18: /* FMINNMP */
11362 gen_helper_advsimd_minnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11365 case 0x1e: /* FMINP */
11366 gen_helper_advsimd_minh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11369 g_assert_not_reached();
11373 for (pass
= 0; pass
< maxpass
; pass
++) {
11374 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_16
);
11375 tcg_temp_free_i32(tcg_res
[pass
]);
11378 tcg_temp_free_i32(tcg_op1
);
11379 tcg_temp_free_i32(tcg_op2
);
11382 for (pass
= 0; pass
< elements
; pass
++) {
11383 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11384 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11385 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11387 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_16
);
11388 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_16
);
11390 switch (fpopcode
) {
11391 case 0x0: /* FMAXNM */
11392 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11394 case 0x1: /* FMLA */
11395 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11396 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11399 case 0x2: /* FADD */
11400 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11402 case 0x3: /* FMULX */
11403 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11405 case 0x4: /* FCMEQ */
11406 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11408 case 0x6: /* FMAX */
11409 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11411 case 0x7: /* FRECPS */
11412 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11414 case 0x8: /* FMINNM */
11415 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11417 case 0x9: /* FMLS */
11418 /* As usual for ARM, separate negation for fused multiply-add */
11419 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
11420 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11421 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11424 case 0xa: /* FSUB */
11425 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11427 case 0xe: /* FMIN */
11428 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11430 case 0xf: /* FRSQRTS */
11431 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11433 case 0x13: /* FMUL */
11434 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11436 case 0x14: /* FCMGE */
11437 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11439 case 0x15: /* FACGE */
11440 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11442 case 0x17: /* FDIV */
11443 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11445 case 0x1a: /* FABD */
11446 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11447 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
11449 case 0x1c: /* FCMGT */
11450 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11452 case 0x1d: /* FACGT */
11453 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11456 fprintf(stderr
, "%s: insn %#04x, fpop %#2x @ %#" PRIx64
"\n",
11457 __func__
, insn
, fpopcode
, s
->pc
);
11458 g_assert_not_reached();
11461 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11462 tcg_temp_free_i32(tcg_res
);
11463 tcg_temp_free_i32(tcg_op1
);
11464 tcg_temp_free_i32(tcg_op2
);
11468 tcg_temp_free_ptr(fpst
);
11470 clear_vec_high(s
, is_q
, rd
);
11473 /* AdvSIMD three same extra
11474 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
11475 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11476 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
11477 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11479 static void disas_simd_three_reg_same_extra(DisasContext
*s
, uint32_t insn
)
11481 int rd
= extract32(insn
, 0, 5);
11482 int rn
= extract32(insn
, 5, 5);
11483 int opcode
= extract32(insn
, 11, 4);
11484 int rm
= extract32(insn
, 16, 5);
11485 int size
= extract32(insn
, 22, 2);
11486 bool u
= extract32(insn
, 29, 1);
11487 bool is_q
= extract32(insn
, 30, 1);
11491 switch (u
* 16 + opcode
) {
11492 case 0x10: /* SQRDMLAH (vector) */
11493 case 0x11: /* SQRDMLSH (vector) */
11494 if (size
!= 1 && size
!= 2) {
11495 unallocated_encoding(s
);
11498 feature
= dc_isar_feature(aa64_rdm
, s
);
11500 case 0x02: /* SDOT (vector) */
11501 case 0x12: /* UDOT (vector) */
11502 if (size
!= MO_32
) {
11503 unallocated_encoding(s
);
11506 feature
= dc_isar_feature(aa64_dp
, s
);
11508 case 0x18: /* FCMLA, #0 */
11509 case 0x19: /* FCMLA, #90 */
11510 case 0x1a: /* FCMLA, #180 */
11511 case 0x1b: /* FCMLA, #270 */
11512 case 0x1c: /* FCADD, #90 */
11513 case 0x1e: /* FCADD, #270 */
11515 || (size
== 1 && !dc_isar_feature(aa64_fp16
, s
))
11516 || (size
== 3 && !is_q
)) {
11517 unallocated_encoding(s
);
11520 feature
= dc_isar_feature(aa64_fcma
, s
);
11523 unallocated_encoding(s
);
11527 unallocated_encoding(s
);
11530 if (!fp_access_check(s
)) {
11535 case 0x0: /* SQRDMLAH (vector) */
11538 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s16
);
11541 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s32
);
11544 g_assert_not_reached();
11548 case 0x1: /* SQRDMLSH (vector) */
11551 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s16
);
11554 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s32
);
11557 g_assert_not_reached();
11561 case 0x2: /* SDOT / UDOT */
11562 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, 0,
11563 u
? gen_helper_gvec_udot_b
: gen_helper_gvec_sdot_b
);
11566 case 0x8: /* FCMLA, #0 */
11567 case 0x9: /* FCMLA, #90 */
11568 case 0xa: /* FCMLA, #180 */
11569 case 0xb: /* FCMLA, #270 */
11570 rot
= extract32(opcode
, 0, 2);
11573 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, true, rot
,
11574 gen_helper_gvec_fcmlah
);
11577 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11578 gen_helper_gvec_fcmlas
);
11581 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11582 gen_helper_gvec_fcmlad
);
11585 g_assert_not_reached();
11589 case 0xc: /* FCADD, #90 */
11590 case 0xe: /* FCADD, #270 */
11591 rot
= extract32(opcode
, 1, 1);
11594 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11595 gen_helper_gvec_fcaddh
);
11598 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11599 gen_helper_gvec_fcadds
);
11602 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11603 gen_helper_gvec_fcaddd
);
11606 g_assert_not_reached();
11611 g_assert_not_reached();
11615 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
11616 int size
, int rn
, int rd
)
11618 /* Handle 2-reg-misc ops which are widening (so each size element
11619 * in the source becomes a 2*size element in the destination.
11620 * The only instruction like this is FCVTL.
11625 /* 32 -> 64 bit fp conversion */
11626 TCGv_i64 tcg_res
[2];
11627 int srcelt
= is_q
? 2 : 0;
11629 for (pass
= 0; pass
< 2; pass
++) {
11630 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11631 tcg_res
[pass
] = tcg_temp_new_i64();
11633 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
11634 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
11635 tcg_temp_free_i32(tcg_op
);
11637 for (pass
= 0; pass
< 2; pass
++) {
11638 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11639 tcg_temp_free_i64(tcg_res
[pass
]);
11642 /* 16 -> 32 bit fp conversion */
11643 int srcelt
= is_q
? 4 : 0;
11644 TCGv_i32 tcg_res
[4];
11645 TCGv_ptr fpst
= get_fpstatus_ptr(false);
11646 TCGv_i32 ahp
= get_ahp_flag();
11648 for (pass
= 0; pass
< 4; pass
++) {
11649 tcg_res
[pass
] = tcg_temp_new_i32();
11651 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
11652 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
11655 for (pass
= 0; pass
< 4; pass
++) {
11656 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
11657 tcg_temp_free_i32(tcg_res
[pass
]);
11660 tcg_temp_free_ptr(fpst
);
11661 tcg_temp_free_i32(ahp
);
11665 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
11666 bool is_q
, int size
, int rn
, int rd
)
11668 int op
= (opcode
<< 1) | u
;
11669 int opsz
= op
+ size
;
11670 int grp_size
= 3 - opsz
;
11671 int dsize
= is_q
? 128 : 64;
11675 unallocated_encoding(s
);
11679 if (!fp_access_check(s
)) {
11684 /* Special case bytes, use bswap op on each group of elements */
11685 int groups
= dsize
/ (8 << grp_size
);
11687 for (i
= 0; i
< groups
; i
++) {
11688 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
11690 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
11691 switch (grp_size
) {
11693 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
11696 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
11699 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
11702 g_assert_not_reached();
11704 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
11705 tcg_temp_free_i64(tcg_tmp
);
11707 clear_vec_high(s
, is_q
, rd
);
11709 int revmask
= (1 << grp_size
) - 1;
11710 int esize
= 8 << size
;
11711 int elements
= dsize
/ esize
;
11712 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
11713 TCGv_i64 tcg_rd
= tcg_const_i64(0);
11714 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
11716 for (i
= 0; i
< elements
; i
++) {
11717 int e_rev
= (i
& 0xf) ^ revmask
;
11718 int off
= e_rev
* esize
;
11719 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
11721 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
11722 tcg_rn
, off
- 64, esize
);
11724 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
11727 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
11728 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
11730 tcg_temp_free_i64(tcg_rd_hi
);
11731 tcg_temp_free_i64(tcg_rd
);
11732 tcg_temp_free_i64(tcg_rn
);
11736 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
11737 bool is_q
, int size
, int rn
, int rd
)
11739 /* Implement the pairwise operations from 2-misc:
11740 * SADDLP, UADDLP, SADALP, UADALP.
11741 * These all add pairs of elements in the input to produce a
11742 * double-width result element in the output (possibly accumulating).
11744 bool accum
= (opcode
== 0x6);
11745 int maxpass
= is_q
? 2 : 1;
11747 TCGv_i64 tcg_res
[2];
11750 /* 32 + 32 -> 64 op */
11751 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
11753 for (pass
= 0; pass
< maxpass
; pass
++) {
11754 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11755 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11757 tcg_res
[pass
] = tcg_temp_new_i64();
11759 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
11760 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
11761 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11763 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
11764 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
11767 tcg_temp_free_i64(tcg_op1
);
11768 tcg_temp_free_i64(tcg_op2
);
11771 for (pass
= 0; pass
< maxpass
; pass
++) {
11772 TCGv_i64 tcg_op
= tcg_temp_new_i64();
11773 NeonGenOneOpFn
*genfn
;
11774 static NeonGenOneOpFn
* const fns
[2][2] = {
11775 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
11776 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
11779 genfn
= fns
[size
][u
];
11781 tcg_res
[pass
] = tcg_temp_new_i64();
11783 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
11784 genfn(tcg_res
[pass
], tcg_op
);
11787 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
11789 gen_helper_neon_addl_u16(tcg_res
[pass
],
11790 tcg_res
[pass
], tcg_op
);
11792 gen_helper_neon_addl_u32(tcg_res
[pass
],
11793 tcg_res
[pass
], tcg_op
);
11796 tcg_temp_free_i64(tcg_op
);
11800 tcg_res
[1] = tcg_const_i64(0);
11802 for (pass
= 0; pass
< 2; pass
++) {
11803 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11804 tcg_temp_free_i64(tcg_res
[pass
]);
11808 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
11810 /* Implement SHLL and SHLL2 */
11812 int part
= is_q
? 2 : 0;
11813 TCGv_i64 tcg_res
[2];
11815 for (pass
= 0; pass
< 2; pass
++) {
11816 static NeonGenWidenFn
* const widenfns
[3] = {
11817 gen_helper_neon_widen_u8
,
11818 gen_helper_neon_widen_u16
,
11819 tcg_gen_extu_i32_i64
,
11821 NeonGenWidenFn
*widenfn
= widenfns
[size
];
11822 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11824 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
11825 tcg_res
[pass
] = tcg_temp_new_i64();
11826 widenfn(tcg_res
[pass
], tcg_op
);
11827 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
11829 tcg_temp_free_i32(tcg_op
);
11832 for (pass
= 0; pass
< 2; pass
++) {
11833 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11834 tcg_temp_free_i64(tcg_res
[pass
]);
11838 /* AdvSIMD two reg misc
11839 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
11840 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11841 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
11842 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11844 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
11846 int size
= extract32(insn
, 22, 2);
11847 int opcode
= extract32(insn
, 12, 5);
11848 bool u
= extract32(insn
, 29, 1);
11849 bool is_q
= extract32(insn
, 30, 1);
11850 int rn
= extract32(insn
, 5, 5);
11851 int rd
= extract32(insn
, 0, 5);
11852 bool need_fpstatus
= false;
11853 bool need_rmode
= false;
11855 TCGv_i32 tcg_rmode
;
11856 TCGv_ptr tcg_fpstatus
;
11859 case 0x0: /* REV64, REV32 */
11860 case 0x1: /* REV16 */
11861 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
11863 case 0x5: /* CNT, NOT, RBIT */
11864 if (u
&& size
== 0) {
11867 } else if (u
&& size
== 1) {
11870 } else if (!u
&& size
== 0) {
11874 unallocated_encoding(s
);
11876 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
11877 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
11879 unallocated_encoding(s
);
11882 if (!fp_access_check(s
)) {
11886 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
11888 case 0x4: /* CLS, CLZ */
11890 unallocated_encoding(s
);
11894 case 0x2: /* SADDLP, UADDLP */
11895 case 0x6: /* SADALP, UADALP */
11897 unallocated_encoding(s
);
11900 if (!fp_access_check(s
)) {
11903 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
11905 case 0x13: /* SHLL, SHLL2 */
11906 if (u
== 0 || size
== 3) {
11907 unallocated_encoding(s
);
11910 if (!fp_access_check(s
)) {
11913 handle_shll(s
, is_q
, size
, rn
, rd
);
11915 case 0xa: /* CMLT */
11917 unallocated_encoding(s
);
11921 case 0x8: /* CMGT, CMGE */
11922 case 0x9: /* CMEQ, CMLE */
11923 case 0xb: /* ABS, NEG */
11924 if (size
== 3 && !is_q
) {
11925 unallocated_encoding(s
);
11929 case 0x3: /* SUQADD, USQADD */
11930 if (size
== 3 && !is_q
) {
11931 unallocated_encoding(s
);
11934 if (!fp_access_check(s
)) {
11937 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
11939 case 0x7: /* SQABS, SQNEG */
11940 if (size
== 3 && !is_q
) {
11941 unallocated_encoding(s
);
11946 case 0x16 ... 0x1d:
11949 /* Floating point: U, size[1] and opcode indicate operation;
11950 * size[0] indicates single or double precision.
11952 int is_double
= extract32(size
, 0, 1);
11953 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
11954 size
= is_double
? 3 : 2;
11956 case 0x2f: /* FABS */
11957 case 0x6f: /* FNEG */
11958 if (size
== 3 && !is_q
) {
11959 unallocated_encoding(s
);
11963 case 0x1d: /* SCVTF */
11964 case 0x5d: /* UCVTF */
11966 bool is_signed
= (opcode
== 0x1d) ? true : false;
11967 int elements
= is_double
? 2 : is_q
? 4 : 2;
11968 if (is_double
&& !is_q
) {
11969 unallocated_encoding(s
);
11972 if (!fp_access_check(s
)) {
11975 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
11978 case 0x2c: /* FCMGT (zero) */
11979 case 0x2d: /* FCMEQ (zero) */
11980 case 0x2e: /* FCMLT (zero) */
11981 case 0x6c: /* FCMGE (zero) */
11982 case 0x6d: /* FCMLE (zero) */
11983 if (size
== 3 && !is_q
) {
11984 unallocated_encoding(s
);
11987 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
11989 case 0x7f: /* FSQRT */
11990 if (size
== 3 && !is_q
) {
11991 unallocated_encoding(s
);
11995 case 0x1a: /* FCVTNS */
11996 case 0x1b: /* FCVTMS */
11997 case 0x3a: /* FCVTPS */
11998 case 0x3b: /* FCVTZS */
11999 case 0x5a: /* FCVTNU */
12000 case 0x5b: /* FCVTMU */
12001 case 0x7a: /* FCVTPU */
12002 case 0x7b: /* FCVTZU */
12003 need_fpstatus
= true;
12005 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12006 if (size
== 3 && !is_q
) {
12007 unallocated_encoding(s
);
12011 case 0x5c: /* FCVTAU */
12012 case 0x1c: /* FCVTAS */
12013 need_fpstatus
= true;
12015 rmode
= FPROUNDING_TIEAWAY
;
12016 if (size
== 3 && !is_q
) {
12017 unallocated_encoding(s
);
12021 case 0x3c: /* URECPE */
12023 unallocated_encoding(s
);
12027 case 0x3d: /* FRECPE */
12028 case 0x7d: /* FRSQRTE */
12029 if (size
== 3 && !is_q
) {
12030 unallocated_encoding(s
);
12033 if (!fp_access_check(s
)) {
12036 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
12038 case 0x56: /* FCVTXN, FCVTXN2 */
12040 unallocated_encoding(s
);
12044 case 0x16: /* FCVTN, FCVTN2 */
12045 /* handle_2misc_narrow does a 2*size -> size operation, but these
12046 * instructions encode the source size rather than dest size.
12048 if (!fp_access_check(s
)) {
12051 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
12053 case 0x17: /* FCVTL, FCVTL2 */
12054 if (!fp_access_check(s
)) {
12057 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
12059 case 0x18: /* FRINTN */
12060 case 0x19: /* FRINTM */
12061 case 0x38: /* FRINTP */
12062 case 0x39: /* FRINTZ */
12064 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
12066 case 0x59: /* FRINTX */
12067 case 0x79: /* FRINTI */
12068 need_fpstatus
= true;
12069 if (size
== 3 && !is_q
) {
12070 unallocated_encoding(s
);
12074 case 0x58: /* FRINTA */
12076 rmode
= FPROUNDING_TIEAWAY
;
12077 need_fpstatus
= true;
12078 if (size
== 3 && !is_q
) {
12079 unallocated_encoding(s
);
12083 case 0x7c: /* URSQRTE */
12085 unallocated_encoding(s
);
12088 need_fpstatus
= true;
12091 unallocated_encoding(s
);
12097 unallocated_encoding(s
);
12101 if (!fp_access_check(s
)) {
12105 if (need_fpstatus
|| need_rmode
) {
12106 tcg_fpstatus
= get_fpstatus_ptr(false);
12108 tcg_fpstatus
= NULL
;
12111 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12112 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12119 if (u
&& size
== 0) { /* NOT */
12120 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_not
, 0);
12126 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_neg
, size
);
12133 /* All 64-bit element operations can be shared with scalar 2misc */
12136 /* Coverity claims (size == 3 && !is_q) has been eliminated
12137 * from all paths leading to here.
12139 tcg_debug_assert(is_q
);
12140 for (pass
= 0; pass
< 2; pass
++) {
12141 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12142 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12144 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12146 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
12147 tcg_rmode
, tcg_fpstatus
);
12149 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12151 tcg_temp_free_i64(tcg_res
);
12152 tcg_temp_free_i64(tcg_op
);
12157 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
12158 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12159 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12162 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
12165 /* Special cases for 32 bit elements */
12167 case 0xa: /* CMLT */
12168 /* 32 bit integer comparison against zero, result is
12169 * test ? (2^32 - 1) : 0. We implement via setcond(test)
12172 cond
= TCG_COND_LT
;
12174 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
12175 tcg_gen_neg_i32(tcg_res
, tcg_res
);
12177 case 0x8: /* CMGT, CMGE */
12178 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
12180 case 0x9: /* CMEQ, CMLE */
12181 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
12183 case 0x4: /* CLS */
12185 tcg_gen_clzi_i32(tcg_res
, tcg_op
, 32);
12187 tcg_gen_clrsb_i32(tcg_res
, tcg_op
);
12190 case 0x7: /* SQABS, SQNEG */
12192 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
12194 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
12197 case 0xb: /* ABS, NEG */
12199 tcg_gen_neg_i32(tcg_res
, tcg_op
);
12201 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12202 tcg_gen_neg_i32(tcg_res
, tcg_op
);
12203 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
12204 tcg_zero
, tcg_op
, tcg_res
);
12205 tcg_temp_free_i32(tcg_zero
);
12208 case 0x2f: /* FABS */
12209 gen_helper_vfp_abss(tcg_res
, tcg_op
);
12211 case 0x6f: /* FNEG */
12212 gen_helper_vfp_negs(tcg_res
, tcg_op
);
12214 case 0x7f: /* FSQRT */
12215 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
12217 case 0x1a: /* FCVTNS */
12218 case 0x1b: /* FCVTMS */
12219 case 0x1c: /* FCVTAS */
12220 case 0x3a: /* FCVTPS */
12221 case 0x3b: /* FCVTZS */
12223 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12224 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
12225 tcg_shift
, tcg_fpstatus
);
12226 tcg_temp_free_i32(tcg_shift
);
12229 case 0x5a: /* FCVTNU */
12230 case 0x5b: /* FCVTMU */
12231 case 0x5c: /* FCVTAU */
12232 case 0x7a: /* FCVTPU */
12233 case 0x7b: /* FCVTZU */
12235 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12236 gen_helper_vfp_touls(tcg_res
, tcg_op
,
12237 tcg_shift
, tcg_fpstatus
);
12238 tcg_temp_free_i32(tcg_shift
);
12241 case 0x18: /* FRINTN */
12242 case 0x19: /* FRINTM */
12243 case 0x38: /* FRINTP */
12244 case 0x39: /* FRINTZ */
12245 case 0x58: /* FRINTA */
12246 case 0x79: /* FRINTI */
12247 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
12249 case 0x59: /* FRINTX */
12250 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12252 case 0x7c: /* URSQRTE */
12253 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
12256 g_assert_not_reached();
12259 /* Use helpers for 8 and 16 bit elements */
12261 case 0x5: /* CNT, RBIT */
12262 /* For these two insns size is part of the opcode specifier
12263 * (handled earlier); they always operate on byte elements.
12266 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
12268 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
12271 case 0x7: /* SQABS, SQNEG */
12273 NeonGenOneOpEnvFn
*genfn
;
12274 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
12275 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
12276 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
12278 genfn
= fns
[size
][u
];
12279 genfn(tcg_res
, cpu_env
, tcg_op
);
12282 case 0x8: /* CMGT, CMGE */
12283 case 0x9: /* CMEQ, CMLE */
12284 case 0xa: /* CMLT */
12286 static NeonGenTwoOpFn
* const fns
[3][2] = {
12287 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
12288 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
12289 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
12291 NeonGenTwoOpFn
*genfn
;
12294 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12296 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
12297 comp
= (opcode
- 0x8) * 2 + u
;
12298 /* ...but LE, LT are implemented as reverse GE, GT */
12299 reverse
= (comp
> 2);
12303 genfn
= fns
[comp
][size
];
12305 genfn(tcg_res
, tcg_zero
, tcg_op
);
12307 genfn(tcg_res
, tcg_op
, tcg_zero
);
12309 tcg_temp_free_i32(tcg_zero
);
12312 case 0xb: /* ABS, NEG */
12314 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12316 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
12318 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
12320 tcg_temp_free_i32(tcg_zero
);
12323 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
12325 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
12329 case 0x4: /* CLS, CLZ */
12332 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
12334 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
12338 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
12340 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
12345 g_assert_not_reached();
12349 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
12351 tcg_temp_free_i32(tcg_res
);
12352 tcg_temp_free_i32(tcg_op
);
12355 clear_vec_high(s
, is_q
, rd
);
12358 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12359 tcg_temp_free_i32(tcg_rmode
);
12361 if (need_fpstatus
) {
12362 tcg_temp_free_ptr(tcg_fpstatus
);
12366 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12368 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12369 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12370 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12371 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12372 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12373 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12375 * This actually covers two groups where scalar access is governed by
12376 * bit 28. A bunch of the instructions (float to integral) only exist
12377 * in the vector form and are un-allocated for the scalar decode. Also
12378 * in the scalar decode Q is always 1.
12380 static void disas_simd_two_reg_misc_fp16(DisasContext
*s
, uint32_t insn
)
12382 int fpop
, opcode
, a
, u
;
12386 bool only_in_vector
= false;
12389 TCGv_i32 tcg_rmode
= NULL
;
12390 TCGv_ptr tcg_fpstatus
= NULL
;
12391 bool need_rmode
= false;
12392 bool need_fpst
= true;
12395 if (!dc_isar_feature(aa64_fp16
, s
)) {
12396 unallocated_encoding(s
);
12400 rd
= extract32(insn
, 0, 5);
12401 rn
= extract32(insn
, 5, 5);
12403 a
= extract32(insn
, 23, 1);
12404 u
= extract32(insn
, 29, 1);
12405 is_scalar
= extract32(insn
, 28, 1);
12406 is_q
= extract32(insn
, 30, 1);
12408 opcode
= extract32(insn
, 12, 5);
12409 fpop
= deposit32(opcode
, 5, 1, a
);
12410 fpop
= deposit32(fpop
, 6, 1, u
);
12412 rd
= extract32(insn
, 0, 5);
12413 rn
= extract32(insn
, 5, 5);
12416 case 0x1d: /* SCVTF */
12417 case 0x5d: /* UCVTF */
12424 elements
= (is_q
? 8 : 4);
12427 if (!fp_access_check(s
)) {
12430 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !u
, 0, MO_16
);
12434 case 0x2c: /* FCMGT (zero) */
12435 case 0x2d: /* FCMEQ (zero) */
12436 case 0x2e: /* FCMLT (zero) */
12437 case 0x6c: /* FCMGE (zero) */
12438 case 0x6d: /* FCMLE (zero) */
12439 handle_2misc_fcmp_zero(s
, fpop
, is_scalar
, 0, is_q
, MO_16
, rn
, rd
);
12441 case 0x3d: /* FRECPE */
12442 case 0x3f: /* FRECPX */
12444 case 0x18: /* FRINTN */
12446 only_in_vector
= true;
12447 rmode
= FPROUNDING_TIEEVEN
;
12449 case 0x19: /* FRINTM */
12451 only_in_vector
= true;
12452 rmode
= FPROUNDING_NEGINF
;
12454 case 0x38: /* FRINTP */
12456 only_in_vector
= true;
12457 rmode
= FPROUNDING_POSINF
;
12459 case 0x39: /* FRINTZ */
12461 only_in_vector
= true;
12462 rmode
= FPROUNDING_ZERO
;
12464 case 0x58: /* FRINTA */
12466 only_in_vector
= true;
12467 rmode
= FPROUNDING_TIEAWAY
;
12469 case 0x59: /* FRINTX */
12470 case 0x79: /* FRINTI */
12471 only_in_vector
= true;
12472 /* current rounding mode */
12474 case 0x1a: /* FCVTNS */
12476 rmode
= FPROUNDING_TIEEVEN
;
12478 case 0x1b: /* FCVTMS */
12480 rmode
= FPROUNDING_NEGINF
;
12482 case 0x1c: /* FCVTAS */
12484 rmode
= FPROUNDING_TIEAWAY
;
12486 case 0x3a: /* FCVTPS */
12488 rmode
= FPROUNDING_POSINF
;
12490 case 0x3b: /* FCVTZS */
12492 rmode
= FPROUNDING_ZERO
;
12494 case 0x5a: /* FCVTNU */
12496 rmode
= FPROUNDING_TIEEVEN
;
12498 case 0x5b: /* FCVTMU */
12500 rmode
= FPROUNDING_NEGINF
;
12502 case 0x5c: /* FCVTAU */
12504 rmode
= FPROUNDING_TIEAWAY
;
12506 case 0x7a: /* FCVTPU */
12508 rmode
= FPROUNDING_POSINF
;
12510 case 0x7b: /* FCVTZU */
12512 rmode
= FPROUNDING_ZERO
;
12514 case 0x2f: /* FABS */
12515 case 0x6f: /* FNEG */
12518 case 0x7d: /* FRSQRTE */
12519 case 0x7f: /* FSQRT (vector) */
12522 fprintf(stderr
, "%s: insn %#04x fpop %#2x\n", __func__
, insn
, fpop
);
12523 g_assert_not_reached();
12527 /* Check additional constraints for the scalar encoding */
12530 unallocated_encoding(s
);
12533 /* FRINTxx is only in the vector form */
12534 if (only_in_vector
) {
12535 unallocated_encoding(s
);
12540 if (!fp_access_check(s
)) {
12544 if (need_rmode
|| need_fpst
) {
12545 tcg_fpstatus
= get_fpstatus_ptr(true);
12549 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12550 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12554 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
12555 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12558 case 0x1a: /* FCVTNS */
12559 case 0x1b: /* FCVTMS */
12560 case 0x1c: /* FCVTAS */
12561 case 0x3a: /* FCVTPS */
12562 case 0x3b: /* FCVTZS */
12563 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12565 case 0x3d: /* FRECPE */
12566 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12568 case 0x3f: /* FRECPX */
12569 gen_helper_frecpx_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12571 case 0x5a: /* FCVTNU */
12572 case 0x5b: /* FCVTMU */
12573 case 0x5c: /* FCVTAU */
12574 case 0x7a: /* FCVTPU */
12575 case 0x7b: /* FCVTZU */
12576 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12578 case 0x6f: /* FNEG */
12579 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12581 case 0x7d: /* FRSQRTE */
12582 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12585 g_assert_not_reached();
12588 /* limit any sign extension going on */
12589 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0xffff);
12590 write_fp_sreg(s
, rd
, tcg_res
);
12592 tcg_temp_free_i32(tcg_res
);
12593 tcg_temp_free_i32(tcg_op
);
12595 for (pass
= 0; pass
< (is_q
? 8 : 4); pass
++) {
12596 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12597 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12599 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_16
);
12602 case 0x1a: /* FCVTNS */
12603 case 0x1b: /* FCVTMS */
12604 case 0x1c: /* FCVTAS */
12605 case 0x3a: /* FCVTPS */
12606 case 0x3b: /* FCVTZS */
12607 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12609 case 0x3d: /* FRECPE */
12610 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12612 case 0x5a: /* FCVTNU */
12613 case 0x5b: /* FCVTMU */
12614 case 0x5c: /* FCVTAU */
12615 case 0x7a: /* FCVTPU */
12616 case 0x7b: /* FCVTZU */
12617 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12619 case 0x18: /* FRINTN */
12620 case 0x19: /* FRINTM */
12621 case 0x38: /* FRINTP */
12622 case 0x39: /* FRINTZ */
12623 case 0x58: /* FRINTA */
12624 case 0x79: /* FRINTI */
12625 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12627 case 0x59: /* FRINTX */
12628 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12630 case 0x2f: /* FABS */
12631 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
12633 case 0x6f: /* FNEG */
12634 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12636 case 0x7d: /* FRSQRTE */
12637 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12639 case 0x7f: /* FSQRT */
12640 gen_helper_sqrt_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12643 g_assert_not_reached();
12646 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12648 tcg_temp_free_i32(tcg_res
);
12649 tcg_temp_free_i32(tcg_op
);
12652 clear_vec_high(s
, is_q
, rd
);
12656 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12657 tcg_temp_free_i32(tcg_rmode
);
12660 if (tcg_fpstatus
) {
12661 tcg_temp_free_ptr(tcg_fpstatus
);
12665 /* AdvSIMD scalar x indexed element
12666 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12667 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12668 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12669 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12670 * AdvSIMD vector x indexed element
12671 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12672 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12673 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12674 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12676 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
12678 /* This encoding has two kinds of instruction:
12679 * normal, where we perform elt x idxelt => elt for each
12680 * element in the vector
12681 * long, where we perform elt x idxelt and generate a result of
12682 * double the width of the input element
12683 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
12685 bool is_scalar
= extract32(insn
, 28, 1);
12686 bool is_q
= extract32(insn
, 30, 1);
12687 bool u
= extract32(insn
, 29, 1);
12688 int size
= extract32(insn
, 22, 2);
12689 int l
= extract32(insn
, 21, 1);
12690 int m
= extract32(insn
, 20, 1);
12691 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
12692 int rm
= extract32(insn
, 16, 4);
12693 int opcode
= extract32(insn
, 12, 4);
12694 int h
= extract32(insn
, 11, 1);
12695 int rn
= extract32(insn
, 5, 5);
12696 int rd
= extract32(insn
, 0, 5);
12697 bool is_long
= false;
12699 bool is_fp16
= false;
12703 switch (16 * u
+ opcode
) {
12704 case 0x08: /* MUL */
12705 case 0x10: /* MLA */
12706 case 0x14: /* MLS */
12708 unallocated_encoding(s
);
12712 case 0x02: /* SMLAL, SMLAL2 */
12713 case 0x12: /* UMLAL, UMLAL2 */
12714 case 0x06: /* SMLSL, SMLSL2 */
12715 case 0x16: /* UMLSL, UMLSL2 */
12716 case 0x0a: /* SMULL, SMULL2 */
12717 case 0x1a: /* UMULL, UMULL2 */
12719 unallocated_encoding(s
);
12724 case 0x03: /* SQDMLAL, SQDMLAL2 */
12725 case 0x07: /* SQDMLSL, SQDMLSL2 */
12726 case 0x0b: /* SQDMULL, SQDMULL2 */
12729 case 0x0c: /* SQDMULH */
12730 case 0x0d: /* SQRDMULH */
12732 case 0x01: /* FMLA */
12733 case 0x05: /* FMLS */
12734 case 0x09: /* FMUL */
12735 case 0x19: /* FMULX */
12738 case 0x1d: /* SQRDMLAH */
12739 case 0x1f: /* SQRDMLSH */
12740 if (!dc_isar_feature(aa64_rdm
, s
)) {
12741 unallocated_encoding(s
);
12745 case 0x0e: /* SDOT */
12746 case 0x1e: /* UDOT */
12747 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_dp
, s
)) {
12748 unallocated_encoding(s
);
12752 case 0x11: /* FCMLA #0 */
12753 case 0x13: /* FCMLA #90 */
12754 case 0x15: /* FCMLA #180 */
12755 case 0x17: /* FCMLA #270 */
12756 if (is_scalar
|| !dc_isar_feature(aa64_fcma
, s
)) {
12757 unallocated_encoding(s
);
12762 case 0x00: /* FMLAL */
12763 case 0x04: /* FMLSL */
12764 case 0x18: /* FMLAL2 */
12765 case 0x1c: /* FMLSL2 */
12766 if (is_scalar
|| size
!= MO_32
|| !dc_isar_feature(aa64_fhm
, s
)) {
12767 unallocated_encoding(s
);
12771 /* is_fp, but we pass cpu_env not fp_status. */
12774 unallocated_encoding(s
);
12779 case 1: /* normal fp */
12780 /* convert insn encoded size to TCGMemOp size */
12782 case 0: /* half-precision */
12786 case MO_32
: /* single precision */
12787 case MO_64
: /* double precision */
12790 unallocated_encoding(s
);
12795 case 2: /* complex fp */
12796 /* Each indexable element is a complex pair. */
12801 unallocated_encoding(s
);
12809 unallocated_encoding(s
);
12814 default: /* integer */
12818 unallocated_encoding(s
);
12823 if (is_fp16
&& !dc_isar_feature(aa64_fp16
, s
)) {
12824 unallocated_encoding(s
);
12828 /* Given TCGMemOp size, adjust register and indexing. */
12831 index
= h
<< 2 | l
<< 1 | m
;
12834 index
= h
<< 1 | l
;
12839 unallocated_encoding(s
);
12846 g_assert_not_reached();
12849 if (!fp_access_check(s
)) {
12854 fpst
= get_fpstatus_ptr(is_fp16
);
12859 switch (16 * u
+ opcode
) {
12860 case 0x0e: /* SDOT */
12861 case 0x1e: /* UDOT */
12862 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, index
,
12863 u
? gen_helper_gvec_udot_idx_b
12864 : gen_helper_gvec_sdot_idx_b
);
12866 case 0x11: /* FCMLA #0 */
12867 case 0x13: /* FCMLA #90 */
12868 case 0x15: /* FCMLA #180 */
12869 case 0x17: /* FCMLA #270 */
12871 int rot
= extract32(insn
, 13, 2);
12872 int data
= (index
<< 2) | rot
;
12873 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
12874 vec_full_reg_offset(s
, rn
),
12875 vec_full_reg_offset(s
, rm
), fpst
,
12876 is_q
? 16 : 8, vec_full_reg_size(s
), data
,
12878 ? gen_helper_gvec_fcmlas_idx
12879 : gen_helper_gvec_fcmlah_idx
);
12880 tcg_temp_free_ptr(fpst
);
12884 case 0x00: /* FMLAL */
12885 case 0x04: /* FMLSL */
12886 case 0x18: /* FMLAL2 */
12887 case 0x1c: /* FMLSL2 */
12889 int is_s
= extract32(opcode
, 2, 1);
12891 int data
= (index
<< 2) | (is_2
<< 1) | is_s
;
12892 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
12893 vec_full_reg_offset(s
, rn
),
12894 vec_full_reg_offset(s
, rm
), cpu_env
,
12895 is_q
? 16 : 8, vec_full_reg_size(s
),
12896 data
, gen_helper_gvec_fmlal_idx_a64
);
12902 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
12905 assert(is_fp
&& is_q
&& !is_long
);
12907 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
12909 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
12910 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12911 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12913 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12915 switch (16 * u
+ opcode
) {
12916 case 0x05: /* FMLS */
12917 /* As usual for ARM, separate negation for fused multiply-add */
12918 gen_helper_vfp_negd(tcg_op
, tcg_op
);
12920 case 0x01: /* FMLA */
12921 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12922 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
12924 case 0x09: /* FMUL */
12925 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12927 case 0x19: /* FMULX */
12928 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12931 g_assert_not_reached();
12934 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12935 tcg_temp_free_i64(tcg_op
);
12936 tcg_temp_free_i64(tcg_res
);
12939 tcg_temp_free_i64(tcg_idx
);
12940 clear_vec_high(s
, !is_scalar
, rd
);
12941 } else if (!is_long
) {
12942 /* 32 bit floating point, or 16 or 32 bit integer.
12943 * For the 16 bit scalar case we use the usual Neon helpers and
12944 * rely on the fact that 0 op 0 == 0 with no side effects.
12946 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
12947 int pass
, maxpasses
;
12952 maxpasses
= is_q
? 4 : 2;
12955 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
12957 if (size
== 1 && !is_scalar
) {
12958 /* The simplest way to handle the 16x16 indexed ops is to duplicate
12959 * the index into both halves of the 32 bit tcg_idx and then use
12960 * the usual Neon helpers.
12962 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
12965 for (pass
= 0; pass
< maxpasses
; pass
++) {
12966 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12967 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12969 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
12971 switch (16 * u
+ opcode
) {
12972 case 0x08: /* MUL */
12973 case 0x10: /* MLA */
12974 case 0x14: /* MLS */
12976 static NeonGenTwoOpFn
* const fns
[2][2] = {
12977 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
12978 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
12980 NeonGenTwoOpFn
*genfn
;
12981 bool is_sub
= opcode
== 0x4;
12984 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
12986 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
12988 if (opcode
== 0x8) {
12991 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
12992 genfn
= fns
[size
- 1][is_sub
];
12993 genfn(tcg_res
, tcg_op
, tcg_res
);
12996 case 0x05: /* FMLS */
12997 case 0x01: /* FMLA */
12998 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
12999 is_scalar
? size
: MO_32
);
13002 if (opcode
== 0x5) {
13003 /* As usual for ARM, separate negation for fused
13005 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80008000);
13008 gen_helper_advsimd_muladdh(tcg_res
, tcg_op
, tcg_idx
,
13011 gen_helper_advsimd_muladd2h(tcg_res
, tcg_op
, tcg_idx
,
13016 if (opcode
== 0x5) {
13017 /* As usual for ARM, separate negation for
13018 * fused multiply-add */
13019 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80000000);
13021 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
,
13025 g_assert_not_reached();
13028 case 0x09: /* FMUL */
13032 gen_helper_advsimd_mulh(tcg_res
, tcg_op
,
13035 gen_helper_advsimd_mul2h(tcg_res
, tcg_op
,
13040 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13043 g_assert_not_reached();
13046 case 0x19: /* FMULX */
13050 gen_helper_advsimd_mulxh(tcg_res
, tcg_op
,
13053 gen_helper_advsimd_mulx2h(tcg_res
, tcg_op
,
13058 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
13061 g_assert_not_reached();
13064 case 0x0c: /* SQDMULH */
13066 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
13069 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
13073 case 0x0d: /* SQRDMULH */
13075 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
13078 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
13082 case 0x1d: /* SQRDMLAH */
13083 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13084 is_scalar
? size
: MO_32
);
13086 gen_helper_neon_qrdmlah_s16(tcg_res
, cpu_env
,
13087 tcg_op
, tcg_idx
, tcg_res
);
13089 gen_helper_neon_qrdmlah_s32(tcg_res
, cpu_env
,
13090 tcg_op
, tcg_idx
, tcg_res
);
13093 case 0x1f: /* SQRDMLSH */
13094 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
13095 is_scalar
? size
: MO_32
);
13097 gen_helper_neon_qrdmlsh_s16(tcg_res
, cpu_env
,
13098 tcg_op
, tcg_idx
, tcg_res
);
13100 gen_helper_neon_qrdmlsh_s32(tcg_res
, cpu_env
,
13101 tcg_op
, tcg_idx
, tcg_res
);
13105 g_assert_not_reached();
13109 write_fp_sreg(s
, rd
, tcg_res
);
13111 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
13114 tcg_temp_free_i32(tcg_op
);
13115 tcg_temp_free_i32(tcg_res
);
13118 tcg_temp_free_i32(tcg_idx
);
13119 clear_vec_high(s
, is_q
, rd
);
13121 /* long ops: 16x16->32 or 32x32->64 */
13122 TCGv_i64 tcg_res
[2];
13124 bool satop
= extract32(opcode
, 0, 1);
13125 TCGMemOp memop
= MO_32
;
13132 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
13134 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
13136 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13137 TCGv_i64 tcg_op
= tcg_temp_new_i64();
13138 TCGv_i64 tcg_passres
;
13144 passelt
= pass
+ (is_q
* 2);
13147 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
13149 tcg_res
[pass
] = tcg_temp_new_i64();
13151 if (opcode
== 0xa || opcode
== 0xb) {
13152 /* Non-accumulating ops */
13153 tcg_passres
= tcg_res
[pass
];
13155 tcg_passres
= tcg_temp_new_i64();
13158 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
13159 tcg_temp_free_i64(tcg_op
);
13162 /* saturating, doubling */
13163 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
13164 tcg_passres
, tcg_passres
);
13167 if (opcode
== 0xa || opcode
== 0xb) {
13171 /* Accumulating op: handle accumulate step */
13172 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13175 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13176 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13178 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13179 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13181 case 0x7: /* SQDMLSL, SQDMLSL2 */
13182 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
13184 case 0x3: /* SQDMLAL, SQDMLAL2 */
13185 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
13190 g_assert_not_reached();
13192 tcg_temp_free_i64(tcg_passres
);
13194 tcg_temp_free_i64(tcg_idx
);
13196 clear_vec_high(s
, !is_scalar
, rd
);
13198 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13201 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13204 /* The simplest way to handle the 16x16 indexed ops is to
13205 * duplicate the index into both halves of the 32 bit tcg_idx
13206 * and then use the usual Neon helpers.
13208 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13211 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13212 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13213 TCGv_i64 tcg_passres
;
13216 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
13218 read_vec_element_i32(s
, tcg_op
, rn
,
13219 pass
+ (is_q
* 2), MO_32
);
13222 tcg_res
[pass
] = tcg_temp_new_i64();
13224 if (opcode
== 0xa || opcode
== 0xb) {
13225 /* Non-accumulating ops */
13226 tcg_passres
= tcg_res
[pass
];
13228 tcg_passres
= tcg_temp_new_i64();
13231 if (memop
& MO_SIGN
) {
13232 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
13234 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
13237 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
13238 tcg_passres
, tcg_passres
);
13240 tcg_temp_free_i32(tcg_op
);
13242 if (opcode
== 0xa || opcode
== 0xb) {
13246 /* Accumulating op: handle accumulate step */
13247 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13250 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13251 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
13254 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13255 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
13258 case 0x7: /* SQDMLSL, SQDMLSL2 */
13259 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
13261 case 0x3: /* SQDMLAL, SQDMLAL2 */
13262 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
13267 g_assert_not_reached();
13269 tcg_temp_free_i64(tcg_passres
);
13271 tcg_temp_free_i32(tcg_idx
);
13274 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
13279 tcg_res
[1] = tcg_const_i64(0);
13282 for (pass
= 0; pass
< 2; pass
++) {
13283 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13284 tcg_temp_free_i64(tcg_res
[pass
]);
13289 tcg_temp_free_ptr(fpst
);
13294 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13295 * +-----------------+------+-----------+--------+-----+------+------+
13296 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13297 * +-----------------+------+-----------+--------+-----+------+------+
13299 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
13301 int size
= extract32(insn
, 22, 2);
13302 int opcode
= extract32(insn
, 12, 5);
13303 int rn
= extract32(insn
, 5, 5);
13304 int rd
= extract32(insn
, 0, 5);
13306 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13307 TCGv_i32 tcg_decrypt
;
13308 CryptoThreeOpIntFn
*genfn
;
13310 if (!dc_isar_feature(aa64_aes
, s
) || size
!= 0) {
13311 unallocated_encoding(s
);
13316 case 0x4: /* AESE */
13318 genfn
= gen_helper_crypto_aese
;
13320 case 0x6: /* AESMC */
13322 genfn
= gen_helper_crypto_aesmc
;
13324 case 0x5: /* AESD */
13326 genfn
= gen_helper_crypto_aese
;
13328 case 0x7: /* AESIMC */
13330 genfn
= gen_helper_crypto_aesmc
;
13333 unallocated_encoding(s
);
13337 if (!fp_access_check(s
)) {
13341 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13342 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13343 tcg_decrypt
= tcg_const_i32(decrypt
);
13345 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_decrypt
);
13347 tcg_temp_free_ptr(tcg_rd_ptr
);
13348 tcg_temp_free_ptr(tcg_rn_ptr
);
13349 tcg_temp_free_i32(tcg_decrypt
);
13352 /* Crypto three-reg SHA
13353 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
13354 * +-----------------+------+---+------+---+--------+-----+------+------+
13355 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
13356 * +-----------------+------+---+------+---+--------+-----+------+------+
13358 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
13360 int size
= extract32(insn
, 22, 2);
13361 int opcode
= extract32(insn
, 12, 3);
13362 int rm
= extract32(insn
, 16, 5);
13363 int rn
= extract32(insn
, 5, 5);
13364 int rd
= extract32(insn
, 0, 5);
13365 CryptoThreeOpFn
*genfn
;
13366 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13370 unallocated_encoding(s
);
13375 case 0: /* SHA1C */
13376 case 1: /* SHA1P */
13377 case 2: /* SHA1M */
13378 case 3: /* SHA1SU0 */
13380 feature
= dc_isar_feature(aa64_sha1
, s
);
13382 case 4: /* SHA256H */
13383 genfn
= gen_helper_crypto_sha256h
;
13384 feature
= dc_isar_feature(aa64_sha256
, s
);
13386 case 5: /* SHA256H2 */
13387 genfn
= gen_helper_crypto_sha256h2
;
13388 feature
= dc_isar_feature(aa64_sha256
, s
);
13390 case 6: /* SHA256SU1 */
13391 genfn
= gen_helper_crypto_sha256su1
;
13392 feature
= dc_isar_feature(aa64_sha256
, s
);
13395 unallocated_encoding(s
);
13400 unallocated_encoding(s
);
13404 if (!fp_access_check(s
)) {
13408 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13409 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13410 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13413 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13415 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
13417 gen_helper_crypto_sha1_3reg(tcg_rd_ptr
, tcg_rn_ptr
,
13418 tcg_rm_ptr
, tcg_opcode
);
13419 tcg_temp_free_i32(tcg_opcode
);
13422 tcg_temp_free_ptr(tcg_rd_ptr
);
13423 tcg_temp_free_ptr(tcg_rn_ptr
);
13424 tcg_temp_free_ptr(tcg_rm_ptr
);
13427 /* Crypto two-reg SHA
13428 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13429 * +-----------------+------+-----------+--------+-----+------+------+
13430 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13431 * +-----------------+------+-----------+--------+-----+------+------+
13433 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
13435 int size
= extract32(insn
, 22, 2);
13436 int opcode
= extract32(insn
, 12, 5);
13437 int rn
= extract32(insn
, 5, 5);
13438 int rd
= extract32(insn
, 0, 5);
13439 CryptoTwoOpFn
*genfn
;
13441 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13444 unallocated_encoding(s
);
13449 case 0: /* SHA1H */
13450 feature
= dc_isar_feature(aa64_sha1
, s
);
13451 genfn
= gen_helper_crypto_sha1h
;
13453 case 1: /* SHA1SU1 */
13454 feature
= dc_isar_feature(aa64_sha1
, s
);
13455 genfn
= gen_helper_crypto_sha1su1
;
13457 case 2: /* SHA256SU0 */
13458 feature
= dc_isar_feature(aa64_sha256
, s
);
13459 genfn
= gen_helper_crypto_sha256su0
;
13462 unallocated_encoding(s
);
13467 unallocated_encoding(s
);
13471 if (!fp_access_check(s
)) {
13475 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13476 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13478 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13480 tcg_temp_free_ptr(tcg_rd_ptr
);
13481 tcg_temp_free_ptr(tcg_rn_ptr
);
13484 /* Crypto three-reg SHA512
13485 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13486 * +-----------------------+------+---+---+-----+--------+------+------+
13487 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
13488 * +-----------------------+------+---+---+-----+--------+------+------+
13490 static void disas_crypto_three_reg_sha512(DisasContext
*s
, uint32_t insn
)
13492 int opcode
= extract32(insn
, 10, 2);
13493 int o
= extract32(insn
, 14, 1);
13494 int rm
= extract32(insn
, 16, 5);
13495 int rn
= extract32(insn
, 5, 5);
13496 int rd
= extract32(insn
, 0, 5);
13498 CryptoThreeOpFn
*genfn
;
13502 case 0: /* SHA512H */
13503 feature
= dc_isar_feature(aa64_sha512
, s
);
13504 genfn
= gen_helper_crypto_sha512h
;
13506 case 1: /* SHA512H2 */
13507 feature
= dc_isar_feature(aa64_sha512
, s
);
13508 genfn
= gen_helper_crypto_sha512h2
;
13510 case 2: /* SHA512SU1 */
13511 feature
= dc_isar_feature(aa64_sha512
, s
);
13512 genfn
= gen_helper_crypto_sha512su1
;
13515 feature
= dc_isar_feature(aa64_sha3
, s
);
13521 case 0: /* SM3PARTW1 */
13522 feature
= dc_isar_feature(aa64_sm3
, s
);
13523 genfn
= gen_helper_crypto_sm3partw1
;
13525 case 1: /* SM3PARTW2 */
13526 feature
= dc_isar_feature(aa64_sm3
, s
);
13527 genfn
= gen_helper_crypto_sm3partw2
;
13529 case 2: /* SM4EKEY */
13530 feature
= dc_isar_feature(aa64_sm4
, s
);
13531 genfn
= gen_helper_crypto_sm4ekey
;
13534 unallocated_encoding(s
);
13540 unallocated_encoding(s
);
13544 if (!fp_access_check(s
)) {
13549 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13551 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13552 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13553 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13555 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13557 tcg_temp_free_ptr(tcg_rd_ptr
);
13558 tcg_temp_free_ptr(tcg_rn_ptr
);
13559 tcg_temp_free_ptr(tcg_rm_ptr
);
13561 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13564 tcg_op1
= tcg_temp_new_i64();
13565 tcg_op2
= tcg_temp_new_i64();
13566 tcg_res
[0] = tcg_temp_new_i64();
13567 tcg_res
[1] = tcg_temp_new_i64();
13569 for (pass
= 0; pass
< 2; pass
++) {
13570 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13571 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13573 tcg_gen_rotli_i64(tcg_res
[pass
], tcg_op2
, 1);
13574 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13576 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13577 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13579 tcg_temp_free_i64(tcg_op1
);
13580 tcg_temp_free_i64(tcg_op2
);
13581 tcg_temp_free_i64(tcg_res
[0]);
13582 tcg_temp_free_i64(tcg_res
[1]);
13586 /* Crypto two-reg SHA512
13587 * 31 12 11 10 9 5 4 0
13588 * +-----------------------------------------+--------+------+------+
13589 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
13590 * +-----------------------------------------+--------+------+------+
13592 static void disas_crypto_two_reg_sha512(DisasContext
*s
, uint32_t insn
)
13594 int opcode
= extract32(insn
, 10, 2);
13595 int rn
= extract32(insn
, 5, 5);
13596 int rd
= extract32(insn
, 0, 5);
13597 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13599 CryptoTwoOpFn
*genfn
;
13602 case 0: /* SHA512SU0 */
13603 feature
= dc_isar_feature(aa64_sha512
, s
);
13604 genfn
= gen_helper_crypto_sha512su0
;
13607 feature
= dc_isar_feature(aa64_sm4
, s
);
13608 genfn
= gen_helper_crypto_sm4e
;
13611 unallocated_encoding(s
);
13616 unallocated_encoding(s
);
13620 if (!fp_access_check(s
)) {
13624 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13625 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13627 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13629 tcg_temp_free_ptr(tcg_rd_ptr
);
13630 tcg_temp_free_ptr(tcg_rn_ptr
);
13633 /* Crypto four-register
13634 * 31 23 22 21 20 16 15 14 10 9 5 4 0
13635 * +-------------------+-----+------+---+------+------+------+
13636 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
13637 * +-------------------+-----+------+---+------+------+------+
13639 static void disas_crypto_four_reg(DisasContext
*s
, uint32_t insn
)
13641 int op0
= extract32(insn
, 21, 2);
13642 int rm
= extract32(insn
, 16, 5);
13643 int ra
= extract32(insn
, 10, 5);
13644 int rn
= extract32(insn
, 5, 5);
13645 int rd
= extract32(insn
, 0, 5);
13651 feature
= dc_isar_feature(aa64_sha3
, s
);
13653 case 2: /* SM3SS1 */
13654 feature
= dc_isar_feature(aa64_sm3
, s
);
13657 unallocated_encoding(s
);
13662 unallocated_encoding(s
);
13666 if (!fp_access_check(s
)) {
13671 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
[2];
13674 tcg_op1
= tcg_temp_new_i64();
13675 tcg_op2
= tcg_temp_new_i64();
13676 tcg_op3
= tcg_temp_new_i64();
13677 tcg_res
[0] = tcg_temp_new_i64();
13678 tcg_res
[1] = tcg_temp_new_i64();
13680 for (pass
= 0; pass
< 2; pass
++) {
13681 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13682 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13683 read_vec_element(s
, tcg_op3
, ra
, pass
, MO_64
);
13687 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13690 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13692 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13694 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13695 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13697 tcg_temp_free_i64(tcg_op1
);
13698 tcg_temp_free_i64(tcg_op2
);
13699 tcg_temp_free_i64(tcg_op3
);
13700 tcg_temp_free_i64(tcg_res
[0]);
13701 tcg_temp_free_i64(tcg_res
[1]);
13703 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
, tcg_zero
;
13705 tcg_op1
= tcg_temp_new_i32();
13706 tcg_op2
= tcg_temp_new_i32();
13707 tcg_op3
= tcg_temp_new_i32();
13708 tcg_res
= tcg_temp_new_i32();
13709 tcg_zero
= tcg_const_i32(0);
13711 read_vec_element_i32(s
, tcg_op1
, rn
, 3, MO_32
);
13712 read_vec_element_i32(s
, tcg_op2
, rm
, 3, MO_32
);
13713 read_vec_element_i32(s
, tcg_op3
, ra
, 3, MO_32
);
13715 tcg_gen_rotri_i32(tcg_res
, tcg_op1
, 20);
13716 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op2
);
13717 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op3
);
13718 tcg_gen_rotri_i32(tcg_res
, tcg_res
, 25);
13720 write_vec_element_i32(s
, tcg_zero
, rd
, 0, MO_32
);
13721 write_vec_element_i32(s
, tcg_zero
, rd
, 1, MO_32
);
13722 write_vec_element_i32(s
, tcg_zero
, rd
, 2, MO_32
);
13723 write_vec_element_i32(s
, tcg_res
, rd
, 3, MO_32
);
13725 tcg_temp_free_i32(tcg_op1
);
13726 tcg_temp_free_i32(tcg_op2
);
13727 tcg_temp_free_i32(tcg_op3
);
13728 tcg_temp_free_i32(tcg_res
);
13729 tcg_temp_free_i32(tcg_zero
);
13734 * 31 21 20 16 15 10 9 5 4 0
13735 * +-----------------------+------+--------+------+------+
13736 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
13737 * +-----------------------+------+--------+------+------+
13739 static void disas_crypto_xar(DisasContext
*s
, uint32_t insn
)
13741 int rm
= extract32(insn
, 16, 5);
13742 int imm6
= extract32(insn
, 10, 6);
13743 int rn
= extract32(insn
, 5, 5);
13744 int rd
= extract32(insn
, 0, 5);
13745 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13748 if (!dc_isar_feature(aa64_sha3
, s
)) {
13749 unallocated_encoding(s
);
13753 if (!fp_access_check(s
)) {
13757 tcg_op1
= tcg_temp_new_i64();
13758 tcg_op2
= tcg_temp_new_i64();
13759 tcg_res
[0] = tcg_temp_new_i64();
13760 tcg_res
[1] = tcg_temp_new_i64();
13762 for (pass
= 0; pass
< 2; pass
++) {
13763 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13764 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13766 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
13767 tcg_gen_rotri_i64(tcg_res
[pass
], tcg_res
[pass
], imm6
);
13769 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13770 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13772 tcg_temp_free_i64(tcg_op1
);
13773 tcg_temp_free_i64(tcg_op2
);
13774 tcg_temp_free_i64(tcg_res
[0]);
13775 tcg_temp_free_i64(tcg_res
[1]);
13778 /* Crypto three-reg imm2
13779 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13780 * +-----------------------+------+-----+------+--------+------+------+
13781 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
13782 * +-----------------------+------+-----+------+--------+------+------+
13784 static void disas_crypto_three_reg_imm2(DisasContext
*s
, uint32_t insn
)
13786 int opcode
= extract32(insn
, 10, 2);
13787 int imm2
= extract32(insn
, 12, 2);
13788 int rm
= extract32(insn
, 16, 5);
13789 int rn
= extract32(insn
, 5, 5);
13790 int rd
= extract32(insn
, 0, 5);
13791 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13792 TCGv_i32 tcg_imm2
, tcg_opcode
;
13794 if (!dc_isar_feature(aa64_sm3
, s
)) {
13795 unallocated_encoding(s
);
13799 if (!fp_access_check(s
)) {
13803 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13804 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13805 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13806 tcg_imm2
= tcg_const_i32(imm2
);
13807 tcg_opcode
= tcg_const_i32(opcode
);
13809 gen_helper_crypto_sm3tt(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
, tcg_imm2
,
13812 tcg_temp_free_ptr(tcg_rd_ptr
);
13813 tcg_temp_free_ptr(tcg_rn_ptr
);
13814 tcg_temp_free_ptr(tcg_rm_ptr
);
13815 tcg_temp_free_i32(tcg_imm2
);
13816 tcg_temp_free_i32(tcg_opcode
);
13819 /* C3.6 Data processing - SIMD, inc Crypto
13821 * As the decode gets a little complex we are using a table based
13822 * approach for this part of the decode.
13824 static const AArch64DecodeTable data_proc_simd
[] = {
13825 /* pattern , mask , fn */
13826 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
13827 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra
},
13828 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
13829 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
13830 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
13831 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
13832 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
13833 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
13834 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
13835 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
13836 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
13837 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
13838 { 0x2e000000, 0xbf208400, disas_simd_ext
},
13839 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
13840 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra
},
13841 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
13842 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
13843 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
13844 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
13845 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
13846 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
13847 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
13848 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
13849 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
13850 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512
},
13851 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512
},
13852 { 0xce000000, 0xff808000, disas_crypto_four_reg
},
13853 { 0xce800000, 0xffe00000, disas_crypto_xar
},
13854 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2
},
13855 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16
},
13856 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16
},
13857 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16
},
13858 { 0x00000000, 0x00000000, NULL
}
13861 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
13863 /* Note that this is called with all non-FP cases from
13864 * table C3-6 so it must UNDEF for entries not specifically
13865 * allocated to instructions in that table.
13867 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
13871 unallocated_encoding(s
);
13875 /* C3.6 Data processing - SIMD and floating point */
13876 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
13878 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
13879 disas_data_proc_fp(s
, insn
);
13881 /* SIMD, including crypto */
13882 disas_data_proc_simd(s
, insn
);
13888 * @env: The cpu environment
13889 * @s: The DisasContext
13891 * Return true if the page is guarded.
13893 static bool is_guarded_page(CPUARMState
*env
, DisasContext
*s
)
13895 #ifdef CONFIG_USER_ONLY
13896 return false; /* FIXME */
13898 uint64_t addr
= s
->base
.pc_first
;
13899 int mmu_idx
= arm_to_core_mmu_idx(s
->mmu_idx
);
13900 unsigned int index
= tlb_index(env
, mmu_idx
, addr
);
13901 CPUTLBEntry
*entry
= tlb_entry(env
, mmu_idx
, addr
);
13904 * We test this immediately after reading an insn, which means
13905 * that any normal page must be in the TLB. The only exception
13906 * would be for executing from flash or device memory, which
13907 * does not retain the TLB entry.
13909 * FIXME: Assume false for those, for now. We could use
13910 * arm_cpu_get_phys_page_attrs_debug to re-read the page
13911 * table entry even for that case.
13913 return (tlb_hit(entry
->addr_code
, addr
) &&
13914 env
->iotlb
[mmu_idx
][index
].attrs
.target_tlb_bit0
);
13919 * btype_destination_ok:
13920 * @insn: The instruction at the branch destination
13921 * @bt: SCTLR_ELx.BT
13922 * @btype: PSTATE.BTYPE, and is non-zero
13924 * On a guarded page, there are a limited number of insns
13925 * that may be present at the branch target:
13926 * - branch target identifiers,
13927 * - paciasp, pacibsp,
13930 * Anything else causes a Branch Target Exception.
13932 * Return true if the branch is compatible, false to raise BTITRAP.
13934 static bool btype_destination_ok(uint32_t insn
, bool bt
, int btype
)
13936 if ((insn
& 0xfffff01fu
) == 0xd503201fu
) {
13938 switch (extract32(insn
, 5, 7)) {
13939 case 0b011001: /* PACIASP */
13940 case 0b011011: /* PACIBSP */
13942 * If SCTLR_ELx.BT, then PACI*SP are not compatible
13943 * with btype == 3. Otherwise all btype are ok.
13945 return !bt
|| btype
!= 3;
13946 case 0b100000: /* BTI */
13947 /* Not compatible with any btype. */
13949 case 0b100010: /* BTI c */
13950 /* Not compatible with btype == 3 */
13952 case 0b100100: /* BTI j */
13953 /* Not compatible with btype == 2 */
13955 case 0b100110: /* BTI jc */
13956 /* Compatible with any btype. */
13960 switch (insn
& 0xffe0001fu
) {
13961 case 0xd4200000u
: /* BRK */
13962 case 0xd4400000u
: /* HLT */
13963 /* Give priority to the breakpoint exception. */
13970 /* C3.1 A64 instruction index by encoding */
13971 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
13975 insn
= arm_ldl_code(env
, s
->pc
, s
->sctlr_b
);
13979 s
->fp_access_checked
= false;
13981 if (dc_isar_feature(aa64_bti
, s
)) {
13982 if (s
->base
.num_insns
== 1) {
13984 * At the first insn of the TB, compute s->guarded_page.
13985 * We delayed computing this until successfully reading
13986 * the first insn of the TB, above. This (mostly) ensures
13987 * that the softmmu tlb entry has been populated, and the
13988 * page table GP bit is available.
13990 * Note that we need to compute this even if btype == 0,
13991 * because this value is used for BR instructions later
13992 * where ENV is not available.
13994 s
->guarded_page
= is_guarded_page(env
, s
);
13996 /* First insn can have btype set to non-zero. */
13997 tcg_debug_assert(s
->btype
>= 0);
14000 * Note that the Branch Target Exception has fairly high
14001 * priority -- below debugging exceptions but above most
14002 * everything else. This allows us to handle this now
14003 * instead of waiting until the insn is otherwise decoded.
14007 && !btype_destination_ok(insn
, s
->bt
, s
->btype
)) {
14008 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_btitrap(s
->btype
),
14009 default_exception_el(s
));
14013 /* Not the first insn: btype must be 0. */
14014 tcg_debug_assert(s
->btype
== 0);
14018 switch (extract32(insn
, 25, 4)) {
14019 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
14020 unallocated_encoding(s
);
14023 if (!dc_isar_feature(aa64_sve
, s
) || !disas_sve(s
, insn
)) {
14024 unallocated_encoding(s
);
14027 case 0x8: case 0x9: /* Data processing - immediate */
14028 disas_data_proc_imm(s
, insn
);
14030 case 0xa: case 0xb: /* Branch, exception generation and system insns */
14031 disas_b_exc_sys(s
, insn
);
14036 case 0xe: /* Loads and stores */
14037 disas_ldst(s
, insn
);
14040 case 0xd: /* Data processing - register */
14041 disas_data_proc_reg(s
, insn
);
14044 case 0xf: /* Data processing - SIMD and floating point */
14045 disas_data_proc_simd_fp(s
, insn
);
14048 assert(FALSE
); /* all 15 cases should be handled above */
14052 /* if we allocated any temporaries, free them here */
14056 * After execution of most insns, btype is reset to 0.
14057 * Note that we set btype == -1 when the insn sets btype.
14059 if (s
->btype
> 0 && s
->base
.is_jmp
!= DISAS_NORETURN
) {
14064 static void aarch64_tr_init_disas_context(DisasContextBase
*dcbase
,
14067 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14068 CPUARMState
*env
= cpu
->env_ptr
;
14069 ARMCPU
*arm_cpu
= arm_env_get_cpu(env
);
14070 uint32_t tb_flags
= dc
->base
.tb
->flags
;
14071 int bound
, core_mmu_idx
;
14073 dc
->isar
= &arm_cpu
->isar
;
14074 dc
->pc
= dc
->base
.pc_first
;
14078 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
14079 * there is no secure EL1, so we route exceptions to EL3.
14081 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
14082 !arm_el_is_aa64(env
, 3);
14085 dc
->be_data
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, BE_DATA
) ? MO_BE
: MO_LE
;
14086 dc
->condexec_mask
= 0;
14087 dc
->condexec_cond
= 0;
14088 core_mmu_idx
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, MMUIDX
);
14089 dc
->mmu_idx
= core_to_arm_mmu_idx(env
, core_mmu_idx
);
14090 dc
->tbii
= FIELD_EX32(tb_flags
, TBFLAG_A64
, TBII
);
14091 dc
->tbid
= FIELD_EX32(tb_flags
, TBFLAG_A64
, TBID
);
14092 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
14093 #if !defined(CONFIG_USER_ONLY)
14094 dc
->user
= (dc
->current_el
== 0);
14096 dc
->fp_excp_el
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, FPEXC_EL
);
14097 dc
->sve_excp_el
= FIELD_EX32(tb_flags
, TBFLAG_A64
, SVEEXC_EL
);
14098 dc
->sve_len
= (FIELD_EX32(tb_flags
, TBFLAG_A64
, ZCR_LEN
) + 1) * 16;
14099 dc
->pauth_active
= FIELD_EX32(tb_flags
, TBFLAG_A64
, PAUTH_ACTIVE
);
14100 dc
->bt
= FIELD_EX32(tb_flags
, TBFLAG_A64
, BT
);
14101 dc
->btype
= FIELD_EX32(tb_flags
, TBFLAG_A64
, BTYPE
);
14103 dc
->vec_stride
= 0;
14104 dc
->cp_regs
= arm_cpu
->cp_regs
;
14105 dc
->features
= env
->features
;
14107 /* Single step state. The code-generation logic here is:
14109 * generate code with no special handling for single-stepping (except
14110 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
14111 * this happens anyway because those changes are all system register or
14113 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
14114 * emit code for one insn
14115 * emit code to clear PSTATE.SS
14116 * emit code to generate software step exception for completed step
14117 * end TB (as usual for having generated an exception)
14118 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
14119 * emit code to generate a software step exception
14122 dc
->ss_active
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, SS_ACTIVE
);
14123 dc
->pstate_ss
= FIELD_EX32(tb_flags
, TBFLAG_ANY
, PSTATE_SS
);
14124 dc
->is_ldex
= false;
14125 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
14127 /* Bound the number of insns to execute to those left on the page. */
14128 bound
= -(dc
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
14130 /* If architectural single step active, limit to 1. */
14131 if (dc
->ss_active
) {
14134 dc
->base
.max_insns
= MIN(dc
->base
.max_insns
, bound
);
14136 init_tmp_a64_array(dc
);
14139 static void aarch64_tr_tb_start(DisasContextBase
*db
, CPUState
*cpu
)
14143 static void aarch64_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
14145 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14147 tcg_gen_insn_start(dc
->pc
, 0, 0);
14148 dc
->insn_start
= tcg_last_op();
14151 static bool aarch64_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cpu
,
14152 const CPUBreakpoint
*bp
)
14154 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14156 if (bp
->flags
& BP_CPU
) {
14157 gen_a64_set_pc_im(dc
->pc
);
14158 gen_helper_check_breakpoints(cpu_env
);
14159 /* End the TB early; it likely won't be executed */
14160 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
14162 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
14163 /* The address covered by the breakpoint must be
14164 included in [tb->pc, tb->pc + tb->size) in order
14165 to for it to be properly cleared -- thus we
14166 increment the PC here so that the logic setting
14167 tb->size below does the right thing. */
14169 dc
->base
.is_jmp
= DISAS_NORETURN
;
14175 static void aarch64_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
14177 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14178 CPUARMState
*env
= cpu
->env_ptr
;
14180 if (dc
->ss_active
&& !dc
->pstate_ss
) {
14181 /* Singlestep state is Active-pending.
14182 * If we're in this state at the start of a TB then either
14183 * a) we just took an exception to an EL which is being debugged
14184 * and this is the first insn in the exception handler
14185 * b) debug exceptions were masked and we just unmasked them
14186 * without changing EL (eg by clearing PSTATE.D)
14187 * In either case we're going to take a swstep exception in the
14188 * "did not step an insn" case, and so the syndrome ISV and EX
14189 * bits should be zero.
14191 assert(dc
->base
.num_insns
== 1);
14192 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0),
14193 default_exception_el(dc
));
14194 dc
->base
.is_jmp
= DISAS_NORETURN
;
14196 disas_a64_insn(env
, dc
);
14199 dc
->base
.pc_next
= dc
->pc
;
14200 translator_loop_temp_check(&dc
->base
);
14203 static void aarch64_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
14205 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14207 if (unlikely(dc
->base
.singlestep_enabled
|| dc
->ss_active
)) {
14208 /* Note that this means single stepping WFI doesn't halt the CPU.
14209 * For conditional branch insns this is harmless unreachable code as
14210 * gen_goto_tb() has already handled emitting the debug exception
14211 * (and thus a tb-jump is not possible when singlestepping).
14213 switch (dc
->base
.is_jmp
) {
14215 gen_a64_set_pc_im(dc
->pc
);
14219 if (dc
->base
.singlestep_enabled
) {
14220 gen_exception_internal(EXCP_DEBUG
);
14222 gen_step_complete_exception(dc
);
14225 case DISAS_NORETURN
:
14229 switch (dc
->base
.is_jmp
) {
14231 case DISAS_TOO_MANY
:
14232 gen_goto_tb(dc
, 1, dc
->pc
);
14236 gen_a64_set_pc_im(dc
->pc
);
14239 tcg_gen_exit_tb(NULL
, 0);
14242 tcg_gen_lookup_and_goto_ptr();
14244 case DISAS_NORETURN
:
14248 gen_a64_set_pc_im(dc
->pc
);
14249 gen_helper_wfe(cpu_env
);
14252 gen_a64_set_pc_im(dc
->pc
);
14253 gen_helper_yield(cpu_env
);
14257 /* This is a special case because we don't want to just halt the CPU
14258 * if trying to debug across a WFI.
14260 TCGv_i32 tmp
= tcg_const_i32(4);
14262 gen_a64_set_pc_im(dc
->pc
);
14263 gen_helper_wfi(cpu_env
, tmp
);
14264 tcg_temp_free_i32(tmp
);
14265 /* The helper doesn't necessarily throw an exception, but we
14266 * must go back to the main loop to check for interrupts anyway.
14268 tcg_gen_exit_tb(NULL
, 0);
14274 /* Functions above can change dc->pc, so re-align db->pc_next */
14275 dc
->base
.pc_next
= dc
->pc
;
14278 static void aarch64_tr_disas_log(const DisasContextBase
*dcbase
,
14281 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14283 qemu_log("IN: %s\n", lookup_symbol(dc
->base
.pc_first
));
14284 log_target_disas(cpu
, dc
->base
.pc_first
, dc
->base
.tb
->size
);
14287 const TranslatorOps aarch64_translator_ops
= {
14288 .init_disas_context
= aarch64_tr_init_disas_context
,
14289 .tb_start
= aarch64_tr_tb_start
,
14290 .insn_start
= aarch64_tr_insn_start
,
14291 .breakpoint_check
= aarch64_tr_breakpoint_check
,
14292 .translate_insn
= aarch64_tr_translate_insn
,
14293 .tb_stop
= aarch64_tr_tb_stop
,
14294 .disas_log
= aarch64_tr_disas_log
,