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"
26 #include "translate.h"
27 #include "internals.h"
28 #include "qemu/host-utils.h"
30 #include "exec/semihost.h"
31 #include "exec/gen-icount.h"
33 #include "exec/helper-proto.h"
34 #include "exec/helper-gen.h"
37 #include "trace-tcg.h"
39 static TCGv_i64 cpu_X
[32];
40 static TCGv_i64 cpu_pc
;
42 /* Load/store exclusive handling */
43 static TCGv_i64 cpu_exclusive_high
;
45 static const char *regnames
[] = {
46 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
47 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
48 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
49 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
53 A64_SHIFT_TYPE_LSL
= 0,
54 A64_SHIFT_TYPE_LSR
= 1,
55 A64_SHIFT_TYPE_ASR
= 2,
56 A64_SHIFT_TYPE_ROR
= 3
59 /* Table based decoder typedefs - used when the relevant bits for decode
60 * are too awkwardly scattered across the instruction (eg SIMD).
62 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
64 typedef struct AArch64DecodeTable
{
67 AArch64DecodeFn
*disas_fn
;
70 /* Function prototype for gen_ functions for calling Neon helpers */
71 typedef void NeonGenOneOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
);
72 typedef void NeonGenTwoOpFn(TCGv_i32
, TCGv_i32
, TCGv_i32
);
73 typedef void NeonGenTwoOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
, TCGv_i32
);
74 typedef void NeonGenTwo64OpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
);
75 typedef void NeonGenTwo64OpEnvFn(TCGv_i64
, TCGv_ptr
, TCGv_i64
, TCGv_i64
);
76 typedef void NeonGenNarrowFn(TCGv_i32
, TCGv_i64
);
77 typedef void NeonGenNarrowEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i64
);
78 typedef void NeonGenWidenFn(TCGv_i64
, TCGv_i32
);
79 typedef void NeonGenTwoSingleOPFn(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
80 typedef void NeonGenTwoDoubleOPFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGv_ptr
);
81 typedef void NeonGenOneOpFn(TCGv_i64
, TCGv_i64
);
82 typedef void CryptoTwoOpEnvFn(TCGv_ptr
, TCGv_i32
, TCGv_i32
);
83 typedef void CryptoThreeOpEnvFn(TCGv_ptr
, TCGv_i32
, TCGv_i32
, TCGv_i32
);
85 /* initialize TCG globals. */
86 void a64_translate_init(void)
90 cpu_pc
= tcg_global_mem_new_i64(cpu_env
,
91 offsetof(CPUARMState
, pc
),
93 for (i
= 0; i
< 32; i
++) {
94 cpu_X
[i
] = tcg_global_mem_new_i64(cpu_env
,
95 offsetof(CPUARMState
, xregs
[i
]),
99 cpu_exclusive_high
= tcg_global_mem_new_i64(cpu_env
,
100 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
103 static inline ARMMMUIdx
get_a64_user_mem_index(DisasContext
*s
)
105 /* Return the mmu_idx to use for A64 "unprivileged load/store" insns:
106 * if EL1, access as if EL0; otherwise access at current EL
108 switch (s
->mmu_idx
) {
109 case ARMMMUIdx_S12NSE1
:
110 return ARMMMUIdx_S12NSE0
;
111 case ARMMMUIdx_S1SE1
:
112 return ARMMMUIdx_S1SE0
;
114 g_assert_not_reached();
120 void aarch64_cpu_dump_state(CPUState
*cs
, FILE *f
,
121 fprintf_function cpu_fprintf
, int flags
)
123 ARMCPU
*cpu
= ARM_CPU(cs
);
124 CPUARMState
*env
= &cpu
->env
;
125 uint32_t psr
= pstate_read(env
);
127 int el
= arm_current_el(env
);
128 const char *ns_status
;
130 cpu_fprintf(f
, "PC=%016"PRIx64
" SP=%016"PRIx64
"\n",
131 env
->pc
, env
->xregs
[31]);
132 for (i
= 0; i
< 31; i
++) {
133 cpu_fprintf(f
, "X%02d=%016"PRIx64
, i
, env
->xregs
[i
]);
135 cpu_fprintf(f
, "\n");
141 if (arm_feature(env
, ARM_FEATURE_EL3
) && el
!= 3) {
142 ns_status
= env
->cp15
.scr_el3
& SCR_NS
? "NS " : "S ";
147 cpu_fprintf(f
, "\nPSTATE=%08x %c%c%c%c %sEL%d%c\n",
149 psr
& PSTATE_N
? 'N' : '-',
150 psr
& PSTATE_Z
? 'Z' : '-',
151 psr
& PSTATE_C
? 'C' : '-',
152 psr
& PSTATE_V
? 'V' : '-',
155 psr
& PSTATE_SP
? 'h' : 't');
157 if (flags
& CPU_DUMP_FPU
) {
159 for (i
= 0; i
< numvfpregs
; i
+= 2) {
160 uint64_t vlo
= float64_val(env
->vfp
.regs
[i
* 2]);
161 uint64_t vhi
= float64_val(env
->vfp
.regs
[(i
* 2) + 1]);
162 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
" ",
164 vlo
= float64_val(env
->vfp
.regs
[(i
+ 1) * 2]);
165 vhi
= float64_val(env
->vfp
.regs
[((i
+ 1) * 2) + 1]);
166 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
"\n",
169 cpu_fprintf(f
, "FPCR: %08x FPSR: %08x\n",
170 vfp_get_fpcr(env
), vfp_get_fpsr(env
));
174 void gen_a64_set_pc_im(uint64_t val
)
176 tcg_gen_movi_i64(cpu_pc
, val
);
179 typedef struct DisasCompare64
{
184 static void a64_test_cc(DisasCompare64
*c64
, int cc
)
188 arm_test_cc(&c32
, cc
);
190 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
191 * properly. The NE/EQ comparisons are also fine with this choice. */
192 c64
->cond
= c32
.cond
;
193 c64
->value
= tcg_temp_new_i64();
194 tcg_gen_ext_i32_i64(c64
->value
, c32
.value
);
199 static void a64_free_cc(DisasCompare64
*c64
)
201 tcg_temp_free_i64(c64
->value
);
204 static void gen_exception_internal(int excp
)
206 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
208 assert(excp_is_internal(excp
));
209 gen_helper_exception_internal(cpu_env
, tcg_excp
);
210 tcg_temp_free_i32(tcg_excp
);
213 static void gen_exception(int excp
, uint32_t syndrome
, uint32_t target_el
)
215 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
216 TCGv_i32 tcg_syn
= tcg_const_i32(syndrome
);
217 TCGv_i32 tcg_el
= tcg_const_i32(target_el
);
219 gen_helper_exception_with_syndrome(cpu_env
, tcg_excp
,
221 tcg_temp_free_i32(tcg_el
);
222 tcg_temp_free_i32(tcg_syn
);
223 tcg_temp_free_i32(tcg_excp
);
226 static void gen_exception_internal_insn(DisasContext
*s
, int offset
, int excp
)
228 gen_a64_set_pc_im(s
->pc
- offset
);
229 gen_exception_internal(excp
);
230 s
->is_jmp
= DISAS_EXC
;
233 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
,
234 uint32_t syndrome
, uint32_t target_el
)
236 gen_a64_set_pc_im(s
->pc
- offset
);
237 gen_exception(excp
, syndrome
, target_el
);
238 s
->is_jmp
= DISAS_EXC
;
241 static void gen_ss_advance(DisasContext
*s
)
243 /* If the singlestep state is Active-not-pending, advance to
248 gen_helper_clear_pstate_ss(cpu_env
);
252 static void gen_step_complete_exception(DisasContext
*s
)
254 /* We just completed step of an insn. Move from Active-not-pending
255 * to Active-pending, and then also take the swstep exception.
256 * This corresponds to making the (IMPDEF) choice to prioritize
257 * swstep exceptions over asynchronous exceptions taken to an exception
258 * level where debug is disabled. This choice has the advantage that
259 * we do not need to maintain internal state corresponding to the
260 * ISV/EX syndrome bits between completion of the step and generation
261 * of the exception, and our syndrome information is always correct.
264 gen_exception(EXCP_UDEF
, syn_swstep(s
->ss_same_el
, 1, s
->is_ldex
),
265 default_exception_el(s
));
266 s
->is_jmp
= DISAS_EXC
;
269 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
271 /* No direct tb linking with singlestep (either QEMU's or the ARM
272 * debug architecture kind) or deterministic io
274 if (s
->singlestep_enabled
|| s
->ss_active
|| (s
->tb
->cflags
& CF_LAST_IO
)) {
278 #ifndef CONFIG_USER_ONLY
279 /* Only link tbs from inside the same guest page */
280 if ((s
->tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
288 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
290 TranslationBlock
*tb
;
293 if (use_goto_tb(s
, n
, dest
)) {
295 gen_a64_set_pc_im(dest
);
296 tcg_gen_exit_tb((intptr_t)tb
+ n
);
297 s
->is_jmp
= DISAS_TB_JUMP
;
299 gen_a64_set_pc_im(dest
);
301 gen_step_complete_exception(s
);
302 } else if (s
->singlestep_enabled
) {
303 gen_exception_internal(EXCP_DEBUG
);
306 s
->is_jmp
= DISAS_TB_JUMP
;
311 static void unallocated_encoding(DisasContext
*s
)
313 /* Unallocated and reserved encodings are uncategorized */
314 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized(),
315 default_exception_el(s
));
318 #define unsupported_encoding(s, insn) \
320 qemu_log_mask(LOG_UNIMP, \
321 "%s:%d: unsupported instruction encoding 0x%08x " \
322 "at pc=%016" PRIx64 "\n", \
323 __FILE__, __LINE__, insn, s->pc - 4); \
324 unallocated_encoding(s); \
327 static void init_tmp_a64_array(DisasContext
*s
)
329 #ifdef CONFIG_DEBUG_TCG
331 for (i
= 0; i
< ARRAY_SIZE(s
->tmp_a64
); i
++) {
332 TCGV_UNUSED_I64(s
->tmp_a64
[i
]);
335 s
->tmp_a64_count
= 0;
338 static void free_tmp_a64(DisasContext
*s
)
341 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
342 tcg_temp_free_i64(s
->tmp_a64
[i
]);
344 init_tmp_a64_array(s
);
347 static TCGv_i64
new_tmp_a64(DisasContext
*s
)
349 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
350 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
353 static TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
355 TCGv_i64 t
= new_tmp_a64(s
);
356 tcg_gen_movi_i64(t
, 0);
361 * Register access functions
363 * These functions are used for directly accessing a register in where
364 * changes to the final register value are likely to be made. If you
365 * need to use a register for temporary calculation (e.g. index type
366 * operations) use the read_* form.
368 * B1.2.1 Register mappings
370 * In instruction register encoding 31 can refer to ZR (zero register) or
371 * the SP (stack pointer) depending on context. In QEMU's case we map SP
372 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
373 * This is the point of the _sp forms.
375 static TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
378 return new_tmp_a64_zero(s
);
384 /* register access for when 31 == SP */
385 static TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
390 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
391 * representing the register contents. This TCGv is an auto-freed
392 * temporary so it need not be explicitly freed, and may be modified.
394 static TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
396 TCGv_i64 v
= new_tmp_a64(s
);
399 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
401 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
404 tcg_gen_movi_i64(v
, 0);
409 static TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
411 TCGv_i64 v
= new_tmp_a64(s
);
413 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
415 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
420 /* We should have at some point before trying to access an FP register
421 * done the necessary access check, so assert that
422 * (a) we did the check and
423 * (b) we didn't then just plough ahead anyway if it failed.
424 * Print the instruction pattern in the abort message so we can figure
425 * out what we need to fix if a user encounters this problem in the wild.
427 static inline void assert_fp_access_checked(DisasContext
*s
)
429 #ifdef CONFIG_DEBUG_TCG
430 if (unlikely(!s
->fp_access_checked
|| s
->fp_excp_el
)) {
431 fprintf(stderr
, "target-arm: FP access check missing for "
432 "instruction 0x%08x\n", s
->insn
);
438 /* Return the offset into CPUARMState of an element of specified
439 * size, 'element' places in from the least significant end of
440 * the FP/vector register Qn.
442 static inline int vec_reg_offset(DisasContext
*s
, int regno
,
443 int element
, TCGMemOp size
)
445 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
446 #ifdef HOST_WORDS_BIGENDIAN
447 /* This is complicated slightly because vfp.regs[2n] is
448 * still the low half and vfp.regs[2n+1] the high half
449 * of the 128 bit vector, even on big endian systems.
450 * Calculate the offset assuming a fully bigendian 128 bits,
451 * then XOR to account for the order of the two 64 bit halves.
453 offs
+= (16 - ((element
+ 1) * (1 << size
)));
456 offs
+= element
* (1 << size
);
458 assert_fp_access_checked(s
);
462 /* Return the offset into CPUARMState of a slice (from
463 * the least significant end) of FP register Qn (ie
465 * (Note that this is not the same mapping as for A32; see cpu.h)
467 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
469 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
470 #ifdef HOST_WORDS_BIGENDIAN
471 offs
+= (8 - (1 << size
));
473 assert_fp_access_checked(s
);
477 /* Offset of the high half of the 128 bit vector Qn */
478 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
480 assert_fp_access_checked(s
);
481 return offsetof(CPUARMState
, vfp
.regs
[regno
* 2 + 1]);
484 /* Convenience accessors for reading and writing single and double
485 * FP registers. Writing clears the upper parts of the associated
486 * 128 bit vector register, as required by the architecture.
487 * Note that unlike the GP register accessors, the values returned
488 * by the read functions must be manually freed.
490 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
492 TCGv_i64 v
= tcg_temp_new_i64();
494 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
498 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
500 TCGv_i32 v
= tcg_temp_new_i32();
502 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
506 static void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
508 TCGv_i64 tcg_zero
= tcg_const_i64(0);
510 tcg_gen_st_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
511 tcg_gen_st_i64(tcg_zero
, cpu_env
, fp_reg_hi_offset(s
, reg
));
512 tcg_temp_free_i64(tcg_zero
);
515 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
517 TCGv_i64 tmp
= tcg_temp_new_i64();
519 tcg_gen_extu_i32_i64(tmp
, v
);
520 write_fp_dreg(s
, reg
, tmp
);
521 tcg_temp_free_i64(tmp
);
524 static TCGv_ptr
get_fpstatus_ptr(void)
526 TCGv_ptr statusptr
= tcg_temp_new_ptr();
529 /* In A64 all instructions (both FP and Neon) use the FPCR;
530 * there is no equivalent of the A32 Neon "standard FPSCR value"
531 * and all operations use vfp.fp_status.
533 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
534 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
538 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
539 * than the 32 bit equivalent.
541 static inline void gen_set_NZ64(TCGv_i64 result
)
543 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
544 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
547 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
548 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
551 gen_set_NZ64(result
);
553 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
554 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
556 tcg_gen_movi_i32(cpu_CF
, 0);
557 tcg_gen_movi_i32(cpu_VF
, 0);
560 /* dest = T0 + T1; compute C, N, V and Z flags */
561 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
564 TCGv_i64 result
, flag
, tmp
;
565 result
= tcg_temp_new_i64();
566 flag
= tcg_temp_new_i64();
567 tmp
= tcg_temp_new_i64();
569 tcg_gen_movi_i64(tmp
, 0);
570 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
572 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
574 gen_set_NZ64(result
);
576 tcg_gen_xor_i64(flag
, result
, t0
);
577 tcg_gen_xor_i64(tmp
, t0
, t1
);
578 tcg_gen_andc_i64(flag
, flag
, tmp
);
579 tcg_temp_free_i64(tmp
);
580 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
582 tcg_gen_mov_i64(dest
, result
);
583 tcg_temp_free_i64(result
);
584 tcg_temp_free_i64(flag
);
586 /* 32 bit arithmetic */
587 TCGv_i32 t0_32
= tcg_temp_new_i32();
588 TCGv_i32 t1_32
= tcg_temp_new_i32();
589 TCGv_i32 tmp
= tcg_temp_new_i32();
591 tcg_gen_movi_i32(tmp
, 0);
592 tcg_gen_extrl_i64_i32(t0_32
, t0
);
593 tcg_gen_extrl_i64_i32(t1_32
, t1
);
594 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
595 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
596 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
597 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
598 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
599 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
601 tcg_temp_free_i32(tmp
);
602 tcg_temp_free_i32(t0_32
);
603 tcg_temp_free_i32(t1_32
);
607 /* dest = T0 - T1; compute C, N, V and Z flags */
608 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
611 /* 64 bit arithmetic */
612 TCGv_i64 result
, flag
, tmp
;
614 result
= tcg_temp_new_i64();
615 flag
= tcg_temp_new_i64();
616 tcg_gen_sub_i64(result
, t0
, t1
);
618 gen_set_NZ64(result
);
620 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
621 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
623 tcg_gen_xor_i64(flag
, result
, t0
);
624 tmp
= tcg_temp_new_i64();
625 tcg_gen_xor_i64(tmp
, t0
, t1
);
626 tcg_gen_and_i64(flag
, flag
, tmp
);
627 tcg_temp_free_i64(tmp
);
628 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
629 tcg_gen_mov_i64(dest
, result
);
630 tcg_temp_free_i64(flag
);
631 tcg_temp_free_i64(result
);
633 /* 32 bit arithmetic */
634 TCGv_i32 t0_32
= tcg_temp_new_i32();
635 TCGv_i32 t1_32
= tcg_temp_new_i32();
638 tcg_gen_extrl_i64_i32(t0_32
, t0
);
639 tcg_gen_extrl_i64_i32(t1_32
, t1
);
640 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
641 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
642 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
643 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
644 tmp
= tcg_temp_new_i32();
645 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
646 tcg_temp_free_i32(t0_32
);
647 tcg_temp_free_i32(t1_32
);
648 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
649 tcg_temp_free_i32(tmp
);
650 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
654 /* dest = T0 + T1 + CF; do not compute flags. */
655 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
657 TCGv_i64 flag
= tcg_temp_new_i64();
658 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
659 tcg_gen_add_i64(dest
, t0
, t1
);
660 tcg_gen_add_i64(dest
, dest
, flag
);
661 tcg_temp_free_i64(flag
);
664 tcg_gen_ext32u_i64(dest
, dest
);
668 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
669 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
672 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
673 result
= tcg_temp_new_i64();
674 cf_64
= tcg_temp_new_i64();
675 vf_64
= tcg_temp_new_i64();
676 tmp
= tcg_const_i64(0);
678 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
679 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
680 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
681 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
682 gen_set_NZ64(result
);
684 tcg_gen_xor_i64(vf_64
, result
, t0
);
685 tcg_gen_xor_i64(tmp
, t0
, t1
);
686 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
687 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
689 tcg_gen_mov_i64(dest
, result
);
691 tcg_temp_free_i64(tmp
);
692 tcg_temp_free_i64(vf_64
);
693 tcg_temp_free_i64(cf_64
);
694 tcg_temp_free_i64(result
);
696 TCGv_i32 t0_32
, t1_32
, tmp
;
697 t0_32
= tcg_temp_new_i32();
698 t1_32
= tcg_temp_new_i32();
699 tmp
= tcg_const_i32(0);
701 tcg_gen_extrl_i64_i32(t0_32
, t0
);
702 tcg_gen_extrl_i64_i32(t1_32
, t1
);
703 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
704 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
706 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
707 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
708 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
709 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
710 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
712 tcg_temp_free_i32(tmp
);
713 tcg_temp_free_i32(t1_32
);
714 tcg_temp_free_i32(t0_32
);
719 * Load/Store generators
723 * Store from GPR register to memory.
725 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
726 TCGv_i64 tcg_addr
, int size
, int memidx
)
729 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, s
->be_data
+ size
);
732 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
733 TCGv_i64 tcg_addr
, int size
)
735 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
));
739 * Load from memory to GPR register
741 static void do_gpr_ld_memidx(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
742 int size
, bool is_signed
, bool extend
, int memidx
)
744 TCGMemOp memop
= s
->be_data
+ size
;
752 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
754 if (extend
&& is_signed
) {
756 tcg_gen_ext32u_i64(dest
, dest
);
760 static void do_gpr_ld(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
761 int size
, bool is_signed
, bool extend
)
763 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
768 * Store from FP register to memory
770 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
772 /* This writes the bottom N bits of a 128 bit wide vector to memory */
773 TCGv_i64 tmp
= tcg_temp_new_i64();
774 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
776 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
),
779 bool be
= s
->be_data
== MO_BE
;
780 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
782 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
783 tcg_gen_qemu_st_i64(tmp
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
785 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
786 tcg_gen_qemu_st_i64(tmp
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
788 tcg_temp_free_i64(tcg_hiaddr
);
791 tcg_temp_free_i64(tmp
);
795 * Load from memory to FP register
797 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
799 /* This always zero-extends and writes to a full 128 bit wide vector */
800 TCGv_i64 tmplo
= tcg_temp_new_i64();
804 TCGMemOp memop
= s
->be_data
+ size
;
805 tmphi
= tcg_const_i64(0);
806 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
808 bool be
= s
->be_data
== MO_BE
;
811 tmphi
= tcg_temp_new_i64();
812 tcg_hiaddr
= tcg_temp_new_i64();
814 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
815 tcg_gen_qemu_ld_i64(tmplo
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
817 tcg_gen_qemu_ld_i64(tmphi
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
819 tcg_temp_free_i64(tcg_hiaddr
);
822 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
823 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
825 tcg_temp_free_i64(tmplo
);
826 tcg_temp_free_i64(tmphi
);
830 * Vector load/store helpers.
832 * The principal difference between this and a FP load is that we don't
833 * zero extend as we are filling a partial chunk of the vector register.
834 * These functions don't support 128 bit loads/stores, which would be
835 * normal load/store operations.
837 * The _i32 versions are useful when operating on 32 bit quantities
838 * (eg for floating point single or using Neon helper functions).
841 /* Get value of an element within a vector register */
842 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
843 int element
, TCGMemOp memop
)
845 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
848 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
851 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
854 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
857 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
860 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
863 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
867 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
870 g_assert_not_reached();
874 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
875 int element
, TCGMemOp memop
)
877 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
880 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
883 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
886 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
889 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
893 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
896 g_assert_not_reached();
900 /* Set value of an element within a vector register */
901 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
902 int element
, TCGMemOp memop
)
904 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
907 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
910 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
913 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
916 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
919 g_assert_not_reached();
923 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
924 int destidx
, int element
, TCGMemOp memop
)
926 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
929 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
932 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
935 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
938 g_assert_not_reached();
942 /* Clear the high 64 bits of a 128 bit vector (in general non-quad
943 * vector ops all need to do this).
945 static void clear_vec_high(DisasContext
*s
, int rd
)
947 TCGv_i64 tcg_zero
= tcg_const_i64(0);
949 write_vec_element(s
, tcg_zero
, rd
, 1, MO_64
);
950 tcg_temp_free_i64(tcg_zero
);
953 /* Store from vector register to memory */
954 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
955 TCGv_i64 tcg_addr
, int size
)
957 TCGMemOp memop
= s
->be_data
+ size
;
958 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
960 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
961 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
963 tcg_temp_free_i64(tcg_tmp
);
966 /* Load from memory to vector register */
967 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
968 TCGv_i64 tcg_addr
, int size
)
970 TCGMemOp memop
= s
->be_data
+ size
;
971 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
973 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
974 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
976 tcg_temp_free_i64(tcg_tmp
);
979 /* Check that FP/Neon access is enabled. If it is, return
980 * true. If not, emit code to generate an appropriate exception,
981 * and return false; the caller should not emit any code for
982 * the instruction. Note that this check must happen after all
983 * unallocated-encoding checks (otherwise the syndrome information
984 * for the resulting exception will be incorrect).
986 static inline bool fp_access_check(DisasContext
*s
)
988 assert(!s
->fp_access_checked
);
989 s
->fp_access_checked
= true;
991 if (!s
->fp_excp_el
) {
995 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false),
1001 * This utility function is for doing register extension with an
1002 * optional shift. You will likely want to pass a temporary for the
1003 * destination register. See DecodeRegExtend() in the ARM ARM.
1005 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1006 int option
, unsigned int shift
)
1008 int extsize
= extract32(option
, 0, 2);
1009 bool is_signed
= extract32(option
, 2, 1);
1014 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1017 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1020 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1023 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1029 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1032 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1035 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1038 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1044 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1048 static inline void gen_check_sp_alignment(DisasContext
*s
)
1050 /* The AArch64 architecture mandates that (if enabled via PSTATE
1051 * or SCTLR bits) there is a check that SP is 16-aligned on every
1052 * SP-relative load or store (with an exception generated if it is not).
1053 * In line with general QEMU practice regarding misaligned accesses,
1054 * we omit these checks for the sake of guest program performance.
1055 * This function is provided as a hook so we can more easily add these
1056 * checks in future (possibly as a "favour catching guest program bugs
1057 * over speed" user selectable option).
1062 * This provides a simple table based table lookup decoder. It is
1063 * intended to be used when the relevant bits for decode are too
1064 * awkwardly placed and switch/if based logic would be confusing and
1065 * deeply nested. Since it's a linear search through the table, tables
1066 * should be kept small.
1068 * It returns the first handler where insn & mask == pattern, or
1069 * NULL if there is no match.
1070 * The table is terminated by an empty mask (i.e. 0)
1072 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1075 const AArch64DecodeTable
*tptr
= table
;
1077 while (tptr
->mask
) {
1078 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1079 return tptr
->disas_fn
;
1087 * the instruction disassembly implemented here matches
1088 * the instruction encoding classifications in chapter 3 (C3)
1089 * of the ARM Architecture Reference Manual (DDI0487A_a)
1092 /* C3.2.7 Unconditional branch (immediate)
1094 * +----+-----------+-------------------------------------+
1095 * | op | 0 0 1 0 1 | imm26 |
1096 * +----+-----------+-------------------------------------+
1098 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1100 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1102 if (insn
& (1U << 31)) {
1103 /* C5.6.26 BL Branch with link */
1104 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1107 /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
1108 gen_goto_tb(s
, 0, addr
);
1111 /* C3.2.1 Compare & branch (immediate)
1112 * 31 30 25 24 23 5 4 0
1113 * +----+-------------+----+---------------------+--------+
1114 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1115 * +----+-------------+----+---------------------+--------+
1117 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1119 unsigned int sf
, op
, rt
;
1121 TCGLabel
*label_match
;
1124 sf
= extract32(insn
, 31, 1);
1125 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1126 rt
= extract32(insn
, 0, 5);
1127 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1129 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1130 label_match
= gen_new_label();
1132 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1133 tcg_cmp
, 0, label_match
);
1135 gen_goto_tb(s
, 0, s
->pc
);
1136 gen_set_label(label_match
);
1137 gen_goto_tb(s
, 1, addr
);
1140 /* C3.2.5 Test & branch (immediate)
1141 * 31 30 25 24 23 19 18 5 4 0
1142 * +----+-------------+----+-------+-------------+------+
1143 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1144 * +----+-------------+----+-------+-------------+------+
1146 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1148 unsigned int bit_pos
, op
, rt
;
1150 TCGLabel
*label_match
;
1153 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1154 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1155 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1156 rt
= extract32(insn
, 0, 5);
1158 tcg_cmp
= tcg_temp_new_i64();
1159 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1160 label_match
= gen_new_label();
1161 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1162 tcg_cmp
, 0, label_match
);
1163 tcg_temp_free_i64(tcg_cmp
);
1164 gen_goto_tb(s
, 0, s
->pc
);
1165 gen_set_label(label_match
);
1166 gen_goto_tb(s
, 1, addr
);
1169 /* C3.2.2 / C5.6.19 Conditional branch (immediate)
1170 * 31 25 24 23 5 4 3 0
1171 * +---------------+----+---------------------+----+------+
1172 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1173 * +---------------+----+---------------------+----+------+
1175 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1180 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1181 unallocated_encoding(s
);
1184 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1185 cond
= extract32(insn
, 0, 4);
1188 /* genuinely conditional branches */
1189 TCGLabel
*label_match
= gen_new_label();
1190 arm_gen_test_cc(cond
, label_match
);
1191 gen_goto_tb(s
, 0, s
->pc
);
1192 gen_set_label(label_match
);
1193 gen_goto_tb(s
, 1, addr
);
1195 /* 0xe and 0xf are both "always" conditions */
1196 gen_goto_tb(s
, 0, addr
);
1201 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1202 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1204 unsigned int selector
= crm
<< 3 | op2
;
1207 unallocated_encoding(s
);
1215 s
->is_jmp
= DISAS_WFI
;
1218 s
->is_jmp
= DISAS_YIELD
;
1221 s
->is_jmp
= DISAS_WFE
;
1225 /* we treat all as NOP at least for now */
1228 /* default specified as NOP equivalent */
1233 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1235 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1238 /* CLREX, DSB, DMB, ISB */
1239 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1240 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1243 unallocated_encoding(s
);
1253 /* We don't emulate caches so barriers are no-ops */
1256 /* We need to break the TB after this insn to execute
1257 * a self-modified code correctly and also to take
1258 * any pending interrupts immediately.
1260 s
->is_jmp
= DISAS_UPDATE
;
1263 unallocated_encoding(s
);
1268 /* C5.6.130 MSR (immediate) - move immediate to processor state field */
1269 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1270 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1272 int op
= op1
<< 3 | op2
;
1274 case 0x05: /* SPSel */
1275 if (s
->current_el
== 0) {
1276 unallocated_encoding(s
);
1280 case 0x1e: /* DAIFSet */
1281 case 0x1f: /* DAIFClear */
1283 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1284 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1285 gen_a64_set_pc_im(s
->pc
- 4);
1286 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1287 tcg_temp_free_i32(tcg_imm
);
1288 tcg_temp_free_i32(tcg_op
);
1289 s
->is_jmp
= DISAS_UPDATE
;
1293 unallocated_encoding(s
);
1298 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1300 TCGv_i32 tmp
= tcg_temp_new_i32();
1301 TCGv_i32 nzcv
= tcg_temp_new_i32();
1303 /* build bit 31, N */
1304 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1305 /* build bit 30, Z */
1306 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1307 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1308 /* build bit 29, C */
1309 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1310 /* build bit 28, V */
1311 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1312 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1313 /* generate result */
1314 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1316 tcg_temp_free_i32(nzcv
);
1317 tcg_temp_free_i32(tmp
);
1320 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1323 TCGv_i32 nzcv
= tcg_temp_new_i32();
1325 /* take NZCV from R[t] */
1326 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1329 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1331 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1332 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1334 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1335 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1337 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1338 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1339 tcg_temp_free_i32(nzcv
);
1342 /* C5.6.129 MRS - move from system register
1343 * C5.6.131 MSR (register) - move to system register
1346 * These are all essentially the same insn in 'read' and 'write'
1347 * versions, with varying op0 fields.
1349 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1350 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1351 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1353 const ARMCPRegInfo
*ri
;
1356 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1357 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1358 crn
, crm
, op0
, op1
, op2
));
1361 /* Unknown register; this might be a guest error or a QEMU
1362 * unimplemented feature.
1364 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1365 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1366 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1367 unallocated_encoding(s
);
1371 /* Check access permissions */
1372 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1373 unallocated_encoding(s
);
1378 /* Emit code to perform further access permissions checks at
1379 * runtime; this may result in an exception.
1382 TCGv_i32 tcg_syn
, tcg_isread
;
1385 gen_a64_set_pc_im(s
->pc
- 4);
1386 tmpptr
= tcg_const_ptr(ri
);
1387 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1388 tcg_syn
= tcg_const_i32(syndrome
);
1389 tcg_isread
= tcg_const_i32(isread
);
1390 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
, tcg_isread
);
1391 tcg_temp_free_ptr(tmpptr
);
1392 tcg_temp_free_i32(tcg_syn
);
1393 tcg_temp_free_i32(tcg_isread
);
1396 /* Handle special cases first */
1397 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1401 tcg_rt
= cpu_reg(s
, rt
);
1403 gen_get_nzcv(tcg_rt
);
1405 gen_set_nzcv(tcg_rt
);
1408 case ARM_CP_CURRENTEL
:
1409 /* Reads as current EL value from pstate, which is
1410 * guaranteed to be constant by the tb flags.
1412 tcg_rt
= cpu_reg(s
, rt
);
1413 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1416 /* Writes clear the aligned block of memory which rt points into. */
1417 tcg_rt
= cpu_reg(s
, rt
);
1418 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1424 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1428 tcg_rt
= cpu_reg(s
, rt
);
1431 if (ri
->type
& ARM_CP_CONST
) {
1432 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1433 } else if (ri
->readfn
) {
1435 tmpptr
= tcg_const_ptr(ri
);
1436 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1437 tcg_temp_free_ptr(tmpptr
);
1439 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1442 if (ri
->type
& ARM_CP_CONST
) {
1443 /* If not forbidden by access permissions, treat as WI */
1445 } else if (ri
->writefn
) {
1447 tmpptr
= tcg_const_ptr(ri
);
1448 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1449 tcg_temp_free_ptr(tmpptr
);
1451 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1455 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1456 /* I/O operations must end the TB here (whether read or write) */
1458 s
->is_jmp
= DISAS_UPDATE
;
1459 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1460 /* We default to ending the TB on a coprocessor register write,
1461 * but allow this to be suppressed by the register definition
1462 * (usually only necessary to work around guest bugs).
1464 s
->is_jmp
= DISAS_UPDATE
;
1469 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1470 * +---------------------+---+-----+-----+-------+-------+-----+------+
1471 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1472 * +---------------------+---+-----+-----+-------+-------+-----+------+
1474 static void disas_system(DisasContext
*s
, uint32_t insn
)
1476 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1477 l
= extract32(insn
, 21, 1);
1478 op0
= extract32(insn
, 19, 2);
1479 op1
= extract32(insn
, 16, 3);
1480 crn
= extract32(insn
, 12, 4);
1481 crm
= extract32(insn
, 8, 4);
1482 op2
= extract32(insn
, 5, 3);
1483 rt
= extract32(insn
, 0, 5);
1486 if (l
|| rt
!= 31) {
1487 unallocated_encoding(s
);
1491 case 2: /* C5.6.68 HINT */
1492 handle_hint(s
, insn
, op1
, op2
, crm
);
1494 case 3: /* CLREX, DSB, DMB, ISB */
1495 handle_sync(s
, insn
, op1
, op2
, crm
);
1497 case 4: /* C5.6.130 MSR (immediate) */
1498 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1501 unallocated_encoding(s
);
1506 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1509 /* C3.2.3 Exception generation
1511 * 31 24 23 21 20 5 4 2 1 0
1512 * +-----------------+-----+------------------------+-----+----+
1513 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1514 * +-----------------------+------------------------+----------+
1516 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1518 int opc
= extract32(insn
, 21, 3);
1519 int op2_ll
= extract32(insn
, 0, 5);
1520 int imm16
= extract32(insn
, 5, 16);
1525 /* For SVC, HVC and SMC we advance the single-step state
1526 * machine before taking the exception. This is architecturally
1527 * mandated, to ensure that single-stepping a system call
1528 * instruction works properly.
1533 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
),
1534 default_exception_el(s
));
1537 if (s
->current_el
== 0) {
1538 unallocated_encoding(s
);
1541 /* The pre HVC helper handles cases when HVC gets trapped
1542 * as an undefined insn by runtime configuration.
1544 gen_a64_set_pc_im(s
->pc
- 4);
1545 gen_helper_pre_hvc(cpu_env
);
1547 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
), 2);
1550 if (s
->current_el
== 0) {
1551 unallocated_encoding(s
);
1554 gen_a64_set_pc_im(s
->pc
- 4);
1555 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1556 gen_helper_pre_smc(cpu_env
, tmp
);
1557 tcg_temp_free_i32(tmp
);
1559 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
), 3);
1562 unallocated_encoding(s
);
1568 unallocated_encoding(s
);
1572 gen_exception_insn(s
, 4, EXCP_BKPT
, syn_aa64_bkpt(imm16
),
1573 default_exception_el(s
));
1577 unallocated_encoding(s
);
1580 /* HLT. This has two purposes.
1581 * Architecturally, it is an external halting debug instruction.
1582 * Since QEMU doesn't implement external debug, we treat this as
1583 * it is required for halting debug disabled: it will UNDEF.
1584 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1586 if (semihosting_enabled() && imm16
== 0xf000) {
1587 #ifndef CONFIG_USER_ONLY
1588 /* In system mode, don't allow userspace access to semihosting,
1589 * to provide some semblance of security (and for consistency
1590 * with our 32-bit semihosting).
1592 if (s
->current_el
== 0) {
1593 unsupported_encoding(s
, insn
);
1597 gen_exception_internal_insn(s
, 0, EXCP_SEMIHOST
);
1599 unsupported_encoding(s
, insn
);
1603 if (op2_ll
< 1 || op2_ll
> 3) {
1604 unallocated_encoding(s
);
1607 /* DCPS1, DCPS2, DCPS3 */
1608 unsupported_encoding(s
, insn
);
1611 unallocated_encoding(s
);
1616 /* C3.2.7 Unconditional branch (register)
1617 * 31 25 24 21 20 16 15 10 9 5 4 0
1618 * +---------------+-------+-------+-------+------+-------+
1619 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1620 * +---------------+-------+-------+-------+------+-------+
1622 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1624 unsigned int opc
, op2
, op3
, rn
, op4
;
1626 opc
= extract32(insn
, 21, 4);
1627 op2
= extract32(insn
, 16, 5);
1628 op3
= extract32(insn
, 10, 6);
1629 rn
= extract32(insn
, 5, 5);
1630 op4
= extract32(insn
, 0, 5);
1632 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1633 unallocated_encoding(s
);
1640 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1643 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1644 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1647 if (s
->current_el
== 0) {
1648 unallocated_encoding(s
);
1651 gen_helper_exception_return(cpu_env
);
1652 s
->is_jmp
= DISAS_JUMP
;
1656 unallocated_encoding(s
);
1658 unsupported_encoding(s
, insn
);
1662 unallocated_encoding(s
);
1666 s
->is_jmp
= DISAS_JUMP
;
1669 /* C3.2 Branches, exception generating and system instructions */
1670 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1672 switch (extract32(insn
, 25, 7)) {
1673 case 0x0a: case 0x0b:
1674 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1675 disas_uncond_b_imm(s
, insn
);
1677 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1678 disas_comp_b_imm(s
, insn
);
1680 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1681 disas_test_b_imm(s
, insn
);
1683 case 0x2a: /* Conditional branch (immediate) */
1684 disas_cond_b_imm(s
, insn
);
1686 case 0x6a: /* Exception generation / System */
1687 if (insn
& (1 << 24)) {
1688 disas_system(s
, insn
);
1693 case 0x6b: /* Unconditional branch (register) */
1694 disas_uncond_b_reg(s
, insn
);
1697 unallocated_encoding(s
);
1703 * Load/Store exclusive instructions are implemented by remembering
1704 * the value/address loaded, and seeing if these are the same
1705 * when the store is performed. This is not actually the architecturally
1706 * mandated semantics, but it works for typical guest code sequences
1707 * and avoids having to monitor regular stores.
1709 * In system emulation mode only one CPU will be running at once, so
1710 * this sequence is effectively atomic. In user emulation mode we
1711 * throw an exception and handle the atomic operation elsewhere.
1713 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
1714 TCGv_i64 addr
, int size
, bool is_pair
)
1716 TCGv_i64 tmp
= tcg_temp_new_i64();
1717 TCGMemOp memop
= s
->be_data
+ size
;
1719 g_assert(size
<= 3);
1720 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), memop
);
1723 TCGv_i64 addr2
= tcg_temp_new_i64();
1724 TCGv_i64 hitmp
= tcg_temp_new_i64();
1726 g_assert(size
>= 2);
1727 tcg_gen_addi_i64(addr2
, addr
, 1 << size
);
1728 tcg_gen_qemu_ld_i64(hitmp
, addr2
, get_mem_index(s
), memop
);
1729 tcg_temp_free_i64(addr2
);
1730 tcg_gen_mov_i64(cpu_exclusive_high
, hitmp
);
1731 tcg_gen_mov_i64(cpu_reg(s
, rt2
), hitmp
);
1732 tcg_temp_free_i64(hitmp
);
1735 tcg_gen_mov_i64(cpu_exclusive_val
, tmp
);
1736 tcg_gen_mov_i64(cpu_reg(s
, rt
), tmp
);
1738 tcg_temp_free_i64(tmp
);
1739 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
1742 #ifdef CONFIG_USER_ONLY
1743 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1744 TCGv_i64 addr
, int size
, int is_pair
)
1746 tcg_gen_mov_i64(cpu_exclusive_test
, addr
);
1747 tcg_gen_movi_i32(cpu_exclusive_info
,
1748 size
| is_pair
<< 2 | (rd
<< 4) | (rt
<< 9) | (rt2
<< 14));
1749 gen_exception_internal_insn(s
, 4, EXCP_STREX
);
1752 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1753 TCGv_i64 inaddr
, int size
, int is_pair
)
1755 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1756 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1759 * [addr + datasize] = {Rt2};
1765 * env->exclusive_addr = -1;
1767 TCGLabel
*fail_label
= gen_new_label();
1768 TCGLabel
*done_label
= gen_new_label();
1769 TCGv_i64 addr
= tcg_temp_local_new_i64();
1772 /* Copy input into a local temp so it is not trashed when the
1773 * basic block ends at the branch insn.
1775 tcg_gen_mov_i64(addr
, inaddr
);
1776 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
1778 tmp
= tcg_temp_new_i64();
1779 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), s
->be_data
+ size
);
1780 tcg_gen_brcond_i64(TCG_COND_NE
, tmp
, cpu_exclusive_val
, fail_label
);
1781 tcg_temp_free_i64(tmp
);
1784 TCGv_i64 addrhi
= tcg_temp_new_i64();
1785 TCGv_i64 tmphi
= tcg_temp_new_i64();
1787 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1788 tcg_gen_qemu_ld_i64(tmphi
, addrhi
, get_mem_index(s
),
1790 tcg_gen_brcond_i64(TCG_COND_NE
, tmphi
, cpu_exclusive_high
, fail_label
);
1792 tcg_temp_free_i64(tmphi
);
1793 tcg_temp_free_i64(addrhi
);
1796 /* We seem to still have the exclusive monitor, so do the store */
1797 tcg_gen_qemu_st_i64(cpu_reg(s
, rt
), addr
, get_mem_index(s
),
1800 TCGv_i64 addrhi
= tcg_temp_new_i64();
1802 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1803 tcg_gen_qemu_st_i64(cpu_reg(s
, rt2
), addrhi
,
1804 get_mem_index(s
), s
->be_data
+ size
);
1805 tcg_temp_free_i64(addrhi
);
1808 tcg_temp_free_i64(addr
);
1810 tcg_gen_movi_i64(cpu_reg(s
, rd
), 0);
1811 tcg_gen_br(done_label
);
1812 gen_set_label(fail_label
);
1813 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
1814 gen_set_label(done_label
);
1815 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1820 /* C3.3.6 Load/store exclusive
1822 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
1823 * +-----+-------------+----+---+----+------+----+-------+------+------+
1824 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
1825 * +-----+-------------+----+---+----+------+----+-------+------+------+
1827 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
1828 * L: 0 -> store, 1 -> load
1829 * o2: 0 -> exclusive, 1 -> not
1830 * o1: 0 -> single register, 1 -> register pair
1831 * o0: 1 -> load-acquire/store-release, 0 -> not
1833 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
1835 int rt
= extract32(insn
, 0, 5);
1836 int rn
= extract32(insn
, 5, 5);
1837 int rt2
= extract32(insn
, 10, 5);
1838 int is_lasr
= extract32(insn
, 15, 1);
1839 int rs
= extract32(insn
, 16, 5);
1840 int is_pair
= extract32(insn
, 21, 1);
1841 int is_store
= !extract32(insn
, 22, 1);
1842 int is_excl
= !extract32(insn
, 23, 1);
1843 int size
= extract32(insn
, 30, 2);
1846 if ((!is_excl
&& !is_pair
&& !is_lasr
) ||
1847 (!is_excl
&& is_pair
) ||
1848 (is_pair
&& size
< 2)) {
1849 unallocated_encoding(s
);
1854 gen_check_sp_alignment(s
);
1856 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1858 /* Note that since TCG is single threaded load-acquire/store-release
1859 * semantics require no extra if (is_lasr) { ... } handling.
1865 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1867 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1870 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1872 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1874 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, false, false);
1880 * C3.3.5 Load register (literal)
1882 * 31 30 29 27 26 25 24 23 5 4 0
1883 * +-----+-------+---+-----+-------------------+-------+
1884 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
1885 * +-----+-------+---+-----+-------------------+-------+
1887 * V: 1 -> vector (simd/fp)
1888 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
1889 * 10-> 32 bit signed, 11 -> prefetch
1890 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
1892 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
1894 int rt
= extract32(insn
, 0, 5);
1895 int64_t imm
= sextract32(insn
, 5, 19) << 2;
1896 bool is_vector
= extract32(insn
, 26, 1);
1897 int opc
= extract32(insn
, 30, 2);
1898 bool is_signed
= false;
1900 TCGv_i64 tcg_rt
, tcg_addr
;
1904 unallocated_encoding(s
);
1908 if (!fp_access_check(s
)) {
1913 /* PRFM (literal) : prefetch */
1916 size
= 2 + extract32(opc
, 0, 1);
1917 is_signed
= extract32(opc
, 1, 1);
1920 tcg_rt
= cpu_reg(s
, rt
);
1922 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
1924 do_fp_ld(s
, rt
, tcg_addr
, size
);
1926 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
1928 tcg_temp_free_i64(tcg_addr
);
1932 * C5.6.80 LDNP (Load Pair - non-temporal hint)
1933 * C5.6.81 LDP (Load Pair - non vector)
1934 * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
1935 * C5.6.176 STNP (Store Pair - non-temporal hint)
1936 * C5.6.177 STP (Store Pair - non vector)
1937 * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
1938 * C6.3.165 LDP (Load Pair of SIMD&FP)
1939 * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
1940 * C6.3.284 STP (Store Pair of SIMD&FP)
1942 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
1943 * +-----+-------+---+---+-------+---+-----------------------------+
1944 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
1945 * +-----+-------+---+---+-------+---+-------+-------+------+------+
1947 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
1949 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
1950 * V: 0 -> GPR, 1 -> Vector
1951 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
1952 * 10 -> signed offset, 11 -> pre-index
1953 * L: 0 -> Store 1 -> Load
1955 * Rt, Rt2 = GPR or SIMD registers to be stored
1956 * Rn = general purpose register containing address
1957 * imm7 = signed offset (multiple of 4 or 8 depending on size)
1959 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
1961 int rt
= extract32(insn
, 0, 5);
1962 int rn
= extract32(insn
, 5, 5);
1963 int rt2
= extract32(insn
, 10, 5);
1964 uint64_t offset
= sextract64(insn
, 15, 7);
1965 int index
= extract32(insn
, 23, 2);
1966 bool is_vector
= extract32(insn
, 26, 1);
1967 bool is_load
= extract32(insn
, 22, 1);
1968 int opc
= extract32(insn
, 30, 2);
1970 bool is_signed
= false;
1971 bool postindex
= false;
1974 TCGv_i64 tcg_addr
; /* calculated address */
1978 unallocated_encoding(s
);
1985 size
= 2 + extract32(opc
, 1, 1);
1986 is_signed
= extract32(opc
, 0, 1);
1987 if (!is_load
&& is_signed
) {
1988 unallocated_encoding(s
);
1994 case 1: /* post-index */
1999 /* signed offset with "non-temporal" hint. Since we don't emulate
2000 * caches we don't care about hints to the cache system about
2001 * data access patterns, and handle this identically to plain
2005 /* There is no non-temporal-hint version of LDPSW */
2006 unallocated_encoding(s
);
2011 case 2: /* signed offset, rn not updated */
2014 case 3: /* pre-index */
2020 if (is_vector
&& !fp_access_check(s
)) {
2027 gen_check_sp_alignment(s
);
2030 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2033 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2038 do_fp_ld(s
, rt
, tcg_addr
, size
);
2040 do_fp_st(s
, rt
, tcg_addr
, size
);
2043 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2045 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
2047 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2050 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2053 do_fp_ld(s
, rt2
, tcg_addr
, size
);
2055 do_fp_st(s
, rt2
, tcg_addr
, size
);
2058 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2060 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false);
2062 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
2068 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
2070 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2072 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
2077 * C3.3.8 Load/store (immediate post-indexed)
2078 * C3.3.9 Load/store (immediate pre-indexed)
2079 * C3.3.12 Load/store (unscaled immediate)
2081 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2082 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2083 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2084 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2086 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2088 * V = 0 -> non-vector
2089 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2090 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2092 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
2098 int rn
= extract32(insn
, 5, 5);
2099 int imm9
= sextract32(insn
, 12, 9);
2100 int idx
= extract32(insn
, 10, 2);
2101 bool is_signed
= false;
2102 bool is_store
= false;
2103 bool is_extended
= false;
2104 bool is_unpriv
= (idx
== 2);
2111 size
|= (opc
& 2) << 1;
2112 if (size
> 4 || is_unpriv
) {
2113 unallocated_encoding(s
);
2116 is_store
= ((opc
& 1) == 0);
2117 if (!fp_access_check(s
)) {
2121 if (size
== 3 && opc
== 2) {
2122 /* PRFM - prefetch */
2124 unallocated_encoding(s
);
2129 if (opc
== 3 && size
> 1) {
2130 unallocated_encoding(s
);
2133 is_store
= (opc
== 0);
2134 is_signed
= extract32(opc
, 1, 1);
2135 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2155 gen_check_sp_alignment(s
);
2157 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2160 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2165 do_fp_st(s
, rt
, tcg_addr
, size
);
2167 do_fp_ld(s
, rt
, tcg_addr
, size
);
2170 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2171 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2174 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
);
2176 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
2177 is_signed
, is_extended
, memidx
);
2182 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2184 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2186 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2191 * C3.3.10 Load/store (register offset)
2193 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2194 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2195 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2196 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2199 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2200 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2202 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2203 * opc<0>: 0 -> store, 1 -> load
2204 * V: 1 -> vector/simd
2205 * opt: extend encoding (see DecodeRegExtend)
2206 * S: if S=1 then scale (essentially index by sizeof(size))
2207 * Rt: register to transfer into/out of
2208 * Rn: address register or SP for base
2209 * Rm: offset register or ZR for offset
2211 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
2217 int rn
= extract32(insn
, 5, 5);
2218 int shift
= extract32(insn
, 12, 1);
2219 int rm
= extract32(insn
, 16, 5);
2220 int opt
= extract32(insn
, 13, 3);
2221 bool is_signed
= false;
2222 bool is_store
= false;
2223 bool is_extended
= false;
2228 if (extract32(opt
, 1, 1) == 0) {
2229 unallocated_encoding(s
);
2234 size
|= (opc
& 2) << 1;
2236 unallocated_encoding(s
);
2239 is_store
= !extract32(opc
, 0, 1);
2240 if (!fp_access_check(s
)) {
2244 if (size
== 3 && opc
== 2) {
2245 /* PRFM - prefetch */
2248 if (opc
== 3 && size
> 1) {
2249 unallocated_encoding(s
);
2252 is_store
= (opc
== 0);
2253 is_signed
= extract32(opc
, 1, 1);
2254 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2258 gen_check_sp_alignment(s
);
2260 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2262 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2263 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2265 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2269 do_fp_st(s
, rt
, tcg_addr
, size
);
2271 do_fp_ld(s
, rt
, tcg_addr
, size
);
2274 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2276 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2278 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2284 * C3.3.13 Load/store (unsigned immediate)
2286 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2287 * +----+-------+---+-----+-----+------------+-------+------+
2288 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2289 * +----+-------+---+-----+-----+------------+-------+------+
2292 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2293 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2295 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2296 * opc<0>: 0 -> store, 1 -> load
2297 * Rn: base address register (inc SP)
2298 * Rt: target register
2300 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
2306 int rn
= extract32(insn
, 5, 5);
2307 unsigned int imm12
= extract32(insn
, 10, 12);
2308 unsigned int offset
;
2313 bool is_signed
= false;
2314 bool is_extended
= false;
2317 size
|= (opc
& 2) << 1;
2319 unallocated_encoding(s
);
2322 is_store
= !extract32(opc
, 0, 1);
2323 if (!fp_access_check(s
)) {
2327 if (size
== 3 && opc
== 2) {
2328 /* PRFM - prefetch */
2331 if (opc
== 3 && size
> 1) {
2332 unallocated_encoding(s
);
2335 is_store
= (opc
== 0);
2336 is_signed
= extract32(opc
, 1, 1);
2337 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2341 gen_check_sp_alignment(s
);
2343 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2344 offset
= imm12
<< size
;
2345 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2349 do_fp_st(s
, rt
, tcg_addr
, size
);
2351 do_fp_ld(s
, rt
, tcg_addr
, size
);
2354 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2356 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2358 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2363 /* Load/store register (all forms) */
2364 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2366 int rt
= extract32(insn
, 0, 5);
2367 int opc
= extract32(insn
, 22, 2);
2368 bool is_vector
= extract32(insn
, 26, 1);
2369 int size
= extract32(insn
, 30, 2);
2371 switch (extract32(insn
, 24, 2)) {
2373 if (extract32(insn
, 21, 1) == 1 && extract32(insn
, 10, 2) == 2) {
2374 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
2376 /* Load/store register (unscaled immediate)
2377 * Load/store immediate pre/post-indexed
2378 * Load/store register unprivileged
2380 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
2384 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
2387 unallocated_encoding(s
);
2392 /* C3.3.1 AdvSIMD load/store multiple structures
2394 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2395 * +---+---+---------------+---+-------------+--------+------+------+------+
2396 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2397 * +---+---+---------------+---+-------------+--------+------+------+------+
2399 * C3.3.2 AdvSIMD load/store multiple structures (post-indexed)
2401 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2402 * +---+---+---------------+---+---+---------+--------+------+------+------+
2403 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2404 * +---+---+---------------+---+---+---------+--------+------+------+------+
2406 * Rt: first (or only) SIMD&FP register to be transferred
2407 * Rn: base address or SP
2408 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2410 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
2412 int rt
= extract32(insn
, 0, 5);
2413 int rn
= extract32(insn
, 5, 5);
2414 int size
= extract32(insn
, 10, 2);
2415 int opcode
= extract32(insn
, 12, 4);
2416 bool is_store
= !extract32(insn
, 22, 1);
2417 bool is_postidx
= extract32(insn
, 23, 1);
2418 bool is_q
= extract32(insn
, 30, 1);
2419 TCGv_i64 tcg_addr
, tcg_rn
;
2421 int ebytes
= 1 << size
;
2422 int elements
= (is_q
? 128 : 64) / (8 << size
);
2423 int rpt
; /* num iterations */
2424 int selem
; /* structure elements */
2427 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
2428 unallocated_encoding(s
);
2432 /* From the shared decode logic */
2463 unallocated_encoding(s
);
2467 if (size
== 3 && !is_q
&& selem
!= 1) {
2469 unallocated_encoding(s
);
2473 if (!fp_access_check(s
)) {
2478 gen_check_sp_alignment(s
);
2481 tcg_rn
= cpu_reg_sp(s
, rn
);
2482 tcg_addr
= tcg_temp_new_i64();
2483 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2485 for (r
= 0; r
< rpt
; r
++) {
2487 for (e
= 0; e
< elements
; e
++) {
2488 int tt
= (rt
+ r
) % 32;
2490 for (xs
= 0; xs
< selem
; xs
++) {
2492 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
2494 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
2496 /* For non-quad operations, setting a slice of the low
2497 * 64 bits of the register clears the high 64 bits (in
2498 * the ARM ARM pseudocode this is implicit in the fact
2499 * that 'rval' is a 64 bit wide variable). We optimize
2500 * by noticing that we only need to do this the first
2501 * time we touch a register.
2503 if (!is_q
&& e
== 0 && (r
== 0 || xs
== selem
- 1)) {
2504 clear_vec_high(s
, tt
);
2507 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2514 int rm
= extract32(insn
, 16, 5);
2516 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2518 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2521 tcg_temp_free_i64(tcg_addr
);
2524 /* C3.3.3 AdvSIMD load/store single structure
2526 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2527 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2528 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
2529 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2531 * C3.3.4 AdvSIMD load/store single structure (post-indexed)
2533 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2534 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2535 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
2536 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2538 * Rt: first (or only) SIMD&FP register to be transferred
2539 * Rn: base address or SP
2540 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2541 * index = encoded in Q:S:size dependent on size
2543 * lane_size = encoded in R, opc
2544 * transfer width = encoded in opc, S, size
2546 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
2548 int rt
= extract32(insn
, 0, 5);
2549 int rn
= extract32(insn
, 5, 5);
2550 int size
= extract32(insn
, 10, 2);
2551 int S
= extract32(insn
, 12, 1);
2552 int opc
= extract32(insn
, 13, 3);
2553 int R
= extract32(insn
, 21, 1);
2554 int is_load
= extract32(insn
, 22, 1);
2555 int is_postidx
= extract32(insn
, 23, 1);
2556 int is_q
= extract32(insn
, 30, 1);
2558 int scale
= extract32(opc
, 1, 2);
2559 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
2560 bool replicate
= false;
2561 int index
= is_q
<< 3 | S
<< 2 | size
;
2563 TCGv_i64 tcg_addr
, tcg_rn
;
2567 if (!is_load
|| S
) {
2568 unallocated_encoding(s
);
2577 if (extract32(size
, 0, 1)) {
2578 unallocated_encoding(s
);
2584 if (extract32(size
, 1, 1)) {
2585 unallocated_encoding(s
);
2588 if (!extract32(size
, 0, 1)) {
2592 unallocated_encoding(s
);
2600 g_assert_not_reached();
2603 if (!fp_access_check(s
)) {
2607 ebytes
= 1 << scale
;
2610 gen_check_sp_alignment(s
);
2613 tcg_rn
= cpu_reg_sp(s
, rn
);
2614 tcg_addr
= tcg_temp_new_i64();
2615 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2617 for (xs
= 0; xs
< selem
; xs
++) {
2619 /* Load and replicate to all elements */
2621 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
2623 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
2624 get_mem_index(s
), s
->be_data
+ scale
);
2627 mulconst
= 0x0101010101010101ULL
;
2630 mulconst
= 0x0001000100010001ULL
;
2633 mulconst
= 0x0000000100000001ULL
;
2639 g_assert_not_reached();
2642 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
2644 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
2646 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
2648 clear_vec_high(s
, rt
);
2650 tcg_temp_free_i64(tcg_tmp
);
2652 /* Load/store one element per register */
2654 do_vec_ld(s
, rt
, index
, tcg_addr
, s
->be_data
+ scale
);
2656 do_vec_st(s
, rt
, index
, tcg_addr
, s
->be_data
+ scale
);
2659 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2664 int rm
= extract32(insn
, 16, 5);
2666 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2668 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2671 tcg_temp_free_i64(tcg_addr
);
2674 /* C3.3 Loads and stores */
2675 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
2677 switch (extract32(insn
, 24, 6)) {
2678 case 0x08: /* Load/store exclusive */
2679 disas_ldst_excl(s
, insn
);
2681 case 0x18: case 0x1c: /* Load register (literal) */
2682 disas_ld_lit(s
, insn
);
2684 case 0x28: case 0x29:
2685 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
2686 disas_ldst_pair(s
, insn
);
2688 case 0x38: case 0x39:
2689 case 0x3c: case 0x3d: /* Load/store register (all forms) */
2690 disas_ldst_reg(s
, insn
);
2692 case 0x0c: /* AdvSIMD load/store multiple structures */
2693 disas_ldst_multiple_struct(s
, insn
);
2695 case 0x0d: /* AdvSIMD load/store single structure */
2696 disas_ldst_single_struct(s
, insn
);
2699 unallocated_encoding(s
);
2704 /* C3.4.6 PC-rel. addressing
2705 * 31 30 29 28 24 23 5 4 0
2706 * +----+-------+-----------+-------------------+------+
2707 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
2708 * +----+-------+-----------+-------------------+------+
2710 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
2712 unsigned int page
, rd
;
2716 page
= extract32(insn
, 31, 1);
2717 /* SignExtend(immhi:immlo) -> offset */
2718 offset
= sextract64(insn
, 5, 19);
2719 offset
= offset
<< 2 | extract32(insn
, 29, 2);
2720 rd
= extract32(insn
, 0, 5);
2724 /* ADRP (page based) */
2729 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
2733 * C3.4.1 Add/subtract (immediate)
2735 * 31 30 29 28 24 23 22 21 10 9 5 4 0
2736 * +--+--+--+-----------+-----+-------------+-----+-----+
2737 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
2738 * +--+--+--+-----------+-----+-------------+-----+-----+
2740 * sf: 0 -> 32bit, 1 -> 64bit
2741 * op: 0 -> add , 1 -> sub
2743 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
2745 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
2747 int rd
= extract32(insn
, 0, 5);
2748 int rn
= extract32(insn
, 5, 5);
2749 uint64_t imm
= extract32(insn
, 10, 12);
2750 int shift
= extract32(insn
, 22, 2);
2751 bool setflags
= extract32(insn
, 29, 1);
2752 bool sub_op
= extract32(insn
, 30, 1);
2753 bool is_64bit
= extract32(insn
, 31, 1);
2755 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2756 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
2757 TCGv_i64 tcg_result
;
2766 unallocated_encoding(s
);
2770 tcg_result
= tcg_temp_new_i64();
2773 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
2775 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
2778 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
2780 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2782 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2784 tcg_temp_free_i64(tcg_imm
);
2788 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
2790 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
2793 tcg_temp_free_i64(tcg_result
);
2796 /* The input should be a value in the bottom e bits (with higher
2797 * bits zero); returns that value replicated into every element
2798 * of size e in a 64 bit integer.
2800 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
2810 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
2811 static inline uint64_t bitmask64(unsigned int length
)
2813 assert(length
> 0 && length
<= 64);
2814 return ~0ULL >> (64 - length
);
2817 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
2818 * only require the wmask. Returns false if the imms/immr/immn are a reserved
2819 * value (ie should cause a guest UNDEF exception), and true if they are
2820 * valid, in which case the decoded bit pattern is written to result.
2822 static bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
2823 unsigned int imms
, unsigned int immr
)
2826 unsigned e
, levels
, s
, r
;
2829 assert(immn
< 2 && imms
< 64 && immr
< 64);
2831 /* The bit patterns we create here are 64 bit patterns which
2832 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
2833 * 64 bits each. Each element contains the same value: a run
2834 * of between 1 and e-1 non-zero bits, rotated within the
2835 * element by between 0 and e-1 bits.
2837 * The element size and run length are encoded into immn (1 bit)
2838 * and imms (6 bits) as follows:
2839 * 64 bit elements: immn = 1, imms = <length of run - 1>
2840 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
2841 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
2842 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
2843 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
2844 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
2845 * Notice that immn = 0, imms = 11111x is the only combination
2846 * not covered by one of the above options; this is reserved.
2847 * Further, <length of run - 1> all-ones is a reserved pattern.
2849 * In all cases the rotation is by immr % e (and immr is 6 bits).
2852 /* First determine the element size */
2853 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
2855 /* This is the immn == 0, imms == 0x11111x case */
2865 /* <length of run - 1> mustn't be all-ones. */
2869 /* Create the value of one element: s+1 set bits rotated
2870 * by r within the element (which is e bits wide)...
2872 mask
= bitmask64(s
+ 1);
2874 mask
= (mask
>> r
) | (mask
<< (e
- r
));
2875 mask
&= bitmask64(e
);
2877 /* ...then replicate the element over the whole 64 bit value */
2878 mask
= bitfield_replicate(mask
, e
);
2883 /* C3.4.4 Logical (immediate)
2884 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2885 * +----+-----+-------------+---+------+------+------+------+
2886 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
2887 * +----+-----+-------------+---+------+------+------+------+
2889 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
2891 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
2892 TCGv_i64 tcg_rd
, tcg_rn
;
2894 bool is_and
= false;
2896 sf
= extract32(insn
, 31, 1);
2897 opc
= extract32(insn
, 29, 2);
2898 is_n
= extract32(insn
, 22, 1);
2899 immr
= extract32(insn
, 16, 6);
2900 imms
= extract32(insn
, 10, 6);
2901 rn
= extract32(insn
, 5, 5);
2902 rd
= extract32(insn
, 0, 5);
2905 unallocated_encoding(s
);
2909 if (opc
== 0x3) { /* ANDS */
2910 tcg_rd
= cpu_reg(s
, rd
);
2912 tcg_rd
= cpu_reg_sp(s
, rd
);
2914 tcg_rn
= cpu_reg(s
, rn
);
2916 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
2917 /* some immediate field values are reserved */
2918 unallocated_encoding(s
);
2923 wmask
&= 0xffffffff;
2927 case 0x3: /* ANDS */
2929 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
2933 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
2936 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
2939 assert(FALSE
); /* must handle all above */
2943 if (!sf
&& !is_and
) {
2944 /* zero extend final result; we know we can skip this for AND
2945 * since the immediate had the high 32 bits clear.
2947 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2950 if (opc
== 3) { /* ANDS */
2951 gen_logic_CC(sf
, tcg_rd
);
2956 * C3.4.5 Move wide (immediate)
2958 * 31 30 29 28 23 22 21 20 5 4 0
2959 * +--+-----+-------------+-----+----------------+------+
2960 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
2961 * +--+-----+-------------+-----+----------------+------+
2963 * sf: 0 -> 32 bit, 1 -> 64 bit
2964 * opc: 00 -> N, 10 -> Z, 11 -> K
2965 * hw: shift/16 (0,16, and sf only 32, 48)
2967 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
2969 int rd
= extract32(insn
, 0, 5);
2970 uint64_t imm
= extract32(insn
, 5, 16);
2971 int sf
= extract32(insn
, 31, 1);
2972 int opc
= extract32(insn
, 29, 2);
2973 int pos
= extract32(insn
, 21, 2) << 4;
2974 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
2977 if (!sf
&& (pos
>= 32)) {
2978 unallocated_encoding(s
);
2992 tcg_gen_movi_i64(tcg_rd
, imm
);
2995 tcg_imm
= tcg_const_i64(imm
);
2996 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
2997 tcg_temp_free_i64(tcg_imm
);
2999 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3003 unallocated_encoding(s
);
3009 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3010 * +----+-----+-------------+---+------+------+------+------+
3011 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3012 * +----+-----+-------------+---+------+------+------+------+
3014 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
3016 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
3017 TCGv_i64 tcg_rd
, tcg_tmp
;
3019 sf
= extract32(insn
, 31, 1);
3020 opc
= extract32(insn
, 29, 2);
3021 n
= extract32(insn
, 22, 1);
3022 ri
= extract32(insn
, 16, 6);
3023 si
= extract32(insn
, 10, 6);
3024 rn
= extract32(insn
, 5, 5);
3025 rd
= extract32(insn
, 0, 5);
3026 bitsize
= sf
? 64 : 32;
3028 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
3029 unallocated_encoding(s
);
3033 tcg_rd
= cpu_reg(s
, rd
);
3035 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3036 to be smaller than bitsize, we'll never reference data outside the
3037 low 32-bits anyway. */
3038 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
3040 /* Recognize the common aliases. */
3041 if (opc
== 0) { /* SBFM */
3043 if (si
== 7) { /* SXTB */
3044 tcg_gen_ext8s_i64(tcg_rd
, tcg_tmp
);
3046 } else if (si
== 15) { /* SXTH */
3047 tcg_gen_ext16s_i64(tcg_rd
, tcg_tmp
);
3049 } else if (si
== 31) { /* SXTW */
3050 tcg_gen_ext32s_i64(tcg_rd
, tcg_tmp
);
3054 if (si
== 63 || (si
== 31 && ri
<= si
)) { /* ASR */
3056 tcg_gen_ext32s_i64(tcg_tmp
, tcg_tmp
);
3058 tcg_gen_sari_i64(tcg_rd
, tcg_tmp
, ri
);
3061 } else if (opc
== 2) { /* UBFM */
3062 if (ri
== 0) { /* UXTB, UXTH, plus non-canonical AND */
3063 tcg_gen_andi_i64(tcg_rd
, tcg_tmp
, bitmask64(si
+ 1));
3066 if (si
== 63 || (si
== 31 && ri
<= si
)) { /* LSR */
3068 tcg_gen_ext32u_i64(tcg_tmp
, tcg_tmp
);
3070 tcg_gen_shri_i64(tcg_rd
, tcg_tmp
, ri
);
3073 if (si
+ 1 == ri
&& si
!= bitsize
- 1) { /* LSL */
3074 int shift
= bitsize
- 1 - si
;
3075 tcg_gen_shli_i64(tcg_rd
, tcg_tmp
, shift
);
3080 if (opc
!= 1) { /* SBFM or UBFM */
3081 tcg_gen_movi_i64(tcg_rd
, 0);
3084 /* do the bit move operation */
3086 /* Wd<s-r:0> = Wn<s:r> */
3087 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
3089 len
= (si
- ri
) + 1;
3091 /* Wd<32+s-r,32-r> = Wn<s:0> */
3096 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
3098 if (opc
== 0) { /* SBFM - sign extend the destination field */
3099 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
3100 tcg_gen_sari_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
3104 if (!sf
) { /* zero extend final result */
3105 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3110 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3111 * +----+------+-------------+---+----+------+--------+------+------+
3112 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3113 * +----+------+-------------+---+----+------+--------+------+------+
3115 static void disas_extract(DisasContext
*s
, uint32_t insn
)
3117 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
3119 sf
= extract32(insn
, 31, 1);
3120 n
= extract32(insn
, 22, 1);
3121 rm
= extract32(insn
, 16, 5);
3122 imm
= extract32(insn
, 10, 6);
3123 rn
= extract32(insn
, 5, 5);
3124 rd
= extract32(insn
, 0, 5);
3125 op21
= extract32(insn
, 29, 2);
3126 op0
= extract32(insn
, 21, 1);
3127 bitsize
= sf
? 64 : 32;
3129 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
3130 unallocated_encoding(s
);
3132 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
3134 tcg_rd
= cpu_reg(s
, rd
);
3136 if (unlikely(imm
== 0)) {
3137 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3138 * so an extract from bit 0 is a special case.
3141 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
3143 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
3145 } else if (rm
== rn
) { /* ROR */
3146 tcg_rm
= cpu_reg(s
, rm
);
3148 tcg_gen_rotri_i64(tcg_rd
, tcg_rm
, imm
);
3150 TCGv_i32 tmp
= tcg_temp_new_i32();
3151 tcg_gen_extrl_i64_i32(tmp
, tcg_rm
);
3152 tcg_gen_rotri_i32(tmp
, tmp
, imm
);
3153 tcg_gen_extu_i32_i64(tcg_rd
, tmp
);
3154 tcg_temp_free_i32(tmp
);
3157 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3158 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3159 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
3160 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
3161 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
3163 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3169 /* C3.4 Data processing - immediate */
3170 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
3172 switch (extract32(insn
, 23, 6)) {
3173 case 0x20: case 0x21: /* PC-rel. addressing */
3174 disas_pc_rel_adr(s
, insn
);
3176 case 0x22: case 0x23: /* Add/subtract (immediate) */
3177 disas_add_sub_imm(s
, insn
);
3179 case 0x24: /* Logical (immediate) */
3180 disas_logic_imm(s
, insn
);
3182 case 0x25: /* Move wide (immediate) */
3183 disas_movw_imm(s
, insn
);
3185 case 0x26: /* Bitfield */
3186 disas_bitfield(s
, insn
);
3188 case 0x27: /* Extract */
3189 disas_extract(s
, insn
);
3192 unallocated_encoding(s
);
3197 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3198 * Note that it is the caller's responsibility to ensure that the
3199 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3200 * mandated semantics for out of range shifts.
3202 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3203 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
3205 switch (shift_type
) {
3206 case A64_SHIFT_TYPE_LSL
:
3207 tcg_gen_shl_i64(dst
, src
, shift_amount
);
3209 case A64_SHIFT_TYPE_LSR
:
3210 tcg_gen_shr_i64(dst
, src
, shift_amount
);
3212 case A64_SHIFT_TYPE_ASR
:
3214 tcg_gen_ext32s_i64(dst
, src
);
3216 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
3218 case A64_SHIFT_TYPE_ROR
:
3220 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
3223 t0
= tcg_temp_new_i32();
3224 t1
= tcg_temp_new_i32();
3225 tcg_gen_extrl_i64_i32(t0
, src
);
3226 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
3227 tcg_gen_rotr_i32(t0
, t0
, t1
);
3228 tcg_gen_extu_i32_i64(dst
, t0
);
3229 tcg_temp_free_i32(t0
);
3230 tcg_temp_free_i32(t1
);
3234 assert(FALSE
); /* all shift types should be handled */
3238 if (!sf
) { /* zero extend final result */
3239 tcg_gen_ext32u_i64(dst
, dst
);
3243 /* Shift a TCGv src by immediate, put result in dst.
3244 * The shift amount must be in range (this should always be true as the
3245 * relevant instructions will UNDEF on bad shift immediates).
3247 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3248 enum a64_shift_type shift_type
, unsigned int shift_i
)
3250 assert(shift_i
< (sf
? 64 : 32));
3253 tcg_gen_mov_i64(dst
, src
);
3255 TCGv_i64 shift_const
;
3257 shift_const
= tcg_const_i64(shift_i
);
3258 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
3259 tcg_temp_free_i64(shift_const
);
3263 /* C3.5.10 Logical (shifted register)
3264 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3265 * +----+-----+-----------+-------+---+------+--------+------+------+
3266 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3267 * +----+-----+-----------+-------+---+------+--------+------+------+
3269 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
3271 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
3272 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
3274 sf
= extract32(insn
, 31, 1);
3275 opc
= extract32(insn
, 29, 2);
3276 shift_type
= extract32(insn
, 22, 2);
3277 invert
= extract32(insn
, 21, 1);
3278 rm
= extract32(insn
, 16, 5);
3279 shift_amount
= extract32(insn
, 10, 6);
3280 rn
= extract32(insn
, 5, 5);
3281 rd
= extract32(insn
, 0, 5);
3283 if (!sf
&& (shift_amount
& (1 << 5))) {
3284 unallocated_encoding(s
);
3288 tcg_rd
= cpu_reg(s
, rd
);
3290 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3291 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3292 * register-register MOV and MVN, so it is worth special casing.
3294 tcg_rm
= cpu_reg(s
, rm
);
3296 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3298 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3302 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3304 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3310 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3313 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3316 tcg_rn
= cpu_reg(s
, rn
);
3318 switch (opc
| (invert
<< 2)) {
3321 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3324 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3327 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3331 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3334 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3337 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3345 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3349 gen_logic_CC(sf
, tcg_rd
);
3354 * C3.5.1 Add/subtract (extended register)
3356 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3357 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3358 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3359 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3361 * sf: 0 -> 32bit, 1 -> 64bit
3362 * op: 0 -> add , 1 -> sub
3365 * option: extension type (see DecodeRegExtend)
3366 * imm3: optional shift to Rm
3368 * Rd = Rn + LSL(extend(Rm), amount)
3370 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3372 int rd
= extract32(insn
, 0, 5);
3373 int rn
= extract32(insn
, 5, 5);
3374 int imm3
= extract32(insn
, 10, 3);
3375 int option
= extract32(insn
, 13, 3);
3376 int rm
= extract32(insn
, 16, 5);
3377 bool setflags
= extract32(insn
, 29, 1);
3378 bool sub_op
= extract32(insn
, 30, 1);
3379 bool sf
= extract32(insn
, 31, 1);
3381 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3383 TCGv_i64 tcg_result
;
3386 unallocated_encoding(s
);
3390 /* non-flag setting ops may use SP */
3392 tcg_rd
= cpu_reg_sp(s
, rd
);
3394 tcg_rd
= cpu_reg(s
, rd
);
3396 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3398 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3399 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3401 tcg_result
= tcg_temp_new_i64();
3405 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3407 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3411 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3413 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3418 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3420 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3423 tcg_temp_free_i64(tcg_result
);
3427 * C3.5.2 Add/subtract (shifted register)
3429 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3430 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3431 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3432 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3434 * sf: 0 -> 32bit, 1 -> 64bit
3435 * op: 0 -> add , 1 -> sub
3437 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3438 * imm6: Shift amount to apply to Rm before the add/sub
3440 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
3442 int rd
= extract32(insn
, 0, 5);
3443 int rn
= extract32(insn
, 5, 5);
3444 int imm6
= extract32(insn
, 10, 6);
3445 int rm
= extract32(insn
, 16, 5);
3446 int shift_type
= extract32(insn
, 22, 2);
3447 bool setflags
= extract32(insn
, 29, 1);
3448 bool sub_op
= extract32(insn
, 30, 1);
3449 bool sf
= extract32(insn
, 31, 1);
3451 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3452 TCGv_i64 tcg_rn
, tcg_rm
;
3453 TCGv_i64 tcg_result
;
3455 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
3456 unallocated_encoding(s
);
3460 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3461 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3463 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
3465 tcg_result
= tcg_temp_new_i64();
3469 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3471 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3475 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3477 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3482 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3484 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3487 tcg_temp_free_i64(tcg_result
);
3490 /* C3.5.9 Data-processing (3 source)
3492 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3493 +--+------+-----------+------+------+----+------+------+------+
3494 |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3495 +--+------+-----------+------+------+----+------+------+------+
3498 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
3500 int rd
= extract32(insn
, 0, 5);
3501 int rn
= extract32(insn
, 5, 5);
3502 int ra
= extract32(insn
, 10, 5);
3503 int rm
= extract32(insn
, 16, 5);
3504 int op_id
= (extract32(insn
, 29, 3) << 4) |
3505 (extract32(insn
, 21, 3) << 1) |
3506 extract32(insn
, 15, 1);
3507 bool sf
= extract32(insn
, 31, 1);
3508 bool is_sub
= extract32(op_id
, 0, 1);
3509 bool is_high
= extract32(op_id
, 2, 1);
3510 bool is_signed
= false;
3515 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
3517 case 0x42: /* SMADDL */
3518 case 0x43: /* SMSUBL */
3519 case 0x44: /* SMULH */
3522 case 0x0: /* MADD (32bit) */
3523 case 0x1: /* MSUB (32bit) */
3524 case 0x40: /* MADD (64bit) */
3525 case 0x41: /* MSUB (64bit) */
3526 case 0x4a: /* UMADDL */
3527 case 0x4b: /* UMSUBL */
3528 case 0x4c: /* UMULH */
3531 unallocated_encoding(s
);
3536 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
3537 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3538 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
3539 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
3542 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3544 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3547 tcg_temp_free_i64(low_bits
);
3551 tcg_op1
= tcg_temp_new_i64();
3552 tcg_op2
= tcg_temp_new_i64();
3553 tcg_tmp
= tcg_temp_new_i64();
3556 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
3557 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
3560 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
3561 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
3563 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
3564 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
3568 if (ra
== 31 && !is_sub
) {
3569 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
3570 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
3572 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
3574 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3576 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3581 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
3584 tcg_temp_free_i64(tcg_op1
);
3585 tcg_temp_free_i64(tcg_op2
);
3586 tcg_temp_free_i64(tcg_tmp
);
3589 /* C3.5.3 - Add/subtract (with carry)
3590 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
3591 * +--+--+--+------------------------+------+---------+------+-----+
3592 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
3593 * +--+--+--+------------------------+------+---------+------+-----+
3597 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
3599 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
3600 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
3602 if (extract32(insn
, 10, 6) != 0) {
3603 unallocated_encoding(s
);
3607 sf
= extract32(insn
, 31, 1);
3608 op
= extract32(insn
, 30, 1);
3609 setflags
= extract32(insn
, 29, 1);
3610 rm
= extract32(insn
, 16, 5);
3611 rn
= extract32(insn
, 5, 5);
3612 rd
= extract32(insn
, 0, 5);
3614 tcg_rd
= cpu_reg(s
, rd
);
3615 tcg_rn
= cpu_reg(s
, rn
);
3618 tcg_y
= new_tmp_a64(s
);
3619 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
3621 tcg_y
= cpu_reg(s
, rm
);
3625 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3627 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3631 /* C3.5.4 - C3.5.5 Conditional compare (immediate / register)
3632 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3633 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3634 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
3635 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3638 static void disas_cc(DisasContext
*s
, uint32_t insn
)
3640 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
3641 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
3642 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
3645 if (!extract32(insn
, 29, 1)) {
3646 unallocated_encoding(s
);
3649 if (insn
& (1 << 10 | 1 << 4)) {
3650 unallocated_encoding(s
);
3653 sf
= extract32(insn
, 31, 1);
3654 op
= extract32(insn
, 30, 1);
3655 is_imm
= extract32(insn
, 11, 1);
3656 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
3657 cond
= extract32(insn
, 12, 4);
3658 rn
= extract32(insn
, 5, 5);
3659 nzcv
= extract32(insn
, 0, 4);
3661 /* Set T0 = !COND. */
3662 tcg_t0
= tcg_temp_new_i32();
3663 arm_test_cc(&c
, cond
);
3664 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
3667 /* Load the arguments for the new comparison. */
3669 tcg_y
= new_tmp_a64(s
);
3670 tcg_gen_movi_i64(tcg_y
, y
);
3672 tcg_y
= cpu_reg(s
, y
);
3674 tcg_rn
= cpu_reg(s
, rn
);
3676 /* Set the flags for the new comparison. */
3677 tcg_tmp
= tcg_temp_new_i64();
3679 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3681 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3683 tcg_temp_free_i64(tcg_tmp
);
3685 /* If COND was false, force the flags to #nzcv. Compute two masks
3686 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
3687 * For tcg hosts that support ANDC, we can make do with just T1.
3688 * In either case, allow the tcg optimizer to delete any unused mask.
3690 tcg_t1
= tcg_temp_new_i32();
3691 tcg_t2
= tcg_temp_new_i32();
3692 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
3693 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
3695 if (nzcv
& 8) { /* N */
3696 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
3698 if (TCG_TARGET_HAS_andc_i32
) {
3699 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
3701 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
3704 if (nzcv
& 4) { /* Z */
3705 if (TCG_TARGET_HAS_andc_i32
) {
3706 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
3708 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
3711 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
3713 if (nzcv
& 2) { /* C */
3714 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
3716 if (TCG_TARGET_HAS_andc_i32
) {
3717 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
3719 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
3722 if (nzcv
& 1) { /* V */
3723 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
3725 if (TCG_TARGET_HAS_andc_i32
) {
3726 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
3728 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
3731 tcg_temp_free_i32(tcg_t0
);
3732 tcg_temp_free_i32(tcg_t1
);
3733 tcg_temp_free_i32(tcg_t2
);
3736 /* C3.5.6 Conditional select
3737 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
3738 * +----+----+---+-----------------+------+------+-----+------+------+
3739 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
3740 * +----+----+---+-----------------+------+------+-----+------+------+
3742 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
3744 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
3745 TCGv_i64 tcg_rd
, zero
;
3748 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
3749 /* S == 1 or op2<1> == 1 */
3750 unallocated_encoding(s
);
3753 sf
= extract32(insn
, 31, 1);
3754 else_inv
= extract32(insn
, 30, 1);
3755 rm
= extract32(insn
, 16, 5);
3756 cond
= extract32(insn
, 12, 4);
3757 else_inc
= extract32(insn
, 10, 1);
3758 rn
= extract32(insn
, 5, 5);
3759 rd
= extract32(insn
, 0, 5);
3761 tcg_rd
= cpu_reg(s
, rd
);
3763 a64_test_cc(&c
, cond
);
3764 zero
= tcg_const_i64(0);
3766 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
3768 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
3770 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
3773 TCGv_i64 t_true
= cpu_reg(s
, rn
);
3774 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
3775 if (else_inv
&& else_inc
) {
3776 tcg_gen_neg_i64(t_false
, t_false
);
3777 } else if (else_inv
) {
3778 tcg_gen_not_i64(t_false
, t_false
);
3779 } else if (else_inc
) {
3780 tcg_gen_addi_i64(t_false
, t_false
, 1);
3782 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
3785 tcg_temp_free_i64(zero
);
3789 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3793 static void handle_clz(DisasContext
*s
, unsigned int sf
,
3794 unsigned int rn
, unsigned int rd
)
3796 TCGv_i64 tcg_rd
, tcg_rn
;
3797 tcg_rd
= cpu_reg(s
, rd
);
3798 tcg_rn
= cpu_reg(s
, rn
);
3801 gen_helper_clz64(tcg_rd
, tcg_rn
);
3803 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3804 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3805 gen_helper_clz(tcg_tmp32
, tcg_tmp32
);
3806 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3807 tcg_temp_free_i32(tcg_tmp32
);
3811 static void handle_cls(DisasContext
*s
, unsigned int sf
,
3812 unsigned int rn
, unsigned int rd
)
3814 TCGv_i64 tcg_rd
, tcg_rn
;
3815 tcg_rd
= cpu_reg(s
, rd
);
3816 tcg_rn
= cpu_reg(s
, rn
);
3819 gen_helper_cls64(tcg_rd
, tcg_rn
);
3821 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3822 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3823 gen_helper_cls32(tcg_tmp32
, tcg_tmp32
);
3824 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3825 tcg_temp_free_i32(tcg_tmp32
);
3829 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
3830 unsigned int rn
, unsigned int rd
)
3832 TCGv_i64 tcg_rd
, tcg_rn
;
3833 tcg_rd
= cpu_reg(s
, rd
);
3834 tcg_rn
= cpu_reg(s
, rn
);
3837 gen_helper_rbit64(tcg_rd
, tcg_rn
);
3839 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3840 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3841 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
3842 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3843 tcg_temp_free_i32(tcg_tmp32
);
3847 /* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
3848 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
3849 unsigned int rn
, unsigned int rd
)
3852 unallocated_encoding(s
);
3855 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
3858 /* C5.6.149 REV with sf==0, opcode==2
3859 * C5.6.151 REV32 (sf==1, opcode==2)
3861 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
3862 unsigned int rn
, unsigned int rd
)
3864 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3867 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3868 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3870 /* bswap32_i64 requires zero high word */
3871 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
3872 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
3873 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3874 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
3875 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
3877 tcg_temp_free_i64(tcg_tmp
);
3879 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
3880 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
3884 /* C5.6.150 REV16 (opcode==1) */
3885 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
3886 unsigned int rn
, unsigned int rd
)
3888 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3889 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3890 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3892 tcg_gen_andi_i64(tcg_tmp
, tcg_rn
, 0xffff);
3893 tcg_gen_bswap16_i64(tcg_rd
, tcg_tmp
);
3895 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 16);
3896 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3897 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3898 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 16, 16);
3901 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3902 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3903 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3904 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 32, 16);
3906 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 48);
3907 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3908 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 48, 16);
3911 tcg_temp_free_i64(tcg_tmp
);
3914 /* C3.5.7 Data-processing (1 source)
3915 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3916 * +----+---+---+-----------------+---------+--------+------+------+
3917 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
3918 * +----+---+---+-----------------+---------+--------+------+------+
3920 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
3922 unsigned int sf
, opcode
, rn
, rd
;
3924 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
3925 unallocated_encoding(s
);
3929 sf
= extract32(insn
, 31, 1);
3930 opcode
= extract32(insn
, 10, 6);
3931 rn
= extract32(insn
, 5, 5);
3932 rd
= extract32(insn
, 0, 5);
3936 handle_rbit(s
, sf
, rn
, rd
);
3939 handle_rev16(s
, sf
, rn
, rd
);
3942 handle_rev32(s
, sf
, rn
, rd
);
3945 handle_rev64(s
, sf
, rn
, rd
);
3948 handle_clz(s
, sf
, rn
, rd
);
3951 handle_cls(s
, sf
, rn
, rd
);
3956 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
3957 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3959 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
3960 tcg_rd
= cpu_reg(s
, rd
);
3962 if (!sf
&& is_signed
) {
3963 tcg_n
= new_tmp_a64(s
);
3964 tcg_m
= new_tmp_a64(s
);
3965 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
3966 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
3968 tcg_n
= read_cpu_reg(s
, rn
, sf
);
3969 tcg_m
= read_cpu_reg(s
, rm
, sf
);
3973 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
3975 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
3978 if (!sf
) { /* zero extend final result */
3979 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3983 /* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
3984 static void handle_shift_reg(DisasContext
*s
,
3985 enum a64_shift_type shift_type
, unsigned int sf
,
3986 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3988 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
3989 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3990 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3992 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
3993 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
3994 tcg_temp_free_i64(tcg_shift
);
3997 /* CRC32[BHWX], CRC32C[BHWX] */
3998 static void handle_crc32(DisasContext
*s
,
3999 unsigned int sf
, unsigned int sz
, bool crc32c
,
4000 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4002 TCGv_i64 tcg_acc
, tcg_val
;
4005 if (!arm_dc_feature(s
, ARM_FEATURE_CRC
)
4006 || (sf
== 1 && sz
!= 3)
4007 || (sf
== 0 && sz
== 3)) {
4008 unallocated_encoding(s
);
4013 tcg_val
= cpu_reg(s
, rm
);
4027 g_assert_not_reached();
4029 tcg_val
= new_tmp_a64(s
);
4030 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
4033 tcg_acc
= cpu_reg(s
, rn
);
4034 tcg_bytes
= tcg_const_i32(1 << sz
);
4037 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4039 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4042 tcg_temp_free_i32(tcg_bytes
);
4045 /* C3.5.8 Data-processing (2 source)
4046 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4047 * +----+---+---+-----------------+------+--------+------+------+
4048 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
4049 * +----+---+---+-----------------+------+--------+------+------+
4051 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
4053 unsigned int sf
, rm
, opcode
, rn
, rd
;
4054 sf
= extract32(insn
, 31, 1);
4055 rm
= extract32(insn
, 16, 5);
4056 opcode
= extract32(insn
, 10, 6);
4057 rn
= extract32(insn
, 5, 5);
4058 rd
= extract32(insn
, 0, 5);
4060 if (extract32(insn
, 29, 1)) {
4061 unallocated_encoding(s
);
4067 handle_div(s
, false, sf
, rm
, rn
, rd
);
4070 handle_div(s
, true, sf
, rm
, rn
, rd
);
4073 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
4076 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
4079 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
4082 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
4091 case 23: /* CRC32 */
4093 int sz
= extract32(opcode
, 0, 2);
4094 bool crc32c
= extract32(opcode
, 2, 1);
4095 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
4099 unallocated_encoding(s
);
4104 /* C3.5 Data processing - register */
4105 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
4107 switch (extract32(insn
, 24, 5)) {
4108 case 0x0a: /* Logical (shifted register) */
4109 disas_logic_reg(s
, insn
);
4111 case 0x0b: /* Add/subtract */
4112 if (insn
& (1 << 21)) { /* (extended register) */
4113 disas_add_sub_ext_reg(s
, insn
);
4115 disas_add_sub_reg(s
, insn
);
4118 case 0x1b: /* Data-processing (3 source) */
4119 disas_data_proc_3src(s
, insn
);
4122 switch (extract32(insn
, 21, 3)) {
4123 case 0x0: /* Add/subtract (with carry) */
4124 disas_adc_sbc(s
, insn
);
4126 case 0x2: /* Conditional compare */
4127 disas_cc(s
, insn
); /* both imm and reg forms */
4129 case 0x4: /* Conditional select */
4130 disas_cond_select(s
, insn
);
4132 case 0x6: /* Data-processing */
4133 if (insn
& (1 << 30)) { /* (1 source) */
4134 disas_data_proc_1src(s
, insn
);
4135 } else { /* (2 source) */
4136 disas_data_proc_2src(s
, insn
);
4140 unallocated_encoding(s
);
4145 unallocated_encoding(s
);
4150 static void handle_fp_compare(DisasContext
*s
, bool is_double
,
4151 unsigned int rn
, unsigned int rm
,
4152 bool cmp_with_zero
, bool signal_all_nans
)
4154 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
4155 TCGv_ptr fpst
= get_fpstatus_ptr();
4158 TCGv_i64 tcg_vn
, tcg_vm
;
4160 tcg_vn
= read_fp_dreg(s
, rn
);
4161 if (cmp_with_zero
) {
4162 tcg_vm
= tcg_const_i64(0);
4164 tcg_vm
= read_fp_dreg(s
, rm
);
4166 if (signal_all_nans
) {
4167 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4169 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4171 tcg_temp_free_i64(tcg_vn
);
4172 tcg_temp_free_i64(tcg_vm
);
4174 TCGv_i32 tcg_vn
, tcg_vm
;
4176 tcg_vn
= read_fp_sreg(s
, rn
);
4177 if (cmp_with_zero
) {
4178 tcg_vm
= tcg_const_i32(0);
4180 tcg_vm
= read_fp_sreg(s
, rm
);
4182 if (signal_all_nans
) {
4183 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4185 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4187 tcg_temp_free_i32(tcg_vn
);
4188 tcg_temp_free_i32(tcg_vm
);
4191 tcg_temp_free_ptr(fpst
);
4193 gen_set_nzcv(tcg_flags
);
4195 tcg_temp_free_i64(tcg_flags
);
4198 /* C3.6.22 Floating point compare
4199 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
4200 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4201 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
4202 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4204 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
4206 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
4208 mos
= extract32(insn
, 29, 3);
4209 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4210 rm
= extract32(insn
, 16, 5);
4211 op
= extract32(insn
, 14, 2);
4212 rn
= extract32(insn
, 5, 5);
4213 opc
= extract32(insn
, 3, 2);
4214 op2r
= extract32(insn
, 0, 3);
4216 if (mos
|| op
|| op2r
|| type
> 1) {
4217 unallocated_encoding(s
);
4221 if (!fp_access_check(s
)) {
4225 handle_fp_compare(s
, type
, rn
, rm
, opc
& 1, opc
& 2);
4228 /* C3.6.23 Floating point conditional compare
4229 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4230 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4231 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
4232 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4234 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
4236 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
4238 TCGLabel
*label_continue
= NULL
;
4240 mos
= extract32(insn
, 29, 3);
4241 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4242 rm
= extract32(insn
, 16, 5);
4243 cond
= extract32(insn
, 12, 4);
4244 rn
= extract32(insn
, 5, 5);
4245 op
= extract32(insn
, 4, 1);
4246 nzcv
= extract32(insn
, 0, 4);
4248 if (mos
|| type
> 1) {
4249 unallocated_encoding(s
);
4253 if (!fp_access_check(s
)) {
4257 if (cond
< 0x0e) { /* not always */
4258 TCGLabel
*label_match
= gen_new_label();
4259 label_continue
= gen_new_label();
4260 arm_gen_test_cc(cond
, label_match
);
4262 tcg_flags
= tcg_const_i64(nzcv
<< 28);
4263 gen_set_nzcv(tcg_flags
);
4264 tcg_temp_free_i64(tcg_flags
);
4265 tcg_gen_br(label_continue
);
4266 gen_set_label(label_match
);
4269 handle_fp_compare(s
, type
, rn
, rm
, false, op
);
4272 gen_set_label(label_continue
);
4276 /* C3.6.24 Floating point conditional select
4277 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4278 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4279 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
4280 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4282 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
4284 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
4285 TCGv_i64 t_true
, t_false
, t_zero
;
4288 mos
= extract32(insn
, 29, 3);
4289 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4290 rm
= extract32(insn
, 16, 5);
4291 cond
= extract32(insn
, 12, 4);
4292 rn
= extract32(insn
, 5, 5);
4293 rd
= extract32(insn
, 0, 5);
4295 if (mos
|| type
> 1) {
4296 unallocated_encoding(s
);
4300 if (!fp_access_check(s
)) {
4304 /* Zero extend sreg inputs to 64 bits now. */
4305 t_true
= tcg_temp_new_i64();
4306 t_false
= tcg_temp_new_i64();
4307 read_vec_element(s
, t_true
, rn
, 0, type
? MO_64
: MO_32
);
4308 read_vec_element(s
, t_false
, rm
, 0, type
? MO_64
: MO_32
);
4310 a64_test_cc(&c
, cond
);
4311 t_zero
= tcg_const_i64(0);
4312 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, t_zero
, t_true
, t_false
);
4313 tcg_temp_free_i64(t_zero
);
4314 tcg_temp_free_i64(t_false
);
4317 /* Note that sregs write back zeros to the high bits,
4318 and we've already done the zero-extension. */
4319 write_fp_dreg(s
, rd
, t_true
);
4320 tcg_temp_free_i64(t_true
);
4323 /* C3.6.25 Floating-point data-processing (1 source) - single precision */
4324 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
4330 fpst
= get_fpstatus_ptr();
4331 tcg_op
= read_fp_sreg(s
, rn
);
4332 tcg_res
= tcg_temp_new_i32();
4335 case 0x0: /* FMOV */
4336 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4338 case 0x1: /* FABS */
4339 gen_helper_vfp_abss(tcg_res
, tcg_op
);
4341 case 0x2: /* FNEG */
4342 gen_helper_vfp_negs(tcg_res
, tcg_op
);
4344 case 0x3: /* FSQRT */
4345 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
4347 case 0x8: /* FRINTN */
4348 case 0x9: /* FRINTP */
4349 case 0xa: /* FRINTM */
4350 case 0xb: /* FRINTZ */
4351 case 0xc: /* FRINTA */
4353 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4355 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4356 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4358 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4359 tcg_temp_free_i32(tcg_rmode
);
4362 case 0xe: /* FRINTX */
4363 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
4365 case 0xf: /* FRINTI */
4366 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4372 write_fp_sreg(s
, rd
, tcg_res
);
4374 tcg_temp_free_ptr(fpst
);
4375 tcg_temp_free_i32(tcg_op
);
4376 tcg_temp_free_i32(tcg_res
);
4379 /* C3.6.25 Floating-point data-processing (1 source) - double precision */
4380 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
4386 fpst
= get_fpstatus_ptr();
4387 tcg_op
= read_fp_dreg(s
, rn
);
4388 tcg_res
= tcg_temp_new_i64();
4391 case 0x0: /* FMOV */
4392 tcg_gen_mov_i64(tcg_res
, tcg_op
);
4394 case 0x1: /* FABS */
4395 gen_helper_vfp_absd(tcg_res
, tcg_op
);
4397 case 0x2: /* FNEG */
4398 gen_helper_vfp_negd(tcg_res
, tcg_op
);
4400 case 0x3: /* FSQRT */
4401 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
4403 case 0x8: /* FRINTN */
4404 case 0x9: /* FRINTP */
4405 case 0xa: /* FRINTM */
4406 case 0xb: /* FRINTZ */
4407 case 0xc: /* FRINTA */
4409 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4411 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4412 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4414 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4415 tcg_temp_free_i32(tcg_rmode
);
4418 case 0xe: /* FRINTX */
4419 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
4421 case 0xf: /* FRINTI */
4422 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4428 write_fp_dreg(s
, rd
, tcg_res
);
4430 tcg_temp_free_ptr(fpst
);
4431 tcg_temp_free_i64(tcg_op
);
4432 tcg_temp_free_i64(tcg_res
);
4435 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
4436 int rd
, int rn
, int dtype
, int ntype
)
4441 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4443 /* Single to double */
4444 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4445 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
4446 write_fp_dreg(s
, rd
, tcg_rd
);
4447 tcg_temp_free_i64(tcg_rd
);
4449 /* Single to half */
4450 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4451 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4452 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4453 write_fp_sreg(s
, rd
, tcg_rd
);
4454 tcg_temp_free_i32(tcg_rd
);
4456 tcg_temp_free_i32(tcg_rn
);
4461 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
4462 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4464 /* Double to single */
4465 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
4467 /* Double to half */
4468 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4469 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4471 write_fp_sreg(s
, rd
, tcg_rd
);
4472 tcg_temp_free_i32(tcg_rd
);
4473 tcg_temp_free_i64(tcg_rn
);
4478 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4479 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
4481 /* Half to single */
4482 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4483 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, cpu_env
);
4484 write_fp_sreg(s
, rd
, tcg_rd
);
4485 tcg_temp_free_i32(tcg_rd
);
4487 /* Half to double */
4488 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4489 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, cpu_env
);
4490 write_fp_dreg(s
, rd
, tcg_rd
);
4491 tcg_temp_free_i64(tcg_rd
);
4493 tcg_temp_free_i32(tcg_rn
);
4501 /* C3.6.25 Floating point data-processing (1 source)
4502 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
4503 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4504 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
4505 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4507 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
4509 int type
= extract32(insn
, 22, 2);
4510 int opcode
= extract32(insn
, 15, 6);
4511 int rn
= extract32(insn
, 5, 5);
4512 int rd
= extract32(insn
, 0, 5);
4515 case 0x4: case 0x5: case 0x7:
4517 /* FCVT between half, single and double precision */
4518 int dtype
= extract32(opcode
, 0, 2);
4519 if (type
== 2 || dtype
== type
) {
4520 unallocated_encoding(s
);
4523 if (!fp_access_check(s
)) {
4527 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
4533 /* 32-to-32 and 64-to-64 ops */
4536 if (!fp_access_check(s
)) {
4540 handle_fp_1src_single(s
, opcode
, rd
, rn
);
4543 if (!fp_access_check(s
)) {
4547 handle_fp_1src_double(s
, opcode
, rd
, rn
);
4550 unallocated_encoding(s
);
4554 unallocated_encoding(s
);
4559 /* C3.6.26 Floating-point data-processing (2 source) - single precision */
4560 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
4561 int rd
, int rn
, int rm
)
4568 tcg_res
= tcg_temp_new_i32();
4569 fpst
= get_fpstatus_ptr();
4570 tcg_op1
= read_fp_sreg(s
, rn
);
4571 tcg_op2
= read_fp_sreg(s
, rm
);
4574 case 0x0: /* FMUL */
4575 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4577 case 0x1: /* FDIV */
4578 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4580 case 0x2: /* FADD */
4581 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4583 case 0x3: /* FSUB */
4584 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4586 case 0x4: /* FMAX */
4587 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4589 case 0x5: /* FMIN */
4590 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4592 case 0x6: /* FMAXNM */
4593 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4595 case 0x7: /* FMINNM */
4596 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4598 case 0x8: /* FNMUL */
4599 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4600 gen_helper_vfp_negs(tcg_res
, tcg_res
);
4604 write_fp_sreg(s
, rd
, tcg_res
);
4606 tcg_temp_free_ptr(fpst
);
4607 tcg_temp_free_i32(tcg_op1
);
4608 tcg_temp_free_i32(tcg_op2
);
4609 tcg_temp_free_i32(tcg_res
);
4612 /* C3.6.26 Floating-point data-processing (2 source) - double precision */
4613 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
4614 int rd
, int rn
, int rm
)
4621 tcg_res
= tcg_temp_new_i64();
4622 fpst
= get_fpstatus_ptr();
4623 tcg_op1
= read_fp_dreg(s
, rn
);
4624 tcg_op2
= read_fp_dreg(s
, rm
);
4627 case 0x0: /* FMUL */
4628 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4630 case 0x1: /* FDIV */
4631 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4633 case 0x2: /* FADD */
4634 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4636 case 0x3: /* FSUB */
4637 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4639 case 0x4: /* FMAX */
4640 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4642 case 0x5: /* FMIN */
4643 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4645 case 0x6: /* FMAXNM */
4646 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4648 case 0x7: /* FMINNM */
4649 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4651 case 0x8: /* FNMUL */
4652 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4653 gen_helper_vfp_negd(tcg_res
, tcg_res
);
4657 write_fp_dreg(s
, rd
, tcg_res
);
4659 tcg_temp_free_ptr(fpst
);
4660 tcg_temp_free_i64(tcg_op1
);
4661 tcg_temp_free_i64(tcg_op2
);
4662 tcg_temp_free_i64(tcg_res
);
4665 /* C3.6.26 Floating point data-processing (2 source)
4666 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4667 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4668 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
4669 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4671 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
4673 int type
= extract32(insn
, 22, 2);
4674 int rd
= extract32(insn
, 0, 5);
4675 int rn
= extract32(insn
, 5, 5);
4676 int rm
= extract32(insn
, 16, 5);
4677 int opcode
= extract32(insn
, 12, 4);
4680 unallocated_encoding(s
);
4686 if (!fp_access_check(s
)) {
4689 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
4692 if (!fp_access_check(s
)) {
4695 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
4698 unallocated_encoding(s
);
4702 /* C3.6.27 Floating-point data-processing (3 source) - single precision */
4703 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
4704 int rd
, int rn
, int rm
, int ra
)
4706 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
4707 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4708 TCGv_ptr fpst
= get_fpstatus_ptr();
4710 tcg_op1
= read_fp_sreg(s
, rn
);
4711 tcg_op2
= read_fp_sreg(s
, rm
);
4712 tcg_op3
= read_fp_sreg(s
, ra
);
4714 /* These are fused multiply-add, and must be done as one
4715 * floating point operation with no rounding between the
4716 * multiplication and addition steps.
4717 * NB that doing the negations here as separate steps is
4718 * correct : an input NaN should come out with its sign bit
4719 * flipped if it is a negated-input.
4722 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
4726 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
4729 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4731 write_fp_sreg(s
, rd
, tcg_res
);
4733 tcg_temp_free_ptr(fpst
);
4734 tcg_temp_free_i32(tcg_op1
);
4735 tcg_temp_free_i32(tcg_op2
);
4736 tcg_temp_free_i32(tcg_op3
);
4737 tcg_temp_free_i32(tcg_res
);
4740 /* C3.6.27 Floating-point data-processing (3 source) - double precision */
4741 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
4742 int rd
, int rn
, int rm
, int ra
)
4744 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
4745 TCGv_i64 tcg_res
= tcg_temp_new_i64();
4746 TCGv_ptr fpst
= get_fpstatus_ptr();
4748 tcg_op1
= read_fp_dreg(s
, rn
);
4749 tcg_op2
= read_fp_dreg(s
, rm
);
4750 tcg_op3
= read_fp_dreg(s
, ra
);
4752 /* These are fused multiply-add, and must be done as one
4753 * floating point operation with no rounding between the
4754 * multiplication and addition steps.
4755 * NB that doing the negations here as separate steps is
4756 * correct : an input NaN should come out with its sign bit
4757 * flipped if it is a negated-input.
4760 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
4764 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
4767 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4769 write_fp_dreg(s
, rd
, tcg_res
);
4771 tcg_temp_free_ptr(fpst
);
4772 tcg_temp_free_i64(tcg_op1
);
4773 tcg_temp_free_i64(tcg_op2
);
4774 tcg_temp_free_i64(tcg_op3
);
4775 tcg_temp_free_i64(tcg_res
);
4778 /* C3.6.27 Floating point data-processing (3 source)
4779 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
4780 * +---+---+---+-----------+------+----+------+----+------+------+------+
4781 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
4782 * +---+---+---+-----------+------+----+------+----+------+------+------+
4784 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
4786 int type
= extract32(insn
, 22, 2);
4787 int rd
= extract32(insn
, 0, 5);
4788 int rn
= extract32(insn
, 5, 5);
4789 int ra
= extract32(insn
, 10, 5);
4790 int rm
= extract32(insn
, 16, 5);
4791 bool o0
= extract32(insn
, 15, 1);
4792 bool o1
= extract32(insn
, 21, 1);
4796 if (!fp_access_check(s
)) {
4799 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4802 if (!fp_access_check(s
)) {
4805 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4808 unallocated_encoding(s
);
4812 /* C3.6.28 Floating point immediate
4813 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
4814 * +---+---+---+-----------+------+---+------------+-------+------+------+
4815 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
4816 * +---+---+---+-----------+------+---+------------+-------+------+------+
4818 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
4820 int rd
= extract32(insn
, 0, 5);
4821 int imm8
= extract32(insn
, 13, 8);
4822 int is_double
= extract32(insn
, 22, 2);
4826 if (is_double
> 1) {
4827 unallocated_encoding(s
);
4831 if (!fp_access_check(s
)) {
4835 /* The imm8 encodes the sign bit, enough bits to represent
4836 * an exponent in the range 01....1xx to 10....0xx,
4837 * and the most significant 4 bits of the mantissa; see
4838 * VFPExpandImm() in the v8 ARM ARM.
4841 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4842 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
4843 extract32(imm8
, 0, 6);
4846 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4847 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
4848 (extract32(imm8
, 0, 6) << 3);
4852 tcg_res
= tcg_const_i64(imm
);
4853 write_fp_dreg(s
, rd
, tcg_res
);
4854 tcg_temp_free_i64(tcg_res
);
4857 /* Handle floating point <=> fixed point conversions. Note that we can
4858 * also deal with fp <=> integer conversions as a special case (scale == 64)
4859 * OPTME: consider handling that special case specially or at least skipping
4860 * the call to scalbn in the helpers for zero shifts.
4862 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
4863 bool itof
, int rmode
, int scale
, int sf
, int type
)
4865 bool is_signed
= !(opcode
& 1);
4866 bool is_double
= type
;
4867 TCGv_ptr tcg_fpstatus
;
4870 tcg_fpstatus
= get_fpstatus_ptr();
4872 tcg_shift
= tcg_const_i32(64 - scale
);
4875 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
4877 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
4880 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
4882 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
4885 tcg_int
= tcg_extend
;
4889 TCGv_i64 tcg_double
= tcg_temp_new_i64();
4891 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
4892 tcg_shift
, tcg_fpstatus
);
4894 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
4895 tcg_shift
, tcg_fpstatus
);
4897 write_fp_dreg(s
, rd
, tcg_double
);
4898 tcg_temp_free_i64(tcg_double
);
4900 TCGv_i32 tcg_single
= tcg_temp_new_i32();
4902 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
4903 tcg_shift
, tcg_fpstatus
);
4905 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
4906 tcg_shift
, tcg_fpstatus
);
4908 write_fp_sreg(s
, rd
, tcg_single
);
4909 tcg_temp_free_i32(tcg_single
);
4912 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
4915 if (extract32(opcode
, 2, 1)) {
4916 /* There are too many rounding modes to all fit into rmode,
4917 * so FCVTA[US] is a special case.
4919 rmode
= FPROUNDING_TIEAWAY
;
4922 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
4924 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4927 TCGv_i64 tcg_double
= read_fp_dreg(s
, rn
);
4930 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
4931 tcg_shift
, tcg_fpstatus
);
4933 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
4934 tcg_shift
, tcg_fpstatus
);
4938 gen_helper_vfp_tould(tcg_int
, tcg_double
,
4939 tcg_shift
, tcg_fpstatus
);
4941 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
4942 tcg_shift
, tcg_fpstatus
);
4945 tcg_temp_free_i64(tcg_double
);
4947 TCGv_i32 tcg_single
= read_fp_sreg(s
, rn
);
4950 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
4951 tcg_shift
, tcg_fpstatus
);
4953 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
4954 tcg_shift
, tcg_fpstatus
);
4957 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
4959 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
4960 tcg_shift
, tcg_fpstatus
);
4962 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
4963 tcg_shift
, tcg_fpstatus
);
4965 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
4966 tcg_temp_free_i32(tcg_dest
);
4968 tcg_temp_free_i32(tcg_single
);
4971 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4972 tcg_temp_free_i32(tcg_rmode
);
4975 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
4979 tcg_temp_free_ptr(tcg_fpstatus
);
4980 tcg_temp_free_i32(tcg_shift
);
4983 /* C3.6.29 Floating point <-> fixed point conversions
4984 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4985 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4986 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
4987 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4989 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
4991 int rd
= extract32(insn
, 0, 5);
4992 int rn
= extract32(insn
, 5, 5);
4993 int scale
= extract32(insn
, 10, 6);
4994 int opcode
= extract32(insn
, 16, 3);
4995 int rmode
= extract32(insn
, 19, 2);
4996 int type
= extract32(insn
, 22, 2);
4997 bool sbit
= extract32(insn
, 29, 1);
4998 bool sf
= extract32(insn
, 31, 1);
5001 if (sbit
|| (type
> 1)
5002 || (!sf
&& scale
< 32)) {
5003 unallocated_encoding(s
);
5007 switch ((rmode
<< 3) | opcode
) {
5008 case 0x2: /* SCVTF */
5009 case 0x3: /* UCVTF */
5012 case 0x18: /* FCVTZS */
5013 case 0x19: /* FCVTZU */
5017 unallocated_encoding(s
);
5021 if (!fp_access_check(s
)) {
5025 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
5028 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
5030 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
5031 * without conversion.
5035 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
5041 TCGv_i64 tmp
= tcg_temp_new_i64();
5042 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
5043 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
5044 tcg_gen_movi_i64(tmp
, 0);
5045 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5046 tcg_temp_free_i64(tmp
);
5052 TCGv_i64 tmp
= tcg_const_i64(0);
5053 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
5054 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5055 tcg_temp_free_i64(tmp
);
5059 /* 64 bit to top half. */
5060 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5064 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5069 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
5073 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
5076 /* 64 bits from top half */
5077 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
5083 /* C3.6.30 Floating point <-> integer conversions
5084 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
5085 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5086 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
5087 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5089 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
5091 int rd
= extract32(insn
, 0, 5);
5092 int rn
= extract32(insn
, 5, 5);
5093 int opcode
= extract32(insn
, 16, 3);
5094 int rmode
= extract32(insn
, 19, 2);
5095 int type
= extract32(insn
, 22, 2);
5096 bool sbit
= extract32(insn
, 29, 1);
5097 bool sf
= extract32(insn
, 31, 1);
5100 unallocated_encoding(s
);
5106 bool itof
= opcode
& 1;
5109 unallocated_encoding(s
);
5113 switch (sf
<< 3 | type
<< 1 | rmode
) {
5114 case 0x0: /* 32 bit */
5115 case 0xa: /* 64 bit */
5116 case 0xd: /* 64 bit to top half of quad */
5119 /* all other sf/type/rmode combinations are invalid */
5120 unallocated_encoding(s
);
5124 if (!fp_access_check(s
)) {
5127 handle_fmov(s
, rd
, rn
, type
, itof
);
5129 /* actual FP conversions */
5130 bool itof
= extract32(opcode
, 1, 1);
5132 if (type
> 1 || (rmode
!= 0 && opcode
> 1)) {
5133 unallocated_encoding(s
);
5137 if (!fp_access_check(s
)) {
5140 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
5144 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
5145 * 31 30 29 28 25 24 0
5146 * +---+---+---+---------+-----------------------------+
5147 * | | 0 | | 1 1 1 1 | |
5148 * +---+---+---+---------+-----------------------------+
5150 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
5152 if (extract32(insn
, 24, 1)) {
5153 /* Floating point data-processing (3 source) */
5154 disas_fp_3src(s
, insn
);
5155 } else if (extract32(insn
, 21, 1) == 0) {
5156 /* Floating point to fixed point conversions */
5157 disas_fp_fixed_conv(s
, insn
);
5159 switch (extract32(insn
, 10, 2)) {
5161 /* Floating point conditional compare */
5162 disas_fp_ccomp(s
, insn
);
5165 /* Floating point data-processing (2 source) */
5166 disas_fp_2src(s
, insn
);
5169 /* Floating point conditional select */
5170 disas_fp_csel(s
, insn
);
5173 switch (ctz32(extract32(insn
, 12, 4))) {
5174 case 0: /* [15:12] == xxx1 */
5175 /* Floating point immediate */
5176 disas_fp_imm(s
, insn
);
5178 case 1: /* [15:12] == xx10 */
5179 /* Floating point compare */
5180 disas_fp_compare(s
, insn
);
5182 case 2: /* [15:12] == x100 */
5183 /* Floating point data-processing (1 source) */
5184 disas_fp_1src(s
, insn
);
5186 case 3: /* [15:12] == 1000 */
5187 unallocated_encoding(s
);
5189 default: /* [15:12] == 0000 */
5190 /* Floating point <-> integer conversions */
5191 disas_fp_int_conv(s
, insn
);
5199 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
5202 /* Extract 64 bits from the middle of two concatenated 64 bit
5203 * vector register slices left:right. The extracted bits start
5204 * at 'pos' bits into the right (least significant) side.
5205 * We return the result in tcg_right, and guarantee not to
5208 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5209 assert(pos
> 0 && pos
< 64);
5211 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
5212 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
5213 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
5215 tcg_temp_free_i64(tcg_tmp
);
5219 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
5220 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5221 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
5222 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5224 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
5226 int is_q
= extract32(insn
, 30, 1);
5227 int op2
= extract32(insn
, 22, 2);
5228 int imm4
= extract32(insn
, 11, 4);
5229 int rm
= extract32(insn
, 16, 5);
5230 int rn
= extract32(insn
, 5, 5);
5231 int rd
= extract32(insn
, 0, 5);
5232 int pos
= imm4
<< 3;
5233 TCGv_i64 tcg_resl
, tcg_resh
;
5235 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
5236 unallocated_encoding(s
);
5240 if (!fp_access_check(s
)) {
5244 tcg_resh
= tcg_temp_new_i64();
5245 tcg_resl
= tcg_temp_new_i64();
5247 /* Vd gets bits starting at pos bits into Vm:Vn. This is
5248 * either extracting 128 bits from a 128:128 concatenation, or
5249 * extracting 64 bits from a 64:64 concatenation.
5252 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
5254 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
5255 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5257 tcg_gen_movi_i64(tcg_resh
, 0);
5264 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
5265 EltPosns
*elt
= eltposns
;
5272 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
5274 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
5277 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5278 tcg_hh
= tcg_temp_new_i64();
5279 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
5280 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
5281 tcg_temp_free_i64(tcg_hh
);
5285 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5286 tcg_temp_free_i64(tcg_resl
);
5287 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5288 tcg_temp_free_i64(tcg_resh
);
5292 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
5293 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5294 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
5295 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5297 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
5299 int op2
= extract32(insn
, 22, 2);
5300 int is_q
= extract32(insn
, 30, 1);
5301 int rm
= extract32(insn
, 16, 5);
5302 int rn
= extract32(insn
, 5, 5);
5303 int rd
= extract32(insn
, 0, 5);
5304 int is_tblx
= extract32(insn
, 12, 1);
5305 int len
= extract32(insn
, 13, 2);
5306 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
5307 TCGv_i32 tcg_regno
, tcg_numregs
;
5310 unallocated_encoding(s
);
5314 if (!fp_access_check(s
)) {
5318 /* This does a table lookup: for every byte element in the input
5319 * we index into a table formed from up to four vector registers,
5320 * and then the output is the result of the lookups. Our helper
5321 * function does the lookup operation for a single 64 bit part of
5324 tcg_resl
= tcg_temp_new_i64();
5325 tcg_resh
= tcg_temp_new_i64();
5328 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5330 tcg_gen_movi_i64(tcg_resl
, 0);
5332 if (is_tblx
&& is_q
) {
5333 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5335 tcg_gen_movi_i64(tcg_resh
, 0);
5338 tcg_idx
= tcg_temp_new_i64();
5339 tcg_regno
= tcg_const_i32(rn
);
5340 tcg_numregs
= tcg_const_i32(len
+ 1);
5341 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
5342 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
5343 tcg_regno
, tcg_numregs
);
5345 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
5346 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
5347 tcg_regno
, tcg_numregs
);
5349 tcg_temp_free_i64(tcg_idx
);
5350 tcg_temp_free_i32(tcg_regno
);
5351 tcg_temp_free_i32(tcg_numregs
);
5353 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5354 tcg_temp_free_i64(tcg_resl
);
5355 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5356 tcg_temp_free_i64(tcg_resh
);
5359 /* C3.6.3 ZIP/UZP/TRN
5360 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
5361 * +---+---+-------------+------+---+------+---+------------------+------+
5362 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
5363 * +---+---+-------------+------+---+------+---+------------------+------+
5365 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
5367 int rd
= extract32(insn
, 0, 5);
5368 int rn
= extract32(insn
, 5, 5);
5369 int rm
= extract32(insn
, 16, 5);
5370 int size
= extract32(insn
, 22, 2);
5371 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
5372 * bit 2 indicates 1 vs 2 variant of the insn.
5374 int opcode
= extract32(insn
, 12, 2);
5375 bool part
= extract32(insn
, 14, 1);
5376 bool is_q
= extract32(insn
, 30, 1);
5377 int esize
= 8 << size
;
5379 int datasize
= is_q
? 128 : 64;
5380 int elements
= datasize
/ esize
;
5381 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
5383 if (opcode
== 0 || (size
== 3 && !is_q
)) {
5384 unallocated_encoding(s
);
5388 if (!fp_access_check(s
)) {
5392 tcg_resl
= tcg_const_i64(0);
5393 tcg_resh
= tcg_const_i64(0);
5394 tcg_res
= tcg_temp_new_i64();
5396 for (i
= 0; i
< elements
; i
++) {
5398 case 1: /* UZP1/2 */
5400 int midpoint
= elements
/ 2;
5402 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
5404 read_vec_element(s
, tcg_res
, rm
,
5405 2 * (i
- midpoint
) + part
, size
);
5409 case 2: /* TRN1/2 */
5411 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
5413 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
5416 case 3: /* ZIP1/2 */
5418 int base
= part
* elements
/ 2;
5420 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
5422 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
5427 g_assert_not_reached();
5432 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
5433 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
5435 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
5436 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
5440 tcg_temp_free_i64(tcg_res
);
5442 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5443 tcg_temp_free_i64(tcg_resl
);
5444 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5445 tcg_temp_free_i64(tcg_resh
);
5448 static void do_minmaxop(DisasContext
*s
, TCGv_i32 tcg_elt1
, TCGv_i32 tcg_elt2
,
5449 int opc
, bool is_min
, TCGv_ptr fpst
)
5451 /* Helper function for disas_simd_across_lanes: do a single precision
5452 * min/max operation on the specified two inputs,
5453 * and return the result in tcg_elt1.
5457 gen_helper_vfp_minnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5459 gen_helper_vfp_maxnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5464 gen_helper_vfp_mins(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5466 gen_helper_vfp_maxs(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5471 /* C3.6.4 AdvSIMD across lanes
5472 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5473 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5474 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5475 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5477 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
5479 int rd
= extract32(insn
, 0, 5);
5480 int rn
= extract32(insn
, 5, 5);
5481 int size
= extract32(insn
, 22, 2);
5482 int opcode
= extract32(insn
, 12, 5);
5483 bool is_q
= extract32(insn
, 30, 1);
5484 bool is_u
= extract32(insn
, 29, 1);
5486 bool is_min
= false;
5490 TCGv_i64 tcg_res
, tcg_elt
;
5493 case 0x1b: /* ADDV */
5495 unallocated_encoding(s
);
5499 case 0x3: /* SADDLV, UADDLV */
5500 case 0xa: /* SMAXV, UMAXV */
5501 case 0x1a: /* SMINV, UMINV */
5502 if (size
== 3 || (size
== 2 && !is_q
)) {
5503 unallocated_encoding(s
);
5507 case 0xc: /* FMAXNMV, FMINNMV */
5508 case 0xf: /* FMAXV, FMINV */
5509 if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
5510 unallocated_encoding(s
);
5513 /* Bit 1 of size field encodes min vs max, and actual size is always
5514 * 32 bits: adjust the size variable so following code can rely on it
5516 is_min
= extract32(size
, 1, 1);
5521 unallocated_encoding(s
);
5525 if (!fp_access_check(s
)) {
5530 elements
= (is_q
? 128 : 64) / esize
;
5532 tcg_res
= tcg_temp_new_i64();
5533 tcg_elt
= tcg_temp_new_i64();
5535 /* These instructions operate across all lanes of a vector
5536 * to produce a single result. We can guarantee that a 64
5537 * bit intermediate is sufficient:
5538 * + for [US]ADDLV the maximum element size is 32 bits, and
5539 * the result type is 64 bits
5540 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
5541 * same as the element size, which is 32 bits at most
5542 * For the integer operations we can choose to work at 64
5543 * or 32 bits and truncate at the end; for simplicity
5544 * we use 64 bits always. The floating point
5545 * ops do require 32 bit intermediates, though.
5548 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
5550 for (i
= 1; i
< elements
; i
++) {
5551 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
5554 case 0x03: /* SADDLV / UADDLV */
5555 case 0x1b: /* ADDV */
5556 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
5558 case 0x0a: /* SMAXV / UMAXV */
5559 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
5561 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5563 case 0x1a: /* SMINV / UMINV */
5564 tcg_gen_movcond_i64(is_u
? TCG_COND_LEU
: TCG_COND_LE
,
5566 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5570 g_assert_not_reached();
5575 /* Floating point ops which work on 32 bit (single) intermediates.
5576 * Note that correct NaN propagation requires that we do these
5577 * operations in exactly the order specified by the pseudocode.
5579 TCGv_i32 tcg_elt1
= tcg_temp_new_i32();
5580 TCGv_i32 tcg_elt2
= tcg_temp_new_i32();
5581 TCGv_i32 tcg_elt3
= tcg_temp_new_i32();
5582 TCGv_ptr fpst
= get_fpstatus_ptr();
5584 assert(esize
== 32);
5585 assert(elements
== 4);
5587 read_vec_element(s
, tcg_elt
, rn
, 0, MO_32
);
5588 tcg_gen_extrl_i64_i32(tcg_elt1
, tcg_elt
);
5589 read_vec_element(s
, tcg_elt
, rn
, 1, MO_32
);
5590 tcg_gen_extrl_i64_i32(tcg_elt2
, tcg_elt
);
5592 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5594 read_vec_element(s
, tcg_elt
, rn
, 2, MO_32
);
5595 tcg_gen_extrl_i64_i32(tcg_elt2
, tcg_elt
);
5596 read_vec_element(s
, tcg_elt
, rn
, 3, MO_32
);
5597 tcg_gen_extrl_i64_i32(tcg_elt3
, tcg_elt
);
5599 do_minmaxop(s
, tcg_elt2
, tcg_elt3
, opcode
, is_min
, fpst
);
5601 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5603 tcg_gen_extu_i32_i64(tcg_res
, tcg_elt1
);
5604 tcg_temp_free_i32(tcg_elt1
);
5605 tcg_temp_free_i32(tcg_elt2
);
5606 tcg_temp_free_i32(tcg_elt3
);
5607 tcg_temp_free_ptr(fpst
);
5610 tcg_temp_free_i64(tcg_elt
);
5612 /* Now truncate the result to the width required for the final output */
5613 if (opcode
== 0x03) {
5614 /* SADDLV, UADDLV: result is 2*esize */
5620 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
5623 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
5626 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
5631 g_assert_not_reached();
5634 write_fp_dreg(s
, rd
, tcg_res
);
5635 tcg_temp_free_i64(tcg_res
);
5638 /* C6.3.31 DUP (Element, Vector)
5640 * 31 30 29 21 20 16 15 10 9 5 4 0
5641 * +---+---+-------------------+--------+-------------+------+------+
5642 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5643 * +---+---+-------------------+--------+-------------+------+------+
5645 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5647 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
5650 int size
= ctz32(imm5
);
5651 int esize
= 8 << size
;
5652 int elements
= (is_q
? 128 : 64) / esize
;
5656 if (size
> 3 || (size
== 3 && !is_q
)) {
5657 unallocated_encoding(s
);
5661 if (!fp_access_check(s
)) {
5665 index
= imm5
>> (size
+ 1);
5667 tmp
= tcg_temp_new_i64();
5668 read_vec_element(s
, tmp
, rn
, index
, size
);
5670 for (i
= 0; i
< elements
; i
++) {
5671 write_vec_element(s
, tmp
, rd
, i
, size
);
5675 clear_vec_high(s
, rd
);
5678 tcg_temp_free_i64(tmp
);
5681 /* C6.3.31 DUP (element, scalar)
5682 * 31 21 20 16 15 10 9 5 4 0
5683 * +-----------------------+--------+-------------+------+------+
5684 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5685 * +-----------------------+--------+-------------+------+------+
5687 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
5690 int size
= ctz32(imm5
);
5695 unallocated_encoding(s
);
5699 if (!fp_access_check(s
)) {
5703 index
= imm5
>> (size
+ 1);
5705 /* This instruction just extracts the specified element and
5706 * zero-extends it into the bottom of the destination register.
5708 tmp
= tcg_temp_new_i64();
5709 read_vec_element(s
, tmp
, rn
, index
, size
);
5710 write_fp_dreg(s
, rd
, tmp
);
5711 tcg_temp_free_i64(tmp
);
5714 /* C6.3.32 DUP (General)
5716 * 31 30 29 21 20 16 15 10 9 5 4 0
5717 * +---+---+-------------------+--------+-------------+------+------+
5718 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
5719 * +---+---+-------------------+--------+-------------+------+------+
5721 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5723 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
5726 int size
= ctz32(imm5
);
5727 int esize
= 8 << size
;
5728 int elements
= (is_q
? 128 : 64)/esize
;
5731 if (size
> 3 || ((size
== 3) && !is_q
)) {
5732 unallocated_encoding(s
);
5736 if (!fp_access_check(s
)) {
5740 for (i
= 0; i
< elements
; i
++) {
5741 write_vec_element(s
, cpu_reg(s
, rn
), rd
, i
, size
);
5744 clear_vec_high(s
, rd
);
5748 /* C6.3.150 INS (Element)
5750 * 31 21 20 16 15 14 11 10 9 5 4 0
5751 * +-----------------------+--------+------------+---+------+------+
5752 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5753 * +-----------------------+--------+------------+---+------+------+
5755 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5756 * index: encoded in imm5<4:size+1>
5758 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
5761 int size
= ctz32(imm5
);
5762 int src_index
, dst_index
;
5766 unallocated_encoding(s
);
5770 if (!fp_access_check(s
)) {
5774 dst_index
= extract32(imm5
, 1+size
, 5);
5775 src_index
= extract32(imm4
, size
, 4);
5777 tmp
= tcg_temp_new_i64();
5779 read_vec_element(s
, tmp
, rn
, src_index
, size
);
5780 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
5782 tcg_temp_free_i64(tmp
);
5786 /* C6.3.151 INS (General)
5788 * 31 21 20 16 15 10 9 5 4 0
5789 * +-----------------------+--------+-------------+------+------+
5790 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
5791 * +-----------------------+--------+-------------+------+------+
5793 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5794 * index: encoded in imm5<4:size+1>
5796 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
5798 int size
= ctz32(imm5
);
5802 unallocated_encoding(s
);
5806 if (!fp_access_check(s
)) {
5810 idx
= extract32(imm5
, 1 + size
, 4 - size
);
5811 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
5815 * C6.3.321 UMOV (General)
5816 * C6.3.237 SMOV (General)
5818 * 31 30 29 21 20 16 15 12 10 9 5 4 0
5819 * +---+---+-------------------+--------+-------------+------+------+
5820 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
5821 * +---+---+-------------------+--------+-------------+------+------+
5823 * U: unsigned when set
5824 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5826 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
5827 int rn
, int rd
, int imm5
)
5829 int size
= ctz32(imm5
);
5833 /* Check for UnallocatedEncodings */
5835 if (size
> 2 || (size
== 2 && !is_q
)) {
5836 unallocated_encoding(s
);
5841 || (size
< 3 && is_q
)
5842 || (size
== 3 && !is_q
)) {
5843 unallocated_encoding(s
);
5848 if (!fp_access_check(s
)) {
5852 element
= extract32(imm5
, 1+size
, 4);
5854 tcg_rd
= cpu_reg(s
, rd
);
5855 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
5856 if (is_signed
&& !is_q
) {
5857 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5861 /* C3.6.5 AdvSIMD copy
5862 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5863 * +---+---+----+-----------------+------+---+------+---+------+------+
5864 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5865 * +---+---+----+-----------------+------+---+------+---+------+------+
5867 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
5869 int rd
= extract32(insn
, 0, 5);
5870 int rn
= extract32(insn
, 5, 5);
5871 int imm4
= extract32(insn
, 11, 4);
5872 int op
= extract32(insn
, 29, 1);
5873 int is_q
= extract32(insn
, 30, 1);
5874 int imm5
= extract32(insn
, 16, 5);
5879 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
5881 unallocated_encoding(s
);
5886 /* DUP (element - vector) */
5887 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
5891 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
5896 handle_simd_insg(s
, rd
, rn
, imm5
);
5898 unallocated_encoding(s
);
5903 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
5904 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
5907 unallocated_encoding(s
);
5913 /* C3.6.6 AdvSIMD modified immediate
5914 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
5915 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5916 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
5917 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5919 * There are a number of operations that can be carried out here:
5920 * MOVI - move (shifted) imm into register
5921 * MVNI - move inverted (shifted) imm into register
5922 * ORR - bitwise OR of (shifted) imm with register
5923 * BIC - bitwise clear of (shifted) imm with register
5925 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
5927 int rd
= extract32(insn
, 0, 5);
5928 int cmode
= extract32(insn
, 12, 4);
5929 int cmode_3_1
= extract32(cmode
, 1, 3);
5930 int cmode_0
= extract32(cmode
, 0, 1);
5931 int o2
= extract32(insn
, 11, 1);
5932 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
5933 bool is_neg
= extract32(insn
, 29, 1);
5934 bool is_q
= extract32(insn
, 30, 1);
5936 TCGv_i64 tcg_rd
, tcg_imm
;
5939 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
5940 unallocated_encoding(s
);
5944 if (!fp_access_check(s
)) {
5948 /* See AdvSIMDExpandImm() in ARM ARM */
5949 switch (cmode_3_1
) {
5950 case 0: /* Replicate(Zeros(24):imm8, 2) */
5951 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
5952 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
5953 case 3: /* Replicate(imm8:Zeros(24), 2) */
5955 int shift
= cmode_3_1
* 8;
5956 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
5959 case 4: /* Replicate(Zeros(8):imm8, 4) */
5960 case 5: /* Replicate(imm8:Zeros(8), 4) */
5962 int shift
= (cmode_3_1
& 0x1) * 8;
5963 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
5968 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
5969 imm
= (abcdefgh
<< 16) | 0xffff;
5971 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
5972 imm
= (abcdefgh
<< 8) | 0xff;
5974 imm
= bitfield_replicate(imm
, 32);
5977 if (!cmode_0
&& !is_neg
) {
5978 imm
= bitfield_replicate(abcdefgh
, 8);
5979 } else if (!cmode_0
&& is_neg
) {
5982 for (i
= 0; i
< 8; i
++) {
5983 if ((abcdefgh
) & (1 << i
)) {
5984 imm
|= 0xffULL
<< (i
* 8);
5987 } else if (cmode_0
) {
5989 imm
= (abcdefgh
& 0x3f) << 48;
5990 if (abcdefgh
& 0x80) {
5991 imm
|= 0x8000000000000000ULL
;
5993 if (abcdefgh
& 0x40) {
5994 imm
|= 0x3fc0000000000000ULL
;
5996 imm
|= 0x4000000000000000ULL
;
5999 imm
= (abcdefgh
& 0x3f) << 19;
6000 if (abcdefgh
& 0x80) {
6003 if (abcdefgh
& 0x40) {
6014 if (cmode_3_1
!= 7 && is_neg
) {
6018 tcg_imm
= tcg_const_i64(imm
);
6019 tcg_rd
= new_tmp_a64(s
);
6021 for (i
= 0; i
< 2; i
++) {
6022 int foffs
= i
? fp_reg_hi_offset(s
, rd
) : fp_reg_offset(s
, rd
, MO_64
);
6024 if (i
== 1 && !is_q
) {
6025 /* non-quad ops clear high half of vector */
6026 tcg_gen_movi_i64(tcg_rd
, 0);
6027 } else if ((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9) {
6028 tcg_gen_ld_i64(tcg_rd
, cpu_env
, foffs
);
6031 tcg_gen_and_i64(tcg_rd
, tcg_rd
, tcg_imm
);
6034 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_imm
);
6038 tcg_gen_mov_i64(tcg_rd
, tcg_imm
);
6040 tcg_gen_st_i64(tcg_rd
, cpu_env
, foffs
);
6043 tcg_temp_free_i64(tcg_imm
);
6046 /* C3.6.7 AdvSIMD scalar copy
6047 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
6048 * +-----+----+-----------------+------+---+------+---+------+------+
6049 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6050 * +-----+----+-----------------+------+---+------+---+------+------+
6052 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
6054 int rd
= extract32(insn
, 0, 5);
6055 int rn
= extract32(insn
, 5, 5);
6056 int imm4
= extract32(insn
, 11, 4);
6057 int imm5
= extract32(insn
, 16, 5);
6058 int op
= extract32(insn
, 29, 1);
6060 if (op
!= 0 || imm4
!= 0) {
6061 unallocated_encoding(s
);
6065 /* DUP (element, scalar) */
6066 handle_simd_dupes(s
, rd
, rn
, imm5
);
6069 /* C3.6.8 AdvSIMD scalar pairwise
6070 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6071 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6072 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6073 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6075 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
6077 int u
= extract32(insn
, 29, 1);
6078 int size
= extract32(insn
, 22, 2);
6079 int opcode
= extract32(insn
, 12, 5);
6080 int rn
= extract32(insn
, 5, 5);
6081 int rd
= extract32(insn
, 0, 5);
6084 /* For some ops (the FP ones), size[1] is part of the encoding.
6085 * For ADDP strictly it is not but size[1] is always 1 for valid
6088 opcode
|= (extract32(size
, 1, 1) << 5);
6091 case 0x3b: /* ADDP */
6092 if (u
|| size
!= 3) {
6093 unallocated_encoding(s
);
6096 if (!fp_access_check(s
)) {
6100 TCGV_UNUSED_PTR(fpst
);
6102 case 0xc: /* FMAXNMP */
6103 case 0xd: /* FADDP */
6104 case 0xf: /* FMAXP */
6105 case 0x2c: /* FMINNMP */
6106 case 0x2f: /* FMINP */
6107 /* FP op, size[0] is 32 or 64 bit */
6109 unallocated_encoding(s
);
6112 if (!fp_access_check(s
)) {
6116 size
= extract32(size
, 0, 1) ? 3 : 2;
6117 fpst
= get_fpstatus_ptr();
6120 unallocated_encoding(s
);
6125 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6126 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6127 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6129 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
6130 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
6133 case 0x3b: /* ADDP */
6134 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
6136 case 0xc: /* FMAXNMP */
6137 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6139 case 0xd: /* FADDP */
6140 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6142 case 0xf: /* FMAXP */
6143 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6145 case 0x2c: /* FMINNMP */
6146 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6148 case 0x2f: /* FMINP */
6149 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6152 g_assert_not_reached();
6155 write_fp_dreg(s
, rd
, tcg_res
);
6157 tcg_temp_free_i64(tcg_op1
);
6158 tcg_temp_free_i64(tcg_op2
);
6159 tcg_temp_free_i64(tcg_res
);
6161 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6162 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6163 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6165 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_32
);
6166 read_vec_element_i32(s
, tcg_op2
, rn
, 1, MO_32
);
6169 case 0xc: /* FMAXNMP */
6170 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6172 case 0xd: /* FADDP */
6173 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6175 case 0xf: /* FMAXP */
6176 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6178 case 0x2c: /* FMINNMP */
6179 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6181 case 0x2f: /* FMINP */
6182 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6185 g_assert_not_reached();
6188 write_fp_sreg(s
, rd
, tcg_res
);
6190 tcg_temp_free_i32(tcg_op1
);
6191 tcg_temp_free_i32(tcg_op2
);
6192 tcg_temp_free_i32(tcg_res
);
6195 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
6196 tcg_temp_free_ptr(fpst
);
6201 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
6203 * This code is handles the common shifting code and is used by both
6204 * the vector and scalar code.
6206 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6207 TCGv_i64 tcg_rnd
, bool accumulate
,
6208 bool is_u
, int size
, int shift
)
6210 bool extended_result
= false;
6211 bool round
= !TCGV_IS_UNUSED_I64(tcg_rnd
);
6213 TCGv_i64 tcg_src_hi
;
6215 if (round
&& size
== 3) {
6216 extended_result
= true;
6217 ext_lshift
= 64 - shift
;
6218 tcg_src_hi
= tcg_temp_new_i64();
6219 } else if (shift
== 64) {
6220 if (!accumulate
&& is_u
) {
6221 /* result is zero */
6222 tcg_gen_movi_i64(tcg_res
, 0);
6227 /* Deal with the rounding step */
6229 if (extended_result
) {
6230 TCGv_i64 tcg_zero
= tcg_const_i64(0);
6232 /* take care of sign extending tcg_res */
6233 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
6234 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6235 tcg_src
, tcg_src_hi
,
6238 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6242 tcg_temp_free_i64(tcg_zero
);
6244 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
6248 /* Now do the shift right */
6249 if (round
&& extended_result
) {
6250 /* extended case, >64 bit precision required */
6251 if (ext_lshift
== 0) {
6252 /* special case, only high bits matter */
6253 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
6255 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6256 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
6257 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
6262 /* essentially shifting in 64 zeros */
6263 tcg_gen_movi_i64(tcg_src
, 0);
6265 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6269 /* effectively extending the sign-bit */
6270 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
6272 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
6278 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
6280 tcg_gen_mov_i64(tcg_res
, tcg_src
);
6283 if (extended_result
) {
6284 tcg_temp_free_i64(tcg_src_hi
);
6288 /* Common SHL/SLI - Shift left with an optional insert */
6289 static void handle_shli_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6290 bool insert
, int shift
)
6292 if (insert
) { /* SLI */
6293 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, shift
, 64 - shift
);
6295 tcg_gen_shli_i64(tcg_res
, tcg_src
, shift
);
6299 /* SRI: shift right with insert */
6300 static void handle_shri_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6301 int size
, int shift
)
6303 int esize
= 8 << size
;
6305 /* shift count same as element size is valid but does nothing;
6306 * special case to avoid potential shift by 64.
6308 if (shift
!= esize
) {
6309 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6310 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, 0, esize
- shift
);
6314 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
6315 static void handle_scalar_simd_shri(DisasContext
*s
,
6316 bool is_u
, int immh
, int immb
,
6317 int opcode
, int rn
, int rd
)
6320 int immhb
= immh
<< 3 | immb
;
6321 int shift
= 2 * (8 << size
) - immhb
;
6322 bool accumulate
= false;
6324 bool insert
= false;
6329 if (!extract32(immh
, 3, 1)) {
6330 unallocated_encoding(s
);
6334 if (!fp_access_check(s
)) {
6339 case 0x02: /* SSRA / USRA (accumulate) */
6342 case 0x04: /* SRSHR / URSHR (rounding) */
6345 case 0x06: /* SRSRA / URSRA (accum + rounding) */
6346 accumulate
= round
= true;
6348 case 0x08: /* SRI */
6354 uint64_t round_const
= 1ULL << (shift
- 1);
6355 tcg_round
= tcg_const_i64(round_const
);
6357 TCGV_UNUSED_I64(tcg_round
);
6360 tcg_rn
= read_fp_dreg(s
, rn
);
6361 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6364 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
6366 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6367 accumulate
, is_u
, size
, shift
);
6370 write_fp_dreg(s
, rd
, tcg_rd
);
6372 tcg_temp_free_i64(tcg_rn
);
6373 tcg_temp_free_i64(tcg_rd
);
6375 tcg_temp_free_i64(tcg_round
);
6379 /* SHL/SLI - Scalar shift left */
6380 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
6381 int immh
, int immb
, int opcode
,
6384 int size
= 32 - clz32(immh
) - 1;
6385 int immhb
= immh
<< 3 | immb
;
6386 int shift
= immhb
- (8 << size
);
6387 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
6388 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
6390 if (!extract32(immh
, 3, 1)) {
6391 unallocated_encoding(s
);
6395 if (!fp_access_check(s
)) {
6399 tcg_rn
= read_fp_dreg(s
, rn
);
6400 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6402 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
6404 write_fp_dreg(s
, rd
, tcg_rd
);
6406 tcg_temp_free_i64(tcg_rn
);
6407 tcg_temp_free_i64(tcg_rd
);
6410 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
6411 * (signed/unsigned) narrowing */
6412 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
6413 bool is_u_shift
, bool is_u_narrow
,
6414 int immh
, int immb
, int opcode
,
6417 int immhb
= immh
<< 3 | immb
;
6418 int size
= 32 - clz32(immh
) - 1;
6419 int esize
= 8 << size
;
6420 int shift
= (2 * esize
) - immhb
;
6421 int elements
= is_scalar
? 1 : (64 / esize
);
6422 bool round
= extract32(opcode
, 0, 1);
6423 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
6424 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
6425 TCGv_i32 tcg_rd_narrowed
;
6428 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
6429 { gen_helper_neon_narrow_sat_s8
,
6430 gen_helper_neon_unarrow_sat8
},
6431 { gen_helper_neon_narrow_sat_s16
,
6432 gen_helper_neon_unarrow_sat16
},
6433 { gen_helper_neon_narrow_sat_s32
,
6434 gen_helper_neon_unarrow_sat32
},
6437 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
6438 gen_helper_neon_narrow_sat_u8
,
6439 gen_helper_neon_narrow_sat_u16
,
6440 gen_helper_neon_narrow_sat_u32
,
6443 NeonGenNarrowEnvFn
*narrowfn
;
6449 if (extract32(immh
, 3, 1)) {
6450 unallocated_encoding(s
);
6454 if (!fp_access_check(s
)) {
6459 narrowfn
= unsigned_narrow_fns
[size
];
6461 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
6464 tcg_rn
= tcg_temp_new_i64();
6465 tcg_rd
= tcg_temp_new_i64();
6466 tcg_rd_narrowed
= tcg_temp_new_i32();
6467 tcg_final
= tcg_const_i64(0);
6470 uint64_t round_const
= 1ULL << (shift
- 1);
6471 tcg_round
= tcg_const_i64(round_const
);
6473 TCGV_UNUSED_I64(tcg_round
);
6476 for (i
= 0; i
< elements
; i
++) {
6477 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
6478 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6479 false, is_u_shift
, size
+1, shift
);
6480 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
6481 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
6482 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
6486 clear_vec_high(s
, rd
);
6487 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
6489 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
6493 tcg_temp_free_i64(tcg_round
);
6495 tcg_temp_free_i64(tcg_rn
);
6496 tcg_temp_free_i64(tcg_rd
);
6497 tcg_temp_free_i32(tcg_rd_narrowed
);
6498 tcg_temp_free_i64(tcg_final
);
6502 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
6503 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
6504 bool src_unsigned
, bool dst_unsigned
,
6505 int immh
, int immb
, int rn
, int rd
)
6507 int immhb
= immh
<< 3 | immb
;
6508 int size
= 32 - clz32(immh
) - 1;
6509 int shift
= immhb
- (8 << size
);
6513 assert(!(scalar
&& is_q
));
6516 if (!is_q
&& extract32(immh
, 3, 1)) {
6517 unallocated_encoding(s
);
6521 /* Since we use the variable-shift helpers we must
6522 * replicate the shift count into each element of
6523 * the tcg_shift value.
6527 shift
|= shift
<< 8;
6530 shift
|= shift
<< 16;
6536 g_assert_not_reached();
6540 if (!fp_access_check(s
)) {
6545 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
6546 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
6547 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
6548 { NULL
, gen_helper_neon_qshl_u64
},
6550 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
6551 int maxpass
= is_q
? 2 : 1;
6553 for (pass
= 0; pass
< maxpass
; pass
++) {
6554 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6556 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6557 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6558 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6560 tcg_temp_free_i64(tcg_op
);
6562 tcg_temp_free_i64(tcg_shift
);
6565 clear_vec_high(s
, rd
);
6568 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
6569 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
6571 { gen_helper_neon_qshl_s8
,
6572 gen_helper_neon_qshl_s16
,
6573 gen_helper_neon_qshl_s32
},
6574 { gen_helper_neon_qshlu_s8
,
6575 gen_helper_neon_qshlu_s16
,
6576 gen_helper_neon_qshlu_s32
}
6578 { NULL
, NULL
, NULL
},
6579 { gen_helper_neon_qshl_u8
,
6580 gen_helper_neon_qshl_u16
,
6581 gen_helper_neon_qshl_u32
}
6584 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
6585 TCGMemOp memop
= scalar
? size
: MO_32
;
6586 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
6588 for (pass
= 0; pass
< maxpass
; pass
++) {
6589 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6591 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
6592 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6596 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
6599 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
6604 g_assert_not_reached();
6606 write_fp_sreg(s
, rd
, tcg_op
);
6608 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6611 tcg_temp_free_i32(tcg_op
);
6613 tcg_temp_free_i32(tcg_shift
);
6615 if (!is_q
&& !scalar
) {
6616 clear_vec_high(s
, rd
);
6621 /* Common vector code for handling integer to FP conversion */
6622 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
6623 int elements
, int is_signed
,
6624 int fracbits
, int size
)
6626 bool is_double
= size
== 3 ? true : false;
6627 TCGv_ptr tcg_fpst
= get_fpstatus_ptr();
6628 TCGv_i32 tcg_shift
= tcg_const_i32(fracbits
);
6629 TCGv_i64 tcg_int
= tcg_temp_new_i64();
6630 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
6633 for (pass
= 0; pass
< elements
; pass
++) {
6634 read_vec_element(s
, tcg_int
, rn
, pass
, mop
);
6637 TCGv_i64 tcg_double
= tcg_temp_new_i64();
6639 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6640 tcg_shift
, tcg_fpst
);
6642 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6643 tcg_shift
, tcg_fpst
);
6645 if (elements
== 1) {
6646 write_fp_dreg(s
, rd
, tcg_double
);
6648 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
6650 tcg_temp_free_i64(tcg_double
);
6652 TCGv_i32 tcg_single
= tcg_temp_new_i32();
6654 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6655 tcg_shift
, tcg_fpst
);
6657 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6658 tcg_shift
, tcg_fpst
);
6660 if (elements
== 1) {
6661 write_fp_sreg(s
, rd
, tcg_single
);
6663 write_vec_element_i32(s
, tcg_single
, rd
, pass
, MO_32
);
6665 tcg_temp_free_i32(tcg_single
);
6669 if (!is_double
&& elements
== 2) {
6670 clear_vec_high(s
, rd
);
6673 tcg_temp_free_i64(tcg_int
);
6674 tcg_temp_free_ptr(tcg_fpst
);
6675 tcg_temp_free_i32(tcg_shift
);
6678 /* UCVTF/SCVTF - Integer to FP conversion */
6679 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
6680 bool is_q
, bool is_u
,
6681 int immh
, int immb
, int opcode
,
6684 bool is_double
= extract32(immh
, 3, 1);
6685 int size
= is_double
? MO_64
: MO_32
;
6687 int immhb
= immh
<< 3 | immb
;
6688 int fracbits
= (is_double
? 128 : 64) - immhb
;
6690 if (!extract32(immh
, 2, 2)) {
6691 unallocated_encoding(s
);
6698 elements
= is_double
? 2 : is_q
? 4 : 2;
6699 if (is_double
&& !is_q
) {
6700 unallocated_encoding(s
);
6705 if (!fp_access_check(s
)) {
6709 /* immh == 0 would be a failure of the decode logic */
6712 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
6715 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
6716 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
6717 bool is_q
, bool is_u
,
6718 int immh
, int immb
, int rn
, int rd
)
6720 bool is_double
= extract32(immh
, 3, 1);
6721 int immhb
= immh
<< 3 | immb
;
6722 int fracbits
= (is_double
? 128 : 64) - immhb
;
6724 TCGv_ptr tcg_fpstatus
;
6725 TCGv_i32 tcg_rmode
, tcg_shift
;
6727 if (!extract32(immh
, 2, 2)) {
6728 unallocated_encoding(s
);
6732 if (!is_scalar
&& !is_q
&& is_double
) {
6733 unallocated_encoding(s
);
6737 if (!fp_access_check(s
)) {
6741 assert(!(is_scalar
&& is_q
));
6743 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
6744 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6745 tcg_fpstatus
= get_fpstatus_ptr();
6746 tcg_shift
= tcg_const_i32(fracbits
);
6749 int maxpass
= is_scalar
? 1 : 2;
6751 for (pass
= 0; pass
< maxpass
; pass
++) {
6752 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6754 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6756 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6758 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6760 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6761 tcg_temp_free_i64(tcg_op
);
6764 clear_vec_high(s
, rd
);
6767 int maxpass
= is_scalar
? 1 : is_q
? 4 : 2;
6768 for (pass
= 0; pass
< maxpass
; pass
++) {
6769 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6771 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
6773 gen_helper_vfp_touls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6775 gen_helper_vfp_tosls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6778 write_fp_sreg(s
, rd
, tcg_op
);
6780 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6782 tcg_temp_free_i32(tcg_op
);
6784 if (!is_q
&& !is_scalar
) {
6785 clear_vec_high(s
, rd
);
6789 tcg_temp_free_ptr(tcg_fpstatus
);
6790 tcg_temp_free_i32(tcg_shift
);
6791 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6792 tcg_temp_free_i32(tcg_rmode
);
6795 /* C3.6.9 AdvSIMD scalar shift by immediate
6796 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
6797 * +-----+---+-------------+------+------+--------+---+------+------+
6798 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
6799 * +-----+---+-------------+------+------+--------+---+------+------+
6801 * This is the scalar version so it works on a fixed sized registers
6803 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
6805 int rd
= extract32(insn
, 0, 5);
6806 int rn
= extract32(insn
, 5, 5);
6807 int opcode
= extract32(insn
, 11, 5);
6808 int immb
= extract32(insn
, 16, 3);
6809 int immh
= extract32(insn
, 19, 4);
6810 bool is_u
= extract32(insn
, 29, 1);
6813 unallocated_encoding(s
);
6818 case 0x08: /* SRI */
6820 unallocated_encoding(s
);
6824 case 0x00: /* SSHR / USHR */
6825 case 0x02: /* SSRA / USRA */
6826 case 0x04: /* SRSHR / URSHR */
6827 case 0x06: /* SRSRA / URSRA */
6828 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6830 case 0x0a: /* SHL / SLI */
6831 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6833 case 0x1c: /* SCVTF, UCVTF */
6834 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
6837 case 0x10: /* SQSHRUN, SQSHRUN2 */
6838 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
6840 unallocated_encoding(s
);
6843 handle_vec_simd_sqshrn(s
, true, false, false, true,
6844 immh
, immb
, opcode
, rn
, rd
);
6846 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
6847 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
6848 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
6849 immh
, immb
, opcode
, rn
, rd
);
6851 case 0xc: /* SQSHLU */
6853 unallocated_encoding(s
);
6856 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
6858 case 0xe: /* SQSHL, UQSHL */
6859 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
6861 case 0x1f: /* FCVTZS, FCVTZU */
6862 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
6865 unallocated_encoding(s
);
6870 /* C3.6.10 AdvSIMD scalar three different
6871 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6872 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6873 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
6874 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6876 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
6878 bool is_u
= extract32(insn
, 29, 1);
6879 int size
= extract32(insn
, 22, 2);
6880 int opcode
= extract32(insn
, 12, 4);
6881 int rm
= extract32(insn
, 16, 5);
6882 int rn
= extract32(insn
, 5, 5);
6883 int rd
= extract32(insn
, 0, 5);
6886 unallocated_encoding(s
);
6891 case 0x9: /* SQDMLAL, SQDMLAL2 */
6892 case 0xb: /* SQDMLSL, SQDMLSL2 */
6893 case 0xd: /* SQDMULL, SQDMULL2 */
6894 if (size
== 0 || size
== 3) {
6895 unallocated_encoding(s
);
6900 unallocated_encoding(s
);
6904 if (!fp_access_check(s
)) {
6909 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6910 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6911 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6913 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
6914 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
6916 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
6917 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6920 case 0xd: /* SQDMULL, SQDMULL2 */
6922 case 0xb: /* SQDMLSL, SQDMLSL2 */
6923 tcg_gen_neg_i64(tcg_res
, tcg_res
);
6925 case 0x9: /* SQDMLAL, SQDMLAL2 */
6926 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
6927 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
6931 g_assert_not_reached();
6934 write_fp_dreg(s
, rd
, tcg_res
);
6936 tcg_temp_free_i64(tcg_op1
);
6937 tcg_temp_free_i64(tcg_op2
);
6938 tcg_temp_free_i64(tcg_res
);
6940 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6941 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6942 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6944 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_16
);
6945 read_vec_element_i32(s
, tcg_op2
, rm
, 0, MO_16
);
6947 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
6948 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6951 case 0xd: /* SQDMULL, SQDMULL2 */
6953 case 0xb: /* SQDMLSL, SQDMLSL2 */
6954 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
6956 case 0x9: /* SQDMLAL, SQDMLAL2 */
6958 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
6959 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
6960 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
6962 tcg_temp_free_i64(tcg_op3
);
6966 g_assert_not_reached();
6969 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
6970 write_fp_dreg(s
, rd
, tcg_res
);
6972 tcg_temp_free_i32(tcg_op1
);
6973 tcg_temp_free_i32(tcg_op2
);
6974 tcg_temp_free_i64(tcg_res
);
6978 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
6979 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
6981 /* Handle 64x64->64 opcodes which are shared between the scalar
6982 * and vector 3-same groups. We cover every opcode where size == 3
6983 * is valid in either the three-reg-same (integer, not pairwise)
6984 * or scalar-three-reg-same groups. (Some opcodes are not yet
6990 case 0x1: /* SQADD */
6992 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6994 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6997 case 0x5: /* SQSUB */
6999 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7001 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7004 case 0x6: /* CMGT, CMHI */
7005 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
7006 * We implement this using setcond (test) and then negating.
7008 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
7010 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
7011 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7013 case 0x7: /* CMGE, CMHS */
7014 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
7016 case 0x11: /* CMTST, CMEQ */
7021 /* CMTST : test is "if (X & Y != 0)". */
7022 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
7023 tcg_gen_setcondi_i64(TCG_COND_NE
, tcg_rd
, tcg_rd
, 0);
7024 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7026 case 0x8: /* SSHL, USHL */
7028 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
7030 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
7033 case 0x9: /* SQSHL, UQSHL */
7035 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7037 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7040 case 0xa: /* SRSHL, URSHL */
7042 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
7044 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
7047 case 0xb: /* SQRSHL, UQRSHL */
7049 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7051 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7054 case 0x10: /* ADD, SUB */
7056 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
7058 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
7062 g_assert_not_reached();
7066 /* Handle the 3-same-operands float operations; shared by the scalar
7067 * and vector encodings. The caller must filter out any encodings
7068 * not allocated for the encoding it is dealing with.
7070 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
7071 int fpopcode
, int rd
, int rn
, int rm
)
7074 TCGv_ptr fpst
= get_fpstatus_ptr();
7076 for (pass
= 0; pass
< elements
; pass
++) {
7079 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7080 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7081 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7083 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
7084 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
7087 case 0x39: /* FMLS */
7088 /* As usual for ARM, separate negation for fused multiply-add */
7089 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
7091 case 0x19: /* FMLA */
7092 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7093 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
7096 case 0x18: /* FMAXNM */
7097 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7099 case 0x1a: /* FADD */
7100 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7102 case 0x1b: /* FMULX */
7103 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7105 case 0x1c: /* FCMEQ */
7106 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7108 case 0x1e: /* FMAX */
7109 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7111 case 0x1f: /* FRECPS */
7112 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7114 case 0x38: /* FMINNM */
7115 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7117 case 0x3a: /* FSUB */
7118 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7120 case 0x3e: /* FMIN */
7121 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7123 case 0x3f: /* FRSQRTS */
7124 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7126 case 0x5b: /* FMUL */
7127 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7129 case 0x5c: /* FCMGE */
7130 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7132 case 0x5d: /* FACGE */
7133 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7135 case 0x5f: /* FDIV */
7136 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7138 case 0x7a: /* FABD */
7139 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7140 gen_helper_vfp_absd(tcg_res
, tcg_res
);
7142 case 0x7c: /* FCMGT */
7143 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7145 case 0x7d: /* FACGT */
7146 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7149 g_assert_not_reached();
7152 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7154 tcg_temp_free_i64(tcg_res
);
7155 tcg_temp_free_i64(tcg_op1
);
7156 tcg_temp_free_i64(tcg_op2
);
7159 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7160 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7161 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7163 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
7164 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
7167 case 0x39: /* FMLS */
7168 /* As usual for ARM, separate negation for fused multiply-add */
7169 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
7171 case 0x19: /* FMLA */
7172 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7173 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
7176 case 0x1a: /* FADD */
7177 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7179 case 0x1b: /* FMULX */
7180 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7182 case 0x1c: /* FCMEQ */
7183 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7185 case 0x1e: /* FMAX */
7186 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7188 case 0x1f: /* FRECPS */
7189 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7191 case 0x18: /* FMAXNM */
7192 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7194 case 0x38: /* FMINNM */
7195 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7197 case 0x3a: /* FSUB */
7198 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7200 case 0x3e: /* FMIN */
7201 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7203 case 0x3f: /* FRSQRTS */
7204 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7206 case 0x5b: /* FMUL */
7207 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7209 case 0x5c: /* FCMGE */
7210 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7212 case 0x5d: /* FACGE */
7213 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7215 case 0x5f: /* FDIV */
7216 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7218 case 0x7a: /* FABD */
7219 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7220 gen_helper_vfp_abss(tcg_res
, tcg_res
);
7222 case 0x7c: /* FCMGT */
7223 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7225 case 0x7d: /* FACGT */
7226 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7229 g_assert_not_reached();
7232 if (elements
== 1) {
7233 /* scalar single so clear high part */
7234 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
7236 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
7237 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
7238 tcg_temp_free_i64(tcg_tmp
);
7240 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7243 tcg_temp_free_i32(tcg_res
);
7244 tcg_temp_free_i32(tcg_op1
);
7245 tcg_temp_free_i32(tcg_op2
);
7249 tcg_temp_free_ptr(fpst
);
7251 if ((elements
<< size
) < 4) {
7252 /* scalar, or non-quad vector op */
7253 clear_vec_high(s
, rd
);
7257 /* C3.6.11 AdvSIMD scalar three same
7258 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
7259 * +-----+---+-----------+------+---+------+--------+---+------+------+
7260 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
7261 * +-----+---+-----------+------+---+------+--------+---+------+------+
7263 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
7265 int rd
= extract32(insn
, 0, 5);
7266 int rn
= extract32(insn
, 5, 5);
7267 int opcode
= extract32(insn
, 11, 5);
7268 int rm
= extract32(insn
, 16, 5);
7269 int size
= extract32(insn
, 22, 2);
7270 bool u
= extract32(insn
, 29, 1);
7273 if (opcode
>= 0x18) {
7274 /* Floating point: U, size[1] and opcode indicate operation */
7275 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
7277 case 0x1b: /* FMULX */
7278 case 0x1f: /* FRECPS */
7279 case 0x3f: /* FRSQRTS */
7280 case 0x5d: /* FACGE */
7281 case 0x7d: /* FACGT */
7282 case 0x1c: /* FCMEQ */
7283 case 0x5c: /* FCMGE */
7284 case 0x7c: /* FCMGT */
7285 case 0x7a: /* FABD */
7288 unallocated_encoding(s
);
7292 if (!fp_access_check(s
)) {
7296 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
7301 case 0x1: /* SQADD, UQADD */
7302 case 0x5: /* SQSUB, UQSUB */
7303 case 0x9: /* SQSHL, UQSHL */
7304 case 0xb: /* SQRSHL, UQRSHL */
7306 case 0x8: /* SSHL, USHL */
7307 case 0xa: /* SRSHL, URSHL */
7308 case 0x6: /* CMGT, CMHI */
7309 case 0x7: /* CMGE, CMHS */
7310 case 0x11: /* CMTST, CMEQ */
7311 case 0x10: /* ADD, SUB (vector) */
7313 unallocated_encoding(s
);
7317 case 0x16: /* SQDMULH, SQRDMULH (vector) */
7318 if (size
!= 1 && size
!= 2) {
7319 unallocated_encoding(s
);
7324 unallocated_encoding(s
);
7328 if (!fp_access_check(s
)) {
7332 tcg_rd
= tcg_temp_new_i64();
7335 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7336 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
7338 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
7339 tcg_temp_free_i64(tcg_rn
);
7340 tcg_temp_free_i64(tcg_rm
);
7342 /* Do a single operation on the lowest element in the vector.
7343 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
7344 * no side effects for all these operations.
7345 * OPTME: special-purpose helpers would avoid doing some
7346 * unnecessary work in the helper for the 8 and 16 bit cases.
7348 NeonGenTwoOpEnvFn
*genenvfn
;
7349 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7350 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
7351 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
7353 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7354 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
7357 case 0x1: /* SQADD, UQADD */
7359 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7360 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
7361 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
7362 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
7364 genenvfn
= fns
[size
][u
];
7367 case 0x5: /* SQSUB, UQSUB */
7369 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7370 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
7371 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
7372 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
7374 genenvfn
= fns
[size
][u
];
7377 case 0x9: /* SQSHL, UQSHL */
7379 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7380 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
7381 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
7382 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
7384 genenvfn
= fns
[size
][u
];
7387 case 0xb: /* SQRSHL, UQRSHL */
7389 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7390 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
7391 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
7392 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
7394 genenvfn
= fns
[size
][u
];
7397 case 0x16: /* SQDMULH, SQRDMULH */
7399 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
7400 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
7401 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
7403 assert(size
== 1 || size
== 2);
7404 genenvfn
= fns
[size
- 1][u
];
7408 g_assert_not_reached();
7411 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
7412 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
7413 tcg_temp_free_i32(tcg_rd32
);
7414 tcg_temp_free_i32(tcg_rn
);
7415 tcg_temp_free_i32(tcg_rm
);
7418 write_fp_dreg(s
, rd
, tcg_rd
);
7420 tcg_temp_free_i64(tcg_rd
);
7423 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
7424 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
7425 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
7427 /* Handle 64->64 opcodes which are shared between the scalar and
7428 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
7429 * is valid in either group and also the double-precision fp ops.
7430 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
7436 case 0x4: /* CLS, CLZ */
7438 gen_helper_clz64(tcg_rd
, tcg_rn
);
7440 gen_helper_cls64(tcg_rd
, tcg_rn
);
7444 /* This opcode is shared with CNT and RBIT but we have earlier
7445 * enforced that size == 3 if and only if this is the NOT insn.
7447 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
7449 case 0x7: /* SQABS, SQNEG */
7451 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
7453 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
7456 case 0xa: /* CMLT */
7457 /* 64 bit integer comparison against zero, result is
7458 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
7463 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
7464 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7466 case 0x8: /* CMGT, CMGE */
7467 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
7469 case 0x9: /* CMEQ, CMLE */
7470 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
7472 case 0xb: /* ABS, NEG */
7474 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7476 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7477 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7478 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
7480 tcg_temp_free_i64(tcg_zero
);
7483 case 0x2f: /* FABS */
7484 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
7486 case 0x6f: /* FNEG */
7487 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
7489 case 0x7f: /* FSQRT */
7490 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
7492 case 0x1a: /* FCVTNS */
7493 case 0x1b: /* FCVTMS */
7494 case 0x1c: /* FCVTAS */
7495 case 0x3a: /* FCVTPS */
7496 case 0x3b: /* FCVTZS */
7498 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7499 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7500 tcg_temp_free_i32(tcg_shift
);
7503 case 0x5a: /* FCVTNU */
7504 case 0x5b: /* FCVTMU */
7505 case 0x5c: /* FCVTAU */
7506 case 0x7a: /* FCVTPU */
7507 case 0x7b: /* FCVTZU */
7509 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7510 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7511 tcg_temp_free_i32(tcg_shift
);
7514 case 0x18: /* FRINTN */
7515 case 0x19: /* FRINTM */
7516 case 0x38: /* FRINTP */
7517 case 0x39: /* FRINTZ */
7518 case 0x58: /* FRINTA */
7519 case 0x79: /* FRINTI */
7520 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7522 case 0x59: /* FRINTX */
7523 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7526 g_assert_not_reached();
7530 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
7531 bool is_scalar
, bool is_u
, bool is_q
,
7532 int size
, int rn
, int rd
)
7534 bool is_double
= (size
== 3);
7537 if (!fp_access_check(s
)) {
7541 fpst
= get_fpstatus_ptr();
7544 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7545 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7546 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7547 NeonGenTwoDoubleOPFn
*genfn
;
7552 case 0x2e: /* FCMLT (zero) */
7555 case 0x2c: /* FCMGT (zero) */
7556 genfn
= gen_helper_neon_cgt_f64
;
7558 case 0x2d: /* FCMEQ (zero) */
7559 genfn
= gen_helper_neon_ceq_f64
;
7561 case 0x6d: /* FCMLE (zero) */
7564 case 0x6c: /* FCMGE (zero) */
7565 genfn
= gen_helper_neon_cge_f64
;
7568 g_assert_not_reached();
7571 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7572 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7574 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7576 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7578 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7581 clear_vec_high(s
, rd
);
7584 tcg_temp_free_i64(tcg_res
);
7585 tcg_temp_free_i64(tcg_zero
);
7586 tcg_temp_free_i64(tcg_op
);
7588 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7589 TCGv_i32 tcg_zero
= tcg_const_i32(0);
7590 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7591 NeonGenTwoSingleOPFn
*genfn
;
7593 int pass
, maxpasses
;
7596 case 0x2e: /* FCMLT (zero) */
7599 case 0x2c: /* FCMGT (zero) */
7600 genfn
= gen_helper_neon_cgt_f32
;
7602 case 0x2d: /* FCMEQ (zero) */
7603 genfn
= gen_helper_neon_ceq_f32
;
7605 case 0x6d: /* FCMLE (zero) */
7608 case 0x6c: /* FCMGE (zero) */
7609 genfn
= gen_helper_neon_cge_f32
;
7612 g_assert_not_reached();
7618 maxpasses
= is_q
? 4 : 2;
7621 for (pass
= 0; pass
< maxpasses
; pass
++) {
7622 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7624 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7626 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7629 write_fp_sreg(s
, rd
, tcg_res
);
7631 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7634 tcg_temp_free_i32(tcg_res
);
7635 tcg_temp_free_i32(tcg_zero
);
7636 tcg_temp_free_i32(tcg_op
);
7637 if (!is_q
&& !is_scalar
) {
7638 clear_vec_high(s
, rd
);
7642 tcg_temp_free_ptr(fpst
);
7645 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
7646 bool is_scalar
, bool is_u
, bool is_q
,
7647 int size
, int rn
, int rd
)
7649 bool is_double
= (size
== 3);
7650 TCGv_ptr fpst
= get_fpstatus_ptr();
7653 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7654 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7657 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7658 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7660 case 0x3d: /* FRECPE */
7661 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
7663 case 0x3f: /* FRECPX */
7664 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
7666 case 0x7d: /* FRSQRTE */
7667 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
7670 g_assert_not_reached();
7672 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7675 clear_vec_high(s
, rd
);
7678 tcg_temp_free_i64(tcg_res
);
7679 tcg_temp_free_i64(tcg_op
);
7681 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7682 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7683 int pass
, maxpasses
;
7688 maxpasses
= is_q
? 4 : 2;
7691 for (pass
= 0; pass
< maxpasses
; pass
++) {
7692 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7695 case 0x3c: /* URECPE */
7696 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
7698 case 0x3d: /* FRECPE */
7699 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
7701 case 0x3f: /* FRECPX */
7702 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
7704 case 0x7d: /* FRSQRTE */
7705 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
7708 g_assert_not_reached();
7712 write_fp_sreg(s
, rd
, tcg_res
);
7714 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7717 tcg_temp_free_i32(tcg_res
);
7718 tcg_temp_free_i32(tcg_op
);
7719 if (!is_q
&& !is_scalar
) {
7720 clear_vec_high(s
, rd
);
7723 tcg_temp_free_ptr(fpst
);
7726 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
7727 int opcode
, bool u
, bool is_q
,
7728 int size
, int rn
, int rd
)
7730 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
7731 * in the source becomes a size element in the destination).
7734 TCGv_i32 tcg_res
[2];
7735 int destelt
= is_q
? 2 : 0;
7736 int passes
= scalar
? 1 : 2;
7739 tcg_res
[1] = tcg_const_i32(0);
7742 for (pass
= 0; pass
< passes
; pass
++) {
7743 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7744 NeonGenNarrowFn
*genfn
= NULL
;
7745 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
7748 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
7750 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7752 tcg_res
[pass
] = tcg_temp_new_i32();
7755 case 0x12: /* XTN, SQXTUN */
7757 static NeonGenNarrowFn
* const xtnfns
[3] = {
7758 gen_helper_neon_narrow_u8
,
7759 gen_helper_neon_narrow_u16
,
7760 tcg_gen_extrl_i64_i32
,
7762 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
7763 gen_helper_neon_unarrow_sat8
,
7764 gen_helper_neon_unarrow_sat16
,
7765 gen_helper_neon_unarrow_sat32
,
7768 genenvfn
= sqxtunfns
[size
];
7770 genfn
= xtnfns
[size
];
7774 case 0x14: /* SQXTN, UQXTN */
7776 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
7777 { gen_helper_neon_narrow_sat_s8
,
7778 gen_helper_neon_narrow_sat_u8
},
7779 { gen_helper_neon_narrow_sat_s16
,
7780 gen_helper_neon_narrow_sat_u16
},
7781 { gen_helper_neon_narrow_sat_s32
,
7782 gen_helper_neon_narrow_sat_u32
},
7784 genenvfn
= fns
[size
][u
];
7787 case 0x16: /* FCVTN, FCVTN2 */
7788 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
7790 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
7792 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
7793 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
7794 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
7795 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, cpu_env
);
7796 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, cpu_env
);
7797 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
7798 tcg_temp_free_i32(tcg_lo
);
7799 tcg_temp_free_i32(tcg_hi
);
7802 case 0x56: /* FCVTXN, FCVTXN2 */
7803 /* 64 bit to 32 bit float conversion
7804 * with von Neumann rounding (round to odd)
7807 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
7810 g_assert_not_reached();
7814 genfn(tcg_res
[pass
], tcg_op
);
7815 } else if (genenvfn
) {
7816 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
7819 tcg_temp_free_i64(tcg_op
);
7822 for (pass
= 0; pass
< 2; pass
++) {
7823 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
7824 tcg_temp_free_i32(tcg_res
[pass
]);
7827 clear_vec_high(s
, rd
);
7831 /* Remaining saturating accumulating ops */
7832 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
7833 bool is_q
, int size
, int rn
, int rd
)
7835 bool is_double
= (size
== 3);
7838 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
7839 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7842 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7843 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
7844 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7846 if (is_u
) { /* USQADD */
7847 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7848 } else { /* SUQADD */
7849 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7851 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7854 clear_vec_high(s
, rd
);
7857 tcg_temp_free_i64(tcg_rd
);
7858 tcg_temp_free_i64(tcg_rn
);
7860 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7861 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7862 int pass
, maxpasses
;
7867 maxpasses
= is_q
? 4 : 2;
7870 for (pass
= 0; pass
< maxpasses
; pass
++) {
7872 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
7873 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
7875 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
7876 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7879 if (is_u
) { /* USQADD */
7882 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7885 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7888 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7891 g_assert_not_reached();
7893 } else { /* SUQADD */
7896 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7899 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7902 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7905 g_assert_not_reached();
7910 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7911 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
7912 tcg_temp_free_i64(tcg_zero
);
7914 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7918 clear_vec_high(s
, rd
);
7921 tcg_temp_free_i32(tcg_rd
);
7922 tcg_temp_free_i32(tcg_rn
);
7926 /* C3.6.12 AdvSIMD scalar two reg misc
7927 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7928 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7929 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
7930 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7932 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
7934 int rd
= extract32(insn
, 0, 5);
7935 int rn
= extract32(insn
, 5, 5);
7936 int opcode
= extract32(insn
, 12, 5);
7937 int size
= extract32(insn
, 22, 2);
7938 bool u
= extract32(insn
, 29, 1);
7939 bool is_fcvt
= false;
7942 TCGv_ptr tcg_fpstatus
;
7945 case 0x3: /* USQADD / SUQADD*/
7946 if (!fp_access_check(s
)) {
7949 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
7951 case 0x7: /* SQABS / SQNEG */
7953 case 0xa: /* CMLT */
7955 unallocated_encoding(s
);
7959 case 0x8: /* CMGT, CMGE */
7960 case 0x9: /* CMEQ, CMLE */
7961 case 0xb: /* ABS, NEG */
7963 unallocated_encoding(s
);
7967 case 0x12: /* SQXTUN */
7969 unallocated_encoding(s
);
7973 case 0x14: /* SQXTN, UQXTN */
7975 unallocated_encoding(s
);
7978 if (!fp_access_check(s
)) {
7981 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
7986 /* Floating point: U, size[1] and opcode indicate operation;
7987 * size[0] indicates single or double precision.
7989 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
7990 size
= extract32(size
, 0, 1) ? 3 : 2;
7992 case 0x2c: /* FCMGT (zero) */
7993 case 0x2d: /* FCMEQ (zero) */
7994 case 0x2e: /* FCMLT (zero) */
7995 case 0x6c: /* FCMGE (zero) */
7996 case 0x6d: /* FCMLE (zero) */
7997 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
7999 case 0x1d: /* SCVTF */
8000 case 0x5d: /* UCVTF */
8002 bool is_signed
= (opcode
== 0x1d);
8003 if (!fp_access_check(s
)) {
8006 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
8009 case 0x3d: /* FRECPE */
8010 case 0x3f: /* FRECPX */
8011 case 0x7d: /* FRSQRTE */
8012 if (!fp_access_check(s
)) {
8015 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
8017 case 0x1a: /* FCVTNS */
8018 case 0x1b: /* FCVTMS */
8019 case 0x3a: /* FCVTPS */
8020 case 0x3b: /* FCVTZS */
8021 case 0x5a: /* FCVTNU */
8022 case 0x5b: /* FCVTMU */
8023 case 0x7a: /* FCVTPU */
8024 case 0x7b: /* FCVTZU */
8026 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
8028 case 0x1c: /* FCVTAS */
8029 case 0x5c: /* FCVTAU */
8030 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
8032 rmode
= FPROUNDING_TIEAWAY
;
8034 case 0x56: /* FCVTXN, FCVTXN2 */
8036 unallocated_encoding(s
);
8039 if (!fp_access_check(s
)) {
8042 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
8045 unallocated_encoding(s
);
8050 unallocated_encoding(s
);
8054 if (!fp_access_check(s
)) {
8059 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
8060 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
8061 tcg_fpstatus
= get_fpstatus_ptr();
8063 TCGV_UNUSED_I32(tcg_rmode
);
8064 TCGV_UNUSED_PTR(tcg_fpstatus
);
8068 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
8069 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
8071 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
8072 write_fp_dreg(s
, rd
, tcg_rd
);
8073 tcg_temp_free_i64(tcg_rd
);
8074 tcg_temp_free_i64(tcg_rn
);
8076 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
8077 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
8079 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
8082 case 0x7: /* SQABS, SQNEG */
8084 NeonGenOneOpEnvFn
*genfn
;
8085 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
8086 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
8087 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
8088 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
8090 genfn
= fns
[size
][u
];
8091 genfn(tcg_rd
, cpu_env
, tcg_rn
);
8094 case 0x1a: /* FCVTNS */
8095 case 0x1b: /* FCVTMS */
8096 case 0x1c: /* FCVTAS */
8097 case 0x3a: /* FCVTPS */
8098 case 0x3b: /* FCVTZS */
8100 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8101 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8102 tcg_temp_free_i32(tcg_shift
);
8105 case 0x5a: /* FCVTNU */
8106 case 0x5b: /* FCVTMU */
8107 case 0x5c: /* FCVTAU */
8108 case 0x7a: /* FCVTPU */
8109 case 0x7b: /* FCVTZU */
8111 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8112 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8113 tcg_temp_free_i32(tcg_shift
);
8117 g_assert_not_reached();
8120 write_fp_sreg(s
, rd
, tcg_rd
);
8121 tcg_temp_free_i32(tcg_rd
);
8122 tcg_temp_free_i32(tcg_rn
);
8126 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
8127 tcg_temp_free_i32(tcg_rmode
);
8128 tcg_temp_free_ptr(tcg_fpstatus
);
8132 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
8133 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
8134 int immh
, int immb
, int opcode
, int rn
, int rd
)
8136 int size
= 32 - clz32(immh
) - 1;
8137 int immhb
= immh
<< 3 | immb
;
8138 int shift
= 2 * (8 << size
) - immhb
;
8139 bool accumulate
= false;
8141 bool insert
= false;
8142 int dsize
= is_q
? 128 : 64;
8143 int esize
= 8 << size
;
8144 int elements
= dsize
/esize
;
8145 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
8146 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8147 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8151 if (extract32(immh
, 3, 1) && !is_q
) {
8152 unallocated_encoding(s
);
8156 if (size
> 3 && !is_q
) {
8157 unallocated_encoding(s
);
8161 if (!fp_access_check(s
)) {
8166 case 0x02: /* SSRA / USRA (accumulate) */
8169 case 0x04: /* SRSHR / URSHR (rounding) */
8172 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8173 accumulate
= round
= true;
8175 case 0x08: /* SRI */
8181 uint64_t round_const
= 1ULL << (shift
- 1);
8182 tcg_round
= tcg_const_i64(round_const
);
8184 TCGV_UNUSED_I64(tcg_round
);
8187 for (i
= 0; i
< elements
; i
++) {
8188 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
8189 if (accumulate
|| insert
) {
8190 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
8194 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
8196 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8197 accumulate
, is_u
, size
, shift
);
8200 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8204 clear_vec_high(s
, rd
);
8208 tcg_temp_free_i64(tcg_round
);
8212 /* SHL/SLI - Vector shift left */
8213 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
8214 int immh
, int immb
, int opcode
, int rn
, int rd
)
8216 int size
= 32 - clz32(immh
) - 1;
8217 int immhb
= immh
<< 3 | immb
;
8218 int shift
= immhb
- (8 << size
);
8219 int dsize
= is_q
? 128 : 64;
8220 int esize
= 8 << size
;
8221 int elements
= dsize
/esize
;
8222 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8223 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8226 if (extract32(immh
, 3, 1) && !is_q
) {
8227 unallocated_encoding(s
);
8231 if (size
> 3 && !is_q
) {
8232 unallocated_encoding(s
);
8236 if (!fp_access_check(s
)) {
8240 for (i
= 0; i
< elements
; i
++) {
8241 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
8243 read_vec_element(s
, tcg_rd
, rd
, i
, size
);
8246 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
8248 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8252 clear_vec_high(s
, rd
);
8256 /* USHLL/SHLL - Vector shift left with widening */
8257 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
8258 int immh
, int immb
, int opcode
, int rn
, int rd
)
8260 int size
= 32 - clz32(immh
) - 1;
8261 int immhb
= immh
<< 3 | immb
;
8262 int shift
= immhb
- (8 << size
);
8264 int esize
= 8 << size
;
8265 int elements
= dsize
/esize
;
8266 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8267 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8271 unallocated_encoding(s
);
8275 if (!fp_access_check(s
)) {
8279 /* For the LL variants the store is larger than the load,
8280 * so if rd == rn we would overwrite parts of our input.
8281 * So load everything right now and use shifts in the main loop.
8283 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
8285 for (i
= 0; i
< elements
; i
++) {
8286 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
8287 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
8288 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
8289 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
8293 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
8294 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
8295 int immh
, int immb
, int opcode
, int rn
, int rd
)
8297 int immhb
= immh
<< 3 | immb
;
8298 int size
= 32 - clz32(immh
) - 1;
8300 int esize
= 8 << size
;
8301 int elements
= dsize
/esize
;
8302 int shift
= (2 * esize
) - immhb
;
8303 bool round
= extract32(opcode
, 0, 1);
8304 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
8308 if (extract32(immh
, 3, 1)) {
8309 unallocated_encoding(s
);
8313 if (!fp_access_check(s
)) {
8317 tcg_rn
= tcg_temp_new_i64();
8318 tcg_rd
= tcg_temp_new_i64();
8319 tcg_final
= tcg_temp_new_i64();
8320 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
8323 uint64_t round_const
= 1ULL << (shift
- 1);
8324 tcg_round
= tcg_const_i64(round_const
);
8326 TCGV_UNUSED_I64(tcg_round
);
8329 for (i
= 0; i
< elements
; i
++) {
8330 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
8331 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8332 false, true, size
+1, shift
);
8334 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8338 clear_vec_high(s
, rd
);
8339 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8341 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8345 tcg_temp_free_i64(tcg_round
);
8347 tcg_temp_free_i64(tcg_rn
);
8348 tcg_temp_free_i64(tcg_rd
);
8349 tcg_temp_free_i64(tcg_final
);
8354 /* C3.6.14 AdvSIMD shift by immediate
8355 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8356 * +---+---+---+-------------+------+------+--------+---+------+------+
8357 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8358 * +---+---+---+-------------+------+------+--------+---+------+------+
8360 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
8362 int rd
= extract32(insn
, 0, 5);
8363 int rn
= extract32(insn
, 5, 5);
8364 int opcode
= extract32(insn
, 11, 5);
8365 int immb
= extract32(insn
, 16, 3);
8366 int immh
= extract32(insn
, 19, 4);
8367 bool is_u
= extract32(insn
, 29, 1);
8368 bool is_q
= extract32(insn
, 30, 1);
8371 case 0x08: /* SRI */
8373 unallocated_encoding(s
);
8377 case 0x00: /* SSHR / USHR */
8378 case 0x02: /* SSRA / USRA (accumulate) */
8379 case 0x04: /* SRSHR / URSHR (rounding) */
8380 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8381 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8383 case 0x0a: /* SHL / SLI */
8384 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8386 case 0x10: /* SHRN */
8387 case 0x11: /* RSHRN / SQRSHRUN */
8389 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
8392 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
8395 case 0x12: /* SQSHRN / UQSHRN */
8396 case 0x13: /* SQRSHRN / UQRSHRN */
8397 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
8400 case 0x14: /* SSHLL / USHLL */
8401 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8403 case 0x1c: /* SCVTF / UCVTF */
8404 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
8407 case 0xc: /* SQSHLU */
8409 unallocated_encoding(s
);
8412 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
8414 case 0xe: /* SQSHL, UQSHL */
8415 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
8417 case 0x1f: /* FCVTZS/ FCVTZU */
8418 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
8421 unallocated_encoding(s
);
8426 /* Generate code to do a "long" addition or subtraction, ie one done in
8427 * TCGv_i64 on vector lanes twice the width specified by size.
8429 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
8430 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
8432 static NeonGenTwo64OpFn
* const fns
[3][2] = {
8433 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
8434 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
8435 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
8437 NeonGenTwo64OpFn
*genfn
;
8440 genfn
= fns
[size
][is_sub
];
8441 genfn(tcg_res
, tcg_op1
, tcg_op2
);
8444 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
8445 int opcode
, int rd
, int rn
, int rm
)
8447 /* 3-reg-different widening insns: 64 x 64 -> 128 */
8448 TCGv_i64 tcg_res
[2];
8451 tcg_res
[0] = tcg_temp_new_i64();
8452 tcg_res
[1] = tcg_temp_new_i64();
8454 /* Does this op do an adding accumulate, a subtracting accumulate,
8455 * or no accumulate at all?
8473 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8474 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8477 /* size == 2 means two 32x32->64 operations; this is worth special
8478 * casing because we can generally handle it inline.
8481 for (pass
= 0; pass
< 2; pass
++) {
8482 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8483 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8484 TCGv_i64 tcg_passres
;
8485 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
8487 int elt
= pass
+ is_q
* 2;
8489 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
8490 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
8493 tcg_passres
= tcg_res
[pass
];
8495 tcg_passres
= tcg_temp_new_i64();
8499 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8500 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8502 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8503 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8505 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8506 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8508 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
8509 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
8511 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
8512 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
8513 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
8515 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
8516 tcg_temp_free_i64(tcg_tmp1
);
8517 tcg_temp_free_i64(tcg_tmp2
);
8520 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8521 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8522 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8523 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8525 case 9: /* SQDMLAL, SQDMLAL2 */
8526 case 11: /* SQDMLSL, SQDMLSL2 */
8527 case 13: /* SQDMULL, SQDMULL2 */
8528 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8529 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
8530 tcg_passres
, tcg_passres
);
8533 g_assert_not_reached();
8536 if (opcode
== 9 || opcode
== 11) {
8537 /* saturating accumulate ops */
8539 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
8541 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
8542 tcg_res
[pass
], tcg_passres
);
8543 } else if (accop
> 0) {
8544 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8545 } else if (accop
< 0) {
8546 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8550 tcg_temp_free_i64(tcg_passres
);
8553 tcg_temp_free_i64(tcg_op1
);
8554 tcg_temp_free_i64(tcg_op2
);
8557 /* size 0 or 1, generally helper functions */
8558 for (pass
= 0; pass
< 2; pass
++) {
8559 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8560 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8561 TCGv_i64 tcg_passres
;
8562 int elt
= pass
+ is_q
* 2;
8564 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
8565 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
8568 tcg_passres
= tcg_res
[pass
];
8570 tcg_passres
= tcg_temp_new_i64();
8574 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8575 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8577 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
8578 static NeonGenWidenFn
* const widenfns
[2][2] = {
8579 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8580 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8582 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8584 widenfn(tcg_op2_64
, tcg_op2
);
8585 widenfn(tcg_passres
, tcg_op1
);
8586 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
8587 tcg_passres
, tcg_op2_64
);
8588 tcg_temp_free_i64(tcg_op2_64
);
8591 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8592 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8595 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8597 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8601 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
8603 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
8607 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8608 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8609 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8612 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
8614 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
8618 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8620 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8624 case 9: /* SQDMLAL, SQDMLAL2 */
8625 case 11: /* SQDMLSL, SQDMLSL2 */
8626 case 13: /* SQDMULL, SQDMULL2 */
8628 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8629 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
8630 tcg_passres
, tcg_passres
);
8632 case 14: /* PMULL */
8634 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
8637 g_assert_not_reached();
8639 tcg_temp_free_i32(tcg_op1
);
8640 tcg_temp_free_i32(tcg_op2
);
8643 if (opcode
== 9 || opcode
== 11) {
8644 /* saturating accumulate ops */
8646 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
8648 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
8652 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
8653 tcg_res
[pass
], tcg_passres
);
8655 tcg_temp_free_i64(tcg_passres
);
8660 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8661 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8662 tcg_temp_free_i64(tcg_res
[0]);
8663 tcg_temp_free_i64(tcg_res
[1]);
8666 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
8667 int opcode
, int rd
, int rn
, int rm
)
8669 TCGv_i64 tcg_res
[2];
8670 int part
= is_q
? 2 : 0;
8673 for (pass
= 0; pass
< 2; pass
++) {
8674 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8675 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8676 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
8677 static NeonGenWidenFn
* const widenfns
[3][2] = {
8678 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8679 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8680 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
8682 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8684 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8685 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
8686 widenfn(tcg_op2_wide
, tcg_op2
);
8687 tcg_temp_free_i32(tcg_op2
);
8688 tcg_res
[pass
] = tcg_temp_new_i64();
8689 gen_neon_addl(size
, (opcode
== 3),
8690 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
8691 tcg_temp_free_i64(tcg_op1
);
8692 tcg_temp_free_i64(tcg_op2_wide
);
8695 for (pass
= 0; pass
< 2; pass
++) {
8696 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8697 tcg_temp_free_i64(tcg_res
[pass
]);
8701 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8703 tcg_gen_addi_i64(in
, in
, 1U << 31);
8704 tcg_gen_extrh_i64_i32(res
, in
);
8707 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
8708 int opcode
, int rd
, int rn
, int rm
)
8710 TCGv_i32 tcg_res
[2];
8711 int part
= is_q
? 2 : 0;
8714 for (pass
= 0; pass
< 2; pass
++) {
8715 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8716 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8717 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
8718 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
8719 { gen_helper_neon_narrow_high_u8
,
8720 gen_helper_neon_narrow_round_high_u8
},
8721 { gen_helper_neon_narrow_high_u16
,
8722 gen_helper_neon_narrow_round_high_u16
},
8723 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
8725 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
8727 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8728 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8730 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
8732 tcg_temp_free_i64(tcg_op1
);
8733 tcg_temp_free_i64(tcg_op2
);
8735 tcg_res
[pass
] = tcg_temp_new_i32();
8736 gennarrow(tcg_res
[pass
], tcg_wideres
);
8737 tcg_temp_free_i64(tcg_wideres
);
8740 for (pass
= 0; pass
< 2; pass
++) {
8741 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
8742 tcg_temp_free_i32(tcg_res
[pass
]);
8745 clear_vec_high(s
, rd
);
8749 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
8751 /* PMULL of 64 x 64 -> 128 is an odd special case because it
8752 * is the only three-reg-diff instruction which produces a
8753 * 128-bit wide result from a single operation. However since
8754 * it's possible to calculate the two halves more or less
8755 * separately we just use two helper calls.
8757 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8758 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8759 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8761 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
8762 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
8763 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
8764 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
8765 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
8766 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
8768 tcg_temp_free_i64(tcg_op1
);
8769 tcg_temp_free_i64(tcg_op2
);
8770 tcg_temp_free_i64(tcg_res
);
8773 /* C3.6.15 AdvSIMD three different
8774 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8775 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8776 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8777 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8779 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8781 /* Instructions in this group fall into three basic classes
8782 * (in each case with the operation working on each element in
8783 * the input vectors):
8784 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
8786 * (2) wide 64 x 128 -> 128
8787 * (3) narrowing 128 x 128 -> 64
8788 * Here we do initial decode, catch unallocated cases and
8789 * dispatch to separate functions for each class.
8791 int is_q
= extract32(insn
, 30, 1);
8792 int is_u
= extract32(insn
, 29, 1);
8793 int size
= extract32(insn
, 22, 2);
8794 int opcode
= extract32(insn
, 12, 4);
8795 int rm
= extract32(insn
, 16, 5);
8796 int rn
= extract32(insn
, 5, 5);
8797 int rd
= extract32(insn
, 0, 5);
8800 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
8801 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
8802 /* 64 x 128 -> 128 */
8804 unallocated_encoding(s
);
8807 if (!fp_access_check(s
)) {
8810 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8812 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
8813 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
8814 /* 128 x 128 -> 64 */
8816 unallocated_encoding(s
);
8819 if (!fp_access_check(s
)) {
8822 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8824 case 14: /* PMULL, PMULL2 */
8825 if (is_u
|| size
== 1 || size
== 2) {
8826 unallocated_encoding(s
);
8830 if (!arm_dc_feature(s
, ARM_FEATURE_V8_PMULL
)) {
8831 unallocated_encoding(s
);
8834 if (!fp_access_check(s
)) {
8837 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
8841 case 9: /* SQDMLAL, SQDMLAL2 */
8842 case 11: /* SQDMLSL, SQDMLSL2 */
8843 case 13: /* SQDMULL, SQDMULL2 */
8844 if (is_u
|| size
== 0) {
8845 unallocated_encoding(s
);
8849 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8850 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8851 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8852 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8853 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8854 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8855 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
8856 /* 64 x 64 -> 128 */
8858 unallocated_encoding(s
);
8862 if (!fp_access_check(s
)) {
8866 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8869 /* opcode 15 not allocated */
8870 unallocated_encoding(s
);
8875 /* Logic op (opcode == 3) subgroup of C3.6.16. */
8876 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
8878 int rd
= extract32(insn
, 0, 5);
8879 int rn
= extract32(insn
, 5, 5);
8880 int rm
= extract32(insn
, 16, 5);
8881 int size
= extract32(insn
, 22, 2);
8882 bool is_u
= extract32(insn
, 29, 1);
8883 bool is_q
= extract32(insn
, 30, 1);
8884 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
8887 if (!fp_access_check(s
)) {
8891 tcg_op1
= tcg_temp_new_i64();
8892 tcg_op2
= tcg_temp_new_i64();
8893 tcg_res
[0] = tcg_temp_new_i64();
8894 tcg_res
[1] = tcg_temp_new_i64();
8896 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
8897 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8898 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8903 tcg_gen_and_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8906 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8909 tcg_gen_or_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8912 tcg_gen_orc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8917 /* B* ops need res loaded to operate on */
8918 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8923 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8925 case 1: /* BSL bitwise select */
8926 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8927 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8928 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op1
);
8930 case 2: /* BIT, bitwise insert if true */
8931 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8932 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8933 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8935 case 3: /* BIF, bitwise insert if false */
8936 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8937 tcg_gen_andc_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8938 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8944 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8946 tcg_gen_movi_i64(tcg_res
[1], 0);
8948 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8950 tcg_temp_free_i64(tcg_op1
);
8951 tcg_temp_free_i64(tcg_op2
);
8952 tcg_temp_free_i64(tcg_res
[0]);
8953 tcg_temp_free_i64(tcg_res
[1]);
8956 /* Helper functions for 32 bit comparisons */
8957 static void gen_max_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8959 tcg_gen_movcond_i32(TCG_COND_GE
, res
, op1
, op2
, op1
, op2
);
8962 static void gen_max_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8964 tcg_gen_movcond_i32(TCG_COND_GEU
, res
, op1
, op2
, op1
, op2
);
8967 static void gen_min_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8969 tcg_gen_movcond_i32(TCG_COND_LE
, res
, op1
, op2
, op1
, op2
);
8972 static void gen_min_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8974 tcg_gen_movcond_i32(TCG_COND_LEU
, res
, op1
, op2
, op1
, op2
);
8977 /* Pairwise op subgroup of C3.6.16.
8979 * This is called directly or via the handle_3same_float for float pairwise
8980 * operations where the opcode and size are calculated differently.
8982 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
8983 int size
, int rn
, int rm
, int rd
)
8988 /* Floating point operations need fpst */
8989 if (opcode
>= 0x58) {
8990 fpst
= get_fpstatus_ptr();
8992 TCGV_UNUSED_PTR(fpst
);
8995 if (!fp_access_check(s
)) {
8999 /* These operations work on the concatenated rm:rn, with each pair of
9000 * adjacent elements being operated on to produce an element in the result.
9003 TCGv_i64 tcg_res
[2];
9005 for (pass
= 0; pass
< 2; pass
++) {
9006 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9007 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9008 int passreg
= (pass
== 0) ? rn
: rm
;
9010 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
9011 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
9012 tcg_res
[pass
] = tcg_temp_new_i64();
9015 case 0x17: /* ADDP */
9016 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9018 case 0x58: /* FMAXNMP */
9019 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9021 case 0x5a: /* FADDP */
9022 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9024 case 0x5e: /* FMAXP */
9025 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9027 case 0x78: /* FMINNMP */
9028 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9030 case 0x7e: /* FMINP */
9031 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9034 g_assert_not_reached();
9037 tcg_temp_free_i64(tcg_op1
);
9038 tcg_temp_free_i64(tcg_op2
);
9041 for (pass
= 0; pass
< 2; pass
++) {
9042 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9043 tcg_temp_free_i64(tcg_res
[pass
]);
9046 int maxpass
= is_q
? 4 : 2;
9047 TCGv_i32 tcg_res
[4];
9049 for (pass
= 0; pass
< maxpass
; pass
++) {
9050 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9051 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9052 NeonGenTwoOpFn
*genfn
= NULL
;
9053 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
9054 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
9056 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
9057 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
9058 tcg_res
[pass
] = tcg_temp_new_i32();
9061 case 0x17: /* ADDP */
9063 static NeonGenTwoOpFn
* const fns
[3] = {
9064 gen_helper_neon_padd_u8
,
9065 gen_helper_neon_padd_u16
,
9071 case 0x14: /* SMAXP, UMAXP */
9073 static NeonGenTwoOpFn
* const fns
[3][2] = {
9074 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
9075 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
9076 { gen_max_s32
, gen_max_u32
},
9078 genfn
= fns
[size
][u
];
9081 case 0x15: /* SMINP, UMINP */
9083 static NeonGenTwoOpFn
* const fns
[3][2] = {
9084 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
9085 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
9086 { gen_min_s32
, gen_min_u32
},
9088 genfn
= fns
[size
][u
];
9091 /* The FP operations are all on single floats (32 bit) */
9092 case 0x58: /* FMAXNMP */
9093 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9095 case 0x5a: /* FADDP */
9096 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9098 case 0x5e: /* FMAXP */
9099 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9101 case 0x78: /* FMINNMP */
9102 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9104 case 0x7e: /* FMINP */
9105 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9108 g_assert_not_reached();
9111 /* FP ops called directly, otherwise call now */
9113 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9116 tcg_temp_free_i32(tcg_op1
);
9117 tcg_temp_free_i32(tcg_op2
);
9120 for (pass
= 0; pass
< maxpass
; pass
++) {
9121 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9122 tcg_temp_free_i32(tcg_res
[pass
]);
9125 clear_vec_high(s
, rd
);
9129 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
9130 tcg_temp_free_ptr(fpst
);
9134 /* Floating point op subgroup of C3.6.16. */
9135 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
9137 /* For floating point ops, the U, size[1] and opcode bits
9138 * together indicate the operation. size[0] indicates single
9141 int fpopcode
= extract32(insn
, 11, 5)
9142 | (extract32(insn
, 23, 1) << 5)
9143 | (extract32(insn
, 29, 1) << 6);
9144 int is_q
= extract32(insn
, 30, 1);
9145 int size
= extract32(insn
, 22, 1);
9146 int rm
= extract32(insn
, 16, 5);
9147 int rn
= extract32(insn
, 5, 5);
9148 int rd
= extract32(insn
, 0, 5);
9150 int datasize
= is_q
? 128 : 64;
9151 int esize
= 32 << size
;
9152 int elements
= datasize
/ esize
;
9154 if (size
== 1 && !is_q
) {
9155 unallocated_encoding(s
);
9160 case 0x58: /* FMAXNMP */
9161 case 0x5a: /* FADDP */
9162 case 0x5e: /* FMAXP */
9163 case 0x78: /* FMINNMP */
9164 case 0x7e: /* FMINP */
9165 if (size
&& !is_q
) {
9166 unallocated_encoding(s
);
9169 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
9172 case 0x1b: /* FMULX */
9173 case 0x1f: /* FRECPS */
9174 case 0x3f: /* FRSQRTS */
9175 case 0x5d: /* FACGE */
9176 case 0x7d: /* FACGT */
9177 case 0x19: /* FMLA */
9178 case 0x39: /* FMLS */
9179 case 0x18: /* FMAXNM */
9180 case 0x1a: /* FADD */
9181 case 0x1c: /* FCMEQ */
9182 case 0x1e: /* FMAX */
9183 case 0x38: /* FMINNM */
9184 case 0x3a: /* FSUB */
9185 case 0x3e: /* FMIN */
9186 case 0x5b: /* FMUL */
9187 case 0x5c: /* FCMGE */
9188 case 0x5f: /* FDIV */
9189 case 0x7a: /* FABD */
9190 case 0x7c: /* FCMGT */
9191 if (!fp_access_check(s
)) {
9195 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
9198 unallocated_encoding(s
);
9203 /* Integer op subgroup of C3.6.16. */
9204 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
9206 int is_q
= extract32(insn
, 30, 1);
9207 int u
= extract32(insn
, 29, 1);
9208 int size
= extract32(insn
, 22, 2);
9209 int opcode
= extract32(insn
, 11, 5);
9210 int rm
= extract32(insn
, 16, 5);
9211 int rn
= extract32(insn
, 5, 5);
9212 int rd
= extract32(insn
, 0, 5);
9216 case 0x13: /* MUL, PMUL */
9217 if (u
&& size
!= 0) {
9218 unallocated_encoding(s
);
9222 case 0x0: /* SHADD, UHADD */
9223 case 0x2: /* SRHADD, URHADD */
9224 case 0x4: /* SHSUB, UHSUB */
9225 case 0xc: /* SMAX, UMAX */
9226 case 0xd: /* SMIN, UMIN */
9227 case 0xe: /* SABD, UABD */
9228 case 0xf: /* SABA, UABA */
9229 case 0x12: /* MLA, MLS */
9231 unallocated_encoding(s
);
9235 case 0x16: /* SQDMULH, SQRDMULH */
9236 if (size
== 0 || size
== 3) {
9237 unallocated_encoding(s
);
9242 if (size
== 3 && !is_q
) {
9243 unallocated_encoding(s
);
9249 if (!fp_access_check(s
)) {
9255 for (pass
= 0; pass
< 2; pass
++) {
9256 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9257 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9258 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9260 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9261 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9263 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
9265 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9267 tcg_temp_free_i64(tcg_res
);
9268 tcg_temp_free_i64(tcg_op1
);
9269 tcg_temp_free_i64(tcg_op2
);
9272 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9273 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9274 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9275 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9276 NeonGenTwoOpFn
*genfn
= NULL
;
9277 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
9279 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
9280 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
9283 case 0x0: /* SHADD, UHADD */
9285 static NeonGenTwoOpFn
* const fns
[3][2] = {
9286 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
9287 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
9288 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
9290 genfn
= fns
[size
][u
];
9293 case 0x1: /* SQADD, UQADD */
9295 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9296 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9297 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9298 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9300 genenvfn
= fns
[size
][u
];
9303 case 0x2: /* SRHADD, URHADD */
9305 static NeonGenTwoOpFn
* const fns
[3][2] = {
9306 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
9307 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
9308 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
9310 genfn
= fns
[size
][u
];
9313 case 0x4: /* SHSUB, UHSUB */
9315 static NeonGenTwoOpFn
* const fns
[3][2] = {
9316 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
9317 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
9318 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
9320 genfn
= fns
[size
][u
];
9323 case 0x5: /* SQSUB, UQSUB */
9325 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9326 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9327 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9328 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9330 genenvfn
= fns
[size
][u
];
9333 case 0x6: /* CMGT, CMHI */
9335 static NeonGenTwoOpFn
* const fns
[3][2] = {
9336 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_u8
},
9337 { gen_helper_neon_cgt_s16
, gen_helper_neon_cgt_u16
},
9338 { gen_helper_neon_cgt_s32
, gen_helper_neon_cgt_u32
},
9340 genfn
= fns
[size
][u
];
9343 case 0x7: /* CMGE, CMHS */
9345 static NeonGenTwoOpFn
* const fns
[3][2] = {
9346 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_u8
},
9347 { gen_helper_neon_cge_s16
, gen_helper_neon_cge_u16
},
9348 { gen_helper_neon_cge_s32
, gen_helper_neon_cge_u32
},
9350 genfn
= fns
[size
][u
];
9353 case 0x8: /* SSHL, USHL */
9355 static NeonGenTwoOpFn
* const fns
[3][2] = {
9356 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
9357 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
9358 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
9360 genfn
= fns
[size
][u
];
9363 case 0x9: /* SQSHL, UQSHL */
9365 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9366 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9367 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9368 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9370 genenvfn
= fns
[size
][u
];
9373 case 0xa: /* SRSHL, URSHL */
9375 static NeonGenTwoOpFn
* const fns
[3][2] = {
9376 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
9377 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
9378 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
9380 genfn
= fns
[size
][u
];
9383 case 0xb: /* SQRSHL, UQRSHL */
9385 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9386 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9387 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9388 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9390 genenvfn
= fns
[size
][u
];
9393 case 0xc: /* SMAX, UMAX */
9395 static NeonGenTwoOpFn
* const fns
[3][2] = {
9396 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
9397 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
9398 { gen_max_s32
, gen_max_u32
},
9400 genfn
= fns
[size
][u
];
9404 case 0xd: /* SMIN, UMIN */
9406 static NeonGenTwoOpFn
* const fns
[3][2] = {
9407 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
9408 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
9409 { gen_min_s32
, gen_min_u32
},
9411 genfn
= fns
[size
][u
];
9414 case 0xe: /* SABD, UABD */
9415 case 0xf: /* SABA, UABA */
9417 static NeonGenTwoOpFn
* const fns
[3][2] = {
9418 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
9419 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
9420 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
9422 genfn
= fns
[size
][u
];
9425 case 0x10: /* ADD, SUB */
9427 static NeonGenTwoOpFn
* const fns
[3][2] = {
9428 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9429 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9430 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9432 genfn
= fns
[size
][u
];
9435 case 0x11: /* CMTST, CMEQ */
9437 static NeonGenTwoOpFn
* const fns
[3][2] = {
9438 { gen_helper_neon_tst_u8
, gen_helper_neon_ceq_u8
},
9439 { gen_helper_neon_tst_u16
, gen_helper_neon_ceq_u16
},
9440 { gen_helper_neon_tst_u32
, gen_helper_neon_ceq_u32
},
9442 genfn
= fns
[size
][u
];
9445 case 0x13: /* MUL, PMUL */
9449 genfn
= gen_helper_neon_mul_p8
;
9452 /* fall through : MUL */
9453 case 0x12: /* MLA, MLS */
9455 static NeonGenTwoOpFn
* const fns
[3] = {
9456 gen_helper_neon_mul_u8
,
9457 gen_helper_neon_mul_u16
,
9463 case 0x16: /* SQDMULH, SQRDMULH */
9465 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9466 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9467 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9469 assert(size
== 1 || size
== 2);
9470 genenvfn
= fns
[size
- 1][u
];
9474 g_assert_not_reached();
9478 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
9480 genfn(tcg_res
, tcg_op1
, tcg_op2
);
9483 if (opcode
== 0xf || opcode
== 0x12) {
9484 /* SABA, UABA, MLA, MLS: accumulating ops */
9485 static NeonGenTwoOpFn
* const fns
[3][2] = {
9486 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9487 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9488 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9490 bool is_sub
= (opcode
== 0x12 && u
); /* MLS */
9492 genfn
= fns
[size
][is_sub
];
9493 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
9494 genfn(tcg_res
, tcg_op1
, tcg_res
);
9497 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9499 tcg_temp_free_i32(tcg_res
);
9500 tcg_temp_free_i32(tcg_op1
);
9501 tcg_temp_free_i32(tcg_op2
);
9506 clear_vec_high(s
, rd
);
9510 /* C3.6.16 AdvSIMD three same
9511 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
9512 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9513 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
9514 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9516 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
9518 int opcode
= extract32(insn
, 11, 5);
9521 case 0x3: /* logic ops */
9522 disas_simd_3same_logic(s
, insn
);
9524 case 0x17: /* ADDP */
9525 case 0x14: /* SMAXP, UMAXP */
9526 case 0x15: /* SMINP, UMINP */
9528 /* Pairwise operations */
9529 int is_q
= extract32(insn
, 30, 1);
9530 int u
= extract32(insn
, 29, 1);
9531 int size
= extract32(insn
, 22, 2);
9532 int rm
= extract32(insn
, 16, 5);
9533 int rn
= extract32(insn
, 5, 5);
9534 int rd
= extract32(insn
, 0, 5);
9535 if (opcode
== 0x17) {
9536 if (u
|| (size
== 3 && !is_q
)) {
9537 unallocated_encoding(s
);
9542 unallocated_encoding(s
);
9546 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
9550 /* floating point ops, sz[1] and U are part of opcode */
9551 disas_simd_3same_float(s
, insn
);
9554 disas_simd_3same_int(s
, insn
);
9559 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
9560 int size
, int rn
, int rd
)
9562 /* Handle 2-reg-misc ops which are widening (so each size element
9563 * in the source becomes a 2*size element in the destination.
9564 * The only instruction like this is FCVTL.
9569 /* 32 -> 64 bit fp conversion */
9570 TCGv_i64 tcg_res
[2];
9571 int srcelt
= is_q
? 2 : 0;
9573 for (pass
= 0; pass
< 2; pass
++) {
9574 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9575 tcg_res
[pass
] = tcg_temp_new_i64();
9577 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
9578 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
9579 tcg_temp_free_i32(tcg_op
);
9581 for (pass
= 0; pass
< 2; pass
++) {
9582 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9583 tcg_temp_free_i64(tcg_res
[pass
]);
9586 /* 16 -> 32 bit fp conversion */
9587 int srcelt
= is_q
? 4 : 0;
9588 TCGv_i32 tcg_res
[4];
9590 for (pass
= 0; pass
< 4; pass
++) {
9591 tcg_res
[pass
] = tcg_temp_new_i32();
9593 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
9594 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
9597 for (pass
= 0; pass
< 4; pass
++) {
9598 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9599 tcg_temp_free_i32(tcg_res
[pass
]);
9604 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
9605 bool is_q
, int size
, int rn
, int rd
)
9607 int op
= (opcode
<< 1) | u
;
9608 int opsz
= op
+ size
;
9609 int grp_size
= 3 - opsz
;
9610 int dsize
= is_q
? 128 : 64;
9614 unallocated_encoding(s
);
9618 if (!fp_access_check(s
)) {
9623 /* Special case bytes, use bswap op on each group of elements */
9624 int groups
= dsize
/ (8 << grp_size
);
9626 for (i
= 0; i
< groups
; i
++) {
9627 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9629 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
9632 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
9635 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
9638 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
9641 g_assert_not_reached();
9643 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
9644 tcg_temp_free_i64(tcg_tmp
);
9647 clear_vec_high(s
, rd
);
9650 int revmask
= (1 << grp_size
) - 1;
9651 int esize
= 8 << size
;
9652 int elements
= dsize
/ esize
;
9653 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9654 TCGv_i64 tcg_rd
= tcg_const_i64(0);
9655 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
9657 for (i
= 0; i
< elements
; i
++) {
9658 int e_rev
= (i
& 0xf) ^ revmask
;
9659 int off
= e_rev
* esize
;
9660 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
9662 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
9663 tcg_rn
, off
- 64, esize
);
9665 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
9668 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
9669 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
9671 tcg_temp_free_i64(tcg_rd_hi
);
9672 tcg_temp_free_i64(tcg_rd
);
9673 tcg_temp_free_i64(tcg_rn
);
9677 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
9678 bool is_q
, int size
, int rn
, int rd
)
9680 /* Implement the pairwise operations from 2-misc:
9681 * SADDLP, UADDLP, SADALP, UADALP.
9682 * These all add pairs of elements in the input to produce a
9683 * double-width result element in the output (possibly accumulating).
9685 bool accum
= (opcode
== 0x6);
9686 int maxpass
= is_q
? 2 : 1;
9688 TCGv_i64 tcg_res
[2];
9691 /* 32 + 32 -> 64 op */
9692 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
9694 for (pass
= 0; pass
< maxpass
; pass
++) {
9695 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9696 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9698 tcg_res
[pass
] = tcg_temp_new_i64();
9700 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
9701 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
9702 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9704 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
9705 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9708 tcg_temp_free_i64(tcg_op1
);
9709 tcg_temp_free_i64(tcg_op2
);
9712 for (pass
= 0; pass
< maxpass
; pass
++) {
9713 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9714 NeonGenOneOpFn
*genfn
;
9715 static NeonGenOneOpFn
* const fns
[2][2] = {
9716 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
9717 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
9720 genfn
= fns
[size
][u
];
9722 tcg_res
[pass
] = tcg_temp_new_i64();
9724 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9725 genfn(tcg_res
[pass
], tcg_op
);
9728 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
9730 gen_helper_neon_addl_u16(tcg_res
[pass
],
9731 tcg_res
[pass
], tcg_op
);
9733 gen_helper_neon_addl_u32(tcg_res
[pass
],
9734 tcg_res
[pass
], tcg_op
);
9737 tcg_temp_free_i64(tcg_op
);
9741 tcg_res
[1] = tcg_const_i64(0);
9743 for (pass
= 0; pass
< 2; pass
++) {
9744 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9745 tcg_temp_free_i64(tcg_res
[pass
]);
9749 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
9751 /* Implement SHLL and SHLL2 */
9753 int part
= is_q
? 2 : 0;
9754 TCGv_i64 tcg_res
[2];
9756 for (pass
= 0; pass
< 2; pass
++) {
9757 static NeonGenWidenFn
* const widenfns
[3] = {
9758 gen_helper_neon_widen_u8
,
9759 gen_helper_neon_widen_u16
,
9760 tcg_gen_extu_i32_i64
,
9762 NeonGenWidenFn
*widenfn
= widenfns
[size
];
9763 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9765 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
9766 tcg_res
[pass
] = tcg_temp_new_i64();
9767 widenfn(tcg_res
[pass
], tcg_op
);
9768 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
9770 tcg_temp_free_i32(tcg_op
);
9773 for (pass
= 0; pass
< 2; pass
++) {
9774 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9775 tcg_temp_free_i64(tcg_res
[pass
]);
9779 /* C3.6.17 AdvSIMD two reg misc
9780 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9781 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9782 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9783 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9785 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9787 int size
= extract32(insn
, 22, 2);
9788 int opcode
= extract32(insn
, 12, 5);
9789 bool u
= extract32(insn
, 29, 1);
9790 bool is_q
= extract32(insn
, 30, 1);
9791 int rn
= extract32(insn
, 5, 5);
9792 int rd
= extract32(insn
, 0, 5);
9793 bool need_fpstatus
= false;
9794 bool need_rmode
= false;
9797 TCGv_ptr tcg_fpstatus
;
9800 case 0x0: /* REV64, REV32 */
9801 case 0x1: /* REV16 */
9802 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9804 case 0x5: /* CNT, NOT, RBIT */
9805 if (u
&& size
== 0) {
9806 /* NOT: adjust size so we can use the 64-bits-at-a-time loop. */
9809 } else if (u
&& size
== 1) {
9812 } else if (!u
&& size
== 0) {
9816 unallocated_encoding(s
);
9818 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
9819 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
9821 unallocated_encoding(s
);
9824 if (!fp_access_check(s
)) {
9828 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
9830 case 0x4: /* CLS, CLZ */
9832 unallocated_encoding(s
);
9836 case 0x2: /* SADDLP, UADDLP */
9837 case 0x6: /* SADALP, UADALP */
9839 unallocated_encoding(s
);
9842 if (!fp_access_check(s
)) {
9845 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9847 case 0x13: /* SHLL, SHLL2 */
9848 if (u
== 0 || size
== 3) {
9849 unallocated_encoding(s
);
9852 if (!fp_access_check(s
)) {
9855 handle_shll(s
, is_q
, size
, rn
, rd
);
9857 case 0xa: /* CMLT */
9859 unallocated_encoding(s
);
9863 case 0x8: /* CMGT, CMGE */
9864 case 0x9: /* CMEQ, CMLE */
9865 case 0xb: /* ABS, NEG */
9866 if (size
== 3 && !is_q
) {
9867 unallocated_encoding(s
);
9871 case 0x3: /* SUQADD, USQADD */
9872 if (size
== 3 && !is_q
) {
9873 unallocated_encoding(s
);
9876 if (!fp_access_check(s
)) {
9879 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
9881 case 0x7: /* SQABS, SQNEG */
9882 if (size
== 3 && !is_q
) {
9883 unallocated_encoding(s
);
9891 /* Floating point: U, size[1] and opcode indicate operation;
9892 * size[0] indicates single or double precision.
9894 int is_double
= extract32(size
, 0, 1);
9895 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9896 size
= is_double
? 3 : 2;
9898 case 0x2f: /* FABS */
9899 case 0x6f: /* FNEG */
9900 if (size
== 3 && !is_q
) {
9901 unallocated_encoding(s
);
9905 case 0x1d: /* SCVTF */
9906 case 0x5d: /* UCVTF */
9908 bool is_signed
= (opcode
== 0x1d) ? true : false;
9909 int elements
= is_double
? 2 : is_q
? 4 : 2;
9910 if (is_double
&& !is_q
) {
9911 unallocated_encoding(s
);
9914 if (!fp_access_check(s
)) {
9917 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
9920 case 0x2c: /* FCMGT (zero) */
9921 case 0x2d: /* FCMEQ (zero) */
9922 case 0x2e: /* FCMLT (zero) */
9923 case 0x6c: /* FCMGE (zero) */
9924 case 0x6d: /* FCMLE (zero) */
9925 if (size
== 3 && !is_q
) {
9926 unallocated_encoding(s
);
9929 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9931 case 0x7f: /* FSQRT */
9932 if (size
== 3 && !is_q
) {
9933 unallocated_encoding(s
);
9937 case 0x1a: /* FCVTNS */
9938 case 0x1b: /* FCVTMS */
9939 case 0x3a: /* FCVTPS */
9940 case 0x3b: /* FCVTZS */
9941 case 0x5a: /* FCVTNU */
9942 case 0x5b: /* FCVTMU */
9943 case 0x7a: /* FCVTPU */
9944 case 0x7b: /* FCVTZU */
9945 need_fpstatus
= true;
9947 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9948 if (size
== 3 && !is_q
) {
9949 unallocated_encoding(s
);
9953 case 0x5c: /* FCVTAU */
9954 case 0x1c: /* FCVTAS */
9955 need_fpstatus
= true;
9957 rmode
= FPROUNDING_TIEAWAY
;
9958 if (size
== 3 && !is_q
) {
9959 unallocated_encoding(s
);
9963 case 0x3c: /* URECPE */
9965 unallocated_encoding(s
);
9969 case 0x3d: /* FRECPE */
9970 case 0x7d: /* FRSQRTE */
9971 if (size
== 3 && !is_q
) {
9972 unallocated_encoding(s
);
9975 if (!fp_access_check(s
)) {
9978 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9980 case 0x56: /* FCVTXN, FCVTXN2 */
9982 unallocated_encoding(s
);
9986 case 0x16: /* FCVTN, FCVTN2 */
9987 /* handle_2misc_narrow does a 2*size -> size operation, but these
9988 * instructions encode the source size rather than dest size.
9990 if (!fp_access_check(s
)) {
9993 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
9995 case 0x17: /* FCVTL, FCVTL2 */
9996 if (!fp_access_check(s
)) {
9999 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
10001 case 0x18: /* FRINTN */
10002 case 0x19: /* FRINTM */
10003 case 0x38: /* FRINTP */
10004 case 0x39: /* FRINTZ */
10006 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
10008 case 0x59: /* FRINTX */
10009 case 0x79: /* FRINTI */
10010 need_fpstatus
= true;
10011 if (size
== 3 && !is_q
) {
10012 unallocated_encoding(s
);
10016 case 0x58: /* FRINTA */
10018 rmode
= FPROUNDING_TIEAWAY
;
10019 need_fpstatus
= true;
10020 if (size
== 3 && !is_q
) {
10021 unallocated_encoding(s
);
10025 case 0x7c: /* URSQRTE */
10027 unallocated_encoding(s
);
10030 need_fpstatus
= true;
10033 unallocated_encoding(s
);
10039 unallocated_encoding(s
);
10043 if (!fp_access_check(s
)) {
10047 if (need_fpstatus
) {
10048 tcg_fpstatus
= get_fpstatus_ptr();
10050 TCGV_UNUSED_PTR(tcg_fpstatus
);
10053 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
10054 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10056 TCGV_UNUSED_I32(tcg_rmode
);
10060 /* All 64-bit element operations can be shared with scalar 2misc */
10063 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
10064 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10065 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10067 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10069 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
10070 tcg_rmode
, tcg_fpstatus
);
10072 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10074 tcg_temp_free_i64(tcg_res
);
10075 tcg_temp_free_i64(tcg_op
);
10080 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
10081 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10082 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10085 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
10088 /* Special cases for 32 bit elements */
10090 case 0xa: /* CMLT */
10091 /* 32 bit integer comparison against zero, result is
10092 * test ? (2^32 - 1) : 0. We implement via setcond(test)
10095 cond
= TCG_COND_LT
;
10097 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
10098 tcg_gen_neg_i32(tcg_res
, tcg_res
);
10100 case 0x8: /* CMGT, CMGE */
10101 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
10103 case 0x9: /* CMEQ, CMLE */
10104 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
10106 case 0x4: /* CLS */
10108 gen_helper_clz32(tcg_res
, tcg_op
);
10110 gen_helper_cls32(tcg_res
, tcg_op
);
10113 case 0x7: /* SQABS, SQNEG */
10115 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
10117 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
10120 case 0xb: /* ABS, NEG */
10122 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10124 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10125 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10126 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
10127 tcg_zero
, tcg_op
, tcg_res
);
10128 tcg_temp_free_i32(tcg_zero
);
10131 case 0x2f: /* FABS */
10132 gen_helper_vfp_abss(tcg_res
, tcg_op
);
10134 case 0x6f: /* FNEG */
10135 gen_helper_vfp_negs(tcg_res
, tcg_op
);
10137 case 0x7f: /* FSQRT */
10138 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
10140 case 0x1a: /* FCVTNS */
10141 case 0x1b: /* FCVTMS */
10142 case 0x1c: /* FCVTAS */
10143 case 0x3a: /* FCVTPS */
10144 case 0x3b: /* FCVTZS */
10146 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10147 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
10148 tcg_shift
, tcg_fpstatus
);
10149 tcg_temp_free_i32(tcg_shift
);
10152 case 0x5a: /* FCVTNU */
10153 case 0x5b: /* FCVTMU */
10154 case 0x5c: /* FCVTAU */
10155 case 0x7a: /* FCVTPU */
10156 case 0x7b: /* FCVTZU */
10158 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10159 gen_helper_vfp_touls(tcg_res
, tcg_op
,
10160 tcg_shift
, tcg_fpstatus
);
10161 tcg_temp_free_i32(tcg_shift
);
10164 case 0x18: /* FRINTN */
10165 case 0x19: /* FRINTM */
10166 case 0x38: /* FRINTP */
10167 case 0x39: /* FRINTZ */
10168 case 0x58: /* FRINTA */
10169 case 0x79: /* FRINTI */
10170 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
10172 case 0x59: /* FRINTX */
10173 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
10175 case 0x7c: /* URSQRTE */
10176 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
10179 g_assert_not_reached();
10182 /* Use helpers for 8 and 16 bit elements */
10184 case 0x5: /* CNT, RBIT */
10185 /* For these two insns size is part of the opcode specifier
10186 * (handled earlier); they always operate on byte elements.
10189 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
10191 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
10194 case 0x7: /* SQABS, SQNEG */
10196 NeonGenOneOpEnvFn
*genfn
;
10197 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
10198 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
10199 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
10201 genfn
= fns
[size
][u
];
10202 genfn(tcg_res
, cpu_env
, tcg_op
);
10205 case 0x8: /* CMGT, CMGE */
10206 case 0x9: /* CMEQ, CMLE */
10207 case 0xa: /* CMLT */
10209 static NeonGenTwoOpFn
* const fns
[3][2] = {
10210 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
10211 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
10212 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
10214 NeonGenTwoOpFn
*genfn
;
10217 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10219 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
10220 comp
= (opcode
- 0x8) * 2 + u
;
10221 /* ...but LE, LT are implemented as reverse GE, GT */
10222 reverse
= (comp
> 2);
10226 genfn
= fns
[comp
][size
];
10228 genfn(tcg_res
, tcg_zero
, tcg_op
);
10230 genfn(tcg_res
, tcg_op
, tcg_zero
);
10232 tcg_temp_free_i32(tcg_zero
);
10235 case 0xb: /* ABS, NEG */
10237 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10239 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
10241 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
10243 tcg_temp_free_i32(tcg_zero
);
10246 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
10248 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
10252 case 0x4: /* CLS, CLZ */
10255 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
10257 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
10261 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
10263 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
10268 g_assert_not_reached();
10272 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10274 tcg_temp_free_i32(tcg_res
);
10275 tcg_temp_free_i32(tcg_op
);
10279 clear_vec_high(s
, rd
);
10283 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10284 tcg_temp_free_i32(tcg_rmode
);
10286 if (need_fpstatus
) {
10287 tcg_temp_free_ptr(tcg_fpstatus
);
10291 /* C3.6.13 AdvSIMD scalar x indexed element
10292 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10293 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10294 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10295 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10296 * C3.6.18 AdvSIMD vector x indexed element
10297 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10298 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10299 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10300 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10302 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
10304 /* This encoding has two kinds of instruction:
10305 * normal, where we perform elt x idxelt => elt for each
10306 * element in the vector
10307 * long, where we perform elt x idxelt and generate a result of
10308 * double the width of the input element
10309 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
10311 bool is_scalar
= extract32(insn
, 28, 1);
10312 bool is_q
= extract32(insn
, 30, 1);
10313 bool u
= extract32(insn
, 29, 1);
10314 int size
= extract32(insn
, 22, 2);
10315 int l
= extract32(insn
, 21, 1);
10316 int m
= extract32(insn
, 20, 1);
10317 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
10318 int rm
= extract32(insn
, 16, 4);
10319 int opcode
= extract32(insn
, 12, 4);
10320 int h
= extract32(insn
, 11, 1);
10321 int rn
= extract32(insn
, 5, 5);
10322 int rd
= extract32(insn
, 0, 5);
10323 bool is_long
= false;
10324 bool is_fp
= false;
10329 case 0x0: /* MLA */
10330 case 0x4: /* MLS */
10331 if (!u
|| is_scalar
) {
10332 unallocated_encoding(s
);
10336 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10337 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10338 case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
10340 unallocated_encoding(s
);
10345 case 0x3: /* SQDMLAL, SQDMLAL2 */
10346 case 0x7: /* SQDMLSL, SQDMLSL2 */
10347 case 0xb: /* SQDMULL, SQDMULL2 */
10350 case 0xc: /* SQDMULH */
10351 case 0xd: /* SQRDMULH */
10353 unallocated_encoding(s
);
10357 case 0x8: /* MUL */
10358 if (u
|| is_scalar
) {
10359 unallocated_encoding(s
);
10363 case 0x1: /* FMLA */
10364 case 0x5: /* FMLS */
10366 unallocated_encoding(s
);
10370 case 0x9: /* FMUL, FMULX */
10371 if (!extract32(size
, 1, 1)) {
10372 unallocated_encoding(s
);
10378 unallocated_encoding(s
);
10383 /* low bit of size indicates single/double */
10384 size
= extract32(size
, 0, 1) ? 3 : 2;
10386 index
= h
<< 1 | l
;
10389 unallocated_encoding(s
);
10398 index
= h
<< 2 | l
<< 1 | m
;
10401 index
= h
<< 1 | l
;
10405 unallocated_encoding(s
);
10410 if (!fp_access_check(s
)) {
10415 fpst
= get_fpstatus_ptr();
10417 TCGV_UNUSED_PTR(fpst
);
10421 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10424 assert(is_fp
&& is_q
&& !is_long
);
10426 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
10428 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10429 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10430 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10432 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10435 case 0x5: /* FMLS */
10436 /* As usual for ARM, separate negation for fused multiply-add */
10437 gen_helper_vfp_negd(tcg_op
, tcg_op
);
10439 case 0x1: /* FMLA */
10440 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10441 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10443 case 0x9: /* FMUL, FMULX */
10445 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10447 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10451 g_assert_not_reached();
10454 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10455 tcg_temp_free_i64(tcg_op
);
10456 tcg_temp_free_i64(tcg_res
);
10460 clear_vec_high(s
, rd
);
10463 tcg_temp_free_i64(tcg_idx
);
10464 } else if (!is_long
) {
10465 /* 32 bit floating point, or 16 or 32 bit integer.
10466 * For the 16 bit scalar case we use the usual Neon helpers and
10467 * rely on the fact that 0 op 0 == 0 with no side effects.
10469 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10470 int pass
, maxpasses
;
10475 maxpasses
= is_q
? 4 : 2;
10478 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10480 if (size
== 1 && !is_scalar
) {
10481 /* The simplest way to handle the 16x16 indexed ops is to duplicate
10482 * the index into both halves of the 32 bit tcg_idx and then use
10483 * the usual Neon helpers.
10485 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10488 for (pass
= 0; pass
< maxpasses
; pass
++) {
10489 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10490 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10492 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
10495 case 0x0: /* MLA */
10496 case 0x4: /* MLS */
10497 case 0x8: /* MUL */
10499 static NeonGenTwoOpFn
* const fns
[2][2] = {
10500 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
10501 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
10503 NeonGenTwoOpFn
*genfn
;
10504 bool is_sub
= opcode
== 0x4;
10507 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
10509 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
10511 if (opcode
== 0x8) {
10514 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
10515 genfn
= fns
[size
- 1][is_sub
];
10516 genfn(tcg_res
, tcg_op
, tcg_res
);
10519 case 0x5: /* FMLS */
10520 /* As usual for ARM, separate negation for fused multiply-add */
10521 gen_helper_vfp_negs(tcg_op
, tcg_op
);
10523 case 0x1: /* FMLA */
10524 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10525 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10527 case 0x9: /* FMUL, FMULX */
10529 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10531 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10534 case 0xc: /* SQDMULH */
10536 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
10539 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
10543 case 0xd: /* SQRDMULH */
10545 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
10548 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
10553 g_assert_not_reached();
10557 write_fp_sreg(s
, rd
, tcg_res
);
10559 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10562 tcg_temp_free_i32(tcg_op
);
10563 tcg_temp_free_i32(tcg_res
);
10566 tcg_temp_free_i32(tcg_idx
);
10569 clear_vec_high(s
, rd
);
10572 /* long ops: 16x16->32 or 32x32->64 */
10573 TCGv_i64 tcg_res
[2];
10575 bool satop
= extract32(opcode
, 0, 1);
10576 TCGMemOp memop
= MO_32
;
10583 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10585 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
10587 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10588 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10589 TCGv_i64 tcg_passres
;
10595 passelt
= pass
+ (is_q
* 2);
10598 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
10600 tcg_res
[pass
] = tcg_temp_new_i64();
10602 if (opcode
== 0xa || opcode
== 0xb) {
10603 /* Non-accumulating ops */
10604 tcg_passres
= tcg_res
[pass
];
10606 tcg_passres
= tcg_temp_new_i64();
10609 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
10610 tcg_temp_free_i64(tcg_op
);
10613 /* saturating, doubling */
10614 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10615 tcg_passres
, tcg_passres
);
10618 if (opcode
== 0xa || opcode
== 0xb) {
10622 /* Accumulating op: handle accumulate step */
10623 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10626 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10627 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10629 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10630 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10632 case 0x7: /* SQDMLSL, SQDMLSL2 */
10633 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10635 case 0x3: /* SQDMLAL, SQDMLAL2 */
10636 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10641 g_assert_not_reached();
10643 tcg_temp_free_i64(tcg_passres
);
10645 tcg_temp_free_i64(tcg_idx
);
10648 clear_vec_high(s
, rd
);
10651 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10654 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10657 /* The simplest way to handle the 16x16 indexed ops is to
10658 * duplicate the index into both halves of the 32 bit tcg_idx
10659 * and then use the usual Neon helpers.
10661 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10664 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10665 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10666 TCGv_i64 tcg_passres
;
10669 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10671 read_vec_element_i32(s
, tcg_op
, rn
,
10672 pass
+ (is_q
* 2), MO_32
);
10675 tcg_res
[pass
] = tcg_temp_new_i64();
10677 if (opcode
== 0xa || opcode
== 0xb) {
10678 /* Non-accumulating ops */
10679 tcg_passres
= tcg_res
[pass
];
10681 tcg_passres
= tcg_temp_new_i64();
10684 if (memop
& MO_SIGN
) {
10685 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
10687 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
10690 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10691 tcg_passres
, tcg_passres
);
10693 tcg_temp_free_i32(tcg_op
);
10695 if (opcode
== 0xa || opcode
== 0xb) {
10699 /* Accumulating op: handle accumulate step */
10700 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10703 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10704 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
10707 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10708 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
10711 case 0x7: /* SQDMLSL, SQDMLSL2 */
10712 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10714 case 0x3: /* SQDMLAL, SQDMLAL2 */
10715 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10720 g_assert_not_reached();
10722 tcg_temp_free_i64(tcg_passres
);
10724 tcg_temp_free_i32(tcg_idx
);
10727 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
10732 tcg_res
[1] = tcg_const_i64(0);
10735 for (pass
= 0; pass
< 2; pass
++) {
10736 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10737 tcg_temp_free_i64(tcg_res
[pass
]);
10741 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
10742 tcg_temp_free_ptr(fpst
);
10746 /* C3.6.19 Crypto AES
10747 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10748 * +-----------------+------+-----------+--------+-----+------+------+
10749 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10750 * +-----------------+------+-----------+--------+-----+------+------+
10752 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
10754 int size
= extract32(insn
, 22, 2);
10755 int opcode
= extract32(insn
, 12, 5);
10756 int rn
= extract32(insn
, 5, 5);
10757 int rd
= extract32(insn
, 0, 5);
10759 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
;
10760 CryptoThreeOpEnvFn
*genfn
;
10762 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)
10764 unallocated_encoding(s
);
10769 case 0x4: /* AESE */
10771 genfn
= gen_helper_crypto_aese
;
10773 case 0x6: /* AESMC */
10775 genfn
= gen_helper_crypto_aesmc
;
10777 case 0x5: /* AESD */
10779 genfn
= gen_helper_crypto_aese
;
10781 case 0x7: /* AESIMC */
10783 genfn
= gen_helper_crypto_aesmc
;
10786 unallocated_encoding(s
);
10790 /* Note that we convert the Vx register indexes into the
10791 * index within the vfp.regs[] array, so we can share the
10792 * helper with the AArch32 instructions.
10794 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10795 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10796 tcg_decrypt
= tcg_const_i32(decrypt
);
10798 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
);
10800 tcg_temp_free_i32(tcg_rd_regno
);
10801 tcg_temp_free_i32(tcg_rn_regno
);
10802 tcg_temp_free_i32(tcg_decrypt
);
10805 /* C3.6.20 Crypto three-reg SHA
10806 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
10807 * +-----------------+------+---+------+---+--------+-----+------+------+
10808 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
10809 * +-----------------+------+---+------+---+--------+-----+------+------+
10811 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
10813 int size
= extract32(insn
, 22, 2);
10814 int opcode
= extract32(insn
, 12, 3);
10815 int rm
= extract32(insn
, 16, 5);
10816 int rn
= extract32(insn
, 5, 5);
10817 int rd
= extract32(insn
, 0, 5);
10818 CryptoThreeOpEnvFn
*genfn
;
10819 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
;
10820 int feature
= ARM_FEATURE_V8_SHA256
;
10823 unallocated_encoding(s
);
10828 case 0: /* SHA1C */
10829 case 1: /* SHA1P */
10830 case 2: /* SHA1M */
10831 case 3: /* SHA1SU0 */
10833 feature
= ARM_FEATURE_V8_SHA1
;
10835 case 4: /* SHA256H */
10836 genfn
= gen_helper_crypto_sha256h
;
10838 case 5: /* SHA256H2 */
10839 genfn
= gen_helper_crypto_sha256h2
;
10841 case 6: /* SHA256SU1 */
10842 genfn
= gen_helper_crypto_sha256su1
;
10845 unallocated_encoding(s
);
10849 if (!arm_dc_feature(s
, feature
)) {
10850 unallocated_encoding(s
);
10854 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10855 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10856 tcg_rm_regno
= tcg_const_i32(rm
<< 1);
10859 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
);
10861 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
10863 gen_helper_crypto_sha1_3reg(cpu_env
, tcg_rd_regno
,
10864 tcg_rn_regno
, tcg_rm_regno
, tcg_opcode
);
10865 tcg_temp_free_i32(tcg_opcode
);
10868 tcg_temp_free_i32(tcg_rd_regno
);
10869 tcg_temp_free_i32(tcg_rn_regno
);
10870 tcg_temp_free_i32(tcg_rm_regno
);
10873 /* C3.6.21 Crypto two-reg SHA
10874 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10875 * +-----------------+------+-----------+--------+-----+------+------+
10876 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10877 * +-----------------+------+-----------+--------+-----+------+------+
10879 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
10881 int size
= extract32(insn
, 22, 2);
10882 int opcode
= extract32(insn
, 12, 5);
10883 int rn
= extract32(insn
, 5, 5);
10884 int rd
= extract32(insn
, 0, 5);
10885 CryptoTwoOpEnvFn
*genfn
;
10887 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
;
10890 unallocated_encoding(s
);
10895 case 0: /* SHA1H */
10896 feature
= ARM_FEATURE_V8_SHA1
;
10897 genfn
= gen_helper_crypto_sha1h
;
10899 case 1: /* SHA1SU1 */
10900 feature
= ARM_FEATURE_V8_SHA1
;
10901 genfn
= gen_helper_crypto_sha1su1
;
10903 case 2: /* SHA256SU0 */
10904 feature
= ARM_FEATURE_V8_SHA256
;
10905 genfn
= gen_helper_crypto_sha256su0
;
10908 unallocated_encoding(s
);
10912 if (!arm_dc_feature(s
, feature
)) {
10913 unallocated_encoding(s
);
10917 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10918 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10920 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
);
10922 tcg_temp_free_i32(tcg_rd_regno
);
10923 tcg_temp_free_i32(tcg_rn_regno
);
10926 /* C3.6 Data processing - SIMD, inc Crypto
10928 * As the decode gets a little complex we are using a table based
10929 * approach for this part of the decode.
10931 static const AArch64DecodeTable data_proc_simd
[] = {
10932 /* pattern , mask , fn */
10933 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
10934 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
10935 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
10936 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
10937 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
10938 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
10939 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
10940 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
10941 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
10942 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
10943 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
10944 { 0x2e000000, 0xbf208400, disas_simd_ext
},
10945 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
10946 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
10947 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
10948 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
10949 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
10950 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
10951 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
10952 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
10953 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
10954 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
10955 { 0x00000000, 0x00000000, NULL
}
10958 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
10960 /* Note that this is called with all non-FP cases from
10961 * table C3-6 so it must UNDEF for entries not specifically
10962 * allocated to instructions in that table.
10964 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
10968 unallocated_encoding(s
);
10972 /* C3.6 Data processing - SIMD and floating point */
10973 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
10975 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
10976 disas_data_proc_fp(s
, insn
);
10978 /* SIMD, including crypto */
10979 disas_data_proc_simd(s
, insn
);
10983 /* C3.1 A64 instruction index by encoding */
10984 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
10988 insn
= arm_ldl_code(env
, s
->pc
, s
->sctlr_b
);
10992 s
->fp_access_checked
= false;
10994 switch (extract32(insn
, 25, 4)) {
10995 case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
10996 unallocated_encoding(s
);
10998 case 0x8: case 0x9: /* Data processing - immediate */
10999 disas_data_proc_imm(s
, insn
);
11001 case 0xa: case 0xb: /* Branch, exception generation and system insns */
11002 disas_b_exc_sys(s
, insn
);
11007 case 0xe: /* Loads and stores */
11008 disas_ldst(s
, insn
);
11011 case 0xd: /* Data processing - register */
11012 disas_data_proc_reg(s
, insn
);
11015 case 0xf: /* Data processing - SIMD and floating point */
11016 disas_data_proc_simd_fp(s
, insn
);
11019 assert(FALSE
); /* all 15 cases should be handled above */
11023 /* if we allocated any temporaries, free them here */
11027 void gen_intermediate_code_a64(ARMCPU
*cpu
, TranslationBlock
*tb
)
11029 CPUState
*cs
= CPU(cpu
);
11030 CPUARMState
*env
= &cpu
->env
;
11031 DisasContext dc1
, *dc
= &dc1
;
11032 target_ulong pc_start
;
11033 target_ulong next_page_start
;
11041 dc
->is_jmp
= DISAS_NEXT
;
11043 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
11047 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
11048 * there is no secure EL1, so we route exceptions to EL3.
11050 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
11051 !arm_el_is_aa64(env
, 3);
11054 dc
->be_data
= ARM_TBFLAG_BE_DATA(tb
->flags
) ? MO_BE
: MO_LE
;
11055 dc
->condexec_mask
= 0;
11056 dc
->condexec_cond
= 0;
11057 dc
->mmu_idx
= ARM_TBFLAG_MMUIDX(tb
->flags
);
11058 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
11059 #if !defined(CONFIG_USER_ONLY)
11060 dc
->user
= (dc
->current_el
== 0);
11062 dc
->fp_excp_el
= ARM_TBFLAG_FPEXC_EL(tb
->flags
);
11064 dc
->vec_stride
= 0;
11065 dc
->cp_regs
= cpu
->cp_regs
;
11066 dc
->features
= env
->features
;
11068 /* Single step state. The code-generation logic here is:
11070 * generate code with no special handling for single-stepping (except
11071 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
11072 * this happens anyway because those changes are all system register or
11074 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
11075 * emit code for one insn
11076 * emit code to clear PSTATE.SS
11077 * emit code to generate software step exception for completed step
11078 * end TB (as usual for having generated an exception)
11079 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
11080 * emit code to generate a software step exception
11083 dc
->ss_active
= ARM_TBFLAG_SS_ACTIVE(tb
->flags
);
11084 dc
->pstate_ss
= ARM_TBFLAG_PSTATE_SS(tb
->flags
);
11085 dc
->is_ldex
= false;
11086 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
11088 init_tmp_a64_array(dc
);
11090 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
11092 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
11093 if (max_insns
== 0) {
11094 max_insns
= CF_COUNT_MASK
;
11096 if (max_insns
> TCG_MAX_INSNS
) {
11097 max_insns
= TCG_MAX_INSNS
;
11102 tcg_clear_temp_count();
11105 tcg_gen_insn_start(dc
->pc
, 0);
11108 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
11110 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
11111 if (bp
->pc
== dc
->pc
) {
11112 if (bp
->flags
& BP_CPU
) {
11113 gen_a64_set_pc_im(dc
->pc
);
11114 gen_helper_check_breakpoints(cpu_env
);
11115 /* End the TB early; it likely won't be executed */
11116 dc
->is_jmp
= DISAS_UPDATE
;
11118 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
11119 /* The address covered by the breakpoint must be
11120 included in [tb->pc, tb->pc + tb->size) in order
11121 to for it to be properly cleared -- thus we
11122 increment the PC here so that the logic setting
11123 tb->size below does the right thing. */
11125 goto done_generating
;
11132 if (num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
11136 if (dc
->ss_active
&& !dc
->pstate_ss
) {
11137 /* Singlestep state is Active-pending.
11138 * If we're in this state at the start of a TB then either
11139 * a) we just took an exception to an EL which is being debugged
11140 * and this is the first insn in the exception handler
11141 * b) debug exceptions were masked and we just unmasked them
11142 * without changing EL (eg by clearing PSTATE.D)
11143 * In either case we're going to take a swstep exception in the
11144 * "did not step an insn" case, and so the syndrome ISV and EX
11145 * bits should be zero.
11147 assert(num_insns
== 1);
11148 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0),
11149 default_exception_el(dc
));
11150 dc
->is_jmp
= DISAS_EXC
;
11154 disas_a64_insn(env
, dc
);
11156 if (tcg_check_temp_count()) {
11157 fprintf(stderr
, "TCG temporary leak before "TARGET_FMT_lx
"\n",
11161 /* Translation stops when a conditional branch is encountered.
11162 * Otherwise the subsequent code could get translated several times.
11163 * Also stop translation when a page boundary is reached. This
11164 * ensures prefetch aborts occur at the right place.
11166 } while (!dc
->is_jmp
&& !tcg_op_buf_full() &&
11167 !cs
->singlestep_enabled
&&
11170 dc
->pc
< next_page_start
&&
11171 num_insns
< max_insns
);
11173 if (tb
->cflags
& CF_LAST_IO
) {
11177 if (unlikely(cs
->singlestep_enabled
|| dc
->ss_active
)
11178 && dc
->is_jmp
!= DISAS_EXC
) {
11179 /* Note that this means single stepping WFI doesn't halt the CPU.
11180 * For conditional branch insns this is harmless unreachable code as
11181 * gen_goto_tb() has already handled emitting the debug exception
11182 * (and thus a tb-jump is not possible when singlestepping).
11184 assert(dc
->is_jmp
!= DISAS_TB_JUMP
);
11185 if (dc
->is_jmp
!= DISAS_JUMP
) {
11186 gen_a64_set_pc_im(dc
->pc
);
11188 if (cs
->singlestep_enabled
) {
11189 gen_exception_internal(EXCP_DEBUG
);
11191 gen_step_complete_exception(dc
);
11194 switch (dc
->is_jmp
) {
11196 gen_goto_tb(dc
, 1, dc
->pc
);
11200 gen_a64_set_pc_im(dc
->pc
);
11203 /* indicate that the hash table must be used to find the next TB */
11204 tcg_gen_exit_tb(0);
11206 case DISAS_TB_JUMP
:
11211 gen_a64_set_pc_im(dc
->pc
);
11212 gen_helper_wfe(cpu_env
);
11215 gen_a64_set_pc_im(dc
->pc
);
11216 gen_helper_yield(cpu_env
);
11219 /* This is a special case because we don't want to just halt the CPU
11220 * if trying to debug across a WFI.
11222 gen_a64_set_pc_im(dc
->pc
);
11223 gen_helper_wfi(cpu_env
);
11224 /* The helper doesn't necessarily throw an exception, but we
11225 * must go back to the main loop to check for interrupts anyway.
11227 tcg_gen_exit_tb(0);
11233 gen_tb_end(tb
, num_insns
);
11236 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
) &&
11237 qemu_log_in_addr_range(pc_start
)) {
11238 qemu_log("----------------\n");
11239 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
11240 log_target_disas(cs
, pc_start
, dc
->pc
- pc_start
,
11241 4 | (bswap_code(dc
->sctlr_b
) ? 2 : 0));
11245 tb
->size
= dc
->pc
- pc_start
;
11246 tb
->icount
= num_insns
;