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
)
202 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
203 TCGv_i32 tcg_syn
= tcg_const_i32(syndrome
);
205 gen_helper_exception_with_syndrome(cpu_env
, tcg_excp
, tcg_syn
);
206 tcg_temp_free_i32(tcg_syn
);
207 tcg_temp_free_i32(tcg_excp
);
210 static void gen_exception_internal_insn(DisasContext
*s
, int offset
, int excp
)
212 gen_a64_set_pc_im(s
->pc
- offset
);
213 gen_exception_internal(excp
);
214 s
->is_jmp
= DISAS_EXC
;
217 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
,
220 gen_a64_set_pc_im(s
->pc
- offset
);
221 gen_exception(excp
, syndrome
);
222 s
->is_jmp
= DISAS_EXC
;
225 static void gen_ss_advance(DisasContext
*s
)
227 /* If the singlestep state is Active-not-pending, advance to
232 gen_helper_clear_pstate_ss(cpu_env
);
236 static void gen_step_complete_exception(DisasContext
*s
)
238 /* We just completed step of an insn. Move from Active-not-pending
239 * to Active-pending, and then also take the swstep exception.
240 * This corresponds to making the (IMPDEF) choice to prioritize
241 * swstep exceptions over asynchronous exceptions taken to an exception
242 * level where debug is disabled. This choice has the advantage that
243 * we do not need to maintain internal state corresponding to the
244 * ISV/EX syndrome bits between completion of the step and generation
245 * of the exception, and our syndrome information is always correct.
248 gen_exception(EXCP_UDEF
, syn_swstep(s
->ss_same_el
, 1, s
->is_ldex
));
249 s
->is_jmp
= DISAS_EXC
;
252 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
254 /* No direct tb linking with singlestep (either QEMU's or the ARM
255 * debug architecture kind) or deterministic io
257 if (s
->singlestep_enabled
|| s
->ss_active
|| (s
->tb
->cflags
& CF_LAST_IO
)) {
261 /* Only link tbs from inside the same guest page */
262 if ((s
->tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
269 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
271 TranslationBlock
*tb
;
274 if (use_goto_tb(s
, n
, dest
)) {
276 gen_a64_set_pc_im(dest
);
277 tcg_gen_exit_tb((intptr_t)tb
+ n
);
278 s
->is_jmp
= DISAS_TB_JUMP
;
280 gen_a64_set_pc_im(dest
);
282 gen_step_complete_exception(s
);
283 } else if (s
->singlestep_enabled
) {
284 gen_exception_internal(EXCP_DEBUG
);
287 s
->is_jmp
= DISAS_TB_JUMP
;
292 static void unallocated_encoding(DisasContext
*s
)
294 /* Unallocated and reserved encodings are uncategorized */
295 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized());
298 #define unsupported_encoding(s, insn) \
300 qemu_log_mask(LOG_UNIMP, \
301 "%s:%d: unsupported instruction encoding 0x%08x " \
302 "at pc=%016" PRIx64 "\n", \
303 __FILE__, __LINE__, insn, s->pc - 4); \
304 unallocated_encoding(s); \
307 static void init_tmp_a64_array(DisasContext
*s
)
309 #ifdef CONFIG_DEBUG_TCG
311 for (i
= 0; i
< ARRAY_SIZE(s
->tmp_a64
); i
++) {
312 TCGV_UNUSED_I64(s
->tmp_a64
[i
]);
315 s
->tmp_a64_count
= 0;
318 static void free_tmp_a64(DisasContext
*s
)
321 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
322 tcg_temp_free_i64(s
->tmp_a64
[i
]);
324 init_tmp_a64_array(s
);
327 static TCGv_i64
new_tmp_a64(DisasContext
*s
)
329 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
330 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
333 static TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
335 TCGv_i64 t
= new_tmp_a64(s
);
336 tcg_gen_movi_i64(t
, 0);
341 * Register access functions
343 * These functions are used for directly accessing a register in where
344 * changes to the final register value are likely to be made. If you
345 * need to use a register for temporary calculation (e.g. index type
346 * operations) use the read_* form.
348 * B1.2.1 Register mappings
350 * In instruction register encoding 31 can refer to ZR (zero register) or
351 * the SP (stack pointer) depending on context. In QEMU's case we map SP
352 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
353 * This is the point of the _sp forms.
355 static TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
358 return new_tmp_a64_zero(s
);
364 /* register access for when 31 == SP */
365 static TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
370 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
371 * representing the register contents. This TCGv is an auto-freed
372 * temporary so it need not be explicitly freed, and may be modified.
374 static TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
376 TCGv_i64 v
= new_tmp_a64(s
);
379 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
381 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
384 tcg_gen_movi_i64(v
, 0);
389 static TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
391 TCGv_i64 v
= new_tmp_a64(s
);
393 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
395 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
400 /* We should have at some point before trying to access an FP register
401 * done the necessary access check, so assert that
402 * (a) we did the check and
403 * (b) we didn't then just plough ahead anyway if it failed.
404 * Print the instruction pattern in the abort message so we can figure
405 * out what we need to fix if a user encounters this problem in the wild.
407 static inline void assert_fp_access_checked(DisasContext
*s
)
409 #ifdef CONFIG_DEBUG_TCG
410 if (unlikely(!s
->fp_access_checked
|| !s
->cpacr_fpen
)) {
411 fprintf(stderr
, "target-arm: FP access check missing for "
412 "instruction 0x%08x\n", s
->insn
);
418 /* Return the offset into CPUARMState of an element of specified
419 * size, 'element' places in from the least significant end of
420 * the FP/vector register Qn.
422 static inline int vec_reg_offset(DisasContext
*s
, int regno
,
423 int element
, TCGMemOp size
)
425 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
426 #ifdef HOST_WORDS_BIGENDIAN
427 /* This is complicated slightly because vfp.regs[2n] is
428 * still the low half and vfp.regs[2n+1] the high half
429 * of the 128 bit vector, even on big endian systems.
430 * Calculate the offset assuming a fully bigendian 128 bits,
431 * then XOR to account for the order of the two 64 bit halves.
433 offs
+= (16 - ((element
+ 1) * (1 << size
)));
436 offs
+= element
* (1 << size
);
438 assert_fp_access_checked(s
);
442 /* Return the offset into CPUARMState of a slice (from
443 * the least significant end) of FP register Qn (ie
445 * (Note that this is not the same mapping as for A32; see cpu.h)
447 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
449 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
450 #ifdef HOST_WORDS_BIGENDIAN
451 offs
+= (8 - (1 << size
));
453 assert_fp_access_checked(s
);
457 /* Offset of the high half of the 128 bit vector Qn */
458 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
460 assert_fp_access_checked(s
);
461 return offsetof(CPUARMState
, vfp
.regs
[regno
* 2 + 1]);
464 /* Convenience accessors for reading and writing single and double
465 * FP registers. Writing clears the upper parts of the associated
466 * 128 bit vector register, as required by the architecture.
467 * Note that unlike the GP register accessors, the values returned
468 * by the read functions must be manually freed.
470 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
472 TCGv_i64 v
= tcg_temp_new_i64();
474 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
478 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
480 TCGv_i32 v
= tcg_temp_new_i32();
482 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
486 static void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
488 TCGv_i64 tcg_zero
= tcg_const_i64(0);
490 tcg_gen_st_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
491 tcg_gen_st_i64(tcg_zero
, cpu_env
, fp_reg_hi_offset(s
, reg
));
492 tcg_temp_free_i64(tcg_zero
);
495 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
497 TCGv_i64 tmp
= tcg_temp_new_i64();
499 tcg_gen_extu_i32_i64(tmp
, v
);
500 write_fp_dreg(s
, reg
, tmp
);
501 tcg_temp_free_i64(tmp
);
504 static TCGv_ptr
get_fpstatus_ptr(void)
506 TCGv_ptr statusptr
= tcg_temp_new_ptr();
509 /* In A64 all instructions (both FP and Neon) use the FPCR;
510 * there is no equivalent of the A32 Neon "standard FPSCR value"
511 * and all operations use vfp.fp_status.
513 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
514 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
518 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
519 * than the 32 bit equivalent.
521 static inline void gen_set_NZ64(TCGv_i64 result
)
523 TCGv_i64 flag
= tcg_temp_new_i64();
525 tcg_gen_setcondi_i64(TCG_COND_NE
, flag
, result
, 0);
526 tcg_gen_trunc_i64_i32(cpu_ZF
, flag
);
527 tcg_gen_shri_i64(flag
, result
, 32);
528 tcg_gen_trunc_i64_i32(cpu_NF
, flag
);
529 tcg_temp_free_i64(flag
);
532 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
533 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
536 gen_set_NZ64(result
);
538 tcg_gen_trunc_i64_i32(cpu_ZF
, result
);
539 tcg_gen_trunc_i64_i32(cpu_NF
, result
);
541 tcg_gen_movi_i32(cpu_CF
, 0);
542 tcg_gen_movi_i32(cpu_VF
, 0);
545 /* dest = T0 + T1; compute C, N, V and Z flags */
546 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
549 TCGv_i64 result
, flag
, tmp
;
550 result
= tcg_temp_new_i64();
551 flag
= tcg_temp_new_i64();
552 tmp
= tcg_temp_new_i64();
554 tcg_gen_movi_i64(tmp
, 0);
555 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
557 tcg_gen_trunc_i64_i32(cpu_CF
, flag
);
559 gen_set_NZ64(result
);
561 tcg_gen_xor_i64(flag
, result
, t0
);
562 tcg_gen_xor_i64(tmp
, t0
, t1
);
563 tcg_gen_andc_i64(flag
, flag
, tmp
);
564 tcg_temp_free_i64(tmp
);
565 tcg_gen_shri_i64(flag
, flag
, 32);
566 tcg_gen_trunc_i64_i32(cpu_VF
, flag
);
568 tcg_gen_mov_i64(dest
, result
);
569 tcg_temp_free_i64(result
);
570 tcg_temp_free_i64(flag
);
572 /* 32 bit arithmetic */
573 TCGv_i32 t0_32
= tcg_temp_new_i32();
574 TCGv_i32 t1_32
= tcg_temp_new_i32();
575 TCGv_i32 tmp
= tcg_temp_new_i32();
577 tcg_gen_movi_i32(tmp
, 0);
578 tcg_gen_trunc_i64_i32(t0_32
, t0
);
579 tcg_gen_trunc_i64_i32(t1_32
, t1
);
580 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
581 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
582 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
583 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
584 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
585 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
587 tcg_temp_free_i32(tmp
);
588 tcg_temp_free_i32(t0_32
);
589 tcg_temp_free_i32(t1_32
);
593 /* dest = T0 - T1; compute C, N, V and Z flags */
594 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
597 /* 64 bit arithmetic */
598 TCGv_i64 result
, flag
, tmp
;
600 result
= tcg_temp_new_i64();
601 flag
= tcg_temp_new_i64();
602 tcg_gen_sub_i64(result
, t0
, t1
);
604 gen_set_NZ64(result
);
606 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
607 tcg_gen_trunc_i64_i32(cpu_CF
, flag
);
609 tcg_gen_xor_i64(flag
, result
, t0
);
610 tmp
= tcg_temp_new_i64();
611 tcg_gen_xor_i64(tmp
, t0
, t1
);
612 tcg_gen_and_i64(flag
, flag
, tmp
);
613 tcg_temp_free_i64(tmp
);
614 tcg_gen_shri_i64(flag
, flag
, 32);
615 tcg_gen_trunc_i64_i32(cpu_VF
, flag
);
616 tcg_gen_mov_i64(dest
, result
);
617 tcg_temp_free_i64(flag
);
618 tcg_temp_free_i64(result
);
620 /* 32 bit arithmetic */
621 TCGv_i32 t0_32
= tcg_temp_new_i32();
622 TCGv_i32 t1_32
= tcg_temp_new_i32();
625 tcg_gen_trunc_i64_i32(t0_32
, t0
);
626 tcg_gen_trunc_i64_i32(t1_32
, t1
);
627 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
628 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
629 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
630 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
631 tmp
= tcg_temp_new_i32();
632 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
633 tcg_temp_free_i32(t0_32
);
634 tcg_temp_free_i32(t1_32
);
635 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
636 tcg_temp_free_i32(tmp
);
637 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
641 /* dest = T0 + T1 + CF; do not compute flags. */
642 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
644 TCGv_i64 flag
= tcg_temp_new_i64();
645 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
646 tcg_gen_add_i64(dest
, t0
, t1
);
647 tcg_gen_add_i64(dest
, dest
, flag
);
648 tcg_temp_free_i64(flag
);
651 tcg_gen_ext32u_i64(dest
, dest
);
655 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
656 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
659 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
660 result
= tcg_temp_new_i64();
661 cf_64
= tcg_temp_new_i64();
662 vf_64
= tcg_temp_new_i64();
663 tmp
= tcg_const_i64(0);
665 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
666 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
667 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
668 tcg_gen_trunc_i64_i32(cpu_CF
, cf_64
);
669 gen_set_NZ64(result
);
671 tcg_gen_xor_i64(vf_64
, result
, t0
);
672 tcg_gen_xor_i64(tmp
, t0
, t1
);
673 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
674 tcg_gen_shri_i64(vf_64
, vf_64
, 32);
675 tcg_gen_trunc_i64_i32(cpu_VF
, vf_64
);
677 tcg_gen_mov_i64(dest
, result
);
679 tcg_temp_free_i64(tmp
);
680 tcg_temp_free_i64(vf_64
);
681 tcg_temp_free_i64(cf_64
);
682 tcg_temp_free_i64(result
);
684 TCGv_i32 t0_32
, t1_32
, tmp
;
685 t0_32
= tcg_temp_new_i32();
686 t1_32
= tcg_temp_new_i32();
687 tmp
= tcg_const_i32(0);
689 tcg_gen_trunc_i64_i32(t0_32
, t0
);
690 tcg_gen_trunc_i64_i32(t1_32
, t1
);
691 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
692 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
694 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
695 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
696 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
697 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
698 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
700 tcg_temp_free_i32(tmp
);
701 tcg_temp_free_i32(t1_32
);
702 tcg_temp_free_i32(t0_32
);
707 * Load/Store generators
711 * Store from GPR register to memory.
713 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
714 TCGv_i64 tcg_addr
, int size
, int memidx
)
717 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, MO_TE
+ size
);
720 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
721 TCGv_i64 tcg_addr
, int size
)
723 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
));
727 * Load from memory to GPR register
729 static void do_gpr_ld_memidx(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
730 int size
, bool is_signed
, bool extend
, int memidx
)
732 TCGMemOp memop
= MO_TE
+ size
;
740 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
742 if (extend
&& is_signed
) {
744 tcg_gen_ext32u_i64(dest
, dest
);
748 static void do_gpr_ld(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
749 int size
, bool is_signed
, bool extend
)
751 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
756 * Store from FP register to memory
758 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
760 /* This writes the bottom N bits of a 128 bit wide vector to memory */
761 TCGv_i64 tmp
= tcg_temp_new_i64();
762 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
764 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TE
+ size
);
766 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
767 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
768 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
769 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
770 tcg_gen_qemu_st_i64(tmp
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
771 tcg_temp_free_i64(tcg_hiaddr
);
774 tcg_temp_free_i64(tmp
);
778 * Load from memory to FP register
780 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
782 /* This always zero-extends and writes to a full 128 bit wide vector */
783 TCGv_i64 tmplo
= tcg_temp_new_i64();
787 TCGMemOp memop
= MO_TE
+ size
;
788 tmphi
= tcg_const_i64(0);
789 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
792 tmphi
= tcg_temp_new_i64();
793 tcg_hiaddr
= tcg_temp_new_i64();
795 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
796 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
797 tcg_gen_qemu_ld_i64(tmphi
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
798 tcg_temp_free_i64(tcg_hiaddr
);
801 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
802 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
804 tcg_temp_free_i64(tmplo
);
805 tcg_temp_free_i64(tmphi
);
809 * Vector load/store helpers.
811 * The principal difference between this and a FP load is that we don't
812 * zero extend as we are filling a partial chunk of the vector register.
813 * These functions don't support 128 bit loads/stores, which would be
814 * normal load/store operations.
816 * The _i32 versions are useful when operating on 32 bit quantities
817 * (eg for floating point single or using Neon helper functions).
820 /* Get value of an element within a vector register */
821 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
822 int element
, TCGMemOp memop
)
824 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
827 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
830 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
833 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
836 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
839 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
842 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
846 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
849 g_assert_not_reached();
853 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
854 int element
, TCGMemOp memop
)
856 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
859 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
862 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
865 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
868 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
872 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
875 g_assert_not_reached();
879 /* Set value of an element within a vector register */
880 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
881 int element
, TCGMemOp memop
)
883 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
886 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
889 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
892 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
895 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
898 g_assert_not_reached();
902 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
903 int destidx
, int element
, TCGMemOp memop
)
905 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
908 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
911 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
914 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
917 g_assert_not_reached();
921 /* Clear the high 64 bits of a 128 bit vector (in general non-quad
922 * vector ops all need to do this).
924 static void clear_vec_high(DisasContext
*s
, int rd
)
926 TCGv_i64 tcg_zero
= tcg_const_i64(0);
928 write_vec_element(s
, tcg_zero
, rd
, 1, MO_64
);
929 tcg_temp_free_i64(tcg_zero
);
932 /* Store from vector register to memory */
933 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
934 TCGv_i64 tcg_addr
, int size
)
936 TCGMemOp memop
= MO_TE
+ size
;
937 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
939 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
940 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
942 tcg_temp_free_i64(tcg_tmp
);
945 /* Load from memory to vector register */
946 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
947 TCGv_i64 tcg_addr
, int size
)
949 TCGMemOp memop
= MO_TE
+ size
;
950 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
952 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
953 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
955 tcg_temp_free_i64(tcg_tmp
);
958 /* Check that FP/Neon access is enabled. If it is, return
959 * true. If not, emit code to generate an appropriate exception,
960 * and return false; the caller should not emit any code for
961 * the instruction. Note that this check must happen after all
962 * unallocated-encoding checks (otherwise the syndrome information
963 * for the resulting exception will be incorrect).
965 static inline bool fp_access_check(DisasContext
*s
)
967 assert(!s
->fp_access_checked
);
968 s
->fp_access_checked
= true;
974 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false));
979 * This utility function is for doing register extension with an
980 * optional shift. You will likely want to pass a temporary for the
981 * destination register. See DecodeRegExtend() in the ARM ARM.
983 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
984 int option
, unsigned int shift
)
986 int extsize
= extract32(option
, 0, 2);
987 bool is_signed
= extract32(option
, 2, 1);
992 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
995 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
998 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
1001 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1007 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
1010 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
1013 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1016 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1022 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1026 static inline void gen_check_sp_alignment(DisasContext
*s
)
1028 /* The AArch64 architecture mandates that (if enabled via PSTATE
1029 * or SCTLR bits) there is a check that SP is 16-aligned on every
1030 * SP-relative load or store (with an exception generated if it is not).
1031 * In line with general QEMU practice regarding misaligned accesses,
1032 * we omit these checks for the sake of guest program performance.
1033 * This function is provided as a hook so we can more easily add these
1034 * checks in future (possibly as a "favour catching guest program bugs
1035 * over speed" user selectable option).
1040 * This provides a simple table based table lookup decoder. It is
1041 * intended to be used when the relevant bits for decode are too
1042 * awkwardly placed and switch/if based logic would be confusing and
1043 * deeply nested. Since it's a linear search through the table, tables
1044 * should be kept small.
1046 * It returns the first handler where insn & mask == pattern, or
1047 * NULL if there is no match.
1048 * The table is terminated by an empty mask (i.e. 0)
1050 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1053 const AArch64DecodeTable
*tptr
= table
;
1055 while (tptr
->mask
) {
1056 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1057 return tptr
->disas_fn
;
1065 * the instruction disassembly implemented here matches
1066 * the instruction encoding classifications in chapter 3 (C3)
1067 * of the ARM Architecture Reference Manual (DDI0487A_a)
1070 /* C3.2.7 Unconditional branch (immediate)
1072 * +----+-----------+-------------------------------------+
1073 * | op | 0 0 1 0 1 | imm26 |
1074 * +----+-----------+-------------------------------------+
1076 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1078 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1080 if (insn
& (1U << 31)) {
1081 /* C5.6.26 BL Branch with link */
1082 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1085 /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
1086 gen_goto_tb(s
, 0, addr
);
1089 /* C3.2.1 Compare & branch (immediate)
1090 * 31 30 25 24 23 5 4 0
1091 * +----+-------------+----+---------------------+--------+
1092 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1093 * +----+-------------+----+---------------------+--------+
1095 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1097 unsigned int sf
, op
, rt
;
1099 TCGLabel
*label_match
;
1102 sf
= extract32(insn
, 31, 1);
1103 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1104 rt
= extract32(insn
, 0, 5);
1105 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1107 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1108 label_match
= gen_new_label();
1110 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1111 tcg_cmp
, 0, label_match
);
1113 gen_goto_tb(s
, 0, s
->pc
);
1114 gen_set_label(label_match
);
1115 gen_goto_tb(s
, 1, addr
);
1118 /* C3.2.5 Test & branch (immediate)
1119 * 31 30 25 24 23 19 18 5 4 0
1120 * +----+-------------+----+-------+-------------+------+
1121 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1122 * +----+-------------+----+-------+-------------+------+
1124 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1126 unsigned int bit_pos
, op
, rt
;
1128 TCGLabel
*label_match
;
1131 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1132 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1133 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1134 rt
= extract32(insn
, 0, 5);
1136 tcg_cmp
= tcg_temp_new_i64();
1137 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1138 label_match
= gen_new_label();
1139 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1140 tcg_cmp
, 0, label_match
);
1141 tcg_temp_free_i64(tcg_cmp
);
1142 gen_goto_tb(s
, 0, s
->pc
);
1143 gen_set_label(label_match
);
1144 gen_goto_tb(s
, 1, addr
);
1147 /* C3.2.2 / C5.6.19 Conditional branch (immediate)
1148 * 31 25 24 23 5 4 3 0
1149 * +---------------+----+---------------------+----+------+
1150 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1151 * +---------------+----+---------------------+----+------+
1153 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1158 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1159 unallocated_encoding(s
);
1162 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1163 cond
= extract32(insn
, 0, 4);
1166 /* genuinely conditional branches */
1167 TCGLabel
*label_match
= gen_new_label();
1168 arm_gen_test_cc(cond
, label_match
);
1169 gen_goto_tb(s
, 0, s
->pc
);
1170 gen_set_label(label_match
);
1171 gen_goto_tb(s
, 1, addr
);
1173 /* 0xe and 0xf are both "always" conditions */
1174 gen_goto_tb(s
, 0, addr
);
1179 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1180 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1182 unsigned int selector
= crm
<< 3 | op2
;
1185 unallocated_encoding(s
);
1193 s
->is_jmp
= DISAS_WFI
;
1197 s
->is_jmp
= DISAS_WFE
;
1201 /* we treat all as NOP at least for now */
1204 /* default specified as NOP equivalent */
1209 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1211 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1214 /* CLREX, DSB, DMB, ISB */
1215 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1216 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1219 unallocated_encoding(s
);
1230 /* We don't emulate caches so barriers are no-ops */
1233 unallocated_encoding(s
);
1238 /* C5.6.130 MSR (immediate) - move immediate to processor state field */
1239 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1240 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1242 int op
= op1
<< 3 | op2
;
1244 case 0x05: /* SPSel */
1245 if (s
->current_el
== 0) {
1246 unallocated_encoding(s
);
1250 case 0x1e: /* DAIFSet */
1251 case 0x1f: /* DAIFClear */
1253 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1254 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1255 gen_a64_set_pc_im(s
->pc
- 4);
1256 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1257 tcg_temp_free_i32(tcg_imm
);
1258 tcg_temp_free_i32(tcg_op
);
1259 s
->is_jmp
= DISAS_UPDATE
;
1263 unallocated_encoding(s
);
1268 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1270 TCGv_i32 tmp
= tcg_temp_new_i32();
1271 TCGv_i32 nzcv
= tcg_temp_new_i32();
1273 /* build bit 31, N */
1274 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1U << 31));
1275 /* build bit 30, Z */
1276 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1277 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1278 /* build bit 29, C */
1279 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1280 /* build bit 28, V */
1281 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1282 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1283 /* generate result */
1284 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1286 tcg_temp_free_i32(nzcv
);
1287 tcg_temp_free_i32(tmp
);
1290 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1293 TCGv_i32 nzcv
= tcg_temp_new_i32();
1295 /* take NZCV from R[t] */
1296 tcg_gen_trunc_i64_i32(nzcv
, tcg_rt
);
1299 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1U << 31));
1301 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1302 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1304 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1305 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1307 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1308 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1309 tcg_temp_free_i32(nzcv
);
1312 /* C5.6.129 MRS - move from system register
1313 * C5.6.131 MSR (register) - move to system register
1316 * These are all essentially the same insn in 'read' and 'write'
1317 * versions, with varying op0 fields.
1319 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1320 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1321 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1323 const ARMCPRegInfo
*ri
;
1326 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1327 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1328 crn
, crm
, op0
, op1
, op2
));
1331 /* Unknown register; this might be a guest error or a QEMU
1332 * unimplemented feature.
1334 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1335 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1336 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1337 unallocated_encoding(s
);
1341 /* Check access permissions */
1342 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1343 unallocated_encoding(s
);
1348 /* Emit code to perform further access permissions checks at
1349 * runtime; this may result in an exception.
1355 gen_a64_set_pc_im(s
->pc
- 4);
1356 tmpptr
= tcg_const_ptr(ri
);
1357 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1358 tcg_syn
= tcg_const_i32(syndrome
);
1359 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
);
1360 tcg_temp_free_ptr(tmpptr
);
1361 tcg_temp_free_i32(tcg_syn
);
1364 /* Handle special cases first */
1365 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1369 tcg_rt
= cpu_reg(s
, rt
);
1371 gen_get_nzcv(tcg_rt
);
1373 gen_set_nzcv(tcg_rt
);
1376 case ARM_CP_CURRENTEL
:
1377 /* Reads as current EL value from pstate, which is
1378 * guaranteed to be constant by the tb flags.
1380 tcg_rt
= cpu_reg(s
, rt
);
1381 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1384 /* Writes clear the aligned block of memory which rt points into. */
1385 tcg_rt
= cpu_reg(s
, rt
);
1386 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1392 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1396 tcg_rt
= cpu_reg(s
, rt
);
1399 if (ri
->type
& ARM_CP_CONST
) {
1400 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1401 } else if (ri
->readfn
) {
1403 tmpptr
= tcg_const_ptr(ri
);
1404 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1405 tcg_temp_free_ptr(tmpptr
);
1407 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1410 if (ri
->type
& ARM_CP_CONST
) {
1411 /* If not forbidden by access permissions, treat as WI */
1413 } else if (ri
->writefn
) {
1415 tmpptr
= tcg_const_ptr(ri
);
1416 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1417 tcg_temp_free_ptr(tmpptr
);
1419 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1423 if ((s
->tb
->cflags
& CF_USE_ICOUNT
) && (ri
->type
& ARM_CP_IO
)) {
1424 /* I/O operations must end the TB here (whether read or write) */
1426 s
->is_jmp
= DISAS_UPDATE
;
1427 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1428 /* We default to ending the TB on a coprocessor register write,
1429 * but allow this to be suppressed by the register definition
1430 * (usually only necessary to work around guest bugs).
1432 s
->is_jmp
= DISAS_UPDATE
;
1437 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1438 * +---------------------+---+-----+-----+-------+-------+-----+------+
1439 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1440 * +---------------------+---+-----+-----+-------+-------+-----+------+
1442 static void disas_system(DisasContext
*s
, uint32_t insn
)
1444 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1445 l
= extract32(insn
, 21, 1);
1446 op0
= extract32(insn
, 19, 2);
1447 op1
= extract32(insn
, 16, 3);
1448 crn
= extract32(insn
, 12, 4);
1449 crm
= extract32(insn
, 8, 4);
1450 op2
= extract32(insn
, 5, 3);
1451 rt
= extract32(insn
, 0, 5);
1454 if (l
|| rt
!= 31) {
1455 unallocated_encoding(s
);
1459 case 2: /* C5.6.68 HINT */
1460 handle_hint(s
, insn
, op1
, op2
, crm
);
1462 case 3: /* CLREX, DSB, DMB, ISB */
1463 handle_sync(s
, insn
, op1
, op2
, crm
);
1465 case 4: /* C5.6.130 MSR (immediate) */
1466 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1469 unallocated_encoding(s
);
1474 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1477 /* C3.2.3 Exception generation
1479 * 31 24 23 21 20 5 4 2 1 0
1480 * +-----------------+-----+------------------------+-----+----+
1481 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1482 * +-----------------------+------------------------+----------+
1484 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1486 int opc
= extract32(insn
, 21, 3);
1487 int op2_ll
= extract32(insn
, 0, 5);
1488 int imm16
= extract32(insn
, 5, 16);
1493 /* For SVC, HVC and SMC we advance the single-step state
1494 * machine before taking the exception. This is architecturally
1495 * mandated, to ensure that single-stepping a system call
1496 * instruction works properly.
1501 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
));
1504 if (s
->current_el
== 0) {
1505 unallocated_encoding(s
);
1508 /* The pre HVC helper handles cases when HVC gets trapped
1509 * as an undefined insn by runtime configuration.
1511 gen_a64_set_pc_im(s
->pc
- 4);
1512 gen_helper_pre_hvc(cpu_env
);
1514 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
));
1517 if (s
->current_el
== 0) {
1518 unallocated_encoding(s
);
1521 gen_a64_set_pc_im(s
->pc
- 4);
1522 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1523 gen_helper_pre_smc(cpu_env
, tmp
);
1524 tcg_temp_free_i32(tmp
);
1526 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
));
1529 unallocated_encoding(s
);
1535 unallocated_encoding(s
);
1539 gen_exception_insn(s
, 4, EXCP_BKPT
, syn_aa64_bkpt(imm16
));
1543 unallocated_encoding(s
);
1547 unsupported_encoding(s
, insn
);
1550 if (op2_ll
< 1 || op2_ll
> 3) {
1551 unallocated_encoding(s
);
1554 /* DCPS1, DCPS2, DCPS3 */
1555 unsupported_encoding(s
, insn
);
1558 unallocated_encoding(s
);
1563 /* C3.2.7 Unconditional branch (register)
1564 * 31 25 24 21 20 16 15 10 9 5 4 0
1565 * +---------------+-------+-------+-------+------+-------+
1566 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1567 * +---------------+-------+-------+-------+------+-------+
1569 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1571 unsigned int opc
, op2
, op3
, rn
, op4
;
1573 opc
= extract32(insn
, 21, 4);
1574 op2
= extract32(insn
, 16, 5);
1575 op3
= extract32(insn
, 10, 6);
1576 rn
= extract32(insn
, 5, 5);
1577 op4
= extract32(insn
, 0, 5);
1579 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1580 unallocated_encoding(s
);
1587 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1590 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1591 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1594 if (s
->current_el
== 0) {
1595 unallocated_encoding(s
);
1598 gen_helper_exception_return(cpu_env
);
1599 s
->is_jmp
= DISAS_JUMP
;
1603 unallocated_encoding(s
);
1605 unsupported_encoding(s
, insn
);
1609 unallocated_encoding(s
);
1613 s
->is_jmp
= DISAS_JUMP
;
1616 /* C3.2 Branches, exception generating and system instructions */
1617 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1619 switch (extract32(insn
, 25, 7)) {
1620 case 0x0a: case 0x0b:
1621 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1622 disas_uncond_b_imm(s
, insn
);
1624 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1625 disas_comp_b_imm(s
, insn
);
1627 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1628 disas_test_b_imm(s
, insn
);
1630 case 0x2a: /* Conditional branch (immediate) */
1631 disas_cond_b_imm(s
, insn
);
1633 case 0x6a: /* Exception generation / System */
1634 if (insn
& (1 << 24)) {
1635 disas_system(s
, insn
);
1640 case 0x6b: /* Unconditional branch (register) */
1641 disas_uncond_b_reg(s
, insn
);
1644 unallocated_encoding(s
);
1650 * Load/Store exclusive instructions are implemented by remembering
1651 * the value/address loaded, and seeing if these are the same
1652 * when the store is performed. This is not actually the architecturally
1653 * mandated semantics, but it works for typical guest code sequences
1654 * and avoids having to monitor regular stores.
1656 * In system emulation mode only one CPU will be running at once, so
1657 * this sequence is effectively atomic. In user emulation mode we
1658 * throw an exception and handle the atomic operation elsewhere.
1660 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
1661 TCGv_i64 addr
, int size
, bool is_pair
)
1663 TCGv_i64 tmp
= tcg_temp_new_i64();
1664 TCGMemOp memop
= MO_TE
+ size
;
1666 g_assert(size
<= 3);
1667 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), memop
);
1670 TCGv_i64 addr2
= tcg_temp_new_i64();
1671 TCGv_i64 hitmp
= tcg_temp_new_i64();
1673 g_assert(size
>= 2);
1674 tcg_gen_addi_i64(addr2
, addr
, 1 << size
);
1675 tcg_gen_qemu_ld_i64(hitmp
, addr2
, get_mem_index(s
), memop
);
1676 tcg_temp_free_i64(addr2
);
1677 tcg_gen_mov_i64(cpu_exclusive_high
, hitmp
);
1678 tcg_gen_mov_i64(cpu_reg(s
, rt2
), hitmp
);
1679 tcg_temp_free_i64(hitmp
);
1682 tcg_gen_mov_i64(cpu_exclusive_val
, tmp
);
1683 tcg_gen_mov_i64(cpu_reg(s
, rt
), tmp
);
1685 tcg_temp_free_i64(tmp
);
1686 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
1689 #ifdef CONFIG_USER_ONLY
1690 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1691 TCGv_i64 addr
, int size
, int is_pair
)
1693 tcg_gen_mov_i64(cpu_exclusive_test
, addr
);
1694 tcg_gen_movi_i32(cpu_exclusive_info
,
1695 size
| is_pair
<< 2 | (rd
<< 4) | (rt
<< 9) | (rt2
<< 14));
1696 gen_exception_internal_insn(s
, 4, EXCP_STREX
);
1699 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1700 TCGv_i64 inaddr
, int size
, int is_pair
)
1702 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1703 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1706 * [addr + datasize] = {Rt2};
1712 * env->exclusive_addr = -1;
1714 TCGLabel
*fail_label
= gen_new_label();
1715 TCGLabel
*done_label
= gen_new_label();
1716 TCGv_i64 addr
= tcg_temp_local_new_i64();
1719 /* Copy input into a local temp so it is not trashed when the
1720 * basic block ends at the branch insn.
1722 tcg_gen_mov_i64(addr
, inaddr
);
1723 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
1725 tmp
= tcg_temp_new_i64();
1726 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), MO_TE
+ size
);
1727 tcg_gen_brcond_i64(TCG_COND_NE
, tmp
, cpu_exclusive_val
, fail_label
);
1728 tcg_temp_free_i64(tmp
);
1731 TCGv_i64 addrhi
= tcg_temp_new_i64();
1732 TCGv_i64 tmphi
= tcg_temp_new_i64();
1734 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1735 tcg_gen_qemu_ld_i64(tmphi
, addrhi
, get_mem_index(s
), MO_TE
+ size
);
1736 tcg_gen_brcond_i64(TCG_COND_NE
, tmphi
, cpu_exclusive_high
, fail_label
);
1738 tcg_temp_free_i64(tmphi
);
1739 tcg_temp_free_i64(addrhi
);
1742 /* We seem to still have the exclusive monitor, so do the store */
1743 tcg_gen_qemu_st_i64(cpu_reg(s
, rt
), addr
, get_mem_index(s
), MO_TE
+ size
);
1745 TCGv_i64 addrhi
= tcg_temp_new_i64();
1747 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1748 tcg_gen_qemu_st_i64(cpu_reg(s
, rt2
), addrhi
,
1749 get_mem_index(s
), MO_TE
+ size
);
1750 tcg_temp_free_i64(addrhi
);
1753 tcg_temp_free_i64(addr
);
1755 tcg_gen_movi_i64(cpu_reg(s
, rd
), 0);
1756 tcg_gen_br(done_label
);
1757 gen_set_label(fail_label
);
1758 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
1759 gen_set_label(done_label
);
1760 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1765 /* C3.3.6 Load/store exclusive
1767 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
1768 * +-----+-------------+----+---+----+------+----+-------+------+------+
1769 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
1770 * +-----+-------------+----+---+----+------+----+-------+------+------+
1772 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
1773 * L: 0 -> store, 1 -> load
1774 * o2: 0 -> exclusive, 1 -> not
1775 * o1: 0 -> single register, 1 -> register pair
1776 * o0: 1 -> load-acquire/store-release, 0 -> not
1778 * o0 == 0 AND o2 == 1 is un-allocated
1779 * o1 == 1 is un-allocated except for 32 and 64 bit sizes
1781 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
1783 int rt
= extract32(insn
, 0, 5);
1784 int rn
= extract32(insn
, 5, 5);
1785 int rt2
= extract32(insn
, 10, 5);
1786 int is_lasr
= extract32(insn
, 15, 1);
1787 int rs
= extract32(insn
, 16, 5);
1788 int is_pair
= extract32(insn
, 21, 1);
1789 int is_store
= !extract32(insn
, 22, 1);
1790 int is_excl
= !extract32(insn
, 23, 1);
1791 int size
= extract32(insn
, 30, 2);
1794 if ((!is_excl
&& !is_lasr
) ||
1795 (is_pair
&& size
< 2)) {
1796 unallocated_encoding(s
);
1801 gen_check_sp_alignment(s
);
1803 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1805 /* Note that since TCG is single threaded load-acquire/store-release
1806 * semantics require no extra if (is_lasr) { ... } handling.
1812 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1814 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1817 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1819 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1821 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, false, false);
1824 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt
);
1825 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
1827 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
1829 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, false, false);
1836 * C3.3.5 Load register (literal)
1838 * 31 30 29 27 26 25 24 23 5 4 0
1839 * +-----+-------+---+-----+-------------------+-------+
1840 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
1841 * +-----+-------+---+-----+-------------------+-------+
1843 * V: 1 -> vector (simd/fp)
1844 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
1845 * 10-> 32 bit signed, 11 -> prefetch
1846 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
1848 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
1850 int rt
= extract32(insn
, 0, 5);
1851 int64_t imm
= sextract32(insn
, 5, 19) << 2;
1852 bool is_vector
= extract32(insn
, 26, 1);
1853 int opc
= extract32(insn
, 30, 2);
1854 bool is_signed
= false;
1856 TCGv_i64 tcg_rt
, tcg_addr
;
1860 unallocated_encoding(s
);
1864 if (!fp_access_check(s
)) {
1869 /* PRFM (literal) : prefetch */
1872 size
= 2 + extract32(opc
, 0, 1);
1873 is_signed
= extract32(opc
, 1, 1);
1876 tcg_rt
= cpu_reg(s
, rt
);
1878 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
1880 do_fp_ld(s
, rt
, tcg_addr
, size
);
1882 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
1884 tcg_temp_free_i64(tcg_addr
);
1888 * C5.6.80 LDNP (Load Pair - non-temporal hint)
1889 * C5.6.81 LDP (Load Pair - non vector)
1890 * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
1891 * C5.6.176 STNP (Store Pair - non-temporal hint)
1892 * C5.6.177 STP (Store Pair - non vector)
1893 * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
1894 * C6.3.165 LDP (Load Pair of SIMD&FP)
1895 * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
1896 * C6.3.284 STP (Store Pair of SIMD&FP)
1898 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
1899 * +-----+-------+---+---+-------+---+-----------------------------+
1900 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
1901 * +-----+-------+---+---+-------+---+-------+-------+------+------+
1903 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
1905 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
1906 * V: 0 -> GPR, 1 -> Vector
1907 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
1908 * 10 -> signed offset, 11 -> pre-index
1909 * L: 0 -> Store 1 -> Load
1911 * Rt, Rt2 = GPR or SIMD registers to be stored
1912 * Rn = general purpose register containing address
1913 * imm7 = signed offset (multiple of 4 or 8 depending on size)
1915 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
1917 int rt
= extract32(insn
, 0, 5);
1918 int rn
= extract32(insn
, 5, 5);
1919 int rt2
= extract32(insn
, 10, 5);
1920 uint64_t offset
= sextract64(insn
, 15, 7);
1921 int index
= extract32(insn
, 23, 2);
1922 bool is_vector
= extract32(insn
, 26, 1);
1923 bool is_load
= extract32(insn
, 22, 1);
1924 int opc
= extract32(insn
, 30, 2);
1926 bool is_signed
= false;
1927 bool postindex
= false;
1930 TCGv_i64 tcg_addr
; /* calculated address */
1934 unallocated_encoding(s
);
1941 size
= 2 + extract32(opc
, 1, 1);
1942 is_signed
= extract32(opc
, 0, 1);
1943 if (!is_load
&& is_signed
) {
1944 unallocated_encoding(s
);
1950 case 1: /* post-index */
1955 /* signed offset with "non-temporal" hint. Since we don't emulate
1956 * caches we don't care about hints to the cache system about
1957 * data access patterns, and handle this identically to plain
1961 /* There is no non-temporal-hint version of LDPSW */
1962 unallocated_encoding(s
);
1967 case 2: /* signed offset, rn not updated */
1970 case 3: /* pre-index */
1976 if (is_vector
&& !fp_access_check(s
)) {
1983 gen_check_sp_alignment(s
);
1986 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1989 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
1994 do_fp_ld(s
, rt
, tcg_addr
, size
);
1996 do_fp_st(s
, rt
, tcg_addr
, size
);
1999 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2001 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
2003 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2006 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2009 do_fp_ld(s
, rt2
, tcg_addr
, size
);
2011 do_fp_st(s
, rt2
, tcg_addr
, size
);
2014 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2016 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false);
2018 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
2024 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
2026 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2028 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
2033 * C3.3.8 Load/store (immediate post-indexed)
2034 * C3.3.9 Load/store (immediate pre-indexed)
2035 * C3.3.12 Load/store (unscaled immediate)
2037 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2038 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2039 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2040 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2042 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2044 * V = 0 -> non-vector
2045 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2046 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2048 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
)
2050 int rt
= extract32(insn
, 0, 5);
2051 int rn
= extract32(insn
, 5, 5);
2052 int imm9
= sextract32(insn
, 12, 9);
2053 int opc
= extract32(insn
, 22, 2);
2054 int size
= extract32(insn
, 30, 2);
2055 int idx
= extract32(insn
, 10, 2);
2056 bool is_signed
= false;
2057 bool is_store
= false;
2058 bool is_extended
= false;
2059 bool is_unpriv
= (idx
== 2);
2060 bool is_vector
= extract32(insn
, 26, 1);
2067 size
|= (opc
& 2) << 1;
2068 if (size
> 4 || is_unpriv
) {
2069 unallocated_encoding(s
);
2072 is_store
= ((opc
& 1) == 0);
2073 if (!fp_access_check(s
)) {
2077 if (size
== 3 && opc
== 2) {
2078 /* PRFM - prefetch */
2080 unallocated_encoding(s
);
2085 if (opc
== 3 && size
> 1) {
2086 unallocated_encoding(s
);
2089 is_store
= (opc
== 0);
2090 is_signed
= opc
& (1<<1);
2091 is_extended
= (size
< 3) && (opc
& 1);
2111 gen_check_sp_alignment(s
);
2113 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2116 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2121 do_fp_st(s
, rt
, tcg_addr
, size
);
2123 do_fp_ld(s
, rt
, tcg_addr
, size
);
2126 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2127 int memidx
= is_unpriv
? get_a64_user_mem_index(s
) : get_mem_index(s
);
2130 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
);
2132 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
2133 is_signed
, is_extended
, memidx
);
2138 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2140 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2142 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2147 * C3.3.10 Load/store (register offset)
2149 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2150 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2151 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2152 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2155 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2156 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2158 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2159 * opc<0>: 0 -> store, 1 -> load
2160 * V: 1 -> vector/simd
2161 * opt: extend encoding (see DecodeRegExtend)
2162 * S: if S=1 then scale (essentially index by sizeof(size))
2163 * Rt: register to transfer into/out of
2164 * Rn: address register or SP for base
2165 * Rm: offset register or ZR for offset
2167 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
)
2169 int rt
= extract32(insn
, 0, 5);
2170 int rn
= extract32(insn
, 5, 5);
2171 int shift
= extract32(insn
, 12, 1);
2172 int rm
= extract32(insn
, 16, 5);
2173 int opc
= extract32(insn
, 22, 2);
2174 int opt
= extract32(insn
, 13, 3);
2175 int size
= extract32(insn
, 30, 2);
2176 bool is_signed
= false;
2177 bool is_store
= false;
2178 bool is_extended
= false;
2179 bool is_vector
= extract32(insn
, 26, 1);
2184 if (extract32(opt
, 1, 1) == 0) {
2185 unallocated_encoding(s
);
2190 size
|= (opc
& 2) << 1;
2192 unallocated_encoding(s
);
2195 is_store
= !extract32(opc
, 0, 1);
2196 if (!fp_access_check(s
)) {
2200 if (size
== 3 && opc
== 2) {
2201 /* PRFM - prefetch */
2204 if (opc
== 3 && size
> 1) {
2205 unallocated_encoding(s
);
2208 is_store
= (opc
== 0);
2209 is_signed
= extract32(opc
, 1, 1);
2210 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2214 gen_check_sp_alignment(s
);
2216 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2218 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2219 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2221 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2225 do_fp_st(s
, rt
, tcg_addr
, size
);
2227 do_fp_ld(s
, rt
, tcg_addr
, size
);
2230 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2232 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2234 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2240 * C3.3.13 Load/store (unsigned immediate)
2242 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2243 * +----+-------+---+-----+-----+------------+-------+------+
2244 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2245 * +----+-------+---+-----+-----+------------+-------+------+
2248 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2249 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2251 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2252 * opc<0>: 0 -> store, 1 -> load
2253 * Rn: base address register (inc SP)
2254 * Rt: target register
2256 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
)
2258 int rt
= extract32(insn
, 0, 5);
2259 int rn
= extract32(insn
, 5, 5);
2260 unsigned int imm12
= extract32(insn
, 10, 12);
2261 bool is_vector
= extract32(insn
, 26, 1);
2262 int size
= extract32(insn
, 30, 2);
2263 int opc
= extract32(insn
, 22, 2);
2264 unsigned int offset
;
2269 bool is_signed
= false;
2270 bool is_extended
= false;
2273 size
|= (opc
& 2) << 1;
2275 unallocated_encoding(s
);
2278 is_store
= !extract32(opc
, 0, 1);
2279 if (!fp_access_check(s
)) {
2283 if (size
== 3 && opc
== 2) {
2284 /* PRFM - prefetch */
2287 if (opc
== 3 && size
> 1) {
2288 unallocated_encoding(s
);
2291 is_store
= (opc
== 0);
2292 is_signed
= extract32(opc
, 1, 1);
2293 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2297 gen_check_sp_alignment(s
);
2299 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2300 offset
= imm12
<< size
;
2301 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2305 do_fp_st(s
, rt
, tcg_addr
, size
);
2307 do_fp_ld(s
, rt
, tcg_addr
, size
);
2310 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2312 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2314 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2319 /* Load/store register (all forms) */
2320 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2322 switch (extract32(insn
, 24, 2)) {
2324 if (extract32(insn
, 21, 1) == 1 && extract32(insn
, 10, 2) == 2) {
2325 disas_ldst_reg_roffset(s
, insn
);
2327 /* Load/store register (unscaled immediate)
2328 * Load/store immediate pre/post-indexed
2329 * Load/store register unprivileged
2331 disas_ldst_reg_imm9(s
, insn
);
2335 disas_ldst_reg_unsigned_imm(s
, insn
);
2338 unallocated_encoding(s
);
2343 /* C3.3.1 AdvSIMD load/store multiple structures
2345 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2346 * +---+---+---------------+---+-------------+--------+------+------+------+
2347 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2348 * +---+---+---------------+---+-------------+--------+------+------+------+
2350 * C3.3.2 AdvSIMD load/store multiple structures (post-indexed)
2352 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2353 * +---+---+---------------+---+---+---------+--------+------+------+------+
2354 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2355 * +---+---+---------------+---+---+---------+--------+------+------+------+
2357 * Rt: first (or only) SIMD&FP register to be transferred
2358 * Rn: base address or SP
2359 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2361 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
2363 int rt
= extract32(insn
, 0, 5);
2364 int rn
= extract32(insn
, 5, 5);
2365 int size
= extract32(insn
, 10, 2);
2366 int opcode
= extract32(insn
, 12, 4);
2367 bool is_store
= !extract32(insn
, 22, 1);
2368 bool is_postidx
= extract32(insn
, 23, 1);
2369 bool is_q
= extract32(insn
, 30, 1);
2370 TCGv_i64 tcg_addr
, tcg_rn
;
2372 int ebytes
= 1 << size
;
2373 int elements
= (is_q
? 128 : 64) / (8 << size
);
2374 int rpt
; /* num iterations */
2375 int selem
; /* structure elements */
2378 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
2379 unallocated_encoding(s
);
2383 /* From the shared decode logic */
2414 unallocated_encoding(s
);
2418 if (size
== 3 && !is_q
&& selem
!= 1) {
2420 unallocated_encoding(s
);
2424 if (!fp_access_check(s
)) {
2429 gen_check_sp_alignment(s
);
2432 tcg_rn
= cpu_reg_sp(s
, rn
);
2433 tcg_addr
= tcg_temp_new_i64();
2434 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2436 for (r
= 0; r
< rpt
; r
++) {
2438 for (e
= 0; e
< elements
; e
++) {
2439 int tt
= (rt
+ r
) % 32;
2441 for (xs
= 0; xs
< selem
; xs
++) {
2443 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
2445 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
2447 /* For non-quad operations, setting a slice of the low
2448 * 64 bits of the register clears the high 64 bits (in
2449 * the ARM ARM pseudocode this is implicit in the fact
2450 * that 'rval' is a 64 bit wide variable). We optimize
2451 * by noticing that we only need to do this the first
2452 * time we touch a register.
2454 if (!is_q
&& e
== 0 && (r
== 0 || xs
== selem
- 1)) {
2455 clear_vec_high(s
, tt
);
2458 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2465 int rm
= extract32(insn
, 16, 5);
2467 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2469 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2472 tcg_temp_free_i64(tcg_addr
);
2475 /* C3.3.3 AdvSIMD load/store single structure
2477 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2478 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2479 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
2480 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2482 * C3.3.4 AdvSIMD load/store single structure (post-indexed)
2484 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2485 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2486 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
2487 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2489 * Rt: first (or only) SIMD&FP register to be transferred
2490 * Rn: base address or SP
2491 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2492 * index = encoded in Q:S:size dependent on size
2494 * lane_size = encoded in R, opc
2495 * transfer width = encoded in opc, S, size
2497 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
2499 int rt
= extract32(insn
, 0, 5);
2500 int rn
= extract32(insn
, 5, 5);
2501 int size
= extract32(insn
, 10, 2);
2502 int S
= extract32(insn
, 12, 1);
2503 int opc
= extract32(insn
, 13, 3);
2504 int R
= extract32(insn
, 21, 1);
2505 int is_load
= extract32(insn
, 22, 1);
2506 int is_postidx
= extract32(insn
, 23, 1);
2507 int is_q
= extract32(insn
, 30, 1);
2509 int scale
= extract32(opc
, 1, 2);
2510 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
2511 bool replicate
= false;
2512 int index
= is_q
<< 3 | S
<< 2 | size
;
2514 TCGv_i64 tcg_addr
, tcg_rn
;
2518 if (!is_load
|| S
) {
2519 unallocated_encoding(s
);
2528 if (extract32(size
, 0, 1)) {
2529 unallocated_encoding(s
);
2535 if (extract32(size
, 1, 1)) {
2536 unallocated_encoding(s
);
2539 if (!extract32(size
, 0, 1)) {
2543 unallocated_encoding(s
);
2551 g_assert_not_reached();
2554 if (!fp_access_check(s
)) {
2558 ebytes
= 1 << scale
;
2561 gen_check_sp_alignment(s
);
2564 tcg_rn
= cpu_reg_sp(s
, rn
);
2565 tcg_addr
= tcg_temp_new_i64();
2566 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2568 for (xs
= 0; xs
< selem
; xs
++) {
2570 /* Load and replicate to all elements */
2572 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
2574 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
2575 get_mem_index(s
), MO_TE
+ scale
);
2578 mulconst
= 0x0101010101010101ULL
;
2581 mulconst
= 0x0001000100010001ULL
;
2584 mulconst
= 0x0000000100000001ULL
;
2590 g_assert_not_reached();
2593 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
2595 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
2597 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
2599 clear_vec_high(s
, rt
);
2601 tcg_temp_free_i64(tcg_tmp
);
2603 /* Load/store one element per register */
2605 do_vec_ld(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2607 do_vec_st(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2610 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2615 int rm
= extract32(insn
, 16, 5);
2617 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2619 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2622 tcg_temp_free_i64(tcg_addr
);
2625 /* C3.3 Loads and stores */
2626 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
2628 switch (extract32(insn
, 24, 6)) {
2629 case 0x08: /* Load/store exclusive */
2630 disas_ldst_excl(s
, insn
);
2632 case 0x18: case 0x1c: /* Load register (literal) */
2633 disas_ld_lit(s
, insn
);
2635 case 0x28: case 0x29:
2636 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
2637 disas_ldst_pair(s
, insn
);
2639 case 0x38: case 0x39:
2640 case 0x3c: case 0x3d: /* Load/store register (all forms) */
2641 disas_ldst_reg(s
, insn
);
2643 case 0x0c: /* AdvSIMD load/store multiple structures */
2644 disas_ldst_multiple_struct(s
, insn
);
2646 case 0x0d: /* AdvSIMD load/store single structure */
2647 disas_ldst_single_struct(s
, insn
);
2650 unallocated_encoding(s
);
2655 /* C3.4.6 PC-rel. addressing
2656 * 31 30 29 28 24 23 5 4 0
2657 * +----+-------+-----------+-------------------+------+
2658 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
2659 * +----+-------+-----------+-------------------+------+
2661 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
2663 unsigned int page
, rd
;
2667 page
= extract32(insn
, 31, 1);
2668 /* SignExtend(immhi:immlo) -> offset */
2669 offset
= sextract64(insn
, 5, 19);
2670 offset
= offset
<< 2 | extract32(insn
, 29, 2);
2671 rd
= extract32(insn
, 0, 5);
2675 /* ADRP (page based) */
2680 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
2684 * C3.4.1 Add/subtract (immediate)
2686 * 31 30 29 28 24 23 22 21 10 9 5 4 0
2687 * +--+--+--+-----------+-----+-------------+-----+-----+
2688 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
2689 * +--+--+--+-----------+-----+-------------+-----+-----+
2691 * sf: 0 -> 32bit, 1 -> 64bit
2692 * op: 0 -> add , 1 -> sub
2694 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
2696 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
2698 int rd
= extract32(insn
, 0, 5);
2699 int rn
= extract32(insn
, 5, 5);
2700 uint64_t imm
= extract32(insn
, 10, 12);
2701 int shift
= extract32(insn
, 22, 2);
2702 bool setflags
= extract32(insn
, 29, 1);
2703 bool sub_op
= extract32(insn
, 30, 1);
2704 bool is_64bit
= extract32(insn
, 31, 1);
2706 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2707 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
2708 TCGv_i64 tcg_result
;
2717 unallocated_encoding(s
);
2721 tcg_result
= tcg_temp_new_i64();
2724 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
2726 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
2729 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
2731 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2733 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2735 tcg_temp_free_i64(tcg_imm
);
2739 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
2741 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
2744 tcg_temp_free_i64(tcg_result
);
2747 /* The input should be a value in the bottom e bits (with higher
2748 * bits zero); returns that value replicated into every element
2749 * of size e in a 64 bit integer.
2751 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
2761 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
2762 static inline uint64_t bitmask64(unsigned int length
)
2764 assert(length
> 0 && length
<= 64);
2765 return ~0ULL >> (64 - length
);
2768 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
2769 * only require the wmask. Returns false if the imms/immr/immn are a reserved
2770 * value (ie should cause a guest UNDEF exception), and true if they are
2771 * valid, in which case the decoded bit pattern is written to result.
2773 static bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
2774 unsigned int imms
, unsigned int immr
)
2777 unsigned e
, levels
, s
, r
;
2780 assert(immn
< 2 && imms
< 64 && immr
< 64);
2782 /* The bit patterns we create here are 64 bit patterns which
2783 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
2784 * 64 bits each. Each element contains the same value: a run
2785 * of between 1 and e-1 non-zero bits, rotated within the
2786 * element by between 0 and e-1 bits.
2788 * The element size and run length are encoded into immn (1 bit)
2789 * and imms (6 bits) as follows:
2790 * 64 bit elements: immn = 1, imms = <length of run - 1>
2791 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
2792 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
2793 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
2794 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
2795 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
2796 * Notice that immn = 0, imms = 11111x is the only combination
2797 * not covered by one of the above options; this is reserved.
2798 * Further, <length of run - 1> all-ones is a reserved pattern.
2800 * In all cases the rotation is by immr % e (and immr is 6 bits).
2803 /* First determine the element size */
2804 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
2806 /* This is the immn == 0, imms == 0x11111x case */
2816 /* <length of run - 1> mustn't be all-ones. */
2820 /* Create the value of one element: s+1 set bits rotated
2821 * by r within the element (which is e bits wide)...
2823 mask
= bitmask64(s
+ 1);
2825 mask
= (mask
>> r
) | (mask
<< (e
- r
));
2826 mask
&= bitmask64(e
);
2828 /* ...then replicate the element over the whole 64 bit value */
2829 mask
= bitfield_replicate(mask
, e
);
2834 /* C3.4.4 Logical (immediate)
2835 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2836 * +----+-----+-------------+---+------+------+------+------+
2837 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
2838 * +----+-----+-------------+---+------+------+------+------+
2840 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
2842 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
2843 TCGv_i64 tcg_rd
, tcg_rn
;
2845 bool is_and
= false;
2847 sf
= extract32(insn
, 31, 1);
2848 opc
= extract32(insn
, 29, 2);
2849 is_n
= extract32(insn
, 22, 1);
2850 immr
= extract32(insn
, 16, 6);
2851 imms
= extract32(insn
, 10, 6);
2852 rn
= extract32(insn
, 5, 5);
2853 rd
= extract32(insn
, 0, 5);
2856 unallocated_encoding(s
);
2860 if (opc
== 0x3) { /* ANDS */
2861 tcg_rd
= cpu_reg(s
, rd
);
2863 tcg_rd
= cpu_reg_sp(s
, rd
);
2865 tcg_rn
= cpu_reg(s
, rn
);
2867 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
2868 /* some immediate field values are reserved */
2869 unallocated_encoding(s
);
2874 wmask
&= 0xffffffff;
2878 case 0x3: /* ANDS */
2880 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
2884 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
2887 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
2890 assert(FALSE
); /* must handle all above */
2894 if (!sf
&& !is_and
) {
2895 /* zero extend final result; we know we can skip this for AND
2896 * since the immediate had the high 32 bits clear.
2898 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2901 if (opc
== 3) { /* ANDS */
2902 gen_logic_CC(sf
, tcg_rd
);
2907 * C3.4.5 Move wide (immediate)
2909 * 31 30 29 28 23 22 21 20 5 4 0
2910 * +--+-----+-------------+-----+----------------+------+
2911 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
2912 * +--+-----+-------------+-----+----------------+------+
2914 * sf: 0 -> 32 bit, 1 -> 64 bit
2915 * opc: 00 -> N, 10 -> Z, 11 -> K
2916 * hw: shift/16 (0,16, and sf only 32, 48)
2918 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
2920 int rd
= extract32(insn
, 0, 5);
2921 uint64_t imm
= extract32(insn
, 5, 16);
2922 int sf
= extract32(insn
, 31, 1);
2923 int opc
= extract32(insn
, 29, 2);
2924 int pos
= extract32(insn
, 21, 2) << 4;
2925 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
2928 if (!sf
&& (pos
>= 32)) {
2929 unallocated_encoding(s
);
2943 tcg_gen_movi_i64(tcg_rd
, imm
);
2946 tcg_imm
= tcg_const_i64(imm
);
2947 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
2948 tcg_temp_free_i64(tcg_imm
);
2950 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2954 unallocated_encoding(s
);
2960 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2961 * +----+-----+-------------+---+------+------+------+------+
2962 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
2963 * +----+-----+-------------+---+------+------+------+------+
2965 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
2967 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
2968 TCGv_i64 tcg_rd
, tcg_tmp
;
2970 sf
= extract32(insn
, 31, 1);
2971 opc
= extract32(insn
, 29, 2);
2972 n
= extract32(insn
, 22, 1);
2973 ri
= extract32(insn
, 16, 6);
2974 si
= extract32(insn
, 10, 6);
2975 rn
= extract32(insn
, 5, 5);
2976 rd
= extract32(insn
, 0, 5);
2977 bitsize
= sf
? 64 : 32;
2979 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
2980 unallocated_encoding(s
);
2984 tcg_rd
= cpu_reg(s
, rd
);
2985 tcg_tmp
= read_cpu_reg(s
, rn
, sf
);
2987 /* OPTME: probably worth recognizing common cases of ext{8,16,32}{u,s} */
2989 if (opc
!= 1) { /* SBFM or UBFM */
2990 tcg_gen_movi_i64(tcg_rd
, 0);
2993 /* do the bit move operation */
2995 /* Wd<s-r:0> = Wn<s:r> */
2996 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
2998 len
= (si
- ri
) + 1;
3000 /* Wd<32+s-r,32-r> = Wn<s:0> */
3005 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
3007 if (opc
== 0) { /* SBFM - sign extend the destination field */
3008 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
3009 tcg_gen_sari_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
3012 if (!sf
) { /* zero extend final result */
3013 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3018 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
3019 * +----+------+-------------+---+----+------+--------+------+------+
3020 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3021 * +----+------+-------------+---+----+------+--------+------+------+
3023 static void disas_extract(DisasContext
*s
, uint32_t insn
)
3025 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
3027 sf
= extract32(insn
, 31, 1);
3028 n
= extract32(insn
, 22, 1);
3029 rm
= extract32(insn
, 16, 5);
3030 imm
= extract32(insn
, 10, 6);
3031 rn
= extract32(insn
, 5, 5);
3032 rd
= extract32(insn
, 0, 5);
3033 op21
= extract32(insn
, 29, 2);
3034 op0
= extract32(insn
, 21, 1);
3035 bitsize
= sf
? 64 : 32;
3037 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
3038 unallocated_encoding(s
);
3040 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
3042 tcg_rd
= cpu_reg(s
, rd
);
3045 /* OPTME: we can special case rm==rn as a rotate */
3046 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3047 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3048 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
3049 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
3050 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
3052 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3055 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3056 * so an extract from bit 0 is a special case.
3059 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
3061 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
3068 /* C3.4 Data processing - immediate */
3069 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
3071 switch (extract32(insn
, 23, 6)) {
3072 case 0x20: case 0x21: /* PC-rel. addressing */
3073 disas_pc_rel_adr(s
, insn
);
3075 case 0x22: case 0x23: /* Add/subtract (immediate) */
3076 disas_add_sub_imm(s
, insn
);
3078 case 0x24: /* Logical (immediate) */
3079 disas_logic_imm(s
, insn
);
3081 case 0x25: /* Move wide (immediate) */
3082 disas_movw_imm(s
, insn
);
3084 case 0x26: /* Bitfield */
3085 disas_bitfield(s
, insn
);
3087 case 0x27: /* Extract */
3088 disas_extract(s
, insn
);
3091 unallocated_encoding(s
);
3096 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3097 * Note that it is the caller's responsibility to ensure that the
3098 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3099 * mandated semantics for out of range shifts.
3101 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3102 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
3104 switch (shift_type
) {
3105 case A64_SHIFT_TYPE_LSL
:
3106 tcg_gen_shl_i64(dst
, src
, shift_amount
);
3108 case A64_SHIFT_TYPE_LSR
:
3109 tcg_gen_shr_i64(dst
, src
, shift_amount
);
3111 case A64_SHIFT_TYPE_ASR
:
3113 tcg_gen_ext32s_i64(dst
, src
);
3115 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
3117 case A64_SHIFT_TYPE_ROR
:
3119 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
3122 t0
= tcg_temp_new_i32();
3123 t1
= tcg_temp_new_i32();
3124 tcg_gen_trunc_i64_i32(t0
, src
);
3125 tcg_gen_trunc_i64_i32(t1
, shift_amount
);
3126 tcg_gen_rotr_i32(t0
, t0
, t1
);
3127 tcg_gen_extu_i32_i64(dst
, t0
);
3128 tcg_temp_free_i32(t0
);
3129 tcg_temp_free_i32(t1
);
3133 assert(FALSE
); /* all shift types should be handled */
3137 if (!sf
) { /* zero extend final result */
3138 tcg_gen_ext32u_i64(dst
, dst
);
3142 /* Shift a TCGv src by immediate, put result in dst.
3143 * The shift amount must be in range (this should always be true as the
3144 * relevant instructions will UNDEF on bad shift immediates).
3146 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3147 enum a64_shift_type shift_type
, unsigned int shift_i
)
3149 assert(shift_i
< (sf
? 64 : 32));
3152 tcg_gen_mov_i64(dst
, src
);
3154 TCGv_i64 shift_const
;
3156 shift_const
= tcg_const_i64(shift_i
);
3157 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
3158 tcg_temp_free_i64(shift_const
);
3162 /* C3.5.10 Logical (shifted register)
3163 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3164 * +----+-----+-----------+-------+---+------+--------+------+------+
3165 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3166 * +----+-----+-----------+-------+---+------+--------+------+------+
3168 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
3170 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
3171 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
3173 sf
= extract32(insn
, 31, 1);
3174 opc
= extract32(insn
, 29, 2);
3175 shift_type
= extract32(insn
, 22, 2);
3176 invert
= extract32(insn
, 21, 1);
3177 rm
= extract32(insn
, 16, 5);
3178 shift_amount
= extract32(insn
, 10, 6);
3179 rn
= extract32(insn
, 5, 5);
3180 rd
= extract32(insn
, 0, 5);
3182 if (!sf
&& (shift_amount
& (1 << 5))) {
3183 unallocated_encoding(s
);
3187 tcg_rd
= cpu_reg(s
, rd
);
3189 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3190 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3191 * register-register MOV and MVN, so it is worth special casing.
3193 tcg_rm
= cpu_reg(s
, rm
);
3195 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3197 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3201 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3203 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3209 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3212 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3215 tcg_rn
= cpu_reg(s
, rn
);
3217 switch (opc
| (invert
<< 2)) {
3220 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3223 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3226 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3230 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3233 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3236 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3244 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3248 gen_logic_CC(sf
, tcg_rd
);
3253 * C3.5.1 Add/subtract (extended register)
3255 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3256 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3257 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3258 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3260 * sf: 0 -> 32bit, 1 -> 64bit
3261 * op: 0 -> add , 1 -> sub
3264 * option: extension type (see DecodeRegExtend)
3265 * imm3: optional shift to Rm
3267 * Rd = Rn + LSL(extend(Rm), amount)
3269 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3271 int rd
= extract32(insn
, 0, 5);
3272 int rn
= extract32(insn
, 5, 5);
3273 int imm3
= extract32(insn
, 10, 3);
3274 int option
= extract32(insn
, 13, 3);
3275 int rm
= extract32(insn
, 16, 5);
3276 bool setflags
= extract32(insn
, 29, 1);
3277 bool sub_op
= extract32(insn
, 30, 1);
3278 bool sf
= extract32(insn
, 31, 1);
3280 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3282 TCGv_i64 tcg_result
;
3285 unallocated_encoding(s
);
3289 /* non-flag setting ops may use SP */
3291 tcg_rd
= cpu_reg_sp(s
, rd
);
3293 tcg_rd
= cpu_reg(s
, rd
);
3295 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3297 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3298 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3300 tcg_result
= tcg_temp_new_i64();
3304 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3306 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3310 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3312 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3317 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3319 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3322 tcg_temp_free_i64(tcg_result
);
3326 * C3.5.2 Add/subtract (shifted register)
3328 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3329 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3330 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3331 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3333 * sf: 0 -> 32bit, 1 -> 64bit
3334 * op: 0 -> add , 1 -> sub
3336 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3337 * imm6: Shift amount to apply to Rm before the add/sub
3339 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
3341 int rd
= extract32(insn
, 0, 5);
3342 int rn
= extract32(insn
, 5, 5);
3343 int imm6
= extract32(insn
, 10, 6);
3344 int rm
= extract32(insn
, 16, 5);
3345 int shift_type
= extract32(insn
, 22, 2);
3346 bool setflags
= extract32(insn
, 29, 1);
3347 bool sub_op
= extract32(insn
, 30, 1);
3348 bool sf
= extract32(insn
, 31, 1);
3350 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3351 TCGv_i64 tcg_rn
, tcg_rm
;
3352 TCGv_i64 tcg_result
;
3354 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
3355 unallocated_encoding(s
);
3359 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3360 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3362 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
3364 tcg_result
= tcg_temp_new_i64();
3368 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3370 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3374 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3376 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3381 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3383 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3386 tcg_temp_free_i64(tcg_result
);
3389 /* C3.5.9 Data-processing (3 source)
3391 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3392 +--+------+-----------+------+------+----+------+------+------+
3393 |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3394 +--+------+-----------+------+------+----+------+------+------+
3397 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
3399 int rd
= extract32(insn
, 0, 5);
3400 int rn
= extract32(insn
, 5, 5);
3401 int ra
= extract32(insn
, 10, 5);
3402 int rm
= extract32(insn
, 16, 5);
3403 int op_id
= (extract32(insn
, 29, 3) << 4) |
3404 (extract32(insn
, 21, 3) << 1) |
3405 extract32(insn
, 15, 1);
3406 bool sf
= extract32(insn
, 31, 1);
3407 bool is_sub
= extract32(op_id
, 0, 1);
3408 bool is_high
= extract32(op_id
, 2, 1);
3409 bool is_signed
= false;
3414 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
3416 case 0x42: /* SMADDL */
3417 case 0x43: /* SMSUBL */
3418 case 0x44: /* SMULH */
3421 case 0x0: /* MADD (32bit) */
3422 case 0x1: /* MSUB (32bit) */
3423 case 0x40: /* MADD (64bit) */
3424 case 0x41: /* MSUB (64bit) */
3425 case 0x4a: /* UMADDL */
3426 case 0x4b: /* UMSUBL */
3427 case 0x4c: /* UMULH */
3430 unallocated_encoding(s
);
3435 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
3436 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3437 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
3438 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
3441 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3443 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3446 tcg_temp_free_i64(low_bits
);
3450 tcg_op1
= tcg_temp_new_i64();
3451 tcg_op2
= tcg_temp_new_i64();
3452 tcg_tmp
= tcg_temp_new_i64();
3455 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
3456 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
3459 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
3460 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
3462 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
3463 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
3467 if (ra
== 31 && !is_sub
) {
3468 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
3469 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
3471 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
3473 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3475 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3480 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
3483 tcg_temp_free_i64(tcg_op1
);
3484 tcg_temp_free_i64(tcg_op2
);
3485 tcg_temp_free_i64(tcg_tmp
);
3488 /* C3.5.3 - Add/subtract (with carry)
3489 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
3490 * +--+--+--+------------------------+------+---------+------+-----+
3491 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
3492 * +--+--+--+------------------------+------+---------+------+-----+
3496 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
3498 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
3499 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
3501 if (extract32(insn
, 10, 6) != 0) {
3502 unallocated_encoding(s
);
3506 sf
= extract32(insn
, 31, 1);
3507 op
= extract32(insn
, 30, 1);
3508 setflags
= extract32(insn
, 29, 1);
3509 rm
= extract32(insn
, 16, 5);
3510 rn
= extract32(insn
, 5, 5);
3511 rd
= extract32(insn
, 0, 5);
3513 tcg_rd
= cpu_reg(s
, rd
);
3514 tcg_rn
= cpu_reg(s
, rn
);
3517 tcg_y
= new_tmp_a64(s
);
3518 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
3520 tcg_y
= cpu_reg(s
, rm
);
3524 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3526 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3530 /* C3.5.4 - C3.5.5 Conditional compare (immediate / register)
3531 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3532 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3533 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
3534 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3537 static void disas_cc(DisasContext
*s
, uint32_t insn
)
3539 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
3540 TCGLabel
*label_continue
= NULL
;
3541 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
3543 if (!extract32(insn
, 29, 1)) {
3544 unallocated_encoding(s
);
3547 if (insn
& (1 << 10 | 1 << 4)) {
3548 unallocated_encoding(s
);
3551 sf
= extract32(insn
, 31, 1);
3552 op
= extract32(insn
, 30, 1);
3553 is_imm
= extract32(insn
, 11, 1);
3554 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
3555 cond
= extract32(insn
, 12, 4);
3556 rn
= extract32(insn
, 5, 5);
3557 nzcv
= extract32(insn
, 0, 4);
3559 if (cond
< 0x0e) { /* not always */
3560 TCGLabel
*label_match
= gen_new_label();
3561 label_continue
= gen_new_label();
3562 arm_gen_test_cc(cond
, label_match
);
3564 tcg_tmp
= tcg_temp_new_i64();
3565 tcg_gen_movi_i64(tcg_tmp
, nzcv
<< 28);
3566 gen_set_nzcv(tcg_tmp
);
3567 tcg_temp_free_i64(tcg_tmp
);
3568 tcg_gen_br(label_continue
);
3569 gen_set_label(label_match
);
3571 /* match, or condition is always */
3573 tcg_y
= new_tmp_a64(s
);
3574 tcg_gen_movi_i64(tcg_y
, y
);
3576 tcg_y
= cpu_reg(s
, y
);
3578 tcg_rn
= cpu_reg(s
, rn
);
3580 tcg_tmp
= tcg_temp_new_i64();
3582 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3584 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3586 tcg_temp_free_i64(tcg_tmp
);
3588 if (cond
< 0x0e) { /* continue */
3589 gen_set_label(label_continue
);
3593 /* C3.5.6 Conditional select
3594 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
3595 * +----+----+---+-----------------+------+------+-----+------+------+
3596 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
3597 * +----+----+---+-----------------+------+------+-----+------+------+
3599 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
3601 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
3602 TCGv_i64 tcg_rd
, tcg_src
;
3604 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
3605 /* S == 1 or op2<1> == 1 */
3606 unallocated_encoding(s
);
3609 sf
= extract32(insn
, 31, 1);
3610 else_inv
= extract32(insn
, 30, 1);
3611 rm
= extract32(insn
, 16, 5);
3612 cond
= extract32(insn
, 12, 4);
3613 else_inc
= extract32(insn
, 10, 1);
3614 rn
= extract32(insn
, 5, 5);
3615 rd
= extract32(insn
, 0, 5);
3618 /* silly no-op write; until we use movcond we must special-case
3619 * this to avoid a dead temporary across basic blocks.
3624 tcg_rd
= cpu_reg(s
, rd
);
3626 if (cond
>= 0x0e) { /* condition "always" */
3627 tcg_src
= read_cpu_reg(s
, rn
, sf
);
3628 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3630 /* OPTME: we could use movcond here, at the cost of duplicating
3631 * a lot of the arm_gen_test_cc() logic.
3633 TCGLabel
*label_match
= gen_new_label();
3634 TCGLabel
*label_continue
= gen_new_label();
3636 arm_gen_test_cc(cond
, label_match
);
3638 tcg_src
= cpu_reg(s
, rm
);
3640 if (else_inv
&& else_inc
) {
3641 tcg_gen_neg_i64(tcg_rd
, tcg_src
);
3642 } else if (else_inv
) {
3643 tcg_gen_not_i64(tcg_rd
, tcg_src
);
3644 } else if (else_inc
) {
3645 tcg_gen_addi_i64(tcg_rd
, tcg_src
, 1);
3647 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3650 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3652 tcg_gen_br(label_continue
);
3654 gen_set_label(label_match
);
3655 tcg_src
= read_cpu_reg(s
, rn
, sf
);
3656 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3658 gen_set_label(label_continue
);
3662 static void handle_clz(DisasContext
*s
, unsigned int sf
,
3663 unsigned int rn
, unsigned int rd
)
3665 TCGv_i64 tcg_rd
, tcg_rn
;
3666 tcg_rd
= cpu_reg(s
, rd
);
3667 tcg_rn
= cpu_reg(s
, rn
);
3670 gen_helper_clz64(tcg_rd
, tcg_rn
);
3672 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3673 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3674 gen_helper_clz(tcg_tmp32
, tcg_tmp32
);
3675 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3676 tcg_temp_free_i32(tcg_tmp32
);
3680 static void handle_cls(DisasContext
*s
, unsigned int sf
,
3681 unsigned int rn
, unsigned int rd
)
3683 TCGv_i64 tcg_rd
, tcg_rn
;
3684 tcg_rd
= cpu_reg(s
, rd
);
3685 tcg_rn
= cpu_reg(s
, rn
);
3688 gen_helper_cls64(tcg_rd
, tcg_rn
);
3690 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3691 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3692 gen_helper_cls32(tcg_tmp32
, tcg_tmp32
);
3693 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3694 tcg_temp_free_i32(tcg_tmp32
);
3698 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
3699 unsigned int rn
, unsigned int rd
)
3701 TCGv_i64 tcg_rd
, tcg_rn
;
3702 tcg_rd
= cpu_reg(s
, rd
);
3703 tcg_rn
= cpu_reg(s
, rn
);
3706 gen_helper_rbit64(tcg_rd
, tcg_rn
);
3708 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3709 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3710 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
3711 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3712 tcg_temp_free_i32(tcg_tmp32
);
3716 /* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
3717 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
3718 unsigned int rn
, unsigned int rd
)
3721 unallocated_encoding(s
);
3724 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
3727 /* C5.6.149 REV with sf==0, opcode==2
3728 * C5.6.151 REV32 (sf==1, opcode==2)
3730 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
3731 unsigned int rn
, unsigned int rd
)
3733 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3736 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3737 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3739 /* bswap32_i64 requires zero high word */
3740 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
3741 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
3742 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3743 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
3744 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
3746 tcg_temp_free_i64(tcg_tmp
);
3748 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
3749 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
3753 /* C5.6.150 REV16 (opcode==1) */
3754 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
3755 unsigned int rn
, unsigned int rd
)
3757 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3758 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3759 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3761 tcg_gen_andi_i64(tcg_tmp
, tcg_rn
, 0xffff);
3762 tcg_gen_bswap16_i64(tcg_rd
, tcg_tmp
);
3764 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 16);
3765 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3766 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3767 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 16, 16);
3770 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3771 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3772 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3773 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 32, 16);
3775 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 48);
3776 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3777 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 48, 16);
3780 tcg_temp_free_i64(tcg_tmp
);
3783 /* C3.5.7 Data-processing (1 source)
3784 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3785 * +----+---+---+-----------------+---------+--------+------+------+
3786 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
3787 * +----+---+---+-----------------+---------+--------+------+------+
3789 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
3791 unsigned int sf
, opcode
, rn
, rd
;
3793 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
3794 unallocated_encoding(s
);
3798 sf
= extract32(insn
, 31, 1);
3799 opcode
= extract32(insn
, 10, 6);
3800 rn
= extract32(insn
, 5, 5);
3801 rd
= extract32(insn
, 0, 5);
3805 handle_rbit(s
, sf
, rn
, rd
);
3808 handle_rev16(s
, sf
, rn
, rd
);
3811 handle_rev32(s
, sf
, rn
, rd
);
3814 handle_rev64(s
, sf
, rn
, rd
);
3817 handle_clz(s
, sf
, rn
, rd
);
3820 handle_cls(s
, sf
, rn
, rd
);
3825 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
3826 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3828 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
3829 tcg_rd
= cpu_reg(s
, rd
);
3831 if (!sf
&& is_signed
) {
3832 tcg_n
= new_tmp_a64(s
);
3833 tcg_m
= new_tmp_a64(s
);
3834 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
3835 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
3837 tcg_n
= read_cpu_reg(s
, rn
, sf
);
3838 tcg_m
= read_cpu_reg(s
, rm
, sf
);
3842 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
3844 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
3847 if (!sf
) { /* zero extend final result */
3848 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3852 /* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
3853 static void handle_shift_reg(DisasContext
*s
,
3854 enum a64_shift_type shift_type
, unsigned int sf
,
3855 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3857 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
3858 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3859 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3861 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
3862 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
3863 tcg_temp_free_i64(tcg_shift
);
3866 /* CRC32[BHWX], CRC32C[BHWX] */
3867 static void handle_crc32(DisasContext
*s
,
3868 unsigned int sf
, unsigned int sz
, bool crc32c
,
3869 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3871 TCGv_i64 tcg_acc
, tcg_val
;
3874 if (!arm_dc_feature(s
, ARM_FEATURE_CRC
)
3875 || (sf
== 1 && sz
!= 3)
3876 || (sf
== 0 && sz
== 3)) {
3877 unallocated_encoding(s
);
3882 tcg_val
= cpu_reg(s
, rm
);
3896 g_assert_not_reached();
3898 tcg_val
= new_tmp_a64(s
);
3899 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
3902 tcg_acc
= cpu_reg(s
, rn
);
3903 tcg_bytes
= tcg_const_i32(1 << sz
);
3906 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
3908 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
3911 tcg_temp_free_i32(tcg_bytes
);
3914 /* C3.5.8 Data-processing (2 source)
3915 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3916 * +----+---+---+-----------------+------+--------+------+------+
3917 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
3918 * +----+---+---+-----------------+------+--------+------+------+
3920 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
3922 unsigned int sf
, rm
, opcode
, rn
, rd
;
3923 sf
= extract32(insn
, 31, 1);
3924 rm
= extract32(insn
, 16, 5);
3925 opcode
= extract32(insn
, 10, 6);
3926 rn
= extract32(insn
, 5, 5);
3927 rd
= extract32(insn
, 0, 5);
3929 if (extract32(insn
, 29, 1)) {
3930 unallocated_encoding(s
);
3936 handle_div(s
, false, sf
, rm
, rn
, rd
);
3939 handle_div(s
, true, sf
, rm
, rn
, rd
);
3942 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
3945 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
3948 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
3951 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
3960 case 23: /* CRC32 */
3962 int sz
= extract32(opcode
, 0, 2);
3963 bool crc32c
= extract32(opcode
, 2, 1);
3964 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
3968 unallocated_encoding(s
);
3973 /* C3.5 Data processing - register */
3974 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
3976 switch (extract32(insn
, 24, 5)) {
3977 case 0x0a: /* Logical (shifted register) */
3978 disas_logic_reg(s
, insn
);
3980 case 0x0b: /* Add/subtract */
3981 if (insn
& (1 << 21)) { /* (extended register) */
3982 disas_add_sub_ext_reg(s
, insn
);
3984 disas_add_sub_reg(s
, insn
);
3987 case 0x1b: /* Data-processing (3 source) */
3988 disas_data_proc_3src(s
, insn
);
3991 switch (extract32(insn
, 21, 3)) {
3992 case 0x0: /* Add/subtract (with carry) */
3993 disas_adc_sbc(s
, insn
);
3995 case 0x2: /* Conditional compare */
3996 disas_cc(s
, insn
); /* both imm and reg forms */
3998 case 0x4: /* Conditional select */
3999 disas_cond_select(s
, insn
);
4001 case 0x6: /* Data-processing */
4002 if (insn
& (1 << 30)) { /* (1 source) */
4003 disas_data_proc_1src(s
, insn
);
4004 } else { /* (2 source) */
4005 disas_data_proc_2src(s
, insn
);
4009 unallocated_encoding(s
);
4014 unallocated_encoding(s
);
4019 static void handle_fp_compare(DisasContext
*s
, bool is_double
,
4020 unsigned int rn
, unsigned int rm
,
4021 bool cmp_with_zero
, bool signal_all_nans
)
4023 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
4024 TCGv_ptr fpst
= get_fpstatus_ptr();
4027 TCGv_i64 tcg_vn
, tcg_vm
;
4029 tcg_vn
= read_fp_dreg(s
, rn
);
4030 if (cmp_with_zero
) {
4031 tcg_vm
= tcg_const_i64(0);
4033 tcg_vm
= read_fp_dreg(s
, rm
);
4035 if (signal_all_nans
) {
4036 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4038 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4040 tcg_temp_free_i64(tcg_vn
);
4041 tcg_temp_free_i64(tcg_vm
);
4043 TCGv_i32 tcg_vn
, tcg_vm
;
4045 tcg_vn
= read_fp_sreg(s
, rn
);
4046 if (cmp_with_zero
) {
4047 tcg_vm
= tcg_const_i32(0);
4049 tcg_vm
= read_fp_sreg(s
, rm
);
4051 if (signal_all_nans
) {
4052 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4054 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4056 tcg_temp_free_i32(tcg_vn
);
4057 tcg_temp_free_i32(tcg_vm
);
4060 tcg_temp_free_ptr(fpst
);
4062 gen_set_nzcv(tcg_flags
);
4064 tcg_temp_free_i64(tcg_flags
);
4067 /* C3.6.22 Floating point compare
4068 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
4069 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4070 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
4071 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4073 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
4075 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
4077 mos
= extract32(insn
, 29, 3);
4078 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4079 rm
= extract32(insn
, 16, 5);
4080 op
= extract32(insn
, 14, 2);
4081 rn
= extract32(insn
, 5, 5);
4082 opc
= extract32(insn
, 3, 2);
4083 op2r
= extract32(insn
, 0, 3);
4085 if (mos
|| op
|| op2r
|| type
> 1) {
4086 unallocated_encoding(s
);
4090 if (!fp_access_check(s
)) {
4094 handle_fp_compare(s
, type
, rn
, rm
, opc
& 1, opc
& 2);
4097 /* C3.6.23 Floating point conditional compare
4098 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4099 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4100 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
4101 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4103 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
4105 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
4107 TCGLabel
*label_continue
= NULL
;
4109 mos
= extract32(insn
, 29, 3);
4110 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4111 rm
= extract32(insn
, 16, 5);
4112 cond
= extract32(insn
, 12, 4);
4113 rn
= extract32(insn
, 5, 5);
4114 op
= extract32(insn
, 4, 1);
4115 nzcv
= extract32(insn
, 0, 4);
4117 if (mos
|| type
> 1) {
4118 unallocated_encoding(s
);
4122 if (!fp_access_check(s
)) {
4126 if (cond
< 0x0e) { /* not always */
4127 TCGLabel
*label_match
= gen_new_label();
4128 label_continue
= gen_new_label();
4129 arm_gen_test_cc(cond
, label_match
);
4131 tcg_flags
= tcg_const_i64(nzcv
<< 28);
4132 gen_set_nzcv(tcg_flags
);
4133 tcg_temp_free_i64(tcg_flags
);
4134 tcg_gen_br(label_continue
);
4135 gen_set_label(label_match
);
4138 handle_fp_compare(s
, type
, rn
, rm
, false, op
);
4141 gen_set_label(label_continue
);
4145 /* copy src FP register to dst FP register; type specifies single or double */
4146 static void gen_mov_fp2fp(DisasContext
*s
, int type
, int dst
, int src
)
4149 TCGv_i64 v
= read_fp_dreg(s
, src
);
4150 write_fp_dreg(s
, dst
, v
);
4151 tcg_temp_free_i64(v
);
4153 TCGv_i32 v
= read_fp_sreg(s
, src
);
4154 write_fp_sreg(s
, dst
, v
);
4155 tcg_temp_free_i32(v
);
4159 /* C3.6.24 Floating point conditional select
4160 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4161 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4162 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
4163 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4165 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
4167 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
4168 TCGLabel
*label_continue
= NULL
;
4170 mos
= extract32(insn
, 29, 3);
4171 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4172 rm
= extract32(insn
, 16, 5);
4173 cond
= extract32(insn
, 12, 4);
4174 rn
= extract32(insn
, 5, 5);
4175 rd
= extract32(insn
, 0, 5);
4177 if (mos
|| type
> 1) {
4178 unallocated_encoding(s
);
4182 if (!fp_access_check(s
)) {
4186 if (cond
< 0x0e) { /* not always */
4187 TCGLabel
*label_match
= gen_new_label();
4188 label_continue
= gen_new_label();
4189 arm_gen_test_cc(cond
, label_match
);
4191 gen_mov_fp2fp(s
, type
, rd
, rm
);
4192 tcg_gen_br(label_continue
);
4193 gen_set_label(label_match
);
4196 gen_mov_fp2fp(s
, type
, rd
, rn
);
4198 if (cond
< 0x0e) { /* continue */
4199 gen_set_label(label_continue
);
4203 /* C3.6.25 Floating-point data-processing (1 source) - single precision */
4204 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
4210 fpst
= get_fpstatus_ptr();
4211 tcg_op
= read_fp_sreg(s
, rn
);
4212 tcg_res
= tcg_temp_new_i32();
4215 case 0x0: /* FMOV */
4216 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4218 case 0x1: /* FABS */
4219 gen_helper_vfp_abss(tcg_res
, tcg_op
);
4221 case 0x2: /* FNEG */
4222 gen_helper_vfp_negs(tcg_res
, tcg_op
);
4224 case 0x3: /* FSQRT */
4225 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
4227 case 0x8: /* FRINTN */
4228 case 0x9: /* FRINTP */
4229 case 0xa: /* FRINTM */
4230 case 0xb: /* FRINTZ */
4231 case 0xc: /* FRINTA */
4233 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4235 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4236 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4238 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4239 tcg_temp_free_i32(tcg_rmode
);
4242 case 0xe: /* FRINTX */
4243 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
4245 case 0xf: /* FRINTI */
4246 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4252 write_fp_sreg(s
, rd
, tcg_res
);
4254 tcg_temp_free_ptr(fpst
);
4255 tcg_temp_free_i32(tcg_op
);
4256 tcg_temp_free_i32(tcg_res
);
4259 /* C3.6.25 Floating-point data-processing (1 source) - double precision */
4260 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
4266 fpst
= get_fpstatus_ptr();
4267 tcg_op
= read_fp_dreg(s
, rn
);
4268 tcg_res
= tcg_temp_new_i64();
4271 case 0x0: /* FMOV */
4272 tcg_gen_mov_i64(tcg_res
, tcg_op
);
4274 case 0x1: /* FABS */
4275 gen_helper_vfp_absd(tcg_res
, tcg_op
);
4277 case 0x2: /* FNEG */
4278 gen_helper_vfp_negd(tcg_res
, tcg_op
);
4280 case 0x3: /* FSQRT */
4281 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
4283 case 0x8: /* FRINTN */
4284 case 0x9: /* FRINTP */
4285 case 0xa: /* FRINTM */
4286 case 0xb: /* FRINTZ */
4287 case 0xc: /* FRINTA */
4289 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4291 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4292 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4294 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4295 tcg_temp_free_i32(tcg_rmode
);
4298 case 0xe: /* FRINTX */
4299 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
4301 case 0xf: /* FRINTI */
4302 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4308 write_fp_dreg(s
, rd
, tcg_res
);
4310 tcg_temp_free_ptr(fpst
);
4311 tcg_temp_free_i64(tcg_op
);
4312 tcg_temp_free_i64(tcg_res
);
4315 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
4316 int rd
, int rn
, int dtype
, int ntype
)
4321 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4323 /* Single to double */
4324 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4325 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
4326 write_fp_dreg(s
, rd
, tcg_rd
);
4327 tcg_temp_free_i64(tcg_rd
);
4329 /* Single to half */
4330 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4331 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4332 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4333 write_fp_sreg(s
, rd
, tcg_rd
);
4334 tcg_temp_free_i32(tcg_rd
);
4336 tcg_temp_free_i32(tcg_rn
);
4341 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
4342 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4344 /* Double to single */
4345 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
4347 /* Double to half */
4348 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4349 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4351 write_fp_sreg(s
, rd
, tcg_rd
);
4352 tcg_temp_free_i32(tcg_rd
);
4353 tcg_temp_free_i64(tcg_rn
);
4358 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4359 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
4361 /* Half to single */
4362 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4363 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, cpu_env
);
4364 write_fp_sreg(s
, rd
, tcg_rd
);
4365 tcg_temp_free_i32(tcg_rd
);
4367 /* Half to double */
4368 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4369 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, cpu_env
);
4370 write_fp_dreg(s
, rd
, tcg_rd
);
4371 tcg_temp_free_i64(tcg_rd
);
4373 tcg_temp_free_i32(tcg_rn
);
4381 /* C3.6.25 Floating point data-processing (1 source)
4382 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
4383 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4384 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
4385 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4387 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
4389 int type
= extract32(insn
, 22, 2);
4390 int opcode
= extract32(insn
, 15, 6);
4391 int rn
= extract32(insn
, 5, 5);
4392 int rd
= extract32(insn
, 0, 5);
4395 case 0x4: case 0x5: case 0x7:
4397 /* FCVT between half, single and double precision */
4398 int dtype
= extract32(opcode
, 0, 2);
4399 if (type
== 2 || dtype
== type
) {
4400 unallocated_encoding(s
);
4403 if (!fp_access_check(s
)) {
4407 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
4413 /* 32-to-32 and 64-to-64 ops */
4416 if (!fp_access_check(s
)) {
4420 handle_fp_1src_single(s
, opcode
, rd
, rn
);
4423 if (!fp_access_check(s
)) {
4427 handle_fp_1src_double(s
, opcode
, rd
, rn
);
4430 unallocated_encoding(s
);
4434 unallocated_encoding(s
);
4439 /* C3.6.26 Floating-point data-processing (2 source) - single precision */
4440 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
4441 int rd
, int rn
, int rm
)
4448 tcg_res
= tcg_temp_new_i32();
4449 fpst
= get_fpstatus_ptr();
4450 tcg_op1
= read_fp_sreg(s
, rn
);
4451 tcg_op2
= read_fp_sreg(s
, rm
);
4454 case 0x0: /* FMUL */
4455 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4457 case 0x1: /* FDIV */
4458 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4460 case 0x2: /* FADD */
4461 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4463 case 0x3: /* FSUB */
4464 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4466 case 0x4: /* FMAX */
4467 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4469 case 0x5: /* FMIN */
4470 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4472 case 0x6: /* FMAXNM */
4473 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4475 case 0x7: /* FMINNM */
4476 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4478 case 0x8: /* FNMUL */
4479 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4480 gen_helper_vfp_negs(tcg_res
, tcg_res
);
4484 write_fp_sreg(s
, rd
, tcg_res
);
4486 tcg_temp_free_ptr(fpst
);
4487 tcg_temp_free_i32(tcg_op1
);
4488 tcg_temp_free_i32(tcg_op2
);
4489 tcg_temp_free_i32(tcg_res
);
4492 /* C3.6.26 Floating-point data-processing (2 source) - double precision */
4493 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
4494 int rd
, int rn
, int rm
)
4501 tcg_res
= tcg_temp_new_i64();
4502 fpst
= get_fpstatus_ptr();
4503 tcg_op1
= read_fp_dreg(s
, rn
);
4504 tcg_op2
= read_fp_dreg(s
, rm
);
4507 case 0x0: /* FMUL */
4508 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4510 case 0x1: /* FDIV */
4511 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4513 case 0x2: /* FADD */
4514 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4516 case 0x3: /* FSUB */
4517 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4519 case 0x4: /* FMAX */
4520 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4522 case 0x5: /* FMIN */
4523 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4525 case 0x6: /* FMAXNM */
4526 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4528 case 0x7: /* FMINNM */
4529 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4531 case 0x8: /* FNMUL */
4532 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4533 gen_helper_vfp_negd(tcg_res
, tcg_res
);
4537 write_fp_dreg(s
, rd
, tcg_res
);
4539 tcg_temp_free_ptr(fpst
);
4540 tcg_temp_free_i64(tcg_op1
);
4541 tcg_temp_free_i64(tcg_op2
);
4542 tcg_temp_free_i64(tcg_res
);
4545 /* C3.6.26 Floating point data-processing (2 source)
4546 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4547 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4548 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
4549 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4551 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
4553 int type
= extract32(insn
, 22, 2);
4554 int rd
= extract32(insn
, 0, 5);
4555 int rn
= extract32(insn
, 5, 5);
4556 int rm
= extract32(insn
, 16, 5);
4557 int opcode
= extract32(insn
, 12, 4);
4560 unallocated_encoding(s
);
4566 if (!fp_access_check(s
)) {
4569 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
4572 if (!fp_access_check(s
)) {
4575 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
4578 unallocated_encoding(s
);
4582 /* C3.6.27 Floating-point data-processing (3 source) - single precision */
4583 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
4584 int rd
, int rn
, int rm
, int ra
)
4586 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
4587 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4588 TCGv_ptr fpst
= get_fpstatus_ptr();
4590 tcg_op1
= read_fp_sreg(s
, rn
);
4591 tcg_op2
= read_fp_sreg(s
, rm
);
4592 tcg_op3
= read_fp_sreg(s
, ra
);
4594 /* These are fused multiply-add, and must be done as one
4595 * floating point operation with no rounding between the
4596 * multiplication and addition steps.
4597 * NB that doing the negations here as separate steps is
4598 * correct : an input NaN should come out with its sign bit
4599 * flipped if it is a negated-input.
4602 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
4606 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
4609 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4611 write_fp_sreg(s
, rd
, tcg_res
);
4613 tcg_temp_free_ptr(fpst
);
4614 tcg_temp_free_i32(tcg_op1
);
4615 tcg_temp_free_i32(tcg_op2
);
4616 tcg_temp_free_i32(tcg_op3
);
4617 tcg_temp_free_i32(tcg_res
);
4620 /* C3.6.27 Floating-point data-processing (3 source) - double precision */
4621 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
4622 int rd
, int rn
, int rm
, int ra
)
4624 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
4625 TCGv_i64 tcg_res
= tcg_temp_new_i64();
4626 TCGv_ptr fpst
= get_fpstatus_ptr();
4628 tcg_op1
= read_fp_dreg(s
, rn
);
4629 tcg_op2
= read_fp_dreg(s
, rm
);
4630 tcg_op3
= read_fp_dreg(s
, ra
);
4632 /* These are fused multiply-add, and must be done as one
4633 * floating point operation with no rounding between the
4634 * multiplication and addition steps.
4635 * NB that doing the negations here as separate steps is
4636 * correct : an input NaN should come out with its sign bit
4637 * flipped if it is a negated-input.
4640 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
4644 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
4647 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4649 write_fp_dreg(s
, rd
, tcg_res
);
4651 tcg_temp_free_ptr(fpst
);
4652 tcg_temp_free_i64(tcg_op1
);
4653 tcg_temp_free_i64(tcg_op2
);
4654 tcg_temp_free_i64(tcg_op3
);
4655 tcg_temp_free_i64(tcg_res
);
4658 /* C3.6.27 Floating point data-processing (3 source)
4659 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
4660 * +---+---+---+-----------+------+----+------+----+------+------+------+
4661 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
4662 * +---+---+---+-----------+------+----+------+----+------+------+------+
4664 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
4666 int type
= extract32(insn
, 22, 2);
4667 int rd
= extract32(insn
, 0, 5);
4668 int rn
= extract32(insn
, 5, 5);
4669 int ra
= extract32(insn
, 10, 5);
4670 int rm
= extract32(insn
, 16, 5);
4671 bool o0
= extract32(insn
, 15, 1);
4672 bool o1
= extract32(insn
, 21, 1);
4676 if (!fp_access_check(s
)) {
4679 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4682 if (!fp_access_check(s
)) {
4685 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4688 unallocated_encoding(s
);
4692 /* C3.6.28 Floating point immediate
4693 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
4694 * +---+---+---+-----------+------+---+------------+-------+------+------+
4695 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
4696 * +---+---+---+-----------+------+---+------------+-------+------+------+
4698 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
4700 int rd
= extract32(insn
, 0, 5);
4701 int imm8
= extract32(insn
, 13, 8);
4702 int is_double
= extract32(insn
, 22, 2);
4706 if (is_double
> 1) {
4707 unallocated_encoding(s
);
4711 if (!fp_access_check(s
)) {
4715 /* The imm8 encodes the sign bit, enough bits to represent
4716 * an exponent in the range 01....1xx to 10....0xx,
4717 * and the most significant 4 bits of the mantissa; see
4718 * VFPExpandImm() in the v8 ARM ARM.
4721 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4722 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
4723 extract32(imm8
, 0, 6);
4726 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4727 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
4728 (extract32(imm8
, 0, 6) << 3);
4732 tcg_res
= tcg_const_i64(imm
);
4733 write_fp_dreg(s
, rd
, tcg_res
);
4734 tcg_temp_free_i64(tcg_res
);
4737 /* Handle floating point <=> fixed point conversions. Note that we can
4738 * also deal with fp <=> integer conversions as a special case (scale == 64)
4739 * OPTME: consider handling that special case specially or at least skipping
4740 * the call to scalbn in the helpers for zero shifts.
4742 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
4743 bool itof
, int rmode
, int scale
, int sf
, int type
)
4745 bool is_signed
= !(opcode
& 1);
4746 bool is_double
= type
;
4747 TCGv_ptr tcg_fpstatus
;
4750 tcg_fpstatus
= get_fpstatus_ptr();
4752 tcg_shift
= tcg_const_i32(64 - scale
);
4755 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
4757 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
4760 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
4762 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
4765 tcg_int
= tcg_extend
;
4769 TCGv_i64 tcg_double
= tcg_temp_new_i64();
4771 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
4772 tcg_shift
, tcg_fpstatus
);
4774 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
4775 tcg_shift
, tcg_fpstatus
);
4777 write_fp_dreg(s
, rd
, tcg_double
);
4778 tcg_temp_free_i64(tcg_double
);
4780 TCGv_i32 tcg_single
= tcg_temp_new_i32();
4782 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
4783 tcg_shift
, tcg_fpstatus
);
4785 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
4786 tcg_shift
, tcg_fpstatus
);
4788 write_fp_sreg(s
, rd
, tcg_single
);
4789 tcg_temp_free_i32(tcg_single
);
4792 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
4795 if (extract32(opcode
, 2, 1)) {
4796 /* There are too many rounding modes to all fit into rmode,
4797 * so FCVTA[US] is a special case.
4799 rmode
= FPROUNDING_TIEAWAY
;
4802 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
4804 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4807 TCGv_i64 tcg_double
= read_fp_dreg(s
, rn
);
4810 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
4811 tcg_shift
, tcg_fpstatus
);
4813 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
4814 tcg_shift
, tcg_fpstatus
);
4818 gen_helper_vfp_tould(tcg_int
, tcg_double
,
4819 tcg_shift
, tcg_fpstatus
);
4821 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
4822 tcg_shift
, tcg_fpstatus
);
4825 tcg_temp_free_i64(tcg_double
);
4827 TCGv_i32 tcg_single
= read_fp_sreg(s
, rn
);
4830 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
4831 tcg_shift
, tcg_fpstatus
);
4833 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
4834 tcg_shift
, tcg_fpstatus
);
4837 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
4839 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
4840 tcg_shift
, tcg_fpstatus
);
4842 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
4843 tcg_shift
, tcg_fpstatus
);
4845 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
4846 tcg_temp_free_i32(tcg_dest
);
4848 tcg_temp_free_i32(tcg_single
);
4851 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4852 tcg_temp_free_i32(tcg_rmode
);
4855 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
4859 tcg_temp_free_ptr(tcg_fpstatus
);
4860 tcg_temp_free_i32(tcg_shift
);
4863 /* C3.6.29 Floating point <-> fixed point conversions
4864 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4865 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4866 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
4867 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4869 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
4871 int rd
= extract32(insn
, 0, 5);
4872 int rn
= extract32(insn
, 5, 5);
4873 int scale
= extract32(insn
, 10, 6);
4874 int opcode
= extract32(insn
, 16, 3);
4875 int rmode
= extract32(insn
, 19, 2);
4876 int type
= extract32(insn
, 22, 2);
4877 bool sbit
= extract32(insn
, 29, 1);
4878 bool sf
= extract32(insn
, 31, 1);
4881 if (sbit
|| (type
> 1)
4882 || (!sf
&& scale
< 32)) {
4883 unallocated_encoding(s
);
4887 switch ((rmode
<< 3) | opcode
) {
4888 case 0x2: /* SCVTF */
4889 case 0x3: /* UCVTF */
4892 case 0x18: /* FCVTZS */
4893 case 0x19: /* FCVTZU */
4897 unallocated_encoding(s
);
4901 if (!fp_access_check(s
)) {
4905 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
4908 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
4910 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
4911 * without conversion.
4915 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4921 TCGv_i64 tmp
= tcg_temp_new_i64();
4922 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
4923 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
4924 tcg_gen_movi_i64(tmp
, 0);
4925 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4926 tcg_temp_free_i64(tmp
);
4932 TCGv_i64 tmp
= tcg_const_i64(0);
4933 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
4934 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4935 tcg_temp_free_i64(tmp
);
4939 /* 64 bit to top half. */
4940 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4944 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4949 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
4953 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
4956 /* 64 bits from top half */
4957 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
4963 /* C3.6.30 Floating point <-> integer conversions
4964 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4965 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4966 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
4967 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4969 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
4971 int rd
= extract32(insn
, 0, 5);
4972 int rn
= extract32(insn
, 5, 5);
4973 int opcode
= extract32(insn
, 16, 3);
4974 int rmode
= extract32(insn
, 19, 2);
4975 int type
= extract32(insn
, 22, 2);
4976 bool sbit
= extract32(insn
, 29, 1);
4977 bool sf
= extract32(insn
, 31, 1);
4980 unallocated_encoding(s
);
4986 bool itof
= opcode
& 1;
4989 unallocated_encoding(s
);
4993 switch (sf
<< 3 | type
<< 1 | rmode
) {
4994 case 0x0: /* 32 bit */
4995 case 0xa: /* 64 bit */
4996 case 0xd: /* 64 bit to top half of quad */
4999 /* all other sf/type/rmode combinations are invalid */
5000 unallocated_encoding(s
);
5004 if (!fp_access_check(s
)) {
5007 handle_fmov(s
, rd
, rn
, type
, itof
);
5009 /* actual FP conversions */
5010 bool itof
= extract32(opcode
, 1, 1);
5012 if (type
> 1 || (rmode
!= 0 && opcode
> 1)) {
5013 unallocated_encoding(s
);
5017 if (!fp_access_check(s
)) {
5020 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
5024 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
5025 * 31 30 29 28 25 24 0
5026 * +---+---+---+---------+-----------------------------+
5027 * | | 0 | | 1 1 1 1 | |
5028 * +---+---+---+---------+-----------------------------+
5030 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
5032 if (extract32(insn
, 24, 1)) {
5033 /* Floating point data-processing (3 source) */
5034 disas_fp_3src(s
, insn
);
5035 } else if (extract32(insn
, 21, 1) == 0) {
5036 /* Floating point to fixed point conversions */
5037 disas_fp_fixed_conv(s
, insn
);
5039 switch (extract32(insn
, 10, 2)) {
5041 /* Floating point conditional compare */
5042 disas_fp_ccomp(s
, insn
);
5045 /* Floating point data-processing (2 source) */
5046 disas_fp_2src(s
, insn
);
5049 /* Floating point conditional select */
5050 disas_fp_csel(s
, insn
);
5053 switch (ctz32(extract32(insn
, 12, 4))) {
5054 case 0: /* [15:12] == xxx1 */
5055 /* Floating point immediate */
5056 disas_fp_imm(s
, insn
);
5058 case 1: /* [15:12] == xx10 */
5059 /* Floating point compare */
5060 disas_fp_compare(s
, insn
);
5062 case 2: /* [15:12] == x100 */
5063 /* Floating point data-processing (1 source) */
5064 disas_fp_1src(s
, insn
);
5066 case 3: /* [15:12] == 1000 */
5067 unallocated_encoding(s
);
5069 default: /* [15:12] == 0000 */
5070 /* Floating point <-> integer conversions */
5071 disas_fp_int_conv(s
, insn
);
5079 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
5082 /* Extract 64 bits from the middle of two concatenated 64 bit
5083 * vector register slices left:right. The extracted bits start
5084 * at 'pos' bits into the right (least significant) side.
5085 * We return the result in tcg_right, and guarantee not to
5088 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5089 assert(pos
> 0 && pos
< 64);
5091 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
5092 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
5093 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
5095 tcg_temp_free_i64(tcg_tmp
);
5099 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
5100 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5101 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
5102 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5104 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
5106 int is_q
= extract32(insn
, 30, 1);
5107 int op2
= extract32(insn
, 22, 2);
5108 int imm4
= extract32(insn
, 11, 4);
5109 int rm
= extract32(insn
, 16, 5);
5110 int rn
= extract32(insn
, 5, 5);
5111 int rd
= extract32(insn
, 0, 5);
5112 int pos
= imm4
<< 3;
5113 TCGv_i64 tcg_resl
, tcg_resh
;
5115 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
5116 unallocated_encoding(s
);
5120 if (!fp_access_check(s
)) {
5124 tcg_resh
= tcg_temp_new_i64();
5125 tcg_resl
= tcg_temp_new_i64();
5127 /* Vd gets bits starting at pos bits into Vm:Vn. This is
5128 * either extracting 128 bits from a 128:128 concatenation, or
5129 * extracting 64 bits from a 64:64 concatenation.
5132 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
5134 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
5135 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5137 tcg_gen_movi_i64(tcg_resh
, 0);
5144 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
5145 EltPosns
*elt
= eltposns
;
5152 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
5154 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
5157 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5158 tcg_hh
= tcg_temp_new_i64();
5159 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
5160 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
5161 tcg_temp_free_i64(tcg_hh
);
5165 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5166 tcg_temp_free_i64(tcg_resl
);
5167 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5168 tcg_temp_free_i64(tcg_resh
);
5172 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
5173 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5174 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
5175 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5177 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
5179 int op2
= extract32(insn
, 22, 2);
5180 int is_q
= extract32(insn
, 30, 1);
5181 int rm
= extract32(insn
, 16, 5);
5182 int rn
= extract32(insn
, 5, 5);
5183 int rd
= extract32(insn
, 0, 5);
5184 int is_tblx
= extract32(insn
, 12, 1);
5185 int len
= extract32(insn
, 13, 2);
5186 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
5187 TCGv_i32 tcg_regno
, tcg_numregs
;
5190 unallocated_encoding(s
);
5194 if (!fp_access_check(s
)) {
5198 /* This does a table lookup: for every byte element in the input
5199 * we index into a table formed from up to four vector registers,
5200 * and then the output is the result of the lookups. Our helper
5201 * function does the lookup operation for a single 64 bit part of
5204 tcg_resl
= tcg_temp_new_i64();
5205 tcg_resh
= tcg_temp_new_i64();
5208 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5210 tcg_gen_movi_i64(tcg_resl
, 0);
5212 if (is_tblx
&& is_q
) {
5213 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5215 tcg_gen_movi_i64(tcg_resh
, 0);
5218 tcg_idx
= tcg_temp_new_i64();
5219 tcg_regno
= tcg_const_i32(rn
);
5220 tcg_numregs
= tcg_const_i32(len
+ 1);
5221 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
5222 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
5223 tcg_regno
, tcg_numregs
);
5225 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
5226 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
5227 tcg_regno
, tcg_numregs
);
5229 tcg_temp_free_i64(tcg_idx
);
5230 tcg_temp_free_i32(tcg_regno
);
5231 tcg_temp_free_i32(tcg_numregs
);
5233 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5234 tcg_temp_free_i64(tcg_resl
);
5235 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5236 tcg_temp_free_i64(tcg_resh
);
5239 /* C3.6.3 ZIP/UZP/TRN
5240 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
5241 * +---+---+-------------+------+---+------+---+------------------+------+
5242 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
5243 * +---+---+-------------+------+---+------+---+------------------+------+
5245 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
5247 int rd
= extract32(insn
, 0, 5);
5248 int rn
= extract32(insn
, 5, 5);
5249 int rm
= extract32(insn
, 16, 5);
5250 int size
= extract32(insn
, 22, 2);
5251 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
5252 * bit 2 indicates 1 vs 2 variant of the insn.
5254 int opcode
= extract32(insn
, 12, 2);
5255 bool part
= extract32(insn
, 14, 1);
5256 bool is_q
= extract32(insn
, 30, 1);
5257 int esize
= 8 << size
;
5259 int datasize
= is_q
? 128 : 64;
5260 int elements
= datasize
/ esize
;
5261 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
5263 if (opcode
== 0 || (size
== 3 && !is_q
)) {
5264 unallocated_encoding(s
);
5268 if (!fp_access_check(s
)) {
5272 tcg_resl
= tcg_const_i64(0);
5273 tcg_resh
= tcg_const_i64(0);
5274 tcg_res
= tcg_temp_new_i64();
5276 for (i
= 0; i
< elements
; i
++) {
5278 case 1: /* UZP1/2 */
5280 int midpoint
= elements
/ 2;
5282 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
5284 read_vec_element(s
, tcg_res
, rm
,
5285 2 * (i
- midpoint
) + part
, size
);
5289 case 2: /* TRN1/2 */
5291 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
5293 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
5296 case 3: /* ZIP1/2 */
5298 int base
= part
* elements
/ 2;
5300 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
5302 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
5307 g_assert_not_reached();
5312 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
5313 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
5315 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
5316 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
5320 tcg_temp_free_i64(tcg_res
);
5322 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5323 tcg_temp_free_i64(tcg_resl
);
5324 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5325 tcg_temp_free_i64(tcg_resh
);
5328 static void do_minmaxop(DisasContext
*s
, TCGv_i32 tcg_elt1
, TCGv_i32 tcg_elt2
,
5329 int opc
, bool is_min
, TCGv_ptr fpst
)
5331 /* Helper function for disas_simd_across_lanes: do a single precision
5332 * min/max operation on the specified two inputs,
5333 * and return the result in tcg_elt1.
5337 gen_helper_vfp_minnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5339 gen_helper_vfp_maxnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5344 gen_helper_vfp_mins(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5346 gen_helper_vfp_maxs(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5351 /* C3.6.4 AdvSIMD across lanes
5352 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5353 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5354 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5355 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5357 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
5359 int rd
= extract32(insn
, 0, 5);
5360 int rn
= extract32(insn
, 5, 5);
5361 int size
= extract32(insn
, 22, 2);
5362 int opcode
= extract32(insn
, 12, 5);
5363 bool is_q
= extract32(insn
, 30, 1);
5364 bool is_u
= extract32(insn
, 29, 1);
5366 bool is_min
= false;
5370 TCGv_i64 tcg_res
, tcg_elt
;
5373 case 0x1b: /* ADDV */
5375 unallocated_encoding(s
);
5379 case 0x3: /* SADDLV, UADDLV */
5380 case 0xa: /* SMAXV, UMAXV */
5381 case 0x1a: /* SMINV, UMINV */
5382 if (size
== 3 || (size
== 2 && !is_q
)) {
5383 unallocated_encoding(s
);
5387 case 0xc: /* FMAXNMV, FMINNMV */
5388 case 0xf: /* FMAXV, FMINV */
5389 if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
5390 unallocated_encoding(s
);
5393 /* Bit 1 of size field encodes min vs max, and actual size is always
5394 * 32 bits: adjust the size variable so following code can rely on it
5396 is_min
= extract32(size
, 1, 1);
5401 unallocated_encoding(s
);
5405 if (!fp_access_check(s
)) {
5410 elements
= (is_q
? 128 : 64) / esize
;
5412 tcg_res
= tcg_temp_new_i64();
5413 tcg_elt
= tcg_temp_new_i64();
5415 /* These instructions operate across all lanes of a vector
5416 * to produce a single result. We can guarantee that a 64
5417 * bit intermediate is sufficient:
5418 * + for [US]ADDLV the maximum element size is 32 bits, and
5419 * the result type is 64 bits
5420 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
5421 * same as the element size, which is 32 bits at most
5422 * For the integer operations we can choose to work at 64
5423 * or 32 bits and truncate at the end; for simplicity
5424 * we use 64 bits always. The floating point
5425 * ops do require 32 bit intermediates, though.
5428 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
5430 for (i
= 1; i
< elements
; i
++) {
5431 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
5434 case 0x03: /* SADDLV / UADDLV */
5435 case 0x1b: /* ADDV */
5436 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
5438 case 0x0a: /* SMAXV / UMAXV */
5439 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
5441 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5443 case 0x1a: /* SMINV / UMINV */
5444 tcg_gen_movcond_i64(is_u
? TCG_COND_LEU
: TCG_COND_LE
,
5446 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5450 g_assert_not_reached();
5455 /* Floating point ops which work on 32 bit (single) intermediates.
5456 * Note that correct NaN propagation requires that we do these
5457 * operations in exactly the order specified by the pseudocode.
5459 TCGv_i32 tcg_elt1
= tcg_temp_new_i32();
5460 TCGv_i32 tcg_elt2
= tcg_temp_new_i32();
5461 TCGv_i32 tcg_elt3
= tcg_temp_new_i32();
5462 TCGv_ptr fpst
= get_fpstatus_ptr();
5464 assert(esize
== 32);
5465 assert(elements
== 4);
5467 read_vec_element(s
, tcg_elt
, rn
, 0, MO_32
);
5468 tcg_gen_trunc_i64_i32(tcg_elt1
, tcg_elt
);
5469 read_vec_element(s
, tcg_elt
, rn
, 1, MO_32
);
5470 tcg_gen_trunc_i64_i32(tcg_elt2
, tcg_elt
);
5472 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5474 read_vec_element(s
, tcg_elt
, rn
, 2, MO_32
);
5475 tcg_gen_trunc_i64_i32(tcg_elt2
, tcg_elt
);
5476 read_vec_element(s
, tcg_elt
, rn
, 3, MO_32
);
5477 tcg_gen_trunc_i64_i32(tcg_elt3
, tcg_elt
);
5479 do_minmaxop(s
, tcg_elt2
, tcg_elt3
, opcode
, is_min
, fpst
);
5481 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5483 tcg_gen_extu_i32_i64(tcg_res
, tcg_elt1
);
5484 tcg_temp_free_i32(tcg_elt1
);
5485 tcg_temp_free_i32(tcg_elt2
);
5486 tcg_temp_free_i32(tcg_elt3
);
5487 tcg_temp_free_ptr(fpst
);
5490 tcg_temp_free_i64(tcg_elt
);
5492 /* Now truncate the result to the width required for the final output */
5493 if (opcode
== 0x03) {
5494 /* SADDLV, UADDLV: result is 2*esize */
5500 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
5503 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
5506 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
5511 g_assert_not_reached();
5514 write_fp_dreg(s
, rd
, tcg_res
);
5515 tcg_temp_free_i64(tcg_res
);
5518 /* C6.3.31 DUP (Element, Vector)
5520 * 31 30 29 21 20 16 15 10 9 5 4 0
5521 * +---+---+-------------------+--------+-------------+------+------+
5522 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5523 * +---+---+-------------------+--------+-------------+------+------+
5525 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5527 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
5530 int size
= ctz32(imm5
);
5531 int esize
= 8 << size
;
5532 int elements
= (is_q
? 128 : 64) / esize
;
5536 if (size
> 3 || (size
== 3 && !is_q
)) {
5537 unallocated_encoding(s
);
5541 if (!fp_access_check(s
)) {
5545 index
= imm5
>> (size
+ 1);
5547 tmp
= tcg_temp_new_i64();
5548 read_vec_element(s
, tmp
, rn
, index
, size
);
5550 for (i
= 0; i
< elements
; i
++) {
5551 write_vec_element(s
, tmp
, rd
, i
, size
);
5555 clear_vec_high(s
, rd
);
5558 tcg_temp_free_i64(tmp
);
5561 /* C6.3.31 DUP (element, scalar)
5562 * 31 21 20 16 15 10 9 5 4 0
5563 * +-----------------------+--------+-------------+------+------+
5564 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5565 * +-----------------------+--------+-------------+------+------+
5567 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
5570 int size
= ctz32(imm5
);
5575 unallocated_encoding(s
);
5579 if (!fp_access_check(s
)) {
5583 index
= imm5
>> (size
+ 1);
5585 /* This instruction just extracts the specified element and
5586 * zero-extends it into the bottom of the destination register.
5588 tmp
= tcg_temp_new_i64();
5589 read_vec_element(s
, tmp
, rn
, index
, size
);
5590 write_fp_dreg(s
, rd
, tmp
);
5591 tcg_temp_free_i64(tmp
);
5594 /* C6.3.32 DUP (General)
5596 * 31 30 29 21 20 16 15 10 9 5 4 0
5597 * +---+---+-------------------+--------+-------------+------+------+
5598 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
5599 * +---+---+-------------------+--------+-------------+------+------+
5601 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5603 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
5606 int size
= ctz32(imm5
);
5607 int esize
= 8 << size
;
5608 int elements
= (is_q
? 128 : 64)/esize
;
5611 if (size
> 3 || ((size
== 3) && !is_q
)) {
5612 unallocated_encoding(s
);
5616 if (!fp_access_check(s
)) {
5620 for (i
= 0; i
< elements
; i
++) {
5621 write_vec_element(s
, cpu_reg(s
, rn
), rd
, i
, size
);
5624 clear_vec_high(s
, rd
);
5628 /* C6.3.150 INS (Element)
5630 * 31 21 20 16 15 14 11 10 9 5 4 0
5631 * +-----------------------+--------+------------+---+------+------+
5632 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5633 * +-----------------------+--------+------------+---+------+------+
5635 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5636 * index: encoded in imm5<4:size+1>
5638 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
5641 int size
= ctz32(imm5
);
5642 int src_index
, dst_index
;
5646 unallocated_encoding(s
);
5650 if (!fp_access_check(s
)) {
5654 dst_index
= extract32(imm5
, 1+size
, 5);
5655 src_index
= extract32(imm4
, size
, 4);
5657 tmp
= tcg_temp_new_i64();
5659 read_vec_element(s
, tmp
, rn
, src_index
, size
);
5660 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
5662 tcg_temp_free_i64(tmp
);
5666 /* C6.3.151 INS (General)
5668 * 31 21 20 16 15 10 9 5 4 0
5669 * +-----------------------+--------+-------------+------+------+
5670 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
5671 * +-----------------------+--------+-------------+------+------+
5673 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5674 * index: encoded in imm5<4:size+1>
5676 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
5678 int size
= ctz32(imm5
);
5682 unallocated_encoding(s
);
5686 if (!fp_access_check(s
)) {
5690 idx
= extract32(imm5
, 1 + size
, 4 - size
);
5691 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
5695 * C6.3.321 UMOV (General)
5696 * C6.3.237 SMOV (General)
5698 * 31 30 29 21 20 16 15 12 10 9 5 4 0
5699 * +---+---+-------------------+--------+-------------+------+------+
5700 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
5701 * +---+---+-------------------+--------+-------------+------+------+
5703 * U: unsigned when set
5704 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5706 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
5707 int rn
, int rd
, int imm5
)
5709 int size
= ctz32(imm5
);
5713 /* Check for UnallocatedEncodings */
5715 if (size
> 2 || (size
== 2 && !is_q
)) {
5716 unallocated_encoding(s
);
5721 || (size
< 3 && is_q
)
5722 || (size
== 3 && !is_q
)) {
5723 unallocated_encoding(s
);
5728 if (!fp_access_check(s
)) {
5732 element
= extract32(imm5
, 1+size
, 4);
5734 tcg_rd
= cpu_reg(s
, rd
);
5735 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
5736 if (is_signed
&& !is_q
) {
5737 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5741 /* C3.6.5 AdvSIMD copy
5742 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5743 * +---+---+----+-----------------+------+---+------+---+------+------+
5744 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5745 * +---+---+----+-----------------+------+---+------+---+------+------+
5747 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
5749 int rd
= extract32(insn
, 0, 5);
5750 int rn
= extract32(insn
, 5, 5);
5751 int imm4
= extract32(insn
, 11, 4);
5752 int op
= extract32(insn
, 29, 1);
5753 int is_q
= extract32(insn
, 30, 1);
5754 int imm5
= extract32(insn
, 16, 5);
5759 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
5761 unallocated_encoding(s
);
5766 /* DUP (element - vector) */
5767 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
5771 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
5776 handle_simd_insg(s
, rd
, rn
, imm5
);
5778 unallocated_encoding(s
);
5783 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
5784 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
5787 unallocated_encoding(s
);
5793 /* C3.6.6 AdvSIMD modified immediate
5794 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
5795 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5796 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
5797 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5799 * There are a number of operations that can be carried out here:
5800 * MOVI - move (shifted) imm into register
5801 * MVNI - move inverted (shifted) imm into register
5802 * ORR - bitwise OR of (shifted) imm with register
5803 * BIC - bitwise clear of (shifted) imm with register
5805 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
5807 int rd
= extract32(insn
, 0, 5);
5808 int cmode
= extract32(insn
, 12, 4);
5809 int cmode_3_1
= extract32(cmode
, 1, 3);
5810 int cmode_0
= extract32(cmode
, 0, 1);
5811 int o2
= extract32(insn
, 11, 1);
5812 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
5813 bool is_neg
= extract32(insn
, 29, 1);
5814 bool is_q
= extract32(insn
, 30, 1);
5816 TCGv_i64 tcg_rd
, tcg_imm
;
5819 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
5820 unallocated_encoding(s
);
5824 if (!fp_access_check(s
)) {
5828 /* See AdvSIMDExpandImm() in ARM ARM */
5829 switch (cmode_3_1
) {
5830 case 0: /* Replicate(Zeros(24):imm8, 2) */
5831 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
5832 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
5833 case 3: /* Replicate(imm8:Zeros(24), 2) */
5835 int shift
= cmode_3_1
* 8;
5836 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
5839 case 4: /* Replicate(Zeros(8):imm8, 4) */
5840 case 5: /* Replicate(imm8:Zeros(8), 4) */
5842 int shift
= (cmode_3_1
& 0x1) * 8;
5843 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
5848 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
5849 imm
= (abcdefgh
<< 16) | 0xffff;
5851 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
5852 imm
= (abcdefgh
<< 8) | 0xff;
5854 imm
= bitfield_replicate(imm
, 32);
5857 if (!cmode_0
&& !is_neg
) {
5858 imm
= bitfield_replicate(abcdefgh
, 8);
5859 } else if (!cmode_0
&& is_neg
) {
5862 for (i
= 0; i
< 8; i
++) {
5863 if ((abcdefgh
) & (1 << i
)) {
5864 imm
|= 0xffULL
<< (i
* 8);
5867 } else if (cmode_0
) {
5869 imm
= (abcdefgh
& 0x3f) << 48;
5870 if (abcdefgh
& 0x80) {
5871 imm
|= 0x8000000000000000ULL
;
5873 if (abcdefgh
& 0x40) {
5874 imm
|= 0x3fc0000000000000ULL
;
5876 imm
|= 0x4000000000000000ULL
;
5879 imm
= (abcdefgh
& 0x3f) << 19;
5880 if (abcdefgh
& 0x80) {
5883 if (abcdefgh
& 0x40) {
5894 if (cmode_3_1
!= 7 && is_neg
) {
5898 tcg_imm
= tcg_const_i64(imm
);
5899 tcg_rd
= new_tmp_a64(s
);
5901 for (i
= 0; i
< 2; i
++) {
5902 int foffs
= i
? fp_reg_hi_offset(s
, rd
) : fp_reg_offset(s
, rd
, MO_64
);
5904 if (i
== 1 && !is_q
) {
5905 /* non-quad ops clear high half of vector */
5906 tcg_gen_movi_i64(tcg_rd
, 0);
5907 } else if ((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9) {
5908 tcg_gen_ld_i64(tcg_rd
, cpu_env
, foffs
);
5911 tcg_gen_and_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5914 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5918 tcg_gen_mov_i64(tcg_rd
, tcg_imm
);
5920 tcg_gen_st_i64(tcg_rd
, cpu_env
, foffs
);
5923 tcg_temp_free_i64(tcg_imm
);
5926 /* C3.6.7 AdvSIMD scalar copy
5927 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5928 * +-----+----+-----------------+------+---+------+---+------+------+
5929 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5930 * +-----+----+-----------------+------+---+------+---+------+------+
5932 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
5934 int rd
= extract32(insn
, 0, 5);
5935 int rn
= extract32(insn
, 5, 5);
5936 int imm4
= extract32(insn
, 11, 4);
5937 int imm5
= extract32(insn
, 16, 5);
5938 int op
= extract32(insn
, 29, 1);
5940 if (op
!= 0 || imm4
!= 0) {
5941 unallocated_encoding(s
);
5945 /* DUP (element, scalar) */
5946 handle_simd_dupes(s
, rd
, rn
, imm5
);
5949 /* C3.6.8 AdvSIMD scalar pairwise
5950 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5951 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5952 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5953 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5955 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
5957 int u
= extract32(insn
, 29, 1);
5958 int size
= extract32(insn
, 22, 2);
5959 int opcode
= extract32(insn
, 12, 5);
5960 int rn
= extract32(insn
, 5, 5);
5961 int rd
= extract32(insn
, 0, 5);
5964 /* For some ops (the FP ones), size[1] is part of the encoding.
5965 * For ADDP strictly it is not but size[1] is always 1 for valid
5968 opcode
|= (extract32(size
, 1, 1) << 5);
5971 case 0x3b: /* ADDP */
5972 if (u
|| size
!= 3) {
5973 unallocated_encoding(s
);
5976 if (!fp_access_check(s
)) {
5980 TCGV_UNUSED_PTR(fpst
);
5982 case 0xc: /* FMAXNMP */
5983 case 0xd: /* FADDP */
5984 case 0xf: /* FMAXP */
5985 case 0x2c: /* FMINNMP */
5986 case 0x2f: /* FMINP */
5987 /* FP op, size[0] is 32 or 64 bit */
5989 unallocated_encoding(s
);
5992 if (!fp_access_check(s
)) {
5996 size
= extract32(size
, 0, 1) ? 3 : 2;
5997 fpst
= get_fpstatus_ptr();
6000 unallocated_encoding(s
);
6005 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6006 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6007 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6009 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
6010 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
6013 case 0x3b: /* ADDP */
6014 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
6016 case 0xc: /* FMAXNMP */
6017 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6019 case 0xd: /* FADDP */
6020 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6022 case 0xf: /* FMAXP */
6023 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6025 case 0x2c: /* FMINNMP */
6026 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6028 case 0x2f: /* FMINP */
6029 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6032 g_assert_not_reached();
6035 write_fp_dreg(s
, rd
, tcg_res
);
6037 tcg_temp_free_i64(tcg_op1
);
6038 tcg_temp_free_i64(tcg_op2
);
6039 tcg_temp_free_i64(tcg_res
);
6041 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6042 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6043 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6045 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_32
);
6046 read_vec_element_i32(s
, tcg_op2
, rn
, 1, MO_32
);
6049 case 0xc: /* FMAXNMP */
6050 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6052 case 0xd: /* FADDP */
6053 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6055 case 0xf: /* FMAXP */
6056 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6058 case 0x2c: /* FMINNMP */
6059 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6061 case 0x2f: /* FMINP */
6062 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6065 g_assert_not_reached();
6068 write_fp_sreg(s
, rd
, tcg_res
);
6070 tcg_temp_free_i32(tcg_op1
);
6071 tcg_temp_free_i32(tcg_op2
);
6072 tcg_temp_free_i32(tcg_res
);
6075 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
6076 tcg_temp_free_ptr(fpst
);
6081 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
6083 * This code is handles the common shifting code and is used by both
6084 * the vector and scalar code.
6086 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6087 TCGv_i64 tcg_rnd
, bool accumulate
,
6088 bool is_u
, int size
, int shift
)
6090 bool extended_result
= false;
6091 bool round
= !TCGV_IS_UNUSED_I64(tcg_rnd
);
6093 TCGv_i64 tcg_src_hi
;
6095 if (round
&& size
== 3) {
6096 extended_result
= true;
6097 ext_lshift
= 64 - shift
;
6098 tcg_src_hi
= tcg_temp_new_i64();
6099 } else if (shift
== 64) {
6100 if (!accumulate
&& is_u
) {
6101 /* result is zero */
6102 tcg_gen_movi_i64(tcg_res
, 0);
6107 /* Deal with the rounding step */
6109 if (extended_result
) {
6110 TCGv_i64 tcg_zero
= tcg_const_i64(0);
6112 /* take care of sign extending tcg_res */
6113 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
6114 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6115 tcg_src
, tcg_src_hi
,
6118 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6122 tcg_temp_free_i64(tcg_zero
);
6124 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
6128 /* Now do the shift right */
6129 if (round
&& extended_result
) {
6130 /* extended case, >64 bit precision required */
6131 if (ext_lshift
== 0) {
6132 /* special case, only high bits matter */
6133 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
6135 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6136 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
6137 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
6142 /* essentially shifting in 64 zeros */
6143 tcg_gen_movi_i64(tcg_src
, 0);
6145 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6149 /* effectively extending the sign-bit */
6150 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
6152 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
6158 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
6160 tcg_gen_mov_i64(tcg_res
, tcg_src
);
6163 if (extended_result
) {
6164 tcg_temp_free_i64(tcg_src_hi
);
6168 /* Common SHL/SLI - Shift left with an optional insert */
6169 static void handle_shli_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6170 bool insert
, int shift
)
6172 if (insert
) { /* SLI */
6173 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, shift
, 64 - shift
);
6175 tcg_gen_shli_i64(tcg_res
, tcg_src
, shift
);
6179 /* SRI: shift right with insert */
6180 static void handle_shri_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6181 int size
, int shift
)
6183 int esize
= 8 << size
;
6185 /* shift count same as element size is valid but does nothing;
6186 * special case to avoid potential shift by 64.
6188 if (shift
!= esize
) {
6189 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6190 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, 0, esize
- shift
);
6194 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
6195 static void handle_scalar_simd_shri(DisasContext
*s
,
6196 bool is_u
, int immh
, int immb
,
6197 int opcode
, int rn
, int rd
)
6200 int immhb
= immh
<< 3 | immb
;
6201 int shift
= 2 * (8 << size
) - immhb
;
6202 bool accumulate
= false;
6204 bool insert
= false;
6209 if (!extract32(immh
, 3, 1)) {
6210 unallocated_encoding(s
);
6214 if (!fp_access_check(s
)) {
6219 case 0x02: /* SSRA / USRA (accumulate) */
6222 case 0x04: /* SRSHR / URSHR (rounding) */
6225 case 0x06: /* SRSRA / URSRA (accum + rounding) */
6226 accumulate
= round
= true;
6228 case 0x08: /* SRI */
6234 uint64_t round_const
= 1ULL << (shift
- 1);
6235 tcg_round
= tcg_const_i64(round_const
);
6237 TCGV_UNUSED_I64(tcg_round
);
6240 tcg_rn
= read_fp_dreg(s
, rn
);
6241 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6244 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
6246 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6247 accumulate
, is_u
, size
, shift
);
6250 write_fp_dreg(s
, rd
, tcg_rd
);
6252 tcg_temp_free_i64(tcg_rn
);
6253 tcg_temp_free_i64(tcg_rd
);
6255 tcg_temp_free_i64(tcg_round
);
6259 /* SHL/SLI - Scalar shift left */
6260 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
6261 int immh
, int immb
, int opcode
,
6264 int size
= 32 - clz32(immh
) - 1;
6265 int immhb
= immh
<< 3 | immb
;
6266 int shift
= immhb
- (8 << size
);
6267 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
6268 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
6270 if (!extract32(immh
, 3, 1)) {
6271 unallocated_encoding(s
);
6275 if (!fp_access_check(s
)) {
6279 tcg_rn
= read_fp_dreg(s
, rn
);
6280 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6282 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
6284 write_fp_dreg(s
, rd
, tcg_rd
);
6286 tcg_temp_free_i64(tcg_rn
);
6287 tcg_temp_free_i64(tcg_rd
);
6290 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
6291 * (signed/unsigned) narrowing */
6292 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
6293 bool is_u_shift
, bool is_u_narrow
,
6294 int immh
, int immb
, int opcode
,
6297 int immhb
= immh
<< 3 | immb
;
6298 int size
= 32 - clz32(immh
) - 1;
6299 int esize
= 8 << size
;
6300 int shift
= (2 * esize
) - immhb
;
6301 int elements
= is_scalar
? 1 : (64 / esize
);
6302 bool round
= extract32(opcode
, 0, 1);
6303 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
6304 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
6305 TCGv_i32 tcg_rd_narrowed
;
6308 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
6309 { gen_helper_neon_narrow_sat_s8
,
6310 gen_helper_neon_unarrow_sat8
},
6311 { gen_helper_neon_narrow_sat_s16
,
6312 gen_helper_neon_unarrow_sat16
},
6313 { gen_helper_neon_narrow_sat_s32
,
6314 gen_helper_neon_unarrow_sat32
},
6317 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
6318 gen_helper_neon_narrow_sat_u8
,
6319 gen_helper_neon_narrow_sat_u16
,
6320 gen_helper_neon_narrow_sat_u32
,
6323 NeonGenNarrowEnvFn
*narrowfn
;
6329 if (extract32(immh
, 3, 1)) {
6330 unallocated_encoding(s
);
6334 if (!fp_access_check(s
)) {
6339 narrowfn
= unsigned_narrow_fns
[size
];
6341 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
6344 tcg_rn
= tcg_temp_new_i64();
6345 tcg_rd
= tcg_temp_new_i64();
6346 tcg_rd_narrowed
= tcg_temp_new_i32();
6347 tcg_final
= tcg_const_i64(0);
6350 uint64_t round_const
= 1ULL << (shift
- 1);
6351 tcg_round
= tcg_const_i64(round_const
);
6353 TCGV_UNUSED_I64(tcg_round
);
6356 for (i
= 0; i
< elements
; i
++) {
6357 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
6358 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6359 false, is_u_shift
, size
+1, shift
);
6360 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
6361 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
6362 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
6366 clear_vec_high(s
, rd
);
6367 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
6369 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
6373 tcg_temp_free_i64(tcg_round
);
6375 tcg_temp_free_i64(tcg_rn
);
6376 tcg_temp_free_i64(tcg_rd
);
6377 tcg_temp_free_i32(tcg_rd_narrowed
);
6378 tcg_temp_free_i64(tcg_final
);
6382 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
6383 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
6384 bool src_unsigned
, bool dst_unsigned
,
6385 int immh
, int immb
, int rn
, int rd
)
6387 int immhb
= immh
<< 3 | immb
;
6388 int size
= 32 - clz32(immh
) - 1;
6389 int shift
= immhb
- (8 << size
);
6393 assert(!(scalar
&& is_q
));
6396 if (!is_q
&& extract32(immh
, 3, 1)) {
6397 unallocated_encoding(s
);
6401 /* Since we use the variable-shift helpers we must
6402 * replicate the shift count into each element of
6403 * the tcg_shift value.
6407 shift
|= shift
<< 8;
6410 shift
|= shift
<< 16;
6416 g_assert_not_reached();
6420 if (!fp_access_check(s
)) {
6425 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
6426 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
6427 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
6428 { NULL
, gen_helper_neon_qshl_u64
},
6430 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
6431 int maxpass
= is_q
? 2 : 1;
6433 for (pass
= 0; pass
< maxpass
; pass
++) {
6434 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6436 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6437 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6438 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6440 tcg_temp_free_i64(tcg_op
);
6442 tcg_temp_free_i64(tcg_shift
);
6445 clear_vec_high(s
, rd
);
6448 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
6449 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
6451 { gen_helper_neon_qshl_s8
,
6452 gen_helper_neon_qshl_s16
,
6453 gen_helper_neon_qshl_s32
},
6454 { gen_helper_neon_qshlu_s8
,
6455 gen_helper_neon_qshlu_s16
,
6456 gen_helper_neon_qshlu_s32
}
6458 { NULL
, NULL
, NULL
},
6459 { gen_helper_neon_qshl_u8
,
6460 gen_helper_neon_qshl_u16
,
6461 gen_helper_neon_qshl_u32
}
6464 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
6465 TCGMemOp memop
= scalar
? size
: MO_32
;
6466 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
6468 for (pass
= 0; pass
< maxpass
; pass
++) {
6469 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6471 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
6472 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6476 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
6479 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
6484 g_assert_not_reached();
6486 write_fp_sreg(s
, rd
, tcg_op
);
6488 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6491 tcg_temp_free_i32(tcg_op
);
6493 tcg_temp_free_i32(tcg_shift
);
6495 if (!is_q
&& !scalar
) {
6496 clear_vec_high(s
, rd
);
6501 /* Common vector code for handling integer to FP conversion */
6502 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
6503 int elements
, int is_signed
,
6504 int fracbits
, int size
)
6506 bool is_double
= size
== 3 ? true : false;
6507 TCGv_ptr tcg_fpst
= get_fpstatus_ptr();
6508 TCGv_i32 tcg_shift
= tcg_const_i32(fracbits
);
6509 TCGv_i64 tcg_int
= tcg_temp_new_i64();
6510 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
6513 for (pass
= 0; pass
< elements
; pass
++) {
6514 read_vec_element(s
, tcg_int
, rn
, pass
, mop
);
6517 TCGv_i64 tcg_double
= tcg_temp_new_i64();
6519 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6520 tcg_shift
, tcg_fpst
);
6522 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6523 tcg_shift
, tcg_fpst
);
6525 if (elements
== 1) {
6526 write_fp_dreg(s
, rd
, tcg_double
);
6528 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
6530 tcg_temp_free_i64(tcg_double
);
6532 TCGv_i32 tcg_single
= tcg_temp_new_i32();
6534 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6535 tcg_shift
, tcg_fpst
);
6537 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6538 tcg_shift
, tcg_fpst
);
6540 if (elements
== 1) {
6541 write_fp_sreg(s
, rd
, tcg_single
);
6543 write_vec_element_i32(s
, tcg_single
, rd
, pass
, MO_32
);
6545 tcg_temp_free_i32(tcg_single
);
6549 if (!is_double
&& elements
== 2) {
6550 clear_vec_high(s
, rd
);
6553 tcg_temp_free_i64(tcg_int
);
6554 tcg_temp_free_ptr(tcg_fpst
);
6555 tcg_temp_free_i32(tcg_shift
);
6558 /* UCVTF/SCVTF - Integer to FP conversion */
6559 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
6560 bool is_q
, bool is_u
,
6561 int immh
, int immb
, int opcode
,
6564 bool is_double
= extract32(immh
, 3, 1);
6565 int size
= is_double
? MO_64
: MO_32
;
6567 int immhb
= immh
<< 3 | immb
;
6568 int fracbits
= (is_double
? 128 : 64) - immhb
;
6570 if (!extract32(immh
, 2, 2)) {
6571 unallocated_encoding(s
);
6578 elements
= is_double
? 2 : is_q
? 4 : 2;
6579 if (is_double
&& !is_q
) {
6580 unallocated_encoding(s
);
6585 if (!fp_access_check(s
)) {
6589 /* immh == 0 would be a failure of the decode logic */
6592 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
6595 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
6596 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
6597 bool is_q
, bool is_u
,
6598 int immh
, int immb
, int rn
, int rd
)
6600 bool is_double
= extract32(immh
, 3, 1);
6601 int immhb
= immh
<< 3 | immb
;
6602 int fracbits
= (is_double
? 128 : 64) - immhb
;
6604 TCGv_ptr tcg_fpstatus
;
6605 TCGv_i32 tcg_rmode
, tcg_shift
;
6607 if (!extract32(immh
, 2, 2)) {
6608 unallocated_encoding(s
);
6612 if (!is_scalar
&& !is_q
&& is_double
) {
6613 unallocated_encoding(s
);
6617 if (!fp_access_check(s
)) {
6621 assert(!(is_scalar
&& is_q
));
6623 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
6624 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6625 tcg_fpstatus
= get_fpstatus_ptr();
6626 tcg_shift
= tcg_const_i32(fracbits
);
6629 int maxpass
= is_scalar
? 1 : 2;
6631 for (pass
= 0; pass
< maxpass
; pass
++) {
6632 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6634 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6636 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6638 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6640 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6641 tcg_temp_free_i64(tcg_op
);
6644 clear_vec_high(s
, rd
);
6647 int maxpass
= is_scalar
? 1 : is_q
? 4 : 2;
6648 for (pass
= 0; pass
< maxpass
; pass
++) {
6649 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6651 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
6653 gen_helper_vfp_touls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6655 gen_helper_vfp_tosls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6658 write_fp_sreg(s
, rd
, tcg_op
);
6660 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6662 tcg_temp_free_i32(tcg_op
);
6664 if (!is_q
&& !is_scalar
) {
6665 clear_vec_high(s
, rd
);
6669 tcg_temp_free_ptr(tcg_fpstatus
);
6670 tcg_temp_free_i32(tcg_shift
);
6671 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6672 tcg_temp_free_i32(tcg_rmode
);
6675 /* C3.6.9 AdvSIMD scalar shift by immediate
6676 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
6677 * +-----+---+-------------+------+------+--------+---+------+------+
6678 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
6679 * +-----+---+-------------+------+------+--------+---+------+------+
6681 * This is the scalar version so it works on a fixed sized registers
6683 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
6685 int rd
= extract32(insn
, 0, 5);
6686 int rn
= extract32(insn
, 5, 5);
6687 int opcode
= extract32(insn
, 11, 5);
6688 int immb
= extract32(insn
, 16, 3);
6689 int immh
= extract32(insn
, 19, 4);
6690 bool is_u
= extract32(insn
, 29, 1);
6693 unallocated_encoding(s
);
6698 case 0x08: /* SRI */
6700 unallocated_encoding(s
);
6704 case 0x00: /* SSHR / USHR */
6705 case 0x02: /* SSRA / USRA */
6706 case 0x04: /* SRSHR / URSHR */
6707 case 0x06: /* SRSRA / URSRA */
6708 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6710 case 0x0a: /* SHL / SLI */
6711 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6713 case 0x1c: /* SCVTF, UCVTF */
6714 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
6717 case 0x10: /* SQSHRUN, SQSHRUN2 */
6718 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
6720 unallocated_encoding(s
);
6723 handle_vec_simd_sqshrn(s
, true, false, false, true,
6724 immh
, immb
, opcode
, rn
, rd
);
6726 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
6727 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
6728 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
6729 immh
, immb
, opcode
, rn
, rd
);
6731 case 0xc: /* SQSHLU */
6733 unallocated_encoding(s
);
6736 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
6738 case 0xe: /* SQSHL, UQSHL */
6739 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
6741 case 0x1f: /* FCVTZS, FCVTZU */
6742 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
6745 unallocated_encoding(s
);
6750 /* C3.6.10 AdvSIMD scalar three different
6751 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6752 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6753 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
6754 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6756 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
6758 bool is_u
= extract32(insn
, 29, 1);
6759 int size
= extract32(insn
, 22, 2);
6760 int opcode
= extract32(insn
, 12, 4);
6761 int rm
= extract32(insn
, 16, 5);
6762 int rn
= extract32(insn
, 5, 5);
6763 int rd
= extract32(insn
, 0, 5);
6766 unallocated_encoding(s
);
6771 case 0x9: /* SQDMLAL, SQDMLAL2 */
6772 case 0xb: /* SQDMLSL, SQDMLSL2 */
6773 case 0xd: /* SQDMULL, SQDMULL2 */
6774 if (size
== 0 || size
== 3) {
6775 unallocated_encoding(s
);
6780 unallocated_encoding(s
);
6784 if (!fp_access_check(s
)) {
6789 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6790 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6791 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6793 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
6794 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
6796 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
6797 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6800 case 0xd: /* SQDMULL, SQDMULL2 */
6802 case 0xb: /* SQDMLSL, SQDMLSL2 */
6803 tcg_gen_neg_i64(tcg_res
, tcg_res
);
6805 case 0x9: /* SQDMLAL, SQDMLAL2 */
6806 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
6807 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
6811 g_assert_not_reached();
6814 write_fp_dreg(s
, rd
, tcg_res
);
6816 tcg_temp_free_i64(tcg_op1
);
6817 tcg_temp_free_i64(tcg_op2
);
6818 tcg_temp_free_i64(tcg_res
);
6820 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6821 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6822 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6824 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_16
);
6825 read_vec_element_i32(s
, tcg_op2
, rm
, 0, MO_16
);
6827 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
6828 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6831 case 0xd: /* SQDMULL, SQDMULL2 */
6833 case 0xb: /* SQDMLSL, SQDMLSL2 */
6834 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
6836 case 0x9: /* SQDMLAL, SQDMLAL2 */
6838 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
6839 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
6840 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
6842 tcg_temp_free_i64(tcg_op3
);
6846 g_assert_not_reached();
6849 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
6850 write_fp_dreg(s
, rd
, tcg_res
);
6852 tcg_temp_free_i32(tcg_op1
);
6853 tcg_temp_free_i32(tcg_op2
);
6854 tcg_temp_free_i64(tcg_res
);
6858 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
6859 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
6861 /* Handle 64x64->64 opcodes which are shared between the scalar
6862 * and vector 3-same groups. We cover every opcode where size == 3
6863 * is valid in either the three-reg-same (integer, not pairwise)
6864 * or scalar-three-reg-same groups. (Some opcodes are not yet
6870 case 0x1: /* SQADD */
6872 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6874 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6877 case 0x5: /* SQSUB */
6879 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6881 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6884 case 0x6: /* CMGT, CMHI */
6885 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
6886 * We implement this using setcond (test) and then negating.
6888 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
6890 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
6891 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6893 case 0x7: /* CMGE, CMHS */
6894 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
6896 case 0x11: /* CMTST, CMEQ */
6901 /* CMTST : test is "if (X & Y != 0)". */
6902 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6903 tcg_gen_setcondi_i64(TCG_COND_NE
, tcg_rd
, tcg_rd
, 0);
6904 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6906 case 0x8: /* SSHL, USHL */
6908 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6910 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
6913 case 0x9: /* SQSHL, UQSHL */
6915 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6917 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6920 case 0xa: /* SRSHL, URSHL */
6922 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6924 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
6927 case 0xb: /* SQRSHL, UQRSHL */
6929 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6931 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6934 case 0x10: /* ADD, SUB */
6936 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6938 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6942 g_assert_not_reached();
6946 /* Handle the 3-same-operands float operations; shared by the scalar
6947 * and vector encodings. The caller must filter out any encodings
6948 * not allocated for the encoding it is dealing with.
6950 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
6951 int fpopcode
, int rd
, int rn
, int rm
)
6954 TCGv_ptr fpst
= get_fpstatus_ptr();
6956 for (pass
= 0; pass
< elements
; pass
++) {
6959 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6960 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6961 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6963 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
6964 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
6967 case 0x39: /* FMLS */
6968 /* As usual for ARM, separate negation for fused multiply-add */
6969 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
6971 case 0x19: /* FMLA */
6972 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
6973 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
6976 case 0x18: /* FMAXNM */
6977 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6979 case 0x1a: /* FADD */
6980 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6982 case 0x1b: /* FMULX */
6983 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6985 case 0x1c: /* FCMEQ */
6986 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6988 case 0x1e: /* FMAX */
6989 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6991 case 0x1f: /* FRECPS */
6992 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6994 case 0x38: /* FMINNM */
6995 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6997 case 0x3a: /* FSUB */
6998 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7000 case 0x3e: /* FMIN */
7001 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7003 case 0x3f: /* FRSQRTS */
7004 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7006 case 0x5b: /* FMUL */
7007 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7009 case 0x5c: /* FCMGE */
7010 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7012 case 0x5d: /* FACGE */
7013 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7015 case 0x5f: /* FDIV */
7016 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7018 case 0x7a: /* FABD */
7019 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7020 gen_helper_vfp_absd(tcg_res
, tcg_res
);
7022 case 0x7c: /* FCMGT */
7023 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7025 case 0x7d: /* FACGT */
7026 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7029 g_assert_not_reached();
7032 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7034 tcg_temp_free_i64(tcg_res
);
7035 tcg_temp_free_i64(tcg_op1
);
7036 tcg_temp_free_i64(tcg_op2
);
7039 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7040 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7041 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7043 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
7044 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
7047 case 0x39: /* FMLS */
7048 /* As usual for ARM, separate negation for fused multiply-add */
7049 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
7051 case 0x19: /* FMLA */
7052 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7053 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
7056 case 0x1a: /* FADD */
7057 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7059 case 0x1b: /* FMULX */
7060 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7062 case 0x1c: /* FCMEQ */
7063 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7065 case 0x1e: /* FMAX */
7066 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7068 case 0x1f: /* FRECPS */
7069 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7071 case 0x18: /* FMAXNM */
7072 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7074 case 0x38: /* FMINNM */
7075 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7077 case 0x3a: /* FSUB */
7078 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7080 case 0x3e: /* FMIN */
7081 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7083 case 0x3f: /* FRSQRTS */
7084 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7086 case 0x5b: /* FMUL */
7087 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7089 case 0x5c: /* FCMGE */
7090 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7092 case 0x5d: /* FACGE */
7093 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7095 case 0x5f: /* FDIV */
7096 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7098 case 0x7a: /* FABD */
7099 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7100 gen_helper_vfp_abss(tcg_res
, tcg_res
);
7102 case 0x7c: /* FCMGT */
7103 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7105 case 0x7d: /* FACGT */
7106 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7109 g_assert_not_reached();
7112 if (elements
== 1) {
7113 /* scalar single so clear high part */
7114 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
7116 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
7117 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
7118 tcg_temp_free_i64(tcg_tmp
);
7120 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7123 tcg_temp_free_i32(tcg_res
);
7124 tcg_temp_free_i32(tcg_op1
);
7125 tcg_temp_free_i32(tcg_op2
);
7129 tcg_temp_free_ptr(fpst
);
7131 if ((elements
<< size
) < 4) {
7132 /* scalar, or non-quad vector op */
7133 clear_vec_high(s
, rd
);
7137 /* C3.6.11 AdvSIMD scalar three same
7138 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
7139 * +-----+---+-----------+------+---+------+--------+---+------+------+
7140 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
7141 * +-----+---+-----------+------+---+------+--------+---+------+------+
7143 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
7145 int rd
= extract32(insn
, 0, 5);
7146 int rn
= extract32(insn
, 5, 5);
7147 int opcode
= extract32(insn
, 11, 5);
7148 int rm
= extract32(insn
, 16, 5);
7149 int size
= extract32(insn
, 22, 2);
7150 bool u
= extract32(insn
, 29, 1);
7153 if (opcode
>= 0x18) {
7154 /* Floating point: U, size[1] and opcode indicate operation */
7155 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
7157 case 0x1b: /* FMULX */
7158 case 0x1f: /* FRECPS */
7159 case 0x3f: /* FRSQRTS */
7160 case 0x5d: /* FACGE */
7161 case 0x7d: /* FACGT */
7162 case 0x1c: /* FCMEQ */
7163 case 0x5c: /* FCMGE */
7164 case 0x7c: /* FCMGT */
7165 case 0x7a: /* FABD */
7168 unallocated_encoding(s
);
7172 if (!fp_access_check(s
)) {
7176 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
7181 case 0x1: /* SQADD, UQADD */
7182 case 0x5: /* SQSUB, UQSUB */
7183 case 0x9: /* SQSHL, UQSHL */
7184 case 0xb: /* SQRSHL, UQRSHL */
7186 case 0x8: /* SSHL, USHL */
7187 case 0xa: /* SRSHL, URSHL */
7188 case 0x6: /* CMGT, CMHI */
7189 case 0x7: /* CMGE, CMHS */
7190 case 0x11: /* CMTST, CMEQ */
7191 case 0x10: /* ADD, SUB (vector) */
7193 unallocated_encoding(s
);
7197 case 0x16: /* SQDMULH, SQRDMULH (vector) */
7198 if (size
!= 1 && size
!= 2) {
7199 unallocated_encoding(s
);
7204 unallocated_encoding(s
);
7208 if (!fp_access_check(s
)) {
7212 tcg_rd
= tcg_temp_new_i64();
7215 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7216 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
7218 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
7219 tcg_temp_free_i64(tcg_rn
);
7220 tcg_temp_free_i64(tcg_rm
);
7222 /* Do a single operation on the lowest element in the vector.
7223 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
7224 * no side effects for all these operations.
7225 * OPTME: special-purpose helpers would avoid doing some
7226 * unnecessary work in the helper for the 8 and 16 bit cases.
7228 NeonGenTwoOpEnvFn
*genenvfn
;
7229 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7230 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
7231 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
7233 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7234 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
7237 case 0x1: /* SQADD, UQADD */
7239 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7240 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
7241 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
7242 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
7244 genenvfn
= fns
[size
][u
];
7247 case 0x5: /* SQSUB, UQSUB */
7249 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7250 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
7251 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
7252 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
7254 genenvfn
= fns
[size
][u
];
7257 case 0x9: /* SQSHL, UQSHL */
7259 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7260 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
7261 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
7262 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
7264 genenvfn
= fns
[size
][u
];
7267 case 0xb: /* SQRSHL, UQRSHL */
7269 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7270 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
7271 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
7272 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
7274 genenvfn
= fns
[size
][u
];
7277 case 0x16: /* SQDMULH, SQRDMULH */
7279 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
7280 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
7281 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
7283 assert(size
== 1 || size
== 2);
7284 genenvfn
= fns
[size
- 1][u
];
7288 g_assert_not_reached();
7291 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
7292 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
7293 tcg_temp_free_i32(tcg_rd32
);
7294 tcg_temp_free_i32(tcg_rn
);
7295 tcg_temp_free_i32(tcg_rm
);
7298 write_fp_dreg(s
, rd
, tcg_rd
);
7300 tcg_temp_free_i64(tcg_rd
);
7303 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
7304 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
7305 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
7307 /* Handle 64->64 opcodes which are shared between the scalar and
7308 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
7309 * is valid in either group and also the double-precision fp ops.
7310 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
7316 case 0x4: /* CLS, CLZ */
7318 gen_helper_clz64(tcg_rd
, tcg_rn
);
7320 gen_helper_cls64(tcg_rd
, tcg_rn
);
7324 /* This opcode is shared with CNT and RBIT but we have earlier
7325 * enforced that size == 3 if and only if this is the NOT insn.
7327 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
7329 case 0x7: /* SQABS, SQNEG */
7331 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
7333 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
7336 case 0xa: /* CMLT */
7337 /* 64 bit integer comparison against zero, result is
7338 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
7343 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
7344 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7346 case 0x8: /* CMGT, CMGE */
7347 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
7349 case 0x9: /* CMEQ, CMLE */
7350 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
7352 case 0xb: /* ABS, NEG */
7354 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7356 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7357 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7358 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
7360 tcg_temp_free_i64(tcg_zero
);
7363 case 0x2f: /* FABS */
7364 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
7366 case 0x6f: /* FNEG */
7367 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
7369 case 0x7f: /* FSQRT */
7370 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
7372 case 0x1a: /* FCVTNS */
7373 case 0x1b: /* FCVTMS */
7374 case 0x1c: /* FCVTAS */
7375 case 0x3a: /* FCVTPS */
7376 case 0x3b: /* FCVTZS */
7378 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7379 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7380 tcg_temp_free_i32(tcg_shift
);
7383 case 0x5a: /* FCVTNU */
7384 case 0x5b: /* FCVTMU */
7385 case 0x5c: /* FCVTAU */
7386 case 0x7a: /* FCVTPU */
7387 case 0x7b: /* FCVTZU */
7389 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7390 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7391 tcg_temp_free_i32(tcg_shift
);
7394 case 0x18: /* FRINTN */
7395 case 0x19: /* FRINTM */
7396 case 0x38: /* FRINTP */
7397 case 0x39: /* FRINTZ */
7398 case 0x58: /* FRINTA */
7399 case 0x79: /* FRINTI */
7400 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7402 case 0x59: /* FRINTX */
7403 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7406 g_assert_not_reached();
7410 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
7411 bool is_scalar
, bool is_u
, bool is_q
,
7412 int size
, int rn
, int rd
)
7414 bool is_double
= (size
== 3);
7417 if (!fp_access_check(s
)) {
7421 fpst
= get_fpstatus_ptr();
7424 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7425 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7426 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7427 NeonGenTwoDoubleOPFn
*genfn
;
7432 case 0x2e: /* FCMLT (zero) */
7435 case 0x2c: /* FCMGT (zero) */
7436 genfn
= gen_helper_neon_cgt_f64
;
7438 case 0x2d: /* FCMEQ (zero) */
7439 genfn
= gen_helper_neon_ceq_f64
;
7441 case 0x6d: /* FCMLE (zero) */
7444 case 0x6c: /* FCMGE (zero) */
7445 genfn
= gen_helper_neon_cge_f64
;
7448 g_assert_not_reached();
7451 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7452 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7454 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7456 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7458 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7461 clear_vec_high(s
, rd
);
7464 tcg_temp_free_i64(tcg_res
);
7465 tcg_temp_free_i64(tcg_zero
);
7466 tcg_temp_free_i64(tcg_op
);
7468 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7469 TCGv_i32 tcg_zero
= tcg_const_i32(0);
7470 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7471 NeonGenTwoSingleOPFn
*genfn
;
7473 int pass
, maxpasses
;
7476 case 0x2e: /* FCMLT (zero) */
7479 case 0x2c: /* FCMGT (zero) */
7480 genfn
= gen_helper_neon_cgt_f32
;
7482 case 0x2d: /* FCMEQ (zero) */
7483 genfn
= gen_helper_neon_ceq_f32
;
7485 case 0x6d: /* FCMLE (zero) */
7488 case 0x6c: /* FCMGE (zero) */
7489 genfn
= gen_helper_neon_cge_f32
;
7492 g_assert_not_reached();
7498 maxpasses
= is_q
? 4 : 2;
7501 for (pass
= 0; pass
< maxpasses
; pass
++) {
7502 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7504 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7506 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7509 write_fp_sreg(s
, rd
, tcg_res
);
7511 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7514 tcg_temp_free_i32(tcg_res
);
7515 tcg_temp_free_i32(tcg_zero
);
7516 tcg_temp_free_i32(tcg_op
);
7517 if (!is_q
&& !is_scalar
) {
7518 clear_vec_high(s
, rd
);
7522 tcg_temp_free_ptr(fpst
);
7525 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
7526 bool is_scalar
, bool is_u
, bool is_q
,
7527 int size
, int rn
, int rd
)
7529 bool is_double
= (size
== 3);
7530 TCGv_ptr fpst
= get_fpstatus_ptr();
7533 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7534 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7537 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7538 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7540 case 0x3d: /* FRECPE */
7541 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
7543 case 0x3f: /* FRECPX */
7544 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
7546 case 0x7d: /* FRSQRTE */
7547 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
7550 g_assert_not_reached();
7552 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7555 clear_vec_high(s
, rd
);
7558 tcg_temp_free_i64(tcg_res
);
7559 tcg_temp_free_i64(tcg_op
);
7561 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7562 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7563 int pass
, maxpasses
;
7568 maxpasses
= is_q
? 4 : 2;
7571 for (pass
= 0; pass
< maxpasses
; pass
++) {
7572 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7575 case 0x3c: /* URECPE */
7576 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
7578 case 0x3d: /* FRECPE */
7579 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
7581 case 0x3f: /* FRECPX */
7582 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
7584 case 0x7d: /* FRSQRTE */
7585 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
7588 g_assert_not_reached();
7592 write_fp_sreg(s
, rd
, tcg_res
);
7594 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7597 tcg_temp_free_i32(tcg_res
);
7598 tcg_temp_free_i32(tcg_op
);
7599 if (!is_q
&& !is_scalar
) {
7600 clear_vec_high(s
, rd
);
7603 tcg_temp_free_ptr(fpst
);
7606 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
7607 int opcode
, bool u
, bool is_q
,
7608 int size
, int rn
, int rd
)
7610 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
7611 * in the source becomes a size element in the destination).
7614 TCGv_i32 tcg_res
[2];
7615 int destelt
= is_q
? 2 : 0;
7616 int passes
= scalar
? 1 : 2;
7619 tcg_res
[1] = tcg_const_i32(0);
7622 for (pass
= 0; pass
< passes
; pass
++) {
7623 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7624 NeonGenNarrowFn
*genfn
= NULL
;
7625 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
7628 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
7630 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7632 tcg_res
[pass
] = tcg_temp_new_i32();
7635 case 0x12: /* XTN, SQXTUN */
7637 static NeonGenNarrowFn
* const xtnfns
[3] = {
7638 gen_helper_neon_narrow_u8
,
7639 gen_helper_neon_narrow_u16
,
7640 tcg_gen_trunc_i64_i32
,
7642 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
7643 gen_helper_neon_unarrow_sat8
,
7644 gen_helper_neon_unarrow_sat16
,
7645 gen_helper_neon_unarrow_sat32
,
7648 genenvfn
= sqxtunfns
[size
];
7650 genfn
= xtnfns
[size
];
7654 case 0x14: /* SQXTN, UQXTN */
7656 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
7657 { gen_helper_neon_narrow_sat_s8
,
7658 gen_helper_neon_narrow_sat_u8
},
7659 { gen_helper_neon_narrow_sat_s16
,
7660 gen_helper_neon_narrow_sat_u16
},
7661 { gen_helper_neon_narrow_sat_s32
,
7662 gen_helper_neon_narrow_sat_u32
},
7664 genenvfn
= fns
[size
][u
];
7667 case 0x16: /* FCVTN, FCVTN2 */
7668 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
7670 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
7672 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
7673 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
7674 tcg_gen_trunc_i64_i32(tcg_lo
, tcg_op
);
7675 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, cpu_env
);
7676 tcg_gen_shri_i64(tcg_op
, tcg_op
, 32);
7677 tcg_gen_trunc_i64_i32(tcg_hi
, tcg_op
);
7678 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, cpu_env
);
7679 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
7680 tcg_temp_free_i32(tcg_lo
);
7681 tcg_temp_free_i32(tcg_hi
);
7684 case 0x56: /* FCVTXN, FCVTXN2 */
7685 /* 64 bit to 32 bit float conversion
7686 * with von Neumann rounding (round to odd)
7689 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
7692 g_assert_not_reached();
7696 genfn(tcg_res
[pass
], tcg_op
);
7697 } else if (genenvfn
) {
7698 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
7701 tcg_temp_free_i64(tcg_op
);
7704 for (pass
= 0; pass
< 2; pass
++) {
7705 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
7706 tcg_temp_free_i32(tcg_res
[pass
]);
7709 clear_vec_high(s
, rd
);
7713 /* Remaining saturating accumulating ops */
7714 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
7715 bool is_q
, int size
, int rn
, int rd
)
7717 bool is_double
= (size
== 3);
7720 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
7721 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7724 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7725 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
7726 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7728 if (is_u
) { /* USQADD */
7729 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7730 } else { /* SUQADD */
7731 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7733 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7736 clear_vec_high(s
, rd
);
7739 tcg_temp_free_i64(tcg_rd
);
7740 tcg_temp_free_i64(tcg_rn
);
7742 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7743 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7744 int pass
, maxpasses
;
7749 maxpasses
= is_q
? 4 : 2;
7752 for (pass
= 0; pass
< maxpasses
; pass
++) {
7754 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
7755 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
7757 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
7758 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7761 if (is_u
) { /* USQADD */
7764 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7767 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7770 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7773 g_assert_not_reached();
7775 } else { /* SUQADD */
7778 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7781 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7784 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7787 g_assert_not_reached();
7792 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7793 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
7794 tcg_temp_free_i64(tcg_zero
);
7796 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7800 clear_vec_high(s
, rd
);
7803 tcg_temp_free_i32(tcg_rd
);
7804 tcg_temp_free_i32(tcg_rn
);
7808 /* C3.6.12 AdvSIMD scalar two reg misc
7809 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7810 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7811 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
7812 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7814 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
7816 int rd
= extract32(insn
, 0, 5);
7817 int rn
= extract32(insn
, 5, 5);
7818 int opcode
= extract32(insn
, 12, 5);
7819 int size
= extract32(insn
, 22, 2);
7820 bool u
= extract32(insn
, 29, 1);
7821 bool is_fcvt
= false;
7824 TCGv_ptr tcg_fpstatus
;
7827 case 0x3: /* USQADD / SUQADD*/
7828 if (!fp_access_check(s
)) {
7831 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
7833 case 0x7: /* SQABS / SQNEG */
7835 case 0xa: /* CMLT */
7837 unallocated_encoding(s
);
7841 case 0x8: /* CMGT, CMGE */
7842 case 0x9: /* CMEQ, CMLE */
7843 case 0xb: /* ABS, NEG */
7845 unallocated_encoding(s
);
7849 case 0x12: /* SQXTUN */
7851 unallocated_encoding(s
);
7855 case 0x14: /* SQXTN, UQXTN */
7857 unallocated_encoding(s
);
7860 if (!fp_access_check(s
)) {
7863 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
7868 /* Floating point: U, size[1] and opcode indicate operation;
7869 * size[0] indicates single or double precision.
7871 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
7872 size
= extract32(size
, 0, 1) ? 3 : 2;
7874 case 0x2c: /* FCMGT (zero) */
7875 case 0x2d: /* FCMEQ (zero) */
7876 case 0x2e: /* FCMLT (zero) */
7877 case 0x6c: /* FCMGE (zero) */
7878 case 0x6d: /* FCMLE (zero) */
7879 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
7881 case 0x1d: /* SCVTF */
7882 case 0x5d: /* UCVTF */
7884 bool is_signed
= (opcode
== 0x1d);
7885 if (!fp_access_check(s
)) {
7888 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
7891 case 0x3d: /* FRECPE */
7892 case 0x3f: /* FRECPX */
7893 case 0x7d: /* FRSQRTE */
7894 if (!fp_access_check(s
)) {
7897 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
7899 case 0x1a: /* FCVTNS */
7900 case 0x1b: /* FCVTMS */
7901 case 0x3a: /* FCVTPS */
7902 case 0x3b: /* FCVTZS */
7903 case 0x5a: /* FCVTNU */
7904 case 0x5b: /* FCVTMU */
7905 case 0x7a: /* FCVTPU */
7906 case 0x7b: /* FCVTZU */
7908 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
7910 case 0x1c: /* FCVTAS */
7911 case 0x5c: /* FCVTAU */
7912 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
7914 rmode
= FPROUNDING_TIEAWAY
;
7916 case 0x56: /* FCVTXN, FCVTXN2 */
7918 unallocated_encoding(s
);
7921 if (!fp_access_check(s
)) {
7924 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
7927 unallocated_encoding(s
);
7932 unallocated_encoding(s
);
7936 if (!fp_access_check(s
)) {
7941 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
7942 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
7943 tcg_fpstatus
= get_fpstatus_ptr();
7945 TCGV_UNUSED_I32(tcg_rmode
);
7946 TCGV_UNUSED_PTR(tcg_fpstatus
);
7950 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7951 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7953 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
7954 write_fp_dreg(s
, rd
, tcg_rd
);
7955 tcg_temp_free_i64(tcg_rd
);
7956 tcg_temp_free_i64(tcg_rn
);
7958 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7959 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7961 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7964 case 0x7: /* SQABS, SQNEG */
7966 NeonGenOneOpEnvFn
*genfn
;
7967 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
7968 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
7969 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
7970 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
7972 genfn
= fns
[size
][u
];
7973 genfn(tcg_rd
, cpu_env
, tcg_rn
);
7976 case 0x1a: /* FCVTNS */
7977 case 0x1b: /* FCVTMS */
7978 case 0x1c: /* FCVTAS */
7979 case 0x3a: /* FCVTPS */
7980 case 0x3b: /* FCVTZS */
7982 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7983 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7984 tcg_temp_free_i32(tcg_shift
);
7987 case 0x5a: /* FCVTNU */
7988 case 0x5b: /* FCVTMU */
7989 case 0x5c: /* FCVTAU */
7990 case 0x7a: /* FCVTPU */
7991 case 0x7b: /* FCVTZU */
7993 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7994 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7995 tcg_temp_free_i32(tcg_shift
);
7999 g_assert_not_reached();
8002 write_fp_sreg(s
, rd
, tcg_rd
);
8003 tcg_temp_free_i32(tcg_rd
);
8004 tcg_temp_free_i32(tcg_rn
);
8008 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
8009 tcg_temp_free_i32(tcg_rmode
);
8010 tcg_temp_free_ptr(tcg_fpstatus
);
8014 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
8015 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
8016 int immh
, int immb
, int opcode
, int rn
, int rd
)
8018 int size
= 32 - clz32(immh
) - 1;
8019 int immhb
= immh
<< 3 | immb
;
8020 int shift
= 2 * (8 << size
) - immhb
;
8021 bool accumulate
= false;
8023 bool insert
= false;
8024 int dsize
= is_q
? 128 : 64;
8025 int esize
= 8 << size
;
8026 int elements
= dsize
/esize
;
8027 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
8028 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8029 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8033 if (extract32(immh
, 3, 1) && !is_q
) {
8034 unallocated_encoding(s
);
8038 if (size
> 3 && !is_q
) {
8039 unallocated_encoding(s
);
8043 if (!fp_access_check(s
)) {
8048 case 0x02: /* SSRA / USRA (accumulate) */
8051 case 0x04: /* SRSHR / URSHR (rounding) */
8054 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8055 accumulate
= round
= true;
8057 case 0x08: /* SRI */
8063 uint64_t round_const
= 1ULL << (shift
- 1);
8064 tcg_round
= tcg_const_i64(round_const
);
8066 TCGV_UNUSED_I64(tcg_round
);
8069 for (i
= 0; i
< elements
; i
++) {
8070 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
8071 if (accumulate
|| insert
) {
8072 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
8076 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
8078 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8079 accumulate
, is_u
, size
, shift
);
8082 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8086 clear_vec_high(s
, rd
);
8090 tcg_temp_free_i64(tcg_round
);
8094 /* SHL/SLI - Vector shift left */
8095 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
8096 int immh
, int immb
, int opcode
, int rn
, int rd
)
8098 int size
= 32 - clz32(immh
) - 1;
8099 int immhb
= immh
<< 3 | immb
;
8100 int shift
= immhb
- (8 << size
);
8101 int dsize
= is_q
? 128 : 64;
8102 int esize
= 8 << size
;
8103 int elements
= dsize
/esize
;
8104 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8105 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8108 if (extract32(immh
, 3, 1) && !is_q
) {
8109 unallocated_encoding(s
);
8113 if (size
> 3 && !is_q
) {
8114 unallocated_encoding(s
);
8118 if (!fp_access_check(s
)) {
8122 for (i
= 0; i
< elements
; i
++) {
8123 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
8125 read_vec_element(s
, tcg_rd
, rd
, i
, size
);
8128 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
8130 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8134 clear_vec_high(s
, rd
);
8138 /* USHLL/SHLL - Vector shift left with widening */
8139 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
8140 int immh
, int immb
, int opcode
, int rn
, int rd
)
8142 int size
= 32 - clz32(immh
) - 1;
8143 int immhb
= immh
<< 3 | immb
;
8144 int shift
= immhb
- (8 << size
);
8146 int esize
= 8 << size
;
8147 int elements
= dsize
/esize
;
8148 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8149 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8153 unallocated_encoding(s
);
8157 if (!fp_access_check(s
)) {
8161 /* For the LL variants the store is larger than the load,
8162 * so if rd == rn we would overwrite parts of our input.
8163 * So load everything right now and use shifts in the main loop.
8165 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
8167 for (i
= 0; i
< elements
; i
++) {
8168 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
8169 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
8170 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
8171 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
8175 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
8176 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
8177 int immh
, int immb
, int opcode
, int rn
, int rd
)
8179 int immhb
= immh
<< 3 | immb
;
8180 int size
= 32 - clz32(immh
) - 1;
8182 int esize
= 8 << size
;
8183 int elements
= dsize
/esize
;
8184 int shift
= (2 * esize
) - immhb
;
8185 bool round
= extract32(opcode
, 0, 1);
8186 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
8190 if (extract32(immh
, 3, 1)) {
8191 unallocated_encoding(s
);
8195 if (!fp_access_check(s
)) {
8199 tcg_rn
= tcg_temp_new_i64();
8200 tcg_rd
= tcg_temp_new_i64();
8201 tcg_final
= tcg_temp_new_i64();
8202 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
8205 uint64_t round_const
= 1ULL << (shift
- 1);
8206 tcg_round
= tcg_const_i64(round_const
);
8208 TCGV_UNUSED_I64(tcg_round
);
8211 for (i
= 0; i
< elements
; i
++) {
8212 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
8213 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8214 false, true, size
+1, shift
);
8216 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8220 clear_vec_high(s
, rd
);
8221 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8223 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8227 tcg_temp_free_i64(tcg_round
);
8229 tcg_temp_free_i64(tcg_rn
);
8230 tcg_temp_free_i64(tcg_rd
);
8231 tcg_temp_free_i64(tcg_final
);
8236 /* C3.6.14 AdvSIMD shift by immediate
8237 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8238 * +---+---+---+-------------+------+------+--------+---+------+------+
8239 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8240 * +---+---+---+-------------+------+------+--------+---+------+------+
8242 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
8244 int rd
= extract32(insn
, 0, 5);
8245 int rn
= extract32(insn
, 5, 5);
8246 int opcode
= extract32(insn
, 11, 5);
8247 int immb
= extract32(insn
, 16, 3);
8248 int immh
= extract32(insn
, 19, 4);
8249 bool is_u
= extract32(insn
, 29, 1);
8250 bool is_q
= extract32(insn
, 30, 1);
8253 case 0x08: /* SRI */
8255 unallocated_encoding(s
);
8259 case 0x00: /* SSHR / USHR */
8260 case 0x02: /* SSRA / USRA (accumulate) */
8261 case 0x04: /* SRSHR / URSHR (rounding) */
8262 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8263 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8265 case 0x0a: /* SHL / SLI */
8266 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8268 case 0x10: /* SHRN */
8269 case 0x11: /* RSHRN / SQRSHRUN */
8271 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
8274 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
8277 case 0x12: /* SQSHRN / UQSHRN */
8278 case 0x13: /* SQRSHRN / UQRSHRN */
8279 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
8282 case 0x14: /* SSHLL / USHLL */
8283 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8285 case 0x1c: /* SCVTF / UCVTF */
8286 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
8289 case 0xc: /* SQSHLU */
8291 unallocated_encoding(s
);
8294 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
8296 case 0xe: /* SQSHL, UQSHL */
8297 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
8299 case 0x1f: /* FCVTZS/ FCVTZU */
8300 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
8303 unallocated_encoding(s
);
8308 /* Generate code to do a "long" addition or subtraction, ie one done in
8309 * TCGv_i64 on vector lanes twice the width specified by size.
8311 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
8312 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
8314 static NeonGenTwo64OpFn
* const fns
[3][2] = {
8315 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
8316 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
8317 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
8319 NeonGenTwo64OpFn
*genfn
;
8322 genfn
= fns
[size
][is_sub
];
8323 genfn(tcg_res
, tcg_op1
, tcg_op2
);
8326 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
8327 int opcode
, int rd
, int rn
, int rm
)
8329 /* 3-reg-different widening insns: 64 x 64 -> 128 */
8330 TCGv_i64 tcg_res
[2];
8333 tcg_res
[0] = tcg_temp_new_i64();
8334 tcg_res
[1] = tcg_temp_new_i64();
8336 /* Does this op do an adding accumulate, a subtracting accumulate,
8337 * or no accumulate at all?
8355 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8356 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8359 /* size == 2 means two 32x32->64 operations; this is worth special
8360 * casing because we can generally handle it inline.
8363 for (pass
= 0; pass
< 2; pass
++) {
8364 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8365 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8366 TCGv_i64 tcg_passres
;
8367 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
8369 int elt
= pass
+ is_q
* 2;
8371 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
8372 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
8375 tcg_passres
= tcg_res
[pass
];
8377 tcg_passres
= tcg_temp_new_i64();
8381 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8382 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8384 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8385 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8387 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8388 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8390 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
8391 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
8393 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
8394 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
8395 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
8397 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
8398 tcg_temp_free_i64(tcg_tmp1
);
8399 tcg_temp_free_i64(tcg_tmp2
);
8402 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8403 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8404 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8405 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8407 case 9: /* SQDMLAL, SQDMLAL2 */
8408 case 11: /* SQDMLSL, SQDMLSL2 */
8409 case 13: /* SQDMULL, SQDMULL2 */
8410 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8411 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
8412 tcg_passres
, tcg_passres
);
8415 g_assert_not_reached();
8418 if (opcode
== 9 || opcode
== 11) {
8419 /* saturating accumulate ops */
8421 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
8423 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
8424 tcg_res
[pass
], tcg_passres
);
8425 } else if (accop
> 0) {
8426 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8427 } else if (accop
< 0) {
8428 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8432 tcg_temp_free_i64(tcg_passres
);
8435 tcg_temp_free_i64(tcg_op1
);
8436 tcg_temp_free_i64(tcg_op2
);
8439 /* size 0 or 1, generally helper functions */
8440 for (pass
= 0; pass
< 2; pass
++) {
8441 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8442 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8443 TCGv_i64 tcg_passres
;
8444 int elt
= pass
+ is_q
* 2;
8446 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
8447 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
8450 tcg_passres
= tcg_res
[pass
];
8452 tcg_passres
= tcg_temp_new_i64();
8456 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8457 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8459 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
8460 static NeonGenWidenFn
* const widenfns
[2][2] = {
8461 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8462 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8464 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8466 widenfn(tcg_op2_64
, tcg_op2
);
8467 widenfn(tcg_passres
, tcg_op1
);
8468 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
8469 tcg_passres
, tcg_op2_64
);
8470 tcg_temp_free_i64(tcg_op2_64
);
8473 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8474 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8477 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8479 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8483 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
8485 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
8489 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8490 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8491 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8494 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
8496 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
8500 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8502 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8506 case 9: /* SQDMLAL, SQDMLAL2 */
8507 case 11: /* SQDMLSL, SQDMLSL2 */
8508 case 13: /* SQDMULL, SQDMULL2 */
8510 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8511 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
8512 tcg_passres
, tcg_passres
);
8514 case 14: /* PMULL */
8516 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
8519 g_assert_not_reached();
8521 tcg_temp_free_i32(tcg_op1
);
8522 tcg_temp_free_i32(tcg_op2
);
8525 if (opcode
== 9 || opcode
== 11) {
8526 /* saturating accumulate ops */
8528 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
8530 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
8534 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
8535 tcg_res
[pass
], tcg_passres
);
8537 tcg_temp_free_i64(tcg_passres
);
8542 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8543 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8544 tcg_temp_free_i64(tcg_res
[0]);
8545 tcg_temp_free_i64(tcg_res
[1]);
8548 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
8549 int opcode
, int rd
, int rn
, int rm
)
8551 TCGv_i64 tcg_res
[2];
8552 int part
= is_q
? 2 : 0;
8555 for (pass
= 0; pass
< 2; pass
++) {
8556 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8557 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8558 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
8559 static NeonGenWidenFn
* const widenfns
[3][2] = {
8560 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8561 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8562 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
8564 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8566 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8567 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
8568 widenfn(tcg_op2_wide
, tcg_op2
);
8569 tcg_temp_free_i32(tcg_op2
);
8570 tcg_res
[pass
] = tcg_temp_new_i64();
8571 gen_neon_addl(size
, (opcode
== 3),
8572 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
8573 tcg_temp_free_i64(tcg_op1
);
8574 tcg_temp_free_i64(tcg_op2_wide
);
8577 for (pass
= 0; pass
< 2; pass
++) {
8578 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8579 tcg_temp_free_i64(tcg_res
[pass
]);
8583 static void do_narrow_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8585 tcg_gen_shri_i64(in
, in
, 32);
8586 tcg_gen_trunc_i64_i32(res
, in
);
8589 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8591 tcg_gen_addi_i64(in
, in
, 1U << 31);
8592 do_narrow_high_u32(res
, in
);
8595 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
8596 int opcode
, int rd
, int rn
, int rm
)
8598 TCGv_i32 tcg_res
[2];
8599 int part
= is_q
? 2 : 0;
8602 for (pass
= 0; pass
< 2; pass
++) {
8603 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8604 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8605 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
8606 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
8607 { gen_helper_neon_narrow_high_u8
,
8608 gen_helper_neon_narrow_round_high_u8
},
8609 { gen_helper_neon_narrow_high_u16
,
8610 gen_helper_neon_narrow_round_high_u16
},
8611 { do_narrow_high_u32
, do_narrow_round_high_u32
},
8613 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
8615 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8616 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8618 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
8620 tcg_temp_free_i64(tcg_op1
);
8621 tcg_temp_free_i64(tcg_op2
);
8623 tcg_res
[pass
] = tcg_temp_new_i32();
8624 gennarrow(tcg_res
[pass
], tcg_wideres
);
8625 tcg_temp_free_i64(tcg_wideres
);
8628 for (pass
= 0; pass
< 2; pass
++) {
8629 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
8630 tcg_temp_free_i32(tcg_res
[pass
]);
8633 clear_vec_high(s
, rd
);
8637 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
8639 /* PMULL of 64 x 64 -> 128 is an odd special case because it
8640 * is the only three-reg-diff instruction which produces a
8641 * 128-bit wide result from a single operation. However since
8642 * it's possible to calculate the two halves more or less
8643 * separately we just use two helper calls.
8645 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8646 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8647 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8649 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
8650 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
8651 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
8652 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
8653 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
8654 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
8656 tcg_temp_free_i64(tcg_op1
);
8657 tcg_temp_free_i64(tcg_op2
);
8658 tcg_temp_free_i64(tcg_res
);
8661 /* C3.6.15 AdvSIMD three different
8662 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8663 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8664 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8665 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8667 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8669 /* Instructions in this group fall into three basic classes
8670 * (in each case with the operation working on each element in
8671 * the input vectors):
8672 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
8674 * (2) wide 64 x 128 -> 128
8675 * (3) narrowing 128 x 128 -> 64
8676 * Here we do initial decode, catch unallocated cases and
8677 * dispatch to separate functions for each class.
8679 int is_q
= extract32(insn
, 30, 1);
8680 int is_u
= extract32(insn
, 29, 1);
8681 int size
= extract32(insn
, 22, 2);
8682 int opcode
= extract32(insn
, 12, 4);
8683 int rm
= extract32(insn
, 16, 5);
8684 int rn
= extract32(insn
, 5, 5);
8685 int rd
= extract32(insn
, 0, 5);
8688 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
8689 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
8690 /* 64 x 128 -> 128 */
8692 unallocated_encoding(s
);
8695 if (!fp_access_check(s
)) {
8698 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8700 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
8701 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
8702 /* 128 x 128 -> 64 */
8704 unallocated_encoding(s
);
8707 if (!fp_access_check(s
)) {
8710 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8712 case 14: /* PMULL, PMULL2 */
8713 if (is_u
|| size
== 1 || size
== 2) {
8714 unallocated_encoding(s
);
8718 if (!arm_dc_feature(s
, ARM_FEATURE_V8_PMULL
)) {
8719 unallocated_encoding(s
);
8722 if (!fp_access_check(s
)) {
8725 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
8729 case 9: /* SQDMLAL, SQDMLAL2 */
8730 case 11: /* SQDMLSL, SQDMLSL2 */
8731 case 13: /* SQDMULL, SQDMULL2 */
8732 if (is_u
|| size
== 0) {
8733 unallocated_encoding(s
);
8737 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8738 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8739 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8740 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8741 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8742 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8743 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
8744 /* 64 x 64 -> 128 */
8746 unallocated_encoding(s
);
8750 if (!fp_access_check(s
)) {
8754 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8757 /* opcode 15 not allocated */
8758 unallocated_encoding(s
);
8763 /* Logic op (opcode == 3) subgroup of C3.6.16. */
8764 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
8766 int rd
= extract32(insn
, 0, 5);
8767 int rn
= extract32(insn
, 5, 5);
8768 int rm
= extract32(insn
, 16, 5);
8769 int size
= extract32(insn
, 22, 2);
8770 bool is_u
= extract32(insn
, 29, 1);
8771 bool is_q
= extract32(insn
, 30, 1);
8772 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
8775 if (!fp_access_check(s
)) {
8779 tcg_op1
= tcg_temp_new_i64();
8780 tcg_op2
= tcg_temp_new_i64();
8781 tcg_res
[0] = tcg_temp_new_i64();
8782 tcg_res
[1] = tcg_temp_new_i64();
8784 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
8785 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8786 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8791 tcg_gen_and_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8794 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8797 tcg_gen_or_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8800 tcg_gen_orc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8805 /* B* ops need res loaded to operate on */
8806 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8811 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8813 case 1: /* BSL bitwise select */
8814 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8815 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8816 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op1
);
8818 case 2: /* BIT, bitwise insert if true */
8819 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8820 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8821 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8823 case 3: /* BIF, bitwise insert if false */
8824 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8825 tcg_gen_andc_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8826 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8832 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8834 tcg_gen_movi_i64(tcg_res
[1], 0);
8836 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8838 tcg_temp_free_i64(tcg_op1
);
8839 tcg_temp_free_i64(tcg_op2
);
8840 tcg_temp_free_i64(tcg_res
[0]);
8841 tcg_temp_free_i64(tcg_res
[1]);
8844 /* Helper functions for 32 bit comparisons */
8845 static void gen_max_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8847 tcg_gen_movcond_i32(TCG_COND_GE
, res
, op1
, op2
, op1
, op2
);
8850 static void gen_max_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8852 tcg_gen_movcond_i32(TCG_COND_GEU
, res
, op1
, op2
, op1
, op2
);
8855 static void gen_min_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8857 tcg_gen_movcond_i32(TCG_COND_LE
, res
, op1
, op2
, op1
, op2
);
8860 static void gen_min_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8862 tcg_gen_movcond_i32(TCG_COND_LEU
, res
, op1
, op2
, op1
, op2
);
8865 /* Pairwise op subgroup of C3.6.16.
8867 * This is called directly or via the handle_3same_float for float pairwise
8868 * operations where the opcode and size are calculated differently.
8870 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
8871 int size
, int rn
, int rm
, int rd
)
8876 /* Floating point operations need fpst */
8877 if (opcode
>= 0x58) {
8878 fpst
= get_fpstatus_ptr();
8880 TCGV_UNUSED_PTR(fpst
);
8883 if (!fp_access_check(s
)) {
8887 /* These operations work on the concatenated rm:rn, with each pair of
8888 * adjacent elements being operated on to produce an element in the result.
8891 TCGv_i64 tcg_res
[2];
8893 for (pass
= 0; pass
< 2; pass
++) {
8894 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8895 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8896 int passreg
= (pass
== 0) ? rn
: rm
;
8898 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
8899 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
8900 tcg_res
[pass
] = tcg_temp_new_i64();
8903 case 0x17: /* ADDP */
8904 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8906 case 0x58: /* FMAXNMP */
8907 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8909 case 0x5a: /* FADDP */
8910 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8912 case 0x5e: /* FMAXP */
8913 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8915 case 0x78: /* FMINNMP */
8916 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8918 case 0x7e: /* FMINP */
8919 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8922 g_assert_not_reached();
8925 tcg_temp_free_i64(tcg_op1
);
8926 tcg_temp_free_i64(tcg_op2
);
8929 for (pass
= 0; pass
< 2; pass
++) {
8930 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8931 tcg_temp_free_i64(tcg_res
[pass
]);
8934 int maxpass
= is_q
? 4 : 2;
8935 TCGv_i32 tcg_res
[4];
8937 for (pass
= 0; pass
< maxpass
; pass
++) {
8938 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8939 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8940 NeonGenTwoOpFn
*genfn
= NULL
;
8941 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
8942 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
8944 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
8945 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
8946 tcg_res
[pass
] = tcg_temp_new_i32();
8949 case 0x17: /* ADDP */
8951 static NeonGenTwoOpFn
* const fns
[3] = {
8952 gen_helper_neon_padd_u8
,
8953 gen_helper_neon_padd_u16
,
8959 case 0x14: /* SMAXP, UMAXP */
8961 static NeonGenTwoOpFn
* const fns
[3][2] = {
8962 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
8963 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
8964 { gen_max_s32
, gen_max_u32
},
8966 genfn
= fns
[size
][u
];
8969 case 0x15: /* SMINP, UMINP */
8971 static NeonGenTwoOpFn
* const fns
[3][2] = {
8972 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
8973 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
8974 { gen_min_s32
, gen_min_u32
},
8976 genfn
= fns
[size
][u
];
8979 /* The FP operations are all on single floats (32 bit) */
8980 case 0x58: /* FMAXNMP */
8981 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8983 case 0x5a: /* FADDP */
8984 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8986 case 0x5e: /* FMAXP */
8987 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8989 case 0x78: /* FMINNMP */
8990 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8992 case 0x7e: /* FMINP */
8993 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8996 g_assert_not_reached();
8999 /* FP ops called directly, otherwise call now */
9001 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9004 tcg_temp_free_i32(tcg_op1
);
9005 tcg_temp_free_i32(tcg_op2
);
9008 for (pass
= 0; pass
< maxpass
; pass
++) {
9009 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9010 tcg_temp_free_i32(tcg_res
[pass
]);
9013 clear_vec_high(s
, rd
);
9017 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
9018 tcg_temp_free_ptr(fpst
);
9022 /* Floating point op subgroup of C3.6.16. */
9023 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
9025 /* For floating point ops, the U, size[1] and opcode bits
9026 * together indicate the operation. size[0] indicates single
9029 int fpopcode
= extract32(insn
, 11, 5)
9030 | (extract32(insn
, 23, 1) << 5)
9031 | (extract32(insn
, 29, 1) << 6);
9032 int is_q
= extract32(insn
, 30, 1);
9033 int size
= extract32(insn
, 22, 1);
9034 int rm
= extract32(insn
, 16, 5);
9035 int rn
= extract32(insn
, 5, 5);
9036 int rd
= extract32(insn
, 0, 5);
9038 int datasize
= is_q
? 128 : 64;
9039 int esize
= 32 << size
;
9040 int elements
= datasize
/ esize
;
9042 if (size
== 1 && !is_q
) {
9043 unallocated_encoding(s
);
9048 case 0x58: /* FMAXNMP */
9049 case 0x5a: /* FADDP */
9050 case 0x5e: /* FMAXP */
9051 case 0x78: /* FMINNMP */
9052 case 0x7e: /* FMINP */
9053 if (size
&& !is_q
) {
9054 unallocated_encoding(s
);
9057 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
9060 case 0x1b: /* FMULX */
9061 case 0x1f: /* FRECPS */
9062 case 0x3f: /* FRSQRTS */
9063 case 0x5d: /* FACGE */
9064 case 0x7d: /* FACGT */
9065 case 0x19: /* FMLA */
9066 case 0x39: /* FMLS */
9067 case 0x18: /* FMAXNM */
9068 case 0x1a: /* FADD */
9069 case 0x1c: /* FCMEQ */
9070 case 0x1e: /* FMAX */
9071 case 0x38: /* FMINNM */
9072 case 0x3a: /* FSUB */
9073 case 0x3e: /* FMIN */
9074 case 0x5b: /* FMUL */
9075 case 0x5c: /* FCMGE */
9076 case 0x5f: /* FDIV */
9077 case 0x7a: /* FABD */
9078 case 0x7c: /* FCMGT */
9079 if (!fp_access_check(s
)) {
9083 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
9086 unallocated_encoding(s
);
9091 /* Integer op subgroup of C3.6.16. */
9092 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
9094 int is_q
= extract32(insn
, 30, 1);
9095 int u
= extract32(insn
, 29, 1);
9096 int size
= extract32(insn
, 22, 2);
9097 int opcode
= extract32(insn
, 11, 5);
9098 int rm
= extract32(insn
, 16, 5);
9099 int rn
= extract32(insn
, 5, 5);
9100 int rd
= extract32(insn
, 0, 5);
9104 case 0x13: /* MUL, PMUL */
9105 if (u
&& size
!= 0) {
9106 unallocated_encoding(s
);
9110 case 0x0: /* SHADD, UHADD */
9111 case 0x2: /* SRHADD, URHADD */
9112 case 0x4: /* SHSUB, UHSUB */
9113 case 0xc: /* SMAX, UMAX */
9114 case 0xd: /* SMIN, UMIN */
9115 case 0xe: /* SABD, UABD */
9116 case 0xf: /* SABA, UABA */
9117 case 0x12: /* MLA, MLS */
9119 unallocated_encoding(s
);
9123 case 0x16: /* SQDMULH, SQRDMULH */
9124 if (size
== 0 || size
== 3) {
9125 unallocated_encoding(s
);
9130 if (size
== 3 && !is_q
) {
9131 unallocated_encoding(s
);
9137 if (!fp_access_check(s
)) {
9143 for (pass
= 0; pass
< 2; pass
++) {
9144 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9145 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9146 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9148 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9149 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9151 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
9153 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9155 tcg_temp_free_i64(tcg_res
);
9156 tcg_temp_free_i64(tcg_op1
);
9157 tcg_temp_free_i64(tcg_op2
);
9160 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9161 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9162 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9163 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9164 NeonGenTwoOpFn
*genfn
= NULL
;
9165 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
9167 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
9168 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
9171 case 0x0: /* SHADD, UHADD */
9173 static NeonGenTwoOpFn
* const fns
[3][2] = {
9174 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
9175 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
9176 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
9178 genfn
= fns
[size
][u
];
9181 case 0x1: /* SQADD, UQADD */
9183 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9184 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9185 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9186 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9188 genenvfn
= fns
[size
][u
];
9191 case 0x2: /* SRHADD, URHADD */
9193 static NeonGenTwoOpFn
* const fns
[3][2] = {
9194 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
9195 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
9196 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
9198 genfn
= fns
[size
][u
];
9201 case 0x4: /* SHSUB, UHSUB */
9203 static NeonGenTwoOpFn
* const fns
[3][2] = {
9204 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
9205 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
9206 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
9208 genfn
= fns
[size
][u
];
9211 case 0x5: /* SQSUB, UQSUB */
9213 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9214 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9215 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9216 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9218 genenvfn
= fns
[size
][u
];
9221 case 0x6: /* CMGT, CMHI */
9223 static NeonGenTwoOpFn
* const fns
[3][2] = {
9224 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_u8
},
9225 { gen_helper_neon_cgt_s16
, gen_helper_neon_cgt_u16
},
9226 { gen_helper_neon_cgt_s32
, gen_helper_neon_cgt_u32
},
9228 genfn
= fns
[size
][u
];
9231 case 0x7: /* CMGE, CMHS */
9233 static NeonGenTwoOpFn
* const fns
[3][2] = {
9234 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_u8
},
9235 { gen_helper_neon_cge_s16
, gen_helper_neon_cge_u16
},
9236 { gen_helper_neon_cge_s32
, gen_helper_neon_cge_u32
},
9238 genfn
= fns
[size
][u
];
9241 case 0x8: /* SSHL, USHL */
9243 static NeonGenTwoOpFn
* const fns
[3][2] = {
9244 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
9245 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
9246 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
9248 genfn
= fns
[size
][u
];
9251 case 0x9: /* SQSHL, UQSHL */
9253 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9254 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9255 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9256 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9258 genenvfn
= fns
[size
][u
];
9261 case 0xa: /* SRSHL, URSHL */
9263 static NeonGenTwoOpFn
* const fns
[3][2] = {
9264 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
9265 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
9266 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
9268 genfn
= fns
[size
][u
];
9271 case 0xb: /* SQRSHL, UQRSHL */
9273 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9274 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9275 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9276 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9278 genenvfn
= fns
[size
][u
];
9281 case 0xc: /* SMAX, UMAX */
9283 static NeonGenTwoOpFn
* const fns
[3][2] = {
9284 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
9285 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
9286 { gen_max_s32
, gen_max_u32
},
9288 genfn
= fns
[size
][u
];
9292 case 0xd: /* SMIN, UMIN */
9294 static NeonGenTwoOpFn
* const fns
[3][2] = {
9295 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
9296 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
9297 { gen_min_s32
, gen_min_u32
},
9299 genfn
= fns
[size
][u
];
9302 case 0xe: /* SABD, UABD */
9303 case 0xf: /* SABA, UABA */
9305 static NeonGenTwoOpFn
* const fns
[3][2] = {
9306 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
9307 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
9308 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
9310 genfn
= fns
[size
][u
];
9313 case 0x10: /* ADD, SUB */
9315 static NeonGenTwoOpFn
* const fns
[3][2] = {
9316 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9317 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9318 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9320 genfn
= fns
[size
][u
];
9323 case 0x11: /* CMTST, CMEQ */
9325 static NeonGenTwoOpFn
* const fns
[3][2] = {
9326 { gen_helper_neon_tst_u8
, gen_helper_neon_ceq_u8
},
9327 { gen_helper_neon_tst_u16
, gen_helper_neon_ceq_u16
},
9328 { gen_helper_neon_tst_u32
, gen_helper_neon_ceq_u32
},
9330 genfn
= fns
[size
][u
];
9333 case 0x13: /* MUL, PMUL */
9337 genfn
= gen_helper_neon_mul_p8
;
9340 /* fall through : MUL */
9341 case 0x12: /* MLA, MLS */
9343 static NeonGenTwoOpFn
* const fns
[3] = {
9344 gen_helper_neon_mul_u8
,
9345 gen_helper_neon_mul_u16
,
9351 case 0x16: /* SQDMULH, SQRDMULH */
9353 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9354 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9355 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9357 assert(size
== 1 || size
== 2);
9358 genenvfn
= fns
[size
- 1][u
];
9362 g_assert_not_reached();
9366 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
9368 genfn(tcg_res
, tcg_op1
, tcg_op2
);
9371 if (opcode
== 0xf || opcode
== 0x12) {
9372 /* SABA, UABA, MLA, MLS: accumulating ops */
9373 static NeonGenTwoOpFn
* const fns
[3][2] = {
9374 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9375 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9376 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9378 bool is_sub
= (opcode
== 0x12 && u
); /* MLS */
9380 genfn
= fns
[size
][is_sub
];
9381 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
9382 genfn(tcg_res
, tcg_op1
, tcg_res
);
9385 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9387 tcg_temp_free_i32(tcg_res
);
9388 tcg_temp_free_i32(tcg_op1
);
9389 tcg_temp_free_i32(tcg_op2
);
9394 clear_vec_high(s
, rd
);
9398 /* C3.6.16 AdvSIMD three same
9399 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
9400 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9401 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
9402 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9404 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
9406 int opcode
= extract32(insn
, 11, 5);
9409 case 0x3: /* logic ops */
9410 disas_simd_3same_logic(s
, insn
);
9412 case 0x17: /* ADDP */
9413 case 0x14: /* SMAXP, UMAXP */
9414 case 0x15: /* SMINP, UMINP */
9416 /* Pairwise operations */
9417 int is_q
= extract32(insn
, 30, 1);
9418 int u
= extract32(insn
, 29, 1);
9419 int size
= extract32(insn
, 22, 2);
9420 int rm
= extract32(insn
, 16, 5);
9421 int rn
= extract32(insn
, 5, 5);
9422 int rd
= extract32(insn
, 0, 5);
9423 if (opcode
== 0x17) {
9424 if (u
|| (size
== 3 && !is_q
)) {
9425 unallocated_encoding(s
);
9430 unallocated_encoding(s
);
9434 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
9438 /* floating point ops, sz[1] and U are part of opcode */
9439 disas_simd_3same_float(s
, insn
);
9442 disas_simd_3same_int(s
, insn
);
9447 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
9448 int size
, int rn
, int rd
)
9450 /* Handle 2-reg-misc ops which are widening (so each size element
9451 * in the source becomes a 2*size element in the destination.
9452 * The only instruction like this is FCVTL.
9457 /* 32 -> 64 bit fp conversion */
9458 TCGv_i64 tcg_res
[2];
9459 int srcelt
= is_q
? 2 : 0;
9461 for (pass
= 0; pass
< 2; pass
++) {
9462 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9463 tcg_res
[pass
] = tcg_temp_new_i64();
9465 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
9466 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
9467 tcg_temp_free_i32(tcg_op
);
9469 for (pass
= 0; pass
< 2; pass
++) {
9470 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9471 tcg_temp_free_i64(tcg_res
[pass
]);
9474 /* 16 -> 32 bit fp conversion */
9475 int srcelt
= is_q
? 4 : 0;
9476 TCGv_i32 tcg_res
[4];
9478 for (pass
= 0; pass
< 4; pass
++) {
9479 tcg_res
[pass
] = tcg_temp_new_i32();
9481 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
9482 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
9485 for (pass
= 0; pass
< 4; pass
++) {
9486 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9487 tcg_temp_free_i32(tcg_res
[pass
]);
9492 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
9493 bool is_q
, int size
, int rn
, int rd
)
9495 int op
= (opcode
<< 1) | u
;
9496 int opsz
= op
+ size
;
9497 int grp_size
= 3 - opsz
;
9498 int dsize
= is_q
? 128 : 64;
9502 unallocated_encoding(s
);
9506 if (!fp_access_check(s
)) {
9511 /* Special case bytes, use bswap op on each group of elements */
9512 int groups
= dsize
/ (8 << grp_size
);
9514 for (i
= 0; i
< groups
; i
++) {
9515 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9517 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
9520 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
9523 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
9526 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
9529 g_assert_not_reached();
9531 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
9532 tcg_temp_free_i64(tcg_tmp
);
9535 clear_vec_high(s
, rd
);
9538 int revmask
= (1 << grp_size
) - 1;
9539 int esize
= 8 << size
;
9540 int elements
= dsize
/ esize
;
9541 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9542 TCGv_i64 tcg_rd
= tcg_const_i64(0);
9543 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
9545 for (i
= 0; i
< elements
; i
++) {
9546 int e_rev
= (i
& 0xf) ^ revmask
;
9547 int off
= e_rev
* esize
;
9548 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
9550 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
9551 tcg_rn
, off
- 64, esize
);
9553 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
9556 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
9557 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
9559 tcg_temp_free_i64(tcg_rd_hi
);
9560 tcg_temp_free_i64(tcg_rd
);
9561 tcg_temp_free_i64(tcg_rn
);
9565 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
9566 bool is_q
, int size
, int rn
, int rd
)
9568 /* Implement the pairwise operations from 2-misc:
9569 * SADDLP, UADDLP, SADALP, UADALP.
9570 * These all add pairs of elements in the input to produce a
9571 * double-width result element in the output (possibly accumulating).
9573 bool accum
= (opcode
== 0x6);
9574 int maxpass
= is_q
? 2 : 1;
9576 TCGv_i64 tcg_res
[2];
9579 /* 32 + 32 -> 64 op */
9580 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
9582 for (pass
= 0; pass
< maxpass
; pass
++) {
9583 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9584 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9586 tcg_res
[pass
] = tcg_temp_new_i64();
9588 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
9589 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
9590 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9592 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
9593 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9596 tcg_temp_free_i64(tcg_op1
);
9597 tcg_temp_free_i64(tcg_op2
);
9600 for (pass
= 0; pass
< maxpass
; pass
++) {
9601 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9602 NeonGenOneOpFn
*genfn
;
9603 static NeonGenOneOpFn
* const fns
[2][2] = {
9604 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
9605 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
9608 genfn
= fns
[size
][u
];
9610 tcg_res
[pass
] = tcg_temp_new_i64();
9612 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9613 genfn(tcg_res
[pass
], tcg_op
);
9616 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
9618 gen_helper_neon_addl_u16(tcg_res
[pass
],
9619 tcg_res
[pass
], tcg_op
);
9621 gen_helper_neon_addl_u32(tcg_res
[pass
],
9622 tcg_res
[pass
], tcg_op
);
9625 tcg_temp_free_i64(tcg_op
);
9629 tcg_res
[1] = tcg_const_i64(0);
9631 for (pass
= 0; pass
< 2; pass
++) {
9632 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9633 tcg_temp_free_i64(tcg_res
[pass
]);
9637 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
9639 /* Implement SHLL and SHLL2 */
9641 int part
= is_q
? 2 : 0;
9642 TCGv_i64 tcg_res
[2];
9644 for (pass
= 0; pass
< 2; pass
++) {
9645 static NeonGenWidenFn
* const widenfns
[3] = {
9646 gen_helper_neon_widen_u8
,
9647 gen_helper_neon_widen_u16
,
9648 tcg_gen_extu_i32_i64
,
9650 NeonGenWidenFn
*widenfn
= widenfns
[size
];
9651 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9653 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
9654 tcg_res
[pass
] = tcg_temp_new_i64();
9655 widenfn(tcg_res
[pass
], tcg_op
);
9656 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
9658 tcg_temp_free_i32(tcg_op
);
9661 for (pass
= 0; pass
< 2; pass
++) {
9662 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9663 tcg_temp_free_i64(tcg_res
[pass
]);
9667 /* C3.6.17 AdvSIMD two reg misc
9668 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9669 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9670 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9671 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9673 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9675 int size
= extract32(insn
, 22, 2);
9676 int opcode
= extract32(insn
, 12, 5);
9677 bool u
= extract32(insn
, 29, 1);
9678 bool is_q
= extract32(insn
, 30, 1);
9679 int rn
= extract32(insn
, 5, 5);
9680 int rd
= extract32(insn
, 0, 5);
9681 bool need_fpstatus
= false;
9682 bool need_rmode
= false;
9685 TCGv_ptr tcg_fpstatus
;
9688 case 0x0: /* REV64, REV32 */
9689 case 0x1: /* REV16 */
9690 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9692 case 0x5: /* CNT, NOT, RBIT */
9693 if (u
&& size
== 0) {
9694 /* NOT: adjust size so we can use the 64-bits-at-a-time loop. */
9697 } else if (u
&& size
== 1) {
9700 } else if (!u
&& size
== 0) {
9704 unallocated_encoding(s
);
9706 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
9707 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
9709 unallocated_encoding(s
);
9712 if (!fp_access_check(s
)) {
9716 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
9718 case 0x4: /* CLS, CLZ */
9720 unallocated_encoding(s
);
9724 case 0x2: /* SADDLP, UADDLP */
9725 case 0x6: /* SADALP, UADALP */
9727 unallocated_encoding(s
);
9730 if (!fp_access_check(s
)) {
9733 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9735 case 0x13: /* SHLL, SHLL2 */
9736 if (u
== 0 || size
== 3) {
9737 unallocated_encoding(s
);
9740 if (!fp_access_check(s
)) {
9743 handle_shll(s
, is_q
, size
, rn
, rd
);
9745 case 0xa: /* CMLT */
9747 unallocated_encoding(s
);
9751 case 0x8: /* CMGT, CMGE */
9752 case 0x9: /* CMEQ, CMLE */
9753 case 0xb: /* ABS, NEG */
9754 if (size
== 3 && !is_q
) {
9755 unallocated_encoding(s
);
9759 case 0x3: /* SUQADD, USQADD */
9760 if (size
== 3 && !is_q
) {
9761 unallocated_encoding(s
);
9764 if (!fp_access_check(s
)) {
9767 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
9769 case 0x7: /* SQABS, SQNEG */
9770 if (size
== 3 && !is_q
) {
9771 unallocated_encoding(s
);
9779 /* Floating point: U, size[1] and opcode indicate operation;
9780 * size[0] indicates single or double precision.
9782 int is_double
= extract32(size
, 0, 1);
9783 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9784 size
= is_double
? 3 : 2;
9786 case 0x2f: /* FABS */
9787 case 0x6f: /* FNEG */
9788 if (size
== 3 && !is_q
) {
9789 unallocated_encoding(s
);
9793 case 0x1d: /* SCVTF */
9794 case 0x5d: /* UCVTF */
9796 bool is_signed
= (opcode
== 0x1d) ? true : false;
9797 int elements
= is_double
? 2 : is_q
? 4 : 2;
9798 if (is_double
&& !is_q
) {
9799 unallocated_encoding(s
);
9802 if (!fp_access_check(s
)) {
9805 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
9808 case 0x2c: /* FCMGT (zero) */
9809 case 0x2d: /* FCMEQ (zero) */
9810 case 0x2e: /* FCMLT (zero) */
9811 case 0x6c: /* FCMGE (zero) */
9812 case 0x6d: /* FCMLE (zero) */
9813 if (size
== 3 && !is_q
) {
9814 unallocated_encoding(s
);
9817 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9819 case 0x7f: /* FSQRT */
9820 if (size
== 3 && !is_q
) {
9821 unallocated_encoding(s
);
9825 case 0x1a: /* FCVTNS */
9826 case 0x1b: /* FCVTMS */
9827 case 0x3a: /* FCVTPS */
9828 case 0x3b: /* FCVTZS */
9829 case 0x5a: /* FCVTNU */
9830 case 0x5b: /* FCVTMU */
9831 case 0x7a: /* FCVTPU */
9832 case 0x7b: /* FCVTZU */
9833 need_fpstatus
= true;
9835 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9836 if (size
== 3 && !is_q
) {
9837 unallocated_encoding(s
);
9841 case 0x5c: /* FCVTAU */
9842 case 0x1c: /* FCVTAS */
9843 need_fpstatus
= true;
9845 rmode
= FPROUNDING_TIEAWAY
;
9846 if (size
== 3 && !is_q
) {
9847 unallocated_encoding(s
);
9851 case 0x3c: /* URECPE */
9853 unallocated_encoding(s
);
9857 case 0x3d: /* FRECPE */
9858 case 0x7d: /* FRSQRTE */
9859 if (size
== 3 && !is_q
) {
9860 unallocated_encoding(s
);
9863 if (!fp_access_check(s
)) {
9866 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9868 case 0x56: /* FCVTXN, FCVTXN2 */
9870 unallocated_encoding(s
);
9874 case 0x16: /* FCVTN, FCVTN2 */
9875 /* handle_2misc_narrow does a 2*size -> size operation, but these
9876 * instructions encode the source size rather than dest size.
9878 if (!fp_access_check(s
)) {
9881 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
9883 case 0x17: /* FCVTL, FCVTL2 */
9884 if (!fp_access_check(s
)) {
9887 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
9889 case 0x18: /* FRINTN */
9890 case 0x19: /* FRINTM */
9891 case 0x38: /* FRINTP */
9892 case 0x39: /* FRINTZ */
9894 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9896 case 0x59: /* FRINTX */
9897 case 0x79: /* FRINTI */
9898 need_fpstatus
= true;
9899 if (size
== 3 && !is_q
) {
9900 unallocated_encoding(s
);
9904 case 0x58: /* FRINTA */
9906 rmode
= FPROUNDING_TIEAWAY
;
9907 need_fpstatus
= true;
9908 if (size
== 3 && !is_q
) {
9909 unallocated_encoding(s
);
9913 case 0x7c: /* URSQRTE */
9915 unallocated_encoding(s
);
9918 need_fpstatus
= true;
9921 unallocated_encoding(s
);
9927 unallocated_encoding(s
);
9931 if (!fp_access_check(s
)) {
9935 if (need_fpstatus
) {
9936 tcg_fpstatus
= get_fpstatus_ptr();
9938 TCGV_UNUSED_PTR(tcg_fpstatus
);
9941 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
9942 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
9944 TCGV_UNUSED_I32(tcg_rmode
);
9948 /* All 64-bit element operations can be shared with scalar 2misc */
9951 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
9952 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9953 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9955 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9957 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
9958 tcg_rmode
, tcg_fpstatus
);
9960 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9962 tcg_temp_free_i64(tcg_res
);
9963 tcg_temp_free_i64(tcg_op
);
9968 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9969 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9970 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9973 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
9976 /* Special cases for 32 bit elements */
9978 case 0xa: /* CMLT */
9979 /* 32 bit integer comparison against zero, result is
9980 * test ? (2^32 - 1) : 0. We implement via setcond(test)
9985 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
9986 tcg_gen_neg_i32(tcg_res
, tcg_res
);
9988 case 0x8: /* CMGT, CMGE */
9989 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
9991 case 0x9: /* CMEQ, CMLE */
9992 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
9996 gen_helper_clz32(tcg_res
, tcg_op
);
9998 gen_helper_cls32(tcg_res
, tcg_op
);
10001 case 0x7: /* SQABS, SQNEG */
10003 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
10005 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
10008 case 0xb: /* ABS, NEG */
10010 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10012 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10013 tcg_gen_neg_i32(tcg_res
, tcg_op
);
10014 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
10015 tcg_zero
, tcg_op
, tcg_res
);
10016 tcg_temp_free_i32(tcg_zero
);
10019 case 0x2f: /* FABS */
10020 gen_helper_vfp_abss(tcg_res
, tcg_op
);
10022 case 0x6f: /* FNEG */
10023 gen_helper_vfp_negs(tcg_res
, tcg_op
);
10025 case 0x7f: /* FSQRT */
10026 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
10028 case 0x1a: /* FCVTNS */
10029 case 0x1b: /* FCVTMS */
10030 case 0x1c: /* FCVTAS */
10031 case 0x3a: /* FCVTPS */
10032 case 0x3b: /* FCVTZS */
10034 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10035 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
10036 tcg_shift
, tcg_fpstatus
);
10037 tcg_temp_free_i32(tcg_shift
);
10040 case 0x5a: /* FCVTNU */
10041 case 0x5b: /* FCVTMU */
10042 case 0x5c: /* FCVTAU */
10043 case 0x7a: /* FCVTPU */
10044 case 0x7b: /* FCVTZU */
10046 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10047 gen_helper_vfp_touls(tcg_res
, tcg_op
,
10048 tcg_shift
, tcg_fpstatus
);
10049 tcg_temp_free_i32(tcg_shift
);
10052 case 0x18: /* FRINTN */
10053 case 0x19: /* FRINTM */
10054 case 0x38: /* FRINTP */
10055 case 0x39: /* FRINTZ */
10056 case 0x58: /* FRINTA */
10057 case 0x79: /* FRINTI */
10058 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
10060 case 0x59: /* FRINTX */
10061 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
10063 case 0x7c: /* URSQRTE */
10064 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
10067 g_assert_not_reached();
10070 /* Use helpers for 8 and 16 bit elements */
10072 case 0x5: /* CNT, RBIT */
10073 /* For these two insns size is part of the opcode specifier
10074 * (handled earlier); they always operate on byte elements.
10077 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
10079 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
10082 case 0x7: /* SQABS, SQNEG */
10084 NeonGenOneOpEnvFn
*genfn
;
10085 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
10086 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
10087 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
10089 genfn
= fns
[size
][u
];
10090 genfn(tcg_res
, cpu_env
, tcg_op
);
10093 case 0x8: /* CMGT, CMGE */
10094 case 0x9: /* CMEQ, CMLE */
10095 case 0xa: /* CMLT */
10097 static NeonGenTwoOpFn
* const fns
[3][2] = {
10098 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
10099 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
10100 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
10102 NeonGenTwoOpFn
*genfn
;
10105 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10107 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
10108 comp
= (opcode
- 0x8) * 2 + u
;
10109 /* ...but LE, LT are implemented as reverse GE, GT */
10110 reverse
= (comp
> 2);
10114 genfn
= fns
[comp
][size
];
10116 genfn(tcg_res
, tcg_zero
, tcg_op
);
10118 genfn(tcg_res
, tcg_op
, tcg_zero
);
10120 tcg_temp_free_i32(tcg_zero
);
10123 case 0xb: /* ABS, NEG */
10125 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10127 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
10129 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
10131 tcg_temp_free_i32(tcg_zero
);
10134 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
10136 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
10140 case 0x4: /* CLS, CLZ */
10143 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
10145 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
10149 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
10151 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
10156 g_assert_not_reached();
10160 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10162 tcg_temp_free_i32(tcg_res
);
10163 tcg_temp_free_i32(tcg_op
);
10167 clear_vec_high(s
, rd
);
10171 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10172 tcg_temp_free_i32(tcg_rmode
);
10174 if (need_fpstatus
) {
10175 tcg_temp_free_ptr(tcg_fpstatus
);
10179 /* C3.6.13 AdvSIMD scalar x indexed element
10180 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10181 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10182 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10183 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10184 * C3.6.18 AdvSIMD vector x indexed element
10185 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10186 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10187 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10188 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10190 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
10192 /* This encoding has two kinds of instruction:
10193 * normal, where we perform elt x idxelt => elt for each
10194 * element in the vector
10195 * long, where we perform elt x idxelt and generate a result of
10196 * double the width of the input element
10197 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
10199 bool is_scalar
= extract32(insn
, 28, 1);
10200 bool is_q
= extract32(insn
, 30, 1);
10201 bool u
= extract32(insn
, 29, 1);
10202 int size
= extract32(insn
, 22, 2);
10203 int l
= extract32(insn
, 21, 1);
10204 int m
= extract32(insn
, 20, 1);
10205 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
10206 int rm
= extract32(insn
, 16, 4);
10207 int opcode
= extract32(insn
, 12, 4);
10208 int h
= extract32(insn
, 11, 1);
10209 int rn
= extract32(insn
, 5, 5);
10210 int rd
= extract32(insn
, 0, 5);
10211 bool is_long
= false;
10212 bool is_fp
= false;
10217 case 0x0: /* MLA */
10218 case 0x4: /* MLS */
10219 if (!u
|| is_scalar
) {
10220 unallocated_encoding(s
);
10224 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10225 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10226 case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
10228 unallocated_encoding(s
);
10233 case 0x3: /* SQDMLAL, SQDMLAL2 */
10234 case 0x7: /* SQDMLSL, SQDMLSL2 */
10235 case 0xb: /* SQDMULL, SQDMULL2 */
10238 case 0xc: /* SQDMULH */
10239 case 0xd: /* SQRDMULH */
10241 unallocated_encoding(s
);
10245 case 0x8: /* MUL */
10246 if (u
|| is_scalar
) {
10247 unallocated_encoding(s
);
10251 case 0x1: /* FMLA */
10252 case 0x5: /* FMLS */
10254 unallocated_encoding(s
);
10258 case 0x9: /* FMUL, FMULX */
10259 if (!extract32(size
, 1, 1)) {
10260 unallocated_encoding(s
);
10266 unallocated_encoding(s
);
10271 /* low bit of size indicates single/double */
10272 size
= extract32(size
, 0, 1) ? 3 : 2;
10274 index
= h
<< 1 | l
;
10277 unallocated_encoding(s
);
10286 index
= h
<< 2 | l
<< 1 | m
;
10289 index
= h
<< 1 | l
;
10293 unallocated_encoding(s
);
10298 if (!fp_access_check(s
)) {
10303 fpst
= get_fpstatus_ptr();
10305 TCGV_UNUSED_PTR(fpst
);
10309 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10312 assert(is_fp
&& is_q
&& !is_long
);
10314 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
10316 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10317 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10318 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10320 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10323 case 0x5: /* FMLS */
10324 /* As usual for ARM, separate negation for fused multiply-add */
10325 gen_helper_vfp_negd(tcg_op
, tcg_op
);
10327 case 0x1: /* FMLA */
10328 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10329 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10331 case 0x9: /* FMUL, FMULX */
10333 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10335 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10339 g_assert_not_reached();
10342 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10343 tcg_temp_free_i64(tcg_op
);
10344 tcg_temp_free_i64(tcg_res
);
10348 clear_vec_high(s
, rd
);
10351 tcg_temp_free_i64(tcg_idx
);
10352 } else if (!is_long
) {
10353 /* 32 bit floating point, or 16 or 32 bit integer.
10354 * For the 16 bit scalar case we use the usual Neon helpers and
10355 * rely on the fact that 0 op 0 == 0 with no side effects.
10357 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10358 int pass
, maxpasses
;
10363 maxpasses
= is_q
? 4 : 2;
10366 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10368 if (size
== 1 && !is_scalar
) {
10369 /* The simplest way to handle the 16x16 indexed ops is to duplicate
10370 * the index into both halves of the 32 bit tcg_idx and then use
10371 * the usual Neon helpers.
10373 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10376 for (pass
= 0; pass
< maxpasses
; pass
++) {
10377 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10378 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10380 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
10383 case 0x0: /* MLA */
10384 case 0x4: /* MLS */
10385 case 0x8: /* MUL */
10387 static NeonGenTwoOpFn
* const fns
[2][2] = {
10388 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
10389 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
10391 NeonGenTwoOpFn
*genfn
;
10392 bool is_sub
= opcode
== 0x4;
10395 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
10397 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
10399 if (opcode
== 0x8) {
10402 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
10403 genfn
= fns
[size
- 1][is_sub
];
10404 genfn(tcg_res
, tcg_op
, tcg_res
);
10407 case 0x5: /* FMLS */
10408 /* As usual for ARM, separate negation for fused multiply-add */
10409 gen_helper_vfp_negs(tcg_op
, tcg_op
);
10411 case 0x1: /* FMLA */
10412 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10413 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10415 case 0x9: /* FMUL, FMULX */
10417 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10419 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10422 case 0xc: /* SQDMULH */
10424 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
10427 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
10431 case 0xd: /* SQRDMULH */
10433 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
10436 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
10441 g_assert_not_reached();
10445 write_fp_sreg(s
, rd
, tcg_res
);
10447 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10450 tcg_temp_free_i32(tcg_op
);
10451 tcg_temp_free_i32(tcg_res
);
10454 tcg_temp_free_i32(tcg_idx
);
10457 clear_vec_high(s
, rd
);
10460 /* long ops: 16x16->32 or 32x32->64 */
10461 TCGv_i64 tcg_res
[2];
10463 bool satop
= extract32(opcode
, 0, 1);
10464 TCGMemOp memop
= MO_32
;
10471 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10473 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
10475 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10476 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10477 TCGv_i64 tcg_passres
;
10483 passelt
= pass
+ (is_q
* 2);
10486 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
10488 tcg_res
[pass
] = tcg_temp_new_i64();
10490 if (opcode
== 0xa || opcode
== 0xb) {
10491 /* Non-accumulating ops */
10492 tcg_passres
= tcg_res
[pass
];
10494 tcg_passres
= tcg_temp_new_i64();
10497 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
10498 tcg_temp_free_i64(tcg_op
);
10501 /* saturating, doubling */
10502 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10503 tcg_passres
, tcg_passres
);
10506 if (opcode
== 0xa || opcode
== 0xb) {
10510 /* Accumulating op: handle accumulate step */
10511 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10514 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10515 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10517 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10518 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10520 case 0x7: /* SQDMLSL, SQDMLSL2 */
10521 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10523 case 0x3: /* SQDMLAL, SQDMLAL2 */
10524 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10529 g_assert_not_reached();
10531 tcg_temp_free_i64(tcg_passres
);
10533 tcg_temp_free_i64(tcg_idx
);
10536 clear_vec_high(s
, rd
);
10539 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10542 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10545 /* The simplest way to handle the 16x16 indexed ops is to
10546 * duplicate the index into both halves of the 32 bit tcg_idx
10547 * and then use the usual Neon helpers.
10549 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10552 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10553 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10554 TCGv_i64 tcg_passres
;
10557 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10559 read_vec_element_i32(s
, tcg_op
, rn
,
10560 pass
+ (is_q
* 2), MO_32
);
10563 tcg_res
[pass
] = tcg_temp_new_i64();
10565 if (opcode
== 0xa || opcode
== 0xb) {
10566 /* Non-accumulating ops */
10567 tcg_passres
= tcg_res
[pass
];
10569 tcg_passres
= tcg_temp_new_i64();
10572 if (memop
& MO_SIGN
) {
10573 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
10575 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
10578 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10579 tcg_passres
, tcg_passres
);
10581 tcg_temp_free_i32(tcg_op
);
10583 if (opcode
== 0xa || opcode
== 0xb) {
10587 /* Accumulating op: handle accumulate step */
10588 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10591 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10592 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
10595 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10596 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
10599 case 0x7: /* SQDMLSL, SQDMLSL2 */
10600 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10602 case 0x3: /* SQDMLAL, SQDMLAL2 */
10603 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10608 g_assert_not_reached();
10610 tcg_temp_free_i64(tcg_passres
);
10612 tcg_temp_free_i32(tcg_idx
);
10615 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
10620 tcg_res
[1] = tcg_const_i64(0);
10623 for (pass
= 0; pass
< 2; pass
++) {
10624 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10625 tcg_temp_free_i64(tcg_res
[pass
]);
10629 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
10630 tcg_temp_free_ptr(fpst
);
10634 /* C3.6.19 Crypto AES
10635 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10636 * +-----------------+------+-----------+--------+-----+------+------+
10637 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10638 * +-----------------+------+-----------+--------+-----+------+------+
10640 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
10642 int size
= extract32(insn
, 22, 2);
10643 int opcode
= extract32(insn
, 12, 5);
10644 int rn
= extract32(insn
, 5, 5);
10645 int rd
= extract32(insn
, 0, 5);
10647 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
;
10648 CryptoThreeOpEnvFn
*genfn
;
10650 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)
10652 unallocated_encoding(s
);
10657 case 0x4: /* AESE */
10659 genfn
= gen_helper_crypto_aese
;
10661 case 0x6: /* AESMC */
10663 genfn
= gen_helper_crypto_aesmc
;
10665 case 0x5: /* AESD */
10667 genfn
= gen_helper_crypto_aese
;
10669 case 0x7: /* AESIMC */
10671 genfn
= gen_helper_crypto_aesmc
;
10674 unallocated_encoding(s
);
10678 /* Note that we convert the Vx register indexes into the
10679 * index within the vfp.regs[] array, so we can share the
10680 * helper with the AArch32 instructions.
10682 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10683 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10684 tcg_decrypt
= tcg_const_i32(decrypt
);
10686 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
);
10688 tcg_temp_free_i32(tcg_rd_regno
);
10689 tcg_temp_free_i32(tcg_rn_regno
);
10690 tcg_temp_free_i32(tcg_decrypt
);
10693 /* C3.6.20 Crypto three-reg SHA
10694 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
10695 * +-----------------+------+---+------+---+--------+-----+------+------+
10696 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
10697 * +-----------------+------+---+------+---+--------+-----+------+------+
10699 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
10701 int size
= extract32(insn
, 22, 2);
10702 int opcode
= extract32(insn
, 12, 3);
10703 int rm
= extract32(insn
, 16, 5);
10704 int rn
= extract32(insn
, 5, 5);
10705 int rd
= extract32(insn
, 0, 5);
10706 CryptoThreeOpEnvFn
*genfn
;
10707 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
;
10708 int feature
= ARM_FEATURE_V8_SHA256
;
10711 unallocated_encoding(s
);
10716 case 0: /* SHA1C */
10717 case 1: /* SHA1P */
10718 case 2: /* SHA1M */
10719 case 3: /* SHA1SU0 */
10721 feature
= ARM_FEATURE_V8_SHA1
;
10723 case 4: /* SHA256H */
10724 genfn
= gen_helper_crypto_sha256h
;
10726 case 5: /* SHA256H2 */
10727 genfn
= gen_helper_crypto_sha256h2
;
10729 case 6: /* SHA256SU1 */
10730 genfn
= gen_helper_crypto_sha256su1
;
10733 unallocated_encoding(s
);
10737 if (!arm_dc_feature(s
, feature
)) {
10738 unallocated_encoding(s
);
10742 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10743 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10744 tcg_rm_regno
= tcg_const_i32(rm
<< 1);
10747 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
);
10749 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
10751 gen_helper_crypto_sha1_3reg(cpu_env
, tcg_rd_regno
,
10752 tcg_rn_regno
, tcg_rm_regno
, tcg_opcode
);
10753 tcg_temp_free_i32(tcg_opcode
);
10756 tcg_temp_free_i32(tcg_rd_regno
);
10757 tcg_temp_free_i32(tcg_rn_regno
);
10758 tcg_temp_free_i32(tcg_rm_regno
);
10761 /* C3.6.21 Crypto two-reg SHA
10762 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10763 * +-----------------+------+-----------+--------+-----+------+------+
10764 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10765 * +-----------------+------+-----------+--------+-----+------+------+
10767 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
10769 int size
= extract32(insn
, 22, 2);
10770 int opcode
= extract32(insn
, 12, 5);
10771 int rn
= extract32(insn
, 5, 5);
10772 int rd
= extract32(insn
, 0, 5);
10773 CryptoTwoOpEnvFn
*genfn
;
10775 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
;
10778 unallocated_encoding(s
);
10783 case 0: /* SHA1H */
10784 feature
= ARM_FEATURE_V8_SHA1
;
10785 genfn
= gen_helper_crypto_sha1h
;
10787 case 1: /* SHA1SU1 */
10788 feature
= ARM_FEATURE_V8_SHA1
;
10789 genfn
= gen_helper_crypto_sha1su1
;
10791 case 2: /* SHA256SU0 */
10792 feature
= ARM_FEATURE_V8_SHA256
;
10793 genfn
= gen_helper_crypto_sha256su0
;
10796 unallocated_encoding(s
);
10800 if (!arm_dc_feature(s
, feature
)) {
10801 unallocated_encoding(s
);
10805 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10806 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10808 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
);
10810 tcg_temp_free_i32(tcg_rd_regno
);
10811 tcg_temp_free_i32(tcg_rn_regno
);
10814 /* C3.6 Data processing - SIMD, inc Crypto
10816 * As the decode gets a little complex we are using a table based
10817 * approach for this part of the decode.
10819 static const AArch64DecodeTable data_proc_simd
[] = {
10820 /* pattern , mask , fn */
10821 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
10822 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
10823 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
10824 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
10825 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
10826 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
10827 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
10828 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
10829 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
10830 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
10831 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
10832 { 0x2e000000, 0xbf208400, disas_simd_ext
},
10833 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
10834 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
10835 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
10836 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
10837 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
10838 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
10839 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
10840 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
10841 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
10842 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
10843 { 0x00000000, 0x00000000, NULL
}
10846 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
10848 /* Note that this is called with all non-FP cases from
10849 * table C3-6 so it must UNDEF for entries not specifically
10850 * allocated to instructions in that table.
10852 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
10856 unallocated_encoding(s
);
10860 /* C3.6 Data processing - SIMD and floating point */
10861 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
10863 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
10864 disas_data_proc_fp(s
, insn
);
10866 /* SIMD, including crypto */
10867 disas_data_proc_simd(s
, insn
);
10871 /* C3.1 A64 instruction index by encoding */
10872 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
10876 insn
= arm_ldl_code(env
, s
->pc
, s
->bswap_code
);
10880 s
->fp_access_checked
= false;
10882 switch (extract32(insn
, 25, 4)) {
10883 case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
10884 unallocated_encoding(s
);
10886 case 0x8: case 0x9: /* Data processing - immediate */
10887 disas_data_proc_imm(s
, insn
);
10889 case 0xa: case 0xb: /* Branch, exception generation and system insns */
10890 disas_b_exc_sys(s
, insn
);
10895 case 0xe: /* Loads and stores */
10896 disas_ldst(s
, insn
);
10899 case 0xd: /* Data processing - register */
10900 disas_data_proc_reg(s
, insn
);
10903 case 0xf: /* Data processing - SIMD and floating point */
10904 disas_data_proc_simd_fp(s
, insn
);
10907 assert(FALSE
); /* all 15 cases should be handled above */
10911 /* if we allocated any temporaries, free them here */
10915 void gen_intermediate_code_internal_a64(ARMCPU
*cpu
,
10916 TranslationBlock
*tb
,
10919 CPUState
*cs
= CPU(cpu
);
10920 CPUARMState
*env
= &cpu
->env
;
10921 DisasContext dc1
, *dc
= &dc1
;
10924 target_ulong pc_start
;
10925 target_ulong next_page_start
;
10933 dc
->is_jmp
= DISAS_NEXT
;
10935 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
10940 dc
->bswap_code
= 0;
10941 dc
->condexec_mask
= 0;
10942 dc
->condexec_cond
= 0;
10943 dc
->mmu_idx
= ARM_TBFLAG_MMUIDX(tb
->flags
);
10944 dc
->current_el
= arm_mmu_idx_to_el(dc
->mmu_idx
);
10945 #if !defined(CONFIG_USER_ONLY)
10946 dc
->user
= (dc
->current_el
== 0);
10948 dc
->cpacr_fpen
= ARM_TBFLAG_AA64_FPEN(tb
->flags
);
10950 dc
->vec_stride
= 0;
10951 dc
->cp_regs
= cpu
->cp_regs
;
10952 dc
->features
= env
->features
;
10954 /* Single step state. The code-generation logic here is:
10956 * generate code with no special handling for single-stepping (except
10957 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
10958 * this happens anyway because those changes are all system register or
10960 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
10961 * emit code for one insn
10962 * emit code to clear PSTATE.SS
10963 * emit code to generate software step exception for completed step
10964 * end TB (as usual for having generated an exception)
10965 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
10966 * emit code to generate a software step exception
10969 dc
->ss_active
= ARM_TBFLAG_AA64_SS_ACTIVE(tb
->flags
);
10970 dc
->pstate_ss
= ARM_TBFLAG_AA64_PSTATE_SS(tb
->flags
);
10971 dc
->is_ldex
= false;
10972 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
10974 init_tmp_a64_array(dc
);
10976 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
10979 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
10980 if (max_insns
== 0) {
10981 max_insns
= CF_COUNT_MASK
;
10986 tcg_clear_temp_count();
10989 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
10990 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
10991 if (bp
->pc
== dc
->pc
) {
10992 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
10993 /* Advance PC so that clearing the breakpoint will
10994 invalidate this TB. */
10996 goto done_generating
;
11002 j
= tcg_op_buf_count();
11006 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
11009 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
11010 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
11011 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
11014 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
11018 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
11019 tcg_gen_debug_insn_start(dc
->pc
);
11022 if (dc
->ss_active
&& !dc
->pstate_ss
) {
11023 /* Singlestep state is Active-pending.
11024 * If we're in this state at the start of a TB then either
11025 * a) we just took an exception to an EL which is being debugged
11026 * and this is the first insn in the exception handler
11027 * b) debug exceptions were masked and we just unmasked them
11028 * without changing EL (eg by clearing PSTATE.D)
11029 * In either case we're going to take a swstep exception in the
11030 * "did not step an insn" case, and so the syndrome ISV and EX
11031 * bits should be zero.
11033 assert(num_insns
== 0);
11034 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0));
11035 dc
->is_jmp
= DISAS_EXC
;
11039 disas_a64_insn(env
, dc
);
11041 if (tcg_check_temp_count()) {
11042 fprintf(stderr
, "TCG temporary leak before "TARGET_FMT_lx
"\n",
11046 /* Translation stops when a conditional branch is encountered.
11047 * Otherwise the subsequent code could get translated several times.
11048 * Also stop translation when a page boundary is reached. This
11049 * ensures prefetch aborts occur at the right place.
11052 } while (!dc
->is_jmp
&& !tcg_op_buf_full() &&
11053 !cs
->singlestep_enabled
&&
11056 dc
->pc
< next_page_start
&&
11057 num_insns
< max_insns
);
11059 if (tb
->cflags
& CF_LAST_IO
) {
11063 if (unlikely(cs
->singlestep_enabled
|| dc
->ss_active
)
11064 && dc
->is_jmp
!= DISAS_EXC
) {
11065 /* Note that this means single stepping WFI doesn't halt the CPU.
11066 * For conditional branch insns this is harmless unreachable code as
11067 * gen_goto_tb() has already handled emitting the debug exception
11068 * (and thus a tb-jump is not possible when singlestepping).
11070 assert(dc
->is_jmp
!= DISAS_TB_JUMP
);
11071 if (dc
->is_jmp
!= DISAS_JUMP
) {
11072 gen_a64_set_pc_im(dc
->pc
);
11074 if (cs
->singlestep_enabled
) {
11075 gen_exception_internal(EXCP_DEBUG
);
11077 gen_step_complete_exception(dc
);
11080 switch (dc
->is_jmp
) {
11082 gen_goto_tb(dc
, 1, dc
->pc
);
11086 gen_a64_set_pc_im(dc
->pc
);
11089 /* indicate that the hash table must be used to find the next TB */
11090 tcg_gen_exit_tb(0);
11092 case DISAS_TB_JUMP
:
11097 gen_a64_set_pc_im(dc
->pc
);
11098 gen_helper_wfe(cpu_env
);
11101 /* This is a special case because we don't want to just halt the CPU
11102 * if trying to debug across a WFI.
11104 gen_a64_set_pc_im(dc
->pc
);
11105 gen_helper_wfi(cpu_env
);
11111 gen_tb_end(tb
, num_insns
);
11114 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
11115 qemu_log("----------------\n");
11116 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
11117 log_target_disas(env
, pc_start
, dc
->pc
- pc_start
,
11118 4 | (dc
->bswap_code
<< 1));
11123 j
= tcg_op_buf_count();
11126 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
11129 tb
->size
= dc
->pc
- pc_start
;
11130 tb
->icount
= num_insns
;