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 disas_set_insn_syndrome(DisasContext
*s
, uint32_t syn
)
313 /* We don't need to save all of the syndrome so we mask and shift
314 * out uneeded bits to help the sleb128 encoder do a better job.
316 syn
&= ARM_INSN_START_WORD2_MASK
;
317 syn
>>= ARM_INSN_START_WORD2_SHIFT
;
319 /* We check and clear insn_start_idx to catch multiple updates. */
320 assert(s
->insn_start_idx
!= 0);
321 tcg_set_insn_param(s
->insn_start_idx
, 2, syn
);
322 s
->insn_start_idx
= 0;
325 static void unallocated_encoding(DisasContext
*s
)
327 /* Unallocated and reserved encodings are uncategorized */
328 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized(),
329 default_exception_el(s
));
332 #define unsupported_encoding(s, insn) \
334 qemu_log_mask(LOG_UNIMP, \
335 "%s:%d: unsupported instruction encoding 0x%08x " \
336 "at pc=%016" PRIx64 "\n", \
337 __FILE__, __LINE__, insn, s->pc - 4); \
338 unallocated_encoding(s); \
341 static void init_tmp_a64_array(DisasContext
*s
)
343 #ifdef CONFIG_DEBUG_TCG
345 for (i
= 0; i
< ARRAY_SIZE(s
->tmp_a64
); i
++) {
346 TCGV_UNUSED_I64(s
->tmp_a64
[i
]);
349 s
->tmp_a64_count
= 0;
352 static void free_tmp_a64(DisasContext
*s
)
355 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
356 tcg_temp_free_i64(s
->tmp_a64
[i
]);
358 init_tmp_a64_array(s
);
361 static TCGv_i64
new_tmp_a64(DisasContext
*s
)
363 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
364 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
367 static TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
369 TCGv_i64 t
= new_tmp_a64(s
);
370 tcg_gen_movi_i64(t
, 0);
375 * Register access functions
377 * These functions are used for directly accessing a register in where
378 * changes to the final register value are likely to be made. If you
379 * need to use a register for temporary calculation (e.g. index type
380 * operations) use the read_* form.
382 * B1.2.1 Register mappings
384 * In instruction register encoding 31 can refer to ZR (zero register) or
385 * the SP (stack pointer) depending on context. In QEMU's case we map SP
386 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
387 * This is the point of the _sp forms.
389 static TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
392 return new_tmp_a64_zero(s
);
398 /* register access for when 31 == SP */
399 static TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
404 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
405 * representing the register contents. This TCGv is an auto-freed
406 * temporary so it need not be explicitly freed, and may be modified.
408 static TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
410 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
]);
418 tcg_gen_movi_i64(v
, 0);
423 static TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
425 TCGv_i64 v
= new_tmp_a64(s
);
427 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
429 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
434 /* We should have at some point before trying to access an FP register
435 * done the necessary access check, so assert that
436 * (a) we did the check and
437 * (b) we didn't then just plough ahead anyway if it failed.
438 * Print the instruction pattern in the abort message so we can figure
439 * out what we need to fix if a user encounters this problem in the wild.
441 static inline void assert_fp_access_checked(DisasContext
*s
)
443 #ifdef CONFIG_DEBUG_TCG
444 if (unlikely(!s
->fp_access_checked
|| s
->fp_excp_el
)) {
445 fprintf(stderr
, "target-arm: FP access check missing for "
446 "instruction 0x%08x\n", s
->insn
);
452 /* Return the offset into CPUARMState of an element of specified
453 * size, 'element' places in from the least significant end of
454 * the FP/vector register Qn.
456 static inline int vec_reg_offset(DisasContext
*s
, int regno
,
457 int element
, TCGMemOp size
)
459 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
460 #ifdef HOST_WORDS_BIGENDIAN
461 /* This is complicated slightly because vfp.regs[2n] is
462 * still the low half and vfp.regs[2n+1] the high half
463 * of the 128 bit vector, even on big endian systems.
464 * Calculate the offset assuming a fully bigendian 128 bits,
465 * then XOR to account for the order of the two 64 bit halves.
467 offs
+= (16 - ((element
+ 1) * (1 << size
)));
470 offs
+= element
* (1 << size
);
472 assert_fp_access_checked(s
);
476 /* Return the offset into CPUARMState of a slice (from
477 * the least significant end) of FP register Qn (ie
479 * (Note that this is not the same mapping as for A32; see cpu.h)
481 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
483 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
484 #ifdef HOST_WORDS_BIGENDIAN
485 offs
+= (8 - (1 << size
));
487 assert_fp_access_checked(s
);
491 /* Offset of the high half of the 128 bit vector Qn */
492 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
494 assert_fp_access_checked(s
);
495 return offsetof(CPUARMState
, vfp
.regs
[regno
* 2 + 1]);
498 /* Convenience accessors for reading and writing single and double
499 * FP registers. Writing clears the upper parts of the associated
500 * 128 bit vector register, as required by the architecture.
501 * Note that unlike the GP register accessors, the values returned
502 * by the read functions must be manually freed.
504 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
506 TCGv_i64 v
= tcg_temp_new_i64();
508 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
512 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
514 TCGv_i32 v
= tcg_temp_new_i32();
516 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
520 static void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
522 TCGv_i64 tcg_zero
= tcg_const_i64(0);
524 tcg_gen_st_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
525 tcg_gen_st_i64(tcg_zero
, cpu_env
, fp_reg_hi_offset(s
, reg
));
526 tcg_temp_free_i64(tcg_zero
);
529 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
531 TCGv_i64 tmp
= tcg_temp_new_i64();
533 tcg_gen_extu_i32_i64(tmp
, v
);
534 write_fp_dreg(s
, reg
, tmp
);
535 tcg_temp_free_i64(tmp
);
538 static TCGv_ptr
get_fpstatus_ptr(void)
540 TCGv_ptr statusptr
= tcg_temp_new_ptr();
543 /* In A64 all instructions (both FP and Neon) use the FPCR;
544 * there is no equivalent of the A32 Neon "standard FPSCR value"
545 * and all operations use vfp.fp_status.
547 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
548 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
552 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
553 * than the 32 bit equivalent.
555 static inline void gen_set_NZ64(TCGv_i64 result
)
557 tcg_gen_extr_i64_i32(cpu_ZF
, cpu_NF
, result
);
558 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, cpu_NF
);
561 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
562 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
565 gen_set_NZ64(result
);
567 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
568 tcg_gen_mov_i32(cpu_NF
, cpu_ZF
);
570 tcg_gen_movi_i32(cpu_CF
, 0);
571 tcg_gen_movi_i32(cpu_VF
, 0);
574 /* dest = T0 + T1; compute C, N, V and Z flags */
575 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
578 TCGv_i64 result
, flag
, tmp
;
579 result
= tcg_temp_new_i64();
580 flag
= tcg_temp_new_i64();
581 tmp
= tcg_temp_new_i64();
583 tcg_gen_movi_i64(tmp
, 0);
584 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
586 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
588 gen_set_NZ64(result
);
590 tcg_gen_xor_i64(flag
, result
, t0
);
591 tcg_gen_xor_i64(tmp
, t0
, t1
);
592 tcg_gen_andc_i64(flag
, flag
, tmp
);
593 tcg_temp_free_i64(tmp
);
594 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
596 tcg_gen_mov_i64(dest
, result
);
597 tcg_temp_free_i64(result
);
598 tcg_temp_free_i64(flag
);
600 /* 32 bit arithmetic */
601 TCGv_i32 t0_32
= tcg_temp_new_i32();
602 TCGv_i32 t1_32
= tcg_temp_new_i32();
603 TCGv_i32 tmp
= tcg_temp_new_i32();
605 tcg_gen_movi_i32(tmp
, 0);
606 tcg_gen_extrl_i64_i32(t0_32
, t0
);
607 tcg_gen_extrl_i64_i32(t1_32
, t1
);
608 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
609 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
610 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
611 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
612 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
613 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
615 tcg_temp_free_i32(tmp
);
616 tcg_temp_free_i32(t0_32
);
617 tcg_temp_free_i32(t1_32
);
621 /* dest = T0 - T1; compute C, N, V and Z flags */
622 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
625 /* 64 bit arithmetic */
626 TCGv_i64 result
, flag
, tmp
;
628 result
= tcg_temp_new_i64();
629 flag
= tcg_temp_new_i64();
630 tcg_gen_sub_i64(result
, t0
, t1
);
632 gen_set_NZ64(result
);
634 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
635 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
637 tcg_gen_xor_i64(flag
, result
, t0
);
638 tmp
= tcg_temp_new_i64();
639 tcg_gen_xor_i64(tmp
, t0
, t1
);
640 tcg_gen_and_i64(flag
, flag
, tmp
);
641 tcg_temp_free_i64(tmp
);
642 tcg_gen_extrh_i64_i32(cpu_VF
, flag
);
643 tcg_gen_mov_i64(dest
, result
);
644 tcg_temp_free_i64(flag
);
645 tcg_temp_free_i64(result
);
647 /* 32 bit arithmetic */
648 TCGv_i32 t0_32
= tcg_temp_new_i32();
649 TCGv_i32 t1_32
= tcg_temp_new_i32();
652 tcg_gen_extrl_i64_i32(t0_32
, t0
);
653 tcg_gen_extrl_i64_i32(t1_32
, t1
);
654 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
655 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
656 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
657 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
658 tmp
= tcg_temp_new_i32();
659 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
660 tcg_temp_free_i32(t0_32
);
661 tcg_temp_free_i32(t1_32
);
662 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
663 tcg_temp_free_i32(tmp
);
664 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
668 /* dest = T0 + T1 + CF; do not compute flags. */
669 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
671 TCGv_i64 flag
= tcg_temp_new_i64();
672 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
673 tcg_gen_add_i64(dest
, t0
, t1
);
674 tcg_gen_add_i64(dest
, dest
, flag
);
675 tcg_temp_free_i64(flag
);
678 tcg_gen_ext32u_i64(dest
, dest
);
682 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
683 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
686 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
687 result
= tcg_temp_new_i64();
688 cf_64
= tcg_temp_new_i64();
689 vf_64
= tcg_temp_new_i64();
690 tmp
= tcg_const_i64(0);
692 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
693 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
694 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
695 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
696 gen_set_NZ64(result
);
698 tcg_gen_xor_i64(vf_64
, result
, t0
);
699 tcg_gen_xor_i64(tmp
, t0
, t1
);
700 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
701 tcg_gen_extrh_i64_i32(cpu_VF
, vf_64
);
703 tcg_gen_mov_i64(dest
, result
);
705 tcg_temp_free_i64(tmp
);
706 tcg_temp_free_i64(vf_64
);
707 tcg_temp_free_i64(cf_64
);
708 tcg_temp_free_i64(result
);
710 TCGv_i32 t0_32
, t1_32
, tmp
;
711 t0_32
= tcg_temp_new_i32();
712 t1_32
= tcg_temp_new_i32();
713 tmp
= tcg_const_i32(0);
715 tcg_gen_extrl_i64_i32(t0_32
, t0
);
716 tcg_gen_extrl_i64_i32(t1_32
, t1
);
717 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
718 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
720 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
721 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
722 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
723 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
724 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
726 tcg_temp_free_i32(tmp
);
727 tcg_temp_free_i32(t1_32
);
728 tcg_temp_free_i32(t0_32
);
733 * Load/Store generators
737 * Store from GPR register to memory.
739 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
740 TCGv_i64 tcg_addr
, int size
, int memidx
,
742 unsigned int iss_srt
,
743 bool iss_sf
, bool iss_ar
)
746 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, s
->be_data
+ size
);
751 syn
= syn_data_abort_with_iss(0,
757 0, 0, 0, 0, 0, false);
758 disas_set_insn_syndrome(s
, syn
);
762 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
763 TCGv_i64 tcg_addr
, int size
,
765 unsigned int iss_srt
,
766 bool iss_sf
, bool iss_ar
)
768 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
),
769 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
773 * Load from memory to GPR register
775 static void do_gpr_ld_memidx(DisasContext
*s
,
776 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
777 int size
, bool is_signed
,
778 bool extend
, int memidx
,
779 bool iss_valid
, unsigned int iss_srt
,
780 bool iss_sf
, bool iss_ar
)
782 TCGMemOp memop
= s
->be_data
+ size
;
790 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
792 if (extend
&& is_signed
) {
794 tcg_gen_ext32u_i64(dest
, dest
);
800 syn
= syn_data_abort_with_iss(0,
806 0, 0, 0, 0, 0, false);
807 disas_set_insn_syndrome(s
, syn
);
811 static void do_gpr_ld(DisasContext
*s
,
812 TCGv_i64 dest
, TCGv_i64 tcg_addr
,
813 int size
, bool is_signed
, bool extend
,
814 bool iss_valid
, unsigned int iss_srt
,
815 bool iss_sf
, bool iss_ar
)
817 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
819 iss_valid
, iss_srt
, iss_sf
, iss_ar
);
823 * Store from FP register to memory
825 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
827 /* This writes the bottom N bits of a 128 bit wide vector to memory */
828 TCGv_i64 tmp
= tcg_temp_new_i64();
829 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
831 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
),
834 bool be
= s
->be_data
== MO_BE
;
835 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
837 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
838 tcg_gen_qemu_st_i64(tmp
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
840 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
841 tcg_gen_qemu_st_i64(tmp
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
843 tcg_temp_free_i64(tcg_hiaddr
);
846 tcg_temp_free_i64(tmp
);
850 * Load from memory to FP register
852 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
854 /* This always zero-extends and writes to a full 128 bit wide vector */
855 TCGv_i64 tmplo
= tcg_temp_new_i64();
859 TCGMemOp memop
= s
->be_data
+ size
;
860 tmphi
= tcg_const_i64(0);
861 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
863 bool be
= s
->be_data
== MO_BE
;
866 tmphi
= tcg_temp_new_i64();
867 tcg_hiaddr
= tcg_temp_new_i64();
869 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
870 tcg_gen_qemu_ld_i64(tmplo
, be
? tcg_hiaddr
: tcg_addr
, get_mem_index(s
),
872 tcg_gen_qemu_ld_i64(tmphi
, be
? tcg_addr
: tcg_hiaddr
, get_mem_index(s
),
874 tcg_temp_free_i64(tcg_hiaddr
);
877 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
878 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
880 tcg_temp_free_i64(tmplo
);
881 tcg_temp_free_i64(tmphi
);
885 * Vector load/store helpers.
887 * The principal difference between this and a FP load is that we don't
888 * zero extend as we are filling a partial chunk of the vector register.
889 * These functions don't support 128 bit loads/stores, which would be
890 * normal load/store operations.
892 * The _i32 versions are useful when operating on 32 bit quantities
893 * (eg for floating point single or using Neon helper functions).
896 /* Get value of an element within a vector register */
897 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
898 int element
, TCGMemOp memop
)
900 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
903 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
906 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
909 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
912 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
915 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
918 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
922 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
925 g_assert_not_reached();
929 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
930 int element
, TCGMemOp memop
)
932 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
935 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
938 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
941 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
944 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
948 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
951 g_assert_not_reached();
955 /* Set value of an element within a vector register */
956 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
957 int element
, TCGMemOp memop
)
959 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
962 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
965 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
968 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
971 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
974 g_assert_not_reached();
978 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
979 int destidx
, int element
, TCGMemOp memop
)
981 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
984 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
987 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
990 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
993 g_assert_not_reached();
997 /* Clear the high 64 bits of a 128 bit vector (in general non-quad
998 * vector ops all need to do this).
1000 static void clear_vec_high(DisasContext
*s
, int rd
)
1002 TCGv_i64 tcg_zero
= tcg_const_i64(0);
1004 write_vec_element(s
, tcg_zero
, rd
, 1, MO_64
);
1005 tcg_temp_free_i64(tcg_zero
);
1008 /* Store from vector register to memory */
1009 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
1010 TCGv_i64 tcg_addr
, int size
)
1012 TCGMemOp memop
= s
->be_data
+ size
;
1013 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1015 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
1016 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
1018 tcg_temp_free_i64(tcg_tmp
);
1021 /* Load from memory to vector register */
1022 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
1023 TCGv_i64 tcg_addr
, int size
)
1025 TCGMemOp memop
= s
->be_data
+ size
;
1026 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
1028 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
1029 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
1031 tcg_temp_free_i64(tcg_tmp
);
1034 /* Check that FP/Neon access is enabled. If it is, return
1035 * true. If not, emit code to generate an appropriate exception,
1036 * and return false; the caller should not emit any code for
1037 * the instruction. Note that this check must happen after all
1038 * unallocated-encoding checks (otherwise the syndrome information
1039 * for the resulting exception will be incorrect).
1041 static inline bool fp_access_check(DisasContext
*s
)
1043 assert(!s
->fp_access_checked
);
1044 s
->fp_access_checked
= true;
1046 if (!s
->fp_excp_el
) {
1050 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false),
1056 * This utility function is for doing register extension with an
1057 * optional shift. You will likely want to pass a temporary for the
1058 * destination register. See DecodeRegExtend() in the ARM ARM.
1060 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
1061 int option
, unsigned int shift
)
1063 int extsize
= extract32(option
, 0, 2);
1064 bool is_signed
= extract32(option
, 2, 1);
1069 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1072 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1075 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1078 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1084 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1087 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1090 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1093 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1099 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1103 static inline void gen_check_sp_alignment(DisasContext
*s
)
1105 /* The AArch64 architecture mandates that (if enabled via PSTATE
1106 * or SCTLR bits) there is a check that SP is 16-aligned on every
1107 * SP-relative load or store (with an exception generated if it is not).
1108 * In line with general QEMU practice regarding misaligned accesses,
1109 * we omit these checks for the sake of guest program performance.
1110 * This function is provided as a hook so we can more easily add these
1111 * checks in future (possibly as a "favour catching guest program bugs
1112 * over speed" user selectable option).
1117 * This provides a simple table based table lookup decoder. It is
1118 * intended to be used when the relevant bits for decode are too
1119 * awkwardly placed and switch/if based logic would be confusing and
1120 * deeply nested. Since it's a linear search through the table, tables
1121 * should be kept small.
1123 * It returns the first handler where insn & mask == pattern, or
1124 * NULL if there is no match.
1125 * The table is terminated by an empty mask (i.e. 0)
1127 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1130 const AArch64DecodeTable
*tptr
= table
;
1132 while (tptr
->mask
) {
1133 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1134 return tptr
->disas_fn
;
1142 * the instruction disassembly implemented here matches
1143 * the instruction encoding classifications in chapter 3 (C3)
1144 * of the ARM Architecture Reference Manual (DDI0487A_a)
1147 /* C3.2.7 Unconditional branch (immediate)
1149 * +----+-----------+-------------------------------------+
1150 * | op | 0 0 1 0 1 | imm26 |
1151 * +----+-----------+-------------------------------------+
1153 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1155 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1157 if (insn
& (1U << 31)) {
1158 /* C5.6.26 BL Branch with link */
1159 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1162 /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
1163 gen_goto_tb(s
, 0, addr
);
1166 /* C3.2.1 Compare & branch (immediate)
1167 * 31 30 25 24 23 5 4 0
1168 * +----+-------------+----+---------------------+--------+
1169 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1170 * +----+-------------+----+---------------------+--------+
1172 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1174 unsigned int sf
, op
, rt
;
1176 TCGLabel
*label_match
;
1179 sf
= extract32(insn
, 31, 1);
1180 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1181 rt
= extract32(insn
, 0, 5);
1182 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1184 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1185 label_match
= gen_new_label();
1187 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1188 tcg_cmp
, 0, label_match
);
1190 gen_goto_tb(s
, 0, s
->pc
);
1191 gen_set_label(label_match
);
1192 gen_goto_tb(s
, 1, addr
);
1195 /* C3.2.5 Test & branch (immediate)
1196 * 31 30 25 24 23 19 18 5 4 0
1197 * +----+-------------+----+-------+-------------+------+
1198 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1199 * +----+-------------+----+-------+-------------+------+
1201 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1203 unsigned int bit_pos
, op
, rt
;
1205 TCGLabel
*label_match
;
1208 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1209 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1210 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1211 rt
= extract32(insn
, 0, 5);
1213 tcg_cmp
= tcg_temp_new_i64();
1214 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1215 label_match
= gen_new_label();
1216 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1217 tcg_cmp
, 0, label_match
);
1218 tcg_temp_free_i64(tcg_cmp
);
1219 gen_goto_tb(s
, 0, s
->pc
);
1220 gen_set_label(label_match
);
1221 gen_goto_tb(s
, 1, addr
);
1224 /* C3.2.2 / C5.6.19 Conditional branch (immediate)
1225 * 31 25 24 23 5 4 3 0
1226 * +---------------+----+---------------------+----+------+
1227 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1228 * +---------------+----+---------------------+----+------+
1230 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1235 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1236 unallocated_encoding(s
);
1239 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1240 cond
= extract32(insn
, 0, 4);
1243 /* genuinely conditional branches */
1244 TCGLabel
*label_match
= gen_new_label();
1245 arm_gen_test_cc(cond
, label_match
);
1246 gen_goto_tb(s
, 0, s
->pc
);
1247 gen_set_label(label_match
);
1248 gen_goto_tb(s
, 1, addr
);
1250 /* 0xe and 0xf are both "always" conditions */
1251 gen_goto_tb(s
, 0, addr
);
1256 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1257 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1259 unsigned int selector
= crm
<< 3 | op2
;
1262 unallocated_encoding(s
);
1270 s
->is_jmp
= DISAS_WFI
;
1273 s
->is_jmp
= DISAS_YIELD
;
1276 s
->is_jmp
= DISAS_WFE
;
1280 /* we treat all as NOP at least for now */
1283 /* default specified as NOP equivalent */
1288 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1290 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1293 /* CLREX, DSB, DMB, ISB */
1294 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1295 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1300 unallocated_encoding(s
);
1311 case 1: /* MBReqTypes_Reads */
1312 bar
= TCG_BAR_SC
| TCG_MO_LD_LD
| TCG_MO_LD_ST
;
1314 case 2: /* MBReqTypes_Writes */
1315 bar
= TCG_BAR_SC
| TCG_MO_ST_ST
;
1317 default: /* MBReqTypes_All */
1318 bar
= TCG_BAR_SC
| TCG_MO_ALL
;
1324 /* We need to break the TB after this insn to execute
1325 * a self-modified code correctly and also to take
1326 * any pending interrupts immediately.
1328 s
->is_jmp
= DISAS_UPDATE
;
1331 unallocated_encoding(s
);
1336 /* C5.6.130 MSR (immediate) - move immediate to processor state field */
1337 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1338 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1340 int op
= op1
<< 3 | op2
;
1342 case 0x05: /* SPSel */
1343 if (s
->current_el
== 0) {
1344 unallocated_encoding(s
);
1348 case 0x1e: /* DAIFSet */
1349 case 0x1f: /* DAIFClear */
1351 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1352 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1353 gen_a64_set_pc_im(s
->pc
- 4);
1354 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1355 tcg_temp_free_i32(tcg_imm
);
1356 tcg_temp_free_i32(tcg_op
);
1357 s
->is_jmp
= DISAS_UPDATE
;
1361 unallocated_encoding(s
);
1366 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1368 TCGv_i32 tmp
= tcg_temp_new_i32();
1369 TCGv_i32 nzcv
= tcg_temp_new_i32();
1371 /* build bit 31, N */
1372 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1373 /* build bit 30, Z */
1374 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1375 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1376 /* build bit 29, C */
1377 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1378 /* build bit 28, V */
1379 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1380 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1381 /* generate result */
1382 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1384 tcg_temp_free_i32(nzcv
);
1385 tcg_temp_free_i32(tmp
);
1388 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1391 TCGv_i32 nzcv
= tcg_temp_new_i32();
1393 /* take NZCV from R[t] */
1394 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1397 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1399 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1400 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1402 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1403 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1405 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1406 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1407 tcg_temp_free_i32(nzcv
);
1410 /* C5.6.129 MRS - move from system register
1411 * C5.6.131 MSR (register) - move to system register
1414 * These are all essentially the same insn in 'read' and 'write'
1415 * versions, with varying op0 fields.
1417 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1418 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1419 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1421 const ARMCPRegInfo
*ri
;
1424 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1425 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1426 crn
, crm
, op0
, op1
, op2
));
1429 /* Unknown register; this might be a guest error or a QEMU
1430 * unimplemented feature.
1432 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1433 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1434 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1435 unallocated_encoding(s
);
1439 /* Check access permissions */
1440 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1441 unallocated_encoding(s
);
1446 /* Emit code to perform further access permissions checks at
1447 * runtime; this may result in an exception.
1450 TCGv_i32 tcg_syn
, tcg_isread
;
1453 gen_a64_set_pc_im(s
->pc
- 4);
1454 tmpptr
= tcg_const_ptr(ri
);
1455 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1456 tcg_syn
= tcg_const_i32(syndrome
);
1457 tcg_isread
= tcg_const_i32(isread
);
1458 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
, tcg_isread
);
1459 tcg_temp_free_ptr(tmpptr
);
1460 tcg_temp_free_i32(tcg_syn
);
1461 tcg_temp_free_i32(tcg_isread
);
1464 /* Handle special cases first */
1465 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1469 tcg_rt
= cpu_reg(s
, rt
);
1471 gen_get_nzcv(tcg_rt
);
1473 gen_set_nzcv(tcg_rt
);
1476 case ARM_CP_CURRENTEL
:
1477 /* Reads as current EL value from pstate, which is
1478 * guaranteed to be constant by the tb flags.
1480 tcg_rt
= cpu_reg(s
, rt
);
1481 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1484 /* Writes clear the aligned block of memory which rt points into. */
1485 tcg_rt
= cpu_reg(s
, rt
);
1486 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1492 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1496 tcg_rt
= cpu_reg(s
, rt
);
1499 if (ri
->type
& ARM_CP_CONST
) {
1500 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1501 } else if (ri
->readfn
) {
1503 tmpptr
= tcg_const_ptr(ri
);
1504 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1505 tcg_temp_free_ptr(tmpptr
);
1507 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1510 if (ri
->type
& ARM_CP_CONST
) {
1511 /* If not forbidden by access permissions, treat as WI */
1513 } else if (ri
->writefn
) {
1515 tmpptr
= tcg_const_ptr(ri
);
1516 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1517 tcg_temp_free_ptr(tmpptr
);
1519 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1523 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1524 /* I/O operations must end the TB here (whether read or write) */
1526 s
->is_jmp
= DISAS_UPDATE
;
1527 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1528 /* We default to ending the TB on a coprocessor register write,
1529 * but allow this to be suppressed by the register definition
1530 * (usually only necessary to work around guest bugs).
1532 s
->is_jmp
= DISAS_UPDATE
;
1537 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1538 * +---------------------+---+-----+-----+-------+-------+-----+------+
1539 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1540 * +---------------------+---+-----+-----+-------+-------+-----+------+
1542 static void disas_system(DisasContext
*s
, uint32_t insn
)
1544 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1545 l
= extract32(insn
, 21, 1);
1546 op0
= extract32(insn
, 19, 2);
1547 op1
= extract32(insn
, 16, 3);
1548 crn
= extract32(insn
, 12, 4);
1549 crm
= extract32(insn
, 8, 4);
1550 op2
= extract32(insn
, 5, 3);
1551 rt
= extract32(insn
, 0, 5);
1554 if (l
|| rt
!= 31) {
1555 unallocated_encoding(s
);
1559 case 2: /* C5.6.68 HINT */
1560 handle_hint(s
, insn
, op1
, op2
, crm
);
1562 case 3: /* CLREX, DSB, DMB, ISB */
1563 handle_sync(s
, insn
, op1
, op2
, crm
);
1565 case 4: /* C5.6.130 MSR (immediate) */
1566 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1569 unallocated_encoding(s
);
1574 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1577 /* C3.2.3 Exception generation
1579 * 31 24 23 21 20 5 4 2 1 0
1580 * +-----------------+-----+------------------------+-----+----+
1581 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1582 * +-----------------------+------------------------+----------+
1584 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1586 int opc
= extract32(insn
, 21, 3);
1587 int op2_ll
= extract32(insn
, 0, 5);
1588 int imm16
= extract32(insn
, 5, 16);
1593 /* For SVC, HVC and SMC we advance the single-step state
1594 * machine before taking the exception. This is architecturally
1595 * mandated, to ensure that single-stepping a system call
1596 * instruction works properly.
1601 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
),
1602 default_exception_el(s
));
1605 if (s
->current_el
== 0) {
1606 unallocated_encoding(s
);
1609 /* The pre HVC helper handles cases when HVC gets trapped
1610 * as an undefined insn by runtime configuration.
1612 gen_a64_set_pc_im(s
->pc
- 4);
1613 gen_helper_pre_hvc(cpu_env
);
1615 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
), 2);
1618 if (s
->current_el
== 0) {
1619 unallocated_encoding(s
);
1622 gen_a64_set_pc_im(s
->pc
- 4);
1623 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1624 gen_helper_pre_smc(cpu_env
, tmp
);
1625 tcg_temp_free_i32(tmp
);
1627 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
), 3);
1630 unallocated_encoding(s
);
1636 unallocated_encoding(s
);
1640 gen_exception_insn(s
, 4, EXCP_BKPT
, syn_aa64_bkpt(imm16
),
1641 default_exception_el(s
));
1645 unallocated_encoding(s
);
1648 /* HLT. This has two purposes.
1649 * Architecturally, it is an external halting debug instruction.
1650 * Since QEMU doesn't implement external debug, we treat this as
1651 * it is required for halting debug disabled: it will UNDEF.
1652 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1654 if (semihosting_enabled() && imm16
== 0xf000) {
1655 #ifndef CONFIG_USER_ONLY
1656 /* In system mode, don't allow userspace access to semihosting,
1657 * to provide some semblance of security (and for consistency
1658 * with our 32-bit semihosting).
1660 if (s
->current_el
== 0) {
1661 unsupported_encoding(s
, insn
);
1665 gen_exception_internal_insn(s
, 0, EXCP_SEMIHOST
);
1667 unsupported_encoding(s
, insn
);
1671 if (op2_ll
< 1 || op2_ll
> 3) {
1672 unallocated_encoding(s
);
1675 /* DCPS1, DCPS2, DCPS3 */
1676 unsupported_encoding(s
, insn
);
1679 unallocated_encoding(s
);
1684 /* C3.2.7 Unconditional branch (register)
1685 * 31 25 24 21 20 16 15 10 9 5 4 0
1686 * +---------------+-------+-------+-------+------+-------+
1687 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1688 * +---------------+-------+-------+-------+------+-------+
1690 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1692 unsigned int opc
, op2
, op3
, rn
, op4
;
1694 opc
= extract32(insn
, 21, 4);
1695 op2
= extract32(insn
, 16, 5);
1696 op3
= extract32(insn
, 10, 6);
1697 rn
= extract32(insn
, 5, 5);
1698 op4
= extract32(insn
, 0, 5);
1700 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1701 unallocated_encoding(s
);
1708 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1711 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1712 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1715 if (s
->current_el
== 0) {
1716 unallocated_encoding(s
);
1719 gen_helper_exception_return(cpu_env
);
1720 s
->is_jmp
= DISAS_JUMP
;
1724 unallocated_encoding(s
);
1726 unsupported_encoding(s
, insn
);
1730 unallocated_encoding(s
);
1734 s
->is_jmp
= DISAS_JUMP
;
1737 /* C3.2 Branches, exception generating and system instructions */
1738 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1740 switch (extract32(insn
, 25, 7)) {
1741 case 0x0a: case 0x0b:
1742 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1743 disas_uncond_b_imm(s
, insn
);
1745 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1746 disas_comp_b_imm(s
, insn
);
1748 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1749 disas_test_b_imm(s
, insn
);
1751 case 0x2a: /* Conditional branch (immediate) */
1752 disas_cond_b_imm(s
, insn
);
1754 case 0x6a: /* Exception generation / System */
1755 if (insn
& (1 << 24)) {
1756 disas_system(s
, insn
);
1761 case 0x6b: /* Unconditional branch (register) */
1762 disas_uncond_b_reg(s
, insn
);
1765 unallocated_encoding(s
);
1771 * Load/Store exclusive instructions are implemented by remembering
1772 * the value/address loaded, and seeing if these are the same
1773 * when the store is performed. This is not actually the architecturally
1774 * mandated semantics, but it works for typical guest code sequences
1775 * and avoids having to monitor regular stores.
1777 * In system emulation mode only one CPU will be running at once, so
1778 * this sequence is effectively atomic. In user emulation mode we
1779 * throw an exception and handle the atomic operation elsewhere.
1781 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
1782 TCGv_i64 addr
, int size
, bool is_pair
)
1784 TCGv_i64 tmp
= tcg_temp_new_i64();
1785 TCGMemOp memop
= s
->be_data
+ size
;
1787 g_assert(size
<= 3);
1788 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), memop
);
1791 TCGv_i64 addr2
= tcg_temp_new_i64();
1792 TCGv_i64 hitmp
= tcg_temp_new_i64();
1794 g_assert(size
>= 2);
1795 tcg_gen_addi_i64(addr2
, addr
, 1 << size
);
1796 tcg_gen_qemu_ld_i64(hitmp
, addr2
, get_mem_index(s
), memop
);
1797 tcg_temp_free_i64(addr2
);
1798 tcg_gen_mov_i64(cpu_exclusive_high
, hitmp
);
1799 tcg_gen_mov_i64(cpu_reg(s
, rt2
), hitmp
);
1800 tcg_temp_free_i64(hitmp
);
1803 tcg_gen_mov_i64(cpu_exclusive_val
, tmp
);
1804 tcg_gen_mov_i64(cpu_reg(s
, rt
), tmp
);
1806 tcg_temp_free_i64(tmp
);
1807 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
1810 #ifdef CONFIG_USER_ONLY
1811 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1812 TCGv_i64 addr
, int size
, int is_pair
)
1814 tcg_gen_mov_i64(cpu_exclusive_test
, addr
);
1815 tcg_gen_movi_i32(cpu_exclusive_info
,
1816 size
| is_pair
<< 2 | (rd
<< 4) | (rt
<< 9) | (rt2
<< 14));
1817 gen_exception_internal_insn(s
, 4, EXCP_STREX
);
1820 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1821 TCGv_i64 inaddr
, int size
, int is_pair
)
1823 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1824 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1827 * [addr + datasize] = {Rt2};
1833 * env->exclusive_addr = -1;
1835 TCGLabel
*fail_label
= gen_new_label();
1836 TCGLabel
*done_label
= gen_new_label();
1837 TCGv_i64 addr
= tcg_temp_local_new_i64();
1840 /* Copy input into a local temp so it is not trashed when the
1841 * basic block ends at the branch insn.
1843 tcg_gen_mov_i64(addr
, inaddr
);
1844 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
1846 tmp
= tcg_temp_new_i64();
1847 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), s
->be_data
+ size
);
1848 tcg_gen_brcond_i64(TCG_COND_NE
, tmp
, cpu_exclusive_val
, fail_label
);
1849 tcg_temp_free_i64(tmp
);
1852 TCGv_i64 addrhi
= tcg_temp_new_i64();
1853 TCGv_i64 tmphi
= tcg_temp_new_i64();
1855 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1856 tcg_gen_qemu_ld_i64(tmphi
, addrhi
, get_mem_index(s
),
1858 tcg_gen_brcond_i64(TCG_COND_NE
, tmphi
, cpu_exclusive_high
, fail_label
);
1860 tcg_temp_free_i64(tmphi
);
1861 tcg_temp_free_i64(addrhi
);
1864 /* We seem to still have the exclusive monitor, so do the store */
1865 tcg_gen_qemu_st_i64(cpu_reg(s
, rt
), addr
, get_mem_index(s
),
1868 TCGv_i64 addrhi
= tcg_temp_new_i64();
1870 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1871 tcg_gen_qemu_st_i64(cpu_reg(s
, rt2
), addrhi
,
1872 get_mem_index(s
), s
->be_data
+ size
);
1873 tcg_temp_free_i64(addrhi
);
1876 tcg_temp_free_i64(addr
);
1878 tcg_gen_movi_i64(cpu_reg(s
, rd
), 0);
1879 tcg_gen_br(done_label
);
1880 gen_set_label(fail_label
);
1881 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
1882 gen_set_label(done_label
);
1883 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1888 /* Update the Sixty-Four bit (SF) registersize. This logic is derived
1889 * from the ARMv8 specs for LDR (Shared decode for all encodings).
1891 static bool disas_ldst_compute_iss_sf(int size
, bool is_signed
, int opc
)
1893 int opc0
= extract32(opc
, 0, 1);
1897 regsize
= opc0
? 32 : 64;
1899 regsize
= size
== 3 ? 64 : 32;
1901 return regsize
== 64;
1904 /* C3.3.6 Load/store exclusive
1906 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
1907 * +-----+-------------+----+---+----+------+----+-------+------+------+
1908 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
1909 * +-----+-------------+----+---+----+------+----+-------+------+------+
1911 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
1912 * L: 0 -> store, 1 -> load
1913 * o2: 0 -> exclusive, 1 -> not
1914 * o1: 0 -> single register, 1 -> register pair
1915 * o0: 1 -> load-acquire/store-release, 0 -> not
1917 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
1919 int rt
= extract32(insn
, 0, 5);
1920 int rn
= extract32(insn
, 5, 5);
1921 int rt2
= extract32(insn
, 10, 5);
1922 int is_lasr
= extract32(insn
, 15, 1);
1923 int rs
= extract32(insn
, 16, 5);
1924 int is_pair
= extract32(insn
, 21, 1);
1925 int is_store
= !extract32(insn
, 22, 1);
1926 int is_excl
= !extract32(insn
, 23, 1);
1927 int size
= extract32(insn
, 30, 2);
1930 if ((!is_excl
&& !is_pair
&& !is_lasr
) ||
1931 (!is_excl
&& is_pair
) ||
1932 (is_pair
&& size
< 2)) {
1933 unallocated_encoding(s
);
1938 gen_check_sp_alignment(s
);
1940 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1942 /* Note that since TCG is single threaded load-acquire/store-release
1943 * semantics require no extra if (is_lasr) { ... } handling.
1949 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1951 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
1955 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
1957 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1960 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1961 bool iss_sf
= disas_ldst_compute_iss_sf(size
, false, 0);
1963 /* Generate ISS for non-exclusive accesses including LASR. */
1966 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
1968 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
1969 true, rt
, iss_sf
, is_lasr
);
1971 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, false, false,
1972 true, rt
, iss_sf
, is_lasr
);
1974 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
1981 * C3.3.5 Load register (literal)
1983 * 31 30 29 27 26 25 24 23 5 4 0
1984 * +-----+-------+---+-----+-------------------+-------+
1985 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
1986 * +-----+-------+---+-----+-------------------+-------+
1988 * V: 1 -> vector (simd/fp)
1989 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
1990 * 10-> 32 bit signed, 11 -> prefetch
1991 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
1993 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
1995 int rt
= extract32(insn
, 0, 5);
1996 int64_t imm
= sextract32(insn
, 5, 19) << 2;
1997 bool is_vector
= extract32(insn
, 26, 1);
1998 int opc
= extract32(insn
, 30, 2);
1999 bool is_signed
= false;
2001 TCGv_i64 tcg_rt
, tcg_addr
;
2005 unallocated_encoding(s
);
2009 if (!fp_access_check(s
)) {
2014 /* PRFM (literal) : prefetch */
2017 size
= 2 + extract32(opc
, 0, 1);
2018 is_signed
= extract32(opc
, 1, 1);
2021 tcg_rt
= cpu_reg(s
, rt
);
2023 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
2025 do_fp_ld(s
, rt
, tcg_addr
, size
);
2027 /* Only unsigned 32bit loads target 32bit registers. */
2028 bool iss_sf
= opc
!= 0;
2030 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false,
2031 true, rt
, iss_sf
, false);
2033 tcg_temp_free_i64(tcg_addr
);
2037 * C5.6.80 LDNP (Load Pair - non-temporal hint)
2038 * C5.6.81 LDP (Load Pair - non vector)
2039 * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
2040 * C5.6.176 STNP (Store Pair - non-temporal hint)
2041 * C5.6.177 STP (Store Pair - non vector)
2042 * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
2043 * C6.3.165 LDP (Load Pair of SIMD&FP)
2044 * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
2045 * C6.3.284 STP (Store Pair of SIMD&FP)
2047 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
2048 * +-----+-------+---+---+-------+---+-----------------------------+
2049 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
2050 * +-----+-------+---+---+-------+---+-------+-------+------+------+
2052 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
2054 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
2055 * V: 0 -> GPR, 1 -> Vector
2056 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
2057 * 10 -> signed offset, 11 -> pre-index
2058 * L: 0 -> Store 1 -> Load
2060 * Rt, Rt2 = GPR or SIMD registers to be stored
2061 * Rn = general purpose register containing address
2062 * imm7 = signed offset (multiple of 4 or 8 depending on size)
2064 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
2066 int rt
= extract32(insn
, 0, 5);
2067 int rn
= extract32(insn
, 5, 5);
2068 int rt2
= extract32(insn
, 10, 5);
2069 uint64_t offset
= sextract64(insn
, 15, 7);
2070 int index
= extract32(insn
, 23, 2);
2071 bool is_vector
= extract32(insn
, 26, 1);
2072 bool is_load
= extract32(insn
, 22, 1);
2073 int opc
= extract32(insn
, 30, 2);
2075 bool is_signed
= false;
2076 bool postindex
= false;
2079 TCGv_i64 tcg_addr
; /* calculated address */
2083 unallocated_encoding(s
);
2090 size
= 2 + extract32(opc
, 1, 1);
2091 is_signed
= extract32(opc
, 0, 1);
2092 if (!is_load
&& is_signed
) {
2093 unallocated_encoding(s
);
2099 case 1: /* post-index */
2104 /* signed offset with "non-temporal" hint. Since we don't emulate
2105 * caches we don't care about hints to the cache system about
2106 * data access patterns, and handle this identically to plain
2110 /* There is no non-temporal-hint version of LDPSW */
2111 unallocated_encoding(s
);
2116 case 2: /* signed offset, rn not updated */
2119 case 3: /* pre-index */
2125 if (is_vector
&& !fp_access_check(s
)) {
2132 gen_check_sp_alignment(s
);
2135 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2138 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2143 do_fp_ld(s
, rt
, tcg_addr
, size
);
2145 do_fp_st(s
, rt
, tcg_addr
, size
);
2148 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2150 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false,
2151 false, 0, false, false);
2153 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2154 false, 0, false, false);
2157 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2160 do_fp_ld(s
, rt2
, tcg_addr
, size
);
2162 do_fp_st(s
, rt2
, tcg_addr
, size
);
2165 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2167 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false,
2168 false, 0, false, false);
2170 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
,
2171 false, 0, false, false);
2177 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
2179 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2181 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
2186 * C3.3.8 Load/store (immediate post-indexed)
2187 * C3.3.9 Load/store (immediate pre-indexed)
2188 * C3.3.12 Load/store (unscaled immediate)
2190 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2191 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2192 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2193 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2195 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2197 * V = 0 -> non-vector
2198 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2199 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2201 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
,
2207 int rn
= extract32(insn
, 5, 5);
2208 int imm9
= sextract32(insn
, 12, 9);
2209 int idx
= extract32(insn
, 10, 2);
2210 bool is_signed
= false;
2211 bool is_store
= false;
2212 bool is_extended
= false;
2213 bool is_unpriv
= (idx
== 2);
2214 bool iss_valid
= !is_vector
;
2221 size
|= (opc
& 2) << 1;
2222 if (size
> 4 || is_unpriv
) {
2223 unallocated_encoding(s
);
2226 is_store
= ((opc
& 1) == 0);
2227 if (!fp_access_check(s
)) {
2231 if (size
== 3 && opc
== 2) {
2232 /* PRFM - prefetch */
2234 unallocated_encoding(s
);
2239 if (opc
== 3 && size
> 1) {
2240 unallocated_encoding(s
);
2243 is_store
= (opc
== 0);
2244 is_signed
= extract32(opc
, 1, 1);
2245 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2265 gen_check_sp_alignment(s
);
2267 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2270 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2275 do_fp_st(s
, rt
, tcg_addr
, size
);
2277 do_fp_ld(s
, rt
, tcg_addr
, size
);
2280 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2281 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2282 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2285 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
,
2286 iss_valid
, rt
, iss_sf
, false);
2288 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
2289 is_signed
, is_extended
, memidx
,
2290 iss_valid
, rt
, iss_sf
, false);
2295 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2297 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2299 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2304 * C3.3.10 Load/store (register offset)
2306 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2307 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2308 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2309 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2312 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2313 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2315 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2316 * opc<0>: 0 -> store, 1 -> load
2317 * V: 1 -> vector/simd
2318 * opt: extend encoding (see DecodeRegExtend)
2319 * S: if S=1 then scale (essentially index by sizeof(size))
2320 * Rt: register to transfer into/out of
2321 * Rn: address register or SP for base
2322 * Rm: offset register or ZR for offset
2324 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
,
2330 int rn
= extract32(insn
, 5, 5);
2331 int shift
= extract32(insn
, 12, 1);
2332 int rm
= extract32(insn
, 16, 5);
2333 int opt
= extract32(insn
, 13, 3);
2334 bool is_signed
= false;
2335 bool is_store
= false;
2336 bool is_extended
= false;
2341 if (extract32(opt
, 1, 1) == 0) {
2342 unallocated_encoding(s
);
2347 size
|= (opc
& 2) << 1;
2349 unallocated_encoding(s
);
2352 is_store
= !extract32(opc
, 0, 1);
2353 if (!fp_access_check(s
)) {
2357 if (size
== 3 && opc
== 2) {
2358 /* PRFM - prefetch */
2361 if (opc
== 3 && size
> 1) {
2362 unallocated_encoding(s
);
2365 is_store
= (opc
== 0);
2366 is_signed
= extract32(opc
, 1, 1);
2367 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2371 gen_check_sp_alignment(s
);
2373 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2375 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2376 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2378 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2382 do_fp_st(s
, rt
, tcg_addr
, size
);
2384 do_fp_ld(s
, rt
, tcg_addr
, size
);
2387 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2388 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2390 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2391 true, rt
, iss_sf
, false);
2393 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
,
2394 is_signed
, is_extended
,
2395 true, rt
, iss_sf
, false);
2401 * C3.3.13 Load/store (unsigned immediate)
2403 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2404 * +----+-------+---+-----+-----+------------+-------+------+
2405 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2406 * +----+-------+---+-----+-----+------------+-------+------+
2409 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2410 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2412 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2413 * opc<0>: 0 -> store, 1 -> load
2414 * Rn: base address register (inc SP)
2415 * Rt: target register
2417 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
,
2423 int rn
= extract32(insn
, 5, 5);
2424 unsigned int imm12
= extract32(insn
, 10, 12);
2425 unsigned int offset
;
2430 bool is_signed
= false;
2431 bool is_extended
= false;
2434 size
|= (opc
& 2) << 1;
2436 unallocated_encoding(s
);
2439 is_store
= !extract32(opc
, 0, 1);
2440 if (!fp_access_check(s
)) {
2444 if (size
== 3 && opc
== 2) {
2445 /* PRFM - prefetch */
2448 if (opc
== 3 && size
> 1) {
2449 unallocated_encoding(s
);
2452 is_store
= (opc
== 0);
2453 is_signed
= extract32(opc
, 1, 1);
2454 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2458 gen_check_sp_alignment(s
);
2460 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2461 offset
= imm12
<< size
;
2462 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2466 do_fp_st(s
, rt
, tcg_addr
, size
);
2468 do_fp_ld(s
, rt
, tcg_addr
, size
);
2471 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2472 bool iss_sf
= disas_ldst_compute_iss_sf(size
, is_signed
, opc
);
2474 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
,
2475 true, rt
, iss_sf
, false);
2477 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
,
2478 true, rt
, iss_sf
, false);
2483 /* Load/store register (all forms) */
2484 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2486 int rt
= extract32(insn
, 0, 5);
2487 int opc
= extract32(insn
, 22, 2);
2488 bool is_vector
= extract32(insn
, 26, 1);
2489 int size
= extract32(insn
, 30, 2);
2491 switch (extract32(insn
, 24, 2)) {
2493 if (extract32(insn
, 21, 1) == 1 && extract32(insn
, 10, 2) == 2) {
2494 disas_ldst_reg_roffset(s
, insn
, opc
, size
, rt
, is_vector
);
2496 /* Load/store register (unscaled immediate)
2497 * Load/store immediate pre/post-indexed
2498 * Load/store register unprivileged
2500 disas_ldst_reg_imm9(s
, insn
, opc
, size
, rt
, is_vector
);
2504 disas_ldst_reg_unsigned_imm(s
, insn
, opc
, size
, rt
, is_vector
);
2507 unallocated_encoding(s
);
2512 /* C3.3.1 AdvSIMD load/store multiple structures
2514 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2515 * +---+---+---------------+---+-------------+--------+------+------+------+
2516 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2517 * +---+---+---------------+---+-------------+--------+------+------+------+
2519 * C3.3.2 AdvSIMD load/store multiple structures (post-indexed)
2521 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2522 * +---+---+---------------+---+---+---------+--------+------+------+------+
2523 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2524 * +---+---+---------------+---+---+---------+--------+------+------+------+
2526 * Rt: first (or only) SIMD&FP register to be transferred
2527 * Rn: base address or SP
2528 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2530 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
2532 int rt
= extract32(insn
, 0, 5);
2533 int rn
= extract32(insn
, 5, 5);
2534 int size
= extract32(insn
, 10, 2);
2535 int opcode
= extract32(insn
, 12, 4);
2536 bool is_store
= !extract32(insn
, 22, 1);
2537 bool is_postidx
= extract32(insn
, 23, 1);
2538 bool is_q
= extract32(insn
, 30, 1);
2539 TCGv_i64 tcg_addr
, tcg_rn
;
2541 int ebytes
= 1 << size
;
2542 int elements
= (is_q
? 128 : 64) / (8 << size
);
2543 int rpt
; /* num iterations */
2544 int selem
; /* structure elements */
2547 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
2548 unallocated_encoding(s
);
2552 /* From the shared decode logic */
2583 unallocated_encoding(s
);
2587 if (size
== 3 && !is_q
&& selem
!= 1) {
2589 unallocated_encoding(s
);
2593 if (!fp_access_check(s
)) {
2598 gen_check_sp_alignment(s
);
2601 tcg_rn
= cpu_reg_sp(s
, rn
);
2602 tcg_addr
= tcg_temp_new_i64();
2603 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2605 for (r
= 0; r
< rpt
; r
++) {
2607 for (e
= 0; e
< elements
; e
++) {
2608 int tt
= (rt
+ r
) % 32;
2610 for (xs
= 0; xs
< selem
; xs
++) {
2612 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
2614 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
2616 /* For non-quad operations, setting a slice of the low
2617 * 64 bits of the register clears the high 64 bits (in
2618 * the ARM ARM pseudocode this is implicit in the fact
2619 * that 'rval' is a 64 bit wide variable). We optimize
2620 * by noticing that we only need to do this the first
2621 * time we touch a register.
2623 if (!is_q
&& e
== 0 && (r
== 0 || xs
== selem
- 1)) {
2624 clear_vec_high(s
, tt
);
2627 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2634 int rm
= extract32(insn
, 16, 5);
2636 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2638 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2641 tcg_temp_free_i64(tcg_addr
);
2644 /* C3.3.3 AdvSIMD load/store single structure
2646 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2647 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2648 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
2649 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2651 * C3.3.4 AdvSIMD load/store single structure (post-indexed)
2653 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2654 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2655 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
2656 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2658 * Rt: first (or only) SIMD&FP register to be transferred
2659 * Rn: base address or SP
2660 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2661 * index = encoded in Q:S:size dependent on size
2663 * lane_size = encoded in R, opc
2664 * transfer width = encoded in opc, S, size
2666 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
2668 int rt
= extract32(insn
, 0, 5);
2669 int rn
= extract32(insn
, 5, 5);
2670 int size
= extract32(insn
, 10, 2);
2671 int S
= extract32(insn
, 12, 1);
2672 int opc
= extract32(insn
, 13, 3);
2673 int R
= extract32(insn
, 21, 1);
2674 int is_load
= extract32(insn
, 22, 1);
2675 int is_postidx
= extract32(insn
, 23, 1);
2676 int is_q
= extract32(insn
, 30, 1);
2678 int scale
= extract32(opc
, 1, 2);
2679 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
2680 bool replicate
= false;
2681 int index
= is_q
<< 3 | S
<< 2 | size
;
2683 TCGv_i64 tcg_addr
, tcg_rn
;
2687 if (!is_load
|| S
) {
2688 unallocated_encoding(s
);
2697 if (extract32(size
, 0, 1)) {
2698 unallocated_encoding(s
);
2704 if (extract32(size
, 1, 1)) {
2705 unallocated_encoding(s
);
2708 if (!extract32(size
, 0, 1)) {
2712 unallocated_encoding(s
);
2720 g_assert_not_reached();
2723 if (!fp_access_check(s
)) {
2727 ebytes
= 1 << scale
;
2730 gen_check_sp_alignment(s
);
2733 tcg_rn
= cpu_reg_sp(s
, rn
);
2734 tcg_addr
= tcg_temp_new_i64();
2735 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2737 for (xs
= 0; xs
< selem
; xs
++) {
2739 /* Load and replicate to all elements */
2741 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
2743 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
2744 get_mem_index(s
), s
->be_data
+ scale
);
2747 mulconst
= 0x0101010101010101ULL
;
2750 mulconst
= 0x0001000100010001ULL
;
2753 mulconst
= 0x0000000100000001ULL
;
2759 g_assert_not_reached();
2762 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
2764 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
2766 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
2768 clear_vec_high(s
, rt
);
2770 tcg_temp_free_i64(tcg_tmp
);
2772 /* Load/store one element per register */
2774 do_vec_ld(s
, rt
, index
, tcg_addr
, s
->be_data
+ scale
);
2776 do_vec_st(s
, rt
, index
, tcg_addr
, s
->be_data
+ scale
);
2779 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2784 int rm
= extract32(insn
, 16, 5);
2786 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2788 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2791 tcg_temp_free_i64(tcg_addr
);
2794 /* C3.3 Loads and stores */
2795 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
2797 switch (extract32(insn
, 24, 6)) {
2798 case 0x08: /* Load/store exclusive */
2799 disas_ldst_excl(s
, insn
);
2801 case 0x18: case 0x1c: /* Load register (literal) */
2802 disas_ld_lit(s
, insn
);
2804 case 0x28: case 0x29:
2805 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
2806 disas_ldst_pair(s
, insn
);
2808 case 0x38: case 0x39:
2809 case 0x3c: case 0x3d: /* Load/store register (all forms) */
2810 disas_ldst_reg(s
, insn
);
2812 case 0x0c: /* AdvSIMD load/store multiple structures */
2813 disas_ldst_multiple_struct(s
, insn
);
2815 case 0x0d: /* AdvSIMD load/store single structure */
2816 disas_ldst_single_struct(s
, insn
);
2819 unallocated_encoding(s
);
2824 /* C3.4.6 PC-rel. addressing
2825 * 31 30 29 28 24 23 5 4 0
2826 * +----+-------+-----------+-------------------+------+
2827 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
2828 * +----+-------+-----------+-------------------+------+
2830 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
2832 unsigned int page
, rd
;
2836 page
= extract32(insn
, 31, 1);
2837 /* SignExtend(immhi:immlo) -> offset */
2838 offset
= sextract64(insn
, 5, 19);
2839 offset
= offset
<< 2 | extract32(insn
, 29, 2);
2840 rd
= extract32(insn
, 0, 5);
2844 /* ADRP (page based) */
2849 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
2853 * C3.4.1 Add/subtract (immediate)
2855 * 31 30 29 28 24 23 22 21 10 9 5 4 0
2856 * +--+--+--+-----------+-----+-------------+-----+-----+
2857 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
2858 * +--+--+--+-----------+-----+-------------+-----+-----+
2860 * sf: 0 -> 32bit, 1 -> 64bit
2861 * op: 0 -> add , 1 -> sub
2863 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
2865 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
2867 int rd
= extract32(insn
, 0, 5);
2868 int rn
= extract32(insn
, 5, 5);
2869 uint64_t imm
= extract32(insn
, 10, 12);
2870 int shift
= extract32(insn
, 22, 2);
2871 bool setflags
= extract32(insn
, 29, 1);
2872 bool sub_op
= extract32(insn
, 30, 1);
2873 bool is_64bit
= extract32(insn
, 31, 1);
2875 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2876 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
2877 TCGv_i64 tcg_result
;
2886 unallocated_encoding(s
);
2890 tcg_result
= tcg_temp_new_i64();
2893 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
2895 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
2898 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
2900 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2902 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2904 tcg_temp_free_i64(tcg_imm
);
2908 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
2910 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
2913 tcg_temp_free_i64(tcg_result
);
2916 /* The input should be a value in the bottom e bits (with higher
2917 * bits zero); returns that value replicated into every element
2918 * of size e in a 64 bit integer.
2920 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
2930 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
2931 static inline uint64_t bitmask64(unsigned int length
)
2933 assert(length
> 0 && length
<= 64);
2934 return ~0ULL >> (64 - length
);
2937 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
2938 * only require the wmask. Returns false if the imms/immr/immn are a reserved
2939 * value (ie should cause a guest UNDEF exception), and true if they are
2940 * valid, in which case the decoded bit pattern is written to result.
2942 static bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
2943 unsigned int imms
, unsigned int immr
)
2946 unsigned e
, levels
, s
, r
;
2949 assert(immn
< 2 && imms
< 64 && immr
< 64);
2951 /* The bit patterns we create here are 64 bit patterns which
2952 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
2953 * 64 bits each. Each element contains the same value: a run
2954 * of between 1 and e-1 non-zero bits, rotated within the
2955 * element by between 0 and e-1 bits.
2957 * The element size and run length are encoded into immn (1 bit)
2958 * and imms (6 bits) as follows:
2959 * 64 bit elements: immn = 1, imms = <length of run - 1>
2960 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
2961 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
2962 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
2963 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
2964 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
2965 * Notice that immn = 0, imms = 11111x is the only combination
2966 * not covered by one of the above options; this is reserved.
2967 * Further, <length of run - 1> all-ones is a reserved pattern.
2969 * In all cases the rotation is by immr % e (and immr is 6 bits).
2972 /* First determine the element size */
2973 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
2975 /* This is the immn == 0, imms == 0x11111x case */
2985 /* <length of run - 1> mustn't be all-ones. */
2989 /* Create the value of one element: s+1 set bits rotated
2990 * by r within the element (which is e bits wide)...
2992 mask
= bitmask64(s
+ 1);
2994 mask
= (mask
>> r
) | (mask
<< (e
- r
));
2995 mask
&= bitmask64(e
);
2997 /* ...then replicate the element over the whole 64 bit value */
2998 mask
= bitfield_replicate(mask
, e
);
3003 /* C3.4.4 Logical (immediate)
3004 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3005 * +----+-----+-------------+---+------+------+------+------+
3006 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
3007 * +----+-----+-------------+---+------+------+------+------+
3009 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
3011 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
3012 TCGv_i64 tcg_rd
, tcg_rn
;
3014 bool is_and
= false;
3016 sf
= extract32(insn
, 31, 1);
3017 opc
= extract32(insn
, 29, 2);
3018 is_n
= extract32(insn
, 22, 1);
3019 immr
= extract32(insn
, 16, 6);
3020 imms
= extract32(insn
, 10, 6);
3021 rn
= extract32(insn
, 5, 5);
3022 rd
= extract32(insn
, 0, 5);
3025 unallocated_encoding(s
);
3029 if (opc
== 0x3) { /* ANDS */
3030 tcg_rd
= cpu_reg(s
, rd
);
3032 tcg_rd
= cpu_reg_sp(s
, rd
);
3034 tcg_rn
= cpu_reg(s
, rn
);
3036 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
3037 /* some immediate field values are reserved */
3038 unallocated_encoding(s
);
3043 wmask
&= 0xffffffff;
3047 case 0x3: /* ANDS */
3049 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
3053 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
3056 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
3059 assert(FALSE
); /* must handle all above */
3063 if (!sf
&& !is_and
) {
3064 /* zero extend final result; we know we can skip this for AND
3065 * since the immediate had the high 32 bits clear.
3067 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3070 if (opc
== 3) { /* ANDS */
3071 gen_logic_CC(sf
, tcg_rd
);
3076 * C3.4.5 Move wide (immediate)
3078 * 31 30 29 28 23 22 21 20 5 4 0
3079 * +--+-----+-------------+-----+----------------+------+
3080 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
3081 * +--+-----+-------------+-----+----------------+------+
3083 * sf: 0 -> 32 bit, 1 -> 64 bit
3084 * opc: 00 -> N, 10 -> Z, 11 -> K
3085 * hw: shift/16 (0,16, and sf only 32, 48)
3087 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
3089 int rd
= extract32(insn
, 0, 5);
3090 uint64_t imm
= extract32(insn
, 5, 16);
3091 int sf
= extract32(insn
, 31, 1);
3092 int opc
= extract32(insn
, 29, 2);
3093 int pos
= extract32(insn
, 21, 2) << 4;
3094 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3097 if (!sf
&& (pos
>= 32)) {
3098 unallocated_encoding(s
);
3112 tcg_gen_movi_i64(tcg_rd
, imm
);
3115 tcg_imm
= tcg_const_i64(imm
);
3116 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
3117 tcg_temp_free_i64(tcg_imm
);
3119 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3123 unallocated_encoding(s
);
3129 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
3130 * +----+-----+-------------+---+------+------+------+------+
3131 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
3132 * +----+-----+-------------+---+------+------+------+------+
3134 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
3136 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
3137 TCGv_i64 tcg_rd
, tcg_tmp
;
3139 sf
= extract32(insn
, 31, 1);
3140 opc
= extract32(insn
, 29, 2);
3141 n
= extract32(insn
, 22, 1);
3142 ri
= extract32(insn
, 16, 6);
3143 si
= extract32(insn
, 10, 6);
3144 rn
= extract32(insn
, 5, 5);
3145 rd
= extract32(insn
, 0, 5);
3146 bitsize
= sf
? 64 : 32;
3148 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
3149 unallocated_encoding(s
);
3153 tcg_rd
= cpu_reg(s
, rd
);
3155 /* Suppress the zero-extend for !sf. Since RI and SI are constrained
3156 to be smaller than bitsize, we'll never reference data outside the
3157 low 32-bits anyway. */
3158 tcg_tmp
= read_cpu_reg(s
, rn
, 1);
3160 /* Recognize the common aliases. */
3161 if (opc
== 0) { /* SBFM */
3163 if (si
== 7) { /* SXTB */
3164 tcg_gen_ext8s_i64(tcg_rd
, tcg_tmp
);
3166 } else if (si
== 15) { /* SXTH */
3167 tcg_gen_ext16s_i64(tcg_rd
, tcg_tmp
);
3169 } else if (si
== 31) { /* SXTW */
3170 tcg_gen_ext32s_i64(tcg_rd
, tcg_tmp
);
3174 if (si
== 63 || (si
== 31 && ri
<= si
)) { /* ASR */
3176 tcg_gen_ext32s_i64(tcg_tmp
, tcg_tmp
);
3178 tcg_gen_sari_i64(tcg_rd
, tcg_tmp
, ri
);
3181 } else if (opc
== 2) { /* UBFM */
3182 if (ri
== 0) { /* UXTB, UXTH, plus non-canonical AND */
3183 tcg_gen_andi_i64(tcg_rd
, tcg_tmp
, bitmask64(si
+ 1));
3186 if (si
== 63 || (si
== 31 && ri
<= si
)) { /* LSR */
3188 tcg_gen_ext32u_i64(tcg_tmp
, tcg_tmp
);
3190 tcg_gen_shri_i64(tcg_rd
, tcg_tmp
, ri
);
3193 if (si
+ 1 == ri
&& si
!= bitsize
- 1) { /* LSL */
3194 int shift
= bitsize
- 1 - si
;
3195 tcg_gen_shli_i64(tcg_rd
, tcg_tmp
, shift
);
3200 if (opc
!= 1) { /* SBFM or UBFM */
3201 tcg_gen_movi_i64(tcg_rd
, 0);
3204 /* do the bit move operation */
3206 /* Wd<s-r:0> = Wn<s:r> */
3207 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
3209 len
= (si
- ri
) + 1;
3211 /* Wd<32+s-r,32-r> = Wn<s:0> */
3216 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
3218 if (opc
== 0) { /* SBFM - sign extend the destination field */
3219 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
3220 tcg_gen_sari_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
3224 if (!sf
) { /* zero extend final result */
3225 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3230 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3231 * +----+------+-------------+---+----+------+--------+------+------+
3232 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3233 * +----+------+-------------+---+----+------+--------+------+------+
3235 static void disas_extract(DisasContext
*s
, uint32_t insn
)
3237 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
3239 sf
= extract32(insn
, 31, 1);
3240 n
= extract32(insn
, 22, 1);
3241 rm
= extract32(insn
, 16, 5);
3242 imm
= extract32(insn
, 10, 6);
3243 rn
= extract32(insn
, 5, 5);
3244 rd
= extract32(insn
, 0, 5);
3245 op21
= extract32(insn
, 29, 2);
3246 op0
= extract32(insn
, 21, 1);
3247 bitsize
= sf
? 64 : 32;
3249 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
3250 unallocated_encoding(s
);
3252 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
3254 tcg_rd
= cpu_reg(s
, rd
);
3256 if (unlikely(imm
== 0)) {
3257 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3258 * so an extract from bit 0 is a special case.
3261 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
3263 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
3265 } else if (rm
== rn
) { /* ROR */
3266 tcg_rm
= cpu_reg(s
, rm
);
3268 tcg_gen_rotri_i64(tcg_rd
, tcg_rm
, imm
);
3270 TCGv_i32 tmp
= tcg_temp_new_i32();
3271 tcg_gen_extrl_i64_i32(tmp
, tcg_rm
);
3272 tcg_gen_rotri_i32(tmp
, tmp
, imm
);
3273 tcg_gen_extu_i32_i64(tcg_rd
, tmp
);
3274 tcg_temp_free_i32(tmp
);
3277 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3278 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3279 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
3280 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
3281 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
3283 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3289 /* C3.4 Data processing - immediate */
3290 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
3292 switch (extract32(insn
, 23, 6)) {
3293 case 0x20: case 0x21: /* PC-rel. addressing */
3294 disas_pc_rel_adr(s
, insn
);
3296 case 0x22: case 0x23: /* Add/subtract (immediate) */
3297 disas_add_sub_imm(s
, insn
);
3299 case 0x24: /* Logical (immediate) */
3300 disas_logic_imm(s
, insn
);
3302 case 0x25: /* Move wide (immediate) */
3303 disas_movw_imm(s
, insn
);
3305 case 0x26: /* Bitfield */
3306 disas_bitfield(s
, insn
);
3308 case 0x27: /* Extract */
3309 disas_extract(s
, insn
);
3312 unallocated_encoding(s
);
3317 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3318 * Note that it is the caller's responsibility to ensure that the
3319 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3320 * mandated semantics for out of range shifts.
3322 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3323 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
3325 switch (shift_type
) {
3326 case A64_SHIFT_TYPE_LSL
:
3327 tcg_gen_shl_i64(dst
, src
, shift_amount
);
3329 case A64_SHIFT_TYPE_LSR
:
3330 tcg_gen_shr_i64(dst
, src
, shift_amount
);
3332 case A64_SHIFT_TYPE_ASR
:
3334 tcg_gen_ext32s_i64(dst
, src
);
3336 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
3338 case A64_SHIFT_TYPE_ROR
:
3340 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
3343 t0
= tcg_temp_new_i32();
3344 t1
= tcg_temp_new_i32();
3345 tcg_gen_extrl_i64_i32(t0
, src
);
3346 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
3347 tcg_gen_rotr_i32(t0
, t0
, t1
);
3348 tcg_gen_extu_i32_i64(dst
, t0
);
3349 tcg_temp_free_i32(t0
);
3350 tcg_temp_free_i32(t1
);
3354 assert(FALSE
); /* all shift types should be handled */
3358 if (!sf
) { /* zero extend final result */
3359 tcg_gen_ext32u_i64(dst
, dst
);
3363 /* Shift a TCGv src by immediate, put result in dst.
3364 * The shift amount must be in range (this should always be true as the
3365 * relevant instructions will UNDEF on bad shift immediates).
3367 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3368 enum a64_shift_type shift_type
, unsigned int shift_i
)
3370 assert(shift_i
< (sf
? 64 : 32));
3373 tcg_gen_mov_i64(dst
, src
);
3375 TCGv_i64 shift_const
;
3377 shift_const
= tcg_const_i64(shift_i
);
3378 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
3379 tcg_temp_free_i64(shift_const
);
3383 /* C3.5.10 Logical (shifted register)
3384 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3385 * +----+-----+-----------+-------+---+------+--------+------+------+
3386 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3387 * +----+-----+-----------+-------+---+------+--------+------+------+
3389 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
3391 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
3392 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
3394 sf
= extract32(insn
, 31, 1);
3395 opc
= extract32(insn
, 29, 2);
3396 shift_type
= extract32(insn
, 22, 2);
3397 invert
= extract32(insn
, 21, 1);
3398 rm
= extract32(insn
, 16, 5);
3399 shift_amount
= extract32(insn
, 10, 6);
3400 rn
= extract32(insn
, 5, 5);
3401 rd
= extract32(insn
, 0, 5);
3403 if (!sf
&& (shift_amount
& (1 << 5))) {
3404 unallocated_encoding(s
);
3408 tcg_rd
= cpu_reg(s
, rd
);
3410 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3411 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3412 * register-register MOV and MVN, so it is worth special casing.
3414 tcg_rm
= cpu_reg(s
, rm
);
3416 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3418 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3422 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3424 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3430 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3433 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3436 tcg_rn
= cpu_reg(s
, rn
);
3438 switch (opc
| (invert
<< 2)) {
3441 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3444 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3447 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3451 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3454 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3457 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3465 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3469 gen_logic_CC(sf
, tcg_rd
);
3474 * C3.5.1 Add/subtract (extended register)
3476 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3477 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3478 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3479 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3481 * sf: 0 -> 32bit, 1 -> 64bit
3482 * op: 0 -> add , 1 -> sub
3485 * option: extension type (see DecodeRegExtend)
3486 * imm3: optional shift to Rm
3488 * Rd = Rn + LSL(extend(Rm), amount)
3490 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3492 int rd
= extract32(insn
, 0, 5);
3493 int rn
= extract32(insn
, 5, 5);
3494 int imm3
= extract32(insn
, 10, 3);
3495 int option
= extract32(insn
, 13, 3);
3496 int rm
= extract32(insn
, 16, 5);
3497 bool setflags
= extract32(insn
, 29, 1);
3498 bool sub_op
= extract32(insn
, 30, 1);
3499 bool sf
= extract32(insn
, 31, 1);
3501 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3503 TCGv_i64 tcg_result
;
3506 unallocated_encoding(s
);
3510 /* non-flag setting ops may use SP */
3512 tcg_rd
= cpu_reg_sp(s
, rd
);
3514 tcg_rd
= cpu_reg(s
, rd
);
3516 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3518 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3519 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3521 tcg_result
= tcg_temp_new_i64();
3525 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3527 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3531 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3533 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3538 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3540 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3543 tcg_temp_free_i64(tcg_result
);
3547 * C3.5.2 Add/subtract (shifted register)
3549 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3550 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3551 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3552 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3554 * sf: 0 -> 32bit, 1 -> 64bit
3555 * op: 0 -> add , 1 -> sub
3557 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3558 * imm6: Shift amount to apply to Rm before the add/sub
3560 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
3562 int rd
= extract32(insn
, 0, 5);
3563 int rn
= extract32(insn
, 5, 5);
3564 int imm6
= extract32(insn
, 10, 6);
3565 int rm
= extract32(insn
, 16, 5);
3566 int shift_type
= extract32(insn
, 22, 2);
3567 bool setflags
= extract32(insn
, 29, 1);
3568 bool sub_op
= extract32(insn
, 30, 1);
3569 bool sf
= extract32(insn
, 31, 1);
3571 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3572 TCGv_i64 tcg_rn
, tcg_rm
;
3573 TCGv_i64 tcg_result
;
3575 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
3576 unallocated_encoding(s
);
3580 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3581 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3583 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
3585 tcg_result
= tcg_temp_new_i64();
3589 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3591 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3595 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3597 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3602 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3604 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3607 tcg_temp_free_i64(tcg_result
);
3610 /* C3.5.9 Data-processing (3 source)
3612 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3613 +--+------+-----------+------+------+----+------+------+------+
3614 |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3615 +--+------+-----------+------+------+----+------+------+------+
3618 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
3620 int rd
= extract32(insn
, 0, 5);
3621 int rn
= extract32(insn
, 5, 5);
3622 int ra
= extract32(insn
, 10, 5);
3623 int rm
= extract32(insn
, 16, 5);
3624 int op_id
= (extract32(insn
, 29, 3) << 4) |
3625 (extract32(insn
, 21, 3) << 1) |
3626 extract32(insn
, 15, 1);
3627 bool sf
= extract32(insn
, 31, 1);
3628 bool is_sub
= extract32(op_id
, 0, 1);
3629 bool is_high
= extract32(op_id
, 2, 1);
3630 bool is_signed
= false;
3635 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
3637 case 0x42: /* SMADDL */
3638 case 0x43: /* SMSUBL */
3639 case 0x44: /* SMULH */
3642 case 0x0: /* MADD (32bit) */
3643 case 0x1: /* MSUB (32bit) */
3644 case 0x40: /* MADD (64bit) */
3645 case 0x41: /* MSUB (64bit) */
3646 case 0x4a: /* UMADDL */
3647 case 0x4b: /* UMSUBL */
3648 case 0x4c: /* UMULH */
3651 unallocated_encoding(s
);
3656 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
3657 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3658 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
3659 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
3662 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3664 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3667 tcg_temp_free_i64(low_bits
);
3671 tcg_op1
= tcg_temp_new_i64();
3672 tcg_op2
= tcg_temp_new_i64();
3673 tcg_tmp
= tcg_temp_new_i64();
3676 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
3677 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
3680 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
3681 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
3683 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
3684 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
3688 if (ra
== 31 && !is_sub
) {
3689 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
3690 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
3692 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
3694 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3696 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3701 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
3704 tcg_temp_free_i64(tcg_op1
);
3705 tcg_temp_free_i64(tcg_op2
);
3706 tcg_temp_free_i64(tcg_tmp
);
3709 /* C3.5.3 - Add/subtract (with carry)
3710 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
3711 * +--+--+--+------------------------+------+---------+------+-----+
3712 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
3713 * +--+--+--+------------------------+------+---------+------+-----+
3717 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
3719 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
3720 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
3722 if (extract32(insn
, 10, 6) != 0) {
3723 unallocated_encoding(s
);
3727 sf
= extract32(insn
, 31, 1);
3728 op
= extract32(insn
, 30, 1);
3729 setflags
= extract32(insn
, 29, 1);
3730 rm
= extract32(insn
, 16, 5);
3731 rn
= extract32(insn
, 5, 5);
3732 rd
= extract32(insn
, 0, 5);
3734 tcg_rd
= cpu_reg(s
, rd
);
3735 tcg_rn
= cpu_reg(s
, rn
);
3738 tcg_y
= new_tmp_a64(s
);
3739 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
3741 tcg_y
= cpu_reg(s
, rm
);
3745 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3747 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3751 /* C3.5.4 - C3.5.5 Conditional compare (immediate / register)
3752 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3753 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3754 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
3755 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3758 static void disas_cc(DisasContext
*s
, uint32_t insn
)
3760 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
3761 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
3762 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
3765 if (!extract32(insn
, 29, 1)) {
3766 unallocated_encoding(s
);
3769 if (insn
& (1 << 10 | 1 << 4)) {
3770 unallocated_encoding(s
);
3773 sf
= extract32(insn
, 31, 1);
3774 op
= extract32(insn
, 30, 1);
3775 is_imm
= extract32(insn
, 11, 1);
3776 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
3777 cond
= extract32(insn
, 12, 4);
3778 rn
= extract32(insn
, 5, 5);
3779 nzcv
= extract32(insn
, 0, 4);
3781 /* Set T0 = !COND. */
3782 tcg_t0
= tcg_temp_new_i32();
3783 arm_test_cc(&c
, cond
);
3784 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
3787 /* Load the arguments for the new comparison. */
3789 tcg_y
= new_tmp_a64(s
);
3790 tcg_gen_movi_i64(tcg_y
, y
);
3792 tcg_y
= cpu_reg(s
, y
);
3794 tcg_rn
= cpu_reg(s
, rn
);
3796 /* Set the flags for the new comparison. */
3797 tcg_tmp
= tcg_temp_new_i64();
3799 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3801 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3803 tcg_temp_free_i64(tcg_tmp
);
3805 /* If COND was false, force the flags to #nzcv. Compute two masks
3806 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
3807 * For tcg hosts that support ANDC, we can make do with just T1.
3808 * In either case, allow the tcg optimizer to delete any unused mask.
3810 tcg_t1
= tcg_temp_new_i32();
3811 tcg_t2
= tcg_temp_new_i32();
3812 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
3813 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
3815 if (nzcv
& 8) { /* N */
3816 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
3818 if (TCG_TARGET_HAS_andc_i32
) {
3819 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
3821 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
3824 if (nzcv
& 4) { /* Z */
3825 if (TCG_TARGET_HAS_andc_i32
) {
3826 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
3828 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
3831 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
3833 if (nzcv
& 2) { /* C */
3834 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
3836 if (TCG_TARGET_HAS_andc_i32
) {
3837 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
3839 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
3842 if (nzcv
& 1) { /* V */
3843 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
3845 if (TCG_TARGET_HAS_andc_i32
) {
3846 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
3848 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
3851 tcg_temp_free_i32(tcg_t0
);
3852 tcg_temp_free_i32(tcg_t1
);
3853 tcg_temp_free_i32(tcg_t2
);
3856 /* C3.5.6 Conditional select
3857 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
3858 * +----+----+---+-----------------+------+------+-----+------+------+
3859 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
3860 * +----+----+---+-----------------+------+------+-----+------+------+
3862 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
3864 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
3865 TCGv_i64 tcg_rd
, zero
;
3868 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
3869 /* S == 1 or op2<1> == 1 */
3870 unallocated_encoding(s
);
3873 sf
= extract32(insn
, 31, 1);
3874 else_inv
= extract32(insn
, 30, 1);
3875 rm
= extract32(insn
, 16, 5);
3876 cond
= extract32(insn
, 12, 4);
3877 else_inc
= extract32(insn
, 10, 1);
3878 rn
= extract32(insn
, 5, 5);
3879 rd
= extract32(insn
, 0, 5);
3881 tcg_rd
= cpu_reg(s
, rd
);
3883 a64_test_cc(&c
, cond
);
3884 zero
= tcg_const_i64(0);
3886 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
3888 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
3890 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
3893 TCGv_i64 t_true
= cpu_reg(s
, rn
);
3894 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
3895 if (else_inv
&& else_inc
) {
3896 tcg_gen_neg_i64(t_false
, t_false
);
3897 } else if (else_inv
) {
3898 tcg_gen_not_i64(t_false
, t_false
);
3899 } else if (else_inc
) {
3900 tcg_gen_addi_i64(t_false
, t_false
, 1);
3902 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
3905 tcg_temp_free_i64(zero
);
3909 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3913 static void handle_clz(DisasContext
*s
, unsigned int sf
,
3914 unsigned int rn
, unsigned int rd
)
3916 TCGv_i64 tcg_rd
, tcg_rn
;
3917 tcg_rd
= cpu_reg(s
, rd
);
3918 tcg_rn
= cpu_reg(s
, rn
);
3921 gen_helper_clz64(tcg_rd
, tcg_rn
);
3923 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3924 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3925 gen_helper_clz(tcg_tmp32
, tcg_tmp32
);
3926 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3927 tcg_temp_free_i32(tcg_tmp32
);
3931 static void handle_cls(DisasContext
*s
, unsigned int sf
,
3932 unsigned int rn
, unsigned int rd
)
3934 TCGv_i64 tcg_rd
, tcg_rn
;
3935 tcg_rd
= cpu_reg(s
, rd
);
3936 tcg_rn
= cpu_reg(s
, rn
);
3939 gen_helper_cls64(tcg_rd
, tcg_rn
);
3941 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3942 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3943 gen_helper_cls32(tcg_tmp32
, tcg_tmp32
);
3944 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3945 tcg_temp_free_i32(tcg_tmp32
);
3949 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
3950 unsigned int rn
, unsigned int rd
)
3952 TCGv_i64 tcg_rd
, tcg_rn
;
3953 tcg_rd
= cpu_reg(s
, rd
);
3954 tcg_rn
= cpu_reg(s
, rn
);
3957 gen_helper_rbit64(tcg_rd
, tcg_rn
);
3959 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3960 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3961 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
3962 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3963 tcg_temp_free_i32(tcg_tmp32
);
3967 /* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
3968 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
3969 unsigned int rn
, unsigned int rd
)
3972 unallocated_encoding(s
);
3975 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
3978 /* C5.6.149 REV with sf==0, opcode==2
3979 * C5.6.151 REV32 (sf==1, opcode==2)
3981 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
3982 unsigned int rn
, unsigned int rd
)
3984 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3987 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3988 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3990 /* bswap32_i64 requires zero high word */
3991 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
3992 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
3993 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3994 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
3995 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
3997 tcg_temp_free_i64(tcg_tmp
);
3999 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
4000 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
4004 /* C5.6.150 REV16 (opcode==1) */
4005 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
4006 unsigned int rn
, unsigned int rd
)
4008 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4009 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
4010 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4012 tcg_gen_andi_i64(tcg_tmp
, tcg_rn
, 0xffff);
4013 tcg_gen_bswap16_i64(tcg_rd
, tcg_tmp
);
4015 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 16);
4016 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
4017 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
4018 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 16, 16);
4021 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
4022 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
4023 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
4024 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 32, 16);
4026 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 48);
4027 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
4028 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 48, 16);
4031 tcg_temp_free_i64(tcg_tmp
);
4034 /* C3.5.7 Data-processing (1 source)
4035 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4036 * +----+---+---+-----------------+---------+--------+------+------+
4037 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
4038 * +----+---+---+-----------------+---------+--------+------+------+
4040 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
4042 unsigned int sf
, opcode
, rn
, rd
;
4044 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
4045 unallocated_encoding(s
);
4049 sf
= extract32(insn
, 31, 1);
4050 opcode
= extract32(insn
, 10, 6);
4051 rn
= extract32(insn
, 5, 5);
4052 rd
= extract32(insn
, 0, 5);
4056 handle_rbit(s
, sf
, rn
, rd
);
4059 handle_rev16(s
, sf
, rn
, rd
);
4062 handle_rev32(s
, sf
, rn
, rd
);
4065 handle_rev64(s
, sf
, rn
, rd
);
4068 handle_clz(s
, sf
, rn
, rd
);
4071 handle_cls(s
, sf
, rn
, rd
);
4076 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
4077 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4079 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
4080 tcg_rd
= cpu_reg(s
, rd
);
4082 if (!sf
&& is_signed
) {
4083 tcg_n
= new_tmp_a64(s
);
4084 tcg_m
= new_tmp_a64(s
);
4085 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
4086 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
4088 tcg_n
= read_cpu_reg(s
, rn
, sf
);
4089 tcg_m
= read_cpu_reg(s
, rm
, sf
);
4093 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
4095 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
4098 if (!sf
) { /* zero extend final result */
4099 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
4103 /* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
4104 static void handle_shift_reg(DisasContext
*s
,
4105 enum a64_shift_type shift_type
, unsigned int sf
,
4106 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4108 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
4109 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4110 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
4112 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
4113 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
4114 tcg_temp_free_i64(tcg_shift
);
4117 /* CRC32[BHWX], CRC32C[BHWX] */
4118 static void handle_crc32(DisasContext
*s
,
4119 unsigned int sf
, unsigned int sz
, bool crc32c
,
4120 unsigned int rm
, unsigned int rn
, unsigned int rd
)
4122 TCGv_i64 tcg_acc
, tcg_val
;
4125 if (!arm_dc_feature(s
, ARM_FEATURE_CRC
)
4126 || (sf
== 1 && sz
!= 3)
4127 || (sf
== 0 && sz
== 3)) {
4128 unallocated_encoding(s
);
4133 tcg_val
= cpu_reg(s
, rm
);
4147 g_assert_not_reached();
4149 tcg_val
= new_tmp_a64(s
);
4150 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
4153 tcg_acc
= cpu_reg(s
, rn
);
4154 tcg_bytes
= tcg_const_i32(1 << sz
);
4157 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4159 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
4162 tcg_temp_free_i32(tcg_bytes
);
4165 /* C3.5.8 Data-processing (2 source)
4166 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4167 * +----+---+---+-----------------+------+--------+------+------+
4168 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
4169 * +----+---+---+-----------------+------+--------+------+------+
4171 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
4173 unsigned int sf
, rm
, opcode
, rn
, rd
;
4174 sf
= extract32(insn
, 31, 1);
4175 rm
= extract32(insn
, 16, 5);
4176 opcode
= extract32(insn
, 10, 6);
4177 rn
= extract32(insn
, 5, 5);
4178 rd
= extract32(insn
, 0, 5);
4180 if (extract32(insn
, 29, 1)) {
4181 unallocated_encoding(s
);
4187 handle_div(s
, false, sf
, rm
, rn
, rd
);
4190 handle_div(s
, true, sf
, rm
, rn
, rd
);
4193 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
4196 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
4199 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
4202 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
4211 case 23: /* CRC32 */
4213 int sz
= extract32(opcode
, 0, 2);
4214 bool crc32c
= extract32(opcode
, 2, 1);
4215 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
4219 unallocated_encoding(s
);
4224 /* C3.5 Data processing - register */
4225 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
4227 switch (extract32(insn
, 24, 5)) {
4228 case 0x0a: /* Logical (shifted register) */
4229 disas_logic_reg(s
, insn
);
4231 case 0x0b: /* Add/subtract */
4232 if (insn
& (1 << 21)) { /* (extended register) */
4233 disas_add_sub_ext_reg(s
, insn
);
4235 disas_add_sub_reg(s
, insn
);
4238 case 0x1b: /* Data-processing (3 source) */
4239 disas_data_proc_3src(s
, insn
);
4242 switch (extract32(insn
, 21, 3)) {
4243 case 0x0: /* Add/subtract (with carry) */
4244 disas_adc_sbc(s
, insn
);
4246 case 0x2: /* Conditional compare */
4247 disas_cc(s
, insn
); /* both imm and reg forms */
4249 case 0x4: /* Conditional select */
4250 disas_cond_select(s
, insn
);
4252 case 0x6: /* Data-processing */
4253 if (insn
& (1 << 30)) { /* (1 source) */
4254 disas_data_proc_1src(s
, insn
);
4255 } else { /* (2 source) */
4256 disas_data_proc_2src(s
, insn
);
4260 unallocated_encoding(s
);
4265 unallocated_encoding(s
);
4270 static void handle_fp_compare(DisasContext
*s
, bool is_double
,
4271 unsigned int rn
, unsigned int rm
,
4272 bool cmp_with_zero
, bool signal_all_nans
)
4274 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
4275 TCGv_ptr fpst
= get_fpstatus_ptr();
4278 TCGv_i64 tcg_vn
, tcg_vm
;
4280 tcg_vn
= read_fp_dreg(s
, rn
);
4281 if (cmp_with_zero
) {
4282 tcg_vm
= tcg_const_i64(0);
4284 tcg_vm
= read_fp_dreg(s
, rm
);
4286 if (signal_all_nans
) {
4287 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4289 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4291 tcg_temp_free_i64(tcg_vn
);
4292 tcg_temp_free_i64(tcg_vm
);
4294 TCGv_i32 tcg_vn
, tcg_vm
;
4296 tcg_vn
= read_fp_sreg(s
, rn
);
4297 if (cmp_with_zero
) {
4298 tcg_vm
= tcg_const_i32(0);
4300 tcg_vm
= read_fp_sreg(s
, rm
);
4302 if (signal_all_nans
) {
4303 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4305 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4307 tcg_temp_free_i32(tcg_vn
);
4308 tcg_temp_free_i32(tcg_vm
);
4311 tcg_temp_free_ptr(fpst
);
4313 gen_set_nzcv(tcg_flags
);
4315 tcg_temp_free_i64(tcg_flags
);
4318 /* C3.6.22 Floating point compare
4319 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
4320 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4321 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
4322 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4324 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
4326 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
4328 mos
= extract32(insn
, 29, 3);
4329 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4330 rm
= extract32(insn
, 16, 5);
4331 op
= extract32(insn
, 14, 2);
4332 rn
= extract32(insn
, 5, 5);
4333 opc
= extract32(insn
, 3, 2);
4334 op2r
= extract32(insn
, 0, 3);
4336 if (mos
|| op
|| op2r
|| type
> 1) {
4337 unallocated_encoding(s
);
4341 if (!fp_access_check(s
)) {
4345 handle_fp_compare(s
, type
, rn
, rm
, opc
& 1, opc
& 2);
4348 /* C3.6.23 Floating point conditional compare
4349 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4350 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4351 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
4352 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4354 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
4356 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
4358 TCGLabel
*label_continue
= NULL
;
4360 mos
= extract32(insn
, 29, 3);
4361 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4362 rm
= extract32(insn
, 16, 5);
4363 cond
= extract32(insn
, 12, 4);
4364 rn
= extract32(insn
, 5, 5);
4365 op
= extract32(insn
, 4, 1);
4366 nzcv
= extract32(insn
, 0, 4);
4368 if (mos
|| type
> 1) {
4369 unallocated_encoding(s
);
4373 if (!fp_access_check(s
)) {
4377 if (cond
< 0x0e) { /* not always */
4378 TCGLabel
*label_match
= gen_new_label();
4379 label_continue
= gen_new_label();
4380 arm_gen_test_cc(cond
, label_match
);
4382 tcg_flags
= tcg_const_i64(nzcv
<< 28);
4383 gen_set_nzcv(tcg_flags
);
4384 tcg_temp_free_i64(tcg_flags
);
4385 tcg_gen_br(label_continue
);
4386 gen_set_label(label_match
);
4389 handle_fp_compare(s
, type
, rn
, rm
, false, op
);
4392 gen_set_label(label_continue
);
4396 /* C3.6.24 Floating point conditional select
4397 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4398 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4399 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
4400 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4402 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
4404 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
4405 TCGv_i64 t_true
, t_false
, t_zero
;
4408 mos
= extract32(insn
, 29, 3);
4409 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4410 rm
= extract32(insn
, 16, 5);
4411 cond
= extract32(insn
, 12, 4);
4412 rn
= extract32(insn
, 5, 5);
4413 rd
= extract32(insn
, 0, 5);
4415 if (mos
|| type
> 1) {
4416 unallocated_encoding(s
);
4420 if (!fp_access_check(s
)) {
4424 /* Zero extend sreg inputs to 64 bits now. */
4425 t_true
= tcg_temp_new_i64();
4426 t_false
= tcg_temp_new_i64();
4427 read_vec_element(s
, t_true
, rn
, 0, type
? MO_64
: MO_32
);
4428 read_vec_element(s
, t_false
, rm
, 0, type
? MO_64
: MO_32
);
4430 a64_test_cc(&c
, cond
);
4431 t_zero
= tcg_const_i64(0);
4432 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, t_zero
, t_true
, t_false
);
4433 tcg_temp_free_i64(t_zero
);
4434 tcg_temp_free_i64(t_false
);
4437 /* Note that sregs write back zeros to the high bits,
4438 and we've already done the zero-extension. */
4439 write_fp_dreg(s
, rd
, t_true
);
4440 tcg_temp_free_i64(t_true
);
4443 /* C3.6.25 Floating-point data-processing (1 source) - single precision */
4444 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
4450 fpst
= get_fpstatus_ptr();
4451 tcg_op
= read_fp_sreg(s
, rn
);
4452 tcg_res
= tcg_temp_new_i32();
4455 case 0x0: /* FMOV */
4456 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4458 case 0x1: /* FABS */
4459 gen_helper_vfp_abss(tcg_res
, tcg_op
);
4461 case 0x2: /* FNEG */
4462 gen_helper_vfp_negs(tcg_res
, tcg_op
);
4464 case 0x3: /* FSQRT */
4465 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
4467 case 0x8: /* FRINTN */
4468 case 0x9: /* FRINTP */
4469 case 0xa: /* FRINTM */
4470 case 0xb: /* FRINTZ */
4471 case 0xc: /* FRINTA */
4473 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4475 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4476 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4478 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4479 tcg_temp_free_i32(tcg_rmode
);
4482 case 0xe: /* FRINTX */
4483 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
4485 case 0xf: /* FRINTI */
4486 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4492 write_fp_sreg(s
, rd
, tcg_res
);
4494 tcg_temp_free_ptr(fpst
);
4495 tcg_temp_free_i32(tcg_op
);
4496 tcg_temp_free_i32(tcg_res
);
4499 /* C3.6.25 Floating-point data-processing (1 source) - double precision */
4500 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
4506 fpst
= get_fpstatus_ptr();
4507 tcg_op
= read_fp_dreg(s
, rn
);
4508 tcg_res
= tcg_temp_new_i64();
4511 case 0x0: /* FMOV */
4512 tcg_gen_mov_i64(tcg_res
, tcg_op
);
4514 case 0x1: /* FABS */
4515 gen_helper_vfp_absd(tcg_res
, tcg_op
);
4517 case 0x2: /* FNEG */
4518 gen_helper_vfp_negd(tcg_res
, tcg_op
);
4520 case 0x3: /* FSQRT */
4521 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
4523 case 0x8: /* FRINTN */
4524 case 0x9: /* FRINTP */
4525 case 0xa: /* FRINTM */
4526 case 0xb: /* FRINTZ */
4527 case 0xc: /* FRINTA */
4529 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4531 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4532 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4534 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4535 tcg_temp_free_i32(tcg_rmode
);
4538 case 0xe: /* FRINTX */
4539 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
4541 case 0xf: /* FRINTI */
4542 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4548 write_fp_dreg(s
, rd
, tcg_res
);
4550 tcg_temp_free_ptr(fpst
);
4551 tcg_temp_free_i64(tcg_op
);
4552 tcg_temp_free_i64(tcg_res
);
4555 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
4556 int rd
, int rn
, int dtype
, int ntype
)
4561 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4563 /* Single to double */
4564 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4565 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
4566 write_fp_dreg(s
, rd
, tcg_rd
);
4567 tcg_temp_free_i64(tcg_rd
);
4569 /* Single to half */
4570 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4571 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4572 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4573 write_fp_sreg(s
, rd
, tcg_rd
);
4574 tcg_temp_free_i32(tcg_rd
);
4576 tcg_temp_free_i32(tcg_rn
);
4581 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
4582 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4584 /* Double to single */
4585 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
4587 /* Double to half */
4588 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4589 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4591 write_fp_sreg(s
, rd
, tcg_rd
);
4592 tcg_temp_free_i32(tcg_rd
);
4593 tcg_temp_free_i64(tcg_rn
);
4598 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4599 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
4601 /* Half to single */
4602 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4603 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, cpu_env
);
4604 write_fp_sreg(s
, rd
, tcg_rd
);
4605 tcg_temp_free_i32(tcg_rd
);
4607 /* Half to double */
4608 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4609 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, cpu_env
);
4610 write_fp_dreg(s
, rd
, tcg_rd
);
4611 tcg_temp_free_i64(tcg_rd
);
4613 tcg_temp_free_i32(tcg_rn
);
4621 /* C3.6.25 Floating point data-processing (1 source)
4622 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
4623 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4624 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
4625 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4627 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
4629 int type
= extract32(insn
, 22, 2);
4630 int opcode
= extract32(insn
, 15, 6);
4631 int rn
= extract32(insn
, 5, 5);
4632 int rd
= extract32(insn
, 0, 5);
4635 case 0x4: case 0x5: case 0x7:
4637 /* FCVT between half, single and double precision */
4638 int dtype
= extract32(opcode
, 0, 2);
4639 if (type
== 2 || dtype
== type
) {
4640 unallocated_encoding(s
);
4643 if (!fp_access_check(s
)) {
4647 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
4653 /* 32-to-32 and 64-to-64 ops */
4656 if (!fp_access_check(s
)) {
4660 handle_fp_1src_single(s
, opcode
, rd
, rn
);
4663 if (!fp_access_check(s
)) {
4667 handle_fp_1src_double(s
, opcode
, rd
, rn
);
4670 unallocated_encoding(s
);
4674 unallocated_encoding(s
);
4679 /* C3.6.26 Floating-point data-processing (2 source) - single precision */
4680 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
4681 int rd
, int rn
, int rm
)
4688 tcg_res
= tcg_temp_new_i32();
4689 fpst
= get_fpstatus_ptr();
4690 tcg_op1
= read_fp_sreg(s
, rn
);
4691 tcg_op2
= read_fp_sreg(s
, rm
);
4694 case 0x0: /* FMUL */
4695 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4697 case 0x1: /* FDIV */
4698 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4700 case 0x2: /* FADD */
4701 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4703 case 0x3: /* FSUB */
4704 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4706 case 0x4: /* FMAX */
4707 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4709 case 0x5: /* FMIN */
4710 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4712 case 0x6: /* FMAXNM */
4713 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4715 case 0x7: /* FMINNM */
4716 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4718 case 0x8: /* FNMUL */
4719 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4720 gen_helper_vfp_negs(tcg_res
, tcg_res
);
4724 write_fp_sreg(s
, rd
, tcg_res
);
4726 tcg_temp_free_ptr(fpst
);
4727 tcg_temp_free_i32(tcg_op1
);
4728 tcg_temp_free_i32(tcg_op2
);
4729 tcg_temp_free_i32(tcg_res
);
4732 /* C3.6.26 Floating-point data-processing (2 source) - double precision */
4733 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
4734 int rd
, int rn
, int rm
)
4741 tcg_res
= tcg_temp_new_i64();
4742 fpst
= get_fpstatus_ptr();
4743 tcg_op1
= read_fp_dreg(s
, rn
);
4744 tcg_op2
= read_fp_dreg(s
, rm
);
4747 case 0x0: /* FMUL */
4748 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4750 case 0x1: /* FDIV */
4751 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4753 case 0x2: /* FADD */
4754 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4756 case 0x3: /* FSUB */
4757 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4759 case 0x4: /* FMAX */
4760 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4762 case 0x5: /* FMIN */
4763 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4765 case 0x6: /* FMAXNM */
4766 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4768 case 0x7: /* FMINNM */
4769 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4771 case 0x8: /* FNMUL */
4772 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4773 gen_helper_vfp_negd(tcg_res
, tcg_res
);
4777 write_fp_dreg(s
, rd
, tcg_res
);
4779 tcg_temp_free_ptr(fpst
);
4780 tcg_temp_free_i64(tcg_op1
);
4781 tcg_temp_free_i64(tcg_op2
);
4782 tcg_temp_free_i64(tcg_res
);
4785 /* C3.6.26 Floating point data-processing (2 source)
4786 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4787 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4788 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
4789 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4791 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
4793 int type
= extract32(insn
, 22, 2);
4794 int rd
= extract32(insn
, 0, 5);
4795 int rn
= extract32(insn
, 5, 5);
4796 int rm
= extract32(insn
, 16, 5);
4797 int opcode
= extract32(insn
, 12, 4);
4800 unallocated_encoding(s
);
4806 if (!fp_access_check(s
)) {
4809 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
4812 if (!fp_access_check(s
)) {
4815 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
4818 unallocated_encoding(s
);
4822 /* C3.6.27 Floating-point data-processing (3 source) - single precision */
4823 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
4824 int rd
, int rn
, int rm
, int ra
)
4826 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
4827 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4828 TCGv_ptr fpst
= get_fpstatus_ptr();
4830 tcg_op1
= read_fp_sreg(s
, rn
);
4831 tcg_op2
= read_fp_sreg(s
, rm
);
4832 tcg_op3
= read_fp_sreg(s
, ra
);
4834 /* These are fused multiply-add, and must be done as one
4835 * floating point operation with no rounding between the
4836 * multiplication and addition steps.
4837 * NB that doing the negations here as separate steps is
4838 * correct : an input NaN should come out with its sign bit
4839 * flipped if it is a negated-input.
4842 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
4846 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
4849 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4851 write_fp_sreg(s
, rd
, tcg_res
);
4853 tcg_temp_free_ptr(fpst
);
4854 tcg_temp_free_i32(tcg_op1
);
4855 tcg_temp_free_i32(tcg_op2
);
4856 tcg_temp_free_i32(tcg_op3
);
4857 tcg_temp_free_i32(tcg_res
);
4860 /* C3.6.27 Floating-point data-processing (3 source) - double precision */
4861 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
4862 int rd
, int rn
, int rm
, int ra
)
4864 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
4865 TCGv_i64 tcg_res
= tcg_temp_new_i64();
4866 TCGv_ptr fpst
= get_fpstatus_ptr();
4868 tcg_op1
= read_fp_dreg(s
, rn
);
4869 tcg_op2
= read_fp_dreg(s
, rm
);
4870 tcg_op3
= read_fp_dreg(s
, ra
);
4872 /* These are fused multiply-add, and must be done as one
4873 * floating point operation with no rounding between the
4874 * multiplication and addition steps.
4875 * NB that doing the negations here as separate steps is
4876 * correct : an input NaN should come out with its sign bit
4877 * flipped if it is a negated-input.
4880 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
4884 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
4887 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4889 write_fp_dreg(s
, rd
, tcg_res
);
4891 tcg_temp_free_ptr(fpst
);
4892 tcg_temp_free_i64(tcg_op1
);
4893 tcg_temp_free_i64(tcg_op2
);
4894 tcg_temp_free_i64(tcg_op3
);
4895 tcg_temp_free_i64(tcg_res
);
4898 /* C3.6.27 Floating point data-processing (3 source)
4899 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
4900 * +---+---+---+-----------+------+----+------+----+------+------+------+
4901 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
4902 * +---+---+---+-----------+------+----+------+----+------+------+------+
4904 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
4906 int type
= extract32(insn
, 22, 2);
4907 int rd
= extract32(insn
, 0, 5);
4908 int rn
= extract32(insn
, 5, 5);
4909 int ra
= extract32(insn
, 10, 5);
4910 int rm
= extract32(insn
, 16, 5);
4911 bool o0
= extract32(insn
, 15, 1);
4912 bool o1
= extract32(insn
, 21, 1);
4916 if (!fp_access_check(s
)) {
4919 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4922 if (!fp_access_check(s
)) {
4925 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4928 unallocated_encoding(s
);
4932 /* C3.6.28 Floating point immediate
4933 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
4934 * +---+---+---+-----------+------+---+------------+-------+------+------+
4935 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
4936 * +---+---+---+-----------+------+---+------------+-------+------+------+
4938 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
4940 int rd
= extract32(insn
, 0, 5);
4941 int imm8
= extract32(insn
, 13, 8);
4942 int is_double
= extract32(insn
, 22, 2);
4946 if (is_double
> 1) {
4947 unallocated_encoding(s
);
4951 if (!fp_access_check(s
)) {
4955 /* The imm8 encodes the sign bit, enough bits to represent
4956 * an exponent in the range 01....1xx to 10....0xx,
4957 * and the most significant 4 bits of the mantissa; see
4958 * VFPExpandImm() in the v8 ARM ARM.
4961 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4962 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
4963 extract32(imm8
, 0, 6);
4966 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4967 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
4968 (extract32(imm8
, 0, 6) << 3);
4972 tcg_res
= tcg_const_i64(imm
);
4973 write_fp_dreg(s
, rd
, tcg_res
);
4974 tcg_temp_free_i64(tcg_res
);
4977 /* Handle floating point <=> fixed point conversions. Note that we can
4978 * also deal with fp <=> integer conversions as a special case (scale == 64)
4979 * OPTME: consider handling that special case specially or at least skipping
4980 * the call to scalbn in the helpers for zero shifts.
4982 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
4983 bool itof
, int rmode
, int scale
, int sf
, int type
)
4985 bool is_signed
= !(opcode
& 1);
4986 bool is_double
= type
;
4987 TCGv_ptr tcg_fpstatus
;
4990 tcg_fpstatus
= get_fpstatus_ptr();
4992 tcg_shift
= tcg_const_i32(64 - scale
);
4995 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
4997 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
5000 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
5002 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
5005 tcg_int
= tcg_extend
;
5009 TCGv_i64 tcg_double
= tcg_temp_new_i64();
5011 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
5012 tcg_shift
, tcg_fpstatus
);
5014 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
5015 tcg_shift
, tcg_fpstatus
);
5017 write_fp_dreg(s
, rd
, tcg_double
);
5018 tcg_temp_free_i64(tcg_double
);
5020 TCGv_i32 tcg_single
= tcg_temp_new_i32();
5022 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
5023 tcg_shift
, tcg_fpstatus
);
5025 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
5026 tcg_shift
, tcg_fpstatus
);
5028 write_fp_sreg(s
, rd
, tcg_single
);
5029 tcg_temp_free_i32(tcg_single
);
5032 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
5035 if (extract32(opcode
, 2, 1)) {
5036 /* There are too many rounding modes to all fit into rmode,
5037 * so FCVTA[US] is a special case.
5039 rmode
= FPROUNDING_TIEAWAY
;
5042 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
5044 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
5047 TCGv_i64 tcg_double
= read_fp_dreg(s
, rn
);
5050 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
5051 tcg_shift
, tcg_fpstatus
);
5053 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
5054 tcg_shift
, tcg_fpstatus
);
5058 gen_helper_vfp_tould(tcg_int
, tcg_double
,
5059 tcg_shift
, tcg_fpstatus
);
5061 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
5062 tcg_shift
, tcg_fpstatus
);
5065 tcg_temp_free_i64(tcg_double
);
5067 TCGv_i32 tcg_single
= read_fp_sreg(s
, rn
);
5070 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
5071 tcg_shift
, tcg_fpstatus
);
5073 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
5074 tcg_shift
, tcg_fpstatus
);
5077 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
5079 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
5080 tcg_shift
, tcg_fpstatus
);
5082 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
5083 tcg_shift
, tcg_fpstatus
);
5085 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
5086 tcg_temp_free_i32(tcg_dest
);
5088 tcg_temp_free_i32(tcg_single
);
5091 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
5092 tcg_temp_free_i32(tcg_rmode
);
5095 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
5099 tcg_temp_free_ptr(tcg_fpstatus
);
5100 tcg_temp_free_i32(tcg_shift
);
5103 /* C3.6.29 Floating point <-> fixed point conversions
5104 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
5105 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
5106 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
5107 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
5109 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
5111 int rd
= extract32(insn
, 0, 5);
5112 int rn
= extract32(insn
, 5, 5);
5113 int scale
= extract32(insn
, 10, 6);
5114 int opcode
= extract32(insn
, 16, 3);
5115 int rmode
= extract32(insn
, 19, 2);
5116 int type
= extract32(insn
, 22, 2);
5117 bool sbit
= extract32(insn
, 29, 1);
5118 bool sf
= extract32(insn
, 31, 1);
5121 if (sbit
|| (type
> 1)
5122 || (!sf
&& scale
< 32)) {
5123 unallocated_encoding(s
);
5127 switch ((rmode
<< 3) | opcode
) {
5128 case 0x2: /* SCVTF */
5129 case 0x3: /* UCVTF */
5132 case 0x18: /* FCVTZS */
5133 case 0x19: /* FCVTZU */
5137 unallocated_encoding(s
);
5141 if (!fp_access_check(s
)) {
5145 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
5148 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
5150 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
5151 * without conversion.
5155 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
5161 TCGv_i64 tmp
= tcg_temp_new_i64();
5162 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
5163 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
5164 tcg_gen_movi_i64(tmp
, 0);
5165 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5166 tcg_temp_free_i64(tmp
);
5172 TCGv_i64 tmp
= tcg_const_i64(0);
5173 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
5174 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5175 tcg_temp_free_i64(tmp
);
5179 /* 64 bit to top half. */
5180 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5184 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5189 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
5193 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
5196 /* 64 bits from top half */
5197 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
5203 /* C3.6.30 Floating point <-> integer conversions
5204 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
5205 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5206 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
5207 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5209 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
5211 int rd
= extract32(insn
, 0, 5);
5212 int rn
= extract32(insn
, 5, 5);
5213 int opcode
= extract32(insn
, 16, 3);
5214 int rmode
= extract32(insn
, 19, 2);
5215 int type
= extract32(insn
, 22, 2);
5216 bool sbit
= extract32(insn
, 29, 1);
5217 bool sf
= extract32(insn
, 31, 1);
5220 unallocated_encoding(s
);
5226 bool itof
= opcode
& 1;
5229 unallocated_encoding(s
);
5233 switch (sf
<< 3 | type
<< 1 | rmode
) {
5234 case 0x0: /* 32 bit */
5235 case 0xa: /* 64 bit */
5236 case 0xd: /* 64 bit to top half of quad */
5239 /* all other sf/type/rmode combinations are invalid */
5240 unallocated_encoding(s
);
5244 if (!fp_access_check(s
)) {
5247 handle_fmov(s
, rd
, rn
, type
, itof
);
5249 /* actual FP conversions */
5250 bool itof
= extract32(opcode
, 1, 1);
5252 if (type
> 1 || (rmode
!= 0 && opcode
> 1)) {
5253 unallocated_encoding(s
);
5257 if (!fp_access_check(s
)) {
5260 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
5264 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
5265 * 31 30 29 28 25 24 0
5266 * +---+---+---+---------+-----------------------------+
5267 * | | 0 | | 1 1 1 1 | |
5268 * +---+---+---+---------+-----------------------------+
5270 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
5272 if (extract32(insn
, 24, 1)) {
5273 /* Floating point data-processing (3 source) */
5274 disas_fp_3src(s
, insn
);
5275 } else if (extract32(insn
, 21, 1) == 0) {
5276 /* Floating point to fixed point conversions */
5277 disas_fp_fixed_conv(s
, insn
);
5279 switch (extract32(insn
, 10, 2)) {
5281 /* Floating point conditional compare */
5282 disas_fp_ccomp(s
, insn
);
5285 /* Floating point data-processing (2 source) */
5286 disas_fp_2src(s
, insn
);
5289 /* Floating point conditional select */
5290 disas_fp_csel(s
, insn
);
5293 switch (ctz32(extract32(insn
, 12, 4))) {
5294 case 0: /* [15:12] == xxx1 */
5295 /* Floating point immediate */
5296 disas_fp_imm(s
, insn
);
5298 case 1: /* [15:12] == xx10 */
5299 /* Floating point compare */
5300 disas_fp_compare(s
, insn
);
5302 case 2: /* [15:12] == x100 */
5303 /* Floating point data-processing (1 source) */
5304 disas_fp_1src(s
, insn
);
5306 case 3: /* [15:12] == 1000 */
5307 unallocated_encoding(s
);
5309 default: /* [15:12] == 0000 */
5310 /* Floating point <-> integer conversions */
5311 disas_fp_int_conv(s
, insn
);
5319 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
5322 /* Extract 64 bits from the middle of two concatenated 64 bit
5323 * vector register slices left:right. The extracted bits start
5324 * at 'pos' bits into the right (least significant) side.
5325 * We return the result in tcg_right, and guarantee not to
5328 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5329 assert(pos
> 0 && pos
< 64);
5331 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
5332 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
5333 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
5335 tcg_temp_free_i64(tcg_tmp
);
5339 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
5340 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5341 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
5342 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5344 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
5346 int is_q
= extract32(insn
, 30, 1);
5347 int op2
= extract32(insn
, 22, 2);
5348 int imm4
= extract32(insn
, 11, 4);
5349 int rm
= extract32(insn
, 16, 5);
5350 int rn
= extract32(insn
, 5, 5);
5351 int rd
= extract32(insn
, 0, 5);
5352 int pos
= imm4
<< 3;
5353 TCGv_i64 tcg_resl
, tcg_resh
;
5355 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
5356 unallocated_encoding(s
);
5360 if (!fp_access_check(s
)) {
5364 tcg_resh
= tcg_temp_new_i64();
5365 tcg_resl
= tcg_temp_new_i64();
5367 /* Vd gets bits starting at pos bits into Vm:Vn. This is
5368 * either extracting 128 bits from a 128:128 concatenation, or
5369 * extracting 64 bits from a 64:64 concatenation.
5372 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
5374 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
5375 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5377 tcg_gen_movi_i64(tcg_resh
, 0);
5384 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
5385 EltPosns
*elt
= eltposns
;
5392 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
5394 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
5397 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5398 tcg_hh
= tcg_temp_new_i64();
5399 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
5400 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
5401 tcg_temp_free_i64(tcg_hh
);
5405 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5406 tcg_temp_free_i64(tcg_resl
);
5407 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5408 tcg_temp_free_i64(tcg_resh
);
5412 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
5413 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5414 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
5415 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5417 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
5419 int op2
= extract32(insn
, 22, 2);
5420 int is_q
= extract32(insn
, 30, 1);
5421 int rm
= extract32(insn
, 16, 5);
5422 int rn
= extract32(insn
, 5, 5);
5423 int rd
= extract32(insn
, 0, 5);
5424 int is_tblx
= extract32(insn
, 12, 1);
5425 int len
= extract32(insn
, 13, 2);
5426 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
5427 TCGv_i32 tcg_regno
, tcg_numregs
;
5430 unallocated_encoding(s
);
5434 if (!fp_access_check(s
)) {
5438 /* This does a table lookup: for every byte element in the input
5439 * we index into a table formed from up to four vector registers,
5440 * and then the output is the result of the lookups. Our helper
5441 * function does the lookup operation for a single 64 bit part of
5444 tcg_resl
= tcg_temp_new_i64();
5445 tcg_resh
= tcg_temp_new_i64();
5448 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5450 tcg_gen_movi_i64(tcg_resl
, 0);
5452 if (is_tblx
&& is_q
) {
5453 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5455 tcg_gen_movi_i64(tcg_resh
, 0);
5458 tcg_idx
= tcg_temp_new_i64();
5459 tcg_regno
= tcg_const_i32(rn
);
5460 tcg_numregs
= tcg_const_i32(len
+ 1);
5461 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
5462 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
5463 tcg_regno
, tcg_numregs
);
5465 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
5466 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
5467 tcg_regno
, tcg_numregs
);
5469 tcg_temp_free_i64(tcg_idx
);
5470 tcg_temp_free_i32(tcg_regno
);
5471 tcg_temp_free_i32(tcg_numregs
);
5473 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5474 tcg_temp_free_i64(tcg_resl
);
5475 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5476 tcg_temp_free_i64(tcg_resh
);
5479 /* C3.6.3 ZIP/UZP/TRN
5480 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
5481 * +---+---+-------------+------+---+------+---+------------------+------+
5482 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
5483 * +---+---+-------------+------+---+------+---+------------------+------+
5485 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
5487 int rd
= extract32(insn
, 0, 5);
5488 int rn
= extract32(insn
, 5, 5);
5489 int rm
= extract32(insn
, 16, 5);
5490 int size
= extract32(insn
, 22, 2);
5491 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
5492 * bit 2 indicates 1 vs 2 variant of the insn.
5494 int opcode
= extract32(insn
, 12, 2);
5495 bool part
= extract32(insn
, 14, 1);
5496 bool is_q
= extract32(insn
, 30, 1);
5497 int esize
= 8 << size
;
5499 int datasize
= is_q
? 128 : 64;
5500 int elements
= datasize
/ esize
;
5501 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
5503 if (opcode
== 0 || (size
== 3 && !is_q
)) {
5504 unallocated_encoding(s
);
5508 if (!fp_access_check(s
)) {
5512 tcg_resl
= tcg_const_i64(0);
5513 tcg_resh
= tcg_const_i64(0);
5514 tcg_res
= tcg_temp_new_i64();
5516 for (i
= 0; i
< elements
; i
++) {
5518 case 1: /* UZP1/2 */
5520 int midpoint
= elements
/ 2;
5522 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
5524 read_vec_element(s
, tcg_res
, rm
,
5525 2 * (i
- midpoint
) + part
, size
);
5529 case 2: /* TRN1/2 */
5531 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
5533 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
5536 case 3: /* ZIP1/2 */
5538 int base
= part
* elements
/ 2;
5540 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
5542 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
5547 g_assert_not_reached();
5552 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
5553 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
5555 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
5556 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
5560 tcg_temp_free_i64(tcg_res
);
5562 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5563 tcg_temp_free_i64(tcg_resl
);
5564 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5565 tcg_temp_free_i64(tcg_resh
);
5568 static void do_minmaxop(DisasContext
*s
, TCGv_i32 tcg_elt1
, TCGv_i32 tcg_elt2
,
5569 int opc
, bool is_min
, TCGv_ptr fpst
)
5571 /* Helper function for disas_simd_across_lanes: do a single precision
5572 * min/max operation on the specified two inputs,
5573 * and return the result in tcg_elt1.
5577 gen_helper_vfp_minnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5579 gen_helper_vfp_maxnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5584 gen_helper_vfp_mins(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5586 gen_helper_vfp_maxs(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5591 /* C3.6.4 AdvSIMD across lanes
5592 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5593 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5594 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5595 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5597 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
5599 int rd
= extract32(insn
, 0, 5);
5600 int rn
= extract32(insn
, 5, 5);
5601 int size
= extract32(insn
, 22, 2);
5602 int opcode
= extract32(insn
, 12, 5);
5603 bool is_q
= extract32(insn
, 30, 1);
5604 bool is_u
= extract32(insn
, 29, 1);
5606 bool is_min
= false;
5610 TCGv_i64 tcg_res
, tcg_elt
;
5613 case 0x1b: /* ADDV */
5615 unallocated_encoding(s
);
5619 case 0x3: /* SADDLV, UADDLV */
5620 case 0xa: /* SMAXV, UMAXV */
5621 case 0x1a: /* SMINV, UMINV */
5622 if (size
== 3 || (size
== 2 && !is_q
)) {
5623 unallocated_encoding(s
);
5627 case 0xc: /* FMAXNMV, FMINNMV */
5628 case 0xf: /* FMAXV, FMINV */
5629 if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
5630 unallocated_encoding(s
);
5633 /* Bit 1 of size field encodes min vs max, and actual size is always
5634 * 32 bits: adjust the size variable so following code can rely on it
5636 is_min
= extract32(size
, 1, 1);
5641 unallocated_encoding(s
);
5645 if (!fp_access_check(s
)) {
5650 elements
= (is_q
? 128 : 64) / esize
;
5652 tcg_res
= tcg_temp_new_i64();
5653 tcg_elt
= tcg_temp_new_i64();
5655 /* These instructions operate across all lanes of a vector
5656 * to produce a single result. We can guarantee that a 64
5657 * bit intermediate is sufficient:
5658 * + for [US]ADDLV the maximum element size is 32 bits, and
5659 * the result type is 64 bits
5660 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
5661 * same as the element size, which is 32 bits at most
5662 * For the integer operations we can choose to work at 64
5663 * or 32 bits and truncate at the end; for simplicity
5664 * we use 64 bits always. The floating point
5665 * ops do require 32 bit intermediates, though.
5668 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
5670 for (i
= 1; i
< elements
; i
++) {
5671 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
5674 case 0x03: /* SADDLV / UADDLV */
5675 case 0x1b: /* ADDV */
5676 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
5678 case 0x0a: /* SMAXV / UMAXV */
5679 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
5681 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5683 case 0x1a: /* SMINV / UMINV */
5684 tcg_gen_movcond_i64(is_u
? TCG_COND_LEU
: TCG_COND_LE
,
5686 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5690 g_assert_not_reached();
5695 /* Floating point ops which work on 32 bit (single) intermediates.
5696 * Note that correct NaN propagation requires that we do these
5697 * operations in exactly the order specified by the pseudocode.
5699 TCGv_i32 tcg_elt1
= tcg_temp_new_i32();
5700 TCGv_i32 tcg_elt2
= tcg_temp_new_i32();
5701 TCGv_i32 tcg_elt3
= tcg_temp_new_i32();
5702 TCGv_ptr fpst
= get_fpstatus_ptr();
5704 assert(esize
== 32);
5705 assert(elements
== 4);
5707 read_vec_element(s
, tcg_elt
, rn
, 0, MO_32
);
5708 tcg_gen_extrl_i64_i32(tcg_elt1
, tcg_elt
);
5709 read_vec_element(s
, tcg_elt
, rn
, 1, MO_32
);
5710 tcg_gen_extrl_i64_i32(tcg_elt2
, tcg_elt
);
5712 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5714 read_vec_element(s
, tcg_elt
, rn
, 2, MO_32
);
5715 tcg_gen_extrl_i64_i32(tcg_elt2
, tcg_elt
);
5716 read_vec_element(s
, tcg_elt
, rn
, 3, MO_32
);
5717 tcg_gen_extrl_i64_i32(tcg_elt3
, tcg_elt
);
5719 do_minmaxop(s
, tcg_elt2
, tcg_elt3
, opcode
, is_min
, fpst
);
5721 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5723 tcg_gen_extu_i32_i64(tcg_res
, tcg_elt1
);
5724 tcg_temp_free_i32(tcg_elt1
);
5725 tcg_temp_free_i32(tcg_elt2
);
5726 tcg_temp_free_i32(tcg_elt3
);
5727 tcg_temp_free_ptr(fpst
);
5730 tcg_temp_free_i64(tcg_elt
);
5732 /* Now truncate the result to the width required for the final output */
5733 if (opcode
== 0x03) {
5734 /* SADDLV, UADDLV: result is 2*esize */
5740 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
5743 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
5746 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
5751 g_assert_not_reached();
5754 write_fp_dreg(s
, rd
, tcg_res
);
5755 tcg_temp_free_i64(tcg_res
);
5758 /* C6.3.31 DUP (Element, Vector)
5760 * 31 30 29 21 20 16 15 10 9 5 4 0
5761 * +---+---+-------------------+--------+-------------+------+------+
5762 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5763 * +---+---+-------------------+--------+-------------+------+------+
5765 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5767 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
5770 int size
= ctz32(imm5
);
5771 int esize
= 8 << size
;
5772 int elements
= (is_q
? 128 : 64) / esize
;
5776 if (size
> 3 || (size
== 3 && !is_q
)) {
5777 unallocated_encoding(s
);
5781 if (!fp_access_check(s
)) {
5785 index
= imm5
>> (size
+ 1);
5787 tmp
= tcg_temp_new_i64();
5788 read_vec_element(s
, tmp
, rn
, index
, size
);
5790 for (i
= 0; i
< elements
; i
++) {
5791 write_vec_element(s
, tmp
, rd
, i
, size
);
5795 clear_vec_high(s
, rd
);
5798 tcg_temp_free_i64(tmp
);
5801 /* C6.3.31 DUP (element, scalar)
5802 * 31 21 20 16 15 10 9 5 4 0
5803 * +-----------------------+--------+-------------+------+------+
5804 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5805 * +-----------------------+--------+-------------+------+------+
5807 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
5810 int size
= ctz32(imm5
);
5815 unallocated_encoding(s
);
5819 if (!fp_access_check(s
)) {
5823 index
= imm5
>> (size
+ 1);
5825 /* This instruction just extracts the specified element and
5826 * zero-extends it into the bottom of the destination register.
5828 tmp
= tcg_temp_new_i64();
5829 read_vec_element(s
, tmp
, rn
, index
, size
);
5830 write_fp_dreg(s
, rd
, tmp
);
5831 tcg_temp_free_i64(tmp
);
5834 /* C6.3.32 DUP (General)
5836 * 31 30 29 21 20 16 15 10 9 5 4 0
5837 * +---+---+-------------------+--------+-------------+------+------+
5838 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
5839 * +---+---+-------------------+--------+-------------+------+------+
5841 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5843 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
5846 int size
= ctz32(imm5
);
5847 int esize
= 8 << size
;
5848 int elements
= (is_q
? 128 : 64)/esize
;
5851 if (size
> 3 || ((size
== 3) && !is_q
)) {
5852 unallocated_encoding(s
);
5856 if (!fp_access_check(s
)) {
5860 for (i
= 0; i
< elements
; i
++) {
5861 write_vec_element(s
, cpu_reg(s
, rn
), rd
, i
, size
);
5864 clear_vec_high(s
, rd
);
5868 /* C6.3.150 INS (Element)
5870 * 31 21 20 16 15 14 11 10 9 5 4 0
5871 * +-----------------------+--------+------------+---+------+------+
5872 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5873 * +-----------------------+--------+------------+---+------+------+
5875 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5876 * index: encoded in imm5<4:size+1>
5878 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
5881 int size
= ctz32(imm5
);
5882 int src_index
, dst_index
;
5886 unallocated_encoding(s
);
5890 if (!fp_access_check(s
)) {
5894 dst_index
= extract32(imm5
, 1+size
, 5);
5895 src_index
= extract32(imm4
, size
, 4);
5897 tmp
= tcg_temp_new_i64();
5899 read_vec_element(s
, tmp
, rn
, src_index
, size
);
5900 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
5902 tcg_temp_free_i64(tmp
);
5906 /* C6.3.151 INS (General)
5908 * 31 21 20 16 15 10 9 5 4 0
5909 * +-----------------------+--------+-------------+------+------+
5910 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
5911 * +-----------------------+--------+-------------+------+------+
5913 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5914 * index: encoded in imm5<4:size+1>
5916 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
5918 int size
= ctz32(imm5
);
5922 unallocated_encoding(s
);
5926 if (!fp_access_check(s
)) {
5930 idx
= extract32(imm5
, 1 + size
, 4 - size
);
5931 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
5935 * C6.3.321 UMOV (General)
5936 * C6.3.237 SMOV (General)
5938 * 31 30 29 21 20 16 15 12 10 9 5 4 0
5939 * +---+---+-------------------+--------+-------------+------+------+
5940 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
5941 * +---+---+-------------------+--------+-------------+------+------+
5943 * U: unsigned when set
5944 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5946 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
5947 int rn
, int rd
, int imm5
)
5949 int size
= ctz32(imm5
);
5953 /* Check for UnallocatedEncodings */
5955 if (size
> 2 || (size
== 2 && !is_q
)) {
5956 unallocated_encoding(s
);
5961 || (size
< 3 && is_q
)
5962 || (size
== 3 && !is_q
)) {
5963 unallocated_encoding(s
);
5968 if (!fp_access_check(s
)) {
5972 element
= extract32(imm5
, 1+size
, 4);
5974 tcg_rd
= cpu_reg(s
, rd
);
5975 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
5976 if (is_signed
&& !is_q
) {
5977 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5981 /* C3.6.5 AdvSIMD copy
5982 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5983 * +---+---+----+-----------------+------+---+------+---+------+------+
5984 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5985 * +---+---+----+-----------------+------+---+------+---+------+------+
5987 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
5989 int rd
= extract32(insn
, 0, 5);
5990 int rn
= extract32(insn
, 5, 5);
5991 int imm4
= extract32(insn
, 11, 4);
5992 int op
= extract32(insn
, 29, 1);
5993 int is_q
= extract32(insn
, 30, 1);
5994 int imm5
= extract32(insn
, 16, 5);
5999 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
6001 unallocated_encoding(s
);
6006 /* DUP (element - vector) */
6007 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
6011 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
6016 handle_simd_insg(s
, rd
, rn
, imm5
);
6018 unallocated_encoding(s
);
6023 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
6024 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
6027 unallocated_encoding(s
);
6033 /* C3.6.6 AdvSIMD modified immediate
6034 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
6035 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
6036 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
6037 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
6039 * There are a number of operations that can be carried out here:
6040 * MOVI - move (shifted) imm into register
6041 * MVNI - move inverted (shifted) imm into register
6042 * ORR - bitwise OR of (shifted) imm with register
6043 * BIC - bitwise clear of (shifted) imm with register
6045 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
6047 int rd
= extract32(insn
, 0, 5);
6048 int cmode
= extract32(insn
, 12, 4);
6049 int cmode_3_1
= extract32(cmode
, 1, 3);
6050 int cmode_0
= extract32(cmode
, 0, 1);
6051 int o2
= extract32(insn
, 11, 1);
6052 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
6053 bool is_neg
= extract32(insn
, 29, 1);
6054 bool is_q
= extract32(insn
, 30, 1);
6056 TCGv_i64 tcg_rd
, tcg_imm
;
6059 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
6060 unallocated_encoding(s
);
6064 if (!fp_access_check(s
)) {
6068 /* See AdvSIMDExpandImm() in ARM ARM */
6069 switch (cmode_3_1
) {
6070 case 0: /* Replicate(Zeros(24):imm8, 2) */
6071 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
6072 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
6073 case 3: /* Replicate(imm8:Zeros(24), 2) */
6075 int shift
= cmode_3_1
* 8;
6076 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
6079 case 4: /* Replicate(Zeros(8):imm8, 4) */
6080 case 5: /* Replicate(imm8:Zeros(8), 4) */
6082 int shift
= (cmode_3_1
& 0x1) * 8;
6083 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
6088 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
6089 imm
= (abcdefgh
<< 16) | 0xffff;
6091 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
6092 imm
= (abcdefgh
<< 8) | 0xff;
6094 imm
= bitfield_replicate(imm
, 32);
6097 if (!cmode_0
&& !is_neg
) {
6098 imm
= bitfield_replicate(abcdefgh
, 8);
6099 } else if (!cmode_0
&& is_neg
) {
6102 for (i
= 0; i
< 8; i
++) {
6103 if ((abcdefgh
) & (1 << i
)) {
6104 imm
|= 0xffULL
<< (i
* 8);
6107 } else if (cmode_0
) {
6109 imm
= (abcdefgh
& 0x3f) << 48;
6110 if (abcdefgh
& 0x80) {
6111 imm
|= 0x8000000000000000ULL
;
6113 if (abcdefgh
& 0x40) {
6114 imm
|= 0x3fc0000000000000ULL
;
6116 imm
|= 0x4000000000000000ULL
;
6119 imm
= (abcdefgh
& 0x3f) << 19;
6120 if (abcdefgh
& 0x80) {
6123 if (abcdefgh
& 0x40) {
6134 if (cmode_3_1
!= 7 && is_neg
) {
6138 tcg_imm
= tcg_const_i64(imm
);
6139 tcg_rd
= new_tmp_a64(s
);
6141 for (i
= 0; i
< 2; i
++) {
6142 int foffs
= i
? fp_reg_hi_offset(s
, rd
) : fp_reg_offset(s
, rd
, MO_64
);
6144 if (i
== 1 && !is_q
) {
6145 /* non-quad ops clear high half of vector */
6146 tcg_gen_movi_i64(tcg_rd
, 0);
6147 } else if ((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9) {
6148 tcg_gen_ld_i64(tcg_rd
, cpu_env
, foffs
);
6151 tcg_gen_and_i64(tcg_rd
, tcg_rd
, tcg_imm
);
6154 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_imm
);
6158 tcg_gen_mov_i64(tcg_rd
, tcg_imm
);
6160 tcg_gen_st_i64(tcg_rd
, cpu_env
, foffs
);
6163 tcg_temp_free_i64(tcg_imm
);
6166 /* C3.6.7 AdvSIMD scalar copy
6167 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
6168 * +-----+----+-----------------+------+---+------+---+------+------+
6169 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6170 * +-----+----+-----------------+------+---+------+---+------+------+
6172 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
6174 int rd
= extract32(insn
, 0, 5);
6175 int rn
= extract32(insn
, 5, 5);
6176 int imm4
= extract32(insn
, 11, 4);
6177 int imm5
= extract32(insn
, 16, 5);
6178 int op
= extract32(insn
, 29, 1);
6180 if (op
!= 0 || imm4
!= 0) {
6181 unallocated_encoding(s
);
6185 /* DUP (element, scalar) */
6186 handle_simd_dupes(s
, rd
, rn
, imm5
);
6189 /* C3.6.8 AdvSIMD scalar pairwise
6190 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6191 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6192 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6193 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6195 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
6197 int u
= extract32(insn
, 29, 1);
6198 int size
= extract32(insn
, 22, 2);
6199 int opcode
= extract32(insn
, 12, 5);
6200 int rn
= extract32(insn
, 5, 5);
6201 int rd
= extract32(insn
, 0, 5);
6204 /* For some ops (the FP ones), size[1] is part of the encoding.
6205 * For ADDP strictly it is not but size[1] is always 1 for valid
6208 opcode
|= (extract32(size
, 1, 1) << 5);
6211 case 0x3b: /* ADDP */
6212 if (u
|| size
!= 3) {
6213 unallocated_encoding(s
);
6216 if (!fp_access_check(s
)) {
6220 TCGV_UNUSED_PTR(fpst
);
6222 case 0xc: /* FMAXNMP */
6223 case 0xd: /* FADDP */
6224 case 0xf: /* FMAXP */
6225 case 0x2c: /* FMINNMP */
6226 case 0x2f: /* FMINP */
6227 /* FP op, size[0] is 32 or 64 bit */
6229 unallocated_encoding(s
);
6232 if (!fp_access_check(s
)) {
6236 size
= extract32(size
, 0, 1) ? 3 : 2;
6237 fpst
= get_fpstatus_ptr();
6240 unallocated_encoding(s
);
6245 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6246 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6247 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6249 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
6250 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
6253 case 0x3b: /* ADDP */
6254 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
6256 case 0xc: /* FMAXNMP */
6257 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6259 case 0xd: /* FADDP */
6260 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6262 case 0xf: /* FMAXP */
6263 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6265 case 0x2c: /* FMINNMP */
6266 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6268 case 0x2f: /* FMINP */
6269 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6272 g_assert_not_reached();
6275 write_fp_dreg(s
, rd
, tcg_res
);
6277 tcg_temp_free_i64(tcg_op1
);
6278 tcg_temp_free_i64(tcg_op2
);
6279 tcg_temp_free_i64(tcg_res
);
6281 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6282 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6283 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6285 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_32
);
6286 read_vec_element_i32(s
, tcg_op2
, rn
, 1, MO_32
);
6289 case 0xc: /* FMAXNMP */
6290 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6292 case 0xd: /* FADDP */
6293 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6295 case 0xf: /* FMAXP */
6296 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6298 case 0x2c: /* FMINNMP */
6299 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6301 case 0x2f: /* FMINP */
6302 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6305 g_assert_not_reached();
6308 write_fp_sreg(s
, rd
, tcg_res
);
6310 tcg_temp_free_i32(tcg_op1
);
6311 tcg_temp_free_i32(tcg_op2
);
6312 tcg_temp_free_i32(tcg_res
);
6315 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
6316 tcg_temp_free_ptr(fpst
);
6321 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
6323 * This code is handles the common shifting code and is used by both
6324 * the vector and scalar code.
6326 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6327 TCGv_i64 tcg_rnd
, bool accumulate
,
6328 bool is_u
, int size
, int shift
)
6330 bool extended_result
= false;
6331 bool round
= !TCGV_IS_UNUSED_I64(tcg_rnd
);
6333 TCGv_i64 tcg_src_hi
;
6335 if (round
&& size
== 3) {
6336 extended_result
= true;
6337 ext_lshift
= 64 - shift
;
6338 tcg_src_hi
= tcg_temp_new_i64();
6339 } else if (shift
== 64) {
6340 if (!accumulate
&& is_u
) {
6341 /* result is zero */
6342 tcg_gen_movi_i64(tcg_res
, 0);
6347 /* Deal with the rounding step */
6349 if (extended_result
) {
6350 TCGv_i64 tcg_zero
= tcg_const_i64(0);
6352 /* take care of sign extending tcg_res */
6353 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
6354 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6355 tcg_src
, tcg_src_hi
,
6358 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6362 tcg_temp_free_i64(tcg_zero
);
6364 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
6368 /* Now do the shift right */
6369 if (round
&& extended_result
) {
6370 /* extended case, >64 bit precision required */
6371 if (ext_lshift
== 0) {
6372 /* special case, only high bits matter */
6373 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
6375 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6376 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
6377 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
6382 /* essentially shifting in 64 zeros */
6383 tcg_gen_movi_i64(tcg_src
, 0);
6385 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6389 /* effectively extending the sign-bit */
6390 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
6392 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
6398 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
6400 tcg_gen_mov_i64(tcg_res
, tcg_src
);
6403 if (extended_result
) {
6404 tcg_temp_free_i64(tcg_src_hi
);
6408 /* Common SHL/SLI - Shift left with an optional insert */
6409 static void handle_shli_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6410 bool insert
, int shift
)
6412 if (insert
) { /* SLI */
6413 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, shift
, 64 - shift
);
6415 tcg_gen_shli_i64(tcg_res
, tcg_src
, shift
);
6419 /* SRI: shift right with insert */
6420 static void handle_shri_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6421 int size
, int shift
)
6423 int esize
= 8 << size
;
6425 /* shift count same as element size is valid but does nothing;
6426 * special case to avoid potential shift by 64.
6428 if (shift
!= esize
) {
6429 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6430 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, 0, esize
- shift
);
6434 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
6435 static void handle_scalar_simd_shri(DisasContext
*s
,
6436 bool is_u
, int immh
, int immb
,
6437 int opcode
, int rn
, int rd
)
6440 int immhb
= immh
<< 3 | immb
;
6441 int shift
= 2 * (8 << size
) - immhb
;
6442 bool accumulate
= false;
6444 bool insert
= false;
6449 if (!extract32(immh
, 3, 1)) {
6450 unallocated_encoding(s
);
6454 if (!fp_access_check(s
)) {
6459 case 0x02: /* SSRA / USRA (accumulate) */
6462 case 0x04: /* SRSHR / URSHR (rounding) */
6465 case 0x06: /* SRSRA / URSRA (accum + rounding) */
6466 accumulate
= round
= true;
6468 case 0x08: /* SRI */
6474 uint64_t round_const
= 1ULL << (shift
- 1);
6475 tcg_round
= tcg_const_i64(round_const
);
6477 TCGV_UNUSED_I64(tcg_round
);
6480 tcg_rn
= read_fp_dreg(s
, rn
);
6481 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6484 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
6486 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6487 accumulate
, is_u
, size
, shift
);
6490 write_fp_dreg(s
, rd
, tcg_rd
);
6492 tcg_temp_free_i64(tcg_rn
);
6493 tcg_temp_free_i64(tcg_rd
);
6495 tcg_temp_free_i64(tcg_round
);
6499 /* SHL/SLI - Scalar shift left */
6500 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
6501 int immh
, int immb
, int opcode
,
6504 int size
= 32 - clz32(immh
) - 1;
6505 int immhb
= immh
<< 3 | immb
;
6506 int shift
= immhb
- (8 << size
);
6507 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
6508 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
6510 if (!extract32(immh
, 3, 1)) {
6511 unallocated_encoding(s
);
6515 if (!fp_access_check(s
)) {
6519 tcg_rn
= read_fp_dreg(s
, rn
);
6520 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6522 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
6524 write_fp_dreg(s
, rd
, tcg_rd
);
6526 tcg_temp_free_i64(tcg_rn
);
6527 tcg_temp_free_i64(tcg_rd
);
6530 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
6531 * (signed/unsigned) narrowing */
6532 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
6533 bool is_u_shift
, bool is_u_narrow
,
6534 int immh
, int immb
, int opcode
,
6537 int immhb
= immh
<< 3 | immb
;
6538 int size
= 32 - clz32(immh
) - 1;
6539 int esize
= 8 << size
;
6540 int shift
= (2 * esize
) - immhb
;
6541 int elements
= is_scalar
? 1 : (64 / esize
);
6542 bool round
= extract32(opcode
, 0, 1);
6543 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
6544 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
6545 TCGv_i32 tcg_rd_narrowed
;
6548 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
6549 { gen_helper_neon_narrow_sat_s8
,
6550 gen_helper_neon_unarrow_sat8
},
6551 { gen_helper_neon_narrow_sat_s16
,
6552 gen_helper_neon_unarrow_sat16
},
6553 { gen_helper_neon_narrow_sat_s32
,
6554 gen_helper_neon_unarrow_sat32
},
6557 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
6558 gen_helper_neon_narrow_sat_u8
,
6559 gen_helper_neon_narrow_sat_u16
,
6560 gen_helper_neon_narrow_sat_u32
,
6563 NeonGenNarrowEnvFn
*narrowfn
;
6569 if (extract32(immh
, 3, 1)) {
6570 unallocated_encoding(s
);
6574 if (!fp_access_check(s
)) {
6579 narrowfn
= unsigned_narrow_fns
[size
];
6581 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
6584 tcg_rn
= tcg_temp_new_i64();
6585 tcg_rd
= tcg_temp_new_i64();
6586 tcg_rd_narrowed
= tcg_temp_new_i32();
6587 tcg_final
= tcg_const_i64(0);
6590 uint64_t round_const
= 1ULL << (shift
- 1);
6591 tcg_round
= tcg_const_i64(round_const
);
6593 TCGV_UNUSED_I64(tcg_round
);
6596 for (i
= 0; i
< elements
; i
++) {
6597 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
6598 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6599 false, is_u_shift
, size
+1, shift
);
6600 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
6601 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
6602 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
6606 clear_vec_high(s
, rd
);
6607 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
6609 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
6613 tcg_temp_free_i64(tcg_round
);
6615 tcg_temp_free_i64(tcg_rn
);
6616 tcg_temp_free_i64(tcg_rd
);
6617 tcg_temp_free_i32(tcg_rd_narrowed
);
6618 tcg_temp_free_i64(tcg_final
);
6622 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
6623 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
6624 bool src_unsigned
, bool dst_unsigned
,
6625 int immh
, int immb
, int rn
, int rd
)
6627 int immhb
= immh
<< 3 | immb
;
6628 int size
= 32 - clz32(immh
) - 1;
6629 int shift
= immhb
- (8 << size
);
6633 assert(!(scalar
&& is_q
));
6636 if (!is_q
&& extract32(immh
, 3, 1)) {
6637 unallocated_encoding(s
);
6641 /* Since we use the variable-shift helpers we must
6642 * replicate the shift count into each element of
6643 * the tcg_shift value.
6647 shift
|= shift
<< 8;
6650 shift
|= shift
<< 16;
6656 g_assert_not_reached();
6660 if (!fp_access_check(s
)) {
6665 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
6666 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
6667 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
6668 { NULL
, gen_helper_neon_qshl_u64
},
6670 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
6671 int maxpass
= is_q
? 2 : 1;
6673 for (pass
= 0; pass
< maxpass
; pass
++) {
6674 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6676 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6677 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6678 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6680 tcg_temp_free_i64(tcg_op
);
6682 tcg_temp_free_i64(tcg_shift
);
6685 clear_vec_high(s
, rd
);
6688 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
6689 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
6691 { gen_helper_neon_qshl_s8
,
6692 gen_helper_neon_qshl_s16
,
6693 gen_helper_neon_qshl_s32
},
6694 { gen_helper_neon_qshlu_s8
,
6695 gen_helper_neon_qshlu_s16
,
6696 gen_helper_neon_qshlu_s32
}
6698 { NULL
, NULL
, NULL
},
6699 { gen_helper_neon_qshl_u8
,
6700 gen_helper_neon_qshl_u16
,
6701 gen_helper_neon_qshl_u32
}
6704 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
6705 TCGMemOp memop
= scalar
? size
: MO_32
;
6706 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
6708 for (pass
= 0; pass
< maxpass
; pass
++) {
6709 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6711 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
6712 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6716 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
6719 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
6724 g_assert_not_reached();
6726 write_fp_sreg(s
, rd
, tcg_op
);
6728 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6731 tcg_temp_free_i32(tcg_op
);
6733 tcg_temp_free_i32(tcg_shift
);
6735 if (!is_q
&& !scalar
) {
6736 clear_vec_high(s
, rd
);
6741 /* Common vector code for handling integer to FP conversion */
6742 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
6743 int elements
, int is_signed
,
6744 int fracbits
, int size
)
6746 bool is_double
= size
== 3 ? true : false;
6747 TCGv_ptr tcg_fpst
= get_fpstatus_ptr();
6748 TCGv_i32 tcg_shift
= tcg_const_i32(fracbits
);
6749 TCGv_i64 tcg_int
= tcg_temp_new_i64();
6750 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
6753 for (pass
= 0; pass
< elements
; pass
++) {
6754 read_vec_element(s
, tcg_int
, rn
, pass
, mop
);
6757 TCGv_i64 tcg_double
= tcg_temp_new_i64();
6759 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6760 tcg_shift
, tcg_fpst
);
6762 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6763 tcg_shift
, tcg_fpst
);
6765 if (elements
== 1) {
6766 write_fp_dreg(s
, rd
, tcg_double
);
6768 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
6770 tcg_temp_free_i64(tcg_double
);
6772 TCGv_i32 tcg_single
= tcg_temp_new_i32();
6774 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6775 tcg_shift
, tcg_fpst
);
6777 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6778 tcg_shift
, tcg_fpst
);
6780 if (elements
== 1) {
6781 write_fp_sreg(s
, rd
, tcg_single
);
6783 write_vec_element_i32(s
, tcg_single
, rd
, pass
, MO_32
);
6785 tcg_temp_free_i32(tcg_single
);
6789 if (!is_double
&& elements
== 2) {
6790 clear_vec_high(s
, rd
);
6793 tcg_temp_free_i64(tcg_int
);
6794 tcg_temp_free_ptr(tcg_fpst
);
6795 tcg_temp_free_i32(tcg_shift
);
6798 /* UCVTF/SCVTF - Integer to FP conversion */
6799 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
6800 bool is_q
, bool is_u
,
6801 int immh
, int immb
, int opcode
,
6804 bool is_double
= extract32(immh
, 3, 1);
6805 int size
= is_double
? MO_64
: MO_32
;
6807 int immhb
= immh
<< 3 | immb
;
6808 int fracbits
= (is_double
? 128 : 64) - immhb
;
6810 if (!extract32(immh
, 2, 2)) {
6811 unallocated_encoding(s
);
6818 elements
= is_double
? 2 : is_q
? 4 : 2;
6819 if (is_double
&& !is_q
) {
6820 unallocated_encoding(s
);
6825 if (!fp_access_check(s
)) {
6829 /* immh == 0 would be a failure of the decode logic */
6832 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
6835 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
6836 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
6837 bool is_q
, bool is_u
,
6838 int immh
, int immb
, int rn
, int rd
)
6840 bool is_double
= extract32(immh
, 3, 1);
6841 int immhb
= immh
<< 3 | immb
;
6842 int fracbits
= (is_double
? 128 : 64) - immhb
;
6844 TCGv_ptr tcg_fpstatus
;
6845 TCGv_i32 tcg_rmode
, tcg_shift
;
6847 if (!extract32(immh
, 2, 2)) {
6848 unallocated_encoding(s
);
6852 if (!is_scalar
&& !is_q
&& is_double
) {
6853 unallocated_encoding(s
);
6857 if (!fp_access_check(s
)) {
6861 assert(!(is_scalar
&& is_q
));
6863 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
6864 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6865 tcg_fpstatus
= get_fpstatus_ptr();
6866 tcg_shift
= tcg_const_i32(fracbits
);
6869 int maxpass
= is_scalar
? 1 : 2;
6871 for (pass
= 0; pass
< maxpass
; pass
++) {
6872 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6874 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6876 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6878 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6880 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6881 tcg_temp_free_i64(tcg_op
);
6884 clear_vec_high(s
, rd
);
6887 int maxpass
= is_scalar
? 1 : is_q
? 4 : 2;
6888 for (pass
= 0; pass
< maxpass
; pass
++) {
6889 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6891 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
6893 gen_helper_vfp_touls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6895 gen_helper_vfp_tosls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6898 write_fp_sreg(s
, rd
, tcg_op
);
6900 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6902 tcg_temp_free_i32(tcg_op
);
6904 if (!is_q
&& !is_scalar
) {
6905 clear_vec_high(s
, rd
);
6909 tcg_temp_free_ptr(tcg_fpstatus
);
6910 tcg_temp_free_i32(tcg_shift
);
6911 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6912 tcg_temp_free_i32(tcg_rmode
);
6915 /* C3.6.9 AdvSIMD scalar shift by immediate
6916 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
6917 * +-----+---+-------------+------+------+--------+---+------+------+
6918 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
6919 * +-----+---+-------------+------+------+--------+---+------+------+
6921 * This is the scalar version so it works on a fixed sized registers
6923 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
6925 int rd
= extract32(insn
, 0, 5);
6926 int rn
= extract32(insn
, 5, 5);
6927 int opcode
= extract32(insn
, 11, 5);
6928 int immb
= extract32(insn
, 16, 3);
6929 int immh
= extract32(insn
, 19, 4);
6930 bool is_u
= extract32(insn
, 29, 1);
6933 unallocated_encoding(s
);
6938 case 0x08: /* SRI */
6940 unallocated_encoding(s
);
6944 case 0x00: /* SSHR / USHR */
6945 case 0x02: /* SSRA / USRA */
6946 case 0x04: /* SRSHR / URSHR */
6947 case 0x06: /* SRSRA / URSRA */
6948 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6950 case 0x0a: /* SHL / SLI */
6951 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6953 case 0x1c: /* SCVTF, UCVTF */
6954 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
6957 case 0x10: /* SQSHRUN, SQSHRUN2 */
6958 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
6960 unallocated_encoding(s
);
6963 handle_vec_simd_sqshrn(s
, true, false, false, true,
6964 immh
, immb
, opcode
, rn
, rd
);
6966 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
6967 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
6968 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
6969 immh
, immb
, opcode
, rn
, rd
);
6971 case 0xc: /* SQSHLU */
6973 unallocated_encoding(s
);
6976 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
6978 case 0xe: /* SQSHL, UQSHL */
6979 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
6981 case 0x1f: /* FCVTZS, FCVTZU */
6982 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
6985 unallocated_encoding(s
);
6990 /* C3.6.10 AdvSIMD scalar three different
6991 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6992 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6993 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
6994 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6996 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
6998 bool is_u
= extract32(insn
, 29, 1);
6999 int size
= extract32(insn
, 22, 2);
7000 int opcode
= extract32(insn
, 12, 4);
7001 int rm
= extract32(insn
, 16, 5);
7002 int rn
= extract32(insn
, 5, 5);
7003 int rd
= extract32(insn
, 0, 5);
7006 unallocated_encoding(s
);
7011 case 0x9: /* SQDMLAL, SQDMLAL2 */
7012 case 0xb: /* SQDMLSL, SQDMLSL2 */
7013 case 0xd: /* SQDMULL, SQDMULL2 */
7014 if (size
== 0 || size
== 3) {
7015 unallocated_encoding(s
);
7020 unallocated_encoding(s
);
7024 if (!fp_access_check(s
)) {
7029 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7030 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7031 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7033 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
7034 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
7036 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
7037 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
7040 case 0xd: /* SQDMULL, SQDMULL2 */
7042 case 0xb: /* SQDMLSL, SQDMLSL2 */
7043 tcg_gen_neg_i64(tcg_res
, tcg_res
);
7045 case 0x9: /* SQDMLAL, SQDMLAL2 */
7046 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
7047 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
7051 g_assert_not_reached();
7054 write_fp_dreg(s
, rd
, tcg_res
);
7056 tcg_temp_free_i64(tcg_op1
);
7057 tcg_temp_free_i64(tcg_op2
);
7058 tcg_temp_free_i64(tcg_res
);
7060 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7061 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7062 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7064 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_16
);
7065 read_vec_element_i32(s
, tcg_op2
, rm
, 0, MO_16
);
7067 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
7068 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
7071 case 0xd: /* SQDMULL, SQDMULL2 */
7073 case 0xb: /* SQDMLSL, SQDMLSL2 */
7074 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
7076 case 0x9: /* SQDMLAL, SQDMLAL2 */
7078 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
7079 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
7080 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
7082 tcg_temp_free_i64(tcg_op3
);
7086 g_assert_not_reached();
7089 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
7090 write_fp_dreg(s
, rd
, tcg_res
);
7092 tcg_temp_free_i32(tcg_op1
);
7093 tcg_temp_free_i32(tcg_op2
);
7094 tcg_temp_free_i64(tcg_res
);
7098 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
7099 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
7101 /* Handle 64x64->64 opcodes which are shared between the scalar
7102 * and vector 3-same groups. We cover every opcode where size == 3
7103 * is valid in either the three-reg-same (integer, not pairwise)
7104 * or scalar-three-reg-same groups. (Some opcodes are not yet
7110 case 0x1: /* SQADD */
7112 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7114 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7117 case 0x5: /* SQSUB */
7119 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7121 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7124 case 0x6: /* CMGT, CMHI */
7125 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
7126 * We implement this using setcond (test) and then negating.
7128 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
7130 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
7131 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7133 case 0x7: /* CMGE, CMHS */
7134 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
7136 case 0x11: /* CMTST, CMEQ */
7141 /* CMTST : test is "if (X & Y != 0)". */
7142 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
7143 tcg_gen_setcondi_i64(TCG_COND_NE
, tcg_rd
, tcg_rd
, 0);
7144 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7146 case 0x8: /* SSHL, USHL */
7148 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
7150 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
7153 case 0x9: /* SQSHL, UQSHL */
7155 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7157 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7160 case 0xa: /* SRSHL, URSHL */
7162 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
7164 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
7167 case 0xb: /* SQRSHL, UQRSHL */
7169 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7171 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7174 case 0x10: /* ADD, SUB */
7176 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
7178 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
7182 g_assert_not_reached();
7186 /* Handle the 3-same-operands float operations; shared by the scalar
7187 * and vector encodings. The caller must filter out any encodings
7188 * not allocated for the encoding it is dealing with.
7190 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
7191 int fpopcode
, int rd
, int rn
, int rm
)
7194 TCGv_ptr fpst
= get_fpstatus_ptr();
7196 for (pass
= 0; pass
< elements
; pass
++) {
7199 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7200 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7201 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7203 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
7204 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
7207 case 0x39: /* FMLS */
7208 /* As usual for ARM, separate negation for fused multiply-add */
7209 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
7211 case 0x19: /* FMLA */
7212 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7213 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
7216 case 0x18: /* FMAXNM */
7217 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7219 case 0x1a: /* FADD */
7220 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7222 case 0x1b: /* FMULX */
7223 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7225 case 0x1c: /* FCMEQ */
7226 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7228 case 0x1e: /* FMAX */
7229 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7231 case 0x1f: /* FRECPS */
7232 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7234 case 0x38: /* FMINNM */
7235 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7237 case 0x3a: /* FSUB */
7238 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7240 case 0x3e: /* FMIN */
7241 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7243 case 0x3f: /* FRSQRTS */
7244 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7246 case 0x5b: /* FMUL */
7247 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7249 case 0x5c: /* FCMGE */
7250 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7252 case 0x5d: /* FACGE */
7253 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7255 case 0x5f: /* FDIV */
7256 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7258 case 0x7a: /* FABD */
7259 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7260 gen_helper_vfp_absd(tcg_res
, tcg_res
);
7262 case 0x7c: /* FCMGT */
7263 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7265 case 0x7d: /* FACGT */
7266 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7269 g_assert_not_reached();
7272 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7274 tcg_temp_free_i64(tcg_res
);
7275 tcg_temp_free_i64(tcg_op1
);
7276 tcg_temp_free_i64(tcg_op2
);
7279 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7280 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7281 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7283 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
7284 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
7287 case 0x39: /* FMLS */
7288 /* As usual for ARM, separate negation for fused multiply-add */
7289 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
7291 case 0x19: /* FMLA */
7292 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7293 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
7296 case 0x1a: /* FADD */
7297 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7299 case 0x1b: /* FMULX */
7300 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7302 case 0x1c: /* FCMEQ */
7303 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7305 case 0x1e: /* FMAX */
7306 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7308 case 0x1f: /* FRECPS */
7309 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7311 case 0x18: /* FMAXNM */
7312 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7314 case 0x38: /* FMINNM */
7315 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7317 case 0x3a: /* FSUB */
7318 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7320 case 0x3e: /* FMIN */
7321 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7323 case 0x3f: /* FRSQRTS */
7324 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7326 case 0x5b: /* FMUL */
7327 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7329 case 0x5c: /* FCMGE */
7330 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7332 case 0x5d: /* FACGE */
7333 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7335 case 0x5f: /* FDIV */
7336 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7338 case 0x7a: /* FABD */
7339 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7340 gen_helper_vfp_abss(tcg_res
, tcg_res
);
7342 case 0x7c: /* FCMGT */
7343 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7345 case 0x7d: /* FACGT */
7346 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7349 g_assert_not_reached();
7352 if (elements
== 1) {
7353 /* scalar single so clear high part */
7354 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
7356 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
7357 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
7358 tcg_temp_free_i64(tcg_tmp
);
7360 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7363 tcg_temp_free_i32(tcg_res
);
7364 tcg_temp_free_i32(tcg_op1
);
7365 tcg_temp_free_i32(tcg_op2
);
7369 tcg_temp_free_ptr(fpst
);
7371 if ((elements
<< size
) < 4) {
7372 /* scalar, or non-quad vector op */
7373 clear_vec_high(s
, rd
);
7377 /* C3.6.11 AdvSIMD scalar three same
7378 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
7379 * +-----+---+-----------+------+---+------+--------+---+------+------+
7380 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
7381 * +-----+---+-----------+------+---+------+--------+---+------+------+
7383 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
7385 int rd
= extract32(insn
, 0, 5);
7386 int rn
= extract32(insn
, 5, 5);
7387 int opcode
= extract32(insn
, 11, 5);
7388 int rm
= extract32(insn
, 16, 5);
7389 int size
= extract32(insn
, 22, 2);
7390 bool u
= extract32(insn
, 29, 1);
7393 if (opcode
>= 0x18) {
7394 /* Floating point: U, size[1] and opcode indicate operation */
7395 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
7397 case 0x1b: /* FMULX */
7398 case 0x1f: /* FRECPS */
7399 case 0x3f: /* FRSQRTS */
7400 case 0x5d: /* FACGE */
7401 case 0x7d: /* FACGT */
7402 case 0x1c: /* FCMEQ */
7403 case 0x5c: /* FCMGE */
7404 case 0x7c: /* FCMGT */
7405 case 0x7a: /* FABD */
7408 unallocated_encoding(s
);
7412 if (!fp_access_check(s
)) {
7416 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
7421 case 0x1: /* SQADD, UQADD */
7422 case 0x5: /* SQSUB, UQSUB */
7423 case 0x9: /* SQSHL, UQSHL */
7424 case 0xb: /* SQRSHL, UQRSHL */
7426 case 0x8: /* SSHL, USHL */
7427 case 0xa: /* SRSHL, URSHL */
7428 case 0x6: /* CMGT, CMHI */
7429 case 0x7: /* CMGE, CMHS */
7430 case 0x11: /* CMTST, CMEQ */
7431 case 0x10: /* ADD, SUB (vector) */
7433 unallocated_encoding(s
);
7437 case 0x16: /* SQDMULH, SQRDMULH (vector) */
7438 if (size
!= 1 && size
!= 2) {
7439 unallocated_encoding(s
);
7444 unallocated_encoding(s
);
7448 if (!fp_access_check(s
)) {
7452 tcg_rd
= tcg_temp_new_i64();
7455 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7456 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
7458 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
7459 tcg_temp_free_i64(tcg_rn
);
7460 tcg_temp_free_i64(tcg_rm
);
7462 /* Do a single operation on the lowest element in the vector.
7463 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
7464 * no side effects for all these operations.
7465 * OPTME: special-purpose helpers would avoid doing some
7466 * unnecessary work in the helper for the 8 and 16 bit cases.
7468 NeonGenTwoOpEnvFn
*genenvfn
;
7469 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7470 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
7471 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
7473 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7474 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
7477 case 0x1: /* SQADD, UQADD */
7479 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7480 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
7481 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
7482 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
7484 genenvfn
= fns
[size
][u
];
7487 case 0x5: /* SQSUB, UQSUB */
7489 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7490 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
7491 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
7492 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
7494 genenvfn
= fns
[size
][u
];
7497 case 0x9: /* SQSHL, UQSHL */
7499 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7500 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
7501 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
7502 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
7504 genenvfn
= fns
[size
][u
];
7507 case 0xb: /* SQRSHL, UQRSHL */
7509 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7510 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
7511 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
7512 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
7514 genenvfn
= fns
[size
][u
];
7517 case 0x16: /* SQDMULH, SQRDMULH */
7519 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
7520 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
7521 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
7523 assert(size
== 1 || size
== 2);
7524 genenvfn
= fns
[size
- 1][u
];
7528 g_assert_not_reached();
7531 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
7532 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
7533 tcg_temp_free_i32(tcg_rd32
);
7534 tcg_temp_free_i32(tcg_rn
);
7535 tcg_temp_free_i32(tcg_rm
);
7538 write_fp_dreg(s
, rd
, tcg_rd
);
7540 tcg_temp_free_i64(tcg_rd
);
7543 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
7544 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
7545 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
7547 /* Handle 64->64 opcodes which are shared between the scalar and
7548 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
7549 * is valid in either group and also the double-precision fp ops.
7550 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
7556 case 0x4: /* CLS, CLZ */
7558 gen_helper_clz64(tcg_rd
, tcg_rn
);
7560 gen_helper_cls64(tcg_rd
, tcg_rn
);
7564 /* This opcode is shared with CNT and RBIT but we have earlier
7565 * enforced that size == 3 if and only if this is the NOT insn.
7567 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
7569 case 0x7: /* SQABS, SQNEG */
7571 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
7573 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
7576 case 0xa: /* CMLT */
7577 /* 64 bit integer comparison against zero, result is
7578 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
7583 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
7584 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7586 case 0x8: /* CMGT, CMGE */
7587 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
7589 case 0x9: /* CMEQ, CMLE */
7590 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
7592 case 0xb: /* ABS, NEG */
7594 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7596 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7597 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7598 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
7600 tcg_temp_free_i64(tcg_zero
);
7603 case 0x2f: /* FABS */
7604 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
7606 case 0x6f: /* FNEG */
7607 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
7609 case 0x7f: /* FSQRT */
7610 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
7612 case 0x1a: /* FCVTNS */
7613 case 0x1b: /* FCVTMS */
7614 case 0x1c: /* FCVTAS */
7615 case 0x3a: /* FCVTPS */
7616 case 0x3b: /* FCVTZS */
7618 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7619 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7620 tcg_temp_free_i32(tcg_shift
);
7623 case 0x5a: /* FCVTNU */
7624 case 0x5b: /* FCVTMU */
7625 case 0x5c: /* FCVTAU */
7626 case 0x7a: /* FCVTPU */
7627 case 0x7b: /* FCVTZU */
7629 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7630 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7631 tcg_temp_free_i32(tcg_shift
);
7634 case 0x18: /* FRINTN */
7635 case 0x19: /* FRINTM */
7636 case 0x38: /* FRINTP */
7637 case 0x39: /* FRINTZ */
7638 case 0x58: /* FRINTA */
7639 case 0x79: /* FRINTI */
7640 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7642 case 0x59: /* FRINTX */
7643 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7646 g_assert_not_reached();
7650 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
7651 bool is_scalar
, bool is_u
, bool is_q
,
7652 int size
, int rn
, int rd
)
7654 bool is_double
= (size
== 3);
7657 if (!fp_access_check(s
)) {
7661 fpst
= get_fpstatus_ptr();
7664 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7665 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7666 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7667 NeonGenTwoDoubleOPFn
*genfn
;
7672 case 0x2e: /* FCMLT (zero) */
7675 case 0x2c: /* FCMGT (zero) */
7676 genfn
= gen_helper_neon_cgt_f64
;
7678 case 0x2d: /* FCMEQ (zero) */
7679 genfn
= gen_helper_neon_ceq_f64
;
7681 case 0x6d: /* FCMLE (zero) */
7684 case 0x6c: /* FCMGE (zero) */
7685 genfn
= gen_helper_neon_cge_f64
;
7688 g_assert_not_reached();
7691 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7692 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7694 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7696 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7698 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7701 clear_vec_high(s
, rd
);
7704 tcg_temp_free_i64(tcg_res
);
7705 tcg_temp_free_i64(tcg_zero
);
7706 tcg_temp_free_i64(tcg_op
);
7708 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7709 TCGv_i32 tcg_zero
= tcg_const_i32(0);
7710 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7711 NeonGenTwoSingleOPFn
*genfn
;
7713 int pass
, maxpasses
;
7716 case 0x2e: /* FCMLT (zero) */
7719 case 0x2c: /* FCMGT (zero) */
7720 genfn
= gen_helper_neon_cgt_f32
;
7722 case 0x2d: /* FCMEQ (zero) */
7723 genfn
= gen_helper_neon_ceq_f32
;
7725 case 0x6d: /* FCMLE (zero) */
7728 case 0x6c: /* FCMGE (zero) */
7729 genfn
= gen_helper_neon_cge_f32
;
7732 g_assert_not_reached();
7738 maxpasses
= is_q
? 4 : 2;
7741 for (pass
= 0; pass
< maxpasses
; pass
++) {
7742 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7744 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7746 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7749 write_fp_sreg(s
, rd
, tcg_res
);
7751 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7754 tcg_temp_free_i32(tcg_res
);
7755 tcg_temp_free_i32(tcg_zero
);
7756 tcg_temp_free_i32(tcg_op
);
7757 if (!is_q
&& !is_scalar
) {
7758 clear_vec_high(s
, rd
);
7762 tcg_temp_free_ptr(fpst
);
7765 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
7766 bool is_scalar
, bool is_u
, bool is_q
,
7767 int size
, int rn
, int rd
)
7769 bool is_double
= (size
== 3);
7770 TCGv_ptr fpst
= get_fpstatus_ptr();
7773 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7774 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7777 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7778 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7780 case 0x3d: /* FRECPE */
7781 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
7783 case 0x3f: /* FRECPX */
7784 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
7786 case 0x7d: /* FRSQRTE */
7787 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
7790 g_assert_not_reached();
7792 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7795 clear_vec_high(s
, rd
);
7798 tcg_temp_free_i64(tcg_res
);
7799 tcg_temp_free_i64(tcg_op
);
7801 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7802 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7803 int pass
, maxpasses
;
7808 maxpasses
= is_q
? 4 : 2;
7811 for (pass
= 0; pass
< maxpasses
; pass
++) {
7812 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7815 case 0x3c: /* URECPE */
7816 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
7818 case 0x3d: /* FRECPE */
7819 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
7821 case 0x3f: /* FRECPX */
7822 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
7824 case 0x7d: /* FRSQRTE */
7825 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
7828 g_assert_not_reached();
7832 write_fp_sreg(s
, rd
, tcg_res
);
7834 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7837 tcg_temp_free_i32(tcg_res
);
7838 tcg_temp_free_i32(tcg_op
);
7839 if (!is_q
&& !is_scalar
) {
7840 clear_vec_high(s
, rd
);
7843 tcg_temp_free_ptr(fpst
);
7846 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
7847 int opcode
, bool u
, bool is_q
,
7848 int size
, int rn
, int rd
)
7850 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
7851 * in the source becomes a size element in the destination).
7854 TCGv_i32 tcg_res
[2];
7855 int destelt
= is_q
? 2 : 0;
7856 int passes
= scalar
? 1 : 2;
7859 tcg_res
[1] = tcg_const_i32(0);
7862 for (pass
= 0; pass
< passes
; pass
++) {
7863 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7864 NeonGenNarrowFn
*genfn
= NULL
;
7865 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
7868 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
7870 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7872 tcg_res
[pass
] = tcg_temp_new_i32();
7875 case 0x12: /* XTN, SQXTUN */
7877 static NeonGenNarrowFn
* const xtnfns
[3] = {
7878 gen_helper_neon_narrow_u8
,
7879 gen_helper_neon_narrow_u16
,
7880 tcg_gen_extrl_i64_i32
,
7882 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
7883 gen_helper_neon_unarrow_sat8
,
7884 gen_helper_neon_unarrow_sat16
,
7885 gen_helper_neon_unarrow_sat32
,
7888 genenvfn
= sqxtunfns
[size
];
7890 genfn
= xtnfns
[size
];
7894 case 0x14: /* SQXTN, UQXTN */
7896 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
7897 { gen_helper_neon_narrow_sat_s8
,
7898 gen_helper_neon_narrow_sat_u8
},
7899 { gen_helper_neon_narrow_sat_s16
,
7900 gen_helper_neon_narrow_sat_u16
},
7901 { gen_helper_neon_narrow_sat_s32
,
7902 gen_helper_neon_narrow_sat_u32
},
7904 genenvfn
= fns
[size
][u
];
7907 case 0x16: /* FCVTN, FCVTN2 */
7908 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
7910 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
7912 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
7913 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
7914 tcg_gen_extr_i64_i32(tcg_lo
, tcg_hi
, tcg_op
);
7915 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, cpu_env
);
7916 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, cpu_env
);
7917 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
7918 tcg_temp_free_i32(tcg_lo
);
7919 tcg_temp_free_i32(tcg_hi
);
7922 case 0x56: /* FCVTXN, FCVTXN2 */
7923 /* 64 bit to 32 bit float conversion
7924 * with von Neumann rounding (round to odd)
7927 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
7930 g_assert_not_reached();
7934 genfn(tcg_res
[pass
], tcg_op
);
7935 } else if (genenvfn
) {
7936 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
7939 tcg_temp_free_i64(tcg_op
);
7942 for (pass
= 0; pass
< 2; pass
++) {
7943 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
7944 tcg_temp_free_i32(tcg_res
[pass
]);
7947 clear_vec_high(s
, rd
);
7951 /* Remaining saturating accumulating ops */
7952 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
7953 bool is_q
, int size
, int rn
, int rd
)
7955 bool is_double
= (size
== 3);
7958 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
7959 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7962 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7963 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
7964 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7966 if (is_u
) { /* USQADD */
7967 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7968 } else { /* SUQADD */
7969 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7971 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7974 clear_vec_high(s
, rd
);
7977 tcg_temp_free_i64(tcg_rd
);
7978 tcg_temp_free_i64(tcg_rn
);
7980 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7981 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7982 int pass
, maxpasses
;
7987 maxpasses
= is_q
? 4 : 2;
7990 for (pass
= 0; pass
< maxpasses
; pass
++) {
7992 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
7993 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
7995 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
7996 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7999 if (is_u
) { /* USQADD */
8002 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8005 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8008 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8011 g_assert_not_reached();
8013 } else { /* SUQADD */
8016 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8019 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8022 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
8025 g_assert_not_reached();
8030 TCGv_i64 tcg_zero
= tcg_const_i64(0);
8031 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
8032 tcg_temp_free_i64(tcg_zero
);
8034 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
8038 clear_vec_high(s
, rd
);
8041 tcg_temp_free_i32(tcg_rd
);
8042 tcg_temp_free_i32(tcg_rn
);
8046 /* C3.6.12 AdvSIMD scalar two reg misc
8047 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
8048 * +-----+---+-----------+------+-----------+--------+-----+------+------+
8049 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
8050 * +-----+---+-----------+------+-----------+--------+-----+------+------+
8052 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
8054 int rd
= extract32(insn
, 0, 5);
8055 int rn
= extract32(insn
, 5, 5);
8056 int opcode
= extract32(insn
, 12, 5);
8057 int size
= extract32(insn
, 22, 2);
8058 bool u
= extract32(insn
, 29, 1);
8059 bool is_fcvt
= false;
8062 TCGv_ptr tcg_fpstatus
;
8065 case 0x3: /* USQADD / SUQADD*/
8066 if (!fp_access_check(s
)) {
8069 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
8071 case 0x7: /* SQABS / SQNEG */
8073 case 0xa: /* CMLT */
8075 unallocated_encoding(s
);
8079 case 0x8: /* CMGT, CMGE */
8080 case 0x9: /* CMEQ, CMLE */
8081 case 0xb: /* ABS, NEG */
8083 unallocated_encoding(s
);
8087 case 0x12: /* SQXTUN */
8089 unallocated_encoding(s
);
8093 case 0x14: /* SQXTN, UQXTN */
8095 unallocated_encoding(s
);
8098 if (!fp_access_check(s
)) {
8101 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
8106 /* Floating point: U, size[1] and opcode indicate operation;
8107 * size[0] indicates single or double precision.
8109 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
8110 size
= extract32(size
, 0, 1) ? 3 : 2;
8112 case 0x2c: /* FCMGT (zero) */
8113 case 0x2d: /* FCMEQ (zero) */
8114 case 0x2e: /* FCMLT (zero) */
8115 case 0x6c: /* FCMGE (zero) */
8116 case 0x6d: /* FCMLE (zero) */
8117 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
8119 case 0x1d: /* SCVTF */
8120 case 0x5d: /* UCVTF */
8122 bool is_signed
= (opcode
== 0x1d);
8123 if (!fp_access_check(s
)) {
8126 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
8129 case 0x3d: /* FRECPE */
8130 case 0x3f: /* FRECPX */
8131 case 0x7d: /* FRSQRTE */
8132 if (!fp_access_check(s
)) {
8135 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
8137 case 0x1a: /* FCVTNS */
8138 case 0x1b: /* FCVTMS */
8139 case 0x3a: /* FCVTPS */
8140 case 0x3b: /* FCVTZS */
8141 case 0x5a: /* FCVTNU */
8142 case 0x5b: /* FCVTMU */
8143 case 0x7a: /* FCVTPU */
8144 case 0x7b: /* FCVTZU */
8146 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
8148 case 0x1c: /* FCVTAS */
8149 case 0x5c: /* FCVTAU */
8150 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
8152 rmode
= FPROUNDING_TIEAWAY
;
8154 case 0x56: /* FCVTXN, FCVTXN2 */
8156 unallocated_encoding(s
);
8159 if (!fp_access_check(s
)) {
8162 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
8165 unallocated_encoding(s
);
8170 unallocated_encoding(s
);
8174 if (!fp_access_check(s
)) {
8179 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
8180 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
8181 tcg_fpstatus
= get_fpstatus_ptr();
8183 TCGV_UNUSED_I32(tcg_rmode
);
8184 TCGV_UNUSED_PTR(tcg_fpstatus
);
8188 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
8189 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
8191 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
8192 write_fp_dreg(s
, rd
, tcg_rd
);
8193 tcg_temp_free_i64(tcg_rd
);
8194 tcg_temp_free_i64(tcg_rn
);
8196 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
8197 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
8199 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
8202 case 0x7: /* SQABS, SQNEG */
8204 NeonGenOneOpEnvFn
*genfn
;
8205 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
8206 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
8207 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
8208 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
8210 genfn
= fns
[size
][u
];
8211 genfn(tcg_rd
, cpu_env
, tcg_rn
);
8214 case 0x1a: /* FCVTNS */
8215 case 0x1b: /* FCVTMS */
8216 case 0x1c: /* FCVTAS */
8217 case 0x3a: /* FCVTPS */
8218 case 0x3b: /* FCVTZS */
8220 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8221 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8222 tcg_temp_free_i32(tcg_shift
);
8225 case 0x5a: /* FCVTNU */
8226 case 0x5b: /* FCVTMU */
8227 case 0x5c: /* FCVTAU */
8228 case 0x7a: /* FCVTPU */
8229 case 0x7b: /* FCVTZU */
8231 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8232 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8233 tcg_temp_free_i32(tcg_shift
);
8237 g_assert_not_reached();
8240 write_fp_sreg(s
, rd
, tcg_rd
);
8241 tcg_temp_free_i32(tcg_rd
);
8242 tcg_temp_free_i32(tcg_rn
);
8246 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
8247 tcg_temp_free_i32(tcg_rmode
);
8248 tcg_temp_free_ptr(tcg_fpstatus
);
8252 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
8253 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
8254 int immh
, int immb
, int opcode
, int rn
, int rd
)
8256 int size
= 32 - clz32(immh
) - 1;
8257 int immhb
= immh
<< 3 | immb
;
8258 int shift
= 2 * (8 << size
) - immhb
;
8259 bool accumulate
= false;
8261 bool insert
= false;
8262 int dsize
= is_q
? 128 : 64;
8263 int esize
= 8 << size
;
8264 int elements
= dsize
/esize
;
8265 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
8266 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8267 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8271 if (extract32(immh
, 3, 1) && !is_q
) {
8272 unallocated_encoding(s
);
8276 if (size
> 3 && !is_q
) {
8277 unallocated_encoding(s
);
8281 if (!fp_access_check(s
)) {
8286 case 0x02: /* SSRA / USRA (accumulate) */
8289 case 0x04: /* SRSHR / URSHR (rounding) */
8292 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8293 accumulate
= round
= true;
8295 case 0x08: /* SRI */
8301 uint64_t round_const
= 1ULL << (shift
- 1);
8302 tcg_round
= tcg_const_i64(round_const
);
8304 TCGV_UNUSED_I64(tcg_round
);
8307 for (i
= 0; i
< elements
; i
++) {
8308 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
8309 if (accumulate
|| insert
) {
8310 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
8314 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
8316 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8317 accumulate
, is_u
, size
, shift
);
8320 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8324 clear_vec_high(s
, rd
);
8328 tcg_temp_free_i64(tcg_round
);
8332 /* SHL/SLI - Vector shift left */
8333 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
8334 int immh
, int immb
, int opcode
, int rn
, int rd
)
8336 int size
= 32 - clz32(immh
) - 1;
8337 int immhb
= immh
<< 3 | immb
;
8338 int shift
= immhb
- (8 << size
);
8339 int dsize
= is_q
? 128 : 64;
8340 int esize
= 8 << size
;
8341 int elements
= dsize
/esize
;
8342 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8343 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8346 if (extract32(immh
, 3, 1) && !is_q
) {
8347 unallocated_encoding(s
);
8351 if (size
> 3 && !is_q
) {
8352 unallocated_encoding(s
);
8356 if (!fp_access_check(s
)) {
8360 for (i
= 0; i
< elements
; i
++) {
8361 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
8363 read_vec_element(s
, tcg_rd
, rd
, i
, size
);
8366 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
8368 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8372 clear_vec_high(s
, rd
);
8376 /* USHLL/SHLL - Vector shift left with widening */
8377 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
8378 int immh
, int immb
, int opcode
, int rn
, int rd
)
8380 int size
= 32 - clz32(immh
) - 1;
8381 int immhb
= immh
<< 3 | immb
;
8382 int shift
= immhb
- (8 << size
);
8384 int esize
= 8 << size
;
8385 int elements
= dsize
/esize
;
8386 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8387 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8391 unallocated_encoding(s
);
8395 if (!fp_access_check(s
)) {
8399 /* For the LL variants the store is larger than the load,
8400 * so if rd == rn we would overwrite parts of our input.
8401 * So load everything right now and use shifts in the main loop.
8403 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
8405 for (i
= 0; i
< elements
; i
++) {
8406 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
8407 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
8408 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
8409 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
8413 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
8414 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
8415 int immh
, int immb
, int opcode
, int rn
, int rd
)
8417 int immhb
= immh
<< 3 | immb
;
8418 int size
= 32 - clz32(immh
) - 1;
8420 int esize
= 8 << size
;
8421 int elements
= dsize
/esize
;
8422 int shift
= (2 * esize
) - immhb
;
8423 bool round
= extract32(opcode
, 0, 1);
8424 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
8428 if (extract32(immh
, 3, 1)) {
8429 unallocated_encoding(s
);
8433 if (!fp_access_check(s
)) {
8437 tcg_rn
= tcg_temp_new_i64();
8438 tcg_rd
= tcg_temp_new_i64();
8439 tcg_final
= tcg_temp_new_i64();
8440 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
8443 uint64_t round_const
= 1ULL << (shift
- 1);
8444 tcg_round
= tcg_const_i64(round_const
);
8446 TCGV_UNUSED_I64(tcg_round
);
8449 for (i
= 0; i
< elements
; i
++) {
8450 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
8451 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8452 false, true, size
+1, shift
);
8454 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8458 clear_vec_high(s
, rd
);
8459 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8461 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8465 tcg_temp_free_i64(tcg_round
);
8467 tcg_temp_free_i64(tcg_rn
);
8468 tcg_temp_free_i64(tcg_rd
);
8469 tcg_temp_free_i64(tcg_final
);
8474 /* C3.6.14 AdvSIMD shift by immediate
8475 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8476 * +---+---+---+-------------+------+------+--------+---+------+------+
8477 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8478 * +---+---+---+-------------+------+------+--------+---+------+------+
8480 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
8482 int rd
= extract32(insn
, 0, 5);
8483 int rn
= extract32(insn
, 5, 5);
8484 int opcode
= extract32(insn
, 11, 5);
8485 int immb
= extract32(insn
, 16, 3);
8486 int immh
= extract32(insn
, 19, 4);
8487 bool is_u
= extract32(insn
, 29, 1);
8488 bool is_q
= extract32(insn
, 30, 1);
8491 case 0x08: /* SRI */
8493 unallocated_encoding(s
);
8497 case 0x00: /* SSHR / USHR */
8498 case 0x02: /* SSRA / USRA (accumulate) */
8499 case 0x04: /* SRSHR / URSHR (rounding) */
8500 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8501 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8503 case 0x0a: /* SHL / SLI */
8504 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8506 case 0x10: /* SHRN */
8507 case 0x11: /* RSHRN / SQRSHRUN */
8509 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
8512 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
8515 case 0x12: /* SQSHRN / UQSHRN */
8516 case 0x13: /* SQRSHRN / UQRSHRN */
8517 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
8520 case 0x14: /* SSHLL / USHLL */
8521 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8523 case 0x1c: /* SCVTF / UCVTF */
8524 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
8527 case 0xc: /* SQSHLU */
8529 unallocated_encoding(s
);
8532 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
8534 case 0xe: /* SQSHL, UQSHL */
8535 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
8537 case 0x1f: /* FCVTZS/ FCVTZU */
8538 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
8541 unallocated_encoding(s
);
8546 /* Generate code to do a "long" addition or subtraction, ie one done in
8547 * TCGv_i64 on vector lanes twice the width specified by size.
8549 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
8550 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
8552 static NeonGenTwo64OpFn
* const fns
[3][2] = {
8553 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
8554 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
8555 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
8557 NeonGenTwo64OpFn
*genfn
;
8560 genfn
= fns
[size
][is_sub
];
8561 genfn(tcg_res
, tcg_op1
, tcg_op2
);
8564 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
8565 int opcode
, int rd
, int rn
, int rm
)
8567 /* 3-reg-different widening insns: 64 x 64 -> 128 */
8568 TCGv_i64 tcg_res
[2];
8571 tcg_res
[0] = tcg_temp_new_i64();
8572 tcg_res
[1] = tcg_temp_new_i64();
8574 /* Does this op do an adding accumulate, a subtracting accumulate,
8575 * or no accumulate at all?
8593 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8594 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8597 /* size == 2 means two 32x32->64 operations; this is worth special
8598 * casing because we can generally handle it inline.
8601 for (pass
= 0; pass
< 2; pass
++) {
8602 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8603 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8604 TCGv_i64 tcg_passres
;
8605 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
8607 int elt
= pass
+ is_q
* 2;
8609 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
8610 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
8613 tcg_passres
= tcg_res
[pass
];
8615 tcg_passres
= tcg_temp_new_i64();
8619 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8620 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8622 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8623 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8625 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8626 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8628 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
8629 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
8631 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
8632 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
8633 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
8635 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
8636 tcg_temp_free_i64(tcg_tmp1
);
8637 tcg_temp_free_i64(tcg_tmp2
);
8640 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8641 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8642 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8643 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8645 case 9: /* SQDMLAL, SQDMLAL2 */
8646 case 11: /* SQDMLSL, SQDMLSL2 */
8647 case 13: /* SQDMULL, SQDMULL2 */
8648 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8649 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
8650 tcg_passres
, tcg_passres
);
8653 g_assert_not_reached();
8656 if (opcode
== 9 || opcode
== 11) {
8657 /* saturating accumulate ops */
8659 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
8661 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
8662 tcg_res
[pass
], tcg_passres
);
8663 } else if (accop
> 0) {
8664 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8665 } else if (accop
< 0) {
8666 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8670 tcg_temp_free_i64(tcg_passres
);
8673 tcg_temp_free_i64(tcg_op1
);
8674 tcg_temp_free_i64(tcg_op2
);
8677 /* size 0 or 1, generally helper functions */
8678 for (pass
= 0; pass
< 2; pass
++) {
8679 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8680 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8681 TCGv_i64 tcg_passres
;
8682 int elt
= pass
+ is_q
* 2;
8684 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
8685 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
8688 tcg_passres
= tcg_res
[pass
];
8690 tcg_passres
= tcg_temp_new_i64();
8694 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8695 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8697 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
8698 static NeonGenWidenFn
* const widenfns
[2][2] = {
8699 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8700 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8702 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8704 widenfn(tcg_op2_64
, tcg_op2
);
8705 widenfn(tcg_passres
, tcg_op1
);
8706 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
8707 tcg_passres
, tcg_op2_64
);
8708 tcg_temp_free_i64(tcg_op2_64
);
8711 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8712 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8715 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8717 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8721 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
8723 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
8727 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8728 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8729 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8732 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
8734 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
8738 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8740 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8744 case 9: /* SQDMLAL, SQDMLAL2 */
8745 case 11: /* SQDMLSL, SQDMLSL2 */
8746 case 13: /* SQDMULL, SQDMULL2 */
8748 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8749 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
8750 tcg_passres
, tcg_passres
);
8752 case 14: /* PMULL */
8754 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
8757 g_assert_not_reached();
8759 tcg_temp_free_i32(tcg_op1
);
8760 tcg_temp_free_i32(tcg_op2
);
8763 if (opcode
== 9 || opcode
== 11) {
8764 /* saturating accumulate ops */
8766 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
8768 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
8772 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
8773 tcg_res
[pass
], tcg_passres
);
8775 tcg_temp_free_i64(tcg_passres
);
8780 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8781 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8782 tcg_temp_free_i64(tcg_res
[0]);
8783 tcg_temp_free_i64(tcg_res
[1]);
8786 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
8787 int opcode
, int rd
, int rn
, int rm
)
8789 TCGv_i64 tcg_res
[2];
8790 int part
= is_q
? 2 : 0;
8793 for (pass
= 0; pass
< 2; pass
++) {
8794 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8795 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8796 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
8797 static NeonGenWidenFn
* const widenfns
[3][2] = {
8798 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8799 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8800 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
8802 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8804 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8805 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
8806 widenfn(tcg_op2_wide
, tcg_op2
);
8807 tcg_temp_free_i32(tcg_op2
);
8808 tcg_res
[pass
] = tcg_temp_new_i64();
8809 gen_neon_addl(size
, (opcode
== 3),
8810 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
8811 tcg_temp_free_i64(tcg_op1
);
8812 tcg_temp_free_i64(tcg_op2_wide
);
8815 for (pass
= 0; pass
< 2; pass
++) {
8816 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8817 tcg_temp_free_i64(tcg_res
[pass
]);
8821 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8823 tcg_gen_addi_i64(in
, in
, 1U << 31);
8824 tcg_gen_extrh_i64_i32(res
, in
);
8827 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
8828 int opcode
, int rd
, int rn
, int rm
)
8830 TCGv_i32 tcg_res
[2];
8831 int part
= is_q
? 2 : 0;
8834 for (pass
= 0; pass
< 2; pass
++) {
8835 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8836 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8837 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
8838 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
8839 { gen_helper_neon_narrow_high_u8
,
8840 gen_helper_neon_narrow_round_high_u8
},
8841 { gen_helper_neon_narrow_high_u16
,
8842 gen_helper_neon_narrow_round_high_u16
},
8843 { tcg_gen_extrh_i64_i32
, do_narrow_round_high_u32
},
8845 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
8847 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8848 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8850 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
8852 tcg_temp_free_i64(tcg_op1
);
8853 tcg_temp_free_i64(tcg_op2
);
8855 tcg_res
[pass
] = tcg_temp_new_i32();
8856 gennarrow(tcg_res
[pass
], tcg_wideres
);
8857 tcg_temp_free_i64(tcg_wideres
);
8860 for (pass
= 0; pass
< 2; pass
++) {
8861 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
8862 tcg_temp_free_i32(tcg_res
[pass
]);
8865 clear_vec_high(s
, rd
);
8869 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
8871 /* PMULL of 64 x 64 -> 128 is an odd special case because it
8872 * is the only three-reg-diff instruction which produces a
8873 * 128-bit wide result from a single operation. However since
8874 * it's possible to calculate the two halves more or less
8875 * separately we just use two helper calls.
8877 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8878 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8879 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8881 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
8882 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
8883 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
8884 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
8885 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
8886 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
8888 tcg_temp_free_i64(tcg_op1
);
8889 tcg_temp_free_i64(tcg_op2
);
8890 tcg_temp_free_i64(tcg_res
);
8893 /* C3.6.15 AdvSIMD three different
8894 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8895 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8896 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8897 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8899 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8901 /* Instructions in this group fall into three basic classes
8902 * (in each case with the operation working on each element in
8903 * the input vectors):
8904 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
8906 * (2) wide 64 x 128 -> 128
8907 * (3) narrowing 128 x 128 -> 64
8908 * Here we do initial decode, catch unallocated cases and
8909 * dispatch to separate functions for each class.
8911 int is_q
= extract32(insn
, 30, 1);
8912 int is_u
= extract32(insn
, 29, 1);
8913 int size
= extract32(insn
, 22, 2);
8914 int opcode
= extract32(insn
, 12, 4);
8915 int rm
= extract32(insn
, 16, 5);
8916 int rn
= extract32(insn
, 5, 5);
8917 int rd
= extract32(insn
, 0, 5);
8920 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
8921 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
8922 /* 64 x 128 -> 128 */
8924 unallocated_encoding(s
);
8927 if (!fp_access_check(s
)) {
8930 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8932 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
8933 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
8934 /* 128 x 128 -> 64 */
8936 unallocated_encoding(s
);
8939 if (!fp_access_check(s
)) {
8942 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8944 case 14: /* PMULL, PMULL2 */
8945 if (is_u
|| size
== 1 || size
== 2) {
8946 unallocated_encoding(s
);
8950 if (!arm_dc_feature(s
, ARM_FEATURE_V8_PMULL
)) {
8951 unallocated_encoding(s
);
8954 if (!fp_access_check(s
)) {
8957 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
8961 case 9: /* SQDMLAL, SQDMLAL2 */
8962 case 11: /* SQDMLSL, SQDMLSL2 */
8963 case 13: /* SQDMULL, SQDMULL2 */
8964 if (is_u
|| size
== 0) {
8965 unallocated_encoding(s
);
8969 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8970 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8971 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8972 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8973 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8974 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8975 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
8976 /* 64 x 64 -> 128 */
8978 unallocated_encoding(s
);
8982 if (!fp_access_check(s
)) {
8986 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8989 /* opcode 15 not allocated */
8990 unallocated_encoding(s
);
8995 /* Logic op (opcode == 3) subgroup of C3.6.16. */
8996 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
8998 int rd
= extract32(insn
, 0, 5);
8999 int rn
= extract32(insn
, 5, 5);
9000 int rm
= extract32(insn
, 16, 5);
9001 int size
= extract32(insn
, 22, 2);
9002 bool is_u
= extract32(insn
, 29, 1);
9003 bool is_q
= extract32(insn
, 30, 1);
9004 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
9007 if (!fp_access_check(s
)) {
9011 tcg_op1
= tcg_temp_new_i64();
9012 tcg_op2
= tcg_temp_new_i64();
9013 tcg_res
[0] = tcg_temp_new_i64();
9014 tcg_res
[1] = tcg_temp_new_i64();
9016 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
9017 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9018 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9023 tcg_gen_and_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9026 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9029 tcg_gen_or_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9032 tcg_gen_orc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9037 /* B* ops need res loaded to operate on */
9038 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9043 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9045 case 1: /* BSL bitwise select */
9046 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_op2
);
9047 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
9048 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op1
);
9050 case 2: /* BIT, bitwise insert if true */
9051 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
9052 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_op2
);
9053 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9055 case 3: /* BIF, bitwise insert if false */
9056 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
9057 tcg_gen_andc_i64(tcg_op1
, tcg_op1
, tcg_op2
);
9058 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9064 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
9066 tcg_gen_movi_i64(tcg_res
[1], 0);
9068 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
9070 tcg_temp_free_i64(tcg_op1
);
9071 tcg_temp_free_i64(tcg_op2
);
9072 tcg_temp_free_i64(tcg_res
[0]);
9073 tcg_temp_free_i64(tcg_res
[1]);
9076 /* Helper functions for 32 bit comparisons */
9077 static void gen_max_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
9079 tcg_gen_movcond_i32(TCG_COND_GE
, res
, op1
, op2
, op1
, op2
);
9082 static void gen_max_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
9084 tcg_gen_movcond_i32(TCG_COND_GEU
, res
, op1
, op2
, op1
, op2
);
9087 static void gen_min_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
9089 tcg_gen_movcond_i32(TCG_COND_LE
, res
, op1
, op2
, op1
, op2
);
9092 static void gen_min_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
9094 tcg_gen_movcond_i32(TCG_COND_LEU
, res
, op1
, op2
, op1
, op2
);
9097 /* Pairwise op subgroup of C3.6.16.
9099 * This is called directly or via the handle_3same_float for float pairwise
9100 * operations where the opcode and size are calculated differently.
9102 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
9103 int size
, int rn
, int rm
, int rd
)
9108 /* Floating point operations need fpst */
9109 if (opcode
>= 0x58) {
9110 fpst
= get_fpstatus_ptr();
9112 TCGV_UNUSED_PTR(fpst
);
9115 if (!fp_access_check(s
)) {
9119 /* These operations work on the concatenated rm:rn, with each pair of
9120 * adjacent elements being operated on to produce an element in the result.
9123 TCGv_i64 tcg_res
[2];
9125 for (pass
= 0; pass
< 2; pass
++) {
9126 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9127 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9128 int passreg
= (pass
== 0) ? rn
: rm
;
9130 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
9131 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
9132 tcg_res
[pass
] = tcg_temp_new_i64();
9135 case 0x17: /* ADDP */
9136 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9138 case 0x58: /* FMAXNMP */
9139 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9141 case 0x5a: /* FADDP */
9142 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9144 case 0x5e: /* FMAXP */
9145 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9147 case 0x78: /* FMINNMP */
9148 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9150 case 0x7e: /* FMINP */
9151 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9154 g_assert_not_reached();
9157 tcg_temp_free_i64(tcg_op1
);
9158 tcg_temp_free_i64(tcg_op2
);
9161 for (pass
= 0; pass
< 2; pass
++) {
9162 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9163 tcg_temp_free_i64(tcg_res
[pass
]);
9166 int maxpass
= is_q
? 4 : 2;
9167 TCGv_i32 tcg_res
[4];
9169 for (pass
= 0; pass
< maxpass
; pass
++) {
9170 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9171 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9172 NeonGenTwoOpFn
*genfn
= NULL
;
9173 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
9174 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
9176 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
9177 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
9178 tcg_res
[pass
] = tcg_temp_new_i32();
9181 case 0x17: /* ADDP */
9183 static NeonGenTwoOpFn
* const fns
[3] = {
9184 gen_helper_neon_padd_u8
,
9185 gen_helper_neon_padd_u16
,
9191 case 0x14: /* SMAXP, UMAXP */
9193 static NeonGenTwoOpFn
* const fns
[3][2] = {
9194 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
9195 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
9196 { gen_max_s32
, gen_max_u32
},
9198 genfn
= fns
[size
][u
];
9201 case 0x15: /* SMINP, UMINP */
9203 static NeonGenTwoOpFn
* const fns
[3][2] = {
9204 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
9205 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
9206 { gen_min_s32
, gen_min_u32
},
9208 genfn
= fns
[size
][u
];
9211 /* The FP operations are all on single floats (32 bit) */
9212 case 0x58: /* FMAXNMP */
9213 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9215 case 0x5a: /* FADDP */
9216 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9218 case 0x5e: /* FMAXP */
9219 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9221 case 0x78: /* FMINNMP */
9222 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9224 case 0x7e: /* FMINP */
9225 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9228 g_assert_not_reached();
9231 /* FP ops called directly, otherwise call now */
9233 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9236 tcg_temp_free_i32(tcg_op1
);
9237 tcg_temp_free_i32(tcg_op2
);
9240 for (pass
= 0; pass
< maxpass
; pass
++) {
9241 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9242 tcg_temp_free_i32(tcg_res
[pass
]);
9245 clear_vec_high(s
, rd
);
9249 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
9250 tcg_temp_free_ptr(fpst
);
9254 /* Floating point op subgroup of C3.6.16. */
9255 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
9257 /* For floating point ops, the U, size[1] and opcode bits
9258 * together indicate the operation. size[0] indicates single
9261 int fpopcode
= extract32(insn
, 11, 5)
9262 | (extract32(insn
, 23, 1) << 5)
9263 | (extract32(insn
, 29, 1) << 6);
9264 int is_q
= extract32(insn
, 30, 1);
9265 int size
= extract32(insn
, 22, 1);
9266 int rm
= extract32(insn
, 16, 5);
9267 int rn
= extract32(insn
, 5, 5);
9268 int rd
= extract32(insn
, 0, 5);
9270 int datasize
= is_q
? 128 : 64;
9271 int esize
= 32 << size
;
9272 int elements
= datasize
/ esize
;
9274 if (size
== 1 && !is_q
) {
9275 unallocated_encoding(s
);
9280 case 0x58: /* FMAXNMP */
9281 case 0x5a: /* FADDP */
9282 case 0x5e: /* FMAXP */
9283 case 0x78: /* FMINNMP */
9284 case 0x7e: /* FMINP */
9285 if (size
&& !is_q
) {
9286 unallocated_encoding(s
);
9289 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
9292 case 0x1b: /* FMULX */
9293 case 0x1f: /* FRECPS */
9294 case 0x3f: /* FRSQRTS */
9295 case 0x5d: /* FACGE */
9296 case 0x7d: /* FACGT */
9297 case 0x19: /* FMLA */
9298 case 0x39: /* FMLS */
9299 case 0x18: /* FMAXNM */
9300 case 0x1a: /* FADD */
9301 case 0x1c: /* FCMEQ */
9302 case 0x1e: /* FMAX */
9303 case 0x38: /* FMINNM */
9304 case 0x3a: /* FSUB */
9305 case 0x3e: /* FMIN */
9306 case 0x5b: /* FMUL */
9307 case 0x5c: /* FCMGE */
9308 case 0x5f: /* FDIV */
9309 case 0x7a: /* FABD */
9310 case 0x7c: /* FCMGT */
9311 if (!fp_access_check(s
)) {
9315 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
9318 unallocated_encoding(s
);
9323 /* Integer op subgroup of C3.6.16. */
9324 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
9326 int is_q
= extract32(insn
, 30, 1);
9327 int u
= extract32(insn
, 29, 1);
9328 int size
= extract32(insn
, 22, 2);
9329 int opcode
= extract32(insn
, 11, 5);
9330 int rm
= extract32(insn
, 16, 5);
9331 int rn
= extract32(insn
, 5, 5);
9332 int rd
= extract32(insn
, 0, 5);
9336 case 0x13: /* MUL, PMUL */
9337 if (u
&& size
!= 0) {
9338 unallocated_encoding(s
);
9342 case 0x0: /* SHADD, UHADD */
9343 case 0x2: /* SRHADD, URHADD */
9344 case 0x4: /* SHSUB, UHSUB */
9345 case 0xc: /* SMAX, UMAX */
9346 case 0xd: /* SMIN, UMIN */
9347 case 0xe: /* SABD, UABD */
9348 case 0xf: /* SABA, UABA */
9349 case 0x12: /* MLA, MLS */
9351 unallocated_encoding(s
);
9355 case 0x16: /* SQDMULH, SQRDMULH */
9356 if (size
== 0 || size
== 3) {
9357 unallocated_encoding(s
);
9362 if (size
== 3 && !is_q
) {
9363 unallocated_encoding(s
);
9369 if (!fp_access_check(s
)) {
9375 for (pass
= 0; pass
< 2; pass
++) {
9376 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9377 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9378 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9380 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9381 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9383 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
9385 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9387 tcg_temp_free_i64(tcg_res
);
9388 tcg_temp_free_i64(tcg_op1
);
9389 tcg_temp_free_i64(tcg_op2
);
9392 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9393 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9394 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9395 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9396 NeonGenTwoOpFn
*genfn
= NULL
;
9397 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
9399 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
9400 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
9403 case 0x0: /* SHADD, UHADD */
9405 static NeonGenTwoOpFn
* const fns
[3][2] = {
9406 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
9407 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
9408 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
9410 genfn
= fns
[size
][u
];
9413 case 0x1: /* SQADD, UQADD */
9415 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9416 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9417 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9418 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9420 genenvfn
= fns
[size
][u
];
9423 case 0x2: /* SRHADD, URHADD */
9425 static NeonGenTwoOpFn
* const fns
[3][2] = {
9426 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
9427 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
9428 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
9430 genfn
= fns
[size
][u
];
9433 case 0x4: /* SHSUB, UHSUB */
9435 static NeonGenTwoOpFn
* const fns
[3][2] = {
9436 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
9437 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
9438 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
9440 genfn
= fns
[size
][u
];
9443 case 0x5: /* SQSUB, UQSUB */
9445 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9446 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9447 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9448 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9450 genenvfn
= fns
[size
][u
];
9453 case 0x6: /* CMGT, CMHI */
9455 static NeonGenTwoOpFn
* const fns
[3][2] = {
9456 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_u8
},
9457 { gen_helper_neon_cgt_s16
, gen_helper_neon_cgt_u16
},
9458 { gen_helper_neon_cgt_s32
, gen_helper_neon_cgt_u32
},
9460 genfn
= fns
[size
][u
];
9463 case 0x7: /* CMGE, CMHS */
9465 static NeonGenTwoOpFn
* const fns
[3][2] = {
9466 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_u8
},
9467 { gen_helper_neon_cge_s16
, gen_helper_neon_cge_u16
},
9468 { gen_helper_neon_cge_s32
, gen_helper_neon_cge_u32
},
9470 genfn
= fns
[size
][u
];
9473 case 0x8: /* SSHL, USHL */
9475 static NeonGenTwoOpFn
* const fns
[3][2] = {
9476 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
9477 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
9478 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
9480 genfn
= fns
[size
][u
];
9483 case 0x9: /* SQSHL, UQSHL */
9485 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9486 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9487 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9488 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9490 genenvfn
= fns
[size
][u
];
9493 case 0xa: /* SRSHL, URSHL */
9495 static NeonGenTwoOpFn
* const fns
[3][2] = {
9496 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
9497 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
9498 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
9500 genfn
= fns
[size
][u
];
9503 case 0xb: /* SQRSHL, UQRSHL */
9505 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9506 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9507 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9508 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9510 genenvfn
= fns
[size
][u
];
9513 case 0xc: /* SMAX, UMAX */
9515 static NeonGenTwoOpFn
* const fns
[3][2] = {
9516 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
9517 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
9518 { gen_max_s32
, gen_max_u32
},
9520 genfn
= fns
[size
][u
];
9524 case 0xd: /* SMIN, UMIN */
9526 static NeonGenTwoOpFn
* const fns
[3][2] = {
9527 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
9528 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
9529 { gen_min_s32
, gen_min_u32
},
9531 genfn
= fns
[size
][u
];
9534 case 0xe: /* SABD, UABD */
9535 case 0xf: /* SABA, UABA */
9537 static NeonGenTwoOpFn
* const fns
[3][2] = {
9538 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
9539 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
9540 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
9542 genfn
= fns
[size
][u
];
9545 case 0x10: /* ADD, SUB */
9547 static NeonGenTwoOpFn
* const fns
[3][2] = {
9548 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9549 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9550 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9552 genfn
= fns
[size
][u
];
9555 case 0x11: /* CMTST, CMEQ */
9557 static NeonGenTwoOpFn
* const fns
[3][2] = {
9558 { gen_helper_neon_tst_u8
, gen_helper_neon_ceq_u8
},
9559 { gen_helper_neon_tst_u16
, gen_helper_neon_ceq_u16
},
9560 { gen_helper_neon_tst_u32
, gen_helper_neon_ceq_u32
},
9562 genfn
= fns
[size
][u
];
9565 case 0x13: /* MUL, PMUL */
9569 genfn
= gen_helper_neon_mul_p8
;
9572 /* fall through : MUL */
9573 case 0x12: /* MLA, MLS */
9575 static NeonGenTwoOpFn
* const fns
[3] = {
9576 gen_helper_neon_mul_u8
,
9577 gen_helper_neon_mul_u16
,
9583 case 0x16: /* SQDMULH, SQRDMULH */
9585 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9586 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9587 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9589 assert(size
== 1 || size
== 2);
9590 genenvfn
= fns
[size
- 1][u
];
9594 g_assert_not_reached();
9598 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
9600 genfn(tcg_res
, tcg_op1
, tcg_op2
);
9603 if (opcode
== 0xf || opcode
== 0x12) {
9604 /* SABA, UABA, MLA, MLS: accumulating ops */
9605 static NeonGenTwoOpFn
* const fns
[3][2] = {
9606 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9607 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9608 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9610 bool is_sub
= (opcode
== 0x12 && u
); /* MLS */
9612 genfn
= fns
[size
][is_sub
];
9613 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
9614 genfn(tcg_res
, tcg_op1
, tcg_res
);
9617 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9619 tcg_temp_free_i32(tcg_res
);
9620 tcg_temp_free_i32(tcg_op1
);
9621 tcg_temp_free_i32(tcg_op2
);
9626 clear_vec_high(s
, rd
);
9630 /* C3.6.16 AdvSIMD three same
9631 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
9632 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9633 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
9634 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9636 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
9638 int opcode
= extract32(insn
, 11, 5);
9641 case 0x3: /* logic ops */
9642 disas_simd_3same_logic(s
, insn
);
9644 case 0x17: /* ADDP */
9645 case 0x14: /* SMAXP, UMAXP */
9646 case 0x15: /* SMINP, UMINP */
9648 /* Pairwise operations */
9649 int is_q
= extract32(insn
, 30, 1);
9650 int u
= extract32(insn
, 29, 1);
9651 int size
= extract32(insn
, 22, 2);
9652 int rm
= extract32(insn
, 16, 5);
9653 int rn
= extract32(insn
, 5, 5);
9654 int rd
= extract32(insn
, 0, 5);
9655 if (opcode
== 0x17) {
9656 if (u
|| (size
== 3 && !is_q
)) {
9657 unallocated_encoding(s
);
9662 unallocated_encoding(s
);
9666 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
9670 /* floating point ops, sz[1] and U are part of opcode */
9671 disas_simd_3same_float(s
, insn
);
9674 disas_simd_3same_int(s
, insn
);
9679 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
9680 int size
, int rn
, int rd
)
9682 /* Handle 2-reg-misc ops which are widening (so each size element
9683 * in the source becomes a 2*size element in the destination.
9684 * The only instruction like this is FCVTL.
9689 /* 32 -> 64 bit fp conversion */
9690 TCGv_i64 tcg_res
[2];
9691 int srcelt
= is_q
? 2 : 0;
9693 for (pass
= 0; pass
< 2; pass
++) {
9694 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9695 tcg_res
[pass
] = tcg_temp_new_i64();
9697 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
9698 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
9699 tcg_temp_free_i32(tcg_op
);
9701 for (pass
= 0; pass
< 2; pass
++) {
9702 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9703 tcg_temp_free_i64(tcg_res
[pass
]);
9706 /* 16 -> 32 bit fp conversion */
9707 int srcelt
= is_q
? 4 : 0;
9708 TCGv_i32 tcg_res
[4];
9710 for (pass
= 0; pass
< 4; pass
++) {
9711 tcg_res
[pass
] = tcg_temp_new_i32();
9713 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
9714 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
9717 for (pass
= 0; pass
< 4; pass
++) {
9718 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9719 tcg_temp_free_i32(tcg_res
[pass
]);
9724 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
9725 bool is_q
, int size
, int rn
, int rd
)
9727 int op
= (opcode
<< 1) | u
;
9728 int opsz
= op
+ size
;
9729 int grp_size
= 3 - opsz
;
9730 int dsize
= is_q
? 128 : 64;
9734 unallocated_encoding(s
);
9738 if (!fp_access_check(s
)) {
9743 /* Special case bytes, use bswap op on each group of elements */
9744 int groups
= dsize
/ (8 << grp_size
);
9746 for (i
= 0; i
< groups
; i
++) {
9747 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9749 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
9752 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
9755 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
9758 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
9761 g_assert_not_reached();
9763 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
9764 tcg_temp_free_i64(tcg_tmp
);
9767 clear_vec_high(s
, rd
);
9770 int revmask
= (1 << grp_size
) - 1;
9771 int esize
= 8 << size
;
9772 int elements
= dsize
/ esize
;
9773 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9774 TCGv_i64 tcg_rd
= tcg_const_i64(0);
9775 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
9777 for (i
= 0; i
< elements
; i
++) {
9778 int e_rev
= (i
& 0xf) ^ revmask
;
9779 int off
= e_rev
* esize
;
9780 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
9782 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
9783 tcg_rn
, off
- 64, esize
);
9785 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
9788 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
9789 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
9791 tcg_temp_free_i64(tcg_rd_hi
);
9792 tcg_temp_free_i64(tcg_rd
);
9793 tcg_temp_free_i64(tcg_rn
);
9797 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
9798 bool is_q
, int size
, int rn
, int rd
)
9800 /* Implement the pairwise operations from 2-misc:
9801 * SADDLP, UADDLP, SADALP, UADALP.
9802 * These all add pairs of elements in the input to produce a
9803 * double-width result element in the output (possibly accumulating).
9805 bool accum
= (opcode
== 0x6);
9806 int maxpass
= is_q
? 2 : 1;
9808 TCGv_i64 tcg_res
[2];
9811 /* 32 + 32 -> 64 op */
9812 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
9814 for (pass
= 0; pass
< maxpass
; pass
++) {
9815 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9816 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9818 tcg_res
[pass
] = tcg_temp_new_i64();
9820 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
9821 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
9822 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9824 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
9825 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9828 tcg_temp_free_i64(tcg_op1
);
9829 tcg_temp_free_i64(tcg_op2
);
9832 for (pass
= 0; pass
< maxpass
; pass
++) {
9833 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9834 NeonGenOneOpFn
*genfn
;
9835 static NeonGenOneOpFn
* const fns
[2][2] = {
9836 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
9837 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
9840 genfn
= fns
[size
][u
];
9842 tcg_res
[pass
] = tcg_temp_new_i64();
9844 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9845 genfn(tcg_res
[pass
], tcg_op
);
9848 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
9850 gen_helper_neon_addl_u16(tcg_res
[pass
],
9851 tcg_res
[pass
], tcg_op
);
9853 gen_helper_neon_addl_u32(tcg_res
[pass
],
9854 tcg_res
[pass
], tcg_op
);
9857 tcg_temp_free_i64(tcg_op
);
9861 tcg_res
[1] = tcg_const_i64(0);
9863 for (pass
= 0; pass
< 2; pass
++) {
9864 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9865 tcg_temp_free_i64(tcg_res
[pass
]);
9869 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
9871 /* Implement SHLL and SHLL2 */
9873 int part
= is_q
? 2 : 0;
9874 TCGv_i64 tcg_res
[2];
9876 for (pass
= 0; pass
< 2; pass
++) {
9877 static NeonGenWidenFn
* const widenfns
[3] = {
9878 gen_helper_neon_widen_u8
,
9879 gen_helper_neon_widen_u16
,
9880 tcg_gen_extu_i32_i64
,
9882 NeonGenWidenFn
*widenfn
= widenfns
[size
];
9883 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9885 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
9886 tcg_res
[pass
] = tcg_temp_new_i64();
9887 widenfn(tcg_res
[pass
], tcg_op
);
9888 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
9890 tcg_temp_free_i32(tcg_op
);
9893 for (pass
= 0; pass
< 2; pass
++) {
9894 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9895 tcg_temp_free_i64(tcg_res
[pass
]);
9899 /* C3.6.17 AdvSIMD two reg misc
9900 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9901 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9902 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9903 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9905 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9907 int size
= extract32(insn
, 22, 2);
9908 int opcode
= extract32(insn
, 12, 5);
9909 bool u
= extract32(insn
, 29, 1);
9910 bool is_q
= extract32(insn
, 30, 1);
9911 int rn
= extract32(insn
, 5, 5);
9912 int rd
= extract32(insn
, 0, 5);
9913 bool need_fpstatus
= false;
9914 bool need_rmode
= false;
9917 TCGv_ptr tcg_fpstatus
;
9920 case 0x0: /* REV64, REV32 */
9921 case 0x1: /* REV16 */
9922 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9924 case 0x5: /* CNT, NOT, RBIT */
9925 if (u
&& size
== 0) {
9926 /* NOT: adjust size so we can use the 64-bits-at-a-time loop. */
9929 } else if (u
&& size
== 1) {
9932 } else if (!u
&& size
== 0) {
9936 unallocated_encoding(s
);
9938 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
9939 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
9941 unallocated_encoding(s
);
9944 if (!fp_access_check(s
)) {
9948 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
9950 case 0x4: /* CLS, CLZ */
9952 unallocated_encoding(s
);
9956 case 0x2: /* SADDLP, UADDLP */
9957 case 0x6: /* SADALP, UADALP */
9959 unallocated_encoding(s
);
9962 if (!fp_access_check(s
)) {
9965 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9967 case 0x13: /* SHLL, SHLL2 */
9968 if (u
== 0 || size
== 3) {
9969 unallocated_encoding(s
);
9972 if (!fp_access_check(s
)) {
9975 handle_shll(s
, is_q
, size
, rn
, rd
);
9977 case 0xa: /* CMLT */
9979 unallocated_encoding(s
);
9983 case 0x8: /* CMGT, CMGE */
9984 case 0x9: /* CMEQ, CMLE */
9985 case 0xb: /* ABS, NEG */
9986 if (size
== 3 && !is_q
) {
9987 unallocated_encoding(s
);
9991 case 0x3: /* SUQADD, USQADD */
9992 if (size
== 3 && !is_q
) {
9993 unallocated_encoding(s
);
9996 if (!fp_access_check(s
)) {
9999 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
10001 case 0x7: /* SQABS, SQNEG */
10002 if (size
== 3 && !is_q
) {
10003 unallocated_encoding(s
);
10008 case 0x16 ... 0x1d:
10011 /* Floating point: U, size[1] and opcode indicate operation;
10012 * size[0] indicates single or double precision.
10014 int is_double
= extract32(size
, 0, 1);
10015 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
10016 size
= is_double
? 3 : 2;
10018 case 0x2f: /* FABS */
10019 case 0x6f: /* FNEG */
10020 if (size
== 3 && !is_q
) {
10021 unallocated_encoding(s
);
10025 case 0x1d: /* SCVTF */
10026 case 0x5d: /* UCVTF */
10028 bool is_signed
= (opcode
== 0x1d) ? true : false;
10029 int elements
= is_double
? 2 : is_q
? 4 : 2;
10030 if (is_double
&& !is_q
) {
10031 unallocated_encoding(s
);
10034 if (!fp_access_check(s
)) {
10037 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
10040 case 0x2c: /* FCMGT (zero) */
10041 case 0x2d: /* FCMEQ (zero) */
10042 case 0x2e: /* FCMLT (zero) */
10043 case 0x6c: /* FCMGE (zero) */
10044 case 0x6d: /* FCMLE (zero) */
10045 if (size
== 3 && !is_q
) {
10046 unallocated_encoding(s
);
10049 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
10051 case 0x7f: /* FSQRT */
10052 if (size
== 3 && !is_q
) {
10053 unallocated_encoding(s
);
10057 case 0x1a: /* FCVTNS */
10058 case 0x1b: /* FCVTMS */
10059 case 0x3a: /* FCVTPS */
10060 case 0x3b: /* FCVTZS */
10061 case 0x5a: /* FCVTNU */
10062 case 0x5b: /* FCVTMU */
10063 case 0x7a: /* FCVTPU */
10064 case 0x7b: /* FCVTZU */
10065 need_fpstatus
= true;
10067 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
10068 if (size
== 3 && !is_q
) {
10069 unallocated_encoding(s
);
10073 case 0x5c: /* FCVTAU */
10074 case 0x1c: /* FCVTAS */
10075 need_fpstatus
= true;
10077 rmode
= FPROUNDING_TIEAWAY
;
10078 if (size
== 3 && !is_q
) {
10079 unallocated_encoding(s
);
10083 case 0x3c: /* URECPE */
10085 unallocated_encoding(s
);
10089 case 0x3d: /* FRECPE */
10090 case 0x7d: /* FRSQRTE */
10091 if (size
== 3 && !is_q
) {
10092 unallocated_encoding(s
);
10095 if (!fp_access_check(s
)) {
10098 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
10100 case 0x56: /* FCVTXN, FCVTXN2 */
10102 unallocated_encoding(s
);
10106 case 0x16: /* FCVTN, FCVTN2 */
10107 /* handle_2misc_narrow does a 2*size -> size operation, but these
10108 * instructions encode the source size rather than dest size.
10110 if (!fp_access_check(s
)) {
10113 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
10115 case 0x17: /* FCVTL, FCVTL2 */
10116 if (!fp_access_check(s
)) {
10119 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
10121 case 0x18: /* FRINTN */
10122 case 0x19: /* FRINTM */
10123 case 0x38: /* FRINTP */
10124 case 0x39: /* FRINTZ */
10126 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
10128 case 0x59: /* FRINTX */
10129 case 0x79: /* FRINTI */
10130 need_fpstatus
= true;
10131 if (size
== 3 && !is_q
) {
10132 unallocated_encoding(s
);
10136 case 0x58: /* FRINTA */
10138 rmode
= FPROUNDING_TIEAWAY
;
10139 need_fpstatus
= true;
10140 if (size
== 3 && !is_q
) {
10141 unallocated_encoding(s
);
10145 case 0x7c: /* URSQRTE */
10147 unallocated_encoding(s
);
10150 need_fpstatus
= true;
10153 unallocated_encoding(s
);
10159 unallocated_encoding(s
);
10163 if (!fp_access_check(s
)) {
10167 if (need_fpstatus
) {
10168 tcg_fpstatus
= get_fpstatus_ptr();
10170 TCGV_UNUSED_PTR(tcg_fpstatus
);
10173 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
10174 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10176 TCGV_UNUSED_I32(tcg_rmode
);
10180 /* All 64-bit element operations can be shared with scalar 2misc */
10183 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
10184 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10185 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10187 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10189 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
10190 tcg_rmode
, tcg_fpstatus
);
10192 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10194 tcg_temp_free_i64(tcg_res
);
10195 tcg_temp_free_i64(tcg_op
);
10200 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
10201 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10202 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10205 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
10208 /* Special cases for 32 bit elements */
10210 case 0xa: /* CMLT */
10211 /* 32 bit integer comparison against zero, result is
10212 * test ? (2^32 - 1) : 0. We implement via setcond(test)
10215 cond
= TCG_COND_LT
;
10217 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
10218 tcg_gen_neg_i32(tcg_res
, tcg_res
);
10220 case 0x8: /* CMGT, CMGE */
10221 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
10223 case 0x9: /* CMEQ, CMLE */
10224 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
10226 case 0x4: /* CLS */
10228 gen_helper_clz32(tcg_res
, tcg_op
);
10230 gen_helper_cls32(tcg_res
, tcg_op
);
10233 case 0x7: /* SQABS, SQNEG */
10235 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
10237 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
10240 case 0xb: /* ABS, NEG */
10242 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10244 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10245 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10246 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
10247 tcg_zero
, tcg_op
, tcg_res
);
10248 tcg_temp_free_i32(tcg_zero
);
10251 case 0x2f: /* FABS */
10252 gen_helper_vfp_abss(tcg_res
, tcg_op
);
10254 case 0x6f: /* FNEG */
10255 gen_helper_vfp_negs(tcg_res
, tcg_op
);
10257 case 0x7f: /* FSQRT */
10258 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
10260 case 0x1a: /* FCVTNS */
10261 case 0x1b: /* FCVTMS */
10262 case 0x1c: /* FCVTAS */
10263 case 0x3a: /* FCVTPS */
10264 case 0x3b: /* FCVTZS */
10266 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10267 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
10268 tcg_shift
, tcg_fpstatus
);
10269 tcg_temp_free_i32(tcg_shift
);
10272 case 0x5a: /* FCVTNU */
10273 case 0x5b: /* FCVTMU */
10274 case 0x5c: /* FCVTAU */
10275 case 0x7a: /* FCVTPU */
10276 case 0x7b: /* FCVTZU */
10278 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10279 gen_helper_vfp_touls(tcg_res
, tcg_op
,
10280 tcg_shift
, tcg_fpstatus
);
10281 tcg_temp_free_i32(tcg_shift
);
10284 case 0x18: /* FRINTN */
10285 case 0x19: /* FRINTM */
10286 case 0x38: /* FRINTP */
10287 case 0x39: /* FRINTZ */
10288 case 0x58: /* FRINTA */
10289 case 0x79: /* FRINTI */
10290 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
10292 case 0x59: /* FRINTX */
10293 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
10295 case 0x7c: /* URSQRTE */
10296 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
10299 g_assert_not_reached();
10302 /* Use helpers for 8 and 16 bit elements */
10304 case 0x5: /* CNT, RBIT */
10305 /* For these two insns size is part of the opcode specifier
10306 * (handled earlier); they always operate on byte elements.
10309 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
10311 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
10314 case 0x7: /* SQABS, SQNEG */
10316 NeonGenOneOpEnvFn
*genfn
;
10317 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
10318 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
10319 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
10321 genfn
= fns
[size
][u
];
10322 genfn(tcg_res
, cpu_env
, tcg_op
);
10325 case 0x8: /* CMGT, CMGE */
10326 case 0x9: /* CMEQ, CMLE */
10327 case 0xa: /* CMLT */
10329 static NeonGenTwoOpFn
* const fns
[3][2] = {
10330 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
10331 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
10332 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
10334 NeonGenTwoOpFn
*genfn
;
10337 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10339 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
10340 comp
= (opcode
- 0x8) * 2 + u
;
10341 /* ...but LE, LT are implemented as reverse GE, GT */
10342 reverse
= (comp
> 2);
10346 genfn
= fns
[comp
][size
];
10348 genfn(tcg_res
, tcg_zero
, tcg_op
);
10350 genfn(tcg_res
, tcg_op
, tcg_zero
);
10352 tcg_temp_free_i32(tcg_zero
);
10355 case 0xb: /* ABS, NEG */
10357 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10359 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
10361 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
10363 tcg_temp_free_i32(tcg_zero
);
10366 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
10368 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
10372 case 0x4: /* CLS, CLZ */
10375 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
10377 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
10381 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
10383 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
10388 g_assert_not_reached();
10392 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10394 tcg_temp_free_i32(tcg_res
);
10395 tcg_temp_free_i32(tcg_op
);
10399 clear_vec_high(s
, rd
);
10403 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10404 tcg_temp_free_i32(tcg_rmode
);
10406 if (need_fpstatus
) {
10407 tcg_temp_free_ptr(tcg_fpstatus
);
10411 /* C3.6.13 AdvSIMD scalar x indexed element
10412 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10413 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10414 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10415 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10416 * C3.6.18 AdvSIMD vector x indexed element
10417 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10418 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10419 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10420 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10422 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
10424 /* This encoding has two kinds of instruction:
10425 * normal, where we perform elt x idxelt => elt for each
10426 * element in the vector
10427 * long, where we perform elt x idxelt and generate a result of
10428 * double the width of the input element
10429 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
10431 bool is_scalar
= extract32(insn
, 28, 1);
10432 bool is_q
= extract32(insn
, 30, 1);
10433 bool u
= extract32(insn
, 29, 1);
10434 int size
= extract32(insn
, 22, 2);
10435 int l
= extract32(insn
, 21, 1);
10436 int m
= extract32(insn
, 20, 1);
10437 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
10438 int rm
= extract32(insn
, 16, 4);
10439 int opcode
= extract32(insn
, 12, 4);
10440 int h
= extract32(insn
, 11, 1);
10441 int rn
= extract32(insn
, 5, 5);
10442 int rd
= extract32(insn
, 0, 5);
10443 bool is_long
= false;
10444 bool is_fp
= false;
10449 case 0x0: /* MLA */
10450 case 0x4: /* MLS */
10451 if (!u
|| is_scalar
) {
10452 unallocated_encoding(s
);
10456 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10457 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10458 case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
10460 unallocated_encoding(s
);
10465 case 0x3: /* SQDMLAL, SQDMLAL2 */
10466 case 0x7: /* SQDMLSL, SQDMLSL2 */
10467 case 0xb: /* SQDMULL, SQDMULL2 */
10470 case 0xc: /* SQDMULH */
10471 case 0xd: /* SQRDMULH */
10473 unallocated_encoding(s
);
10477 case 0x8: /* MUL */
10478 if (u
|| is_scalar
) {
10479 unallocated_encoding(s
);
10483 case 0x1: /* FMLA */
10484 case 0x5: /* FMLS */
10486 unallocated_encoding(s
);
10490 case 0x9: /* FMUL, FMULX */
10491 if (!extract32(size
, 1, 1)) {
10492 unallocated_encoding(s
);
10498 unallocated_encoding(s
);
10503 /* low bit of size indicates single/double */
10504 size
= extract32(size
, 0, 1) ? 3 : 2;
10506 index
= h
<< 1 | l
;
10509 unallocated_encoding(s
);
10518 index
= h
<< 2 | l
<< 1 | m
;
10521 index
= h
<< 1 | l
;
10525 unallocated_encoding(s
);
10530 if (!fp_access_check(s
)) {
10535 fpst
= get_fpstatus_ptr();
10537 TCGV_UNUSED_PTR(fpst
);
10541 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10544 assert(is_fp
&& is_q
&& !is_long
);
10546 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
10548 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10549 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10550 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10552 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10555 case 0x5: /* FMLS */
10556 /* As usual for ARM, separate negation for fused multiply-add */
10557 gen_helper_vfp_negd(tcg_op
, tcg_op
);
10559 case 0x1: /* FMLA */
10560 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10561 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10563 case 0x9: /* FMUL, FMULX */
10565 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10567 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10571 g_assert_not_reached();
10574 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10575 tcg_temp_free_i64(tcg_op
);
10576 tcg_temp_free_i64(tcg_res
);
10580 clear_vec_high(s
, rd
);
10583 tcg_temp_free_i64(tcg_idx
);
10584 } else if (!is_long
) {
10585 /* 32 bit floating point, or 16 or 32 bit integer.
10586 * For the 16 bit scalar case we use the usual Neon helpers and
10587 * rely on the fact that 0 op 0 == 0 with no side effects.
10589 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10590 int pass
, maxpasses
;
10595 maxpasses
= is_q
? 4 : 2;
10598 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10600 if (size
== 1 && !is_scalar
) {
10601 /* The simplest way to handle the 16x16 indexed ops is to duplicate
10602 * the index into both halves of the 32 bit tcg_idx and then use
10603 * the usual Neon helpers.
10605 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10608 for (pass
= 0; pass
< maxpasses
; pass
++) {
10609 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10610 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10612 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
10615 case 0x0: /* MLA */
10616 case 0x4: /* MLS */
10617 case 0x8: /* MUL */
10619 static NeonGenTwoOpFn
* const fns
[2][2] = {
10620 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
10621 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
10623 NeonGenTwoOpFn
*genfn
;
10624 bool is_sub
= opcode
== 0x4;
10627 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
10629 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
10631 if (opcode
== 0x8) {
10634 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
10635 genfn
= fns
[size
- 1][is_sub
];
10636 genfn(tcg_res
, tcg_op
, tcg_res
);
10639 case 0x5: /* FMLS */
10640 /* As usual for ARM, separate negation for fused multiply-add */
10641 gen_helper_vfp_negs(tcg_op
, tcg_op
);
10643 case 0x1: /* FMLA */
10644 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10645 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10647 case 0x9: /* FMUL, FMULX */
10649 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10651 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10654 case 0xc: /* SQDMULH */
10656 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
10659 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
10663 case 0xd: /* SQRDMULH */
10665 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
10668 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
10673 g_assert_not_reached();
10677 write_fp_sreg(s
, rd
, tcg_res
);
10679 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10682 tcg_temp_free_i32(tcg_op
);
10683 tcg_temp_free_i32(tcg_res
);
10686 tcg_temp_free_i32(tcg_idx
);
10689 clear_vec_high(s
, rd
);
10692 /* long ops: 16x16->32 or 32x32->64 */
10693 TCGv_i64 tcg_res
[2];
10695 bool satop
= extract32(opcode
, 0, 1);
10696 TCGMemOp memop
= MO_32
;
10703 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10705 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
10707 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10708 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10709 TCGv_i64 tcg_passres
;
10715 passelt
= pass
+ (is_q
* 2);
10718 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
10720 tcg_res
[pass
] = tcg_temp_new_i64();
10722 if (opcode
== 0xa || opcode
== 0xb) {
10723 /* Non-accumulating ops */
10724 tcg_passres
= tcg_res
[pass
];
10726 tcg_passres
= tcg_temp_new_i64();
10729 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
10730 tcg_temp_free_i64(tcg_op
);
10733 /* saturating, doubling */
10734 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10735 tcg_passres
, tcg_passres
);
10738 if (opcode
== 0xa || opcode
== 0xb) {
10742 /* Accumulating op: handle accumulate step */
10743 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10746 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10747 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10749 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10750 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10752 case 0x7: /* SQDMLSL, SQDMLSL2 */
10753 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10755 case 0x3: /* SQDMLAL, SQDMLAL2 */
10756 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10761 g_assert_not_reached();
10763 tcg_temp_free_i64(tcg_passres
);
10765 tcg_temp_free_i64(tcg_idx
);
10768 clear_vec_high(s
, rd
);
10771 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10774 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10777 /* The simplest way to handle the 16x16 indexed ops is to
10778 * duplicate the index into both halves of the 32 bit tcg_idx
10779 * and then use the usual Neon helpers.
10781 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10784 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10785 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10786 TCGv_i64 tcg_passres
;
10789 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10791 read_vec_element_i32(s
, tcg_op
, rn
,
10792 pass
+ (is_q
* 2), MO_32
);
10795 tcg_res
[pass
] = tcg_temp_new_i64();
10797 if (opcode
== 0xa || opcode
== 0xb) {
10798 /* Non-accumulating ops */
10799 tcg_passres
= tcg_res
[pass
];
10801 tcg_passres
= tcg_temp_new_i64();
10804 if (memop
& MO_SIGN
) {
10805 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
10807 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
10810 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10811 tcg_passres
, tcg_passres
);
10813 tcg_temp_free_i32(tcg_op
);
10815 if (opcode
== 0xa || opcode
== 0xb) {
10819 /* Accumulating op: handle accumulate step */
10820 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10823 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10824 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
10827 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10828 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
10831 case 0x7: /* SQDMLSL, SQDMLSL2 */
10832 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10834 case 0x3: /* SQDMLAL, SQDMLAL2 */
10835 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10840 g_assert_not_reached();
10842 tcg_temp_free_i64(tcg_passres
);
10844 tcg_temp_free_i32(tcg_idx
);
10847 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
10852 tcg_res
[1] = tcg_const_i64(0);
10855 for (pass
= 0; pass
< 2; pass
++) {
10856 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10857 tcg_temp_free_i64(tcg_res
[pass
]);
10861 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
10862 tcg_temp_free_ptr(fpst
);
10866 /* C3.6.19 Crypto AES
10867 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10868 * +-----------------+------+-----------+--------+-----+------+------+
10869 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10870 * +-----------------+------+-----------+--------+-----+------+------+
10872 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
10874 int size
= extract32(insn
, 22, 2);
10875 int opcode
= extract32(insn
, 12, 5);
10876 int rn
= extract32(insn
, 5, 5);
10877 int rd
= extract32(insn
, 0, 5);
10879 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
;
10880 CryptoThreeOpEnvFn
*genfn
;
10882 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)
10884 unallocated_encoding(s
);
10889 case 0x4: /* AESE */
10891 genfn
= gen_helper_crypto_aese
;
10893 case 0x6: /* AESMC */
10895 genfn
= gen_helper_crypto_aesmc
;
10897 case 0x5: /* AESD */
10899 genfn
= gen_helper_crypto_aese
;
10901 case 0x7: /* AESIMC */
10903 genfn
= gen_helper_crypto_aesmc
;
10906 unallocated_encoding(s
);
10910 /* Note that we convert the Vx register indexes into the
10911 * index within the vfp.regs[] array, so we can share the
10912 * helper with the AArch32 instructions.
10914 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10915 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10916 tcg_decrypt
= tcg_const_i32(decrypt
);
10918 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
);
10920 tcg_temp_free_i32(tcg_rd_regno
);
10921 tcg_temp_free_i32(tcg_rn_regno
);
10922 tcg_temp_free_i32(tcg_decrypt
);
10925 /* C3.6.20 Crypto three-reg SHA
10926 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
10927 * +-----------------+------+---+------+---+--------+-----+------+------+
10928 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
10929 * +-----------------+------+---+------+---+--------+-----+------+------+
10931 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
10933 int size
= extract32(insn
, 22, 2);
10934 int opcode
= extract32(insn
, 12, 3);
10935 int rm
= extract32(insn
, 16, 5);
10936 int rn
= extract32(insn
, 5, 5);
10937 int rd
= extract32(insn
, 0, 5);
10938 CryptoThreeOpEnvFn
*genfn
;
10939 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
;
10940 int feature
= ARM_FEATURE_V8_SHA256
;
10943 unallocated_encoding(s
);
10948 case 0: /* SHA1C */
10949 case 1: /* SHA1P */
10950 case 2: /* SHA1M */
10951 case 3: /* SHA1SU0 */
10953 feature
= ARM_FEATURE_V8_SHA1
;
10955 case 4: /* SHA256H */
10956 genfn
= gen_helper_crypto_sha256h
;
10958 case 5: /* SHA256H2 */
10959 genfn
= gen_helper_crypto_sha256h2
;
10961 case 6: /* SHA256SU1 */
10962 genfn
= gen_helper_crypto_sha256su1
;
10965 unallocated_encoding(s
);
10969 if (!arm_dc_feature(s
, feature
)) {
10970 unallocated_encoding(s
);
10974 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10975 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10976 tcg_rm_regno
= tcg_const_i32(rm
<< 1);
10979 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
);
10981 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
10983 gen_helper_crypto_sha1_3reg(cpu_env
, tcg_rd_regno
,
10984 tcg_rn_regno
, tcg_rm_regno
, tcg_opcode
);
10985 tcg_temp_free_i32(tcg_opcode
);
10988 tcg_temp_free_i32(tcg_rd_regno
);
10989 tcg_temp_free_i32(tcg_rn_regno
);
10990 tcg_temp_free_i32(tcg_rm_regno
);
10993 /* C3.6.21 Crypto two-reg SHA
10994 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10995 * +-----------------+------+-----------+--------+-----+------+------+
10996 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10997 * +-----------------+------+-----------+--------+-----+------+------+
10999 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
11001 int size
= extract32(insn
, 22, 2);
11002 int opcode
= extract32(insn
, 12, 5);
11003 int rn
= extract32(insn
, 5, 5);
11004 int rd
= extract32(insn
, 0, 5);
11005 CryptoTwoOpEnvFn
*genfn
;
11007 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
;
11010 unallocated_encoding(s
);
11015 case 0: /* SHA1H */
11016 feature
= ARM_FEATURE_V8_SHA1
;
11017 genfn
= gen_helper_crypto_sha1h
;
11019 case 1: /* SHA1SU1 */
11020 feature
= ARM_FEATURE_V8_SHA1
;
11021 genfn
= gen_helper_crypto_sha1su1
;
11023 case 2: /* SHA256SU0 */
11024 feature
= ARM_FEATURE_V8_SHA256
;
11025 genfn
= gen_helper_crypto_sha256su0
;
11028 unallocated_encoding(s
);
11032 if (!arm_dc_feature(s
, feature
)) {
11033 unallocated_encoding(s
);
11037 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
11038 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
11040 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
);
11042 tcg_temp_free_i32(tcg_rd_regno
);
11043 tcg_temp_free_i32(tcg_rn_regno
);
11046 /* C3.6 Data processing - SIMD, inc Crypto
11048 * As the decode gets a little complex we are using a table based
11049 * approach for this part of the decode.
11051 static const AArch64DecodeTable data_proc_simd
[] = {
11052 /* pattern , mask , fn */
11053 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
11054 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
11055 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
11056 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
11057 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
11058 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
11059 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
11060 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
11061 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
11062 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
11063 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
11064 { 0x2e000000, 0xbf208400, disas_simd_ext
},
11065 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
11066 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
11067 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
11068 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
11069 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
11070 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
11071 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
11072 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
11073 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
11074 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
11075 { 0x00000000, 0x00000000, NULL
}
11078 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
11080 /* Note that this is called with all non-FP cases from
11081 * table C3-6 so it must UNDEF for entries not specifically
11082 * allocated to instructions in that table.
11084 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
11088 unallocated_encoding(s
);
11092 /* C3.6 Data processing - SIMD and floating point */
11093 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
11095 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
11096 disas_data_proc_fp(s
, insn
);
11098 /* SIMD, including crypto */
11099 disas_data_proc_simd(s
, insn
);
11103 /* C3.1 A64 instruction index by encoding */
11104 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
11108 insn
= arm_ldl_code(env
, s
->pc
, s
->sctlr_b
);
11112 s
->fp_access_checked
= false;
11114 switch (extract32(insn
, 25, 4)) {
11115 case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
11116 unallocated_encoding(s
);
11118 case 0x8: case 0x9: /* Data processing - immediate */
11119 disas_data_proc_imm(s
, insn
);
11121 case 0xa: case 0xb: /* Branch, exception generation and system insns */
11122 disas_b_exc_sys(s
, insn
);
11127 case 0xe: /* Loads and stores */
11128 disas_ldst(s
, insn
);
11131 case 0xd: /* Data processing - register */
11132 disas_data_proc_reg(s
, insn
);
11135 case 0xf: /* Data processing - SIMD and floating point */
11136 disas_data_proc_simd_fp(s
, insn
);
11139 assert(FALSE
); /* all 15 cases should be handled above */
11143 /* if we allocated any temporaries, free them here */
11147 void gen_intermediate_code_a64(ARMCPU
*cpu
, TranslationBlock
*tb
)
11149 CPUState
*cs
= CPU(cpu
);
11150 CPUARMState
*env
= &cpu
->env
;
11151 DisasContext dc1
, *dc
= &dc1
;
11152 target_ulong pc_start
;
11153 target_ulong next_page_start
;
11161 dc
->is_jmp
= DISAS_NEXT
;
11163 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
11167 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
11168 * there is no secure EL1, so we route exceptions to EL3.
11170 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
11171 !arm_el_is_aa64(env
, 3);
11174 dc
->be_data
= ARM_TBFLAG_BE_DATA(tb
->flags
) ? MO_BE
: MO_LE
;
11175 dc
->condexec_mask
= 0;
11176 dc
->condexec_cond
= 0;
11177 dc
->mmu_idx
= ARM_TBFLAG_MMUIDX(tb
->flags
);
11178 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
11179 #if !defined(CONFIG_USER_ONLY)
11180 dc
->user
= (dc
->current_el
== 0);
11182 dc
->fp_excp_el
= ARM_TBFLAG_FPEXC_EL(tb
->flags
);
11184 dc
->vec_stride
= 0;
11185 dc
->cp_regs
= cpu
->cp_regs
;
11186 dc
->features
= env
->features
;
11188 /* Single step state. The code-generation logic here is:
11190 * generate code with no special handling for single-stepping (except
11191 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
11192 * this happens anyway because those changes are all system register or
11194 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
11195 * emit code for one insn
11196 * emit code to clear PSTATE.SS
11197 * emit code to generate software step exception for completed step
11198 * end TB (as usual for having generated an exception)
11199 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
11200 * emit code to generate a software step exception
11203 dc
->ss_active
= ARM_TBFLAG_SS_ACTIVE(tb
->flags
);
11204 dc
->pstate_ss
= ARM_TBFLAG_PSTATE_SS(tb
->flags
);
11205 dc
->is_ldex
= false;
11206 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
11208 init_tmp_a64_array(dc
);
11210 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
11212 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
11213 if (max_insns
== 0) {
11214 max_insns
= CF_COUNT_MASK
;
11216 if (max_insns
> TCG_MAX_INSNS
) {
11217 max_insns
= TCG_MAX_INSNS
;
11222 tcg_clear_temp_count();
11225 dc
->insn_start_idx
= tcg_op_buf_count();
11226 tcg_gen_insn_start(dc
->pc
, 0, 0);
11229 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
11231 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
11232 if (bp
->pc
== dc
->pc
) {
11233 if (bp
->flags
& BP_CPU
) {
11234 gen_a64_set_pc_im(dc
->pc
);
11235 gen_helper_check_breakpoints(cpu_env
);
11236 /* End the TB early; it likely won't be executed */
11237 dc
->is_jmp
= DISAS_UPDATE
;
11239 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
11240 /* The address covered by the breakpoint must be
11241 included in [tb->pc, tb->pc + tb->size) in order
11242 to for it to be properly cleared -- thus we
11243 increment the PC here so that the logic setting
11244 tb->size below does the right thing. */
11246 goto done_generating
;
11253 if (num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
11257 if (dc
->ss_active
&& !dc
->pstate_ss
) {
11258 /* Singlestep state is Active-pending.
11259 * If we're in this state at the start of a TB then either
11260 * a) we just took an exception to an EL which is being debugged
11261 * and this is the first insn in the exception handler
11262 * b) debug exceptions were masked and we just unmasked them
11263 * without changing EL (eg by clearing PSTATE.D)
11264 * In either case we're going to take a swstep exception in the
11265 * "did not step an insn" case, and so the syndrome ISV and EX
11266 * bits should be zero.
11268 assert(num_insns
== 1);
11269 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0),
11270 default_exception_el(dc
));
11271 dc
->is_jmp
= DISAS_EXC
;
11275 disas_a64_insn(env
, dc
);
11277 if (tcg_check_temp_count()) {
11278 fprintf(stderr
, "TCG temporary leak before "TARGET_FMT_lx
"\n",
11282 /* Translation stops when a conditional branch is encountered.
11283 * Otherwise the subsequent code could get translated several times.
11284 * Also stop translation when a page boundary is reached. This
11285 * ensures prefetch aborts occur at the right place.
11287 } while (!dc
->is_jmp
&& !tcg_op_buf_full() &&
11288 !cs
->singlestep_enabled
&&
11291 dc
->pc
< next_page_start
&&
11292 num_insns
< max_insns
);
11294 if (tb
->cflags
& CF_LAST_IO
) {
11298 if (unlikely(cs
->singlestep_enabled
|| dc
->ss_active
)
11299 && dc
->is_jmp
!= DISAS_EXC
) {
11300 /* Note that this means single stepping WFI doesn't halt the CPU.
11301 * For conditional branch insns this is harmless unreachable code as
11302 * gen_goto_tb() has already handled emitting the debug exception
11303 * (and thus a tb-jump is not possible when singlestepping).
11305 assert(dc
->is_jmp
!= DISAS_TB_JUMP
);
11306 if (dc
->is_jmp
!= DISAS_JUMP
) {
11307 gen_a64_set_pc_im(dc
->pc
);
11309 if (cs
->singlestep_enabled
) {
11310 gen_exception_internal(EXCP_DEBUG
);
11312 gen_step_complete_exception(dc
);
11315 switch (dc
->is_jmp
) {
11317 gen_goto_tb(dc
, 1, dc
->pc
);
11321 gen_a64_set_pc_im(dc
->pc
);
11324 /* indicate that the hash table must be used to find the next TB */
11325 tcg_gen_exit_tb(0);
11327 case DISAS_TB_JUMP
:
11332 gen_a64_set_pc_im(dc
->pc
);
11333 gen_helper_wfe(cpu_env
);
11336 gen_a64_set_pc_im(dc
->pc
);
11337 gen_helper_yield(cpu_env
);
11340 /* This is a special case because we don't want to just halt the CPU
11341 * if trying to debug across a WFI.
11343 gen_a64_set_pc_im(dc
->pc
);
11344 gen_helper_wfi(cpu_env
);
11345 /* The helper doesn't necessarily throw an exception, but we
11346 * must go back to the main loop to check for interrupts anyway.
11348 tcg_gen_exit_tb(0);
11354 gen_tb_end(tb
, num_insns
);
11357 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
) &&
11358 qemu_log_in_addr_range(pc_start
)) {
11359 qemu_log("----------------\n");
11360 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
11361 log_target_disas(cs
, pc_start
, dc
->pc
- pc_start
,
11362 4 | (bswap_code(dc
->sctlr_b
) ? 2 : 0));
11366 tb
->size
= dc
->pc
- pc_start
;
11367 tb
->icount
= num_insns
;