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"
41 static TCGv_i64 cpu_X
[32];
42 static TCGv_i64 cpu_pc
;
44 /* Load/store exclusive handling */
45 static TCGv_i64 cpu_exclusive_high
;
47 static const char *regnames
[] = {
48 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
49 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
50 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
51 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
55 A64_SHIFT_TYPE_LSL
= 0,
56 A64_SHIFT_TYPE_LSR
= 1,
57 A64_SHIFT_TYPE_ASR
= 2,
58 A64_SHIFT_TYPE_ROR
= 3
61 /* Table based decoder typedefs - used when the relevant bits for decode
62 * are too awkwardly scattered across the instruction (eg SIMD).
64 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
66 typedef struct AArch64DecodeTable
{
69 AArch64DecodeFn
*disas_fn
;
72 /* Function prototype for gen_ functions for calling Neon helpers */
73 typedef void NeonGenOneOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
);
74 typedef void NeonGenTwoOpFn(TCGv_i32
, TCGv_i32
, TCGv_i32
);
75 typedef void NeonGenTwoOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
, TCGv_i32
);
76 typedef void NeonGenTwo64OpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
);
77 typedef void NeonGenTwo64OpEnvFn(TCGv_i64
, TCGv_ptr
, TCGv_i64
, TCGv_i64
);
78 typedef void NeonGenNarrowFn(TCGv_i32
, TCGv_i64
);
79 typedef void NeonGenNarrowEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i64
);
80 typedef void NeonGenWidenFn(TCGv_i64
, TCGv_i32
);
81 typedef void NeonGenTwoSingleOPFn(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
82 typedef void NeonGenTwoDoubleOPFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGv_ptr
);
83 typedef void NeonGenOneOpFn(TCGv_i64
, TCGv_i64
);
84 typedef void CryptoTwoOpFn(TCGv_ptr
, TCGv_ptr
);
85 typedef void CryptoThreeOpIntFn(TCGv_ptr
, TCGv_ptr
, TCGv_i32
);
86 typedef void CryptoThreeOpFn(TCGv_ptr
, TCGv_ptr
, TCGv_ptr
);
87 typedef void AtomicThreeOpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGArg
, TCGMemOp
);
89 /* initialize TCG globals. */
90 void a64_translate_init(void)
94 cpu_pc
= tcg_global_mem_new_i64(cpu_env
,
95 offsetof(CPUARMState
, pc
),
97 for (i
= 0; i
< 32; i
++) {
98 cpu_X
[i
] = tcg_global_mem_new_i64(cpu_env
,
99 offsetof(CPUARMState
, xregs
[i
]),
103 cpu_exclusive_high
= tcg_global_mem_new_i64(cpu_env
,
104 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
107 static inline int get_a64_user_mem_index(DisasContext
*s
)
109 /* Return the core mmu_idx to use for A64 "unprivileged load/store" insns:
110 * if EL1, access as if EL0; otherwise access at current EL
114 switch (s
->mmu_idx
) {
115 case ARMMMUIdx_S12NSE1
:
116 useridx
= ARMMMUIdx_S12NSE0
;
118 case ARMMMUIdx_S1SE1
:
119 useridx
= ARMMMUIdx_S1SE0
;
122 g_assert_not_reached();
124 useridx
= s
->mmu_idx
;
127 return arm_to_core_mmu_idx(useridx
);
130 void aarch64_cpu_dump_state(CPUState
*cs
, FILE *f
,
131 fprintf_function cpu_fprintf
, int flags
)
133 ARMCPU
*cpu
= ARM_CPU(cs
);
134 CPUARMState
*env
= &cpu
->env
;
135 uint32_t psr
= pstate_read(env
);
137 int el
= arm_current_el(env
);
138 const char *ns_status
;
140 cpu_fprintf(f
, " PC=%016" PRIx64
" ", env
->pc
);
141 for (i
= 0; i
< 32; i
++) {
143 cpu_fprintf(f
, " SP=%016" PRIx64
"\n", env
->xregs
[i
]);
145 cpu_fprintf(f
, "X%02d=%016" PRIx64
"%s", i
, env
->xregs
[i
],
146 (i
+ 2) % 3 ? " " : "\n");
150 if (arm_feature(env
, ARM_FEATURE_EL3
) && el
!= 3) {
151 ns_status
= env
->cp15
.scr_el3
& SCR_NS
? "NS " : "S ";
155 cpu_fprintf(f
, "PSTATE=%08x %c%c%c%c %sEL%d%c",
157 psr
& PSTATE_N
? 'N' : '-',
158 psr
& PSTATE_Z
? 'Z' : '-',
159 psr
& PSTATE_C
? 'C' : '-',
160 psr
& PSTATE_V
? 'V' : '-',
163 psr
& PSTATE_SP
? 'h' : 't');
165 if (!(flags
& CPU_DUMP_FPU
)) {
166 cpu_fprintf(f
, "\n");
169 if (fp_exception_el(env
, el
) != 0) {
170 cpu_fprintf(f
, " FPU disabled\n");
173 cpu_fprintf(f
, " FPCR=%08x FPSR=%08x\n",
174 vfp_get_fpcr(env
), vfp_get_fpsr(env
));
176 if (arm_feature(env
, ARM_FEATURE_SVE
) && sve_exception_el(env
, el
) == 0) {
177 int j
, zcr_len
= sve_zcr_len_for_el(env
, el
);
179 for (i
= 0; i
<= FFR_PRED_NUM
; i
++) {
181 if (i
== FFR_PRED_NUM
) {
182 cpu_fprintf(f
, "FFR=");
183 /* It's last, so end the line. */
186 cpu_fprintf(f
, "P%02d=", i
);
199 /* More than one quadword per predicate. */
204 for (j
= zcr_len
/ 4; j
>= 0; j
--) {
206 if (j
* 4 + 4 <= zcr_len
+ 1) {
209 digits
= (zcr_len
% 4 + 1) * 4;
211 cpu_fprintf(f
, "%0*" PRIx64
"%s", digits
,
212 env
->vfp
.pregs
[i
].p
[j
],
213 j
? ":" : eol
? "\n" : " ");
217 for (i
= 0; i
< 32; i
++) {
219 cpu_fprintf(f
, "Z%02d=%016" PRIx64
":%016" PRIx64
"%s",
220 i
, env
->vfp
.zregs
[i
].d
[1],
221 env
->vfp
.zregs
[i
].d
[0], i
& 1 ? "\n" : " ");
222 } else if (zcr_len
== 1) {
223 cpu_fprintf(f
, "Z%02d=%016" PRIx64
":%016" PRIx64
224 ":%016" PRIx64
":%016" PRIx64
"\n",
225 i
, env
->vfp
.zregs
[i
].d
[3], env
->vfp
.zregs
[i
].d
[2],
226 env
->vfp
.zregs
[i
].d
[1], env
->vfp
.zregs
[i
].d
[0]);
228 for (j
= zcr_len
; j
>= 0; j
--) {
229 bool odd
= (zcr_len
- j
) % 2 != 0;
231 cpu_fprintf(f
, "Z%02d[%x-%x]=", i
, j
, j
- 1);
234 cpu_fprintf(f
, " [%x-%x]=", j
, j
- 1);
236 cpu_fprintf(f
, " [%x]=", j
);
239 cpu_fprintf(f
, "%016" PRIx64
":%016" PRIx64
"%s",
240 env
->vfp
.zregs
[i
].d
[j
* 2 + 1],
241 env
->vfp
.zregs
[i
].d
[j
* 2],
242 odd
|| j
== 0 ? "\n" : ":");
247 for (i
= 0; i
< 32; i
++) {
248 uint64_t *q
= aa64_vfp_qreg(env
, i
);
249 cpu_fprintf(f
, "Q%02d=%016" PRIx64
":%016" PRIx64
"%s",
250 i
, q
[1], q
[0], (i
& 1 ? "\n" : " "));
255 void gen_a64_set_pc_im(uint64_t val
)
257 tcg_gen_movi_i64(cpu_pc
, val
);
260 /* Load the PC from a generic TCG variable.
262 * If address tagging is enabled via the TCR TBI bits, then loading
263 * an address into the PC will clear out any tag in the it:
264 * + for EL2 and EL3 there is only one TBI bit, and if it is set
265 * then the address is zero-extended, clearing bits [63:56]
266 * + for EL0 and EL1, TBI0 controls addresses with bit 55 == 0
267 * and TBI1 controls addressses with bit 55 == 1.
268 * If the appropriate TBI bit is set for the address then
269 * the address is sign-extended from bit 55 into bits [63:56]
271 * We can avoid doing this for relative-branches, because the
272 * PC + offset can never overflow into the tag bits (assuming
273 * that virtual addresses are less than 56 bits wide, as they
274 * are currently), but we must handle it for branch-to-register.
276 static void gen_a64_set_pc(DisasContext
*s
, TCGv_i64 src
)
279 if (s
->current_el
<= 1) {
280 /* Test if NEITHER or BOTH TBI values are set. If so, no need to
281 * examine bit 55 of address, can just generate code.
282 * If mixed, then test via generated code
284 if (s
->tbi0
&& s
->tbi1
) {
285 TCGv_i64 tmp_reg
= tcg_temp_new_i64();
286 /* Both bits set, sign extension from bit 55 into [63:56] will
289 tcg_gen_shli_i64(tmp_reg
, src
, 8);
290 tcg_gen_sari_i64(cpu_pc
, tmp_reg
, 8);
291 tcg_temp_free_i64(tmp_reg
);
292 } else if (!s
->tbi0
&& !s
->tbi1
) {
293 /* Neither bit set, just load it as-is */
294 tcg_gen_mov_i64(cpu_pc
, src
);
296 TCGv_i64 tcg_tmpval
= tcg_temp_new_i64();
297 TCGv_i64 tcg_bit55
= tcg_temp_new_i64();
298 TCGv_i64 tcg_zero
= tcg_const_i64(0);
300 tcg_gen_andi_i64(tcg_bit55
, src
, (1ull << 55));
303 /* tbi0==1, tbi1==0, so 0-fill upper byte if bit 55 = 0 */
304 tcg_gen_andi_i64(tcg_tmpval
, src
,
305 0x00FFFFFFFFFFFFFFull
);
306 tcg_gen_movcond_i64(TCG_COND_EQ
, cpu_pc
, tcg_bit55
, tcg_zero
,
309 /* tbi0==0, tbi1==1, so 1-fill upper byte if bit 55 = 1 */
310 tcg_gen_ori_i64(tcg_tmpval
, src
,
311 0xFF00000000000000ull
);
312 tcg_gen_movcond_i64(TCG_COND_NE
, cpu_pc
, tcg_bit55
, tcg_zero
,
315 tcg_temp_free_i64(tcg_zero
);
316 tcg_temp_free_i64(tcg_bit55
);
317 tcg_temp_free_i64(tcg_tmpval
);
319 } else { /* EL > 1 */
321 /* Force tag byte to all zero */
322 tcg_gen_andi_i64(cpu_pc
, src
, 0x00FFFFFFFFFFFFFFull
);
324 /* Load unmodified address */
325 tcg_gen_mov_i64(cpu_pc
, src
);
330 typedef struct DisasCompare64
{
335 static void a64_test_cc(DisasCompare64
*c64
, int cc
)
339 arm_test_cc(&c32
, cc
);
341 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
342 * properly. The NE/EQ comparisons are also fine with this choice. */
343 c64
->cond
= c32
.cond
;
344 c64
->value
= tcg_temp_new_i64();
345 tcg_gen_ext_i32_i64(c64
->value
, c32
.value
);
350 static void a64_free_cc(DisasCompare64
*c64
)
352 tcg_temp_free_i64(c64
->value
);
355 static void gen_exception_internal(int excp
)
357 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
359 assert(excp_is_internal(excp
));
360 gen_helper_exception_internal(cpu_env
, tcg_excp
);
361 tcg_temp_free_i32(tcg_excp
);
364 static void gen_exception(int excp
, uint32_t syndrome
, uint32_t target_el
)
366 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
367 TCGv_i32 tcg_syn
= tcg_const_i32(syndrome
);
368 TCGv_i32 tcg_el
= tcg_const_i32(target_el
);
370 gen_helper_exception_with_syndrome(cpu_env
, tcg_excp
,
372 tcg_temp_free_i32(tcg_el
);
373 tcg_temp_free_i32(tcg_syn
);
374 tcg_temp_free_i32(tcg_excp
);
377 static void gen_exception_internal_insn(DisasContext
*s
, int offset
, int excp
)
379 gen_a64_set_pc_im(s
->pc
- offset
);
380 gen_exception_internal(excp
);
381 s
->base
.is_jmp
= DISAS_NORETURN
;
384 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
,
385 uint32_t syndrome
, uint32_t target_el
)
387 gen_a64_set_pc_im(s
->pc
- offset
);
388 gen_exception(excp
, syndrome
, target_el
);
389 s
->base
.is_jmp
= DISAS_NORETURN
;
392 static void gen_exception_bkpt_insn(DisasContext
*s
, int offset
,
397 gen_a64_set_pc_im(s
->pc
- offset
);
398 tcg_syn
= tcg_const_i32(syndrome
);
399 gen_helper_exception_bkpt_insn(cpu_env
, tcg_syn
);
400 tcg_temp_free_i32(tcg_syn
);
401 s
->base
.is_jmp
= DISAS_NORETURN
;
404 static void gen_ss_advance(DisasContext
*s
)
406 /* If the singlestep state is Active-not-pending, advance to
411 gen_helper_clear_pstate_ss(cpu_env
);
415 static void gen_step_complete_exception(DisasContext
*s
)
417 /* We just completed step of an insn. Move from Active-not-pending
418 * to Active-pending, and then also take the swstep exception.
419 * This corresponds to making the (IMPDEF) choice to prioritize
420 * swstep exceptions over asynchronous exceptions taken to an exception
421 * level where debug is disabled. This choice has the advantage that
422 * we do not need to maintain internal state corresponding to the
423 * ISV/EX syndrome bits between completion of the step and generation
424 * of the exception, and our syndrome information is always correct.
427 gen_exception(EXCP_UDEF
, syn_swstep(s
->ss_same_el
, 1, s
->is_ldex
),
428 default_exception_el(s
));
429 s
->base
.is_jmp
= DISAS_NORETURN
;
432 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
434 /* No direct tb linking with singlestep (either QEMU's or the ARM
435 * debug architecture kind) or deterministic io
437 if (s
->base
.singlestep_enabled
|| s
->ss_active
||
438 (tb_cflags(s
->base
.tb
) & CF_LAST_IO
)) {
442 #ifndef CONFIG_USER_ONLY
443 /* Only link tbs from inside the same guest page */
444 if ((s
->base
.tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
452 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
454 TranslationBlock
*tb
;
457 if (use_goto_tb(s
, n
, dest
)) {
459 gen_a64_set_pc_im(dest
);
460 tcg_gen_exit_tb(tb
, n
);
461 s
->base
.is_jmp
= DISAS_NORETURN
;
463 gen_a64_set_pc_im(dest
);
465 gen_step_complete_exception(s
);
466 } else if (s
->base
.singlestep_enabled
) {
467 gen_exception_internal(EXCP_DEBUG
);
469 tcg_gen_lookup_and_goto_ptr();
470 s
->base
.is_jmp
= DISAS_NORETURN
;
475 void unallocated_encoding(DisasContext
*s
)
477 /* Unallocated and reserved encodings are uncategorized */
478 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized(),
479 default_exception_el(s
));
482 static void init_tmp_a64_array(DisasContext
*s
)
484 #ifdef CONFIG_DEBUG_TCG
485 memset(s
->tmp_a64
, 0, sizeof(s
->tmp_a64
));
487 s
->tmp_a64_count
= 0;
490 static void free_tmp_a64(DisasContext
*s
)
493 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
494 tcg_temp_free_i64(s
->tmp_a64
[i
]);
496 init_tmp_a64_array(s
);
499 TCGv_i64
new_tmp_a64(DisasContext
*s
)
501 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
502 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
505 TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
507 TCGv_i64 t
= new_tmp_a64(s
);
508 tcg_gen_movi_i64(t
, 0);
513 * Register access functions
515 * These functions are used for directly accessing a register in where
516 * changes to the final register value are likely to be made. If you
517 * need to use a register for temporary calculation (e.g. index type
518 * operations) use the read_* form.
520 * B1.2.1 Register mappings
522 * In instruction register encoding 31 can refer to ZR (zero register) or
523 * the SP (stack pointer) depending on context. In QEMU's case we map SP
524 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
525 * This is the point of the _sp forms.
527 TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
530 return new_tmp_a64_zero(s
);
536 /* register access for when 31 == SP */
537 TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
542 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
543 * representing the register contents. This TCGv is an auto-freed
544 * temporary so it need not be explicitly freed, and may be modified.
546 TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
548 TCGv_i64 v
= new_tmp_a64(s
);
551 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
553 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
556 tcg_gen_movi_i64(v
, 0);
561 TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
563 TCGv_i64 v
= new_tmp_a64(s
);
565 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
567 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
572 /* Return the offset into CPUARMState of a slice (from
573 * the least significant end) of FP register Qn (ie
575 * (Note that this is not the same mapping as for A32; see cpu.h)
577 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
579 return vec_reg_offset(s
, regno
, 0, size
);
582 /* Offset of the high half of the 128 bit vector Qn */
583 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
585 return vec_reg_offset(s
, regno
, 1, MO_64
);
588 /* Convenience accessors for reading and writing single and double
589 * FP registers. Writing clears the upper parts of the associated
590 * 128 bit vector register, as required by the architecture.
591 * Note that unlike the GP register accessors, the values returned
592 * by the read functions must be manually freed.
594 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
596 TCGv_i64 v
= tcg_temp_new_i64();
598 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
602 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
604 TCGv_i32 v
= tcg_temp_new_i32();
606 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
610 static TCGv_i32
read_fp_hreg(DisasContext
*s
, int reg
)
612 TCGv_i32 v
= tcg_temp_new_i32();
614 tcg_gen_ld16u_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_16
));
618 /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64).
619 * If SVE is not enabled, then there are only 128 bits in the vector.
621 static void clear_vec_high(DisasContext
*s
, bool is_q
, int rd
)
623 unsigned ofs
= fp_reg_offset(s
, rd
, MO_64
);
624 unsigned vsz
= vec_full_reg_size(s
);
627 TCGv_i64 tcg_zero
= tcg_const_i64(0);
628 tcg_gen_st_i64(tcg_zero
, cpu_env
, ofs
+ 8);
629 tcg_temp_free_i64(tcg_zero
);
632 tcg_gen_gvec_dup8i(ofs
+ 16, vsz
- 16, vsz
- 16, 0);
636 void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
638 unsigned ofs
= fp_reg_offset(s
, reg
, MO_64
);
640 tcg_gen_st_i64(v
, cpu_env
, ofs
);
641 clear_vec_high(s
, false, reg
);
644 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
646 TCGv_i64 tmp
= tcg_temp_new_i64();
648 tcg_gen_extu_i32_i64(tmp
, v
);
649 write_fp_dreg(s
, reg
, tmp
);
650 tcg_temp_free_i64(tmp
);
653 TCGv_ptr
get_fpstatus_ptr(bool is_f16
)
655 TCGv_ptr statusptr
= tcg_temp_new_ptr();
658 /* In A64 all instructions (both FP and Neon) use the FPCR; there
659 * is no equivalent of the A32 Neon "standard FPSCR value".
660 * However half-precision operations operate under a different
661 * FZ16 flag and use vfp.fp_status_f16 instead of vfp.fp_status.
664 offset
= offsetof(CPUARMState
, vfp
.fp_status_f16
);
666 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
668 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
672 /* Expand a 2-operand AdvSIMD vector operation using an expander function. */
673 static void gen_gvec_fn2(DisasContext
*s
, bool is_q
, int rd
, int rn
,
674 GVecGen2Fn
*gvec_fn
, int vece
)
676 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
677 is_q
? 16 : 8, vec_full_reg_size(s
));
680 /* Expand a 2-operand + immediate AdvSIMD vector operation using
681 * an expander function.
683 static void gen_gvec_fn2i(DisasContext
*s
, bool is_q
, int rd
, int rn
,
684 int64_t imm
, GVecGen2iFn
*gvec_fn
, int vece
)
686 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
687 imm
, is_q
? 16 : 8, vec_full_reg_size(s
));
690 /* Expand a 3-operand AdvSIMD vector operation using an expander function. */
691 static void gen_gvec_fn3(DisasContext
*s
, bool is_q
, int rd
, int rn
, int rm
,
692 GVecGen3Fn
*gvec_fn
, int vece
)
694 gvec_fn(vece
, vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
695 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8, vec_full_reg_size(s
));
698 /* Expand a 2-operand + immediate AdvSIMD vector operation using
701 static void gen_gvec_op2i(DisasContext
*s
, bool is_q
, int rd
,
702 int rn
, int64_t imm
, const GVecGen2i
*gvec_op
)
704 tcg_gen_gvec_2i(vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
705 is_q
? 16 : 8, vec_full_reg_size(s
), imm
, gvec_op
);
708 /* Expand a 3-operand AdvSIMD vector operation using an op descriptor. */
709 static void gen_gvec_op3(DisasContext
*s
, bool is_q
, int rd
,
710 int rn
, int rm
, const GVecGen3
*gvec_op
)
712 tcg_gen_gvec_3(vec_full_reg_offset(s
, rd
), vec_full_reg_offset(s
, rn
),
713 vec_full_reg_offset(s
, rm
), is_q
? 16 : 8,
714 vec_full_reg_size(s
), gvec_op
);
717 /* Expand a 3-operand operation using an out-of-line helper. */
718 static void gen_gvec_op3_ool(DisasContext
*s
, bool is_q
, int rd
,
719 int rn
, int rm
, int data
, gen_helper_gvec_3
*fn
)
721 tcg_gen_gvec_3_ool(vec_full_reg_offset(s
, rd
),
722 vec_full_reg_offset(s
, rn
),
723 vec_full_reg_offset(s
, rm
),
724 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
727 /* Expand a 3-operand + env pointer operation using
728 * an out-of-line helper.
730 static void gen_gvec_op3_env(DisasContext
*s
, bool is_q
, int rd
,
731 int rn
, int rm
, gen_helper_gvec_3_ptr
*fn
)
733 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
734 vec_full_reg_offset(s
, rn
),
735 vec_full_reg_offset(s
, rm
), cpu_env
,
736 is_q
? 16 : 8, vec_full_reg_size(s
), 0, fn
);
739 /* Expand a 3-operand + fpstatus pointer + simd data value operation using
740 * an out-of-line helper.
742 static void gen_gvec_op3_fpst(DisasContext
*s
, bool is_q
, int rd
, int rn
,
743 int rm
, bool is_fp16
, int data
,
744 gen_helper_gvec_3_ptr
*fn
)
746 TCGv_ptr fpst
= get_fpstatus_ptr(is_fp16
);
747 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
748 vec_full_reg_offset(s
, rn
),
749 vec_full_reg_offset(s
, rm
), fpst
,
750 is_q
? 16 : 8, vec_full_reg_size(s
), data
, fn
);
751 tcg_temp_free_ptr(fpst
);
754 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
755 * than the 32 bit equivalent.
757 static inline void gen_set_NZ64(TCGv_i64 result
)
759 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
760 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
763 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
764 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
767 gen_set_NZ64(result
);
769 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
770 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
772 tcg_gen_movi_i32(cpu_CF
, 0);
773 tcg_gen_movi_i32(cpu_VF
, 0);
776 /* dest = T0 + T1; compute C, N, V and Z flags */
777 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
780 TCGv_i64 result
, flag
, tmp
;
781 result
= tcg_temp_new_i64();
782 flag
= tcg_temp_new_i64();
783 tmp
= tcg_temp_new_i64();
785 tcg_gen_movi_i64(tmp
, 0);
786 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
788 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
790 gen_set_NZ64(result
);
792 tcg_gen_xor_i64(flag
, result
, t0
);
793 tcg_gen_xor_i64(tmp
, t0
, t1
);
794 tcg_gen_andc_i64(flag
, flag
, tmp
);
795 tcg_temp_free_i64(tmp
);
796 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
798 tcg_gen_mov_i64(dest
, result
);
799 tcg_temp_free_i64(result
);
800 tcg_temp_free_i64(flag
);
802 /* 32 bit arithmetic */
803 TCGv_i32 t0_32
= tcg_temp_new_i32();
804 TCGv_i32 t1_32
= tcg_temp_new_i32();
805 TCGv_i32 tmp
= tcg_temp_new_i32();
807 tcg_gen_movi_i32(tmp
, 0);
808 tcg_gen_extrl_i64_i32(t0_32
, t0
);
809 tcg_gen_extrl_i64_i32(t1_32
, t1
);
810 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
811 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
812 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
813 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
814 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
815 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
817 tcg_temp_free_i32(tmp
);
818 tcg_temp_free_i32(t0_32
);
819 tcg_temp_free_i32(t1_32
);
823 /* dest = T0 - T1; compute C, N, V and Z flags */
824 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
827 /* 64 bit arithmetic */
828 TCGv_i64 result
, flag
, tmp
;
830 result
= tcg_temp_new_i64();
831 flag
= tcg_temp_new_i64();
832 tcg_gen_sub_i64(result
, t0
, t1
);
834 gen_set_NZ64(result
);
836 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
837 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
839 tcg_gen_xor_i64(flag
, result
, t0
);
840 tmp
= tcg_temp_new_i64();
841 tcg_gen_xor_i64(tmp
, t0
, t1
);
842 tcg_gen_and_i64(flag
, flag
, tmp
);
843 tcg_temp_free_i64(tmp
);
844 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
845 tcg_gen_mov_i64(dest
, result
);
846 tcg_temp_free_i64(flag
);
847 tcg_temp_free_i64(result
);
849 /* 32 bit arithmetic */
850 TCGv_i32 t0_32
= tcg_temp_new_i32();
851 TCGv_i32 t1_32
= tcg_temp_new_i32();
854 tcg_gen_extrl_i64_i32(t0_32
, t0
);
855 tcg_gen_extrl_i64_i32(t1_32
, t1
);
856 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
857 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
858 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
859 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
860 tmp
= tcg_temp_new_i32();
861 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
862 tcg_temp_free_i32(t0_32
);
863 tcg_temp_free_i32(t1_32
);
864 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
865 tcg_temp_free_i32(tmp
);
866 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
870 /* dest = T0 + T1 + CF; do not compute flags. */
871 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
873 TCGv_i64 flag
= tcg_temp_new_i64();
874 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
875 tcg_gen_add_i64(dest
, t0
, t1
);
876 tcg_gen_add_i64(dest
, dest
, flag
);
877 tcg_temp_free_i64(flag
);
880 tcg_gen_ext32u_i64(dest
, dest
);
884 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
885 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
888 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
889 result
= tcg_temp_new_i64();
890 cf_64
= tcg_temp_new_i64();
891 vf_64
= tcg_temp_new_i64();
892 tmp
= tcg_const_i64(0);
894 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
895 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
896 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
897 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
898 gen_set_NZ64(result
);
900 tcg_gen_xor_i64(vf_64
, result
, t0
);
901 tcg_gen_xor_i64(tmp
, t0
, t1
);
902 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
903 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
905 tcg_gen_mov_i64(dest
, result
);
907 tcg_temp_free_i64(tmp
);
908 tcg_temp_free_i64(vf_64
);
909 tcg_temp_free_i64(cf_64
);
910 tcg_temp_free_i64(result
);
912 TCGv_i32 t0_32
, t1_32
, tmp
;
913 t0_32
= tcg_temp_new_i32();
914 t1_32
= tcg_temp_new_i32();
915 tmp
= tcg_const_i32(0);
917 tcg_gen_extrl_i64_i32(t0_32
, t0
);
918 tcg_gen_extrl_i64_i32(t1_32
, t1
);
919 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
920 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
922 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
923 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
924 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
925 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
926 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
928 tcg_temp_free_i32(tmp
);
929 tcg_temp_free_i32(t1_32
);
930 tcg_temp_free_i32(t0_32
);
935 * Load/Store generators
939 * Store from GPR register to memory.
941 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
942 TCGv_i64 tcg_addr
, int size
, int memidx
,
944 unsigned int iss_srt
,
945 bool iss_sf
, bool iss_ar
)
948 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, s
->be_data
+ size
);
953 syn
= syn_data_abort_with_iss(0,
959 0, 0, 0, 0, 0, false);
960 disas_set_insn_syndrome(s
, syn
);
964 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
965 TCGv_i64 tcg_addr
, int size
,
967 unsigned int iss_srt
,
968 bool iss_sf
, bool iss_ar
)
970 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
),
971 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
975 * Load from memory to GPR register
977 static void do_gpr_ld_memidx(DisasContext
*s
,
978 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
979 int size
, bool is_signed
,
980 bool extend
, int memidx
,
981 bool iss_valid
, unsigned int iss_srt
,
982 bool iss_sf
, bool iss_ar
)
984 TCGMemOp memop
= s
->be_data
+ size
;
992 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
994 if (extend
&& is_signed
) {
996 tcg_gen_ext32u_i64(dest
, dest
);
1002 syn
= syn_data_abort_with_iss(0,
1008 0, 0, 0, 0, 0, false);
1009 disas_set_insn_syndrome(s
, syn
);
1013 static void do_gpr_ld(DisasContext
*s
,
1014 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
1015 int size
, bool is_signed
, bool extend
,
1016 bool iss_valid
, unsigned int iss_srt
,
1017 bool iss_sf
, bool iss_ar
)
1019 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
1021 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
1025 * Store from FP register to memory
1027 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
1029 /* This writes the bottom N bits of a 128 bit wide vector to memory */
1030 TCGv_i64 tmp
= tcg_temp_new_i64();
1031 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
1033 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
),
1036 bool be
= s
->be_data
== MO_BE
;
1037 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
1039 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
1040 tcg_gen_qemu_st_i64(tmp
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
1042 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
1043 tcg_gen_qemu_st_i64(tmp
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
1045 tcg_temp_free_i64(tcg_hiaddr
);
1048 tcg_temp_free_i64(tmp
);
1052 * Load from memory to FP register
1054 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
1056 /* This always zero-extends and writes to a full 128 bit wide vector */
1057 TCGv_i64 tmplo
= tcg_temp_new_i64();
1061 TCGMemOp memop
= s
->be_data
+ size
;
1062 tmphi
= tcg_const_i64(0);
1063 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
1065 bool be
= s
->be_data
== MO_BE
;
1066 TCGv_i64 tcg_hiaddr
;
1068 tmphi
= tcg_temp_new_i64();
1069 tcg_hiaddr
= tcg_temp_new_i64();
1071 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
1072 tcg_gen_qemu_ld_i64(tmplo
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
1074 tcg_gen_qemu_ld_i64(tmphi
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
1076 tcg_temp_free_i64(tcg_hiaddr
);
1079 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
1080 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
1082 tcg_temp_free_i64(tmplo
);
1083 tcg_temp_free_i64(tmphi
);
1085 clear_vec_high(s
, true, destidx
);
1089 * Vector load/store helpers.
1091 * The principal difference between this and a FP load is that we don't
1092 * zero extend as we are filling a partial chunk of the vector register.
1093 * These functions don't support 128 bit loads/stores, which would be
1094 * normal load/store operations.
1096 * The _i32 versions are useful when operating on 32 bit quantities
1097 * (eg for floating point single or using Neon helper functions).
1100 /* Get value of an element within a vector register */
1101 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
1102 int element
, TCGMemOp memop
)
1104 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1107 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
1110 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
1113 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
1116 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
1119 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
1122 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
1126 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
1129 g_assert_not_reached();
1133 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
1134 int element
, TCGMemOp memop
)
1136 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
1139 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
1142 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
1145 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
1148 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
1152 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
1155 g_assert_not_reached();
1159 /* Set value of an element within a vector register */
1160 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
1161 int element
, TCGMemOp memop
)
1163 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1166 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
1169 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
1172 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
1175 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
1178 g_assert_not_reached();
1182 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
1183 int destidx
, int element
, TCGMemOp memop
)
1185 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
1188 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
1191 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
1194 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
1197 g_assert_not_reached();
1201 /* Store from vector register to memory */
1202 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
1203 TCGv_i64 tcg_addr
, int size
)
1205 TCGMemOp memop
= s
->be_data
+ size
;
1206 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1208 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
1209 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
1211 tcg_temp_free_i64(tcg_tmp
);
1214 /* Load from memory to vector register */
1215 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
1216 TCGv_i64 tcg_addr
, int size
)
1218 TCGMemOp memop
= s
->be_data
+ size
;
1219 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1221 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
1222 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
1224 tcg_temp_free_i64(tcg_tmp
);
1227 /* Check that FP/Neon access is enabled. If it is, return
1228 * true. If not, emit code to generate an appropriate exception,
1229 * and return false; the caller should not emit any code for
1230 * the instruction. Note that this check must happen after all
1231 * unallocated-encoding checks (otherwise the syndrome information
1232 * for the resulting exception will be incorrect).
1234 static inline bool fp_access_check(DisasContext
*s
)
1236 assert(!s
->fp_access_checked
);
1237 s
->fp_access_checked
= true;
1239 if (!s
->fp_excp_el
) {
1243 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false),
1248 /* Check that SVE access is enabled. If it is, return true.
1249 * If not, emit code to generate an appropriate exception and return false.
1251 bool sve_access_check(DisasContext
*s
)
1253 if (s
->sve_excp_el
) {
1254 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_sve_access_trap(),
1258 return fp_access_check(s
);
1262 * This utility function is for doing register extension with an
1263 * optional shift. You will likely want to pass a temporary for the
1264 * destination register. See DecodeRegExtend() in the ARM ARM.
1266 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1267 int option
, unsigned int shift
)
1269 int extsize
= extract32(option
, 0, 2);
1270 bool is_signed
= extract32(option
, 2, 1);
1275 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1278 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1281 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1284 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1290 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1293 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1296 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1299 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1305 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1309 static inline void gen_check_sp_alignment(DisasContext
*s
)
1311 /* The AArch64 architecture mandates that (if enabled via PSTATE
1312 * or SCTLR bits) there is a check that SP is 16-aligned on every
1313 * SP-relative load or store (with an exception generated if it is not).
1314 * In line with general QEMU practice regarding misaligned accesses,
1315 * we omit these checks for the sake of guest program performance.
1316 * This function is provided as a hook so we can more easily add these
1317 * checks in future (possibly as a "favour catching guest program bugs
1318 * over speed" user selectable option).
1323 * This provides a simple table based table lookup decoder. It is
1324 * intended to be used when the relevant bits for decode are too
1325 * awkwardly placed and switch/if based logic would be confusing and
1326 * deeply nested. Since it's a linear search through the table, tables
1327 * should be kept small.
1329 * It returns the first handler where insn & mask == pattern, or
1330 * NULL if there is no match.
1331 * The table is terminated by an empty mask (i.e. 0)
1333 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1336 const AArch64DecodeTable
*tptr
= table
;
1338 while (tptr
->mask
) {
1339 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1340 return tptr
->disas_fn
;
1348 * The instruction disassembly implemented here matches
1349 * the instruction encoding classifications in chapter C4
1350 * of the ARM Architecture Reference Manual (DDI0487B_a);
1351 * classification names and decode diagrams here should generally
1352 * match up with those in the manual.
1355 /* Unconditional branch (immediate)
1357 * +----+-----------+-------------------------------------+
1358 * | op | 0 0 1 0 1 | imm26 |
1359 * +----+-----------+-------------------------------------+
1361 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1363 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1365 if (insn
& (1U << 31)) {
1366 /* BL Branch with link */
1367 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1370 /* B Branch / BL Branch with link */
1371 gen_goto_tb(s
, 0, addr
);
1374 /* Compare and branch (immediate)
1375 * 31 30 25 24 23 5 4 0
1376 * +----+-------------+----+---------------------+--------+
1377 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1378 * +----+-------------+----+---------------------+--------+
1380 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1382 unsigned int sf
, op
, rt
;
1384 TCGLabel
*label_match
;
1387 sf
= extract32(insn
, 31, 1);
1388 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1389 rt
= extract32(insn
, 0, 5);
1390 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1392 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1393 label_match
= gen_new_label();
1395 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1396 tcg_cmp
, 0, label_match
);
1398 gen_goto_tb(s
, 0, s
->pc
);
1399 gen_set_label(label_match
);
1400 gen_goto_tb(s
, 1, addr
);
1403 /* Test and branch (immediate)
1404 * 31 30 25 24 23 19 18 5 4 0
1405 * +----+-------------+----+-------+-------------+------+
1406 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1407 * +----+-------------+----+-------+-------------+------+
1409 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1411 unsigned int bit_pos
, op
, rt
;
1413 TCGLabel
*label_match
;
1416 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1417 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1418 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1419 rt
= extract32(insn
, 0, 5);
1421 tcg_cmp
= tcg_temp_new_i64();
1422 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1423 label_match
= gen_new_label();
1424 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1425 tcg_cmp
, 0, label_match
);
1426 tcg_temp_free_i64(tcg_cmp
);
1427 gen_goto_tb(s
, 0, s
->pc
);
1428 gen_set_label(label_match
);
1429 gen_goto_tb(s
, 1, addr
);
1432 /* Conditional branch (immediate)
1433 * 31 25 24 23 5 4 3 0
1434 * +---------------+----+---------------------+----+------+
1435 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1436 * +---------------+----+---------------------+----+------+
1438 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1443 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1444 unallocated_encoding(s
);
1447 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1448 cond
= extract32(insn
, 0, 4);
1451 /* genuinely conditional branches */
1452 TCGLabel
*label_match
= gen_new_label();
1453 arm_gen_test_cc(cond
, label_match
);
1454 gen_goto_tb(s
, 0, s
->pc
);
1455 gen_set_label(label_match
);
1456 gen_goto_tb(s
, 1, addr
);
1458 /* 0xe and 0xf are both "always" conditions */
1459 gen_goto_tb(s
, 0, addr
);
1463 /* HINT instruction group, including various allocated HINTs */
1464 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1465 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1467 unsigned int selector
= crm
<< 3 | op2
;
1470 unallocated_encoding(s
);
1478 s
->base
.is_jmp
= DISAS_WFI
;
1480 /* When running in MTTCG we don't generate jumps to the yield and
1481 * WFE helpers as it won't affect the scheduling of other vCPUs.
1482 * If we wanted to more completely model WFE/SEV so we don't busy
1483 * spin unnecessarily we would need to do something more involved.
1486 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1487 s
->base
.is_jmp
= DISAS_YIELD
;
1491 if (!(tb_cflags(s
->base
.tb
) & CF_PARALLEL
)) {
1492 s
->base
.is_jmp
= DISAS_WFE
;
1497 /* we treat all as NOP at least for now */
1500 /* default specified as NOP equivalent */
1505 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1507 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1510 /* CLREX, DSB, DMB, ISB */
1511 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1512 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1517 unallocated_encoding(s
);
1528 case 1: /* MBReqTypes_Reads */
1529 bar
= TCG_BAR_SC
| TCG_MO_LD_LD
| TCG_MO_LD_ST
;
1531 case 2: /* MBReqTypes_Writes */
1532 bar
= TCG_BAR_SC
| TCG_MO_ST_ST
;
1534 default: /* MBReqTypes_All */
1535 bar
= TCG_BAR_SC
| TCG_MO_ALL
;
1541 /* We need to break the TB after this insn to execute
1542 * a self-modified code correctly and also to take
1543 * any pending interrupts immediately.
1545 gen_goto_tb(s
, 0, s
->pc
);
1548 unallocated_encoding(s
);
1553 /* MSR (immediate) - move immediate to processor state field */
1554 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1555 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1557 int op
= op1
<< 3 | op2
;
1559 case 0x05: /* SPSel */
1560 if (s
->current_el
== 0) {
1561 unallocated_encoding(s
);
1565 case 0x1e: /* DAIFSet */
1566 case 0x1f: /* DAIFClear */
1568 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1569 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1570 gen_a64_set_pc_im(s
->pc
- 4);
1571 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1572 tcg_temp_free_i32(tcg_imm
);
1573 tcg_temp_free_i32(tcg_op
);
1574 /* For DAIFClear, exit the cpu loop to re-evaluate pending IRQs. */
1575 gen_a64_set_pc_im(s
->pc
);
1576 s
->base
.is_jmp
= (op
== 0x1f ? DISAS_EXIT
: DISAS_JUMP
);
1580 unallocated_encoding(s
);
1585 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1587 TCGv_i32 tmp
= tcg_temp_new_i32();
1588 TCGv_i32 nzcv
= tcg_temp_new_i32();
1590 /* build bit 31, N */
1591 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1592 /* build bit 30, Z */
1593 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1594 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1595 /* build bit 29, C */
1596 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1597 /* build bit 28, V */
1598 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1599 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1600 /* generate result */
1601 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1603 tcg_temp_free_i32(nzcv
);
1604 tcg_temp_free_i32(tmp
);
1607 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1610 TCGv_i32 nzcv
= tcg_temp_new_i32();
1612 /* take NZCV from R[t] */
1613 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1616 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1618 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1619 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1621 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1622 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1624 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1625 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1626 tcg_temp_free_i32(nzcv
);
1629 /* MRS - move from system register
1630 * MSR (register) - move to system register
1633 * These are all essentially the same insn in 'read' and 'write'
1634 * versions, with varying op0 fields.
1636 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1637 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1638 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1640 const ARMCPRegInfo
*ri
;
1643 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1644 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1645 crn
, crm
, op0
, op1
, op2
));
1648 /* Unknown register; this might be a guest error or a QEMU
1649 * unimplemented feature.
1651 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1652 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1653 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1654 unallocated_encoding(s
);
1658 /* Check access permissions */
1659 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1660 unallocated_encoding(s
);
1665 /* Emit code to perform further access permissions checks at
1666 * runtime; this may result in an exception.
1669 TCGv_i32 tcg_syn
, tcg_isread
;
1672 gen_a64_set_pc_im(s
->pc
- 4);
1673 tmpptr
= tcg_const_ptr(ri
);
1674 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1675 tcg_syn
= tcg_const_i32(syndrome
);
1676 tcg_isread
= tcg_const_i32(isread
);
1677 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
, tcg_isread
);
1678 tcg_temp_free_ptr(tmpptr
);
1679 tcg_temp_free_i32(tcg_syn
);
1680 tcg_temp_free_i32(tcg_isread
);
1683 /* Handle special cases first */
1684 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1688 tcg_rt
= cpu_reg(s
, rt
);
1690 gen_get_nzcv(tcg_rt
);
1692 gen_set_nzcv(tcg_rt
);
1695 case ARM_CP_CURRENTEL
:
1696 /* Reads as current EL value from pstate, which is
1697 * guaranteed to be constant by the tb flags.
1699 tcg_rt
= cpu_reg(s
, rt
);
1700 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1703 /* Writes clear the aligned block of memory which rt points into. */
1704 tcg_rt
= cpu_reg(s
, rt
);
1705 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1710 if ((ri
->type
& ARM_CP_FPU
) && !fp_access_check(s
)) {
1712 } else if ((ri
->type
& ARM_CP_SVE
) && !sve_access_check(s
)) {
1716 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1720 tcg_rt
= cpu_reg(s
, rt
);
1723 if (ri
->type
& ARM_CP_CONST
) {
1724 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1725 } else if (ri
->readfn
) {
1727 tmpptr
= tcg_const_ptr(ri
);
1728 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1729 tcg_temp_free_ptr(tmpptr
);
1731 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1734 if (ri
->type
& ARM_CP_CONST
) {
1735 /* If not forbidden by access permissions, treat as WI */
1737 } else if (ri
->writefn
) {
1739 tmpptr
= tcg_const_ptr(ri
);
1740 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1741 tcg_temp_free_ptr(tmpptr
);
1743 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1747 if ((tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1748 /* I/O operations must end the TB here (whether read or write) */
1750 s
->base
.is_jmp
= DISAS_UPDATE
;
1751 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1752 /* We default to ending the TB on a coprocessor register write,
1753 * but allow this to be suppressed by the register definition
1754 * (usually only necessary to work around guest bugs).
1756 s
->base
.is_jmp
= DISAS_UPDATE
;
1761 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1762 * +---------------------+---+-----+-----+-------+-------+-----+------+
1763 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1764 * +---------------------+---+-----+-----+-------+-------+-----+------+
1766 static void disas_system(DisasContext
*s
, uint32_t insn
)
1768 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1769 l
= extract32(insn
, 21, 1);
1770 op0
= extract32(insn
, 19, 2);
1771 op1
= extract32(insn
, 16, 3);
1772 crn
= extract32(insn
, 12, 4);
1773 crm
= extract32(insn
, 8, 4);
1774 op2
= extract32(insn
, 5, 3);
1775 rt
= extract32(insn
, 0, 5);
1778 if (l
|| rt
!= 31) {
1779 unallocated_encoding(s
);
1783 case 2: /* HINT (including allocated hints like NOP, YIELD, etc) */
1784 handle_hint(s
, insn
, op1
, op2
, crm
);
1786 case 3: /* CLREX, DSB, DMB, ISB */
1787 handle_sync(s
, insn
, op1
, op2
, crm
);
1789 case 4: /* MSR (immediate) */
1790 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1793 unallocated_encoding(s
);
1798 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1801 /* Exception generation
1803 * 31 24 23 21 20 5 4 2 1 0
1804 * +-----------------+-----+------------------------+-----+----+
1805 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1806 * +-----------------------+------------------------+----------+
1808 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1810 int opc
= extract32(insn
, 21, 3);
1811 int op2_ll
= extract32(insn
, 0, 5);
1812 int imm16
= extract32(insn
, 5, 16);
1817 /* For SVC, HVC and SMC we advance the single-step state
1818 * machine before taking the exception. This is architecturally
1819 * mandated, to ensure that single-stepping a system call
1820 * instruction works properly.
1825 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
),
1826 default_exception_el(s
));
1829 if (s
->current_el
== 0) {
1830 unallocated_encoding(s
);
1833 /* The pre HVC helper handles cases when HVC gets trapped
1834 * as an undefined insn by runtime configuration.
1836 gen_a64_set_pc_im(s
->pc
- 4);
1837 gen_helper_pre_hvc(cpu_env
);
1839 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
), 2);
1842 if (s
->current_el
== 0) {
1843 unallocated_encoding(s
);
1846 gen_a64_set_pc_im(s
->pc
- 4);
1847 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1848 gen_helper_pre_smc(cpu_env
, tmp
);
1849 tcg_temp_free_i32(tmp
);
1851 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
), 3);
1854 unallocated_encoding(s
);
1860 unallocated_encoding(s
);
1864 gen_exception_bkpt_insn(s
, 4, syn_aa64_bkpt(imm16
));
1868 unallocated_encoding(s
);
1871 /* HLT. This has two purposes.
1872 * Architecturally, it is an external halting debug instruction.
1873 * Since QEMU doesn't implement external debug, we treat this as
1874 * it is required for halting debug disabled: it will UNDEF.
1875 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1877 if (semihosting_enabled() && imm16
== 0xf000) {
1878 #ifndef CONFIG_USER_ONLY
1879 /* In system mode, don't allow userspace access to semihosting,
1880 * to provide some semblance of security (and for consistency
1881 * with our 32-bit semihosting).
1883 if (s
->current_el
== 0) {
1884 unsupported_encoding(s
, insn
);
1888 gen_exception_internal_insn(s
, 0, EXCP_SEMIHOST
);
1890 unsupported_encoding(s
, insn
);
1894 if (op2_ll
< 1 || op2_ll
> 3) {
1895 unallocated_encoding(s
);
1898 /* DCPS1, DCPS2, DCPS3 */
1899 unsupported_encoding(s
, insn
);
1902 unallocated_encoding(s
);
1907 /* Unconditional branch (register)
1908 * 31 25 24 21 20 16 15 10 9 5 4 0
1909 * +---------------+-------+-------+-------+------+-------+
1910 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1911 * +---------------+-------+-------+-------+------+-------+
1913 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1915 unsigned int opc
, op2
, op3
, rn
, op4
;
1917 opc
= extract32(insn
, 21, 4);
1918 op2
= extract32(insn
, 16, 5);
1919 op3
= extract32(insn
, 10, 6);
1920 rn
= extract32(insn
, 5, 5);
1921 op4
= extract32(insn
, 0, 5);
1923 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1924 unallocated_encoding(s
);
1932 gen_a64_set_pc(s
, cpu_reg(s
, rn
));
1933 /* BLR also needs to load return address */
1935 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1939 if (s
->current_el
== 0) {
1940 unallocated_encoding(s
);
1943 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
1946 gen_helper_exception_return(cpu_env
);
1947 if (tb_cflags(s
->base
.tb
) & CF_USE_ICOUNT
) {
1950 /* Must exit loop to check un-masked IRQs */
1951 s
->base
.is_jmp
= DISAS_EXIT
;
1955 unallocated_encoding(s
);
1957 unsupported_encoding(s
, insn
);
1961 unallocated_encoding(s
);
1965 s
->base
.is_jmp
= DISAS_JUMP
;
1968 /* Branches, exception generating and system instructions */
1969 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1971 switch (extract32(insn
, 25, 7)) {
1972 case 0x0a: case 0x0b:
1973 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1974 disas_uncond_b_imm(s
, insn
);
1976 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1977 disas_comp_b_imm(s
, insn
);
1979 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1980 disas_test_b_imm(s
, insn
);
1982 case 0x2a: /* Conditional branch (immediate) */
1983 disas_cond_b_imm(s
, insn
);
1985 case 0x6a: /* Exception generation / System */
1986 if (insn
& (1 << 24)) {
1987 disas_system(s
, insn
);
1992 case 0x6b: /* Unconditional branch (register) */
1993 disas_uncond_b_reg(s
, insn
);
1996 unallocated_encoding(s
);
2002 * Load/Store exclusive instructions are implemented by remembering
2003 * the value/address loaded, and seeing if these are the same
2004 * when the store is performed. This is not actually the architecturally
2005 * mandated semantics, but it works for typical guest code sequences
2006 * and avoids having to monitor regular stores.
2008 * The store exclusive uses the atomic cmpxchg primitives to avoid
2009 * races in multi-threaded linux-user and when MTTCG softmmu is
2012 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
2013 TCGv_i64 addr
, int size
, bool is_pair
)
2015 int idx
= get_mem_index(s
);
2016 TCGMemOp memop
= s
->be_data
;
2018 g_assert(size
<= 3);
2020 g_assert(size
>= 2);
2022 /* The pair must be single-copy atomic for the doubleword. */
2023 memop
|= MO_64
| MO_ALIGN
;
2024 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2025 if (s
->be_data
== MO_LE
) {
2026 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 0, 32);
2027 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 32, 32);
2029 tcg_gen_extract_i64(cpu_reg(s
, rt
), cpu_exclusive_val
, 32, 32);
2030 tcg_gen_extract_i64(cpu_reg(s
, rt2
), cpu_exclusive_val
, 0, 32);
2033 /* The pair must be single-copy atomic for *each* doubleword, not
2034 the entire quadword, however it must be quadword aligned. */
2036 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
,
2037 memop
| MO_ALIGN_16
);
2039 TCGv_i64 addr2
= tcg_temp_new_i64();
2040 tcg_gen_addi_i64(addr2
, addr
, 8);
2041 tcg_gen_qemu_ld_i64(cpu_exclusive_high
, addr2
, idx
, memop
);
2042 tcg_temp_free_i64(addr2
);
2044 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2045 tcg_gen_mov_i64(cpu_reg(s
, rt2
), cpu_exclusive_high
);
2048 memop
|= size
| MO_ALIGN
;
2049 tcg_gen_qemu_ld_i64(cpu_exclusive_val
, addr
, idx
, memop
);
2050 tcg_gen_mov_i64(cpu_reg(s
, rt
), cpu_exclusive_val
);
2052 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
2055 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
2056 TCGv_i64 addr
, int size
, int is_pair
)
2058 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
2059 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
2062 * [addr + datasize] = {Rt2};
2068 * env->exclusive_addr = -1;
2070 TCGLabel
*fail_label
= gen_new_label();
2071 TCGLabel
*done_label
= gen_new_label();
2074 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
2076 tmp
= tcg_temp_new_i64();
2079 if (s
->be_data
== MO_LE
) {
2080 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2082 tcg_gen_concat32_i64(tmp
, cpu_reg(s
, rt2
), cpu_reg(s
, rt
));
2084 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
,
2085 cpu_exclusive_val
, tmp
,
2087 MO_64
| MO_ALIGN
| s
->be_data
);
2088 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2089 } else if (s
->be_data
== MO_LE
) {
2090 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2091 gen_helper_paired_cmpxchg64_le_parallel(tmp
, cpu_env
,
2096 gen_helper_paired_cmpxchg64_le(tmp
, cpu_env
, cpu_exclusive_addr
,
2097 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2100 if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2101 gen_helper_paired_cmpxchg64_be_parallel(tmp
, cpu_env
,
2106 gen_helper_paired_cmpxchg64_be(tmp
, cpu_env
, cpu_exclusive_addr
,
2107 cpu_reg(s
, rt
), cpu_reg(s
, rt2
));
2111 tcg_gen_atomic_cmpxchg_i64(tmp
, cpu_exclusive_addr
, cpu_exclusive_val
,
2112 cpu_reg(s
, rt
), get_mem_index(s
),
2113 size
| MO_ALIGN
| s
->be_data
);
2114 tcg_gen_setcond_i64(TCG_COND_NE
, tmp
, tmp
, cpu_exclusive_val
);
2116 tcg_gen_mov_i64(cpu_reg(s
, rd
), tmp
);
2117 tcg_temp_free_i64(tmp
);
2118 tcg_gen_br(done_label
);
2120 gen_set_label(fail_label
);
2121 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
2122 gen_set_label(done_label
);
2123 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
2126 static void gen_compare_and_swap(DisasContext
*s
, int rs
, int rt
,
2129 TCGv_i64 tcg_rs
= cpu_reg(s
, rs
);
2130 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2131 int memidx
= get_mem_index(s
);
2132 TCGv_i64 addr
= cpu_reg_sp(s
, rn
);
2135 gen_check_sp_alignment(s
);
2137 tcg_gen_atomic_cmpxchg_i64(tcg_rs
, addr
, tcg_rs
, tcg_rt
, memidx
,
2138 size
| MO_ALIGN
| s
->be_data
);
2141 static void gen_compare_and_swap_pair(DisasContext
*s
, int rs
, int rt
,
2144 TCGv_i64 s1
= cpu_reg(s
, rs
);
2145 TCGv_i64 s2
= cpu_reg(s
, rs
+ 1);
2146 TCGv_i64 t1
= cpu_reg(s
, rt
);
2147 TCGv_i64 t2
= cpu_reg(s
, rt
+ 1);
2148 TCGv_i64 addr
= cpu_reg_sp(s
, rn
);
2149 int memidx
= get_mem_index(s
);
2152 gen_check_sp_alignment(s
);
2156 TCGv_i64 cmp
= tcg_temp_new_i64();
2157 TCGv_i64 val
= tcg_temp_new_i64();
2159 if (s
->be_data
== MO_LE
) {
2160 tcg_gen_concat32_i64(val
, t1
, t2
);
2161 tcg_gen_concat32_i64(cmp
, s1
, s2
);
2163 tcg_gen_concat32_i64(val
, t2
, t1
);
2164 tcg_gen_concat32_i64(cmp
, s2
, s1
);
2167 tcg_gen_atomic_cmpxchg_i64(cmp
, addr
, cmp
, val
, memidx
,
2168 MO_64
| MO_ALIGN
| s
->be_data
);
2169 tcg_temp_free_i64(val
);
2171 if (s
->be_data
== MO_LE
) {
2172 tcg_gen_extr32_i64(s1
, s2
, cmp
);
2174 tcg_gen_extr32_i64(s2
, s1
, cmp
);
2176 tcg_temp_free_i64(cmp
);
2177 } else if (tb_cflags(s
->base
.tb
) & CF_PARALLEL
) {
2178 TCGv_i32 tcg_rs
= tcg_const_i32(rs
);
2180 if (s
->be_data
== MO_LE
) {
2181 gen_helper_casp_le_parallel(cpu_env
, tcg_rs
, addr
, t1
, t2
);
2183 gen_helper_casp_be_parallel(cpu_env
, tcg_rs
, addr
, t1
, t2
);
2185 tcg_temp_free_i32(tcg_rs
);
2187 TCGv_i64 d1
= tcg_temp_new_i64();
2188 TCGv_i64 d2
= tcg_temp_new_i64();
2189 TCGv_i64 a2
= tcg_temp_new_i64();
2190 TCGv_i64 c1
= tcg_temp_new_i64();
2191 TCGv_i64 c2
= tcg_temp_new_i64();
2192 TCGv_i64 zero
= tcg_const_i64(0);
2194 /* Load the two words, in memory order. */
2195 tcg_gen_qemu_ld_i64(d1
, addr
, memidx
,
2196 MO_64
| MO_ALIGN_16
| s
->be_data
);
2197 tcg_gen_addi_i64(a2
, addr
, 8);
2198 tcg_gen_qemu_ld_i64(d2
, addr
, memidx
, MO_64
| s
->be_data
);
2200 /* Compare the two words, also in memory order. */
2201 tcg_gen_setcond_i64(TCG_COND_EQ
, c1
, d1
, s1
);
2202 tcg_gen_setcond_i64(TCG_COND_EQ
, c2
, d2
, s2
);
2203 tcg_gen_and_i64(c2
, c2
, c1
);
2205 /* If compare equal, write back new data, else write back old data. */
2206 tcg_gen_movcond_i64(TCG_COND_NE
, c1
, c2
, zero
, t1
, d1
);
2207 tcg_gen_movcond_i64(TCG_COND_NE
, c2
, c2
, zero
, t2
, d2
);
2208 tcg_gen_qemu_st_i64(c1
, addr
, memidx
, MO_64
| s
->be_data
);
2209 tcg_gen_qemu_st_i64(c2
, a2
, memidx
, MO_64
| s
->be_data
);
2210 tcg_temp_free_i64(a2
);
2211 tcg_temp_free_i64(c1
);
2212 tcg_temp_free_i64(c2
);
2213 tcg_temp_free_i64(zero
);
2215 /* Write back the data from memory to Rs. */
2216 tcg_gen_mov_i64(s1
, d1
);
2217 tcg_gen_mov_i64(s2
, d2
);
2218 tcg_temp_free_i64(d1
);
2219 tcg_temp_free_i64(d2
);
2223 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
2224 * from the ARMv8 specs for LDR (Shared decode for all encodings).
2226 static bool disas_ldst_compute_iss_sf(int size
, bool is_signed
, int opc
)
2228 int opc0
= extract32(opc
, 0, 1);
2232 regsize
= opc0
? 32 : 64;
2234 regsize
= size
== 3 ? 64 : 32;
2236 return regsize
== 64;
2239 /* Load/store exclusive
2241 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
2242 * +-----+-------------+----+---+----+------+----+-------+------+------+
2243 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
2244 * +-----+-------------+----+---+----+------+----+-------+------+------+
2246 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
2247 * L: 0 -> store, 1 -> load
2248 * o2: 0 -> exclusive, 1 -> not
2249 * o1: 0 -> single register, 1 -> register pair
2250 * o0: 1 -> load-acquire/store-release, 0 -> not
2252 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
2254 int rt
= extract32(insn
, 0, 5);
2255 int rn
= extract32(insn
, 5, 5);
2256 int rt2
= extract32(insn
, 10, 5);
2257 int rs
= extract32(insn
, 16, 5);
2258 int is_lasr
= extract32(insn
, 15, 1);
2259 int o2_L_o1_o0
= extract32(insn
, 21, 3) * 2 | is_lasr
;
2260 int size
= extract32(insn
, 30, 2);
2263 switch (o2_L_o1_o0
) {
2264 case 0x0: /* STXR */
2265 case 0x1: /* STLXR */
2267 gen_check_sp_alignment(s
);
2270 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2272 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2273 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, false);
2276 case 0x4: /* LDXR */
2277 case 0x5: /* LDAXR */
2279 gen_check_sp_alignment(s
);
2281 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2283 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, false);
2285 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2289 case 0x9: /* STLR */
2290 /* Generate ISS for non-exclusive accesses including LASR. */
2292 gen_check_sp_alignment(s
);
2294 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2295 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2296 do_gpr_st(s
, cpu_reg(s
, rt
), tcg_addr
, size
, true, rt
,
2297 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2300 case 0xd: /* LDAR */
2301 /* Generate ISS for non-exclusive accesses including LASR. */
2303 gen_check_sp_alignment(s
);
2305 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2306 do_gpr_ld(s
, cpu_reg(s
, rt
), tcg_addr
, size
, false, false, true, rt
,
2307 disas_ldst_compute_iss_sf(size
, false, 0), is_lasr
);
2308 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2311 case 0x2: case 0x3: /* CASP / STXP */
2312 if (size
& 2) { /* STXP / STLXP */
2314 gen_check_sp_alignment(s
);
2317 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
2319 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2320 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, true);
2324 && ((rt
| rs
) & 1) == 0
2325 && arm_dc_feature(s
, ARM_FEATURE_V8_ATOMICS
)) {
2327 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2332 case 0x6: case 0x7: /* CASPA / LDXP */
2333 if (size
& 2) { /* LDXP / LDAXP */
2335 gen_check_sp_alignment(s
);
2337 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2339 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, true);
2341 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
2346 && ((rt
| rs
) & 1) == 0
2347 && arm_dc_feature(s
, ARM_FEATURE_V8_ATOMICS
)) {
2348 /* CASPA / CASPAL */
2349 gen_compare_and_swap_pair(s
, rs
, rt
, rn
, size
| 2);
2355 case 0xb: /* CASL */
2356 case 0xe: /* CASA */
2357 case 0xf: /* CASAL */
2358 if (rt2
== 31 && arm_dc_feature(s
, ARM_FEATURE_V8_ATOMICS
)) {
2359 gen_compare_and_swap(s
, rs
, rt
, rn
, size
);
2364 unallocated_encoding(s
);
2368 * Load register (literal)
2370 * 31 30 29 27 26 25 24 23 5 4 0
2371 * +-----+-------+---+-----+-------------------+-------+
2372 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
2373 * +-----+-------+---+-----+-------------------+-------+
2375 * V: 1 -> vector (simd/fp)
2376 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
2377 * 10-> 32 bit signed, 11 -> prefetch
2378 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
2380 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
2382 int rt
= extract32(insn
, 0, 5);
2383 int64_t imm
= sextract32(insn
, 5, 19) << 2;
2384 bool is_vector
= extract32(insn
, 26, 1);
2385 int opc
= extract32(insn
, 30, 2);
2386 bool is_signed
= false;
2388 TCGv_i64 tcg_rt
, tcg_addr
;
2392 unallocated_encoding(s
);
2396 if (!fp_access_check(s
)) {
2401 /* PRFM (literal) : prefetch */
2404 size
= 2 + extract32(opc
, 0, 1);
2405 is_signed
= extract32(opc
, 1, 1);
2408 tcg_rt
= cpu_reg(s
, rt
);
2410 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
2412 do_fp_ld(s
, rt
, tcg_addr
, size
);
2414 /* Only unsigned 32bit loads target 32bit registers. */
2415 bool iss_sf
= opc
!= 0;
2417 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false,
2418 true, rt
, iss_sf
, false);
2420 tcg_temp_free_i64(tcg_addr
);
2424 * LDNP (Load Pair - non-temporal hint)
2425 * LDP (Load Pair - non vector)
2426 * LDPSW (Load Pair Signed Word - non vector)
2427 * STNP (Store Pair - non-temporal hint)
2428 * STP (Store Pair - non vector)
2429 * LDNP (Load Pair of SIMD&FP - non-temporal hint)
2430 * LDP (Load Pair of SIMD&FP)
2431 * STNP (Store Pair of SIMD&FP - non-temporal hint)
2432 * STP (Store Pair of SIMD&FP)
2434 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2435 * +-----+-------+---+---+-------+---+-----------------------------+
2436 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2437 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2439 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2441 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2442 * V: 0 -> GPR, 1 -> Vector
2443 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2444 * 10 -> signed offset, 11 -> pre-index
2445 * L: 0 -> Store 1 -> Load
2447 * Rt, Rt2 = GPR or SIMD registers to be stored
2448 * Rn = general purpose register containing address
2449 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2451 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
2453 int rt
= extract32(insn
, 0, 5);
2454 int rn
= extract32(insn
, 5, 5);
2455 int rt2
= extract32(insn
, 10, 5);
2456 uint64_t offset
= sextract64(insn
, 15, 7);
2457 int index
= extract32(insn
, 23, 2);
2458 bool is_vector
= extract32(insn
, 26, 1);
2459 bool is_load
= extract32(insn
, 22, 1);
2460 int opc
= extract32(insn
, 30, 2);
2462 bool is_signed
= false;
2463 bool postindex
= false;
2466 TCGv_i64 tcg_addr
; /* calculated address */
2470 unallocated_encoding(s
);
2477 size
= 2 + extract32(opc
, 1, 1);
2478 is_signed
= extract32(opc
, 0, 1);
2479 if (!is_load
&& is_signed
) {
2480 unallocated_encoding(s
);
2486 case 1: /* post-index */
2491 /* signed offset with "non-temporal" hint. Since we don't emulate
2492 * caches we don't care about hints to the cache system about
2493 * data access patterns, and handle this identically to plain
2497 /* There is no non-temporal-hint version of LDPSW */
2498 unallocated_encoding(s
);
2503 case 2: /* signed offset, rn not updated */
2506 case 3: /* pre-index */
2512 if (is_vector
&& !fp_access_check(s
)) {
2519 gen_check_sp_alignment(s
);
2522 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2525 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2530 do_fp_ld(s
, rt
, tcg_addr
, size
);
2532 do_fp_st(s
, rt
, tcg_addr
, size
);
2534 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2536 do_fp_ld(s
, rt2
, tcg_addr
, size
);
2538 do_fp_st(s
, rt2
, tcg_addr
, size
);
2541 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2542 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2545 TCGv_i64 tmp
= tcg_temp_new_i64();
2547 /* Do not modify tcg_rt before recognizing any exception
2548 * from the second load.
2550 do_gpr_ld(s
, tmp
, tcg_addr
, size
, is_signed
, false,
2551 false, 0, false, false);
2552 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2553 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false,
2554 false, 0, false, false);
2556 tcg_gen_mov_i64(tcg_rt
, tmp
);
2557 tcg_temp_free_i64(tmp
);
2559 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2560 false, 0, false, false);
2561 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2562 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
,
2563 false, 0, false, false);
2569 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
2571 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2573 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
2578 * Load/store (immediate post-indexed)
2579 * Load/store (immediate pre-indexed)
2580 * Load/store (unscaled immediate)
2582 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2583 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2584 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2585 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2587 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2589 * V = 0 -> non-vector
2590 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2591 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2593 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
2599 int rn
= extract32(insn
, 5, 5);
2600 int imm9
= sextract32(insn
, 12, 9);
2601 int idx
= extract32(insn
, 10, 2);
2602 bool is_signed
= false;
2603 bool is_store
= false;
2604 bool is_extended
= false;
2605 bool is_unpriv
= (idx
== 2);
2606 bool iss_valid
= !is_vector
;
2613 size
|= (opc
& 2) << 1;
2614 if (size
> 4 || is_unpriv
) {
2615 unallocated_encoding(s
);
2618 is_store
= ((opc
& 1) == 0);
2619 if (!fp_access_check(s
)) {
2623 if (size
== 3 && opc
== 2) {
2624 /* PRFM - prefetch */
2626 unallocated_encoding(s
);
2631 if (opc
== 3 && size
> 1) {
2632 unallocated_encoding(s
);
2635 is_store
= (opc
== 0);
2636 is_signed
= extract32(opc
, 1, 1);
2637 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2655 g_assert_not_reached();
2659 gen_check_sp_alignment(s
);
2661 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2664 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2669 do_fp_st(s
, rt
, tcg_addr
, size
);
2671 do_fp_ld(s
, rt
, tcg_addr
, size
);
2674 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2675 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2676 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2679 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
,
2680 iss_valid
, rt
, iss_sf
, false);
2682 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
2683 is_signed
, is_extended
, memidx
,
2684 iss_valid
, rt
, iss_sf
, false);
2689 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2691 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2693 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2698 * Load/store (register offset)
2700 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2701 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2702 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2703 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2706 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2707 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2709 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2710 * opc<0>: 0 -> store, 1 -> load
2711 * V: 1 -> vector/simd
2712 * opt: extend encoding (see DecodeRegExtend)
2713 * S: if S=1 then scale (essentially index by sizeof(size))
2714 * Rt: register to transfer into/out of
2715 * Rn: address register or SP for base
2716 * Rm: offset register or ZR for offset
2718 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
2724 int rn
= extract32(insn
, 5, 5);
2725 int shift
= extract32(insn
, 12, 1);
2726 int rm
= extract32(insn
, 16, 5);
2727 int opt
= extract32(insn
, 13, 3);
2728 bool is_signed
= false;
2729 bool is_store
= false;
2730 bool is_extended
= false;
2735 if (extract32(opt
, 1, 1) == 0) {
2736 unallocated_encoding(s
);
2741 size
|= (opc
& 2) << 1;
2743 unallocated_encoding(s
);
2746 is_store
= !extract32(opc
, 0, 1);
2747 if (!fp_access_check(s
)) {
2751 if (size
== 3 && opc
== 2) {
2752 /* PRFM - prefetch */
2755 if (opc
== 3 && size
> 1) {
2756 unallocated_encoding(s
);
2759 is_store
= (opc
== 0);
2760 is_signed
= extract32(opc
, 1, 1);
2761 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2765 gen_check_sp_alignment(s
);
2767 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2769 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2770 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2772 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2776 do_fp_st(s
, rt
, tcg_addr
, size
);
2778 do_fp_ld(s
, rt
, tcg_addr
, size
);
2781 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2782 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2784 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2785 true, rt
, iss_sf
, false);
2787 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
,
2788 is_signed
, is_extended
,
2789 true, rt
, iss_sf
, false);
2795 * Load/store (unsigned immediate)
2797 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2798 * +----+-------+---+-----+-----+------------+-------+------+
2799 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2800 * +----+-------+---+-----+-----+------------+-------+------+
2803 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2804 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2806 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2807 * opc<0>: 0 -> store, 1 -> load
2808 * Rn: base address register (inc SP)
2809 * Rt: target register
2811 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
2817 int rn
= extract32(insn
, 5, 5);
2818 unsigned int imm12
= extract32(insn
, 10, 12);
2819 unsigned int offset
;
2824 bool is_signed
= false;
2825 bool is_extended
= false;
2828 size
|= (opc
& 2) << 1;
2830 unallocated_encoding(s
);
2833 is_store
= !extract32(opc
, 0, 1);
2834 if (!fp_access_check(s
)) {
2838 if (size
== 3 && opc
== 2) {
2839 /* PRFM - prefetch */
2842 if (opc
== 3 && size
> 1) {
2843 unallocated_encoding(s
);
2846 is_store
= (opc
== 0);
2847 is_signed
= extract32(opc
, 1, 1);
2848 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2852 gen_check_sp_alignment(s
);
2854 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2855 offset
= imm12
<< size
;
2856 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2860 do_fp_st(s
, rt
, tcg_addr
, size
);
2862 do_fp_ld(s
, rt
, tcg_addr
, size
);
2865 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2866 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2868 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2869 true, rt
, iss_sf
, false);
2871 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
,
2872 true, rt
, iss_sf
, false);
2877 /* Atomic memory operations
2879 * 31 30 27 26 24 22 21 16 15 12 10 5 0
2880 * +------+-------+---+-----+-----+---+----+----+-----+-----+----+-----+
2881 * | size | 1 1 1 | V | 0 0 | A R | 1 | Rs | o3 | opc | 0 0 | Rn | Rt |
2882 * +------+-------+---+-----+-----+--------+----+-----+-----+----+-----+
2884 * Rt: the result register
2885 * Rn: base address or SP
2886 * Rs: the source register for the operation
2887 * V: vector flag (always 0 as of v8.3)
2891 static void disas_ldst_atomic(DisasContext
*s
, uint32_t insn
,
2892 int size
, int rt
, bool is_vector
)
2894 int rs
= extract32(insn
, 16, 5);
2895 int rn
= extract32(insn
, 5, 5);
2896 int o3_opc
= extract32(insn
, 12, 4);
2897 int feature
= ARM_FEATURE_V8_ATOMICS
;
2898 TCGv_i64 tcg_rn
, tcg_rs
;
2899 AtomicThreeOpFn
*fn
;
2902 unallocated_encoding(s
);
2906 case 000: /* LDADD */
2907 fn
= tcg_gen_atomic_fetch_add_i64
;
2909 case 001: /* LDCLR */
2910 fn
= tcg_gen_atomic_fetch_and_i64
;
2912 case 002: /* LDEOR */
2913 fn
= tcg_gen_atomic_fetch_xor_i64
;
2915 case 003: /* LDSET */
2916 fn
= tcg_gen_atomic_fetch_or_i64
;
2918 case 004: /* LDSMAX */
2919 fn
= tcg_gen_atomic_fetch_smax_i64
;
2921 case 005: /* LDSMIN */
2922 fn
= tcg_gen_atomic_fetch_smin_i64
;
2924 case 006: /* LDUMAX */
2925 fn
= tcg_gen_atomic_fetch_umax_i64
;
2927 case 007: /* LDUMIN */
2928 fn
= tcg_gen_atomic_fetch_umin_i64
;
2931 fn
= tcg_gen_atomic_xchg_i64
;
2934 unallocated_encoding(s
);
2937 if (!arm_dc_feature(s
, feature
)) {
2938 unallocated_encoding(s
);
2943 gen_check_sp_alignment(s
);
2945 tcg_rn
= cpu_reg_sp(s
, rn
);
2946 tcg_rs
= read_cpu_reg(s
, rs
, true);
2948 if (o3_opc
== 1) { /* LDCLR */
2949 tcg_gen_not_i64(tcg_rs
, tcg_rs
);
2952 /* The tcg atomic primitives are all full barriers. Therefore we
2953 * can ignore the Acquire and Release bits of this instruction.
2955 fn(cpu_reg(s
, rt
), tcg_rn
, tcg_rs
, get_mem_index(s
),
2956 s
->be_data
| size
| MO_ALIGN
);
2959 /* Load/store register (all forms) */
2960 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2962 int rt
= extract32(insn
, 0, 5);
2963 int opc
= extract32(insn
, 22, 2);
2964 bool is_vector
= extract32(insn
, 26, 1);
2965 int size
= extract32(insn
, 30, 2);
2967 switch (extract32(insn
, 24, 2)) {
2969 if (extract32(insn
, 21, 1) == 0) {
2970 /* Load/store register (unscaled immediate)
2971 * Load/store immediate pre/post-indexed
2972 * Load/store register unprivileged
2974 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
2977 switch (extract32(insn
, 10, 2)) {
2979 disas_ldst_atomic(s
, insn
, size
, rt
, is_vector
);
2982 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
2987 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
2990 unallocated_encoding(s
);
2993 /* AdvSIMD load/store multiple structures
2995 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2996 * +---+---+---------------+---+-------------+--------+------+------+------+
2997 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2998 * +---+---+---------------+---+-------------+--------+------+------+------+
3000 * AdvSIMD load/store multiple structures (post-indexed)
3002 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
3003 * +---+---+---------------+---+---+---------+--------+------+------+------+
3004 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
3005 * +---+---+---------------+---+---+---------+--------+------+------+------+
3007 * Rt: first (or only) SIMD&FP register to be transferred
3008 * Rn: base address or SP
3009 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3011 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
3013 int rt
= extract32(insn
, 0, 5);
3014 int rn
= extract32(insn
, 5, 5);
3015 int size
= extract32(insn
, 10, 2);
3016 int opcode
= extract32(insn
, 12, 4);
3017 bool is_store
= !extract32(insn
, 22, 1);
3018 bool is_postidx
= extract32(insn
, 23, 1);
3019 bool is_q
= extract32(insn
, 30, 1);
3020 TCGv_i64 tcg_addr
, tcg_rn
;
3022 int ebytes
= 1 << size
;
3023 int elements
= (is_q
? 128 : 64) / (8 << size
);
3024 int rpt
; /* num iterations */
3025 int selem
; /* structure elements */
3028 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
3029 unallocated_encoding(s
);
3033 /* From the shared decode logic */
3064 unallocated_encoding(s
);
3068 if (size
== 3 && !is_q
&& selem
!= 1) {
3070 unallocated_encoding(s
);
3074 if (!fp_access_check(s
)) {
3079 gen_check_sp_alignment(s
);
3082 tcg_rn
= cpu_reg_sp(s
, rn
);
3083 tcg_addr
= tcg_temp_new_i64();
3084 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
3086 for (r
= 0; r
< rpt
; r
++) {
3088 for (e
= 0; e
< elements
; e
++) {
3089 int tt
= (rt
+ r
) % 32;
3091 for (xs
= 0; xs
< selem
; xs
++) {
3093 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
3095 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
3097 /* For non-quad operations, setting a slice of the low
3098 * 64 bits of the register clears the high 64 bits (in
3099 * the ARM ARM pseudocode this is implicit in the fact
3100 * that 'rval' is a 64 bit wide variable).
3101 * For quad operations, we might still need to zero the
3102 * high bits of SVE. We optimize by noticing that we only
3103 * need to do this the first time we touch a register.
3105 if (e
== 0 && (r
== 0 || xs
== selem
- 1)) {
3106 clear_vec_high(s
, is_q
, tt
);
3109 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
3116 int rm
= extract32(insn
, 16, 5);
3118 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
3120 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3123 tcg_temp_free_i64(tcg_addr
);
3126 /* AdvSIMD load/store single structure
3128 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3129 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3130 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
3131 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3133 * AdvSIMD load/store single structure (post-indexed)
3135 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
3136 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3137 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
3138 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
3140 * Rt: first (or only) SIMD&FP register to be transferred
3141 * Rn: base address or SP
3142 * Rm (post-index only): post-index register (when !31) or size dependent #imm
3143 * index = encoded in Q:S:size dependent on size
3145 * lane_size = encoded in R, opc
3146 * transfer width = encoded in opc, S, size
3148 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
3150 int rt
= extract32(insn
, 0, 5);
3151 int rn
= extract32(insn
, 5, 5);
3152 int size
= extract32(insn
, 10, 2);
3153 int S
= extract32(insn
, 12, 1);
3154 int opc
= extract32(insn
, 13, 3);
3155 int R
= extract32(insn
, 21, 1);
3156 int is_load
= extract32(insn
, 22, 1);
3157 int is_postidx
= extract32(insn
, 23, 1);
3158 int is_q
= extract32(insn
, 30, 1);
3160 int scale
= extract32(opc
, 1, 2);
3161 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
3162 bool replicate
= false;
3163 int index
= is_q
<< 3 | S
<< 2 | size
;
3165 TCGv_i64 tcg_addr
, tcg_rn
;
3169 if (!is_load
|| S
) {
3170 unallocated_encoding(s
);
3179 if (extract32(size
, 0, 1)) {
3180 unallocated_encoding(s
);
3186 if (extract32(size
, 1, 1)) {
3187 unallocated_encoding(s
);
3190 if (!extract32(size
, 0, 1)) {
3194 unallocated_encoding(s
);
3202 g_assert_not_reached();
3205 if (!fp_access_check(s
)) {
3209 ebytes
= 1 << scale
;
3212 gen_check_sp_alignment(s
);
3215 tcg_rn
= cpu_reg_sp(s
, rn
);
3216 tcg_addr
= tcg_temp_new_i64();
3217 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
3219 for (xs
= 0; xs
< selem
; xs
++) {
3221 /* Load and replicate to all elements */
3223 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3225 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
3226 get_mem_index(s
), s
->be_data
+ scale
);
3229 mulconst
= 0x0101010101010101ULL
;
3232 mulconst
= 0x0001000100010001ULL
;
3235 mulconst
= 0x0000000100000001ULL
;
3241 g_assert_not_reached();
3244 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
3246 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
3248 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
3250 tcg_temp_free_i64(tcg_tmp
);
3251 clear_vec_high(s
, is_q
, rt
);
3253 /* Load/store one element per register */
3255 do_vec_ld(s
, rt
, index
, tcg_addr
, scale
);
3257 do_vec_st(s
, rt
, index
, tcg_addr
, scale
);
3260 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
3265 int rm
= extract32(insn
, 16, 5);
3267 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
3269 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
3272 tcg_temp_free_i64(tcg_addr
);
3275 /* Loads and stores */
3276 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
3278 switch (extract32(insn
, 24, 6)) {
3279 case 0x08: /* Load/store exclusive */
3280 disas_ldst_excl(s
, insn
);
3282 case 0x18: case 0x1c: /* Load register (literal) */
3283 disas_ld_lit(s
, insn
);
3285 case 0x28: case 0x29:
3286 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
3287 disas_ldst_pair(s
, insn
);
3289 case 0x38: case 0x39:
3290 case 0x3c: case 0x3d: /* Load/store register (all forms) */
3291 disas_ldst_reg(s
, insn
);
3293 case 0x0c: /* AdvSIMD load/store multiple structures */
3294 disas_ldst_multiple_struct(s
, insn
);
3296 case 0x0d: /* AdvSIMD load/store single structure */
3297 disas_ldst_single_struct(s
, insn
);
3300 unallocated_encoding(s
);
3305 /* PC-rel. addressing
3306 * 31 30 29 28 24 23 5 4 0
3307 * +----+-------+-----------+-------------------+------+
3308 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
3309 * +----+-------+-----------+-------------------+------+
3311 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
3313 unsigned int page
, rd
;
3317 page
= extract32(insn
, 31, 1);
3318 /* SignExtend(immhi:immlo) -> offset */
3319 offset
= sextract64(insn
, 5, 19);
3320 offset
= offset
<< 2 | extract32(insn
, 29, 2);
3321 rd
= extract32(insn
, 0, 5);
3325 /* ADRP (page based) */
3330 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
3334 * Add/subtract (immediate)
3336 * 31 30 29 28 24 23 22 21 10 9 5 4 0
3337 * +--+--+--+-----------+-----+-------------+-----+-----+
3338 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
3339 * +--+--+--+-----------+-----+-------------+-----+-----+
3341 * sf: 0 -> 32bit, 1 -> 64bit
3342 * op: 0 -> add , 1 -> sub
3344 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
3346 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
3348 int rd
= extract32(insn
, 0, 5);
3349 int rn
= extract32(insn
, 5, 5);
3350 uint64_t imm
= extract32(insn
, 10, 12);
3351 int shift
= extract32(insn
, 22, 2);
3352 bool setflags
= extract32(insn
, 29, 1);
3353 bool sub_op
= extract32(insn
, 30, 1);
3354 bool is_64bit
= extract32(insn
, 31, 1);
3356 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
3357 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
3358 TCGv_i64 tcg_result
;
3367 unallocated_encoding(s
);
3371 tcg_result
= tcg_temp_new_i64();
3374 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
3376 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
3379 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
3381 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3383 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
3385 tcg_temp_free_i64(tcg_imm
);
3389 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3391 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3394 tcg_temp_free_i64(tcg_result
);
3397 /* The input should be a value in the bottom e bits (with higher
3398 * bits zero); returns that value replicated into every element
3399 * of size e in a 64 bit integer.
3401 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
3411 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
3412 static inline uint64_t bitmask64(unsigned int length
)
3414 assert(length
> 0 && length
<= 64);
3415 return ~0ULL >> (64 - length
);
3418 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
3419 * only require the wmask. Returns false if the imms/immr/immn are a reserved
3420 * value (ie should cause a guest UNDEF exception), and true if they are
3421 * valid, in which case the decoded bit pattern is written to result.
3423 bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
3424 unsigned int imms
, unsigned int immr
)
3427 unsigned e
, levels
, s
, r
;
3430 assert(immn
< 2 && imms
< 64 && immr
< 64);
3432 /* The bit patterns we create here are 64 bit patterns which
3433 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
3434 * 64 bits each. Each element contains the same value: a run
3435 * of between 1 and e-1 non-zero bits, rotated within the
3436 * element by between 0 and e-1 bits.
3438 * The element size and run length are encoded into immn (1 bit)
3439 * and imms (6 bits) as follows:
3440 * 64 bit elements: immn = 1, imms = <length of run - 1>
3441 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
3442 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
3443 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
3444 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
3445 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
3446 * Notice that immn = 0, imms = 11111x is the only combination
3447 * not covered by one of the above options; this is reserved.
3448 * Further, <length of run - 1> all-ones is a reserved pattern.
3450 * In all cases the rotation is by immr % e (and immr is 6 bits).
3453 /* First determine the element size */
3454 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
3456 /* This is the immn == 0, imms == 0x11111x case */
3466 /* <length of run - 1> mustn't be all-ones. */
3470 /* Create the value of one element: s+1 set bits rotated
3471 * by r within the element (which is e bits wide)...
3473 mask
= bitmask64(s
+ 1);
3475 mask
= (mask
>> r
) | (mask
<< (e
- r
));
3476 mask
&= bitmask64(e
);
3478 /* ...then replicate the element over the whole 64 bit value */
3479 mask
= bitfield_replicate(mask
, e
);
3484 /* Logical (immediate)
3485 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3486 * +----+-----+-------------+---+------+------+------+------+
3487 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
3488 * +----+-----+-------------+---+------+------+------+------+
3490 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
3492 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
3493 TCGv_i64 tcg_rd
, tcg_rn
;
3495 bool is_and
= false;
3497 sf
= extract32(insn
, 31, 1);
3498 opc
= extract32(insn
, 29, 2);
3499 is_n
= extract32(insn
, 22, 1);
3500 immr
= extract32(insn
, 16, 6);
3501 imms
= extract32(insn
, 10, 6);
3502 rn
= extract32(insn
, 5, 5);
3503 rd
= extract32(insn
, 0, 5);
3506 unallocated_encoding(s
);
3510 if (opc
== 0x3) { /* ANDS */
3511 tcg_rd
= cpu_reg(s
, rd
);
3513 tcg_rd
= cpu_reg_sp(s
, rd
);
3515 tcg_rn
= cpu_reg(s
, rn
);
3517 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
3518 /* some immediate field values are reserved */
3519 unallocated_encoding(s
);
3524 wmask
&= 0xffffffff;
3528 case 0x3: /* ANDS */
3530 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
3534 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
3537 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
3540 assert(FALSE
); /* must handle all above */
3544 if (!sf
&& !is_and
) {
3545 /* zero extend final result; we know we can skip this for AND
3546 * since the immediate had the high 32 bits clear.
3548 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3551 if (opc
== 3) { /* ANDS */
3552 gen_logic_CC(sf
, tcg_rd
);
3557 * Move wide (immediate)
3559 * 31 30 29 28 23 22 21 20 5 4 0
3560 * +--+-----+-------------+-----+----------------+------+
3561 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
3562 * +--+-----+-------------+-----+----------------+------+
3564 * sf: 0 -> 32 bit, 1 -> 64 bit
3565 * opc: 00 -> N, 10 -> Z, 11 -> K
3566 * hw: shift/16 (0,16, and sf only 32, 48)
3568 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
3570 int rd
= extract32(insn
, 0, 5);
3571 uint64_t imm
= extract32(insn
, 5, 16);
3572 int sf
= extract32(insn
, 31, 1);
3573 int opc
= extract32(insn
, 29, 2);
3574 int pos
= extract32(insn
, 21, 2) << 4;
3575 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3578 if (!sf
&& (pos
>= 32)) {
3579 unallocated_encoding(s
);
3593 tcg_gen_movi_i64(tcg_rd
, imm
);
3596 tcg_imm
= tcg_const_i64(imm
);
3597 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
3598 tcg_temp_free_i64(tcg_imm
);
3600 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3604 unallocated_encoding(s
);
3610 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3611 * +----+-----+-------------+---+------+------+------+------+
3612 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3613 * +----+-----+-------------+---+------+------+------+------+
3615 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
3617 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
3618 TCGv_i64 tcg_rd
, tcg_tmp
;
3620 sf
= extract32(insn
, 31, 1);
3621 opc
= extract32(insn
, 29, 2);
3622 n
= extract32(insn
, 22, 1);
3623 ri
= extract32(insn
, 16, 6);
3624 si
= extract32(insn
, 10, 6);
3625 rn
= extract32(insn
, 5, 5);
3626 rd
= extract32(insn
, 0, 5);
3627 bitsize
= sf
? 64 : 32;
3629 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
3630 unallocated_encoding(s
);
3634 tcg_rd
= cpu_reg(s
, rd
);
3636 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3637 to be smaller than bitsize, we'll never reference data outside the
3638 low 32-bits anyway. */
3639 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
3641 /* Recognize simple(r) extractions. */
3643 /* Wd<s-r:0> = Wn<s:r> */
3644 len
= (si
- ri
) + 1;
3645 if (opc
== 0) { /* SBFM: ASR, SBFX, SXTB, SXTH, SXTW */
3646 tcg_gen_sextract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3648 } else if (opc
== 2) { /* UBFM: UBFX, LSR, UXTB, UXTH */
3649 tcg_gen_extract_i64(tcg_rd
, tcg_tmp
, ri
, len
);
3652 /* opc == 1, BXFIL fall through to deposit */
3653 tcg_gen_extract_i64(tcg_tmp
, tcg_tmp
, ri
, len
);
3656 /* Handle the ri > si case with a deposit
3657 * Wd<32+s-r,32-r> = Wn<s:0>
3660 pos
= (bitsize
- ri
) & (bitsize
- 1);
3663 if (opc
== 0 && len
< ri
) {
3664 /* SBFM: sign extend the destination field from len to fill
3665 the balance of the word. Let the deposit below insert all
3666 of those sign bits. */
3667 tcg_gen_sextract_i64(tcg_tmp
, tcg_tmp
, 0, len
);
3671 if (opc
== 1) { /* BFM, BXFIL */
3672 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
3674 /* SBFM or UBFM: We start with zero, and we haven't modified
3675 any bits outside bitsize, therefore the zero-extension
3676 below is unneeded. */
3677 tcg_gen_deposit_z_i64(tcg_rd
, tcg_tmp
, pos
, len
);
3682 if (!sf
) { /* zero extend final result */
3683 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3688 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3689 * +----+------+-------------+---+----+------+--------+------+------+
3690 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3691 * +----+------+-------------+---+----+------+--------+------+------+
3693 static void disas_extract(DisasContext
*s
, uint32_t insn
)
3695 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
3697 sf
= extract32(insn
, 31, 1);
3698 n
= extract32(insn
, 22, 1);
3699 rm
= extract32(insn
, 16, 5);
3700 imm
= extract32(insn
, 10, 6);
3701 rn
= extract32(insn
, 5, 5);
3702 rd
= extract32(insn
, 0, 5);
3703 op21
= extract32(insn
, 29, 2);
3704 op0
= extract32(insn
, 21, 1);
3705 bitsize
= sf
? 64 : 32;
3707 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
3708 unallocated_encoding(s
);
3710 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
3712 tcg_rd
= cpu_reg(s
, rd
);
3714 if (unlikely(imm
== 0)) {
3715 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3716 * so an extract from bit 0 is a special case.
3719 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
3721 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
3723 } else if (rm
== rn
) { /* ROR */
3724 tcg_rm
= cpu_reg(s
, rm
);
3726 tcg_gen_rotri_i64(tcg_rd
, tcg_rm
, imm
);
3728 TCGv_i32 tmp
= tcg_temp_new_i32();
3729 tcg_gen_extrl_i64_i32(tmp
, tcg_rm
);
3730 tcg_gen_rotri_i32(tmp
, tmp
, imm
);
3731 tcg_gen_extu_i32_i64(tcg_rd
, tmp
);
3732 tcg_temp_free_i32(tmp
);
3735 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3736 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3737 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
3738 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
3739 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
3741 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3747 /* Data processing - immediate */
3748 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
3750 switch (extract32(insn
, 23, 6)) {
3751 case 0x20: case 0x21: /* PC-rel. addressing */
3752 disas_pc_rel_adr(s
, insn
);
3754 case 0x22: case 0x23: /* Add/subtract (immediate) */
3755 disas_add_sub_imm(s
, insn
);
3757 case 0x24: /* Logical (immediate) */
3758 disas_logic_imm(s
, insn
);
3760 case 0x25: /* Move wide (immediate) */
3761 disas_movw_imm(s
, insn
);
3763 case 0x26: /* Bitfield */
3764 disas_bitfield(s
, insn
);
3766 case 0x27: /* Extract */
3767 disas_extract(s
, insn
);
3770 unallocated_encoding(s
);
3775 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3776 * Note that it is the caller's responsibility to ensure that the
3777 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3778 * mandated semantics for out of range shifts.
3780 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3781 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
3783 switch (shift_type
) {
3784 case A64_SHIFT_TYPE_LSL
:
3785 tcg_gen_shl_i64(dst
, src
, shift_amount
);
3787 case A64_SHIFT_TYPE_LSR
:
3788 tcg_gen_shr_i64(dst
, src
, shift_amount
);
3790 case A64_SHIFT_TYPE_ASR
:
3792 tcg_gen_ext32s_i64(dst
, src
);
3794 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
3796 case A64_SHIFT_TYPE_ROR
:
3798 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
3801 t0
= tcg_temp_new_i32();
3802 t1
= tcg_temp_new_i32();
3803 tcg_gen_extrl_i64_i32(t0
, src
);
3804 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
3805 tcg_gen_rotr_i32(t0
, t0
, t1
);
3806 tcg_gen_extu_i32_i64(dst
, t0
);
3807 tcg_temp_free_i32(t0
);
3808 tcg_temp_free_i32(t1
);
3812 assert(FALSE
); /* all shift types should be handled */
3816 if (!sf
) { /* zero extend final result */
3817 tcg_gen_ext32u_i64(dst
, dst
);
3821 /* Shift a TCGv src by immediate, put result in dst.
3822 * The shift amount must be in range (this should always be true as the
3823 * relevant instructions will UNDEF on bad shift immediates).
3825 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3826 enum a64_shift_type shift_type
, unsigned int shift_i
)
3828 assert(shift_i
< (sf
? 64 : 32));
3831 tcg_gen_mov_i64(dst
, src
);
3833 TCGv_i64 shift_const
;
3835 shift_const
= tcg_const_i64(shift_i
);
3836 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
3837 tcg_temp_free_i64(shift_const
);
3841 /* Logical (shifted register)
3842 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3843 * +----+-----+-----------+-------+---+------+--------+------+------+
3844 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3845 * +----+-----+-----------+-------+---+------+--------+------+------+
3847 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
3849 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
3850 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
3852 sf
= extract32(insn
, 31, 1);
3853 opc
= extract32(insn
, 29, 2);
3854 shift_type
= extract32(insn
, 22, 2);
3855 invert
= extract32(insn
, 21, 1);
3856 rm
= extract32(insn
, 16, 5);
3857 shift_amount
= extract32(insn
, 10, 6);
3858 rn
= extract32(insn
, 5, 5);
3859 rd
= extract32(insn
, 0, 5);
3861 if (!sf
&& (shift_amount
& (1 << 5))) {
3862 unallocated_encoding(s
);
3866 tcg_rd
= cpu_reg(s
, rd
);
3868 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3869 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3870 * register-register MOV and MVN, so it is worth special casing.
3872 tcg_rm
= cpu_reg(s
, rm
);
3874 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3876 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3880 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3882 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3888 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3891 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3894 tcg_rn
= cpu_reg(s
, rn
);
3896 switch (opc
| (invert
<< 2)) {
3899 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3902 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3905 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3909 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3912 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3915 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3923 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3927 gen_logic_CC(sf
, tcg_rd
);
3932 * Add/subtract (extended register)
3934 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3935 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3936 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3937 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3939 * sf: 0 -> 32bit, 1 -> 64bit
3940 * op: 0 -> add , 1 -> sub
3943 * option: extension type (see DecodeRegExtend)
3944 * imm3: optional shift to Rm
3946 * Rd = Rn + LSL(extend(Rm), amount)
3948 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3950 int rd
= extract32(insn
, 0, 5);
3951 int rn
= extract32(insn
, 5, 5);
3952 int imm3
= extract32(insn
, 10, 3);
3953 int option
= extract32(insn
, 13, 3);
3954 int rm
= extract32(insn
, 16, 5);
3955 bool setflags
= extract32(insn
, 29, 1);
3956 bool sub_op
= extract32(insn
, 30, 1);
3957 bool sf
= extract32(insn
, 31, 1);
3959 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3961 TCGv_i64 tcg_result
;
3964 unallocated_encoding(s
);
3968 /* non-flag setting ops may use SP */
3970 tcg_rd
= cpu_reg_sp(s
, rd
);
3972 tcg_rd
= cpu_reg(s
, rd
);
3974 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3976 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3977 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3979 tcg_result
= tcg_temp_new_i64();
3983 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3985 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3989 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3991 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3996 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3998 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4001 tcg_temp_free_i64(tcg_result
);
4005 * Add/subtract (shifted register)
4007 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
4008 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4009 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
4010 * +--+--+--+-----------+-----+--+-------+---------+------+------+
4012 * sf: 0 -> 32bit, 1 -> 64bit
4013 * op: 0 -> add , 1 -> sub
4015 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
4016 * imm6: Shift amount to apply to Rm before the add/sub
4018 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
4020 int rd
= extract32(insn
, 0, 5);
4021 int rn
= extract32(insn
, 5, 5);
4022 int imm6
= extract32(insn
, 10, 6);
4023 int rm
= extract32(insn
, 16, 5);
4024 int shift_type
= extract32(insn
, 22, 2);
4025 bool setflags
= extract32(insn
, 29, 1);
4026 bool sub_op
= extract32(insn
, 30, 1);
4027 bool sf
= extract32(insn
, 31, 1);
4029 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4030 TCGv_i64 tcg_rn
, tcg_rm
;
4031 TCGv_i64 tcg_result
;
4033 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
4034 unallocated_encoding(s
);
4038 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4039 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
4041 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
4043 tcg_result
= tcg_temp_new_i64();
4047 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
4049 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
4053 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4055 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
4060 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
4062 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
4065 tcg_temp_free_i64(tcg_result
);
4068 /* Data-processing (3 source)
4070 * 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
4071 * +--+------+-----------+------+------+----+------+------+------+
4072 * |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
4073 * +--+------+-----------+------+------+----+------+------+------+
4075 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
4077 int rd
= extract32(insn
, 0, 5);
4078 int rn
= extract32(insn
, 5, 5);
4079 int ra
= extract32(insn
, 10, 5);
4080 int rm
= extract32(insn
, 16, 5);
4081 int op_id
= (extract32(insn
, 29, 3) << 4) |
4082 (extract32(insn
, 21, 3) << 1) |
4083 extract32(insn
, 15, 1);
4084 bool sf
= extract32(insn
, 31, 1);
4085 bool is_sub
= extract32(op_id
, 0, 1);
4086 bool is_high
= extract32(op_id
, 2, 1);
4087 bool is_signed
= false;
4092 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
4094 case 0x42: /* SMADDL */
4095 case 0x43: /* SMSUBL */
4096 case 0x44: /* SMULH */
4099 case 0x0: /* MADD (32bit) */
4100 case 0x1: /* MSUB (32bit) */
4101 case 0x40: /* MADD (64bit) */
4102 case 0x41: /* MSUB (64bit) */
4103 case 0x4a: /* UMADDL */
4104 case 0x4b: /* UMSUBL */
4105 case 0x4c: /* UMULH */
4108 unallocated_encoding(s
);
4113 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
4114 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4115 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4116 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
4119 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4121 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
4124 tcg_temp_free_i64(low_bits
);
4128 tcg_op1
= tcg_temp_new_i64();
4129 tcg_op2
= tcg_temp_new_i64();
4130 tcg_tmp
= tcg_temp_new_i64();
4133 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
4134 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
4137 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
4138 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
4140 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
4141 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
4145 if (ra
== 31 && !is_sub
) {
4146 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
4147 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
4149 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
4151 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4153 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
4158 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
4161 tcg_temp_free_i64(tcg_op1
);
4162 tcg_temp_free_i64(tcg_op2
);
4163 tcg_temp_free_i64(tcg_tmp
);
4166 /* Add/subtract (with carry)
4167 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
4168 * +--+--+--+------------------------+------+---------+------+-----+
4169 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
4170 * +--+--+--+------------------------+------+---------+------+-----+
4174 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
4176 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
4177 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
4179 if (extract32(insn
, 10, 6) != 0) {
4180 unallocated_encoding(s
);
4184 sf
= extract32(insn
, 31, 1);
4185 op
= extract32(insn
, 30, 1);
4186 setflags
= extract32(insn
, 29, 1);
4187 rm
= extract32(insn
, 16, 5);
4188 rn
= extract32(insn
, 5, 5);
4189 rd
= extract32(insn
, 0, 5);
4191 tcg_rd
= cpu_reg(s
, rd
);
4192 tcg_rn
= cpu_reg(s
, rn
);
4195 tcg_y
= new_tmp_a64(s
);
4196 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
4198 tcg_y
= cpu_reg(s
, rm
);
4202 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4204 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
4208 /* Conditional compare (immediate / register)
4209 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4210 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4211 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
4212 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
4215 static void disas_cc(DisasContext
*s
, uint32_t insn
)
4217 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
4218 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
4219 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
4222 if (!extract32(insn
, 29, 1)) {
4223 unallocated_encoding(s
);
4226 if (insn
& (1 << 10 | 1 << 4)) {
4227 unallocated_encoding(s
);
4230 sf
= extract32(insn
, 31, 1);
4231 op
= extract32(insn
, 30, 1);
4232 is_imm
= extract32(insn
, 11, 1);
4233 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
4234 cond
= extract32(insn
, 12, 4);
4235 rn
= extract32(insn
, 5, 5);
4236 nzcv
= extract32(insn
, 0, 4);
4238 /* Set T0 = !COND. */
4239 tcg_t0
= tcg_temp_new_i32();
4240 arm_test_cc(&c
, cond
);
4241 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
4244 /* Load the arguments for the new comparison. */
4246 tcg_y
= new_tmp_a64(s
);
4247 tcg_gen_movi_i64(tcg_y
, y
);
4249 tcg_y
= cpu_reg(s
, y
);
4251 tcg_rn
= cpu_reg(s
, rn
);
4253 /* Set the flags for the new comparison. */
4254 tcg_tmp
= tcg_temp_new_i64();
4256 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4258 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
4260 tcg_temp_free_i64(tcg_tmp
);
4262 /* If COND was false, force the flags to #nzcv. Compute two masks
4263 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
4264 * For tcg hosts that support ANDC, we can make do with just T1.
4265 * In either case, allow the tcg optimizer to delete any unused mask.
4267 tcg_t1
= tcg_temp_new_i32();
4268 tcg_t2
= tcg_temp_new_i32();
4269 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
4270 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
4272 if (nzcv
& 8) { /* N */
4273 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4275 if (TCG_TARGET_HAS_andc_i32
) {
4276 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
4278 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
4281 if (nzcv
& 4) { /* Z */
4282 if (TCG_TARGET_HAS_andc_i32
) {
4283 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
4285 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
4288 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
4290 if (nzcv
& 2) { /* C */
4291 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
4293 if (TCG_TARGET_HAS_andc_i32
) {
4294 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
4296 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
4299 if (nzcv
& 1) { /* V */
4300 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4302 if (TCG_TARGET_HAS_andc_i32
) {
4303 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
4305 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
4308 tcg_temp_free_i32(tcg_t0
);
4309 tcg_temp_free_i32(tcg_t1
);
4310 tcg_temp_free_i32(tcg_t2
);
4313 /* Conditional select
4314 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
4315 * +----+----+---+-----------------+------+------+-----+------+------+
4316 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
4317 * +----+----+---+-----------------+------+------+-----+------+------+
4319 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
4321 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
4322 TCGv_i64 tcg_rd
, zero
;
4325 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
4326 /* S == 1 or op2<1> == 1 */
4327 unallocated_encoding(s
);
4330 sf
= extract32(insn
, 31, 1);
4331 else_inv
= extract32(insn
, 30, 1);
4332 rm
= extract32(insn
, 16, 5);
4333 cond
= extract32(insn
, 12, 4);
4334 else_inc
= extract32(insn
, 10, 1);
4335 rn
= extract32(insn
, 5, 5);
4336 rd
= extract32(insn
, 0, 5);
4338 tcg_rd
= cpu_reg(s
, rd
);
4340 a64_test_cc(&c
, cond
);
4341 zero
= tcg_const_i64(0);
4343 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
4345 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
4347 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
4350 TCGv_i64 t_true
= cpu_reg(s
, rn
);
4351 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
4352 if (else_inv
&& else_inc
) {
4353 tcg_gen_neg_i64(t_false
, t_false
);
4354 } else if (else_inv
) {
4355 tcg_gen_not_i64(t_false
, t_false
);
4356 } else if (else_inc
) {
4357 tcg_gen_addi_i64(t_false
, t_false
, 1);
4359 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
4362 tcg_temp_free_i64(zero
);
4366 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4370 static void handle_clz(DisasContext
*s
, unsigned int sf
,
4371 unsigned int rn
, unsigned int rd
)
4373 TCGv_i64 tcg_rd
, tcg_rn
;
4374 tcg_rd
= cpu_reg(s
, rd
);
4375 tcg_rn
= cpu_reg(s
, rn
);
4378 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
4380 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4381 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4382 tcg_gen_clzi_i32(tcg_tmp32
, tcg_tmp32
, 32);
4383 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4384 tcg_temp_free_i32(tcg_tmp32
);
4388 static void handle_cls(DisasContext
*s
, unsigned int sf
,
4389 unsigned int rn
, unsigned int rd
)
4391 TCGv_i64 tcg_rd
, tcg_rn
;
4392 tcg_rd
= cpu_reg(s
, rd
);
4393 tcg_rn
= cpu_reg(s
, rn
);
4396 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
4398 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4399 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4400 tcg_gen_clrsb_i32(tcg_tmp32
, tcg_tmp32
);
4401 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4402 tcg_temp_free_i32(tcg_tmp32
);
4406 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
4407 unsigned int rn
, unsigned int rd
)
4409 TCGv_i64 tcg_rd
, tcg_rn
;
4410 tcg_rd
= cpu_reg(s
, rd
);
4411 tcg_rn
= cpu_reg(s
, rn
);
4414 gen_helper_rbit64(tcg_rd
, tcg_rn
);
4416 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
4417 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
4418 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
4419 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
4420 tcg_temp_free_i32(tcg_tmp32
);
4424 /* REV with sf==1, opcode==3 ("REV64") */
4425 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
4426 unsigned int rn
, unsigned int rd
)
4429 unallocated_encoding(s
);
4432 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
4435 /* REV with sf==0, opcode==2
4436 * REV32 (sf==1, opcode==2)
4438 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
4439 unsigned int rn
, unsigned int rd
)
4441 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4444 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4445 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4447 /* bswap32_i64 requires zero high word */
4448 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
4449 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
4450 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
4451 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
4452 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4454 tcg_temp_free_i64(tcg_tmp
);
4456 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
4457 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
4461 /* REV16 (opcode==1) */
4462 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
4463 unsigned int rn
, unsigned int rd
)
4465 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4466 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4467 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4468 TCGv_i64 mask
= tcg_const_i64(sf
? 0x00ff00ff00ff00ffull
: 0x00ff00ff);
4470 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 8);
4471 tcg_gen_and_i64(tcg_rd
, tcg_rn
, mask
);
4472 tcg_gen_and_i64(tcg_tmp
, tcg_tmp
, mask
);
4473 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 8);
4474 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
4476 tcg_temp_free_i64(mask
);
4477 tcg_temp_free_i64(tcg_tmp
);
4480 /* Data-processing (1 source)
4481 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4482 * +----+---+---+-----------------+---------+--------+------+------+
4483 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
4484 * +----+---+---+-----------------+---------+--------+------+------+
4486 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
4488 unsigned int sf
, opcode
, rn
, rd
;
4490 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
4491 unallocated_encoding(s
);
4495 sf
= extract32(insn
, 31, 1);
4496 opcode
= extract32(insn
, 10, 6);
4497 rn
= extract32(insn
, 5, 5);
4498 rd
= extract32(insn
, 0, 5);
4502 handle_rbit(s
, sf
, rn
, rd
);
4505 handle_rev16(s
, sf
, rn
, rd
);
4508 handle_rev32(s
, sf
, rn
, rd
);
4511 handle_rev64(s
, sf
, rn
, rd
);
4514 handle_clz(s
, sf
, rn
, rd
);
4517 handle_cls(s
, sf
, rn
, rd
);
4522 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
4523 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4525 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
4526 tcg_rd
= cpu_reg(s
, rd
);
4528 if (!sf
&& is_signed
) {
4529 tcg_n
= new_tmp_a64(s
);
4530 tcg_m
= new_tmp_a64(s
);
4531 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
4532 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
4534 tcg_n
= read_cpu_reg(s
, rn
, sf
);
4535 tcg_m
= read_cpu_reg(s
, rm
, sf
);
4539 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
4541 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
4544 if (!sf
) { /* zero extend final result */
4545 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4549 /* LSLV, LSRV, ASRV, RORV */
4550 static void handle_shift_reg(DisasContext
*s
,
4551 enum a64_shift_type shift_type
, unsigned int sf
,
4552 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4554 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
4555 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4556 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4558 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
4559 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
4560 tcg_temp_free_i64(tcg_shift
);
4563 /* CRC32[BHWX], CRC32C[BHWX] */
4564 static void handle_crc32(DisasContext
*s
,
4565 unsigned int sf
, unsigned int sz
, bool crc32c
,
4566 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4568 TCGv_i64 tcg_acc
, tcg_val
;
4571 if (!arm_dc_feature(s
, ARM_FEATURE_CRC
)
4572 || (sf
== 1 && sz
!= 3)
4573 || (sf
== 0 && sz
== 3)) {
4574 unallocated_encoding(s
);
4579 tcg_val
= cpu_reg(s
, rm
);
4593 g_assert_not_reached();
4595 tcg_val
= new_tmp_a64(s
);
4596 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
4599 tcg_acc
= cpu_reg(s
, rn
);
4600 tcg_bytes
= tcg_const_i32(1 << sz
);
4603 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4605 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4608 tcg_temp_free_i32(tcg_bytes
);
4611 /* Data-processing (2 source)
4612 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4613 * +----+---+---+-----------------+------+--------+------+------+
4614 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
4615 * +----+---+---+-----------------+------+--------+------+------+
4617 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
4619 unsigned int sf
, rm
, opcode
, rn
, rd
;
4620 sf
= extract32(insn
, 31, 1);
4621 rm
= extract32(insn
, 16, 5);
4622 opcode
= extract32(insn
, 10, 6);
4623 rn
= extract32(insn
, 5, 5);
4624 rd
= extract32(insn
, 0, 5);
4626 if (extract32(insn
, 29, 1)) {
4627 unallocated_encoding(s
);
4633 handle_div(s
, false, sf
, rm
, rn
, rd
);
4636 handle_div(s
, true, sf
, rm
, rn
, rd
);
4639 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
4642 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
4645 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
4648 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
4657 case 23: /* CRC32 */
4659 int sz
= extract32(opcode
, 0, 2);
4660 bool crc32c
= extract32(opcode
, 2, 1);
4661 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
4665 unallocated_encoding(s
);
4670 /* Data processing - register */
4671 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
4673 switch (extract32(insn
, 24, 5)) {
4674 case 0x0a: /* Logical (shifted register) */
4675 disas_logic_reg(s
, insn
);
4677 case 0x0b: /* Add/subtract */
4678 if (insn
& (1 << 21)) { /* (extended register) */
4679 disas_add_sub_ext_reg(s
, insn
);
4681 disas_add_sub_reg(s
, insn
);
4684 case 0x1b: /* Data-processing (3 source) */
4685 disas_data_proc_3src(s
, insn
);
4688 switch (extract32(insn
, 21, 3)) {
4689 case 0x0: /* Add/subtract (with carry) */
4690 disas_adc_sbc(s
, insn
);
4692 case 0x2: /* Conditional compare */
4693 disas_cc(s
, insn
); /* both imm and reg forms */
4695 case 0x4: /* Conditional select */
4696 disas_cond_select(s
, insn
);
4698 case 0x6: /* Data-processing */
4699 if (insn
& (1 << 30)) { /* (1 source) */
4700 disas_data_proc_1src(s
, insn
);
4701 } else { /* (2 source) */
4702 disas_data_proc_2src(s
, insn
);
4706 unallocated_encoding(s
);
4711 unallocated_encoding(s
);
4716 static void handle_fp_compare(DisasContext
*s
, int size
,
4717 unsigned int rn
, unsigned int rm
,
4718 bool cmp_with_zero
, bool signal_all_nans
)
4720 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
4721 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
4723 if (size
== MO_64
) {
4724 TCGv_i64 tcg_vn
, tcg_vm
;
4726 tcg_vn
= read_fp_dreg(s
, rn
);
4727 if (cmp_with_zero
) {
4728 tcg_vm
= tcg_const_i64(0);
4730 tcg_vm
= read_fp_dreg(s
, rm
);
4732 if (signal_all_nans
) {
4733 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4735 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4737 tcg_temp_free_i64(tcg_vn
);
4738 tcg_temp_free_i64(tcg_vm
);
4740 TCGv_i32 tcg_vn
= tcg_temp_new_i32();
4741 TCGv_i32 tcg_vm
= tcg_temp_new_i32();
4743 read_vec_element_i32(s
, tcg_vn
, rn
, 0, size
);
4744 if (cmp_with_zero
) {
4745 tcg_gen_movi_i32(tcg_vm
, 0);
4747 read_vec_element_i32(s
, tcg_vm
, rm
, 0, size
);
4752 if (signal_all_nans
) {
4753 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4755 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4759 if (signal_all_nans
) {
4760 gen_helper_vfp_cmpeh_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4762 gen_helper_vfp_cmph_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4766 g_assert_not_reached();
4769 tcg_temp_free_i32(tcg_vn
);
4770 tcg_temp_free_i32(tcg_vm
);
4773 tcg_temp_free_ptr(fpst
);
4775 gen_set_nzcv(tcg_flags
);
4777 tcg_temp_free_i64(tcg_flags
);
4780 /* Floating point compare
4781 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
4782 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4783 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
4784 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4786 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
4788 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
4791 mos
= extract32(insn
, 29, 3);
4792 type
= extract32(insn
, 22, 2);
4793 rm
= extract32(insn
, 16, 5);
4794 op
= extract32(insn
, 14, 2);
4795 rn
= extract32(insn
, 5, 5);
4796 opc
= extract32(insn
, 3, 2);
4797 op2r
= extract32(insn
, 0, 3);
4799 if (mos
|| op
|| op2r
) {
4800 unallocated_encoding(s
);
4813 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
4818 unallocated_encoding(s
);
4822 if (!fp_access_check(s
)) {
4826 handle_fp_compare(s
, size
, rn
, rm
, opc
& 1, opc
& 2);
4829 /* Floating point conditional compare
4830 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4831 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4832 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
4833 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4835 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
4837 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
4839 TCGLabel
*label_continue
= NULL
;
4842 mos
= extract32(insn
, 29, 3);
4843 type
= extract32(insn
, 22, 2);
4844 rm
= extract32(insn
, 16, 5);
4845 cond
= extract32(insn
, 12, 4);
4846 rn
= extract32(insn
, 5, 5);
4847 op
= extract32(insn
, 4, 1);
4848 nzcv
= extract32(insn
, 0, 4);
4851 unallocated_encoding(s
);
4864 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
4869 unallocated_encoding(s
);
4873 if (!fp_access_check(s
)) {
4877 if (cond
< 0x0e) { /* not always */
4878 TCGLabel
*label_match
= gen_new_label();
4879 label_continue
= gen_new_label();
4880 arm_gen_test_cc(cond
, label_match
);
4882 tcg_flags
= tcg_const_i64(nzcv
<< 28);
4883 gen_set_nzcv(tcg_flags
);
4884 tcg_temp_free_i64(tcg_flags
);
4885 tcg_gen_br(label_continue
);
4886 gen_set_label(label_match
);
4889 handle_fp_compare(s
, size
, rn
, rm
, false, op
);
4892 gen_set_label(label_continue
);
4896 /* Floating point conditional select
4897 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4898 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4899 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
4900 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4902 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
4904 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
4905 TCGv_i64 t_true
, t_false
, t_zero
;
4909 mos
= extract32(insn
, 29, 3);
4910 type
= extract32(insn
, 22, 2);
4911 rm
= extract32(insn
, 16, 5);
4912 cond
= extract32(insn
, 12, 4);
4913 rn
= extract32(insn
, 5, 5);
4914 rd
= extract32(insn
, 0, 5);
4917 unallocated_encoding(s
);
4930 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
4935 unallocated_encoding(s
);
4939 if (!fp_access_check(s
)) {
4943 /* Zero extend sreg & hreg inputs to 64 bits now. */
4944 t_true
= tcg_temp_new_i64();
4945 t_false
= tcg_temp_new_i64();
4946 read_vec_element(s
, t_true
, rn
, 0, sz
);
4947 read_vec_element(s
, t_false
, rm
, 0, sz
);
4949 a64_test_cc(&c
, cond
);
4950 t_zero
= tcg_const_i64(0);
4951 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, t_zero
, t_true
, t_false
);
4952 tcg_temp_free_i64(t_zero
);
4953 tcg_temp_free_i64(t_false
);
4956 /* Note that sregs & hregs write back zeros to the high bits,
4957 and we've already done the zero-extension. */
4958 write_fp_dreg(s
, rd
, t_true
);
4959 tcg_temp_free_i64(t_true
);
4962 /* Floating-point data-processing (1 source) - half precision */
4963 static void handle_fp_1src_half(DisasContext
*s
, int opcode
, int rd
, int rn
)
4965 TCGv_ptr fpst
= NULL
;
4966 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
4967 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4970 case 0x0: /* FMOV */
4971 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4973 case 0x1: /* FABS */
4974 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
4976 case 0x2: /* FNEG */
4977 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
4979 case 0x3: /* FSQRT */
4980 fpst
= get_fpstatus_ptr(true);
4981 gen_helper_sqrt_f16(tcg_res
, tcg_op
, fpst
);
4983 case 0x8: /* FRINTN */
4984 case 0x9: /* FRINTP */
4985 case 0xa: /* FRINTM */
4986 case 0xb: /* FRINTZ */
4987 case 0xc: /* FRINTA */
4989 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4990 fpst
= get_fpstatus_ptr(true);
4992 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
4993 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
4995 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
4996 tcg_temp_free_i32(tcg_rmode
);
4999 case 0xe: /* FRINTX */
5000 fpst
= get_fpstatus_ptr(true);
5001 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, fpst
);
5003 case 0xf: /* FRINTI */
5004 fpst
= get_fpstatus_ptr(true);
5005 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, fpst
);
5011 write_fp_sreg(s
, rd
, tcg_res
);
5014 tcg_temp_free_ptr(fpst
);
5016 tcg_temp_free_i32(tcg_op
);
5017 tcg_temp_free_i32(tcg_res
);
5020 /* Floating-point data-processing (1 source) - single precision */
5021 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
5027 fpst
= get_fpstatus_ptr(false);
5028 tcg_op
= read_fp_sreg(s
, rn
);
5029 tcg_res
= tcg_temp_new_i32();
5032 case 0x0: /* FMOV */
5033 tcg_gen_mov_i32(tcg_res
, tcg_op
);
5035 case 0x1: /* FABS */
5036 gen_helper_vfp_abss(tcg_res
, tcg_op
);
5038 case 0x2: /* FNEG */
5039 gen_helper_vfp_negs(tcg_res
, tcg_op
);
5041 case 0x3: /* FSQRT */
5042 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
5044 case 0x8: /* FRINTN */
5045 case 0x9: /* FRINTP */
5046 case 0xa: /* FRINTM */
5047 case 0xb: /* FRINTZ */
5048 case 0xc: /* FRINTA */
5050 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
5052 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5053 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
5055 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5056 tcg_temp_free_i32(tcg_rmode
);
5059 case 0xe: /* FRINTX */
5060 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
5062 case 0xf: /* FRINTI */
5063 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
5069 write_fp_sreg(s
, rd
, tcg_res
);
5071 tcg_temp_free_ptr(fpst
);
5072 tcg_temp_free_i32(tcg_op
);
5073 tcg_temp_free_i32(tcg_res
);
5076 /* Floating-point data-processing (1 source) - double precision */
5077 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
5084 case 0x0: /* FMOV */
5085 gen_gvec_fn2(s
, false, rd
, rn
, tcg_gen_gvec_mov
, 0);
5089 fpst
= get_fpstatus_ptr(false);
5090 tcg_op
= read_fp_dreg(s
, rn
);
5091 tcg_res
= tcg_temp_new_i64();
5094 case 0x1: /* FABS */
5095 gen_helper_vfp_absd(tcg_res
, tcg_op
);
5097 case 0x2: /* FNEG */
5098 gen_helper_vfp_negd(tcg_res
, tcg_op
);
5100 case 0x3: /* FSQRT */
5101 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
5103 case 0x8: /* FRINTN */
5104 case 0x9: /* FRINTP */
5105 case 0xa: /* FRINTM */
5106 case 0xb: /* FRINTZ */
5107 case 0xc: /* FRINTA */
5109 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
5111 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5112 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
5114 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, fpst
);
5115 tcg_temp_free_i32(tcg_rmode
);
5118 case 0xe: /* FRINTX */
5119 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
5121 case 0xf: /* FRINTI */
5122 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
5128 write_fp_dreg(s
, rd
, tcg_res
);
5130 tcg_temp_free_ptr(fpst
);
5131 tcg_temp_free_i64(tcg_op
);
5132 tcg_temp_free_i64(tcg_res
);
5135 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
5136 int rd
, int rn
, int dtype
, int ntype
)
5141 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5143 /* Single to double */
5144 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5145 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
5146 write_fp_dreg(s
, rd
, tcg_rd
);
5147 tcg_temp_free_i64(tcg_rd
);
5149 /* Single to half */
5150 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5151 TCGv_i32 ahp
= get_ahp_flag();
5152 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5154 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5155 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5156 write_fp_sreg(s
, rd
, tcg_rd
);
5157 tcg_temp_free_i32(tcg_rd
);
5158 tcg_temp_free_i32(ahp
);
5159 tcg_temp_free_ptr(fpst
);
5161 tcg_temp_free_i32(tcg_rn
);
5166 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
5167 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5169 /* Double to single */
5170 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
5172 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5173 TCGv_i32 ahp
= get_ahp_flag();
5174 /* Double to half */
5175 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, fpst
, ahp
);
5176 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
5177 tcg_temp_free_ptr(fpst
);
5178 tcg_temp_free_i32(ahp
);
5180 write_fp_sreg(s
, rd
, tcg_rd
);
5181 tcg_temp_free_i32(tcg_rd
);
5182 tcg_temp_free_i64(tcg_rn
);
5187 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
5188 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(false);
5189 TCGv_i32 tcg_ahp
= get_ahp_flag();
5190 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
5192 /* Half to single */
5193 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
5194 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5195 write_fp_sreg(s
, rd
, tcg_rd
);
5196 tcg_temp_free_ptr(tcg_fpst
);
5197 tcg_temp_free_i32(tcg_ahp
);
5198 tcg_temp_free_i32(tcg_rd
);
5200 /* Half to double */
5201 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
5202 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, tcg_fpst
, tcg_ahp
);
5203 write_fp_dreg(s
, rd
, tcg_rd
);
5204 tcg_temp_free_i64(tcg_rd
);
5206 tcg_temp_free_i32(tcg_rn
);
5214 /* Floating point data-processing (1 source)
5215 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
5216 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5217 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
5218 * +---+---+---+-----------+------+---+--------+-----------+------+------+
5220 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
5222 int type
= extract32(insn
, 22, 2);
5223 int opcode
= extract32(insn
, 15, 6);
5224 int rn
= extract32(insn
, 5, 5);
5225 int rd
= extract32(insn
, 0, 5);
5228 case 0x4: case 0x5: case 0x7:
5230 /* FCVT between half, single and double precision */
5231 int dtype
= extract32(opcode
, 0, 2);
5232 if (type
== 2 || dtype
== type
) {
5233 unallocated_encoding(s
);
5236 if (!fp_access_check(s
)) {
5240 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
5246 /* 32-to-32 and 64-to-64 ops */
5249 if (!fp_access_check(s
)) {
5253 handle_fp_1src_single(s
, opcode
, rd
, rn
);
5256 if (!fp_access_check(s
)) {
5260 handle_fp_1src_double(s
, opcode
, rd
, rn
);
5263 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5264 unallocated_encoding(s
);
5268 if (!fp_access_check(s
)) {
5272 handle_fp_1src_half(s
, opcode
, rd
, rn
);
5275 unallocated_encoding(s
);
5279 unallocated_encoding(s
);
5284 /* Floating-point data-processing (2 source) - single precision */
5285 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
5286 int rd
, int rn
, int rm
)
5293 tcg_res
= tcg_temp_new_i32();
5294 fpst
= get_fpstatus_ptr(false);
5295 tcg_op1
= read_fp_sreg(s
, rn
);
5296 tcg_op2
= read_fp_sreg(s
, rm
);
5299 case 0x0: /* FMUL */
5300 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5302 case 0x1: /* FDIV */
5303 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5305 case 0x2: /* FADD */
5306 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5308 case 0x3: /* FSUB */
5309 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5311 case 0x4: /* FMAX */
5312 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5314 case 0x5: /* FMIN */
5315 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5317 case 0x6: /* FMAXNM */
5318 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5320 case 0x7: /* FMINNM */
5321 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5323 case 0x8: /* FNMUL */
5324 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5325 gen_helper_vfp_negs(tcg_res
, tcg_res
);
5329 write_fp_sreg(s
, rd
, tcg_res
);
5331 tcg_temp_free_ptr(fpst
);
5332 tcg_temp_free_i32(tcg_op1
);
5333 tcg_temp_free_i32(tcg_op2
);
5334 tcg_temp_free_i32(tcg_res
);
5337 /* Floating-point data-processing (2 source) - double precision */
5338 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
5339 int rd
, int rn
, int rm
)
5346 tcg_res
= tcg_temp_new_i64();
5347 fpst
= get_fpstatus_ptr(false);
5348 tcg_op1
= read_fp_dreg(s
, rn
);
5349 tcg_op2
= read_fp_dreg(s
, rm
);
5352 case 0x0: /* FMUL */
5353 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5355 case 0x1: /* FDIV */
5356 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5358 case 0x2: /* FADD */
5359 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5361 case 0x3: /* FSUB */
5362 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5364 case 0x4: /* FMAX */
5365 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5367 case 0x5: /* FMIN */
5368 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5370 case 0x6: /* FMAXNM */
5371 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5373 case 0x7: /* FMINNM */
5374 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5376 case 0x8: /* FNMUL */
5377 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5378 gen_helper_vfp_negd(tcg_res
, tcg_res
);
5382 write_fp_dreg(s
, rd
, tcg_res
);
5384 tcg_temp_free_ptr(fpst
);
5385 tcg_temp_free_i64(tcg_op1
);
5386 tcg_temp_free_i64(tcg_op2
);
5387 tcg_temp_free_i64(tcg_res
);
5390 /* Floating-point data-processing (2 source) - half precision */
5391 static void handle_fp_2src_half(DisasContext
*s
, int opcode
,
5392 int rd
, int rn
, int rm
)
5399 tcg_res
= tcg_temp_new_i32();
5400 fpst
= get_fpstatus_ptr(true);
5401 tcg_op1
= read_fp_hreg(s
, rn
);
5402 tcg_op2
= read_fp_hreg(s
, rm
);
5405 case 0x0: /* FMUL */
5406 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5408 case 0x1: /* FDIV */
5409 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5411 case 0x2: /* FADD */
5412 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5414 case 0x3: /* FSUB */
5415 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5417 case 0x4: /* FMAX */
5418 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5420 case 0x5: /* FMIN */
5421 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5423 case 0x6: /* FMAXNM */
5424 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5426 case 0x7: /* FMINNM */
5427 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5429 case 0x8: /* FNMUL */
5430 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5431 tcg_gen_xori_i32(tcg_res
, tcg_res
, 0x8000);
5434 g_assert_not_reached();
5437 write_fp_sreg(s
, rd
, tcg_res
);
5439 tcg_temp_free_ptr(fpst
);
5440 tcg_temp_free_i32(tcg_op1
);
5441 tcg_temp_free_i32(tcg_op2
);
5442 tcg_temp_free_i32(tcg_res
);
5445 /* Floating point data-processing (2 source)
5446 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
5447 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5448 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
5449 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
5451 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
5453 int type
= extract32(insn
, 22, 2);
5454 int rd
= extract32(insn
, 0, 5);
5455 int rn
= extract32(insn
, 5, 5);
5456 int rm
= extract32(insn
, 16, 5);
5457 int opcode
= extract32(insn
, 12, 4);
5460 unallocated_encoding(s
);
5466 if (!fp_access_check(s
)) {
5469 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
5472 if (!fp_access_check(s
)) {
5475 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
5478 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5479 unallocated_encoding(s
);
5482 if (!fp_access_check(s
)) {
5485 handle_fp_2src_half(s
, opcode
, rd
, rn
, rm
);
5488 unallocated_encoding(s
);
5492 /* Floating-point data-processing (3 source) - single precision */
5493 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
5494 int rd
, int rn
, int rm
, int ra
)
5496 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
5497 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5498 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5500 tcg_op1
= read_fp_sreg(s
, rn
);
5501 tcg_op2
= read_fp_sreg(s
, rm
);
5502 tcg_op3
= read_fp_sreg(s
, ra
);
5504 /* These are fused multiply-add, and must be done as one
5505 * floating point operation with no rounding between the
5506 * multiplication and addition steps.
5507 * NB that doing the negations here as separate steps is
5508 * correct : an input NaN should come out with its sign bit
5509 * flipped if it is a negated-input.
5512 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
5516 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
5519 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
5521 write_fp_sreg(s
, rd
, tcg_res
);
5523 tcg_temp_free_ptr(fpst
);
5524 tcg_temp_free_i32(tcg_op1
);
5525 tcg_temp_free_i32(tcg_op2
);
5526 tcg_temp_free_i32(tcg_op3
);
5527 tcg_temp_free_i32(tcg_res
);
5530 /* Floating-point data-processing (3 source) - double precision */
5531 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
5532 int rd
, int rn
, int rm
, int ra
)
5534 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
5535 TCGv_i64 tcg_res
= tcg_temp_new_i64();
5536 TCGv_ptr fpst
= get_fpstatus_ptr(false);
5538 tcg_op1
= read_fp_dreg(s
, rn
);
5539 tcg_op2
= read_fp_dreg(s
, rm
);
5540 tcg_op3
= read_fp_dreg(s
, ra
);
5542 /* These are fused multiply-add, and must be done as one
5543 * floating point operation with no rounding between the
5544 * multiplication and addition steps.
5545 * NB that doing the negations here as separate steps is
5546 * correct : an input NaN should come out with its sign bit
5547 * flipped if it is a negated-input.
5550 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
5554 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
5557 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
5559 write_fp_dreg(s
, rd
, tcg_res
);
5561 tcg_temp_free_ptr(fpst
);
5562 tcg_temp_free_i64(tcg_op1
);
5563 tcg_temp_free_i64(tcg_op2
);
5564 tcg_temp_free_i64(tcg_op3
);
5565 tcg_temp_free_i64(tcg_res
);
5568 /* Floating-point data-processing (3 source) - half precision */
5569 static void handle_fp_3src_half(DisasContext
*s
, bool o0
, bool o1
,
5570 int rd
, int rn
, int rm
, int ra
)
5572 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
5573 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5574 TCGv_ptr fpst
= get_fpstatus_ptr(true);
5576 tcg_op1
= read_fp_hreg(s
, rn
);
5577 tcg_op2
= read_fp_hreg(s
, rm
);
5578 tcg_op3
= read_fp_hreg(s
, ra
);
5580 /* These are fused multiply-add, and must be done as one
5581 * floating point operation with no rounding between the
5582 * multiplication and addition steps.
5583 * NB that doing the negations here as separate steps is
5584 * correct : an input NaN should come out with its sign bit
5585 * flipped if it is a negated-input.
5588 tcg_gen_xori_i32(tcg_op3
, tcg_op3
, 0x8000);
5592 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
5595 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
5597 write_fp_sreg(s
, rd
, tcg_res
);
5599 tcg_temp_free_ptr(fpst
);
5600 tcg_temp_free_i32(tcg_op1
);
5601 tcg_temp_free_i32(tcg_op2
);
5602 tcg_temp_free_i32(tcg_op3
);
5603 tcg_temp_free_i32(tcg_res
);
5606 /* Floating point data-processing (3 source)
5607 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
5608 * +---+---+---+-----------+------+----+------+----+------+------+------+
5609 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
5610 * +---+---+---+-----------+------+----+------+----+------+------+------+
5612 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
5614 int type
= extract32(insn
, 22, 2);
5615 int rd
= extract32(insn
, 0, 5);
5616 int rn
= extract32(insn
, 5, 5);
5617 int ra
= extract32(insn
, 10, 5);
5618 int rm
= extract32(insn
, 16, 5);
5619 bool o0
= extract32(insn
, 15, 1);
5620 bool o1
= extract32(insn
, 21, 1);
5624 if (!fp_access_check(s
)) {
5627 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
5630 if (!fp_access_check(s
)) {
5633 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
5636 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5637 unallocated_encoding(s
);
5640 if (!fp_access_check(s
)) {
5643 handle_fp_3src_half(s
, o0
, o1
, rd
, rn
, rm
, ra
);
5646 unallocated_encoding(s
);
5650 /* The imm8 encodes the sign bit, enough bits to represent an exponent in
5651 * the range 01....1xx to 10....0xx, and the most significant 4 bits of
5652 * the mantissa; see VFPExpandImm() in the v8 ARM ARM.
5654 uint64_t vfp_expand_imm(int size
, uint8_t imm8
)
5660 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
5661 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
5662 extract32(imm8
, 0, 6);
5666 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
5667 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
5668 (extract32(imm8
, 0, 6) << 3);
5672 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
5673 (extract32(imm8
, 6, 1) ? 0x3000 : 0x4000) |
5674 (extract32(imm8
, 0, 6) << 6);
5677 g_assert_not_reached();
5682 /* Floating point immediate
5683 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
5684 * +---+---+---+-----------+------+---+------------+-------+------+------+
5685 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
5686 * +---+---+---+-----------+------+---+------------+-------+------+------+
5688 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
5690 int rd
= extract32(insn
, 0, 5);
5691 int imm8
= extract32(insn
, 13, 8);
5692 int type
= extract32(insn
, 22, 2);
5706 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5711 unallocated_encoding(s
);
5715 if (!fp_access_check(s
)) {
5719 imm
= vfp_expand_imm(sz
, imm8
);
5721 tcg_res
= tcg_const_i64(imm
);
5722 write_fp_dreg(s
, rd
, tcg_res
);
5723 tcg_temp_free_i64(tcg_res
);
5726 /* Handle floating point <=> fixed point conversions. Note that we can
5727 * also deal with fp <=> integer conversions as a special case (scale == 64)
5728 * OPTME: consider handling that special case specially or at least skipping
5729 * the call to scalbn in the helpers for zero shifts.
5731 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
5732 bool itof
, int rmode
, int scale
, int sf
, int type
)
5734 bool is_signed
= !(opcode
& 1);
5735 TCGv_ptr tcg_fpstatus
;
5736 TCGv_i32 tcg_shift
, tcg_single
;
5737 TCGv_i64 tcg_double
;
5739 tcg_fpstatus
= get_fpstatus_ptr(type
== 3);
5741 tcg_shift
= tcg_const_i32(64 - scale
);
5744 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
5746 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
5749 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
5751 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
5754 tcg_int
= tcg_extend
;
5758 case 1: /* float64 */
5759 tcg_double
= tcg_temp_new_i64();
5761 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
5762 tcg_shift
, tcg_fpstatus
);
5764 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
5765 tcg_shift
, tcg_fpstatus
);
5767 write_fp_dreg(s
, rd
, tcg_double
);
5768 tcg_temp_free_i64(tcg_double
);
5771 case 0: /* float32 */
5772 tcg_single
= tcg_temp_new_i32();
5774 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
5775 tcg_shift
, tcg_fpstatus
);
5777 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
5778 tcg_shift
, tcg_fpstatus
);
5780 write_fp_sreg(s
, rd
, tcg_single
);
5781 tcg_temp_free_i32(tcg_single
);
5784 case 3: /* float16 */
5785 tcg_single
= tcg_temp_new_i32();
5787 gen_helper_vfp_sqtoh(tcg_single
, tcg_int
,
5788 tcg_shift
, tcg_fpstatus
);
5790 gen_helper_vfp_uqtoh(tcg_single
, tcg_int
,
5791 tcg_shift
, tcg_fpstatus
);
5793 write_fp_sreg(s
, rd
, tcg_single
);
5794 tcg_temp_free_i32(tcg_single
);
5798 g_assert_not_reached();
5801 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
5804 if (extract32(opcode
, 2, 1)) {
5805 /* There are too many rounding modes to all fit into rmode,
5806 * so FCVTA[US] is a special case.
5808 rmode
= FPROUNDING_TIEAWAY
;
5811 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
5813 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
5816 case 1: /* float64 */
5817 tcg_double
= read_fp_dreg(s
, rn
);
5820 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
5821 tcg_shift
, tcg_fpstatus
);
5823 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
5824 tcg_shift
, tcg_fpstatus
);
5828 gen_helper_vfp_tould(tcg_int
, tcg_double
,
5829 tcg_shift
, tcg_fpstatus
);
5831 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
5832 tcg_shift
, tcg_fpstatus
);
5836 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
5838 tcg_temp_free_i64(tcg_double
);
5841 case 0: /* float32 */
5842 tcg_single
= read_fp_sreg(s
, rn
);
5845 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
5846 tcg_shift
, tcg_fpstatus
);
5848 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
5849 tcg_shift
, tcg_fpstatus
);
5852 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
5854 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
5855 tcg_shift
, tcg_fpstatus
);
5857 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
5858 tcg_shift
, tcg_fpstatus
);
5860 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
5861 tcg_temp_free_i32(tcg_dest
);
5863 tcg_temp_free_i32(tcg_single
);
5866 case 3: /* float16 */
5867 tcg_single
= read_fp_sreg(s
, rn
);
5870 gen_helper_vfp_tosqh(tcg_int
, tcg_single
,
5871 tcg_shift
, tcg_fpstatus
);
5873 gen_helper_vfp_touqh(tcg_int
, tcg_single
,
5874 tcg_shift
, tcg_fpstatus
);
5877 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
5879 gen_helper_vfp_toslh(tcg_dest
, tcg_single
,
5880 tcg_shift
, tcg_fpstatus
);
5882 gen_helper_vfp_toulh(tcg_dest
, tcg_single
,
5883 tcg_shift
, tcg_fpstatus
);
5885 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
5886 tcg_temp_free_i32(tcg_dest
);
5888 tcg_temp_free_i32(tcg_single
);
5892 g_assert_not_reached();
5895 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
5896 tcg_temp_free_i32(tcg_rmode
);
5899 tcg_temp_free_ptr(tcg_fpstatus
);
5900 tcg_temp_free_i32(tcg_shift
);
5903 /* Floating point <-> fixed point conversions
5904 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
5905 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
5906 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
5907 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
5909 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
5911 int rd
= extract32(insn
, 0, 5);
5912 int rn
= extract32(insn
, 5, 5);
5913 int scale
= extract32(insn
, 10, 6);
5914 int opcode
= extract32(insn
, 16, 3);
5915 int rmode
= extract32(insn
, 19, 2);
5916 int type
= extract32(insn
, 22, 2);
5917 bool sbit
= extract32(insn
, 29, 1);
5918 bool sf
= extract32(insn
, 31, 1);
5921 if (sbit
|| (!sf
&& scale
< 32)) {
5922 unallocated_encoding(s
);
5927 case 0: /* float32 */
5928 case 1: /* float64 */
5930 case 3: /* float16 */
5931 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
5936 unallocated_encoding(s
);
5940 switch ((rmode
<< 3) | opcode
) {
5941 case 0x2: /* SCVTF */
5942 case 0x3: /* UCVTF */
5945 case 0x18: /* FCVTZS */
5946 case 0x19: /* FCVTZU */
5950 unallocated_encoding(s
);
5954 if (!fp_access_check(s
)) {
5958 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
5961 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
5963 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
5964 * without conversion.
5968 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
5974 tmp
= tcg_temp_new_i64();
5975 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
5976 write_fp_dreg(s
, rd
, tmp
);
5977 tcg_temp_free_i64(tmp
);
5981 write_fp_dreg(s
, rd
, tcg_rn
);
5984 /* 64 bit to top half. */
5985 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5986 clear_vec_high(s
, true, rd
);
5990 tmp
= tcg_temp_new_i64();
5991 tcg_gen_ext16u_i64(tmp
, tcg_rn
);
5992 write_fp_dreg(s
, rd
, tmp
);
5993 tcg_temp_free_i64(tmp
);
5996 g_assert_not_reached();
5999 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
6004 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
6008 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
6011 /* 64 bits from top half */
6012 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
6016 tcg_gen_ld16u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_16
));
6019 g_assert_not_reached();
6024 /* Floating point <-> integer conversions
6025 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
6026 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6027 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
6028 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
6030 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
6032 int rd
= extract32(insn
, 0, 5);
6033 int rn
= extract32(insn
, 5, 5);
6034 int opcode
= extract32(insn
, 16, 3);
6035 int rmode
= extract32(insn
, 19, 2);
6036 int type
= extract32(insn
, 22, 2);
6037 bool sbit
= extract32(insn
, 29, 1);
6038 bool sf
= extract32(insn
, 31, 1);
6041 unallocated_encoding(s
);
6047 bool itof
= opcode
& 1;
6050 unallocated_encoding(s
);
6054 switch (sf
<< 3 | type
<< 1 | rmode
) {
6055 case 0x0: /* 32 bit */
6056 case 0xa: /* 64 bit */
6057 case 0xd: /* 64 bit to top half of quad */
6059 case 0x6: /* 16-bit float, 32-bit int */
6060 case 0xe: /* 16-bit float, 64-bit int */
6061 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
6066 /* all other sf/type/rmode combinations are invalid */
6067 unallocated_encoding(s
);
6071 if (!fp_access_check(s
)) {
6074 handle_fmov(s
, rd
, rn
, type
, itof
);
6076 /* actual FP conversions */
6077 bool itof
= extract32(opcode
, 1, 1);
6079 if (rmode
!= 0 && opcode
> 1) {
6080 unallocated_encoding(s
);
6084 case 0: /* float32 */
6085 case 1: /* float64 */
6087 case 3: /* float16 */
6088 if (arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
6093 unallocated_encoding(s
);
6097 if (!fp_access_check(s
)) {
6100 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
6104 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
6105 * 31 30 29 28 25 24 0
6106 * +---+---+---+---------+-----------------------------+
6107 * | | 0 | | 1 1 1 1 | |
6108 * +---+---+---+---------+-----------------------------+
6110 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
6112 if (extract32(insn
, 24, 1)) {
6113 /* Floating point data-processing (3 source) */
6114 disas_fp_3src(s
, insn
);
6115 } else if (extract32(insn
, 21, 1) == 0) {
6116 /* Floating point to fixed point conversions */
6117 disas_fp_fixed_conv(s
, insn
);
6119 switch (extract32(insn
, 10, 2)) {
6121 /* Floating point conditional compare */
6122 disas_fp_ccomp(s
, insn
);
6125 /* Floating point data-processing (2 source) */
6126 disas_fp_2src(s
, insn
);
6129 /* Floating point conditional select */
6130 disas_fp_csel(s
, insn
);
6133 switch (ctz32(extract32(insn
, 12, 4))) {
6134 case 0: /* [15:12] == xxx1 */
6135 /* Floating point immediate */
6136 disas_fp_imm(s
, insn
);
6138 case 1: /* [15:12] == xx10 */
6139 /* Floating point compare */
6140 disas_fp_compare(s
, insn
);
6142 case 2: /* [15:12] == x100 */
6143 /* Floating point data-processing (1 source) */
6144 disas_fp_1src(s
, insn
);
6146 case 3: /* [15:12] == 1000 */
6147 unallocated_encoding(s
);
6149 default: /* [15:12] == 0000 */
6150 /* Floating point <-> integer conversions */
6151 disas_fp_int_conv(s
, insn
);
6159 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
6162 /* Extract 64 bits from the middle of two concatenated 64 bit
6163 * vector register slices left:right. The extracted bits start
6164 * at 'pos' bits into the right (least significant) side.
6165 * We return the result in tcg_right, and guarantee not to
6168 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
6169 assert(pos
> 0 && pos
< 64);
6171 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
6172 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
6173 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
6175 tcg_temp_free_i64(tcg_tmp
);
6179 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
6180 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6181 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
6182 * +---+---+-------------+-----+---+------+---+------+---+------+------+
6184 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
6186 int is_q
= extract32(insn
, 30, 1);
6187 int op2
= extract32(insn
, 22, 2);
6188 int imm4
= extract32(insn
, 11, 4);
6189 int rm
= extract32(insn
, 16, 5);
6190 int rn
= extract32(insn
, 5, 5);
6191 int rd
= extract32(insn
, 0, 5);
6192 int pos
= imm4
<< 3;
6193 TCGv_i64 tcg_resl
, tcg_resh
;
6195 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
6196 unallocated_encoding(s
);
6200 if (!fp_access_check(s
)) {
6204 tcg_resh
= tcg_temp_new_i64();
6205 tcg_resl
= tcg_temp_new_i64();
6207 /* Vd gets bits starting at pos bits into Vm:Vn. This is
6208 * either extracting 128 bits from a 128:128 concatenation, or
6209 * extracting 64 bits from a 64:64 concatenation.
6212 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
6214 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
6215 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6217 tcg_gen_movi_i64(tcg_resh
, 0);
6224 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
6225 EltPosns
*elt
= eltposns
;
6232 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
6234 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
6237 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
6238 tcg_hh
= tcg_temp_new_i64();
6239 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
6240 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
6241 tcg_temp_free_i64(tcg_hh
);
6245 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6246 tcg_temp_free_i64(tcg_resl
);
6247 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6248 tcg_temp_free_i64(tcg_resh
);
6252 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
6253 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6254 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
6255 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
6257 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
6259 int op2
= extract32(insn
, 22, 2);
6260 int is_q
= extract32(insn
, 30, 1);
6261 int rm
= extract32(insn
, 16, 5);
6262 int rn
= extract32(insn
, 5, 5);
6263 int rd
= extract32(insn
, 0, 5);
6264 int is_tblx
= extract32(insn
, 12, 1);
6265 int len
= extract32(insn
, 13, 2);
6266 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
6267 TCGv_i32 tcg_regno
, tcg_numregs
;
6270 unallocated_encoding(s
);
6274 if (!fp_access_check(s
)) {
6278 /* This does a table lookup: for every byte element in the input
6279 * we index into a table formed from up to four vector registers,
6280 * and then the output is the result of the lookups. Our helper
6281 * function does the lookup operation for a single 64 bit part of
6284 tcg_resl
= tcg_temp_new_i64();
6285 tcg_resh
= tcg_temp_new_i64();
6288 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6290 tcg_gen_movi_i64(tcg_resl
, 0);
6292 if (is_tblx
&& is_q
) {
6293 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6295 tcg_gen_movi_i64(tcg_resh
, 0);
6298 tcg_idx
= tcg_temp_new_i64();
6299 tcg_regno
= tcg_const_i32(rn
);
6300 tcg_numregs
= tcg_const_i32(len
+ 1);
6301 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
6302 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
6303 tcg_regno
, tcg_numregs
);
6305 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
6306 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
6307 tcg_regno
, tcg_numregs
);
6309 tcg_temp_free_i64(tcg_idx
);
6310 tcg_temp_free_i32(tcg_regno
);
6311 tcg_temp_free_i32(tcg_numregs
);
6313 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6314 tcg_temp_free_i64(tcg_resl
);
6315 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6316 tcg_temp_free_i64(tcg_resh
);
6320 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
6321 * +---+---+-------------+------+---+------+---+------------------+------+
6322 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
6323 * +---+---+-------------+------+---+------+---+------------------+------+
6325 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
6327 int rd
= extract32(insn
, 0, 5);
6328 int rn
= extract32(insn
, 5, 5);
6329 int rm
= extract32(insn
, 16, 5);
6330 int size
= extract32(insn
, 22, 2);
6331 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
6332 * bit 2 indicates 1 vs 2 variant of the insn.
6334 int opcode
= extract32(insn
, 12, 2);
6335 bool part
= extract32(insn
, 14, 1);
6336 bool is_q
= extract32(insn
, 30, 1);
6337 int esize
= 8 << size
;
6339 int datasize
= is_q
? 128 : 64;
6340 int elements
= datasize
/ esize
;
6341 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
6343 if (opcode
== 0 || (size
== 3 && !is_q
)) {
6344 unallocated_encoding(s
);
6348 if (!fp_access_check(s
)) {
6352 tcg_resl
= tcg_const_i64(0);
6353 tcg_resh
= tcg_const_i64(0);
6354 tcg_res
= tcg_temp_new_i64();
6356 for (i
= 0; i
< elements
; i
++) {
6358 case 1: /* UZP1/2 */
6360 int midpoint
= elements
/ 2;
6362 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
6364 read_vec_element(s
, tcg_res
, rm
,
6365 2 * (i
- midpoint
) + part
, size
);
6369 case 2: /* TRN1/2 */
6371 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
6373 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
6376 case 3: /* ZIP1/2 */
6378 int base
= part
* elements
/ 2;
6380 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
6382 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
6387 g_assert_not_reached();
6392 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
6393 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
6395 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
6396 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
6400 tcg_temp_free_i64(tcg_res
);
6402 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
6403 tcg_temp_free_i64(tcg_resl
);
6404 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
6405 tcg_temp_free_i64(tcg_resh
);
6409 * do_reduction_op helper
6411 * This mirrors the Reduce() pseudocode in the ARM ARM. It is
6412 * important for correct NaN propagation that we do these
6413 * operations in exactly the order specified by the pseudocode.
6415 * This is a recursive function, TCG temps should be freed by the
6416 * calling function once it is done with the values.
6418 static TCGv_i32
do_reduction_op(DisasContext
*s
, int fpopcode
, int rn
,
6419 int esize
, int size
, int vmap
, TCGv_ptr fpst
)
6421 if (esize
== size
) {
6423 TCGMemOp msize
= esize
== 16 ? MO_16
: MO_32
;
6426 /* We should have one register left here */
6427 assert(ctpop8(vmap
) == 1);
6428 element
= ctz32(vmap
);
6429 assert(element
< 8);
6431 tcg_elem
= tcg_temp_new_i32();
6432 read_vec_element_i32(s
, tcg_elem
, rn
, element
, msize
);
6435 int bits
= size
/ 2;
6436 int shift
= ctpop8(vmap
) / 2;
6437 int vmap_lo
= (vmap
>> shift
) & vmap
;
6438 int vmap_hi
= (vmap
& ~vmap_lo
);
6439 TCGv_i32 tcg_hi
, tcg_lo
, tcg_res
;
6441 tcg_hi
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_hi
, fpst
);
6442 tcg_lo
= do_reduction_op(s
, fpopcode
, rn
, esize
, bits
, vmap_lo
, fpst
);
6443 tcg_res
= tcg_temp_new_i32();
6446 case 0x0c: /* fmaxnmv half-precision */
6447 gen_helper_advsimd_maxnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6449 case 0x0f: /* fmaxv half-precision */
6450 gen_helper_advsimd_maxh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6452 case 0x1c: /* fminnmv half-precision */
6453 gen_helper_advsimd_minnumh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6455 case 0x1f: /* fminv half-precision */
6456 gen_helper_advsimd_minh(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6458 case 0x2c: /* fmaxnmv */
6459 gen_helper_vfp_maxnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6461 case 0x2f: /* fmaxv */
6462 gen_helper_vfp_maxs(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6464 case 0x3c: /* fminnmv */
6465 gen_helper_vfp_minnums(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6467 case 0x3f: /* fminv */
6468 gen_helper_vfp_mins(tcg_res
, tcg_lo
, tcg_hi
, fpst
);
6471 g_assert_not_reached();
6474 tcg_temp_free_i32(tcg_hi
);
6475 tcg_temp_free_i32(tcg_lo
);
6480 /* AdvSIMD across lanes
6481 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6482 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6483 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6484 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
6486 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
6488 int rd
= extract32(insn
, 0, 5);
6489 int rn
= extract32(insn
, 5, 5);
6490 int size
= extract32(insn
, 22, 2);
6491 int opcode
= extract32(insn
, 12, 5);
6492 bool is_q
= extract32(insn
, 30, 1);
6493 bool is_u
= extract32(insn
, 29, 1);
6495 bool is_min
= false;
6499 TCGv_i64 tcg_res
, tcg_elt
;
6502 case 0x1b: /* ADDV */
6504 unallocated_encoding(s
);
6508 case 0x3: /* SADDLV, UADDLV */
6509 case 0xa: /* SMAXV, UMAXV */
6510 case 0x1a: /* SMINV, UMINV */
6511 if (size
== 3 || (size
== 2 && !is_q
)) {
6512 unallocated_encoding(s
);
6516 case 0xc: /* FMAXNMV, FMINNMV */
6517 case 0xf: /* FMAXV, FMINV */
6518 /* Bit 1 of size field encodes min vs max and the actual size
6519 * depends on the encoding of the U bit. If not set (and FP16
6520 * enabled) then we do half-precision float instead of single
6523 is_min
= extract32(size
, 1, 1);
6525 if (!is_u
&& arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
6527 } else if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
6528 unallocated_encoding(s
);
6535 unallocated_encoding(s
);
6539 if (!fp_access_check(s
)) {
6544 elements
= (is_q
? 128 : 64) / esize
;
6546 tcg_res
= tcg_temp_new_i64();
6547 tcg_elt
= tcg_temp_new_i64();
6549 /* These instructions operate across all lanes of a vector
6550 * to produce a single result. We can guarantee that a 64
6551 * bit intermediate is sufficient:
6552 * + for [US]ADDLV the maximum element size is 32 bits, and
6553 * the result type is 64 bits
6554 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
6555 * same as the element size, which is 32 bits at most
6556 * For the integer operations we can choose to work at 64
6557 * or 32 bits and truncate at the end; for simplicity
6558 * we use 64 bits always. The floating point
6559 * ops do require 32 bit intermediates, though.
6562 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
6564 for (i
= 1; i
< elements
; i
++) {
6565 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
6568 case 0x03: /* SADDLV / UADDLV */
6569 case 0x1b: /* ADDV */
6570 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
6572 case 0x0a: /* SMAXV / UMAXV */
6574 tcg_gen_umax_i64(tcg_res
, tcg_res
, tcg_elt
);
6576 tcg_gen_smax_i64(tcg_res
, tcg_res
, tcg_elt
);
6579 case 0x1a: /* SMINV / UMINV */
6581 tcg_gen_umin_i64(tcg_res
, tcg_res
, tcg_elt
);
6583 tcg_gen_smin_i64(tcg_res
, tcg_res
, tcg_elt
);
6587 g_assert_not_reached();
6592 /* Floating point vector reduction ops which work across 32
6593 * bit (single) or 16 bit (half-precision) intermediates.
6594 * Note that correct NaN propagation requires that we do these
6595 * operations in exactly the order specified by the pseudocode.
6597 TCGv_ptr fpst
= get_fpstatus_ptr(size
== MO_16
);
6598 int fpopcode
= opcode
| is_min
<< 4 | is_u
<< 5;
6599 int vmap
= (1 << elements
) - 1;
6600 TCGv_i32 tcg_res32
= do_reduction_op(s
, fpopcode
, rn
, esize
,
6601 (is_q
? 128 : 64), vmap
, fpst
);
6602 tcg_gen_extu_i32_i64(tcg_res
, tcg_res32
);
6603 tcg_temp_free_i32(tcg_res32
);
6604 tcg_temp_free_ptr(fpst
);
6607 tcg_temp_free_i64(tcg_elt
);
6609 /* Now truncate the result to the width required for the final output */
6610 if (opcode
== 0x03) {
6611 /* SADDLV, UADDLV: result is 2*esize */
6617 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
6620 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
6623 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
6628 g_assert_not_reached();
6631 write_fp_dreg(s
, rd
, tcg_res
);
6632 tcg_temp_free_i64(tcg_res
);
6635 /* DUP (Element, Vector)
6637 * 31 30 29 21 20 16 15 10 9 5 4 0
6638 * +---+---+-------------------+--------+-------------+------+------+
6639 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
6640 * +---+---+-------------------+--------+-------------+------+------+
6642 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6644 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
6647 int size
= ctz32(imm5
);
6648 int index
= imm5
>> (size
+ 1);
6650 if (size
> 3 || (size
== 3 && !is_q
)) {
6651 unallocated_encoding(s
);
6655 if (!fp_access_check(s
)) {
6659 tcg_gen_gvec_dup_mem(size
, vec_full_reg_offset(s
, rd
),
6660 vec_reg_offset(s
, rn
, index
, size
),
6661 is_q
? 16 : 8, vec_full_reg_size(s
));
6664 /* DUP (element, scalar)
6665 * 31 21 20 16 15 10 9 5 4 0
6666 * +-----------------------+--------+-------------+------+------+
6667 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
6668 * +-----------------------+--------+-------------+------+------+
6670 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
6673 int size
= ctz32(imm5
);
6678 unallocated_encoding(s
);
6682 if (!fp_access_check(s
)) {
6686 index
= imm5
>> (size
+ 1);
6688 /* This instruction just extracts the specified element and
6689 * zero-extends it into the bottom of the destination register.
6691 tmp
= tcg_temp_new_i64();
6692 read_vec_element(s
, tmp
, rn
, index
, size
);
6693 write_fp_dreg(s
, rd
, tmp
);
6694 tcg_temp_free_i64(tmp
);
6699 * 31 30 29 21 20 16 15 10 9 5 4 0
6700 * +---+---+-------------------+--------+-------------+------+------+
6701 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
6702 * +---+---+-------------------+--------+-------------+------+------+
6704 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6706 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
6709 int size
= ctz32(imm5
);
6710 uint32_t dofs
, oprsz
, maxsz
;
6712 if (size
> 3 || ((size
== 3) && !is_q
)) {
6713 unallocated_encoding(s
);
6717 if (!fp_access_check(s
)) {
6721 dofs
= vec_full_reg_offset(s
, rd
);
6722 oprsz
= is_q
? 16 : 8;
6723 maxsz
= vec_full_reg_size(s
);
6725 tcg_gen_gvec_dup_i64(size
, dofs
, oprsz
, maxsz
, cpu_reg(s
, rn
));
6730 * 31 21 20 16 15 14 11 10 9 5 4 0
6731 * +-----------------------+--------+------------+---+------+------+
6732 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6733 * +-----------------------+--------+------------+---+------+------+
6735 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6736 * index: encoded in imm5<4:size+1>
6738 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
6741 int size
= ctz32(imm5
);
6742 int src_index
, dst_index
;
6746 unallocated_encoding(s
);
6750 if (!fp_access_check(s
)) {
6754 dst_index
= extract32(imm5
, 1+size
, 5);
6755 src_index
= extract32(imm4
, size
, 4);
6757 tmp
= tcg_temp_new_i64();
6759 read_vec_element(s
, tmp
, rn
, src_index
, size
);
6760 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
6762 tcg_temp_free_i64(tmp
);
6768 * 31 21 20 16 15 10 9 5 4 0
6769 * +-----------------------+--------+-------------+------+------+
6770 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
6771 * +-----------------------+--------+-------------+------+------+
6773 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6774 * index: encoded in imm5<4:size+1>
6776 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
6778 int size
= ctz32(imm5
);
6782 unallocated_encoding(s
);
6786 if (!fp_access_check(s
)) {
6790 idx
= extract32(imm5
, 1 + size
, 4 - size
);
6791 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
6798 * 31 30 29 21 20 16 15 12 10 9 5 4 0
6799 * +---+---+-------------------+--------+-------------+------+------+
6800 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
6801 * +---+---+-------------------+--------+-------------+------+------+
6803 * U: unsigned when set
6804 * size: encoded in imm5 (see ARM ARM LowestSetBit())
6806 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
6807 int rn
, int rd
, int imm5
)
6809 int size
= ctz32(imm5
);
6813 /* Check for UnallocatedEncodings */
6815 if (size
> 2 || (size
== 2 && !is_q
)) {
6816 unallocated_encoding(s
);
6821 || (size
< 3 && is_q
)
6822 || (size
== 3 && !is_q
)) {
6823 unallocated_encoding(s
);
6828 if (!fp_access_check(s
)) {
6832 element
= extract32(imm5
, 1+size
, 4);
6834 tcg_rd
= cpu_reg(s
, rd
);
6835 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
6836 if (is_signed
&& !is_q
) {
6837 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
6842 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
6843 * +---+---+----+-----------------+------+---+------+---+------+------+
6844 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6845 * +---+---+----+-----------------+------+---+------+---+------+------+
6847 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
6849 int rd
= extract32(insn
, 0, 5);
6850 int rn
= extract32(insn
, 5, 5);
6851 int imm4
= extract32(insn
, 11, 4);
6852 int op
= extract32(insn
, 29, 1);
6853 int is_q
= extract32(insn
, 30, 1);
6854 int imm5
= extract32(insn
, 16, 5);
6859 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
6861 unallocated_encoding(s
);
6866 /* DUP (element - vector) */
6867 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
6871 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
6876 handle_simd_insg(s
, rd
, rn
, imm5
);
6878 unallocated_encoding(s
);
6883 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
6884 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
6887 unallocated_encoding(s
);
6893 /* AdvSIMD modified immediate
6894 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
6895 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
6896 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
6897 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
6899 * There are a number of operations that can be carried out here:
6900 * MOVI - move (shifted) imm into register
6901 * MVNI - move inverted (shifted) imm into register
6902 * ORR - bitwise OR of (shifted) imm with register
6903 * BIC - bitwise clear of (shifted) imm with register
6904 * With ARMv8.2 we also have:
6905 * FMOV half-precision
6907 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
6909 int rd
= extract32(insn
, 0, 5);
6910 int cmode
= extract32(insn
, 12, 4);
6911 int cmode_3_1
= extract32(cmode
, 1, 3);
6912 int cmode_0
= extract32(cmode
, 0, 1);
6913 int o2
= extract32(insn
, 11, 1);
6914 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
6915 bool is_neg
= extract32(insn
, 29, 1);
6916 bool is_q
= extract32(insn
, 30, 1);
6919 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
6920 /* Check for FMOV (vector, immediate) - half-precision */
6921 if (!(arm_dc_feature(s
, ARM_FEATURE_V8_FP16
) && o2
&& cmode
== 0xf)) {
6922 unallocated_encoding(s
);
6927 if (!fp_access_check(s
)) {
6931 /* See AdvSIMDExpandImm() in ARM ARM */
6932 switch (cmode_3_1
) {
6933 case 0: /* Replicate(Zeros(24):imm8, 2) */
6934 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
6935 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
6936 case 3: /* Replicate(imm8:Zeros(24), 2) */
6938 int shift
= cmode_3_1
* 8;
6939 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
6942 case 4: /* Replicate(Zeros(8):imm8, 4) */
6943 case 5: /* Replicate(imm8:Zeros(8), 4) */
6945 int shift
= (cmode_3_1
& 0x1) * 8;
6946 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
6951 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
6952 imm
= (abcdefgh
<< 16) | 0xffff;
6954 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
6955 imm
= (abcdefgh
<< 8) | 0xff;
6957 imm
= bitfield_replicate(imm
, 32);
6960 if (!cmode_0
&& !is_neg
) {
6961 imm
= bitfield_replicate(abcdefgh
, 8);
6962 } else if (!cmode_0
&& is_neg
) {
6965 for (i
= 0; i
< 8; i
++) {
6966 if ((abcdefgh
) & (1 << i
)) {
6967 imm
|= 0xffULL
<< (i
* 8);
6970 } else if (cmode_0
) {
6972 imm
= (abcdefgh
& 0x3f) << 48;
6973 if (abcdefgh
& 0x80) {
6974 imm
|= 0x8000000000000000ULL
;
6976 if (abcdefgh
& 0x40) {
6977 imm
|= 0x3fc0000000000000ULL
;
6979 imm
|= 0x4000000000000000ULL
;
6983 /* FMOV (vector, immediate) - half-precision */
6984 imm
= vfp_expand_imm(MO_16
, abcdefgh
);
6985 /* now duplicate across the lanes */
6986 imm
= bitfield_replicate(imm
, 16);
6988 imm
= (abcdefgh
& 0x3f) << 19;
6989 if (abcdefgh
& 0x80) {
6992 if (abcdefgh
& 0x40) {
7003 fprintf(stderr
, "%s: cmode_3_1: %x\n", __func__
, cmode_3_1
);
7004 g_assert_not_reached();
7007 if (cmode_3_1
!= 7 && is_neg
) {
7011 if (!((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9)) {
7012 /* MOVI or MVNI, with MVNI negation handled above. */
7013 tcg_gen_gvec_dup64i(vec_full_reg_offset(s
, rd
), is_q
? 16 : 8,
7014 vec_full_reg_size(s
), imm
);
7016 /* ORR or BIC, with BIC negation to AND handled above. */
7018 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_andi
, MO_64
);
7020 gen_gvec_fn2i(s
, is_q
, rd
, rd
, imm
, tcg_gen_gvec_ori
, MO_64
);
7025 /* AdvSIMD scalar copy
7026 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
7027 * +-----+----+-----------------+------+---+------+---+------+------+
7028 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
7029 * +-----+----+-----------------+------+---+------+---+------+------+
7031 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
7033 int rd
= extract32(insn
, 0, 5);
7034 int rn
= extract32(insn
, 5, 5);
7035 int imm4
= extract32(insn
, 11, 4);
7036 int imm5
= extract32(insn
, 16, 5);
7037 int op
= extract32(insn
, 29, 1);
7039 if (op
!= 0 || imm4
!= 0) {
7040 unallocated_encoding(s
);
7044 /* DUP (element, scalar) */
7045 handle_simd_dupes(s
, rd
, rn
, imm5
);
7048 /* AdvSIMD scalar pairwise
7049 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7050 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7051 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
7052 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7054 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
7056 int u
= extract32(insn
, 29, 1);
7057 int size
= extract32(insn
, 22, 2);
7058 int opcode
= extract32(insn
, 12, 5);
7059 int rn
= extract32(insn
, 5, 5);
7060 int rd
= extract32(insn
, 0, 5);
7063 /* For some ops (the FP ones), size[1] is part of the encoding.
7064 * For ADDP strictly it is not but size[1] is always 1 for valid
7067 opcode
|= (extract32(size
, 1, 1) << 5);
7070 case 0x3b: /* ADDP */
7071 if (u
|| size
!= 3) {
7072 unallocated_encoding(s
);
7075 if (!fp_access_check(s
)) {
7081 case 0xc: /* FMAXNMP */
7082 case 0xd: /* FADDP */
7083 case 0xf: /* FMAXP */
7084 case 0x2c: /* FMINNMP */
7085 case 0x2f: /* FMINP */
7086 /* FP op, size[0] is 32 or 64 bit*/
7088 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
7089 unallocated_encoding(s
);
7095 size
= extract32(size
, 0, 1) ? MO_64
: MO_32
;
7098 if (!fp_access_check(s
)) {
7102 fpst
= get_fpstatus_ptr(size
== MO_16
);
7105 unallocated_encoding(s
);
7109 if (size
== MO_64
) {
7110 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7111 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7112 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7114 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
7115 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
7118 case 0x3b: /* ADDP */
7119 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
7121 case 0xc: /* FMAXNMP */
7122 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7124 case 0xd: /* FADDP */
7125 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7127 case 0xf: /* FMAXP */
7128 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7130 case 0x2c: /* FMINNMP */
7131 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7133 case 0x2f: /* FMINP */
7134 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7137 g_assert_not_reached();
7140 write_fp_dreg(s
, rd
, tcg_res
);
7142 tcg_temp_free_i64(tcg_op1
);
7143 tcg_temp_free_i64(tcg_op2
);
7144 tcg_temp_free_i64(tcg_res
);
7146 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7147 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7148 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7150 read_vec_element_i32(s
, tcg_op1
, rn
, 0, size
);
7151 read_vec_element_i32(s
, tcg_op2
, rn
, 1, size
);
7153 if (size
== MO_16
) {
7155 case 0xc: /* FMAXNMP */
7156 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7158 case 0xd: /* FADDP */
7159 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7161 case 0xf: /* FMAXP */
7162 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7164 case 0x2c: /* FMINNMP */
7165 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7167 case 0x2f: /* FMINP */
7168 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7171 g_assert_not_reached();
7175 case 0xc: /* FMAXNMP */
7176 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7178 case 0xd: /* FADDP */
7179 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7181 case 0xf: /* FMAXP */
7182 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7184 case 0x2c: /* FMINNMP */
7185 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7187 case 0x2f: /* FMINP */
7188 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7191 g_assert_not_reached();
7195 write_fp_sreg(s
, rd
, tcg_res
);
7197 tcg_temp_free_i32(tcg_op1
);
7198 tcg_temp_free_i32(tcg_op2
);
7199 tcg_temp_free_i32(tcg_res
);
7203 tcg_temp_free_ptr(fpst
);
7208 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
7210 * This code is handles the common shifting code and is used by both
7211 * the vector and scalar code.
7213 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
7214 TCGv_i64 tcg_rnd
, bool accumulate
,
7215 bool is_u
, int size
, int shift
)
7217 bool extended_result
= false;
7218 bool round
= tcg_rnd
!= NULL
;
7220 TCGv_i64 tcg_src_hi
;
7222 if (round
&& size
== 3) {
7223 extended_result
= true;
7224 ext_lshift
= 64 - shift
;
7225 tcg_src_hi
= tcg_temp_new_i64();
7226 } else if (shift
== 64) {
7227 if (!accumulate
&& is_u
) {
7228 /* result is zero */
7229 tcg_gen_movi_i64(tcg_res
, 0);
7234 /* Deal with the rounding step */
7236 if (extended_result
) {
7237 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7239 /* take care of sign extending tcg_res */
7240 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
7241 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7242 tcg_src
, tcg_src_hi
,
7245 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
7249 tcg_temp_free_i64(tcg_zero
);
7251 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
7255 /* Now do the shift right */
7256 if (round
&& extended_result
) {
7257 /* extended case, >64 bit precision required */
7258 if (ext_lshift
== 0) {
7259 /* special case, only high bits matter */
7260 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
7262 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7263 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
7264 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
7269 /* essentially shifting in 64 zeros */
7270 tcg_gen_movi_i64(tcg_src
, 0);
7272 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
7276 /* effectively extending the sign-bit */
7277 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
7279 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
7285 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
7287 tcg_gen_mov_i64(tcg_res
, tcg_src
);
7290 if (extended_result
) {
7291 tcg_temp_free_i64(tcg_src_hi
);
7295 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
7296 static void handle_scalar_simd_shri(DisasContext
*s
,
7297 bool is_u
, int immh
, int immb
,
7298 int opcode
, int rn
, int rd
)
7301 int immhb
= immh
<< 3 | immb
;
7302 int shift
= 2 * (8 << size
) - immhb
;
7303 bool accumulate
= false;
7305 bool insert
= false;
7310 if (!extract32(immh
, 3, 1)) {
7311 unallocated_encoding(s
);
7315 if (!fp_access_check(s
)) {
7320 case 0x02: /* SSRA / USRA (accumulate) */
7323 case 0x04: /* SRSHR / URSHR (rounding) */
7326 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7327 accumulate
= round
= true;
7329 case 0x08: /* SRI */
7335 uint64_t round_const
= 1ULL << (shift
- 1);
7336 tcg_round
= tcg_const_i64(round_const
);
7341 tcg_rn
= read_fp_dreg(s
, rn
);
7342 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
7345 /* shift count same as element size is valid but does nothing;
7346 * special case to avoid potential shift by 64.
7348 int esize
= 8 << size
;
7349 if (shift
!= esize
) {
7350 tcg_gen_shri_i64(tcg_rn
, tcg_rn
, shift
);
7351 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, 0, esize
- shift
);
7354 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
7355 accumulate
, is_u
, size
, shift
);
7358 write_fp_dreg(s
, rd
, tcg_rd
);
7360 tcg_temp_free_i64(tcg_rn
);
7361 tcg_temp_free_i64(tcg_rd
);
7363 tcg_temp_free_i64(tcg_round
);
7367 /* SHL/SLI - Scalar shift left */
7368 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
7369 int immh
, int immb
, int opcode
,
7372 int size
= 32 - clz32(immh
) - 1;
7373 int immhb
= immh
<< 3 | immb
;
7374 int shift
= immhb
- (8 << size
);
7375 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
7376 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
7378 if (!extract32(immh
, 3, 1)) {
7379 unallocated_encoding(s
);
7383 if (!fp_access_check(s
)) {
7387 tcg_rn
= read_fp_dreg(s
, rn
);
7388 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
7391 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, shift
, 64 - shift
);
7393 tcg_gen_shli_i64(tcg_rd
, tcg_rn
, shift
);
7396 write_fp_dreg(s
, rd
, tcg_rd
);
7398 tcg_temp_free_i64(tcg_rn
);
7399 tcg_temp_free_i64(tcg_rd
);
7402 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
7403 * (signed/unsigned) narrowing */
7404 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
7405 bool is_u_shift
, bool is_u_narrow
,
7406 int immh
, int immb
, int opcode
,
7409 int immhb
= immh
<< 3 | immb
;
7410 int size
= 32 - clz32(immh
) - 1;
7411 int esize
= 8 << size
;
7412 int shift
= (2 * esize
) - immhb
;
7413 int elements
= is_scalar
? 1 : (64 / esize
);
7414 bool round
= extract32(opcode
, 0, 1);
7415 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
7416 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
7417 TCGv_i32 tcg_rd_narrowed
;
7420 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
7421 { gen_helper_neon_narrow_sat_s8
,
7422 gen_helper_neon_unarrow_sat8
},
7423 { gen_helper_neon_narrow_sat_s16
,
7424 gen_helper_neon_unarrow_sat16
},
7425 { gen_helper_neon_narrow_sat_s32
,
7426 gen_helper_neon_unarrow_sat32
},
7429 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
7430 gen_helper_neon_narrow_sat_u8
,
7431 gen_helper_neon_narrow_sat_u16
,
7432 gen_helper_neon_narrow_sat_u32
,
7435 NeonGenNarrowEnvFn
*narrowfn
;
7441 if (extract32(immh
, 3, 1)) {
7442 unallocated_encoding(s
);
7446 if (!fp_access_check(s
)) {
7451 narrowfn
= unsigned_narrow_fns
[size
];
7453 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
7456 tcg_rn
= tcg_temp_new_i64();
7457 tcg_rd
= tcg_temp_new_i64();
7458 tcg_rd_narrowed
= tcg_temp_new_i32();
7459 tcg_final
= tcg_const_i64(0);
7462 uint64_t round_const
= 1ULL << (shift
- 1);
7463 tcg_round
= tcg_const_i64(round_const
);
7468 for (i
= 0; i
< elements
; i
++) {
7469 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
7470 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
7471 false, is_u_shift
, size
+1, shift
);
7472 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
7473 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
7474 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
7478 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
7480 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
7484 tcg_temp_free_i64(tcg_round
);
7486 tcg_temp_free_i64(tcg_rn
);
7487 tcg_temp_free_i64(tcg_rd
);
7488 tcg_temp_free_i32(tcg_rd_narrowed
);
7489 tcg_temp_free_i64(tcg_final
);
7491 clear_vec_high(s
, is_q
, rd
);
7494 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
7495 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
7496 bool src_unsigned
, bool dst_unsigned
,
7497 int immh
, int immb
, int rn
, int rd
)
7499 int immhb
= immh
<< 3 | immb
;
7500 int size
= 32 - clz32(immh
) - 1;
7501 int shift
= immhb
- (8 << size
);
7505 assert(!(scalar
&& is_q
));
7508 if (!is_q
&& extract32(immh
, 3, 1)) {
7509 unallocated_encoding(s
);
7513 /* Since we use the variable-shift helpers we must
7514 * replicate the shift count into each element of
7515 * the tcg_shift value.
7519 shift
|= shift
<< 8;
7522 shift
|= shift
<< 16;
7528 g_assert_not_reached();
7532 if (!fp_access_check(s
)) {
7537 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
7538 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
7539 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
7540 { NULL
, gen_helper_neon_qshl_u64
},
7542 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
7543 int maxpass
= is_q
? 2 : 1;
7545 for (pass
= 0; pass
< maxpass
; pass
++) {
7546 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7548 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7549 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
7550 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
7552 tcg_temp_free_i64(tcg_op
);
7554 tcg_temp_free_i64(tcg_shift
);
7555 clear_vec_high(s
, is_q
, rd
);
7557 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
7558 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
7560 { gen_helper_neon_qshl_s8
,
7561 gen_helper_neon_qshl_s16
,
7562 gen_helper_neon_qshl_s32
},
7563 { gen_helper_neon_qshlu_s8
,
7564 gen_helper_neon_qshlu_s16
,
7565 gen_helper_neon_qshlu_s32
}
7567 { NULL
, NULL
, NULL
},
7568 { gen_helper_neon_qshl_u8
,
7569 gen_helper_neon_qshl_u16
,
7570 gen_helper_neon_qshl_u32
}
7573 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
7574 TCGMemOp memop
= scalar
? size
: MO_32
;
7575 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
7577 for (pass
= 0; pass
< maxpass
; pass
++) {
7578 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7580 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
7581 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
7585 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
7588 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
7593 g_assert_not_reached();
7595 write_fp_sreg(s
, rd
, tcg_op
);
7597 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
7600 tcg_temp_free_i32(tcg_op
);
7602 tcg_temp_free_i32(tcg_shift
);
7605 clear_vec_high(s
, is_q
, rd
);
7610 /* Common vector code for handling integer to FP conversion */
7611 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
7612 int elements
, int is_signed
,
7613 int fracbits
, int size
)
7615 TCGv_ptr tcg_fpst
= get_fpstatus_ptr(size
== MO_16
);
7616 TCGv_i32 tcg_shift
= NULL
;
7618 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
7621 if (fracbits
|| size
== MO_64
) {
7622 tcg_shift
= tcg_const_i32(fracbits
);
7625 if (size
== MO_64
) {
7626 TCGv_i64 tcg_int64
= tcg_temp_new_i64();
7627 TCGv_i64 tcg_double
= tcg_temp_new_i64();
7629 for (pass
= 0; pass
< elements
; pass
++) {
7630 read_vec_element(s
, tcg_int64
, rn
, pass
, mop
);
7633 gen_helper_vfp_sqtod(tcg_double
, tcg_int64
,
7634 tcg_shift
, tcg_fpst
);
7636 gen_helper_vfp_uqtod(tcg_double
, tcg_int64
,
7637 tcg_shift
, tcg_fpst
);
7639 if (elements
== 1) {
7640 write_fp_dreg(s
, rd
, tcg_double
);
7642 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
7646 tcg_temp_free_i64(tcg_int64
);
7647 tcg_temp_free_i64(tcg_double
);
7650 TCGv_i32 tcg_int32
= tcg_temp_new_i32();
7651 TCGv_i32 tcg_float
= tcg_temp_new_i32();
7653 for (pass
= 0; pass
< elements
; pass
++) {
7654 read_vec_element_i32(s
, tcg_int32
, rn
, pass
, mop
);
7660 gen_helper_vfp_sltos(tcg_float
, tcg_int32
,
7661 tcg_shift
, tcg_fpst
);
7663 gen_helper_vfp_ultos(tcg_float
, tcg_int32
,
7664 tcg_shift
, tcg_fpst
);
7668 gen_helper_vfp_sitos(tcg_float
, tcg_int32
, tcg_fpst
);
7670 gen_helper_vfp_uitos(tcg_float
, tcg_int32
, tcg_fpst
);
7677 gen_helper_vfp_sltoh(tcg_float
, tcg_int32
,
7678 tcg_shift
, tcg_fpst
);
7680 gen_helper_vfp_ultoh(tcg_float
, tcg_int32
,
7681 tcg_shift
, tcg_fpst
);
7685 gen_helper_vfp_sitoh(tcg_float
, tcg_int32
, tcg_fpst
);
7687 gen_helper_vfp_uitoh(tcg_float
, tcg_int32
, tcg_fpst
);
7692 g_assert_not_reached();
7695 if (elements
== 1) {
7696 write_fp_sreg(s
, rd
, tcg_float
);
7698 write_vec_element_i32(s
, tcg_float
, rd
, pass
, size
);
7702 tcg_temp_free_i32(tcg_int32
);
7703 tcg_temp_free_i32(tcg_float
);
7706 tcg_temp_free_ptr(tcg_fpst
);
7708 tcg_temp_free_i32(tcg_shift
);
7711 clear_vec_high(s
, elements
<< size
== 16, rd
);
7714 /* UCVTF/SCVTF - Integer to FP conversion */
7715 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
7716 bool is_q
, bool is_u
,
7717 int immh
, int immb
, int opcode
,
7720 int size
, elements
, fracbits
;
7721 int immhb
= immh
<< 3 | immb
;
7725 if (!is_scalar
&& !is_q
) {
7726 unallocated_encoding(s
);
7729 } else if (immh
& 4) {
7731 } else if (immh
& 2) {
7733 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
7734 unallocated_encoding(s
);
7738 /* immh == 0 would be a failure of the decode logic */
7739 g_assert(immh
== 1);
7740 unallocated_encoding(s
);
7747 elements
= (8 << is_q
) >> size
;
7749 fracbits
= (16 << size
) - immhb
;
7751 if (!fp_access_check(s
)) {
7755 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
7758 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
7759 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
7760 bool is_q
, bool is_u
,
7761 int immh
, int immb
, int rn
, int rd
)
7763 int immhb
= immh
<< 3 | immb
;
7764 int pass
, size
, fracbits
;
7765 TCGv_ptr tcg_fpstatus
;
7766 TCGv_i32 tcg_rmode
, tcg_shift
;
7770 if (!is_scalar
&& !is_q
) {
7771 unallocated_encoding(s
);
7774 } else if (immh
& 0x4) {
7776 } else if (immh
& 0x2) {
7778 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
7779 unallocated_encoding(s
);
7783 /* Should have split out AdvSIMD modified immediate earlier. */
7785 unallocated_encoding(s
);
7789 if (!fp_access_check(s
)) {
7793 assert(!(is_scalar
&& is_q
));
7795 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
7796 tcg_fpstatus
= get_fpstatus_ptr(size
== MO_16
);
7797 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7798 fracbits
= (16 << size
) - immhb
;
7799 tcg_shift
= tcg_const_i32(fracbits
);
7801 if (size
== MO_64
) {
7802 int maxpass
= is_scalar
? 1 : 2;
7804 for (pass
= 0; pass
< maxpass
; pass
++) {
7805 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7807 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7809 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
7811 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
7813 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
7814 tcg_temp_free_i64(tcg_op
);
7816 clear_vec_high(s
, is_q
, rd
);
7818 void (*fn
)(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
7819 int maxpass
= is_scalar
? 1 : ((8 << is_q
) >> size
);
7824 fn
= gen_helper_vfp_touhh
;
7826 fn
= gen_helper_vfp_toshh
;
7831 fn
= gen_helper_vfp_touls
;
7833 fn
= gen_helper_vfp_tosls
;
7837 g_assert_not_reached();
7840 for (pass
= 0; pass
< maxpass
; pass
++) {
7841 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7843 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
7844 fn(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
7846 write_fp_sreg(s
, rd
, tcg_op
);
7848 write_vec_element_i32(s
, tcg_op
, rd
, pass
, size
);
7850 tcg_temp_free_i32(tcg_op
);
7853 clear_vec_high(s
, is_q
, rd
);
7857 tcg_temp_free_ptr(tcg_fpstatus
);
7858 tcg_temp_free_i32(tcg_shift
);
7859 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
7860 tcg_temp_free_i32(tcg_rmode
);
7863 /* AdvSIMD scalar shift by immediate
7864 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
7865 * +-----+---+-------------+------+------+--------+---+------+------+
7866 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
7867 * +-----+---+-------------+------+------+--------+---+------+------+
7869 * This is the scalar version so it works on a fixed sized registers
7871 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
7873 int rd
= extract32(insn
, 0, 5);
7874 int rn
= extract32(insn
, 5, 5);
7875 int opcode
= extract32(insn
, 11, 5);
7876 int immb
= extract32(insn
, 16, 3);
7877 int immh
= extract32(insn
, 19, 4);
7878 bool is_u
= extract32(insn
, 29, 1);
7881 unallocated_encoding(s
);
7886 case 0x08: /* SRI */
7888 unallocated_encoding(s
);
7892 case 0x00: /* SSHR / USHR */
7893 case 0x02: /* SSRA / USRA */
7894 case 0x04: /* SRSHR / URSHR */
7895 case 0x06: /* SRSRA / URSRA */
7896 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
7898 case 0x0a: /* SHL / SLI */
7899 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
7901 case 0x1c: /* SCVTF, UCVTF */
7902 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
7905 case 0x10: /* SQSHRUN, SQSHRUN2 */
7906 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
7908 unallocated_encoding(s
);
7911 handle_vec_simd_sqshrn(s
, true, false, false, true,
7912 immh
, immb
, opcode
, rn
, rd
);
7914 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
7915 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
7916 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
7917 immh
, immb
, opcode
, rn
, rd
);
7919 case 0xc: /* SQSHLU */
7921 unallocated_encoding(s
);
7924 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
7926 case 0xe: /* SQSHL, UQSHL */
7927 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
7929 case 0x1f: /* FCVTZS, FCVTZU */
7930 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
7933 unallocated_encoding(s
);
7938 /* AdvSIMD scalar three different
7939 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
7940 * +-----+---+-----------+------+---+------+--------+-----+------+------+
7941 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
7942 * +-----+---+-----------+------+---+------+--------+-----+------+------+
7944 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
7946 bool is_u
= extract32(insn
, 29, 1);
7947 int size
= extract32(insn
, 22, 2);
7948 int opcode
= extract32(insn
, 12, 4);
7949 int rm
= extract32(insn
, 16, 5);
7950 int rn
= extract32(insn
, 5, 5);
7951 int rd
= extract32(insn
, 0, 5);
7954 unallocated_encoding(s
);
7959 case 0x9: /* SQDMLAL, SQDMLAL2 */
7960 case 0xb: /* SQDMLSL, SQDMLSL2 */
7961 case 0xd: /* SQDMULL, SQDMULL2 */
7962 if (size
== 0 || size
== 3) {
7963 unallocated_encoding(s
);
7968 unallocated_encoding(s
);
7972 if (!fp_access_check(s
)) {
7977 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7978 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7979 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7981 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
7982 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
7984 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
7985 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
7988 case 0xd: /* SQDMULL, SQDMULL2 */
7990 case 0xb: /* SQDMLSL, SQDMLSL2 */
7991 tcg_gen_neg_i64(tcg_res
, tcg_res
);
7993 case 0x9: /* SQDMLAL, SQDMLAL2 */
7994 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
7995 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
7999 g_assert_not_reached();
8002 write_fp_dreg(s
, rd
, tcg_res
);
8004 tcg_temp_free_i64(tcg_op1
);
8005 tcg_temp_free_i64(tcg_op2
);
8006 tcg_temp_free_i64(tcg_res
);
8008 TCGv_i32 tcg_op1
= read_fp_hreg(s
, rn
);
8009 TCGv_i32 tcg_op2
= read_fp_hreg(s
, rm
);
8010 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8012 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
8013 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
8016 case 0xd: /* SQDMULL, SQDMULL2 */
8018 case 0xb: /* SQDMLSL, SQDMLSL2 */
8019 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
8021 case 0x9: /* SQDMLAL, SQDMLAL2 */
8023 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
8024 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
8025 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
8027 tcg_temp_free_i64(tcg_op3
);
8031 g_assert_not_reached();
8034 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
8035 write_fp_dreg(s
, rd
, tcg_res
);
8037 tcg_temp_free_i32(tcg_op1
);
8038 tcg_temp_free_i32(tcg_op2
);
8039 tcg_temp_free_i64(tcg_res
);
8043 /* CMTST : test is "if (X & Y != 0)". */
8044 static void gen_cmtst_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
8046 tcg_gen_and_i32(d
, a
, b
);
8047 tcg_gen_setcondi_i32(TCG_COND_NE
, d
, d
, 0);
8048 tcg_gen_neg_i32(d
, d
);
8051 static void gen_cmtst_i64(TCGv_i64 d
, TCGv_i64 a
, TCGv_i64 b
)
8053 tcg_gen_and_i64(d
, a
, b
);
8054 tcg_gen_setcondi_i64(TCG_COND_NE
, d
, d
, 0);
8055 tcg_gen_neg_i64(d
, d
);
8058 static void gen_cmtst_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, TCGv_vec b
)
8060 tcg_gen_and_vec(vece
, d
, a
, b
);
8061 tcg_gen_dupi_vec(vece
, a
, 0);
8062 tcg_gen_cmp_vec(TCG_COND_NE
, vece
, d
, d
, a
);
8065 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
8066 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
8068 /* Handle 64x64->64 opcodes which are shared between the scalar
8069 * and vector 3-same groups. We cover every opcode where size == 3
8070 * is valid in either the three-reg-same (integer, not pairwise)
8071 * or scalar-three-reg-same groups.
8076 case 0x1: /* SQADD */
8078 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8080 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8083 case 0x5: /* SQSUB */
8085 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8087 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8090 case 0x6: /* CMGT, CMHI */
8091 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
8092 * We implement this using setcond (test) and then negating.
8094 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
8096 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
8097 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
8099 case 0x7: /* CMGE, CMHS */
8100 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
8102 case 0x11: /* CMTST, CMEQ */
8107 gen_cmtst_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8109 case 0x8: /* SSHL, USHL */
8111 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8113 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8116 case 0x9: /* SQSHL, UQSHL */
8118 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8120 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8123 case 0xa: /* SRSHL, URSHL */
8125 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
8127 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
8130 case 0xb: /* SQRSHL, UQRSHL */
8132 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8134 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
8137 case 0x10: /* ADD, SUB */
8139 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8141 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
8145 g_assert_not_reached();
8149 /* Handle the 3-same-operands float operations; shared by the scalar
8150 * and vector encodings. The caller must filter out any encodings
8151 * not allocated for the encoding it is dealing with.
8153 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
8154 int fpopcode
, int rd
, int rn
, int rm
)
8157 TCGv_ptr fpst
= get_fpstatus_ptr(false);
8159 for (pass
= 0; pass
< elements
; pass
++) {
8162 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8163 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8164 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8166 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8167 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8170 case 0x39: /* FMLS */
8171 /* As usual for ARM, separate negation for fused multiply-add */
8172 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
8174 case 0x19: /* FMLA */
8175 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8176 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
8179 case 0x18: /* FMAXNM */
8180 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8182 case 0x1a: /* FADD */
8183 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8185 case 0x1b: /* FMULX */
8186 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8188 case 0x1c: /* FCMEQ */
8189 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8191 case 0x1e: /* FMAX */
8192 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8194 case 0x1f: /* FRECPS */
8195 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8197 case 0x38: /* FMINNM */
8198 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8200 case 0x3a: /* FSUB */
8201 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8203 case 0x3e: /* FMIN */
8204 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8206 case 0x3f: /* FRSQRTS */
8207 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8209 case 0x5b: /* FMUL */
8210 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8212 case 0x5c: /* FCMGE */
8213 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8215 case 0x5d: /* FACGE */
8216 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8218 case 0x5f: /* FDIV */
8219 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8221 case 0x7a: /* FABD */
8222 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8223 gen_helper_vfp_absd(tcg_res
, tcg_res
);
8225 case 0x7c: /* FCMGT */
8226 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8228 case 0x7d: /* FACGT */
8229 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8232 g_assert_not_reached();
8235 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8237 tcg_temp_free_i64(tcg_res
);
8238 tcg_temp_free_i64(tcg_op1
);
8239 tcg_temp_free_i64(tcg_op2
);
8242 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8243 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8244 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8246 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
8247 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
8250 case 0x39: /* FMLS */
8251 /* As usual for ARM, separate negation for fused multiply-add */
8252 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
8254 case 0x19: /* FMLA */
8255 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8256 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
8259 case 0x1a: /* FADD */
8260 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8262 case 0x1b: /* FMULX */
8263 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8265 case 0x1c: /* FCMEQ */
8266 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8268 case 0x1e: /* FMAX */
8269 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8271 case 0x1f: /* FRECPS */
8272 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8274 case 0x18: /* FMAXNM */
8275 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8277 case 0x38: /* FMINNM */
8278 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8280 case 0x3a: /* FSUB */
8281 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8283 case 0x3e: /* FMIN */
8284 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8286 case 0x3f: /* FRSQRTS */
8287 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8289 case 0x5b: /* FMUL */
8290 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8292 case 0x5c: /* FCMGE */
8293 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8295 case 0x5d: /* FACGE */
8296 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8298 case 0x5f: /* FDIV */
8299 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8301 case 0x7a: /* FABD */
8302 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8303 gen_helper_vfp_abss(tcg_res
, tcg_res
);
8305 case 0x7c: /* FCMGT */
8306 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8308 case 0x7d: /* FACGT */
8309 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8312 g_assert_not_reached();
8315 if (elements
== 1) {
8316 /* scalar single so clear high part */
8317 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
8319 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
8320 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
8321 tcg_temp_free_i64(tcg_tmp
);
8323 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8326 tcg_temp_free_i32(tcg_res
);
8327 tcg_temp_free_i32(tcg_op1
);
8328 tcg_temp_free_i32(tcg_op2
);
8332 tcg_temp_free_ptr(fpst
);
8334 clear_vec_high(s
, elements
* (size
? 8 : 4) > 8, rd
);
8337 /* AdvSIMD scalar three same
8338 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
8339 * +-----+---+-----------+------+---+------+--------+---+------+------+
8340 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
8341 * +-----+---+-----------+------+---+------+--------+---+------+------+
8343 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
8345 int rd
= extract32(insn
, 0, 5);
8346 int rn
= extract32(insn
, 5, 5);
8347 int opcode
= extract32(insn
, 11, 5);
8348 int rm
= extract32(insn
, 16, 5);
8349 int size
= extract32(insn
, 22, 2);
8350 bool u
= extract32(insn
, 29, 1);
8353 if (opcode
>= 0x18) {
8354 /* Floating point: U, size[1] and opcode indicate operation */
8355 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
8357 case 0x1b: /* FMULX */
8358 case 0x1f: /* FRECPS */
8359 case 0x3f: /* FRSQRTS */
8360 case 0x5d: /* FACGE */
8361 case 0x7d: /* FACGT */
8362 case 0x1c: /* FCMEQ */
8363 case 0x5c: /* FCMGE */
8364 case 0x7c: /* FCMGT */
8365 case 0x7a: /* FABD */
8368 unallocated_encoding(s
);
8372 if (!fp_access_check(s
)) {
8376 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
8381 case 0x1: /* SQADD, UQADD */
8382 case 0x5: /* SQSUB, UQSUB */
8383 case 0x9: /* SQSHL, UQSHL */
8384 case 0xb: /* SQRSHL, UQRSHL */
8386 case 0x8: /* SSHL, USHL */
8387 case 0xa: /* SRSHL, URSHL */
8388 case 0x6: /* CMGT, CMHI */
8389 case 0x7: /* CMGE, CMHS */
8390 case 0x11: /* CMTST, CMEQ */
8391 case 0x10: /* ADD, SUB (vector) */
8393 unallocated_encoding(s
);
8397 case 0x16: /* SQDMULH, SQRDMULH (vector) */
8398 if (size
!= 1 && size
!= 2) {
8399 unallocated_encoding(s
);
8404 unallocated_encoding(s
);
8408 if (!fp_access_check(s
)) {
8412 tcg_rd
= tcg_temp_new_i64();
8415 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
8416 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
8418 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
8419 tcg_temp_free_i64(tcg_rn
);
8420 tcg_temp_free_i64(tcg_rm
);
8422 /* Do a single operation on the lowest element in the vector.
8423 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
8424 * no side effects for all these operations.
8425 * OPTME: special-purpose helpers would avoid doing some
8426 * unnecessary work in the helper for the 8 and 16 bit cases.
8428 NeonGenTwoOpEnvFn
*genenvfn
;
8429 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
8430 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
8431 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
8433 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
8434 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
8437 case 0x1: /* SQADD, UQADD */
8439 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8440 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
8441 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
8442 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
8444 genenvfn
= fns
[size
][u
];
8447 case 0x5: /* SQSUB, UQSUB */
8449 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8450 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
8451 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
8452 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
8454 genenvfn
= fns
[size
][u
];
8457 case 0x9: /* SQSHL, UQSHL */
8459 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8460 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
8461 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
8462 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
8464 genenvfn
= fns
[size
][u
];
8467 case 0xb: /* SQRSHL, UQRSHL */
8469 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
8470 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
8471 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
8472 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
8474 genenvfn
= fns
[size
][u
];
8477 case 0x16: /* SQDMULH, SQRDMULH */
8479 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
8480 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
8481 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
8483 assert(size
== 1 || size
== 2);
8484 genenvfn
= fns
[size
- 1][u
];
8488 g_assert_not_reached();
8491 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
8492 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
8493 tcg_temp_free_i32(tcg_rd32
);
8494 tcg_temp_free_i32(tcg_rn
);
8495 tcg_temp_free_i32(tcg_rm
);
8498 write_fp_dreg(s
, rd
, tcg_rd
);
8500 tcg_temp_free_i64(tcg_rd
);
8503 /* AdvSIMD scalar three same FP16
8504 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
8505 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8506 * | 0 1 | U | 1 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
8507 * +-----+---+-----------+---+-----+------+-----+--------+---+----+----+
8508 * v: 0101 1110 0100 0000 0000 0100 0000 0000 => 5e400400
8509 * m: 1101 1111 0110 0000 1100 0100 0000 0000 => df60c400
8511 static void disas_simd_scalar_three_reg_same_fp16(DisasContext
*s
,
8514 int rd
= extract32(insn
, 0, 5);
8515 int rn
= extract32(insn
, 5, 5);
8516 int opcode
= extract32(insn
, 11, 3);
8517 int rm
= extract32(insn
, 16, 5);
8518 bool u
= extract32(insn
, 29, 1);
8519 bool a
= extract32(insn
, 23, 1);
8520 int fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
8527 case 0x03: /* FMULX */
8528 case 0x04: /* FCMEQ (reg) */
8529 case 0x07: /* FRECPS */
8530 case 0x0f: /* FRSQRTS */
8531 case 0x14: /* FCMGE (reg) */
8532 case 0x15: /* FACGE */
8533 case 0x1a: /* FABD */
8534 case 0x1c: /* FCMGT (reg) */
8535 case 0x1d: /* FACGT */
8538 unallocated_encoding(s
);
8542 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
8543 unallocated_encoding(s
);
8546 if (!fp_access_check(s
)) {
8550 fpst
= get_fpstatus_ptr(true);
8552 tcg_op1
= read_fp_hreg(s
, rn
);
8553 tcg_op2
= read_fp_hreg(s
, rm
);
8554 tcg_res
= tcg_temp_new_i32();
8557 case 0x03: /* FMULX */
8558 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8560 case 0x04: /* FCMEQ (reg) */
8561 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8563 case 0x07: /* FRECPS */
8564 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8566 case 0x0f: /* FRSQRTS */
8567 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8569 case 0x14: /* FCMGE (reg) */
8570 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8572 case 0x15: /* FACGE */
8573 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8575 case 0x1a: /* FABD */
8576 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8577 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
8579 case 0x1c: /* FCMGT (reg) */
8580 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8582 case 0x1d: /* FACGT */
8583 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
8586 g_assert_not_reached();
8589 write_fp_sreg(s
, rd
, tcg_res
);
8592 tcg_temp_free_i32(tcg_res
);
8593 tcg_temp_free_i32(tcg_op1
);
8594 tcg_temp_free_i32(tcg_op2
);
8595 tcg_temp_free_ptr(fpst
);
8598 /* AdvSIMD scalar three same extra
8599 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
8600 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
8601 * | 0 1 | U | 1 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
8602 * +-----+---+-----------+------+---+------+---+--------+---+----+----+
8604 static void disas_simd_scalar_three_reg_same_extra(DisasContext
*s
,
8607 int rd
= extract32(insn
, 0, 5);
8608 int rn
= extract32(insn
, 5, 5);
8609 int opcode
= extract32(insn
, 11, 4);
8610 int rm
= extract32(insn
, 16, 5);
8611 int size
= extract32(insn
, 22, 2);
8612 bool u
= extract32(insn
, 29, 1);
8613 TCGv_i32 ele1
, ele2
, ele3
;
8617 switch (u
* 16 + opcode
) {
8618 case 0x10: /* SQRDMLAH (vector) */
8619 case 0x11: /* SQRDMLSH (vector) */
8620 if (size
!= 1 && size
!= 2) {
8621 unallocated_encoding(s
);
8624 feature
= ARM_FEATURE_V8_RDM
;
8627 unallocated_encoding(s
);
8630 if (!arm_dc_feature(s
, feature
)) {
8631 unallocated_encoding(s
);
8634 if (!fp_access_check(s
)) {
8638 /* Do a single operation on the lowest element in the vector.
8639 * We use the standard Neon helpers and rely on 0 OP 0 == 0
8640 * with no side effects for all these operations.
8641 * OPTME: special-purpose helpers would avoid doing some
8642 * unnecessary work in the helper for the 16 bit cases.
8644 ele1
= tcg_temp_new_i32();
8645 ele2
= tcg_temp_new_i32();
8646 ele3
= tcg_temp_new_i32();
8648 read_vec_element_i32(s
, ele1
, rn
, 0, size
);
8649 read_vec_element_i32(s
, ele2
, rm
, 0, size
);
8650 read_vec_element_i32(s
, ele3
, rd
, 0, size
);
8653 case 0x0: /* SQRDMLAH */
8655 gen_helper_neon_qrdmlah_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8657 gen_helper_neon_qrdmlah_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8660 case 0x1: /* SQRDMLSH */
8662 gen_helper_neon_qrdmlsh_s16(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8664 gen_helper_neon_qrdmlsh_s32(ele3
, cpu_env
, ele1
, ele2
, ele3
);
8668 g_assert_not_reached();
8670 tcg_temp_free_i32(ele1
);
8671 tcg_temp_free_i32(ele2
);
8673 res
= tcg_temp_new_i64();
8674 tcg_gen_extu_i32_i64(res
, ele3
);
8675 tcg_temp_free_i32(ele3
);
8677 write_fp_dreg(s
, rd
, res
);
8678 tcg_temp_free_i64(res
);
8681 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
8682 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
8683 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
8685 /* Handle 64->64 opcodes which are shared between the scalar and
8686 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
8687 * is valid in either group and also the double-precision fp ops.
8688 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
8694 case 0x4: /* CLS, CLZ */
8696 tcg_gen_clzi_i64(tcg_rd
, tcg_rn
, 64);
8698 tcg_gen_clrsb_i64(tcg_rd
, tcg_rn
);
8702 /* This opcode is shared with CNT and RBIT but we have earlier
8703 * enforced that size == 3 if and only if this is the NOT insn.
8705 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
8707 case 0x7: /* SQABS, SQNEG */
8709 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
8711 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
8714 case 0xa: /* CMLT */
8715 /* 64 bit integer comparison against zero, result is
8716 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
8721 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
8722 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
8724 case 0x8: /* CMGT, CMGE */
8725 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
8727 case 0x9: /* CMEQ, CMLE */
8728 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
8730 case 0xb: /* ABS, NEG */
8732 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
8734 TCGv_i64 tcg_zero
= tcg_const_i64(0);
8735 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
8736 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
8738 tcg_temp_free_i64(tcg_zero
);
8741 case 0x2f: /* FABS */
8742 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
8744 case 0x6f: /* FNEG */
8745 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
8747 case 0x7f: /* FSQRT */
8748 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
8750 case 0x1a: /* FCVTNS */
8751 case 0x1b: /* FCVTMS */
8752 case 0x1c: /* FCVTAS */
8753 case 0x3a: /* FCVTPS */
8754 case 0x3b: /* FCVTZS */
8756 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8757 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8758 tcg_temp_free_i32(tcg_shift
);
8761 case 0x5a: /* FCVTNU */
8762 case 0x5b: /* FCVTMU */
8763 case 0x5c: /* FCVTAU */
8764 case 0x7a: /* FCVTPU */
8765 case 0x7b: /* FCVTZU */
8767 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8768 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8769 tcg_temp_free_i32(tcg_shift
);
8772 case 0x18: /* FRINTN */
8773 case 0x19: /* FRINTM */
8774 case 0x38: /* FRINTP */
8775 case 0x39: /* FRINTZ */
8776 case 0x58: /* FRINTA */
8777 case 0x79: /* FRINTI */
8778 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
8780 case 0x59: /* FRINTX */
8781 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
8784 g_assert_not_reached();
8788 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
8789 bool is_scalar
, bool is_u
, bool is_q
,
8790 int size
, int rn
, int rd
)
8792 bool is_double
= (size
== MO_64
);
8795 if (!fp_access_check(s
)) {
8799 fpst
= get_fpstatus_ptr(size
== MO_16
);
8802 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8803 TCGv_i64 tcg_zero
= tcg_const_i64(0);
8804 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8805 NeonGenTwoDoubleOPFn
*genfn
;
8810 case 0x2e: /* FCMLT (zero) */
8813 case 0x2c: /* FCMGT (zero) */
8814 genfn
= gen_helper_neon_cgt_f64
;
8816 case 0x2d: /* FCMEQ (zero) */
8817 genfn
= gen_helper_neon_ceq_f64
;
8819 case 0x6d: /* FCMLE (zero) */
8822 case 0x6c: /* FCMGE (zero) */
8823 genfn
= gen_helper_neon_cge_f64
;
8826 g_assert_not_reached();
8829 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
8830 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8832 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
8834 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
8836 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8838 tcg_temp_free_i64(tcg_res
);
8839 tcg_temp_free_i64(tcg_zero
);
8840 tcg_temp_free_i64(tcg_op
);
8842 clear_vec_high(s
, !is_scalar
, rd
);
8844 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8845 TCGv_i32 tcg_zero
= tcg_const_i32(0);
8846 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8847 NeonGenTwoSingleOPFn
*genfn
;
8849 int pass
, maxpasses
;
8851 if (size
== MO_16
) {
8853 case 0x2e: /* FCMLT (zero) */
8856 case 0x2c: /* FCMGT (zero) */
8857 genfn
= gen_helper_advsimd_cgt_f16
;
8859 case 0x2d: /* FCMEQ (zero) */
8860 genfn
= gen_helper_advsimd_ceq_f16
;
8862 case 0x6d: /* FCMLE (zero) */
8865 case 0x6c: /* FCMGE (zero) */
8866 genfn
= gen_helper_advsimd_cge_f16
;
8869 g_assert_not_reached();
8873 case 0x2e: /* FCMLT (zero) */
8876 case 0x2c: /* FCMGT (zero) */
8877 genfn
= gen_helper_neon_cgt_f32
;
8879 case 0x2d: /* FCMEQ (zero) */
8880 genfn
= gen_helper_neon_ceq_f32
;
8882 case 0x6d: /* FCMLE (zero) */
8885 case 0x6c: /* FCMGE (zero) */
8886 genfn
= gen_helper_neon_cge_f32
;
8889 g_assert_not_reached();
8896 int vector_size
= 8 << is_q
;
8897 maxpasses
= vector_size
>> size
;
8900 for (pass
= 0; pass
< maxpasses
; pass
++) {
8901 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
8903 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
8905 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
8908 write_fp_sreg(s
, rd
, tcg_res
);
8910 write_vec_element_i32(s
, tcg_res
, rd
, pass
, size
);
8913 tcg_temp_free_i32(tcg_res
);
8914 tcg_temp_free_i32(tcg_zero
);
8915 tcg_temp_free_i32(tcg_op
);
8917 clear_vec_high(s
, is_q
, rd
);
8921 tcg_temp_free_ptr(fpst
);
8924 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
8925 bool is_scalar
, bool is_u
, bool is_q
,
8926 int size
, int rn
, int rd
)
8928 bool is_double
= (size
== 3);
8929 TCGv_ptr fpst
= get_fpstatus_ptr(false);
8932 TCGv_i64 tcg_op
= tcg_temp_new_i64();
8933 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8936 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
8937 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
8939 case 0x3d: /* FRECPE */
8940 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
8942 case 0x3f: /* FRECPX */
8943 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
8945 case 0x7d: /* FRSQRTE */
8946 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
8949 g_assert_not_reached();
8951 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
8953 tcg_temp_free_i64(tcg_res
);
8954 tcg_temp_free_i64(tcg_op
);
8955 clear_vec_high(s
, !is_scalar
, rd
);
8957 TCGv_i32 tcg_op
= tcg_temp_new_i32();
8958 TCGv_i32 tcg_res
= tcg_temp_new_i32();
8959 int pass
, maxpasses
;
8964 maxpasses
= is_q
? 4 : 2;
8967 for (pass
= 0; pass
< maxpasses
; pass
++) {
8968 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
8971 case 0x3c: /* URECPE */
8972 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
8974 case 0x3d: /* FRECPE */
8975 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
8977 case 0x3f: /* FRECPX */
8978 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
8980 case 0x7d: /* FRSQRTE */
8981 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
8984 g_assert_not_reached();
8988 write_fp_sreg(s
, rd
, tcg_res
);
8990 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
8993 tcg_temp_free_i32(tcg_res
);
8994 tcg_temp_free_i32(tcg_op
);
8996 clear_vec_high(s
, is_q
, rd
);
8999 tcg_temp_free_ptr(fpst
);
9002 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
9003 int opcode
, bool u
, bool is_q
,
9004 int size
, int rn
, int rd
)
9006 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
9007 * in the source becomes a size element in the destination).
9010 TCGv_i32 tcg_res
[2];
9011 int destelt
= is_q
? 2 : 0;
9012 int passes
= scalar
? 1 : 2;
9015 tcg_res
[1] = tcg_const_i32(0);
9018 for (pass
= 0; pass
< passes
; pass
++) {
9019 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9020 NeonGenNarrowFn
*genfn
= NULL
;
9021 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
9024 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
9026 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9028 tcg_res
[pass
] = tcg_temp_new_i32();
9031 case 0x12: /* XTN, SQXTUN */
9033 static NeonGenNarrowFn
* const xtnfns
[3] = {
9034 gen_helper_neon_narrow_u8
,
9035 gen_helper_neon_narrow_u16
,
9036 tcg_gen_extrl_i64_i32
,
9038 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
9039 gen_helper_neon_unarrow_sat8
,
9040 gen_helper_neon_unarrow_sat16
,
9041 gen_helper_neon_unarrow_sat32
,
9044 genenvfn
= sqxtunfns
[size
];
9046 genfn
= xtnfns
[size
];
9050 case 0x14: /* SQXTN, UQXTN */
9052 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
9053 { gen_helper_neon_narrow_sat_s8
,
9054 gen_helper_neon_narrow_sat_u8
},
9055 { gen_helper_neon_narrow_sat_s16
,
9056 gen_helper_neon_narrow_sat_u16
},
9057 { gen_helper_neon_narrow_sat_s32
,
9058 gen_helper_neon_narrow_sat_u32
},
9060 genenvfn
= fns
[size
][u
];
9063 case 0x16: /* FCVTN, FCVTN2 */
9064 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
9066 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
9068 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
9069 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
9070 TCGv_ptr fpst
= get_fpstatus_ptr(false);
9071 TCGv_i32 ahp
= get_ahp_flag();
9073 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
9074 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, fpst
, ahp
);
9075 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, fpst
, ahp
);
9076 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
9077 tcg_temp_free_i32(tcg_lo
);
9078 tcg_temp_free_i32(tcg_hi
);
9079 tcg_temp_free_ptr(fpst
);
9080 tcg_temp_free_i32(ahp
);
9083 case 0x56: /* FCVTXN, FCVTXN2 */
9084 /* 64 bit to 32 bit float conversion
9085 * with von Neumann rounding (round to odd)
9088 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
9091 g_assert_not_reached();
9095 genfn(tcg_res
[pass
], tcg_op
);
9096 } else if (genenvfn
) {
9097 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
9100 tcg_temp_free_i64(tcg_op
);
9103 for (pass
= 0; pass
< 2; pass
++) {
9104 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
9105 tcg_temp_free_i32(tcg_res
[pass
]);
9107 clear_vec_high(s
, is_q
, rd
);
9110 /* Remaining saturating accumulating ops */
9111 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
9112 bool is_q
, int size
, int rn
, int rd
)
9114 bool is_double
= (size
== 3);
9117 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9118 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9121 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
9122 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
9123 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9125 if (is_u
) { /* USQADD */
9126 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9127 } else { /* SUQADD */
9128 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9130 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
9132 tcg_temp_free_i64(tcg_rd
);
9133 tcg_temp_free_i64(tcg_rn
);
9134 clear_vec_high(s
, !is_scalar
, rd
);
9136 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9137 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9138 int pass
, maxpasses
;
9143 maxpasses
= is_q
? 4 : 2;
9146 for (pass
= 0; pass
< maxpasses
; pass
++) {
9148 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
9149 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
9151 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
9152 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9155 if (is_u
) { /* USQADD */
9158 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9161 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9164 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9167 g_assert_not_reached();
9169 } else { /* SUQADD */
9172 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9175 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9178 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
9181 g_assert_not_reached();
9186 TCGv_i64 tcg_zero
= tcg_const_i64(0);
9187 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
9188 tcg_temp_free_i64(tcg_zero
);
9190 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
9192 tcg_temp_free_i32(tcg_rd
);
9193 tcg_temp_free_i32(tcg_rn
);
9194 clear_vec_high(s
, is_q
, rd
);
9198 /* AdvSIMD scalar two reg misc
9199 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9200 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9201 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9202 * +-----+---+-----------+------+-----------+--------+-----+------+------+
9204 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9206 int rd
= extract32(insn
, 0, 5);
9207 int rn
= extract32(insn
, 5, 5);
9208 int opcode
= extract32(insn
, 12, 5);
9209 int size
= extract32(insn
, 22, 2);
9210 bool u
= extract32(insn
, 29, 1);
9211 bool is_fcvt
= false;
9214 TCGv_ptr tcg_fpstatus
;
9217 case 0x3: /* USQADD / SUQADD*/
9218 if (!fp_access_check(s
)) {
9221 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
9223 case 0x7: /* SQABS / SQNEG */
9225 case 0xa: /* CMLT */
9227 unallocated_encoding(s
);
9231 case 0x8: /* CMGT, CMGE */
9232 case 0x9: /* CMEQ, CMLE */
9233 case 0xb: /* ABS, NEG */
9235 unallocated_encoding(s
);
9239 case 0x12: /* SQXTUN */
9241 unallocated_encoding(s
);
9245 case 0x14: /* SQXTN, UQXTN */
9247 unallocated_encoding(s
);
9250 if (!fp_access_check(s
)) {
9253 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
9258 /* Floating point: U, size[1] and opcode indicate operation;
9259 * size[0] indicates single or double precision.
9261 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9262 size
= extract32(size
, 0, 1) ? 3 : 2;
9264 case 0x2c: /* FCMGT (zero) */
9265 case 0x2d: /* FCMEQ (zero) */
9266 case 0x2e: /* FCMLT (zero) */
9267 case 0x6c: /* FCMGE (zero) */
9268 case 0x6d: /* FCMLE (zero) */
9269 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
9271 case 0x1d: /* SCVTF */
9272 case 0x5d: /* UCVTF */
9274 bool is_signed
= (opcode
== 0x1d);
9275 if (!fp_access_check(s
)) {
9278 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
9281 case 0x3d: /* FRECPE */
9282 case 0x3f: /* FRECPX */
9283 case 0x7d: /* FRSQRTE */
9284 if (!fp_access_check(s
)) {
9287 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
9289 case 0x1a: /* FCVTNS */
9290 case 0x1b: /* FCVTMS */
9291 case 0x3a: /* FCVTPS */
9292 case 0x3b: /* FCVTZS */
9293 case 0x5a: /* FCVTNU */
9294 case 0x5b: /* FCVTMU */
9295 case 0x7a: /* FCVTPU */
9296 case 0x7b: /* FCVTZU */
9298 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9300 case 0x1c: /* FCVTAS */
9301 case 0x5c: /* FCVTAU */
9302 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
9304 rmode
= FPROUNDING_TIEAWAY
;
9306 case 0x56: /* FCVTXN, FCVTXN2 */
9308 unallocated_encoding(s
);
9311 if (!fp_access_check(s
)) {
9314 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
9317 unallocated_encoding(s
);
9322 unallocated_encoding(s
);
9326 if (!fp_access_check(s
)) {
9331 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
9332 tcg_fpstatus
= get_fpstatus_ptr(false);
9333 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9336 tcg_fpstatus
= NULL
;
9340 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
9341 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
9343 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
9344 write_fp_dreg(s
, rd
, tcg_rd
);
9345 tcg_temp_free_i64(tcg_rd
);
9346 tcg_temp_free_i64(tcg_rn
);
9348 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
9349 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
9351 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
9354 case 0x7: /* SQABS, SQNEG */
9356 NeonGenOneOpEnvFn
*genfn
;
9357 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
9358 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
9359 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
9360 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
9362 genfn
= fns
[size
][u
];
9363 genfn(tcg_rd
, cpu_env
, tcg_rn
);
9366 case 0x1a: /* FCVTNS */
9367 case 0x1b: /* FCVTMS */
9368 case 0x1c: /* FCVTAS */
9369 case 0x3a: /* FCVTPS */
9370 case 0x3b: /* FCVTZS */
9372 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9373 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9374 tcg_temp_free_i32(tcg_shift
);
9377 case 0x5a: /* FCVTNU */
9378 case 0x5b: /* FCVTMU */
9379 case 0x5c: /* FCVTAU */
9380 case 0x7a: /* FCVTPU */
9381 case 0x7b: /* FCVTZU */
9383 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9384 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
9385 tcg_temp_free_i32(tcg_shift
);
9389 g_assert_not_reached();
9392 write_fp_sreg(s
, rd
, tcg_rd
);
9393 tcg_temp_free_i32(tcg_rd
);
9394 tcg_temp_free_i32(tcg_rn
);
9398 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
9399 tcg_temp_free_i32(tcg_rmode
);
9400 tcg_temp_free_ptr(tcg_fpstatus
);
9404 static void gen_ssra8_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9406 tcg_gen_vec_sar8i_i64(a
, a
, shift
);
9407 tcg_gen_vec_add8_i64(d
, d
, a
);
9410 static void gen_ssra16_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9412 tcg_gen_vec_sar16i_i64(a
, a
, shift
);
9413 tcg_gen_vec_add16_i64(d
, d
, a
);
9416 static void gen_ssra32_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9418 tcg_gen_sari_i32(a
, a
, shift
);
9419 tcg_gen_add_i32(d
, d
, a
);
9422 static void gen_ssra64_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9424 tcg_gen_sari_i64(a
, a
, shift
);
9425 tcg_gen_add_i64(d
, d
, a
);
9428 static void gen_ssra_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9430 tcg_gen_sari_vec(vece
, a
, a
, sh
);
9431 tcg_gen_add_vec(vece
, d
, d
, a
);
9434 static void gen_usra8_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9436 tcg_gen_vec_shr8i_i64(a
, a
, shift
);
9437 tcg_gen_vec_add8_i64(d
, d
, a
);
9440 static void gen_usra16_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9442 tcg_gen_vec_shr16i_i64(a
, a
, shift
);
9443 tcg_gen_vec_add16_i64(d
, d
, a
);
9446 static void gen_usra32_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9448 tcg_gen_shri_i32(a
, a
, shift
);
9449 tcg_gen_add_i32(d
, d
, a
);
9452 static void gen_usra64_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9454 tcg_gen_shri_i64(a
, a
, shift
);
9455 tcg_gen_add_i64(d
, d
, a
);
9458 static void gen_usra_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9460 tcg_gen_shri_vec(vece
, a
, a
, sh
);
9461 tcg_gen_add_vec(vece
, d
, d
, a
);
9464 static void gen_shr8_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9466 uint64_t mask
= dup_const(MO_8
, 0xff >> shift
);
9467 TCGv_i64 t
= tcg_temp_new_i64();
9469 tcg_gen_shri_i64(t
, a
, shift
);
9470 tcg_gen_andi_i64(t
, t
, mask
);
9471 tcg_gen_andi_i64(d
, d
, ~mask
);
9472 tcg_gen_or_i64(d
, d
, t
);
9473 tcg_temp_free_i64(t
);
9476 static void gen_shr16_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9478 uint64_t mask
= dup_const(MO_16
, 0xffff >> shift
);
9479 TCGv_i64 t
= tcg_temp_new_i64();
9481 tcg_gen_shri_i64(t
, a
, shift
);
9482 tcg_gen_andi_i64(t
, t
, mask
);
9483 tcg_gen_andi_i64(d
, d
, ~mask
);
9484 tcg_gen_or_i64(d
, d
, t
);
9485 tcg_temp_free_i64(t
);
9488 static void gen_shr32_ins_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9490 tcg_gen_shri_i32(a
, a
, shift
);
9491 tcg_gen_deposit_i32(d
, d
, a
, 0, 32 - shift
);
9494 static void gen_shr64_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9496 tcg_gen_shri_i64(a
, a
, shift
);
9497 tcg_gen_deposit_i64(d
, d
, a
, 0, 64 - shift
);
9500 static void gen_shr_ins_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9502 uint64_t mask
= (2ull << ((8 << vece
) - 1)) - 1;
9503 TCGv_vec t
= tcg_temp_new_vec_matching(d
);
9504 TCGv_vec m
= tcg_temp_new_vec_matching(d
);
9506 tcg_gen_dupi_vec(vece
, m
, mask
^ (mask
>> sh
));
9507 tcg_gen_shri_vec(vece
, t
, a
, sh
);
9508 tcg_gen_and_vec(vece
, d
, d
, m
);
9509 tcg_gen_or_vec(vece
, d
, d
, t
);
9511 tcg_temp_free_vec(t
);
9512 tcg_temp_free_vec(m
);
9515 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
9516 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
9517 int immh
, int immb
, int opcode
, int rn
, int rd
)
9519 static const GVecGen2i ssra_op
[4] = {
9520 { .fni8
= gen_ssra8_i64
,
9521 .fniv
= gen_ssra_vec
,
9523 .opc
= INDEX_op_sari_vec
,
9525 { .fni8
= gen_ssra16_i64
,
9526 .fniv
= gen_ssra_vec
,
9528 .opc
= INDEX_op_sari_vec
,
9530 { .fni4
= gen_ssra32_i32
,
9531 .fniv
= gen_ssra_vec
,
9533 .opc
= INDEX_op_sari_vec
,
9535 { .fni8
= gen_ssra64_i64
,
9536 .fniv
= gen_ssra_vec
,
9537 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9539 .opc
= INDEX_op_sari_vec
,
9542 static const GVecGen2i usra_op
[4] = {
9543 { .fni8
= gen_usra8_i64
,
9544 .fniv
= gen_usra_vec
,
9546 .opc
= INDEX_op_shri_vec
,
9548 { .fni8
= gen_usra16_i64
,
9549 .fniv
= gen_usra_vec
,
9551 .opc
= INDEX_op_shri_vec
,
9553 { .fni4
= gen_usra32_i32
,
9554 .fniv
= gen_usra_vec
,
9556 .opc
= INDEX_op_shri_vec
,
9558 { .fni8
= gen_usra64_i64
,
9559 .fniv
= gen_usra_vec
,
9560 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9562 .opc
= INDEX_op_shri_vec
,
9565 static const GVecGen2i sri_op
[4] = {
9566 { .fni8
= gen_shr8_ins_i64
,
9567 .fniv
= gen_shr_ins_vec
,
9569 .opc
= INDEX_op_shri_vec
,
9571 { .fni8
= gen_shr16_ins_i64
,
9572 .fniv
= gen_shr_ins_vec
,
9574 .opc
= INDEX_op_shri_vec
,
9576 { .fni4
= gen_shr32_ins_i32
,
9577 .fniv
= gen_shr_ins_vec
,
9579 .opc
= INDEX_op_shri_vec
,
9581 { .fni8
= gen_shr64_ins_i64
,
9582 .fniv
= gen_shr_ins_vec
,
9583 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9585 .opc
= INDEX_op_shri_vec
,
9589 int size
= 32 - clz32(immh
) - 1;
9590 int immhb
= immh
<< 3 | immb
;
9591 int shift
= 2 * (8 << size
) - immhb
;
9592 bool accumulate
= false;
9593 int dsize
= is_q
? 128 : 64;
9594 int esize
= 8 << size
;
9595 int elements
= dsize
/esize
;
9596 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
9597 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
9598 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
9600 uint64_t round_const
;
9603 if (extract32(immh
, 3, 1) && !is_q
) {
9604 unallocated_encoding(s
);
9607 tcg_debug_assert(size
<= 3);
9609 if (!fp_access_check(s
)) {
9614 case 0x02: /* SSRA / USRA (accumulate) */
9616 /* Shift count same as element size produces zero to add. */
9617 if (shift
== 8 << size
) {
9620 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &usra_op
[size
]);
9622 /* Shift count same as element size produces all sign to add. */
9623 if (shift
== 8 << size
) {
9626 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &ssra_op
[size
]);
9629 case 0x08: /* SRI */
9630 /* Shift count same as element size is valid but does nothing. */
9631 if (shift
== 8 << size
) {
9634 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &sri_op
[size
]);
9637 case 0x00: /* SSHR / USHR */
9639 if (shift
== 8 << size
) {
9640 /* Shift count the same size as element size produces zero. */
9641 tcg_gen_gvec_dup8i(vec_full_reg_offset(s
, rd
),
9642 is_q
? 16 : 8, vec_full_reg_size(s
), 0);
9644 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shri
, size
);
9647 /* Shift count the same size as element size produces all sign. */
9648 if (shift
== 8 << size
) {
9651 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_sari
, size
);
9655 case 0x04: /* SRSHR / URSHR (rounding) */
9657 case 0x06: /* SRSRA / URSRA (accum + rounding) */
9661 g_assert_not_reached();
9664 round_const
= 1ULL << (shift
- 1);
9665 tcg_round
= tcg_const_i64(round_const
);
9667 for (i
= 0; i
< elements
; i
++) {
9668 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
9670 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
9673 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
9674 accumulate
, is_u
, size
, shift
);
9676 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
9678 tcg_temp_free_i64(tcg_round
);
9681 clear_vec_high(s
, is_q
, rd
);
9684 static void gen_shl8_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9686 uint64_t mask
= dup_const(MO_8
, 0xff << shift
);
9687 TCGv_i64 t
= tcg_temp_new_i64();
9689 tcg_gen_shli_i64(t
, a
, shift
);
9690 tcg_gen_andi_i64(t
, t
, mask
);
9691 tcg_gen_andi_i64(d
, d
, ~mask
);
9692 tcg_gen_or_i64(d
, d
, t
);
9693 tcg_temp_free_i64(t
);
9696 static void gen_shl16_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9698 uint64_t mask
= dup_const(MO_16
, 0xffff << shift
);
9699 TCGv_i64 t
= tcg_temp_new_i64();
9701 tcg_gen_shli_i64(t
, a
, shift
);
9702 tcg_gen_andi_i64(t
, t
, mask
);
9703 tcg_gen_andi_i64(d
, d
, ~mask
);
9704 tcg_gen_or_i64(d
, d
, t
);
9705 tcg_temp_free_i64(t
);
9708 static void gen_shl32_ins_i32(TCGv_i32 d
, TCGv_i32 a
, int32_t shift
)
9710 tcg_gen_deposit_i32(d
, d
, a
, shift
, 32 - shift
);
9713 static void gen_shl64_ins_i64(TCGv_i64 d
, TCGv_i64 a
, int64_t shift
)
9715 tcg_gen_deposit_i64(d
, d
, a
, shift
, 64 - shift
);
9718 static void gen_shl_ins_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, int64_t sh
)
9720 uint64_t mask
= (1ull << sh
) - 1;
9721 TCGv_vec t
= tcg_temp_new_vec_matching(d
);
9722 TCGv_vec m
= tcg_temp_new_vec_matching(d
);
9724 tcg_gen_dupi_vec(vece
, m
, mask
);
9725 tcg_gen_shli_vec(vece
, t
, a
, sh
);
9726 tcg_gen_and_vec(vece
, d
, d
, m
);
9727 tcg_gen_or_vec(vece
, d
, d
, t
);
9729 tcg_temp_free_vec(t
);
9730 tcg_temp_free_vec(m
);
9733 /* SHL/SLI - Vector shift left */
9734 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
9735 int immh
, int immb
, int opcode
, int rn
, int rd
)
9737 static const GVecGen2i shi_op
[4] = {
9738 { .fni8
= gen_shl8_ins_i64
,
9739 .fniv
= gen_shl_ins_vec
,
9740 .opc
= INDEX_op_shli_vec
,
9741 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9744 { .fni8
= gen_shl16_ins_i64
,
9745 .fniv
= gen_shl_ins_vec
,
9746 .opc
= INDEX_op_shli_vec
,
9747 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9750 { .fni4
= gen_shl32_ins_i32
,
9751 .fniv
= gen_shl_ins_vec
,
9752 .opc
= INDEX_op_shli_vec
,
9753 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9756 { .fni8
= gen_shl64_ins_i64
,
9757 .fniv
= gen_shl_ins_vec
,
9758 .opc
= INDEX_op_shli_vec
,
9759 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
9763 int size
= 32 - clz32(immh
) - 1;
9764 int immhb
= immh
<< 3 | immb
;
9765 int shift
= immhb
- (8 << size
);
9767 if (extract32(immh
, 3, 1) && !is_q
) {
9768 unallocated_encoding(s
);
9772 if (size
> 3 && !is_q
) {
9773 unallocated_encoding(s
);
9777 if (!fp_access_check(s
)) {
9782 gen_gvec_op2i(s
, is_q
, rd
, rn
, shift
, &shi_op
[size
]);
9784 gen_gvec_fn2i(s
, is_q
, rd
, rn
, shift
, tcg_gen_gvec_shli
, size
);
9788 /* USHLL/SHLL - Vector shift left with widening */
9789 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
9790 int immh
, int immb
, int opcode
, int rn
, int rd
)
9792 int size
= 32 - clz32(immh
) - 1;
9793 int immhb
= immh
<< 3 | immb
;
9794 int shift
= immhb
- (8 << size
);
9796 int esize
= 8 << size
;
9797 int elements
= dsize
/esize
;
9798 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
9799 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
9803 unallocated_encoding(s
);
9807 if (!fp_access_check(s
)) {
9811 /* For the LL variants the store is larger than the load,
9812 * so if rd == rn we would overwrite parts of our input.
9813 * So load everything right now and use shifts in the main loop.
9815 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
9817 for (i
= 0; i
< elements
; i
++) {
9818 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
9819 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
9820 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
9821 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
9825 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
9826 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
9827 int immh
, int immb
, int opcode
, int rn
, int rd
)
9829 int immhb
= immh
<< 3 | immb
;
9830 int size
= 32 - clz32(immh
) - 1;
9832 int esize
= 8 << size
;
9833 int elements
= dsize
/esize
;
9834 int shift
= (2 * esize
) - immhb
;
9835 bool round
= extract32(opcode
, 0, 1);
9836 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
9840 if (extract32(immh
, 3, 1)) {
9841 unallocated_encoding(s
);
9845 if (!fp_access_check(s
)) {
9849 tcg_rn
= tcg_temp_new_i64();
9850 tcg_rd
= tcg_temp_new_i64();
9851 tcg_final
= tcg_temp_new_i64();
9852 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
9855 uint64_t round_const
= 1ULL << (shift
- 1);
9856 tcg_round
= tcg_const_i64(round_const
);
9861 for (i
= 0; i
< elements
; i
++) {
9862 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
9863 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
9864 false, true, size
+1, shift
);
9866 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
9870 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
9872 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
9875 tcg_temp_free_i64(tcg_round
);
9877 tcg_temp_free_i64(tcg_rn
);
9878 tcg_temp_free_i64(tcg_rd
);
9879 tcg_temp_free_i64(tcg_final
);
9881 clear_vec_high(s
, is_q
, rd
);
9885 /* AdvSIMD shift by immediate
9886 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
9887 * +---+---+---+-------------+------+------+--------+---+------+------+
9888 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
9889 * +---+---+---+-------------+------+------+--------+---+------+------+
9891 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
9893 int rd
= extract32(insn
, 0, 5);
9894 int rn
= extract32(insn
, 5, 5);
9895 int opcode
= extract32(insn
, 11, 5);
9896 int immb
= extract32(insn
, 16, 3);
9897 int immh
= extract32(insn
, 19, 4);
9898 bool is_u
= extract32(insn
, 29, 1);
9899 bool is_q
= extract32(insn
, 30, 1);
9902 case 0x08: /* SRI */
9904 unallocated_encoding(s
);
9908 case 0x00: /* SSHR / USHR */
9909 case 0x02: /* SSRA / USRA (accumulate) */
9910 case 0x04: /* SRSHR / URSHR (rounding) */
9911 case 0x06: /* SRSRA / URSRA (accum + rounding) */
9912 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9914 case 0x0a: /* SHL / SLI */
9915 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9917 case 0x10: /* SHRN */
9918 case 0x11: /* RSHRN / SQRSHRUN */
9920 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
9923 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
9926 case 0x12: /* SQSHRN / UQSHRN */
9927 case 0x13: /* SQRSHRN / UQRSHRN */
9928 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
9931 case 0x14: /* SSHLL / USHLL */
9932 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
9934 case 0x1c: /* SCVTF / UCVTF */
9935 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
9938 case 0xc: /* SQSHLU */
9940 unallocated_encoding(s
);
9943 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
9945 case 0xe: /* SQSHL, UQSHL */
9946 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
9948 case 0x1f: /* FCVTZS/ FCVTZU */
9949 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
9952 unallocated_encoding(s
);
9957 /* Generate code to do a "long" addition or subtraction, ie one done in
9958 * TCGv_i64 on vector lanes twice the width specified by size.
9960 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
9961 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
9963 static NeonGenTwo64OpFn
* const fns
[3][2] = {
9964 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
9965 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
9966 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
9968 NeonGenTwo64OpFn
*genfn
;
9971 genfn
= fns
[size
][is_sub
];
9972 genfn(tcg_res
, tcg_op1
, tcg_op2
);
9975 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
9976 int opcode
, int rd
, int rn
, int rm
)
9978 /* 3-reg-different widening insns: 64 x 64 -> 128 */
9979 TCGv_i64 tcg_res
[2];
9982 tcg_res
[0] = tcg_temp_new_i64();
9983 tcg_res
[1] = tcg_temp_new_i64();
9985 /* Does this op do an adding accumulate, a subtracting accumulate,
9986 * or no accumulate at all?
10004 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10005 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10008 /* size == 2 means two 32x32->64 operations; this is worth special
10009 * casing because we can generally handle it inline.
10012 for (pass
= 0; pass
< 2; pass
++) {
10013 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10014 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10015 TCGv_i64 tcg_passres
;
10016 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
10018 int elt
= pass
+ is_q
* 2;
10020 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
10021 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
10024 tcg_passres
= tcg_res
[pass
];
10026 tcg_passres
= tcg_temp_new_i64();
10030 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10031 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10033 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10034 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10036 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10037 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10039 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
10040 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
10042 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
10043 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
10044 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
10046 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
10047 tcg_temp_free_i64(tcg_tmp1
);
10048 tcg_temp_free_i64(tcg_tmp2
);
10051 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10052 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10053 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10054 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10056 case 9: /* SQDMLAL, SQDMLAL2 */
10057 case 11: /* SQDMLSL, SQDMLSL2 */
10058 case 13: /* SQDMULL, SQDMULL2 */
10059 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
10060 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10061 tcg_passres
, tcg_passres
);
10064 g_assert_not_reached();
10067 if (opcode
== 9 || opcode
== 11) {
10068 /* saturating accumulate ops */
10070 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10072 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10073 tcg_res
[pass
], tcg_passres
);
10074 } else if (accop
> 0) {
10075 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10076 } else if (accop
< 0) {
10077 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10081 tcg_temp_free_i64(tcg_passres
);
10084 tcg_temp_free_i64(tcg_op1
);
10085 tcg_temp_free_i64(tcg_op2
);
10088 /* size 0 or 1, generally helper functions */
10089 for (pass
= 0; pass
< 2; pass
++) {
10090 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10091 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10092 TCGv_i64 tcg_passres
;
10093 int elt
= pass
+ is_q
* 2;
10095 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
10096 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
10099 tcg_passres
= tcg_res
[pass
];
10101 tcg_passres
= tcg_temp_new_i64();
10105 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10106 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10108 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
10109 static NeonGenWidenFn
* const widenfns
[2][2] = {
10110 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10111 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10113 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10115 widenfn(tcg_op2_64
, tcg_op2
);
10116 widenfn(tcg_passres
, tcg_op1
);
10117 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
10118 tcg_passres
, tcg_op2_64
);
10119 tcg_temp_free_i64(tcg_op2_64
);
10122 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10123 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10126 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10128 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10132 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
10134 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
10138 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10139 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10140 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
10143 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
10145 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
10149 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
10151 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10155 case 9: /* SQDMLAL, SQDMLAL2 */
10156 case 11: /* SQDMLSL, SQDMLSL2 */
10157 case 13: /* SQDMULL, SQDMULL2 */
10159 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
10160 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10161 tcg_passres
, tcg_passres
);
10163 case 14: /* PMULL */
10165 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
10168 g_assert_not_reached();
10170 tcg_temp_free_i32(tcg_op1
);
10171 tcg_temp_free_i32(tcg_op2
);
10174 if (opcode
== 9 || opcode
== 11) {
10175 /* saturating accumulate ops */
10177 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10179 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10183 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
10184 tcg_res
[pass
], tcg_passres
);
10186 tcg_temp_free_i64(tcg_passres
);
10191 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
10192 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
10193 tcg_temp_free_i64(tcg_res
[0]);
10194 tcg_temp_free_i64(tcg_res
[1]);
10197 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
10198 int opcode
, int rd
, int rn
, int rm
)
10200 TCGv_i64 tcg_res
[2];
10201 int part
= is_q
? 2 : 0;
10204 for (pass
= 0; pass
< 2; pass
++) {
10205 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10206 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10207 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
10208 static NeonGenWidenFn
* const widenfns
[3][2] = {
10209 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
10210 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
10211 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
10213 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
10215 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10216 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
10217 widenfn(tcg_op2_wide
, tcg_op2
);
10218 tcg_temp_free_i32(tcg_op2
);
10219 tcg_res
[pass
] = tcg_temp_new_i64();
10220 gen_neon_addl(size
, (opcode
== 3),
10221 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
10222 tcg_temp_free_i64(tcg_op1
);
10223 tcg_temp_free_i64(tcg_op2_wide
);
10226 for (pass
= 0; pass
< 2; pass
++) {
10227 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10228 tcg_temp_free_i64(tcg_res
[pass
]);
10232 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
10234 tcg_gen_addi_i64(in
, in
, 1U << 31);
10235 tcg_gen_extrh_i64_i32(res
, in
);
10238 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
10239 int opcode
, int rd
, int rn
, int rm
)
10241 TCGv_i32 tcg_res
[2];
10242 int part
= is_q
? 2 : 0;
10245 for (pass
= 0; pass
< 2; pass
++) {
10246 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10247 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10248 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
10249 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
10250 { gen_helper_neon_narrow_high_u8
,
10251 gen_helper_neon_narrow_round_high_u8
},
10252 { gen_helper_neon_narrow_high_u16
,
10253 gen_helper_neon_narrow_round_high_u16
},
10254 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
10256 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
10258 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10259 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
10261 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
10263 tcg_temp_free_i64(tcg_op1
);
10264 tcg_temp_free_i64(tcg_op2
);
10266 tcg_res
[pass
] = tcg_temp_new_i32();
10267 gennarrow(tcg_res
[pass
], tcg_wideres
);
10268 tcg_temp_free_i64(tcg_wideres
);
10271 for (pass
= 0; pass
< 2; pass
++) {
10272 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
10273 tcg_temp_free_i32(tcg_res
[pass
]);
10275 clear_vec_high(s
, is_q
, rd
);
10278 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
10280 /* PMULL of 64 x 64 -> 128 is an odd special case because it
10281 * is the only three-reg-diff instruction which produces a
10282 * 128-bit wide result from a single operation. However since
10283 * it's possible to calculate the two halves more or less
10284 * separately we just use two helper calls.
10286 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10287 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10288 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10290 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
10291 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
10292 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
10293 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
10294 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
10295 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
10297 tcg_temp_free_i64(tcg_op1
);
10298 tcg_temp_free_i64(tcg_op2
);
10299 tcg_temp_free_i64(tcg_res
);
10302 /* AdvSIMD three different
10303 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
10304 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10305 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
10306 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
10308 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
10310 /* Instructions in this group fall into three basic classes
10311 * (in each case with the operation working on each element in
10312 * the input vectors):
10313 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
10315 * (2) wide 64 x 128 -> 128
10316 * (3) narrowing 128 x 128 -> 64
10317 * Here we do initial decode, catch unallocated cases and
10318 * dispatch to separate functions for each class.
10320 int is_q
= extract32(insn
, 30, 1);
10321 int is_u
= extract32(insn
, 29, 1);
10322 int size
= extract32(insn
, 22, 2);
10323 int opcode
= extract32(insn
, 12, 4);
10324 int rm
= extract32(insn
, 16, 5);
10325 int rn
= extract32(insn
, 5, 5);
10326 int rd
= extract32(insn
, 0, 5);
10329 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
10330 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
10331 /* 64 x 128 -> 128 */
10333 unallocated_encoding(s
);
10336 if (!fp_access_check(s
)) {
10339 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10341 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
10342 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
10343 /* 128 x 128 -> 64 */
10345 unallocated_encoding(s
);
10348 if (!fp_access_check(s
)) {
10351 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10353 case 14: /* PMULL, PMULL2 */
10354 if (is_u
|| size
== 1 || size
== 2) {
10355 unallocated_encoding(s
);
10359 if (!arm_dc_feature(s
, ARM_FEATURE_V8_PMULL
)) {
10360 unallocated_encoding(s
);
10363 if (!fp_access_check(s
)) {
10366 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
10370 case 9: /* SQDMLAL, SQDMLAL2 */
10371 case 11: /* SQDMLSL, SQDMLSL2 */
10372 case 13: /* SQDMULL, SQDMULL2 */
10373 if (is_u
|| size
== 0) {
10374 unallocated_encoding(s
);
10378 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
10379 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
10380 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
10381 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
10382 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10383 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10384 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
10385 /* 64 x 64 -> 128 */
10387 unallocated_encoding(s
);
10391 if (!fp_access_check(s
)) {
10395 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
10398 /* opcode 15 not allocated */
10399 unallocated_encoding(s
);
10404 static void gen_bsl_i64(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
10406 tcg_gen_xor_i64(rn
, rn
, rm
);
10407 tcg_gen_and_i64(rn
, rn
, rd
);
10408 tcg_gen_xor_i64(rd
, rm
, rn
);
10411 static void gen_bit_i64(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
10413 tcg_gen_xor_i64(rn
, rn
, rd
);
10414 tcg_gen_and_i64(rn
, rn
, rm
);
10415 tcg_gen_xor_i64(rd
, rd
, rn
);
10418 static void gen_bif_i64(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
10420 tcg_gen_xor_i64(rn
, rn
, rd
);
10421 tcg_gen_andc_i64(rn
, rn
, rm
);
10422 tcg_gen_xor_i64(rd
, rd
, rn
);
10425 static void gen_bsl_vec(unsigned vece
, TCGv_vec rd
, TCGv_vec rn
, TCGv_vec rm
)
10427 tcg_gen_xor_vec(vece
, rn
, rn
, rm
);
10428 tcg_gen_and_vec(vece
, rn
, rn
, rd
);
10429 tcg_gen_xor_vec(vece
, rd
, rm
, rn
);
10432 static void gen_bit_vec(unsigned vece
, TCGv_vec rd
, TCGv_vec rn
, TCGv_vec rm
)
10434 tcg_gen_xor_vec(vece
, rn
, rn
, rd
);
10435 tcg_gen_and_vec(vece
, rn
, rn
, rm
);
10436 tcg_gen_xor_vec(vece
, rd
, rd
, rn
);
10439 static void gen_bif_vec(unsigned vece
, TCGv_vec rd
, TCGv_vec rn
, TCGv_vec rm
)
10441 tcg_gen_xor_vec(vece
, rn
, rn
, rd
);
10442 tcg_gen_andc_vec(vece
, rn
, rn
, rm
);
10443 tcg_gen_xor_vec(vece
, rd
, rd
, rn
);
10446 /* Logic op (opcode == 3) subgroup of C3.6.16. */
10447 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
10449 static const GVecGen3 bsl_op
= {
10450 .fni8
= gen_bsl_i64
,
10451 .fniv
= gen_bsl_vec
,
10452 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10455 static const GVecGen3 bit_op
= {
10456 .fni8
= gen_bit_i64
,
10457 .fniv
= gen_bit_vec
,
10458 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10461 static const GVecGen3 bif_op
= {
10462 .fni8
= gen_bif_i64
,
10463 .fniv
= gen_bif_vec
,
10464 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10468 int rd
= extract32(insn
, 0, 5);
10469 int rn
= extract32(insn
, 5, 5);
10470 int rm
= extract32(insn
, 16, 5);
10471 int size
= extract32(insn
, 22, 2);
10472 bool is_u
= extract32(insn
, 29, 1);
10473 bool is_q
= extract32(insn
, 30, 1);
10475 if (!fp_access_check(s
)) {
10479 switch (size
+ 4 * is_u
) {
10481 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_and
, 0);
10484 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_andc
, 0);
10487 if (rn
== rm
) { /* MOV */
10488 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_mov
, 0);
10490 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_or
, 0);
10494 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_orc
, 0);
10497 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_xor
, 0);
10500 case 5: /* BSL bitwise select */
10501 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bsl_op
);
10503 case 6: /* BIT, bitwise insert if true */
10504 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bit_op
);
10506 case 7: /* BIF, bitwise insert if false */
10507 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &bif_op
);
10511 g_assert_not_reached();
10515 /* Pairwise op subgroup of C3.6.16.
10517 * This is called directly or via the handle_3same_float for float pairwise
10518 * operations where the opcode and size are calculated differently.
10520 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
10521 int size
, int rn
, int rm
, int rd
)
10526 /* Floating point operations need fpst */
10527 if (opcode
>= 0x58) {
10528 fpst
= get_fpstatus_ptr(false);
10533 if (!fp_access_check(s
)) {
10537 /* These operations work on the concatenated rm:rn, with each pair of
10538 * adjacent elements being operated on to produce an element in the result.
10541 TCGv_i64 tcg_res
[2];
10543 for (pass
= 0; pass
< 2; pass
++) {
10544 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10545 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10546 int passreg
= (pass
== 0) ? rn
: rm
;
10548 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
10549 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
10550 tcg_res
[pass
] = tcg_temp_new_i64();
10553 case 0x17: /* ADDP */
10554 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10556 case 0x58: /* FMAXNMP */
10557 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10559 case 0x5a: /* FADDP */
10560 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10562 case 0x5e: /* FMAXP */
10563 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10565 case 0x78: /* FMINNMP */
10566 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10568 case 0x7e: /* FMINP */
10569 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10572 g_assert_not_reached();
10575 tcg_temp_free_i64(tcg_op1
);
10576 tcg_temp_free_i64(tcg_op2
);
10579 for (pass
= 0; pass
< 2; pass
++) {
10580 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10581 tcg_temp_free_i64(tcg_res
[pass
]);
10584 int maxpass
= is_q
? 4 : 2;
10585 TCGv_i32 tcg_res
[4];
10587 for (pass
= 0; pass
< maxpass
; pass
++) {
10588 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10589 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10590 NeonGenTwoOpFn
*genfn
= NULL
;
10591 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
10592 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
10594 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
10595 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
10596 tcg_res
[pass
] = tcg_temp_new_i32();
10599 case 0x17: /* ADDP */
10601 static NeonGenTwoOpFn
* const fns
[3] = {
10602 gen_helper_neon_padd_u8
,
10603 gen_helper_neon_padd_u16
,
10609 case 0x14: /* SMAXP, UMAXP */
10611 static NeonGenTwoOpFn
* const fns
[3][2] = {
10612 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
10613 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
10614 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
10616 genfn
= fns
[size
][u
];
10619 case 0x15: /* SMINP, UMINP */
10621 static NeonGenTwoOpFn
* const fns
[3][2] = {
10622 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
10623 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
10624 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
10626 genfn
= fns
[size
][u
];
10629 /* The FP operations are all on single floats (32 bit) */
10630 case 0x58: /* FMAXNMP */
10631 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10633 case 0x5a: /* FADDP */
10634 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10636 case 0x5e: /* FMAXP */
10637 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10639 case 0x78: /* FMINNMP */
10640 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10642 case 0x7e: /* FMINP */
10643 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
10646 g_assert_not_reached();
10649 /* FP ops called directly, otherwise call now */
10651 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
10654 tcg_temp_free_i32(tcg_op1
);
10655 tcg_temp_free_i32(tcg_op2
);
10658 for (pass
= 0; pass
< maxpass
; pass
++) {
10659 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
10660 tcg_temp_free_i32(tcg_res
[pass
]);
10662 clear_vec_high(s
, is_q
, rd
);
10666 tcg_temp_free_ptr(fpst
);
10670 /* Floating point op subgroup of C3.6.16. */
10671 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
10673 /* For floating point ops, the U, size[1] and opcode bits
10674 * together indicate the operation. size[0] indicates single
10677 int fpopcode
= extract32(insn
, 11, 5)
10678 | (extract32(insn
, 23, 1) << 5)
10679 | (extract32(insn
, 29, 1) << 6);
10680 int is_q
= extract32(insn
, 30, 1);
10681 int size
= extract32(insn
, 22, 1);
10682 int rm
= extract32(insn
, 16, 5);
10683 int rn
= extract32(insn
, 5, 5);
10684 int rd
= extract32(insn
, 0, 5);
10686 int datasize
= is_q
? 128 : 64;
10687 int esize
= 32 << size
;
10688 int elements
= datasize
/ esize
;
10690 if (size
== 1 && !is_q
) {
10691 unallocated_encoding(s
);
10695 switch (fpopcode
) {
10696 case 0x58: /* FMAXNMP */
10697 case 0x5a: /* FADDP */
10698 case 0x5e: /* FMAXP */
10699 case 0x78: /* FMINNMP */
10700 case 0x7e: /* FMINP */
10701 if (size
&& !is_q
) {
10702 unallocated_encoding(s
);
10705 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
10708 case 0x1b: /* FMULX */
10709 case 0x1f: /* FRECPS */
10710 case 0x3f: /* FRSQRTS */
10711 case 0x5d: /* FACGE */
10712 case 0x7d: /* FACGT */
10713 case 0x19: /* FMLA */
10714 case 0x39: /* FMLS */
10715 case 0x18: /* FMAXNM */
10716 case 0x1a: /* FADD */
10717 case 0x1c: /* FCMEQ */
10718 case 0x1e: /* FMAX */
10719 case 0x38: /* FMINNM */
10720 case 0x3a: /* FSUB */
10721 case 0x3e: /* FMIN */
10722 case 0x5b: /* FMUL */
10723 case 0x5c: /* FCMGE */
10724 case 0x5f: /* FDIV */
10725 case 0x7a: /* FABD */
10726 case 0x7c: /* FCMGT */
10727 if (!fp_access_check(s
)) {
10731 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
10734 unallocated_encoding(s
);
10739 static void gen_mla8_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10741 gen_helper_neon_mul_u8(a
, a
, b
);
10742 gen_helper_neon_add_u8(d
, d
, a
);
10745 static void gen_mla16_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10747 gen_helper_neon_mul_u16(a
, a
, b
);
10748 gen_helper_neon_add_u16(d
, d
, a
);
10751 static void gen_mla32_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10753 tcg_gen_mul_i32(a
, a
, b
);
10754 tcg_gen_add_i32(d
, d
, a
);
10757 static void gen_mla64_i64(TCGv_i64 d
, TCGv_i64 a
, TCGv_i64 b
)
10759 tcg_gen_mul_i64(a
, a
, b
);
10760 tcg_gen_add_i64(d
, d
, a
);
10763 static void gen_mla_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, TCGv_vec b
)
10765 tcg_gen_mul_vec(vece
, a
, a
, b
);
10766 tcg_gen_add_vec(vece
, d
, d
, a
);
10769 static void gen_mls8_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10771 gen_helper_neon_mul_u8(a
, a
, b
);
10772 gen_helper_neon_sub_u8(d
, d
, a
);
10775 static void gen_mls16_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10777 gen_helper_neon_mul_u16(a
, a
, b
);
10778 gen_helper_neon_sub_u16(d
, d
, a
);
10781 static void gen_mls32_i32(TCGv_i32 d
, TCGv_i32 a
, TCGv_i32 b
)
10783 tcg_gen_mul_i32(a
, a
, b
);
10784 tcg_gen_sub_i32(d
, d
, a
);
10787 static void gen_mls64_i64(TCGv_i64 d
, TCGv_i64 a
, TCGv_i64 b
)
10789 tcg_gen_mul_i64(a
, a
, b
);
10790 tcg_gen_sub_i64(d
, d
, a
);
10793 static void gen_mls_vec(unsigned vece
, TCGv_vec d
, TCGv_vec a
, TCGv_vec b
)
10795 tcg_gen_mul_vec(vece
, a
, a
, b
);
10796 tcg_gen_sub_vec(vece
, d
, d
, a
);
10799 /* Integer op subgroup of C3.6.16. */
10800 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
10802 static const GVecGen3 cmtst_op
[4] = {
10803 { .fni4
= gen_helper_neon_tst_u8
,
10804 .fniv
= gen_cmtst_vec
,
10806 { .fni4
= gen_helper_neon_tst_u16
,
10807 .fniv
= gen_cmtst_vec
,
10809 { .fni4
= gen_cmtst_i32
,
10810 .fniv
= gen_cmtst_vec
,
10812 { .fni8
= gen_cmtst_i64
,
10813 .fniv
= gen_cmtst_vec
,
10814 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10817 static const GVecGen3 mla_op
[4] = {
10818 { .fni4
= gen_mla8_i32
,
10819 .fniv
= gen_mla_vec
,
10820 .opc
= INDEX_op_mul_vec
,
10823 { .fni4
= gen_mla16_i32
,
10824 .fniv
= gen_mla_vec
,
10825 .opc
= INDEX_op_mul_vec
,
10828 { .fni4
= gen_mla32_i32
,
10829 .fniv
= gen_mla_vec
,
10830 .opc
= INDEX_op_mul_vec
,
10833 { .fni8
= gen_mla64_i64
,
10834 .fniv
= gen_mla_vec
,
10835 .opc
= INDEX_op_mul_vec
,
10836 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10840 static const GVecGen3 mls_op
[4] = {
10841 { .fni4
= gen_mls8_i32
,
10842 .fniv
= gen_mls_vec
,
10843 .opc
= INDEX_op_mul_vec
,
10846 { .fni4
= gen_mls16_i32
,
10847 .fniv
= gen_mls_vec
,
10848 .opc
= INDEX_op_mul_vec
,
10851 { .fni4
= gen_mls32_i32
,
10852 .fniv
= gen_mls_vec
,
10853 .opc
= INDEX_op_mul_vec
,
10856 { .fni8
= gen_mls64_i64
,
10857 .fniv
= gen_mls_vec
,
10858 .opc
= INDEX_op_mul_vec
,
10859 .prefer_i64
= TCG_TARGET_REG_BITS
== 64,
10864 int is_q
= extract32(insn
, 30, 1);
10865 int u
= extract32(insn
, 29, 1);
10866 int size
= extract32(insn
, 22, 2);
10867 int opcode
= extract32(insn
, 11, 5);
10868 int rm
= extract32(insn
, 16, 5);
10869 int rn
= extract32(insn
, 5, 5);
10870 int rd
= extract32(insn
, 0, 5);
10875 case 0x13: /* MUL, PMUL */
10876 if (u
&& size
!= 0) {
10877 unallocated_encoding(s
);
10881 case 0x0: /* SHADD, UHADD */
10882 case 0x2: /* SRHADD, URHADD */
10883 case 0x4: /* SHSUB, UHSUB */
10884 case 0xc: /* SMAX, UMAX */
10885 case 0xd: /* SMIN, UMIN */
10886 case 0xe: /* SABD, UABD */
10887 case 0xf: /* SABA, UABA */
10888 case 0x12: /* MLA, MLS */
10890 unallocated_encoding(s
);
10894 case 0x16: /* SQDMULH, SQRDMULH */
10895 if (size
== 0 || size
== 3) {
10896 unallocated_encoding(s
);
10901 if (size
== 3 && !is_q
) {
10902 unallocated_encoding(s
);
10908 if (!fp_access_check(s
)) {
10913 case 0x10: /* ADD, SUB */
10915 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_sub
, size
);
10917 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_add
, size
);
10920 case 0x13: /* MUL, PMUL */
10921 if (!u
) { /* MUL */
10922 gen_gvec_fn3(s
, is_q
, rd
, rn
, rm
, tcg_gen_gvec_mul
, size
);
10926 case 0x12: /* MLA, MLS */
10928 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mls_op
[size
]);
10930 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &mla_op
[size
]);
10934 if (!u
) { /* CMTST */
10935 gen_gvec_op3(s
, is_q
, rd
, rn
, rm
, &cmtst_op
[size
]);
10939 cond
= TCG_COND_EQ
;
10941 case 0x06: /* CMGT, CMHI */
10942 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
10944 case 0x07: /* CMGE, CMHS */
10945 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
10947 tcg_gen_gvec_cmp(cond
, size
, vec_full_reg_offset(s
, rd
),
10948 vec_full_reg_offset(s
, rn
),
10949 vec_full_reg_offset(s
, rm
),
10950 is_q
? 16 : 8, vec_full_reg_size(s
));
10956 for (pass
= 0; pass
< 2; pass
++) {
10957 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
10958 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
10959 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10961 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
10962 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
10964 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
10966 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10968 tcg_temp_free_i64(tcg_res
);
10969 tcg_temp_free_i64(tcg_op1
);
10970 tcg_temp_free_i64(tcg_op2
);
10973 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
10974 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
10975 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
10976 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10977 NeonGenTwoOpFn
*genfn
= NULL
;
10978 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
10980 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
10981 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
10984 case 0x0: /* SHADD, UHADD */
10986 static NeonGenTwoOpFn
* const fns
[3][2] = {
10987 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
10988 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
10989 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
10991 genfn
= fns
[size
][u
];
10994 case 0x1: /* SQADD, UQADD */
10996 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
10997 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
10998 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
10999 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
11001 genenvfn
= fns
[size
][u
];
11004 case 0x2: /* SRHADD, URHADD */
11006 static NeonGenTwoOpFn
* const fns
[3][2] = {
11007 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
11008 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
11009 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
11011 genfn
= fns
[size
][u
];
11014 case 0x4: /* SHSUB, UHSUB */
11016 static NeonGenTwoOpFn
* const fns
[3][2] = {
11017 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
11018 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
11019 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
11021 genfn
= fns
[size
][u
];
11024 case 0x5: /* SQSUB, UQSUB */
11026 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11027 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
11028 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
11029 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
11031 genenvfn
= fns
[size
][u
];
11034 case 0x8: /* SSHL, USHL */
11036 static NeonGenTwoOpFn
* const fns
[3][2] = {
11037 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
11038 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
11039 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
11041 genfn
= fns
[size
][u
];
11044 case 0x9: /* SQSHL, UQSHL */
11046 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11047 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
11048 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
11049 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
11051 genenvfn
= fns
[size
][u
];
11054 case 0xa: /* SRSHL, URSHL */
11056 static NeonGenTwoOpFn
* const fns
[3][2] = {
11057 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
11058 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
11059 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
11061 genfn
= fns
[size
][u
];
11064 case 0xb: /* SQRSHL, UQRSHL */
11066 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
11067 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
11068 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
11069 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
11071 genenvfn
= fns
[size
][u
];
11074 case 0xc: /* SMAX, UMAX */
11076 static NeonGenTwoOpFn
* const fns
[3][2] = {
11077 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
11078 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
11079 { tcg_gen_smax_i32
, tcg_gen_umax_i32
},
11081 genfn
= fns
[size
][u
];
11085 case 0xd: /* SMIN, UMIN */
11087 static NeonGenTwoOpFn
* const fns
[3][2] = {
11088 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
11089 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
11090 { tcg_gen_smin_i32
, tcg_gen_umin_i32
},
11092 genfn
= fns
[size
][u
];
11095 case 0xe: /* SABD, UABD */
11096 case 0xf: /* SABA, UABA */
11098 static NeonGenTwoOpFn
* const fns
[3][2] = {
11099 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
11100 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
11101 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
11103 genfn
= fns
[size
][u
];
11106 case 0x13: /* MUL, PMUL */
11107 assert(u
); /* PMUL */
11109 genfn
= gen_helper_neon_mul_p8
;
11111 case 0x16: /* SQDMULH, SQRDMULH */
11113 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
11114 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
11115 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
11117 assert(size
== 1 || size
== 2);
11118 genenvfn
= fns
[size
- 1][u
];
11122 g_assert_not_reached();
11126 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
11128 genfn(tcg_res
, tcg_op1
, tcg_op2
);
11131 if (opcode
== 0xf) {
11132 /* SABA, UABA: accumulating ops */
11133 static NeonGenTwoOpFn
* const fns
[3] = {
11134 gen_helper_neon_add_u8
,
11135 gen_helper_neon_add_u16
,
11139 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
11140 fns
[size
](tcg_res
, tcg_op1
, tcg_res
);
11143 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
11145 tcg_temp_free_i32(tcg_res
);
11146 tcg_temp_free_i32(tcg_op1
);
11147 tcg_temp_free_i32(tcg_op2
);
11150 clear_vec_high(s
, is_q
, rd
);
11153 /* AdvSIMD three same
11154 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
11155 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11156 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
11157 * +---+---+---+-----------+------+---+------+--------+---+------+------+
11159 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
11161 int opcode
= extract32(insn
, 11, 5);
11164 case 0x3: /* logic ops */
11165 disas_simd_3same_logic(s
, insn
);
11167 case 0x17: /* ADDP */
11168 case 0x14: /* SMAXP, UMAXP */
11169 case 0x15: /* SMINP, UMINP */
11171 /* Pairwise operations */
11172 int is_q
= extract32(insn
, 30, 1);
11173 int u
= extract32(insn
, 29, 1);
11174 int size
= extract32(insn
, 22, 2);
11175 int rm
= extract32(insn
, 16, 5);
11176 int rn
= extract32(insn
, 5, 5);
11177 int rd
= extract32(insn
, 0, 5);
11178 if (opcode
== 0x17) {
11179 if (u
|| (size
== 3 && !is_q
)) {
11180 unallocated_encoding(s
);
11185 unallocated_encoding(s
);
11189 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
11192 case 0x18 ... 0x31:
11193 /* floating point ops, sz[1] and U are part of opcode */
11194 disas_simd_3same_float(s
, insn
);
11197 disas_simd_3same_int(s
, insn
);
11203 * Advanced SIMD three same (ARMv8.2 FP16 variants)
11205 * 31 30 29 28 24 23 22 21 20 16 15 14 13 11 10 9 5 4 0
11206 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11207 * | 0 | Q | U | 0 1 1 1 0 | a | 1 0 | Rm | 0 0 | opcode | 1 | Rn | Rd |
11208 * +---+---+---+-----------+---------+------+-----+--------+---+------+------+
11210 * This includes FMULX, FCMEQ (register), FRECPS, FRSQRTS, FCMGE
11211 * (register), FACGE, FABD, FCMGT (register) and FACGT.
11214 static void disas_simd_three_reg_same_fp16(DisasContext
*s
, uint32_t insn
)
11216 int opcode
, fpopcode
;
11217 int is_q
, u
, a
, rm
, rn
, rd
;
11218 int datasize
, elements
;
11221 bool pairwise
= false;
11223 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
11224 unallocated_encoding(s
);
11228 if (!fp_access_check(s
)) {
11232 /* For these floating point ops, the U, a and opcode bits
11233 * together indicate the operation.
11235 opcode
= extract32(insn
, 11, 3);
11236 u
= extract32(insn
, 29, 1);
11237 a
= extract32(insn
, 23, 1);
11238 is_q
= extract32(insn
, 30, 1);
11239 rm
= extract32(insn
, 16, 5);
11240 rn
= extract32(insn
, 5, 5);
11241 rd
= extract32(insn
, 0, 5);
11243 fpopcode
= opcode
| (a
<< 3) | (u
<< 4);
11244 datasize
= is_q
? 128 : 64;
11245 elements
= datasize
/ 16;
11247 switch (fpopcode
) {
11248 case 0x10: /* FMAXNMP */
11249 case 0x12: /* FADDP */
11250 case 0x16: /* FMAXP */
11251 case 0x18: /* FMINNMP */
11252 case 0x1e: /* FMINP */
11257 fpst
= get_fpstatus_ptr(true);
11260 int maxpass
= is_q
? 8 : 4;
11261 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11262 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11263 TCGv_i32 tcg_res
[8];
11265 for (pass
= 0; pass
< maxpass
; pass
++) {
11266 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
11267 int passelt
= (pass
<< 1) & (maxpass
- 1);
11269 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_16
);
11270 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_16
);
11271 tcg_res
[pass
] = tcg_temp_new_i32();
11273 switch (fpopcode
) {
11274 case 0x10: /* FMAXNMP */
11275 gen_helper_advsimd_maxnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11278 case 0x12: /* FADDP */
11279 gen_helper_advsimd_addh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11281 case 0x16: /* FMAXP */
11282 gen_helper_advsimd_maxh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11284 case 0x18: /* FMINNMP */
11285 gen_helper_advsimd_minnumh(tcg_res
[pass
], tcg_op1
, tcg_op2
,
11288 case 0x1e: /* FMINP */
11289 gen_helper_advsimd_minh(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
11292 g_assert_not_reached();
11296 for (pass
= 0; pass
< maxpass
; pass
++) {
11297 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_16
);
11298 tcg_temp_free_i32(tcg_res
[pass
]);
11301 tcg_temp_free_i32(tcg_op1
);
11302 tcg_temp_free_i32(tcg_op2
);
11305 for (pass
= 0; pass
< elements
; pass
++) {
11306 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
11307 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
11308 TCGv_i32 tcg_res
= tcg_temp_new_i32();
11310 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_16
);
11311 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_16
);
11313 switch (fpopcode
) {
11314 case 0x0: /* FMAXNM */
11315 gen_helper_advsimd_maxnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11317 case 0x1: /* FMLA */
11318 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11319 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11322 case 0x2: /* FADD */
11323 gen_helper_advsimd_addh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11325 case 0x3: /* FMULX */
11326 gen_helper_advsimd_mulxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11328 case 0x4: /* FCMEQ */
11329 gen_helper_advsimd_ceq_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11331 case 0x6: /* FMAX */
11332 gen_helper_advsimd_maxh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11334 case 0x7: /* FRECPS */
11335 gen_helper_recpsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11337 case 0x8: /* FMINNM */
11338 gen_helper_advsimd_minnumh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11340 case 0x9: /* FMLS */
11341 /* As usual for ARM, separate negation for fused multiply-add */
11342 tcg_gen_xori_i32(tcg_op1
, tcg_op1
, 0x8000);
11343 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11344 gen_helper_advsimd_muladdh(tcg_res
, tcg_op1
, tcg_op2
, tcg_res
,
11347 case 0xa: /* FSUB */
11348 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11350 case 0xe: /* FMIN */
11351 gen_helper_advsimd_minh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11353 case 0xf: /* FRSQRTS */
11354 gen_helper_rsqrtsf_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11356 case 0x13: /* FMUL */
11357 gen_helper_advsimd_mulh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11359 case 0x14: /* FCMGE */
11360 gen_helper_advsimd_cge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11362 case 0x15: /* FACGE */
11363 gen_helper_advsimd_acge_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11365 case 0x17: /* FDIV */
11366 gen_helper_advsimd_divh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11368 case 0x1a: /* FABD */
11369 gen_helper_advsimd_subh(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11370 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0x7fff);
11372 case 0x1c: /* FCMGT */
11373 gen_helper_advsimd_cgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11375 case 0x1d: /* FACGT */
11376 gen_helper_advsimd_acgt_f16(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
11379 fprintf(stderr
, "%s: insn %#04x, fpop %#2x @ %#" PRIx64
"\n",
11380 __func__
, insn
, fpopcode
, s
->pc
);
11381 g_assert_not_reached();
11384 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
11385 tcg_temp_free_i32(tcg_res
);
11386 tcg_temp_free_i32(tcg_op1
);
11387 tcg_temp_free_i32(tcg_op2
);
11391 tcg_temp_free_ptr(fpst
);
11393 clear_vec_high(s
, is_q
, rd
);
11396 /* AdvSIMD three same extra
11397 * 31 30 29 28 24 23 22 21 20 16 15 14 11 10 9 5 4 0
11398 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11399 * | 0 | Q | U | 0 1 1 1 0 | size | 0 | Rm | 1 | opcode | 1 | Rn | Rd |
11400 * +---+---+---+-----------+------+---+------+---+--------+---+----+----+
11402 static void disas_simd_three_reg_same_extra(DisasContext
*s
, uint32_t insn
)
11404 int rd
= extract32(insn
, 0, 5);
11405 int rn
= extract32(insn
, 5, 5);
11406 int opcode
= extract32(insn
, 11, 4);
11407 int rm
= extract32(insn
, 16, 5);
11408 int size
= extract32(insn
, 22, 2);
11409 bool u
= extract32(insn
, 29, 1);
11410 bool is_q
= extract32(insn
, 30, 1);
11413 switch (u
* 16 + opcode
) {
11414 case 0x10: /* SQRDMLAH (vector) */
11415 case 0x11: /* SQRDMLSH (vector) */
11416 if (size
!= 1 && size
!= 2) {
11417 unallocated_encoding(s
);
11420 feature
= ARM_FEATURE_V8_RDM
;
11422 case 0x02: /* SDOT (vector) */
11423 case 0x12: /* UDOT (vector) */
11424 if (size
!= MO_32
) {
11425 unallocated_encoding(s
);
11428 feature
= ARM_FEATURE_V8_DOTPROD
;
11430 case 0x18: /* FCMLA, #0 */
11431 case 0x19: /* FCMLA, #90 */
11432 case 0x1a: /* FCMLA, #180 */
11433 case 0x1b: /* FCMLA, #270 */
11434 case 0x1c: /* FCADD, #90 */
11435 case 0x1e: /* FCADD, #270 */
11437 || (size
== 1 && !arm_dc_feature(s
, ARM_FEATURE_V8_FP16
))
11438 || (size
== 3 && !is_q
)) {
11439 unallocated_encoding(s
);
11442 feature
= ARM_FEATURE_V8_FCMA
;
11445 unallocated_encoding(s
);
11448 if (!arm_dc_feature(s
, feature
)) {
11449 unallocated_encoding(s
);
11452 if (!fp_access_check(s
)) {
11457 case 0x0: /* SQRDMLAH (vector) */
11460 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s16
);
11463 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlah_s32
);
11466 g_assert_not_reached();
11470 case 0x1: /* SQRDMLSH (vector) */
11473 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s16
);
11476 gen_gvec_op3_env(s
, is_q
, rd
, rn
, rm
, gen_helper_gvec_qrdmlsh_s32
);
11479 g_assert_not_reached();
11483 case 0x2: /* SDOT / UDOT */
11484 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, 0,
11485 u
? gen_helper_gvec_udot_b
: gen_helper_gvec_sdot_b
);
11488 case 0x8: /* FCMLA, #0 */
11489 case 0x9: /* FCMLA, #90 */
11490 case 0xa: /* FCMLA, #180 */
11491 case 0xb: /* FCMLA, #270 */
11492 rot
= extract32(opcode
, 0, 2);
11495 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, true, rot
,
11496 gen_helper_gvec_fcmlah
);
11499 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11500 gen_helper_gvec_fcmlas
);
11503 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, false, rot
,
11504 gen_helper_gvec_fcmlad
);
11507 g_assert_not_reached();
11511 case 0xc: /* FCADD, #90 */
11512 case 0xe: /* FCADD, #270 */
11513 rot
= extract32(opcode
, 1, 1);
11516 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11517 gen_helper_gvec_fcaddh
);
11520 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11521 gen_helper_gvec_fcadds
);
11524 gen_gvec_op3_fpst(s
, is_q
, rd
, rn
, rm
, size
== 1, rot
,
11525 gen_helper_gvec_fcaddd
);
11528 g_assert_not_reached();
11533 g_assert_not_reached();
11537 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
11538 int size
, int rn
, int rd
)
11540 /* Handle 2-reg-misc ops which are widening (so each size element
11541 * in the source becomes a 2*size element in the destination.
11542 * The only instruction like this is FCVTL.
11547 /* 32 -> 64 bit fp conversion */
11548 TCGv_i64 tcg_res
[2];
11549 int srcelt
= is_q
? 2 : 0;
11551 for (pass
= 0; pass
< 2; pass
++) {
11552 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11553 tcg_res
[pass
] = tcg_temp_new_i64();
11555 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
11556 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
11557 tcg_temp_free_i32(tcg_op
);
11559 for (pass
= 0; pass
< 2; pass
++) {
11560 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11561 tcg_temp_free_i64(tcg_res
[pass
]);
11564 /* 16 -> 32 bit fp conversion */
11565 int srcelt
= is_q
? 4 : 0;
11566 TCGv_i32 tcg_res
[4];
11567 TCGv_ptr fpst
= get_fpstatus_ptr(false);
11568 TCGv_i32 ahp
= get_ahp_flag();
11570 for (pass
= 0; pass
< 4; pass
++) {
11571 tcg_res
[pass
] = tcg_temp_new_i32();
11573 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
11574 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
11577 for (pass
= 0; pass
< 4; pass
++) {
11578 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
11579 tcg_temp_free_i32(tcg_res
[pass
]);
11582 tcg_temp_free_ptr(fpst
);
11583 tcg_temp_free_i32(ahp
);
11587 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
11588 bool is_q
, int size
, int rn
, int rd
)
11590 int op
= (opcode
<< 1) | u
;
11591 int opsz
= op
+ size
;
11592 int grp_size
= 3 - opsz
;
11593 int dsize
= is_q
? 128 : 64;
11597 unallocated_encoding(s
);
11601 if (!fp_access_check(s
)) {
11606 /* Special case bytes, use bswap op on each group of elements */
11607 int groups
= dsize
/ (8 << grp_size
);
11609 for (i
= 0; i
< groups
; i
++) {
11610 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
11612 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
11613 switch (grp_size
) {
11615 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
11618 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
11621 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
11624 g_assert_not_reached();
11626 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
11627 tcg_temp_free_i64(tcg_tmp
);
11629 clear_vec_high(s
, is_q
, rd
);
11631 int revmask
= (1 << grp_size
) - 1;
11632 int esize
= 8 << size
;
11633 int elements
= dsize
/ esize
;
11634 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
11635 TCGv_i64 tcg_rd
= tcg_const_i64(0);
11636 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
11638 for (i
= 0; i
< elements
; i
++) {
11639 int e_rev
= (i
& 0xf) ^ revmask
;
11640 int off
= e_rev
* esize
;
11641 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
11643 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
11644 tcg_rn
, off
- 64, esize
);
11646 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
11649 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
11650 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
11652 tcg_temp_free_i64(tcg_rd_hi
);
11653 tcg_temp_free_i64(tcg_rd
);
11654 tcg_temp_free_i64(tcg_rn
);
11658 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
11659 bool is_q
, int size
, int rn
, int rd
)
11661 /* Implement the pairwise operations from 2-misc:
11662 * SADDLP, UADDLP, SADALP, UADALP.
11663 * These all add pairs of elements in the input to produce a
11664 * double-width result element in the output (possibly accumulating).
11666 bool accum
= (opcode
== 0x6);
11667 int maxpass
= is_q
? 2 : 1;
11669 TCGv_i64 tcg_res
[2];
11672 /* 32 + 32 -> 64 op */
11673 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
11675 for (pass
= 0; pass
< maxpass
; pass
++) {
11676 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
11677 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
11679 tcg_res
[pass
] = tcg_temp_new_i64();
11681 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
11682 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
11683 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
11685 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
11686 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
11689 tcg_temp_free_i64(tcg_op1
);
11690 tcg_temp_free_i64(tcg_op2
);
11693 for (pass
= 0; pass
< maxpass
; pass
++) {
11694 TCGv_i64 tcg_op
= tcg_temp_new_i64();
11695 NeonGenOneOpFn
*genfn
;
11696 static NeonGenOneOpFn
* const fns
[2][2] = {
11697 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
11698 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
11701 genfn
= fns
[size
][u
];
11703 tcg_res
[pass
] = tcg_temp_new_i64();
11705 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
11706 genfn(tcg_res
[pass
], tcg_op
);
11709 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
11711 gen_helper_neon_addl_u16(tcg_res
[pass
],
11712 tcg_res
[pass
], tcg_op
);
11714 gen_helper_neon_addl_u32(tcg_res
[pass
],
11715 tcg_res
[pass
], tcg_op
);
11718 tcg_temp_free_i64(tcg_op
);
11722 tcg_res
[1] = tcg_const_i64(0);
11724 for (pass
= 0; pass
< 2; pass
++) {
11725 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11726 tcg_temp_free_i64(tcg_res
[pass
]);
11730 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
11732 /* Implement SHLL and SHLL2 */
11734 int part
= is_q
? 2 : 0;
11735 TCGv_i64 tcg_res
[2];
11737 for (pass
= 0; pass
< 2; pass
++) {
11738 static NeonGenWidenFn
* const widenfns
[3] = {
11739 gen_helper_neon_widen_u8
,
11740 gen_helper_neon_widen_u16
,
11741 tcg_gen_extu_i32_i64
,
11743 NeonGenWidenFn
*widenfn
= widenfns
[size
];
11744 TCGv_i32 tcg_op
= tcg_temp_new_i32();
11746 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
11747 tcg_res
[pass
] = tcg_temp_new_i64();
11748 widenfn(tcg_res
[pass
], tcg_op
);
11749 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
11751 tcg_temp_free_i32(tcg_op
);
11754 for (pass
= 0; pass
< 2; pass
++) {
11755 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
11756 tcg_temp_free_i64(tcg_res
[pass
]);
11760 /* AdvSIMD two reg misc
11761 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
11762 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11763 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
11764 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
11766 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
11768 int size
= extract32(insn
, 22, 2);
11769 int opcode
= extract32(insn
, 12, 5);
11770 bool u
= extract32(insn
, 29, 1);
11771 bool is_q
= extract32(insn
, 30, 1);
11772 int rn
= extract32(insn
, 5, 5);
11773 int rd
= extract32(insn
, 0, 5);
11774 bool need_fpstatus
= false;
11775 bool need_rmode
= false;
11777 TCGv_i32 tcg_rmode
;
11778 TCGv_ptr tcg_fpstatus
;
11781 case 0x0: /* REV64, REV32 */
11782 case 0x1: /* REV16 */
11783 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
11785 case 0x5: /* CNT, NOT, RBIT */
11786 if (u
&& size
== 0) {
11789 } else if (u
&& size
== 1) {
11792 } else if (!u
&& size
== 0) {
11796 unallocated_encoding(s
);
11798 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
11799 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
11801 unallocated_encoding(s
);
11804 if (!fp_access_check(s
)) {
11808 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
11810 case 0x4: /* CLS, CLZ */
11812 unallocated_encoding(s
);
11816 case 0x2: /* SADDLP, UADDLP */
11817 case 0x6: /* SADALP, UADALP */
11819 unallocated_encoding(s
);
11822 if (!fp_access_check(s
)) {
11825 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
11827 case 0x13: /* SHLL, SHLL2 */
11828 if (u
== 0 || size
== 3) {
11829 unallocated_encoding(s
);
11832 if (!fp_access_check(s
)) {
11835 handle_shll(s
, is_q
, size
, rn
, rd
);
11837 case 0xa: /* CMLT */
11839 unallocated_encoding(s
);
11843 case 0x8: /* CMGT, CMGE */
11844 case 0x9: /* CMEQ, CMLE */
11845 case 0xb: /* ABS, NEG */
11846 if (size
== 3 && !is_q
) {
11847 unallocated_encoding(s
);
11851 case 0x3: /* SUQADD, USQADD */
11852 if (size
== 3 && !is_q
) {
11853 unallocated_encoding(s
);
11856 if (!fp_access_check(s
)) {
11859 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
11861 case 0x7: /* SQABS, SQNEG */
11862 if (size
== 3 && !is_q
) {
11863 unallocated_encoding(s
);
11868 case 0x16 ... 0x1d:
11871 /* Floating point: U, size[1] and opcode indicate operation;
11872 * size[0] indicates single or double precision.
11874 int is_double
= extract32(size
, 0, 1);
11875 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
11876 size
= is_double
? 3 : 2;
11878 case 0x2f: /* FABS */
11879 case 0x6f: /* FNEG */
11880 if (size
== 3 && !is_q
) {
11881 unallocated_encoding(s
);
11885 case 0x1d: /* SCVTF */
11886 case 0x5d: /* UCVTF */
11888 bool is_signed
= (opcode
== 0x1d) ? true : false;
11889 int elements
= is_double
? 2 : is_q
? 4 : 2;
11890 if (is_double
&& !is_q
) {
11891 unallocated_encoding(s
);
11894 if (!fp_access_check(s
)) {
11897 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
11900 case 0x2c: /* FCMGT (zero) */
11901 case 0x2d: /* FCMEQ (zero) */
11902 case 0x2e: /* FCMLT (zero) */
11903 case 0x6c: /* FCMGE (zero) */
11904 case 0x6d: /* FCMLE (zero) */
11905 if (size
== 3 && !is_q
) {
11906 unallocated_encoding(s
);
11909 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
11911 case 0x7f: /* FSQRT */
11912 if (size
== 3 && !is_q
) {
11913 unallocated_encoding(s
);
11917 case 0x1a: /* FCVTNS */
11918 case 0x1b: /* FCVTMS */
11919 case 0x3a: /* FCVTPS */
11920 case 0x3b: /* FCVTZS */
11921 case 0x5a: /* FCVTNU */
11922 case 0x5b: /* FCVTMU */
11923 case 0x7a: /* FCVTPU */
11924 case 0x7b: /* FCVTZU */
11925 need_fpstatus
= true;
11927 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
11928 if (size
== 3 && !is_q
) {
11929 unallocated_encoding(s
);
11933 case 0x5c: /* FCVTAU */
11934 case 0x1c: /* FCVTAS */
11935 need_fpstatus
= true;
11937 rmode
= FPROUNDING_TIEAWAY
;
11938 if (size
== 3 && !is_q
) {
11939 unallocated_encoding(s
);
11943 case 0x3c: /* URECPE */
11945 unallocated_encoding(s
);
11949 case 0x3d: /* FRECPE */
11950 case 0x7d: /* FRSQRTE */
11951 if (size
== 3 && !is_q
) {
11952 unallocated_encoding(s
);
11955 if (!fp_access_check(s
)) {
11958 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
11960 case 0x56: /* FCVTXN, FCVTXN2 */
11962 unallocated_encoding(s
);
11966 case 0x16: /* FCVTN, FCVTN2 */
11967 /* handle_2misc_narrow does a 2*size -> size operation, but these
11968 * instructions encode the source size rather than dest size.
11970 if (!fp_access_check(s
)) {
11973 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
11975 case 0x17: /* FCVTL, FCVTL2 */
11976 if (!fp_access_check(s
)) {
11979 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
11981 case 0x18: /* FRINTN */
11982 case 0x19: /* FRINTM */
11983 case 0x38: /* FRINTP */
11984 case 0x39: /* FRINTZ */
11986 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
11988 case 0x59: /* FRINTX */
11989 case 0x79: /* FRINTI */
11990 need_fpstatus
= true;
11991 if (size
== 3 && !is_q
) {
11992 unallocated_encoding(s
);
11996 case 0x58: /* FRINTA */
11998 rmode
= FPROUNDING_TIEAWAY
;
11999 need_fpstatus
= true;
12000 if (size
== 3 && !is_q
) {
12001 unallocated_encoding(s
);
12005 case 0x7c: /* URSQRTE */
12007 unallocated_encoding(s
);
12010 need_fpstatus
= true;
12013 unallocated_encoding(s
);
12019 unallocated_encoding(s
);
12023 if (!fp_access_check(s
)) {
12027 if (need_fpstatus
|| need_rmode
) {
12028 tcg_fpstatus
= get_fpstatus_ptr(false);
12030 tcg_fpstatus
= NULL
;
12033 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12034 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12041 if (u
&& size
== 0) { /* NOT */
12042 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_not
, 0);
12048 gen_gvec_fn2(s
, is_q
, rd
, rn
, tcg_gen_gvec_neg
, size
);
12055 /* All 64-bit element operations can be shared with scalar 2misc */
12058 /* Coverity claims (size == 3 && !is_q) has been eliminated
12059 * from all paths leading to here.
12061 tcg_debug_assert(is_q
);
12062 for (pass
= 0; pass
< 2; pass
++) {
12063 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12064 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12066 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12068 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
12069 tcg_rmode
, tcg_fpstatus
);
12071 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12073 tcg_temp_free_i64(tcg_res
);
12074 tcg_temp_free_i64(tcg_op
);
12079 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
12080 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12081 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12084 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
12087 /* Special cases for 32 bit elements */
12089 case 0xa: /* CMLT */
12090 /* 32 bit integer comparison against zero, result is
12091 * test ? (2^32 - 1) : 0. We implement via setcond(test)
12094 cond
= TCG_COND_LT
;
12096 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
12097 tcg_gen_neg_i32(tcg_res
, tcg_res
);
12099 case 0x8: /* CMGT, CMGE */
12100 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
12102 case 0x9: /* CMEQ, CMLE */
12103 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
12105 case 0x4: /* CLS */
12107 tcg_gen_clzi_i32(tcg_res
, tcg_op
, 32);
12109 tcg_gen_clrsb_i32(tcg_res
, tcg_op
);
12112 case 0x7: /* SQABS, SQNEG */
12114 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
12116 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
12119 case 0xb: /* ABS, NEG */
12121 tcg_gen_neg_i32(tcg_res
, tcg_op
);
12123 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12124 tcg_gen_neg_i32(tcg_res
, tcg_op
);
12125 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
12126 tcg_zero
, tcg_op
, tcg_res
);
12127 tcg_temp_free_i32(tcg_zero
);
12130 case 0x2f: /* FABS */
12131 gen_helper_vfp_abss(tcg_res
, tcg_op
);
12133 case 0x6f: /* FNEG */
12134 gen_helper_vfp_negs(tcg_res
, tcg_op
);
12136 case 0x7f: /* FSQRT */
12137 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
12139 case 0x1a: /* FCVTNS */
12140 case 0x1b: /* FCVTMS */
12141 case 0x1c: /* FCVTAS */
12142 case 0x3a: /* FCVTPS */
12143 case 0x3b: /* FCVTZS */
12145 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12146 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
12147 tcg_shift
, tcg_fpstatus
);
12148 tcg_temp_free_i32(tcg_shift
);
12151 case 0x5a: /* FCVTNU */
12152 case 0x5b: /* FCVTMU */
12153 case 0x5c: /* FCVTAU */
12154 case 0x7a: /* FCVTPU */
12155 case 0x7b: /* FCVTZU */
12157 TCGv_i32 tcg_shift
= tcg_const_i32(0);
12158 gen_helper_vfp_touls(tcg_res
, tcg_op
,
12159 tcg_shift
, tcg_fpstatus
);
12160 tcg_temp_free_i32(tcg_shift
);
12163 case 0x18: /* FRINTN */
12164 case 0x19: /* FRINTM */
12165 case 0x38: /* FRINTP */
12166 case 0x39: /* FRINTZ */
12167 case 0x58: /* FRINTA */
12168 case 0x79: /* FRINTI */
12169 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
12171 case 0x59: /* FRINTX */
12172 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12174 case 0x7c: /* URSQRTE */
12175 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
12178 g_assert_not_reached();
12181 /* Use helpers for 8 and 16 bit elements */
12183 case 0x5: /* CNT, RBIT */
12184 /* For these two insns size is part of the opcode specifier
12185 * (handled earlier); they always operate on byte elements.
12188 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
12190 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
12193 case 0x7: /* SQABS, SQNEG */
12195 NeonGenOneOpEnvFn
*genfn
;
12196 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
12197 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
12198 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
12200 genfn
= fns
[size
][u
];
12201 genfn(tcg_res
, cpu_env
, tcg_op
);
12204 case 0x8: /* CMGT, CMGE */
12205 case 0x9: /* CMEQ, CMLE */
12206 case 0xa: /* CMLT */
12208 static NeonGenTwoOpFn
* const fns
[3][2] = {
12209 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
12210 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
12211 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
12213 NeonGenTwoOpFn
*genfn
;
12216 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12218 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
12219 comp
= (opcode
- 0x8) * 2 + u
;
12220 /* ...but LE, LT are implemented as reverse GE, GT */
12221 reverse
= (comp
> 2);
12225 genfn
= fns
[comp
][size
];
12227 genfn(tcg_res
, tcg_zero
, tcg_op
);
12229 genfn(tcg_res
, tcg_op
, tcg_zero
);
12231 tcg_temp_free_i32(tcg_zero
);
12234 case 0xb: /* ABS, NEG */
12236 TCGv_i32 tcg_zero
= tcg_const_i32(0);
12238 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
12240 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
12242 tcg_temp_free_i32(tcg_zero
);
12245 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
12247 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
12251 case 0x4: /* CLS, CLZ */
12254 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
12256 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
12260 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
12262 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
12267 g_assert_not_reached();
12271 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
12273 tcg_temp_free_i32(tcg_res
);
12274 tcg_temp_free_i32(tcg_op
);
12277 clear_vec_high(s
, is_q
, rd
);
12280 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12281 tcg_temp_free_i32(tcg_rmode
);
12283 if (need_fpstatus
) {
12284 tcg_temp_free_ptr(tcg_fpstatus
);
12288 /* AdvSIMD [scalar] two register miscellaneous (FP16)
12290 * 31 30 29 28 27 24 23 22 21 17 16 12 11 10 9 5 4 0
12291 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12292 * | 0 | Q | U | S | 1 1 1 0 | a | 1 1 1 1 0 0 | opcode | 1 0 | Rn | Rd |
12293 * +---+---+---+---+---------+---+-------------+--------+-----+------+------+
12294 * mask: 1000 1111 0111 1110 0000 1100 0000 0000 0x8f7e 0c00
12295 * val: 0000 1110 0111 1000 0000 1000 0000 0000 0x0e78 0800
12297 * This actually covers two groups where scalar access is governed by
12298 * bit 28. A bunch of the instructions (float to integral) only exist
12299 * in the vector form and are un-allocated for the scalar decode. Also
12300 * in the scalar decode Q is always 1.
12302 static void disas_simd_two_reg_misc_fp16(DisasContext
*s
, uint32_t insn
)
12304 int fpop
, opcode
, a
, u
;
12308 bool only_in_vector
= false;
12311 TCGv_i32 tcg_rmode
= NULL
;
12312 TCGv_ptr tcg_fpstatus
= NULL
;
12313 bool need_rmode
= false;
12314 bool need_fpst
= true;
12317 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
12318 unallocated_encoding(s
);
12322 rd
= extract32(insn
, 0, 5);
12323 rn
= extract32(insn
, 5, 5);
12325 a
= extract32(insn
, 23, 1);
12326 u
= extract32(insn
, 29, 1);
12327 is_scalar
= extract32(insn
, 28, 1);
12328 is_q
= extract32(insn
, 30, 1);
12330 opcode
= extract32(insn
, 12, 5);
12331 fpop
= deposit32(opcode
, 5, 1, a
);
12332 fpop
= deposit32(fpop
, 6, 1, u
);
12334 rd
= extract32(insn
, 0, 5);
12335 rn
= extract32(insn
, 5, 5);
12338 case 0x1d: /* SCVTF */
12339 case 0x5d: /* UCVTF */
12346 elements
= (is_q
? 8 : 4);
12349 if (!fp_access_check(s
)) {
12352 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !u
, 0, MO_16
);
12356 case 0x2c: /* FCMGT (zero) */
12357 case 0x2d: /* FCMEQ (zero) */
12358 case 0x2e: /* FCMLT (zero) */
12359 case 0x6c: /* FCMGE (zero) */
12360 case 0x6d: /* FCMLE (zero) */
12361 handle_2misc_fcmp_zero(s
, fpop
, is_scalar
, 0, is_q
, MO_16
, rn
, rd
);
12363 case 0x3d: /* FRECPE */
12364 case 0x3f: /* FRECPX */
12366 case 0x18: /* FRINTN */
12368 only_in_vector
= true;
12369 rmode
= FPROUNDING_TIEEVEN
;
12371 case 0x19: /* FRINTM */
12373 only_in_vector
= true;
12374 rmode
= FPROUNDING_NEGINF
;
12376 case 0x38: /* FRINTP */
12378 only_in_vector
= true;
12379 rmode
= FPROUNDING_POSINF
;
12381 case 0x39: /* FRINTZ */
12383 only_in_vector
= true;
12384 rmode
= FPROUNDING_ZERO
;
12386 case 0x58: /* FRINTA */
12388 only_in_vector
= true;
12389 rmode
= FPROUNDING_TIEAWAY
;
12391 case 0x59: /* FRINTX */
12392 case 0x79: /* FRINTI */
12393 only_in_vector
= true;
12394 /* current rounding mode */
12396 case 0x1a: /* FCVTNS */
12398 rmode
= FPROUNDING_TIEEVEN
;
12400 case 0x1b: /* FCVTMS */
12402 rmode
= FPROUNDING_NEGINF
;
12404 case 0x1c: /* FCVTAS */
12406 rmode
= FPROUNDING_TIEAWAY
;
12408 case 0x3a: /* FCVTPS */
12410 rmode
= FPROUNDING_POSINF
;
12412 case 0x3b: /* FCVTZS */
12414 rmode
= FPROUNDING_ZERO
;
12416 case 0x5a: /* FCVTNU */
12418 rmode
= FPROUNDING_TIEEVEN
;
12420 case 0x5b: /* FCVTMU */
12422 rmode
= FPROUNDING_NEGINF
;
12424 case 0x5c: /* FCVTAU */
12426 rmode
= FPROUNDING_TIEAWAY
;
12428 case 0x7a: /* FCVTPU */
12430 rmode
= FPROUNDING_POSINF
;
12432 case 0x7b: /* FCVTZU */
12434 rmode
= FPROUNDING_ZERO
;
12436 case 0x2f: /* FABS */
12437 case 0x6f: /* FNEG */
12440 case 0x7d: /* FRSQRTE */
12441 case 0x7f: /* FSQRT (vector) */
12444 fprintf(stderr
, "%s: insn %#04x fpop %#2x\n", __func__
, insn
, fpop
);
12445 g_assert_not_reached();
12449 /* Check additional constraints for the scalar encoding */
12452 unallocated_encoding(s
);
12455 /* FRINTxx is only in the vector form */
12456 if (only_in_vector
) {
12457 unallocated_encoding(s
);
12462 if (!fp_access_check(s
)) {
12466 if (need_rmode
|| need_fpst
) {
12467 tcg_fpstatus
= get_fpstatus_ptr(true);
12471 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
12472 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12476 TCGv_i32 tcg_op
= read_fp_hreg(s
, rn
);
12477 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12480 case 0x1a: /* FCVTNS */
12481 case 0x1b: /* FCVTMS */
12482 case 0x1c: /* FCVTAS */
12483 case 0x3a: /* FCVTPS */
12484 case 0x3b: /* FCVTZS */
12485 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12487 case 0x3d: /* FRECPE */
12488 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12490 case 0x3f: /* FRECPX */
12491 gen_helper_frecpx_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12493 case 0x5a: /* FCVTNU */
12494 case 0x5b: /* FCVTMU */
12495 case 0x5c: /* FCVTAU */
12496 case 0x7a: /* FCVTPU */
12497 case 0x7b: /* FCVTZU */
12498 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12500 case 0x6f: /* FNEG */
12501 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12503 case 0x7d: /* FRSQRTE */
12504 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12507 g_assert_not_reached();
12510 /* limit any sign extension going on */
12511 tcg_gen_andi_i32(tcg_res
, tcg_res
, 0xffff);
12512 write_fp_sreg(s
, rd
, tcg_res
);
12514 tcg_temp_free_i32(tcg_res
);
12515 tcg_temp_free_i32(tcg_op
);
12517 for (pass
= 0; pass
< (is_q
? 8 : 4); pass
++) {
12518 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12519 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12521 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_16
);
12524 case 0x1a: /* FCVTNS */
12525 case 0x1b: /* FCVTMS */
12526 case 0x1c: /* FCVTAS */
12527 case 0x3a: /* FCVTPS */
12528 case 0x3b: /* FCVTZS */
12529 gen_helper_advsimd_f16tosinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12531 case 0x3d: /* FRECPE */
12532 gen_helper_recpe_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12534 case 0x5a: /* FCVTNU */
12535 case 0x5b: /* FCVTMU */
12536 case 0x5c: /* FCVTAU */
12537 case 0x7a: /* FCVTPU */
12538 case 0x7b: /* FCVTZU */
12539 gen_helper_advsimd_f16touinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12541 case 0x18: /* FRINTN */
12542 case 0x19: /* FRINTM */
12543 case 0x38: /* FRINTP */
12544 case 0x39: /* FRINTZ */
12545 case 0x58: /* FRINTA */
12546 case 0x79: /* FRINTI */
12547 gen_helper_advsimd_rinth(tcg_res
, tcg_op
, tcg_fpstatus
);
12549 case 0x59: /* FRINTX */
12550 gen_helper_advsimd_rinth_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
12552 case 0x2f: /* FABS */
12553 tcg_gen_andi_i32(tcg_res
, tcg_op
, 0x7fff);
12555 case 0x6f: /* FNEG */
12556 tcg_gen_xori_i32(tcg_res
, tcg_op
, 0x8000);
12558 case 0x7d: /* FRSQRTE */
12559 gen_helper_rsqrte_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12561 case 0x7f: /* FSQRT */
12562 gen_helper_sqrt_f16(tcg_res
, tcg_op
, tcg_fpstatus
);
12565 g_assert_not_reached();
12568 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_16
);
12570 tcg_temp_free_i32(tcg_res
);
12571 tcg_temp_free_i32(tcg_op
);
12574 clear_vec_high(s
, is_q
, rd
);
12578 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, tcg_fpstatus
);
12579 tcg_temp_free_i32(tcg_rmode
);
12582 if (tcg_fpstatus
) {
12583 tcg_temp_free_ptr(tcg_fpstatus
);
12587 /* AdvSIMD scalar x indexed element
12588 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12589 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12590 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12591 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
12592 * AdvSIMD vector x indexed element
12593 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
12594 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12595 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
12596 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
12598 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
12600 /* This encoding has two kinds of instruction:
12601 * normal, where we perform elt x idxelt => elt for each
12602 * element in the vector
12603 * long, where we perform elt x idxelt and generate a result of
12604 * double the width of the input element
12605 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
12607 bool is_scalar
= extract32(insn
, 28, 1);
12608 bool is_q
= extract32(insn
, 30, 1);
12609 bool u
= extract32(insn
, 29, 1);
12610 int size
= extract32(insn
, 22, 2);
12611 int l
= extract32(insn
, 21, 1);
12612 int m
= extract32(insn
, 20, 1);
12613 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
12614 int rm
= extract32(insn
, 16, 4);
12615 int opcode
= extract32(insn
, 12, 4);
12616 int h
= extract32(insn
, 11, 1);
12617 int rn
= extract32(insn
, 5, 5);
12618 int rd
= extract32(insn
, 0, 5);
12619 bool is_long
= false;
12621 bool is_fp16
= false;
12625 switch (16 * u
+ opcode
) {
12626 case 0x08: /* MUL */
12627 case 0x10: /* MLA */
12628 case 0x14: /* MLS */
12630 unallocated_encoding(s
);
12634 case 0x02: /* SMLAL, SMLAL2 */
12635 case 0x12: /* UMLAL, UMLAL2 */
12636 case 0x06: /* SMLSL, SMLSL2 */
12637 case 0x16: /* UMLSL, UMLSL2 */
12638 case 0x0a: /* SMULL, SMULL2 */
12639 case 0x1a: /* UMULL, UMULL2 */
12641 unallocated_encoding(s
);
12646 case 0x03: /* SQDMLAL, SQDMLAL2 */
12647 case 0x07: /* SQDMLSL, SQDMLSL2 */
12648 case 0x0b: /* SQDMULL, SQDMULL2 */
12651 case 0x0c: /* SQDMULH */
12652 case 0x0d: /* SQRDMULH */
12654 case 0x01: /* FMLA */
12655 case 0x05: /* FMLS */
12656 case 0x09: /* FMUL */
12657 case 0x19: /* FMULX */
12660 case 0x1d: /* SQRDMLAH */
12661 case 0x1f: /* SQRDMLSH */
12662 if (!arm_dc_feature(s
, ARM_FEATURE_V8_RDM
)) {
12663 unallocated_encoding(s
);
12667 case 0x0e: /* SDOT */
12668 case 0x1e: /* UDOT */
12669 if (size
!= MO_32
|| !arm_dc_feature(s
, ARM_FEATURE_V8_DOTPROD
)) {
12670 unallocated_encoding(s
);
12674 case 0x11: /* FCMLA #0 */
12675 case 0x13: /* FCMLA #90 */
12676 case 0x15: /* FCMLA #180 */
12677 case 0x17: /* FCMLA #270 */
12678 if (!arm_dc_feature(s
, ARM_FEATURE_V8_FCMA
)) {
12679 unallocated_encoding(s
);
12685 unallocated_encoding(s
);
12690 case 1: /* normal fp */
12691 /* convert insn encoded size to TCGMemOp size */
12693 case 0: /* half-precision */
12697 case MO_32
: /* single precision */
12698 case MO_64
: /* double precision */
12701 unallocated_encoding(s
);
12706 case 2: /* complex fp */
12707 /* Each indexable element is a complex pair. */
12712 unallocated_encoding(s
);
12720 unallocated_encoding(s
);
12725 default: /* integer */
12729 unallocated_encoding(s
);
12734 if (is_fp16
&& !arm_dc_feature(s
, ARM_FEATURE_V8_FP16
)) {
12735 unallocated_encoding(s
);
12739 /* Given TCGMemOp size, adjust register and indexing. */
12742 index
= h
<< 2 | l
<< 1 | m
;
12745 index
= h
<< 1 | l
;
12750 unallocated_encoding(s
);
12757 g_assert_not_reached();
12760 if (!fp_access_check(s
)) {
12765 fpst
= get_fpstatus_ptr(is_fp16
);
12770 switch (16 * u
+ opcode
) {
12771 case 0x0e: /* SDOT */
12772 case 0x1e: /* UDOT */
12773 gen_gvec_op3_ool(s
, is_q
, rd
, rn
, rm
, index
,
12774 u
? gen_helper_gvec_udot_idx_b
12775 : gen_helper_gvec_sdot_idx_b
);
12777 case 0x11: /* FCMLA #0 */
12778 case 0x13: /* FCMLA #90 */
12779 case 0x15: /* FCMLA #180 */
12780 case 0x17: /* FCMLA #270 */
12782 int rot
= extract32(insn
, 13, 2);
12783 int data
= (index
<< 2) | rot
;
12784 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s
, rd
),
12785 vec_full_reg_offset(s
, rn
),
12786 vec_full_reg_offset(s
, rm
), fpst
,
12787 is_q
? 16 : 8, vec_full_reg_size(s
), data
,
12789 ? gen_helper_gvec_fcmlas_idx
12790 : gen_helper_gvec_fcmlah_idx
);
12791 tcg_temp_free_ptr(fpst
);
12797 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
12800 assert(is_fp
&& is_q
&& !is_long
);
12802 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
12804 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
12805 TCGv_i64 tcg_op
= tcg_temp_new_i64();
12806 TCGv_i64 tcg_res
= tcg_temp_new_i64();
12808 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
12810 switch (16 * u
+ opcode
) {
12811 case 0x05: /* FMLS */
12812 /* As usual for ARM, separate negation for fused multiply-add */
12813 gen_helper_vfp_negd(tcg_op
, tcg_op
);
12815 case 0x01: /* FMLA */
12816 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12817 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
12819 case 0x09: /* FMUL */
12820 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12822 case 0x19: /* FMULX */
12823 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12826 g_assert_not_reached();
12829 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
12830 tcg_temp_free_i64(tcg_op
);
12831 tcg_temp_free_i64(tcg_res
);
12834 tcg_temp_free_i64(tcg_idx
);
12835 clear_vec_high(s
, !is_scalar
, rd
);
12836 } else if (!is_long
) {
12837 /* 32 bit floating point, or 16 or 32 bit integer.
12838 * For the 16 bit scalar case we use the usual Neon helpers and
12839 * rely on the fact that 0 op 0 == 0 with no side effects.
12841 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
12842 int pass
, maxpasses
;
12847 maxpasses
= is_q
? 4 : 2;
12850 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
12852 if (size
== 1 && !is_scalar
) {
12853 /* The simplest way to handle the 16x16 indexed ops is to duplicate
12854 * the index into both halves of the 32 bit tcg_idx and then use
12855 * the usual Neon helpers.
12857 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
12860 for (pass
= 0; pass
< maxpasses
; pass
++) {
12861 TCGv_i32 tcg_op
= tcg_temp_new_i32();
12862 TCGv_i32 tcg_res
= tcg_temp_new_i32();
12864 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
12866 switch (16 * u
+ opcode
) {
12867 case 0x08: /* MUL */
12868 case 0x10: /* MLA */
12869 case 0x14: /* MLS */
12871 static NeonGenTwoOpFn
* const fns
[2][2] = {
12872 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
12873 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
12875 NeonGenTwoOpFn
*genfn
;
12876 bool is_sub
= opcode
== 0x4;
12879 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
12881 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
12883 if (opcode
== 0x8) {
12886 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
12887 genfn
= fns
[size
- 1][is_sub
];
12888 genfn(tcg_res
, tcg_op
, tcg_res
);
12891 case 0x05: /* FMLS */
12892 case 0x01: /* FMLA */
12893 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
12894 is_scalar
? size
: MO_32
);
12897 if (opcode
== 0x5) {
12898 /* As usual for ARM, separate negation for fused
12900 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80008000);
12903 gen_helper_advsimd_muladdh(tcg_res
, tcg_op
, tcg_idx
,
12906 gen_helper_advsimd_muladd2h(tcg_res
, tcg_op
, tcg_idx
,
12911 if (opcode
== 0x5) {
12912 /* As usual for ARM, separate negation for
12913 * fused multiply-add */
12914 tcg_gen_xori_i32(tcg_op
, tcg_op
, 0x80000000);
12916 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
,
12920 g_assert_not_reached();
12923 case 0x09: /* FMUL */
12927 gen_helper_advsimd_mulh(tcg_res
, tcg_op
,
12930 gen_helper_advsimd_mul2h(tcg_res
, tcg_op
,
12935 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12938 g_assert_not_reached();
12941 case 0x19: /* FMULX */
12945 gen_helper_advsimd_mulxh(tcg_res
, tcg_op
,
12948 gen_helper_advsimd_mulx2h(tcg_res
, tcg_op
,
12953 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
12956 g_assert_not_reached();
12959 case 0x0c: /* SQDMULH */
12961 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
12964 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
12968 case 0x0d: /* SQRDMULH */
12970 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
12973 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
12977 case 0x1d: /* SQRDMLAH */
12978 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
12979 is_scalar
? size
: MO_32
);
12981 gen_helper_neon_qrdmlah_s16(tcg_res
, cpu_env
,
12982 tcg_op
, tcg_idx
, tcg_res
);
12984 gen_helper_neon_qrdmlah_s32(tcg_res
, cpu_env
,
12985 tcg_op
, tcg_idx
, tcg_res
);
12988 case 0x1f: /* SQRDMLSH */
12989 read_vec_element_i32(s
, tcg_res
, rd
, pass
,
12990 is_scalar
? size
: MO_32
);
12992 gen_helper_neon_qrdmlsh_s16(tcg_res
, cpu_env
,
12993 tcg_op
, tcg_idx
, tcg_res
);
12995 gen_helper_neon_qrdmlsh_s32(tcg_res
, cpu_env
,
12996 tcg_op
, tcg_idx
, tcg_res
);
13000 g_assert_not_reached();
13004 write_fp_sreg(s
, rd
, tcg_res
);
13006 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
13009 tcg_temp_free_i32(tcg_op
);
13010 tcg_temp_free_i32(tcg_res
);
13013 tcg_temp_free_i32(tcg_idx
);
13014 clear_vec_high(s
, is_q
, rd
);
13016 /* long ops: 16x16->32 or 32x32->64 */
13017 TCGv_i64 tcg_res
[2];
13019 bool satop
= extract32(opcode
, 0, 1);
13020 TCGMemOp memop
= MO_32
;
13027 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
13029 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
13031 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13032 TCGv_i64 tcg_op
= tcg_temp_new_i64();
13033 TCGv_i64 tcg_passres
;
13039 passelt
= pass
+ (is_q
* 2);
13042 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
13044 tcg_res
[pass
] = tcg_temp_new_i64();
13046 if (opcode
== 0xa || opcode
== 0xb) {
13047 /* Non-accumulating ops */
13048 tcg_passres
= tcg_res
[pass
];
13050 tcg_passres
= tcg_temp_new_i64();
13053 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
13054 tcg_temp_free_i64(tcg_op
);
13057 /* saturating, doubling */
13058 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
13059 tcg_passres
, tcg_passres
);
13062 if (opcode
== 0xa || opcode
== 0xb) {
13066 /* Accumulating op: handle accumulate step */
13067 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13070 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13071 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13073 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13074 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
13076 case 0x7: /* SQDMLSL, SQDMLSL2 */
13077 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
13079 case 0x3: /* SQDMLAL, SQDMLAL2 */
13080 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
13085 g_assert_not_reached();
13087 tcg_temp_free_i64(tcg_passres
);
13089 tcg_temp_free_i64(tcg_idx
);
13091 clear_vec_high(s
, !is_scalar
, rd
);
13093 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
13096 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
13099 /* The simplest way to handle the 16x16 indexed ops is to
13100 * duplicate the index into both halves of the 32 bit tcg_idx
13101 * and then use the usual Neon helpers.
13103 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
13106 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
13107 TCGv_i32 tcg_op
= tcg_temp_new_i32();
13108 TCGv_i64 tcg_passres
;
13111 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
13113 read_vec_element_i32(s
, tcg_op
, rn
,
13114 pass
+ (is_q
* 2), MO_32
);
13117 tcg_res
[pass
] = tcg_temp_new_i64();
13119 if (opcode
== 0xa || opcode
== 0xb) {
13120 /* Non-accumulating ops */
13121 tcg_passres
= tcg_res
[pass
];
13123 tcg_passres
= tcg_temp_new_i64();
13126 if (memop
& MO_SIGN
) {
13127 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
13129 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
13132 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
13133 tcg_passres
, tcg_passres
);
13135 tcg_temp_free_i32(tcg_op
);
13137 if (opcode
== 0xa || opcode
== 0xb) {
13141 /* Accumulating op: handle accumulate step */
13142 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13145 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
13146 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
13149 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
13150 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
13153 case 0x7: /* SQDMLSL, SQDMLSL2 */
13154 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
13156 case 0x3: /* SQDMLAL, SQDMLAL2 */
13157 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
13162 g_assert_not_reached();
13164 tcg_temp_free_i64(tcg_passres
);
13166 tcg_temp_free_i32(tcg_idx
);
13169 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
13174 tcg_res
[1] = tcg_const_i64(0);
13177 for (pass
= 0; pass
< 2; pass
++) {
13178 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
13179 tcg_temp_free_i64(tcg_res
[pass
]);
13184 tcg_temp_free_ptr(fpst
);
13189 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13190 * +-----------------+------+-----------+--------+-----+------+------+
13191 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13192 * +-----------------+------+-----------+--------+-----+------+------+
13194 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
13196 int size
= extract32(insn
, 22, 2);
13197 int opcode
= extract32(insn
, 12, 5);
13198 int rn
= extract32(insn
, 5, 5);
13199 int rd
= extract32(insn
, 0, 5);
13201 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13202 TCGv_i32 tcg_decrypt
;
13203 CryptoThreeOpIntFn
*genfn
;
13205 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)
13207 unallocated_encoding(s
);
13212 case 0x4: /* AESE */
13214 genfn
= gen_helper_crypto_aese
;
13216 case 0x6: /* AESMC */
13218 genfn
= gen_helper_crypto_aesmc
;
13220 case 0x5: /* AESD */
13222 genfn
= gen_helper_crypto_aese
;
13224 case 0x7: /* AESIMC */
13226 genfn
= gen_helper_crypto_aesmc
;
13229 unallocated_encoding(s
);
13233 if (!fp_access_check(s
)) {
13237 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13238 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13239 tcg_decrypt
= tcg_const_i32(decrypt
);
13241 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_decrypt
);
13243 tcg_temp_free_ptr(tcg_rd_ptr
);
13244 tcg_temp_free_ptr(tcg_rn_ptr
);
13245 tcg_temp_free_i32(tcg_decrypt
);
13248 /* Crypto three-reg SHA
13249 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
13250 * +-----------------+------+---+------+---+--------+-----+------+------+
13251 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
13252 * +-----------------+------+---+------+---+--------+-----+------+------+
13254 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
13256 int size
= extract32(insn
, 22, 2);
13257 int opcode
= extract32(insn
, 12, 3);
13258 int rm
= extract32(insn
, 16, 5);
13259 int rn
= extract32(insn
, 5, 5);
13260 int rd
= extract32(insn
, 0, 5);
13261 CryptoThreeOpFn
*genfn
;
13262 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13263 int feature
= ARM_FEATURE_V8_SHA256
;
13266 unallocated_encoding(s
);
13271 case 0: /* SHA1C */
13272 case 1: /* SHA1P */
13273 case 2: /* SHA1M */
13274 case 3: /* SHA1SU0 */
13276 feature
= ARM_FEATURE_V8_SHA1
;
13278 case 4: /* SHA256H */
13279 genfn
= gen_helper_crypto_sha256h
;
13281 case 5: /* SHA256H2 */
13282 genfn
= gen_helper_crypto_sha256h2
;
13284 case 6: /* SHA256SU1 */
13285 genfn
= gen_helper_crypto_sha256su1
;
13288 unallocated_encoding(s
);
13292 if (!arm_dc_feature(s
, feature
)) {
13293 unallocated_encoding(s
);
13297 if (!fp_access_check(s
)) {
13301 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13302 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13303 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13306 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13308 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
13310 gen_helper_crypto_sha1_3reg(tcg_rd_ptr
, tcg_rn_ptr
,
13311 tcg_rm_ptr
, tcg_opcode
);
13312 tcg_temp_free_i32(tcg_opcode
);
13315 tcg_temp_free_ptr(tcg_rd_ptr
);
13316 tcg_temp_free_ptr(tcg_rn_ptr
);
13317 tcg_temp_free_ptr(tcg_rm_ptr
);
13320 /* Crypto two-reg SHA
13321 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
13322 * +-----------------+------+-----------+--------+-----+------+------+
13323 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
13324 * +-----------------+------+-----------+--------+-----+------+------+
13326 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
13328 int size
= extract32(insn
, 22, 2);
13329 int opcode
= extract32(insn
, 12, 5);
13330 int rn
= extract32(insn
, 5, 5);
13331 int rd
= extract32(insn
, 0, 5);
13332 CryptoTwoOpFn
*genfn
;
13334 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13337 unallocated_encoding(s
);
13342 case 0: /* SHA1H */
13343 feature
= ARM_FEATURE_V8_SHA1
;
13344 genfn
= gen_helper_crypto_sha1h
;
13346 case 1: /* SHA1SU1 */
13347 feature
= ARM_FEATURE_V8_SHA1
;
13348 genfn
= gen_helper_crypto_sha1su1
;
13350 case 2: /* SHA256SU0 */
13351 feature
= ARM_FEATURE_V8_SHA256
;
13352 genfn
= gen_helper_crypto_sha256su0
;
13355 unallocated_encoding(s
);
13359 if (!arm_dc_feature(s
, feature
)) {
13360 unallocated_encoding(s
);
13364 if (!fp_access_check(s
)) {
13368 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13369 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13371 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13373 tcg_temp_free_ptr(tcg_rd_ptr
);
13374 tcg_temp_free_ptr(tcg_rn_ptr
);
13377 /* Crypto three-reg SHA512
13378 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13379 * +-----------------------+------+---+---+-----+--------+------+------+
13380 * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd |
13381 * +-----------------------+------+---+---+-----+--------+------+------+
13383 static void disas_crypto_three_reg_sha512(DisasContext
*s
, uint32_t insn
)
13385 int opcode
= extract32(insn
, 10, 2);
13386 int o
= extract32(insn
, 14, 1);
13387 int rm
= extract32(insn
, 16, 5);
13388 int rn
= extract32(insn
, 5, 5);
13389 int rd
= extract32(insn
, 0, 5);
13391 CryptoThreeOpFn
*genfn
;
13395 case 0: /* SHA512H */
13396 feature
= ARM_FEATURE_V8_SHA512
;
13397 genfn
= gen_helper_crypto_sha512h
;
13399 case 1: /* SHA512H2 */
13400 feature
= ARM_FEATURE_V8_SHA512
;
13401 genfn
= gen_helper_crypto_sha512h2
;
13403 case 2: /* SHA512SU1 */
13404 feature
= ARM_FEATURE_V8_SHA512
;
13405 genfn
= gen_helper_crypto_sha512su1
;
13408 feature
= ARM_FEATURE_V8_SHA3
;
13414 case 0: /* SM3PARTW1 */
13415 feature
= ARM_FEATURE_V8_SM3
;
13416 genfn
= gen_helper_crypto_sm3partw1
;
13418 case 1: /* SM3PARTW2 */
13419 feature
= ARM_FEATURE_V8_SM3
;
13420 genfn
= gen_helper_crypto_sm3partw2
;
13422 case 2: /* SM4EKEY */
13423 feature
= ARM_FEATURE_V8_SM4
;
13424 genfn
= gen_helper_crypto_sm4ekey
;
13427 unallocated_encoding(s
);
13432 if (!arm_dc_feature(s
, feature
)) {
13433 unallocated_encoding(s
);
13437 if (!fp_access_check(s
)) {
13442 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13444 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13445 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13446 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13448 genfn(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
);
13450 tcg_temp_free_ptr(tcg_rd_ptr
);
13451 tcg_temp_free_ptr(tcg_rn_ptr
);
13452 tcg_temp_free_ptr(tcg_rm_ptr
);
13454 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13457 tcg_op1
= tcg_temp_new_i64();
13458 tcg_op2
= tcg_temp_new_i64();
13459 tcg_res
[0] = tcg_temp_new_i64();
13460 tcg_res
[1] = tcg_temp_new_i64();
13462 for (pass
= 0; pass
< 2; pass
++) {
13463 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13464 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13466 tcg_gen_rotli_i64(tcg_res
[pass
], tcg_op2
, 1);
13467 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13469 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13470 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13472 tcg_temp_free_i64(tcg_op1
);
13473 tcg_temp_free_i64(tcg_op2
);
13474 tcg_temp_free_i64(tcg_res
[0]);
13475 tcg_temp_free_i64(tcg_res
[1]);
13479 /* Crypto two-reg SHA512
13480 * 31 12 11 10 9 5 4 0
13481 * +-----------------------------------------+--------+------+------+
13482 * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd |
13483 * +-----------------------------------------+--------+------+------+
13485 static void disas_crypto_two_reg_sha512(DisasContext
*s
, uint32_t insn
)
13487 int opcode
= extract32(insn
, 10, 2);
13488 int rn
= extract32(insn
, 5, 5);
13489 int rd
= extract32(insn
, 0, 5);
13490 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
;
13492 CryptoTwoOpFn
*genfn
;
13495 case 0: /* SHA512SU0 */
13496 feature
= ARM_FEATURE_V8_SHA512
;
13497 genfn
= gen_helper_crypto_sha512su0
;
13500 feature
= ARM_FEATURE_V8_SM4
;
13501 genfn
= gen_helper_crypto_sm4e
;
13504 unallocated_encoding(s
);
13508 if (!arm_dc_feature(s
, feature
)) {
13509 unallocated_encoding(s
);
13513 if (!fp_access_check(s
)) {
13517 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13518 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13520 genfn(tcg_rd_ptr
, tcg_rn_ptr
);
13522 tcg_temp_free_ptr(tcg_rd_ptr
);
13523 tcg_temp_free_ptr(tcg_rn_ptr
);
13526 /* Crypto four-register
13527 * 31 23 22 21 20 16 15 14 10 9 5 4 0
13528 * +-------------------+-----+------+---+------+------+------+
13529 * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd |
13530 * +-------------------+-----+------+---+------+------+------+
13532 static void disas_crypto_four_reg(DisasContext
*s
, uint32_t insn
)
13534 int op0
= extract32(insn
, 21, 2);
13535 int rm
= extract32(insn
, 16, 5);
13536 int ra
= extract32(insn
, 10, 5);
13537 int rn
= extract32(insn
, 5, 5);
13538 int rd
= extract32(insn
, 0, 5);
13544 feature
= ARM_FEATURE_V8_SHA3
;
13546 case 2: /* SM3SS1 */
13547 feature
= ARM_FEATURE_V8_SM3
;
13550 unallocated_encoding(s
);
13554 if (!arm_dc_feature(s
, feature
)) {
13555 unallocated_encoding(s
);
13559 if (!fp_access_check(s
)) {
13564 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
[2];
13567 tcg_op1
= tcg_temp_new_i64();
13568 tcg_op2
= tcg_temp_new_i64();
13569 tcg_op3
= tcg_temp_new_i64();
13570 tcg_res
[0] = tcg_temp_new_i64();
13571 tcg_res
[1] = tcg_temp_new_i64();
13573 for (pass
= 0; pass
< 2; pass
++) {
13574 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13575 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13576 read_vec_element(s
, tcg_op3
, ra
, pass
, MO_64
);
13580 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13583 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op2
, tcg_op3
);
13585 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
13587 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13588 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13590 tcg_temp_free_i64(tcg_op1
);
13591 tcg_temp_free_i64(tcg_op2
);
13592 tcg_temp_free_i64(tcg_op3
);
13593 tcg_temp_free_i64(tcg_res
[0]);
13594 tcg_temp_free_i64(tcg_res
[1]);
13596 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
, tcg_res
, tcg_zero
;
13598 tcg_op1
= tcg_temp_new_i32();
13599 tcg_op2
= tcg_temp_new_i32();
13600 tcg_op3
= tcg_temp_new_i32();
13601 tcg_res
= tcg_temp_new_i32();
13602 tcg_zero
= tcg_const_i32(0);
13604 read_vec_element_i32(s
, tcg_op1
, rn
, 3, MO_32
);
13605 read_vec_element_i32(s
, tcg_op2
, rm
, 3, MO_32
);
13606 read_vec_element_i32(s
, tcg_op3
, ra
, 3, MO_32
);
13608 tcg_gen_rotri_i32(tcg_res
, tcg_op1
, 20);
13609 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op2
);
13610 tcg_gen_add_i32(tcg_res
, tcg_res
, tcg_op3
);
13611 tcg_gen_rotri_i32(tcg_res
, tcg_res
, 25);
13613 write_vec_element_i32(s
, tcg_zero
, rd
, 0, MO_32
);
13614 write_vec_element_i32(s
, tcg_zero
, rd
, 1, MO_32
);
13615 write_vec_element_i32(s
, tcg_zero
, rd
, 2, MO_32
);
13616 write_vec_element_i32(s
, tcg_res
, rd
, 3, MO_32
);
13618 tcg_temp_free_i32(tcg_op1
);
13619 tcg_temp_free_i32(tcg_op2
);
13620 tcg_temp_free_i32(tcg_op3
);
13621 tcg_temp_free_i32(tcg_res
);
13622 tcg_temp_free_i32(tcg_zero
);
13627 * 31 21 20 16 15 10 9 5 4 0
13628 * +-----------------------+------+--------+------+------+
13629 * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd |
13630 * +-----------------------+------+--------+------+------+
13632 static void disas_crypto_xar(DisasContext
*s
, uint32_t insn
)
13634 int rm
= extract32(insn
, 16, 5);
13635 int imm6
= extract32(insn
, 10, 6);
13636 int rn
= extract32(insn
, 5, 5);
13637 int rd
= extract32(insn
, 0, 5);
13638 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
13641 if (!arm_dc_feature(s
, ARM_FEATURE_V8_SHA3
)) {
13642 unallocated_encoding(s
);
13646 if (!fp_access_check(s
)) {
13650 tcg_op1
= tcg_temp_new_i64();
13651 tcg_op2
= tcg_temp_new_i64();
13652 tcg_res
[0] = tcg_temp_new_i64();
13653 tcg_res
[1] = tcg_temp_new_i64();
13655 for (pass
= 0; pass
< 2; pass
++) {
13656 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
13657 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
13659 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
13660 tcg_gen_rotri_i64(tcg_res
[pass
], tcg_res
[pass
], imm6
);
13662 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
13663 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
13665 tcg_temp_free_i64(tcg_op1
);
13666 tcg_temp_free_i64(tcg_op2
);
13667 tcg_temp_free_i64(tcg_res
[0]);
13668 tcg_temp_free_i64(tcg_res
[1]);
13671 /* Crypto three-reg imm2
13672 * 31 21 20 16 15 14 13 12 11 10 9 5 4 0
13673 * +-----------------------+------+-----+------+--------+------+------+
13674 * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd |
13675 * +-----------------------+------+-----+------+--------+------+------+
13677 static void disas_crypto_three_reg_imm2(DisasContext
*s
, uint32_t insn
)
13679 int opcode
= extract32(insn
, 10, 2);
13680 int imm2
= extract32(insn
, 12, 2);
13681 int rm
= extract32(insn
, 16, 5);
13682 int rn
= extract32(insn
, 5, 5);
13683 int rd
= extract32(insn
, 0, 5);
13684 TCGv_ptr tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
;
13685 TCGv_i32 tcg_imm2
, tcg_opcode
;
13687 if (!arm_dc_feature(s
, ARM_FEATURE_V8_SM3
)) {
13688 unallocated_encoding(s
);
13692 if (!fp_access_check(s
)) {
13696 tcg_rd_ptr
= vec_full_reg_ptr(s
, rd
);
13697 tcg_rn_ptr
= vec_full_reg_ptr(s
, rn
);
13698 tcg_rm_ptr
= vec_full_reg_ptr(s
, rm
);
13699 tcg_imm2
= tcg_const_i32(imm2
);
13700 tcg_opcode
= tcg_const_i32(opcode
);
13702 gen_helper_crypto_sm3tt(tcg_rd_ptr
, tcg_rn_ptr
, tcg_rm_ptr
, tcg_imm2
,
13705 tcg_temp_free_ptr(tcg_rd_ptr
);
13706 tcg_temp_free_ptr(tcg_rn_ptr
);
13707 tcg_temp_free_ptr(tcg_rm_ptr
);
13708 tcg_temp_free_i32(tcg_imm2
);
13709 tcg_temp_free_i32(tcg_opcode
);
13712 /* C3.6 Data processing - SIMD, inc Crypto
13714 * As the decode gets a little complex we are using a table based
13715 * approach for this part of the decode.
13717 static const AArch64DecodeTable data_proc_simd
[] = {
13718 /* pattern , mask , fn */
13719 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
13720 { 0x0e008400, 0x9f208400, disas_simd_three_reg_same_extra
},
13721 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
13722 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
13723 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
13724 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
13725 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
13726 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
13727 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
13728 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
13729 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
13730 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
13731 { 0x2e000000, 0xbf208400, disas_simd_ext
},
13732 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
13733 { 0x5e008400, 0xdf208400, disas_simd_scalar_three_reg_same_extra
},
13734 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
13735 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
13736 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
13737 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
13738 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
13739 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
13740 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
13741 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
13742 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
13743 { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512
},
13744 { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512
},
13745 { 0xce000000, 0xff808000, disas_crypto_four_reg
},
13746 { 0xce800000, 0xffe00000, disas_crypto_xar
},
13747 { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2
},
13748 { 0x0e400400, 0x9f60c400, disas_simd_three_reg_same_fp16
},
13749 { 0x0e780800, 0x8f7e0c00, disas_simd_two_reg_misc_fp16
},
13750 { 0x5e400400, 0xdf60c400, disas_simd_scalar_three_reg_same_fp16
},
13751 { 0x00000000, 0x00000000, NULL
}
13754 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
13756 /* Note that this is called with all non-FP cases from
13757 * table C3-6 so it must UNDEF for entries not specifically
13758 * allocated to instructions in that table.
13760 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
13764 unallocated_encoding(s
);
13768 /* C3.6 Data processing - SIMD and floating point */
13769 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
13771 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
13772 disas_data_proc_fp(s
, insn
);
13774 /* SIMD, including crypto */
13775 disas_data_proc_simd(s
, insn
);
13779 /* C3.1 A64 instruction index by encoding */
13780 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
13784 insn
= arm_ldl_code(env
, s
->pc
, s
->sctlr_b
);
13788 s
->fp_access_checked
= false;
13790 switch (extract32(insn
, 25, 4)) {
13791 case 0x0: case 0x1: case 0x3: /* UNALLOCATED */
13792 unallocated_encoding(s
);
13795 if (!arm_dc_feature(s
, ARM_FEATURE_SVE
) || !disas_sve(s
, insn
)) {
13796 unallocated_encoding(s
);
13799 case 0x8: case 0x9: /* Data processing - immediate */
13800 disas_data_proc_imm(s
, insn
);
13802 case 0xa: case 0xb: /* Branch, exception generation and system insns */
13803 disas_b_exc_sys(s
, insn
);
13808 case 0xe: /* Loads and stores */
13809 disas_ldst(s
, insn
);
13812 case 0xd: /* Data processing - register */
13813 disas_data_proc_reg(s
, insn
);
13816 case 0xf: /* Data processing - SIMD and floating point */
13817 disas_data_proc_simd_fp(s
, insn
);
13820 assert(FALSE
); /* all 15 cases should be handled above */
13824 /* if we allocated any temporaries, free them here */
13828 static void aarch64_tr_init_disas_context(DisasContextBase
*dcbase
,
13831 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13832 CPUARMState
*env
= cpu
->env_ptr
;
13833 ARMCPU
*arm_cpu
= arm_env_get_cpu(env
);
13836 dc
->pc
= dc
->base
.pc_first
;
13840 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
13841 * there is no secure EL1, so we route exceptions to EL3.
13843 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
13844 !arm_el_is_aa64(env
, 3);
13847 dc
->be_data
= ARM_TBFLAG_BE_DATA(dc
->base
.tb
->flags
) ? MO_BE
: MO_LE
;
13848 dc
->condexec_mask
= 0;
13849 dc
->condexec_cond
= 0;
13850 dc
->mmu_idx
= core_to_arm_mmu_idx(env
, ARM_TBFLAG_MMUIDX(dc
->base
.tb
->flags
));
13851 dc
->tbi0
= ARM_TBFLAG_TBI0(dc
->base
.tb
->flags
);
13852 dc
->tbi1
= ARM_TBFLAG_TBI1(dc
->base
.tb
->flags
);
13853 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
13854 #if !defined(CONFIG_USER_ONLY)
13855 dc
->user
= (dc
->current_el
== 0);
13857 dc
->fp_excp_el
= ARM_TBFLAG_FPEXC_EL(dc
->base
.tb
->flags
);
13858 dc
->sve_excp_el
= ARM_TBFLAG_SVEEXC_EL(dc
->base
.tb
->flags
);
13859 dc
->sve_len
= (ARM_TBFLAG_ZCR_LEN(dc
->base
.tb
->flags
) + 1) * 16;
13861 dc
->vec_stride
= 0;
13862 dc
->cp_regs
= arm_cpu
->cp_regs
;
13863 dc
->features
= env
->features
;
13865 /* Single step state. The code-generation logic here is:
13867 * generate code with no special handling for single-stepping (except
13868 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
13869 * this happens anyway because those changes are all system register or
13871 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
13872 * emit code for one insn
13873 * emit code to clear PSTATE.SS
13874 * emit code to generate software step exception for completed step
13875 * end TB (as usual for having generated an exception)
13876 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
13877 * emit code to generate a software step exception
13880 dc
->ss_active
= ARM_TBFLAG_SS_ACTIVE(dc
->base
.tb
->flags
);
13881 dc
->pstate_ss
= ARM_TBFLAG_PSTATE_SS(dc
->base
.tb
->flags
);
13882 dc
->is_ldex
= false;
13883 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
13885 /* Bound the number of insns to execute to those left on the page. */
13886 bound
= -(dc
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
13888 /* If architectural single step active, limit to 1. */
13889 if (dc
->ss_active
) {
13892 dc
->base
.max_insns
= MIN(dc
->base
.max_insns
, bound
);
13894 init_tmp_a64_array(dc
);
13897 static void aarch64_tr_tb_start(DisasContextBase
*db
, CPUState
*cpu
)
13899 tcg_clear_temp_count();
13902 static void aarch64_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cpu
)
13904 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13906 tcg_gen_insn_start(dc
->pc
, 0, 0);
13907 dc
->insn_start
= tcg_last_op();
13910 static bool aarch64_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cpu
,
13911 const CPUBreakpoint
*bp
)
13913 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13915 if (bp
->flags
& BP_CPU
) {
13916 gen_a64_set_pc_im(dc
->pc
);
13917 gen_helper_check_breakpoints(cpu_env
);
13918 /* End the TB early; it likely won't be executed */
13919 dc
->base
.is_jmp
= DISAS_TOO_MANY
;
13921 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
13922 /* The address covered by the breakpoint must be
13923 included in [tb->pc, tb->pc + tb->size) in order
13924 to for it to be properly cleared -- thus we
13925 increment the PC here so that the logic setting
13926 tb->size below does the right thing. */
13928 dc
->base
.is_jmp
= DISAS_NORETURN
;
13934 static void aarch64_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cpu
)
13936 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13937 CPUARMState
*env
= cpu
->env_ptr
;
13939 if (dc
->ss_active
&& !dc
->pstate_ss
) {
13940 /* Singlestep state is Active-pending.
13941 * If we're in this state at the start of a TB then either
13942 * a) we just took an exception to an EL which is being debugged
13943 * and this is the first insn in the exception handler
13944 * b) debug exceptions were masked and we just unmasked them
13945 * without changing EL (eg by clearing PSTATE.D)
13946 * In either case we're going to take a swstep exception in the
13947 * "did not step an insn" case, and so the syndrome ISV and EX
13948 * bits should be zero.
13950 assert(dc
->base
.num_insns
== 1);
13951 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0),
13952 default_exception_el(dc
));
13953 dc
->base
.is_jmp
= DISAS_NORETURN
;
13955 disas_a64_insn(env
, dc
);
13958 dc
->base
.pc_next
= dc
->pc
;
13959 translator_loop_temp_check(&dc
->base
);
13962 static void aarch64_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cpu
)
13964 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
13966 if (unlikely(dc
->base
.singlestep_enabled
|| dc
->ss_active
)) {
13967 /* Note that this means single stepping WFI doesn't halt the CPU.
13968 * For conditional branch insns this is harmless unreachable code as
13969 * gen_goto_tb() has already handled emitting the debug exception
13970 * (and thus a tb-jump is not possible when singlestepping).
13972 switch (dc
->base
.is_jmp
) {
13974 gen_a64_set_pc_im(dc
->pc
);
13978 if (dc
->base
.singlestep_enabled
) {
13979 gen_exception_internal(EXCP_DEBUG
);
13981 gen_step_complete_exception(dc
);
13984 case DISAS_NORETURN
:
13988 switch (dc
->base
.is_jmp
) {
13990 case DISAS_TOO_MANY
:
13991 gen_goto_tb(dc
, 1, dc
->pc
);
13995 gen_a64_set_pc_im(dc
->pc
);
13998 tcg_gen_exit_tb(NULL
, 0);
14001 tcg_gen_lookup_and_goto_ptr();
14003 case DISAS_NORETURN
:
14007 gen_a64_set_pc_im(dc
->pc
);
14008 gen_helper_wfe(cpu_env
);
14011 gen_a64_set_pc_im(dc
->pc
);
14012 gen_helper_yield(cpu_env
);
14016 /* This is a special case because we don't want to just halt the CPU
14017 * if trying to debug across a WFI.
14019 TCGv_i32 tmp
= tcg_const_i32(4);
14021 gen_a64_set_pc_im(dc
->pc
);
14022 gen_helper_wfi(cpu_env
, tmp
);
14023 tcg_temp_free_i32(tmp
);
14024 /* The helper doesn't necessarily throw an exception, but we
14025 * must go back to the main loop to check for interrupts anyway.
14027 tcg_gen_exit_tb(NULL
, 0);
14033 /* Functions above can change dc->pc, so re-align db->pc_next */
14034 dc
->base
.pc_next
= dc
->pc
;
14037 static void aarch64_tr_disas_log(const DisasContextBase
*dcbase
,
14040 DisasContext
*dc
= container_of(dcbase
, DisasContext
, base
);
14042 qemu_log("IN: %s\n", lookup_symbol(dc
->base
.pc_first
));
14043 log_target_disas(cpu
, dc
->base
.pc_first
, dc
->base
.tb
->size
);
14046 const TranslatorOps aarch64_translator_ops
= {
14047 .init_disas_context
= aarch64_tr_init_disas_context
,
14048 .tb_start
= aarch64_tr_tb_start
,
14049 .insn_start
= aarch64_tr_insn_start
,
14050 .breakpoint_check
= aarch64_tr_breakpoint_check
,
14051 .translate_insn
= aarch64_tr_translate_insn
,
14052 .tb_stop
= aarch64_tr_tb_stop
,
14053 .disas_log
= aarch64_tr_disas_log
,