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/>.
29 #include "translate.h"
30 #include "internals.h"
31 #include "qemu/host-utils.h"
33 #include "exec/semihost.h"
34 #include "exec/gen-icount.h"
36 #include "exec/helper-proto.h"
37 #include "exec/helper-gen.h"
39 #include "trace-tcg.h"
41 static TCGv_i64 cpu_X
[32];
42 static TCGv_i64 cpu_pc
;
44 /* Load/store exclusive handling */
45 static TCGv_i64 cpu_exclusive_high
;
47 static const char *regnames
[] = {
48 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
49 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
50 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
51 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
55 A64_SHIFT_TYPE_LSL
= 0,
56 A64_SHIFT_TYPE_LSR
= 1,
57 A64_SHIFT_TYPE_ASR
= 2,
58 A64_SHIFT_TYPE_ROR
= 3
61 /* Table based decoder typedefs - used when the relevant bits for decode
62 * are too awkwardly scattered across the instruction (eg SIMD).
64 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
66 typedef struct AArch64DecodeTable
{
69 AArch64DecodeFn
*disas_fn
;
72 /* Function prototype for gen_ functions for calling Neon helpers */
73 typedef void NeonGenOneOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
);
74 typedef void NeonGenTwoOpFn(TCGv_i32
, TCGv_i32
, TCGv_i32
);
75 typedef void NeonGenTwoOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
, TCGv_i32
);
76 typedef void NeonGenTwo64OpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
);
77 typedef void NeonGenTwo64OpEnvFn(TCGv_i64
, TCGv_ptr
, TCGv_i64
, TCGv_i64
);
78 typedef void NeonGenNarrowFn(TCGv_i32
, TCGv_i64
);
79 typedef void NeonGenNarrowEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i64
);
80 typedef void NeonGenWidenFn(TCGv_i64
, TCGv_i32
);
81 typedef void NeonGenTwoSingleOPFn(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
82 typedef void NeonGenTwoDoubleOPFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGv_ptr
);
83 typedef void NeonGenOneOpFn(TCGv_i64
, TCGv_i64
);
84 typedef void CryptoTwoOpEnvFn(TCGv_ptr
, TCGv_i32
, TCGv_i32
);
85 typedef void CryptoThreeOpEnvFn(TCGv_ptr
, TCGv_i32
, TCGv_i32
, TCGv_i32
);
87 /* initialize TCG globals. */
88 void a64_translate_init(void)
92 cpu_pc
= tcg_global_mem_new_i64(TCG_AREG0
,
93 offsetof(CPUARMState
, pc
),
95 for (i
= 0; i
< 32; i
++) {
96 cpu_X
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
97 offsetof(CPUARMState
, xregs
[i
]),
101 cpu_exclusive_high
= tcg_global_mem_new_i64(TCG_AREG0
,
102 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
105 static inline ARMMMUIdx
get_a64_user_mem_index(DisasContext
*s
)
107 /* Return the mmu_idx to use for A64 "unprivileged load/store" insns:
108 * if EL1, access as if EL0; otherwise access at current EL
110 switch (s
->mmu_idx
) {
111 case ARMMMUIdx_S12NSE1
:
112 return ARMMMUIdx_S12NSE0
;
113 case ARMMMUIdx_S1SE1
:
114 return ARMMMUIdx_S1SE0
;
116 g_assert_not_reached();
122 void aarch64_cpu_dump_state(CPUState
*cs
, FILE *f
,
123 fprintf_function cpu_fprintf
, int flags
)
125 ARMCPU
*cpu
= ARM_CPU(cs
);
126 CPUARMState
*env
= &cpu
->env
;
127 uint32_t psr
= pstate_read(env
);
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");
140 cpu_fprintf(f
, "PSTATE=%08x (flags %c%c%c%c)\n",
142 psr
& PSTATE_N
? 'N' : '-',
143 psr
& PSTATE_Z
? 'Z' : '-',
144 psr
& PSTATE_C
? 'C' : '-',
145 psr
& PSTATE_V
? 'V' : '-');
146 cpu_fprintf(f
, "\n");
148 if (flags
& CPU_DUMP_FPU
) {
150 for (i
= 0; i
< numvfpregs
; i
+= 2) {
151 uint64_t vlo
= float64_val(env
->vfp
.regs
[i
* 2]);
152 uint64_t vhi
= float64_val(env
->vfp
.regs
[(i
* 2) + 1]);
153 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
" ",
155 vlo
= float64_val(env
->vfp
.regs
[(i
+ 1) * 2]);
156 vhi
= float64_val(env
->vfp
.regs
[((i
+ 1) * 2) + 1]);
157 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
"\n",
160 cpu_fprintf(f
, "FPCR: %08x FPSR: %08x\n",
161 vfp_get_fpcr(env
), vfp_get_fpsr(env
));
165 void gen_a64_set_pc_im(uint64_t val
)
167 tcg_gen_movi_i64(cpu_pc
, val
);
170 typedef struct DisasCompare64
{
175 static void a64_test_cc(DisasCompare64
*c64
, int cc
)
179 arm_test_cc(&c32
, cc
);
181 /* Sign-extend the 32-bit value so that the GE/LT comparisons work
182 * properly. The NE/EQ comparisons are also fine with this choice. */
183 c64
->cond
= c32
.cond
;
184 c64
->value
= tcg_temp_new_i64();
185 tcg_gen_ext_i32_i64(c64
->value
, c32
.value
);
190 static void a64_free_cc(DisasCompare64
*c64
)
192 tcg_temp_free_i64(c64
->value
);
195 static void gen_exception_internal(int excp
)
197 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
199 assert(excp_is_internal(excp
));
200 gen_helper_exception_internal(cpu_env
, tcg_excp
);
201 tcg_temp_free_i32(tcg_excp
);
204 static void gen_exception(int excp
, uint32_t syndrome
, uint32_t target_el
)
206 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
207 TCGv_i32 tcg_syn
= tcg_const_i32(syndrome
);
208 TCGv_i32 tcg_el
= tcg_const_i32(target_el
);
210 gen_helper_exception_with_syndrome(cpu_env
, tcg_excp
,
212 tcg_temp_free_i32(tcg_el
);
213 tcg_temp_free_i32(tcg_syn
);
214 tcg_temp_free_i32(tcg_excp
);
217 static void gen_exception_internal_insn(DisasContext
*s
, int offset
, int excp
)
219 gen_a64_set_pc_im(s
->pc
- offset
);
220 gen_exception_internal(excp
);
221 s
->is_jmp
= DISAS_EXC
;
224 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
,
225 uint32_t syndrome
, uint32_t target_el
)
227 gen_a64_set_pc_im(s
->pc
- offset
);
228 gen_exception(excp
, syndrome
, target_el
);
229 s
->is_jmp
= DISAS_EXC
;
232 static void gen_ss_advance(DisasContext
*s
)
234 /* If the singlestep state is Active-not-pending, advance to
239 gen_helper_clear_pstate_ss(cpu_env
);
243 static void gen_step_complete_exception(DisasContext
*s
)
245 /* We just completed step of an insn. Move from Active-not-pending
246 * to Active-pending, and then also take the swstep exception.
247 * This corresponds to making the (IMPDEF) choice to prioritize
248 * swstep exceptions over asynchronous exceptions taken to an exception
249 * level where debug is disabled. This choice has the advantage that
250 * we do not need to maintain internal state corresponding to the
251 * ISV/EX syndrome bits between completion of the step and generation
252 * of the exception, and our syndrome information is always correct.
255 gen_exception(EXCP_UDEF
, syn_swstep(s
->ss_same_el
, 1, s
->is_ldex
),
256 default_exception_el(s
));
257 s
->is_jmp
= DISAS_EXC
;
260 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
262 /* No direct tb linking with singlestep (either QEMU's or the ARM
263 * debug architecture kind) or deterministic io
265 if (s
->singlestep_enabled
|| s
->ss_active
|| (s
->tb
->cflags
& CF_LAST_IO
)) {
269 /* Only link tbs from inside the same guest page */
270 if ((s
->tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
277 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
279 TranslationBlock
*tb
;
282 if (use_goto_tb(s
, n
, dest
)) {
284 gen_a64_set_pc_im(dest
);
285 tcg_gen_exit_tb((intptr_t)tb
+ n
);
286 s
->is_jmp
= DISAS_TB_JUMP
;
288 gen_a64_set_pc_im(dest
);
290 gen_step_complete_exception(s
);
291 } else if (s
->singlestep_enabled
) {
292 gen_exception_internal(EXCP_DEBUG
);
295 s
->is_jmp
= DISAS_TB_JUMP
;
300 static void unallocated_encoding(DisasContext
*s
)
302 /* Unallocated and reserved encodings are uncategorized */
303 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized(),
304 default_exception_el(s
));
307 #define unsupported_encoding(s, insn) \
309 qemu_log_mask(LOG_UNIMP, \
310 "%s:%d: unsupported instruction encoding 0x%08x " \
311 "at pc=%016" PRIx64 "\n", \
312 __FILE__, __LINE__, insn, s->pc - 4); \
313 unallocated_encoding(s); \
316 static void init_tmp_a64_array(DisasContext
*s
)
318 #ifdef CONFIG_DEBUG_TCG
320 for (i
= 0; i
< ARRAY_SIZE(s
->tmp_a64
); i
++) {
321 TCGV_UNUSED_I64(s
->tmp_a64
[i
]);
324 s
->tmp_a64_count
= 0;
327 static void free_tmp_a64(DisasContext
*s
)
330 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
331 tcg_temp_free_i64(s
->tmp_a64
[i
]);
333 init_tmp_a64_array(s
);
336 static TCGv_i64
new_tmp_a64(DisasContext
*s
)
338 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
339 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
342 static TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
344 TCGv_i64 t
= new_tmp_a64(s
);
345 tcg_gen_movi_i64(t
, 0);
350 * Register access functions
352 * These functions are used for directly accessing a register in where
353 * changes to the final register value are likely to be made. If you
354 * need to use a register for temporary calculation (e.g. index type
355 * operations) use the read_* form.
357 * B1.2.1 Register mappings
359 * In instruction register encoding 31 can refer to ZR (zero register) or
360 * the SP (stack pointer) depending on context. In QEMU's case we map SP
361 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
362 * This is the point of the _sp forms.
364 static TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
367 return new_tmp_a64_zero(s
);
373 /* register access for when 31 == SP */
374 static TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
379 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
380 * representing the register contents. This TCGv is an auto-freed
381 * temporary so it need not be explicitly freed, and may be modified.
383 static TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
385 TCGv_i64 v
= new_tmp_a64(s
);
388 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
390 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
393 tcg_gen_movi_i64(v
, 0);
398 static TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
400 TCGv_i64 v
= new_tmp_a64(s
);
402 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
404 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
409 /* We should have at some point before trying to access an FP register
410 * done the necessary access check, so assert that
411 * (a) we did the check and
412 * (b) we didn't then just plough ahead anyway if it failed.
413 * Print the instruction pattern in the abort message so we can figure
414 * out what we need to fix if a user encounters this problem in the wild.
416 static inline void assert_fp_access_checked(DisasContext
*s
)
418 #ifdef CONFIG_DEBUG_TCG
419 if (unlikely(!s
->fp_access_checked
|| s
->fp_excp_el
)) {
420 fprintf(stderr
, "target-arm: FP access check missing for "
421 "instruction 0x%08x\n", s
->insn
);
427 /* Return the offset into CPUARMState of an element of specified
428 * size, 'element' places in from the least significant end of
429 * the FP/vector register Qn.
431 static inline int vec_reg_offset(DisasContext
*s
, int regno
,
432 int element
, TCGMemOp size
)
434 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
435 #ifdef HOST_WORDS_BIGENDIAN
436 /* This is complicated slightly because vfp.regs[2n] is
437 * still the low half and vfp.regs[2n+1] the high half
438 * of the 128 bit vector, even on big endian systems.
439 * Calculate the offset assuming a fully bigendian 128 bits,
440 * then XOR to account for the order of the two 64 bit halves.
442 offs
+= (16 - ((element
+ 1) * (1 << size
)));
445 offs
+= element
* (1 << size
);
447 assert_fp_access_checked(s
);
451 /* Return the offset into CPUARMState of a slice (from
452 * the least significant end) of FP register Qn (ie
454 * (Note that this is not the same mapping as for A32; see cpu.h)
456 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
458 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
459 #ifdef HOST_WORDS_BIGENDIAN
460 offs
+= (8 - (1 << size
));
462 assert_fp_access_checked(s
);
466 /* Offset of the high half of the 128 bit vector Qn */
467 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
469 assert_fp_access_checked(s
);
470 return offsetof(CPUARMState
, vfp
.regs
[regno
* 2 + 1]);
473 /* Convenience accessors for reading and writing single and double
474 * FP registers. Writing clears the upper parts of the associated
475 * 128 bit vector register, as required by the architecture.
476 * Note that unlike the GP register accessors, the values returned
477 * by the read functions must be manually freed.
479 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
481 TCGv_i64 v
= tcg_temp_new_i64();
483 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
487 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
489 TCGv_i32 v
= tcg_temp_new_i32();
491 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
495 static void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
497 TCGv_i64 tcg_zero
= tcg_const_i64(0);
499 tcg_gen_st_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
500 tcg_gen_st_i64(tcg_zero
, cpu_env
, fp_reg_hi_offset(s
, reg
));
501 tcg_temp_free_i64(tcg_zero
);
504 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
506 TCGv_i64 tmp
= tcg_temp_new_i64();
508 tcg_gen_extu_i32_i64(tmp
, v
);
509 write_fp_dreg(s
, reg
, tmp
);
510 tcg_temp_free_i64(tmp
);
513 static TCGv_ptr
get_fpstatus_ptr(void)
515 TCGv_ptr statusptr
= tcg_temp_new_ptr();
518 /* In A64 all instructions (both FP and Neon) use the FPCR;
519 * there is no equivalent of the A32 Neon "standard FPSCR value"
520 * and all operations use vfp.fp_status.
522 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
523 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
527 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
528 * than the 32 bit equivalent.
530 static inline void gen_set_NZ64(TCGv_i64 result
)
532 TCGv_i64 flag
= tcg_temp_new_i64();
534 tcg_gen_setcondi_i64(TCG_COND_NE
, flag
, result
, 0);
535 tcg_gen_extrl_i64_i32(cpu_ZF
, flag
);
536 tcg_gen_shri_i64(flag
, result
, 32);
537 tcg_gen_extrl_i64_i32(cpu_NF
, flag
);
538 tcg_temp_free_i64(flag
);
541 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
542 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
545 gen_set_NZ64(result
);
547 tcg_gen_extrl_i64_i32(cpu_ZF
, result
);
548 tcg_gen_extrl_i64_i32(cpu_NF
, result
);
550 tcg_gen_movi_i32(cpu_CF
, 0);
551 tcg_gen_movi_i32(cpu_VF
, 0);
554 /* dest = T0 + T1; compute C, N, V and Z flags */
555 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
558 TCGv_i64 result
, flag
, tmp
;
559 result
= tcg_temp_new_i64();
560 flag
= tcg_temp_new_i64();
561 tmp
= tcg_temp_new_i64();
563 tcg_gen_movi_i64(tmp
, 0);
564 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
566 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
568 gen_set_NZ64(result
);
570 tcg_gen_xor_i64(flag
, result
, t0
);
571 tcg_gen_xor_i64(tmp
, t0
, t1
);
572 tcg_gen_andc_i64(flag
, flag
, tmp
);
573 tcg_temp_free_i64(tmp
);
574 tcg_gen_shri_i64(flag
, flag
, 32);
575 tcg_gen_extrl_i64_i32(cpu_VF
, flag
);
577 tcg_gen_mov_i64(dest
, result
);
578 tcg_temp_free_i64(result
);
579 tcg_temp_free_i64(flag
);
581 /* 32 bit arithmetic */
582 TCGv_i32 t0_32
= tcg_temp_new_i32();
583 TCGv_i32 t1_32
= tcg_temp_new_i32();
584 TCGv_i32 tmp
= tcg_temp_new_i32();
586 tcg_gen_movi_i32(tmp
, 0);
587 tcg_gen_extrl_i64_i32(t0_32
, t0
);
588 tcg_gen_extrl_i64_i32(t1_32
, t1
);
589 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
590 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
591 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
592 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
593 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
594 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
596 tcg_temp_free_i32(tmp
);
597 tcg_temp_free_i32(t0_32
);
598 tcg_temp_free_i32(t1_32
);
602 /* dest = T0 - T1; compute C, N, V and Z flags */
603 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
606 /* 64 bit arithmetic */
607 TCGv_i64 result
, flag
, tmp
;
609 result
= tcg_temp_new_i64();
610 flag
= tcg_temp_new_i64();
611 tcg_gen_sub_i64(result
, t0
, t1
);
613 gen_set_NZ64(result
);
615 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
616 tcg_gen_extrl_i64_i32(cpu_CF
, flag
);
618 tcg_gen_xor_i64(flag
, result
, t0
);
619 tmp
= tcg_temp_new_i64();
620 tcg_gen_xor_i64(tmp
, t0
, t1
);
621 tcg_gen_and_i64(flag
, flag
, tmp
);
622 tcg_temp_free_i64(tmp
);
623 tcg_gen_shri_i64(flag
, flag
, 32);
624 tcg_gen_extrl_i64_i32(cpu_VF
, flag
);
625 tcg_gen_mov_i64(dest
, result
);
626 tcg_temp_free_i64(flag
);
627 tcg_temp_free_i64(result
);
629 /* 32 bit arithmetic */
630 TCGv_i32 t0_32
= tcg_temp_new_i32();
631 TCGv_i32 t1_32
= tcg_temp_new_i32();
634 tcg_gen_extrl_i64_i32(t0_32
, t0
);
635 tcg_gen_extrl_i64_i32(t1_32
, t1
);
636 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
637 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
638 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
639 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
640 tmp
= tcg_temp_new_i32();
641 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
642 tcg_temp_free_i32(t0_32
);
643 tcg_temp_free_i32(t1_32
);
644 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
645 tcg_temp_free_i32(tmp
);
646 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
650 /* dest = T0 + T1 + CF; do not compute flags. */
651 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
653 TCGv_i64 flag
= tcg_temp_new_i64();
654 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
655 tcg_gen_add_i64(dest
, t0
, t1
);
656 tcg_gen_add_i64(dest
, dest
, flag
);
657 tcg_temp_free_i64(flag
);
660 tcg_gen_ext32u_i64(dest
, dest
);
664 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
665 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
668 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
669 result
= tcg_temp_new_i64();
670 cf_64
= tcg_temp_new_i64();
671 vf_64
= tcg_temp_new_i64();
672 tmp
= tcg_const_i64(0);
674 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
675 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
676 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
677 tcg_gen_extrl_i64_i32(cpu_CF
, cf_64
);
678 gen_set_NZ64(result
);
680 tcg_gen_xor_i64(vf_64
, result
, t0
);
681 tcg_gen_xor_i64(tmp
, t0
, t1
);
682 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
683 tcg_gen_shri_i64(vf_64
, vf_64
, 32);
684 tcg_gen_extrl_i64_i32(cpu_VF
, vf_64
);
686 tcg_gen_mov_i64(dest
, result
);
688 tcg_temp_free_i64(tmp
);
689 tcg_temp_free_i64(vf_64
);
690 tcg_temp_free_i64(cf_64
);
691 tcg_temp_free_i64(result
);
693 TCGv_i32 t0_32
, t1_32
, tmp
;
694 t0_32
= tcg_temp_new_i32();
695 t1_32
= tcg_temp_new_i32();
696 tmp
= tcg_const_i32(0);
698 tcg_gen_extrl_i64_i32(t0_32
, t0
);
699 tcg_gen_extrl_i64_i32(t1_32
, t1
);
700 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
701 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
703 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
704 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
705 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
706 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
707 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
709 tcg_temp_free_i32(tmp
);
710 tcg_temp_free_i32(t1_32
);
711 tcg_temp_free_i32(t0_32
);
716 * Load/Store generators
720 * Store from GPR register to memory.
722 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
723 TCGv_i64 tcg_addr
, int size
, int memidx
)
726 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, MO_TE
+ size
);
729 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
730 TCGv_i64 tcg_addr
, int size
)
732 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
));
736 * Load from memory to GPR register
738 static void do_gpr_ld_memidx(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
739 int size
, bool is_signed
, bool extend
, int memidx
)
741 TCGMemOp memop
= MO_TE
+ size
;
749 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
751 if (extend
&& is_signed
) {
753 tcg_gen_ext32u_i64(dest
, dest
);
757 static void do_gpr_ld(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
758 int size
, bool is_signed
, bool extend
)
760 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
765 * Store from FP register to memory
767 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
769 /* This writes the bottom N bits of a 128 bit wide vector to memory */
770 TCGv_i64 tmp
= tcg_temp_new_i64();
771 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
773 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TE
+ size
);
775 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
776 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
777 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
778 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
779 tcg_gen_qemu_st_i64(tmp
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
780 tcg_temp_free_i64(tcg_hiaddr
);
783 tcg_temp_free_i64(tmp
);
787 * Load from memory to FP register
789 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
791 /* This always zero-extends and writes to a full 128 bit wide vector */
792 TCGv_i64 tmplo
= tcg_temp_new_i64();
796 TCGMemOp memop
= MO_TE
+ size
;
797 tmphi
= tcg_const_i64(0);
798 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
801 tmphi
= tcg_temp_new_i64();
802 tcg_hiaddr
= tcg_temp_new_i64();
804 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
805 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
806 tcg_gen_qemu_ld_i64(tmphi
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
807 tcg_temp_free_i64(tcg_hiaddr
);
810 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
811 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
813 tcg_temp_free_i64(tmplo
);
814 tcg_temp_free_i64(tmphi
);
818 * Vector load/store helpers.
820 * The principal difference between this and a FP load is that we don't
821 * zero extend as we are filling a partial chunk of the vector register.
822 * These functions don't support 128 bit loads/stores, which would be
823 * normal load/store operations.
825 * The _i32 versions are useful when operating on 32 bit quantities
826 * (eg for floating point single or using Neon helper functions).
829 /* Get value of an element within a vector register */
830 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
831 int element
, TCGMemOp memop
)
833 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
836 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
839 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
842 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
845 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
848 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
851 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
855 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
858 g_assert_not_reached();
862 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
863 int element
, TCGMemOp memop
)
865 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
868 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
871 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
874 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
877 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
881 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
884 g_assert_not_reached();
888 /* Set value of an element within a vector register */
889 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
890 int element
, TCGMemOp memop
)
892 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
895 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
898 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
901 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
904 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
907 g_assert_not_reached();
911 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
912 int destidx
, int element
, TCGMemOp memop
)
914 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
917 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
920 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
923 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
926 g_assert_not_reached();
930 /* Clear the high 64 bits of a 128 bit vector (in general non-quad
931 * vector ops all need to do this).
933 static void clear_vec_high(DisasContext
*s
, int rd
)
935 TCGv_i64 tcg_zero
= tcg_const_i64(0);
937 write_vec_element(s
, tcg_zero
, rd
, 1, MO_64
);
938 tcg_temp_free_i64(tcg_zero
);
941 /* Store from vector register to memory */
942 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
943 TCGv_i64 tcg_addr
, int size
)
945 TCGMemOp memop
= MO_TE
+ size
;
946 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
948 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
949 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
951 tcg_temp_free_i64(tcg_tmp
);
954 /* Load from memory to vector register */
955 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
956 TCGv_i64 tcg_addr
, int size
)
958 TCGMemOp memop
= MO_TE
+ size
;
959 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
961 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
962 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
964 tcg_temp_free_i64(tcg_tmp
);
967 /* Check that FP/Neon access is enabled. If it is, return
968 * true. If not, emit code to generate an appropriate exception,
969 * and return false; the caller should not emit any code for
970 * the instruction. Note that this check must happen after all
971 * unallocated-encoding checks (otherwise the syndrome information
972 * for the resulting exception will be incorrect).
974 static inline bool fp_access_check(DisasContext
*s
)
976 assert(!s
->fp_access_checked
);
977 s
->fp_access_checked
= true;
979 if (!s
->fp_excp_el
) {
983 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false),
989 * This utility function is for doing register extension with an
990 * optional shift. You will likely want to pass a temporary for the
991 * destination register. See DecodeRegExtend() in the ARM ARM.
993 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
994 int option
, unsigned int shift
)
996 int extsize
= extract32(option
, 0, 2);
997 bool is_signed
= extract32(option
, 2, 1);
1002 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1005 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1008 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1011 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1017 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1020 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1023 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1026 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1032 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1036 static inline void gen_check_sp_alignment(DisasContext
*s
)
1038 /* The AArch64 architecture mandates that (if enabled via PSTATE
1039 * or SCTLR bits) there is a check that SP is 16-aligned on every
1040 * SP-relative load or store (with an exception generated if it is not).
1041 * In line with general QEMU practice regarding misaligned accesses,
1042 * we omit these checks for the sake of guest program performance.
1043 * This function is provided as a hook so we can more easily add these
1044 * checks in future (possibly as a "favour catching guest program bugs
1045 * over speed" user selectable option).
1050 * This provides a simple table based table lookup decoder. It is
1051 * intended to be used when the relevant bits for decode are too
1052 * awkwardly placed and switch/if based logic would be confusing and
1053 * deeply nested. Since it's a linear search through the table, tables
1054 * should be kept small.
1056 * It returns the first handler where insn & mask == pattern, or
1057 * NULL if there is no match.
1058 * The table is terminated by an empty mask (i.e. 0)
1060 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1063 const AArch64DecodeTable
*tptr
= table
;
1065 while (tptr
->mask
) {
1066 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1067 return tptr
->disas_fn
;
1075 * the instruction disassembly implemented here matches
1076 * the instruction encoding classifications in chapter 3 (C3)
1077 * of the ARM Architecture Reference Manual (DDI0487A_a)
1080 /* C3.2.7 Unconditional branch (immediate)
1082 * +----+-----------+-------------------------------------+
1083 * | op | 0 0 1 0 1 | imm26 |
1084 * +----+-----------+-------------------------------------+
1086 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1088 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1090 if (insn
& (1U << 31)) {
1091 /* C5.6.26 BL Branch with link */
1092 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1095 /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
1096 gen_goto_tb(s
, 0, addr
);
1099 /* C3.2.1 Compare & branch (immediate)
1100 * 31 30 25 24 23 5 4 0
1101 * +----+-------------+----+---------------------+--------+
1102 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1103 * +----+-------------+----+---------------------+--------+
1105 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1107 unsigned int sf
, op
, rt
;
1109 TCGLabel
*label_match
;
1112 sf
= extract32(insn
, 31, 1);
1113 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1114 rt
= extract32(insn
, 0, 5);
1115 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1117 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1118 label_match
= gen_new_label();
1120 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1121 tcg_cmp
, 0, label_match
);
1123 gen_goto_tb(s
, 0, s
->pc
);
1124 gen_set_label(label_match
);
1125 gen_goto_tb(s
, 1, addr
);
1128 /* C3.2.5 Test & branch (immediate)
1129 * 31 30 25 24 23 19 18 5 4 0
1130 * +----+-------------+----+-------+-------------+------+
1131 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1132 * +----+-------------+----+-------+-------------+------+
1134 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1136 unsigned int bit_pos
, op
, rt
;
1138 TCGLabel
*label_match
;
1141 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1142 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1143 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1144 rt
= extract32(insn
, 0, 5);
1146 tcg_cmp
= tcg_temp_new_i64();
1147 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1148 label_match
= gen_new_label();
1149 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1150 tcg_cmp
, 0, label_match
);
1151 tcg_temp_free_i64(tcg_cmp
);
1152 gen_goto_tb(s
, 0, s
->pc
);
1153 gen_set_label(label_match
);
1154 gen_goto_tb(s
, 1, addr
);
1157 /* C3.2.2 / C5.6.19 Conditional branch (immediate)
1158 * 31 25 24 23 5 4 3 0
1159 * +---------------+----+---------------------+----+------+
1160 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1161 * +---------------+----+---------------------+----+------+
1163 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1168 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1169 unallocated_encoding(s
);
1172 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1173 cond
= extract32(insn
, 0, 4);
1176 /* genuinely conditional branches */
1177 TCGLabel
*label_match
= gen_new_label();
1178 arm_gen_test_cc(cond
, label_match
);
1179 gen_goto_tb(s
, 0, s
->pc
);
1180 gen_set_label(label_match
);
1181 gen_goto_tb(s
, 1, addr
);
1183 /* 0xe and 0xf are both "always" conditions */
1184 gen_goto_tb(s
, 0, addr
);
1189 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1190 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1192 unsigned int selector
= crm
<< 3 | op2
;
1195 unallocated_encoding(s
);
1203 s
->is_jmp
= DISAS_WFI
;
1206 s
->is_jmp
= DISAS_YIELD
;
1209 s
->is_jmp
= DISAS_WFE
;
1213 /* we treat all as NOP at least for now */
1216 /* default specified as NOP equivalent */
1221 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1223 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1226 /* CLREX, DSB, DMB, ISB */
1227 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1228 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1231 unallocated_encoding(s
);
1242 /* We don't emulate caches so barriers are no-ops */
1245 unallocated_encoding(s
);
1250 /* C5.6.130 MSR (immediate) - move immediate to processor state field */
1251 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1252 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1254 int op
= op1
<< 3 | op2
;
1256 case 0x05: /* SPSel */
1257 if (s
->current_el
== 0) {
1258 unallocated_encoding(s
);
1262 case 0x1e: /* DAIFSet */
1263 case 0x1f: /* DAIFClear */
1265 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1266 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1267 gen_a64_set_pc_im(s
->pc
- 4);
1268 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1269 tcg_temp_free_i32(tcg_imm
);
1270 tcg_temp_free_i32(tcg_op
);
1271 s
->is_jmp
= DISAS_UPDATE
;
1275 unallocated_encoding(s
);
1280 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1282 TCGv_i32 tmp
= tcg_temp_new_i32();
1283 TCGv_i32 nzcv
= tcg_temp_new_i32();
1285 /* build bit 31, N */
1286 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1287 /* build bit 30, Z */
1288 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1289 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1290 /* build bit 29, C */
1291 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1292 /* build bit 28, V */
1293 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1294 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1295 /* generate result */
1296 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1298 tcg_temp_free_i32(nzcv
);
1299 tcg_temp_free_i32(tmp
);
1302 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1305 TCGv_i32 nzcv
= tcg_temp_new_i32();
1307 /* take NZCV from R[t] */
1308 tcg_gen_extrl_i64_i32(nzcv
, tcg_rt
);
1311 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1313 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1314 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1316 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1317 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1319 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1320 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1321 tcg_temp_free_i32(nzcv
);
1324 /* C5.6.129 MRS - move from system register
1325 * C5.6.131 MSR (register) - move to system register
1328 * These are all essentially the same insn in 'read' and 'write'
1329 * versions, with varying op0 fields.
1331 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1332 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1333 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1335 const ARMCPRegInfo
*ri
;
1338 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1339 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1340 crn
, crm
, op0
, op1
, op2
));
1343 /* Unknown register; this might be a guest error or a QEMU
1344 * unimplemented feature.
1346 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1347 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1348 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1349 unallocated_encoding(s
);
1353 /* Check access permissions */
1354 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1355 unallocated_encoding(s
);
1360 /* Emit code to perform further access permissions checks at
1361 * runtime; this may result in an exception.
1367 gen_a64_set_pc_im(s
->pc
- 4);
1368 tmpptr
= tcg_const_ptr(ri
);
1369 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1370 tcg_syn
= tcg_const_i32(syndrome
);
1371 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
);
1372 tcg_temp_free_ptr(tmpptr
);
1373 tcg_temp_free_i32(tcg_syn
);
1376 /* Handle special cases first */
1377 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1381 tcg_rt
= cpu_reg(s
, rt
);
1383 gen_get_nzcv(tcg_rt
);
1385 gen_set_nzcv(tcg_rt
);
1388 case ARM_CP_CURRENTEL
:
1389 /* Reads as current EL value from pstate, which is
1390 * guaranteed to be constant by the tb flags.
1392 tcg_rt
= cpu_reg(s
, rt
);
1393 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1396 /* Writes clear the aligned block of memory which rt points into. */
1397 tcg_rt
= cpu_reg(s
, rt
);
1398 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1404 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1408 tcg_rt
= cpu_reg(s
, rt
);
1411 if (ri
->type
& ARM_CP_CONST
) {
1412 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1413 } else if (ri
->readfn
) {
1415 tmpptr
= tcg_const_ptr(ri
);
1416 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1417 tcg_temp_free_ptr(tmpptr
);
1419 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1422 if (ri
->type
& ARM_CP_CONST
) {
1423 /* If not forbidden by access permissions, treat as WI */
1425 } else if (ri
->writefn
) {
1427 tmpptr
= tcg_const_ptr(ri
);
1428 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1429 tcg_temp_free_ptr(tmpptr
);
1431 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1435 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1436 /* I/O operations must end the TB here (whether read or write) */
1438 s
->is_jmp
= DISAS_UPDATE
;
1439 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1440 /* We default to ending the TB on a coprocessor register write,
1441 * but allow this to be suppressed by the register definition
1442 * (usually only necessary to work around guest bugs).
1444 s
->is_jmp
= DISAS_UPDATE
;
1449 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1450 * +---------------------+---+-----+-----+-------+-------+-----+------+
1451 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1452 * +---------------------+---+-----+-----+-------+-------+-----+------+
1454 static void disas_system(DisasContext
*s
, uint32_t insn
)
1456 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1457 l
= extract32(insn
, 21, 1);
1458 op0
= extract32(insn
, 19, 2);
1459 op1
= extract32(insn
, 16, 3);
1460 crn
= extract32(insn
, 12, 4);
1461 crm
= extract32(insn
, 8, 4);
1462 op2
= extract32(insn
, 5, 3);
1463 rt
= extract32(insn
, 0, 5);
1466 if (l
|| rt
!= 31) {
1467 unallocated_encoding(s
);
1471 case 2: /* C5.6.68 HINT */
1472 handle_hint(s
, insn
, op1
, op2
, crm
);
1474 case 3: /* CLREX, DSB, DMB, ISB */
1475 handle_sync(s
, insn
, op1
, op2
, crm
);
1477 case 4: /* C5.6.130 MSR (immediate) */
1478 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1481 unallocated_encoding(s
);
1486 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1489 /* C3.2.3 Exception generation
1491 * 31 24 23 21 20 5 4 2 1 0
1492 * +-----------------+-----+------------------------+-----+----+
1493 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1494 * +-----------------------+------------------------+----------+
1496 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1498 int opc
= extract32(insn
, 21, 3);
1499 int op2_ll
= extract32(insn
, 0, 5);
1500 int imm16
= extract32(insn
, 5, 16);
1505 /* For SVC, HVC and SMC we advance the single-step state
1506 * machine before taking the exception. This is architecturally
1507 * mandated, to ensure that single-stepping a system call
1508 * instruction works properly.
1513 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
),
1514 default_exception_el(s
));
1517 if (s
->current_el
== 0) {
1518 unallocated_encoding(s
);
1521 /* The pre HVC helper handles cases when HVC gets trapped
1522 * as an undefined insn by runtime configuration.
1524 gen_a64_set_pc_im(s
->pc
- 4);
1525 gen_helper_pre_hvc(cpu_env
);
1527 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
), 2);
1530 if (s
->current_el
== 0) {
1531 unallocated_encoding(s
);
1534 gen_a64_set_pc_im(s
->pc
- 4);
1535 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1536 gen_helper_pre_smc(cpu_env
, tmp
);
1537 tcg_temp_free_i32(tmp
);
1539 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
), 3);
1542 unallocated_encoding(s
);
1548 unallocated_encoding(s
);
1552 gen_exception_insn(s
, 4, EXCP_BKPT
, syn_aa64_bkpt(imm16
),
1553 default_exception_el(s
));
1557 unallocated_encoding(s
);
1560 /* HLT. This has two purposes.
1561 * Architecturally, it is an external halting debug instruction.
1562 * Since QEMU doesn't implement external debug, we treat this as
1563 * it is required for halting debug disabled: it will UNDEF.
1564 * Secondly, "HLT 0xf000" is the A64 semihosting syscall instruction.
1566 if (semihosting_enabled() && imm16
== 0xf000) {
1567 #ifndef CONFIG_USER_ONLY
1568 /* In system mode, don't allow userspace access to semihosting,
1569 * to provide some semblance of security (and for consistency
1570 * with our 32-bit semihosting).
1572 if (s
->current_el
== 0) {
1573 unsupported_encoding(s
, insn
);
1577 gen_exception_internal_insn(s
, 0, EXCP_SEMIHOST
);
1579 unsupported_encoding(s
, insn
);
1583 if (op2_ll
< 1 || op2_ll
> 3) {
1584 unallocated_encoding(s
);
1587 /* DCPS1, DCPS2, DCPS3 */
1588 unsupported_encoding(s
, insn
);
1591 unallocated_encoding(s
);
1596 /* C3.2.7 Unconditional branch (register)
1597 * 31 25 24 21 20 16 15 10 9 5 4 0
1598 * +---------------+-------+-------+-------+------+-------+
1599 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1600 * +---------------+-------+-------+-------+------+-------+
1602 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1604 unsigned int opc
, op2
, op3
, rn
, op4
;
1606 opc
= extract32(insn
, 21, 4);
1607 op2
= extract32(insn
, 16, 5);
1608 op3
= extract32(insn
, 10, 6);
1609 rn
= extract32(insn
, 5, 5);
1610 op4
= extract32(insn
, 0, 5);
1612 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1613 unallocated_encoding(s
);
1620 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1623 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1624 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1627 if (s
->current_el
== 0) {
1628 unallocated_encoding(s
);
1631 gen_helper_exception_return(cpu_env
);
1632 s
->is_jmp
= DISAS_JUMP
;
1636 unallocated_encoding(s
);
1638 unsupported_encoding(s
, insn
);
1642 unallocated_encoding(s
);
1646 s
->is_jmp
= DISAS_JUMP
;
1649 /* C3.2 Branches, exception generating and system instructions */
1650 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1652 switch (extract32(insn
, 25, 7)) {
1653 case 0x0a: case 0x0b:
1654 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1655 disas_uncond_b_imm(s
, insn
);
1657 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1658 disas_comp_b_imm(s
, insn
);
1660 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1661 disas_test_b_imm(s
, insn
);
1663 case 0x2a: /* Conditional branch (immediate) */
1664 disas_cond_b_imm(s
, insn
);
1666 case 0x6a: /* Exception generation / System */
1667 if (insn
& (1 << 24)) {
1668 disas_system(s
, insn
);
1673 case 0x6b: /* Unconditional branch (register) */
1674 disas_uncond_b_reg(s
, insn
);
1677 unallocated_encoding(s
);
1683 * Load/Store exclusive instructions are implemented by remembering
1684 * the value/address loaded, and seeing if these are the same
1685 * when the store is performed. This is not actually the architecturally
1686 * mandated semantics, but it works for typical guest code sequences
1687 * and avoids having to monitor regular stores.
1689 * In system emulation mode only one CPU will be running at once, so
1690 * this sequence is effectively atomic. In user emulation mode we
1691 * throw an exception and handle the atomic operation elsewhere.
1693 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
1694 TCGv_i64 addr
, int size
, bool is_pair
)
1696 TCGv_i64 tmp
= tcg_temp_new_i64();
1697 TCGMemOp memop
= MO_TE
+ size
;
1699 g_assert(size
<= 3);
1700 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), memop
);
1703 TCGv_i64 addr2
= tcg_temp_new_i64();
1704 TCGv_i64 hitmp
= tcg_temp_new_i64();
1706 g_assert(size
>= 2);
1707 tcg_gen_addi_i64(addr2
, addr
, 1 << size
);
1708 tcg_gen_qemu_ld_i64(hitmp
, addr2
, get_mem_index(s
), memop
);
1709 tcg_temp_free_i64(addr2
);
1710 tcg_gen_mov_i64(cpu_exclusive_high
, hitmp
);
1711 tcg_gen_mov_i64(cpu_reg(s
, rt2
), hitmp
);
1712 tcg_temp_free_i64(hitmp
);
1715 tcg_gen_mov_i64(cpu_exclusive_val
, tmp
);
1716 tcg_gen_mov_i64(cpu_reg(s
, rt
), tmp
);
1718 tcg_temp_free_i64(tmp
);
1719 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
1722 #ifdef CONFIG_USER_ONLY
1723 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1724 TCGv_i64 addr
, int size
, int is_pair
)
1726 tcg_gen_mov_i64(cpu_exclusive_test
, addr
);
1727 tcg_gen_movi_i32(cpu_exclusive_info
,
1728 size
| is_pair
<< 2 | (rd
<< 4) | (rt
<< 9) | (rt2
<< 14));
1729 gen_exception_internal_insn(s
, 4, EXCP_STREX
);
1732 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1733 TCGv_i64 inaddr
, int size
, int is_pair
)
1735 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1736 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1739 * [addr + datasize] = {Rt2};
1745 * env->exclusive_addr = -1;
1747 TCGLabel
*fail_label
= gen_new_label();
1748 TCGLabel
*done_label
= gen_new_label();
1749 TCGv_i64 addr
= tcg_temp_local_new_i64();
1752 /* Copy input into a local temp so it is not trashed when the
1753 * basic block ends at the branch insn.
1755 tcg_gen_mov_i64(addr
, inaddr
);
1756 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
1758 tmp
= tcg_temp_new_i64();
1759 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), MO_TE
+ size
);
1760 tcg_gen_brcond_i64(TCG_COND_NE
, tmp
, cpu_exclusive_val
, fail_label
);
1761 tcg_temp_free_i64(tmp
);
1764 TCGv_i64 addrhi
= tcg_temp_new_i64();
1765 TCGv_i64 tmphi
= tcg_temp_new_i64();
1767 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1768 tcg_gen_qemu_ld_i64(tmphi
, addrhi
, get_mem_index(s
), MO_TE
+ size
);
1769 tcg_gen_brcond_i64(TCG_COND_NE
, tmphi
, cpu_exclusive_high
, fail_label
);
1771 tcg_temp_free_i64(tmphi
);
1772 tcg_temp_free_i64(addrhi
);
1775 /* We seem to still have the exclusive monitor, so do the store */
1776 tcg_gen_qemu_st_i64(cpu_reg(s
, rt
), addr
, get_mem_index(s
), MO_TE
+ size
);
1778 TCGv_i64 addrhi
= tcg_temp_new_i64();
1780 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1781 tcg_gen_qemu_st_i64(cpu_reg(s
, rt2
), addrhi
,
1782 get_mem_index(s
), MO_TE
+ size
);
1783 tcg_temp_free_i64(addrhi
);
1786 tcg_temp_free_i64(addr
);
1788 tcg_gen_movi_i64(cpu_reg(s
, rd
), 0);
1789 tcg_gen_br(done_label
);
1790 gen_set_label(fail_label
);
1791 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
1792 gen_set_label(done_label
);
1793 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1798 /* C3.3.6 Load/store exclusive
1800 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
1801 * +-----+-------------+----+---+----+------+----+-------+------+------+
1802 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
1803 * +-----+-------------+----+---+----+------+----+-------+------+------+
1805 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
1806 * L: 0 -> store, 1 -> load
1807 * o2: 0 -> exclusive, 1 -> not
1808 * o1: 0 -> single register, 1 -> register pair
1809 * o0: 1 -> load-acquire/store-release, 0 -> not
1811 * o0 == 0 AND o2 == 1 is un-allocated
1812 * o1 == 1 is un-allocated except for 32 and 64 bit sizes
1814 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
1816 int rt
= extract32(insn
, 0, 5);
1817 int rn
= extract32(insn
, 5, 5);
1818 int rt2
= extract32(insn
, 10, 5);
1819 int is_lasr
= extract32(insn
, 15, 1);
1820 int rs
= extract32(insn
, 16, 5);
1821 int is_pair
= extract32(insn
, 21, 1);
1822 int is_store
= !extract32(insn
, 22, 1);
1823 int is_excl
= !extract32(insn
, 23, 1);
1824 int size
= extract32(insn
, 30, 2);
1827 if ((!is_excl
&& !is_lasr
) ||
1828 (is_pair
&& size
< 2)) {
1829 unallocated_encoding(s
);
1834 gen_check_sp_alignment(s
);
1836 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1838 /* Note that since TCG is single threaded load-acquire/store-release
1839 * semantics require no extra if (is_lasr) { ... } handling.
1845 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1847 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1850 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1852 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1854 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, false, false);
1857 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt
);
1858 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
1860 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
1862 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, false, false);
1869 * C3.3.5 Load register (literal)
1871 * 31 30 29 27 26 25 24 23 5 4 0
1872 * +-----+-------+---+-----+-------------------+-------+
1873 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
1874 * +-----+-------+---+-----+-------------------+-------+
1876 * V: 1 -> vector (simd/fp)
1877 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
1878 * 10-> 32 bit signed, 11 -> prefetch
1879 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
1881 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
1883 int rt
= extract32(insn
, 0, 5);
1884 int64_t imm
= sextract32(insn
, 5, 19) << 2;
1885 bool is_vector
= extract32(insn
, 26, 1);
1886 int opc
= extract32(insn
, 30, 2);
1887 bool is_signed
= false;
1889 TCGv_i64 tcg_rt
, tcg_addr
;
1893 unallocated_encoding(s
);
1897 if (!fp_access_check(s
)) {
1902 /* PRFM (literal) : prefetch */
1905 size
= 2 + extract32(opc
, 0, 1);
1906 is_signed
= extract32(opc
, 1, 1);
1909 tcg_rt
= cpu_reg(s
, rt
);
1911 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
1913 do_fp_ld(s
, rt
, tcg_addr
, size
);
1915 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
1917 tcg_temp_free_i64(tcg_addr
);
1921 * C5.6.80 LDNP (Load Pair - non-temporal hint)
1922 * C5.6.81 LDP (Load Pair - non vector)
1923 * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
1924 * C5.6.176 STNP (Store Pair - non-temporal hint)
1925 * C5.6.177 STP (Store Pair - non vector)
1926 * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
1927 * C6.3.165 LDP (Load Pair of SIMD&FP)
1928 * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
1929 * C6.3.284 STP (Store Pair of SIMD&FP)
1931 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
1932 * +-----+-------+---+---+-------+---+-----------------------------+
1933 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
1934 * +-----+-------+---+---+-------+---+-------+-------+------+------+
1936 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
1938 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
1939 * V: 0 -> GPR, 1 -> Vector
1940 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
1941 * 10 -> signed offset, 11 -> pre-index
1942 * L: 0 -> Store 1 -> Load
1944 * Rt, Rt2 = GPR or SIMD registers to be stored
1945 * Rn = general purpose register containing address
1946 * imm7 = signed offset (multiple of 4 or 8 depending on size)
1948 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
1950 int rt
= extract32(insn
, 0, 5);
1951 int rn
= extract32(insn
, 5, 5);
1952 int rt2
= extract32(insn
, 10, 5);
1953 uint64_t offset
= sextract64(insn
, 15, 7);
1954 int index
= extract32(insn
, 23, 2);
1955 bool is_vector
= extract32(insn
, 26, 1);
1956 bool is_load
= extract32(insn
, 22, 1);
1957 int opc
= extract32(insn
, 30, 2);
1959 bool is_signed
= false;
1960 bool postindex
= false;
1963 TCGv_i64 tcg_addr
; /* calculated address */
1967 unallocated_encoding(s
);
1974 size
= 2 + extract32(opc
, 1, 1);
1975 is_signed
= extract32(opc
, 0, 1);
1976 if (!is_load
&& is_signed
) {
1977 unallocated_encoding(s
);
1983 case 1: /* post-index */
1988 /* signed offset with "non-temporal" hint. Since we don't emulate
1989 * caches we don't care about hints to the cache system about
1990 * data access patterns, and handle this identically to plain
1994 /* There is no non-temporal-hint version of LDPSW */
1995 unallocated_encoding(s
);
2000 case 2: /* signed offset, rn not updated */
2003 case 3: /* pre-index */
2009 if (is_vector
&& !fp_access_check(s
)) {
2016 gen_check_sp_alignment(s
);
2019 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2022 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2027 do_fp_ld(s
, rt
, tcg_addr
, size
);
2029 do_fp_st(s
, rt
, tcg_addr
, size
);
2032 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2034 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
2036 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2039 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2042 do_fp_ld(s
, rt2
, tcg_addr
, size
);
2044 do_fp_st(s
, rt2
, tcg_addr
, size
);
2047 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2049 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false);
2051 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
2057 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
2059 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2061 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
2066 * C3.3.8 Load/store (immediate post-indexed)
2067 * C3.3.9 Load/store (immediate pre-indexed)
2068 * C3.3.12 Load/store (unscaled immediate)
2070 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2071 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2072 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2073 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2075 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2077 * V = 0 -> non-vector
2078 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2079 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2081 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
)
2083 int rt
= extract32(insn
, 0, 5);
2084 int rn
= extract32(insn
, 5, 5);
2085 int imm9
= sextract32(insn
, 12, 9);
2086 int opc
= extract32(insn
, 22, 2);
2087 int size
= extract32(insn
, 30, 2);
2088 int idx
= extract32(insn
, 10, 2);
2089 bool is_signed
= false;
2090 bool is_store
= false;
2091 bool is_extended
= false;
2092 bool is_unpriv
= (idx
== 2);
2093 bool is_vector
= extract32(insn
, 26, 1);
2100 size
|= (opc
& 2) << 1;
2101 if (size
> 4 || is_unpriv
) {
2102 unallocated_encoding(s
);
2105 is_store
= ((opc
& 1) == 0);
2106 if (!fp_access_check(s
)) {
2110 if (size
== 3 && opc
== 2) {
2111 /* PRFM - prefetch */
2113 unallocated_encoding(s
);
2118 if (opc
== 3 && size
> 1) {
2119 unallocated_encoding(s
);
2122 is_store
= (opc
== 0);
2123 is_signed
= opc
& (1<<1);
2124 is_extended
= (size
< 3) && (opc
& 1);
2144 gen_check_sp_alignment(s
);
2146 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2149 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2154 do_fp_st(s
, rt
, tcg_addr
, size
);
2156 do_fp_ld(s
, rt
, tcg_addr
, size
);
2159 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2160 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2163 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
);
2165 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
2166 is_signed
, is_extended
, memidx
);
2171 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2173 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2175 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2180 * C3.3.10 Load/store (register offset)
2182 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2183 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2184 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2185 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2188 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2189 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2191 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2192 * opc<0>: 0 -> store, 1 -> load
2193 * V: 1 -> vector/simd
2194 * opt: extend encoding (see DecodeRegExtend)
2195 * S: if S=1 then scale (essentially index by sizeof(size))
2196 * Rt: register to transfer into/out of
2197 * Rn: address register or SP for base
2198 * Rm: offset register or ZR for offset
2200 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
)
2202 int rt
= extract32(insn
, 0, 5);
2203 int rn
= extract32(insn
, 5, 5);
2204 int shift
= extract32(insn
, 12, 1);
2205 int rm
= extract32(insn
, 16, 5);
2206 int opc
= extract32(insn
, 22, 2);
2207 int opt
= extract32(insn
, 13, 3);
2208 int size
= extract32(insn
, 30, 2);
2209 bool is_signed
= false;
2210 bool is_store
= false;
2211 bool is_extended
= false;
2212 bool is_vector
= extract32(insn
, 26, 1);
2217 if (extract32(opt
, 1, 1) == 0) {
2218 unallocated_encoding(s
);
2223 size
|= (opc
& 2) << 1;
2225 unallocated_encoding(s
);
2228 is_store
= !extract32(opc
, 0, 1);
2229 if (!fp_access_check(s
)) {
2233 if (size
== 3 && opc
== 2) {
2234 /* PRFM - prefetch */
2237 if (opc
== 3 && size
> 1) {
2238 unallocated_encoding(s
);
2241 is_store
= (opc
== 0);
2242 is_signed
= extract32(opc
, 1, 1);
2243 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2247 gen_check_sp_alignment(s
);
2249 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2251 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2252 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2254 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2258 do_fp_st(s
, rt
, tcg_addr
, size
);
2260 do_fp_ld(s
, rt
, tcg_addr
, size
);
2263 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2265 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2267 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2273 * C3.3.13 Load/store (unsigned immediate)
2275 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2276 * +----+-------+---+-----+-----+------------+-------+------+
2277 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2278 * +----+-------+---+-----+-----+------------+-------+------+
2281 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2282 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2284 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2285 * opc<0>: 0 -> store, 1 -> load
2286 * Rn: base address register (inc SP)
2287 * Rt: target register
2289 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
)
2291 int rt
= extract32(insn
, 0, 5);
2292 int rn
= extract32(insn
, 5, 5);
2293 unsigned int imm12
= extract32(insn
, 10, 12);
2294 bool is_vector
= extract32(insn
, 26, 1);
2295 int size
= extract32(insn
, 30, 2);
2296 int opc
= extract32(insn
, 22, 2);
2297 unsigned int offset
;
2302 bool is_signed
= false;
2303 bool is_extended
= false;
2306 size
|= (opc
& 2) << 1;
2308 unallocated_encoding(s
);
2311 is_store
= !extract32(opc
, 0, 1);
2312 if (!fp_access_check(s
)) {
2316 if (size
== 3 && opc
== 2) {
2317 /* PRFM - prefetch */
2320 if (opc
== 3 && size
> 1) {
2321 unallocated_encoding(s
);
2324 is_store
= (opc
== 0);
2325 is_signed
= extract32(opc
, 1, 1);
2326 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2330 gen_check_sp_alignment(s
);
2332 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2333 offset
= imm12
<< size
;
2334 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2338 do_fp_st(s
, rt
, tcg_addr
, size
);
2340 do_fp_ld(s
, rt
, tcg_addr
, size
);
2343 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2345 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2347 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2352 /* Load/store register (all forms) */
2353 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2355 switch (extract32(insn
, 24, 2)) {
2357 if (extract32(insn
, 21, 1) == 1 && extract32(insn
, 10, 2) == 2) {
2358 disas_ldst_reg_roffset(s
, insn
);
2360 /* Load/store register (unscaled immediate)
2361 * Load/store immediate pre/post-indexed
2362 * Load/store register unprivileged
2364 disas_ldst_reg_imm9(s
, insn
);
2368 disas_ldst_reg_unsigned_imm(s
, insn
);
2371 unallocated_encoding(s
);
2376 /* C3.3.1 AdvSIMD load/store multiple structures
2378 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2379 * +---+---+---------------+---+-------------+--------+------+------+------+
2380 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2381 * +---+---+---------------+---+-------------+--------+------+------+------+
2383 * C3.3.2 AdvSIMD load/store multiple structures (post-indexed)
2385 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2386 * +---+---+---------------+---+---+---------+--------+------+------+------+
2387 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2388 * +---+---+---------------+---+---+---------+--------+------+------+------+
2390 * Rt: first (or only) SIMD&FP register to be transferred
2391 * Rn: base address or SP
2392 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2394 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
2396 int rt
= extract32(insn
, 0, 5);
2397 int rn
= extract32(insn
, 5, 5);
2398 int size
= extract32(insn
, 10, 2);
2399 int opcode
= extract32(insn
, 12, 4);
2400 bool is_store
= !extract32(insn
, 22, 1);
2401 bool is_postidx
= extract32(insn
, 23, 1);
2402 bool is_q
= extract32(insn
, 30, 1);
2403 TCGv_i64 tcg_addr
, tcg_rn
;
2405 int ebytes
= 1 << size
;
2406 int elements
= (is_q
? 128 : 64) / (8 << size
);
2407 int rpt
; /* num iterations */
2408 int selem
; /* structure elements */
2411 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
2412 unallocated_encoding(s
);
2416 /* From the shared decode logic */
2447 unallocated_encoding(s
);
2451 if (size
== 3 && !is_q
&& selem
!= 1) {
2453 unallocated_encoding(s
);
2457 if (!fp_access_check(s
)) {
2462 gen_check_sp_alignment(s
);
2465 tcg_rn
= cpu_reg_sp(s
, rn
);
2466 tcg_addr
= tcg_temp_new_i64();
2467 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2469 for (r
= 0; r
< rpt
; r
++) {
2471 for (e
= 0; e
< elements
; e
++) {
2472 int tt
= (rt
+ r
) % 32;
2474 for (xs
= 0; xs
< selem
; xs
++) {
2476 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
2478 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
2480 /* For non-quad operations, setting a slice of the low
2481 * 64 bits of the register clears the high 64 bits (in
2482 * the ARM ARM pseudocode this is implicit in the fact
2483 * that 'rval' is a 64 bit wide variable). We optimize
2484 * by noticing that we only need to do this the first
2485 * time we touch a register.
2487 if (!is_q
&& e
== 0 && (r
== 0 || xs
== selem
- 1)) {
2488 clear_vec_high(s
, tt
);
2491 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2498 int rm
= extract32(insn
, 16, 5);
2500 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2502 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2505 tcg_temp_free_i64(tcg_addr
);
2508 /* C3.3.3 AdvSIMD load/store single structure
2510 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2511 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2512 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
2513 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2515 * C3.3.4 AdvSIMD load/store single structure (post-indexed)
2517 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2518 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2519 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
2520 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2522 * Rt: first (or only) SIMD&FP register to be transferred
2523 * Rn: base address or SP
2524 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2525 * index = encoded in Q:S:size dependent on size
2527 * lane_size = encoded in R, opc
2528 * transfer width = encoded in opc, S, size
2530 static void disas_ldst_single_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 S
= extract32(insn
, 12, 1);
2536 int opc
= extract32(insn
, 13, 3);
2537 int R
= extract32(insn
, 21, 1);
2538 int is_load
= extract32(insn
, 22, 1);
2539 int is_postidx
= extract32(insn
, 23, 1);
2540 int is_q
= extract32(insn
, 30, 1);
2542 int scale
= extract32(opc
, 1, 2);
2543 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
2544 bool replicate
= false;
2545 int index
= is_q
<< 3 | S
<< 2 | size
;
2547 TCGv_i64 tcg_addr
, tcg_rn
;
2551 if (!is_load
|| S
) {
2552 unallocated_encoding(s
);
2561 if (extract32(size
, 0, 1)) {
2562 unallocated_encoding(s
);
2568 if (extract32(size
, 1, 1)) {
2569 unallocated_encoding(s
);
2572 if (!extract32(size
, 0, 1)) {
2576 unallocated_encoding(s
);
2584 g_assert_not_reached();
2587 if (!fp_access_check(s
)) {
2591 ebytes
= 1 << scale
;
2594 gen_check_sp_alignment(s
);
2597 tcg_rn
= cpu_reg_sp(s
, rn
);
2598 tcg_addr
= tcg_temp_new_i64();
2599 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2601 for (xs
= 0; xs
< selem
; xs
++) {
2603 /* Load and replicate to all elements */
2605 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
2607 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
2608 get_mem_index(s
), MO_TE
+ scale
);
2611 mulconst
= 0x0101010101010101ULL
;
2614 mulconst
= 0x0001000100010001ULL
;
2617 mulconst
= 0x0000000100000001ULL
;
2623 g_assert_not_reached();
2626 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
2628 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
2630 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
2632 clear_vec_high(s
, rt
);
2634 tcg_temp_free_i64(tcg_tmp
);
2636 /* Load/store one element per register */
2638 do_vec_ld(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2640 do_vec_st(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2643 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2648 int rm
= extract32(insn
, 16, 5);
2650 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2652 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2655 tcg_temp_free_i64(tcg_addr
);
2658 /* C3.3 Loads and stores */
2659 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
2661 switch (extract32(insn
, 24, 6)) {
2662 case 0x08: /* Load/store exclusive */
2663 disas_ldst_excl(s
, insn
);
2665 case 0x18: case 0x1c: /* Load register (literal) */
2666 disas_ld_lit(s
, insn
);
2668 case 0x28: case 0x29:
2669 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
2670 disas_ldst_pair(s
, insn
);
2672 case 0x38: case 0x39:
2673 case 0x3c: case 0x3d: /* Load/store register (all forms) */
2674 disas_ldst_reg(s
, insn
);
2676 case 0x0c: /* AdvSIMD load/store multiple structures */
2677 disas_ldst_multiple_struct(s
, insn
);
2679 case 0x0d: /* AdvSIMD load/store single structure */
2680 disas_ldst_single_struct(s
, insn
);
2683 unallocated_encoding(s
);
2688 /* C3.4.6 PC-rel. addressing
2689 * 31 30 29 28 24 23 5 4 0
2690 * +----+-------+-----------+-------------------+------+
2691 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
2692 * +----+-------+-----------+-------------------+------+
2694 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
2696 unsigned int page
, rd
;
2700 page
= extract32(insn
, 31, 1);
2701 /* SignExtend(immhi:immlo) -> offset */
2702 offset
= sextract64(insn
, 5, 19);
2703 offset
= offset
<< 2 | extract32(insn
, 29, 2);
2704 rd
= extract32(insn
, 0, 5);
2708 /* ADRP (page based) */
2713 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
2717 * C3.4.1 Add/subtract (immediate)
2719 * 31 30 29 28 24 23 22 21 10 9 5 4 0
2720 * +--+--+--+-----------+-----+-------------+-----+-----+
2721 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
2722 * +--+--+--+-----------+-----+-------------+-----+-----+
2724 * sf: 0 -> 32bit, 1 -> 64bit
2725 * op: 0 -> add , 1 -> sub
2727 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
2729 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
2731 int rd
= extract32(insn
, 0, 5);
2732 int rn
= extract32(insn
, 5, 5);
2733 uint64_t imm
= extract32(insn
, 10, 12);
2734 int shift
= extract32(insn
, 22, 2);
2735 bool setflags
= extract32(insn
, 29, 1);
2736 bool sub_op
= extract32(insn
, 30, 1);
2737 bool is_64bit
= extract32(insn
, 31, 1);
2739 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2740 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
2741 TCGv_i64 tcg_result
;
2750 unallocated_encoding(s
);
2754 tcg_result
= tcg_temp_new_i64();
2757 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
2759 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
2762 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
2764 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2766 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2768 tcg_temp_free_i64(tcg_imm
);
2772 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
2774 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
2777 tcg_temp_free_i64(tcg_result
);
2780 /* The input should be a value in the bottom e bits (with higher
2781 * bits zero); returns that value replicated into every element
2782 * of size e in a 64 bit integer.
2784 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
2794 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
2795 static inline uint64_t bitmask64(unsigned int length
)
2797 assert(length
> 0 && length
<= 64);
2798 return ~0ULL >> (64 - length
);
2801 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
2802 * only require the wmask. Returns false if the imms/immr/immn are a reserved
2803 * value (ie should cause a guest UNDEF exception), and true if they are
2804 * valid, in which case the decoded bit pattern is written to result.
2806 static bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
2807 unsigned int imms
, unsigned int immr
)
2810 unsigned e
, levels
, s
, r
;
2813 assert(immn
< 2 && imms
< 64 && immr
< 64);
2815 /* The bit patterns we create here are 64 bit patterns which
2816 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
2817 * 64 bits each. Each element contains the same value: a run
2818 * of between 1 and e-1 non-zero bits, rotated within the
2819 * element by between 0 and e-1 bits.
2821 * The element size and run length are encoded into immn (1 bit)
2822 * and imms (6 bits) as follows:
2823 * 64 bit elements: immn = 1, imms = <length of run - 1>
2824 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
2825 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
2826 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
2827 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
2828 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
2829 * Notice that immn = 0, imms = 11111x is the only combination
2830 * not covered by one of the above options; this is reserved.
2831 * Further, <length of run - 1> all-ones is a reserved pattern.
2833 * In all cases the rotation is by immr % e (and immr is 6 bits).
2836 /* First determine the element size */
2837 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
2839 /* This is the immn == 0, imms == 0x11111x case */
2849 /* <length of run - 1> mustn't be all-ones. */
2853 /* Create the value of one element: s+1 set bits rotated
2854 * by r within the element (which is e bits wide)...
2856 mask
= bitmask64(s
+ 1);
2858 mask
= (mask
>> r
) | (mask
<< (e
- r
));
2859 mask
&= bitmask64(e
);
2861 /* ...then replicate the element over the whole 64 bit value */
2862 mask
= bitfield_replicate(mask
, e
);
2867 /* C3.4.4 Logical (immediate)
2868 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2869 * +----+-----+-------------+---+------+------+------+------+
2870 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
2871 * +----+-----+-------------+---+------+------+------+------+
2873 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
2875 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
2876 TCGv_i64 tcg_rd
, tcg_rn
;
2878 bool is_and
= false;
2880 sf
= extract32(insn
, 31, 1);
2881 opc
= extract32(insn
, 29, 2);
2882 is_n
= extract32(insn
, 22, 1);
2883 immr
= extract32(insn
, 16, 6);
2884 imms
= extract32(insn
, 10, 6);
2885 rn
= extract32(insn
, 5, 5);
2886 rd
= extract32(insn
, 0, 5);
2889 unallocated_encoding(s
);
2893 if (opc
== 0x3) { /* ANDS */
2894 tcg_rd
= cpu_reg(s
, rd
);
2896 tcg_rd
= cpu_reg_sp(s
, rd
);
2898 tcg_rn
= cpu_reg(s
, rn
);
2900 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
2901 /* some immediate field values are reserved */
2902 unallocated_encoding(s
);
2907 wmask
&= 0xffffffff;
2911 case 0x3: /* ANDS */
2913 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
2917 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
2920 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
2923 assert(FALSE
); /* must handle all above */
2927 if (!sf
&& !is_and
) {
2928 /* zero extend final result; we know we can skip this for AND
2929 * since the immediate had the high 32 bits clear.
2931 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2934 if (opc
== 3) { /* ANDS */
2935 gen_logic_CC(sf
, tcg_rd
);
2940 * C3.4.5 Move wide (immediate)
2942 * 31 30 29 28 23 22 21 20 5 4 0
2943 * +--+-----+-------------+-----+----------------+------+
2944 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
2945 * +--+-----+-------------+-----+----------------+------+
2947 * sf: 0 -> 32 bit, 1 -> 64 bit
2948 * opc: 00 -> N, 10 -> Z, 11 -> K
2949 * hw: shift/16 (0,16, and sf only 32, 48)
2951 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
2953 int rd
= extract32(insn
, 0, 5);
2954 uint64_t imm
= extract32(insn
, 5, 16);
2955 int sf
= extract32(insn
, 31, 1);
2956 int opc
= extract32(insn
, 29, 2);
2957 int pos
= extract32(insn
, 21, 2) << 4;
2958 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
2961 if (!sf
&& (pos
>= 32)) {
2962 unallocated_encoding(s
);
2976 tcg_gen_movi_i64(tcg_rd
, imm
);
2979 tcg_imm
= tcg_const_i64(imm
);
2980 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
2981 tcg_temp_free_i64(tcg_imm
);
2983 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2987 unallocated_encoding(s
);
2993 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2994 * +----+-----+-------------+---+------+------+------+------+
2995 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
2996 * +----+-----+-------------+---+------+------+------+------+
2998 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
3000 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
3001 TCGv_i64 tcg_rd
, tcg_tmp
;
3003 sf
= extract32(insn
, 31, 1);
3004 opc
= extract32(insn
, 29, 2);
3005 n
= extract32(insn
, 22, 1);
3006 ri
= extract32(insn
, 16, 6);
3007 si
= extract32(insn
, 10, 6);
3008 rn
= extract32(insn
, 5, 5);
3009 rd
= extract32(insn
, 0, 5);
3010 bitsize
= sf
? 64 : 32;
3012 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
3013 unallocated_encoding(s
);
3017 tcg_rd
= cpu_reg(s
, rd
);
3018 tcg_tmp
= read_cpu_reg(s
, rn
, sf
);
3020 /* Recognize the common aliases. */
3021 if (opc
== 0) { /* SBFM */
3023 if (si
== 7) { /* SXTB */
3024 tcg_gen_ext8s_i64(tcg_rd
, tcg_tmp
);
3026 } else if (si
== 15) { /* SXTH */
3027 tcg_gen_ext16s_i64(tcg_rd
, tcg_tmp
);
3029 } else if (si
== 31) { /* SXTW */
3030 tcg_gen_ext32s_i64(tcg_rd
, tcg_tmp
);
3034 if (si
== 63 || (si
== 31 && ri
<= si
)) { /* ASR */
3036 tcg_gen_ext32s_i64(tcg_tmp
, tcg_tmp
);
3038 tcg_gen_sari_i64(tcg_rd
, tcg_tmp
, ri
);
3043 if (opc
!= 1) { /* SBFM or UBFM */
3044 tcg_gen_movi_i64(tcg_rd
, 0);
3047 /* do the bit move operation */
3049 /* Wd<s-r:0> = Wn<s:r> */
3050 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
3052 len
= (si
- ri
) + 1;
3054 /* Wd<32+s-r,32-r> = Wn<s:0> */
3059 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
3061 if (opc
== 0) { /* SBFM - sign extend the destination field */
3062 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
3063 tcg_gen_sari_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
3067 if (!sf
) { /* zero extend final result */
3068 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3073 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3074 * +----+------+-------------+---+----+------+--------+------+------+
3075 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3076 * +----+------+-------------+---+----+------+--------+------+------+
3078 static void disas_extract(DisasContext
*s
, uint32_t insn
)
3080 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
3082 sf
= extract32(insn
, 31, 1);
3083 n
= extract32(insn
, 22, 1);
3084 rm
= extract32(insn
, 16, 5);
3085 imm
= extract32(insn
, 10, 6);
3086 rn
= extract32(insn
, 5, 5);
3087 rd
= extract32(insn
, 0, 5);
3088 op21
= extract32(insn
, 29, 2);
3089 op0
= extract32(insn
, 21, 1);
3090 bitsize
= sf
? 64 : 32;
3092 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
3093 unallocated_encoding(s
);
3095 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
3097 tcg_rd
= cpu_reg(s
, rd
);
3100 /* OPTME: we can special case rm==rn as a rotate */
3101 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3102 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3103 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
3104 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
3105 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
3107 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3110 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3111 * so an extract from bit 0 is a special case.
3114 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
3116 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
3123 /* C3.4 Data processing - immediate */
3124 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
3126 switch (extract32(insn
, 23, 6)) {
3127 case 0x20: case 0x21: /* PC-rel. addressing */
3128 disas_pc_rel_adr(s
, insn
);
3130 case 0x22: case 0x23: /* Add/subtract (immediate) */
3131 disas_add_sub_imm(s
, insn
);
3133 case 0x24: /* Logical (immediate) */
3134 disas_logic_imm(s
, insn
);
3136 case 0x25: /* Move wide (immediate) */
3137 disas_movw_imm(s
, insn
);
3139 case 0x26: /* Bitfield */
3140 disas_bitfield(s
, insn
);
3142 case 0x27: /* Extract */
3143 disas_extract(s
, insn
);
3146 unallocated_encoding(s
);
3151 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3152 * Note that it is the caller's responsibility to ensure that the
3153 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3154 * mandated semantics for out of range shifts.
3156 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3157 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
3159 switch (shift_type
) {
3160 case A64_SHIFT_TYPE_LSL
:
3161 tcg_gen_shl_i64(dst
, src
, shift_amount
);
3163 case A64_SHIFT_TYPE_LSR
:
3164 tcg_gen_shr_i64(dst
, src
, shift_amount
);
3166 case A64_SHIFT_TYPE_ASR
:
3168 tcg_gen_ext32s_i64(dst
, src
);
3170 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
3172 case A64_SHIFT_TYPE_ROR
:
3174 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
3177 t0
= tcg_temp_new_i32();
3178 t1
= tcg_temp_new_i32();
3179 tcg_gen_extrl_i64_i32(t0
, src
);
3180 tcg_gen_extrl_i64_i32(t1
, shift_amount
);
3181 tcg_gen_rotr_i32(t0
, t0
, t1
);
3182 tcg_gen_extu_i32_i64(dst
, t0
);
3183 tcg_temp_free_i32(t0
);
3184 tcg_temp_free_i32(t1
);
3188 assert(FALSE
); /* all shift types should be handled */
3192 if (!sf
) { /* zero extend final result */
3193 tcg_gen_ext32u_i64(dst
, dst
);
3197 /* Shift a TCGv src by immediate, put result in dst.
3198 * The shift amount must be in range (this should always be true as the
3199 * relevant instructions will UNDEF on bad shift immediates).
3201 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3202 enum a64_shift_type shift_type
, unsigned int shift_i
)
3204 assert(shift_i
< (sf
? 64 : 32));
3207 tcg_gen_mov_i64(dst
, src
);
3209 TCGv_i64 shift_const
;
3211 shift_const
= tcg_const_i64(shift_i
);
3212 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
3213 tcg_temp_free_i64(shift_const
);
3217 /* C3.5.10 Logical (shifted register)
3218 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3219 * +----+-----+-----------+-------+---+------+--------+------+------+
3220 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3221 * +----+-----+-----------+-------+---+------+--------+------+------+
3223 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
3225 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
3226 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
3228 sf
= extract32(insn
, 31, 1);
3229 opc
= extract32(insn
, 29, 2);
3230 shift_type
= extract32(insn
, 22, 2);
3231 invert
= extract32(insn
, 21, 1);
3232 rm
= extract32(insn
, 16, 5);
3233 shift_amount
= extract32(insn
, 10, 6);
3234 rn
= extract32(insn
, 5, 5);
3235 rd
= extract32(insn
, 0, 5);
3237 if (!sf
&& (shift_amount
& (1 << 5))) {
3238 unallocated_encoding(s
);
3242 tcg_rd
= cpu_reg(s
, rd
);
3244 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3245 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3246 * register-register MOV and MVN, so it is worth special casing.
3248 tcg_rm
= cpu_reg(s
, rm
);
3250 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3252 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3256 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3258 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3264 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3267 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3270 tcg_rn
= cpu_reg(s
, rn
);
3272 switch (opc
| (invert
<< 2)) {
3275 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3278 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3281 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3285 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3288 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3291 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3299 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3303 gen_logic_CC(sf
, tcg_rd
);
3308 * C3.5.1 Add/subtract (extended register)
3310 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3311 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3312 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3313 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3315 * sf: 0 -> 32bit, 1 -> 64bit
3316 * op: 0 -> add , 1 -> sub
3319 * option: extension type (see DecodeRegExtend)
3320 * imm3: optional shift to Rm
3322 * Rd = Rn + LSL(extend(Rm), amount)
3324 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3326 int rd
= extract32(insn
, 0, 5);
3327 int rn
= extract32(insn
, 5, 5);
3328 int imm3
= extract32(insn
, 10, 3);
3329 int option
= extract32(insn
, 13, 3);
3330 int rm
= extract32(insn
, 16, 5);
3331 bool setflags
= extract32(insn
, 29, 1);
3332 bool sub_op
= extract32(insn
, 30, 1);
3333 bool sf
= extract32(insn
, 31, 1);
3335 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3337 TCGv_i64 tcg_result
;
3340 unallocated_encoding(s
);
3344 /* non-flag setting ops may use SP */
3346 tcg_rd
= cpu_reg_sp(s
, rd
);
3348 tcg_rd
= cpu_reg(s
, rd
);
3350 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3352 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3353 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3355 tcg_result
= tcg_temp_new_i64();
3359 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3361 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3365 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3367 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3372 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3374 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3377 tcg_temp_free_i64(tcg_result
);
3381 * C3.5.2 Add/subtract (shifted register)
3383 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3384 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3385 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3386 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3388 * sf: 0 -> 32bit, 1 -> 64bit
3389 * op: 0 -> add , 1 -> sub
3391 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3392 * imm6: Shift amount to apply to Rm before the add/sub
3394 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
3396 int rd
= extract32(insn
, 0, 5);
3397 int rn
= extract32(insn
, 5, 5);
3398 int imm6
= extract32(insn
, 10, 6);
3399 int rm
= extract32(insn
, 16, 5);
3400 int shift_type
= extract32(insn
, 22, 2);
3401 bool setflags
= extract32(insn
, 29, 1);
3402 bool sub_op
= extract32(insn
, 30, 1);
3403 bool sf
= extract32(insn
, 31, 1);
3405 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3406 TCGv_i64 tcg_rn
, tcg_rm
;
3407 TCGv_i64 tcg_result
;
3409 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
3410 unallocated_encoding(s
);
3414 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3415 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3417 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
3419 tcg_result
= tcg_temp_new_i64();
3423 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3425 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3429 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3431 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3436 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3438 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3441 tcg_temp_free_i64(tcg_result
);
3444 /* C3.5.9 Data-processing (3 source)
3446 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3447 +--+------+-----------+------+------+----+------+------+------+
3448 |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3449 +--+------+-----------+------+------+----+------+------+------+
3452 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
3454 int rd
= extract32(insn
, 0, 5);
3455 int rn
= extract32(insn
, 5, 5);
3456 int ra
= extract32(insn
, 10, 5);
3457 int rm
= extract32(insn
, 16, 5);
3458 int op_id
= (extract32(insn
, 29, 3) << 4) |
3459 (extract32(insn
, 21, 3) << 1) |
3460 extract32(insn
, 15, 1);
3461 bool sf
= extract32(insn
, 31, 1);
3462 bool is_sub
= extract32(op_id
, 0, 1);
3463 bool is_high
= extract32(op_id
, 2, 1);
3464 bool is_signed
= false;
3469 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
3471 case 0x42: /* SMADDL */
3472 case 0x43: /* SMSUBL */
3473 case 0x44: /* SMULH */
3476 case 0x0: /* MADD (32bit) */
3477 case 0x1: /* MSUB (32bit) */
3478 case 0x40: /* MADD (64bit) */
3479 case 0x41: /* MSUB (64bit) */
3480 case 0x4a: /* UMADDL */
3481 case 0x4b: /* UMSUBL */
3482 case 0x4c: /* UMULH */
3485 unallocated_encoding(s
);
3490 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
3491 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3492 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
3493 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
3496 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3498 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3501 tcg_temp_free_i64(low_bits
);
3505 tcg_op1
= tcg_temp_new_i64();
3506 tcg_op2
= tcg_temp_new_i64();
3507 tcg_tmp
= tcg_temp_new_i64();
3510 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
3511 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
3514 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
3515 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
3517 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
3518 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
3522 if (ra
== 31 && !is_sub
) {
3523 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
3524 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
3526 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
3528 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3530 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3535 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
3538 tcg_temp_free_i64(tcg_op1
);
3539 tcg_temp_free_i64(tcg_op2
);
3540 tcg_temp_free_i64(tcg_tmp
);
3543 /* C3.5.3 - Add/subtract (with carry)
3544 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
3545 * +--+--+--+------------------------+------+---------+------+-----+
3546 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
3547 * +--+--+--+------------------------+------+---------+------+-----+
3551 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
3553 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
3554 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
3556 if (extract32(insn
, 10, 6) != 0) {
3557 unallocated_encoding(s
);
3561 sf
= extract32(insn
, 31, 1);
3562 op
= extract32(insn
, 30, 1);
3563 setflags
= extract32(insn
, 29, 1);
3564 rm
= extract32(insn
, 16, 5);
3565 rn
= extract32(insn
, 5, 5);
3566 rd
= extract32(insn
, 0, 5);
3568 tcg_rd
= cpu_reg(s
, rd
);
3569 tcg_rn
= cpu_reg(s
, rn
);
3572 tcg_y
= new_tmp_a64(s
);
3573 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
3575 tcg_y
= cpu_reg(s
, rm
);
3579 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3581 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3585 /* C3.5.4 - C3.5.5 Conditional compare (immediate / register)
3586 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3587 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3588 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
3589 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3592 static void disas_cc(DisasContext
*s
, uint32_t insn
)
3594 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
3595 TCGv_i32 tcg_t0
, tcg_t1
, tcg_t2
;
3596 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
3599 if (!extract32(insn
, 29, 1)) {
3600 unallocated_encoding(s
);
3603 if (insn
& (1 << 10 | 1 << 4)) {
3604 unallocated_encoding(s
);
3607 sf
= extract32(insn
, 31, 1);
3608 op
= extract32(insn
, 30, 1);
3609 is_imm
= extract32(insn
, 11, 1);
3610 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
3611 cond
= extract32(insn
, 12, 4);
3612 rn
= extract32(insn
, 5, 5);
3613 nzcv
= extract32(insn
, 0, 4);
3615 /* Set T0 = !COND. */
3616 tcg_t0
= tcg_temp_new_i32();
3617 arm_test_cc(&c
, cond
);
3618 tcg_gen_setcondi_i32(tcg_invert_cond(c
.cond
), tcg_t0
, c
.value
, 0);
3621 /* Load the arguments for the new comparison. */
3623 tcg_y
= new_tmp_a64(s
);
3624 tcg_gen_movi_i64(tcg_y
, y
);
3626 tcg_y
= cpu_reg(s
, y
);
3628 tcg_rn
= cpu_reg(s
, rn
);
3630 /* Set the flags for the new comparison. */
3631 tcg_tmp
= tcg_temp_new_i64();
3633 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3635 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3637 tcg_temp_free_i64(tcg_tmp
);
3639 /* If COND was false, force the flags to #nzcv. Compute two masks
3640 * to help with this: T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).
3641 * For tcg hosts that support ANDC, we can make do with just T1.
3642 * In either case, allow the tcg optimizer to delete any unused mask.
3644 tcg_t1
= tcg_temp_new_i32();
3645 tcg_t2
= tcg_temp_new_i32();
3646 tcg_gen_neg_i32(tcg_t1
, tcg_t0
);
3647 tcg_gen_subi_i32(tcg_t2
, tcg_t0
, 1);
3649 if (nzcv
& 8) { /* N */
3650 tcg_gen_or_i32(cpu_NF
, cpu_NF
, tcg_t1
);
3652 if (TCG_TARGET_HAS_andc_i32
) {
3653 tcg_gen_andc_i32(cpu_NF
, cpu_NF
, tcg_t1
);
3655 tcg_gen_and_i32(cpu_NF
, cpu_NF
, tcg_t2
);
3658 if (nzcv
& 4) { /* Z */
3659 if (TCG_TARGET_HAS_andc_i32
) {
3660 tcg_gen_andc_i32(cpu_ZF
, cpu_ZF
, tcg_t1
);
3662 tcg_gen_and_i32(cpu_ZF
, cpu_ZF
, tcg_t2
);
3665 tcg_gen_or_i32(cpu_ZF
, cpu_ZF
, tcg_t0
);
3667 if (nzcv
& 2) { /* C */
3668 tcg_gen_or_i32(cpu_CF
, cpu_CF
, tcg_t0
);
3670 if (TCG_TARGET_HAS_andc_i32
) {
3671 tcg_gen_andc_i32(cpu_CF
, cpu_CF
, tcg_t1
);
3673 tcg_gen_and_i32(cpu_CF
, cpu_CF
, tcg_t2
);
3676 if (nzcv
& 1) { /* V */
3677 tcg_gen_or_i32(cpu_VF
, cpu_VF
, tcg_t1
);
3679 if (TCG_TARGET_HAS_andc_i32
) {
3680 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tcg_t1
);
3682 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tcg_t2
);
3685 tcg_temp_free_i32(tcg_t0
);
3686 tcg_temp_free_i32(tcg_t1
);
3687 tcg_temp_free_i32(tcg_t2
);
3690 /* C3.5.6 Conditional select
3691 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
3692 * +----+----+---+-----------------+------+------+-----+------+------+
3693 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
3694 * +----+----+---+-----------------+------+------+-----+------+------+
3696 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
3698 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
3699 TCGv_i64 tcg_rd
, zero
;
3702 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
3703 /* S == 1 or op2<1> == 1 */
3704 unallocated_encoding(s
);
3707 sf
= extract32(insn
, 31, 1);
3708 else_inv
= extract32(insn
, 30, 1);
3709 rm
= extract32(insn
, 16, 5);
3710 cond
= extract32(insn
, 12, 4);
3711 else_inc
= extract32(insn
, 10, 1);
3712 rn
= extract32(insn
, 5, 5);
3713 rd
= extract32(insn
, 0, 5);
3715 tcg_rd
= cpu_reg(s
, rd
);
3717 a64_test_cc(&c
, cond
);
3718 zero
= tcg_const_i64(0);
3720 if (rn
== 31 && rm
== 31 && (else_inc
^ else_inv
)) {
3722 tcg_gen_setcond_i64(tcg_invert_cond(c
.cond
), tcg_rd
, c
.value
, zero
);
3724 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
3727 TCGv_i64 t_true
= cpu_reg(s
, rn
);
3728 TCGv_i64 t_false
= read_cpu_reg(s
, rm
, 1);
3729 if (else_inv
&& else_inc
) {
3730 tcg_gen_neg_i64(t_false
, t_false
);
3731 } else if (else_inv
) {
3732 tcg_gen_not_i64(t_false
, t_false
);
3733 } else if (else_inc
) {
3734 tcg_gen_addi_i64(t_false
, t_false
, 1);
3736 tcg_gen_movcond_i64(c
.cond
, tcg_rd
, c
.value
, zero
, t_true
, t_false
);
3739 tcg_temp_free_i64(zero
);
3743 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3747 static void handle_clz(DisasContext
*s
, unsigned int sf
,
3748 unsigned int rn
, unsigned int rd
)
3750 TCGv_i64 tcg_rd
, tcg_rn
;
3751 tcg_rd
= cpu_reg(s
, rd
);
3752 tcg_rn
= cpu_reg(s
, rn
);
3755 gen_helper_clz64(tcg_rd
, tcg_rn
);
3757 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3758 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3759 gen_helper_clz(tcg_tmp32
, tcg_tmp32
);
3760 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3761 tcg_temp_free_i32(tcg_tmp32
);
3765 static void handle_cls(DisasContext
*s
, unsigned int sf
,
3766 unsigned int rn
, unsigned int rd
)
3768 TCGv_i64 tcg_rd
, tcg_rn
;
3769 tcg_rd
= cpu_reg(s
, rd
);
3770 tcg_rn
= cpu_reg(s
, rn
);
3773 gen_helper_cls64(tcg_rd
, tcg_rn
);
3775 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3776 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3777 gen_helper_cls32(tcg_tmp32
, tcg_tmp32
);
3778 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3779 tcg_temp_free_i32(tcg_tmp32
);
3783 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
3784 unsigned int rn
, unsigned int rd
)
3786 TCGv_i64 tcg_rd
, tcg_rn
;
3787 tcg_rd
= cpu_reg(s
, rd
);
3788 tcg_rn
= cpu_reg(s
, rn
);
3791 gen_helper_rbit64(tcg_rd
, tcg_rn
);
3793 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3794 tcg_gen_extrl_i64_i32(tcg_tmp32
, tcg_rn
);
3795 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
3796 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3797 tcg_temp_free_i32(tcg_tmp32
);
3801 /* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
3802 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
3803 unsigned int rn
, unsigned int rd
)
3806 unallocated_encoding(s
);
3809 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
3812 /* C5.6.149 REV with sf==0, opcode==2
3813 * C5.6.151 REV32 (sf==1, opcode==2)
3815 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
3816 unsigned int rn
, unsigned int rd
)
3818 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3821 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3822 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3824 /* bswap32_i64 requires zero high word */
3825 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
3826 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
3827 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3828 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
3829 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
3831 tcg_temp_free_i64(tcg_tmp
);
3833 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
3834 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
3838 /* C5.6.150 REV16 (opcode==1) */
3839 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
3840 unsigned int rn
, unsigned int rd
)
3842 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3843 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3844 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3846 tcg_gen_andi_i64(tcg_tmp
, tcg_rn
, 0xffff);
3847 tcg_gen_bswap16_i64(tcg_rd
, tcg_tmp
);
3849 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 16);
3850 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3851 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3852 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 16, 16);
3855 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3856 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3857 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3858 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 32, 16);
3860 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 48);
3861 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3862 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 48, 16);
3865 tcg_temp_free_i64(tcg_tmp
);
3868 /* C3.5.7 Data-processing (1 source)
3869 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3870 * +----+---+---+-----------------+---------+--------+------+------+
3871 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
3872 * +----+---+---+-----------------+---------+--------+------+------+
3874 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
3876 unsigned int sf
, opcode
, rn
, rd
;
3878 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
3879 unallocated_encoding(s
);
3883 sf
= extract32(insn
, 31, 1);
3884 opcode
= extract32(insn
, 10, 6);
3885 rn
= extract32(insn
, 5, 5);
3886 rd
= extract32(insn
, 0, 5);
3890 handle_rbit(s
, sf
, rn
, rd
);
3893 handle_rev16(s
, sf
, rn
, rd
);
3896 handle_rev32(s
, sf
, rn
, rd
);
3899 handle_rev64(s
, sf
, rn
, rd
);
3902 handle_clz(s
, sf
, rn
, rd
);
3905 handle_cls(s
, sf
, rn
, rd
);
3910 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
3911 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3913 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
3914 tcg_rd
= cpu_reg(s
, rd
);
3916 if (!sf
&& is_signed
) {
3917 tcg_n
= new_tmp_a64(s
);
3918 tcg_m
= new_tmp_a64(s
);
3919 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
3920 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
3922 tcg_n
= read_cpu_reg(s
, rn
, sf
);
3923 tcg_m
= read_cpu_reg(s
, rm
, sf
);
3927 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
3929 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
3932 if (!sf
) { /* zero extend final result */
3933 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3937 /* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
3938 static void handle_shift_reg(DisasContext
*s
,
3939 enum a64_shift_type shift_type
, unsigned int sf
,
3940 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3942 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
3943 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3944 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3946 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
3947 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
3948 tcg_temp_free_i64(tcg_shift
);
3951 /* CRC32[BHWX], CRC32C[BHWX] */
3952 static void handle_crc32(DisasContext
*s
,
3953 unsigned int sf
, unsigned int sz
, bool crc32c
,
3954 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3956 TCGv_i64 tcg_acc
, tcg_val
;
3959 if (!arm_dc_feature(s
, ARM_FEATURE_CRC
)
3960 || (sf
== 1 && sz
!= 3)
3961 || (sf
== 0 && sz
== 3)) {
3962 unallocated_encoding(s
);
3967 tcg_val
= cpu_reg(s
, rm
);
3981 g_assert_not_reached();
3983 tcg_val
= new_tmp_a64(s
);
3984 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
3987 tcg_acc
= cpu_reg(s
, rn
);
3988 tcg_bytes
= tcg_const_i32(1 << sz
);
3991 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
3993 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
3996 tcg_temp_free_i32(tcg_bytes
);
3999 /* C3.5.8 Data-processing (2 source)
4000 * 31 30 29 28 21 20 16 15 10 9 5 4 0
4001 * +----+---+---+-----------------+------+--------+------+------+
4002 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
4003 * +----+---+---+-----------------+------+--------+------+------+
4005 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
4007 unsigned int sf
, rm
, opcode
, rn
, rd
;
4008 sf
= extract32(insn
, 31, 1);
4009 rm
= extract32(insn
, 16, 5);
4010 opcode
= extract32(insn
, 10, 6);
4011 rn
= extract32(insn
, 5, 5);
4012 rd
= extract32(insn
, 0, 5);
4014 if (extract32(insn
, 29, 1)) {
4015 unallocated_encoding(s
);
4021 handle_div(s
, false, sf
, rm
, rn
, rd
);
4024 handle_div(s
, true, sf
, rm
, rn
, rd
);
4027 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
4030 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
4033 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
4036 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
4045 case 23: /* CRC32 */
4047 int sz
= extract32(opcode
, 0, 2);
4048 bool crc32c
= extract32(opcode
, 2, 1);
4049 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
4053 unallocated_encoding(s
);
4058 /* C3.5 Data processing - register */
4059 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
4061 switch (extract32(insn
, 24, 5)) {
4062 case 0x0a: /* Logical (shifted register) */
4063 disas_logic_reg(s
, insn
);
4065 case 0x0b: /* Add/subtract */
4066 if (insn
& (1 << 21)) { /* (extended register) */
4067 disas_add_sub_ext_reg(s
, insn
);
4069 disas_add_sub_reg(s
, insn
);
4072 case 0x1b: /* Data-processing (3 source) */
4073 disas_data_proc_3src(s
, insn
);
4076 switch (extract32(insn
, 21, 3)) {
4077 case 0x0: /* Add/subtract (with carry) */
4078 disas_adc_sbc(s
, insn
);
4080 case 0x2: /* Conditional compare */
4081 disas_cc(s
, insn
); /* both imm and reg forms */
4083 case 0x4: /* Conditional select */
4084 disas_cond_select(s
, insn
);
4086 case 0x6: /* Data-processing */
4087 if (insn
& (1 << 30)) { /* (1 source) */
4088 disas_data_proc_1src(s
, insn
);
4089 } else { /* (2 source) */
4090 disas_data_proc_2src(s
, insn
);
4094 unallocated_encoding(s
);
4099 unallocated_encoding(s
);
4104 static void handle_fp_compare(DisasContext
*s
, bool is_double
,
4105 unsigned int rn
, unsigned int rm
,
4106 bool cmp_with_zero
, bool signal_all_nans
)
4108 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
4109 TCGv_ptr fpst
= get_fpstatus_ptr();
4112 TCGv_i64 tcg_vn
, tcg_vm
;
4114 tcg_vn
= read_fp_dreg(s
, rn
);
4115 if (cmp_with_zero
) {
4116 tcg_vm
= tcg_const_i64(0);
4118 tcg_vm
= read_fp_dreg(s
, rm
);
4120 if (signal_all_nans
) {
4121 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4123 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4125 tcg_temp_free_i64(tcg_vn
);
4126 tcg_temp_free_i64(tcg_vm
);
4128 TCGv_i32 tcg_vn
, tcg_vm
;
4130 tcg_vn
= read_fp_sreg(s
, rn
);
4131 if (cmp_with_zero
) {
4132 tcg_vm
= tcg_const_i32(0);
4134 tcg_vm
= read_fp_sreg(s
, rm
);
4136 if (signal_all_nans
) {
4137 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4139 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4141 tcg_temp_free_i32(tcg_vn
);
4142 tcg_temp_free_i32(tcg_vm
);
4145 tcg_temp_free_ptr(fpst
);
4147 gen_set_nzcv(tcg_flags
);
4149 tcg_temp_free_i64(tcg_flags
);
4152 /* C3.6.22 Floating point compare
4153 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
4154 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4155 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
4156 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4158 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
4160 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
4162 mos
= extract32(insn
, 29, 3);
4163 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4164 rm
= extract32(insn
, 16, 5);
4165 op
= extract32(insn
, 14, 2);
4166 rn
= extract32(insn
, 5, 5);
4167 opc
= extract32(insn
, 3, 2);
4168 op2r
= extract32(insn
, 0, 3);
4170 if (mos
|| op
|| op2r
|| type
> 1) {
4171 unallocated_encoding(s
);
4175 if (!fp_access_check(s
)) {
4179 handle_fp_compare(s
, type
, rn
, rm
, opc
& 1, opc
& 2);
4182 /* C3.6.23 Floating point conditional compare
4183 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4184 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4185 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
4186 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4188 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
4190 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
4192 TCGLabel
*label_continue
= NULL
;
4194 mos
= extract32(insn
, 29, 3);
4195 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4196 rm
= extract32(insn
, 16, 5);
4197 cond
= extract32(insn
, 12, 4);
4198 rn
= extract32(insn
, 5, 5);
4199 op
= extract32(insn
, 4, 1);
4200 nzcv
= extract32(insn
, 0, 4);
4202 if (mos
|| type
> 1) {
4203 unallocated_encoding(s
);
4207 if (!fp_access_check(s
)) {
4211 if (cond
< 0x0e) { /* not always */
4212 TCGLabel
*label_match
= gen_new_label();
4213 label_continue
= gen_new_label();
4214 arm_gen_test_cc(cond
, label_match
);
4216 tcg_flags
= tcg_const_i64(nzcv
<< 28);
4217 gen_set_nzcv(tcg_flags
);
4218 tcg_temp_free_i64(tcg_flags
);
4219 tcg_gen_br(label_continue
);
4220 gen_set_label(label_match
);
4223 handle_fp_compare(s
, type
, rn
, rm
, false, op
);
4226 gen_set_label(label_continue
);
4230 /* C3.6.24 Floating point conditional select
4231 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4232 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4233 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
4234 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4236 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
4238 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
4239 TCGv_i64 t_true
, t_false
, t_zero
;
4242 mos
= extract32(insn
, 29, 3);
4243 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4244 rm
= extract32(insn
, 16, 5);
4245 cond
= extract32(insn
, 12, 4);
4246 rn
= extract32(insn
, 5, 5);
4247 rd
= extract32(insn
, 0, 5);
4249 if (mos
|| type
> 1) {
4250 unallocated_encoding(s
);
4254 if (!fp_access_check(s
)) {
4258 /* Zero extend sreg inputs to 64 bits now. */
4259 t_true
= tcg_temp_new_i64();
4260 t_false
= tcg_temp_new_i64();
4261 read_vec_element(s
, t_true
, rn
, 0, type
? MO_64
: MO_32
);
4262 read_vec_element(s
, t_false
, rm
, 0, type
? MO_64
: MO_32
);
4264 a64_test_cc(&c
, cond
);
4265 t_zero
= tcg_const_i64(0);
4266 tcg_gen_movcond_i64(c
.cond
, t_true
, c
.value
, t_zero
, t_true
, t_false
);
4267 tcg_temp_free_i64(t_zero
);
4268 tcg_temp_free_i64(t_false
);
4271 /* Note that sregs write back zeros to the high bits,
4272 and we've already done the zero-extension. */
4273 write_fp_dreg(s
, rd
, t_true
);
4274 tcg_temp_free_i64(t_true
);
4277 /* C3.6.25 Floating-point data-processing (1 source) - single precision */
4278 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
4284 fpst
= get_fpstatus_ptr();
4285 tcg_op
= read_fp_sreg(s
, rn
);
4286 tcg_res
= tcg_temp_new_i32();
4289 case 0x0: /* FMOV */
4290 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4292 case 0x1: /* FABS */
4293 gen_helper_vfp_abss(tcg_res
, tcg_op
);
4295 case 0x2: /* FNEG */
4296 gen_helper_vfp_negs(tcg_res
, tcg_op
);
4298 case 0x3: /* FSQRT */
4299 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
4301 case 0x8: /* FRINTN */
4302 case 0x9: /* FRINTP */
4303 case 0xa: /* FRINTM */
4304 case 0xb: /* FRINTZ */
4305 case 0xc: /* FRINTA */
4307 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4309 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4310 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4312 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4313 tcg_temp_free_i32(tcg_rmode
);
4316 case 0xe: /* FRINTX */
4317 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
4319 case 0xf: /* FRINTI */
4320 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4326 write_fp_sreg(s
, rd
, tcg_res
);
4328 tcg_temp_free_ptr(fpst
);
4329 tcg_temp_free_i32(tcg_op
);
4330 tcg_temp_free_i32(tcg_res
);
4333 /* C3.6.25 Floating-point data-processing (1 source) - double precision */
4334 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
4340 fpst
= get_fpstatus_ptr();
4341 tcg_op
= read_fp_dreg(s
, rn
);
4342 tcg_res
= tcg_temp_new_i64();
4345 case 0x0: /* FMOV */
4346 tcg_gen_mov_i64(tcg_res
, tcg_op
);
4348 case 0x1: /* FABS */
4349 gen_helper_vfp_absd(tcg_res
, tcg_op
);
4351 case 0x2: /* FNEG */
4352 gen_helper_vfp_negd(tcg_res
, tcg_op
);
4354 case 0x3: /* FSQRT */
4355 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
4357 case 0x8: /* FRINTN */
4358 case 0x9: /* FRINTP */
4359 case 0xa: /* FRINTM */
4360 case 0xb: /* FRINTZ */
4361 case 0xc: /* FRINTA */
4363 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4365 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4366 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4368 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4369 tcg_temp_free_i32(tcg_rmode
);
4372 case 0xe: /* FRINTX */
4373 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
4375 case 0xf: /* FRINTI */
4376 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4382 write_fp_dreg(s
, rd
, tcg_res
);
4384 tcg_temp_free_ptr(fpst
);
4385 tcg_temp_free_i64(tcg_op
);
4386 tcg_temp_free_i64(tcg_res
);
4389 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
4390 int rd
, int rn
, int dtype
, int ntype
)
4395 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4397 /* Single to double */
4398 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4399 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
4400 write_fp_dreg(s
, rd
, tcg_rd
);
4401 tcg_temp_free_i64(tcg_rd
);
4403 /* Single to half */
4404 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4405 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4406 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4407 write_fp_sreg(s
, rd
, tcg_rd
);
4408 tcg_temp_free_i32(tcg_rd
);
4410 tcg_temp_free_i32(tcg_rn
);
4415 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
4416 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4418 /* Double to single */
4419 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
4421 /* Double to half */
4422 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4423 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4425 write_fp_sreg(s
, rd
, tcg_rd
);
4426 tcg_temp_free_i32(tcg_rd
);
4427 tcg_temp_free_i64(tcg_rn
);
4432 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4433 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
4435 /* Half to single */
4436 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4437 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, cpu_env
);
4438 write_fp_sreg(s
, rd
, tcg_rd
);
4439 tcg_temp_free_i32(tcg_rd
);
4441 /* Half to double */
4442 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4443 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, cpu_env
);
4444 write_fp_dreg(s
, rd
, tcg_rd
);
4445 tcg_temp_free_i64(tcg_rd
);
4447 tcg_temp_free_i32(tcg_rn
);
4455 /* C3.6.25 Floating point data-processing (1 source)
4456 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
4457 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4458 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
4459 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4461 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
4463 int type
= extract32(insn
, 22, 2);
4464 int opcode
= extract32(insn
, 15, 6);
4465 int rn
= extract32(insn
, 5, 5);
4466 int rd
= extract32(insn
, 0, 5);
4469 case 0x4: case 0x5: case 0x7:
4471 /* FCVT between half, single and double precision */
4472 int dtype
= extract32(opcode
, 0, 2);
4473 if (type
== 2 || dtype
== type
) {
4474 unallocated_encoding(s
);
4477 if (!fp_access_check(s
)) {
4481 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
4487 /* 32-to-32 and 64-to-64 ops */
4490 if (!fp_access_check(s
)) {
4494 handle_fp_1src_single(s
, opcode
, rd
, rn
);
4497 if (!fp_access_check(s
)) {
4501 handle_fp_1src_double(s
, opcode
, rd
, rn
);
4504 unallocated_encoding(s
);
4508 unallocated_encoding(s
);
4513 /* C3.6.26 Floating-point data-processing (2 source) - single precision */
4514 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
4515 int rd
, int rn
, int rm
)
4522 tcg_res
= tcg_temp_new_i32();
4523 fpst
= get_fpstatus_ptr();
4524 tcg_op1
= read_fp_sreg(s
, rn
);
4525 tcg_op2
= read_fp_sreg(s
, rm
);
4528 case 0x0: /* FMUL */
4529 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4531 case 0x1: /* FDIV */
4532 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4534 case 0x2: /* FADD */
4535 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4537 case 0x3: /* FSUB */
4538 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4540 case 0x4: /* FMAX */
4541 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4543 case 0x5: /* FMIN */
4544 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4546 case 0x6: /* FMAXNM */
4547 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4549 case 0x7: /* FMINNM */
4550 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4552 case 0x8: /* FNMUL */
4553 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4554 gen_helper_vfp_negs(tcg_res
, tcg_res
);
4558 write_fp_sreg(s
, rd
, tcg_res
);
4560 tcg_temp_free_ptr(fpst
);
4561 tcg_temp_free_i32(tcg_op1
);
4562 tcg_temp_free_i32(tcg_op2
);
4563 tcg_temp_free_i32(tcg_res
);
4566 /* C3.6.26 Floating-point data-processing (2 source) - double precision */
4567 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
4568 int rd
, int rn
, int rm
)
4575 tcg_res
= tcg_temp_new_i64();
4576 fpst
= get_fpstatus_ptr();
4577 tcg_op1
= read_fp_dreg(s
, rn
);
4578 tcg_op2
= read_fp_dreg(s
, rm
);
4581 case 0x0: /* FMUL */
4582 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4584 case 0x1: /* FDIV */
4585 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4587 case 0x2: /* FADD */
4588 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4590 case 0x3: /* FSUB */
4591 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4593 case 0x4: /* FMAX */
4594 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4596 case 0x5: /* FMIN */
4597 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4599 case 0x6: /* FMAXNM */
4600 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4602 case 0x7: /* FMINNM */
4603 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4605 case 0x8: /* FNMUL */
4606 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4607 gen_helper_vfp_negd(tcg_res
, tcg_res
);
4611 write_fp_dreg(s
, rd
, tcg_res
);
4613 tcg_temp_free_ptr(fpst
);
4614 tcg_temp_free_i64(tcg_op1
);
4615 tcg_temp_free_i64(tcg_op2
);
4616 tcg_temp_free_i64(tcg_res
);
4619 /* C3.6.26 Floating point data-processing (2 source)
4620 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4621 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4622 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
4623 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4625 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
4627 int type
= extract32(insn
, 22, 2);
4628 int rd
= extract32(insn
, 0, 5);
4629 int rn
= extract32(insn
, 5, 5);
4630 int rm
= extract32(insn
, 16, 5);
4631 int opcode
= extract32(insn
, 12, 4);
4634 unallocated_encoding(s
);
4640 if (!fp_access_check(s
)) {
4643 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
4646 if (!fp_access_check(s
)) {
4649 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
4652 unallocated_encoding(s
);
4656 /* C3.6.27 Floating-point data-processing (3 source) - single precision */
4657 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
4658 int rd
, int rn
, int rm
, int ra
)
4660 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
4661 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4662 TCGv_ptr fpst
= get_fpstatus_ptr();
4664 tcg_op1
= read_fp_sreg(s
, rn
);
4665 tcg_op2
= read_fp_sreg(s
, rm
);
4666 tcg_op3
= read_fp_sreg(s
, ra
);
4668 /* These are fused multiply-add, and must be done as one
4669 * floating point operation with no rounding between the
4670 * multiplication and addition steps.
4671 * NB that doing the negations here as separate steps is
4672 * correct : an input NaN should come out with its sign bit
4673 * flipped if it is a negated-input.
4676 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
4680 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
4683 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4685 write_fp_sreg(s
, rd
, tcg_res
);
4687 tcg_temp_free_ptr(fpst
);
4688 tcg_temp_free_i32(tcg_op1
);
4689 tcg_temp_free_i32(tcg_op2
);
4690 tcg_temp_free_i32(tcg_op3
);
4691 tcg_temp_free_i32(tcg_res
);
4694 /* C3.6.27 Floating-point data-processing (3 source) - double precision */
4695 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
4696 int rd
, int rn
, int rm
, int ra
)
4698 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
4699 TCGv_i64 tcg_res
= tcg_temp_new_i64();
4700 TCGv_ptr fpst
= get_fpstatus_ptr();
4702 tcg_op1
= read_fp_dreg(s
, rn
);
4703 tcg_op2
= read_fp_dreg(s
, rm
);
4704 tcg_op3
= read_fp_dreg(s
, ra
);
4706 /* These are fused multiply-add, and must be done as one
4707 * floating point operation with no rounding between the
4708 * multiplication and addition steps.
4709 * NB that doing the negations here as separate steps is
4710 * correct : an input NaN should come out with its sign bit
4711 * flipped if it is a negated-input.
4714 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
4718 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
4721 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4723 write_fp_dreg(s
, rd
, tcg_res
);
4725 tcg_temp_free_ptr(fpst
);
4726 tcg_temp_free_i64(tcg_op1
);
4727 tcg_temp_free_i64(tcg_op2
);
4728 tcg_temp_free_i64(tcg_op3
);
4729 tcg_temp_free_i64(tcg_res
);
4732 /* C3.6.27 Floating point data-processing (3 source)
4733 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
4734 * +---+---+---+-----------+------+----+------+----+------+------+------+
4735 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
4736 * +---+---+---+-----------+------+----+------+----+------+------+------+
4738 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
4740 int type
= extract32(insn
, 22, 2);
4741 int rd
= extract32(insn
, 0, 5);
4742 int rn
= extract32(insn
, 5, 5);
4743 int ra
= extract32(insn
, 10, 5);
4744 int rm
= extract32(insn
, 16, 5);
4745 bool o0
= extract32(insn
, 15, 1);
4746 bool o1
= extract32(insn
, 21, 1);
4750 if (!fp_access_check(s
)) {
4753 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4756 if (!fp_access_check(s
)) {
4759 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4762 unallocated_encoding(s
);
4766 /* C3.6.28 Floating point immediate
4767 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
4768 * +---+---+---+-----------+------+---+------------+-------+------+------+
4769 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
4770 * +---+---+---+-----------+------+---+------------+-------+------+------+
4772 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
4774 int rd
= extract32(insn
, 0, 5);
4775 int imm8
= extract32(insn
, 13, 8);
4776 int is_double
= extract32(insn
, 22, 2);
4780 if (is_double
> 1) {
4781 unallocated_encoding(s
);
4785 if (!fp_access_check(s
)) {
4789 /* The imm8 encodes the sign bit, enough bits to represent
4790 * an exponent in the range 01....1xx to 10....0xx,
4791 * and the most significant 4 bits of the mantissa; see
4792 * VFPExpandImm() in the v8 ARM ARM.
4795 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4796 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
4797 extract32(imm8
, 0, 6);
4800 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4801 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
4802 (extract32(imm8
, 0, 6) << 3);
4806 tcg_res
= tcg_const_i64(imm
);
4807 write_fp_dreg(s
, rd
, tcg_res
);
4808 tcg_temp_free_i64(tcg_res
);
4811 /* Handle floating point <=> fixed point conversions. Note that we can
4812 * also deal with fp <=> integer conversions as a special case (scale == 64)
4813 * OPTME: consider handling that special case specially or at least skipping
4814 * the call to scalbn in the helpers for zero shifts.
4816 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
4817 bool itof
, int rmode
, int scale
, int sf
, int type
)
4819 bool is_signed
= !(opcode
& 1);
4820 bool is_double
= type
;
4821 TCGv_ptr tcg_fpstatus
;
4824 tcg_fpstatus
= get_fpstatus_ptr();
4826 tcg_shift
= tcg_const_i32(64 - scale
);
4829 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
4831 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
4834 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
4836 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
4839 tcg_int
= tcg_extend
;
4843 TCGv_i64 tcg_double
= tcg_temp_new_i64();
4845 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
4846 tcg_shift
, tcg_fpstatus
);
4848 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
4849 tcg_shift
, tcg_fpstatus
);
4851 write_fp_dreg(s
, rd
, tcg_double
);
4852 tcg_temp_free_i64(tcg_double
);
4854 TCGv_i32 tcg_single
= tcg_temp_new_i32();
4856 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
4857 tcg_shift
, tcg_fpstatus
);
4859 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
4860 tcg_shift
, tcg_fpstatus
);
4862 write_fp_sreg(s
, rd
, tcg_single
);
4863 tcg_temp_free_i32(tcg_single
);
4866 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
4869 if (extract32(opcode
, 2, 1)) {
4870 /* There are too many rounding modes to all fit into rmode,
4871 * so FCVTA[US] is a special case.
4873 rmode
= FPROUNDING_TIEAWAY
;
4876 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
4878 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4881 TCGv_i64 tcg_double
= read_fp_dreg(s
, rn
);
4884 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
4885 tcg_shift
, tcg_fpstatus
);
4887 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
4888 tcg_shift
, tcg_fpstatus
);
4892 gen_helper_vfp_tould(tcg_int
, tcg_double
,
4893 tcg_shift
, tcg_fpstatus
);
4895 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
4896 tcg_shift
, tcg_fpstatus
);
4899 tcg_temp_free_i64(tcg_double
);
4901 TCGv_i32 tcg_single
= read_fp_sreg(s
, rn
);
4904 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
4905 tcg_shift
, tcg_fpstatus
);
4907 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
4908 tcg_shift
, tcg_fpstatus
);
4911 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
4913 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
4914 tcg_shift
, tcg_fpstatus
);
4916 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
4917 tcg_shift
, tcg_fpstatus
);
4919 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
4920 tcg_temp_free_i32(tcg_dest
);
4922 tcg_temp_free_i32(tcg_single
);
4925 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4926 tcg_temp_free_i32(tcg_rmode
);
4929 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
4933 tcg_temp_free_ptr(tcg_fpstatus
);
4934 tcg_temp_free_i32(tcg_shift
);
4937 /* C3.6.29 Floating point <-> fixed point conversions
4938 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4939 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4940 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
4941 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4943 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
4945 int rd
= extract32(insn
, 0, 5);
4946 int rn
= extract32(insn
, 5, 5);
4947 int scale
= extract32(insn
, 10, 6);
4948 int opcode
= extract32(insn
, 16, 3);
4949 int rmode
= extract32(insn
, 19, 2);
4950 int type
= extract32(insn
, 22, 2);
4951 bool sbit
= extract32(insn
, 29, 1);
4952 bool sf
= extract32(insn
, 31, 1);
4955 if (sbit
|| (type
> 1)
4956 || (!sf
&& scale
< 32)) {
4957 unallocated_encoding(s
);
4961 switch ((rmode
<< 3) | opcode
) {
4962 case 0x2: /* SCVTF */
4963 case 0x3: /* UCVTF */
4966 case 0x18: /* FCVTZS */
4967 case 0x19: /* FCVTZU */
4971 unallocated_encoding(s
);
4975 if (!fp_access_check(s
)) {
4979 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
4982 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
4984 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
4985 * without conversion.
4989 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4995 TCGv_i64 tmp
= tcg_temp_new_i64();
4996 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
4997 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
4998 tcg_gen_movi_i64(tmp
, 0);
4999 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5000 tcg_temp_free_i64(tmp
);
5006 TCGv_i64 tmp
= tcg_const_i64(0);
5007 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
5008 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5009 tcg_temp_free_i64(tmp
);
5013 /* 64 bit to top half. */
5014 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
5018 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
5023 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
5027 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
5030 /* 64 bits from top half */
5031 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
5037 /* C3.6.30 Floating point <-> integer conversions
5038 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
5039 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5040 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
5041 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
5043 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
5045 int rd
= extract32(insn
, 0, 5);
5046 int rn
= extract32(insn
, 5, 5);
5047 int opcode
= extract32(insn
, 16, 3);
5048 int rmode
= extract32(insn
, 19, 2);
5049 int type
= extract32(insn
, 22, 2);
5050 bool sbit
= extract32(insn
, 29, 1);
5051 bool sf
= extract32(insn
, 31, 1);
5054 unallocated_encoding(s
);
5060 bool itof
= opcode
& 1;
5063 unallocated_encoding(s
);
5067 switch (sf
<< 3 | type
<< 1 | rmode
) {
5068 case 0x0: /* 32 bit */
5069 case 0xa: /* 64 bit */
5070 case 0xd: /* 64 bit to top half of quad */
5073 /* all other sf/type/rmode combinations are invalid */
5074 unallocated_encoding(s
);
5078 if (!fp_access_check(s
)) {
5081 handle_fmov(s
, rd
, rn
, type
, itof
);
5083 /* actual FP conversions */
5084 bool itof
= extract32(opcode
, 1, 1);
5086 if (type
> 1 || (rmode
!= 0 && opcode
> 1)) {
5087 unallocated_encoding(s
);
5091 if (!fp_access_check(s
)) {
5094 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
5098 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
5099 * 31 30 29 28 25 24 0
5100 * +---+---+---+---------+-----------------------------+
5101 * | | 0 | | 1 1 1 1 | |
5102 * +---+---+---+---------+-----------------------------+
5104 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
5106 if (extract32(insn
, 24, 1)) {
5107 /* Floating point data-processing (3 source) */
5108 disas_fp_3src(s
, insn
);
5109 } else if (extract32(insn
, 21, 1) == 0) {
5110 /* Floating point to fixed point conversions */
5111 disas_fp_fixed_conv(s
, insn
);
5113 switch (extract32(insn
, 10, 2)) {
5115 /* Floating point conditional compare */
5116 disas_fp_ccomp(s
, insn
);
5119 /* Floating point data-processing (2 source) */
5120 disas_fp_2src(s
, insn
);
5123 /* Floating point conditional select */
5124 disas_fp_csel(s
, insn
);
5127 switch (ctz32(extract32(insn
, 12, 4))) {
5128 case 0: /* [15:12] == xxx1 */
5129 /* Floating point immediate */
5130 disas_fp_imm(s
, insn
);
5132 case 1: /* [15:12] == xx10 */
5133 /* Floating point compare */
5134 disas_fp_compare(s
, insn
);
5136 case 2: /* [15:12] == x100 */
5137 /* Floating point data-processing (1 source) */
5138 disas_fp_1src(s
, insn
);
5140 case 3: /* [15:12] == 1000 */
5141 unallocated_encoding(s
);
5143 default: /* [15:12] == 0000 */
5144 /* Floating point <-> integer conversions */
5145 disas_fp_int_conv(s
, insn
);
5153 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
5156 /* Extract 64 bits from the middle of two concatenated 64 bit
5157 * vector register slices left:right. The extracted bits start
5158 * at 'pos' bits into the right (least significant) side.
5159 * We return the result in tcg_right, and guarantee not to
5162 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5163 assert(pos
> 0 && pos
< 64);
5165 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
5166 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
5167 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
5169 tcg_temp_free_i64(tcg_tmp
);
5173 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
5174 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5175 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
5176 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5178 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
5180 int is_q
= extract32(insn
, 30, 1);
5181 int op2
= extract32(insn
, 22, 2);
5182 int imm4
= extract32(insn
, 11, 4);
5183 int rm
= extract32(insn
, 16, 5);
5184 int rn
= extract32(insn
, 5, 5);
5185 int rd
= extract32(insn
, 0, 5);
5186 int pos
= imm4
<< 3;
5187 TCGv_i64 tcg_resl
, tcg_resh
;
5189 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
5190 unallocated_encoding(s
);
5194 if (!fp_access_check(s
)) {
5198 tcg_resh
= tcg_temp_new_i64();
5199 tcg_resl
= tcg_temp_new_i64();
5201 /* Vd gets bits starting at pos bits into Vm:Vn. This is
5202 * either extracting 128 bits from a 128:128 concatenation, or
5203 * extracting 64 bits from a 64:64 concatenation.
5206 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
5208 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
5209 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5211 tcg_gen_movi_i64(tcg_resh
, 0);
5218 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
5219 EltPosns
*elt
= eltposns
;
5226 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
5228 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
5231 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5232 tcg_hh
= tcg_temp_new_i64();
5233 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
5234 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
5235 tcg_temp_free_i64(tcg_hh
);
5239 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5240 tcg_temp_free_i64(tcg_resl
);
5241 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5242 tcg_temp_free_i64(tcg_resh
);
5246 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
5247 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5248 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
5249 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5251 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
5253 int op2
= extract32(insn
, 22, 2);
5254 int is_q
= extract32(insn
, 30, 1);
5255 int rm
= extract32(insn
, 16, 5);
5256 int rn
= extract32(insn
, 5, 5);
5257 int rd
= extract32(insn
, 0, 5);
5258 int is_tblx
= extract32(insn
, 12, 1);
5259 int len
= extract32(insn
, 13, 2);
5260 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
5261 TCGv_i32 tcg_regno
, tcg_numregs
;
5264 unallocated_encoding(s
);
5268 if (!fp_access_check(s
)) {
5272 /* This does a table lookup: for every byte element in the input
5273 * we index into a table formed from up to four vector registers,
5274 * and then the output is the result of the lookups. Our helper
5275 * function does the lookup operation for a single 64 bit part of
5278 tcg_resl
= tcg_temp_new_i64();
5279 tcg_resh
= tcg_temp_new_i64();
5282 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5284 tcg_gen_movi_i64(tcg_resl
, 0);
5286 if (is_tblx
&& is_q
) {
5287 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5289 tcg_gen_movi_i64(tcg_resh
, 0);
5292 tcg_idx
= tcg_temp_new_i64();
5293 tcg_regno
= tcg_const_i32(rn
);
5294 tcg_numregs
= tcg_const_i32(len
+ 1);
5295 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
5296 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
5297 tcg_regno
, tcg_numregs
);
5299 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
5300 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
5301 tcg_regno
, tcg_numregs
);
5303 tcg_temp_free_i64(tcg_idx
);
5304 tcg_temp_free_i32(tcg_regno
);
5305 tcg_temp_free_i32(tcg_numregs
);
5307 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5308 tcg_temp_free_i64(tcg_resl
);
5309 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5310 tcg_temp_free_i64(tcg_resh
);
5313 /* C3.6.3 ZIP/UZP/TRN
5314 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
5315 * +---+---+-------------+------+---+------+---+------------------+------+
5316 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
5317 * +---+---+-------------+------+---+------+---+------------------+------+
5319 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
5321 int rd
= extract32(insn
, 0, 5);
5322 int rn
= extract32(insn
, 5, 5);
5323 int rm
= extract32(insn
, 16, 5);
5324 int size
= extract32(insn
, 22, 2);
5325 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
5326 * bit 2 indicates 1 vs 2 variant of the insn.
5328 int opcode
= extract32(insn
, 12, 2);
5329 bool part
= extract32(insn
, 14, 1);
5330 bool is_q
= extract32(insn
, 30, 1);
5331 int esize
= 8 << size
;
5333 int datasize
= is_q
? 128 : 64;
5334 int elements
= datasize
/ esize
;
5335 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
5337 if (opcode
== 0 || (size
== 3 && !is_q
)) {
5338 unallocated_encoding(s
);
5342 if (!fp_access_check(s
)) {
5346 tcg_resl
= tcg_const_i64(0);
5347 tcg_resh
= tcg_const_i64(0);
5348 tcg_res
= tcg_temp_new_i64();
5350 for (i
= 0; i
< elements
; i
++) {
5352 case 1: /* UZP1/2 */
5354 int midpoint
= elements
/ 2;
5356 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
5358 read_vec_element(s
, tcg_res
, rm
,
5359 2 * (i
- midpoint
) + part
, size
);
5363 case 2: /* TRN1/2 */
5365 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
5367 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
5370 case 3: /* ZIP1/2 */
5372 int base
= part
* elements
/ 2;
5374 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
5376 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
5381 g_assert_not_reached();
5386 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
5387 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
5389 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
5390 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
5394 tcg_temp_free_i64(tcg_res
);
5396 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5397 tcg_temp_free_i64(tcg_resl
);
5398 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5399 tcg_temp_free_i64(tcg_resh
);
5402 static void do_minmaxop(DisasContext
*s
, TCGv_i32 tcg_elt1
, TCGv_i32 tcg_elt2
,
5403 int opc
, bool is_min
, TCGv_ptr fpst
)
5405 /* Helper function for disas_simd_across_lanes: do a single precision
5406 * min/max operation on the specified two inputs,
5407 * and return the result in tcg_elt1.
5411 gen_helper_vfp_minnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5413 gen_helper_vfp_maxnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5418 gen_helper_vfp_mins(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5420 gen_helper_vfp_maxs(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5425 /* C3.6.4 AdvSIMD across lanes
5426 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5427 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5428 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5429 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5431 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
5433 int rd
= extract32(insn
, 0, 5);
5434 int rn
= extract32(insn
, 5, 5);
5435 int size
= extract32(insn
, 22, 2);
5436 int opcode
= extract32(insn
, 12, 5);
5437 bool is_q
= extract32(insn
, 30, 1);
5438 bool is_u
= extract32(insn
, 29, 1);
5440 bool is_min
= false;
5444 TCGv_i64 tcg_res
, tcg_elt
;
5447 case 0x1b: /* ADDV */
5449 unallocated_encoding(s
);
5453 case 0x3: /* SADDLV, UADDLV */
5454 case 0xa: /* SMAXV, UMAXV */
5455 case 0x1a: /* SMINV, UMINV */
5456 if (size
== 3 || (size
== 2 && !is_q
)) {
5457 unallocated_encoding(s
);
5461 case 0xc: /* FMAXNMV, FMINNMV */
5462 case 0xf: /* FMAXV, FMINV */
5463 if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
5464 unallocated_encoding(s
);
5467 /* Bit 1 of size field encodes min vs max, and actual size is always
5468 * 32 bits: adjust the size variable so following code can rely on it
5470 is_min
= extract32(size
, 1, 1);
5475 unallocated_encoding(s
);
5479 if (!fp_access_check(s
)) {
5484 elements
= (is_q
? 128 : 64) / esize
;
5486 tcg_res
= tcg_temp_new_i64();
5487 tcg_elt
= tcg_temp_new_i64();
5489 /* These instructions operate across all lanes of a vector
5490 * to produce a single result. We can guarantee that a 64
5491 * bit intermediate is sufficient:
5492 * + for [US]ADDLV the maximum element size is 32 bits, and
5493 * the result type is 64 bits
5494 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
5495 * same as the element size, which is 32 bits at most
5496 * For the integer operations we can choose to work at 64
5497 * or 32 bits and truncate at the end; for simplicity
5498 * we use 64 bits always. The floating point
5499 * ops do require 32 bit intermediates, though.
5502 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
5504 for (i
= 1; i
< elements
; i
++) {
5505 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
5508 case 0x03: /* SADDLV / UADDLV */
5509 case 0x1b: /* ADDV */
5510 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
5512 case 0x0a: /* SMAXV / UMAXV */
5513 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
5515 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5517 case 0x1a: /* SMINV / UMINV */
5518 tcg_gen_movcond_i64(is_u
? TCG_COND_LEU
: TCG_COND_LE
,
5520 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5524 g_assert_not_reached();
5529 /* Floating point ops which work on 32 bit (single) intermediates.
5530 * Note that correct NaN propagation requires that we do these
5531 * operations in exactly the order specified by the pseudocode.
5533 TCGv_i32 tcg_elt1
= tcg_temp_new_i32();
5534 TCGv_i32 tcg_elt2
= tcg_temp_new_i32();
5535 TCGv_i32 tcg_elt3
= tcg_temp_new_i32();
5536 TCGv_ptr fpst
= get_fpstatus_ptr();
5538 assert(esize
== 32);
5539 assert(elements
== 4);
5541 read_vec_element(s
, tcg_elt
, rn
, 0, MO_32
);
5542 tcg_gen_extrl_i64_i32(tcg_elt1
, tcg_elt
);
5543 read_vec_element(s
, tcg_elt
, rn
, 1, MO_32
);
5544 tcg_gen_extrl_i64_i32(tcg_elt2
, tcg_elt
);
5546 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5548 read_vec_element(s
, tcg_elt
, rn
, 2, MO_32
);
5549 tcg_gen_extrl_i64_i32(tcg_elt2
, tcg_elt
);
5550 read_vec_element(s
, tcg_elt
, rn
, 3, MO_32
);
5551 tcg_gen_extrl_i64_i32(tcg_elt3
, tcg_elt
);
5553 do_minmaxop(s
, tcg_elt2
, tcg_elt3
, opcode
, is_min
, fpst
);
5555 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5557 tcg_gen_extu_i32_i64(tcg_res
, tcg_elt1
);
5558 tcg_temp_free_i32(tcg_elt1
);
5559 tcg_temp_free_i32(tcg_elt2
);
5560 tcg_temp_free_i32(tcg_elt3
);
5561 tcg_temp_free_ptr(fpst
);
5564 tcg_temp_free_i64(tcg_elt
);
5566 /* Now truncate the result to the width required for the final output */
5567 if (opcode
== 0x03) {
5568 /* SADDLV, UADDLV: result is 2*esize */
5574 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
5577 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
5580 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
5585 g_assert_not_reached();
5588 write_fp_dreg(s
, rd
, tcg_res
);
5589 tcg_temp_free_i64(tcg_res
);
5592 /* C6.3.31 DUP (Element, Vector)
5594 * 31 30 29 21 20 16 15 10 9 5 4 0
5595 * +---+---+-------------------+--------+-------------+------+------+
5596 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5597 * +---+---+-------------------+--------+-------------+------+------+
5599 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5601 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
5604 int size
= ctz32(imm5
);
5605 int esize
= 8 << size
;
5606 int elements
= (is_q
? 128 : 64) / esize
;
5610 if (size
> 3 || (size
== 3 && !is_q
)) {
5611 unallocated_encoding(s
);
5615 if (!fp_access_check(s
)) {
5619 index
= imm5
>> (size
+ 1);
5621 tmp
= tcg_temp_new_i64();
5622 read_vec_element(s
, tmp
, rn
, index
, size
);
5624 for (i
= 0; i
< elements
; i
++) {
5625 write_vec_element(s
, tmp
, rd
, i
, size
);
5629 clear_vec_high(s
, rd
);
5632 tcg_temp_free_i64(tmp
);
5635 /* C6.3.31 DUP (element, scalar)
5636 * 31 21 20 16 15 10 9 5 4 0
5637 * +-----------------------+--------+-------------+------+------+
5638 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5639 * +-----------------------+--------+-------------+------+------+
5641 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
5644 int size
= ctz32(imm5
);
5649 unallocated_encoding(s
);
5653 if (!fp_access_check(s
)) {
5657 index
= imm5
>> (size
+ 1);
5659 /* This instruction just extracts the specified element and
5660 * zero-extends it into the bottom of the destination register.
5662 tmp
= tcg_temp_new_i64();
5663 read_vec_element(s
, tmp
, rn
, index
, size
);
5664 write_fp_dreg(s
, rd
, tmp
);
5665 tcg_temp_free_i64(tmp
);
5668 /* C6.3.32 DUP (General)
5670 * 31 30 29 21 20 16 15 10 9 5 4 0
5671 * +---+---+-------------------+--------+-------------+------+------+
5672 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
5673 * +---+---+-------------------+--------+-------------+------+------+
5675 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5677 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
5680 int size
= ctz32(imm5
);
5681 int esize
= 8 << size
;
5682 int elements
= (is_q
? 128 : 64)/esize
;
5685 if (size
> 3 || ((size
== 3) && !is_q
)) {
5686 unallocated_encoding(s
);
5690 if (!fp_access_check(s
)) {
5694 for (i
= 0; i
< elements
; i
++) {
5695 write_vec_element(s
, cpu_reg(s
, rn
), rd
, i
, size
);
5698 clear_vec_high(s
, rd
);
5702 /* C6.3.150 INS (Element)
5704 * 31 21 20 16 15 14 11 10 9 5 4 0
5705 * +-----------------------+--------+------------+---+------+------+
5706 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5707 * +-----------------------+--------+------------+---+------+------+
5709 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5710 * index: encoded in imm5<4:size+1>
5712 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
5715 int size
= ctz32(imm5
);
5716 int src_index
, dst_index
;
5720 unallocated_encoding(s
);
5724 if (!fp_access_check(s
)) {
5728 dst_index
= extract32(imm5
, 1+size
, 5);
5729 src_index
= extract32(imm4
, size
, 4);
5731 tmp
= tcg_temp_new_i64();
5733 read_vec_element(s
, tmp
, rn
, src_index
, size
);
5734 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
5736 tcg_temp_free_i64(tmp
);
5740 /* C6.3.151 INS (General)
5742 * 31 21 20 16 15 10 9 5 4 0
5743 * +-----------------------+--------+-------------+------+------+
5744 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
5745 * +-----------------------+--------+-------------+------+------+
5747 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5748 * index: encoded in imm5<4:size+1>
5750 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
5752 int size
= ctz32(imm5
);
5756 unallocated_encoding(s
);
5760 if (!fp_access_check(s
)) {
5764 idx
= extract32(imm5
, 1 + size
, 4 - size
);
5765 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
5769 * C6.3.321 UMOV (General)
5770 * C6.3.237 SMOV (General)
5772 * 31 30 29 21 20 16 15 12 10 9 5 4 0
5773 * +---+---+-------------------+--------+-------------+------+------+
5774 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
5775 * +---+---+-------------------+--------+-------------+------+------+
5777 * U: unsigned when set
5778 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5780 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
5781 int rn
, int rd
, int imm5
)
5783 int size
= ctz32(imm5
);
5787 /* Check for UnallocatedEncodings */
5789 if (size
> 2 || (size
== 2 && !is_q
)) {
5790 unallocated_encoding(s
);
5795 || (size
< 3 && is_q
)
5796 || (size
== 3 && !is_q
)) {
5797 unallocated_encoding(s
);
5802 if (!fp_access_check(s
)) {
5806 element
= extract32(imm5
, 1+size
, 4);
5808 tcg_rd
= cpu_reg(s
, rd
);
5809 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
5810 if (is_signed
&& !is_q
) {
5811 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5815 /* C3.6.5 AdvSIMD copy
5816 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5817 * +---+---+----+-----------------+------+---+------+---+------+------+
5818 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5819 * +---+---+----+-----------------+------+---+------+---+------+------+
5821 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
5823 int rd
= extract32(insn
, 0, 5);
5824 int rn
= extract32(insn
, 5, 5);
5825 int imm4
= extract32(insn
, 11, 4);
5826 int op
= extract32(insn
, 29, 1);
5827 int is_q
= extract32(insn
, 30, 1);
5828 int imm5
= extract32(insn
, 16, 5);
5833 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
5835 unallocated_encoding(s
);
5840 /* DUP (element - vector) */
5841 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
5845 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
5850 handle_simd_insg(s
, rd
, rn
, imm5
);
5852 unallocated_encoding(s
);
5857 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
5858 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
5861 unallocated_encoding(s
);
5867 /* C3.6.6 AdvSIMD modified immediate
5868 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
5869 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5870 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
5871 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5873 * There are a number of operations that can be carried out here:
5874 * MOVI - move (shifted) imm into register
5875 * MVNI - move inverted (shifted) imm into register
5876 * ORR - bitwise OR of (shifted) imm with register
5877 * BIC - bitwise clear of (shifted) imm with register
5879 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
5881 int rd
= extract32(insn
, 0, 5);
5882 int cmode
= extract32(insn
, 12, 4);
5883 int cmode_3_1
= extract32(cmode
, 1, 3);
5884 int cmode_0
= extract32(cmode
, 0, 1);
5885 int o2
= extract32(insn
, 11, 1);
5886 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
5887 bool is_neg
= extract32(insn
, 29, 1);
5888 bool is_q
= extract32(insn
, 30, 1);
5890 TCGv_i64 tcg_rd
, tcg_imm
;
5893 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
5894 unallocated_encoding(s
);
5898 if (!fp_access_check(s
)) {
5902 /* See AdvSIMDExpandImm() in ARM ARM */
5903 switch (cmode_3_1
) {
5904 case 0: /* Replicate(Zeros(24):imm8, 2) */
5905 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
5906 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
5907 case 3: /* Replicate(imm8:Zeros(24), 2) */
5909 int shift
= cmode_3_1
* 8;
5910 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
5913 case 4: /* Replicate(Zeros(8):imm8, 4) */
5914 case 5: /* Replicate(imm8:Zeros(8), 4) */
5916 int shift
= (cmode_3_1
& 0x1) * 8;
5917 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
5922 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
5923 imm
= (abcdefgh
<< 16) | 0xffff;
5925 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
5926 imm
= (abcdefgh
<< 8) | 0xff;
5928 imm
= bitfield_replicate(imm
, 32);
5931 if (!cmode_0
&& !is_neg
) {
5932 imm
= bitfield_replicate(abcdefgh
, 8);
5933 } else if (!cmode_0
&& is_neg
) {
5936 for (i
= 0; i
< 8; i
++) {
5937 if ((abcdefgh
) & (1 << i
)) {
5938 imm
|= 0xffULL
<< (i
* 8);
5941 } else if (cmode_0
) {
5943 imm
= (abcdefgh
& 0x3f) << 48;
5944 if (abcdefgh
& 0x80) {
5945 imm
|= 0x8000000000000000ULL
;
5947 if (abcdefgh
& 0x40) {
5948 imm
|= 0x3fc0000000000000ULL
;
5950 imm
|= 0x4000000000000000ULL
;
5953 imm
= (abcdefgh
& 0x3f) << 19;
5954 if (abcdefgh
& 0x80) {
5957 if (abcdefgh
& 0x40) {
5968 if (cmode_3_1
!= 7 && is_neg
) {
5972 tcg_imm
= tcg_const_i64(imm
);
5973 tcg_rd
= new_tmp_a64(s
);
5975 for (i
= 0; i
< 2; i
++) {
5976 int foffs
= i
? fp_reg_hi_offset(s
, rd
) : fp_reg_offset(s
, rd
, MO_64
);
5978 if (i
== 1 && !is_q
) {
5979 /* non-quad ops clear high half of vector */
5980 tcg_gen_movi_i64(tcg_rd
, 0);
5981 } else if ((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9) {
5982 tcg_gen_ld_i64(tcg_rd
, cpu_env
, foffs
);
5985 tcg_gen_and_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5988 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5992 tcg_gen_mov_i64(tcg_rd
, tcg_imm
);
5994 tcg_gen_st_i64(tcg_rd
, cpu_env
, foffs
);
5997 tcg_temp_free_i64(tcg_imm
);
6000 /* C3.6.7 AdvSIMD scalar copy
6001 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
6002 * +-----+----+-----------------+------+---+------+---+------+------+
6003 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
6004 * +-----+----+-----------------+------+---+------+---+------+------+
6006 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
6008 int rd
= extract32(insn
, 0, 5);
6009 int rn
= extract32(insn
, 5, 5);
6010 int imm4
= extract32(insn
, 11, 4);
6011 int imm5
= extract32(insn
, 16, 5);
6012 int op
= extract32(insn
, 29, 1);
6014 if (op
!= 0 || imm4
!= 0) {
6015 unallocated_encoding(s
);
6019 /* DUP (element, scalar) */
6020 handle_simd_dupes(s
, rd
, rn
, imm5
);
6023 /* C3.6.8 AdvSIMD scalar pairwise
6024 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
6025 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6026 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
6027 * +-----+---+-----------+------+-----------+--------+-----+------+------+
6029 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
6031 int u
= extract32(insn
, 29, 1);
6032 int size
= extract32(insn
, 22, 2);
6033 int opcode
= extract32(insn
, 12, 5);
6034 int rn
= extract32(insn
, 5, 5);
6035 int rd
= extract32(insn
, 0, 5);
6038 /* For some ops (the FP ones), size[1] is part of the encoding.
6039 * For ADDP strictly it is not but size[1] is always 1 for valid
6042 opcode
|= (extract32(size
, 1, 1) << 5);
6045 case 0x3b: /* ADDP */
6046 if (u
|| size
!= 3) {
6047 unallocated_encoding(s
);
6050 if (!fp_access_check(s
)) {
6054 TCGV_UNUSED_PTR(fpst
);
6056 case 0xc: /* FMAXNMP */
6057 case 0xd: /* FADDP */
6058 case 0xf: /* FMAXP */
6059 case 0x2c: /* FMINNMP */
6060 case 0x2f: /* FMINP */
6061 /* FP op, size[0] is 32 or 64 bit */
6063 unallocated_encoding(s
);
6066 if (!fp_access_check(s
)) {
6070 size
= extract32(size
, 0, 1) ? 3 : 2;
6071 fpst
= get_fpstatus_ptr();
6074 unallocated_encoding(s
);
6079 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6080 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6081 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6083 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
6084 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
6087 case 0x3b: /* ADDP */
6088 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
6090 case 0xc: /* FMAXNMP */
6091 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6093 case 0xd: /* FADDP */
6094 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6096 case 0xf: /* FMAXP */
6097 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6099 case 0x2c: /* FMINNMP */
6100 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6102 case 0x2f: /* FMINP */
6103 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6106 g_assert_not_reached();
6109 write_fp_dreg(s
, rd
, tcg_res
);
6111 tcg_temp_free_i64(tcg_op1
);
6112 tcg_temp_free_i64(tcg_op2
);
6113 tcg_temp_free_i64(tcg_res
);
6115 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6116 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6117 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6119 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_32
);
6120 read_vec_element_i32(s
, tcg_op2
, rn
, 1, MO_32
);
6123 case 0xc: /* FMAXNMP */
6124 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6126 case 0xd: /* FADDP */
6127 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6129 case 0xf: /* FMAXP */
6130 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6132 case 0x2c: /* FMINNMP */
6133 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6135 case 0x2f: /* FMINP */
6136 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6139 g_assert_not_reached();
6142 write_fp_sreg(s
, rd
, tcg_res
);
6144 tcg_temp_free_i32(tcg_op1
);
6145 tcg_temp_free_i32(tcg_op2
);
6146 tcg_temp_free_i32(tcg_res
);
6149 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
6150 tcg_temp_free_ptr(fpst
);
6155 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
6157 * This code is handles the common shifting code and is used by both
6158 * the vector and scalar code.
6160 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6161 TCGv_i64 tcg_rnd
, bool accumulate
,
6162 bool is_u
, int size
, int shift
)
6164 bool extended_result
= false;
6165 bool round
= !TCGV_IS_UNUSED_I64(tcg_rnd
);
6167 TCGv_i64 tcg_src_hi
;
6169 if (round
&& size
== 3) {
6170 extended_result
= true;
6171 ext_lshift
= 64 - shift
;
6172 tcg_src_hi
= tcg_temp_new_i64();
6173 } else if (shift
== 64) {
6174 if (!accumulate
&& is_u
) {
6175 /* result is zero */
6176 tcg_gen_movi_i64(tcg_res
, 0);
6181 /* Deal with the rounding step */
6183 if (extended_result
) {
6184 TCGv_i64 tcg_zero
= tcg_const_i64(0);
6186 /* take care of sign extending tcg_res */
6187 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
6188 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6189 tcg_src
, tcg_src_hi
,
6192 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6196 tcg_temp_free_i64(tcg_zero
);
6198 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
6202 /* Now do the shift right */
6203 if (round
&& extended_result
) {
6204 /* extended case, >64 bit precision required */
6205 if (ext_lshift
== 0) {
6206 /* special case, only high bits matter */
6207 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
6209 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6210 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
6211 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
6216 /* essentially shifting in 64 zeros */
6217 tcg_gen_movi_i64(tcg_src
, 0);
6219 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6223 /* effectively extending the sign-bit */
6224 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
6226 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
6232 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
6234 tcg_gen_mov_i64(tcg_res
, tcg_src
);
6237 if (extended_result
) {
6238 tcg_temp_free_i64(tcg_src_hi
);
6242 /* Common SHL/SLI - Shift left with an optional insert */
6243 static void handle_shli_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6244 bool insert
, int shift
)
6246 if (insert
) { /* SLI */
6247 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, shift
, 64 - shift
);
6249 tcg_gen_shli_i64(tcg_res
, tcg_src
, shift
);
6253 /* SRI: shift right with insert */
6254 static void handle_shri_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6255 int size
, int shift
)
6257 int esize
= 8 << size
;
6259 /* shift count same as element size is valid but does nothing;
6260 * special case to avoid potential shift by 64.
6262 if (shift
!= esize
) {
6263 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6264 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, 0, esize
- shift
);
6268 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
6269 static void handle_scalar_simd_shri(DisasContext
*s
,
6270 bool is_u
, int immh
, int immb
,
6271 int opcode
, int rn
, int rd
)
6274 int immhb
= immh
<< 3 | immb
;
6275 int shift
= 2 * (8 << size
) - immhb
;
6276 bool accumulate
= false;
6278 bool insert
= false;
6283 if (!extract32(immh
, 3, 1)) {
6284 unallocated_encoding(s
);
6288 if (!fp_access_check(s
)) {
6293 case 0x02: /* SSRA / USRA (accumulate) */
6296 case 0x04: /* SRSHR / URSHR (rounding) */
6299 case 0x06: /* SRSRA / URSRA (accum + rounding) */
6300 accumulate
= round
= true;
6302 case 0x08: /* SRI */
6308 uint64_t round_const
= 1ULL << (shift
- 1);
6309 tcg_round
= tcg_const_i64(round_const
);
6311 TCGV_UNUSED_I64(tcg_round
);
6314 tcg_rn
= read_fp_dreg(s
, rn
);
6315 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6318 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
6320 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6321 accumulate
, is_u
, size
, shift
);
6324 write_fp_dreg(s
, rd
, tcg_rd
);
6326 tcg_temp_free_i64(tcg_rn
);
6327 tcg_temp_free_i64(tcg_rd
);
6329 tcg_temp_free_i64(tcg_round
);
6333 /* SHL/SLI - Scalar shift left */
6334 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
6335 int immh
, int immb
, int opcode
,
6338 int size
= 32 - clz32(immh
) - 1;
6339 int immhb
= immh
<< 3 | immb
;
6340 int shift
= immhb
- (8 << size
);
6341 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
6342 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
6344 if (!extract32(immh
, 3, 1)) {
6345 unallocated_encoding(s
);
6349 if (!fp_access_check(s
)) {
6353 tcg_rn
= read_fp_dreg(s
, rn
);
6354 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6356 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
6358 write_fp_dreg(s
, rd
, tcg_rd
);
6360 tcg_temp_free_i64(tcg_rn
);
6361 tcg_temp_free_i64(tcg_rd
);
6364 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
6365 * (signed/unsigned) narrowing */
6366 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
6367 bool is_u_shift
, bool is_u_narrow
,
6368 int immh
, int immb
, int opcode
,
6371 int immhb
= immh
<< 3 | immb
;
6372 int size
= 32 - clz32(immh
) - 1;
6373 int esize
= 8 << size
;
6374 int shift
= (2 * esize
) - immhb
;
6375 int elements
= is_scalar
? 1 : (64 / esize
);
6376 bool round
= extract32(opcode
, 0, 1);
6377 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
6378 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
6379 TCGv_i32 tcg_rd_narrowed
;
6382 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
6383 { gen_helper_neon_narrow_sat_s8
,
6384 gen_helper_neon_unarrow_sat8
},
6385 { gen_helper_neon_narrow_sat_s16
,
6386 gen_helper_neon_unarrow_sat16
},
6387 { gen_helper_neon_narrow_sat_s32
,
6388 gen_helper_neon_unarrow_sat32
},
6391 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
6392 gen_helper_neon_narrow_sat_u8
,
6393 gen_helper_neon_narrow_sat_u16
,
6394 gen_helper_neon_narrow_sat_u32
,
6397 NeonGenNarrowEnvFn
*narrowfn
;
6403 if (extract32(immh
, 3, 1)) {
6404 unallocated_encoding(s
);
6408 if (!fp_access_check(s
)) {
6413 narrowfn
= unsigned_narrow_fns
[size
];
6415 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
6418 tcg_rn
= tcg_temp_new_i64();
6419 tcg_rd
= tcg_temp_new_i64();
6420 tcg_rd_narrowed
= tcg_temp_new_i32();
6421 tcg_final
= tcg_const_i64(0);
6424 uint64_t round_const
= 1ULL << (shift
- 1);
6425 tcg_round
= tcg_const_i64(round_const
);
6427 TCGV_UNUSED_I64(tcg_round
);
6430 for (i
= 0; i
< elements
; i
++) {
6431 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
6432 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6433 false, is_u_shift
, size
+1, shift
);
6434 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
6435 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
6436 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
6440 clear_vec_high(s
, rd
);
6441 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
6443 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
6447 tcg_temp_free_i64(tcg_round
);
6449 tcg_temp_free_i64(tcg_rn
);
6450 tcg_temp_free_i64(tcg_rd
);
6451 tcg_temp_free_i32(tcg_rd_narrowed
);
6452 tcg_temp_free_i64(tcg_final
);
6456 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
6457 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
6458 bool src_unsigned
, bool dst_unsigned
,
6459 int immh
, int immb
, int rn
, int rd
)
6461 int immhb
= immh
<< 3 | immb
;
6462 int size
= 32 - clz32(immh
) - 1;
6463 int shift
= immhb
- (8 << size
);
6467 assert(!(scalar
&& is_q
));
6470 if (!is_q
&& extract32(immh
, 3, 1)) {
6471 unallocated_encoding(s
);
6475 /* Since we use the variable-shift helpers we must
6476 * replicate the shift count into each element of
6477 * the tcg_shift value.
6481 shift
|= shift
<< 8;
6484 shift
|= shift
<< 16;
6490 g_assert_not_reached();
6494 if (!fp_access_check(s
)) {
6499 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
6500 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
6501 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
6502 { NULL
, gen_helper_neon_qshl_u64
},
6504 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
6505 int maxpass
= is_q
? 2 : 1;
6507 for (pass
= 0; pass
< maxpass
; pass
++) {
6508 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6510 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6511 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6512 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6514 tcg_temp_free_i64(tcg_op
);
6516 tcg_temp_free_i64(tcg_shift
);
6519 clear_vec_high(s
, rd
);
6522 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
6523 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
6525 { gen_helper_neon_qshl_s8
,
6526 gen_helper_neon_qshl_s16
,
6527 gen_helper_neon_qshl_s32
},
6528 { gen_helper_neon_qshlu_s8
,
6529 gen_helper_neon_qshlu_s16
,
6530 gen_helper_neon_qshlu_s32
}
6532 { NULL
, NULL
, NULL
},
6533 { gen_helper_neon_qshl_u8
,
6534 gen_helper_neon_qshl_u16
,
6535 gen_helper_neon_qshl_u32
}
6538 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
6539 TCGMemOp memop
= scalar
? size
: MO_32
;
6540 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
6542 for (pass
= 0; pass
< maxpass
; pass
++) {
6543 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6545 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
6546 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6550 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
6553 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
6558 g_assert_not_reached();
6560 write_fp_sreg(s
, rd
, tcg_op
);
6562 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6565 tcg_temp_free_i32(tcg_op
);
6567 tcg_temp_free_i32(tcg_shift
);
6569 if (!is_q
&& !scalar
) {
6570 clear_vec_high(s
, rd
);
6575 /* Common vector code for handling integer to FP conversion */
6576 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
6577 int elements
, int is_signed
,
6578 int fracbits
, int size
)
6580 bool is_double
= size
== 3 ? true : false;
6581 TCGv_ptr tcg_fpst
= get_fpstatus_ptr();
6582 TCGv_i32 tcg_shift
= tcg_const_i32(fracbits
);
6583 TCGv_i64 tcg_int
= tcg_temp_new_i64();
6584 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
6587 for (pass
= 0; pass
< elements
; pass
++) {
6588 read_vec_element(s
, tcg_int
, rn
, pass
, mop
);
6591 TCGv_i64 tcg_double
= tcg_temp_new_i64();
6593 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6594 tcg_shift
, tcg_fpst
);
6596 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6597 tcg_shift
, tcg_fpst
);
6599 if (elements
== 1) {
6600 write_fp_dreg(s
, rd
, tcg_double
);
6602 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
6604 tcg_temp_free_i64(tcg_double
);
6606 TCGv_i32 tcg_single
= tcg_temp_new_i32();
6608 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6609 tcg_shift
, tcg_fpst
);
6611 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6612 tcg_shift
, tcg_fpst
);
6614 if (elements
== 1) {
6615 write_fp_sreg(s
, rd
, tcg_single
);
6617 write_vec_element_i32(s
, tcg_single
, rd
, pass
, MO_32
);
6619 tcg_temp_free_i32(tcg_single
);
6623 if (!is_double
&& elements
== 2) {
6624 clear_vec_high(s
, rd
);
6627 tcg_temp_free_i64(tcg_int
);
6628 tcg_temp_free_ptr(tcg_fpst
);
6629 tcg_temp_free_i32(tcg_shift
);
6632 /* UCVTF/SCVTF - Integer to FP conversion */
6633 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
6634 bool is_q
, bool is_u
,
6635 int immh
, int immb
, int opcode
,
6638 bool is_double
= extract32(immh
, 3, 1);
6639 int size
= is_double
? MO_64
: MO_32
;
6641 int immhb
= immh
<< 3 | immb
;
6642 int fracbits
= (is_double
? 128 : 64) - immhb
;
6644 if (!extract32(immh
, 2, 2)) {
6645 unallocated_encoding(s
);
6652 elements
= is_double
? 2 : is_q
? 4 : 2;
6653 if (is_double
&& !is_q
) {
6654 unallocated_encoding(s
);
6659 if (!fp_access_check(s
)) {
6663 /* immh == 0 would be a failure of the decode logic */
6666 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
6669 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
6670 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
6671 bool is_q
, bool is_u
,
6672 int immh
, int immb
, int rn
, int rd
)
6674 bool is_double
= extract32(immh
, 3, 1);
6675 int immhb
= immh
<< 3 | immb
;
6676 int fracbits
= (is_double
? 128 : 64) - immhb
;
6678 TCGv_ptr tcg_fpstatus
;
6679 TCGv_i32 tcg_rmode
, tcg_shift
;
6681 if (!extract32(immh
, 2, 2)) {
6682 unallocated_encoding(s
);
6686 if (!is_scalar
&& !is_q
&& is_double
) {
6687 unallocated_encoding(s
);
6691 if (!fp_access_check(s
)) {
6695 assert(!(is_scalar
&& is_q
));
6697 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
6698 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6699 tcg_fpstatus
= get_fpstatus_ptr();
6700 tcg_shift
= tcg_const_i32(fracbits
);
6703 int maxpass
= is_scalar
? 1 : 2;
6705 for (pass
= 0; pass
< maxpass
; pass
++) {
6706 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6708 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6710 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6712 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6714 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6715 tcg_temp_free_i64(tcg_op
);
6718 clear_vec_high(s
, rd
);
6721 int maxpass
= is_scalar
? 1 : is_q
? 4 : 2;
6722 for (pass
= 0; pass
< maxpass
; pass
++) {
6723 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6725 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
6727 gen_helper_vfp_touls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6729 gen_helper_vfp_tosls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6732 write_fp_sreg(s
, rd
, tcg_op
);
6734 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6736 tcg_temp_free_i32(tcg_op
);
6738 if (!is_q
&& !is_scalar
) {
6739 clear_vec_high(s
, rd
);
6743 tcg_temp_free_ptr(tcg_fpstatus
);
6744 tcg_temp_free_i32(tcg_shift
);
6745 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6746 tcg_temp_free_i32(tcg_rmode
);
6749 /* C3.6.9 AdvSIMD scalar shift by immediate
6750 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
6751 * +-----+---+-------------+------+------+--------+---+------+------+
6752 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
6753 * +-----+---+-------------+------+------+--------+---+------+------+
6755 * This is the scalar version so it works on a fixed sized registers
6757 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
6759 int rd
= extract32(insn
, 0, 5);
6760 int rn
= extract32(insn
, 5, 5);
6761 int opcode
= extract32(insn
, 11, 5);
6762 int immb
= extract32(insn
, 16, 3);
6763 int immh
= extract32(insn
, 19, 4);
6764 bool is_u
= extract32(insn
, 29, 1);
6767 unallocated_encoding(s
);
6772 case 0x08: /* SRI */
6774 unallocated_encoding(s
);
6778 case 0x00: /* SSHR / USHR */
6779 case 0x02: /* SSRA / USRA */
6780 case 0x04: /* SRSHR / URSHR */
6781 case 0x06: /* SRSRA / URSRA */
6782 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6784 case 0x0a: /* SHL / SLI */
6785 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6787 case 0x1c: /* SCVTF, UCVTF */
6788 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
6791 case 0x10: /* SQSHRUN, SQSHRUN2 */
6792 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
6794 unallocated_encoding(s
);
6797 handle_vec_simd_sqshrn(s
, true, false, false, true,
6798 immh
, immb
, opcode
, rn
, rd
);
6800 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
6801 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
6802 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
6803 immh
, immb
, opcode
, rn
, rd
);
6805 case 0xc: /* SQSHLU */
6807 unallocated_encoding(s
);
6810 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
6812 case 0xe: /* SQSHL, UQSHL */
6813 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
6815 case 0x1f: /* FCVTZS, FCVTZU */
6816 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
6819 unallocated_encoding(s
);
6824 /* C3.6.10 AdvSIMD scalar three different
6825 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6826 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6827 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
6828 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6830 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
6832 bool is_u
= extract32(insn
, 29, 1);
6833 int size
= extract32(insn
, 22, 2);
6834 int opcode
= extract32(insn
, 12, 4);
6835 int rm
= extract32(insn
, 16, 5);
6836 int rn
= extract32(insn
, 5, 5);
6837 int rd
= extract32(insn
, 0, 5);
6840 unallocated_encoding(s
);
6845 case 0x9: /* SQDMLAL, SQDMLAL2 */
6846 case 0xb: /* SQDMLSL, SQDMLSL2 */
6847 case 0xd: /* SQDMULL, SQDMULL2 */
6848 if (size
== 0 || size
== 3) {
6849 unallocated_encoding(s
);
6854 unallocated_encoding(s
);
6858 if (!fp_access_check(s
)) {
6863 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6864 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6865 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6867 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
6868 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
6870 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
6871 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6874 case 0xd: /* SQDMULL, SQDMULL2 */
6876 case 0xb: /* SQDMLSL, SQDMLSL2 */
6877 tcg_gen_neg_i64(tcg_res
, tcg_res
);
6879 case 0x9: /* SQDMLAL, SQDMLAL2 */
6880 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
6881 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
6885 g_assert_not_reached();
6888 write_fp_dreg(s
, rd
, tcg_res
);
6890 tcg_temp_free_i64(tcg_op1
);
6891 tcg_temp_free_i64(tcg_op2
);
6892 tcg_temp_free_i64(tcg_res
);
6894 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6895 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6896 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6898 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_16
);
6899 read_vec_element_i32(s
, tcg_op2
, rm
, 0, MO_16
);
6901 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
6902 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6905 case 0xd: /* SQDMULL, SQDMULL2 */
6907 case 0xb: /* SQDMLSL, SQDMLSL2 */
6908 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
6910 case 0x9: /* SQDMLAL, SQDMLAL2 */
6912 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
6913 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
6914 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
6916 tcg_temp_free_i64(tcg_op3
);
6920 g_assert_not_reached();
6923 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
6924 write_fp_dreg(s
, rd
, tcg_res
);
6926 tcg_temp_free_i32(tcg_op1
);
6927 tcg_temp_free_i32(tcg_op2
);
6928 tcg_temp_free_i64(tcg_res
);
6932 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
6933 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
6935 /* Handle 64x64->64 opcodes which are shared between the scalar
6936 * and vector 3-same groups. We cover every opcode where size == 3
6937 * is valid in either the three-reg-same (integer, not pairwise)
6938 * or scalar-three-reg-same groups. (Some opcodes are not yet
6944 case 0x1: /* SQADD */
6946 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6948 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6951 case 0x5: /* SQSUB */
6953 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6955 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6958 case 0x6: /* CMGT, CMHI */
6959 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
6960 * We implement this using setcond (test) and then negating.
6962 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
6964 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
6965 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6967 case 0x7: /* CMGE, CMHS */
6968 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
6970 case 0x11: /* CMTST, CMEQ */
6975 /* CMTST : test is "if (X & Y != 0)". */
6976 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6977 tcg_gen_setcondi_i64(TCG_COND_NE
, tcg_rd
, tcg_rd
, 0);
6978 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6980 case 0x8: /* SSHL, USHL */
6982 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6984 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
6987 case 0x9: /* SQSHL, UQSHL */
6989 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6991 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6994 case 0xa: /* SRSHL, URSHL */
6996 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6998 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
7001 case 0xb: /* SQRSHL, UQRSHL */
7003 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7005 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
7008 case 0x10: /* ADD, SUB */
7010 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
7012 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
7016 g_assert_not_reached();
7020 /* Handle the 3-same-operands float operations; shared by the scalar
7021 * and vector encodings. The caller must filter out any encodings
7022 * not allocated for the encoding it is dealing with.
7024 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
7025 int fpopcode
, int rd
, int rn
, int rm
)
7028 TCGv_ptr fpst
= get_fpstatus_ptr();
7030 for (pass
= 0; pass
< elements
; pass
++) {
7033 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
7034 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
7035 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7037 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
7038 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
7041 case 0x39: /* FMLS */
7042 /* As usual for ARM, separate negation for fused multiply-add */
7043 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
7045 case 0x19: /* FMLA */
7046 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7047 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
7050 case 0x18: /* FMAXNM */
7051 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7053 case 0x1a: /* FADD */
7054 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7056 case 0x1b: /* FMULX */
7057 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7059 case 0x1c: /* FCMEQ */
7060 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7062 case 0x1e: /* FMAX */
7063 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7065 case 0x1f: /* FRECPS */
7066 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7068 case 0x38: /* FMINNM */
7069 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7071 case 0x3a: /* FSUB */
7072 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7074 case 0x3e: /* FMIN */
7075 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7077 case 0x3f: /* FRSQRTS */
7078 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7080 case 0x5b: /* FMUL */
7081 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7083 case 0x5c: /* FCMGE */
7084 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7086 case 0x5d: /* FACGE */
7087 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7089 case 0x5f: /* FDIV */
7090 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7092 case 0x7a: /* FABD */
7093 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7094 gen_helper_vfp_absd(tcg_res
, tcg_res
);
7096 case 0x7c: /* FCMGT */
7097 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7099 case 0x7d: /* FACGT */
7100 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7103 g_assert_not_reached();
7106 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7108 tcg_temp_free_i64(tcg_res
);
7109 tcg_temp_free_i64(tcg_op1
);
7110 tcg_temp_free_i64(tcg_op2
);
7113 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7114 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7115 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7117 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
7118 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
7121 case 0x39: /* FMLS */
7122 /* As usual for ARM, separate negation for fused multiply-add */
7123 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
7125 case 0x19: /* FMLA */
7126 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7127 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
7130 case 0x1a: /* FADD */
7131 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7133 case 0x1b: /* FMULX */
7134 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7136 case 0x1c: /* FCMEQ */
7137 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7139 case 0x1e: /* FMAX */
7140 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7142 case 0x1f: /* FRECPS */
7143 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7145 case 0x18: /* FMAXNM */
7146 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7148 case 0x38: /* FMINNM */
7149 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7151 case 0x3a: /* FSUB */
7152 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7154 case 0x3e: /* FMIN */
7155 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7157 case 0x3f: /* FRSQRTS */
7158 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7160 case 0x5b: /* FMUL */
7161 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7163 case 0x5c: /* FCMGE */
7164 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7166 case 0x5d: /* FACGE */
7167 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7169 case 0x5f: /* FDIV */
7170 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7172 case 0x7a: /* FABD */
7173 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7174 gen_helper_vfp_abss(tcg_res
, tcg_res
);
7176 case 0x7c: /* FCMGT */
7177 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7179 case 0x7d: /* FACGT */
7180 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7183 g_assert_not_reached();
7186 if (elements
== 1) {
7187 /* scalar single so clear high part */
7188 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
7190 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
7191 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
7192 tcg_temp_free_i64(tcg_tmp
);
7194 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7197 tcg_temp_free_i32(tcg_res
);
7198 tcg_temp_free_i32(tcg_op1
);
7199 tcg_temp_free_i32(tcg_op2
);
7203 tcg_temp_free_ptr(fpst
);
7205 if ((elements
<< size
) < 4) {
7206 /* scalar, or non-quad vector op */
7207 clear_vec_high(s
, rd
);
7211 /* C3.6.11 AdvSIMD scalar three same
7212 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
7213 * +-----+---+-----------+------+---+------+--------+---+------+------+
7214 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
7215 * +-----+---+-----------+------+---+------+--------+---+------+------+
7217 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
7219 int rd
= extract32(insn
, 0, 5);
7220 int rn
= extract32(insn
, 5, 5);
7221 int opcode
= extract32(insn
, 11, 5);
7222 int rm
= extract32(insn
, 16, 5);
7223 int size
= extract32(insn
, 22, 2);
7224 bool u
= extract32(insn
, 29, 1);
7227 if (opcode
>= 0x18) {
7228 /* Floating point: U, size[1] and opcode indicate operation */
7229 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
7231 case 0x1b: /* FMULX */
7232 case 0x1f: /* FRECPS */
7233 case 0x3f: /* FRSQRTS */
7234 case 0x5d: /* FACGE */
7235 case 0x7d: /* FACGT */
7236 case 0x1c: /* FCMEQ */
7237 case 0x5c: /* FCMGE */
7238 case 0x7c: /* FCMGT */
7239 case 0x7a: /* FABD */
7242 unallocated_encoding(s
);
7246 if (!fp_access_check(s
)) {
7250 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
7255 case 0x1: /* SQADD, UQADD */
7256 case 0x5: /* SQSUB, UQSUB */
7257 case 0x9: /* SQSHL, UQSHL */
7258 case 0xb: /* SQRSHL, UQRSHL */
7260 case 0x8: /* SSHL, USHL */
7261 case 0xa: /* SRSHL, URSHL */
7262 case 0x6: /* CMGT, CMHI */
7263 case 0x7: /* CMGE, CMHS */
7264 case 0x11: /* CMTST, CMEQ */
7265 case 0x10: /* ADD, SUB (vector) */
7267 unallocated_encoding(s
);
7271 case 0x16: /* SQDMULH, SQRDMULH (vector) */
7272 if (size
!= 1 && size
!= 2) {
7273 unallocated_encoding(s
);
7278 unallocated_encoding(s
);
7282 if (!fp_access_check(s
)) {
7286 tcg_rd
= tcg_temp_new_i64();
7289 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7290 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
7292 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
7293 tcg_temp_free_i64(tcg_rn
);
7294 tcg_temp_free_i64(tcg_rm
);
7296 /* Do a single operation on the lowest element in the vector.
7297 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
7298 * no side effects for all these operations.
7299 * OPTME: special-purpose helpers would avoid doing some
7300 * unnecessary work in the helper for the 8 and 16 bit cases.
7302 NeonGenTwoOpEnvFn
*genenvfn
;
7303 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7304 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
7305 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
7307 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7308 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
7311 case 0x1: /* SQADD, UQADD */
7313 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7314 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
7315 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
7316 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
7318 genenvfn
= fns
[size
][u
];
7321 case 0x5: /* SQSUB, UQSUB */
7323 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7324 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
7325 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
7326 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
7328 genenvfn
= fns
[size
][u
];
7331 case 0x9: /* SQSHL, UQSHL */
7333 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7334 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
7335 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
7336 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
7338 genenvfn
= fns
[size
][u
];
7341 case 0xb: /* SQRSHL, UQRSHL */
7343 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7344 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
7345 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
7346 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
7348 genenvfn
= fns
[size
][u
];
7351 case 0x16: /* SQDMULH, SQRDMULH */
7353 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
7354 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
7355 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
7357 assert(size
== 1 || size
== 2);
7358 genenvfn
= fns
[size
- 1][u
];
7362 g_assert_not_reached();
7365 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
7366 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
7367 tcg_temp_free_i32(tcg_rd32
);
7368 tcg_temp_free_i32(tcg_rn
);
7369 tcg_temp_free_i32(tcg_rm
);
7372 write_fp_dreg(s
, rd
, tcg_rd
);
7374 tcg_temp_free_i64(tcg_rd
);
7377 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
7378 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
7379 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
7381 /* Handle 64->64 opcodes which are shared between the scalar and
7382 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
7383 * is valid in either group and also the double-precision fp ops.
7384 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
7390 case 0x4: /* CLS, CLZ */
7392 gen_helper_clz64(tcg_rd
, tcg_rn
);
7394 gen_helper_cls64(tcg_rd
, tcg_rn
);
7398 /* This opcode is shared with CNT and RBIT but we have earlier
7399 * enforced that size == 3 if and only if this is the NOT insn.
7401 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
7403 case 0x7: /* SQABS, SQNEG */
7405 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
7407 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
7410 case 0xa: /* CMLT */
7411 /* 64 bit integer comparison against zero, result is
7412 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
7417 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
7418 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7420 case 0x8: /* CMGT, CMGE */
7421 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
7423 case 0x9: /* CMEQ, CMLE */
7424 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
7426 case 0xb: /* ABS, NEG */
7428 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7430 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7431 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7432 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
7434 tcg_temp_free_i64(tcg_zero
);
7437 case 0x2f: /* FABS */
7438 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
7440 case 0x6f: /* FNEG */
7441 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
7443 case 0x7f: /* FSQRT */
7444 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
7446 case 0x1a: /* FCVTNS */
7447 case 0x1b: /* FCVTMS */
7448 case 0x1c: /* FCVTAS */
7449 case 0x3a: /* FCVTPS */
7450 case 0x3b: /* FCVTZS */
7452 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7453 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7454 tcg_temp_free_i32(tcg_shift
);
7457 case 0x5a: /* FCVTNU */
7458 case 0x5b: /* FCVTMU */
7459 case 0x5c: /* FCVTAU */
7460 case 0x7a: /* FCVTPU */
7461 case 0x7b: /* FCVTZU */
7463 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7464 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7465 tcg_temp_free_i32(tcg_shift
);
7468 case 0x18: /* FRINTN */
7469 case 0x19: /* FRINTM */
7470 case 0x38: /* FRINTP */
7471 case 0x39: /* FRINTZ */
7472 case 0x58: /* FRINTA */
7473 case 0x79: /* FRINTI */
7474 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7476 case 0x59: /* FRINTX */
7477 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7480 g_assert_not_reached();
7484 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
7485 bool is_scalar
, bool is_u
, bool is_q
,
7486 int size
, int rn
, int rd
)
7488 bool is_double
= (size
== 3);
7491 if (!fp_access_check(s
)) {
7495 fpst
= get_fpstatus_ptr();
7498 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7499 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7500 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7501 NeonGenTwoDoubleOPFn
*genfn
;
7506 case 0x2e: /* FCMLT (zero) */
7509 case 0x2c: /* FCMGT (zero) */
7510 genfn
= gen_helper_neon_cgt_f64
;
7512 case 0x2d: /* FCMEQ (zero) */
7513 genfn
= gen_helper_neon_ceq_f64
;
7515 case 0x6d: /* FCMLE (zero) */
7518 case 0x6c: /* FCMGE (zero) */
7519 genfn
= gen_helper_neon_cge_f64
;
7522 g_assert_not_reached();
7525 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7526 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7528 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7530 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7532 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7535 clear_vec_high(s
, rd
);
7538 tcg_temp_free_i64(tcg_res
);
7539 tcg_temp_free_i64(tcg_zero
);
7540 tcg_temp_free_i64(tcg_op
);
7542 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7543 TCGv_i32 tcg_zero
= tcg_const_i32(0);
7544 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7545 NeonGenTwoSingleOPFn
*genfn
;
7547 int pass
, maxpasses
;
7550 case 0x2e: /* FCMLT (zero) */
7553 case 0x2c: /* FCMGT (zero) */
7554 genfn
= gen_helper_neon_cgt_f32
;
7556 case 0x2d: /* FCMEQ (zero) */
7557 genfn
= gen_helper_neon_ceq_f32
;
7559 case 0x6d: /* FCMLE (zero) */
7562 case 0x6c: /* FCMGE (zero) */
7563 genfn
= gen_helper_neon_cge_f32
;
7566 g_assert_not_reached();
7572 maxpasses
= is_q
? 4 : 2;
7575 for (pass
= 0; pass
< maxpasses
; pass
++) {
7576 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7578 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7580 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7583 write_fp_sreg(s
, rd
, tcg_res
);
7585 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7588 tcg_temp_free_i32(tcg_res
);
7589 tcg_temp_free_i32(tcg_zero
);
7590 tcg_temp_free_i32(tcg_op
);
7591 if (!is_q
&& !is_scalar
) {
7592 clear_vec_high(s
, rd
);
7596 tcg_temp_free_ptr(fpst
);
7599 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
7600 bool is_scalar
, bool is_u
, bool is_q
,
7601 int size
, int rn
, int rd
)
7603 bool is_double
= (size
== 3);
7604 TCGv_ptr fpst
= get_fpstatus_ptr();
7607 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7608 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7611 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7612 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7614 case 0x3d: /* FRECPE */
7615 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
7617 case 0x3f: /* FRECPX */
7618 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
7620 case 0x7d: /* FRSQRTE */
7621 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
7624 g_assert_not_reached();
7626 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7629 clear_vec_high(s
, rd
);
7632 tcg_temp_free_i64(tcg_res
);
7633 tcg_temp_free_i64(tcg_op
);
7635 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7636 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7637 int pass
, maxpasses
;
7642 maxpasses
= is_q
? 4 : 2;
7645 for (pass
= 0; pass
< maxpasses
; pass
++) {
7646 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7649 case 0x3c: /* URECPE */
7650 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
7652 case 0x3d: /* FRECPE */
7653 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
7655 case 0x3f: /* FRECPX */
7656 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
7658 case 0x7d: /* FRSQRTE */
7659 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
7662 g_assert_not_reached();
7666 write_fp_sreg(s
, rd
, tcg_res
);
7668 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7671 tcg_temp_free_i32(tcg_res
);
7672 tcg_temp_free_i32(tcg_op
);
7673 if (!is_q
&& !is_scalar
) {
7674 clear_vec_high(s
, rd
);
7677 tcg_temp_free_ptr(fpst
);
7680 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
7681 int opcode
, bool u
, bool is_q
,
7682 int size
, int rn
, int rd
)
7684 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
7685 * in the source becomes a size element in the destination).
7688 TCGv_i32 tcg_res
[2];
7689 int destelt
= is_q
? 2 : 0;
7690 int passes
= scalar
? 1 : 2;
7693 tcg_res
[1] = tcg_const_i32(0);
7696 for (pass
= 0; pass
< passes
; pass
++) {
7697 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7698 NeonGenNarrowFn
*genfn
= NULL
;
7699 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
7702 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
7704 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7706 tcg_res
[pass
] = tcg_temp_new_i32();
7709 case 0x12: /* XTN, SQXTUN */
7711 static NeonGenNarrowFn
* const xtnfns
[3] = {
7712 gen_helper_neon_narrow_u8
,
7713 gen_helper_neon_narrow_u16
,
7714 tcg_gen_extrl_i64_i32
,
7716 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
7717 gen_helper_neon_unarrow_sat8
,
7718 gen_helper_neon_unarrow_sat16
,
7719 gen_helper_neon_unarrow_sat32
,
7722 genenvfn
= sqxtunfns
[size
];
7724 genfn
= xtnfns
[size
];
7728 case 0x14: /* SQXTN, UQXTN */
7730 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
7731 { gen_helper_neon_narrow_sat_s8
,
7732 gen_helper_neon_narrow_sat_u8
},
7733 { gen_helper_neon_narrow_sat_s16
,
7734 gen_helper_neon_narrow_sat_u16
},
7735 { gen_helper_neon_narrow_sat_s32
,
7736 gen_helper_neon_narrow_sat_u32
},
7738 genenvfn
= fns
[size
][u
];
7741 case 0x16: /* FCVTN, FCVTN2 */
7742 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
7744 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
7746 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
7747 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
7748 tcg_gen_extrl_i64_i32(tcg_lo
, tcg_op
);
7749 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, cpu_env
);
7750 tcg_gen_shri_i64(tcg_op
, tcg_op
, 32);
7751 tcg_gen_extrl_i64_i32(tcg_hi
, tcg_op
);
7752 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, cpu_env
);
7753 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
7754 tcg_temp_free_i32(tcg_lo
);
7755 tcg_temp_free_i32(tcg_hi
);
7758 case 0x56: /* FCVTXN, FCVTXN2 */
7759 /* 64 bit to 32 bit float conversion
7760 * with von Neumann rounding (round to odd)
7763 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
7766 g_assert_not_reached();
7770 genfn(tcg_res
[pass
], tcg_op
);
7771 } else if (genenvfn
) {
7772 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
7775 tcg_temp_free_i64(tcg_op
);
7778 for (pass
= 0; pass
< 2; pass
++) {
7779 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
7780 tcg_temp_free_i32(tcg_res
[pass
]);
7783 clear_vec_high(s
, rd
);
7787 /* Remaining saturating accumulating ops */
7788 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
7789 bool is_q
, int size
, int rn
, int rd
)
7791 bool is_double
= (size
== 3);
7794 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
7795 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7798 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7799 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
7800 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7802 if (is_u
) { /* USQADD */
7803 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7804 } else { /* SUQADD */
7805 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7807 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7810 clear_vec_high(s
, rd
);
7813 tcg_temp_free_i64(tcg_rd
);
7814 tcg_temp_free_i64(tcg_rn
);
7816 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7817 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7818 int pass
, maxpasses
;
7823 maxpasses
= is_q
? 4 : 2;
7826 for (pass
= 0; pass
< maxpasses
; pass
++) {
7828 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
7829 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
7831 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
7832 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7835 if (is_u
) { /* USQADD */
7838 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7841 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7844 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7847 g_assert_not_reached();
7849 } else { /* SUQADD */
7852 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7855 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7858 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7861 g_assert_not_reached();
7866 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7867 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
7868 tcg_temp_free_i64(tcg_zero
);
7870 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7874 clear_vec_high(s
, rd
);
7877 tcg_temp_free_i32(tcg_rd
);
7878 tcg_temp_free_i32(tcg_rn
);
7882 /* C3.6.12 AdvSIMD scalar two reg misc
7883 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7884 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7885 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
7886 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7888 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
7890 int rd
= extract32(insn
, 0, 5);
7891 int rn
= extract32(insn
, 5, 5);
7892 int opcode
= extract32(insn
, 12, 5);
7893 int size
= extract32(insn
, 22, 2);
7894 bool u
= extract32(insn
, 29, 1);
7895 bool is_fcvt
= false;
7898 TCGv_ptr tcg_fpstatus
;
7901 case 0x3: /* USQADD / SUQADD*/
7902 if (!fp_access_check(s
)) {
7905 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
7907 case 0x7: /* SQABS / SQNEG */
7909 case 0xa: /* CMLT */
7911 unallocated_encoding(s
);
7915 case 0x8: /* CMGT, CMGE */
7916 case 0x9: /* CMEQ, CMLE */
7917 case 0xb: /* ABS, NEG */
7919 unallocated_encoding(s
);
7923 case 0x12: /* SQXTUN */
7925 unallocated_encoding(s
);
7929 case 0x14: /* SQXTN, UQXTN */
7931 unallocated_encoding(s
);
7934 if (!fp_access_check(s
)) {
7937 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
7942 /* Floating point: U, size[1] and opcode indicate operation;
7943 * size[0] indicates single or double precision.
7945 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
7946 size
= extract32(size
, 0, 1) ? 3 : 2;
7948 case 0x2c: /* FCMGT (zero) */
7949 case 0x2d: /* FCMEQ (zero) */
7950 case 0x2e: /* FCMLT (zero) */
7951 case 0x6c: /* FCMGE (zero) */
7952 case 0x6d: /* FCMLE (zero) */
7953 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
7955 case 0x1d: /* SCVTF */
7956 case 0x5d: /* UCVTF */
7958 bool is_signed
= (opcode
== 0x1d);
7959 if (!fp_access_check(s
)) {
7962 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
7965 case 0x3d: /* FRECPE */
7966 case 0x3f: /* FRECPX */
7967 case 0x7d: /* FRSQRTE */
7968 if (!fp_access_check(s
)) {
7971 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
7973 case 0x1a: /* FCVTNS */
7974 case 0x1b: /* FCVTMS */
7975 case 0x3a: /* FCVTPS */
7976 case 0x3b: /* FCVTZS */
7977 case 0x5a: /* FCVTNU */
7978 case 0x5b: /* FCVTMU */
7979 case 0x7a: /* FCVTPU */
7980 case 0x7b: /* FCVTZU */
7982 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
7984 case 0x1c: /* FCVTAS */
7985 case 0x5c: /* FCVTAU */
7986 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
7988 rmode
= FPROUNDING_TIEAWAY
;
7990 case 0x56: /* FCVTXN, FCVTXN2 */
7992 unallocated_encoding(s
);
7995 if (!fp_access_check(s
)) {
7998 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
8001 unallocated_encoding(s
);
8006 unallocated_encoding(s
);
8010 if (!fp_access_check(s
)) {
8015 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
8016 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
8017 tcg_fpstatus
= get_fpstatus_ptr();
8019 TCGV_UNUSED_I32(tcg_rmode
);
8020 TCGV_UNUSED_PTR(tcg_fpstatus
);
8024 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
8025 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
8027 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
8028 write_fp_dreg(s
, rd
, tcg_rd
);
8029 tcg_temp_free_i64(tcg_rd
);
8030 tcg_temp_free_i64(tcg_rn
);
8032 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
8033 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
8035 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
8038 case 0x7: /* SQABS, SQNEG */
8040 NeonGenOneOpEnvFn
*genfn
;
8041 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
8042 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
8043 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
8044 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
8046 genfn
= fns
[size
][u
];
8047 genfn(tcg_rd
, cpu_env
, tcg_rn
);
8050 case 0x1a: /* FCVTNS */
8051 case 0x1b: /* FCVTMS */
8052 case 0x1c: /* FCVTAS */
8053 case 0x3a: /* FCVTPS */
8054 case 0x3b: /* FCVTZS */
8056 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8057 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8058 tcg_temp_free_i32(tcg_shift
);
8061 case 0x5a: /* FCVTNU */
8062 case 0x5b: /* FCVTMU */
8063 case 0x5c: /* FCVTAU */
8064 case 0x7a: /* FCVTPU */
8065 case 0x7b: /* FCVTZU */
8067 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8068 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8069 tcg_temp_free_i32(tcg_shift
);
8073 g_assert_not_reached();
8076 write_fp_sreg(s
, rd
, tcg_rd
);
8077 tcg_temp_free_i32(tcg_rd
);
8078 tcg_temp_free_i32(tcg_rn
);
8082 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
8083 tcg_temp_free_i32(tcg_rmode
);
8084 tcg_temp_free_ptr(tcg_fpstatus
);
8088 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
8089 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
8090 int immh
, int immb
, int opcode
, int rn
, int rd
)
8092 int size
= 32 - clz32(immh
) - 1;
8093 int immhb
= immh
<< 3 | immb
;
8094 int shift
= 2 * (8 << size
) - immhb
;
8095 bool accumulate
= false;
8097 bool insert
= false;
8098 int dsize
= is_q
? 128 : 64;
8099 int esize
= 8 << size
;
8100 int elements
= dsize
/esize
;
8101 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
8102 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8103 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8107 if (extract32(immh
, 3, 1) && !is_q
) {
8108 unallocated_encoding(s
);
8112 if (size
> 3 && !is_q
) {
8113 unallocated_encoding(s
);
8117 if (!fp_access_check(s
)) {
8122 case 0x02: /* SSRA / USRA (accumulate) */
8125 case 0x04: /* SRSHR / URSHR (rounding) */
8128 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8129 accumulate
= round
= true;
8131 case 0x08: /* SRI */
8137 uint64_t round_const
= 1ULL << (shift
- 1);
8138 tcg_round
= tcg_const_i64(round_const
);
8140 TCGV_UNUSED_I64(tcg_round
);
8143 for (i
= 0; i
< elements
; i
++) {
8144 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
8145 if (accumulate
|| insert
) {
8146 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
8150 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
8152 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8153 accumulate
, is_u
, size
, shift
);
8156 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8160 clear_vec_high(s
, rd
);
8164 tcg_temp_free_i64(tcg_round
);
8168 /* SHL/SLI - Vector shift left */
8169 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
8170 int immh
, int immb
, int opcode
, int rn
, int rd
)
8172 int size
= 32 - clz32(immh
) - 1;
8173 int immhb
= immh
<< 3 | immb
;
8174 int shift
= immhb
- (8 << size
);
8175 int dsize
= is_q
? 128 : 64;
8176 int esize
= 8 << size
;
8177 int elements
= dsize
/esize
;
8178 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8179 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8182 if (extract32(immh
, 3, 1) && !is_q
) {
8183 unallocated_encoding(s
);
8187 if (size
> 3 && !is_q
) {
8188 unallocated_encoding(s
);
8192 if (!fp_access_check(s
)) {
8196 for (i
= 0; i
< elements
; i
++) {
8197 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
8199 read_vec_element(s
, tcg_rd
, rd
, i
, size
);
8202 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
8204 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8208 clear_vec_high(s
, rd
);
8212 /* USHLL/SHLL - Vector shift left with widening */
8213 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
8214 int immh
, int immb
, int opcode
, int rn
, int rd
)
8216 int size
= 32 - clz32(immh
) - 1;
8217 int immhb
= immh
<< 3 | immb
;
8218 int shift
= immhb
- (8 << size
);
8220 int esize
= 8 << size
;
8221 int elements
= dsize
/esize
;
8222 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8223 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8227 unallocated_encoding(s
);
8231 if (!fp_access_check(s
)) {
8235 /* For the LL variants the store is larger than the load,
8236 * so if rd == rn we would overwrite parts of our input.
8237 * So load everything right now and use shifts in the main loop.
8239 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
8241 for (i
= 0; i
< elements
; i
++) {
8242 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
8243 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
8244 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
8245 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
8249 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
8250 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
8251 int immh
, int immb
, int opcode
, int rn
, int rd
)
8253 int immhb
= immh
<< 3 | immb
;
8254 int size
= 32 - clz32(immh
) - 1;
8256 int esize
= 8 << size
;
8257 int elements
= dsize
/esize
;
8258 int shift
= (2 * esize
) - immhb
;
8259 bool round
= extract32(opcode
, 0, 1);
8260 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
8264 if (extract32(immh
, 3, 1)) {
8265 unallocated_encoding(s
);
8269 if (!fp_access_check(s
)) {
8273 tcg_rn
= tcg_temp_new_i64();
8274 tcg_rd
= tcg_temp_new_i64();
8275 tcg_final
= tcg_temp_new_i64();
8276 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
8279 uint64_t round_const
= 1ULL << (shift
- 1);
8280 tcg_round
= tcg_const_i64(round_const
);
8282 TCGV_UNUSED_I64(tcg_round
);
8285 for (i
= 0; i
< elements
; i
++) {
8286 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
8287 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8288 false, true, size
+1, shift
);
8290 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8294 clear_vec_high(s
, rd
);
8295 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8297 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8301 tcg_temp_free_i64(tcg_round
);
8303 tcg_temp_free_i64(tcg_rn
);
8304 tcg_temp_free_i64(tcg_rd
);
8305 tcg_temp_free_i64(tcg_final
);
8310 /* C3.6.14 AdvSIMD shift by immediate
8311 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8312 * +---+---+---+-------------+------+------+--------+---+------+------+
8313 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8314 * +---+---+---+-------------+------+------+--------+---+------+------+
8316 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
8318 int rd
= extract32(insn
, 0, 5);
8319 int rn
= extract32(insn
, 5, 5);
8320 int opcode
= extract32(insn
, 11, 5);
8321 int immb
= extract32(insn
, 16, 3);
8322 int immh
= extract32(insn
, 19, 4);
8323 bool is_u
= extract32(insn
, 29, 1);
8324 bool is_q
= extract32(insn
, 30, 1);
8327 case 0x08: /* SRI */
8329 unallocated_encoding(s
);
8333 case 0x00: /* SSHR / USHR */
8334 case 0x02: /* SSRA / USRA (accumulate) */
8335 case 0x04: /* SRSHR / URSHR (rounding) */
8336 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8337 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8339 case 0x0a: /* SHL / SLI */
8340 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8342 case 0x10: /* SHRN */
8343 case 0x11: /* RSHRN / SQRSHRUN */
8345 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
8348 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
8351 case 0x12: /* SQSHRN / UQSHRN */
8352 case 0x13: /* SQRSHRN / UQRSHRN */
8353 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
8356 case 0x14: /* SSHLL / USHLL */
8357 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8359 case 0x1c: /* SCVTF / UCVTF */
8360 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
8363 case 0xc: /* SQSHLU */
8365 unallocated_encoding(s
);
8368 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
8370 case 0xe: /* SQSHL, UQSHL */
8371 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
8373 case 0x1f: /* FCVTZS/ FCVTZU */
8374 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
8377 unallocated_encoding(s
);
8382 /* Generate code to do a "long" addition or subtraction, ie one done in
8383 * TCGv_i64 on vector lanes twice the width specified by size.
8385 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
8386 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
8388 static NeonGenTwo64OpFn
* const fns
[3][2] = {
8389 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
8390 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
8391 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
8393 NeonGenTwo64OpFn
*genfn
;
8396 genfn
= fns
[size
][is_sub
];
8397 genfn(tcg_res
, tcg_op1
, tcg_op2
);
8400 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
8401 int opcode
, int rd
, int rn
, int rm
)
8403 /* 3-reg-different widening insns: 64 x 64 -> 128 */
8404 TCGv_i64 tcg_res
[2];
8407 tcg_res
[0] = tcg_temp_new_i64();
8408 tcg_res
[1] = tcg_temp_new_i64();
8410 /* Does this op do an adding accumulate, a subtracting accumulate,
8411 * or no accumulate at all?
8429 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8430 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8433 /* size == 2 means two 32x32->64 operations; this is worth special
8434 * casing because we can generally handle it inline.
8437 for (pass
= 0; pass
< 2; pass
++) {
8438 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8439 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8440 TCGv_i64 tcg_passres
;
8441 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
8443 int elt
= pass
+ is_q
* 2;
8445 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
8446 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
8449 tcg_passres
= tcg_res
[pass
];
8451 tcg_passres
= tcg_temp_new_i64();
8455 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8456 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8458 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8459 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8461 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8462 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8464 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
8465 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
8467 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
8468 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
8469 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
8471 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
8472 tcg_temp_free_i64(tcg_tmp1
);
8473 tcg_temp_free_i64(tcg_tmp2
);
8476 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8477 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8478 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8479 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8481 case 9: /* SQDMLAL, SQDMLAL2 */
8482 case 11: /* SQDMLSL, SQDMLSL2 */
8483 case 13: /* SQDMULL, SQDMULL2 */
8484 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8485 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
8486 tcg_passres
, tcg_passres
);
8489 g_assert_not_reached();
8492 if (opcode
== 9 || opcode
== 11) {
8493 /* saturating accumulate ops */
8495 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
8497 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
8498 tcg_res
[pass
], tcg_passres
);
8499 } else if (accop
> 0) {
8500 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8501 } else if (accop
< 0) {
8502 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8506 tcg_temp_free_i64(tcg_passres
);
8509 tcg_temp_free_i64(tcg_op1
);
8510 tcg_temp_free_i64(tcg_op2
);
8513 /* size 0 or 1, generally helper functions */
8514 for (pass
= 0; pass
< 2; pass
++) {
8515 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8516 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8517 TCGv_i64 tcg_passres
;
8518 int elt
= pass
+ is_q
* 2;
8520 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
8521 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
8524 tcg_passres
= tcg_res
[pass
];
8526 tcg_passres
= tcg_temp_new_i64();
8530 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8531 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8533 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
8534 static NeonGenWidenFn
* const widenfns
[2][2] = {
8535 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8536 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8538 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8540 widenfn(tcg_op2_64
, tcg_op2
);
8541 widenfn(tcg_passres
, tcg_op1
);
8542 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
8543 tcg_passres
, tcg_op2_64
);
8544 tcg_temp_free_i64(tcg_op2_64
);
8547 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8548 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8551 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8553 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8557 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
8559 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
8563 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8564 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8565 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8568 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
8570 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
8574 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8576 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8580 case 9: /* SQDMLAL, SQDMLAL2 */
8581 case 11: /* SQDMLSL, SQDMLSL2 */
8582 case 13: /* SQDMULL, SQDMULL2 */
8584 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8585 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
8586 tcg_passres
, tcg_passres
);
8588 case 14: /* PMULL */
8590 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
8593 g_assert_not_reached();
8595 tcg_temp_free_i32(tcg_op1
);
8596 tcg_temp_free_i32(tcg_op2
);
8599 if (opcode
== 9 || opcode
== 11) {
8600 /* saturating accumulate ops */
8602 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
8604 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
8608 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
8609 tcg_res
[pass
], tcg_passres
);
8611 tcg_temp_free_i64(tcg_passres
);
8616 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8617 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8618 tcg_temp_free_i64(tcg_res
[0]);
8619 tcg_temp_free_i64(tcg_res
[1]);
8622 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
8623 int opcode
, int rd
, int rn
, int rm
)
8625 TCGv_i64 tcg_res
[2];
8626 int part
= is_q
? 2 : 0;
8629 for (pass
= 0; pass
< 2; pass
++) {
8630 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8631 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8632 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
8633 static NeonGenWidenFn
* const widenfns
[3][2] = {
8634 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8635 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8636 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
8638 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8640 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8641 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
8642 widenfn(tcg_op2_wide
, tcg_op2
);
8643 tcg_temp_free_i32(tcg_op2
);
8644 tcg_res
[pass
] = tcg_temp_new_i64();
8645 gen_neon_addl(size
, (opcode
== 3),
8646 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
8647 tcg_temp_free_i64(tcg_op1
);
8648 tcg_temp_free_i64(tcg_op2_wide
);
8651 for (pass
= 0; pass
< 2; pass
++) {
8652 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8653 tcg_temp_free_i64(tcg_res
[pass
]);
8657 static void do_narrow_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8659 tcg_gen_shri_i64(in
, in
, 32);
8660 tcg_gen_extrl_i64_i32(res
, in
);
8663 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8665 tcg_gen_addi_i64(in
, in
, 1U << 31);
8666 do_narrow_high_u32(res
, in
);
8669 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
8670 int opcode
, int rd
, int rn
, int rm
)
8672 TCGv_i32 tcg_res
[2];
8673 int part
= is_q
? 2 : 0;
8676 for (pass
= 0; pass
< 2; pass
++) {
8677 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8678 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8679 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
8680 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
8681 { gen_helper_neon_narrow_high_u8
,
8682 gen_helper_neon_narrow_round_high_u8
},
8683 { gen_helper_neon_narrow_high_u16
,
8684 gen_helper_neon_narrow_round_high_u16
},
8685 { do_narrow_high_u32
, do_narrow_round_high_u32
},
8687 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
8689 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8690 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8692 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
8694 tcg_temp_free_i64(tcg_op1
);
8695 tcg_temp_free_i64(tcg_op2
);
8697 tcg_res
[pass
] = tcg_temp_new_i32();
8698 gennarrow(tcg_res
[pass
], tcg_wideres
);
8699 tcg_temp_free_i64(tcg_wideres
);
8702 for (pass
= 0; pass
< 2; pass
++) {
8703 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
8704 tcg_temp_free_i32(tcg_res
[pass
]);
8707 clear_vec_high(s
, rd
);
8711 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
8713 /* PMULL of 64 x 64 -> 128 is an odd special case because it
8714 * is the only three-reg-diff instruction which produces a
8715 * 128-bit wide result from a single operation. However since
8716 * it's possible to calculate the two halves more or less
8717 * separately we just use two helper calls.
8719 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8720 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8721 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8723 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
8724 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
8725 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
8726 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
8727 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
8728 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
8730 tcg_temp_free_i64(tcg_op1
);
8731 tcg_temp_free_i64(tcg_op2
);
8732 tcg_temp_free_i64(tcg_res
);
8735 /* C3.6.15 AdvSIMD three different
8736 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8737 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8738 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8739 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8741 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8743 /* Instructions in this group fall into three basic classes
8744 * (in each case with the operation working on each element in
8745 * the input vectors):
8746 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
8748 * (2) wide 64 x 128 -> 128
8749 * (3) narrowing 128 x 128 -> 64
8750 * Here we do initial decode, catch unallocated cases and
8751 * dispatch to separate functions for each class.
8753 int is_q
= extract32(insn
, 30, 1);
8754 int is_u
= extract32(insn
, 29, 1);
8755 int size
= extract32(insn
, 22, 2);
8756 int opcode
= extract32(insn
, 12, 4);
8757 int rm
= extract32(insn
, 16, 5);
8758 int rn
= extract32(insn
, 5, 5);
8759 int rd
= extract32(insn
, 0, 5);
8762 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
8763 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
8764 /* 64 x 128 -> 128 */
8766 unallocated_encoding(s
);
8769 if (!fp_access_check(s
)) {
8772 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8774 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
8775 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
8776 /* 128 x 128 -> 64 */
8778 unallocated_encoding(s
);
8781 if (!fp_access_check(s
)) {
8784 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8786 case 14: /* PMULL, PMULL2 */
8787 if (is_u
|| size
== 1 || size
== 2) {
8788 unallocated_encoding(s
);
8792 if (!arm_dc_feature(s
, ARM_FEATURE_V8_PMULL
)) {
8793 unallocated_encoding(s
);
8796 if (!fp_access_check(s
)) {
8799 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
8803 case 9: /* SQDMLAL, SQDMLAL2 */
8804 case 11: /* SQDMLSL, SQDMLSL2 */
8805 case 13: /* SQDMULL, SQDMULL2 */
8806 if (is_u
|| size
== 0) {
8807 unallocated_encoding(s
);
8811 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8812 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8813 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8814 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8815 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8816 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8817 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
8818 /* 64 x 64 -> 128 */
8820 unallocated_encoding(s
);
8824 if (!fp_access_check(s
)) {
8828 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8831 /* opcode 15 not allocated */
8832 unallocated_encoding(s
);
8837 /* Logic op (opcode == 3) subgroup of C3.6.16. */
8838 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
8840 int rd
= extract32(insn
, 0, 5);
8841 int rn
= extract32(insn
, 5, 5);
8842 int rm
= extract32(insn
, 16, 5);
8843 int size
= extract32(insn
, 22, 2);
8844 bool is_u
= extract32(insn
, 29, 1);
8845 bool is_q
= extract32(insn
, 30, 1);
8846 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
8849 if (!fp_access_check(s
)) {
8853 tcg_op1
= tcg_temp_new_i64();
8854 tcg_op2
= tcg_temp_new_i64();
8855 tcg_res
[0] = tcg_temp_new_i64();
8856 tcg_res
[1] = tcg_temp_new_i64();
8858 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
8859 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8860 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8865 tcg_gen_and_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8868 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8871 tcg_gen_or_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8874 tcg_gen_orc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8879 /* B* ops need res loaded to operate on */
8880 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8885 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8887 case 1: /* BSL bitwise select */
8888 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8889 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8890 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op1
);
8892 case 2: /* BIT, bitwise insert if true */
8893 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8894 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8895 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8897 case 3: /* BIF, bitwise insert if false */
8898 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8899 tcg_gen_andc_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8900 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8906 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8908 tcg_gen_movi_i64(tcg_res
[1], 0);
8910 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8912 tcg_temp_free_i64(tcg_op1
);
8913 tcg_temp_free_i64(tcg_op2
);
8914 tcg_temp_free_i64(tcg_res
[0]);
8915 tcg_temp_free_i64(tcg_res
[1]);
8918 /* Helper functions for 32 bit comparisons */
8919 static void gen_max_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8921 tcg_gen_movcond_i32(TCG_COND_GE
, res
, op1
, op2
, op1
, op2
);
8924 static void gen_max_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8926 tcg_gen_movcond_i32(TCG_COND_GEU
, res
, op1
, op2
, op1
, op2
);
8929 static void gen_min_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8931 tcg_gen_movcond_i32(TCG_COND_LE
, res
, op1
, op2
, op1
, op2
);
8934 static void gen_min_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8936 tcg_gen_movcond_i32(TCG_COND_LEU
, res
, op1
, op2
, op1
, op2
);
8939 /* Pairwise op subgroup of C3.6.16.
8941 * This is called directly or via the handle_3same_float for float pairwise
8942 * operations where the opcode and size are calculated differently.
8944 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
8945 int size
, int rn
, int rm
, int rd
)
8950 /* Floating point operations need fpst */
8951 if (opcode
>= 0x58) {
8952 fpst
= get_fpstatus_ptr();
8954 TCGV_UNUSED_PTR(fpst
);
8957 if (!fp_access_check(s
)) {
8961 /* These operations work on the concatenated rm:rn, with each pair of
8962 * adjacent elements being operated on to produce an element in the result.
8965 TCGv_i64 tcg_res
[2];
8967 for (pass
= 0; pass
< 2; pass
++) {
8968 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8969 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8970 int passreg
= (pass
== 0) ? rn
: rm
;
8972 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
8973 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
8974 tcg_res
[pass
] = tcg_temp_new_i64();
8977 case 0x17: /* ADDP */
8978 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8980 case 0x58: /* FMAXNMP */
8981 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8983 case 0x5a: /* FADDP */
8984 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8986 case 0x5e: /* FMAXP */
8987 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8989 case 0x78: /* FMINNMP */
8990 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8992 case 0x7e: /* FMINP */
8993 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8996 g_assert_not_reached();
8999 tcg_temp_free_i64(tcg_op1
);
9000 tcg_temp_free_i64(tcg_op2
);
9003 for (pass
= 0; pass
< 2; pass
++) {
9004 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9005 tcg_temp_free_i64(tcg_res
[pass
]);
9008 int maxpass
= is_q
? 4 : 2;
9009 TCGv_i32 tcg_res
[4];
9011 for (pass
= 0; pass
< maxpass
; pass
++) {
9012 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9013 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9014 NeonGenTwoOpFn
*genfn
= NULL
;
9015 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
9016 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
9018 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
9019 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
9020 tcg_res
[pass
] = tcg_temp_new_i32();
9023 case 0x17: /* ADDP */
9025 static NeonGenTwoOpFn
* const fns
[3] = {
9026 gen_helper_neon_padd_u8
,
9027 gen_helper_neon_padd_u16
,
9033 case 0x14: /* SMAXP, UMAXP */
9035 static NeonGenTwoOpFn
* const fns
[3][2] = {
9036 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
9037 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
9038 { gen_max_s32
, gen_max_u32
},
9040 genfn
= fns
[size
][u
];
9043 case 0x15: /* SMINP, UMINP */
9045 static NeonGenTwoOpFn
* const fns
[3][2] = {
9046 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
9047 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
9048 { gen_min_s32
, gen_min_u32
},
9050 genfn
= fns
[size
][u
];
9053 /* The FP operations are all on single floats (32 bit) */
9054 case 0x58: /* FMAXNMP */
9055 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9057 case 0x5a: /* FADDP */
9058 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9060 case 0x5e: /* FMAXP */
9061 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9063 case 0x78: /* FMINNMP */
9064 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9066 case 0x7e: /* FMINP */
9067 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9070 g_assert_not_reached();
9073 /* FP ops called directly, otherwise call now */
9075 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9078 tcg_temp_free_i32(tcg_op1
);
9079 tcg_temp_free_i32(tcg_op2
);
9082 for (pass
= 0; pass
< maxpass
; pass
++) {
9083 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9084 tcg_temp_free_i32(tcg_res
[pass
]);
9087 clear_vec_high(s
, rd
);
9091 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
9092 tcg_temp_free_ptr(fpst
);
9096 /* Floating point op subgroup of C3.6.16. */
9097 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
9099 /* For floating point ops, the U, size[1] and opcode bits
9100 * together indicate the operation. size[0] indicates single
9103 int fpopcode
= extract32(insn
, 11, 5)
9104 | (extract32(insn
, 23, 1) << 5)
9105 | (extract32(insn
, 29, 1) << 6);
9106 int is_q
= extract32(insn
, 30, 1);
9107 int size
= extract32(insn
, 22, 1);
9108 int rm
= extract32(insn
, 16, 5);
9109 int rn
= extract32(insn
, 5, 5);
9110 int rd
= extract32(insn
, 0, 5);
9112 int datasize
= is_q
? 128 : 64;
9113 int esize
= 32 << size
;
9114 int elements
= datasize
/ esize
;
9116 if (size
== 1 && !is_q
) {
9117 unallocated_encoding(s
);
9122 case 0x58: /* FMAXNMP */
9123 case 0x5a: /* FADDP */
9124 case 0x5e: /* FMAXP */
9125 case 0x78: /* FMINNMP */
9126 case 0x7e: /* FMINP */
9127 if (size
&& !is_q
) {
9128 unallocated_encoding(s
);
9131 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
9134 case 0x1b: /* FMULX */
9135 case 0x1f: /* FRECPS */
9136 case 0x3f: /* FRSQRTS */
9137 case 0x5d: /* FACGE */
9138 case 0x7d: /* FACGT */
9139 case 0x19: /* FMLA */
9140 case 0x39: /* FMLS */
9141 case 0x18: /* FMAXNM */
9142 case 0x1a: /* FADD */
9143 case 0x1c: /* FCMEQ */
9144 case 0x1e: /* FMAX */
9145 case 0x38: /* FMINNM */
9146 case 0x3a: /* FSUB */
9147 case 0x3e: /* FMIN */
9148 case 0x5b: /* FMUL */
9149 case 0x5c: /* FCMGE */
9150 case 0x5f: /* FDIV */
9151 case 0x7a: /* FABD */
9152 case 0x7c: /* FCMGT */
9153 if (!fp_access_check(s
)) {
9157 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
9160 unallocated_encoding(s
);
9165 /* Integer op subgroup of C3.6.16. */
9166 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
9168 int is_q
= extract32(insn
, 30, 1);
9169 int u
= extract32(insn
, 29, 1);
9170 int size
= extract32(insn
, 22, 2);
9171 int opcode
= extract32(insn
, 11, 5);
9172 int rm
= extract32(insn
, 16, 5);
9173 int rn
= extract32(insn
, 5, 5);
9174 int rd
= extract32(insn
, 0, 5);
9178 case 0x13: /* MUL, PMUL */
9179 if (u
&& size
!= 0) {
9180 unallocated_encoding(s
);
9184 case 0x0: /* SHADD, UHADD */
9185 case 0x2: /* SRHADD, URHADD */
9186 case 0x4: /* SHSUB, UHSUB */
9187 case 0xc: /* SMAX, UMAX */
9188 case 0xd: /* SMIN, UMIN */
9189 case 0xe: /* SABD, UABD */
9190 case 0xf: /* SABA, UABA */
9191 case 0x12: /* MLA, MLS */
9193 unallocated_encoding(s
);
9197 case 0x16: /* SQDMULH, SQRDMULH */
9198 if (size
== 0 || size
== 3) {
9199 unallocated_encoding(s
);
9204 if (size
== 3 && !is_q
) {
9205 unallocated_encoding(s
);
9211 if (!fp_access_check(s
)) {
9217 for (pass
= 0; pass
< 2; pass
++) {
9218 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9219 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9220 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9222 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9223 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9225 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
9227 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9229 tcg_temp_free_i64(tcg_res
);
9230 tcg_temp_free_i64(tcg_op1
);
9231 tcg_temp_free_i64(tcg_op2
);
9234 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9235 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9236 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9237 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9238 NeonGenTwoOpFn
*genfn
= NULL
;
9239 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
9241 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
9242 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
9245 case 0x0: /* SHADD, UHADD */
9247 static NeonGenTwoOpFn
* const fns
[3][2] = {
9248 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
9249 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
9250 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
9252 genfn
= fns
[size
][u
];
9255 case 0x1: /* SQADD, UQADD */
9257 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9258 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9259 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9260 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9262 genenvfn
= fns
[size
][u
];
9265 case 0x2: /* SRHADD, URHADD */
9267 static NeonGenTwoOpFn
* const fns
[3][2] = {
9268 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
9269 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
9270 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
9272 genfn
= fns
[size
][u
];
9275 case 0x4: /* SHSUB, UHSUB */
9277 static NeonGenTwoOpFn
* const fns
[3][2] = {
9278 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
9279 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
9280 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
9282 genfn
= fns
[size
][u
];
9285 case 0x5: /* SQSUB, UQSUB */
9287 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9288 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9289 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9290 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9292 genenvfn
= fns
[size
][u
];
9295 case 0x6: /* CMGT, CMHI */
9297 static NeonGenTwoOpFn
* const fns
[3][2] = {
9298 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_u8
},
9299 { gen_helper_neon_cgt_s16
, gen_helper_neon_cgt_u16
},
9300 { gen_helper_neon_cgt_s32
, gen_helper_neon_cgt_u32
},
9302 genfn
= fns
[size
][u
];
9305 case 0x7: /* CMGE, CMHS */
9307 static NeonGenTwoOpFn
* const fns
[3][2] = {
9308 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_u8
},
9309 { gen_helper_neon_cge_s16
, gen_helper_neon_cge_u16
},
9310 { gen_helper_neon_cge_s32
, gen_helper_neon_cge_u32
},
9312 genfn
= fns
[size
][u
];
9315 case 0x8: /* SSHL, USHL */
9317 static NeonGenTwoOpFn
* const fns
[3][2] = {
9318 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
9319 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
9320 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
9322 genfn
= fns
[size
][u
];
9325 case 0x9: /* SQSHL, UQSHL */
9327 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9328 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9329 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9330 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9332 genenvfn
= fns
[size
][u
];
9335 case 0xa: /* SRSHL, URSHL */
9337 static NeonGenTwoOpFn
* const fns
[3][2] = {
9338 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
9339 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
9340 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
9342 genfn
= fns
[size
][u
];
9345 case 0xb: /* SQRSHL, UQRSHL */
9347 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9348 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9349 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9350 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9352 genenvfn
= fns
[size
][u
];
9355 case 0xc: /* SMAX, UMAX */
9357 static NeonGenTwoOpFn
* const fns
[3][2] = {
9358 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
9359 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
9360 { gen_max_s32
, gen_max_u32
},
9362 genfn
= fns
[size
][u
];
9366 case 0xd: /* SMIN, UMIN */
9368 static NeonGenTwoOpFn
* const fns
[3][2] = {
9369 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
9370 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
9371 { gen_min_s32
, gen_min_u32
},
9373 genfn
= fns
[size
][u
];
9376 case 0xe: /* SABD, UABD */
9377 case 0xf: /* SABA, UABA */
9379 static NeonGenTwoOpFn
* const fns
[3][2] = {
9380 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
9381 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
9382 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
9384 genfn
= fns
[size
][u
];
9387 case 0x10: /* ADD, SUB */
9389 static NeonGenTwoOpFn
* const fns
[3][2] = {
9390 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9391 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9392 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9394 genfn
= fns
[size
][u
];
9397 case 0x11: /* CMTST, CMEQ */
9399 static NeonGenTwoOpFn
* const fns
[3][2] = {
9400 { gen_helper_neon_tst_u8
, gen_helper_neon_ceq_u8
},
9401 { gen_helper_neon_tst_u16
, gen_helper_neon_ceq_u16
},
9402 { gen_helper_neon_tst_u32
, gen_helper_neon_ceq_u32
},
9404 genfn
= fns
[size
][u
];
9407 case 0x13: /* MUL, PMUL */
9411 genfn
= gen_helper_neon_mul_p8
;
9414 /* fall through : MUL */
9415 case 0x12: /* MLA, MLS */
9417 static NeonGenTwoOpFn
* const fns
[3] = {
9418 gen_helper_neon_mul_u8
,
9419 gen_helper_neon_mul_u16
,
9425 case 0x16: /* SQDMULH, SQRDMULH */
9427 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9428 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9429 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9431 assert(size
== 1 || size
== 2);
9432 genenvfn
= fns
[size
- 1][u
];
9436 g_assert_not_reached();
9440 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
9442 genfn(tcg_res
, tcg_op1
, tcg_op2
);
9445 if (opcode
== 0xf || opcode
== 0x12) {
9446 /* SABA, UABA, MLA, MLS: accumulating ops */
9447 static NeonGenTwoOpFn
* const fns
[3][2] = {
9448 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9449 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9450 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9452 bool is_sub
= (opcode
== 0x12 && u
); /* MLS */
9454 genfn
= fns
[size
][is_sub
];
9455 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
9456 genfn(tcg_res
, tcg_op1
, tcg_res
);
9459 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9461 tcg_temp_free_i32(tcg_res
);
9462 tcg_temp_free_i32(tcg_op1
);
9463 tcg_temp_free_i32(tcg_op2
);
9468 clear_vec_high(s
, rd
);
9472 /* C3.6.16 AdvSIMD three same
9473 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
9474 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9475 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
9476 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9478 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
9480 int opcode
= extract32(insn
, 11, 5);
9483 case 0x3: /* logic ops */
9484 disas_simd_3same_logic(s
, insn
);
9486 case 0x17: /* ADDP */
9487 case 0x14: /* SMAXP, UMAXP */
9488 case 0x15: /* SMINP, UMINP */
9490 /* Pairwise operations */
9491 int is_q
= extract32(insn
, 30, 1);
9492 int u
= extract32(insn
, 29, 1);
9493 int size
= extract32(insn
, 22, 2);
9494 int rm
= extract32(insn
, 16, 5);
9495 int rn
= extract32(insn
, 5, 5);
9496 int rd
= extract32(insn
, 0, 5);
9497 if (opcode
== 0x17) {
9498 if (u
|| (size
== 3 && !is_q
)) {
9499 unallocated_encoding(s
);
9504 unallocated_encoding(s
);
9508 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
9512 /* floating point ops, sz[1] and U are part of opcode */
9513 disas_simd_3same_float(s
, insn
);
9516 disas_simd_3same_int(s
, insn
);
9521 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
9522 int size
, int rn
, int rd
)
9524 /* Handle 2-reg-misc ops which are widening (so each size element
9525 * in the source becomes a 2*size element in the destination.
9526 * The only instruction like this is FCVTL.
9531 /* 32 -> 64 bit fp conversion */
9532 TCGv_i64 tcg_res
[2];
9533 int srcelt
= is_q
? 2 : 0;
9535 for (pass
= 0; pass
< 2; pass
++) {
9536 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9537 tcg_res
[pass
] = tcg_temp_new_i64();
9539 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
9540 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
9541 tcg_temp_free_i32(tcg_op
);
9543 for (pass
= 0; pass
< 2; pass
++) {
9544 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9545 tcg_temp_free_i64(tcg_res
[pass
]);
9548 /* 16 -> 32 bit fp conversion */
9549 int srcelt
= is_q
? 4 : 0;
9550 TCGv_i32 tcg_res
[4];
9552 for (pass
= 0; pass
< 4; pass
++) {
9553 tcg_res
[pass
] = tcg_temp_new_i32();
9555 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
9556 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
9559 for (pass
= 0; pass
< 4; pass
++) {
9560 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9561 tcg_temp_free_i32(tcg_res
[pass
]);
9566 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
9567 bool is_q
, int size
, int rn
, int rd
)
9569 int op
= (opcode
<< 1) | u
;
9570 int opsz
= op
+ size
;
9571 int grp_size
= 3 - opsz
;
9572 int dsize
= is_q
? 128 : 64;
9576 unallocated_encoding(s
);
9580 if (!fp_access_check(s
)) {
9585 /* Special case bytes, use bswap op on each group of elements */
9586 int groups
= dsize
/ (8 << grp_size
);
9588 for (i
= 0; i
< groups
; i
++) {
9589 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9591 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
9594 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
9597 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
9600 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
9603 g_assert_not_reached();
9605 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
9606 tcg_temp_free_i64(tcg_tmp
);
9609 clear_vec_high(s
, rd
);
9612 int revmask
= (1 << grp_size
) - 1;
9613 int esize
= 8 << size
;
9614 int elements
= dsize
/ esize
;
9615 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9616 TCGv_i64 tcg_rd
= tcg_const_i64(0);
9617 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
9619 for (i
= 0; i
< elements
; i
++) {
9620 int e_rev
= (i
& 0xf) ^ revmask
;
9621 int off
= e_rev
* esize
;
9622 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
9624 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
9625 tcg_rn
, off
- 64, esize
);
9627 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
9630 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
9631 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
9633 tcg_temp_free_i64(tcg_rd_hi
);
9634 tcg_temp_free_i64(tcg_rd
);
9635 tcg_temp_free_i64(tcg_rn
);
9639 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
9640 bool is_q
, int size
, int rn
, int rd
)
9642 /* Implement the pairwise operations from 2-misc:
9643 * SADDLP, UADDLP, SADALP, UADALP.
9644 * These all add pairs of elements in the input to produce a
9645 * double-width result element in the output (possibly accumulating).
9647 bool accum
= (opcode
== 0x6);
9648 int maxpass
= is_q
? 2 : 1;
9650 TCGv_i64 tcg_res
[2];
9653 /* 32 + 32 -> 64 op */
9654 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
9656 for (pass
= 0; pass
< maxpass
; pass
++) {
9657 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9658 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9660 tcg_res
[pass
] = tcg_temp_new_i64();
9662 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
9663 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
9664 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9666 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
9667 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9670 tcg_temp_free_i64(tcg_op1
);
9671 tcg_temp_free_i64(tcg_op2
);
9674 for (pass
= 0; pass
< maxpass
; pass
++) {
9675 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9676 NeonGenOneOpFn
*genfn
;
9677 static NeonGenOneOpFn
* const fns
[2][2] = {
9678 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
9679 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
9682 genfn
= fns
[size
][u
];
9684 tcg_res
[pass
] = tcg_temp_new_i64();
9686 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9687 genfn(tcg_res
[pass
], tcg_op
);
9690 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
9692 gen_helper_neon_addl_u16(tcg_res
[pass
],
9693 tcg_res
[pass
], tcg_op
);
9695 gen_helper_neon_addl_u32(tcg_res
[pass
],
9696 tcg_res
[pass
], tcg_op
);
9699 tcg_temp_free_i64(tcg_op
);
9703 tcg_res
[1] = tcg_const_i64(0);
9705 for (pass
= 0; pass
< 2; pass
++) {
9706 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9707 tcg_temp_free_i64(tcg_res
[pass
]);
9711 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
9713 /* Implement SHLL and SHLL2 */
9715 int part
= is_q
? 2 : 0;
9716 TCGv_i64 tcg_res
[2];
9718 for (pass
= 0; pass
< 2; pass
++) {
9719 static NeonGenWidenFn
* const widenfns
[3] = {
9720 gen_helper_neon_widen_u8
,
9721 gen_helper_neon_widen_u16
,
9722 tcg_gen_extu_i32_i64
,
9724 NeonGenWidenFn
*widenfn
= widenfns
[size
];
9725 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9727 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
9728 tcg_res
[pass
] = tcg_temp_new_i64();
9729 widenfn(tcg_res
[pass
], tcg_op
);
9730 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
9732 tcg_temp_free_i32(tcg_op
);
9735 for (pass
= 0; pass
< 2; pass
++) {
9736 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9737 tcg_temp_free_i64(tcg_res
[pass
]);
9741 /* C3.6.17 AdvSIMD two reg misc
9742 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9743 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9744 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9745 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9747 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9749 int size
= extract32(insn
, 22, 2);
9750 int opcode
= extract32(insn
, 12, 5);
9751 bool u
= extract32(insn
, 29, 1);
9752 bool is_q
= extract32(insn
, 30, 1);
9753 int rn
= extract32(insn
, 5, 5);
9754 int rd
= extract32(insn
, 0, 5);
9755 bool need_fpstatus
= false;
9756 bool need_rmode
= false;
9759 TCGv_ptr tcg_fpstatus
;
9762 case 0x0: /* REV64, REV32 */
9763 case 0x1: /* REV16 */
9764 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9766 case 0x5: /* CNT, NOT, RBIT */
9767 if (u
&& size
== 0) {
9768 /* NOT: adjust size so we can use the 64-bits-at-a-time loop. */
9771 } else if (u
&& size
== 1) {
9774 } else if (!u
&& size
== 0) {
9778 unallocated_encoding(s
);
9780 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
9781 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
9783 unallocated_encoding(s
);
9786 if (!fp_access_check(s
)) {
9790 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
9792 case 0x4: /* CLS, CLZ */
9794 unallocated_encoding(s
);
9798 case 0x2: /* SADDLP, UADDLP */
9799 case 0x6: /* SADALP, UADALP */
9801 unallocated_encoding(s
);
9804 if (!fp_access_check(s
)) {
9807 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9809 case 0x13: /* SHLL, SHLL2 */
9810 if (u
== 0 || size
== 3) {
9811 unallocated_encoding(s
);
9814 if (!fp_access_check(s
)) {
9817 handle_shll(s
, is_q
, size
, rn
, rd
);
9819 case 0xa: /* CMLT */
9821 unallocated_encoding(s
);
9825 case 0x8: /* CMGT, CMGE */
9826 case 0x9: /* CMEQ, CMLE */
9827 case 0xb: /* ABS, NEG */
9828 if (size
== 3 && !is_q
) {
9829 unallocated_encoding(s
);
9833 case 0x3: /* SUQADD, USQADD */
9834 if (size
== 3 && !is_q
) {
9835 unallocated_encoding(s
);
9838 if (!fp_access_check(s
)) {
9841 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
9843 case 0x7: /* SQABS, SQNEG */
9844 if (size
== 3 && !is_q
) {
9845 unallocated_encoding(s
);
9853 /* Floating point: U, size[1] and opcode indicate operation;
9854 * size[0] indicates single or double precision.
9856 int is_double
= extract32(size
, 0, 1);
9857 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9858 size
= is_double
? 3 : 2;
9860 case 0x2f: /* FABS */
9861 case 0x6f: /* FNEG */
9862 if (size
== 3 && !is_q
) {
9863 unallocated_encoding(s
);
9867 case 0x1d: /* SCVTF */
9868 case 0x5d: /* UCVTF */
9870 bool is_signed
= (opcode
== 0x1d) ? true : false;
9871 int elements
= is_double
? 2 : is_q
? 4 : 2;
9872 if (is_double
&& !is_q
) {
9873 unallocated_encoding(s
);
9876 if (!fp_access_check(s
)) {
9879 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
9882 case 0x2c: /* FCMGT (zero) */
9883 case 0x2d: /* FCMEQ (zero) */
9884 case 0x2e: /* FCMLT (zero) */
9885 case 0x6c: /* FCMGE (zero) */
9886 case 0x6d: /* FCMLE (zero) */
9887 if (size
== 3 && !is_q
) {
9888 unallocated_encoding(s
);
9891 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9893 case 0x7f: /* FSQRT */
9894 if (size
== 3 && !is_q
) {
9895 unallocated_encoding(s
);
9899 case 0x1a: /* FCVTNS */
9900 case 0x1b: /* FCVTMS */
9901 case 0x3a: /* FCVTPS */
9902 case 0x3b: /* FCVTZS */
9903 case 0x5a: /* FCVTNU */
9904 case 0x5b: /* FCVTMU */
9905 case 0x7a: /* FCVTPU */
9906 case 0x7b: /* FCVTZU */
9907 need_fpstatus
= true;
9909 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9910 if (size
== 3 && !is_q
) {
9911 unallocated_encoding(s
);
9915 case 0x5c: /* FCVTAU */
9916 case 0x1c: /* FCVTAS */
9917 need_fpstatus
= true;
9919 rmode
= FPROUNDING_TIEAWAY
;
9920 if (size
== 3 && !is_q
) {
9921 unallocated_encoding(s
);
9925 case 0x3c: /* URECPE */
9927 unallocated_encoding(s
);
9931 case 0x3d: /* FRECPE */
9932 case 0x7d: /* FRSQRTE */
9933 if (size
== 3 && !is_q
) {
9934 unallocated_encoding(s
);
9937 if (!fp_access_check(s
)) {
9940 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9942 case 0x56: /* FCVTXN, FCVTXN2 */
9944 unallocated_encoding(s
);
9948 case 0x16: /* FCVTN, FCVTN2 */
9949 /* handle_2misc_narrow does a 2*size -> size operation, but these
9950 * instructions encode the source size rather than dest size.
9952 if (!fp_access_check(s
)) {
9955 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
9957 case 0x17: /* FCVTL, FCVTL2 */
9958 if (!fp_access_check(s
)) {
9961 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
9963 case 0x18: /* FRINTN */
9964 case 0x19: /* FRINTM */
9965 case 0x38: /* FRINTP */
9966 case 0x39: /* FRINTZ */
9968 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9970 case 0x59: /* FRINTX */
9971 case 0x79: /* FRINTI */
9972 need_fpstatus
= true;
9973 if (size
== 3 && !is_q
) {
9974 unallocated_encoding(s
);
9978 case 0x58: /* FRINTA */
9980 rmode
= FPROUNDING_TIEAWAY
;
9981 need_fpstatus
= true;
9982 if (size
== 3 && !is_q
) {
9983 unallocated_encoding(s
);
9987 case 0x7c: /* URSQRTE */
9989 unallocated_encoding(s
);
9992 need_fpstatus
= true;
9995 unallocated_encoding(s
);
10001 unallocated_encoding(s
);
10005 if (!fp_access_check(s
)) {
10009 if (need_fpstatus
) {
10010 tcg_fpstatus
= get_fpstatus_ptr();
10012 TCGV_UNUSED_PTR(tcg_fpstatus
);
10015 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
10016 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10018 TCGV_UNUSED_I32(tcg_rmode
);
10022 /* All 64-bit element operations can be shared with scalar 2misc */
10025 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
10026 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10027 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10029 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10031 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
10032 tcg_rmode
, tcg_fpstatus
);
10034 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10036 tcg_temp_free_i64(tcg_res
);
10037 tcg_temp_free_i64(tcg_op
);
10042 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
10043 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10044 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10047 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
10050 /* Special cases for 32 bit elements */
10052 case 0xa: /* CMLT */
10053 /* 32 bit integer comparison against zero, result is
10054 * test ? (2^32 - 1) : 0. We implement via setcond(test)
10057 cond
= TCG_COND_LT
;
10059 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
10060 tcg_gen_neg_i32(tcg_res
, tcg_res
);
10062 case 0x8: /* CMGT, CMGE */
10063 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
10065 case 0x9: /* CMEQ, CMLE */
10066 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
10068 case 0x4: /* CLS */
10070 gen_helper_clz32(tcg_res
, tcg_op
);
10072 gen_helper_cls32(tcg_res
, tcg_op
);
10075 case 0x7: /* SQABS, SQNEG */
10077 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
10079 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
10082 case 0xb: /* ABS, NEG */
10084 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10086 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10087 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10088 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
10089 tcg_zero
, tcg_op
, tcg_res
);
10090 tcg_temp_free_i32(tcg_zero
);
10093 case 0x2f: /* FABS */
10094 gen_helper_vfp_abss(tcg_res
, tcg_op
);
10096 case 0x6f: /* FNEG */
10097 gen_helper_vfp_negs(tcg_res
, tcg_op
);
10099 case 0x7f: /* FSQRT */
10100 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
10102 case 0x1a: /* FCVTNS */
10103 case 0x1b: /* FCVTMS */
10104 case 0x1c: /* FCVTAS */
10105 case 0x3a: /* FCVTPS */
10106 case 0x3b: /* FCVTZS */
10108 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10109 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
10110 tcg_shift
, tcg_fpstatus
);
10111 tcg_temp_free_i32(tcg_shift
);
10114 case 0x5a: /* FCVTNU */
10115 case 0x5b: /* FCVTMU */
10116 case 0x5c: /* FCVTAU */
10117 case 0x7a: /* FCVTPU */
10118 case 0x7b: /* FCVTZU */
10120 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10121 gen_helper_vfp_touls(tcg_res
, tcg_op
,
10122 tcg_shift
, tcg_fpstatus
);
10123 tcg_temp_free_i32(tcg_shift
);
10126 case 0x18: /* FRINTN */
10127 case 0x19: /* FRINTM */
10128 case 0x38: /* FRINTP */
10129 case 0x39: /* FRINTZ */
10130 case 0x58: /* FRINTA */
10131 case 0x79: /* FRINTI */
10132 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
10134 case 0x59: /* FRINTX */
10135 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
10137 case 0x7c: /* URSQRTE */
10138 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
10141 g_assert_not_reached();
10144 /* Use helpers for 8 and 16 bit elements */
10146 case 0x5: /* CNT, RBIT */
10147 /* For these two insns size is part of the opcode specifier
10148 * (handled earlier); they always operate on byte elements.
10151 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
10153 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
10156 case 0x7: /* SQABS, SQNEG */
10158 NeonGenOneOpEnvFn
*genfn
;
10159 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
10160 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
10161 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
10163 genfn
= fns
[size
][u
];
10164 genfn(tcg_res
, cpu_env
, tcg_op
);
10167 case 0x8: /* CMGT, CMGE */
10168 case 0x9: /* CMEQ, CMLE */
10169 case 0xa: /* CMLT */
10171 static NeonGenTwoOpFn
* const fns
[3][2] = {
10172 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
10173 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
10174 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
10176 NeonGenTwoOpFn
*genfn
;
10179 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10181 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
10182 comp
= (opcode
- 0x8) * 2 + u
;
10183 /* ...but LE, LT are implemented as reverse GE, GT */
10184 reverse
= (comp
> 2);
10188 genfn
= fns
[comp
][size
];
10190 genfn(tcg_res
, tcg_zero
, tcg_op
);
10192 genfn(tcg_res
, tcg_op
, tcg_zero
);
10194 tcg_temp_free_i32(tcg_zero
);
10197 case 0xb: /* ABS, NEG */
10199 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10201 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
10203 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
10205 tcg_temp_free_i32(tcg_zero
);
10208 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
10210 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
10214 case 0x4: /* CLS, CLZ */
10217 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
10219 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
10223 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
10225 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
10230 g_assert_not_reached();
10234 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10236 tcg_temp_free_i32(tcg_res
);
10237 tcg_temp_free_i32(tcg_op
);
10241 clear_vec_high(s
, rd
);
10245 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10246 tcg_temp_free_i32(tcg_rmode
);
10248 if (need_fpstatus
) {
10249 tcg_temp_free_ptr(tcg_fpstatus
);
10253 /* C3.6.13 AdvSIMD scalar x indexed element
10254 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10255 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10256 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10257 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10258 * C3.6.18 AdvSIMD vector x indexed element
10259 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10260 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10261 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10262 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10264 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
10266 /* This encoding has two kinds of instruction:
10267 * normal, where we perform elt x idxelt => elt for each
10268 * element in the vector
10269 * long, where we perform elt x idxelt and generate a result of
10270 * double the width of the input element
10271 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
10273 bool is_scalar
= extract32(insn
, 28, 1);
10274 bool is_q
= extract32(insn
, 30, 1);
10275 bool u
= extract32(insn
, 29, 1);
10276 int size
= extract32(insn
, 22, 2);
10277 int l
= extract32(insn
, 21, 1);
10278 int m
= extract32(insn
, 20, 1);
10279 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
10280 int rm
= extract32(insn
, 16, 4);
10281 int opcode
= extract32(insn
, 12, 4);
10282 int h
= extract32(insn
, 11, 1);
10283 int rn
= extract32(insn
, 5, 5);
10284 int rd
= extract32(insn
, 0, 5);
10285 bool is_long
= false;
10286 bool is_fp
= false;
10291 case 0x0: /* MLA */
10292 case 0x4: /* MLS */
10293 if (!u
|| is_scalar
) {
10294 unallocated_encoding(s
);
10298 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10299 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10300 case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
10302 unallocated_encoding(s
);
10307 case 0x3: /* SQDMLAL, SQDMLAL2 */
10308 case 0x7: /* SQDMLSL, SQDMLSL2 */
10309 case 0xb: /* SQDMULL, SQDMULL2 */
10312 case 0xc: /* SQDMULH */
10313 case 0xd: /* SQRDMULH */
10315 unallocated_encoding(s
);
10319 case 0x8: /* MUL */
10320 if (u
|| is_scalar
) {
10321 unallocated_encoding(s
);
10325 case 0x1: /* FMLA */
10326 case 0x5: /* FMLS */
10328 unallocated_encoding(s
);
10332 case 0x9: /* FMUL, FMULX */
10333 if (!extract32(size
, 1, 1)) {
10334 unallocated_encoding(s
);
10340 unallocated_encoding(s
);
10345 /* low bit of size indicates single/double */
10346 size
= extract32(size
, 0, 1) ? 3 : 2;
10348 index
= h
<< 1 | l
;
10351 unallocated_encoding(s
);
10360 index
= h
<< 2 | l
<< 1 | m
;
10363 index
= h
<< 1 | l
;
10367 unallocated_encoding(s
);
10372 if (!fp_access_check(s
)) {
10377 fpst
= get_fpstatus_ptr();
10379 TCGV_UNUSED_PTR(fpst
);
10383 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10386 assert(is_fp
&& is_q
&& !is_long
);
10388 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
10390 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10391 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10392 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10394 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10397 case 0x5: /* FMLS */
10398 /* As usual for ARM, separate negation for fused multiply-add */
10399 gen_helper_vfp_negd(tcg_op
, tcg_op
);
10401 case 0x1: /* FMLA */
10402 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10403 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10405 case 0x9: /* FMUL, FMULX */
10407 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10409 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10413 g_assert_not_reached();
10416 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10417 tcg_temp_free_i64(tcg_op
);
10418 tcg_temp_free_i64(tcg_res
);
10422 clear_vec_high(s
, rd
);
10425 tcg_temp_free_i64(tcg_idx
);
10426 } else if (!is_long
) {
10427 /* 32 bit floating point, or 16 or 32 bit integer.
10428 * For the 16 bit scalar case we use the usual Neon helpers and
10429 * rely on the fact that 0 op 0 == 0 with no side effects.
10431 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10432 int pass
, maxpasses
;
10437 maxpasses
= is_q
? 4 : 2;
10440 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10442 if (size
== 1 && !is_scalar
) {
10443 /* The simplest way to handle the 16x16 indexed ops is to duplicate
10444 * the index into both halves of the 32 bit tcg_idx and then use
10445 * the usual Neon helpers.
10447 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10450 for (pass
= 0; pass
< maxpasses
; pass
++) {
10451 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10452 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10454 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
10457 case 0x0: /* MLA */
10458 case 0x4: /* MLS */
10459 case 0x8: /* MUL */
10461 static NeonGenTwoOpFn
* const fns
[2][2] = {
10462 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
10463 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
10465 NeonGenTwoOpFn
*genfn
;
10466 bool is_sub
= opcode
== 0x4;
10469 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
10471 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
10473 if (opcode
== 0x8) {
10476 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
10477 genfn
= fns
[size
- 1][is_sub
];
10478 genfn(tcg_res
, tcg_op
, tcg_res
);
10481 case 0x5: /* FMLS */
10482 /* As usual for ARM, separate negation for fused multiply-add */
10483 gen_helper_vfp_negs(tcg_op
, tcg_op
);
10485 case 0x1: /* FMLA */
10486 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10487 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10489 case 0x9: /* FMUL, FMULX */
10491 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10493 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10496 case 0xc: /* SQDMULH */
10498 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
10501 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
10505 case 0xd: /* SQRDMULH */
10507 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
10510 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
10515 g_assert_not_reached();
10519 write_fp_sreg(s
, rd
, tcg_res
);
10521 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10524 tcg_temp_free_i32(tcg_op
);
10525 tcg_temp_free_i32(tcg_res
);
10528 tcg_temp_free_i32(tcg_idx
);
10531 clear_vec_high(s
, rd
);
10534 /* long ops: 16x16->32 or 32x32->64 */
10535 TCGv_i64 tcg_res
[2];
10537 bool satop
= extract32(opcode
, 0, 1);
10538 TCGMemOp memop
= MO_32
;
10545 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10547 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
10549 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10550 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10551 TCGv_i64 tcg_passres
;
10557 passelt
= pass
+ (is_q
* 2);
10560 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
10562 tcg_res
[pass
] = tcg_temp_new_i64();
10564 if (opcode
== 0xa || opcode
== 0xb) {
10565 /* Non-accumulating ops */
10566 tcg_passres
= tcg_res
[pass
];
10568 tcg_passres
= tcg_temp_new_i64();
10571 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
10572 tcg_temp_free_i64(tcg_op
);
10575 /* saturating, doubling */
10576 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10577 tcg_passres
, tcg_passres
);
10580 if (opcode
== 0xa || opcode
== 0xb) {
10584 /* Accumulating op: handle accumulate step */
10585 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10588 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10589 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10591 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10592 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10594 case 0x7: /* SQDMLSL, SQDMLSL2 */
10595 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10597 case 0x3: /* SQDMLAL, SQDMLAL2 */
10598 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10603 g_assert_not_reached();
10605 tcg_temp_free_i64(tcg_passres
);
10607 tcg_temp_free_i64(tcg_idx
);
10610 clear_vec_high(s
, rd
);
10613 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10616 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10619 /* The simplest way to handle the 16x16 indexed ops is to
10620 * duplicate the index into both halves of the 32 bit tcg_idx
10621 * and then use the usual Neon helpers.
10623 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10626 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10627 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10628 TCGv_i64 tcg_passres
;
10631 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10633 read_vec_element_i32(s
, tcg_op
, rn
,
10634 pass
+ (is_q
* 2), MO_32
);
10637 tcg_res
[pass
] = tcg_temp_new_i64();
10639 if (opcode
== 0xa || opcode
== 0xb) {
10640 /* Non-accumulating ops */
10641 tcg_passres
= tcg_res
[pass
];
10643 tcg_passres
= tcg_temp_new_i64();
10646 if (memop
& MO_SIGN
) {
10647 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
10649 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
10652 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10653 tcg_passres
, tcg_passres
);
10655 tcg_temp_free_i32(tcg_op
);
10657 if (opcode
== 0xa || opcode
== 0xb) {
10661 /* Accumulating op: handle accumulate step */
10662 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10665 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10666 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
10669 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10670 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
10673 case 0x7: /* SQDMLSL, SQDMLSL2 */
10674 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10676 case 0x3: /* SQDMLAL, SQDMLAL2 */
10677 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10682 g_assert_not_reached();
10684 tcg_temp_free_i64(tcg_passres
);
10686 tcg_temp_free_i32(tcg_idx
);
10689 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
10694 tcg_res
[1] = tcg_const_i64(0);
10697 for (pass
= 0; pass
< 2; pass
++) {
10698 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10699 tcg_temp_free_i64(tcg_res
[pass
]);
10703 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
10704 tcg_temp_free_ptr(fpst
);
10708 /* C3.6.19 Crypto AES
10709 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10710 * +-----------------+------+-----------+--------+-----+------+------+
10711 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10712 * +-----------------+------+-----------+--------+-----+------+------+
10714 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
10716 int size
= extract32(insn
, 22, 2);
10717 int opcode
= extract32(insn
, 12, 5);
10718 int rn
= extract32(insn
, 5, 5);
10719 int rd
= extract32(insn
, 0, 5);
10721 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
;
10722 CryptoThreeOpEnvFn
*genfn
;
10724 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)
10726 unallocated_encoding(s
);
10731 case 0x4: /* AESE */
10733 genfn
= gen_helper_crypto_aese
;
10735 case 0x6: /* AESMC */
10737 genfn
= gen_helper_crypto_aesmc
;
10739 case 0x5: /* AESD */
10741 genfn
= gen_helper_crypto_aese
;
10743 case 0x7: /* AESIMC */
10745 genfn
= gen_helper_crypto_aesmc
;
10748 unallocated_encoding(s
);
10752 /* Note that we convert the Vx register indexes into the
10753 * index within the vfp.regs[] array, so we can share the
10754 * helper with the AArch32 instructions.
10756 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10757 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10758 tcg_decrypt
= tcg_const_i32(decrypt
);
10760 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
);
10762 tcg_temp_free_i32(tcg_rd_regno
);
10763 tcg_temp_free_i32(tcg_rn_regno
);
10764 tcg_temp_free_i32(tcg_decrypt
);
10767 /* C3.6.20 Crypto three-reg SHA
10768 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
10769 * +-----------------+------+---+------+---+--------+-----+------+------+
10770 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
10771 * +-----------------+------+---+------+---+--------+-----+------+------+
10773 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
10775 int size
= extract32(insn
, 22, 2);
10776 int opcode
= extract32(insn
, 12, 3);
10777 int rm
= extract32(insn
, 16, 5);
10778 int rn
= extract32(insn
, 5, 5);
10779 int rd
= extract32(insn
, 0, 5);
10780 CryptoThreeOpEnvFn
*genfn
;
10781 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
;
10782 int feature
= ARM_FEATURE_V8_SHA256
;
10785 unallocated_encoding(s
);
10790 case 0: /* SHA1C */
10791 case 1: /* SHA1P */
10792 case 2: /* SHA1M */
10793 case 3: /* SHA1SU0 */
10795 feature
= ARM_FEATURE_V8_SHA1
;
10797 case 4: /* SHA256H */
10798 genfn
= gen_helper_crypto_sha256h
;
10800 case 5: /* SHA256H2 */
10801 genfn
= gen_helper_crypto_sha256h2
;
10803 case 6: /* SHA256SU1 */
10804 genfn
= gen_helper_crypto_sha256su1
;
10807 unallocated_encoding(s
);
10811 if (!arm_dc_feature(s
, feature
)) {
10812 unallocated_encoding(s
);
10816 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10817 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10818 tcg_rm_regno
= tcg_const_i32(rm
<< 1);
10821 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
);
10823 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
10825 gen_helper_crypto_sha1_3reg(cpu_env
, tcg_rd_regno
,
10826 tcg_rn_regno
, tcg_rm_regno
, tcg_opcode
);
10827 tcg_temp_free_i32(tcg_opcode
);
10830 tcg_temp_free_i32(tcg_rd_regno
);
10831 tcg_temp_free_i32(tcg_rn_regno
);
10832 tcg_temp_free_i32(tcg_rm_regno
);
10835 /* C3.6.21 Crypto two-reg SHA
10836 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10837 * +-----------------+------+-----------+--------+-----+------+------+
10838 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10839 * +-----------------+------+-----------+--------+-----+------+------+
10841 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
10843 int size
= extract32(insn
, 22, 2);
10844 int opcode
= extract32(insn
, 12, 5);
10845 int rn
= extract32(insn
, 5, 5);
10846 int rd
= extract32(insn
, 0, 5);
10847 CryptoTwoOpEnvFn
*genfn
;
10849 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
;
10852 unallocated_encoding(s
);
10857 case 0: /* SHA1H */
10858 feature
= ARM_FEATURE_V8_SHA1
;
10859 genfn
= gen_helper_crypto_sha1h
;
10861 case 1: /* SHA1SU1 */
10862 feature
= ARM_FEATURE_V8_SHA1
;
10863 genfn
= gen_helper_crypto_sha1su1
;
10865 case 2: /* SHA256SU0 */
10866 feature
= ARM_FEATURE_V8_SHA256
;
10867 genfn
= gen_helper_crypto_sha256su0
;
10870 unallocated_encoding(s
);
10874 if (!arm_dc_feature(s
, feature
)) {
10875 unallocated_encoding(s
);
10879 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10880 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10882 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
);
10884 tcg_temp_free_i32(tcg_rd_regno
);
10885 tcg_temp_free_i32(tcg_rn_regno
);
10888 /* C3.6 Data processing - SIMD, inc Crypto
10890 * As the decode gets a little complex we are using a table based
10891 * approach for this part of the decode.
10893 static const AArch64DecodeTable data_proc_simd
[] = {
10894 /* pattern , mask , fn */
10895 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
10896 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
10897 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
10898 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
10899 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
10900 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
10901 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
10902 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
10903 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
10904 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
10905 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
10906 { 0x2e000000, 0xbf208400, disas_simd_ext
},
10907 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
10908 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
10909 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
10910 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
10911 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
10912 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
10913 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
10914 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
10915 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
10916 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
10917 { 0x00000000, 0x00000000, NULL
}
10920 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
10922 /* Note that this is called with all non-FP cases from
10923 * table C3-6 so it must UNDEF for entries not specifically
10924 * allocated to instructions in that table.
10926 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
10930 unallocated_encoding(s
);
10934 /* C3.6 Data processing - SIMD and floating point */
10935 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
10937 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
10938 disas_data_proc_fp(s
, insn
);
10940 /* SIMD, including crypto */
10941 disas_data_proc_simd(s
, insn
);
10945 /* C3.1 A64 instruction index by encoding */
10946 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
10950 insn
= arm_ldl_code(env
, s
->pc
, s
->bswap_code
);
10954 s
->fp_access_checked
= false;
10956 switch (extract32(insn
, 25, 4)) {
10957 case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
10958 unallocated_encoding(s
);
10960 case 0x8: case 0x9: /* Data processing - immediate */
10961 disas_data_proc_imm(s
, insn
);
10963 case 0xa: case 0xb: /* Branch, exception generation and system insns */
10964 disas_b_exc_sys(s
, insn
);
10969 case 0xe: /* Loads and stores */
10970 disas_ldst(s
, insn
);
10973 case 0xd: /* Data processing - register */
10974 disas_data_proc_reg(s
, insn
);
10977 case 0xf: /* Data processing - SIMD and floating point */
10978 disas_data_proc_simd_fp(s
, insn
);
10981 assert(FALSE
); /* all 15 cases should be handled above */
10985 /* if we allocated any temporaries, free them here */
10989 void gen_intermediate_code_internal_a64(ARMCPU
*cpu
,
10990 TranslationBlock
*tb
,
10993 CPUState
*cs
= CPU(cpu
);
10994 CPUARMState
*env
= &cpu
->env
;
10995 DisasContext dc1
, *dc
= &dc1
;
10998 target_ulong pc_start
;
10999 target_ulong next_page_start
;
11007 dc
->is_jmp
= DISAS_NEXT
;
11009 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
11013 /* If we are coming from secure EL0 in a system with a 32-bit EL3, then
11014 * there is no secure EL1, so we route exceptions to EL3.
11016 dc
->secure_routed_to_el3
= arm_feature(env
, ARM_FEATURE_EL3
) &&
11017 !arm_el_is_aa64(env
, 3);
11019 dc
->bswap_code
= 0;
11020 dc
->condexec_mask
= 0;
11021 dc
->condexec_cond
= 0;
11022 dc
->mmu_idx
= ARM_TBFLAG_MMUIDX(tb
->flags
);
11023 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
11024 #if !defined(CONFIG_USER_ONLY)
11025 dc
->user
= (dc
->current_el
== 0);
11027 dc
->fp_excp_el
= ARM_TBFLAG_FPEXC_EL(tb
->flags
);
11029 dc
->vec_stride
= 0;
11030 dc
->cp_regs
= cpu
->cp_regs
;
11031 dc
->features
= env
->features
;
11033 /* Single step state. The code-generation logic here is:
11035 * generate code with no special handling for single-stepping (except
11036 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
11037 * this happens anyway because those changes are all system register or
11039 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
11040 * emit code for one insn
11041 * emit code to clear PSTATE.SS
11042 * emit code to generate software step exception for completed step
11043 * end TB (as usual for having generated an exception)
11044 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
11045 * emit code to generate a software step exception
11048 dc
->ss_active
= ARM_TBFLAG_SS_ACTIVE(tb
->flags
);
11049 dc
->pstate_ss
= ARM_TBFLAG_PSTATE_SS(tb
->flags
);
11050 dc
->is_ldex
= false;
11051 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
11053 init_tmp_a64_array(dc
);
11055 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
11058 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
11059 if (max_insns
== 0) {
11060 max_insns
= CF_COUNT_MASK
;
11065 tcg_clear_temp_count();
11068 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
11069 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
11070 if (bp
->pc
== dc
->pc
) {
11071 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
11072 /* Advance PC so that clearing the breakpoint will
11073 invalidate this TB. */
11075 goto done_generating
;
11081 j
= tcg_op_buf_count();
11085 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
11088 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
11089 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
11090 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
11093 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
11097 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
11098 tcg_gen_debug_insn_start(dc
->pc
);
11101 if (dc
->ss_active
&& !dc
->pstate_ss
) {
11102 /* Singlestep state is Active-pending.
11103 * If we're in this state at the start of a TB then either
11104 * a) we just took an exception to an EL which is being debugged
11105 * and this is the first insn in the exception handler
11106 * b) debug exceptions were masked and we just unmasked them
11107 * without changing EL (eg by clearing PSTATE.D)
11108 * In either case we're going to take a swstep exception in the
11109 * "did not step an insn" case, and so the syndrome ISV and EX
11110 * bits should be zero.
11112 assert(num_insns
== 0);
11113 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0),
11114 default_exception_el(dc
));
11115 dc
->is_jmp
= DISAS_EXC
;
11119 disas_a64_insn(env
, dc
);
11121 if (tcg_check_temp_count()) {
11122 fprintf(stderr
, "TCG temporary leak before "TARGET_FMT_lx
"\n",
11126 /* Translation stops when a conditional branch is encountered.
11127 * Otherwise the subsequent code could get translated several times.
11128 * Also stop translation when a page boundary is reached. This
11129 * ensures prefetch aborts occur at the right place.
11132 } while (!dc
->is_jmp
&& !tcg_op_buf_full() &&
11133 !cs
->singlestep_enabled
&&
11136 dc
->pc
< next_page_start
&&
11137 num_insns
< max_insns
);
11139 if (tb
->cflags
& CF_LAST_IO
) {
11143 if (unlikely(cs
->singlestep_enabled
|| dc
->ss_active
)
11144 && dc
->is_jmp
!= DISAS_EXC
) {
11145 /* Note that this means single stepping WFI doesn't halt the CPU.
11146 * For conditional branch insns this is harmless unreachable code as
11147 * gen_goto_tb() has already handled emitting the debug exception
11148 * (and thus a tb-jump is not possible when singlestepping).
11150 assert(dc
->is_jmp
!= DISAS_TB_JUMP
);
11151 if (dc
->is_jmp
!= DISAS_JUMP
) {
11152 gen_a64_set_pc_im(dc
->pc
);
11154 if (cs
->singlestep_enabled
) {
11155 gen_exception_internal(EXCP_DEBUG
);
11157 gen_step_complete_exception(dc
);
11160 switch (dc
->is_jmp
) {
11162 gen_goto_tb(dc
, 1, dc
->pc
);
11166 gen_a64_set_pc_im(dc
->pc
);
11169 /* indicate that the hash table must be used to find the next TB */
11170 tcg_gen_exit_tb(0);
11172 case DISAS_TB_JUMP
:
11177 gen_a64_set_pc_im(dc
->pc
);
11178 gen_helper_wfe(cpu_env
);
11181 gen_a64_set_pc_im(dc
->pc
);
11182 gen_helper_yield(cpu_env
);
11185 /* This is a special case because we don't want to just halt the CPU
11186 * if trying to debug across a WFI.
11188 gen_a64_set_pc_im(dc
->pc
);
11189 gen_helper_wfi(cpu_env
);
11190 /* The helper doesn't necessarily throw an exception, but we
11191 * must go back to the main loop to check for interrupts anyway.
11193 tcg_gen_exit_tb(0);
11199 gen_tb_end(tb
, num_insns
);
11202 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
11203 qemu_log("----------------\n");
11204 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
11205 log_target_disas(cs
, pc_start
, dc
->pc
- pc_start
,
11206 4 | (dc
->bswap_code
<< 1));
11211 j
= tcg_op_buf_count();
11214 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
11217 tb
->size
= dc
->pc
- pc_start
;
11218 tb
->icount
= num_insns
;