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/gen-icount.h"
35 #include "exec/helper-proto.h"
36 #include "exec/helper-gen.h"
38 #include "trace-tcg.h"
40 static TCGv_i64 cpu_X
[32];
41 static TCGv_i64 cpu_pc
;
42 static TCGv_i32 cpu_NF
, cpu_ZF
, cpu_CF
, cpu_VF
;
44 /* Load/store exclusive handling */
45 static TCGv_i64 cpu_exclusive_addr
;
46 static TCGv_i64 cpu_exclusive_val
;
47 static TCGv_i64 cpu_exclusive_high
;
48 #ifdef CONFIG_USER_ONLY
49 static TCGv_i64 cpu_exclusive_test
;
50 static TCGv_i32 cpu_exclusive_info
;
53 static const char *regnames
[] = {
54 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
55 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
56 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
57 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
61 A64_SHIFT_TYPE_LSL
= 0,
62 A64_SHIFT_TYPE_LSR
= 1,
63 A64_SHIFT_TYPE_ASR
= 2,
64 A64_SHIFT_TYPE_ROR
= 3
67 /* Table based decoder typedefs - used when the relevant bits for decode
68 * are too awkwardly scattered across the instruction (eg SIMD).
70 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
72 typedef struct AArch64DecodeTable
{
75 AArch64DecodeFn
*disas_fn
;
78 /* Function prototype for gen_ functions for calling Neon helpers */
79 typedef void NeonGenOneOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
);
80 typedef void NeonGenTwoOpFn(TCGv_i32
, TCGv_i32
, TCGv_i32
);
81 typedef void NeonGenTwoOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
, TCGv_i32
);
82 typedef void NeonGenTwo64OpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
);
83 typedef void NeonGenTwo64OpEnvFn(TCGv_i64
, TCGv_ptr
, TCGv_i64
, TCGv_i64
);
84 typedef void NeonGenNarrowFn(TCGv_i32
, TCGv_i64
);
85 typedef void NeonGenNarrowEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i64
);
86 typedef void NeonGenWidenFn(TCGv_i64
, TCGv_i32
);
87 typedef void NeonGenTwoSingleOPFn(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
88 typedef void NeonGenTwoDoubleOPFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGv_ptr
);
89 typedef void NeonGenOneOpFn(TCGv_i64
, TCGv_i64
);
90 typedef void CryptoTwoOpEnvFn(TCGv_ptr
, TCGv_i32
, TCGv_i32
);
91 typedef void CryptoThreeOpEnvFn(TCGv_ptr
, TCGv_i32
, TCGv_i32
, TCGv_i32
);
93 /* initialize TCG globals. */
94 void a64_translate_init(void)
98 cpu_pc
= tcg_global_mem_new_i64(TCG_AREG0
,
99 offsetof(CPUARMState
, pc
),
101 for (i
= 0; i
< 32; i
++) {
102 cpu_X
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
103 offsetof(CPUARMState
, xregs
[i
]),
107 cpu_NF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, NF
), "NF");
108 cpu_ZF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, ZF
), "ZF");
109 cpu_CF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, CF
), "CF");
110 cpu_VF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, VF
), "VF");
112 cpu_exclusive_addr
= tcg_global_mem_new_i64(TCG_AREG0
,
113 offsetof(CPUARMState
, exclusive_addr
), "exclusive_addr");
114 cpu_exclusive_val
= tcg_global_mem_new_i64(TCG_AREG0
,
115 offsetof(CPUARMState
, exclusive_val
), "exclusive_val");
116 cpu_exclusive_high
= tcg_global_mem_new_i64(TCG_AREG0
,
117 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
118 #ifdef CONFIG_USER_ONLY
119 cpu_exclusive_test
= tcg_global_mem_new_i64(TCG_AREG0
,
120 offsetof(CPUARMState
, exclusive_test
), "exclusive_test");
121 cpu_exclusive_info
= tcg_global_mem_new_i32(TCG_AREG0
,
122 offsetof(CPUARMState
, exclusive_info
), "exclusive_info");
126 static inline ARMMMUIdx
get_a64_user_mem_index(DisasContext
*s
)
128 /* Return the mmu_idx to use for A64 "unprivileged load/store" insns:
129 * if EL1, access as if EL0; otherwise access at current EL
131 switch (s
->mmu_idx
) {
132 case ARMMMUIdx_S12NSE1
:
133 return ARMMMUIdx_S12NSE0
;
134 case ARMMMUIdx_S1SE1
:
135 return ARMMMUIdx_S1SE0
;
137 g_assert_not_reached();
143 void aarch64_cpu_dump_state(CPUState
*cs
, FILE *f
,
144 fprintf_function cpu_fprintf
, int flags
)
146 ARMCPU
*cpu
= ARM_CPU(cs
);
147 CPUARMState
*env
= &cpu
->env
;
148 uint32_t psr
= pstate_read(env
);
151 cpu_fprintf(f
, "PC=%016"PRIx64
" SP=%016"PRIx64
"\n",
152 env
->pc
, env
->xregs
[31]);
153 for (i
= 0; i
< 31; i
++) {
154 cpu_fprintf(f
, "X%02d=%016"PRIx64
, i
, env
->xregs
[i
]);
156 cpu_fprintf(f
, "\n");
161 cpu_fprintf(f
, "PSTATE=%08x (flags %c%c%c%c)\n",
163 psr
& PSTATE_N
? 'N' : '-',
164 psr
& PSTATE_Z
? 'Z' : '-',
165 psr
& PSTATE_C
? 'C' : '-',
166 psr
& PSTATE_V
? 'V' : '-');
167 cpu_fprintf(f
, "\n");
169 if (flags
& CPU_DUMP_FPU
) {
171 for (i
= 0; i
< numvfpregs
; i
+= 2) {
172 uint64_t vlo
= float64_val(env
->vfp
.regs
[i
* 2]);
173 uint64_t vhi
= float64_val(env
->vfp
.regs
[(i
* 2) + 1]);
174 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
" ",
176 vlo
= float64_val(env
->vfp
.regs
[(i
+ 1) * 2]);
177 vhi
= float64_val(env
->vfp
.regs
[((i
+ 1) * 2) + 1]);
178 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
"\n",
181 cpu_fprintf(f
, "FPCR: %08x FPSR: %08x\n",
182 vfp_get_fpcr(env
), vfp_get_fpsr(env
));
186 void gen_a64_set_pc_im(uint64_t val
)
188 tcg_gen_movi_i64(cpu_pc
, val
);
191 static void gen_exception_internal(int excp
)
193 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
195 assert(excp_is_internal(excp
));
196 gen_helper_exception_internal(cpu_env
, tcg_excp
);
197 tcg_temp_free_i32(tcg_excp
);
200 static void gen_exception(int excp
, uint32_t syndrome
, uint32_t target_el
)
202 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
203 TCGv_i32 tcg_syn
= tcg_const_i32(syndrome
);
204 TCGv_i32 tcg_el
= tcg_const_i32(target_el
);
206 gen_helper_exception_with_syndrome(cpu_env
, tcg_excp
,
208 tcg_temp_free_i32(tcg_el
);
209 tcg_temp_free_i32(tcg_syn
);
210 tcg_temp_free_i32(tcg_excp
);
213 static void gen_exception_internal_insn(DisasContext
*s
, int offset
, int excp
)
215 gen_a64_set_pc_im(s
->pc
- offset
);
216 gen_exception_internal(excp
);
217 s
->is_jmp
= DISAS_EXC
;
220 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
,
221 uint32_t syndrome
, uint32_t target_el
)
223 gen_a64_set_pc_im(s
->pc
- offset
);
224 gen_exception(excp
, syndrome
, target_el
);
225 s
->is_jmp
= DISAS_EXC
;
228 static void gen_ss_advance(DisasContext
*s
)
230 /* If the singlestep state is Active-not-pending, advance to
235 gen_helper_clear_pstate_ss(cpu_env
);
239 static void gen_step_complete_exception(DisasContext
*s
)
241 /* We just completed step of an insn. Move from Active-not-pending
242 * to Active-pending, and then also take the swstep exception.
243 * This corresponds to making the (IMPDEF) choice to prioritize
244 * swstep exceptions over asynchronous exceptions taken to an exception
245 * level where debug is disabled. This choice has the advantage that
246 * we do not need to maintain internal state corresponding to the
247 * ISV/EX syndrome bits between completion of the step and generation
248 * of the exception, and our syndrome information is always correct.
251 gen_exception(EXCP_UDEF
, syn_swstep(s
->ss_same_el
, 1, s
->is_ldex
),
252 default_exception_el(s
));
253 s
->is_jmp
= DISAS_EXC
;
256 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
258 /* No direct tb linking with singlestep (either QEMU's or the ARM
259 * debug architecture kind) or deterministic io
261 if (s
->singlestep_enabled
|| s
->ss_active
|| (s
->tb
->cflags
& CF_LAST_IO
)) {
265 /* Only link tbs from inside the same guest page */
266 if ((s
->tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
273 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
275 TranslationBlock
*tb
;
278 if (use_goto_tb(s
, n
, dest
)) {
280 gen_a64_set_pc_im(dest
);
281 tcg_gen_exit_tb((intptr_t)tb
+ n
);
282 s
->is_jmp
= DISAS_TB_JUMP
;
284 gen_a64_set_pc_im(dest
);
286 gen_step_complete_exception(s
);
287 } else if (s
->singlestep_enabled
) {
288 gen_exception_internal(EXCP_DEBUG
);
291 s
->is_jmp
= DISAS_TB_JUMP
;
296 static void unallocated_encoding(DisasContext
*s
)
298 /* Unallocated and reserved encodings are uncategorized */
299 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized(),
300 default_exception_el(s
));
303 #define unsupported_encoding(s, insn) \
305 qemu_log_mask(LOG_UNIMP, \
306 "%s:%d: unsupported instruction encoding 0x%08x " \
307 "at pc=%016" PRIx64 "\n", \
308 __FILE__, __LINE__, insn, s->pc - 4); \
309 unallocated_encoding(s); \
312 static void init_tmp_a64_array(DisasContext
*s
)
314 #ifdef CONFIG_DEBUG_TCG
316 for (i
= 0; i
< ARRAY_SIZE(s
->tmp_a64
); i
++) {
317 TCGV_UNUSED_I64(s
->tmp_a64
[i
]);
320 s
->tmp_a64_count
= 0;
323 static void free_tmp_a64(DisasContext
*s
)
326 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
327 tcg_temp_free_i64(s
->tmp_a64
[i
]);
329 init_tmp_a64_array(s
);
332 static TCGv_i64
new_tmp_a64(DisasContext
*s
)
334 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
335 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
338 static TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
340 TCGv_i64 t
= new_tmp_a64(s
);
341 tcg_gen_movi_i64(t
, 0);
346 * Register access functions
348 * These functions are used for directly accessing a register in where
349 * changes to the final register value are likely to be made. If you
350 * need to use a register for temporary calculation (e.g. index type
351 * operations) use the read_* form.
353 * B1.2.1 Register mappings
355 * In instruction register encoding 31 can refer to ZR (zero register) or
356 * the SP (stack pointer) depending on context. In QEMU's case we map SP
357 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
358 * This is the point of the _sp forms.
360 static TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
363 return new_tmp_a64_zero(s
);
369 /* register access for when 31 == SP */
370 static TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
375 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
376 * representing the register contents. This TCGv is an auto-freed
377 * temporary so it need not be explicitly freed, and may be modified.
379 static TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
381 TCGv_i64 v
= new_tmp_a64(s
);
384 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
386 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
389 tcg_gen_movi_i64(v
, 0);
394 static TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
396 TCGv_i64 v
= new_tmp_a64(s
);
398 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
400 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
405 /* We should have at some point before trying to access an FP register
406 * done the necessary access check, so assert that
407 * (a) we did the check and
408 * (b) we didn't then just plough ahead anyway if it failed.
409 * Print the instruction pattern in the abort message so we can figure
410 * out what we need to fix if a user encounters this problem in the wild.
412 static inline void assert_fp_access_checked(DisasContext
*s
)
414 #ifdef CONFIG_DEBUG_TCG
415 if (unlikely(!s
->fp_access_checked
|| s
->fp_excp_el
)) {
416 fprintf(stderr
, "target-arm: FP access check missing for "
417 "instruction 0x%08x\n", s
->insn
);
423 /* Return the offset into CPUARMState of an element of specified
424 * size, 'element' places in from the least significant end of
425 * the FP/vector register Qn.
427 static inline int vec_reg_offset(DisasContext
*s
, int regno
,
428 int element
, TCGMemOp size
)
430 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
431 #ifdef HOST_WORDS_BIGENDIAN
432 /* This is complicated slightly because vfp.regs[2n] is
433 * still the low half and vfp.regs[2n+1] the high half
434 * of the 128 bit vector, even on big endian systems.
435 * Calculate the offset assuming a fully bigendian 128 bits,
436 * then XOR to account for the order of the two 64 bit halves.
438 offs
+= (16 - ((element
+ 1) * (1 << size
)));
441 offs
+= element
* (1 << size
);
443 assert_fp_access_checked(s
);
447 /* Return the offset into CPUARMState of a slice (from
448 * the least significant end) of FP register Qn (ie
450 * (Note that this is not the same mapping as for A32; see cpu.h)
452 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
454 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
455 #ifdef HOST_WORDS_BIGENDIAN
456 offs
+= (8 - (1 << size
));
458 assert_fp_access_checked(s
);
462 /* Offset of the high half of the 128 bit vector Qn */
463 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
465 assert_fp_access_checked(s
);
466 return offsetof(CPUARMState
, vfp
.regs
[regno
* 2 + 1]);
469 /* Convenience accessors for reading and writing single and double
470 * FP registers. Writing clears the upper parts of the associated
471 * 128 bit vector register, as required by the architecture.
472 * Note that unlike the GP register accessors, the values returned
473 * by the read functions must be manually freed.
475 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
477 TCGv_i64 v
= tcg_temp_new_i64();
479 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
483 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
485 TCGv_i32 v
= tcg_temp_new_i32();
487 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
491 static void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
493 TCGv_i64 tcg_zero
= tcg_const_i64(0);
495 tcg_gen_st_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
496 tcg_gen_st_i64(tcg_zero
, cpu_env
, fp_reg_hi_offset(s
, reg
));
497 tcg_temp_free_i64(tcg_zero
);
500 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
502 TCGv_i64 tmp
= tcg_temp_new_i64();
504 tcg_gen_extu_i32_i64(tmp
, v
);
505 write_fp_dreg(s
, reg
, tmp
);
506 tcg_temp_free_i64(tmp
);
509 static TCGv_ptr
get_fpstatus_ptr(void)
511 TCGv_ptr statusptr
= tcg_temp_new_ptr();
514 /* In A64 all instructions (both FP and Neon) use the FPCR;
515 * there is no equivalent of the A32 Neon "standard FPSCR value"
516 * and all operations use vfp.fp_status.
518 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
519 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
523 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
524 * than the 32 bit equivalent.
526 static inline void gen_set_NZ64(TCGv_i64 result
)
528 TCGv_i64 flag
= tcg_temp_new_i64();
530 tcg_gen_setcondi_i64(TCG_COND_NE
, flag
, result
, 0);
531 tcg_gen_trunc_i64_i32(cpu_ZF
, flag
);
532 tcg_gen_shri_i64(flag
, result
, 32);
533 tcg_gen_trunc_i64_i32(cpu_NF
, flag
);
534 tcg_temp_free_i64(flag
);
537 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
538 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
541 gen_set_NZ64(result
);
543 tcg_gen_trunc_i64_i32(cpu_ZF
, result
);
544 tcg_gen_trunc_i64_i32(cpu_NF
, result
);
546 tcg_gen_movi_i32(cpu_CF
, 0);
547 tcg_gen_movi_i32(cpu_VF
, 0);
550 /* dest = T0 + T1; compute C, N, V and Z flags */
551 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
554 TCGv_i64 result
, flag
, tmp
;
555 result
= tcg_temp_new_i64();
556 flag
= tcg_temp_new_i64();
557 tmp
= tcg_temp_new_i64();
559 tcg_gen_movi_i64(tmp
, 0);
560 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
562 tcg_gen_trunc_i64_i32(cpu_CF
, flag
);
564 gen_set_NZ64(result
);
566 tcg_gen_xor_i64(flag
, result
, t0
);
567 tcg_gen_xor_i64(tmp
, t0
, t1
);
568 tcg_gen_andc_i64(flag
, flag
, tmp
);
569 tcg_temp_free_i64(tmp
);
570 tcg_gen_shri_i64(flag
, flag
, 32);
571 tcg_gen_trunc_i64_i32(cpu_VF
, flag
);
573 tcg_gen_mov_i64(dest
, result
);
574 tcg_temp_free_i64(result
);
575 tcg_temp_free_i64(flag
);
577 /* 32 bit arithmetic */
578 TCGv_i32 t0_32
= tcg_temp_new_i32();
579 TCGv_i32 t1_32
= tcg_temp_new_i32();
580 TCGv_i32 tmp
= tcg_temp_new_i32();
582 tcg_gen_movi_i32(tmp
, 0);
583 tcg_gen_trunc_i64_i32(t0_32
, t0
);
584 tcg_gen_trunc_i64_i32(t1_32
, t1
);
585 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
586 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
587 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
588 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
589 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
590 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
592 tcg_temp_free_i32(tmp
);
593 tcg_temp_free_i32(t0_32
);
594 tcg_temp_free_i32(t1_32
);
598 /* dest = T0 - T1; compute C, N, V and Z flags */
599 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
602 /* 64 bit arithmetic */
603 TCGv_i64 result
, flag
, tmp
;
605 result
= tcg_temp_new_i64();
606 flag
= tcg_temp_new_i64();
607 tcg_gen_sub_i64(result
, t0
, t1
);
609 gen_set_NZ64(result
);
611 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
612 tcg_gen_trunc_i64_i32(cpu_CF
, flag
);
614 tcg_gen_xor_i64(flag
, result
, t0
);
615 tmp
= tcg_temp_new_i64();
616 tcg_gen_xor_i64(tmp
, t0
, t1
);
617 tcg_gen_and_i64(flag
, flag
, tmp
);
618 tcg_temp_free_i64(tmp
);
619 tcg_gen_shri_i64(flag
, flag
, 32);
620 tcg_gen_trunc_i64_i32(cpu_VF
, flag
);
621 tcg_gen_mov_i64(dest
, result
);
622 tcg_temp_free_i64(flag
);
623 tcg_temp_free_i64(result
);
625 /* 32 bit arithmetic */
626 TCGv_i32 t0_32
= tcg_temp_new_i32();
627 TCGv_i32 t1_32
= tcg_temp_new_i32();
630 tcg_gen_trunc_i64_i32(t0_32
, t0
);
631 tcg_gen_trunc_i64_i32(t1_32
, t1
);
632 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
633 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
634 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
635 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
636 tmp
= tcg_temp_new_i32();
637 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
638 tcg_temp_free_i32(t0_32
);
639 tcg_temp_free_i32(t1_32
);
640 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
641 tcg_temp_free_i32(tmp
);
642 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
646 /* dest = T0 + T1 + CF; do not compute flags. */
647 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
649 TCGv_i64 flag
= tcg_temp_new_i64();
650 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
651 tcg_gen_add_i64(dest
, t0
, t1
);
652 tcg_gen_add_i64(dest
, dest
, flag
);
653 tcg_temp_free_i64(flag
);
656 tcg_gen_ext32u_i64(dest
, dest
);
660 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
661 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
664 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
665 result
= tcg_temp_new_i64();
666 cf_64
= tcg_temp_new_i64();
667 vf_64
= tcg_temp_new_i64();
668 tmp
= tcg_const_i64(0);
670 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
671 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
672 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
673 tcg_gen_trunc_i64_i32(cpu_CF
, cf_64
);
674 gen_set_NZ64(result
);
676 tcg_gen_xor_i64(vf_64
, result
, t0
);
677 tcg_gen_xor_i64(tmp
, t0
, t1
);
678 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
679 tcg_gen_shri_i64(vf_64
, vf_64
, 32);
680 tcg_gen_trunc_i64_i32(cpu_VF
, vf_64
);
682 tcg_gen_mov_i64(dest
, result
);
684 tcg_temp_free_i64(tmp
);
685 tcg_temp_free_i64(vf_64
);
686 tcg_temp_free_i64(cf_64
);
687 tcg_temp_free_i64(result
);
689 TCGv_i32 t0_32
, t1_32
, tmp
;
690 t0_32
= tcg_temp_new_i32();
691 t1_32
= tcg_temp_new_i32();
692 tmp
= tcg_const_i32(0);
694 tcg_gen_trunc_i64_i32(t0_32
, t0
);
695 tcg_gen_trunc_i64_i32(t1_32
, t1
);
696 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
697 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
699 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
700 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
701 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
702 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
703 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
705 tcg_temp_free_i32(tmp
);
706 tcg_temp_free_i32(t1_32
);
707 tcg_temp_free_i32(t0_32
);
712 * Load/Store generators
716 * Store from GPR register to memory.
718 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
719 TCGv_i64 tcg_addr
, int size
, int memidx
)
722 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, MO_TE
+ size
);
725 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
726 TCGv_i64 tcg_addr
, int size
)
728 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
));
732 * Load from memory to GPR register
734 static void do_gpr_ld_memidx(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
735 int size
, bool is_signed
, bool extend
, int memidx
)
737 TCGMemOp memop
= MO_TE
+ size
;
745 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
747 if (extend
&& is_signed
) {
749 tcg_gen_ext32u_i64(dest
, dest
);
753 static void do_gpr_ld(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
754 int size
, bool is_signed
, bool extend
)
756 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
761 * Store from FP register to memory
763 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
765 /* This writes the bottom N bits of a 128 bit wide vector to memory */
766 TCGv_i64 tmp
= tcg_temp_new_i64();
767 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
769 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TE
+ size
);
771 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
772 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
773 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
774 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
775 tcg_gen_qemu_st_i64(tmp
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
776 tcg_temp_free_i64(tcg_hiaddr
);
779 tcg_temp_free_i64(tmp
);
783 * Load from memory to FP register
785 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
787 /* This always zero-extends and writes to a full 128 bit wide vector */
788 TCGv_i64 tmplo
= tcg_temp_new_i64();
792 TCGMemOp memop
= MO_TE
+ size
;
793 tmphi
= tcg_const_i64(0);
794 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
797 tmphi
= tcg_temp_new_i64();
798 tcg_hiaddr
= tcg_temp_new_i64();
800 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
801 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
802 tcg_gen_qemu_ld_i64(tmphi
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
803 tcg_temp_free_i64(tcg_hiaddr
);
806 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
807 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
809 tcg_temp_free_i64(tmplo
);
810 tcg_temp_free_i64(tmphi
);
814 * Vector load/store helpers.
816 * The principal difference between this and a FP load is that we don't
817 * zero extend as we are filling a partial chunk of the vector register.
818 * These functions don't support 128 bit loads/stores, which would be
819 * normal load/store operations.
821 * The _i32 versions are useful when operating on 32 bit quantities
822 * (eg for floating point single or using Neon helper functions).
825 /* Get value of an element within a vector register */
826 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
827 int element
, TCGMemOp memop
)
829 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
832 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
835 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
838 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
841 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
844 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
847 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
851 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
854 g_assert_not_reached();
858 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
859 int element
, TCGMemOp memop
)
861 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
864 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
867 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
870 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
873 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
877 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
880 g_assert_not_reached();
884 /* Set value of an element within a vector register */
885 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
886 int element
, TCGMemOp memop
)
888 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
891 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
894 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
897 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
900 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
903 g_assert_not_reached();
907 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
908 int destidx
, int element
, TCGMemOp memop
)
910 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
913 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
916 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
919 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
922 g_assert_not_reached();
926 /* Clear the high 64 bits of a 128 bit vector (in general non-quad
927 * vector ops all need to do this).
929 static void clear_vec_high(DisasContext
*s
, int rd
)
931 TCGv_i64 tcg_zero
= tcg_const_i64(0);
933 write_vec_element(s
, tcg_zero
, rd
, 1, MO_64
);
934 tcg_temp_free_i64(tcg_zero
);
937 /* Store from vector register to memory */
938 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
939 TCGv_i64 tcg_addr
, int size
)
941 TCGMemOp memop
= MO_TE
+ size
;
942 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
944 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
945 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
947 tcg_temp_free_i64(tcg_tmp
);
950 /* Load from memory to vector register */
951 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
952 TCGv_i64 tcg_addr
, int size
)
954 TCGMemOp memop
= MO_TE
+ size
;
955 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
957 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
958 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
960 tcg_temp_free_i64(tcg_tmp
);
963 /* Check that FP/Neon access is enabled. If it is, return
964 * true. If not, emit code to generate an appropriate exception,
965 * and return false; the caller should not emit any code for
966 * the instruction. Note that this check must happen after all
967 * unallocated-encoding checks (otherwise the syndrome information
968 * for the resulting exception will be incorrect).
970 static inline bool fp_access_check(DisasContext
*s
)
972 assert(!s
->fp_access_checked
);
973 s
->fp_access_checked
= true;
975 if (!s
->fp_excp_el
) {
979 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false),
985 * This utility function is for doing register extension with an
986 * optional shift. You will likely want to pass a temporary for the
987 * destination register. See DecodeRegExtend() in the ARM ARM.
989 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
990 int option
, unsigned int shift
)
992 int extsize
= extract32(option
, 0, 2);
993 bool is_signed
= extract32(option
, 2, 1);
998 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
1001 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
1004 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1007 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1013 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1016 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1019 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1022 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1028 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1032 static inline void gen_check_sp_alignment(DisasContext
*s
)
1034 /* The AArch64 architecture mandates that (if enabled via PSTATE
1035 * or SCTLR bits) there is a check that SP is 16-aligned on every
1036 * SP-relative load or store (with an exception generated if it is not).
1037 * In line with general QEMU practice regarding misaligned accesses,
1038 * we omit these checks for the sake of guest program performance.
1039 * This function is provided as a hook so we can more easily add these
1040 * checks in future (possibly as a "favour catching guest program bugs
1041 * over speed" user selectable option).
1046 * This provides a simple table based table lookup decoder. It is
1047 * intended to be used when the relevant bits for decode are too
1048 * awkwardly placed and switch/if based logic would be confusing and
1049 * deeply nested. Since it's a linear search through the table, tables
1050 * should be kept small.
1052 * It returns the first handler where insn & mask == pattern, or
1053 * NULL if there is no match.
1054 * The table is terminated by an empty mask (i.e. 0)
1056 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1059 const AArch64DecodeTable
*tptr
= table
;
1061 while (tptr
->mask
) {
1062 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1063 return tptr
->disas_fn
;
1071 * the instruction disassembly implemented here matches
1072 * the instruction encoding classifications in chapter 3 (C3)
1073 * of the ARM Architecture Reference Manual (DDI0487A_a)
1076 /* C3.2.7 Unconditional branch (immediate)
1078 * +----+-----------+-------------------------------------+
1079 * | op | 0 0 1 0 1 | imm26 |
1080 * +----+-----------+-------------------------------------+
1082 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1084 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1086 if (insn
& (1U << 31)) {
1087 /* C5.6.26 BL Branch with link */
1088 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1091 /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
1092 gen_goto_tb(s
, 0, addr
);
1095 /* C3.2.1 Compare & branch (immediate)
1096 * 31 30 25 24 23 5 4 0
1097 * +----+-------------+----+---------------------+--------+
1098 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1099 * +----+-------------+----+---------------------+--------+
1101 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1103 unsigned int sf
, op
, rt
;
1105 TCGLabel
*label_match
;
1108 sf
= extract32(insn
, 31, 1);
1109 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1110 rt
= extract32(insn
, 0, 5);
1111 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1113 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1114 label_match
= gen_new_label();
1116 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1117 tcg_cmp
, 0, label_match
);
1119 gen_goto_tb(s
, 0, s
->pc
);
1120 gen_set_label(label_match
);
1121 gen_goto_tb(s
, 1, addr
);
1124 /* C3.2.5 Test & branch (immediate)
1125 * 31 30 25 24 23 19 18 5 4 0
1126 * +----+-------------+----+-------+-------------+------+
1127 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1128 * +----+-------------+----+-------+-------------+------+
1130 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1132 unsigned int bit_pos
, op
, rt
;
1134 TCGLabel
*label_match
;
1137 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1138 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1139 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1140 rt
= extract32(insn
, 0, 5);
1142 tcg_cmp
= tcg_temp_new_i64();
1143 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1144 label_match
= gen_new_label();
1145 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1146 tcg_cmp
, 0, label_match
);
1147 tcg_temp_free_i64(tcg_cmp
);
1148 gen_goto_tb(s
, 0, s
->pc
);
1149 gen_set_label(label_match
);
1150 gen_goto_tb(s
, 1, addr
);
1153 /* C3.2.2 / C5.6.19 Conditional branch (immediate)
1154 * 31 25 24 23 5 4 3 0
1155 * +---------------+----+---------------------+----+------+
1156 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1157 * +---------------+----+---------------------+----+------+
1159 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1164 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1165 unallocated_encoding(s
);
1168 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1169 cond
= extract32(insn
, 0, 4);
1172 /* genuinely conditional branches */
1173 TCGLabel
*label_match
= gen_new_label();
1174 arm_gen_test_cc(cond
, label_match
);
1175 gen_goto_tb(s
, 0, s
->pc
);
1176 gen_set_label(label_match
);
1177 gen_goto_tb(s
, 1, addr
);
1179 /* 0xe and 0xf are both "always" conditions */
1180 gen_goto_tb(s
, 0, addr
);
1185 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1186 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1188 unsigned int selector
= crm
<< 3 | op2
;
1191 unallocated_encoding(s
);
1199 s
->is_jmp
= DISAS_WFI
;
1202 s
->is_jmp
= DISAS_YIELD
;
1205 s
->is_jmp
= DISAS_WFE
;
1209 /* we treat all as NOP at least for now */
1212 /* default specified as NOP equivalent */
1217 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1219 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1222 /* CLREX, DSB, DMB, ISB */
1223 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1224 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1227 unallocated_encoding(s
);
1238 /* We don't emulate caches so barriers are no-ops */
1241 unallocated_encoding(s
);
1246 /* C5.6.130 MSR (immediate) - move immediate to processor state field */
1247 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1248 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1250 int op
= op1
<< 3 | op2
;
1252 case 0x05: /* SPSel */
1253 if (s
->current_el
== 0) {
1254 unallocated_encoding(s
);
1258 case 0x1e: /* DAIFSet */
1259 case 0x1f: /* DAIFClear */
1261 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1262 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1263 gen_a64_set_pc_im(s
->pc
- 4);
1264 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1265 tcg_temp_free_i32(tcg_imm
);
1266 tcg_temp_free_i32(tcg_op
);
1267 s
->is_jmp
= DISAS_UPDATE
;
1271 unallocated_encoding(s
);
1276 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1278 TCGv_i32 tmp
= tcg_temp_new_i32();
1279 TCGv_i32 nzcv
= tcg_temp_new_i32();
1281 /* build bit 31, N */
1282 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1283 /* build bit 30, Z */
1284 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1285 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1286 /* build bit 29, C */
1287 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1288 /* build bit 28, V */
1289 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1290 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1291 /* generate result */
1292 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1294 tcg_temp_free_i32(nzcv
);
1295 tcg_temp_free_i32(tmp
);
1298 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1301 TCGv_i32 nzcv
= tcg_temp_new_i32();
1303 /* take NZCV from R[t] */
1304 tcg_gen_trunc_i64_i32(nzcv
, tcg_rt
);
1307 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1309 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1310 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1312 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1313 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1315 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1316 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1317 tcg_temp_free_i32(nzcv
);
1320 /* C5.6.129 MRS - move from system register
1321 * C5.6.131 MSR (register) - move to system register
1324 * These are all essentially the same insn in 'read' and 'write'
1325 * versions, with varying op0 fields.
1327 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1328 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1329 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1331 const ARMCPRegInfo
*ri
;
1334 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1335 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1336 crn
, crm
, op0
, op1
, op2
));
1339 /* Unknown register; this might be a guest error or a QEMU
1340 * unimplemented feature.
1342 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1343 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1344 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1345 unallocated_encoding(s
);
1349 /* Check access permissions */
1350 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1351 unallocated_encoding(s
);
1356 /* Emit code to perform further access permissions checks at
1357 * runtime; this may result in an exception.
1363 gen_a64_set_pc_im(s
->pc
- 4);
1364 tmpptr
= tcg_const_ptr(ri
);
1365 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1366 tcg_syn
= tcg_const_i32(syndrome
);
1367 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
);
1368 tcg_temp_free_ptr(tmpptr
);
1369 tcg_temp_free_i32(tcg_syn
);
1372 /* Handle special cases first */
1373 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1377 tcg_rt
= cpu_reg(s
, rt
);
1379 gen_get_nzcv(tcg_rt
);
1381 gen_set_nzcv(tcg_rt
);
1384 case ARM_CP_CURRENTEL
:
1385 /* Reads as current EL value from pstate, which is
1386 * guaranteed to be constant by the tb flags.
1388 tcg_rt
= cpu_reg(s
, rt
);
1389 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1392 /* Writes clear the aligned block of memory which rt points into. */
1393 tcg_rt
= cpu_reg(s
, rt
);
1394 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1400 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1404 tcg_rt
= cpu_reg(s
, rt
);
1407 if (ri
->type
& ARM_CP_CONST
) {
1408 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1409 } else if (ri
->readfn
) {
1411 tmpptr
= tcg_const_ptr(ri
);
1412 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1413 tcg_temp_free_ptr(tmpptr
);
1415 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1418 if (ri
->type
& ARM_CP_CONST
) {
1419 /* If not forbidden by access permissions, treat as WI */
1421 } else if (ri
->writefn
) {
1423 tmpptr
= tcg_const_ptr(ri
);
1424 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1425 tcg_temp_free_ptr(tmpptr
);
1427 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1431 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1432 /* I/O operations must end the TB here (whether read or write) */
1434 s
->is_jmp
= DISAS_UPDATE
;
1435 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1436 /* We default to ending the TB on a coprocessor register write,
1437 * but allow this to be suppressed by the register definition
1438 * (usually only necessary to work around guest bugs).
1440 s
->is_jmp
= DISAS_UPDATE
;
1445 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1446 * +---------------------+---+-----+-----+-------+-------+-----+------+
1447 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1448 * +---------------------+---+-----+-----+-------+-------+-----+------+
1450 static void disas_system(DisasContext
*s
, uint32_t insn
)
1452 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1453 l
= extract32(insn
, 21, 1);
1454 op0
= extract32(insn
, 19, 2);
1455 op1
= extract32(insn
, 16, 3);
1456 crn
= extract32(insn
, 12, 4);
1457 crm
= extract32(insn
, 8, 4);
1458 op2
= extract32(insn
, 5, 3);
1459 rt
= extract32(insn
, 0, 5);
1462 if (l
|| rt
!= 31) {
1463 unallocated_encoding(s
);
1467 case 2: /* C5.6.68 HINT */
1468 handle_hint(s
, insn
, op1
, op2
, crm
);
1470 case 3: /* CLREX, DSB, DMB, ISB */
1471 handle_sync(s
, insn
, op1
, op2
, crm
);
1473 case 4: /* C5.6.130 MSR (immediate) */
1474 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1477 unallocated_encoding(s
);
1482 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1485 /* C3.2.3 Exception generation
1487 * 31 24 23 21 20 5 4 2 1 0
1488 * +-----------------+-----+------------------------+-----+----+
1489 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1490 * +-----------------------+------------------------+----------+
1492 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1494 int opc
= extract32(insn
, 21, 3);
1495 int op2_ll
= extract32(insn
, 0, 5);
1496 int imm16
= extract32(insn
, 5, 16);
1501 /* For SVC, HVC and SMC we advance the single-step state
1502 * machine before taking the exception. This is architecturally
1503 * mandated, to ensure that single-stepping a system call
1504 * instruction works properly.
1509 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
),
1510 default_exception_el(s
));
1513 if (s
->current_el
== 0) {
1514 unallocated_encoding(s
);
1517 /* The pre HVC helper handles cases when HVC gets trapped
1518 * as an undefined insn by runtime configuration.
1520 gen_a64_set_pc_im(s
->pc
- 4);
1521 gen_helper_pre_hvc(cpu_env
);
1523 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
), 2);
1526 if (s
->current_el
== 0) {
1527 unallocated_encoding(s
);
1530 gen_a64_set_pc_im(s
->pc
- 4);
1531 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1532 gen_helper_pre_smc(cpu_env
, tmp
);
1533 tcg_temp_free_i32(tmp
);
1535 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
), 3);
1538 unallocated_encoding(s
);
1544 unallocated_encoding(s
);
1548 gen_exception_insn(s
, 4, EXCP_BKPT
, syn_aa64_bkpt(imm16
),
1549 default_exception_el(s
));
1553 unallocated_encoding(s
);
1557 unsupported_encoding(s
, insn
);
1560 if (op2_ll
< 1 || op2_ll
> 3) {
1561 unallocated_encoding(s
);
1564 /* DCPS1, DCPS2, DCPS3 */
1565 unsupported_encoding(s
, insn
);
1568 unallocated_encoding(s
);
1573 /* C3.2.7 Unconditional branch (register)
1574 * 31 25 24 21 20 16 15 10 9 5 4 0
1575 * +---------------+-------+-------+-------+------+-------+
1576 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1577 * +---------------+-------+-------+-------+------+-------+
1579 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1581 unsigned int opc
, op2
, op3
, rn
, op4
;
1583 opc
= extract32(insn
, 21, 4);
1584 op2
= extract32(insn
, 16, 5);
1585 op3
= extract32(insn
, 10, 6);
1586 rn
= extract32(insn
, 5, 5);
1587 op4
= extract32(insn
, 0, 5);
1589 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1590 unallocated_encoding(s
);
1597 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1600 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1601 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1604 if (s
->current_el
== 0) {
1605 unallocated_encoding(s
);
1608 gen_helper_exception_return(cpu_env
);
1609 s
->is_jmp
= DISAS_JUMP
;
1613 unallocated_encoding(s
);
1615 unsupported_encoding(s
, insn
);
1619 unallocated_encoding(s
);
1623 s
->is_jmp
= DISAS_JUMP
;
1626 /* C3.2 Branches, exception generating and system instructions */
1627 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1629 switch (extract32(insn
, 25, 7)) {
1630 case 0x0a: case 0x0b:
1631 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1632 disas_uncond_b_imm(s
, insn
);
1634 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1635 disas_comp_b_imm(s
, insn
);
1637 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1638 disas_test_b_imm(s
, insn
);
1640 case 0x2a: /* Conditional branch (immediate) */
1641 disas_cond_b_imm(s
, insn
);
1643 case 0x6a: /* Exception generation / System */
1644 if (insn
& (1 << 24)) {
1645 disas_system(s
, insn
);
1650 case 0x6b: /* Unconditional branch (register) */
1651 disas_uncond_b_reg(s
, insn
);
1654 unallocated_encoding(s
);
1660 * Load/Store exclusive instructions are implemented by remembering
1661 * the value/address loaded, and seeing if these are the same
1662 * when the store is performed. This is not actually the architecturally
1663 * mandated semantics, but it works for typical guest code sequences
1664 * and avoids having to monitor regular stores.
1666 * In system emulation mode only one CPU will be running at once, so
1667 * this sequence is effectively atomic. In user emulation mode we
1668 * throw an exception and handle the atomic operation elsewhere.
1670 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
1671 TCGv_i64 addr
, int size
, bool is_pair
)
1673 TCGv_i64 tmp
= tcg_temp_new_i64();
1674 TCGMemOp memop
= MO_TE
+ size
;
1676 g_assert(size
<= 3);
1677 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), memop
);
1680 TCGv_i64 addr2
= tcg_temp_new_i64();
1681 TCGv_i64 hitmp
= tcg_temp_new_i64();
1683 g_assert(size
>= 2);
1684 tcg_gen_addi_i64(addr2
, addr
, 1 << size
);
1685 tcg_gen_qemu_ld_i64(hitmp
, addr2
, get_mem_index(s
), memop
);
1686 tcg_temp_free_i64(addr2
);
1687 tcg_gen_mov_i64(cpu_exclusive_high
, hitmp
);
1688 tcg_gen_mov_i64(cpu_reg(s
, rt2
), hitmp
);
1689 tcg_temp_free_i64(hitmp
);
1692 tcg_gen_mov_i64(cpu_exclusive_val
, tmp
);
1693 tcg_gen_mov_i64(cpu_reg(s
, rt
), tmp
);
1695 tcg_temp_free_i64(tmp
);
1696 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
1699 #ifdef CONFIG_USER_ONLY
1700 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1701 TCGv_i64 addr
, int size
, int is_pair
)
1703 tcg_gen_mov_i64(cpu_exclusive_test
, addr
);
1704 tcg_gen_movi_i32(cpu_exclusive_info
,
1705 size
| is_pair
<< 2 | (rd
<< 4) | (rt
<< 9) | (rt2
<< 14));
1706 gen_exception_internal_insn(s
, 4, EXCP_STREX
);
1709 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1710 TCGv_i64 inaddr
, int size
, int is_pair
)
1712 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1713 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1716 * [addr + datasize] = {Rt2};
1722 * env->exclusive_addr = -1;
1724 TCGLabel
*fail_label
= gen_new_label();
1725 TCGLabel
*done_label
= gen_new_label();
1726 TCGv_i64 addr
= tcg_temp_local_new_i64();
1729 /* Copy input into a local temp so it is not trashed when the
1730 * basic block ends at the branch insn.
1732 tcg_gen_mov_i64(addr
, inaddr
);
1733 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
1735 tmp
= tcg_temp_new_i64();
1736 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), MO_TE
+ size
);
1737 tcg_gen_brcond_i64(TCG_COND_NE
, tmp
, cpu_exclusive_val
, fail_label
);
1738 tcg_temp_free_i64(tmp
);
1741 TCGv_i64 addrhi
= tcg_temp_new_i64();
1742 TCGv_i64 tmphi
= tcg_temp_new_i64();
1744 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1745 tcg_gen_qemu_ld_i64(tmphi
, addrhi
, get_mem_index(s
), MO_TE
+ size
);
1746 tcg_gen_brcond_i64(TCG_COND_NE
, tmphi
, cpu_exclusive_high
, fail_label
);
1748 tcg_temp_free_i64(tmphi
);
1749 tcg_temp_free_i64(addrhi
);
1752 /* We seem to still have the exclusive monitor, so do the store */
1753 tcg_gen_qemu_st_i64(cpu_reg(s
, rt
), addr
, get_mem_index(s
), MO_TE
+ size
);
1755 TCGv_i64 addrhi
= tcg_temp_new_i64();
1757 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1758 tcg_gen_qemu_st_i64(cpu_reg(s
, rt2
), addrhi
,
1759 get_mem_index(s
), MO_TE
+ size
);
1760 tcg_temp_free_i64(addrhi
);
1763 tcg_temp_free_i64(addr
);
1765 tcg_gen_movi_i64(cpu_reg(s
, rd
), 0);
1766 tcg_gen_br(done_label
);
1767 gen_set_label(fail_label
);
1768 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
1769 gen_set_label(done_label
);
1770 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1775 /* C3.3.6 Load/store exclusive
1777 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
1778 * +-----+-------------+----+---+----+------+----+-------+------+------+
1779 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
1780 * +-----+-------------+----+---+----+------+----+-------+------+------+
1782 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
1783 * L: 0 -> store, 1 -> load
1784 * o2: 0 -> exclusive, 1 -> not
1785 * o1: 0 -> single register, 1 -> register pair
1786 * o0: 1 -> load-acquire/store-release, 0 -> not
1788 * o0 == 0 AND o2 == 1 is un-allocated
1789 * o1 == 1 is un-allocated except for 32 and 64 bit sizes
1791 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
1793 int rt
= extract32(insn
, 0, 5);
1794 int rn
= extract32(insn
, 5, 5);
1795 int rt2
= extract32(insn
, 10, 5);
1796 int is_lasr
= extract32(insn
, 15, 1);
1797 int rs
= extract32(insn
, 16, 5);
1798 int is_pair
= extract32(insn
, 21, 1);
1799 int is_store
= !extract32(insn
, 22, 1);
1800 int is_excl
= !extract32(insn
, 23, 1);
1801 int size
= extract32(insn
, 30, 2);
1804 if ((!is_excl
&& !is_lasr
) ||
1805 (is_pair
&& size
< 2)) {
1806 unallocated_encoding(s
);
1811 gen_check_sp_alignment(s
);
1813 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1815 /* Note that since TCG is single threaded load-acquire/store-release
1816 * semantics require no extra if (is_lasr) { ... } handling.
1822 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1824 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1827 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1829 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1831 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, false, false);
1834 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt
);
1835 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
1837 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
1839 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, false, false);
1846 * C3.3.5 Load register (literal)
1848 * 31 30 29 27 26 25 24 23 5 4 0
1849 * +-----+-------+---+-----+-------------------+-------+
1850 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
1851 * +-----+-------+---+-----+-------------------+-------+
1853 * V: 1 -> vector (simd/fp)
1854 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
1855 * 10-> 32 bit signed, 11 -> prefetch
1856 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
1858 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
1860 int rt
= extract32(insn
, 0, 5);
1861 int64_t imm
= sextract32(insn
, 5, 19) << 2;
1862 bool is_vector
= extract32(insn
, 26, 1);
1863 int opc
= extract32(insn
, 30, 2);
1864 bool is_signed
= false;
1866 TCGv_i64 tcg_rt
, tcg_addr
;
1870 unallocated_encoding(s
);
1874 if (!fp_access_check(s
)) {
1879 /* PRFM (literal) : prefetch */
1882 size
= 2 + extract32(opc
, 0, 1);
1883 is_signed
= extract32(opc
, 1, 1);
1886 tcg_rt
= cpu_reg(s
, rt
);
1888 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
1890 do_fp_ld(s
, rt
, tcg_addr
, size
);
1892 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
1894 tcg_temp_free_i64(tcg_addr
);
1898 * C5.6.80 LDNP (Load Pair - non-temporal hint)
1899 * C5.6.81 LDP (Load Pair - non vector)
1900 * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
1901 * C5.6.176 STNP (Store Pair - non-temporal hint)
1902 * C5.6.177 STP (Store Pair - non vector)
1903 * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
1904 * C6.3.165 LDP (Load Pair of SIMD&FP)
1905 * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
1906 * C6.3.284 STP (Store Pair of SIMD&FP)
1908 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
1909 * +-----+-------+---+---+-------+---+-----------------------------+
1910 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
1911 * +-----+-------+---+---+-------+---+-------+-------+------+------+
1913 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
1915 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
1916 * V: 0 -> GPR, 1 -> Vector
1917 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
1918 * 10 -> signed offset, 11 -> pre-index
1919 * L: 0 -> Store 1 -> Load
1921 * Rt, Rt2 = GPR or SIMD registers to be stored
1922 * Rn = general purpose register containing address
1923 * imm7 = signed offset (multiple of 4 or 8 depending on size)
1925 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
1927 int rt
= extract32(insn
, 0, 5);
1928 int rn
= extract32(insn
, 5, 5);
1929 int rt2
= extract32(insn
, 10, 5);
1930 uint64_t offset
= sextract64(insn
, 15, 7);
1931 int index
= extract32(insn
, 23, 2);
1932 bool is_vector
= extract32(insn
, 26, 1);
1933 bool is_load
= extract32(insn
, 22, 1);
1934 int opc
= extract32(insn
, 30, 2);
1936 bool is_signed
= false;
1937 bool postindex
= false;
1940 TCGv_i64 tcg_addr
; /* calculated address */
1944 unallocated_encoding(s
);
1951 size
= 2 + extract32(opc
, 1, 1);
1952 is_signed
= extract32(opc
, 0, 1);
1953 if (!is_load
&& is_signed
) {
1954 unallocated_encoding(s
);
1960 case 1: /* post-index */
1965 /* signed offset with "non-temporal" hint. Since we don't emulate
1966 * caches we don't care about hints to the cache system about
1967 * data access patterns, and handle this identically to plain
1971 /* There is no non-temporal-hint version of LDPSW */
1972 unallocated_encoding(s
);
1977 case 2: /* signed offset, rn not updated */
1980 case 3: /* pre-index */
1986 if (is_vector
&& !fp_access_check(s
)) {
1993 gen_check_sp_alignment(s
);
1996 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1999 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2004 do_fp_ld(s
, rt
, tcg_addr
, size
);
2006 do_fp_st(s
, rt
, tcg_addr
, size
);
2009 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2011 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
2013 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2016 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2019 do_fp_ld(s
, rt2
, tcg_addr
, size
);
2021 do_fp_st(s
, rt2
, tcg_addr
, size
);
2024 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2026 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false);
2028 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
2034 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
2036 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2038 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
2043 * C3.3.8 Load/store (immediate post-indexed)
2044 * C3.3.9 Load/store (immediate pre-indexed)
2045 * C3.3.12 Load/store (unscaled immediate)
2047 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2048 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2049 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2050 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2052 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2054 * V = 0 -> non-vector
2055 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2056 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2058 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
)
2060 int rt
= extract32(insn
, 0, 5);
2061 int rn
= extract32(insn
, 5, 5);
2062 int imm9
= sextract32(insn
, 12, 9);
2063 int opc
= extract32(insn
, 22, 2);
2064 int size
= extract32(insn
, 30, 2);
2065 int idx
= extract32(insn
, 10, 2);
2066 bool is_signed
= false;
2067 bool is_store
= false;
2068 bool is_extended
= false;
2069 bool is_unpriv
= (idx
== 2);
2070 bool is_vector
= extract32(insn
, 26, 1);
2077 size
|= (opc
& 2) << 1;
2078 if (size
> 4 || is_unpriv
) {
2079 unallocated_encoding(s
);
2082 is_store
= ((opc
& 1) == 0);
2083 if (!fp_access_check(s
)) {
2087 if (size
== 3 && opc
== 2) {
2088 /* PRFM - prefetch */
2090 unallocated_encoding(s
);
2095 if (opc
== 3 && size
> 1) {
2096 unallocated_encoding(s
);
2099 is_store
= (opc
== 0);
2100 is_signed
= opc
& (1<<1);
2101 is_extended
= (size
< 3) && (opc
& 1);
2121 gen_check_sp_alignment(s
);
2123 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2126 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2131 do_fp_st(s
, rt
, tcg_addr
, size
);
2133 do_fp_ld(s
, rt
, tcg_addr
, size
);
2136 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2137 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2140 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
);
2142 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
2143 is_signed
, is_extended
, memidx
);
2148 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2150 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2152 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2157 * C3.3.10 Load/store (register offset)
2159 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2160 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2161 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2162 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2165 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2166 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2168 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2169 * opc<0>: 0 -> store, 1 -> load
2170 * V: 1 -> vector/simd
2171 * opt: extend encoding (see DecodeRegExtend)
2172 * S: if S=1 then scale (essentially index by sizeof(size))
2173 * Rt: register to transfer into/out of
2174 * Rn: address register or SP for base
2175 * Rm: offset register or ZR for offset
2177 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
)
2179 int rt
= extract32(insn
, 0, 5);
2180 int rn
= extract32(insn
, 5, 5);
2181 int shift
= extract32(insn
, 12, 1);
2182 int rm
= extract32(insn
, 16, 5);
2183 int opc
= extract32(insn
, 22, 2);
2184 int opt
= extract32(insn
, 13, 3);
2185 int size
= extract32(insn
, 30, 2);
2186 bool is_signed
= false;
2187 bool is_store
= false;
2188 bool is_extended
= false;
2189 bool is_vector
= extract32(insn
, 26, 1);
2194 if (extract32(opt
, 1, 1) == 0) {
2195 unallocated_encoding(s
);
2200 size
|= (opc
& 2) << 1;
2202 unallocated_encoding(s
);
2205 is_store
= !extract32(opc
, 0, 1);
2206 if (!fp_access_check(s
)) {
2210 if (size
== 3 && opc
== 2) {
2211 /* PRFM - prefetch */
2214 if (opc
== 3 && size
> 1) {
2215 unallocated_encoding(s
);
2218 is_store
= (opc
== 0);
2219 is_signed
= extract32(opc
, 1, 1);
2220 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2224 gen_check_sp_alignment(s
);
2226 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2228 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2229 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2231 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2235 do_fp_st(s
, rt
, tcg_addr
, size
);
2237 do_fp_ld(s
, rt
, tcg_addr
, size
);
2240 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2242 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2244 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2250 * C3.3.13 Load/store (unsigned immediate)
2252 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2253 * +----+-------+---+-----+-----+------------+-------+------+
2254 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2255 * +----+-------+---+-----+-----+------------+-------+------+
2258 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2259 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2261 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2262 * opc<0>: 0 -> store, 1 -> load
2263 * Rn: base address register (inc SP)
2264 * Rt: target register
2266 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
)
2268 int rt
= extract32(insn
, 0, 5);
2269 int rn
= extract32(insn
, 5, 5);
2270 unsigned int imm12
= extract32(insn
, 10, 12);
2271 bool is_vector
= extract32(insn
, 26, 1);
2272 int size
= extract32(insn
, 30, 2);
2273 int opc
= extract32(insn
, 22, 2);
2274 unsigned int offset
;
2279 bool is_signed
= false;
2280 bool is_extended
= false;
2283 size
|= (opc
& 2) << 1;
2285 unallocated_encoding(s
);
2288 is_store
= !extract32(opc
, 0, 1);
2289 if (!fp_access_check(s
)) {
2293 if (size
== 3 && opc
== 2) {
2294 /* PRFM - prefetch */
2297 if (opc
== 3 && size
> 1) {
2298 unallocated_encoding(s
);
2301 is_store
= (opc
== 0);
2302 is_signed
= extract32(opc
, 1, 1);
2303 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2307 gen_check_sp_alignment(s
);
2309 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2310 offset
= imm12
<< size
;
2311 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2315 do_fp_st(s
, rt
, tcg_addr
, size
);
2317 do_fp_ld(s
, rt
, tcg_addr
, size
);
2320 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2322 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2324 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2329 /* Load/store register (all forms) */
2330 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2332 switch (extract32(insn
, 24, 2)) {
2334 if (extract32(insn
, 21, 1) == 1 && extract32(insn
, 10, 2) == 2) {
2335 disas_ldst_reg_roffset(s
, insn
);
2337 /* Load/store register (unscaled immediate)
2338 * Load/store immediate pre/post-indexed
2339 * Load/store register unprivileged
2341 disas_ldst_reg_imm9(s
, insn
);
2345 disas_ldst_reg_unsigned_imm(s
, insn
);
2348 unallocated_encoding(s
);
2353 /* C3.3.1 AdvSIMD load/store multiple structures
2355 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2356 * +---+---+---------------+---+-------------+--------+------+------+------+
2357 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2358 * +---+---+---------------+---+-------------+--------+------+------+------+
2360 * C3.3.2 AdvSIMD load/store multiple structures (post-indexed)
2362 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2363 * +---+---+---------------+---+---+---------+--------+------+------+------+
2364 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2365 * +---+---+---------------+---+---+---------+--------+------+------+------+
2367 * Rt: first (or only) SIMD&FP register to be transferred
2368 * Rn: base address or SP
2369 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2371 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
2373 int rt
= extract32(insn
, 0, 5);
2374 int rn
= extract32(insn
, 5, 5);
2375 int size
= extract32(insn
, 10, 2);
2376 int opcode
= extract32(insn
, 12, 4);
2377 bool is_store
= !extract32(insn
, 22, 1);
2378 bool is_postidx
= extract32(insn
, 23, 1);
2379 bool is_q
= extract32(insn
, 30, 1);
2380 TCGv_i64 tcg_addr
, tcg_rn
;
2382 int ebytes
= 1 << size
;
2383 int elements
= (is_q
? 128 : 64) / (8 << size
);
2384 int rpt
; /* num iterations */
2385 int selem
; /* structure elements */
2388 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
2389 unallocated_encoding(s
);
2393 /* From the shared decode logic */
2424 unallocated_encoding(s
);
2428 if (size
== 3 && !is_q
&& selem
!= 1) {
2430 unallocated_encoding(s
);
2434 if (!fp_access_check(s
)) {
2439 gen_check_sp_alignment(s
);
2442 tcg_rn
= cpu_reg_sp(s
, rn
);
2443 tcg_addr
= tcg_temp_new_i64();
2444 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2446 for (r
= 0; r
< rpt
; r
++) {
2448 for (e
= 0; e
< elements
; e
++) {
2449 int tt
= (rt
+ r
) % 32;
2451 for (xs
= 0; xs
< selem
; xs
++) {
2453 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
2455 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
2457 /* For non-quad operations, setting a slice of the low
2458 * 64 bits of the register clears the high 64 bits (in
2459 * the ARM ARM pseudocode this is implicit in the fact
2460 * that 'rval' is a 64 bit wide variable). We optimize
2461 * by noticing that we only need to do this the first
2462 * time we touch a register.
2464 if (!is_q
&& e
== 0 && (r
== 0 || xs
== selem
- 1)) {
2465 clear_vec_high(s
, tt
);
2468 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2475 int rm
= extract32(insn
, 16, 5);
2477 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2479 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2482 tcg_temp_free_i64(tcg_addr
);
2485 /* C3.3.3 AdvSIMD load/store single structure
2487 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2488 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2489 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
2490 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2492 * C3.3.4 AdvSIMD load/store single structure (post-indexed)
2494 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2495 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2496 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
2497 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2499 * Rt: first (or only) SIMD&FP register to be transferred
2500 * Rn: base address or SP
2501 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2502 * index = encoded in Q:S:size dependent on size
2504 * lane_size = encoded in R, opc
2505 * transfer width = encoded in opc, S, size
2507 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
2509 int rt
= extract32(insn
, 0, 5);
2510 int rn
= extract32(insn
, 5, 5);
2511 int size
= extract32(insn
, 10, 2);
2512 int S
= extract32(insn
, 12, 1);
2513 int opc
= extract32(insn
, 13, 3);
2514 int R
= extract32(insn
, 21, 1);
2515 int is_load
= extract32(insn
, 22, 1);
2516 int is_postidx
= extract32(insn
, 23, 1);
2517 int is_q
= extract32(insn
, 30, 1);
2519 int scale
= extract32(opc
, 1, 2);
2520 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
2521 bool replicate
= false;
2522 int index
= is_q
<< 3 | S
<< 2 | size
;
2524 TCGv_i64 tcg_addr
, tcg_rn
;
2528 if (!is_load
|| S
) {
2529 unallocated_encoding(s
);
2538 if (extract32(size
, 0, 1)) {
2539 unallocated_encoding(s
);
2545 if (extract32(size
, 1, 1)) {
2546 unallocated_encoding(s
);
2549 if (!extract32(size
, 0, 1)) {
2553 unallocated_encoding(s
);
2561 g_assert_not_reached();
2564 if (!fp_access_check(s
)) {
2568 ebytes
= 1 << scale
;
2571 gen_check_sp_alignment(s
);
2574 tcg_rn
= cpu_reg_sp(s
, rn
);
2575 tcg_addr
= tcg_temp_new_i64();
2576 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2578 for (xs
= 0; xs
< selem
; xs
++) {
2580 /* Load and replicate to all elements */
2582 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
2584 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
2585 get_mem_index(s
), MO_TE
+ scale
);
2588 mulconst
= 0x0101010101010101ULL
;
2591 mulconst
= 0x0001000100010001ULL
;
2594 mulconst
= 0x0000000100000001ULL
;
2600 g_assert_not_reached();
2603 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
2605 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
2607 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
2609 clear_vec_high(s
, rt
);
2611 tcg_temp_free_i64(tcg_tmp
);
2613 /* Load/store one element per register */
2615 do_vec_ld(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2617 do_vec_st(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2620 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2625 int rm
= extract32(insn
, 16, 5);
2627 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2629 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2632 tcg_temp_free_i64(tcg_addr
);
2635 /* C3.3 Loads and stores */
2636 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
2638 switch (extract32(insn
, 24, 6)) {
2639 case 0x08: /* Load/store exclusive */
2640 disas_ldst_excl(s
, insn
);
2642 case 0x18: case 0x1c: /* Load register (literal) */
2643 disas_ld_lit(s
, insn
);
2645 case 0x28: case 0x29:
2646 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
2647 disas_ldst_pair(s
, insn
);
2649 case 0x38: case 0x39:
2650 case 0x3c: case 0x3d: /* Load/store register (all forms) */
2651 disas_ldst_reg(s
, insn
);
2653 case 0x0c: /* AdvSIMD load/store multiple structures */
2654 disas_ldst_multiple_struct(s
, insn
);
2656 case 0x0d: /* AdvSIMD load/store single structure */
2657 disas_ldst_single_struct(s
, insn
);
2660 unallocated_encoding(s
);
2665 /* C3.4.6 PC-rel. addressing
2666 * 31 30 29 28 24 23 5 4 0
2667 * +----+-------+-----------+-------------------+------+
2668 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
2669 * +----+-------+-----------+-------------------+------+
2671 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
2673 unsigned int page
, rd
;
2677 page
= extract32(insn
, 31, 1);
2678 /* SignExtend(immhi:immlo) -> offset */
2679 offset
= sextract64(insn
, 5, 19);
2680 offset
= offset
<< 2 | extract32(insn
, 29, 2);
2681 rd
= extract32(insn
, 0, 5);
2685 /* ADRP (page based) */
2690 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
2694 * C3.4.1 Add/subtract (immediate)
2696 * 31 30 29 28 24 23 22 21 10 9 5 4 0
2697 * +--+--+--+-----------+-----+-------------+-----+-----+
2698 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
2699 * +--+--+--+-----------+-----+-------------+-----+-----+
2701 * sf: 0 -> 32bit, 1 -> 64bit
2702 * op: 0 -> add , 1 -> sub
2704 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
2706 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
2708 int rd
= extract32(insn
, 0, 5);
2709 int rn
= extract32(insn
, 5, 5);
2710 uint64_t imm
= extract32(insn
, 10, 12);
2711 int shift
= extract32(insn
, 22, 2);
2712 bool setflags
= extract32(insn
, 29, 1);
2713 bool sub_op
= extract32(insn
, 30, 1);
2714 bool is_64bit
= extract32(insn
, 31, 1);
2716 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2717 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
2718 TCGv_i64 tcg_result
;
2727 unallocated_encoding(s
);
2731 tcg_result
= tcg_temp_new_i64();
2734 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
2736 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
2739 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
2741 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2743 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2745 tcg_temp_free_i64(tcg_imm
);
2749 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
2751 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
2754 tcg_temp_free_i64(tcg_result
);
2757 /* The input should be a value in the bottom e bits (with higher
2758 * bits zero); returns that value replicated into every element
2759 * of size e in a 64 bit integer.
2761 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
2771 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
2772 static inline uint64_t bitmask64(unsigned int length
)
2774 assert(length
> 0 && length
<= 64);
2775 return ~0ULL >> (64 - length
);
2778 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
2779 * only require the wmask. Returns false if the imms/immr/immn are a reserved
2780 * value (ie should cause a guest UNDEF exception), and true if they are
2781 * valid, in which case the decoded bit pattern is written to result.
2783 static bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
2784 unsigned int imms
, unsigned int immr
)
2787 unsigned e
, levels
, s
, r
;
2790 assert(immn
< 2 && imms
< 64 && immr
< 64);
2792 /* The bit patterns we create here are 64 bit patterns which
2793 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
2794 * 64 bits each. Each element contains the same value: a run
2795 * of between 1 and e-1 non-zero bits, rotated within the
2796 * element by between 0 and e-1 bits.
2798 * The element size and run length are encoded into immn (1 bit)
2799 * and imms (6 bits) as follows:
2800 * 64 bit elements: immn = 1, imms = <length of run - 1>
2801 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
2802 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
2803 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
2804 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
2805 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
2806 * Notice that immn = 0, imms = 11111x is the only combination
2807 * not covered by one of the above options; this is reserved.
2808 * Further, <length of run - 1> all-ones is a reserved pattern.
2810 * In all cases the rotation is by immr % e (and immr is 6 bits).
2813 /* First determine the element size */
2814 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
2816 /* This is the immn == 0, imms == 0x11111x case */
2826 /* <length of run - 1> mustn't be all-ones. */
2830 /* Create the value of one element: s+1 set bits rotated
2831 * by r within the element (which is e bits wide)...
2833 mask
= bitmask64(s
+ 1);
2835 mask
= (mask
>> r
) | (mask
<< (e
- r
));
2836 mask
&= bitmask64(e
);
2838 /* ...then replicate the element over the whole 64 bit value */
2839 mask
= bitfield_replicate(mask
, e
);
2844 /* C3.4.4 Logical (immediate)
2845 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2846 * +----+-----+-------------+---+------+------+------+------+
2847 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
2848 * +----+-----+-------------+---+------+------+------+------+
2850 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
2852 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
2853 TCGv_i64 tcg_rd
, tcg_rn
;
2855 bool is_and
= false;
2857 sf
= extract32(insn
, 31, 1);
2858 opc
= extract32(insn
, 29, 2);
2859 is_n
= extract32(insn
, 22, 1);
2860 immr
= extract32(insn
, 16, 6);
2861 imms
= extract32(insn
, 10, 6);
2862 rn
= extract32(insn
, 5, 5);
2863 rd
= extract32(insn
, 0, 5);
2866 unallocated_encoding(s
);
2870 if (opc
== 0x3) { /* ANDS */
2871 tcg_rd
= cpu_reg(s
, rd
);
2873 tcg_rd
= cpu_reg_sp(s
, rd
);
2875 tcg_rn
= cpu_reg(s
, rn
);
2877 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
2878 /* some immediate field values are reserved */
2879 unallocated_encoding(s
);
2884 wmask
&= 0xffffffff;
2888 case 0x3: /* ANDS */
2890 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
2894 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
2897 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
2900 assert(FALSE
); /* must handle all above */
2904 if (!sf
&& !is_and
) {
2905 /* zero extend final result; we know we can skip this for AND
2906 * since the immediate had the high 32 bits clear.
2908 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2911 if (opc
== 3) { /* ANDS */
2912 gen_logic_CC(sf
, tcg_rd
);
2917 * C3.4.5 Move wide (immediate)
2919 * 31 30 29 28 23 22 21 20 5 4 0
2920 * +--+-----+-------------+-----+----------------+------+
2921 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
2922 * +--+-----+-------------+-----+----------------+------+
2924 * sf: 0 -> 32 bit, 1 -> 64 bit
2925 * opc: 00 -> N, 10 -> Z, 11 -> K
2926 * hw: shift/16 (0,16, and sf only 32, 48)
2928 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
2930 int rd
= extract32(insn
, 0, 5);
2931 uint64_t imm
= extract32(insn
, 5, 16);
2932 int sf
= extract32(insn
, 31, 1);
2933 int opc
= extract32(insn
, 29, 2);
2934 int pos
= extract32(insn
, 21, 2) << 4;
2935 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
2938 if (!sf
&& (pos
>= 32)) {
2939 unallocated_encoding(s
);
2953 tcg_gen_movi_i64(tcg_rd
, imm
);
2956 tcg_imm
= tcg_const_i64(imm
);
2957 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
2958 tcg_temp_free_i64(tcg_imm
);
2960 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2964 unallocated_encoding(s
);
2970 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2971 * +----+-----+-------------+---+------+------+------+------+
2972 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
2973 * +----+-----+-------------+---+------+------+------+------+
2975 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
2977 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
2978 TCGv_i64 tcg_rd
, tcg_tmp
;
2980 sf
= extract32(insn
, 31, 1);
2981 opc
= extract32(insn
, 29, 2);
2982 n
= extract32(insn
, 22, 1);
2983 ri
= extract32(insn
, 16, 6);
2984 si
= extract32(insn
, 10, 6);
2985 rn
= extract32(insn
, 5, 5);
2986 rd
= extract32(insn
, 0, 5);
2987 bitsize
= sf
? 64 : 32;
2989 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
2990 unallocated_encoding(s
);
2994 tcg_rd
= cpu_reg(s
, rd
);
2995 tcg_tmp
= read_cpu_reg(s
, rn
, sf
);
2997 /* OPTME: probably worth recognizing common cases of ext{8,16,32}{u,s} */
2999 if (opc
!= 1) { /* SBFM or UBFM */
3000 tcg_gen_movi_i64(tcg_rd
, 0);
3003 /* do the bit move operation */
3005 /* Wd<s-r:0> = Wn<s:r> */
3006 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
3008 len
= (si
- ri
) + 1;
3010 /* Wd<32+s-r,32-r> = Wn<s:0> */
3015 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
3017 if (opc
== 0) { /* SBFM - sign extend the destination field */
3018 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
3019 tcg_gen_sari_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
3022 if (!sf
) { /* zero extend final result */
3023 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3028 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3029 * +----+------+-------------+---+----+------+--------+------+------+
3030 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3031 * +----+------+-------------+---+----+------+--------+------+------+
3033 static void disas_extract(DisasContext
*s
, uint32_t insn
)
3035 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
3037 sf
= extract32(insn
, 31, 1);
3038 n
= extract32(insn
, 22, 1);
3039 rm
= extract32(insn
, 16, 5);
3040 imm
= extract32(insn
, 10, 6);
3041 rn
= extract32(insn
, 5, 5);
3042 rd
= extract32(insn
, 0, 5);
3043 op21
= extract32(insn
, 29, 2);
3044 op0
= extract32(insn
, 21, 1);
3045 bitsize
= sf
? 64 : 32;
3047 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
3048 unallocated_encoding(s
);
3050 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
3052 tcg_rd
= cpu_reg(s
, rd
);
3055 /* OPTME: we can special case rm==rn as a rotate */
3056 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3057 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3058 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
3059 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
3060 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
3062 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3065 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3066 * so an extract from bit 0 is a special case.
3069 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
3071 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
3078 /* C3.4 Data processing - immediate */
3079 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
3081 switch (extract32(insn
, 23, 6)) {
3082 case 0x20: case 0x21: /* PC-rel. addressing */
3083 disas_pc_rel_adr(s
, insn
);
3085 case 0x22: case 0x23: /* Add/subtract (immediate) */
3086 disas_add_sub_imm(s
, insn
);
3088 case 0x24: /* Logical (immediate) */
3089 disas_logic_imm(s
, insn
);
3091 case 0x25: /* Move wide (immediate) */
3092 disas_movw_imm(s
, insn
);
3094 case 0x26: /* Bitfield */
3095 disas_bitfield(s
, insn
);
3097 case 0x27: /* Extract */
3098 disas_extract(s
, insn
);
3101 unallocated_encoding(s
);
3106 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3107 * Note that it is the caller's responsibility to ensure that the
3108 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3109 * mandated semantics for out of range shifts.
3111 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3112 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
3114 switch (shift_type
) {
3115 case A64_SHIFT_TYPE_LSL
:
3116 tcg_gen_shl_i64(dst
, src
, shift_amount
);
3118 case A64_SHIFT_TYPE_LSR
:
3119 tcg_gen_shr_i64(dst
, src
, shift_amount
);
3121 case A64_SHIFT_TYPE_ASR
:
3123 tcg_gen_ext32s_i64(dst
, src
);
3125 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
3127 case A64_SHIFT_TYPE_ROR
:
3129 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
3132 t0
= tcg_temp_new_i32();
3133 t1
= tcg_temp_new_i32();
3134 tcg_gen_trunc_i64_i32(t0
, src
);
3135 tcg_gen_trunc_i64_i32(t1
, shift_amount
);
3136 tcg_gen_rotr_i32(t0
, t0
, t1
);
3137 tcg_gen_extu_i32_i64(dst
, t0
);
3138 tcg_temp_free_i32(t0
);
3139 tcg_temp_free_i32(t1
);
3143 assert(FALSE
); /* all shift types should be handled */
3147 if (!sf
) { /* zero extend final result */
3148 tcg_gen_ext32u_i64(dst
, dst
);
3152 /* Shift a TCGv src by immediate, put result in dst.
3153 * The shift amount must be in range (this should always be true as the
3154 * relevant instructions will UNDEF on bad shift immediates).
3156 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3157 enum a64_shift_type shift_type
, unsigned int shift_i
)
3159 assert(shift_i
< (sf
? 64 : 32));
3162 tcg_gen_mov_i64(dst
, src
);
3164 TCGv_i64 shift_const
;
3166 shift_const
= tcg_const_i64(shift_i
);
3167 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
3168 tcg_temp_free_i64(shift_const
);
3172 /* C3.5.10 Logical (shifted register)
3173 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3174 * +----+-----+-----------+-------+---+------+--------+------+------+
3175 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3176 * +----+-----+-----------+-------+---+------+--------+------+------+
3178 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
3180 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
3181 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
3183 sf
= extract32(insn
, 31, 1);
3184 opc
= extract32(insn
, 29, 2);
3185 shift_type
= extract32(insn
, 22, 2);
3186 invert
= extract32(insn
, 21, 1);
3187 rm
= extract32(insn
, 16, 5);
3188 shift_amount
= extract32(insn
, 10, 6);
3189 rn
= extract32(insn
, 5, 5);
3190 rd
= extract32(insn
, 0, 5);
3192 if (!sf
&& (shift_amount
& (1 << 5))) {
3193 unallocated_encoding(s
);
3197 tcg_rd
= cpu_reg(s
, rd
);
3199 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3200 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3201 * register-register MOV and MVN, so it is worth special casing.
3203 tcg_rm
= cpu_reg(s
, rm
);
3205 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3207 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3211 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3213 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3219 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3222 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3225 tcg_rn
= cpu_reg(s
, rn
);
3227 switch (opc
| (invert
<< 2)) {
3230 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3233 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3236 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3240 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3243 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3246 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3254 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3258 gen_logic_CC(sf
, tcg_rd
);
3263 * C3.5.1 Add/subtract (extended register)
3265 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3266 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3267 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3268 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3270 * sf: 0 -> 32bit, 1 -> 64bit
3271 * op: 0 -> add , 1 -> sub
3274 * option: extension type (see DecodeRegExtend)
3275 * imm3: optional shift to Rm
3277 * Rd = Rn + LSL(extend(Rm), amount)
3279 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3281 int rd
= extract32(insn
, 0, 5);
3282 int rn
= extract32(insn
, 5, 5);
3283 int imm3
= extract32(insn
, 10, 3);
3284 int option
= extract32(insn
, 13, 3);
3285 int rm
= extract32(insn
, 16, 5);
3286 bool setflags
= extract32(insn
, 29, 1);
3287 bool sub_op
= extract32(insn
, 30, 1);
3288 bool sf
= extract32(insn
, 31, 1);
3290 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3292 TCGv_i64 tcg_result
;
3295 unallocated_encoding(s
);
3299 /* non-flag setting ops may use SP */
3301 tcg_rd
= cpu_reg_sp(s
, rd
);
3303 tcg_rd
= cpu_reg(s
, rd
);
3305 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3307 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3308 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3310 tcg_result
= tcg_temp_new_i64();
3314 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3316 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3320 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3322 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3327 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3329 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3332 tcg_temp_free_i64(tcg_result
);
3336 * C3.5.2 Add/subtract (shifted register)
3338 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3339 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3340 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3341 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3343 * sf: 0 -> 32bit, 1 -> 64bit
3344 * op: 0 -> add , 1 -> sub
3346 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3347 * imm6: Shift amount to apply to Rm before the add/sub
3349 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
3351 int rd
= extract32(insn
, 0, 5);
3352 int rn
= extract32(insn
, 5, 5);
3353 int imm6
= extract32(insn
, 10, 6);
3354 int rm
= extract32(insn
, 16, 5);
3355 int shift_type
= extract32(insn
, 22, 2);
3356 bool setflags
= extract32(insn
, 29, 1);
3357 bool sub_op
= extract32(insn
, 30, 1);
3358 bool sf
= extract32(insn
, 31, 1);
3360 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3361 TCGv_i64 tcg_rn
, tcg_rm
;
3362 TCGv_i64 tcg_result
;
3364 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
3365 unallocated_encoding(s
);
3369 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3370 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3372 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
3374 tcg_result
= tcg_temp_new_i64();
3378 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3380 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3384 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3386 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3391 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3393 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3396 tcg_temp_free_i64(tcg_result
);
3399 /* C3.5.9 Data-processing (3 source)
3401 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3402 +--+------+-----------+------+------+----+------+------+------+
3403 |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3404 +--+------+-----------+------+------+----+------+------+------+
3407 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
3409 int rd
= extract32(insn
, 0, 5);
3410 int rn
= extract32(insn
, 5, 5);
3411 int ra
= extract32(insn
, 10, 5);
3412 int rm
= extract32(insn
, 16, 5);
3413 int op_id
= (extract32(insn
, 29, 3) << 4) |
3414 (extract32(insn
, 21, 3) << 1) |
3415 extract32(insn
, 15, 1);
3416 bool sf
= extract32(insn
, 31, 1);
3417 bool is_sub
= extract32(op_id
, 0, 1);
3418 bool is_high
= extract32(op_id
, 2, 1);
3419 bool is_signed
= false;
3424 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
3426 case 0x42: /* SMADDL */
3427 case 0x43: /* SMSUBL */
3428 case 0x44: /* SMULH */
3431 case 0x0: /* MADD (32bit) */
3432 case 0x1: /* MSUB (32bit) */
3433 case 0x40: /* MADD (64bit) */
3434 case 0x41: /* MSUB (64bit) */
3435 case 0x4a: /* UMADDL */
3436 case 0x4b: /* UMSUBL */
3437 case 0x4c: /* UMULH */
3440 unallocated_encoding(s
);
3445 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
3446 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3447 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
3448 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
3451 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3453 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3456 tcg_temp_free_i64(low_bits
);
3460 tcg_op1
= tcg_temp_new_i64();
3461 tcg_op2
= tcg_temp_new_i64();
3462 tcg_tmp
= tcg_temp_new_i64();
3465 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
3466 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
3469 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
3470 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
3472 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
3473 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
3477 if (ra
== 31 && !is_sub
) {
3478 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
3479 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
3481 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
3483 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3485 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3490 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
3493 tcg_temp_free_i64(tcg_op1
);
3494 tcg_temp_free_i64(tcg_op2
);
3495 tcg_temp_free_i64(tcg_tmp
);
3498 /* C3.5.3 - Add/subtract (with carry)
3499 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
3500 * +--+--+--+------------------------+------+---------+------+-----+
3501 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
3502 * +--+--+--+------------------------+------+---------+------+-----+
3506 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
3508 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
3509 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
3511 if (extract32(insn
, 10, 6) != 0) {
3512 unallocated_encoding(s
);
3516 sf
= extract32(insn
, 31, 1);
3517 op
= extract32(insn
, 30, 1);
3518 setflags
= extract32(insn
, 29, 1);
3519 rm
= extract32(insn
, 16, 5);
3520 rn
= extract32(insn
, 5, 5);
3521 rd
= extract32(insn
, 0, 5);
3523 tcg_rd
= cpu_reg(s
, rd
);
3524 tcg_rn
= cpu_reg(s
, rn
);
3527 tcg_y
= new_tmp_a64(s
);
3528 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
3530 tcg_y
= cpu_reg(s
, rm
);
3534 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3536 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3540 /* C3.5.4 - C3.5.5 Conditional compare (immediate / register)
3541 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3542 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3543 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
3544 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3547 static void disas_cc(DisasContext
*s
, uint32_t insn
)
3549 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
3550 TCGLabel
*label_continue
= NULL
;
3551 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
3553 if (!extract32(insn
, 29, 1)) {
3554 unallocated_encoding(s
);
3557 if (insn
& (1 << 10 | 1 << 4)) {
3558 unallocated_encoding(s
);
3561 sf
= extract32(insn
, 31, 1);
3562 op
= extract32(insn
, 30, 1);
3563 is_imm
= extract32(insn
, 11, 1);
3564 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
3565 cond
= extract32(insn
, 12, 4);
3566 rn
= extract32(insn
, 5, 5);
3567 nzcv
= extract32(insn
, 0, 4);
3569 if (cond
< 0x0e) { /* not always */
3570 TCGLabel
*label_match
= gen_new_label();
3571 label_continue
= gen_new_label();
3572 arm_gen_test_cc(cond
, label_match
);
3574 tcg_tmp
= tcg_temp_new_i64();
3575 tcg_gen_movi_i64(tcg_tmp
, nzcv
<< 28);
3576 gen_set_nzcv(tcg_tmp
);
3577 tcg_temp_free_i64(tcg_tmp
);
3578 tcg_gen_br(label_continue
);
3579 gen_set_label(label_match
);
3581 /* match, or condition is always */
3583 tcg_y
= new_tmp_a64(s
);
3584 tcg_gen_movi_i64(tcg_y
, y
);
3586 tcg_y
= cpu_reg(s
, y
);
3588 tcg_rn
= cpu_reg(s
, rn
);
3590 tcg_tmp
= tcg_temp_new_i64();
3592 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3594 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3596 tcg_temp_free_i64(tcg_tmp
);
3598 if (cond
< 0x0e) { /* continue */
3599 gen_set_label(label_continue
);
3603 /* C3.5.6 Conditional select
3604 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
3605 * +----+----+---+-----------------+------+------+-----+------+------+
3606 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
3607 * +----+----+---+-----------------+------+------+-----+------+------+
3609 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
3611 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
3612 TCGv_i64 tcg_rd
, tcg_src
;
3614 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
3615 /* S == 1 or op2<1> == 1 */
3616 unallocated_encoding(s
);
3619 sf
= extract32(insn
, 31, 1);
3620 else_inv
= extract32(insn
, 30, 1);
3621 rm
= extract32(insn
, 16, 5);
3622 cond
= extract32(insn
, 12, 4);
3623 else_inc
= extract32(insn
, 10, 1);
3624 rn
= extract32(insn
, 5, 5);
3625 rd
= extract32(insn
, 0, 5);
3628 /* silly no-op write; until we use movcond we must special-case
3629 * this to avoid a dead temporary across basic blocks.
3634 tcg_rd
= cpu_reg(s
, rd
);
3636 if (cond
>= 0x0e) { /* condition "always" */
3637 tcg_src
= read_cpu_reg(s
, rn
, sf
);
3638 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3640 /* OPTME: we could use movcond here, at the cost of duplicating
3641 * a lot of the arm_gen_test_cc() logic.
3643 TCGLabel
*label_match
= gen_new_label();
3644 TCGLabel
*label_continue
= gen_new_label();
3646 arm_gen_test_cc(cond
, label_match
);
3648 tcg_src
= cpu_reg(s
, rm
);
3650 if (else_inv
&& else_inc
) {
3651 tcg_gen_neg_i64(tcg_rd
, tcg_src
);
3652 } else if (else_inv
) {
3653 tcg_gen_not_i64(tcg_rd
, tcg_src
);
3654 } else if (else_inc
) {
3655 tcg_gen_addi_i64(tcg_rd
, tcg_src
, 1);
3657 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3660 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3662 tcg_gen_br(label_continue
);
3664 gen_set_label(label_match
);
3665 tcg_src
= read_cpu_reg(s
, rn
, sf
);
3666 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3668 gen_set_label(label_continue
);
3672 static void handle_clz(DisasContext
*s
, unsigned int sf
,
3673 unsigned int rn
, unsigned int rd
)
3675 TCGv_i64 tcg_rd
, tcg_rn
;
3676 tcg_rd
= cpu_reg(s
, rd
);
3677 tcg_rn
= cpu_reg(s
, rn
);
3680 gen_helper_clz64(tcg_rd
, tcg_rn
);
3682 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3683 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3684 gen_helper_clz(tcg_tmp32
, tcg_tmp32
);
3685 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3686 tcg_temp_free_i32(tcg_tmp32
);
3690 static void handle_cls(DisasContext
*s
, unsigned int sf
,
3691 unsigned int rn
, unsigned int rd
)
3693 TCGv_i64 tcg_rd
, tcg_rn
;
3694 tcg_rd
= cpu_reg(s
, rd
);
3695 tcg_rn
= cpu_reg(s
, rn
);
3698 gen_helper_cls64(tcg_rd
, tcg_rn
);
3700 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3701 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3702 gen_helper_cls32(tcg_tmp32
, tcg_tmp32
);
3703 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3704 tcg_temp_free_i32(tcg_tmp32
);
3708 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
3709 unsigned int rn
, unsigned int rd
)
3711 TCGv_i64 tcg_rd
, tcg_rn
;
3712 tcg_rd
= cpu_reg(s
, rd
);
3713 tcg_rn
= cpu_reg(s
, rn
);
3716 gen_helper_rbit64(tcg_rd
, tcg_rn
);
3718 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3719 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3720 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
3721 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3722 tcg_temp_free_i32(tcg_tmp32
);
3726 /* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
3727 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
3728 unsigned int rn
, unsigned int rd
)
3731 unallocated_encoding(s
);
3734 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
3737 /* C5.6.149 REV with sf==0, opcode==2
3738 * C5.6.151 REV32 (sf==1, opcode==2)
3740 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
3741 unsigned int rn
, unsigned int rd
)
3743 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3746 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3747 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3749 /* bswap32_i64 requires zero high word */
3750 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
3751 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
3752 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3753 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
3754 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
3756 tcg_temp_free_i64(tcg_tmp
);
3758 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
3759 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
3763 /* C5.6.150 REV16 (opcode==1) */
3764 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
3765 unsigned int rn
, unsigned int rd
)
3767 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3768 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3769 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3771 tcg_gen_andi_i64(tcg_tmp
, tcg_rn
, 0xffff);
3772 tcg_gen_bswap16_i64(tcg_rd
, tcg_tmp
);
3774 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 16);
3775 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3776 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3777 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 16, 16);
3780 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3781 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3782 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3783 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 32, 16);
3785 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 48);
3786 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3787 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 48, 16);
3790 tcg_temp_free_i64(tcg_tmp
);
3793 /* C3.5.7 Data-processing (1 source)
3794 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3795 * +----+---+---+-----------------+---------+--------+------+------+
3796 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
3797 * +----+---+---+-----------------+---------+--------+------+------+
3799 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
3801 unsigned int sf
, opcode
, rn
, rd
;
3803 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
3804 unallocated_encoding(s
);
3808 sf
= extract32(insn
, 31, 1);
3809 opcode
= extract32(insn
, 10, 6);
3810 rn
= extract32(insn
, 5, 5);
3811 rd
= extract32(insn
, 0, 5);
3815 handle_rbit(s
, sf
, rn
, rd
);
3818 handle_rev16(s
, sf
, rn
, rd
);
3821 handle_rev32(s
, sf
, rn
, rd
);
3824 handle_rev64(s
, sf
, rn
, rd
);
3827 handle_clz(s
, sf
, rn
, rd
);
3830 handle_cls(s
, sf
, rn
, rd
);
3835 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
3836 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3838 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
3839 tcg_rd
= cpu_reg(s
, rd
);
3841 if (!sf
&& is_signed
) {
3842 tcg_n
= new_tmp_a64(s
);
3843 tcg_m
= new_tmp_a64(s
);
3844 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
3845 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
3847 tcg_n
= read_cpu_reg(s
, rn
, sf
);
3848 tcg_m
= read_cpu_reg(s
, rm
, sf
);
3852 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
3854 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
3857 if (!sf
) { /* zero extend final result */
3858 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3862 /* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
3863 static void handle_shift_reg(DisasContext
*s
,
3864 enum a64_shift_type shift_type
, unsigned int sf
,
3865 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3867 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
3868 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3869 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3871 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
3872 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
3873 tcg_temp_free_i64(tcg_shift
);
3876 /* CRC32[BHWX], CRC32C[BHWX] */
3877 static void handle_crc32(DisasContext
*s
,
3878 unsigned int sf
, unsigned int sz
, bool crc32c
,
3879 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3881 TCGv_i64 tcg_acc
, tcg_val
;
3884 if (!arm_dc_feature(s
, ARM_FEATURE_CRC
)
3885 || (sf
== 1 && sz
!= 3)
3886 || (sf
== 0 && sz
== 3)) {
3887 unallocated_encoding(s
);
3892 tcg_val
= cpu_reg(s
, rm
);
3906 g_assert_not_reached();
3908 tcg_val
= new_tmp_a64(s
);
3909 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
3912 tcg_acc
= cpu_reg(s
, rn
);
3913 tcg_bytes
= tcg_const_i32(1 << sz
);
3916 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
3918 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
3921 tcg_temp_free_i32(tcg_bytes
);
3924 /* C3.5.8 Data-processing (2 source)
3925 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3926 * +----+---+---+-----------------+------+--------+------+------+
3927 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
3928 * +----+---+---+-----------------+------+--------+------+------+
3930 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
3932 unsigned int sf
, rm
, opcode
, rn
, rd
;
3933 sf
= extract32(insn
, 31, 1);
3934 rm
= extract32(insn
, 16, 5);
3935 opcode
= extract32(insn
, 10, 6);
3936 rn
= extract32(insn
, 5, 5);
3937 rd
= extract32(insn
, 0, 5);
3939 if (extract32(insn
, 29, 1)) {
3940 unallocated_encoding(s
);
3946 handle_div(s
, false, sf
, rm
, rn
, rd
);
3949 handle_div(s
, true, sf
, rm
, rn
, rd
);
3952 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
3955 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
3958 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
3961 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
3970 case 23: /* CRC32 */
3972 int sz
= extract32(opcode
, 0, 2);
3973 bool crc32c
= extract32(opcode
, 2, 1);
3974 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
3978 unallocated_encoding(s
);
3983 /* C3.5 Data processing - register */
3984 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
3986 switch (extract32(insn
, 24, 5)) {
3987 case 0x0a: /* Logical (shifted register) */
3988 disas_logic_reg(s
, insn
);
3990 case 0x0b: /* Add/subtract */
3991 if (insn
& (1 << 21)) { /* (extended register) */
3992 disas_add_sub_ext_reg(s
, insn
);
3994 disas_add_sub_reg(s
, insn
);
3997 case 0x1b: /* Data-processing (3 source) */
3998 disas_data_proc_3src(s
, insn
);
4001 switch (extract32(insn
, 21, 3)) {
4002 case 0x0: /* Add/subtract (with carry) */
4003 disas_adc_sbc(s
, insn
);
4005 case 0x2: /* Conditional compare */
4006 disas_cc(s
, insn
); /* both imm and reg forms */
4008 case 0x4: /* Conditional select */
4009 disas_cond_select(s
, insn
);
4011 case 0x6: /* Data-processing */
4012 if (insn
& (1 << 30)) { /* (1 source) */
4013 disas_data_proc_1src(s
, insn
);
4014 } else { /* (2 source) */
4015 disas_data_proc_2src(s
, insn
);
4019 unallocated_encoding(s
);
4024 unallocated_encoding(s
);
4029 static void handle_fp_compare(DisasContext
*s
, bool is_double
,
4030 unsigned int rn
, unsigned int rm
,
4031 bool cmp_with_zero
, bool signal_all_nans
)
4033 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
4034 TCGv_ptr fpst
= get_fpstatus_ptr();
4037 TCGv_i64 tcg_vn
, tcg_vm
;
4039 tcg_vn
= read_fp_dreg(s
, rn
);
4040 if (cmp_with_zero
) {
4041 tcg_vm
= tcg_const_i64(0);
4043 tcg_vm
= read_fp_dreg(s
, rm
);
4045 if (signal_all_nans
) {
4046 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4048 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4050 tcg_temp_free_i64(tcg_vn
);
4051 tcg_temp_free_i64(tcg_vm
);
4053 TCGv_i32 tcg_vn
, tcg_vm
;
4055 tcg_vn
= read_fp_sreg(s
, rn
);
4056 if (cmp_with_zero
) {
4057 tcg_vm
= tcg_const_i32(0);
4059 tcg_vm
= read_fp_sreg(s
, rm
);
4061 if (signal_all_nans
) {
4062 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4064 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4066 tcg_temp_free_i32(tcg_vn
);
4067 tcg_temp_free_i32(tcg_vm
);
4070 tcg_temp_free_ptr(fpst
);
4072 gen_set_nzcv(tcg_flags
);
4074 tcg_temp_free_i64(tcg_flags
);
4077 /* C3.6.22 Floating point compare
4078 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
4079 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4080 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
4081 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4083 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
4085 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
4087 mos
= extract32(insn
, 29, 3);
4088 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4089 rm
= extract32(insn
, 16, 5);
4090 op
= extract32(insn
, 14, 2);
4091 rn
= extract32(insn
, 5, 5);
4092 opc
= extract32(insn
, 3, 2);
4093 op2r
= extract32(insn
, 0, 3);
4095 if (mos
|| op
|| op2r
|| type
> 1) {
4096 unallocated_encoding(s
);
4100 if (!fp_access_check(s
)) {
4104 handle_fp_compare(s
, type
, rn
, rm
, opc
& 1, opc
& 2);
4107 /* C3.6.23 Floating point conditional compare
4108 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4109 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4110 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
4111 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4113 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
4115 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
4117 TCGLabel
*label_continue
= NULL
;
4119 mos
= extract32(insn
, 29, 3);
4120 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4121 rm
= extract32(insn
, 16, 5);
4122 cond
= extract32(insn
, 12, 4);
4123 rn
= extract32(insn
, 5, 5);
4124 op
= extract32(insn
, 4, 1);
4125 nzcv
= extract32(insn
, 0, 4);
4127 if (mos
|| type
> 1) {
4128 unallocated_encoding(s
);
4132 if (!fp_access_check(s
)) {
4136 if (cond
< 0x0e) { /* not always */
4137 TCGLabel
*label_match
= gen_new_label();
4138 label_continue
= gen_new_label();
4139 arm_gen_test_cc(cond
, label_match
);
4141 tcg_flags
= tcg_const_i64(nzcv
<< 28);
4142 gen_set_nzcv(tcg_flags
);
4143 tcg_temp_free_i64(tcg_flags
);
4144 tcg_gen_br(label_continue
);
4145 gen_set_label(label_match
);
4148 handle_fp_compare(s
, type
, rn
, rm
, false, op
);
4151 gen_set_label(label_continue
);
4155 /* copy src FP register to dst FP register; type specifies single or double */
4156 static void gen_mov_fp2fp(DisasContext
*s
, int type
, int dst
, int src
)
4159 TCGv_i64 v
= read_fp_dreg(s
, src
);
4160 write_fp_dreg(s
, dst
, v
);
4161 tcg_temp_free_i64(v
);
4163 TCGv_i32 v
= read_fp_sreg(s
, src
);
4164 write_fp_sreg(s
, dst
, v
);
4165 tcg_temp_free_i32(v
);
4169 /* C3.6.24 Floating point conditional select
4170 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4171 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4172 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
4173 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4175 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
4177 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
4178 TCGLabel
*label_continue
= NULL
;
4180 mos
= extract32(insn
, 29, 3);
4181 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4182 rm
= extract32(insn
, 16, 5);
4183 cond
= extract32(insn
, 12, 4);
4184 rn
= extract32(insn
, 5, 5);
4185 rd
= extract32(insn
, 0, 5);
4187 if (mos
|| type
> 1) {
4188 unallocated_encoding(s
);
4192 if (!fp_access_check(s
)) {
4196 if (cond
< 0x0e) { /* not always */
4197 TCGLabel
*label_match
= gen_new_label();
4198 label_continue
= gen_new_label();
4199 arm_gen_test_cc(cond
, label_match
);
4201 gen_mov_fp2fp(s
, type
, rd
, rm
);
4202 tcg_gen_br(label_continue
);
4203 gen_set_label(label_match
);
4206 gen_mov_fp2fp(s
, type
, rd
, rn
);
4208 if (cond
< 0x0e) { /* continue */
4209 gen_set_label(label_continue
);
4213 /* C3.6.25 Floating-point data-processing (1 source) - single precision */
4214 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
4220 fpst
= get_fpstatus_ptr();
4221 tcg_op
= read_fp_sreg(s
, rn
);
4222 tcg_res
= tcg_temp_new_i32();
4225 case 0x0: /* FMOV */
4226 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4228 case 0x1: /* FABS */
4229 gen_helper_vfp_abss(tcg_res
, tcg_op
);
4231 case 0x2: /* FNEG */
4232 gen_helper_vfp_negs(tcg_res
, tcg_op
);
4234 case 0x3: /* FSQRT */
4235 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
4237 case 0x8: /* FRINTN */
4238 case 0x9: /* FRINTP */
4239 case 0xa: /* FRINTM */
4240 case 0xb: /* FRINTZ */
4241 case 0xc: /* FRINTA */
4243 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4245 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4246 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4248 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4249 tcg_temp_free_i32(tcg_rmode
);
4252 case 0xe: /* FRINTX */
4253 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
4255 case 0xf: /* FRINTI */
4256 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4262 write_fp_sreg(s
, rd
, tcg_res
);
4264 tcg_temp_free_ptr(fpst
);
4265 tcg_temp_free_i32(tcg_op
);
4266 tcg_temp_free_i32(tcg_res
);
4269 /* C3.6.25 Floating-point data-processing (1 source) - double precision */
4270 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
4276 fpst
= get_fpstatus_ptr();
4277 tcg_op
= read_fp_dreg(s
, rn
);
4278 tcg_res
= tcg_temp_new_i64();
4281 case 0x0: /* FMOV */
4282 tcg_gen_mov_i64(tcg_res
, tcg_op
);
4284 case 0x1: /* FABS */
4285 gen_helper_vfp_absd(tcg_res
, tcg_op
);
4287 case 0x2: /* FNEG */
4288 gen_helper_vfp_negd(tcg_res
, tcg_op
);
4290 case 0x3: /* FSQRT */
4291 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
4293 case 0x8: /* FRINTN */
4294 case 0x9: /* FRINTP */
4295 case 0xa: /* FRINTM */
4296 case 0xb: /* FRINTZ */
4297 case 0xc: /* FRINTA */
4299 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4301 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4302 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4304 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4305 tcg_temp_free_i32(tcg_rmode
);
4308 case 0xe: /* FRINTX */
4309 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
4311 case 0xf: /* FRINTI */
4312 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4318 write_fp_dreg(s
, rd
, tcg_res
);
4320 tcg_temp_free_ptr(fpst
);
4321 tcg_temp_free_i64(tcg_op
);
4322 tcg_temp_free_i64(tcg_res
);
4325 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
4326 int rd
, int rn
, int dtype
, int ntype
)
4331 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4333 /* Single to double */
4334 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4335 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
4336 write_fp_dreg(s
, rd
, tcg_rd
);
4337 tcg_temp_free_i64(tcg_rd
);
4339 /* Single to half */
4340 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4341 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4342 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4343 write_fp_sreg(s
, rd
, tcg_rd
);
4344 tcg_temp_free_i32(tcg_rd
);
4346 tcg_temp_free_i32(tcg_rn
);
4351 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
4352 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4354 /* Double to single */
4355 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
4357 /* Double to half */
4358 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4359 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4361 write_fp_sreg(s
, rd
, tcg_rd
);
4362 tcg_temp_free_i32(tcg_rd
);
4363 tcg_temp_free_i64(tcg_rn
);
4368 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4369 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
4371 /* Half to single */
4372 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4373 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, cpu_env
);
4374 write_fp_sreg(s
, rd
, tcg_rd
);
4375 tcg_temp_free_i32(tcg_rd
);
4377 /* Half to double */
4378 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4379 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, cpu_env
);
4380 write_fp_dreg(s
, rd
, tcg_rd
);
4381 tcg_temp_free_i64(tcg_rd
);
4383 tcg_temp_free_i32(tcg_rn
);
4391 /* C3.6.25 Floating point data-processing (1 source)
4392 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
4393 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4394 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
4395 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4397 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
4399 int type
= extract32(insn
, 22, 2);
4400 int opcode
= extract32(insn
, 15, 6);
4401 int rn
= extract32(insn
, 5, 5);
4402 int rd
= extract32(insn
, 0, 5);
4405 case 0x4: case 0x5: case 0x7:
4407 /* FCVT between half, single and double precision */
4408 int dtype
= extract32(opcode
, 0, 2);
4409 if (type
== 2 || dtype
== type
) {
4410 unallocated_encoding(s
);
4413 if (!fp_access_check(s
)) {
4417 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
4423 /* 32-to-32 and 64-to-64 ops */
4426 if (!fp_access_check(s
)) {
4430 handle_fp_1src_single(s
, opcode
, rd
, rn
);
4433 if (!fp_access_check(s
)) {
4437 handle_fp_1src_double(s
, opcode
, rd
, rn
);
4440 unallocated_encoding(s
);
4444 unallocated_encoding(s
);
4449 /* C3.6.26 Floating-point data-processing (2 source) - single precision */
4450 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
4451 int rd
, int rn
, int rm
)
4458 tcg_res
= tcg_temp_new_i32();
4459 fpst
= get_fpstatus_ptr();
4460 tcg_op1
= read_fp_sreg(s
, rn
);
4461 tcg_op2
= read_fp_sreg(s
, rm
);
4464 case 0x0: /* FMUL */
4465 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4467 case 0x1: /* FDIV */
4468 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4470 case 0x2: /* FADD */
4471 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4473 case 0x3: /* FSUB */
4474 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4476 case 0x4: /* FMAX */
4477 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4479 case 0x5: /* FMIN */
4480 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4482 case 0x6: /* FMAXNM */
4483 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4485 case 0x7: /* FMINNM */
4486 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4488 case 0x8: /* FNMUL */
4489 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4490 gen_helper_vfp_negs(tcg_res
, tcg_res
);
4494 write_fp_sreg(s
, rd
, tcg_res
);
4496 tcg_temp_free_ptr(fpst
);
4497 tcg_temp_free_i32(tcg_op1
);
4498 tcg_temp_free_i32(tcg_op2
);
4499 tcg_temp_free_i32(tcg_res
);
4502 /* C3.6.26 Floating-point data-processing (2 source) - double precision */
4503 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
4504 int rd
, int rn
, int rm
)
4511 tcg_res
= tcg_temp_new_i64();
4512 fpst
= get_fpstatus_ptr();
4513 tcg_op1
= read_fp_dreg(s
, rn
);
4514 tcg_op2
= read_fp_dreg(s
, rm
);
4517 case 0x0: /* FMUL */
4518 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4520 case 0x1: /* FDIV */
4521 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4523 case 0x2: /* FADD */
4524 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4526 case 0x3: /* FSUB */
4527 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4529 case 0x4: /* FMAX */
4530 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4532 case 0x5: /* FMIN */
4533 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4535 case 0x6: /* FMAXNM */
4536 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4538 case 0x7: /* FMINNM */
4539 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4541 case 0x8: /* FNMUL */
4542 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4543 gen_helper_vfp_negd(tcg_res
, tcg_res
);
4547 write_fp_dreg(s
, rd
, tcg_res
);
4549 tcg_temp_free_ptr(fpst
);
4550 tcg_temp_free_i64(tcg_op1
);
4551 tcg_temp_free_i64(tcg_op2
);
4552 tcg_temp_free_i64(tcg_res
);
4555 /* C3.6.26 Floating point data-processing (2 source)
4556 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4557 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4558 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
4559 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4561 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
4563 int type
= extract32(insn
, 22, 2);
4564 int rd
= extract32(insn
, 0, 5);
4565 int rn
= extract32(insn
, 5, 5);
4566 int rm
= extract32(insn
, 16, 5);
4567 int opcode
= extract32(insn
, 12, 4);
4570 unallocated_encoding(s
);
4576 if (!fp_access_check(s
)) {
4579 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
4582 if (!fp_access_check(s
)) {
4585 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
4588 unallocated_encoding(s
);
4592 /* C3.6.27 Floating-point data-processing (3 source) - single precision */
4593 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
4594 int rd
, int rn
, int rm
, int ra
)
4596 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
4597 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4598 TCGv_ptr fpst
= get_fpstatus_ptr();
4600 tcg_op1
= read_fp_sreg(s
, rn
);
4601 tcg_op2
= read_fp_sreg(s
, rm
);
4602 tcg_op3
= read_fp_sreg(s
, ra
);
4604 /* These are fused multiply-add, and must be done as one
4605 * floating point operation with no rounding between the
4606 * multiplication and addition steps.
4607 * NB that doing the negations here as separate steps is
4608 * correct : an input NaN should come out with its sign bit
4609 * flipped if it is a negated-input.
4612 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
4616 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
4619 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4621 write_fp_sreg(s
, rd
, tcg_res
);
4623 tcg_temp_free_ptr(fpst
);
4624 tcg_temp_free_i32(tcg_op1
);
4625 tcg_temp_free_i32(tcg_op2
);
4626 tcg_temp_free_i32(tcg_op3
);
4627 tcg_temp_free_i32(tcg_res
);
4630 /* C3.6.27 Floating-point data-processing (3 source) - double precision */
4631 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
4632 int rd
, int rn
, int rm
, int ra
)
4634 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
4635 TCGv_i64 tcg_res
= tcg_temp_new_i64();
4636 TCGv_ptr fpst
= get_fpstatus_ptr();
4638 tcg_op1
= read_fp_dreg(s
, rn
);
4639 tcg_op2
= read_fp_dreg(s
, rm
);
4640 tcg_op3
= read_fp_dreg(s
, ra
);
4642 /* These are fused multiply-add, and must be done as one
4643 * floating point operation with no rounding between the
4644 * multiplication and addition steps.
4645 * NB that doing the negations here as separate steps is
4646 * correct : an input NaN should come out with its sign bit
4647 * flipped if it is a negated-input.
4650 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
4654 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
4657 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4659 write_fp_dreg(s
, rd
, tcg_res
);
4661 tcg_temp_free_ptr(fpst
);
4662 tcg_temp_free_i64(tcg_op1
);
4663 tcg_temp_free_i64(tcg_op2
);
4664 tcg_temp_free_i64(tcg_op3
);
4665 tcg_temp_free_i64(tcg_res
);
4668 /* C3.6.27 Floating point data-processing (3 source)
4669 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
4670 * +---+---+---+-----------+------+----+------+----+------+------+------+
4671 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
4672 * +---+---+---+-----------+------+----+------+----+------+------+------+
4674 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
4676 int type
= extract32(insn
, 22, 2);
4677 int rd
= extract32(insn
, 0, 5);
4678 int rn
= extract32(insn
, 5, 5);
4679 int ra
= extract32(insn
, 10, 5);
4680 int rm
= extract32(insn
, 16, 5);
4681 bool o0
= extract32(insn
, 15, 1);
4682 bool o1
= extract32(insn
, 21, 1);
4686 if (!fp_access_check(s
)) {
4689 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4692 if (!fp_access_check(s
)) {
4695 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4698 unallocated_encoding(s
);
4702 /* C3.6.28 Floating point immediate
4703 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
4704 * +---+---+---+-----------+------+---+------------+-------+------+------+
4705 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
4706 * +---+---+---+-----------+------+---+------------+-------+------+------+
4708 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
4710 int rd
= extract32(insn
, 0, 5);
4711 int imm8
= extract32(insn
, 13, 8);
4712 int is_double
= extract32(insn
, 22, 2);
4716 if (is_double
> 1) {
4717 unallocated_encoding(s
);
4721 if (!fp_access_check(s
)) {
4725 /* The imm8 encodes the sign bit, enough bits to represent
4726 * an exponent in the range 01....1xx to 10....0xx,
4727 * and the most significant 4 bits of the mantissa; see
4728 * VFPExpandImm() in the v8 ARM ARM.
4731 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4732 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
4733 extract32(imm8
, 0, 6);
4736 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4737 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
4738 (extract32(imm8
, 0, 6) << 3);
4742 tcg_res
= tcg_const_i64(imm
);
4743 write_fp_dreg(s
, rd
, tcg_res
);
4744 tcg_temp_free_i64(tcg_res
);
4747 /* Handle floating point <=> fixed point conversions. Note that we can
4748 * also deal with fp <=> integer conversions as a special case (scale == 64)
4749 * OPTME: consider handling that special case specially or at least skipping
4750 * the call to scalbn in the helpers for zero shifts.
4752 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
4753 bool itof
, int rmode
, int scale
, int sf
, int type
)
4755 bool is_signed
= !(opcode
& 1);
4756 bool is_double
= type
;
4757 TCGv_ptr tcg_fpstatus
;
4760 tcg_fpstatus
= get_fpstatus_ptr();
4762 tcg_shift
= tcg_const_i32(64 - scale
);
4765 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
4767 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
4770 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
4772 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
4775 tcg_int
= tcg_extend
;
4779 TCGv_i64 tcg_double
= tcg_temp_new_i64();
4781 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
4782 tcg_shift
, tcg_fpstatus
);
4784 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
4785 tcg_shift
, tcg_fpstatus
);
4787 write_fp_dreg(s
, rd
, tcg_double
);
4788 tcg_temp_free_i64(tcg_double
);
4790 TCGv_i32 tcg_single
= tcg_temp_new_i32();
4792 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
4793 tcg_shift
, tcg_fpstatus
);
4795 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
4796 tcg_shift
, tcg_fpstatus
);
4798 write_fp_sreg(s
, rd
, tcg_single
);
4799 tcg_temp_free_i32(tcg_single
);
4802 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
4805 if (extract32(opcode
, 2, 1)) {
4806 /* There are too many rounding modes to all fit into rmode,
4807 * so FCVTA[US] is a special case.
4809 rmode
= FPROUNDING_TIEAWAY
;
4812 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
4814 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4817 TCGv_i64 tcg_double
= read_fp_dreg(s
, rn
);
4820 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
4821 tcg_shift
, tcg_fpstatus
);
4823 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
4824 tcg_shift
, tcg_fpstatus
);
4828 gen_helper_vfp_tould(tcg_int
, tcg_double
,
4829 tcg_shift
, tcg_fpstatus
);
4831 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
4832 tcg_shift
, tcg_fpstatus
);
4835 tcg_temp_free_i64(tcg_double
);
4837 TCGv_i32 tcg_single
= read_fp_sreg(s
, rn
);
4840 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
4841 tcg_shift
, tcg_fpstatus
);
4843 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
4844 tcg_shift
, tcg_fpstatus
);
4847 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
4849 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
4850 tcg_shift
, tcg_fpstatus
);
4852 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
4853 tcg_shift
, tcg_fpstatus
);
4855 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
4856 tcg_temp_free_i32(tcg_dest
);
4858 tcg_temp_free_i32(tcg_single
);
4861 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4862 tcg_temp_free_i32(tcg_rmode
);
4865 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
4869 tcg_temp_free_ptr(tcg_fpstatus
);
4870 tcg_temp_free_i32(tcg_shift
);
4873 /* C3.6.29 Floating point <-> fixed point conversions
4874 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4875 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4876 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
4877 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4879 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
4881 int rd
= extract32(insn
, 0, 5);
4882 int rn
= extract32(insn
, 5, 5);
4883 int scale
= extract32(insn
, 10, 6);
4884 int opcode
= extract32(insn
, 16, 3);
4885 int rmode
= extract32(insn
, 19, 2);
4886 int type
= extract32(insn
, 22, 2);
4887 bool sbit
= extract32(insn
, 29, 1);
4888 bool sf
= extract32(insn
, 31, 1);
4891 if (sbit
|| (type
> 1)
4892 || (!sf
&& scale
< 32)) {
4893 unallocated_encoding(s
);
4897 switch ((rmode
<< 3) | opcode
) {
4898 case 0x2: /* SCVTF */
4899 case 0x3: /* UCVTF */
4902 case 0x18: /* FCVTZS */
4903 case 0x19: /* FCVTZU */
4907 unallocated_encoding(s
);
4911 if (!fp_access_check(s
)) {
4915 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
4918 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
4920 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
4921 * without conversion.
4925 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4931 TCGv_i64 tmp
= tcg_temp_new_i64();
4932 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
4933 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
4934 tcg_gen_movi_i64(tmp
, 0);
4935 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4936 tcg_temp_free_i64(tmp
);
4942 TCGv_i64 tmp
= tcg_const_i64(0);
4943 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
4944 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4945 tcg_temp_free_i64(tmp
);
4949 /* 64 bit to top half. */
4950 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4954 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4959 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
4963 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
4966 /* 64 bits from top half */
4967 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
4973 /* C3.6.30 Floating point <-> integer conversions
4974 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4975 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4976 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
4977 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4979 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
4981 int rd
= extract32(insn
, 0, 5);
4982 int rn
= extract32(insn
, 5, 5);
4983 int opcode
= extract32(insn
, 16, 3);
4984 int rmode
= extract32(insn
, 19, 2);
4985 int type
= extract32(insn
, 22, 2);
4986 bool sbit
= extract32(insn
, 29, 1);
4987 bool sf
= extract32(insn
, 31, 1);
4990 unallocated_encoding(s
);
4996 bool itof
= opcode
& 1;
4999 unallocated_encoding(s
);
5003 switch (sf
<< 3 | type
<< 1 | rmode
) {
5004 case 0x0: /* 32 bit */
5005 case 0xa: /* 64 bit */
5006 case 0xd: /* 64 bit to top half of quad */
5009 /* all other sf/type/rmode combinations are invalid */
5010 unallocated_encoding(s
);
5014 if (!fp_access_check(s
)) {
5017 handle_fmov(s
, rd
, rn
, type
, itof
);
5019 /* actual FP conversions */
5020 bool itof
= extract32(opcode
, 1, 1);
5022 if (type
> 1 || (rmode
!= 0 && opcode
> 1)) {
5023 unallocated_encoding(s
);
5027 if (!fp_access_check(s
)) {
5030 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
5034 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
5035 * 31 30 29 28 25 24 0
5036 * +---+---+---+---------+-----------------------------+
5037 * | | 0 | | 1 1 1 1 | |
5038 * +---+---+---+---------+-----------------------------+
5040 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
5042 if (extract32(insn
, 24, 1)) {
5043 /* Floating point data-processing (3 source) */
5044 disas_fp_3src(s
, insn
);
5045 } else if (extract32(insn
, 21, 1) == 0) {
5046 /* Floating point to fixed point conversions */
5047 disas_fp_fixed_conv(s
, insn
);
5049 switch (extract32(insn
, 10, 2)) {
5051 /* Floating point conditional compare */
5052 disas_fp_ccomp(s
, insn
);
5055 /* Floating point data-processing (2 source) */
5056 disas_fp_2src(s
, insn
);
5059 /* Floating point conditional select */
5060 disas_fp_csel(s
, insn
);
5063 switch (ctz32(extract32(insn
, 12, 4))) {
5064 case 0: /* [15:12] == xxx1 */
5065 /* Floating point immediate */
5066 disas_fp_imm(s
, insn
);
5068 case 1: /* [15:12] == xx10 */
5069 /* Floating point compare */
5070 disas_fp_compare(s
, insn
);
5072 case 2: /* [15:12] == x100 */
5073 /* Floating point data-processing (1 source) */
5074 disas_fp_1src(s
, insn
);
5076 case 3: /* [15:12] == 1000 */
5077 unallocated_encoding(s
);
5079 default: /* [15:12] == 0000 */
5080 /* Floating point <-> integer conversions */
5081 disas_fp_int_conv(s
, insn
);
5089 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
5092 /* Extract 64 bits from the middle of two concatenated 64 bit
5093 * vector register slices left:right. The extracted bits start
5094 * at 'pos' bits into the right (least significant) side.
5095 * We return the result in tcg_right, and guarantee not to
5098 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5099 assert(pos
> 0 && pos
< 64);
5101 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
5102 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
5103 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
5105 tcg_temp_free_i64(tcg_tmp
);
5109 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
5110 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5111 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
5112 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5114 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
5116 int is_q
= extract32(insn
, 30, 1);
5117 int op2
= extract32(insn
, 22, 2);
5118 int imm4
= extract32(insn
, 11, 4);
5119 int rm
= extract32(insn
, 16, 5);
5120 int rn
= extract32(insn
, 5, 5);
5121 int rd
= extract32(insn
, 0, 5);
5122 int pos
= imm4
<< 3;
5123 TCGv_i64 tcg_resl
, tcg_resh
;
5125 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
5126 unallocated_encoding(s
);
5130 if (!fp_access_check(s
)) {
5134 tcg_resh
= tcg_temp_new_i64();
5135 tcg_resl
= tcg_temp_new_i64();
5137 /* Vd gets bits starting at pos bits into Vm:Vn. This is
5138 * either extracting 128 bits from a 128:128 concatenation, or
5139 * extracting 64 bits from a 64:64 concatenation.
5142 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
5144 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
5145 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5147 tcg_gen_movi_i64(tcg_resh
, 0);
5154 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
5155 EltPosns
*elt
= eltposns
;
5162 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
5164 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
5167 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5168 tcg_hh
= tcg_temp_new_i64();
5169 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
5170 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
5171 tcg_temp_free_i64(tcg_hh
);
5175 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5176 tcg_temp_free_i64(tcg_resl
);
5177 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5178 tcg_temp_free_i64(tcg_resh
);
5182 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
5183 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5184 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
5185 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5187 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
5189 int op2
= extract32(insn
, 22, 2);
5190 int is_q
= extract32(insn
, 30, 1);
5191 int rm
= extract32(insn
, 16, 5);
5192 int rn
= extract32(insn
, 5, 5);
5193 int rd
= extract32(insn
, 0, 5);
5194 int is_tblx
= extract32(insn
, 12, 1);
5195 int len
= extract32(insn
, 13, 2);
5196 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
5197 TCGv_i32 tcg_regno
, tcg_numregs
;
5200 unallocated_encoding(s
);
5204 if (!fp_access_check(s
)) {
5208 /* This does a table lookup: for every byte element in the input
5209 * we index into a table formed from up to four vector registers,
5210 * and then the output is the result of the lookups. Our helper
5211 * function does the lookup operation for a single 64 bit part of
5214 tcg_resl
= tcg_temp_new_i64();
5215 tcg_resh
= tcg_temp_new_i64();
5218 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5220 tcg_gen_movi_i64(tcg_resl
, 0);
5222 if (is_tblx
&& is_q
) {
5223 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5225 tcg_gen_movi_i64(tcg_resh
, 0);
5228 tcg_idx
= tcg_temp_new_i64();
5229 tcg_regno
= tcg_const_i32(rn
);
5230 tcg_numregs
= tcg_const_i32(len
+ 1);
5231 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
5232 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
5233 tcg_regno
, tcg_numregs
);
5235 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
5236 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
5237 tcg_regno
, tcg_numregs
);
5239 tcg_temp_free_i64(tcg_idx
);
5240 tcg_temp_free_i32(tcg_regno
);
5241 tcg_temp_free_i32(tcg_numregs
);
5243 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5244 tcg_temp_free_i64(tcg_resl
);
5245 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5246 tcg_temp_free_i64(tcg_resh
);
5249 /* C3.6.3 ZIP/UZP/TRN
5250 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
5251 * +---+---+-------------+------+---+------+---+------------------+------+
5252 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
5253 * +---+---+-------------+------+---+------+---+------------------+------+
5255 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
5257 int rd
= extract32(insn
, 0, 5);
5258 int rn
= extract32(insn
, 5, 5);
5259 int rm
= extract32(insn
, 16, 5);
5260 int size
= extract32(insn
, 22, 2);
5261 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
5262 * bit 2 indicates 1 vs 2 variant of the insn.
5264 int opcode
= extract32(insn
, 12, 2);
5265 bool part
= extract32(insn
, 14, 1);
5266 bool is_q
= extract32(insn
, 30, 1);
5267 int esize
= 8 << size
;
5269 int datasize
= is_q
? 128 : 64;
5270 int elements
= datasize
/ esize
;
5271 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
5273 if (opcode
== 0 || (size
== 3 && !is_q
)) {
5274 unallocated_encoding(s
);
5278 if (!fp_access_check(s
)) {
5282 tcg_resl
= tcg_const_i64(0);
5283 tcg_resh
= tcg_const_i64(0);
5284 tcg_res
= tcg_temp_new_i64();
5286 for (i
= 0; i
< elements
; i
++) {
5288 case 1: /* UZP1/2 */
5290 int midpoint
= elements
/ 2;
5292 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
5294 read_vec_element(s
, tcg_res
, rm
,
5295 2 * (i
- midpoint
) + part
, size
);
5299 case 2: /* TRN1/2 */
5301 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
5303 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
5306 case 3: /* ZIP1/2 */
5308 int base
= part
* elements
/ 2;
5310 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
5312 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
5317 g_assert_not_reached();
5322 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
5323 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
5325 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
5326 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
5330 tcg_temp_free_i64(tcg_res
);
5332 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5333 tcg_temp_free_i64(tcg_resl
);
5334 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5335 tcg_temp_free_i64(tcg_resh
);
5338 static void do_minmaxop(DisasContext
*s
, TCGv_i32 tcg_elt1
, TCGv_i32 tcg_elt2
,
5339 int opc
, bool is_min
, TCGv_ptr fpst
)
5341 /* Helper function for disas_simd_across_lanes: do a single precision
5342 * min/max operation on the specified two inputs,
5343 * and return the result in tcg_elt1.
5347 gen_helper_vfp_minnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5349 gen_helper_vfp_maxnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5354 gen_helper_vfp_mins(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5356 gen_helper_vfp_maxs(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5361 /* C3.6.4 AdvSIMD across lanes
5362 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5363 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5364 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5365 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5367 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
5369 int rd
= extract32(insn
, 0, 5);
5370 int rn
= extract32(insn
, 5, 5);
5371 int size
= extract32(insn
, 22, 2);
5372 int opcode
= extract32(insn
, 12, 5);
5373 bool is_q
= extract32(insn
, 30, 1);
5374 bool is_u
= extract32(insn
, 29, 1);
5376 bool is_min
= false;
5380 TCGv_i64 tcg_res
, tcg_elt
;
5383 case 0x1b: /* ADDV */
5385 unallocated_encoding(s
);
5389 case 0x3: /* SADDLV, UADDLV */
5390 case 0xa: /* SMAXV, UMAXV */
5391 case 0x1a: /* SMINV, UMINV */
5392 if (size
== 3 || (size
== 2 && !is_q
)) {
5393 unallocated_encoding(s
);
5397 case 0xc: /* FMAXNMV, FMINNMV */
5398 case 0xf: /* FMAXV, FMINV */
5399 if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
5400 unallocated_encoding(s
);
5403 /* Bit 1 of size field encodes min vs max, and actual size is always
5404 * 32 bits: adjust the size variable so following code can rely on it
5406 is_min
= extract32(size
, 1, 1);
5411 unallocated_encoding(s
);
5415 if (!fp_access_check(s
)) {
5420 elements
= (is_q
? 128 : 64) / esize
;
5422 tcg_res
= tcg_temp_new_i64();
5423 tcg_elt
= tcg_temp_new_i64();
5425 /* These instructions operate across all lanes of a vector
5426 * to produce a single result. We can guarantee that a 64
5427 * bit intermediate is sufficient:
5428 * + for [US]ADDLV the maximum element size is 32 bits, and
5429 * the result type is 64 bits
5430 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
5431 * same as the element size, which is 32 bits at most
5432 * For the integer operations we can choose to work at 64
5433 * or 32 bits and truncate at the end; for simplicity
5434 * we use 64 bits always. The floating point
5435 * ops do require 32 bit intermediates, though.
5438 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
5440 for (i
= 1; i
< elements
; i
++) {
5441 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
5444 case 0x03: /* SADDLV / UADDLV */
5445 case 0x1b: /* ADDV */
5446 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
5448 case 0x0a: /* SMAXV / UMAXV */
5449 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
5451 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5453 case 0x1a: /* SMINV / UMINV */
5454 tcg_gen_movcond_i64(is_u
? TCG_COND_LEU
: TCG_COND_LE
,
5456 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5460 g_assert_not_reached();
5465 /* Floating point ops which work on 32 bit (single) intermediates.
5466 * Note that correct NaN propagation requires that we do these
5467 * operations in exactly the order specified by the pseudocode.
5469 TCGv_i32 tcg_elt1
= tcg_temp_new_i32();
5470 TCGv_i32 tcg_elt2
= tcg_temp_new_i32();
5471 TCGv_i32 tcg_elt3
= tcg_temp_new_i32();
5472 TCGv_ptr fpst
= get_fpstatus_ptr();
5474 assert(esize
== 32);
5475 assert(elements
== 4);
5477 read_vec_element(s
, tcg_elt
, rn
, 0, MO_32
);
5478 tcg_gen_trunc_i64_i32(tcg_elt1
, tcg_elt
);
5479 read_vec_element(s
, tcg_elt
, rn
, 1, MO_32
);
5480 tcg_gen_trunc_i64_i32(tcg_elt2
, tcg_elt
);
5482 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5484 read_vec_element(s
, tcg_elt
, rn
, 2, MO_32
);
5485 tcg_gen_trunc_i64_i32(tcg_elt2
, tcg_elt
);
5486 read_vec_element(s
, tcg_elt
, rn
, 3, MO_32
);
5487 tcg_gen_trunc_i64_i32(tcg_elt3
, tcg_elt
);
5489 do_minmaxop(s
, tcg_elt2
, tcg_elt3
, opcode
, is_min
, fpst
);
5491 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5493 tcg_gen_extu_i32_i64(tcg_res
, tcg_elt1
);
5494 tcg_temp_free_i32(tcg_elt1
);
5495 tcg_temp_free_i32(tcg_elt2
);
5496 tcg_temp_free_i32(tcg_elt3
);
5497 tcg_temp_free_ptr(fpst
);
5500 tcg_temp_free_i64(tcg_elt
);
5502 /* Now truncate the result to the width required for the final output */
5503 if (opcode
== 0x03) {
5504 /* SADDLV, UADDLV: result is 2*esize */
5510 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
5513 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
5516 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
5521 g_assert_not_reached();
5524 write_fp_dreg(s
, rd
, tcg_res
);
5525 tcg_temp_free_i64(tcg_res
);
5528 /* C6.3.31 DUP (Element, Vector)
5530 * 31 30 29 21 20 16 15 10 9 5 4 0
5531 * +---+---+-------------------+--------+-------------+------+------+
5532 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5533 * +---+---+-------------------+--------+-------------+------+------+
5535 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5537 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
5540 int size
= ctz32(imm5
);
5541 int esize
= 8 << size
;
5542 int elements
= (is_q
? 128 : 64) / esize
;
5546 if (size
> 3 || (size
== 3 && !is_q
)) {
5547 unallocated_encoding(s
);
5551 if (!fp_access_check(s
)) {
5555 index
= imm5
>> (size
+ 1);
5557 tmp
= tcg_temp_new_i64();
5558 read_vec_element(s
, tmp
, rn
, index
, size
);
5560 for (i
= 0; i
< elements
; i
++) {
5561 write_vec_element(s
, tmp
, rd
, i
, size
);
5565 clear_vec_high(s
, rd
);
5568 tcg_temp_free_i64(tmp
);
5571 /* C6.3.31 DUP (element, scalar)
5572 * 31 21 20 16 15 10 9 5 4 0
5573 * +-----------------------+--------+-------------+------+------+
5574 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5575 * +-----------------------+--------+-------------+------+------+
5577 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
5580 int size
= ctz32(imm5
);
5585 unallocated_encoding(s
);
5589 if (!fp_access_check(s
)) {
5593 index
= imm5
>> (size
+ 1);
5595 /* This instruction just extracts the specified element and
5596 * zero-extends it into the bottom of the destination register.
5598 tmp
= tcg_temp_new_i64();
5599 read_vec_element(s
, tmp
, rn
, index
, size
);
5600 write_fp_dreg(s
, rd
, tmp
);
5601 tcg_temp_free_i64(tmp
);
5604 /* C6.3.32 DUP (General)
5606 * 31 30 29 21 20 16 15 10 9 5 4 0
5607 * +---+---+-------------------+--------+-------------+------+------+
5608 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
5609 * +---+---+-------------------+--------+-------------+------+------+
5611 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5613 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
5616 int size
= ctz32(imm5
);
5617 int esize
= 8 << size
;
5618 int elements
= (is_q
? 128 : 64)/esize
;
5621 if (size
> 3 || ((size
== 3) && !is_q
)) {
5622 unallocated_encoding(s
);
5626 if (!fp_access_check(s
)) {
5630 for (i
= 0; i
< elements
; i
++) {
5631 write_vec_element(s
, cpu_reg(s
, rn
), rd
, i
, size
);
5634 clear_vec_high(s
, rd
);
5638 /* C6.3.150 INS (Element)
5640 * 31 21 20 16 15 14 11 10 9 5 4 0
5641 * +-----------------------+--------+------------+---+------+------+
5642 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5643 * +-----------------------+--------+------------+---+------+------+
5645 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5646 * index: encoded in imm5<4:size+1>
5648 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
5651 int size
= ctz32(imm5
);
5652 int src_index
, dst_index
;
5656 unallocated_encoding(s
);
5660 if (!fp_access_check(s
)) {
5664 dst_index
= extract32(imm5
, 1+size
, 5);
5665 src_index
= extract32(imm4
, size
, 4);
5667 tmp
= tcg_temp_new_i64();
5669 read_vec_element(s
, tmp
, rn
, src_index
, size
);
5670 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
5672 tcg_temp_free_i64(tmp
);
5676 /* C6.3.151 INS (General)
5678 * 31 21 20 16 15 10 9 5 4 0
5679 * +-----------------------+--------+-------------+------+------+
5680 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
5681 * +-----------------------+--------+-------------+------+------+
5683 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5684 * index: encoded in imm5<4:size+1>
5686 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
5688 int size
= ctz32(imm5
);
5692 unallocated_encoding(s
);
5696 if (!fp_access_check(s
)) {
5700 idx
= extract32(imm5
, 1 + size
, 4 - size
);
5701 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
5705 * C6.3.321 UMOV (General)
5706 * C6.3.237 SMOV (General)
5708 * 31 30 29 21 20 16 15 12 10 9 5 4 0
5709 * +---+---+-------------------+--------+-------------+------+------+
5710 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
5711 * +---+---+-------------------+--------+-------------+------+------+
5713 * U: unsigned when set
5714 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5716 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
5717 int rn
, int rd
, int imm5
)
5719 int size
= ctz32(imm5
);
5723 /* Check for UnallocatedEncodings */
5725 if (size
> 2 || (size
== 2 && !is_q
)) {
5726 unallocated_encoding(s
);
5731 || (size
< 3 && is_q
)
5732 || (size
== 3 && !is_q
)) {
5733 unallocated_encoding(s
);
5738 if (!fp_access_check(s
)) {
5742 element
= extract32(imm5
, 1+size
, 4);
5744 tcg_rd
= cpu_reg(s
, rd
);
5745 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
5746 if (is_signed
&& !is_q
) {
5747 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5751 /* C3.6.5 AdvSIMD copy
5752 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5753 * +---+---+----+-----------------+------+---+------+---+------+------+
5754 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5755 * +---+---+----+-----------------+------+---+------+---+------+------+
5757 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
5759 int rd
= extract32(insn
, 0, 5);
5760 int rn
= extract32(insn
, 5, 5);
5761 int imm4
= extract32(insn
, 11, 4);
5762 int op
= extract32(insn
, 29, 1);
5763 int is_q
= extract32(insn
, 30, 1);
5764 int imm5
= extract32(insn
, 16, 5);
5769 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
5771 unallocated_encoding(s
);
5776 /* DUP (element - vector) */
5777 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
5781 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
5786 handle_simd_insg(s
, rd
, rn
, imm5
);
5788 unallocated_encoding(s
);
5793 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
5794 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
5797 unallocated_encoding(s
);
5803 /* C3.6.6 AdvSIMD modified immediate
5804 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
5805 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5806 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
5807 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5809 * There are a number of operations that can be carried out here:
5810 * MOVI - move (shifted) imm into register
5811 * MVNI - move inverted (shifted) imm into register
5812 * ORR - bitwise OR of (shifted) imm with register
5813 * BIC - bitwise clear of (shifted) imm with register
5815 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
5817 int rd
= extract32(insn
, 0, 5);
5818 int cmode
= extract32(insn
, 12, 4);
5819 int cmode_3_1
= extract32(cmode
, 1, 3);
5820 int cmode_0
= extract32(cmode
, 0, 1);
5821 int o2
= extract32(insn
, 11, 1);
5822 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
5823 bool is_neg
= extract32(insn
, 29, 1);
5824 bool is_q
= extract32(insn
, 30, 1);
5826 TCGv_i64 tcg_rd
, tcg_imm
;
5829 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
5830 unallocated_encoding(s
);
5834 if (!fp_access_check(s
)) {
5838 /* See AdvSIMDExpandImm() in ARM ARM */
5839 switch (cmode_3_1
) {
5840 case 0: /* Replicate(Zeros(24):imm8, 2) */
5841 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
5842 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
5843 case 3: /* Replicate(imm8:Zeros(24), 2) */
5845 int shift
= cmode_3_1
* 8;
5846 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
5849 case 4: /* Replicate(Zeros(8):imm8, 4) */
5850 case 5: /* Replicate(imm8:Zeros(8), 4) */
5852 int shift
= (cmode_3_1
& 0x1) * 8;
5853 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
5858 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
5859 imm
= (abcdefgh
<< 16) | 0xffff;
5861 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
5862 imm
= (abcdefgh
<< 8) | 0xff;
5864 imm
= bitfield_replicate(imm
, 32);
5867 if (!cmode_0
&& !is_neg
) {
5868 imm
= bitfield_replicate(abcdefgh
, 8);
5869 } else if (!cmode_0
&& is_neg
) {
5872 for (i
= 0; i
< 8; i
++) {
5873 if ((abcdefgh
) & (1 << i
)) {
5874 imm
|= 0xffULL
<< (i
* 8);
5877 } else if (cmode_0
) {
5879 imm
= (abcdefgh
& 0x3f) << 48;
5880 if (abcdefgh
& 0x80) {
5881 imm
|= 0x8000000000000000ULL
;
5883 if (abcdefgh
& 0x40) {
5884 imm
|= 0x3fc0000000000000ULL
;
5886 imm
|= 0x4000000000000000ULL
;
5889 imm
= (abcdefgh
& 0x3f) << 19;
5890 if (abcdefgh
& 0x80) {
5893 if (abcdefgh
& 0x40) {
5904 if (cmode_3_1
!= 7 && is_neg
) {
5908 tcg_imm
= tcg_const_i64(imm
);
5909 tcg_rd
= new_tmp_a64(s
);
5911 for (i
= 0; i
< 2; i
++) {
5912 int foffs
= i
? fp_reg_hi_offset(s
, rd
) : fp_reg_offset(s
, rd
, MO_64
);
5914 if (i
== 1 && !is_q
) {
5915 /* non-quad ops clear high half of vector */
5916 tcg_gen_movi_i64(tcg_rd
, 0);
5917 } else if ((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9) {
5918 tcg_gen_ld_i64(tcg_rd
, cpu_env
, foffs
);
5921 tcg_gen_and_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5924 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5928 tcg_gen_mov_i64(tcg_rd
, tcg_imm
);
5930 tcg_gen_st_i64(tcg_rd
, cpu_env
, foffs
);
5933 tcg_temp_free_i64(tcg_imm
);
5936 /* C3.6.7 AdvSIMD scalar copy
5937 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5938 * +-----+----+-----------------+------+---+------+---+------+------+
5939 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5940 * +-----+----+-----------------+------+---+------+---+------+------+
5942 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
5944 int rd
= extract32(insn
, 0, 5);
5945 int rn
= extract32(insn
, 5, 5);
5946 int imm4
= extract32(insn
, 11, 4);
5947 int imm5
= extract32(insn
, 16, 5);
5948 int op
= extract32(insn
, 29, 1);
5950 if (op
!= 0 || imm4
!= 0) {
5951 unallocated_encoding(s
);
5955 /* DUP (element, scalar) */
5956 handle_simd_dupes(s
, rd
, rn
, imm5
);
5959 /* C3.6.8 AdvSIMD scalar pairwise
5960 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5961 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5962 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5963 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5965 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
5967 int u
= extract32(insn
, 29, 1);
5968 int size
= extract32(insn
, 22, 2);
5969 int opcode
= extract32(insn
, 12, 5);
5970 int rn
= extract32(insn
, 5, 5);
5971 int rd
= extract32(insn
, 0, 5);
5974 /* For some ops (the FP ones), size[1] is part of the encoding.
5975 * For ADDP strictly it is not but size[1] is always 1 for valid
5978 opcode
|= (extract32(size
, 1, 1) << 5);
5981 case 0x3b: /* ADDP */
5982 if (u
|| size
!= 3) {
5983 unallocated_encoding(s
);
5986 if (!fp_access_check(s
)) {
5990 TCGV_UNUSED_PTR(fpst
);
5992 case 0xc: /* FMAXNMP */
5993 case 0xd: /* FADDP */
5994 case 0xf: /* FMAXP */
5995 case 0x2c: /* FMINNMP */
5996 case 0x2f: /* FMINP */
5997 /* FP op, size[0] is 32 or 64 bit */
5999 unallocated_encoding(s
);
6002 if (!fp_access_check(s
)) {
6006 size
= extract32(size
, 0, 1) ? 3 : 2;
6007 fpst
= get_fpstatus_ptr();
6010 unallocated_encoding(s
);
6015 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6016 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6017 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6019 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
6020 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
6023 case 0x3b: /* ADDP */
6024 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
6026 case 0xc: /* FMAXNMP */
6027 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6029 case 0xd: /* FADDP */
6030 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6032 case 0xf: /* FMAXP */
6033 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6035 case 0x2c: /* FMINNMP */
6036 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6038 case 0x2f: /* FMINP */
6039 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6042 g_assert_not_reached();
6045 write_fp_dreg(s
, rd
, tcg_res
);
6047 tcg_temp_free_i64(tcg_op1
);
6048 tcg_temp_free_i64(tcg_op2
);
6049 tcg_temp_free_i64(tcg_res
);
6051 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6052 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6053 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6055 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_32
);
6056 read_vec_element_i32(s
, tcg_op2
, rn
, 1, MO_32
);
6059 case 0xc: /* FMAXNMP */
6060 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6062 case 0xd: /* FADDP */
6063 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6065 case 0xf: /* FMAXP */
6066 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6068 case 0x2c: /* FMINNMP */
6069 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6071 case 0x2f: /* FMINP */
6072 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6075 g_assert_not_reached();
6078 write_fp_sreg(s
, rd
, tcg_res
);
6080 tcg_temp_free_i32(tcg_op1
);
6081 tcg_temp_free_i32(tcg_op2
);
6082 tcg_temp_free_i32(tcg_res
);
6085 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
6086 tcg_temp_free_ptr(fpst
);
6091 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
6093 * This code is handles the common shifting code and is used by both
6094 * the vector and scalar code.
6096 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6097 TCGv_i64 tcg_rnd
, bool accumulate
,
6098 bool is_u
, int size
, int shift
)
6100 bool extended_result
= false;
6101 bool round
= !TCGV_IS_UNUSED_I64(tcg_rnd
);
6103 TCGv_i64 tcg_src_hi
;
6105 if (round
&& size
== 3) {
6106 extended_result
= true;
6107 ext_lshift
= 64 - shift
;
6108 tcg_src_hi
= tcg_temp_new_i64();
6109 } else if (shift
== 64) {
6110 if (!accumulate
&& is_u
) {
6111 /* result is zero */
6112 tcg_gen_movi_i64(tcg_res
, 0);
6117 /* Deal with the rounding step */
6119 if (extended_result
) {
6120 TCGv_i64 tcg_zero
= tcg_const_i64(0);
6122 /* take care of sign extending tcg_res */
6123 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
6124 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6125 tcg_src
, tcg_src_hi
,
6128 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6132 tcg_temp_free_i64(tcg_zero
);
6134 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
6138 /* Now do the shift right */
6139 if (round
&& extended_result
) {
6140 /* extended case, >64 bit precision required */
6141 if (ext_lshift
== 0) {
6142 /* special case, only high bits matter */
6143 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
6145 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6146 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
6147 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
6152 /* essentially shifting in 64 zeros */
6153 tcg_gen_movi_i64(tcg_src
, 0);
6155 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6159 /* effectively extending the sign-bit */
6160 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
6162 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
6168 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
6170 tcg_gen_mov_i64(tcg_res
, tcg_src
);
6173 if (extended_result
) {
6174 tcg_temp_free_i64(tcg_src_hi
);
6178 /* Common SHL/SLI - Shift left with an optional insert */
6179 static void handle_shli_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6180 bool insert
, int shift
)
6182 if (insert
) { /* SLI */
6183 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, shift
, 64 - shift
);
6185 tcg_gen_shli_i64(tcg_res
, tcg_src
, shift
);
6189 /* SRI: shift right with insert */
6190 static void handle_shri_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6191 int size
, int shift
)
6193 int esize
= 8 << size
;
6195 /* shift count same as element size is valid but does nothing;
6196 * special case to avoid potential shift by 64.
6198 if (shift
!= esize
) {
6199 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6200 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, 0, esize
- shift
);
6204 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
6205 static void handle_scalar_simd_shri(DisasContext
*s
,
6206 bool is_u
, int immh
, int immb
,
6207 int opcode
, int rn
, int rd
)
6210 int immhb
= immh
<< 3 | immb
;
6211 int shift
= 2 * (8 << size
) - immhb
;
6212 bool accumulate
= false;
6214 bool insert
= false;
6219 if (!extract32(immh
, 3, 1)) {
6220 unallocated_encoding(s
);
6224 if (!fp_access_check(s
)) {
6229 case 0x02: /* SSRA / USRA (accumulate) */
6232 case 0x04: /* SRSHR / URSHR (rounding) */
6235 case 0x06: /* SRSRA / URSRA (accum + rounding) */
6236 accumulate
= round
= true;
6238 case 0x08: /* SRI */
6244 uint64_t round_const
= 1ULL << (shift
- 1);
6245 tcg_round
= tcg_const_i64(round_const
);
6247 TCGV_UNUSED_I64(tcg_round
);
6250 tcg_rn
= read_fp_dreg(s
, rn
);
6251 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6254 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
6256 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6257 accumulate
, is_u
, size
, shift
);
6260 write_fp_dreg(s
, rd
, tcg_rd
);
6262 tcg_temp_free_i64(tcg_rn
);
6263 tcg_temp_free_i64(tcg_rd
);
6265 tcg_temp_free_i64(tcg_round
);
6269 /* SHL/SLI - Scalar shift left */
6270 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
6271 int immh
, int immb
, int opcode
,
6274 int size
= 32 - clz32(immh
) - 1;
6275 int immhb
= immh
<< 3 | immb
;
6276 int shift
= immhb
- (8 << size
);
6277 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
6278 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
6280 if (!extract32(immh
, 3, 1)) {
6281 unallocated_encoding(s
);
6285 if (!fp_access_check(s
)) {
6289 tcg_rn
= read_fp_dreg(s
, rn
);
6290 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6292 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
6294 write_fp_dreg(s
, rd
, tcg_rd
);
6296 tcg_temp_free_i64(tcg_rn
);
6297 tcg_temp_free_i64(tcg_rd
);
6300 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
6301 * (signed/unsigned) narrowing */
6302 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
6303 bool is_u_shift
, bool is_u_narrow
,
6304 int immh
, int immb
, int opcode
,
6307 int immhb
= immh
<< 3 | immb
;
6308 int size
= 32 - clz32(immh
) - 1;
6309 int esize
= 8 << size
;
6310 int shift
= (2 * esize
) - immhb
;
6311 int elements
= is_scalar
? 1 : (64 / esize
);
6312 bool round
= extract32(opcode
, 0, 1);
6313 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
6314 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
6315 TCGv_i32 tcg_rd_narrowed
;
6318 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
6319 { gen_helper_neon_narrow_sat_s8
,
6320 gen_helper_neon_unarrow_sat8
},
6321 { gen_helper_neon_narrow_sat_s16
,
6322 gen_helper_neon_unarrow_sat16
},
6323 { gen_helper_neon_narrow_sat_s32
,
6324 gen_helper_neon_unarrow_sat32
},
6327 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
6328 gen_helper_neon_narrow_sat_u8
,
6329 gen_helper_neon_narrow_sat_u16
,
6330 gen_helper_neon_narrow_sat_u32
,
6333 NeonGenNarrowEnvFn
*narrowfn
;
6339 if (extract32(immh
, 3, 1)) {
6340 unallocated_encoding(s
);
6344 if (!fp_access_check(s
)) {
6349 narrowfn
= unsigned_narrow_fns
[size
];
6351 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
6354 tcg_rn
= tcg_temp_new_i64();
6355 tcg_rd
= tcg_temp_new_i64();
6356 tcg_rd_narrowed
= tcg_temp_new_i32();
6357 tcg_final
= tcg_const_i64(0);
6360 uint64_t round_const
= 1ULL << (shift
- 1);
6361 tcg_round
= tcg_const_i64(round_const
);
6363 TCGV_UNUSED_I64(tcg_round
);
6366 for (i
= 0; i
< elements
; i
++) {
6367 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
6368 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6369 false, is_u_shift
, size
+1, shift
);
6370 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
6371 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
6372 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
6376 clear_vec_high(s
, rd
);
6377 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
6379 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
6383 tcg_temp_free_i64(tcg_round
);
6385 tcg_temp_free_i64(tcg_rn
);
6386 tcg_temp_free_i64(tcg_rd
);
6387 tcg_temp_free_i32(tcg_rd_narrowed
);
6388 tcg_temp_free_i64(tcg_final
);
6392 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
6393 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
6394 bool src_unsigned
, bool dst_unsigned
,
6395 int immh
, int immb
, int rn
, int rd
)
6397 int immhb
= immh
<< 3 | immb
;
6398 int size
= 32 - clz32(immh
) - 1;
6399 int shift
= immhb
- (8 << size
);
6403 assert(!(scalar
&& is_q
));
6406 if (!is_q
&& extract32(immh
, 3, 1)) {
6407 unallocated_encoding(s
);
6411 /* Since we use the variable-shift helpers we must
6412 * replicate the shift count into each element of
6413 * the tcg_shift value.
6417 shift
|= shift
<< 8;
6420 shift
|= shift
<< 16;
6426 g_assert_not_reached();
6430 if (!fp_access_check(s
)) {
6435 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
6436 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
6437 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
6438 { NULL
, gen_helper_neon_qshl_u64
},
6440 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
6441 int maxpass
= is_q
? 2 : 1;
6443 for (pass
= 0; pass
< maxpass
; pass
++) {
6444 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6446 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6447 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6448 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6450 tcg_temp_free_i64(tcg_op
);
6452 tcg_temp_free_i64(tcg_shift
);
6455 clear_vec_high(s
, rd
);
6458 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
6459 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
6461 { gen_helper_neon_qshl_s8
,
6462 gen_helper_neon_qshl_s16
,
6463 gen_helper_neon_qshl_s32
},
6464 { gen_helper_neon_qshlu_s8
,
6465 gen_helper_neon_qshlu_s16
,
6466 gen_helper_neon_qshlu_s32
}
6468 { NULL
, NULL
, NULL
},
6469 { gen_helper_neon_qshl_u8
,
6470 gen_helper_neon_qshl_u16
,
6471 gen_helper_neon_qshl_u32
}
6474 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
6475 TCGMemOp memop
= scalar
? size
: MO_32
;
6476 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
6478 for (pass
= 0; pass
< maxpass
; pass
++) {
6479 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6481 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
6482 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6486 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
6489 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
6494 g_assert_not_reached();
6496 write_fp_sreg(s
, rd
, tcg_op
);
6498 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6501 tcg_temp_free_i32(tcg_op
);
6503 tcg_temp_free_i32(tcg_shift
);
6505 if (!is_q
&& !scalar
) {
6506 clear_vec_high(s
, rd
);
6511 /* Common vector code for handling integer to FP conversion */
6512 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
6513 int elements
, int is_signed
,
6514 int fracbits
, int size
)
6516 bool is_double
= size
== 3 ? true : false;
6517 TCGv_ptr tcg_fpst
= get_fpstatus_ptr();
6518 TCGv_i32 tcg_shift
= tcg_const_i32(fracbits
);
6519 TCGv_i64 tcg_int
= tcg_temp_new_i64();
6520 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
6523 for (pass
= 0; pass
< elements
; pass
++) {
6524 read_vec_element(s
, tcg_int
, rn
, pass
, mop
);
6527 TCGv_i64 tcg_double
= tcg_temp_new_i64();
6529 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6530 tcg_shift
, tcg_fpst
);
6532 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6533 tcg_shift
, tcg_fpst
);
6535 if (elements
== 1) {
6536 write_fp_dreg(s
, rd
, tcg_double
);
6538 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
6540 tcg_temp_free_i64(tcg_double
);
6542 TCGv_i32 tcg_single
= tcg_temp_new_i32();
6544 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6545 tcg_shift
, tcg_fpst
);
6547 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6548 tcg_shift
, tcg_fpst
);
6550 if (elements
== 1) {
6551 write_fp_sreg(s
, rd
, tcg_single
);
6553 write_vec_element_i32(s
, tcg_single
, rd
, pass
, MO_32
);
6555 tcg_temp_free_i32(tcg_single
);
6559 if (!is_double
&& elements
== 2) {
6560 clear_vec_high(s
, rd
);
6563 tcg_temp_free_i64(tcg_int
);
6564 tcg_temp_free_ptr(tcg_fpst
);
6565 tcg_temp_free_i32(tcg_shift
);
6568 /* UCVTF/SCVTF - Integer to FP conversion */
6569 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
6570 bool is_q
, bool is_u
,
6571 int immh
, int immb
, int opcode
,
6574 bool is_double
= extract32(immh
, 3, 1);
6575 int size
= is_double
? MO_64
: MO_32
;
6577 int immhb
= immh
<< 3 | immb
;
6578 int fracbits
= (is_double
? 128 : 64) - immhb
;
6580 if (!extract32(immh
, 2, 2)) {
6581 unallocated_encoding(s
);
6588 elements
= is_double
? 2 : is_q
? 4 : 2;
6589 if (is_double
&& !is_q
) {
6590 unallocated_encoding(s
);
6595 if (!fp_access_check(s
)) {
6599 /* immh == 0 would be a failure of the decode logic */
6602 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
6605 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
6606 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
6607 bool is_q
, bool is_u
,
6608 int immh
, int immb
, int rn
, int rd
)
6610 bool is_double
= extract32(immh
, 3, 1);
6611 int immhb
= immh
<< 3 | immb
;
6612 int fracbits
= (is_double
? 128 : 64) - immhb
;
6614 TCGv_ptr tcg_fpstatus
;
6615 TCGv_i32 tcg_rmode
, tcg_shift
;
6617 if (!extract32(immh
, 2, 2)) {
6618 unallocated_encoding(s
);
6622 if (!is_scalar
&& !is_q
&& is_double
) {
6623 unallocated_encoding(s
);
6627 if (!fp_access_check(s
)) {
6631 assert(!(is_scalar
&& is_q
));
6633 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
6634 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6635 tcg_fpstatus
= get_fpstatus_ptr();
6636 tcg_shift
= tcg_const_i32(fracbits
);
6639 int maxpass
= is_scalar
? 1 : 2;
6641 for (pass
= 0; pass
< maxpass
; pass
++) {
6642 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6644 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6646 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6648 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6650 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6651 tcg_temp_free_i64(tcg_op
);
6654 clear_vec_high(s
, rd
);
6657 int maxpass
= is_scalar
? 1 : is_q
? 4 : 2;
6658 for (pass
= 0; pass
< maxpass
; pass
++) {
6659 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6661 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
6663 gen_helper_vfp_touls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6665 gen_helper_vfp_tosls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6668 write_fp_sreg(s
, rd
, tcg_op
);
6670 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6672 tcg_temp_free_i32(tcg_op
);
6674 if (!is_q
&& !is_scalar
) {
6675 clear_vec_high(s
, rd
);
6679 tcg_temp_free_ptr(tcg_fpstatus
);
6680 tcg_temp_free_i32(tcg_shift
);
6681 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6682 tcg_temp_free_i32(tcg_rmode
);
6685 /* C3.6.9 AdvSIMD scalar shift by immediate
6686 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
6687 * +-----+---+-------------+------+------+--------+---+------+------+
6688 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
6689 * +-----+---+-------------+------+------+--------+---+------+------+
6691 * This is the scalar version so it works on a fixed sized registers
6693 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
6695 int rd
= extract32(insn
, 0, 5);
6696 int rn
= extract32(insn
, 5, 5);
6697 int opcode
= extract32(insn
, 11, 5);
6698 int immb
= extract32(insn
, 16, 3);
6699 int immh
= extract32(insn
, 19, 4);
6700 bool is_u
= extract32(insn
, 29, 1);
6703 unallocated_encoding(s
);
6708 case 0x08: /* SRI */
6710 unallocated_encoding(s
);
6714 case 0x00: /* SSHR / USHR */
6715 case 0x02: /* SSRA / USRA */
6716 case 0x04: /* SRSHR / URSHR */
6717 case 0x06: /* SRSRA / URSRA */
6718 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6720 case 0x0a: /* SHL / SLI */
6721 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6723 case 0x1c: /* SCVTF, UCVTF */
6724 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
6727 case 0x10: /* SQSHRUN, SQSHRUN2 */
6728 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
6730 unallocated_encoding(s
);
6733 handle_vec_simd_sqshrn(s
, true, false, false, true,
6734 immh
, immb
, opcode
, rn
, rd
);
6736 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
6737 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
6738 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
6739 immh
, immb
, opcode
, rn
, rd
);
6741 case 0xc: /* SQSHLU */
6743 unallocated_encoding(s
);
6746 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
6748 case 0xe: /* SQSHL, UQSHL */
6749 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
6751 case 0x1f: /* FCVTZS, FCVTZU */
6752 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
6755 unallocated_encoding(s
);
6760 /* C3.6.10 AdvSIMD scalar three different
6761 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6762 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6763 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
6764 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6766 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
6768 bool is_u
= extract32(insn
, 29, 1);
6769 int size
= extract32(insn
, 22, 2);
6770 int opcode
= extract32(insn
, 12, 4);
6771 int rm
= extract32(insn
, 16, 5);
6772 int rn
= extract32(insn
, 5, 5);
6773 int rd
= extract32(insn
, 0, 5);
6776 unallocated_encoding(s
);
6781 case 0x9: /* SQDMLAL, SQDMLAL2 */
6782 case 0xb: /* SQDMLSL, SQDMLSL2 */
6783 case 0xd: /* SQDMULL, SQDMULL2 */
6784 if (size
== 0 || size
== 3) {
6785 unallocated_encoding(s
);
6790 unallocated_encoding(s
);
6794 if (!fp_access_check(s
)) {
6799 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6800 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6801 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6803 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
6804 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
6806 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
6807 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6810 case 0xd: /* SQDMULL, SQDMULL2 */
6812 case 0xb: /* SQDMLSL, SQDMLSL2 */
6813 tcg_gen_neg_i64(tcg_res
, tcg_res
);
6815 case 0x9: /* SQDMLAL, SQDMLAL2 */
6816 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
6817 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
6821 g_assert_not_reached();
6824 write_fp_dreg(s
, rd
, tcg_res
);
6826 tcg_temp_free_i64(tcg_op1
);
6827 tcg_temp_free_i64(tcg_op2
);
6828 tcg_temp_free_i64(tcg_res
);
6830 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6831 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6832 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6834 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_16
);
6835 read_vec_element_i32(s
, tcg_op2
, rm
, 0, MO_16
);
6837 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
6838 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6841 case 0xd: /* SQDMULL, SQDMULL2 */
6843 case 0xb: /* SQDMLSL, SQDMLSL2 */
6844 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
6846 case 0x9: /* SQDMLAL, SQDMLAL2 */
6848 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
6849 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
6850 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
6852 tcg_temp_free_i64(tcg_op3
);
6856 g_assert_not_reached();
6859 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
6860 write_fp_dreg(s
, rd
, tcg_res
);
6862 tcg_temp_free_i32(tcg_op1
);
6863 tcg_temp_free_i32(tcg_op2
);
6864 tcg_temp_free_i64(tcg_res
);
6868 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
6869 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
6871 /* Handle 64x64->64 opcodes which are shared between the scalar
6872 * and vector 3-same groups. We cover every opcode where size == 3
6873 * is valid in either the three-reg-same (integer, not pairwise)
6874 * or scalar-three-reg-same groups. (Some opcodes are not yet
6880 case 0x1: /* SQADD */
6882 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6884 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6887 case 0x5: /* SQSUB */
6889 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6891 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6894 case 0x6: /* CMGT, CMHI */
6895 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
6896 * We implement this using setcond (test) and then negating.
6898 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
6900 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
6901 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6903 case 0x7: /* CMGE, CMHS */
6904 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
6906 case 0x11: /* CMTST, CMEQ */
6911 /* CMTST : test is "if (X & Y != 0)". */
6912 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6913 tcg_gen_setcondi_i64(TCG_COND_NE
, tcg_rd
, tcg_rd
, 0);
6914 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6916 case 0x8: /* SSHL, USHL */
6918 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6920 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
6923 case 0x9: /* SQSHL, UQSHL */
6925 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6927 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6930 case 0xa: /* SRSHL, URSHL */
6932 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6934 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
6937 case 0xb: /* SQRSHL, UQRSHL */
6939 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6941 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6944 case 0x10: /* ADD, SUB */
6946 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6948 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6952 g_assert_not_reached();
6956 /* Handle the 3-same-operands float operations; shared by the scalar
6957 * and vector encodings. The caller must filter out any encodings
6958 * not allocated for the encoding it is dealing with.
6960 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
6961 int fpopcode
, int rd
, int rn
, int rm
)
6964 TCGv_ptr fpst
= get_fpstatus_ptr();
6966 for (pass
= 0; pass
< elements
; pass
++) {
6969 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6970 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6971 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6973 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
6974 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
6977 case 0x39: /* FMLS */
6978 /* As usual for ARM, separate negation for fused multiply-add */
6979 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
6981 case 0x19: /* FMLA */
6982 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
6983 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
6986 case 0x18: /* FMAXNM */
6987 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6989 case 0x1a: /* FADD */
6990 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6992 case 0x1b: /* FMULX */
6993 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6995 case 0x1c: /* FCMEQ */
6996 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6998 case 0x1e: /* FMAX */
6999 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7001 case 0x1f: /* FRECPS */
7002 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7004 case 0x38: /* FMINNM */
7005 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7007 case 0x3a: /* FSUB */
7008 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7010 case 0x3e: /* FMIN */
7011 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7013 case 0x3f: /* FRSQRTS */
7014 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7016 case 0x5b: /* FMUL */
7017 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7019 case 0x5c: /* FCMGE */
7020 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7022 case 0x5d: /* FACGE */
7023 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7025 case 0x5f: /* FDIV */
7026 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7028 case 0x7a: /* FABD */
7029 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7030 gen_helper_vfp_absd(tcg_res
, tcg_res
);
7032 case 0x7c: /* FCMGT */
7033 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7035 case 0x7d: /* FACGT */
7036 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7039 g_assert_not_reached();
7042 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7044 tcg_temp_free_i64(tcg_res
);
7045 tcg_temp_free_i64(tcg_op1
);
7046 tcg_temp_free_i64(tcg_op2
);
7049 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7050 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7051 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7053 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
7054 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
7057 case 0x39: /* FMLS */
7058 /* As usual for ARM, separate negation for fused multiply-add */
7059 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
7061 case 0x19: /* FMLA */
7062 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7063 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
7066 case 0x1a: /* FADD */
7067 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7069 case 0x1b: /* FMULX */
7070 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7072 case 0x1c: /* FCMEQ */
7073 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7075 case 0x1e: /* FMAX */
7076 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7078 case 0x1f: /* FRECPS */
7079 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7081 case 0x18: /* FMAXNM */
7082 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7084 case 0x38: /* FMINNM */
7085 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7087 case 0x3a: /* FSUB */
7088 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7090 case 0x3e: /* FMIN */
7091 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7093 case 0x3f: /* FRSQRTS */
7094 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7096 case 0x5b: /* FMUL */
7097 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7099 case 0x5c: /* FCMGE */
7100 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7102 case 0x5d: /* FACGE */
7103 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7105 case 0x5f: /* FDIV */
7106 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7108 case 0x7a: /* FABD */
7109 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7110 gen_helper_vfp_abss(tcg_res
, tcg_res
);
7112 case 0x7c: /* FCMGT */
7113 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7115 case 0x7d: /* FACGT */
7116 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7119 g_assert_not_reached();
7122 if (elements
== 1) {
7123 /* scalar single so clear high part */
7124 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
7126 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
7127 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
7128 tcg_temp_free_i64(tcg_tmp
);
7130 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7133 tcg_temp_free_i32(tcg_res
);
7134 tcg_temp_free_i32(tcg_op1
);
7135 tcg_temp_free_i32(tcg_op2
);
7139 tcg_temp_free_ptr(fpst
);
7141 if ((elements
<< size
) < 4) {
7142 /* scalar, or non-quad vector op */
7143 clear_vec_high(s
, rd
);
7147 /* C3.6.11 AdvSIMD scalar three same
7148 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
7149 * +-----+---+-----------+------+---+------+--------+---+------+------+
7150 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
7151 * +-----+---+-----------+------+---+------+--------+---+------+------+
7153 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
7155 int rd
= extract32(insn
, 0, 5);
7156 int rn
= extract32(insn
, 5, 5);
7157 int opcode
= extract32(insn
, 11, 5);
7158 int rm
= extract32(insn
, 16, 5);
7159 int size
= extract32(insn
, 22, 2);
7160 bool u
= extract32(insn
, 29, 1);
7163 if (opcode
>= 0x18) {
7164 /* Floating point: U, size[1] and opcode indicate operation */
7165 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
7167 case 0x1b: /* FMULX */
7168 case 0x1f: /* FRECPS */
7169 case 0x3f: /* FRSQRTS */
7170 case 0x5d: /* FACGE */
7171 case 0x7d: /* FACGT */
7172 case 0x1c: /* FCMEQ */
7173 case 0x5c: /* FCMGE */
7174 case 0x7c: /* FCMGT */
7175 case 0x7a: /* FABD */
7178 unallocated_encoding(s
);
7182 if (!fp_access_check(s
)) {
7186 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
7191 case 0x1: /* SQADD, UQADD */
7192 case 0x5: /* SQSUB, UQSUB */
7193 case 0x9: /* SQSHL, UQSHL */
7194 case 0xb: /* SQRSHL, UQRSHL */
7196 case 0x8: /* SSHL, USHL */
7197 case 0xa: /* SRSHL, URSHL */
7198 case 0x6: /* CMGT, CMHI */
7199 case 0x7: /* CMGE, CMHS */
7200 case 0x11: /* CMTST, CMEQ */
7201 case 0x10: /* ADD, SUB (vector) */
7203 unallocated_encoding(s
);
7207 case 0x16: /* SQDMULH, SQRDMULH (vector) */
7208 if (size
!= 1 && size
!= 2) {
7209 unallocated_encoding(s
);
7214 unallocated_encoding(s
);
7218 if (!fp_access_check(s
)) {
7222 tcg_rd
= tcg_temp_new_i64();
7225 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7226 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
7228 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
7229 tcg_temp_free_i64(tcg_rn
);
7230 tcg_temp_free_i64(tcg_rm
);
7232 /* Do a single operation on the lowest element in the vector.
7233 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
7234 * no side effects for all these operations.
7235 * OPTME: special-purpose helpers would avoid doing some
7236 * unnecessary work in the helper for the 8 and 16 bit cases.
7238 NeonGenTwoOpEnvFn
*genenvfn
;
7239 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7240 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
7241 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
7243 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7244 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
7247 case 0x1: /* SQADD, UQADD */
7249 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7250 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
7251 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
7252 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
7254 genenvfn
= fns
[size
][u
];
7257 case 0x5: /* SQSUB, UQSUB */
7259 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7260 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
7261 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
7262 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
7264 genenvfn
= fns
[size
][u
];
7267 case 0x9: /* SQSHL, UQSHL */
7269 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7270 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
7271 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
7272 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
7274 genenvfn
= fns
[size
][u
];
7277 case 0xb: /* SQRSHL, UQRSHL */
7279 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7280 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
7281 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
7282 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
7284 genenvfn
= fns
[size
][u
];
7287 case 0x16: /* SQDMULH, SQRDMULH */
7289 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
7290 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
7291 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
7293 assert(size
== 1 || size
== 2);
7294 genenvfn
= fns
[size
- 1][u
];
7298 g_assert_not_reached();
7301 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
7302 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
7303 tcg_temp_free_i32(tcg_rd32
);
7304 tcg_temp_free_i32(tcg_rn
);
7305 tcg_temp_free_i32(tcg_rm
);
7308 write_fp_dreg(s
, rd
, tcg_rd
);
7310 tcg_temp_free_i64(tcg_rd
);
7313 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
7314 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
7315 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
7317 /* Handle 64->64 opcodes which are shared between the scalar and
7318 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
7319 * is valid in either group and also the double-precision fp ops.
7320 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
7326 case 0x4: /* CLS, CLZ */
7328 gen_helper_clz64(tcg_rd
, tcg_rn
);
7330 gen_helper_cls64(tcg_rd
, tcg_rn
);
7334 /* This opcode is shared with CNT and RBIT but we have earlier
7335 * enforced that size == 3 if and only if this is the NOT insn.
7337 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
7339 case 0x7: /* SQABS, SQNEG */
7341 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
7343 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
7346 case 0xa: /* CMLT */
7347 /* 64 bit integer comparison against zero, result is
7348 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
7353 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
7354 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7356 case 0x8: /* CMGT, CMGE */
7357 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
7359 case 0x9: /* CMEQ, CMLE */
7360 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
7362 case 0xb: /* ABS, NEG */
7364 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7366 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7367 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7368 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
7370 tcg_temp_free_i64(tcg_zero
);
7373 case 0x2f: /* FABS */
7374 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
7376 case 0x6f: /* FNEG */
7377 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
7379 case 0x7f: /* FSQRT */
7380 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
7382 case 0x1a: /* FCVTNS */
7383 case 0x1b: /* FCVTMS */
7384 case 0x1c: /* FCVTAS */
7385 case 0x3a: /* FCVTPS */
7386 case 0x3b: /* FCVTZS */
7388 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7389 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7390 tcg_temp_free_i32(tcg_shift
);
7393 case 0x5a: /* FCVTNU */
7394 case 0x5b: /* FCVTMU */
7395 case 0x5c: /* FCVTAU */
7396 case 0x7a: /* FCVTPU */
7397 case 0x7b: /* FCVTZU */
7399 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7400 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7401 tcg_temp_free_i32(tcg_shift
);
7404 case 0x18: /* FRINTN */
7405 case 0x19: /* FRINTM */
7406 case 0x38: /* FRINTP */
7407 case 0x39: /* FRINTZ */
7408 case 0x58: /* FRINTA */
7409 case 0x79: /* FRINTI */
7410 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7412 case 0x59: /* FRINTX */
7413 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7416 g_assert_not_reached();
7420 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
7421 bool is_scalar
, bool is_u
, bool is_q
,
7422 int size
, int rn
, int rd
)
7424 bool is_double
= (size
== 3);
7427 if (!fp_access_check(s
)) {
7431 fpst
= get_fpstatus_ptr();
7434 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7435 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7436 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7437 NeonGenTwoDoubleOPFn
*genfn
;
7442 case 0x2e: /* FCMLT (zero) */
7445 case 0x2c: /* FCMGT (zero) */
7446 genfn
= gen_helper_neon_cgt_f64
;
7448 case 0x2d: /* FCMEQ (zero) */
7449 genfn
= gen_helper_neon_ceq_f64
;
7451 case 0x6d: /* FCMLE (zero) */
7454 case 0x6c: /* FCMGE (zero) */
7455 genfn
= gen_helper_neon_cge_f64
;
7458 g_assert_not_reached();
7461 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7462 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7464 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7466 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7468 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7471 clear_vec_high(s
, rd
);
7474 tcg_temp_free_i64(tcg_res
);
7475 tcg_temp_free_i64(tcg_zero
);
7476 tcg_temp_free_i64(tcg_op
);
7478 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7479 TCGv_i32 tcg_zero
= tcg_const_i32(0);
7480 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7481 NeonGenTwoSingleOPFn
*genfn
;
7483 int pass
, maxpasses
;
7486 case 0x2e: /* FCMLT (zero) */
7489 case 0x2c: /* FCMGT (zero) */
7490 genfn
= gen_helper_neon_cgt_f32
;
7492 case 0x2d: /* FCMEQ (zero) */
7493 genfn
= gen_helper_neon_ceq_f32
;
7495 case 0x6d: /* FCMLE (zero) */
7498 case 0x6c: /* FCMGE (zero) */
7499 genfn
= gen_helper_neon_cge_f32
;
7502 g_assert_not_reached();
7508 maxpasses
= is_q
? 4 : 2;
7511 for (pass
= 0; pass
< maxpasses
; pass
++) {
7512 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7514 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7516 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7519 write_fp_sreg(s
, rd
, tcg_res
);
7521 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7524 tcg_temp_free_i32(tcg_res
);
7525 tcg_temp_free_i32(tcg_zero
);
7526 tcg_temp_free_i32(tcg_op
);
7527 if (!is_q
&& !is_scalar
) {
7528 clear_vec_high(s
, rd
);
7532 tcg_temp_free_ptr(fpst
);
7535 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
7536 bool is_scalar
, bool is_u
, bool is_q
,
7537 int size
, int rn
, int rd
)
7539 bool is_double
= (size
== 3);
7540 TCGv_ptr fpst
= get_fpstatus_ptr();
7543 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7544 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7547 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7548 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7550 case 0x3d: /* FRECPE */
7551 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
7553 case 0x3f: /* FRECPX */
7554 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
7556 case 0x7d: /* FRSQRTE */
7557 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
7560 g_assert_not_reached();
7562 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7565 clear_vec_high(s
, rd
);
7568 tcg_temp_free_i64(tcg_res
);
7569 tcg_temp_free_i64(tcg_op
);
7571 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7572 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7573 int pass
, maxpasses
;
7578 maxpasses
= is_q
? 4 : 2;
7581 for (pass
= 0; pass
< maxpasses
; pass
++) {
7582 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7585 case 0x3c: /* URECPE */
7586 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
7588 case 0x3d: /* FRECPE */
7589 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
7591 case 0x3f: /* FRECPX */
7592 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
7594 case 0x7d: /* FRSQRTE */
7595 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
7598 g_assert_not_reached();
7602 write_fp_sreg(s
, rd
, tcg_res
);
7604 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7607 tcg_temp_free_i32(tcg_res
);
7608 tcg_temp_free_i32(tcg_op
);
7609 if (!is_q
&& !is_scalar
) {
7610 clear_vec_high(s
, rd
);
7613 tcg_temp_free_ptr(fpst
);
7616 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
7617 int opcode
, bool u
, bool is_q
,
7618 int size
, int rn
, int rd
)
7620 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
7621 * in the source becomes a size element in the destination).
7624 TCGv_i32 tcg_res
[2];
7625 int destelt
= is_q
? 2 : 0;
7626 int passes
= scalar
? 1 : 2;
7629 tcg_res
[1] = tcg_const_i32(0);
7632 for (pass
= 0; pass
< passes
; pass
++) {
7633 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7634 NeonGenNarrowFn
*genfn
= NULL
;
7635 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
7638 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
7640 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7642 tcg_res
[pass
] = tcg_temp_new_i32();
7645 case 0x12: /* XTN, SQXTUN */
7647 static NeonGenNarrowFn
* const xtnfns
[3] = {
7648 gen_helper_neon_narrow_u8
,
7649 gen_helper_neon_narrow_u16
,
7650 tcg_gen_trunc_i64_i32
,
7652 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
7653 gen_helper_neon_unarrow_sat8
,
7654 gen_helper_neon_unarrow_sat16
,
7655 gen_helper_neon_unarrow_sat32
,
7658 genenvfn
= sqxtunfns
[size
];
7660 genfn
= xtnfns
[size
];
7664 case 0x14: /* SQXTN, UQXTN */
7666 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
7667 { gen_helper_neon_narrow_sat_s8
,
7668 gen_helper_neon_narrow_sat_u8
},
7669 { gen_helper_neon_narrow_sat_s16
,
7670 gen_helper_neon_narrow_sat_u16
},
7671 { gen_helper_neon_narrow_sat_s32
,
7672 gen_helper_neon_narrow_sat_u32
},
7674 genenvfn
= fns
[size
][u
];
7677 case 0x16: /* FCVTN, FCVTN2 */
7678 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
7680 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
7682 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
7683 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
7684 tcg_gen_trunc_i64_i32(tcg_lo
, tcg_op
);
7685 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, cpu_env
);
7686 tcg_gen_shri_i64(tcg_op
, tcg_op
, 32);
7687 tcg_gen_trunc_i64_i32(tcg_hi
, tcg_op
);
7688 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, cpu_env
);
7689 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
7690 tcg_temp_free_i32(tcg_lo
);
7691 tcg_temp_free_i32(tcg_hi
);
7694 case 0x56: /* FCVTXN, FCVTXN2 */
7695 /* 64 bit to 32 bit float conversion
7696 * with von Neumann rounding (round to odd)
7699 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
7702 g_assert_not_reached();
7706 genfn(tcg_res
[pass
], tcg_op
);
7707 } else if (genenvfn
) {
7708 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
7711 tcg_temp_free_i64(tcg_op
);
7714 for (pass
= 0; pass
< 2; pass
++) {
7715 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
7716 tcg_temp_free_i32(tcg_res
[pass
]);
7719 clear_vec_high(s
, rd
);
7723 /* Remaining saturating accumulating ops */
7724 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
7725 bool is_q
, int size
, int rn
, int rd
)
7727 bool is_double
= (size
== 3);
7730 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
7731 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7734 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7735 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
7736 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7738 if (is_u
) { /* USQADD */
7739 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7740 } else { /* SUQADD */
7741 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7743 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7746 clear_vec_high(s
, rd
);
7749 tcg_temp_free_i64(tcg_rd
);
7750 tcg_temp_free_i64(tcg_rn
);
7752 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7753 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7754 int pass
, maxpasses
;
7759 maxpasses
= is_q
? 4 : 2;
7762 for (pass
= 0; pass
< maxpasses
; pass
++) {
7764 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
7765 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
7767 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
7768 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7771 if (is_u
) { /* USQADD */
7774 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7777 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7780 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7783 g_assert_not_reached();
7785 } else { /* SUQADD */
7788 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7791 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7794 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7797 g_assert_not_reached();
7802 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7803 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
7804 tcg_temp_free_i64(tcg_zero
);
7806 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7810 clear_vec_high(s
, rd
);
7813 tcg_temp_free_i32(tcg_rd
);
7814 tcg_temp_free_i32(tcg_rn
);
7818 /* C3.6.12 AdvSIMD scalar two reg misc
7819 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7820 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7821 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
7822 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7824 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
7826 int rd
= extract32(insn
, 0, 5);
7827 int rn
= extract32(insn
, 5, 5);
7828 int opcode
= extract32(insn
, 12, 5);
7829 int size
= extract32(insn
, 22, 2);
7830 bool u
= extract32(insn
, 29, 1);
7831 bool is_fcvt
= false;
7834 TCGv_ptr tcg_fpstatus
;
7837 case 0x3: /* USQADD / SUQADD*/
7838 if (!fp_access_check(s
)) {
7841 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
7843 case 0x7: /* SQABS / SQNEG */
7845 case 0xa: /* CMLT */
7847 unallocated_encoding(s
);
7851 case 0x8: /* CMGT, CMGE */
7852 case 0x9: /* CMEQ, CMLE */
7853 case 0xb: /* ABS, NEG */
7855 unallocated_encoding(s
);
7859 case 0x12: /* SQXTUN */
7861 unallocated_encoding(s
);
7865 case 0x14: /* SQXTN, UQXTN */
7867 unallocated_encoding(s
);
7870 if (!fp_access_check(s
)) {
7873 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
7878 /* Floating point: U, size[1] and opcode indicate operation;
7879 * size[0] indicates single or double precision.
7881 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
7882 size
= extract32(size
, 0, 1) ? 3 : 2;
7884 case 0x2c: /* FCMGT (zero) */
7885 case 0x2d: /* FCMEQ (zero) */
7886 case 0x2e: /* FCMLT (zero) */
7887 case 0x6c: /* FCMGE (zero) */
7888 case 0x6d: /* FCMLE (zero) */
7889 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
7891 case 0x1d: /* SCVTF */
7892 case 0x5d: /* UCVTF */
7894 bool is_signed
= (opcode
== 0x1d);
7895 if (!fp_access_check(s
)) {
7898 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
7901 case 0x3d: /* FRECPE */
7902 case 0x3f: /* FRECPX */
7903 case 0x7d: /* FRSQRTE */
7904 if (!fp_access_check(s
)) {
7907 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
7909 case 0x1a: /* FCVTNS */
7910 case 0x1b: /* FCVTMS */
7911 case 0x3a: /* FCVTPS */
7912 case 0x3b: /* FCVTZS */
7913 case 0x5a: /* FCVTNU */
7914 case 0x5b: /* FCVTMU */
7915 case 0x7a: /* FCVTPU */
7916 case 0x7b: /* FCVTZU */
7918 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
7920 case 0x1c: /* FCVTAS */
7921 case 0x5c: /* FCVTAU */
7922 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
7924 rmode
= FPROUNDING_TIEAWAY
;
7926 case 0x56: /* FCVTXN, FCVTXN2 */
7928 unallocated_encoding(s
);
7931 if (!fp_access_check(s
)) {
7934 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
7937 unallocated_encoding(s
);
7942 unallocated_encoding(s
);
7946 if (!fp_access_check(s
)) {
7951 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
7952 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
7953 tcg_fpstatus
= get_fpstatus_ptr();
7955 TCGV_UNUSED_I32(tcg_rmode
);
7956 TCGV_UNUSED_PTR(tcg_fpstatus
);
7960 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7961 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7963 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
7964 write_fp_dreg(s
, rd
, tcg_rd
);
7965 tcg_temp_free_i64(tcg_rd
);
7966 tcg_temp_free_i64(tcg_rn
);
7968 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7969 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7971 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7974 case 0x7: /* SQABS, SQNEG */
7976 NeonGenOneOpEnvFn
*genfn
;
7977 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
7978 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
7979 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
7980 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
7982 genfn
= fns
[size
][u
];
7983 genfn(tcg_rd
, cpu_env
, tcg_rn
);
7986 case 0x1a: /* FCVTNS */
7987 case 0x1b: /* FCVTMS */
7988 case 0x1c: /* FCVTAS */
7989 case 0x3a: /* FCVTPS */
7990 case 0x3b: /* FCVTZS */
7992 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7993 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7994 tcg_temp_free_i32(tcg_shift
);
7997 case 0x5a: /* FCVTNU */
7998 case 0x5b: /* FCVTMU */
7999 case 0x5c: /* FCVTAU */
8000 case 0x7a: /* FCVTPU */
8001 case 0x7b: /* FCVTZU */
8003 TCGv_i32 tcg_shift
= tcg_const_i32(0);
8004 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
8005 tcg_temp_free_i32(tcg_shift
);
8009 g_assert_not_reached();
8012 write_fp_sreg(s
, rd
, tcg_rd
);
8013 tcg_temp_free_i32(tcg_rd
);
8014 tcg_temp_free_i32(tcg_rn
);
8018 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
8019 tcg_temp_free_i32(tcg_rmode
);
8020 tcg_temp_free_ptr(tcg_fpstatus
);
8024 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
8025 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
8026 int immh
, int immb
, int opcode
, int rn
, int rd
)
8028 int size
= 32 - clz32(immh
) - 1;
8029 int immhb
= immh
<< 3 | immb
;
8030 int shift
= 2 * (8 << size
) - immhb
;
8031 bool accumulate
= false;
8033 bool insert
= false;
8034 int dsize
= is_q
? 128 : 64;
8035 int esize
= 8 << size
;
8036 int elements
= dsize
/esize
;
8037 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
8038 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8039 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8043 if (extract32(immh
, 3, 1) && !is_q
) {
8044 unallocated_encoding(s
);
8048 if (size
> 3 && !is_q
) {
8049 unallocated_encoding(s
);
8053 if (!fp_access_check(s
)) {
8058 case 0x02: /* SSRA / USRA (accumulate) */
8061 case 0x04: /* SRSHR / URSHR (rounding) */
8064 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8065 accumulate
= round
= true;
8067 case 0x08: /* SRI */
8073 uint64_t round_const
= 1ULL << (shift
- 1);
8074 tcg_round
= tcg_const_i64(round_const
);
8076 TCGV_UNUSED_I64(tcg_round
);
8079 for (i
= 0; i
< elements
; i
++) {
8080 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
8081 if (accumulate
|| insert
) {
8082 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
8086 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
8088 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8089 accumulate
, is_u
, size
, shift
);
8092 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8096 clear_vec_high(s
, rd
);
8100 tcg_temp_free_i64(tcg_round
);
8104 /* SHL/SLI - Vector shift left */
8105 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
8106 int immh
, int immb
, int opcode
, int rn
, int rd
)
8108 int size
= 32 - clz32(immh
) - 1;
8109 int immhb
= immh
<< 3 | immb
;
8110 int shift
= immhb
- (8 << size
);
8111 int dsize
= is_q
? 128 : 64;
8112 int esize
= 8 << size
;
8113 int elements
= dsize
/esize
;
8114 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8115 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8118 if (extract32(immh
, 3, 1) && !is_q
) {
8119 unallocated_encoding(s
);
8123 if (size
> 3 && !is_q
) {
8124 unallocated_encoding(s
);
8128 if (!fp_access_check(s
)) {
8132 for (i
= 0; i
< elements
; i
++) {
8133 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
8135 read_vec_element(s
, tcg_rd
, rd
, i
, size
);
8138 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
8140 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8144 clear_vec_high(s
, rd
);
8148 /* USHLL/SHLL - Vector shift left with widening */
8149 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
8150 int immh
, int immb
, int opcode
, int rn
, int rd
)
8152 int size
= 32 - clz32(immh
) - 1;
8153 int immhb
= immh
<< 3 | immb
;
8154 int shift
= immhb
- (8 << size
);
8156 int esize
= 8 << size
;
8157 int elements
= dsize
/esize
;
8158 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8159 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8163 unallocated_encoding(s
);
8167 if (!fp_access_check(s
)) {
8171 /* For the LL variants the store is larger than the load,
8172 * so if rd == rn we would overwrite parts of our input.
8173 * So load everything right now and use shifts in the main loop.
8175 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
8177 for (i
= 0; i
< elements
; i
++) {
8178 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
8179 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
8180 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
8181 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
8185 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
8186 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
8187 int immh
, int immb
, int opcode
, int rn
, int rd
)
8189 int immhb
= immh
<< 3 | immb
;
8190 int size
= 32 - clz32(immh
) - 1;
8192 int esize
= 8 << size
;
8193 int elements
= dsize
/esize
;
8194 int shift
= (2 * esize
) - immhb
;
8195 bool round
= extract32(opcode
, 0, 1);
8196 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
8200 if (extract32(immh
, 3, 1)) {
8201 unallocated_encoding(s
);
8205 if (!fp_access_check(s
)) {
8209 tcg_rn
= tcg_temp_new_i64();
8210 tcg_rd
= tcg_temp_new_i64();
8211 tcg_final
= tcg_temp_new_i64();
8212 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
8215 uint64_t round_const
= 1ULL << (shift
- 1);
8216 tcg_round
= tcg_const_i64(round_const
);
8218 TCGV_UNUSED_I64(tcg_round
);
8221 for (i
= 0; i
< elements
; i
++) {
8222 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
8223 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8224 false, true, size
+1, shift
);
8226 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8230 clear_vec_high(s
, rd
);
8231 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8233 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8237 tcg_temp_free_i64(tcg_round
);
8239 tcg_temp_free_i64(tcg_rn
);
8240 tcg_temp_free_i64(tcg_rd
);
8241 tcg_temp_free_i64(tcg_final
);
8246 /* C3.6.14 AdvSIMD shift by immediate
8247 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8248 * +---+---+---+-------------+------+------+--------+---+------+------+
8249 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8250 * +---+---+---+-------------+------+------+--------+---+------+------+
8252 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
8254 int rd
= extract32(insn
, 0, 5);
8255 int rn
= extract32(insn
, 5, 5);
8256 int opcode
= extract32(insn
, 11, 5);
8257 int immb
= extract32(insn
, 16, 3);
8258 int immh
= extract32(insn
, 19, 4);
8259 bool is_u
= extract32(insn
, 29, 1);
8260 bool is_q
= extract32(insn
, 30, 1);
8263 case 0x08: /* SRI */
8265 unallocated_encoding(s
);
8269 case 0x00: /* SSHR / USHR */
8270 case 0x02: /* SSRA / USRA (accumulate) */
8271 case 0x04: /* SRSHR / URSHR (rounding) */
8272 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8273 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8275 case 0x0a: /* SHL / SLI */
8276 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8278 case 0x10: /* SHRN */
8279 case 0x11: /* RSHRN / SQRSHRUN */
8281 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
8284 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
8287 case 0x12: /* SQSHRN / UQSHRN */
8288 case 0x13: /* SQRSHRN / UQRSHRN */
8289 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
8292 case 0x14: /* SSHLL / USHLL */
8293 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8295 case 0x1c: /* SCVTF / UCVTF */
8296 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
8299 case 0xc: /* SQSHLU */
8301 unallocated_encoding(s
);
8304 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
8306 case 0xe: /* SQSHL, UQSHL */
8307 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
8309 case 0x1f: /* FCVTZS/ FCVTZU */
8310 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
8313 unallocated_encoding(s
);
8318 /* Generate code to do a "long" addition or subtraction, ie one done in
8319 * TCGv_i64 on vector lanes twice the width specified by size.
8321 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
8322 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
8324 static NeonGenTwo64OpFn
* const fns
[3][2] = {
8325 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
8326 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
8327 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
8329 NeonGenTwo64OpFn
*genfn
;
8332 genfn
= fns
[size
][is_sub
];
8333 genfn(tcg_res
, tcg_op1
, tcg_op2
);
8336 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
8337 int opcode
, int rd
, int rn
, int rm
)
8339 /* 3-reg-different widening insns: 64 x 64 -> 128 */
8340 TCGv_i64 tcg_res
[2];
8343 tcg_res
[0] = tcg_temp_new_i64();
8344 tcg_res
[1] = tcg_temp_new_i64();
8346 /* Does this op do an adding accumulate, a subtracting accumulate,
8347 * or no accumulate at all?
8365 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8366 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8369 /* size == 2 means two 32x32->64 operations; this is worth special
8370 * casing because we can generally handle it inline.
8373 for (pass
= 0; pass
< 2; pass
++) {
8374 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8375 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8376 TCGv_i64 tcg_passres
;
8377 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
8379 int elt
= pass
+ is_q
* 2;
8381 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
8382 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
8385 tcg_passres
= tcg_res
[pass
];
8387 tcg_passres
= tcg_temp_new_i64();
8391 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8392 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8394 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8395 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8397 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8398 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8400 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
8401 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
8403 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
8404 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
8405 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
8407 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
8408 tcg_temp_free_i64(tcg_tmp1
);
8409 tcg_temp_free_i64(tcg_tmp2
);
8412 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8413 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8414 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8415 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8417 case 9: /* SQDMLAL, SQDMLAL2 */
8418 case 11: /* SQDMLSL, SQDMLSL2 */
8419 case 13: /* SQDMULL, SQDMULL2 */
8420 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8421 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
8422 tcg_passres
, tcg_passres
);
8425 g_assert_not_reached();
8428 if (opcode
== 9 || opcode
== 11) {
8429 /* saturating accumulate ops */
8431 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
8433 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
8434 tcg_res
[pass
], tcg_passres
);
8435 } else if (accop
> 0) {
8436 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8437 } else if (accop
< 0) {
8438 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8442 tcg_temp_free_i64(tcg_passres
);
8445 tcg_temp_free_i64(tcg_op1
);
8446 tcg_temp_free_i64(tcg_op2
);
8449 /* size 0 or 1, generally helper functions */
8450 for (pass
= 0; pass
< 2; pass
++) {
8451 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8452 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8453 TCGv_i64 tcg_passres
;
8454 int elt
= pass
+ is_q
* 2;
8456 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
8457 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
8460 tcg_passres
= tcg_res
[pass
];
8462 tcg_passres
= tcg_temp_new_i64();
8466 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8467 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8469 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
8470 static NeonGenWidenFn
* const widenfns
[2][2] = {
8471 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8472 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8474 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8476 widenfn(tcg_op2_64
, tcg_op2
);
8477 widenfn(tcg_passres
, tcg_op1
);
8478 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
8479 tcg_passres
, tcg_op2_64
);
8480 tcg_temp_free_i64(tcg_op2_64
);
8483 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8484 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8487 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8489 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8493 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
8495 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
8499 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8500 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8501 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8504 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
8506 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
8510 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8512 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8516 case 9: /* SQDMLAL, SQDMLAL2 */
8517 case 11: /* SQDMLSL, SQDMLSL2 */
8518 case 13: /* SQDMULL, SQDMULL2 */
8520 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8521 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
8522 tcg_passres
, tcg_passres
);
8524 case 14: /* PMULL */
8526 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
8529 g_assert_not_reached();
8531 tcg_temp_free_i32(tcg_op1
);
8532 tcg_temp_free_i32(tcg_op2
);
8535 if (opcode
== 9 || opcode
== 11) {
8536 /* saturating accumulate ops */
8538 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
8540 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
8544 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
8545 tcg_res
[pass
], tcg_passres
);
8547 tcg_temp_free_i64(tcg_passres
);
8552 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8553 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8554 tcg_temp_free_i64(tcg_res
[0]);
8555 tcg_temp_free_i64(tcg_res
[1]);
8558 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
8559 int opcode
, int rd
, int rn
, int rm
)
8561 TCGv_i64 tcg_res
[2];
8562 int part
= is_q
? 2 : 0;
8565 for (pass
= 0; pass
< 2; pass
++) {
8566 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8567 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8568 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
8569 static NeonGenWidenFn
* const widenfns
[3][2] = {
8570 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8571 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8572 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
8574 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8576 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8577 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
8578 widenfn(tcg_op2_wide
, tcg_op2
);
8579 tcg_temp_free_i32(tcg_op2
);
8580 tcg_res
[pass
] = tcg_temp_new_i64();
8581 gen_neon_addl(size
, (opcode
== 3),
8582 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
8583 tcg_temp_free_i64(tcg_op1
);
8584 tcg_temp_free_i64(tcg_op2_wide
);
8587 for (pass
= 0; pass
< 2; pass
++) {
8588 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8589 tcg_temp_free_i64(tcg_res
[pass
]);
8593 static void do_narrow_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8595 tcg_gen_shri_i64(in
, in
, 32);
8596 tcg_gen_trunc_i64_i32(res
, in
);
8599 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8601 tcg_gen_addi_i64(in
, in
, 1U << 31);
8602 do_narrow_high_u32(res
, in
);
8605 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
8606 int opcode
, int rd
, int rn
, int rm
)
8608 TCGv_i32 tcg_res
[2];
8609 int part
= is_q
? 2 : 0;
8612 for (pass
= 0; pass
< 2; pass
++) {
8613 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8614 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8615 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
8616 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
8617 { gen_helper_neon_narrow_high_u8
,
8618 gen_helper_neon_narrow_round_high_u8
},
8619 { gen_helper_neon_narrow_high_u16
,
8620 gen_helper_neon_narrow_round_high_u16
},
8621 { do_narrow_high_u32
, do_narrow_round_high_u32
},
8623 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
8625 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8626 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8628 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
8630 tcg_temp_free_i64(tcg_op1
);
8631 tcg_temp_free_i64(tcg_op2
);
8633 tcg_res
[pass
] = tcg_temp_new_i32();
8634 gennarrow(tcg_res
[pass
], tcg_wideres
);
8635 tcg_temp_free_i64(tcg_wideres
);
8638 for (pass
= 0; pass
< 2; pass
++) {
8639 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
8640 tcg_temp_free_i32(tcg_res
[pass
]);
8643 clear_vec_high(s
, rd
);
8647 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
8649 /* PMULL of 64 x 64 -> 128 is an odd special case because it
8650 * is the only three-reg-diff instruction which produces a
8651 * 128-bit wide result from a single operation. However since
8652 * it's possible to calculate the two halves more or less
8653 * separately we just use two helper calls.
8655 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8656 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8657 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8659 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
8660 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
8661 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
8662 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
8663 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
8664 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
8666 tcg_temp_free_i64(tcg_op1
);
8667 tcg_temp_free_i64(tcg_op2
);
8668 tcg_temp_free_i64(tcg_res
);
8671 /* C3.6.15 AdvSIMD three different
8672 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8673 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8674 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8675 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8677 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8679 /* Instructions in this group fall into three basic classes
8680 * (in each case with the operation working on each element in
8681 * the input vectors):
8682 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
8684 * (2) wide 64 x 128 -> 128
8685 * (3) narrowing 128 x 128 -> 64
8686 * Here we do initial decode, catch unallocated cases and
8687 * dispatch to separate functions for each class.
8689 int is_q
= extract32(insn
, 30, 1);
8690 int is_u
= extract32(insn
, 29, 1);
8691 int size
= extract32(insn
, 22, 2);
8692 int opcode
= extract32(insn
, 12, 4);
8693 int rm
= extract32(insn
, 16, 5);
8694 int rn
= extract32(insn
, 5, 5);
8695 int rd
= extract32(insn
, 0, 5);
8698 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
8699 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
8700 /* 64 x 128 -> 128 */
8702 unallocated_encoding(s
);
8705 if (!fp_access_check(s
)) {
8708 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8710 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
8711 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
8712 /* 128 x 128 -> 64 */
8714 unallocated_encoding(s
);
8717 if (!fp_access_check(s
)) {
8720 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8722 case 14: /* PMULL, PMULL2 */
8723 if (is_u
|| size
== 1 || size
== 2) {
8724 unallocated_encoding(s
);
8728 if (!arm_dc_feature(s
, ARM_FEATURE_V8_PMULL
)) {
8729 unallocated_encoding(s
);
8732 if (!fp_access_check(s
)) {
8735 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
8739 case 9: /* SQDMLAL, SQDMLAL2 */
8740 case 11: /* SQDMLSL, SQDMLSL2 */
8741 case 13: /* SQDMULL, SQDMULL2 */
8742 if (is_u
|| size
== 0) {
8743 unallocated_encoding(s
);
8747 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8748 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8749 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8750 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8751 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8752 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8753 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
8754 /* 64 x 64 -> 128 */
8756 unallocated_encoding(s
);
8760 if (!fp_access_check(s
)) {
8764 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8767 /* opcode 15 not allocated */
8768 unallocated_encoding(s
);
8773 /* Logic op (opcode == 3) subgroup of C3.6.16. */
8774 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
8776 int rd
= extract32(insn
, 0, 5);
8777 int rn
= extract32(insn
, 5, 5);
8778 int rm
= extract32(insn
, 16, 5);
8779 int size
= extract32(insn
, 22, 2);
8780 bool is_u
= extract32(insn
, 29, 1);
8781 bool is_q
= extract32(insn
, 30, 1);
8782 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
8785 if (!fp_access_check(s
)) {
8789 tcg_op1
= tcg_temp_new_i64();
8790 tcg_op2
= tcg_temp_new_i64();
8791 tcg_res
[0] = tcg_temp_new_i64();
8792 tcg_res
[1] = tcg_temp_new_i64();
8794 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
8795 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8796 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8801 tcg_gen_and_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8804 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8807 tcg_gen_or_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8810 tcg_gen_orc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8815 /* B* ops need res loaded to operate on */
8816 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8821 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8823 case 1: /* BSL bitwise select */
8824 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8825 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8826 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op1
);
8828 case 2: /* BIT, bitwise insert if true */
8829 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8830 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8831 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8833 case 3: /* BIF, bitwise insert if false */
8834 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8835 tcg_gen_andc_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8836 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8842 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8844 tcg_gen_movi_i64(tcg_res
[1], 0);
8846 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8848 tcg_temp_free_i64(tcg_op1
);
8849 tcg_temp_free_i64(tcg_op2
);
8850 tcg_temp_free_i64(tcg_res
[0]);
8851 tcg_temp_free_i64(tcg_res
[1]);
8854 /* Helper functions for 32 bit comparisons */
8855 static void gen_max_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8857 tcg_gen_movcond_i32(TCG_COND_GE
, res
, op1
, op2
, op1
, op2
);
8860 static void gen_max_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8862 tcg_gen_movcond_i32(TCG_COND_GEU
, res
, op1
, op2
, op1
, op2
);
8865 static void gen_min_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8867 tcg_gen_movcond_i32(TCG_COND_LE
, res
, op1
, op2
, op1
, op2
);
8870 static void gen_min_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8872 tcg_gen_movcond_i32(TCG_COND_LEU
, res
, op1
, op2
, op1
, op2
);
8875 /* Pairwise op subgroup of C3.6.16.
8877 * This is called directly or via the handle_3same_float for float pairwise
8878 * operations where the opcode and size are calculated differently.
8880 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
8881 int size
, int rn
, int rm
, int rd
)
8886 /* Floating point operations need fpst */
8887 if (opcode
>= 0x58) {
8888 fpst
= get_fpstatus_ptr();
8890 TCGV_UNUSED_PTR(fpst
);
8893 if (!fp_access_check(s
)) {
8897 /* These operations work on the concatenated rm:rn, with each pair of
8898 * adjacent elements being operated on to produce an element in the result.
8901 TCGv_i64 tcg_res
[2];
8903 for (pass
= 0; pass
< 2; pass
++) {
8904 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8905 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8906 int passreg
= (pass
== 0) ? rn
: rm
;
8908 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
8909 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
8910 tcg_res
[pass
] = tcg_temp_new_i64();
8913 case 0x17: /* ADDP */
8914 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8916 case 0x58: /* FMAXNMP */
8917 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8919 case 0x5a: /* FADDP */
8920 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8922 case 0x5e: /* FMAXP */
8923 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8925 case 0x78: /* FMINNMP */
8926 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8928 case 0x7e: /* FMINP */
8929 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8932 g_assert_not_reached();
8935 tcg_temp_free_i64(tcg_op1
);
8936 tcg_temp_free_i64(tcg_op2
);
8939 for (pass
= 0; pass
< 2; pass
++) {
8940 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8941 tcg_temp_free_i64(tcg_res
[pass
]);
8944 int maxpass
= is_q
? 4 : 2;
8945 TCGv_i32 tcg_res
[4];
8947 for (pass
= 0; pass
< maxpass
; pass
++) {
8948 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8949 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8950 NeonGenTwoOpFn
*genfn
= NULL
;
8951 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
8952 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
8954 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
8955 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
8956 tcg_res
[pass
] = tcg_temp_new_i32();
8959 case 0x17: /* ADDP */
8961 static NeonGenTwoOpFn
* const fns
[3] = {
8962 gen_helper_neon_padd_u8
,
8963 gen_helper_neon_padd_u16
,
8969 case 0x14: /* SMAXP, UMAXP */
8971 static NeonGenTwoOpFn
* const fns
[3][2] = {
8972 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
8973 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
8974 { gen_max_s32
, gen_max_u32
},
8976 genfn
= fns
[size
][u
];
8979 case 0x15: /* SMINP, UMINP */
8981 static NeonGenTwoOpFn
* const fns
[3][2] = {
8982 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
8983 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
8984 { gen_min_s32
, gen_min_u32
},
8986 genfn
= fns
[size
][u
];
8989 /* The FP operations are all on single floats (32 bit) */
8990 case 0x58: /* FMAXNMP */
8991 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8993 case 0x5a: /* FADDP */
8994 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8996 case 0x5e: /* FMAXP */
8997 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8999 case 0x78: /* FMINNMP */
9000 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9002 case 0x7e: /* FMINP */
9003 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
9006 g_assert_not_reached();
9009 /* FP ops called directly, otherwise call now */
9011 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9014 tcg_temp_free_i32(tcg_op1
);
9015 tcg_temp_free_i32(tcg_op2
);
9018 for (pass
= 0; pass
< maxpass
; pass
++) {
9019 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9020 tcg_temp_free_i32(tcg_res
[pass
]);
9023 clear_vec_high(s
, rd
);
9027 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
9028 tcg_temp_free_ptr(fpst
);
9032 /* Floating point op subgroup of C3.6.16. */
9033 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
9035 /* For floating point ops, the U, size[1] and opcode bits
9036 * together indicate the operation. size[0] indicates single
9039 int fpopcode
= extract32(insn
, 11, 5)
9040 | (extract32(insn
, 23, 1) << 5)
9041 | (extract32(insn
, 29, 1) << 6);
9042 int is_q
= extract32(insn
, 30, 1);
9043 int size
= extract32(insn
, 22, 1);
9044 int rm
= extract32(insn
, 16, 5);
9045 int rn
= extract32(insn
, 5, 5);
9046 int rd
= extract32(insn
, 0, 5);
9048 int datasize
= is_q
? 128 : 64;
9049 int esize
= 32 << size
;
9050 int elements
= datasize
/ esize
;
9052 if (size
== 1 && !is_q
) {
9053 unallocated_encoding(s
);
9058 case 0x58: /* FMAXNMP */
9059 case 0x5a: /* FADDP */
9060 case 0x5e: /* FMAXP */
9061 case 0x78: /* FMINNMP */
9062 case 0x7e: /* FMINP */
9063 if (size
&& !is_q
) {
9064 unallocated_encoding(s
);
9067 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
9070 case 0x1b: /* FMULX */
9071 case 0x1f: /* FRECPS */
9072 case 0x3f: /* FRSQRTS */
9073 case 0x5d: /* FACGE */
9074 case 0x7d: /* FACGT */
9075 case 0x19: /* FMLA */
9076 case 0x39: /* FMLS */
9077 case 0x18: /* FMAXNM */
9078 case 0x1a: /* FADD */
9079 case 0x1c: /* FCMEQ */
9080 case 0x1e: /* FMAX */
9081 case 0x38: /* FMINNM */
9082 case 0x3a: /* FSUB */
9083 case 0x3e: /* FMIN */
9084 case 0x5b: /* FMUL */
9085 case 0x5c: /* FCMGE */
9086 case 0x5f: /* FDIV */
9087 case 0x7a: /* FABD */
9088 case 0x7c: /* FCMGT */
9089 if (!fp_access_check(s
)) {
9093 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
9096 unallocated_encoding(s
);
9101 /* Integer op subgroup of C3.6.16. */
9102 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
9104 int is_q
= extract32(insn
, 30, 1);
9105 int u
= extract32(insn
, 29, 1);
9106 int size
= extract32(insn
, 22, 2);
9107 int opcode
= extract32(insn
, 11, 5);
9108 int rm
= extract32(insn
, 16, 5);
9109 int rn
= extract32(insn
, 5, 5);
9110 int rd
= extract32(insn
, 0, 5);
9114 case 0x13: /* MUL, PMUL */
9115 if (u
&& size
!= 0) {
9116 unallocated_encoding(s
);
9120 case 0x0: /* SHADD, UHADD */
9121 case 0x2: /* SRHADD, URHADD */
9122 case 0x4: /* SHSUB, UHSUB */
9123 case 0xc: /* SMAX, UMAX */
9124 case 0xd: /* SMIN, UMIN */
9125 case 0xe: /* SABD, UABD */
9126 case 0xf: /* SABA, UABA */
9127 case 0x12: /* MLA, MLS */
9129 unallocated_encoding(s
);
9133 case 0x16: /* SQDMULH, SQRDMULH */
9134 if (size
== 0 || size
== 3) {
9135 unallocated_encoding(s
);
9140 if (size
== 3 && !is_q
) {
9141 unallocated_encoding(s
);
9147 if (!fp_access_check(s
)) {
9153 for (pass
= 0; pass
< 2; pass
++) {
9154 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9155 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9156 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9158 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9159 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9161 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
9163 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9165 tcg_temp_free_i64(tcg_res
);
9166 tcg_temp_free_i64(tcg_op1
);
9167 tcg_temp_free_i64(tcg_op2
);
9170 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9171 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9172 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9173 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9174 NeonGenTwoOpFn
*genfn
= NULL
;
9175 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
9177 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
9178 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
9181 case 0x0: /* SHADD, UHADD */
9183 static NeonGenTwoOpFn
* const fns
[3][2] = {
9184 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
9185 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
9186 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
9188 genfn
= fns
[size
][u
];
9191 case 0x1: /* SQADD, UQADD */
9193 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9194 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9195 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9196 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9198 genenvfn
= fns
[size
][u
];
9201 case 0x2: /* SRHADD, URHADD */
9203 static NeonGenTwoOpFn
* const fns
[3][2] = {
9204 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
9205 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
9206 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
9208 genfn
= fns
[size
][u
];
9211 case 0x4: /* SHSUB, UHSUB */
9213 static NeonGenTwoOpFn
* const fns
[3][2] = {
9214 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
9215 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
9216 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
9218 genfn
= fns
[size
][u
];
9221 case 0x5: /* SQSUB, UQSUB */
9223 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9224 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9225 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9226 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9228 genenvfn
= fns
[size
][u
];
9231 case 0x6: /* CMGT, CMHI */
9233 static NeonGenTwoOpFn
* const fns
[3][2] = {
9234 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_u8
},
9235 { gen_helper_neon_cgt_s16
, gen_helper_neon_cgt_u16
},
9236 { gen_helper_neon_cgt_s32
, gen_helper_neon_cgt_u32
},
9238 genfn
= fns
[size
][u
];
9241 case 0x7: /* CMGE, CMHS */
9243 static NeonGenTwoOpFn
* const fns
[3][2] = {
9244 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_u8
},
9245 { gen_helper_neon_cge_s16
, gen_helper_neon_cge_u16
},
9246 { gen_helper_neon_cge_s32
, gen_helper_neon_cge_u32
},
9248 genfn
= fns
[size
][u
];
9251 case 0x8: /* SSHL, USHL */
9253 static NeonGenTwoOpFn
* const fns
[3][2] = {
9254 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
9255 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
9256 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
9258 genfn
= fns
[size
][u
];
9261 case 0x9: /* SQSHL, UQSHL */
9263 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9264 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9265 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9266 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9268 genenvfn
= fns
[size
][u
];
9271 case 0xa: /* SRSHL, URSHL */
9273 static NeonGenTwoOpFn
* const fns
[3][2] = {
9274 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
9275 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
9276 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
9278 genfn
= fns
[size
][u
];
9281 case 0xb: /* SQRSHL, UQRSHL */
9283 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9284 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9285 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9286 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9288 genenvfn
= fns
[size
][u
];
9291 case 0xc: /* SMAX, UMAX */
9293 static NeonGenTwoOpFn
* const fns
[3][2] = {
9294 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
9295 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
9296 { gen_max_s32
, gen_max_u32
},
9298 genfn
= fns
[size
][u
];
9302 case 0xd: /* SMIN, UMIN */
9304 static NeonGenTwoOpFn
* const fns
[3][2] = {
9305 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
9306 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
9307 { gen_min_s32
, gen_min_u32
},
9309 genfn
= fns
[size
][u
];
9312 case 0xe: /* SABD, UABD */
9313 case 0xf: /* SABA, UABA */
9315 static NeonGenTwoOpFn
* const fns
[3][2] = {
9316 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
9317 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
9318 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
9320 genfn
= fns
[size
][u
];
9323 case 0x10: /* ADD, SUB */
9325 static NeonGenTwoOpFn
* const fns
[3][2] = {
9326 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9327 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9328 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9330 genfn
= fns
[size
][u
];
9333 case 0x11: /* CMTST, CMEQ */
9335 static NeonGenTwoOpFn
* const fns
[3][2] = {
9336 { gen_helper_neon_tst_u8
, gen_helper_neon_ceq_u8
},
9337 { gen_helper_neon_tst_u16
, gen_helper_neon_ceq_u16
},
9338 { gen_helper_neon_tst_u32
, gen_helper_neon_ceq_u32
},
9340 genfn
= fns
[size
][u
];
9343 case 0x13: /* MUL, PMUL */
9347 genfn
= gen_helper_neon_mul_p8
;
9350 /* fall through : MUL */
9351 case 0x12: /* MLA, MLS */
9353 static NeonGenTwoOpFn
* const fns
[3] = {
9354 gen_helper_neon_mul_u8
,
9355 gen_helper_neon_mul_u16
,
9361 case 0x16: /* SQDMULH, SQRDMULH */
9363 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9364 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9365 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9367 assert(size
== 1 || size
== 2);
9368 genenvfn
= fns
[size
- 1][u
];
9372 g_assert_not_reached();
9376 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
9378 genfn(tcg_res
, tcg_op1
, tcg_op2
);
9381 if (opcode
== 0xf || opcode
== 0x12) {
9382 /* SABA, UABA, MLA, MLS: accumulating ops */
9383 static NeonGenTwoOpFn
* const fns
[3][2] = {
9384 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9385 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9386 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9388 bool is_sub
= (opcode
== 0x12 && u
); /* MLS */
9390 genfn
= fns
[size
][is_sub
];
9391 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
9392 genfn(tcg_res
, tcg_op1
, tcg_res
);
9395 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9397 tcg_temp_free_i32(tcg_res
);
9398 tcg_temp_free_i32(tcg_op1
);
9399 tcg_temp_free_i32(tcg_op2
);
9404 clear_vec_high(s
, rd
);
9408 /* C3.6.16 AdvSIMD three same
9409 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
9410 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9411 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
9412 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9414 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
9416 int opcode
= extract32(insn
, 11, 5);
9419 case 0x3: /* logic ops */
9420 disas_simd_3same_logic(s
, insn
);
9422 case 0x17: /* ADDP */
9423 case 0x14: /* SMAXP, UMAXP */
9424 case 0x15: /* SMINP, UMINP */
9426 /* Pairwise operations */
9427 int is_q
= extract32(insn
, 30, 1);
9428 int u
= extract32(insn
, 29, 1);
9429 int size
= extract32(insn
, 22, 2);
9430 int rm
= extract32(insn
, 16, 5);
9431 int rn
= extract32(insn
, 5, 5);
9432 int rd
= extract32(insn
, 0, 5);
9433 if (opcode
== 0x17) {
9434 if (u
|| (size
== 3 && !is_q
)) {
9435 unallocated_encoding(s
);
9440 unallocated_encoding(s
);
9444 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
9448 /* floating point ops, sz[1] and U are part of opcode */
9449 disas_simd_3same_float(s
, insn
);
9452 disas_simd_3same_int(s
, insn
);
9457 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
9458 int size
, int rn
, int rd
)
9460 /* Handle 2-reg-misc ops which are widening (so each size element
9461 * in the source becomes a 2*size element in the destination.
9462 * The only instruction like this is FCVTL.
9467 /* 32 -> 64 bit fp conversion */
9468 TCGv_i64 tcg_res
[2];
9469 int srcelt
= is_q
? 2 : 0;
9471 for (pass
= 0; pass
< 2; pass
++) {
9472 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9473 tcg_res
[pass
] = tcg_temp_new_i64();
9475 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
9476 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
9477 tcg_temp_free_i32(tcg_op
);
9479 for (pass
= 0; pass
< 2; pass
++) {
9480 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9481 tcg_temp_free_i64(tcg_res
[pass
]);
9484 /* 16 -> 32 bit fp conversion */
9485 int srcelt
= is_q
? 4 : 0;
9486 TCGv_i32 tcg_res
[4];
9488 for (pass
= 0; pass
< 4; pass
++) {
9489 tcg_res
[pass
] = tcg_temp_new_i32();
9491 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
9492 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
9495 for (pass
= 0; pass
< 4; pass
++) {
9496 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9497 tcg_temp_free_i32(tcg_res
[pass
]);
9502 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
9503 bool is_q
, int size
, int rn
, int rd
)
9505 int op
= (opcode
<< 1) | u
;
9506 int opsz
= op
+ size
;
9507 int grp_size
= 3 - opsz
;
9508 int dsize
= is_q
? 128 : 64;
9512 unallocated_encoding(s
);
9516 if (!fp_access_check(s
)) {
9521 /* Special case bytes, use bswap op on each group of elements */
9522 int groups
= dsize
/ (8 << grp_size
);
9524 for (i
= 0; i
< groups
; i
++) {
9525 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9527 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
9530 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
9533 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
9536 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
9539 g_assert_not_reached();
9541 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
9542 tcg_temp_free_i64(tcg_tmp
);
9545 clear_vec_high(s
, rd
);
9548 int revmask
= (1 << grp_size
) - 1;
9549 int esize
= 8 << size
;
9550 int elements
= dsize
/ esize
;
9551 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9552 TCGv_i64 tcg_rd
= tcg_const_i64(0);
9553 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
9555 for (i
= 0; i
< elements
; i
++) {
9556 int e_rev
= (i
& 0xf) ^ revmask
;
9557 int off
= e_rev
* esize
;
9558 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
9560 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
9561 tcg_rn
, off
- 64, esize
);
9563 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
9566 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
9567 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
9569 tcg_temp_free_i64(tcg_rd_hi
);
9570 tcg_temp_free_i64(tcg_rd
);
9571 tcg_temp_free_i64(tcg_rn
);
9575 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
9576 bool is_q
, int size
, int rn
, int rd
)
9578 /* Implement the pairwise operations from 2-misc:
9579 * SADDLP, UADDLP, SADALP, UADALP.
9580 * These all add pairs of elements in the input to produce a
9581 * double-width result element in the output (possibly accumulating).
9583 bool accum
= (opcode
== 0x6);
9584 int maxpass
= is_q
? 2 : 1;
9586 TCGv_i64 tcg_res
[2];
9589 /* 32 + 32 -> 64 op */
9590 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
9592 for (pass
= 0; pass
< maxpass
; pass
++) {
9593 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9594 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9596 tcg_res
[pass
] = tcg_temp_new_i64();
9598 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
9599 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
9600 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9602 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
9603 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9606 tcg_temp_free_i64(tcg_op1
);
9607 tcg_temp_free_i64(tcg_op2
);
9610 for (pass
= 0; pass
< maxpass
; pass
++) {
9611 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9612 NeonGenOneOpFn
*genfn
;
9613 static NeonGenOneOpFn
* const fns
[2][2] = {
9614 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
9615 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
9618 genfn
= fns
[size
][u
];
9620 tcg_res
[pass
] = tcg_temp_new_i64();
9622 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9623 genfn(tcg_res
[pass
], tcg_op
);
9626 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
9628 gen_helper_neon_addl_u16(tcg_res
[pass
],
9629 tcg_res
[pass
], tcg_op
);
9631 gen_helper_neon_addl_u32(tcg_res
[pass
],
9632 tcg_res
[pass
], tcg_op
);
9635 tcg_temp_free_i64(tcg_op
);
9639 tcg_res
[1] = tcg_const_i64(0);
9641 for (pass
= 0; pass
< 2; pass
++) {
9642 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9643 tcg_temp_free_i64(tcg_res
[pass
]);
9647 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
9649 /* Implement SHLL and SHLL2 */
9651 int part
= is_q
? 2 : 0;
9652 TCGv_i64 tcg_res
[2];
9654 for (pass
= 0; pass
< 2; pass
++) {
9655 static NeonGenWidenFn
* const widenfns
[3] = {
9656 gen_helper_neon_widen_u8
,
9657 gen_helper_neon_widen_u16
,
9658 tcg_gen_extu_i32_i64
,
9660 NeonGenWidenFn
*widenfn
= widenfns
[size
];
9661 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9663 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
9664 tcg_res
[pass
] = tcg_temp_new_i64();
9665 widenfn(tcg_res
[pass
], tcg_op
);
9666 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
9668 tcg_temp_free_i32(tcg_op
);
9671 for (pass
= 0; pass
< 2; pass
++) {
9672 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9673 tcg_temp_free_i64(tcg_res
[pass
]);
9677 /* C3.6.17 AdvSIMD two reg misc
9678 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9679 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9680 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9681 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9683 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9685 int size
= extract32(insn
, 22, 2);
9686 int opcode
= extract32(insn
, 12, 5);
9687 bool u
= extract32(insn
, 29, 1);
9688 bool is_q
= extract32(insn
, 30, 1);
9689 int rn
= extract32(insn
, 5, 5);
9690 int rd
= extract32(insn
, 0, 5);
9691 bool need_fpstatus
= false;
9692 bool need_rmode
= false;
9695 TCGv_ptr tcg_fpstatus
;
9698 case 0x0: /* REV64, REV32 */
9699 case 0x1: /* REV16 */
9700 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9702 case 0x5: /* CNT, NOT, RBIT */
9703 if (u
&& size
== 0) {
9704 /* NOT: adjust size so we can use the 64-bits-at-a-time loop. */
9707 } else if (u
&& size
== 1) {
9710 } else if (!u
&& size
== 0) {
9714 unallocated_encoding(s
);
9716 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
9717 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
9719 unallocated_encoding(s
);
9722 if (!fp_access_check(s
)) {
9726 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
9728 case 0x4: /* CLS, CLZ */
9730 unallocated_encoding(s
);
9734 case 0x2: /* SADDLP, UADDLP */
9735 case 0x6: /* SADALP, UADALP */
9737 unallocated_encoding(s
);
9740 if (!fp_access_check(s
)) {
9743 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9745 case 0x13: /* SHLL, SHLL2 */
9746 if (u
== 0 || size
== 3) {
9747 unallocated_encoding(s
);
9750 if (!fp_access_check(s
)) {
9753 handle_shll(s
, is_q
, size
, rn
, rd
);
9755 case 0xa: /* CMLT */
9757 unallocated_encoding(s
);
9761 case 0x8: /* CMGT, CMGE */
9762 case 0x9: /* CMEQ, CMLE */
9763 case 0xb: /* ABS, NEG */
9764 if (size
== 3 && !is_q
) {
9765 unallocated_encoding(s
);
9769 case 0x3: /* SUQADD, USQADD */
9770 if (size
== 3 && !is_q
) {
9771 unallocated_encoding(s
);
9774 if (!fp_access_check(s
)) {
9777 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
9779 case 0x7: /* SQABS, SQNEG */
9780 if (size
== 3 && !is_q
) {
9781 unallocated_encoding(s
);
9789 /* Floating point: U, size[1] and opcode indicate operation;
9790 * size[0] indicates single or double precision.
9792 int is_double
= extract32(size
, 0, 1);
9793 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9794 size
= is_double
? 3 : 2;
9796 case 0x2f: /* FABS */
9797 case 0x6f: /* FNEG */
9798 if (size
== 3 && !is_q
) {
9799 unallocated_encoding(s
);
9803 case 0x1d: /* SCVTF */
9804 case 0x5d: /* UCVTF */
9806 bool is_signed
= (opcode
== 0x1d) ? true : false;
9807 int elements
= is_double
? 2 : is_q
? 4 : 2;
9808 if (is_double
&& !is_q
) {
9809 unallocated_encoding(s
);
9812 if (!fp_access_check(s
)) {
9815 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
9818 case 0x2c: /* FCMGT (zero) */
9819 case 0x2d: /* FCMEQ (zero) */
9820 case 0x2e: /* FCMLT (zero) */
9821 case 0x6c: /* FCMGE (zero) */
9822 case 0x6d: /* FCMLE (zero) */
9823 if (size
== 3 && !is_q
) {
9824 unallocated_encoding(s
);
9827 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9829 case 0x7f: /* FSQRT */
9830 if (size
== 3 && !is_q
) {
9831 unallocated_encoding(s
);
9835 case 0x1a: /* FCVTNS */
9836 case 0x1b: /* FCVTMS */
9837 case 0x3a: /* FCVTPS */
9838 case 0x3b: /* FCVTZS */
9839 case 0x5a: /* FCVTNU */
9840 case 0x5b: /* FCVTMU */
9841 case 0x7a: /* FCVTPU */
9842 case 0x7b: /* FCVTZU */
9843 need_fpstatus
= true;
9845 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9846 if (size
== 3 && !is_q
) {
9847 unallocated_encoding(s
);
9851 case 0x5c: /* FCVTAU */
9852 case 0x1c: /* FCVTAS */
9853 need_fpstatus
= true;
9855 rmode
= FPROUNDING_TIEAWAY
;
9856 if (size
== 3 && !is_q
) {
9857 unallocated_encoding(s
);
9861 case 0x3c: /* URECPE */
9863 unallocated_encoding(s
);
9867 case 0x3d: /* FRECPE */
9868 case 0x7d: /* FRSQRTE */
9869 if (size
== 3 && !is_q
) {
9870 unallocated_encoding(s
);
9873 if (!fp_access_check(s
)) {
9876 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9878 case 0x56: /* FCVTXN, FCVTXN2 */
9880 unallocated_encoding(s
);
9884 case 0x16: /* FCVTN, FCVTN2 */
9885 /* handle_2misc_narrow does a 2*size -> size operation, but these
9886 * instructions encode the source size rather than dest size.
9888 if (!fp_access_check(s
)) {
9891 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
9893 case 0x17: /* FCVTL, FCVTL2 */
9894 if (!fp_access_check(s
)) {
9897 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
9899 case 0x18: /* FRINTN */
9900 case 0x19: /* FRINTM */
9901 case 0x38: /* FRINTP */
9902 case 0x39: /* FRINTZ */
9904 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9906 case 0x59: /* FRINTX */
9907 case 0x79: /* FRINTI */
9908 need_fpstatus
= true;
9909 if (size
== 3 && !is_q
) {
9910 unallocated_encoding(s
);
9914 case 0x58: /* FRINTA */
9916 rmode
= FPROUNDING_TIEAWAY
;
9917 need_fpstatus
= true;
9918 if (size
== 3 && !is_q
) {
9919 unallocated_encoding(s
);
9923 case 0x7c: /* URSQRTE */
9925 unallocated_encoding(s
);
9928 need_fpstatus
= true;
9931 unallocated_encoding(s
);
9937 unallocated_encoding(s
);
9941 if (!fp_access_check(s
)) {
9945 if (need_fpstatus
) {
9946 tcg_fpstatus
= get_fpstatus_ptr();
9948 TCGV_UNUSED_PTR(tcg_fpstatus
);
9951 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
9952 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
9954 TCGV_UNUSED_I32(tcg_rmode
);
9958 /* All 64-bit element operations can be shared with scalar 2misc */
9961 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
9962 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9963 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9965 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9967 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
9968 tcg_rmode
, tcg_fpstatus
);
9970 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9972 tcg_temp_free_i64(tcg_res
);
9973 tcg_temp_free_i64(tcg_op
);
9978 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9979 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9980 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9983 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
9986 /* Special cases for 32 bit elements */
9988 case 0xa: /* CMLT */
9989 /* 32 bit integer comparison against zero, result is
9990 * test ? (2^32 - 1) : 0. We implement via setcond(test)
9995 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
9996 tcg_gen_neg_i32(tcg_res
, tcg_res
);
9998 case 0x8: /* CMGT, CMGE */
9999 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
10001 case 0x9: /* CMEQ, CMLE */
10002 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
10004 case 0x4: /* CLS */
10006 gen_helper_clz32(tcg_res
, tcg_op
);
10008 gen_helper_cls32(tcg_res
, tcg_op
);
10011 case 0x7: /* SQABS, SQNEG */
10013 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
10015 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
10018 case 0xb: /* ABS, NEG */
10020 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10022 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10023 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10024 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
10025 tcg_zero
, tcg_op
, tcg_res
);
10026 tcg_temp_free_i32(tcg_zero
);
10029 case 0x2f: /* FABS */
10030 gen_helper_vfp_abss(tcg_res
, tcg_op
);
10032 case 0x6f: /* FNEG */
10033 gen_helper_vfp_negs(tcg_res
, tcg_op
);
10035 case 0x7f: /* FSQRT */
10036 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
10038 case 0x1a: /* FCVTNS */
10039 case 0x1b: /* FCVTMS */
10040 case 0x1c: /* FCVTAS */
10041 case 0x3a: /* FCVTPS */
10042 case 0x3b: /* FCVTZS */
10044 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10045 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
10046 tcg_shift
, tcg_fpstatus
);
10047 tcg_temp_free_i32(tcg_shift
);
10050 case 0x5a: /* FCVTNU */
10051 case 0x5b: /* FCVTMU */
10052 case 0x5c: /* FCVTAU */
10053 case 0x7a: /* FCVTPU */
10054 case 0x7b: /* FCVTZU */
10056 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10057 gen_helper_vfp_touls(tcg_res
, tcg_op
,
10058 tcg_shift
, tcg_fpstatus
);
10059 tcg_temp_free_i32(tcg_shift
);
10062 case 0x18: /* FRINTN */
10063 case 0x19: /* FRINTM */
10064 case 0x38: /* FRINTP */
10065 case 0x39: /* FRINTZ */
10066 case 0x58: /* FRINTA */
10067 case 0x79: /* FRINTI */
10068 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
10070 case 0x59: /* FRINTX */
10071 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
10073 case 0x7c: /* URSQRTE */
10074 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
10077 g_assert_not_reached();
10080 /* Use helpers for 8 and 16 bit elements */
10082 case 0x5: /* CNT, RBIT */
10083 /* For these two insns size is part of the opcode specifier
10084 * (handled earlier); they always operate on byte elements.
10087 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
10089 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
10092 case 0x7: /* SQABS, SQNEG */
10094 NeonGenOneOpEnvFn
*genfn
;
10095 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
10096 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
10097 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
10099 genfn
= fns
[size
][u
];
10100 genfn(tcg_res
, cpu_env
, tcg_op
);
10103 case 0x8: /* CMGT, CMGE */
10104 case 0x9: /* CMEQ, CMLE */
10105 case 0xa: /* CMLT */
10107 static NeonGenTwoOpFn
* const fns
[3][2] = {
10108 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
10109 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
10110 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
10112 NeonGenTwoOpFn
*genfn
;
10115 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10117 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
10118 comp
= (opcode
- 0x8) * 2 + u
;
10119 /* ...but LE, LT are implemented as reverse GE, GT */
10120 reverse
= (comp
> 2);
10124 genfn
= fns
[comp
][size
];
10126 genfn(tcg_res
, tcg_zero
, tcg_op
);
10128 genfn(tcg_res
, tcg_op
, tcg_zero
);
10130 tcg_temp_free_i32(tcg_zero
);
10133 case 0xb: /* ABS, NEG */
10135 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10137 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
10139 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
10141 tcg_temp_free_i32(tcg_zero
);
10144 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
10146 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
10150 case 0x4: /* CLS, CLZ */
10153 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
10155 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
10159 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
10161 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
10166 g_assert_not_reached();
10170 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10172 tcg_temp_free_i32(tcg_res
);
10173 tcg_temp_free_i32(tcg_op
);
10177 clear_vec_high(s
, rd
);
10181 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10182 tcg_temp_free_i32(tcg_rmode
);
10184 if (need_fpstatus
) {
10185 tcg_temp_free_ptr(tcg_fpstatus
);
10189 /* C3.6.13 AdvSIMD scalar x indexed element
10190 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10191 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10192 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10193 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10194 * C3.6.18 AdvSIMD vector x indexed element
10195 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10196 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10197 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10198 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10200 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
10202 /* This encoding has two kinds of instruction:
10203 * normal, where we perform elt x idxelt => elt for each
10204 * element in the vector
10205 * long, where we perform elt x idxelt and generate a result of
10206 * double the width of the input element
10207 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
10209 bool is_scalar
= extract32(insn
, 28, 1);
10210 bool is_q
= extract32(insn
, 30, 1);
10211 bool u
= extract32(insn
, 29, 1);
10212 int size
= extract32(insn
, 22, 2);
10213 int l
= extract32(insn
, 21, 1);
10214 int m
= extract32(insn
, 20, 1);
10215 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
10216 int rm
= extract32(insn
, 16, 4);
10217 int opcode
= extract32(insn
, 12, 4);
10218 int h
= extract32(insn
, 11, 1);
10219 int rn
= extract32(insn
, 5, 5);
10220 int rd
= extract32(insn
, 0, 5);
10221 bool is_long
= false;
10222 bool is_fp
= false;
10227 case 0x0: /* MLA */
10228 case 0x4: /* MLS */
10229 if (!u
|| is_scalar
) {
10230 unallocated_encoding(s
);
10234 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10235 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10236 case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
10238 unallocated_encoding(s
);
10243 case 0x3: /* SQDMLAL, SQDMLAL2 */
10244 case 0x7: /* SQDMLSL, SQDMLSL2 */
10245 case 0xb: /* SQDMULL, SQDMULL2 */
10248 case 0xc: /* SQDMULH */
10249 case 0xd: /* SQRDMULH */
10251 unallocated_encoding(s
);
10255 case 0x8: /* MUL */
10256 if (u
|| is_scalar
) {
10257 unallocated_encoding(s
);
10261 case 0x1: /* FMLA */
10262 case 0x5: /* FMLS */
10264 unallocated_encoding(s
);
10268 case 0x9: /* FMUL, FMULX */
10269 if (!extract32(size
, 1, 1)) {
10270 unallocated_encoding(s
);
10276 unallocated_encoding(s
);
10281 /* low bit of size indicates single/double */
10282 size
= extract32(size
, 0, 1) ? 3 : 2;
10284 index
= h
<< 1 | l
;
10287 unallocated_encoding(s
);
10296 index
= h
<< 2 | l
<< 1 | m
;
10299 index
= h
<< 1 | l
;
10303 unallocated_encoding(s
);
10308 if (!fp_access_check(s
)) {
10313 fpst
= get_fpstatus_ptr();
10315 TCGV_UNUSED_PTR(fpst
);
10319 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10322 assert(is_fp
&& is_q
&& !is_long
);
10324 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
10326 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10327 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10328 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10330 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10333 case 0x5: /* FMLS */
10334 /* As usual for ARM, separate negation for fused multiply-add */
10335 gen_helper_vfp_negd(tcg_op
, tcg_op
);
10337 case 0x1: /* FMLA */
10338 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10339 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10341 case 0x9: /* FMUL, FMULX */
10343 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10345 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10349 g_assert_not_reached();
10352 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10353 tcg_temp_free_i64(tcg_op
);
10354 tcg_temp_free_i64(tcg_res
);
10358 clear_vec_high(s
, rd
);
10361 tcg_temp_free_i64(tcg_idx
);
10362 } else if (!is_long
) {
10363 /* 32 bit floating point, or 16 or 32 bit integer.
10364 * For the 16 bit scalar case we use the usual Neon helpers and
10365 * rely on the fact that 0 op 0 == 0 with no side effects.
10367 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10368 int pass
, maxpasses
;
10373 maxpasses
= is_q
? 4 : 2;
10376 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10378 if (size
== 1 && !is_scalar
) {
10379 /* The simplest way to handle the 16x16 indexed ops is to duplicate
10380 * the index into both halves of the 32 bit tcg_idx and then use
10381 * the usual Neon helpers.
10383 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10386 for (pass
= 0; pass
< maxpasses
; pass
++) {
10387 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10388 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10390 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
10393 case 0x0: /* MLA */
10394 case 0x4: /* MLS */
10395 case 0x8: /* MUL */
10397 static NeonGenTwoOpFn
* const fns
[2][2] = {
10398 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
10399 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
10401 NeonGenTwoOpFn
*genfn
;
10402 bool is_sub
= opcode
== 0x4;
10405 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
10407 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
10409 if (opcode
== 0x8) {
10412 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
10413 genfn
= fns
[size
- 1][is_sub
];
10414 genfn(tcg_res
, tcg_op
, tcg_res
);
10417 case 0x5: /* FMLS */
10418 /* As usual for ARM, separate negation for fused multiply-add */
10419 gen_helper_vfp_negs(tcg_op
, tcg_op
);
10421 case 0x1: /* FMLA */
10422 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10423 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10425 case 0x9: /* FMUL, FMULX */
10427 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10429 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10432 case 0xc: /* SQDMULH */
10434 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
10437 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
10441 case 0xd: /* SQRDMULH */
10443 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
10446 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
10451 g_assert_not_reached();
10455 write_fp_sreg(s
, rd
, tcg_res
);
10457 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10460 tcg_temp_free_i32(tcg_op
);
10461 tcg_temp_free_i32(tcg_res
);
10464 tcg_temp_free_i32(tcg_idx
);
10467 clear_vec_high(s
, rd
);
10470 /* long ops: 16x16->32 or 32x32->64 */
10471 TCGv_i64 tcg_res
[2];
10473 bool satop
= extract32(opcode
, 0, 1);
10474 TCGMemOp memop
= MO_32
;
10481 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10483 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
10485 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10486 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10487 TCGv_i64 tcg_passres
;
10493 passelt
= pass
+ (is_q
* 2);
10496 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
10498 tcg_res
[pass
] = tcg_temp_new_i64();
10500 if (opcode
== 0xa || opcode
== 0xb) {
10501 /* Non-accumulating ops */
10502 tcg_passres
= tcg_res
[pass
];
10504 tcg_passres
= tcg_temp_new_i64();
10507 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
10508 tcg_temp_free_i64(tcg_op
);
10511 /* saturating, doubling */
10512 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10513 tcg_passres
, tcg_passres
);
10516 if (opcode
== 0xa || opcode
== 0xb) {
10520 /* Accumulating op: handle accumulate step */
10521 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10524 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10525 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10527 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10528 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10530 case 0x7: /* SQDMLSL, SQDMLSL2 */
10531 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10533 case 0x3: /* SQDMLAL, SQDMLAL2 */
10534 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10539 g_assert_not_reached();
10541 tcg_temp_free_i64(tcg_passres
);
10543 tcg_temp_free_i64(tcg_idx
);
10546 clear_vec_high(s
, rd
);
10549 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10552 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10555 /* The simplest way to handle the 16x16 indexed ops is to
10556 * duplicate the index into both halves of the 32 bit tcg_idx
10557 * and then use the usual Neon helpers.
10559 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10562 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10563 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10564 TCGv_i64 tcg_passres
;
10567 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10569 read_vec_element_i32(s
, tcg_op
, rn
,
10570 pass
+ (is_q
* 2), MO_32
);
10573 tcg_res
[pass
] = tcg_temp_new_i64();
10575 if (opcode
== 0xa || opcode
== 0xb) {
10576 /* Non-accumulating ops */
10577 tcg_passres
= tcg_res
[pass
];
10579 tcg_passres
= tcg_temp_new_i64();
10582 if (memop
& MO_SIGN
) {
10583 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
10585 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
10588 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10589 tcg_passres
, tcg_passres
);
10591 tcg_temp_free_i32(tcg_op
);
10593 if (opcode
== 0xa || opcode
== 0xb) {
10597 /* Accumulating op: handle accumulate step */
10598 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10601 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10602 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
10605 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10606 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
10609 case 0x7: /* SQDMLSL, SQDMLSL2 */
10610 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10612 case 0x3: /* SQDMLAL, SQDMLAL2 */
10613 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10618 g_assert_not_reached();
10620 tcg_temp_free_i64(tcg_passres
);
10622 tcg_temp_free_i32(tcg_idx
);
10625 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
10630 tcg_res
[1] = tcg_const_i64(0);
10633 for (pass
= 0; pass
< 2; pass
++) {
10634 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10635 tcg_temp_free_i64(tcg_res
[pass
]);
10639 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
10640 tcg_temp_free_ptr(fpst
);
10644 /* C3.6.19 Crypto AES
10645 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10646 * +-----------------+------+-----------+--------+-----+------+------+
10647 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10648 * +-----------------+------+-----------+--------+-----+------+------+
10650 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
10652 int size
= extract32(insn
, 22, 2);
10653 int opcode
= extract32(insn
, 12, 5);
10654 int rn
= extract32(insn
, 5, 5);
10655 int rd
= extract32(insn
, 0, 5);
10657 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
;
10658 CryptoThreeOpEnvFn
*genfn
;
10660 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)
10662 unallocated_encoding(s
);
10667 case 0x4: /* AESE */
10669 genfn
= gen_helper_crypto_aese
;
10671 case 0x6: /* AESMC */
10673 genfn
= gen_helper_crypto_aesmc
;
10675 case 0x5: /* AESD */
10677 genfn
= gen_helper_crypto_aese
;
10679 case 0x7: /* AESIMC */
10681 genfn
= gen_helper_crypto_aesmc
;
10684 unallocated_encoding(s
);
10688 /* Note that we convert the Vx register indexes into the
10689 * index within the vfp.regs[] array, so we can share the
10690 * helper with the AArch32 instructions.
10692 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10693 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10694 tcg_decrypt
= tcg_const_i32(decrypt
);
10696 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
);
10698 tcg_temp_free_i32(tcg_rd_regno
);
10699 tcg_temp_free_i32(tcg_rn_regno
);
10700 tcg_temp_free_i32(tcg_decrypt
);
10703 /* C3.6.20 Crypto three-reg SHA
10704 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
10705 * +-----------------+------+---+------+---+--------+-----+------+------+
10706 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
10707 * +-----------------+------+---+------+---+--------+-----+------+------+
10709 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
10711 int size
= extract32(insn
, 22, 2);
10712 int opcode
= extract32(insn
, 12, 3);
10713 int rm
= extract32(insn
, 16, 5);
10714 int rn
= extract32(insn
, 5, 5);
10715 int rd
= extract32(insn
, 0, 5);
10716 CryptoThreeOpEnvFn
*genfn
;
10717 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
;
10718 int feature
= ARM_FEATURE_V8_SHA256
;
10721 unallocated_encoding(s
);
10726 case 0: /* SHA1C */
10727 case 1: /* SHA1P */
10728 case 2: /* SHA1M */
10729 case 3: /* SHA1SU0 */
10731 feature
= ARM_FEATURE_V8_SHA1
;
10733 case 4: /* SHA256H */
10734 genfn
= gen_helper_crypto_sha256h
;
10736 case 5: /* SHA256H2 */
10737 genfn
= gen_helper_crypto_sha256h2
;
10739 case 6: /* SHA256SU1 */
10740 genfn
= gen_helper_crypto_sha256su1
;
10743 unallocated_encoding(s
);
10747 if (!arm_dc_feature(s
, feature
)) {
10748 unallocated_encoding(s
);
10752 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10753 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10754 tcg_rm_regno
= tcg_const_i32(rm
<< 1);
10757 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
);
10759 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
10761 gen_helper_crypto_sha1_3reg(cpu_env
, tcg_rd_regno
,
10762 tcg_rn_regno
, tcg_rm_regno
, tcg_opcode
);
10763 tcg_temp_free_i32(tcg_opcode
);
10766 tcg_temp_free_i32(tcg_rd_regno
);
10767 tcg_temp_free_i32(tcg_rn_regno
);
10768 tcg_temp_free_i32(tcg_rm_regno
);
10771 /* C3.6.21 Crypto two-reg SHA
10772 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10773 * +-----------------+------+-----------+--------+-----+------+------+
10774 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10775 * +-----------------+------+-----------+--------+-----+------+------+
10777 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
10779 int size
= extract32(insn
, 22, 2);
10780 int opcode
= extract32(insn
, 12, 5);
10781 int rn
= extract32(insn
, 5, 5);
10782 int rd
= extract32(insn
, 0, 5);
10783 CryptoTwoOpEnvFn
*genfn
;
10785 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
;
10788 unallocated_encoding(s
);
10793 case 0: /* SHA1H */
10794 feature
= ARM_FEATURE_V8_SHA1
;
10795 genfn
= gen_helper_crypto_sha1h
;
10797 case 1: /* SHA1SU1 */
10798 feature
= ARM_FEATURE_V8_SHA1
;
10799 genfn
= gen_helper_crypto_sha1su1
;
10801 case 2: /* SHA256SU0 */
10802 feature
= ARM_FEATURE_V8_SHA256
;
10803 genfn
= gen_helper_crypto_sha256su0
;
10806 unallocated_encoding(s
);
10810 if (!arm_dc_feature(s
, feature
)) {
10811 unallocated_encoding(s
);
10815 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10816 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10818 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
);
10820 tcg_temp_free_i32(tcg_rd_regno
);
10821 tcg_temp_free_i32(tcg_rn_regno
);
10824 /* C3.6 Data processing - SIMD, inc Crypto
10826 * As the decode gets a little complex we are using a table based
10827 * approach for this part of the decode.
10829 static const AArch64DecodeTable data_proc_simd
[] = {
10830 /* pattern , mask , fn */
10831 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
10832 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
10833 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
10834 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
10835 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
10836 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
10837 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
10838 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
10839 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
10840 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
10841 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
10842 { 0x2e000000, 0xbf208400, disas_simd_ext
},
10843 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
10844 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
10845 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
10846 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
10847 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
10848 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
10849 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
10850 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
10851 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
10852 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
10853 { 0x00000000, 0x00000000, NULL
}
10856 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
10858 /* Note that this is called with all non-FP cases from
10859 * table C3-6 so it must UNDEF for entries not specifically
10860 * allocated to instructions in that table.
10862 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
10866 unallocated_encoding(s
);
10870 /* C3.6 Data processing - SIMD and floating point */
10871 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
10873 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
10874 disas_data_proc_fp(s
, insn
);
10876 /* SIMD, including crypto */
10877 disas_data_proc_simd(s
, insn
);
10881 /* C3.1 A64 instruction index by encoding */
10882 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
10886 insn
= arm_ldl_code(env
, s
->pc
, s
->bswap_code
);
10890 s
->fp_access_checked
= false;
10892 switch (extract32(insn
, 25, 4)) {
10893 case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
10894 unallocated_encoding(s
);
10896 case 0x8: case 0x9: /* Data processing - immediate */
10897 disas_data_proc_imm(s
, insn
);
10899 case 0xa: case 0xb: /* Branch, exception generation and system insns */
10900 disas_b_exc_sys(s
, insn
);
10905 case 0xe: /* Loads and stores */
10906 disas_ldst(s
, insn
);
10909 case 0xd: /* Data processing - register */
10910 disas_data_proc_reg(s
, insn
);
10913 case 0xf: /* Data processing - SIMD and floating point */
10914 disas_data_proc_simd_fp(s
, insn
);
10917 assert(FALSE
); /* all 15 cases should be handled above */
10921 /* if we allocated any temporaries, free them here */
10925 void gen_intermediate_code_internal_a64(ARMCPU
*cpu
,
10926 TranslationBlock
*tb
,
10929 CPUState
*cs
= CPU(cpu
);
10930 CPUARMState
*env
= &cpu
->env
;
10931 DisasContext dc1
, *dc
= &dc1
;
10934 target_ulong pc_start
;
10935 target_ulong next_page_start
;
10943 dc
->is_jmp
= DISAS_NEXT
;
10945 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
10949 dc
->el3_is_aa64
= arm_el_is_aa64(env
, 3);
10951 dc
->bswap_code
= 0;
10952 dc
->condexec_mask
= 0;
10953 dc
->condexec_cond
= 0;
10954 dc
->mmu_idx
= ARM_TBFLAG_MMUIDX(tb
->flags
);
10955 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
10956 #if !defined(CONFIG_USER_ONLY)
10957 dc
->user
= (dc
->current_el
== 0);
10959 dc
->fp_excp_el
= ARM_TBFLAG_FPEXC_EL(tb
->flags
);
10961 dc
->vec_stride
= 0;
10962 dc
->cp_regs
= cpu
->cp_regs
;
10963 dc
->features
= env
->features
;
10965 /* Single step state. The code-generation logic here is:
10967 * generate code with no special handling for single-stepping (except
10968 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
10969 * this happens anyway because those changes are all system register or
10971 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
10972 * emit code for one insn
10973 * emit code to clear PSTATE.SS
10974 * emit code to generate software step exception for completed step
10975 * end TB (as usual for having generated an exception)
10976 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
10977 * emit code to generate a software step exception
10980 dc
->ss_active
= ARM_TBFLAG_SS_ACTIVE(tb
->flags
);
10981 dc
->pstate_ss
= ARM_TBFLAG_PSTATE_SS(tb
->flags
);
10982 dc
->is_ldex
= false;
10983 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
10985 init_tmp_a64_array(dc
);
10987 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
10990 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
10991 if (max_insns
== 0) {
10992 max_insns
= CF_COUNT_MASK
;
10997 tcg_clear_temp_count();
11000 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
11001 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
11002 if (bp
->pc
== dc
->pc
) {
11003 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
11004 /* Advance PC so that clearing the breakpoint will
11005 invalidate this TB. */
11007 goto done_generating
;
11013 j
= tcg_op_buf_count();
11017 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
11020 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
11021 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
11022 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
11025 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
11029 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
11030 tcg_gen_debug_insn_start(dc
->pc
);
11033 if (dc
->ss_active
&& !dc
->pstate_ss
) {
11034 /* Singlestep state is Active-pending.
11035 * If we're in this state at the start of a TB then either
11036 * a) we just took an exception to an EL which is being debugged
11037 * and this is the first insn in the exception handler
11038 * b) debug exceptions were masked and we just unmasked them
11039 * without changing EL (eg by clearing PSTATE.D)
11040 * In either case we're going to take a swstep exception in the
11041 * "did not step an insn" case, and so the syndrome ISV and EX
11042 * bits should be zero.
11044 assert(num_insns
== 0);
11045 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0),
11046 default_exception_el(dc
));
11047 dc
->is_jmp
= DISAS_EXC
;
11051 disas_a64_insn(env
, dc
);
11053 if (tcg_check_temp_count()) {
11054 fprintf(stderr
, "TCG temporary leak before "TARGET_FMT_lx
"\n",
11058 /* Translation stops when a conditional branch is encountered.
11059 * Otherwise the subsequent code could get translated several times.
11060 * Also stop translation when a page boundary is reached. This
11061 * ensures prefetch aborts occur at the right place.
11064 } while (!dc
->is_jmp
&& !tcg_op_buf_full() &&
11065 !cs
->singlestep_enabled
&&
11068 dc
->pc
< next_page_start
&&
11069 num_insns
< max_insns
);
11071 if (tb
->cflags
& CF_LAST_IO
) {
11075 if (unlikely(cs
->singlestep_enabled
|| dc
->ss_active
)
11076 && dc
->is_jmp
!= DISAS_EXC
) {
11077 /* Note that this means single stepping WFI doesn't halt the CPU.
11078 * For conditional branch insns this is harmless unreachable code as
11079 * gen_goto_tb() has already handled emitting the debug exception
11080 * (and thus a tb-jump is not possible when singlestepping).
11082 assert(dc
->is_jmp
!= DISAS_TB_JUMP
);
11083 if (dc
->is_jmp
!= DISAS_JUMP
) {
11084 gen_a64_set_pc_im(dc
->pc
);
11086 if (cs
->singlestep_enabled
) {
11087 gen_exception_internal(EXCP_DEBUG
);
11089 gen_step_complete_exception(dc
);
11092 switch (dc
->is_jmp
) {
11094 gen_goto_tb(dc
, 1, dc
->pc
);
11098 gen_a64_set_pc_im(dc
->pc
);
11101 /* indicate that the hash table must be used to find the next TB */
11102 tcg_gen_exit_tb(0);
11104 case DISAS_TB_JUMP
:
11109 gen_a64_set_pc_im(dc
->pc
);
11110 gen_helper_wfe(cpu_env
);
11113 gen_a64_set_pc_im(dc
->pc
);
11114 gen_helper_yield(cpu_env
);
11117 /* This is a special case because we don't want to just halt the CPU
11118 * if trying to debug across a WFI.
11120 gen_a64_set_pc_im(dc
->pc
);
11121 gen_helper_wfi(cpu_env
);
11122 /* The helper doesn't necessarily throw an exception, but we
11123 * must go back to the main loop to check for interrupts anyway.
11125 tcg_gen_exit_tb(0);
11131 gen_tb_end(tb
, num_insns
);
11134 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
11135 qemu_log("----------------\n");
11136 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
11137 log_target_disas(cs
, pc_start
, dc
->pc
- pc_start
,
11138 4 | (dc
->bswap_code
<< 1));
11143 j
= tcg_op_buf_count();
11146 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
11149 tb
->size
= dc
->pc
- pc_start
;
11150 tb
->icount
= num_insns
;