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 void aarch64_cpu_dump_state(CPUState
*cs
, FILE *f
,
127 fprintf_function cpu_fprintf
, int flags
)
129 ARMCPU
*cpu
= ARM_CPU(cs
);
130 CPUARMState
*env
= &cpu
->env
;
131 uint32_t psr
= pstate_read(env
);
134 cpu_fprintf(f
, "PC=%016"PRIx64
" SP=%016"PRIx64
"\n",
135 env
->pc
, env
->xregs
[31]);
136 for (i
= 0; i
< 31; i
++) {
137 cpu_fprintf(f
, "X%02d=%016"PRIx64
, i
, env
->xregs
[i
]);
139 cpu_fprintf(f
, "\n");
144 cpu_fprintf(f
, "PSTATE=%08x (flags %c%c%c%c)\n",
146 psr
& PSTATE_N
? 'N' : '-',
147 psr
& PSTATE_Z
? 'Z' : '-',
148 psr
& PSTATE_C
? 'C' : '-',
149 psr
& PSTATE_V
? 'V' : '-');
150 cpu_fprintf(f
, "\n");
152 if (flags
& CPU_DUMP_FPU
) {
154 for (i
= 0; i
< numvfpregs
; i
+= 2) {
155 uint64_t vlo
= float64_val(env
->vfp
.regs
[i
* 2]);
156 uint64_t vhi
= float64_val(env
->vfp
.regs
[(i
* 2) + 1]);
157 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
" ",
159 vlo
= float64_val(env
->vfp
.regs
[(i
+ 1) * 2]);
160 vhi
= float64_val(env
->vfp
.regs
[((i
+ 1) * 2) + 1]);
161 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
"\n",
164 cpu_fprintf(f
, "FPCR: %08x FPSR: %08x\n",
165 vfp_get_fpcr(env
), vfp_get_fpsr(env
));
169 void gen_a64_set_pc_im(uint64_t val
)
171 tcg_gen_movi_i64(cpu_pc
, val
);
174 static void gen_exception_internal(int excp
)
176 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
178 assert(excp_is_internal(excp
));
179 gen_helper_exception_internal(cpu_env
, tcg_excp
);
180 tcg_temp_free_i32(tcg_excp
);
183 static void gen_exception(int excp
, uint32_t syndrome
)
185 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
186 TCGv_i32 tcg_syn
= tcg_const_i32(syndrome
);
188 gen_helper_exception_with_syndrome(cpu_env
, tcg_excp
, tcg_syn
);
189 tcg_temp_free_i32(tcg_syn
);
190 tcg_temp_free_i32(tcg_excp
);
193 static void gen_exception_internal_insn(DisasContext
*s
, int offset
, int excp
)
195 gen_a64_set_pc_im(s
->pc
- offset
);
196 gen_exception_internal(excp
);
197 s
->is_jmp
= DISAS_EXC
;
200 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
,
203 gen_a64_set_pc_im(s
->pc
- offset
);
204 gen_exception(excp
, syndrome
);
205 s
->is_jmp
= DISAS_EXC
;
208 static void gen_ss_advance(DisasContext
*s
)
210 /* If the singlestep state is Active-not-pending, advance to
215 gen_helper_clear_pstate_ss(cpu_env
);
219 static void gen_step_complete_exception(DisasContext
*s
)
221 /* We just completed step of an insn. Move from Active-not-pending
222 * to Active-pending, and then also take the swstep exception.
223 * This corresponds to making the (IMPDEF) choice to prioritize
224 * swstep exceptions over asynchronous exceptions taken to an exception
225 * level where debug is disabled. This choice has the advantage that
226 * we do not need to maintain internal state corresponding to the
227 * ISV/EX syndrome bits between completion of the step and generation
228 * of the exception, and our syndrome information is always correct.
231 gen_exception(EXCP_UDEF
, syn_swstep(s
->ss_same_el
, 1, s
->is_ldex
));
232 s
->is_jmp
= DISAS_EXC
;
235 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
237 /* No direct tb linking with singlestep (either QEMU's or the ARM
238 * debug architecture kind) or deterministic io
240 if (s
->singlestep_enabled
|| s
->ss_active
|| (s
->tb
->cflags
& CF_LAST_IO
)) {
244 /* Only link tbs from inside the same guest page */
245 if ((s
->tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
252 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
254 TranslationBlock
*tb
;
257 if (use_goto_tb(s
, n
, dest
)) {
259 gen_a64_set_pc_im(dest
);
260 tcg_gen_exit_tb((intptr_t)tb
+ n
);
261 s
->is_jmp
= DISAS_TB_JUMP
;
263 gen_a64_set_pc_im(dest
);
265 gen_step_complete_exception(s
);
266 } else if (s
->singlestep_enabled
) {
267 gen_exception_internal(EXCP_DEBUG
);
270 s
->is_jmp
= DISAS_TB_JUMP
;
275 static void unallocated_encoding(DisasContext
*s
)
277 /* Unallocated and reserved encodings are uncategorized */
278 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized());
281 #define unsupported_encoding(s, insn) \
283 qemu_log_mask(LOG_UNIMP, \
284 "%s:%d: unsupported instruction encoding 0x%08x " \
285 "at pc=%016" PRIx64 "\n", \
286 __FILE__, __LINE__, insn, s->pc - 4); \
287 unallocated_encoding(s); \
290 static void init_tmp_a64_array(DisasContext
*s
)
292 #ifdef CONFIG_DEBUG_TCG
294 for (i
= 0; i
< ARRAY_SIZE(s
->tmp_a64
); i
++) {
295 TCGV_UNUSED_I64(s
->tmp_a64
[i
]);
298 s
->tmp_a64_count
= 0;
301 static void free_tmp_a64(DisasContext
*s
)
304 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
305 tcg_temp_free_i64(s
->tmp_a64
[i
]);
307 init_tmp_a64_array(s
);
310 static TCGv_i64
new_tmp_a64(DisasContext
*s
)
312 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
313 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
316 static TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
318 TCGv_i64 t
= new_tmp_a64(s
);
319 tcg_gen_movi_i64(t
, 0);
324 * Register access functions
326 * These functions are used for directly accessing a register in where
327 * changes to the final register value are likely to be made. If you
328 * need to use a register for temporary calculation (e.g. index type
329 * operations) use the read_* form.
331 * B1.2.1 Register mappings
333 * In instruction register encoding 31 can refer to ZR (zero register) or
334 * the SP (stack pointer) depending on context. In QEMU's case we map SP
335 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
336 * This is the point of the _sp forms.
338 static TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
341 return new_tmp_a64_zero(s
);
347 /* register access for when 31 == SP */
348 static TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
353 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
354 * representing the register contents. This TCGv is an auto-freed
355 * temporary so it need not be explicitly freed, and may be modified.
357 static TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
359 TCGv_i64 v
= new_tmp_a64(s
);
362 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
364 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
367 tcg_gen_movi_i64(v
, 0);
372 static TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
374 TCGv_i64 v
= new_tmp_a64(s
);
376 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
378 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
383 /* We should have at some point before trying to access an FP register
384 * done the necessary access check, so assert that
385 * (a) we did the check and
386 * (b) we didn't then just plough ahead anyway if it failed.
387 * Print the instruction pattern in the abort message so we can figure
388 * out what we need to fix if a user encounters this problem in the wild.
390 static inline void assert_fp_access_checked(DisasContext
*s
)
392 #ifdef CONFIG_DEBUG_TCG
393 if (unlikely(!s
->fp_access_checked
|| !s
->cpacr_fpen
)) {
394 fprintf(stderr
, "target-arm: FP access check missing for "
395 "instruction 0x%08x\n", s
->insn
);
401 /* Return the offset into CPUARMState of an element of specified
402 * size, 'element' places in from the least significant end of
403 * the FP/vector register Qn.
405 static inline int vec_reg_offset(DisasContext
*s
, int regno
,
406 int element
, TCGMemOp size
)
408 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
409 #ifdef HOST_WORDS_BIGENDIAN
410 /* This is complicated slightly because vfp.regs[2n] is
411 * still the low half and vfp.regs[2n+1] the high half
412 * of the 128 bit vector, even on big endian systems.
413 * Calculate the offset assuming a fully bigendian 128 bits,
414 * then XOR to account for the order of the two 64 bit halves.
416 offs
+= (16 - ((element
+ 1) * (1 << size
)));
419 offs
+= element
* (1 << size
);
421 assert_fp_access_checked(s
);
425 /* Return the offset into CPUARMState of a slice (from
426 * the least significant end) of FP register Qn (ie
428 * (Note that this is not the same mapping as for A32; see cpu.h)
430 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
432 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
433 #ifdef HOST_WORDS_BIGENDIAN
434 offs
+= (8 - (1 << size
));
436 assert_fp_access_checked(s
);
440 /* Offset of the high half of the 128 bit vector Qn */
441 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
443 assert_fp_access_checked(s
);
444 return offsetof(CPUARMState
, vfp
.regs
[regno
* 2 + 1]);
447 /* Convenience accessors for reading and writing single and double
448 * FP registers. Writing clears the upper parts of the associated
449 * 128 bit vector register, as required by the architecture.
450 * Note that unlike the GP register accessors, the values returned
451 * by the read functions must be manually freed.
453 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
455 TCGv_i64 v
= tcg_temp_new_i64();
457 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
461 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
463 TCGv_i32 v
= tcg_temp_new_i32();
465 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
469 static void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
471 TCGv_i64 tcg_zero
= tcg_const_i64(0);
473 tcg_gen_st_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
474 tcg_gen_st_i64(tcg_zero
, cpu_env
, fp_reg_hi_offset(s
, reg
));
475 tcg_temp_free_i64(tcg_zero
);
478 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
480 TCGv_i64 tmp
= tcg_temp_new_i64();
482 tcg_gen_extu_i32_i64(tmp
, v
);
483 write_fp_dreg(s
, reg
, tmp
);
484 tcg_temp_free_i64(tmp
);
487 static TCGv_ptr
get_fpstatus_ptr(void)
489 TCGv_ptr statusptr
= tcg_temp_new_ptr();
492 /* In A64 all instructions (both FP and Neon) use the FPCR;
493 * there is no equivalent of the A32 Neon "standard FPSCR value"
494 * and all operations use vfp.fp_status.
496 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
497 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
501 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
502 * than the 32 bit equivalent.
504 static inline void gen_set_NZ64(TCGv_i64 result
)
506 TCGv_i64 flag
= tcg_temp_new_i64();
508 tcg_gen_setcondi_i64(TCG_COND_NE
, flag
, result
, 0);
509 tcg_gen_trunc_i64_i32(cpu_ZF
, flag
);
510 tcg_gen_shri_i64(flag
, result
, 32);
511 tcg_gen_trunc_i64_i32(cpu_NF
, flag
);
512 tcg_temp_free_i64(flag
);
515 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
516 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
519 gen_set_NZ64(result
);
521 tcg_gen_trunc_i64_i32(cpu_ZF
, result
);
522 tcg_gen_trunc_i64_i32(cpu_NF
, result
);
524 tcg_gen_movi_i32(cpu_CF
, 0);
525 tcg_gen_movi_i32(cpu_VF
, 0);
528 /* dest = T0 + T1; compute C, N, V and Z flags */
529 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
532 TCGv_i64 result
, flag
, tmp
;
533 result
= tcg_temp_new_i64();
534 flag
= tcg_temp_new_i64();
535 tmp
= tcg_temp_new_i64();
537 tcg_gen_movi_i64(tmp
, 0);
538 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
540 tcg_gen_trunc_i64_i32(cpu_CF
, flag
);
542 gen_set_NZ64(result
);
544 tcg_gen_xor_i64(flag
, result
, t0
);
545 tcg_gen_xor_i64(tmp
, t0
, t1
);
546 tcg_gen_andc_i64(flag
, flag
, tmp
);
547 tcg_temp_free_i64(tmp
);
548 tcg_gen_shri_i64(flag
, flag
, 32);
549 tcg_gen_trunc_i64_i32(cpu_VF
, flag
);
551 tcg_gen_mov_i64(dest
, result
);
552 tcg_temp_free_i64(result
);
553 tcg_temp_free_i64(flag
);
555 /* 32 bit arithmetic */
556 TCGv_i32 t0_32
= tcg_temp_new_i32();
557 TCGv_i32 t1_32
= tcg_temp_new_i32();
558 TCGv_i32 tmp
= tcg_temp_new_i32();
560 tcg_gen_movi_i32(tmp
, 0);
561 tcg_gen_trunc_i64_i32(t0_32
, t0
);
562 tcg_gen_trunc_i64_i32(t1_32
, t1
);
563 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
564 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
565 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
566 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
567 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
568 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
570 tcg_temp_free_i32(tmp
);
571 tcg_temp_free_i32(t0_32
);
572 tcg_temp_free_i32(t1_32
);
576 /* dest = T0 - T1; compute C, N, V and Z flags */
577 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
580 /* 64 bit arithmetic */
581 TCGv_i64 result
, flag
, tmp
;
583 result
= tcg_temp_new_i64();
584 flag
= tcg_temp_new_i64();
585 tcg_gen_sub_i64(result
, t0
, t1
);
587 gen_set_NZ64(result
);
589 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
590 tcg_gen_trunc_i64_i32(cpu_CF
, flag
);
592 tcg_gen_xor_i64(flag
, result
, t0
);
593 tmp
= tcg_temp_new_i64();
594 tcg_gen_xor_i64(tmp
, t0
, t1
);
595 tcg_gen_and_i64(flag
, flag
, tmp
);
596 tcg_temp_free_i64(tmp
);
597 tcg_gen_shri_i64(flag
, flag
, 32);
598 tcg_gen_trunc_i64_i32(cpu_VF
, flag
);
599 tcg_gen_mov_i64(dest
, result
);
600 tcg_temp_free_i64(flag
);
601 tcg_temp_free_i64(result
);
603 /* 32 bit arithmetic */
604 TCGv_i32 t0_32
= tcg_temp_new_i32();
605 TCGv_i32 t1_32
= tcg_temp_new_i32();
608 tcg_gen_trunc_i64_i32(t0_32
, t0
);
609 tcg_gen_trunc_i64_i32(t1_32
, t1
);
610 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
611 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
612 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
613 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
614 tmp
= tcg_temp_new_i32();
615 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
616 tcg_temp_free_i32(t0_32
);
617 tcg_temp_free_i32(t1_32
);
618 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
619 tcg_temp_free_i32(tmp
);
620 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
624 /* dest = T0 + T1 + CF; do not compute flags. */
625 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
627 TCGv_i64 flag
= tcg_temp_new_i64();
628 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
629 tcg_gen_add_i64(dest
, t0
, t1
);
630 tcg_gen_add_i64(dest
, dest
, flag
);
631 tcg_temp_free_i64(flag
);
634 tcg_gen_ext32u_i64(dest
, dest
);
638 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
639 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
642 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
643 result
= tcg_temp_new_i64();
644 cf_64
= tcg_temp_new_i64();
645 vf_64
= tcg_temp_new_i64();
646 tmp
= tcg_const_i64(0);
648 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
649 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
650 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
651 tcg_gen_trunc_i64_i32(cpu_CF
, cf_64
);
652 gen_set_NZ64(result
);
654 tcg_gen_xor_i64(vf_64
, result
, t0
);
655 tcg_gen_xor_i64(tmp
, t0
, t1
);
656 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
657 tcg_gen_shri_i64(vf_64
, vf_64
, 32);
658 tcg_gen_trunc_i64_i32(cpu_VF
, vf_64
);
660 tcg_gen_mov_i64(dest
, result
);
662 tcg_temp_free_i64(tmp
);
663 tcg_temp_free_i64(vf_64
);
664 tcg_temp_free_i64(cf_64
);
665 tcg_temp_free_i64(result
);
667 TCGv_i32 t0_32
, t1_32
, tmp
;
668 t0_32
= tcg_temp_new_i32();
669 t1_32
= tcg_temp_new_i32();
670 tmp
= tcg_const_i32(0);
672 tcg_gen_trunc_i64_i32(t0_32
, t0
);
673 tcg_gen_trunc_i64_i32(t1_32
, t1
);
674 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
675 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
677 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
678 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
679 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
680 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
681 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
683 tcg_temp_free_i32(tmp
);
684 tcg_temp_free_i32(t1_32
);
685 tcg_temp_free_i32(t0_32
);
690 * Load/Store generators
694 * Store from GPR register to memory.
696 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
697 TCGv_i64 tcg_addr
, int size
, int memidx
)
700 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, MO_TE
+ size
);
703 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
704 TCGv_i64 tcg_addr
, int size
)
706 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
));
710 * Load from memory to GPR register
712 static void do_gpr_ld_memidx(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
713 int size
, bool is_signed
, bool extend
, int memidx
)
715 TCGMemOp memop
= MO_TE
+ size
;
723 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
725 if (extend
&& is_signed
) {
727 tcg_gen_ext32u_i64(dest
, dest
);
731 static void do_gpr_ld(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
732 int size
, bool is_signed
, bool extend
)
734 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
739 * Store from FP register to memory
741 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
743 /* This writes the bottom N bits of a 128 bit wide vector to memory */
744 TCGv_i64 tmp
= tcg_temp_new_i64();
745 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
747 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TE
+ size
);
749 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
750 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
751 tcg_gen_qemu_st64(tmp
, tcg_addr
, get_mem_index(s
));
752 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
753 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
754 tcg_gen_qemu_st_i64(tmp
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
755 tcg_temp_free_i64(tcg_hiaddr
);
758 tcg_temp_free_i64(tmp
);
762 * Load from memory to FP register
764 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
766 /* This always zero-extends and writes to a full 128 bit wide vector */
767 TCGv_i64 tmplo
= tcg_temp_new_i64();
771 TCGMemOp memop
= MO_TE
+ size
;
772 tmphi
= tcg_const_i64(0);
773 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
776 tmphi
= tcg_temp_new_i64();
777 tcg_hiaddr
= tcg_temp_new_i64();
779 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
780 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
781 tcg_gen_qemu_ld_i64(tmphi
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
782 tcg_temp_free_i64(tcg_hiaddr
);
785 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
786 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
788 tcg_temp_free_i64(tmplo
);
789 tcg_temp_free_i64(tmphi
);
793 * Vector load/store helpers.
795 * The principal difference between this and a FP load is that we don't
796 * zero extend as we are filling a partial chunk of the vector register.
797 * These functions don't support 128 bit loads/stores, which would be
798 * normal load/store operations.
800 * The _i32 versions are useful when operating on 32 bit quantities
801 * (eg for floating point single or using Neon helper functions).
804 /* Get value of an element within a vector register */
805 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
806 int element
, TCGMemOp memop
)
808 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
811 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
814 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
817 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
820 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
823 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
826 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
830 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
833 g_assert_not_reached();
837 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
838 int element
, TCGMemOp memop
)
840 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
843 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
846 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
849 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
852 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
856 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
859 g_assert_not_reached();
863 /* Set value of an element within a vector register */
864 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
865 int element
, TCGMemOp memop
)
867 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
870 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
873 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
876 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
879 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
882 g_assert_not_reached();
886 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
887 int destidx
, int element
, TCGMemOp memop
)
889 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
892 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
895 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
898 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
901 g_assert_not_reached();
905 /* Clear the high 64 bits of a 128 bit vector (in general non-quad
906 * vector ops all need to do this).
908 static void clear_vec_high(DisasContext
*s
, int rd
)
910 TCGv_i64 tcg_zero
= tcg_const_i64(0);
912 write_vec_element(s
, tcg_zero
, rd
, 1, MO_64
);
913 tcg_temp_free_i64(tcg_zero
);
916 /* Store from vector register to memory */
917 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
918 TCGv_i64 tcg_addr
, int size
)
920 TCGMemOp memop
= MO_TE
+ size
;
921 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
923 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
924 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
926 tcg_temp_free_i64(tcg_tmp
);
929 /* Load from memory to vector register */
930 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
931 TCGv_i64 tcg_addr
, int size
)
933 TCGMemOp memop
= MO_TE
+ size
;
934 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
936 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
937 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
939 tcg_temp_free_i64(tcg_tmp
);
942 /* Check that FP/Neon access is enabled. If it is, return
943 * true. If not, emit code to generate an appropriate exception,
944 * and return false; the caller should not emit any code for
945 * the instruction. Note that this check must happen after all
946 * unallocated-encoding checks (otherwise the syndrome information
947 * for the resulting exception will be incorrect).
949 static inline bool fp_access_check(DisasContext
*s
)
951 assert(!s
->fp_access_checked
);
952 s
->fp_access_checked
= true;
958 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false));
963 * This utility function is for doing register extension with an
964 * optional shift. You will likely want to pass a temporary for the
965 * destination register. See DecodeRegExtend() in the ARM ARM.
967 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
968 int option
, unsigned int shift
)
970 int extsize
= extract32(option
, 0, 2);
971 bool is_signed
= extract32(option
, 2, 1);
976 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
979 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
982 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
985 tcg_gen_mov_i64(tcg_out
, tcg_in
);
991 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
994 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
997 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
1000 tcg_gen_mov_i64(tcg_out
, tcg_in
);
1006 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
1010 static inline void gen_check_sp_alignment(DisasContext
*s
)
1012 /* The AArch64 architecture mandates that (if enabled via PSTATE
1013 * or SCTLR bits) there is a check that SP is 16-aligned on every
1014 * SP-relative load or store (with an exception generated if it is not).
1015 * In line with general QEMU practice regarding misaligned accesses,
1016 * we omit these checks for the sake of guest program performance.
1017 * This function is provided as a hook so we can more easily add these
1018 * checks in future (possibly as a "favour catching guest program bugs
1019 * over speed" user selectable option).
1024 * This provides a simple table based table lookup decoder. It is
1025 * intended to be used when the relevant bits for decode are too
1026 * awkwardly placed and switch/if based logic would be confusing and
1027 * deeply nested. Since it's a linear search through the table, tables
1028 * should be kept small.
1030 * It returns the first handler where insn & mask == pattern, or
1031 * NULL if there is no match.
1032 * The table is terminated by an empty mask (i.e. 0)
1034 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1037 const AArch64DecodeTable
*tptr
= table
;
1039 while (tptr
->mask
) {
1040 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1041 return tptr
->disas_fn
;
1049 * the instruction disassembly implemented here matches
1050 * the instruction encoding classifications in chapter 3 (C3)
1051 * of the ARM Architecture Reference Manual (DDI0487A_a)
1054 /* C3.2.7 Unconditional branch (immediate)
1056 * +----+-----------+-------------------------------------+
1057 * | op | 0 0 1 0 1 | imm26 |
1058 * +----+-----------+-------------------------------------+
1060 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1062 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1064 if (insn
& (1 << 31)) {
1065 /* C5.6.26 BL Branch with link */
1066 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1069 /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
1070 gen_goto_tb(s
, 0, addr
);
1073 /* C3.2.1 Compare & branch (immediate)
1074 * 31 30 25 24 23 5 4 0
1075 * +----+-------------+----+---------------------+--------+
1076 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1077 * +----+-------------+----+---------------------+--------+
1079 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1081 unsigned int sf
, op
, rt
;
1086 sf
= extract32(insn
, 31, 1);
1087 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1088 rt
= extract32(insn
, 0, 5);
1089 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1091 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1092 label_match
= gen_new_label();
1094 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1095 tcg_cmp
, 0, label_match
);
1097 gen_goto_tb(s
, 0, s
->pc
);
1098 gen_set_label(label_match
);
1099 gen_goto_tb(s
, 1, addr
);
1102 /* C3.2.5 Test & branch (immediate)
1103 * 31 30 25 24 23 19 18 5 4 0
1104 * +----+-------------+----+-------+-------------+------+
1105 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1106 * +----+-------------+----+-------+-------------+------+
1108 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1110 unsigned int bit_pos
, op
, rt
;
1115 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1116 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1117 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1118 rt
= extract32(insn
, 0, 5);
1120 tcg_cmp
= tcg_temp_new_i64();
1121 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1122 label_match
= gen_new_label();
1123 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1124 tcg_cmp
, 0, label_match
);
1125 tcg_temp_free_i64(tcg_cmp
);
1126 gen_goto_tb(s
, 0, s
->pc
);
1127 gen_set_label(label_match
);
1128 gen_goto_tb(s
, 1, addr
);
1131 /* C3.2.2 / C5.6.19 Conditional branch (immediate)
1132 * 31 25 24 23 5 4 3 0
1133 * +---------------+----+---------------------+----+------+
1134 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1135 * +---------------+----+---------------------+----+------+
1137 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1142 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1143 unallocated_encoding(s
);
1146 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1147 cond
= extract32(insn
, 0, 4);
1150 /* genuinely conditional branches */
1151 int label_match
= gen_new_label();
1152 arm_gen_test_cc(cond
, label_match
);
1153 gen_goto_tb(s
, 0, s
->pc
);
1154 gen_set_label(label_match
);
1155 gen_goto_tb(s
, 1, addr
);
1157 /* 0xe and 0xf are both "always" conditions */
1158 gen_goto_tb(s
, 0, addr
);
1163 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1164 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1166 unsigned int selector
= crm
<< 3 | op2
;
1169 unallocated_encoding(s
);
1177 s
->is_jmp
= DISAS_WFI
;
1181 s
->is_jmp
= DISAS_WFE
;
1185 /* we treat all as NOP at least for now */
1188 /* default specified as NOP equivalent */
1193 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1195 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1198 /* CLREX, DSB, DMB, ISB */
1199 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1200 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1203 unallocated_encoding(s
);
1214 /* We don't emulate caches so barriers are no-ops */
1217 unallocated_encoding(s
);
1222 /* C5.6.130 MSR (immediate) - move immediate to processor state field */
1223 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1224 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1226 int op
= op1
<< 3 | op2
;
1228 case 0x05: /* SPSel */
1229 if (s
->current_el
== 0) {
1230 unallocated_encoding(s
);
1234 case 0x1e: /* DAIFSet */
1235 case 0x1f: /* DAIFClear */
1237 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1238 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1239 gen_a64_set_pc_im(s
->pc
- 4);
1240 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1241 tcg_temp_free_i32(tcg_imm
);
1242 tcg_temp_free_i32(tcg_op
);
1243 s
->is_jmp
= DISAS_UPDATE
;
1247 unallocated_encoding(s
);
1252 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1254 TCGv_i32 tmp
= tcg_temp_new_i32();
1255 TCGv_i32 nzcv
= tcg_temp_new_i32();
1257 /* build bit 31, N */
1258 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1 << 31));
1259 /* build bit 30, Z */
1260 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1261 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1262 /* build bit 29, C */
1263 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1264 /* build bit 28, V */
1265 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1266 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1267 /* generate result */
1268 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1270 tcg_temp_free_i32(nzcv
);
1271 tcg_temp_free_i32(tmp
);
1274 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1277 TCGv_i32 nzcv
= tcg_temp_new_i32();
1279 /* take NZCV from R[t] */
1280 tcg_gen_trunc_i64_i32(nzcv
, tcg_rt
);
1283 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1 << 31));
1285 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1286 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1288 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1289 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1291 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1292 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1293 tcg_temp_free_i32(nzcv
);
1296 /* C5.6.129 MRS - move from system register
1297 * C5.6.131 MSR (register) - move to system register
1300 * These are all essentially the same insn in 'read' and 'write'
1301 * versions, with varying op0 fields.
1303 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1304 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1305 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1307 const ARMCPRegInfo
*ri
;
1310 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1311 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1312 crn
, crm
, op0
, op1
, op2
));
1315 /* Unknown register; this might be a guest error or a QEMU
1316 * unimplemented feature.
1318 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1319 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1320 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1321 unallocated_encoding(s
);
1325 /* Check access permissions */
1326 if (!cp_access_ok(s
->current_el
, ri
, isread
)) {
1327 unallocated_encoding(s
);
1332 /* Emit code to perform further access permissions checks at
1333 * runtime; this may result in an exception.
1339 gen_a64_set_pc_im(s
->pc
- 4);
1340 tmpptr
= tcg_const_ptr(ri
);
1341 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1342 tcg_syn
= tcg_const_i32(syndrome
);
1343 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
);
1344 tcg_temp_free_ptr(tmpptr
);
1345 tcg_temp_free_i32(tcg_syn
);
1348 /* Handle special cases first */
1349 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1353 tcg_rt
= cpu_reg(s
, rt
);
1355 gen_get_nzcv(tcg_rt
);
1357 gen_set_nzcv(tcg_rt
);
1360 case ARM_CP_CURRENTEL
:
1361 /* Reads as current EL value from pstate, which is
1362 * guaranteed to be constant by the tb flags.
1364 tcg_rt
= cpu_reg(s
, rt
);
1365 tcg_gen_movi_i64(tcg_rt
, s
->current_el
<< 2);
1368 /* Writes clear the aligned block of memory which rt points into. */
1369 tcg_rt
= cpu_reg(s
, rt
);
1370 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1376 if (use_icount
&& (ri
->type
& ARM_CP_IO
)) {
1380 tcg_rt
= cpu_reg(s
, rt
);
1383 if (ri
->type
& ARM_CP_CONST
) {
1384 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1385 } else if (ri
->readfn
) {
1387 tmpptr
= tcg_const_ptr(ri
);
1388 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1389 tcg_temp_free_ptr(tmpptr
);
1391 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1394 if (ri
->type
& ARM_CP_CONST
) {
1395 /* If not forbidden by access permissions, treat as WI */
1397 } else if (ri
->writefn
) {
1399 tmpptr
= tcg_const_ptr(ri
);
1400 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1401 tcg_temp_free_ptr(tmpptr
);
1403 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1407 if (use_icount
&& (ri
->type
& ARM_CP_IO
)) {
1408 /* I/O operations must end the TB here (whether read or write) */
1410 s
->is_jmp
= DISAS_UPDATE
;
1411 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1412 /* We default to ending the TB on a coprocessor register write,
1413 * but allow this to be suppressed by the register definition
1414 * (usually only necessary to work around guest bugs).
1416 s
->is_jmp
= DISAS_UPDATE
;
1421 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1422 * +---------------------+---+-----+-----+-------+-------+-----+------+
1423 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1424 * +---------------------+---+-----+-----+-------+-------+-----+------+
1426 static void disas_system(DisasContext
*s
, uint32_t insn
)
1428 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1429 l
= extract32(insn
, 21, 1);
1430 op0
= extract32(insn
, 19, 2);
1431 op1
= extract32(insn
, 16, 3);
1432 crn
= extract32(insn
, 12, 4);
1433 crm
= extract32(insn
, 8, 4);
1434 op2
= extract32(insn
, 5, 3);
1435 rt
= extract32(insn
, 0, 5);
1438 if (l
|| rt
!= 31) {
1439 unallocated_encoding(s
);
1443 case 2: /* C5.6.68 HINT */
1444 handle_hint(s
, insn
, op1
, op2
, crm
);
1446 case 3: /* CLREX, DSB, DMB, ISB */
1447 handle_sync(s
, insn
, op1
, op2
, crm
);
1449 case 4: /* C5.6.130 MSR (immediate) */
1450 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1453 unallocated_encoding(s
);
1458 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1461 /* C3.2.3 Exception generation
1463 * 31 24 23 21 20 5 4 2 1 0
1464 * +-----------------+-----+------------------------+-----+----+
1465 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1466 * +-----------------------+------------------------+----------+
1468 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1470 int opc
= extract32(insn
, 21, 3);
1471 int op2_ll
= extract32(insn
, 0, 5);
1472 int imm16
= extract32(insn
, 5, 16);
1477 /* For SVC, HVC and SMC we advance the single-step state
1478 * machine before taking the exception. This is architecturally
1479 * mandated, to ensure that single-stepping a system call
1480 * instruction works properly.
1485 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
));
1488 if (s
->current_el
== 0) {
1489 unallocated_encoding(s
);
1492 /* The pre HVC helper handles cases when HVC gets trapped
1493 * as an undefined insn by runtime configuration.
1495 gen_a64_set_pc_im(s
->pc
- 4);
1496 gen_helper_pre_hvc(cpu_env
);
1498 gen_exception_insn(s
, 0, EXCP_HVC
, syn_aa64_hvc(imm16
));
1501 if (s
->current_el
== 0) {
1502 unallocated_encoding(s
);
1505 gen_a64_set_pc_im(s
->pc
- 4);
1506 tmp
= tcg_const_i32(syn_aa64_smc(imm16
));
1507 gen_helper_pre_smc(cpu_env
, tmp
);
1508 tcg_temp_free_i32(tmp
);
1510 gen_exception_insn(s
, 0, EXCP_SMC
, syn_aa64_smc(imm16
));
1513 unallocated_encoding(s
);
1519 unallocated_encoding(s
);
1523 gen_exception_insn(s
, 4, EXCP_BKPT
, syn_aa64_bkpt(imm16
));
1527 unallocated_encoding(s
);
1531 unsupported_encoding(s
, insn
);
1534 if (op2_ll
< 1 || op2_ll
> 3) {
1535 unallocated_encoding(s
);
1538 /* DCPS1, DCPS2, DCPS3 */
1539 unsupported_encoding(s
, insn
);
1542 unallocated_encoding(s
);
1547 /* C3.2.7 Unconditional branch (register)
1548 * 31 25 24 21 20 16 15 10 9 5 4 0
1549 * +---------------+-------+-------+-------+------+-------+
1550 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1551 * +---------------+-------+-------+-------+------+-------+
1553 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1555 unsigned int opc
, op2
, op3
, rn
, op4
;
1557 opc
= extract32(insn
, 21, 4);
1558 op2
= extract32(insn
, 16, 5);
1559 op3
= extract32(insn
, 10, 6);
1560 rn
= extract32(insn
, 5, 5);
1561 op4
= extract32(insn
, 0, 5);
1563 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1564 unallocated_encoding(s
);
1571 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1574 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1575 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1578 if (s
->current_el
== 0) {
1579 unallocated_encoding(s
);
1582 gen_helper_exception_return(cpu_env
);
1583 s
->is_jmp
= DISAS_JUMP
;
1587 unallocated_encoding(s
);
1589 unsupported_encoding(s
, insn
);
1593 unallocated_encoding(s
);
1597 s
->is_jmp
= DISAS_JUMP
;
1600 /* C3.2 Branches, exception generating and system instructions */
1601 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1603 switch (extract32(insn
, 25, 7)) {
1604 case 0x0a: case 0x0b:
1605 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1606 disas_uncond_b_imm(s
, insn
);
1608 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1609 disas_comp_b_imm(s
, insn
);
1611 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1612 disas_test_b_imm(s
, insn
);
1614 case 0x2a: /* Conditional branch (immediate) */
1615 disas_cond_b_imm(s
, insn
);
1617 case 0x6a: /* Exception generation / System */
1618 if (insn
& (1 << 24)) {
1619 disas_system(s
, insn
);
1624 case 0x6b: /* Unconditional branch (register) */
1625 disas_uncond_b_reg(s
, insn
);
1628 unallocated_encoding(s
);
1634 * Load/Store exclusive instructions are implemented by remembering
1635 * the value/address loaded, and seeing if these are the same
1636 * when the store is performed. This is not actually the architecturally
1637 * mandated semantics, but it works for typical guest code sequences
1638 * and avoids having to monitor regular stores.
1640 * In system emulation mode only one CPU will be running at once, so
1641 * this sequence is effectively atomic. In user emulation mode we
1642 * throw an exception and handle the atomic operation elsewhere.
1644 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
1645 TCGv_i64 addr
, int size
, bool is_pair
)
1647 TCGv_i64 tmp
= tcg_temp_new_i64();
1648 TCGMemOp memop
= MO_TE
+ size
;
1650 g_assert(size
<= 3);
1651 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), memop
);
1654 TCGv_i64 addr2
= tcg_temp_new_i64();
1655 TCGv_i64 hitmp
= tcg_temp_new_i64();
1657 g_assert(size
>= 2);
1658 tcg_gen_addi_i64(addr2
, addr
, 1 << size
);
1659 tcg_gen_qemu_ld_i64(hitmp
, addr2
, get_mem_index(s
), memop
);
1660 tcg_temp_free_i64(addr2
);
1661 tcg_gen_mov_i64(cpu_exclusive_high
, hitmp
);
1662 tcg_gen_mov_i64(cpu_reg(s
, rt2
), hitmp
);
1663 tcg_temp_free_i64(hitmp
);
1666 tcg_gen_mov_i64(cpu_exclusive_val
, tmp
);
1667 tcg_gen_mov_i64(cpu_reg(s
, rt
), tmp
);
1669 tcg_temp_free_i64(tmp
);
1670 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
1673 #ifdef CONFIG_USER_ONLY
1674 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1675 TCGv_i64 addr
, int size
, int is_pair
)
1677 tcg_gen_mov_i64(cpu_exclusive_test
, addr
);
1678 tcg_gen_movi_i32(cpu_exclusive_info
,
1679 size
| is_pair
<< 2 | (rd
<< 4) | (rt
<< 9) | (rt2
<< 14));
1680 gen_exception_internal_insn(s
, 4, EXCP_STREX
);
1683 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1684 TCGv_i64 inaddr
, int size
, int is_pair
)
1686 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1687 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1690 * [addr + datasize] = {Rt2};
1696 * env->exclusive_addr = -1;
1698 int fail_label
= gen_new_label();
1699 int done_label
= gen_new_label();
1700 TCGv_i64 addr
= tcg_temp_local_new_i64();
1703 /* Copy input into a local temp so it is not trashed when the
1704 * basic block ends at the branch insn.
1706 tcg_gen_mov_i64(addr
, inaddr
);
1707 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
1709 tmp
= tcg_temp_new_i64();
1710 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), MO_TE
+ size
);
1711 tcg_gen_brcond_i64(TCG_COND_NE
, tmp
, cpu_exclusive_val
, fail_label
);
1712 tcg_temp_free_i64(tmp
);
1715 TCGv_i64 addrhi
= tcg_temp_new_i64();
1716 TCGv_i64 tmphi
= tcg_temp_new_i64();
1718 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1719 tcg_gen_qemu_ld_i64(tmphi
, addrhi
, get_mem_index(s
), MO_TE
+ size
);
1720 tcg_gen_brcond_i64(TCG_COND_NE
, tmphi
, cpu_exclusive_high
, fail_label
);
1722 tcg_temp_free_i64(tmphi
);
1723 tcg_temp_free_i64(addrhi
);
1726 /* We seem to still have the exclusive monitor, so do the store */
1727 tcg_gen_qemu_st_i64(cpu_reg(s
, rt
), addr
, get_mem_index(s
), MO_TE
+ size
);
1729 TCGv_i64 addrhi
= tcg_temp_new_i64();
1731 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1732 tcg_gen_qemu_st_i64(cpu_reg(s
, rt2
), addrhi
,
1733 get_mem_index(s
), MO_TE
+ size
);
1734 tcg_temp_free_i64(addrhi
);
1737 tcg_temp_free_i64(addr
);
1739 tcg_gen_movi_i64(cpu_reg(s
, rd
), 0);
1740 tcg_gen_br(done_label
);
1741 gen_set_label(fail_label
);
1742 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
1743 gen_set_label(done_label
);
1744 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1749 /* C3.3.6 Load/store exclusive
1751 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
1752 * +-----+-------------+----+---+----+------+----+-------+------+------+
1753 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
1754 * +-----+-------------+----+---+----+------+----+-------+------+------+
1756 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
1757 * L: 0 -> store, 1 -> load
1758 * o2: 0 -> exclusive, 1 -> not
1759 * o1: 0 -> single register, 1 -> register pair
1760 * o0: 1 -> load-acquire/store-release, 0 -> not
1762 * o0 == 0 AND o2 == 1 is un-allocated
1763 * o1 == 1 is un-allocated except for 32 and 64 bit sizes
1765 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
1767 int rt
= extract32(insn
, 0, 5);
1768 int rn
= extract32(insn
, 5, 5);
1769 int rt2
= extract32(insn
, 10, 5);
1770 int is_lasr
= extract32(insn
, 15, 1);
1771 int rs
= extract32(insn
, 16, 5);
1772 int is_pair
= extract32(insn
, 21, 1);
1773 int is_store
= !extract32(insn
, 22, 1);
1774 int is_excl
= !extract32(insn
, 23, 1);
1775 int size
= extract32(insn
, 30, 2);
1778 if ((!is_excl
&& !is_lasr
) ||
1779 (is_pair
&& size
< 2)) {
1780 unallocated_encoding(s
);
1785 gen_check_sp_alignment(s
);
1787 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1789 /* Note that since TCG is single threaded load-acquire/store-release
1790 * semantics require no extra if (is_lasr) { ... } handling.
1796 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1798 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1801 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1803 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1805 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, false, false);
1808 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt
);
1809 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
1811 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
1813 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, false, false);
1820 * C3.3.5 Load register (literal)
1822 * 31 30 29 27 26 25 24 23 5 4 0
1823 * +-----+-------+---+-----+-------------------+-------+
1824 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
1825 * +-----+-------+---+-----+-------------------+-------+
1827 * V: 1 -> vector (simd/fp)
1828 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
1829 * 10-> 32 bit signed, 11 -> prefetch
1830 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
1832 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
1834 int rt
= extract32(insn
, 0, 5);
1835 int64_t imm
= sextract32(insn
, 5, 19) << 2;
1836 bool is_vector
= extract32(insn
, 26, 1);
1837 int opc
= extract32(insn
, 30, 2);
1838 bool is_signed
= false;
1840 TCGv_i64 tcg_rt
, tcg_addr
;
1844 unallocated_encoding(s
);
1848 if (!fp_access_check(s
)) {
1853 /* PRFM (literal) : prefetch */
1856 size
= 2 + extract32(opc
, 0, 1);
1857 is_signed
= extract32(opc
, 1, 1);
1860 tcg_rt
= cpu_reg(s
, rt
);
1862 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
1864 do_fp_ld(s
, rt
, tcg_addr
, size
);
1866 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
1868 tcg_temp_free_i64(tcg_addr
);
1872 * C5.6.80 LDNP (Load Pair - non-temporal hint)
1873 * C5.6.81 LDP (Load Pair - non vector)
1874 * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
1875 * C5.6.176 STNP (Store Pair - non-temporal hint)
1876 * C5.6.177 STP (Store Pair - non vector)
1877 * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
1878 * C6.3.165 LDP (Load Pair of SIMD&FP)
1879 * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
1880 * C6.3.284 STP (Store Pair of SIMD&FP)
1882 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
1883 * +-----+-------+---+---+-------+---+-----------------------------+
1884 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
1885 * +-----+-------+---+---+-------+---+-------+-------+------+------+
1887 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
1889 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
1890 * V: 0 -> GPR, 1 -> Vector
1891 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
1892 * 10 -> signed offset, 11 -> pre-index
1893 * L: 0 -> Store 1 -> Load
1895 * Rt, Rt2 = GPR or SIMD registers to be stored
1896 * Rn = general purpose register containing address
1897 * imm7 = signed offset (multiple of 4 or 8 depending on size)
1899 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
1901 int rt
= extract32(insn
, 0, 5);
1902 int rn
= extract32(insn
, 5, 5);
1903 int rt2
= extract32(insn
, 10, 5);
1904 int64_t offset
= sextract32(insn
, 15, 7);
1905 int index
= extract32(insn
, 23, 2);
1906 bool is_vector
= extract32(insn
, 26, 1);
1907 bool is_load
= extract32(insn
, 22, 1);
1908 int opc
= extract32(insn
, 30, 2);
1910 bool is_signed
= false;
1911 bool postindex
= false;
1914 TCGv_i64 tcg_addr
; /* calculated address */
1918 unallocated_encoding(s
);
1925 size
= 2 + extract32(opc
, 1, 1);
1926 is_signed
= extract32(opc
, 0, 1);
1927 if (!is_load
&& is_signed
) {
1928 unallocated_encoding(s
);
1934 case 1: /* post-index */
1939 /* signed offset with "non-temporal" hint. Since we don't emulate
1940 * caches we don't care about hints to the cache system about
1941 * data access patterns, and handle this identically to plain
1945 /* There is no non-temporal-hint version of LDPSW */
1946 unallocated_encoding(s
);
1951 case 2: /* signed offset, rn not updated */
1954 case 3: /* pre-index */
1960 if (is_vector
&& !fp_access_check(s
)) {
1967 gen_check_sp_alignment(s
);
1970 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1973 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
1978 do_fp_ld(s
, rt
, tcg_addr
, size
);
1980 do_fp_st(s
, rt
, tcg_addr
, size
);
1983 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1985 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
1987 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1990 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
1993 do_fp_ld(s
, rt2
, tcg_addr
, size
);
1995 do_fp_st(s
, rt2
, tcg_addr
, size
);
1998 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
2000 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false);
2002 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
2008 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
2010 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
2012 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
2017 * C3.3.8 Load/store (immediate post-indexed)
2018 * C3.3.9 Load/store (immediate pre-indexed)
2019 * C3.3.12 Load/store (unscaled immediate)
2021 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
2022 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2023 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
2024 * +----+-------+---+-----+-----+---+--------+-----+------+------+
2026 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
2028 * V = 0 -> non-vector
2029 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
2030 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2032 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
)
2034 int rt
= extract32(insn
, 0, 5);
2035 int rn
= extract32(insn
, 5, 5);
2036 int imm9
= sextract32(insn
, 12, 9);
2037 int opc
= extract32(insn
, 22, 2);
2038 int size
= extract32(insn
, 30, 2);
2039 int idx
= extract32(insn
, 10, 2);
2040 bool is_signed
= false;
2041 bool is_store
= false;
2042 bool is_extended
= false;
2043 bool is_unpriv
= (idx
== 2);
2044 bool is_vector
= extract32(insn
, 26, 1);
2051 size
|= (opc
& 2) << 1;
2052 if (size
> 4 || is_unpriv
) {
2053 unallocated_encoding(s
);
2056 is_store
= ((opc
& 1) == 0);
2057 if (!fp_access_check(s
)) {
2061 if (size
== 3 && opc
== 2) {
2062 /* PRFM - prefetch */
2064 unallocated_encoding(s
);
2069 if (opc
== 3 && size
> 1) {
2070 unallocated_encoding(s
);
2073 is_store
= (opc
== 0);
2074 is_signed
= opc
& (1<<1);
2075 is_extended
= (size
< 3) && (opc
& 1);
2095 gen_check_sp_alignment(s
);
2097 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2100 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2105 do_fp_st(s
, rt
, tcg_addr
, size
);
2107 do_fp_ld(s
, rt
, tcg_addr
, size
);
2110 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2111 int memidx
= is_unpriv
? 1 : get_mem_index(s
);
2114 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
);
2116 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
2117 is_signed
, is_extended
, memidx
);
2122 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2124 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2126 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2131 * C3.3.10 Load/store (register offset)
2133 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2134 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2135 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2136 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2139 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2140 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2142 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2143 * opc<0>: 0 -> store, 1 -> load
2144 * V: 1 -> vector/simd
2145 * opt: extend encoding (see DecodeRegExtend)
2146 * S: if S=1 then scale (essentially index by sizeof(size))
2147 * Rt: register to transfer into/out of
2148 * Rn: address register or SP for base
2149 * Rm: offset register or ZR for offset
2151 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
)
2153 int rt
= extract32(insn
, 0, 5);
2154 int rn
= extract32(insn
, 5, 5);
2155 int shift
= extract32(insn
, 12, 1);
2156 int rm
= extract32(insn
, 16, 5);
2157 int opc
= extract32(insn
, 22, 2);
2158 int opt
= extract32(insn
, 13, 3);
2159 int size
= extract32(insn
, 30, 2);
2160 bool is_signed
= false;
2161 bool is_store
= false;
2162 bool is_extended
= false;
2163 bool is_vector
= extract32(insn
, 26, 1);
2168 if (extract32(opt
, 1, 1) == 0) {
2169 unallocated_encoding(s
);
2174 size
|= (opc
& 2) << 1;
2176 unallocated_encoding(s
);
2179 is_store
= !extract32(opc
, 0, 1);
2180 if (!fp_access_check(s
)) {
2184 if (size
== 3 && opc
== 2) {
2185 /* PRFM - prefetch */
2188 if (opc
== 3 && size
> 1) {
2189 unallocated_encoding(s
);
2192 is_store
= (opc
== 0);
2193 is_signed
= extract32(opc
, 1, 1);
2194 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2198 gen_check_sp_alignment(s
);
2200 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2202 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2203 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2205 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2209 do_fp_st(s
, rt
, tcg_addr
, size
);
2211 do_fp_ld(s
, rt
, tcg_addr
, size
);
2214 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2216 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2218 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2224 * C3.3.13 Load/store (unsigned immediate)
2226 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2227 * +----+-------+---+-----+-----+------------+-------+------+
2228 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2229 * +----+-------+---+-----+-----+------------+-------+------+
2232 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2233 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2235 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2236 * opc<0>: 0 -> store, 1 -> load
2237 * Rn: base address register (inc SP)
2238 * Rt: target register
2240 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
)
2242 int rt
= extract32(insn
, 0, 5);
2243 int rn
= extract32(insn
, 5, 5);
2244 unsigned int imm12
= extract32(insn
, 10, 12);
2245 bool is_vector
= extract32(insn
, 26, 1);
2246 int size
= extract32(insn
, 30, 2);
2247 int opc
= extract32(insn
, 22, 2);
2248 unsigned int offset
;
2253 bool is_signed
= false;
2254 bool is_extended
= false;
2257 size
|= (opc
& 2) << 1;
2259 unallocated_encoding(s
);
2262 is_store
= !extract32(opc
, 0, 1);
2263 if (!fp_access_check(s
)) {
2267 if (size
== 3 && opc
== 2) {
2268 /* PRFM - prefetch */
2271 if (opc
== 3 && size
> 1) {
2272 unallocated_encoding(s
);
2275 is_store
= (opc
== 0);
2276 is_signed
= extract32(opc
, 1, 1);
2277 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2281 gen_check_sp_alignment(s
);
2283 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2284 offset
= imm12
<< size
;
2285 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2289 do_fp_st(s
, rt
, tcg_addr
, size
);
2291 do_fp_ld(s
, rt
, tcg_addr
, size
);
2294 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2296 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2298 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2303 /* Load/store register (all forms) */
2304 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2306 switch (extract32(insn
, 24, 2)) {
2308 if (extract32(insn
, 21, 1) == 1 && extract32(insn
, 10, 2) == 2) {
2309 disas_ldst_reg_roffset(s
, insn
);
2311 /* Load/store register (unscaled immediate)
2312 * Load/store immediate pre/post-indexed
2313 * Load/store register unprivileged
2315 disas_ldst_reg_imm9(s
, insn
);
2319 disas_ldst_reg_unsigned_imm(s
, insn
);
2322 unallocated_encoding(s
);
2327 /* C3.3.1 AdvSIMD load/store multiple structures
2329 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2330 * +---+---+---------------+---+-------------+--------+------+------+------+
2331 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2332 * +---+---+---------------+---+-------------+--------+------+------+------+
2334 * C3.3.2 AdvSIMD load/store multiple structures (post-indexed)
2336 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2337 * +---+---+---------------+---+---+---------+--------+------+------+------+
2338 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2339 * +---+---+---------------+---+---+---------+--------+------+------+------+
2341 * Rt: first (or only) SIMD&FP register to be transferred
2342 * Rn: base address or SP
2343 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2345 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
2347 int rt
= extract32(insn
, 0, 5);
2348 int rn
= extract32(insn
, 5, 5);
2349 int size
= extract32(insn
, 10, 2);
2350 int opcode
= extract32(insn
, 12, 4);
2351 bool is_store
= !extract32(insn
, 22, 1);
2352 bool is_postidx
= extract32(insn
, 23, 1);
2353 bool is_q
= extract32(insn
, 30, 1);
2354 TCGv_i64 tcg_addr
, tcg_rn
;
2356 int ebytes
= 1 << size
;
2357 int elements
= (is_q
? 128 : 64) / (8 << size
);
2358 int rpt
; /* num iterations */
2359 int selem
; /* structure elements */
2362 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
2363 unallocated_encoding(s
);
2367 /* From the shared decode logic */
2398 unallocated_encoding(s
);
2402 if (size
== 3 && !is_q
&& selem
!= 1) {
2404 unallocated_encoding(s
);
2408 if (!fp_access_check(s
)) {
2413 gen_check_sp_alignment(s
);
2416 tcg_rn
= cpu_reg_sp(s
, rn
);
2417 tcg_addr
= tcg_temp_new_i64();
2418 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2420 for (r
= 0; r
< rpt
; r
++) {
2422 for (e
= 0; e
< elements
; e
++) {
2423 int tt
= (rt
+ r
) % 32;
2425 for (xs
= 0; xs
< selem
; xs
++) {
2427 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
2429 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
2431 /* For non-quad operations, setting a slice of the low
2432 * 64 bits of the register clears the high 64 bits (in
2433 * the ARM ARM pseudocode this is implicit in the fact
2434 * that 'rval' is a 64 bit wide variable). We optimize
2435 * by noticing that we only need to do this the first
2436 * time we touch a register.
2438 if (!is_q
&& e
== 0 && (r
== 0 || xs
== selem
- 1)) {
2439 clear_vec_high(s
, tt
);
2442 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2449 int rm
= extract32(insn
, 16, 5);
2451 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2453 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2456 tcg_temp_free_i64(tcg_addr
);
2459 /* C3.3.3 AdvSIMD load/store single structure
2461 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2462 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2463 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
2464 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2466 * C3.3.4 AdvSIMD load/store single structure (post-indexed)
2468 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2469 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2470 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
2471 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2473 * Rt: first (or only) SIMD&FP register to be transferred
2474 * Rn: base address or SP
2475 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2476 * index = encoded in Q:S:size dependent on size
2478 * lane_size = encoded in R, opc
2479 * transfer width = encoded in opc, S, size
2481 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
2483 int rt
= extract32(insn
, 0, 5);
2484 int rn
= extract32(insn
, 5, 5);
2485 int size
= extract32(insn
, 10, 2);
2486 int S
= extract32(insn
, 12, 1);
2487 int opc
= extract32(insn
, 13, 3);
2488 int R
= extract32(insn
, 21, 1);
2489 int is_load
= extract32(insn
, 22, 1);
2490 int is_postidx
= extract32(insn
, 23, 1);
2491 int is_q
= extract32(insn
, 30, 1);
2493 int scale
= extract32(opc
, 1, 2);
2494 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
2495 bool replicate
= false;
2496 int index
= is_q
<< 3 | S
<< 2 | size
;
2498 TCGv_i64 tcg_addr
, tcg_rn
;
2502 if (!is_load
|| S
) {
2503 unallocated_encoding(s
);
2512 if (extract32(size
, 0, 1)) {
2513 unallocated_encoding(s
);
2519 if (extract32(size
, 1, 1)) {
2520 unallocated_encoding(s
);
2523 if (!extract32(size
, 0, 1)) {
2527 unallocated_encoding(s
);
2535 g_assert_not_reached();
2538 if (!fp_access_check(s
)) {
2542 ebytes
= 1 << scale
;
2545 gen_check_sp_alignment(s
);
2548 tcg_rn
= cpu_reg_sp(s
, rn
);
2549 tcg_addr
= tcg_temp_new_i64();
2550 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2552 for (xs
= 0; xs
< selem
; xs
++) {
2554 /* Load and replicate to all elements */
2556 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
2558 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
2559 get_mem_index(s
), MO_TE
+ scale
);
2562 mulconst
= 0x0101010101010101ULL
;
2565 mulconst
= 0x0001000100010001ULL
;
2568 mulconst
= 0x0000000100000001ULL
;
2574 g_assert_not_reached();
2577 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
2579 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
2581 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
2583 clear_vec_high(s
, rt
);
2585 tcg_temp_free_i64(tcg_tmp
);
2587 /* Load/store one element per register */
2589 do_vec_ld(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2591 do_vec_st(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2594 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2599 int rm
= extract32(insn
, 16, 5);
2601 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2603 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2606 tcg_temp_free_i64(tcg_addr
);
2609 /* C3.3 Loads and stores */
2610 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
2612 switch (extract32(insn
, 24, 6)) {
2613 case 0x08: /* Load/store exclusive */
2614 disas_ldst_excl(s
, insn
);
2616 case 0x18: case 0x1c: /* Load register (literal) */
2617 disas_ld_lit(s
, insn
);
2619 case 0x28: case 0x29:
2620 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
2621 disas_ldst_pair(s
, insn
);
2623 case 0x38: case 0x39:
2624 case 0x3c: case 0x3d: /* Load/store register (all forms) */
2625 disas_ldst_reg(s
, insn
);
2627 case 0x0c: /* AdvSIMD load/store multiple structures */
2628 disas_ldst_multiple_struct(s
, insn
);
2630 case 0x0d: /* AdvSIMD load/store single structure */
2631 disas_ldst_single_struct(s
, insn
);
2634 unallocated_encoding(s
);
2639 /* C3.4.6 PC-rel. addressing
2640 * 31 30 29 28 24 23 5 4 0
2641 * +----+-------+-----------+-------------------+------+
2642 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
2643 * +----+-------+-----------+-------------------+------+
2645 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
2647 unsigned int page
, rd
;
2651 page
= extract32(insn
, 31, 1);
2652 /* SignExtend(immhi:immlo) -> offset */
2653 offset
= ((int64_t)sextract32(insn
, 5, 19) << 2) | extract32(insn
, 29, 2);
2654 rd
= extract32(insn
, 0, 5);
2658 /* ADRP (page based) */
2663 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
2667 * C3.4.1 Add/subtract (immediate)
2669 * 31 30 29 28 24 23 22 21 10 9 5 4 0
2670 * +--+--+--+-----------+-----+-------------+-----+-----+
2671 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
2672 * +--+--+--+-----------+-----+-------------+-----+-----+
2674 * sf: 0 -> 32bit, 1 -> 64bit
2675 * op: 0 -> add , 1 -> sub
2677 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
2679 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
2681 int rd
= extract32(insn
, 0, 5);
2682 int rn
= extract32(insn
, 5, 5);
2683 uint64_t imm
= extract32(insn
, 10, 12);
2684 int shift
= extract32(insn
, 22, 2);
2685 bool setflags
= extract32(insn
, 29, 1);
2686 bool sub_op
= extract32(insn
, 30, 1);
2687 bool is_64bit
= extract32(insn
, 31, 1);
2689 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2690 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
2691 TCGv_i64 tcg_result
;
2700 unallocated_encoding(s
);
2704 tcg_result
= tcg_temp_new_i64();
2707 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
2709 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
2712 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
2714 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2716 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2718 tcg_temp_free_i64(tcg_imm
);
2722 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
2724 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
2727 tcg_temp_free_i64(tcg_result
);
2730 /* The input should be a value in the bottom e bits (with higher
2731 * bits zero); returns that value replicated into every element
2732 * of size e in a 64 bit integer.
2734 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
2744 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
2745 static inline uint64_t bitmask64(unsigned int length
)
2747 assert(length
> 0 && length
<= 64);
2748 return ~0ULL >> (64 - length
);
2751 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
2752 * only require the wmask. Returns false if the imms/immr/immn are a reserved
2753 * value (ie should cause a guest UNDEF exception), and true if they are
2754 * valid, in which case the decoded bit pattern is written to result.
2756 static bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
2757 unsigned int imms
, unsigned int immr
)
2760 unsigned e
, levels
, s
, r
;
2763 assert(immn
< 2 && imms
< 64 && immr
< 64);
2765 /* The bit patterns we create here are 64 bit patterns which
2766 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
2767 * 64 bits each. Each element contains the same value: a run
2768 * of between 1 and e-1 non-zero bits, rotated within the
2769 * element by between 0 and e-1 bits.
2771 * The element size and run length are encoded into immn (1 bit)
2772 * and imms (6 bits) as follows:
2773 * 64 bit elements: immn = 1, imms = <length of run - 1>
2774 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
2775 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
2776 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
2777 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
2778 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
2779 * Notice that immn = 0, imms = 11111x is the only combination
2780 * not covered by one of the above options; this is reserved.
2781 * Further, <length of run - 1> all-ones is a reserved pattern.
2783 * In all cases the rotation is by immr % e (and immr is 6 bits).
2786 /* First determine the element size */
2787 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
2789 /* This is the immn == 0, imms == 0x11111x case */
2799 /* <length of run - 1> mustn't be all-ones. */
2803 /* Create the value of one element: s+1 set bits rotated
2804 * by r within the element (which is e bits wide)...
2806 mask
= bitmask64(s
+ 1);
2807 mask
= (mask
>> r
) | (mask
<< (e
- r
));
2808 /* ...then replicate the element over the whole 64 bit value */
2809 mask
= bitfield_replicate(mask
, e
);
2814 /* C3.4.4 Logical (immediate)
2815 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2816 * +----+-----+-------------+---+------+------+------+------+
2817 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
2818 * +----+-----+-------------+---+------+------+------+------+
2820 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
2822 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
2823 TCGv_i64 tcg_rd
, tcg_rn
;
2825 bool is_and
= false;
2827 sf
= extract32(insn
, 31, 1);
2828 opc
= extract32(insn
, 29, 2);
2829 is_n
= extract32(insn
, 22, 1);
2830 immr
= extract32(insn
, 16, 6);
2831 imms
= extract32(insn
, 10, 6);
2832 rn
= extract32(insn
, 5, 5);
2833 rd
= extract32(insn
, 0, 5);
2836 unallocated_encoding(s
);
2840 if (opc
== 0x3) { /* ANDS */
2841 tcg_rd
= cpu_reg(s
, rd
);
2843 tcg_rd
= cpu_reg_sp(s
, rd
);
2845 tcg_rn
= cpu_reg(s
, rn
);
2847 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
2848 /* some immediate field values are reserved */
2849 unallocated_encoding(s
);
2854 wmask
&= 0xffffffff;
2858 case 0x3: /* ANDS */
2860 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
2864 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
2867 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
2870 assert(FALSE
); /* must handle all above */
2874 if (!sf
&& !is_and
) {
2875 /* zero extend final result; we know we can skip this for AND
2876 * since the immediate had the high 32 bits clear.
2878 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2881 if (opc
== 3) { /* ANDS */
2882 gen_logic_CC(sf
, tcg_rd
);
2887 * C3.4.5 Move wide (immediate)
2889 * 31 30 29 28 23 22 21 20 5 4 0
2890 * +--+-----+-------------+-----+----------------+------+
2891 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
2892 * +--+-----+-------------+-----+----------------+------+
2894 * sf: 0 -> 32 bit, 1 -> 64 bit
2895 * opc: 00 -> N, 10 -> Z, 11 -> K
2896 * hw: shift/16 (0,16, and sf only 32, 48)
2898 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
2900 int rd
= extract32(insn
, 0, 5);
2901 uint64_t imm
= extract32(insn
, 5, 16);
2902 int sf
= extract32(insn
, 31, 1);
2903 int opc
= extract32(insn
, 29, 2);
2904 int pos
= extract32(insn
, 21, 2) << 4;
2905 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
2908 if (!sf
&& (pos
>= 32)) {
2909 unallocated_encoding(s
);
2923 tcg_gen_movi_i64(tcg_rd
, imm
);
2926 tcg_imm
= tcg_const_i64(imm
);
2927 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
2928 tcg_temp_free_i64(tcg_imm
);
2930 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2934 unallocated_encoding(s
);
2940 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2941 * +----+-----+-------------+---+------+------+------+------+
2942 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
2943 * +----+-----+-------------+---+------+------+------+------+
2945 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
2947 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
2948 TCGv_i64 tcg_rd
, tcg_tmp
;
2950 sf
= extract32(insn
, 31, 1);
2951 opc
= extract32(insn
, 29, 2);
2952 n
= extract32(insn
, 22, 1);
2953 ri
= extract32(insn
, 16, 6);
2954 si
= extract32(insn
, 10, 6);
2955 rn
= extract32(insn
, 5, 5);
2956 rd
= extract32(insn
, 0, 5);
2957 bitsize
= sf
? 64 : 32;
2959 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
2960 unallocated_encoding(s
);
2964 tcg_rd
= cpu_reg(s
, rd
);
2965 tcg_tmp
= read_cpu_reg(s
, rn
, sf
);
2967 /* OPTME: probably worth recognizing common cases of ext{8,16,32}{u,s} */
2969 if (opc
!= 1) { /* SBFM or UBFM */
2970 tcg_gen_movi_i64(tcg_rd
, 0);
2973 /* do the bit move operation */
2975 /* Wd<s-r:0> = Wn<s:r> */
2976 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
2978 len
= (si
- ri
) + 1;
2980 /* Wd<32+s-r,32-r> = Wn<s:0> */
2985 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
2987 if (opc
== 0) { /* SBFM - sign extend the destination field */
2988 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
2989 tcg_gen_sari_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
2992 if (!sf
) { /* zero extend final result */
2993 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2998 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
2999 * +----+------+-------------+---+----+------+--------+------+------+
3000 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
3001 * +----+------+-------------+---+----+------+--------+------+------+
3003 static void disas_extract(DisasContext
*s
, uint32_t insn
)
3005 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
3007 sf
= extract32(insn
, 31, 1);
3008 n
= extract32(insn
, 22, 1);
3009 rm
= extract32(insn
, 16, 5);
3010 imm
= extract32(insn
, 10, 6);
3011 rn
= extract32(insn
, 5, 5);
3012 rd
= extract32(insn
, 0, 5);
3013 op21
= extract32(insn
, 29, 2);
3014 op0
= extract32(insn
, 21, 1);
3015 bitsize
= sf
? 64 : 32;
3017 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
3018 unallocated_encoding(s
);
3020 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
3022 tcg_rd
= cpu_reg(s
, rd
);
3025 /* OPTME: we can special case rm==rn as a rotate */
3026 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3027 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3028 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
3029 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
3030 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
3032 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3035 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
3036 * so an extract from bit 0 is a special case.
3039 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
3041 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
3048 /* C3.4 Data processing - immediate */
3049 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
3051 switch (extract32(insn
, 23, 6)) {
3052 case 0x20: case 0x21: /* PC-rel. addressing */
3053 disas_pc_rel_adr(s
, insn
);
3055 case 0x22: case 0x23: /* Add/subtract (immediate) */
3056 disas_add_sub_imm(s
, insn
);
3058 case 0x24: /* Logical (immediate) */
3059 disas_logic_imm(s
, insn
);
3061 case 0x25: /* Move wide (immediate) */
3062 disas_movw_imm(s
, insn
);
3064 case 0x26: /* Bitfield */
3065 disas_bitfield(s
, insn
);
3067 case 0x27: /* Extract */
3068 disas_extract(s
, insn
);
3071 unallocated_encoding(s
);
3076 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3077 * Note that it is the caller's responsibility to ensure that the
3078 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3079 * mandated semantics for out of range shifts.
3081 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3082 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
3084 switch (shift_type
) {
3085 case A64_SHIFT_TYPE_LSL
:
3086 tcg_gen_shl_i64(dst
, src
, shift_amount
);
3088 case A64_SHIFT_TYPE_LSR
:
3089 tcg_gen_shr_i64(dst
, src
, shift_amount
);
3091 case A64_SHIFT_TYPE_ASR
:
3093 tcg_gen_ext32s_i64(dst
, src
);
3095 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
3097 case A64_SHIFT_TYPE_ROR
:
3099 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
3102 t0
= tcg_temp_new_i32();
3103 t1
= tcg_temp_new_i32();
3104 tcg_gen_trunc_i64_i32(t0
, src
);
3105 tcg_gen_trunc_i64_i32(t1
, shift_amount
);
3106 tcg_gen_rotr_i32(t0
, t0
, t1
);
3107 tcg_gen_extu_i32_i64(dst
, t0
);
3108 tcg_temp_free_i32(t0
);
3109 tcg_temp_free_i32(t1
);
3113 assert(FALSE
); /* all shift types should be handled */
3117 if (!sf
) { /* zero extend final result */
3118 tcg_gen_ext32u_i64(dst
, dst
);
3122 /* Shift a TCGv src by immediate, put result in dst.
3123 * The shift amount must be in range (this should always be true as the
3124 * relevant instructions will UNDEF on bad shift immediates).
3126 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3127 enum a64_shift_type shift_type
, unsigned int shift_i
)
3129 assert(shift_i
< (sf
? 64 : 32));
3132 tcg_gen_mov_i64(dst
, src
);
3134 TCGv_i64 shift_const
;
3136 shift_const
= tcg_const_i64(shift_i
);
3137 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
3138 tcg_temp_free_i64(shift_const
);
3142 /* C3.5.10 Logical (shifted register)
3143 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3144 * +----+-----+-----------+-------+---+------+--------+------+------+
3145 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3146 * +----+-----+-----------+-------+---+------+--------+------+------+
3148 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
3150 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
3151 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
3153 sf
= extract32(insn
, 31, 1);
3154 opc
= extract32(insn
, 29, 2);
3155 shift_type
= extract32(insn
, 22, 2);
3156 invert
= extract32(insn
, 21, 1);
3157 rm
= extract32(insn
, 16, 5);
3158 shift_amount
= extract32(insn
, 10, 6);
3159 rn
= extract32(insn
, 5, 5);
3160 rd
= extract32(insn
, 0, 5);
3162 if (!sf
&& (shift_amount
& (1 << 5))) {
3163 unallocated_encoding(s
);
3167 tcg_rd
= cpu_reg(s
, rd
);
3169 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3170 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3171 * register-register MOV and MVN, so it is worth special casing.
3173 tcg_rm
= cpu_reg(s
, rm
);
3175 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3177 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3181 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3183 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3189 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3192 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3195 tcg_rn
= cpu_reg(s
, rn
);
3197 switch (opc
| (invert
<< 2)) {
3200 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3203 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3206 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3210 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3213 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3216 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3224 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3228 gen_logic_CC(sf
, tcg_rd
);
3233 * C3.5.1 Add/subtract (extended register)
3235 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3236 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3237 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3238 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3240 * sf: 0 -> 32bit, 1 -> 64bit
3241 * op: 0 -> add , 1 -> sub
3244 * option: extension type (see DecodeRegExtend)
3245 * imm3: optional shift to Rm
3247 * Rd = Rn + LSL(extend(Rm), amount)
3249 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3251 int rd
= extract32(insn
, 0, 5);
3252 int rn
= extract32(insn
, 5, 5);
3253 int imm3
= extract32(insn
, 10, 3);
3254 int option
= extract32(insn
, 13, 3);
3255 int rm
= extract32(insn
, 16, 5);
3256 bool setflags
= extract32(insn
, 29, 1);
3257 bool sub_op
= extract32(insn
, 30, 1);
3258 bool sf
= extract32(insn
, 31, 1);
3260 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3262 TCGv_i64 tcg_result
;
3265 unallocated_encoding(s
);
3269 /* non-flag setting ops may use SP */
3271 tcg_rd
= cpu_reg_sp(s
, rd
);
3273 tcg_rd
= cpu_reg(s
, rd
);
3275 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3277 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3278 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3280 tcg_result
= tcg_temp_new_i64();
3284 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3286 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3290 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3292 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3297 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3299 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3302 tcg_temp_free_i64(tcg_result
);
3306 * C3.5.2 Add/subtract (shifted register)
3308 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3309 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3310 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3311 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3313 * sf: 0 -> 32bit, 1 -> 64bit
3314 * op: 0 -> add , 1 -> sub
3316 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3317 * imm6: Shift amount to apply to Rm before the add/sub
3319 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
3321 int rd
= extract32(insn
, 0, 5);
3322 int rn
= extract32(insn
, 5, 5);
3323 int imm6
= extract32(insn
, 10, 6);
3324 int rm
= extract32(insn
, 16, 5);
3325 int shift_type
= extract32(insn
, 22, 2);
3326 bool setflags
= extract32(insn
, 29, 1);
3327 bool sub_op
= extract32(insn
, 30, 1);
3328 bool sf
= extract32(insn
, 31, 1);
3330 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3331 TCGv_i64 tcg_rn
, tcg_rm
;
3332 TCGv_i64 tcg_result
;
3334 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
3335 unallocated_encoding(s
);
3339 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3340 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3342 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
3344 tcg_result
= tcg_temp_new_i64();
3348 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3350 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3354 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3356 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3361 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3363 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3366 tcg_temp_free_i64(tcg_result
);
3369 /* C3.5.9 Data-processing (3 source)
3371 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3372 +--+------+-----------+------+------+----+------+------+------+
3373 |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3374 +--+------+-----------+------+------+----+------+------+------+
3377 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
3379 int rd
= extract32(insn
, 0, 5);
3380 int rn
= extract32(insn
, 5, 5);
3381 int ra
= extract32(insn
, 10, 5);
3382 int rm
= extract32(insn
, 16, 5);
3383 int op_id
= (extract32(insn
, 29, 3) << 4) |
3384 (extract32(insn
, 21, 3) << 1) |
3385 extract32(insn
, 15, 1);
3386 bool sf
= extract32(insn
, 31, 1);
3387 bool is_sub
= extract32(op_id
, 0, 1);
3388 bool is_high
= extract32(op_id
, 2, 1);
3389 bool is_signed
= false;
3394 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
3396 case 0x42: /* SMADDL */
3397 case 0x43: /* SMSUBL */
3398 case 0x44: /* SMULH */
3401 case 0x0: /* MADD (32bit) */
3402 case 0x1: /* MSUB (32bit) */
3403 case 0x40: /* MADD (64bit) */
3404 case 0x41: /* MSUB (64bit) */
3405 case 0x4a: /* UMADDL */
3406 case 0x4b: /* UMSUBL */
3407 case 0x4c: /* UMULH */
3410 unallocated_encoding(s
);
3415 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
3416 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3417 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
3418 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
3421 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3423 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3426 tcg_temp_free_i64(low_bits
);
3430 tcg_op1
= tcg_temp_new_i64();
3431 tcg_op2
= tcg_temp_new_i64();
3432 tcg_tmp
= tcg_temp_new_i64();
3435 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
3436 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
3439 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
3440 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
3442 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
3443 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
3447 if (ra
== 31 && !is_sub
) {
3448 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
3449 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
3451 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
3453 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3455 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3460 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
3463 tcg_temp_free_i64(tcg_op1
);
3464 tcg_temp_free_i64(tcg_op2
);
3465 tcg_temp_free_i64(tcg_tmp
);
3468 /* C3.5.3 - Add/subtract (with carry)
3469 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
3470 * +--+--+--+------------------------+------+---------+------+-----+
3471 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
3472 * +--+--+--+------------------------+------+---------+------+-----+
3476 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
3478 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
3479 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
3481 if (extract32(insn
, 10, 6) != 0) {
3482 unallocated_encoding(s
);
3486 sf
= extract32(insn
, 31, 1);
3487 op
= extract32(insn
, 30, 1);
3488 setflags
= extract32(insn
, 29, 1);
3489 rm
= extract32(insn
, 16, 5);
3490 rn
= extract32(insn
, 5, 5);
3491 rd
= extract32(insn
, 0, 5);
3493 tcg_rd
= cpu_reg(s
, rd
);
3494 tcg_rn
= cpu_reg(s
, rn
);
3497 tcg_y
= new_tmp_a64(s
);
3498 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
3500 tcg_y
= cpu_reg(s
, rm
);
3504 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3506 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3510 /* C3.5.4 - C3.5.5 Conditional compare (immediate / register)
3511 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3512 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3513 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
3514 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3517 static void disas_cc(DisasContext
*s
, uint32_t insn
)
3519 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
3520 int label_continue
= -1;
3521 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
3523 if (!extract32(insn
, 29, 1)) {
3524 unallocated_encoding(s
);
3527 if (insn
& (1 << 10 | 1 << 4)) {
3528 unallocated_encoding(s
);
3531 sf
= extract32(insn
, 31, 1);
3532 op
= extract32(insn
, 30, 1);
3533 is_imm
= extract32(insn
, 11, 1);
3534 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
3535 cond
= extract32(insn
, 12, 4);
3536 rn
= extract32(insn
, 5, 5);
3537 nzcv
= extract32(insn
, 0, 4);
3539 if (cond
< 0x0e) { /* not always */
3540 int label_match
= gen_new_label();
3541 label_continue
= gen_new_label();
3542 arm_gen_test_cc(cond
, label_match
);
3544 tcg_tmp
= tcg_temp_new_i64();
3545 tcg_gen_movi_i64(tcg_tmp
, nzcv
<< 28);
3546 gen_set_nzcv(tcg_tmp
);
3547 tcg_temp_free_i64(tcg_tmp
);
3548 tcg_gen_br(label_continue
);
3549 gen_set_label(label_match
);
3551 /* match, or condition is always */
3553 tcg_y
= new_tmp_a64(s
);
3554 tcg_gen_movi_i64(tcg_y
, y
);
3556 tcg_y
= cpu_reg(s
, y
);
3558 tcg_rn
= cpu_reg(s
, rn
);
3560 tcg_tmp
= tcg_temp_new_i64();
3562 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3564 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3566 tcg_temp_free_i64(tcg_tmp
);
3568 if (cond
< 0x0e) { /* continue */
3569 gen_set_label(label_continue
);
3573 /* C3.5.6 Conditional select
3574 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
3575 * +----+----+---+-----------------+------+------+-----+------+------+
3576 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
3577 * +----+----+---+-----------------+------+------+-----+------+------+
3579 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
3581 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
3582 TCGv_i64 tcg_rd
, tcg_src
;
3584 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
3585 /* S == 1 or op2<1> == 1 */
3586 unallocated_encoding(s
);
3589 sf
= extract32(insn
, 31, 1);
3590 else_inv
= extract32(insn
, 30, 1);
3591 rm
= extract32(insn
, 16, 5);
3592 cond
= extract32(insn
, 12, 4);
3593 else_inc
= extract32(insn
, 10, 1);
3594 rn
= extract32(insn
, 5, 5);
3595 rd
= extract32(insn
, 0, 5);
3598 /* silly no-op write; until we use movcond we must special-case
3599 * this to avoid a dead temporary across basic blocks.
3604 tcg_rd
= cpu_reg(s
, rd
);
3606 if (cond
>= 0x0e) { /* condition "always" */
3607 tcg_src
= read_cpu_reg(s
, rn
, sf
);
3608 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3610 /* OPTME: we could use movcond here, at the cost of duplicating
3611 * a lot of the arm_gen_test_cc() logic.
3613 int label_match
= gen_new_label();
3614 int label_continue
= gen_new_label();
3616 arm_gen_test_cc(cond
, label_match
);
3618 tcg_src
= cpu_reg(s
, rm
);
3620 if (else_inv
&& else_inc
) {
3621 tcg_gen_neg_i64(tcg_rd
, tcg_src
);
3622 } else if (else_inv
) {
3623 tcg_gen_not_i64(tcg_rd
, tcg_src
);
3624 } else if (else_inc
) {
3625 tcg_gen_addi_i64(tcg_rd
, tcg_src
, 1);
3627 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3630 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3632 tcg_gen_br(label_continue
);
3634 gen_set_label(label_match
);
3635 tcg_src
= read_cpu_reg(s
, rn
, sf
);
3636 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3638 gen_set_label(label_continue
);
3642 static void handle_clz(DisasContext
*s
, unsigned int sf
,
3643 unsigned int rn
, unsigned int rd
)
3645 TCGv_i64 tcg_rd
, tcg_rn
;
3646 tcg_rd
= cpu_reg(s
, rd
);
3647 tcg_rn
= cpu_reg(s
, rn
);
3650 gen_helper_clz64(tcg_rd
, tcg_rn
);
3652 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3653 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3654 gen_helper_clz(tcg_tmp32
, tcg_tmp32
);
3655 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3656 tcg_temp_free_i32(tcg_tmp32
);
3660 static void handle_cls(DisasContext
*s
, unsigned int sf
,
3661 unsigned int rn
, unsigned int rd
)
3663 TCGv_i64 tcg_rd
, tcg_rn
;
3664 tcg_rd
= cpu_reg(s
, rd
);
3665 tcg_rn
= cpu_reg(s
, rn
);
3668 gen_helper_cls64(tcg_rd
, tcg_rn
);
3670 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3671 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3672 gen_helper_cls32(tcg_tmp32
, tcg_tmp32
);
3673 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3674 tcg_temp_free_i32(tcg_tmp32
);
3678 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
3679 unsigned int rn
, unsigned int rd
)
3681 TCGv_i64 tcg_rd
, tcg_rn
;
3682 tcg_rd
= cpu_reg(s
, rd
);
3683 tcg_rn
= cpu_reg(s
, rn
);
3686 gen_helper_rbit64(tcg_rd
, tcg_rn
);
3688 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3689 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3690 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
3691 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3692 tcg_temp_free_i32(tcg_tmp32
);
3696 /* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
3697 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
3698 unsigned int rn
, unsigned int rd
)
3701 unallocated_encoding(s
);
3704 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
3707 /* C5.6.149 REV with sf==0, opcode==2
3708 * C5.6.151 REV32 (sf==1, opcode==2)
3710 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
3711 unsigned int rn
, unsigned int rd
)
3713 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3716 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3717 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3719 /* bswap32_i64 requires zero high word */
3720 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
3721 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
3722 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3723 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
3724 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
3726 tcg_temp_free_i64(tcg_tmp
);
3728 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
3729 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
3733 /* C5.6.150 REV16 (opcode==1) */
3734 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
3735 unsigned int rn
, unsigned int rd
)
3737 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3738 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3739 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3741 tcg_gen_andi_i64(tcg_tmp
, tcg_rn
, 0xffff);
3742 tcg_gen_bswap16_i64(tcg_rd
, tcg_tmp
);
3744 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 16);
3745 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3746 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3747 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 16, 16);
3750 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3751 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3752 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3753 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 32, 16);
3755 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 48);
3756 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3757 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 48, 16);
3760 tcg_temp_free_i64(tcg_tmp
);
3763 /* C3.5.7 Data-processing (1 source)
3764 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3765 * +----+---+---+-----------------+---------+--------+------+------+
3766 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
3767 * +----+---+---+-----------------+---------+--------+------+------+
3769 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
3771 unsigned int sf
, opcode
, rn
, rd
;
3773 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
3774 unallocated_encoding(s
);
3778 sf
= extract32(insn
, 31, 1);
3779 opcode
= extract32(insn
, 10, 6);
3780 rn
= extract32(insn
, 5, 5);
3781 rd
= extract32(insn
, 0, 5);
3785 handle_rbit(s
, sf
, rn
, rd
);
3788 handle_rev16(s
, sf
, rn
, rd
);
3791 handle_rev32(s
, sf
, rn
, rd
);
3794 handle_rev64(s
, sf
, rn
, rd
);
3797 handle_clz(s
, sf
, rn
, rd
);
3800 handle_cls(s
, sf
, rn
, rd
);
3805 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
3806 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3808 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
3809 tcg_rd
= cpu_reg(s
, rd
);
3811 if (!sf
&& is_signed
) {
3812 tcg_n
= new_tmp_a64(s
);
3813 tcg_m
= new_tmp_a64(s
);
3814 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
3815 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
3817 tcg_n
= read_cpu_reg(s
, rn
, sf
);
3818 tcg_m
= read_cpu_reg(s
, rm
, sf
);
3822 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
3824 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
3827 if (!sf
) { /* zero extend final result */
3828 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3832 /* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
3833 static void handle_shift_reg(DisasContext
*s
,
3834 enum a64_shift_type shift_type
, unsigned int sf
,
3835 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3837 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
3838 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3839 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3841 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
3842 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
3843 tcg_temp_free_i64(tcg_shift
);
3846 /* CRC32[BHWX], CRC32C[BHWX] */
3847 static void handle_crc32(DisasContext
*s
,
3848 unsigned int sf
, unsigned int sz
, bool crc32c
,
3849 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3851 TCGv_i64 tcg_acc
, tcg_val
;
3854 if (!arm_dc_feature(s
, ARM_FEATURE_CRC
)
3855 || (sf
== 1 && sz
!= 3)
3856 || (sf
== 0 && sz
== 3)) {
3857 unallocated_encoding(s
);
3862 tcg_val
= cpu_reg(s
, rm
);
3876 g_assert_not_reached();
3878 tcg_val
= new_tmp_a64(s
);
3879 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
3882 tcg_acc
= cpu_reg(s
, rn
);
3883 tcg_bytes
= tcg_const_i32(1 << sz
);
3886 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
3888 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
3891 tcg_temp_free_i32(tcg_bytes
);
3894 /* C3.5.8 Data-processing (2 source)
3895 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3896 * +----+---+---+-----------------+------+--------+------+------+
3897 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
3898 * +----+---+---+-----------------+------+--------+------+------+
3900 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
3902 unsigned int sf
, rm
, opcode
, rn
, rd
;
3903 sf
= extract32(insn
, 31, 1);
3904 rm
= extract32(insn
, 16, 5);
3905 opcode
= extract32(insn
, 10, 6);
3906 rn
= extract32(insn
, 5, 5);
3907 rd
= extract32(insn
, 0, 5);
3909 if (extract32(insn
, 29, 1)) {
3910 unallocated_encoding(s
);
3916 handle_div(s
, false, sf
, rm
, rn
, rd
);
3919 handle_div(s
, true, sf
, rm
, rn
, rd
);
3922 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
3925 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
3928 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
3931 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
3940 case 23: /* CRC32 */
3942 int sz
= extract32(opcode
, 0, 2);
3943 bool crc32c
= extract32(opcode
, 2, 1);
3944 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
3948 unallocated_encoding(s
);
3953 /* C3.5 Data processing - register */
3954 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
3956 switch (extract32(insn
, 24, 5)) {
3957 case 0x0a: /* Logical (shifted register) */
3958 disas_logic_reg(s
, insn
);
3960 case 0x0b: /* Add/subtract */
3961 if (insn
& (1 << 21)) { /* (extended register) */
3962 disas_add_sub_ext_reg(s
, insn
);
3964 disas_add_sub_reg(s
, insn
);
3967 case 0x1b: /* Data-processing (3 source) */
3968 disas_data_proc_3src(s
, insn
);
3971 switch (extract32(insn
, 21, 3)) {
3972 case 0x0: /* Add/subtract (with carry) */
3973 disas_adc_sbc(s
, insn
);
3975 case 0x2: /* Conditional compare */
3976 disas_cc(s
, insn
); /* both imm and reg forms */
3978 case 0x4: /* Conditional select */
3979 disas_cond_select(s
, insn
);
3981 case 0x6: /* Data-processing */
3982 if (insn
& (1 << 30)) { /* (1 source) */
3983 disas_data_proc_1src(s
, insn
);
3984 } else { /* (2 source) */
3985 disas_data_proc_2src(s
, insn
);
3989 unallocated_encoding(s
);
3994 unallocated_encoding(s
);
3999 static void handle_fp_compare(DisasContext
*s
, bool is_double
,
4000 unsigned int rn
, unsigned int rm
,
4001 bool cmp_with_zero
, bool signal_all_nans
)
4003 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
4004 TCGv_ptr fpst
= get_fpstatus_ptr();
4007 TCGv_i64 tcg_vn
, tcg_vm
;
4009 tcg_vn
= read_fp_dreg(s
, rn
);
4010 if (cmp_with_zero
) {
4011 tcg_vm
= tcg_const_i64(0);
4013 tcg_vm
= read_fp_dreg(s
, rm
);
4015 if (signal_all_nans
) {
4016 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4018 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4020 tcg_temp_free_i64(tcg_vn
);
4021 tcg_temp_free_i64(tcg_vm
);
4023 TCGv_i32 tcg_vn
, tcg_vm
;
4025 tcg_vn
= read_fp_sreg(s
, rn
);
4026 if (cmp_with_zero
) {
4027 tcg_vm
= tcg_const_i32(0);
4029 tcg_vm
= read_fp_sreg(s
, rm
);
4031 if (signal_all_nans
) {
4032 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4034 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
4036 tcg_temp_free_i32(tcg_vn
);
4037 tcg_temp_free_i32(tcg_vm
);
4040 tcg_temp_free_ptr(fpst
);
4042 gen_set_nzcv(tcg_flags
);
4044 tcg_temp_free_i64(tcg_flags
);
4047 /* C3.6.22 Floating point compare
4048 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
4049 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4050 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
4051 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
4053 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
4055 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
4057 mos
= extract32(insn
, 29, 3);
4058 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4059 rm
= extract32(insn
, 16, 5);
4060 op
= extract32(insn
, 14, 2);
4061 rn
= extract32(insn
, 5, 5);
4062 opc
= extract32(insn
, 3, 2);
4063 op2r
= extract32(insn
, 0, 3);
4065 if (mos
|| op
|| op2r
|| type
> 1) {
4066 unallocated_encoding(s
);
4070 if (!fp_access_check(s
)) {
4074 handle_fp_compare(s
, type
, rn
, rm
, opc
& 1, opc
& 2);
4077 /* C3.6.23 Floating point conditional compare
4078 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4079 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4080 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
4081 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4083 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
4085 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
4087 int label_continue
= -1;
4089 mos
= extract32(insn
, 29, 3);
4090 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4091 rm
= extract32(insn
, 16, 5);
4092 cond
= extract32(insn
, 12, 4);
4093 rn
= extract32(insn
, 5, 5);
4094 op
= extract32(insn
, 4, 1);
4095 nzcv
= extract32(insn
, 0, 4);
4097 if (mos
|| type
> 1) {
4098 unallocated_encoding(s
);
4102 if (!fp_access_check(s
)) {
4106 if (cond
< 0x0e) { /* not always */
4107 int label_match
= gen_new_label();
4108 label_continue
= gen_new_label();
4109 arm_gen_test_cc(cond
, label_match
);
4111 tcg_flags
= tcg_const_i64(nzcv
<< 28);
4112 gen_set_nzcv(tcg_flags
);
4113 tcg_temp_free_i64(tcg_flags
);
4114 tcg_gen_br(label_continue
);
4115 gen_set_label(label_match
);
4118 handle_fp_compare(s
, type
, rn
, rm
, false, op
);
4121 gen_set_label(label_continue
);
4125 /* copy src FP register to dst FP register; type specifies single or double */
4126 static void gen_mov_fp2fp(DisasContext
*s
, int type
, int dst
, int src
)
4129 TCGv_i64 v
= read_fp_dreg(s
, src
);
4130 write_fp_dreg(s
, dst
, v
);
4131 tcg_temp_free_i64(v
);
4133 TCGv_i32 v
= read_fp_sreg(s
, src
);
4134 write_fp_sreg(s
, dst
, v
);
4135 tcg_temp_free_i32(v
);
4139 /* C3.6.24 Floating point conditional select
4140 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4141 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4142 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
4143 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4145 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
4147 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
4148 int label_continue
= -1;
4150 mos
= extract32(insn
, 29, 3);
4151 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4152 rm
= extract32(insn
, 16, 5);
4153 cond
= extract32(insn
, 12, 4);
4154 rn
= extract32(insn
, 5, 5);
4155 rd
= extract32(insn
, 0, 5);
4157 if (mos
|| type
> 1) {
4158 unallocated_encoding(s
);
4162 if (!fp_access_check(s
)) {
4166 if (cond
< 0x0e) { /* not always */
4167 int label_match
= gen_new_label();
4168 label_continue
= gen_new_label();
4169 arm_gen_test_cc(cond
, label_match
);
4171 gen_mov_fp2fp(s
, type
, rd
, rm
);
4172 tcg_gen_br(label_continue
);
4173 gen_set_label(label_match
);
4176 gen_mov_fp2fp(s
, type
, rd
, rn
);
4178 if (cond
< 0x0e) { /* continue */
4179 gen_set_label(label_continue
);
4183 /* C3.6.25 Floating-point data-processing (1 source) - single precision */
4184 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
4190 fpst
= get_fpstatus_ptr();
4191 tcg_op
= read_fp_sreg(s
, rn
);
4192 tcg_res
= tcg_temp_new_i32();
4195 case 0x0: /* FMOV */
4196 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4198 case 0x1: /* FABS */
4199 gen_helper_vfp_abss(tcg_res
, tcg_op
);
4201 case 0x2: /* FNEG */
4202 gen_helper_vfp_negs(tcg_res
, tcg_op
);
4204 case 0x3: /* FSQRT */
4205 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
4207 case 0x8: /* FRINTN */
4208 case 0x9: /* FRINTP */
4209 case 0xa: /* FRINTM */
4210 case 0xb: /* FRINTZ */
4211 case 0xc: /* FRINTA */
4213 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4215 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4216 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4218 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4219 tcg_temp_free_i32(tcg_rmode
);
4222 case 0xe: /* FRINTX */
4223 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
4225 case 0xf: /* FRINTI */
4226 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4232 write_fp_sreg(s
, rd
, tcg_res
);
4234 tcg_temp_free_ptr(fpst
);
4235 tcg_temp_free_i32(tcg_op
);
4236 tcg_temp_free_i32(tcg_res
);
4239 /* C3.6.25 Floating-point data-processing (1 source) - double precision */
4240 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
4246 fpst
= get_fpstatus_ptr();
4247 tcg_op
= read_fp_dreg(s
, rn
);
4248 tcg_res
= tcg_temp_new_i64();
4251 case 0x0: /* FMOV */
4252 tcg_gen_mov_i64(tcg_res
, tcg_op
);
4254 case 0x1: /* FABS */
4255 gen_helper_vfp_absd(tcg_res
, tcg_op
);
4257 case 0x2: /* FNEG */
4258 gen_helper_vfp_negd(tcg_res
, tcg_op
);
4260 case 0x3: /* FSQRT */
4261 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
4263 case 0x8: /* FRINTN */
4264 case 0x9: /* FRINTP */
4265 case 0xa: /* FRINTM */
4266 case 0xb: /* FRINTZ */
4267 case 0xc: /* FRINTA */
4269 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4271 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4272 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4274 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4275 tcg_temp_free_i32(tcg_rmode
);
4278 case 0xe: /* FRINTX */
4279 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
4281 case 0xf: /* FRINTI */
4282 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4288 write_fp_dreg(s
, rd
, tcg_res
);
4290 tcg_temp_free_ptr(fpst
);
4291 tcg_temp_free_i64(tcg_op
);
4292 tcg_temp_free_i64(tcg_res
);
4295 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
4296 int rd
, int rn
, int dtype
, int ntype
)
4301 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4303 /* Single to double */
4304 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4305 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
4306 write_fp_dreg(s
, rd
, tcg_rd
);
4307 tcg_temp_free_i64(tcg_rd
);
4309 /* Single to half */
4310 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4311 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4312 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4313 write_fp_sreg(s
, rd
, tcg_rd
);
4314 tcg_temp_free_i32(tcg_rd
);
4316 tcg_temp_free_i32(tcg_rn
);
4321 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
4322 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4324 /* Double to single */
4325 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
4327 /* Double to half */
4328 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4329 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4331 write_fp_sreg(s
, rd
, tcg_rd
);
4332 tcg_temp_free_i32(tcg_rd
);
4333 tcg_temp_free_i64(tcg_rn
);
4338 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4339 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
4341 /* Half to single */
4342 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4343 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, cpu_env
);
4344 write_fp_sreg(s
, rd
, tcg_rd
);
4345 tcg_temp_free_i32(tcg_rd
);
4347 /* Half to double */
4348 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4349 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, cpu_env
);
4350 write_fp_dreg(s
, rd
, tcg_rd
);
4351 tcg_temp_free_i64(tcg_rd
);
4353 tcg_temp_free_i32(tcg_rn
);
4361 /* C3.6.25 Floating point data-processing (1 source)
4362 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
4363 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4364 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
4365 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4367 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
4369 int type
= extract32(insn
, 22, 2);
4370 int opcode
= extract32(insn
, 15, 6);
4371 int rn
= extract32(insn
, 5, 5);
4372 int rd
= extract32(insn
, 0, 5);
4375 case 0x4: case 0x5: case 0x7:
4377 /* FCVT between half, single and double precision */
4378 int dtype
= extract32(opcode
, 0, 2);
4379 if (type
== 2 || dtype
== type
) {
4380 unallocated_encoding(s
);
4383 if (!fp_access_check(s
)) {
4387 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
4393 /* 32-to-32 and 64-to-64 ops */
4396 if (!fp_access_check(s
)) {
4400 handle_fp_1src_single(s
, opcode
, rd
, rn
);
4403 if (!fp_access_check(s
)) {
4407 handle_fp_1src_double(s
, opcode
, rd
, rn
);
4410 unallocated_encoding(s
);
4414 unallocated_encoding(s
);
4419 /* C3.6.26 Floating-point data-processing (2 source) - single precision */
4420 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
4421 int rd
, int rn
, int rm
)
4428 tcg_res
= tcg_temp_new_i32();
4429 fpst
= get_fpstatus_ptr();
4430 tcg_op1
= read_fp_sreg(s
, rn
);
4431 tcg_op2
= read_fp_sreg(s
, rm
);
4434 case 0x0: /* FMUL */
4435 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4437 case 0x1: /* FDIV */
4438 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4440 case 0x2: /* FADD */
4441 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4443 case 0x3: /* FSUB */
4444 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4446 case 0x4: /* FMAX */
4447 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4449 case 0x5: /* FMIN */
4450 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4452 case 0x6: /* FMAXNM */
4453 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4455 case 0x7: /* FMINNM */
4456 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4458 case 0x8: /* FNMUL */
4459 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4460 gen_helper_vfp_negs(tcg_res
, tcg_res
);
4464 write_fp_sreg(s
, rd
, tcg_res
);
4466 tcg_temp_free_ptr(fpst
);
4467 tcg_temp_free_i32(tcg_op1
);
4468 tcg_temp_free_i32(tcg_op2
);
4469 tcg_temp_free_i32(tcg_res
);
4472 /* C3.6.26 Floating-point data-processing (2 source) - double precision */
4473 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
4474 int rd
, int rn
, int rm
)
4481 tcg_res
= tcg_temp_new_i64();
4482 fpst
= get_fpstatus_ptr();
4483 tcg_op1
= read_fp_dreg(s
, rn
);
4484 tcg_op2
= read_fp_dreg(s
, rm
);
4487 case 0x0: /* FMUL */
4488 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4490 case 0x1: /* FDIV */
4491 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4493 case 0x2: /* FADD */
4494 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4496 case 0x3: /* FSUB */
4497 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4499 case 0x4: /* FMAX */
4500 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4502 case 0x5: /* FMIN */
4503 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4505 case 0x6: /* FMAXNM */
4506 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4508 case 0x7: /* FMINNM */
4509 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4511 case 0x8: /* FNMUL */
4512 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4513 gen_helper_vfp_negd(tcg_res
, tcg_res
);
4517 write_fp_dreg(s
, rd
, tcg_res
);
4519 tcg_temp_free_ptr(fpst
);
4520 tcg_temp_free_i64(tcg_op1
);
4521 tcg_temp_free_i64(tcg_op2
);
4522 tcg_temp_free_i64(tcg_res
);
4525 /* C3.6.26 Floating point data-processing (2 source)
4526 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4527 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4528 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
4529 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4531 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
4533 int type
= extract32(insn
, 22, 2);
4534 int rd
= extract32(insn
, 0, 5);
4535 int rn
= extract32(insn
, 5, 5);
4536 int rm
= extract32(insn
, 16, 5);
4537 int opcode
= extract32(insn
, 12, 4);
4540 unallocated_encoding(s
);
4546 if (!fp_access_check(s
)) {
4549 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
4552 if (!fp_access_check(s
)) {
4555 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
4558 unallocated_encoding(s
);
4562 /* C3.6.27 Floating-point data-processing (3 source) - single precision */
4563 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
4564 int rd
, int rn
, int rm
, int ra
)
4566 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
4567 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4568 TCGv_ptr fpst
= get_fpstatus_ptr();
4570 tcg_op1
= read_fp_sreg(s
, rn
);
4571 tcg_op2
= read_fp_sreg(s
, rm
);
4572 tcg_op3
= read_fp_sreg(s
, ra
);
4574 /* These are fused multiply-add, and must be done as one
4575 * floating point operation with no rounding between the
4576 * multiplication and addition steps.
4577 * NB that doing the negations here as separate steps is
4578 * correct : an input NaN should come out with its sign bit
4579 * flipped if it is a negated-input.
4582 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
4586 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
4589 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4591 write_fp_sreg(s
, rd
, tcg_res
);
4593 tcg_temp_free_ptr(fpst
);
4594 tcg_temp_free_i32(tcg_op1
);
4595 tcg_temp_free_i32(tcg_op2
);
4596 tcg_temp_free_i32(tcg_op3
);
4597 tcg_temp_free_i32(tcg_res
);
4600 /* C3.6.27 Floating-point data-processing (3 source) - double precision */
4601 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
4602 int rd
, int rn
, int rm
, int ra
)
4604 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
4605 TCGv_i64 tcg_res
= tcg_temp_new_i64();
4606 TCGv_ptr fpst
= get_fpstatus_ptr();
4608 tcg_op1
= read_fp_dreg(s
, rn
);
4609 tcg_op2
= read_fp_dreg(s
, rm
);
4610 tcg_op3
= read_fp_dreg(s
, ra
);
4612 /* These are fused multiply-add, and must be done as one
4613 * floating point operation with no rounding between the
4614 * multiplication and addition steps.
4615 * NB that doing the negations here as separate steps is
4616 * correct : an input NaN should come out with its sign bit
4617 * flipped if it is a negated-input.
4620 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
4624 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
4627 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4629 write_fp_dreg(s
, rd
, tcg_res
);
4631 tcg_temp_free_ptr(fpst
);
4632 tcg_temp_free_i64(tcg_op1
);
4633 tcg_temp_free_i64(tcg_op2
);
4634 tcg_temp_free_i64(tcg_op3
);
4635 tcg_temp_free_i64(tcg_res
);
4638 /* C3.6.27 Floating point data-processing (3 source)
4639 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
4640 * +---+---+---+-----------+------+----+------+----+------+------+------+
4641 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
4642 * +---+---+---+-----------+------+----+------+----+------+------+------+
4644 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
4646 int type
= extract32(insn
, 22, 2);
4647 int rd
= extract32(insn
, 0, 5);
4648 int rn
= extract32(insn
, 5, 5);
4649 int ra
= extract32(insn
, 10, 5);
4650 int rm
= extract32(insn
, 16, 5);
4651 bool o0
= extract32(insn
, 15, 1);
4652 bool o1
= extract32(insn
, 21, 1);
4656 if (!fp_access_check(s
)) {
4659 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4662 if (!fp_access_check(s
)) {
4665 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4668 unallocated_encoding(s
);
4672 /* C3.6.28 Floating point immediate
4673 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
4674 * +---+---+---+-----------+------+---+------------+-------+------+------+
4675 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
4676 * +---+---+---+-----------+------+---+------------+-------+------+------+
4678 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
4680 int rd
= extract32(insn
, 0, 5);
4681 int imm8
= extract32(insn
, 13, 8);
4682 int is_double
= extract32(insn
, 22, 2);
4686 if (is_double
> 1) {
4687 unallocated_encoding(s
);
4691 if (!fp_access_check(s
)) {
4695 /* The imm8 encodes the sign bit, enough bits to represent
4696 * an exponent in the range 01....1xx to 10....0xx,
4697 * and the most significant 4 bits of the mantissa; see
4698 * VFPExpandImm() in the v8 ARM ARM.
4701 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4702 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
4703 extract32(imm8
, 0, 6);
4706 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4707 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
4708 (extract32(imm8
, 0, 6) << 3);
4712 tcg_res
= tcg_const_i64(imm
);
4713 write_fp_dreg(s
, rd
, tcg_res
);
4714 tcg_temp_free_i64(tcg_res
);
4717 /* Handle floating point <=> fixed point conversions. Note that we can
4718 * also deal with fp <=> integer conversions as a special case (scale == 64)
4719 * OPTME: consider handling that special case specially or at least skipping
4720 * the call to scalbn in the helpers for zero shifts.
4722 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
4723 bool itof
, int rmode
, int scale
, int sf
, int type
)
4725 bool is_signed
= !(opcode
& 1);
4726 bool is_double
= type
;
4727 TCGv_ptr tcg_fpstatus
;
4730 tcg_fpstatus
= get_fpstatus_ptr();
4732 tcg_shift
= tcg_const_i32(64 - scale
);
4735 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
4737 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
4740 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
4742 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
4745 tcg_int
= tcg_extend
;
4749 TCGv_i64 tcg_double
= tcg_temp_new_i64();
4751 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
4752 tcg_shift
, tcg_fpstatus
);
4754 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
4755 tcg_shift
, tcg_fpstatus
);
4757 write_fp_dreg(s
, rd
, tcg_double
);
4758 tcg_temp_free_i64(tcg_double
);
4760 TCGv_i32 tcg_single
= tcg_temp_new_i32();
4762 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
4763 tcg_shift
, tcg_fpstatus
);
4765 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
4766 tcg_shift
, tcg_fpstatus
);
4768 write_fp_sreg(s
, rd
, tcg_single
);
4769 tcg_temp_free_i32(tcg_single
);
4772 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
4775 if (extract32(opcode
, 2, 1)) {
4776 /* There are too many rounding modes to all fit into rmode,
4777 * so FCVTA[US] is a special case.
4779 rmode
= FPROUNDING_TIEAWAY
;
4782 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
4784 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4787 TCGv_i64 tcg_double
= read_fp_dreg(s
, rn
);
4790 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
4791 tcg_shift
, tcg_fpstatus
);
4793 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
4794 tcg_shift
, tcg_fpstatus
);
4798 gen_helper_vfp_tould(tcg_int
, tcg_double
,
4799 tcg_shift
, tcg_fpstatus
);
4801 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
4802 tcg_shift
, tcg_fpstatus
);
4805 tcg_temp_free_i64(tcg_double
);
4807 TCGv_i32 tcg_single
= read_fp_sreg(s
, rn
);
4810 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
4811 tcg_shift
, tcg_fpstatus
);
4813 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
4814 tcg_shift
, tcg_fpstatus
);
4817 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
4819 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
4820 tcg_shift
, tcg_fpstatus
);
4822 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
4823 tcg_shift
, tcg_fpstatus
);
4825 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
4826 tcg_temp_free_i32(tcg_dest
);
4828 tcg_temp_free_i32(tcg_single
);
4831 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4832 tcg_temp_free_i32(tcg_rmode
);
4835 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
4839 tcg_temp_free_ptr(tcg_fpstatus
);
4840 tcg_temp_free_i32(tcg_shift
);
4843 /* C3.6.29 Floating point <-> fixed point conversions
4844 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4845 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4846 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
4847 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4849 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
4851 int rd
= extract32(insn
, 0, 5);
4852 int rn
= extract32(insn
, 5, 5);
4853 int scale
= extract32(insn
, 10, 6);
4854 int opcode
= extract32(insn
, 16, 3);
4855 int rmode
= extract32(insn
, 19, 2);
4856 int type
= extract32(insn
, 22, 2);
4857 bool sbit
= extract32(insn
, 29, 1);
4858 bool sf
= extract32(insn
, 31, 1);
4861 if (sbit
|| (type
> 1)
4862 || (!sf
&& scale
< 32)) {
4863 unallocated_encoding(s
);
4867 switch ((rmode
<< 3) | opcode
) {
4868 case 0x2: /* SCVTF */
4869 case 0x3: /* UCVTF */
4872 case 0x18: /* FCVTZS */
4873 case 0x19: /* FCVTZU */
4877 unallocated_encoding(s
);
4881 if (!fp_access_check(s
)) {
4885 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
4888 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
4890 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
4891 * without conversion.
4895 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4901 TCGv_i64 tmp
= tcg_temp_new_i64();
4902 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
4903 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
4904 tcg_gen_movi_i64(tmp
, 0);
4905 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4906 tcg_temp_free_i64(tmp
);
4912 TCGv_i64 tmp
= tcg_const_i64(0);
4913 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
4914 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4915 tcg_temp_free_i64(tmp
);
4919 /* 64 bit to top half. */
4920 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4924 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4929 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
4933 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
4936 /* 64 bits from top half */
4937 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
4943 /* C3.6.30 Floating point <-> integer conversions
4944 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4945 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4946 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
4947 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4949 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
4951 int rd
= extract32(insn
, 0, 5);
4952 int rn
= extract32(insn
, 5, 5);
4953 int opcode
= extract32(insn
, 16, 3);
4954 int rmode
= extract32(insn
, 19, 2);
4955 int type
= extract32(insn
, 22, 2);
4956 bool sbit
= extract32(insn
, 29, 1);
4957 bool sf
= extract32(insn
, 31, 1);
4960 unallocated_encoding(s
);
4966 bool itof
= opcode
& 1;
4969 unallocated_encoding(s
);
4973 switch (sf
<< 3 | type
<< 1 | rmode
) {
4974 case 0x0: /* 32 bit */
4975 case 0xa: /* 64 bit */
4976 case 0xd: /* 64 bit to top half of quad */
4979 /* all other sf/type/rmode combinations are invalid */
4980 unallocated_encoding(s
);
4984 if (!fp_access_check(s
)) {
4987 handle_fmov(s
, rd
, rn
, type
, itof
);
4989 /* actual FP conversions */
4990 bool itof
= extract32(opcode
, 1, 1);
4992 if (type
> 1 || (rmode
!= 0 && opcode
> 1)) {
4993 unallocated_encoding(s
);
4997 if (!fp_access_check(s
)) {
5000 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
5004 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
5005 * 31 30 29 28 25 24 0
5006 * +---+---+---+---------+-----------------------------+
5007 * | | 0 | | 1 1 1 1 | |
5008 * +---+---+---+---------+-----------------------------+
5010 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
5012 if (extract32(insn
, 24, 1)) {
5013 /* Floating point data-processing (3 source) */
5014 disas_fp_3src(s
, insn
);
5015 } else if (extract32(insn
, 21, 1) == 0) {
5016 /* Floating point to fixed point conversions */
5017 disas_fp_fixed_conv(s
, insn
);
5019 switch (extract32(insn
, 10, 2)) {
5021 /* Floating point conditional compare */
5022 disas_fp_ccomp(s
, insn
);
5025 /* Floating point data-processing (2 source) */
5026 disas_fp_2src(s
, insn
);
5029 /* Floating point conditional select */
5030 disas_fp_csel(s
, insn
);
5033 switch (ctz32(extract32(insn
, 12, 4))) {
5034 case 0: /* [15:12] == xxx1 */
5035 /* Floating point immediate */
5036 disas_fp_imm(s
, insn
);
5038 case 1: /* [15:12] == xx10 */
5039 /* Floating point compare */
5040 disas_fp_compare(s
, insn
);
5042 case 2: /* [15:12] == x100 */
5043 /* Floating point data-processing (1 source) */
5044 disas_fp_1src(s
, insn
);
5046 case 3: /* [15:12] == 1000 */
5047 unallocated_encoding(s
);
5049 default: /* [15:12] == 0000 */
5050 /* Floating point <-> integer conversions */
5051 disas_fp_int_conv(s
, insn
);
5059 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
5062 /* Extract 64 bits from the middle of two concatenated 64 bit
5063 * vector register slices left:right. The extracted bits start
5064 * at 'pos' bits into the right (least significant) side.
5065 * We return the result in tcg_right, and guarantee not to
5068 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5069 assert(pos
> 0 && pos
< 64);
5071 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
5072 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
5073 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
5075 tcg_temp_free_i64(tcg_tmp
);
5079 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
5080 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5081 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
5082 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5084 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
5086 int is_q
= extract32(insn
, 30, 1);
5087 int op2
= extract32(insn
, 22, 2);
5088 int imm4
= extract32(insn
, 11, 4);
5089 int rm
= extract32(insn
, 16, 5);
5090 int rn
= extract32(insn
, 5, 5);
5091 int rd
= extract32(insn
, 0, 5);
5092 int pos
= imm4
<< 3;
5093 TCGv_i64 tcg_resl
, tcg_resh
;
5095 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
5096 unallocated_encoding(s
);
5100 if (!fp_access_check(s
)) {
5104 tcg_resh
= tcg_temp_new_i64();
5105 tcg_resl
= tcg_temp_new_i64();
5107 /* Vd gets bits starting at pos bits into Vm:Vn. This is
5108 * either extracting 128 bits from a 128:128 concatenation, or
5109 * extracting 64 bits from a 64:64 concatenation.
5112 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
5114 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
5115 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5117 tcg_gen_movi_i64(tcg_resh
, 0);
5124 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
5125 EltPosns
*elt
= eltposns
;
5132 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
5134 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
5137 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5138 tcg_hh
= tcg_temp_new_i64();
5139 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
5140 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
5141 tcg_temp_free_i64(tcg_hh
);
5145 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5146 tcg_temp_free_i64(tcg_resl
);
5147 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5148 tcg_temp_free_i64(tcg_resh
);
5152 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
5153 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5154 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
5155 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5157 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
5159 int op2
= extract32(insn
, 22, 2);
5160 int is_q
= extract32(insn
, 30, 1);
5161 int rm
= extract32(insn
, 16, 5);
5162 int rn
= extract32(insn
, 5, 5);
5163 int rd
= extract32(insn
, 0, 5);
5164 int is_tblx
= extract32(insn
, 12, 1);
5165 int len
= extract32(insn
, 13, 2);
5166 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
5167 TCGv_i32 tcg_regno
, tcg_numregs
;
5170 unallocated_encoding(s
);
5174 if (!fp_access_check(s
)) {
5178 /* This does a table lookup: for every byte element in the input
5179 * we index into a table formed from up to four vector registers,
5180 * and then the output is the result of the lookups. Our helper
5181 * function does the lookup operation for a single 64 bit part of
5184 tcg_resl
= tcg_temp_new_i64();
5185 tcg_resh
= tcg_temp_new_i64();
5188 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5190 tcg_gen_movi_i64(tcg_resl
, 0);
5192 if (is_tblx
&& is_q
) {
5193 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5195 tcg_gen_movi_i64(tcg_resh
, 0);
5198 tcg_idx
= tcg_temp_new_i64();
5199 tcg_regno
= tcg_const_i32(rn
);
5200 tcg_numregs
= tcg_const_i32(len
+ 1);
5201 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
5202 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
5203 tcg_regno
, tcg_numregs
);
5205 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
5206 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
5207 tcg_regno
, tcg_numregs
);
5209 tcg_temp_free_i64(tcg_idx
);
5210 tcg_temp_free_i32(tcg_regno
);
5211 tcg_temp_free_i32(tcg_numregs
);
5213 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5214 tcg_temp_free_i64(tcg_resl
);
5215 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5216 tcg_temp_free_i64(tcg_resh
);
5219 /* C3.6.3 ZIP/UZP/TRN
5220 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
5221 * +---+---+-------------+------+---+------+---+------------------+------+
5222 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
5223 * +---+---+-------------+------+---+------+---+------------------+------+
5225 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
5227 int rd
= extract32(insn
, 0, 5);
5228 int rn
= extract32(insn
, 5, 5);
5229 int rm
= extract32(insn
, 16, 5);
5230 int size
= extract32(insn
, 22, 2);
5231 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
5232 * bit 2 indicates 1 vs 2 variant of the insn.
5234 int opcode
= extract32(insn
, 12, 2);
5235 bool part
= extract32(insn
, 14, 1);
5236 bool is_q
= extract32(insn
, 30, 1);
5237 int esize
= 8 << size
;
5239 int datasize
= is_q
? 128 : 64;
5240 int elements
= datasize
/ esize
;
5241 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
5243 if (opcode
== 0 || (size
== 3 && !is_q
)) {
5244 unallocated_encoding(s
);
5248 if (!fp_access_check(s
)) {
5252 tcg_resl
= tcg_const_i64(0);
5253 tcg_resh
= tcg_const_i64(0);
5254 tcg_res
= tcg_temp_new_i64();
5256 for (i
= 0; i
< elements
; i
++) {
5258 case 1: /* UZP1/2 */
5260 int midpoint
= elements
/ 2;
5262 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
5264 read_vec_element(s
, tcg_res
, rm
,
5265 2 * (i
- midpoint
) + part
, size
);
5269 case 2: /* TRN1/2 */
5271 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
5273 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
5276 case 3: /* ZIP1/2 */
5278 int base
= part
* elements
/ 2;
5280 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
5282 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
5287 g_assert_not_reached();
5292 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
5293 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
5295 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
5296 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
5300 tcg_temp_free_i64(tcg_res
);
5302 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5303 tcg_temp_free_i64(tcg_resl
);
5304 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5305 tcg_temp_free_i64(tcg_resh
);
5308 static void do_minmaxop(DisasContext
*s
, TCGv_i32 tcg_elt1
, TCGv_i32 tcg_elt2
,
5309 int opc
, bool is_min
, TCGv_ptr fpst
)
5311 /* Helper function for disas_simd_across_lanes: do a single precision
5312 * min/max operation on the specified two inputs,
5313 * and return the result in tcg_elt1.
5317 gen_helper_vfp_minnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5319 gen_helper_vfp_maxnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5324 gen_helper_vfp_mins(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5326 gen_helper_vfp_maxs(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5331 /* C3.6.4 AdvSIMD across lanes
5332 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5333 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5334 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5335 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5337 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
5339 int rd
= extract32(insn
, 0, 5);
5340 int rn
= extract32(insn
, 5, 5);
5341 int size
= extract32(insn
, 22, 2);
5342 int opcode
= extract32(insn
, 12, 5);
5343 bool is_q
= extract32(insn
, 30, 1);
5344 bool is_u
= extract32(insn
, 29, 1);
5346 bool is_min
= false;
5350 TCGv_i64 tcg_res
, tcg_elt
;
5353 case 0x1b: /* ADDV */
5355 unallocated_encoding(s
);
5359 case 0x3: /* SADDLV, UADDLV */
5360 case 0xa: /* SMAXV, UMAXV */
5361 case 0x1a: /* SMINV, UMINV */
5362 if (size
== 3 || (size
== 2 && !is_q
)) {
5363 unallocated_encoding(s
);
5367 case 0xc: /* FMAXNMV, FMINNMV */
5368 case 0xf: /* FMAXV, FMINV */
5369 if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
5370 unallocated_encoding(s
);
5373 /* Bit 1 of size field encodes min vs max, and actual size is always
5374 * 32 bits: adjust the size variable so following code can rely on it
5376 is_min
= extract32(size
, 1, 1);
5381 unallocated_encoding(s
);
5385 if (!fp_access_check(s
)) {
5390 elements
= (is_q
? 128 : 64) / esize
;
5392 tcg_res
= tcg_temp_new_i64();
5393 tcg_elt
= tcg_temp_new_i64();
5395 /* These instructions operate across all lanes of a vector
5396 * to produce a single result. We can guarantee that a 64
5397 * bit intermediate is sufficient:
5398 * + for [US]ADDLV the maximum element size is 32 bits, and
5399 * the result type is 64 bits
5400 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
5401 * same as the element size, which is 32 bits at most
5402 * For the integer operations we can choose to work at 64
5403 * or 32 bits and truncate at the end; for simplicity
5404 * we use 64 bits always. The floating point
5405 * ops do require 32 bit intermediates, though.
5408 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
5410 for (i
= 1; i
< elements
; i
++) {
5411 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
5414 case 0x03: /* SADDLV / UADDLV */
5415 case 0x1b: /* ADDV */
5416 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
5418 case 0x0a: /* SMAXV / UMAXV */
5419 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
5421 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5423 case 0x1a: /* SMINV / UMINV */
5424 tcg_gen_movcond_i64(is_u
? TCG_COND_LEU
: TCG_COND_LE
,
5426 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5430 g_assert_not_reached();
5435 /* Floating point ops which work on 32 bit (single) intermediates.
5436 * Note that correct NaN propagation requires that we do these
5437 * operations in exactly the order specified by the pseudocode.
5439 TCGv_i32 tcg_elt1
= tcg_temp_new_i32();
5440 TCGv_i32 tcg_elt2
= tcg_temp_new_i32();
5441 TCGv_i32 tcg_elt3
= tcg_temp_new_i32();
5442 TCGv_ptr fpst
= get_fpstatus_ptr();
5444 assert(esize
== 32);
5445 assert(elements
== 4);
5447 read_vec_element(s
, tcg_elt
, rn
, 0, MO_32
);
5448 tcg_gen_trunc_i64_i32(tcg_elt1
, tcg_elt
);
5449 read_vec_element(s
, tcg_elt
, rn
, 1, MO_32
);
5450 tcg_gen_trunc_i64_i32(tcg_elt2
, tcg_elt
);
5452 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5454 read_vec_element(s
, tcg_elt
, rn
, 2, MO_32
);
5455 tcg_gen_trunc_i64_i32(tcg_elt2
, tcg_elt
);
5456 read_vec_element(s
, tcg_elt
, rn
, 3, MO_32
);
5457 tcg_gen_trunc_i64_i32(tcg_elt3
, tcg_elt
);
5459 do_minmaxop(s
, tcg_elt2
, tcg_elt3
, opcode
, is_min
, fpst
);
5461 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5463 tcg_gen_extu_i32_i64(tcg_res
, tcg_elt1
);
5464 tcg_temp_free_i32(tcg_elt1
);
5465 tcg_temp_free_i32(tcg_elt2
);
5466 tcg_temp_free_i32(tcg_elt3
);
5467 tcg_temp_free_ptr(fpst
);
5470 tcg_temp_free_i64(tcg_elt
);
5472 /* Now truncate the result to the width required for the final output */
5473 if (opcode
== 0x03) {
5474 /* SADDLV, UADDLV: result is 2*esize */
5480 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
5483 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
5486 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
5491 g_assert_not_reached();
5494 write_fp_dreg(s
, rd
, tcg_res
);
5495 tcg_temp_free_i64(tcg_res
);
5498 /* C6.3.31 DUP (Element, Vector)
5500 * 31 30 29 21 20 16 15 10 9 5 4 0
5501 * +---+---+-------------------+--------+-------------+------+------+
5502 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5503 * +---+---+-------------------+--------+-------------+------+------+
5505 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5507 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
5510 int size
= ctz32(imm5
);
5511 int esize
= 8 << size
;
5512 int elements
= (is_q
? 128 : 64) / esize
;
5516 if (size
> 3 || (size
== 3 && !is_q
)) {
5517 unallocated_encoding(s
);
5521 if (!fp_access_check(s
)) {
5525 index
= imm5
>> (size
+ 1);
5527 tmp
= tcg_temp_new_i64();
5528 read_vec_element(s
, tmp
, rn
, index
, size
);
5530 for (i
= 0; i
< elements
; i
++) {
5531 write_vec_element(s
, tmp
, rd
, i
, size
);
5535 clear_vec_high(s
, rd
);
5538 tcg_temp_free_i64(tmp
);
5541 /* C6.3.31 DUP (element, scalar)
5542 * 31 21 20 16 15 10 9 5 4 0
5543 * +-----------------------+--------+-------------+------+------+
5544 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5545 * +-----------------------+--------+-------------+------+------+
5547 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
5550 int size
= ctz32(imm5
);
5555 unallocated_encoding(s
);
5559 if (!fp_access_check(s
)) {
5563 index
= imm5
>> (size
+ 1);
5565 /* This instruction just extracts the specified element and
5566 * zero-extends it into the bottom of the destination register.
5568 tmp
= tcg_temp_new_i64();
5569 read_vec_element(s
, tmp
, rn
, index
, size
);
5570 write_fp_dreg(s
, rd
, tmp
);
5571 tcg_temp_free_i64(tmp
);
5574 /* C6.3.32 DUP (General)
5576 * 31 30 29 21 20 16 15 10 9 5 4 0
5577 * +---+---+-------------------+--------+-------------+------+------+
5578 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
5579 * +---+---+-------------------+--------+-------------+------+------+
5581 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5583 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
5586 int size
= ctz32(imm5
);
5587 int esize
= 8 << size
;
5588 int elements
= (is_q
? 128 : 64)/esize
;
5591 if (size
> 3 || ((size
== 3) && !is_q
)) {
5592 unallocated_encoding(s
);
5596 if (!fp_access_check(s
)) {
5600 for (i
= 0; i
< elements
; i
++) {
5601 write_vec_element(s
, cpu_reg(s
, rn
), rd
, i
, size
);
5604 clear_vec_high(s
, rd
);
5608 /* C6.3.150 INS (Element)
5610 * 31 21 20 16 15 14 11 10 9 5 4 0
5611 * +-----------------------+--------+------------+---+------+------+
5612 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5613 * +-----------------------+--------+------------+---+------+------+
5615 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5616 * index: encoded in imm5<4:size+1>
5618 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
5621 int size
= ctz32(imm5
);
5622 int src_index
, dst_index
;
5626 unallocated_encoding(s
);
5630 if (!fp_access_check(s
)) {
5634 dst_index
= extract32(imm5
, 1+size
, 5);
5635 src_index
= extract32(imm4
, size
, 4);
5637 tmp
= tcg_temp_new_i64();
5639 read_vec_element(s
, tmp
, rn
, src_index
, size
);
5640 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
5642 tcg_temp_free_i64(tmp
);
5646 /* C6.3.151 INS (General)
5648 * 31 21 20 16 15 10 9 5 4 0
5649 * +-----------------------+--------+-------------+------+------+
5650 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
5651 * +-----------------------+--------+-------------+------+------+
5653 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5654 * index: encoded in imm5<4:size+1>
5656 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
5658 int size
= ctz32(imm5
);
5662 unallocated_encoding(s
);
5666 if (!fp_access_check(s
)) {
5670 idx
= extract32(imm5
, 1 + size
, 4 - size
);
5671 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
5675 * C6.3.321 UMOV (General)
5676 * C6.3.237 SMOV (General)
5678 * 31 30 29 21 20 16 15 12 10 9 5 4 0
5679 * +---+---+-------------------+--------+-------------+------+------+
5680 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
5681 * +---+---+-------------------+--------+-------------+------+------+
5683 * U: unsigned when set
5684 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5686 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
5687 int rn
, int rd
, int imm5
)
5689 int size
= ctz32(imm5
);
5693 /* Check for UnallocatedEncodings */
5695 if (size
> 2 || (size
== 2 && !is_q
)) {
5696 unallocated_encoding(s
);
5701 || (size
< 3 && is_q
)
5702 || (size
== 3 && !is_q
)) {
5703 unallocated_encoding(s
);
5708 if (!fp_access_check(s
)) {
5712 element
= extract32(imm5
, 1+size
, 4);
5714 tcg_rd
= cpu_reg(s
, rd
);
5715 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
5716 if (is_signed
&& !is_q
) {
5717 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5721 /* C3.6.5 AdvSIMD copy
5722 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5723 * +---+---+----+-----------------+------+---+------+---+------+------+
5724 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5725 * +---+---+----+-----------------+------+---+------+---+------+------+
5727 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
5729 int rd
= extract32(insn
, 0, 5);
5730 int rn
= extract32(insn
, 5, 5);
5731 int imm4
= extract32(insn
, 11, 4);
5732 int op
= extract32(insn
, 29, 1);
5733 int is_q
= extract32(insn
, 30, 1);
5734 int imm5
= extract32(insn
, 16, 5);
5739 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
5741 unallocated_encoding(s
);
5746 /* DUP (element - vector) */
5747 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
5751 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
5756 handle_simd_insg(s
, rd
, rn
, imm5
);
5758 unallocated_encoding(s
);
5763 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
5764 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
5767 unallocated_encoding(s
);
5773 /* C3.6.6 AdvSIMD modified immediate
5774 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
5775 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5776 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
5777 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5779 * There are a number of operations that can be carried out here:
5780 * MOVI - move (shifted) imm into register
5781 * MVNI - move inverted (shifted) imm into register
5782 * ORR - bitwise OR of (shifted) imm with register
5783 * BIC - bitwise clear of (shifted) imm with register
5785 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
5787 int rd
= extract32(insn
, 0, 5);
5788 int cmode
= extract32(insn
, 12, 4);
5789 int cmode_3_1
= extract32(cmode
, 1, 3);
5790 int cmode_0
= extract32(cmode
, 0, 1);
5791 int o2
= extract32(insn
, 11, 1);
5792 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
5793 bool is_neg
= extract32(insn
, 29, 1);
5794 bool is_q
= extract32(insn
, 30, 1);
5796 TCGv_i64 tcg_rd
, tcg_imm
;
5799 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
5800 unallocated_encoding(s
);
5804 if (!fp_access_check(s
)) {
5808 /* See AdvSIMDExpandImm() in ARM ARM */
5809 switch (cmode_3_1
) {
5810 case 0: /* Replicate(Zeros(24):imm8, 2) */
5811 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
5812 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
5813 case 3: /* Replicate(imm8:Zeros(24), 2) */
5815 int shift
= cmode_3_1
* 8;
5816 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
5819 case 4: /* Replicate(Zeros(8):imm8, 4) */
5820 case 5: /* Replicate(imm8:Zeros(8), 4) */
5822 int shift
= (cmode_3_1
& 0x1) * 8;
5823 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
5828 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
5829 imm
= (abcdefgh
<< 16) | 0xffff;
5831 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
5832 imm
= (abcdefgh
<< 8) | 0xff;
5834 imm
= bitfield_replicate(imm
, 32);
5837 if (!cmode_0
&& !is_neg
) {
5838 imm
= bitfield_replicate(abcdefgh
, 8);
5839 } else if (!cmode_0
&& is_neg
) {
5842 for (i
= 0; i
< 8; i
++) {
5843 if ((abcdefgh
) & (1 << i
)) {
5844 imm
|= 0xffULL
<< (i
* 8);
5847 } else if (cmode_0
) {
5849 imm
= (abcdefgh
& 0x3f) << 48;
5850 if (abcdefgh
& 0x80) {
5851 imm
|= 0x8000000000000000ULL
;
5853 if (abcdefgh
& 0x40) {
5854 imm
|= 0x3fc0000000000000ULL
;
5856 imm
|= 0x4000000000000000ULL
;
5859 imm
= (abcdefgh
& 0x3f) << 19;
5860 if (abcdefgh
& 0x80) {
5863 if (abcdefgh
& 0x40) {
5874 if (cmode_3_1
!= 7 && is_neg
) {
5878 tcg_imm
= tcg_const_i64(imm
);
5879 tcg_rd
= new_tmp_a64(s
);
5881 for (i
= 0; i
< 2; i
++) {
5882 int foffs
= i
? fp_reg_hi_offset(s
, rd
) : fp_reg_offset(s
, rd
, MO_64
);
5884 if (i
== 1 && !is_q
) {
5885 /* non-quad ops clear high half of vector */
5886 tcg_gen_movi_i64(tcg_rd
, 0);
5887 } else if ((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9) {
5888 tcg_gen_ld_i64(tcg_rd
, cpu_env
, foffs
);
5891 tcg_gen_and_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5894 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5898 tcg_gen_mov_i64(tcg_rd
, tcg_imm
);
5900 tcg_gen_st_i64(tcg_rd
, cpu_env
, foffs
);
5903 tcg_temp_free_i64(tcg_imm
);
5906 /* C3.6.7 AdvSIMD scalar copy
5907 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5908 * +-----+----+-----------------+------+---+------+---+------+------+
5909 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5910 * +-----+----+-----------------+------+---+------+---+------+------+
5912 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
5914 int rd
= extract32(insn
, 0, 5);
5915 int rn
= extract32(insn
, 5, 5);
5916 int imm4
= extract32(insn
, 11, 4);
5917 int imm5
= extract32(insn
, 16, 5);
5918 int op
= extract32(insn
, 29, 1);
5920 if (op
!= 0 || imm4
!= 0) {
5921 unallocated_encoding(s
);
5925 /* DUP (element, scalar) */
5926 handle_simd_dupes(s
, rd
, rn
, imm5
);
5929 /* C3.6.8 AdvSIMD scalar pairwise
5930 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5931 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5932 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5933 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5935 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
5937 int u
= extract32(insn
, 29, 1);
5938 int size
= extract32(insn
, 22, 2);
5939 int opcode
= extract32(insn
, 12, 5);
5940 int rn
= extract32(insn
, 5, 5);
5941 int rd
= extract32(insn
, 0, 5);
5944 /* For some ops (the FP ones), size[1] is part of the encoding.
5945 * For ADDP strictly it is not but size[1] is always 1 for valid
5948 opcode
|= (extract32(size
, 1, 1) << 5);
5951 case 0x3b: /* ADDP */
5952 if (u
|| size
!= 3) {
5953 unallocated_encoding(s
);
5956 if (!fp_access_check(s
)) {
5960 TCGV_UNUSED_PTR(fpst
);
5962 case 0xc: /* FMAXNMP */
5963 case 0xd: /* FADDP */
5964 case 0xf: /* FMAXP */
5965 case 0x2c: /* FMINNMP */
5966 case 0x2f: /* FMINP */
5967 /* FP op, size[0] is 32 or 64 bit */
5969 unallocated_encoding(s
);
5972 if (!fp_access_check(s
)) {
5976 size
= extract32(size
, 0, 1) ? 3 : 2;
5977 fpst
= get_fpstatus_ptr();
5980 unallocated_encoding(s
);
5985 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
5986 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
5987 TCGv_i64 tcg_res
= tcg_temp_new_i64();
5989 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
5990 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
5993 case 0x3b: /* ADDP */
5994 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
5996 case 0xc: /* FMAXNMP */
5997 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5999 case 0xd: /* FADDP */
6000 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6002 case 0xf: /* FMAXP */
6003 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6005 case 0x2c: /* FMINNMP */
6006 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6008 case 0x2f: /* FMINP */
6009 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6012 g_assert_not_reached();
6015 write_fp_dreg(s
, rd
, tcg_res
);
6017 tcg_temp_free_i64(tcg_op1
);
6018 tcg_temp_free_i64(tcg_op2
);
6019 tcg_temp_free_i64(tcg_res
);
6021 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6022 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6023 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6025 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_32
);
6026 read_vec_element_i32(s
, tcg_op2
, rn
, 1, MO_32
);
6029 case 0xc: /* FMAXNMP */
6030 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6032 case 0xd: /* FADDP */
6033 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6035 case 0xf: /* FMAXP */
6036 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6038 case 0x2c: /* FMINNMP */
6039 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6041 case 0x2f: /* FMINP */
6042 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6045 g_assert_not_reached();
6048 write_fp_sreg(s
, rd
, tcg_res
);
6050 tcg_temp_free_i32(tcg_op1
);
6051 tcg_temp_free_i32(tcg_op2
);
6052 tcg_temp_free_i32(tcg_res
);
6055 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
6056 tcg_temp_free_ptr(fpst
);
6061 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
6063 * This code is handles the common shifting code and is used by both
6064 * the vector and scalar code.
6066 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6067 TCGv_i64 tcg_rnd
, bool accumulate
,
6068 bool is_u
, int size
, int shift
)
6070 bool extended_result
= false;
6071 bool round
= !TCGV_IS_UNUSED_I64(tcg_rnd
);
6073 TCGv_i64 tcg_src_hi
;
6075 if (round
&& size
== 3) {
6076 extended_result
= true;
6077 ext_lshift
= 64 - shift
;
6078 tcg_src_hi
= tcg_temp_new_i64();
6079 } else if (shift
== 64) {
6080 if (!accumulate
&& is_u
) {
6081 /* result is zero */
6082 tcg_gen_movi_i64(tcg_res
, 0);
6087 /* Deal with the rounding step */
6089 if (extended_result
) {
6090 TCGv_i64 tcg_zero
= tcg_const_i64(0);
6092 /* take care of sign extending tcg_res */
6093 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
6094 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6095 tcg_src
, tcg_src_hi
,
6098 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6102 tcg_temp_free_i64(tcg_zero
);
6104 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
6108 /* Now do the shift right */
6109 if (round
&& extended_result
) {
6110 /* extended case, >64 bit precision required */
6111 if (ext_lshift
== 0) {
6112 /* special case, only high bits matter */
6113 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
6115 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6116 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
6117 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
6122 /* essentially shifting in 64 zeros */
6123 tcg_gen_movi_i64(tcg_src
, 0);
6125 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6129 /* effectively extending the sign-bit */
6130 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
6132 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
6138 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
6140 tcg_gen_mov_i64(tcg_res
, tcg_src
);
6143 if (extended_result
) {
6144 tcg_temp_free_i64(tcg_src_hi
);
6148 /* Common SHL/SLI - Shift left with an optional insert */
6149 static void handle_shli_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6150 bool insert
, int shift
)
6152 if (insert
) { /* SLI */
6153 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, shift
, 64 - shift
);
6155 tcg_gen_shli_i64(tcg_res
, tcg_src
, shift
);
6159 /* SRI: shift right with insert */
6160 static void handle_shri_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6161 int size
, int shift
)
6163 int esize
= 8 << size
;
6165 /* shift count same as element size is valid but does nothing;
6166 * special case to avoid potential shift by 64.
6168 if (shift
!= esize
) {
6169 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6170 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, 0, esize
- shift
);
6174 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
6175 static void handle_scalar_simd_shri(DisasContext
*s
,
6176 bool is_u
, int immh
, int immb
,
6177 int opcode
, int rn
, int rd
)
6180 int immhb
= immh
<< 3 | immb
;
6181 int shift
= 2 * (8 << size
) - immhb
;
6182 bool accumulate
= false;
6184 bool insert
= false;
6189 if (!extract32(immh
, 3, 1)) {
6190 unallocated_encoding(s
);
6194 if (!fp_access_check(s
)) {
6199 case 0x02: /* SSRA / USRA (accumulate) */
6202 case 0x04: /* SRSHR / URSHR (rounding) */
6205 case 0x06: /* SRSRA / URSRA (accum + rounding) */
6206 accumulate
= round
= true;
6208 case 0x08: /* SRI */
6214 uint64_t round_const
= 1ULL << (shift
- 1);
6215 tcg_round
= tcg_const_i64(round_const
);
6217 TCGV_UNUSED_I64(tcg_round
);
6220 tcg_rn
= read_fp_dreg(s
, rn
);
6221 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6224 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
6226 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6227 accumulate
, is_u
, size
, shift
);
6230 write_fp_dreg(s
, rd
, tcg_rd
);
6232 tcg_temp_free_i64(tcg_rn
);
6233 tcg_temp_free_i64(tcg_rd
);
6235 tcg_temp_free_i64(tcg_round
);
6239 /* SHL/SLI - Scalar shift left */
6240 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
6241 int immh
, int immb
, int opcode
,
6244 int size
= 32 - clz32(immh
) - 1;
6245 int immhb
= immh
<< 3 | immb
;
6246 int shift
= immhb
- (8 << size
);
6247 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
6248 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
6250 if (!extract32(immh
, 3, 1)) {
6251 unallocated_encoding(s
);
6255 if (!fp_access_check(s
)) {
6259 tcg_rn
= read_fp_dreg(s
, rn
);
6260 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6262 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
6264 write_fp_dreg(s
, rd
, tcg_rd
);
6266 tcg_temp_free_i64(tcg_rn
);
6267 tcg_temp_free_i64(tcg_rd
);
6270 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
6271 * (signed/unsigned) narrowing */
6272 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
6273 bool is_u_shift
, bool is_u_narrow
,
6274 int immh
, int immb
, int opcode
,
6277 int immhb
= immh
<< 3 | immb
;
6278 int size
= 32 - clz32(immh
) - 1;
6279 int esize
= 8 << size
;
6280 int shift
= (2 * esize
) - immhb
;
6281 int elements
= is_scalar
? 1 : (64 / esize
);
6282 bool round
= extract32(opcode
, 0, 1);
6283 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
6284 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
6285 TCGv_i32 tcg_rd_narrowed
;
6288 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
6289 { gen_helper_neon_narrow_sat_s8
,
6290 gen_helper_neon_unarrow_sat8
},
6291 { gen_helper_neon_narrow_sat_s16
,
6292 gen_helper_neon_unarrow_sat16
},
6293 { gen_helper_neon_narrow_sat_s32
,
6294 gen_helper_neon_unarrow_sat32
},
6297 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
6298 gen_helper_neon_narrow_sat_u8
,
6299 gen_helper_neon_narrow_sat_u16
,
6300 gen_helper_neon_narrow_sat_u32
,
6303 NeonGenNarrowEnvFn
*narrowfn
;
6309 if (extract32(immh
, 3, 1)) {
6310 unallocated_encoding(s
);
6314 if (!fp_access_check(s
)) {
6319 narrowfn
= unsigned_narrow_fns
[size
];
6321 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
6324 tcg_rn
= tcg_temp_new_i64();
6325 tcg_rd
= tcg_temp_new_i64();
6326 tcg_rd_narrowed
= tcg_temp_new_i32();
6327 tcg_final
= tcg_const_i64(0);
6330 uint64_t round_const
= 1ULL << (shift
- 1);
6331 tcg_round
= tcg_const_i64(round_const
);
6333 TCGV_UNUSED_I64(tcg_round
);
6336 for (i
= 0; i
< elements
; i
++) {
6337 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
6338 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6339 false, is_u_shift
, size
+1, shift
);
6340 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
6341 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
6342 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
6346 clear_vec_high(s
, rd
);
6347 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
6349 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
6353 tcg_temp_free_i64(tcg_round
);
6355 tcg_temp_free_i64(tcg_rn
);
6356 tcg_temp_free_i64(tcg_rd
);
6357 tcg_temp_free_i32(tcg_rd_narrowed
);
6358 tcg_temp_free_i64(tcg_final
);
6362 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
6363 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
6364 bool src_unsigned
, bool dst_unsigned
,
6365 int immh
, int immb
, int rn
, int rd
)
6367 int immhb
= immh
<< 3 | immb
;
6368 int size
= 32 - clz32(immh
) - 1;
6369 int shift
= immhb
- (8 << size
);
6373 assert(!(scalar
&& is_q
));
6376 if (!is_q
&& extract32(immh
, 3, 1)) {
6377 unallocated_encoding(s
);
6381 /* Since we use the variable-shift helpers we must
6382 * replicate the shift count into each element of
6383 * the tcg_shift value.
6387 shift
|= shift
<< 8;
6390 shift
|= shift
<< 16;
6396 g_assert_not_reached();
6400 if (!fp_access_check(s
)) {
6405 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
6406 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
6407 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
6408 { NULL
, gen_helper_neon_qshl_u64
},
6410 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
6411 int maxpass
= is_q
? 2 : 1;
6413 for (pass
= 0; pass
< maxpass
; pass
++) {
6414 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6416 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6417 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6418 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6420 tcg_temp_free_i64(tcg_op
);
6422 tcg_temp_free_i64(tcg_shift
);
6425 clear_vec_high(s
, rd
);
6428 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
6429 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
6431 { gen_helper_neon_qshl_s8
,
6432 gen_helper_neon_qshl_s16
,
6433 gen_helper_neon_qshl_s32
},
6434 { gen_helper_neon_qshlu_s8
,
6435 gen_helper_neon_qshlu_s16
,
6436 gen_helper_neon_qshlu_s32
}
6438 { NULL
, NULL
, NULL
},
6439 { gen_helper_neon_qshl_u8
,
6440 gen_helper_neon_qshl_u16
,
6441 gen_helper_neon_qshl_u32
}
6444 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
6445 TCGMemOp memop
= scalar
? size
: MO_32
;
6446 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
6448 for (pass
= 0; pass
< maxpass
; pass
++) {
6449 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6451 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
6452 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6456 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
6459 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
6464 g_assert_not_reached();
6466 write_fp_sreg(s
, rd
, tcg_op
);
6468 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6471 tcg_temp_free_i32(tcg_op
);
6473 tcg_temp_free_i32(tcg_shift
);
6475 if (!is_q
&& !scalar
) {
6476 clear_vec_high(s
, rd
);
6481 /* Common vector code for handling integer to FP conversion */
6482 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
6483 int elements
, int is_signed
,
6484 int fracbits
, int size
)
6486 bool is_double
= size
== 3 ? true : false;
6487 TCGv_ptr tcg_fpst
= get_fpstatus_ptr();
6488 TCGv_i32 tcg_shift
= tcg_const_i32(fracbits
);
6489 TCGv_i64 tcg_int
= tcg_temp_new_i64();
6490 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
6493 for (pass
= 0; pass
< elements
; pass
++) {
6494 read_vec_element(s
, tcg_int
, rn
, pass
, mop
);
6497 TCGv_i64 tcg_double
= tcg_temp_new_i64();
6499 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6500 tcg_shift
, tcg_fpst
);
6502 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6503 tcg_shift
, tcg_fpst
);
6505 if (elements
== 1) {
6506 write_fp_dreg(s
, rd
, tcg_double
);
6508 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
6510 tcg_temp_free_i64(tcg_double
);
6512 TCGv_i32 tcg_single
= tcg_temp_new_i32();
6514 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6515 tcg_shift
, tcg_fpst
);
6517 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6518 tcg_shift
, tcg_fpst
);
6520 if (elements
== 1) {
6521 write_fp_sreg(s
, rd
, tcg_single
);
6523 write_vec_element_i32(s
, tcg_single
, rd
, pass
, MO_32
);
6525 tcg_temp_free_i32(tcg_single
);
6529 if (!is_double
&& elements
== 2) {
6530 clear_vec_high(s
, rd
);
6533 tcg_temp_free_i64(tcg_int
);
6534 tcg_temp_free_ptr(tcg_fpst
);
6535 tcg_temp_free_i32(tcg_shift
);
6538 /* UCVTF/SCVTF - Integer to FP conversion */
6539 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
6540 bool is_q
, bool is_u
,
6541 int immh
, int immb
, int opcode
,
6544 bool is_double
= extract32(immh
, 3, 1);
6545 int size
= is_double
? MO_64
: MO_32
;
6547 int immhb
= immh
<< 3 | immb
;
6548 int fracbits
= (is_double
? 128 : 64) - immhb
;
6550 if (!extract32(immh
, 2, 2)) {
6551 unallocated_encoding(s
);
6558 elements
= is_double
? 2 : is_q
? 4 : 2;
6559 if (is_double
&& !is_q
) {
6560 unallocated_encoding(s
);
6565 if (!fp_access_check(s
)) {
6569 /* immh == 0 would be a failure of the decode logic */
6572 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
6575 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
6576 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
6577 bool is_q
, bool is_u
,
6578 int immh
, int immb
, int rn
, int rd
)
6580 bool is_double
= extract32(immh
, 3, 1);
6581 int immhb
= immh
<< 3 | immb
;
6582 int fracbits
= (is_double
? 128 : 64) - immhb
;
6584 TCGv_ptr tcg_fpstatus
;
6585 TCGv_i32 tcg_rmode
, tcg_shift
;
6587 if (!extract32(immh
, 2, 2)) {
6588 unallocated_encoding(s
);
6592 if (!is_scalar
&& !is_q
&& is_double
) {
6593 unallocated_encoding(s
);
6597 if (!fp_access_check(s
)) {
6601 assert(!(is_scalar
&& is_q
));
6603 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
6604 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6605 tcg_fpstatus
= get_fpstatus_ptr();
6606 tcg_shift
= tcg_const_i32(fracbits
);
6609 int maxpass
= is_scalar
? 1 : 2;
6611 for (pass
= 0; pass
< maxpass
; pass
++) {
6612 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6614 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6616 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6618 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6620 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6621 tcg_temp_free_i64(tcg_op
);
6624 clear_vec_high(s
, rd
);
6627 int maxpass
= is_scalar
? 1 : is_q
? 4 : 2;
6628 for (pass
= 0; pass
< maxpass
; pass
++) {
6629 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6631 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
6633 gen_helper_vfp_touls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6635 gen_helper_vfp_tosls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6638 write_fp_sreg(s
, rd
, tcg_op
);
6640 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6642 tcg_temp_free_i32(tcg_op
);
6644 if (!is_q
&& !is_scalar
) {
6645 clear_vec_high(s
, rd
);
6649 tcg_temp_free_ptr(tcg_fpstatus
);
6650 tcg_temp_free_i32(tcg_shift
);
6651 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6652 tcg_temp_free_i32(tcg_rmode
);
6655 /* C3.6.9 AdvSIMD scalar shift by immediate
6656 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
6657 * +-----+---+-------------+------+------+--------+---+------+------+
6658 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
6659 * +-----+---+-------------+------+------+--------+---+------+------+
6661 * This is the scalar version so it works on a fixed sized registers
6663 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
6665 int rd
= extract32(insn
, 0, 5);
6666 int rn
= extract32(insn
, 5, 5);
6667 int opcode
= extract32(insn
, 11, 5);
6668 int immb
= extract32(insn
, 16, 3);
6669 int immh
= extract32(insn
, 19, 4);
6670 bool is_u
= extract32(insn
, 29, 1);
6673 unallocated_encoding(s
);
6678 case 0x08: /* SRI */
6680 unallocated_encoding(s
);
6684 case 0x00: /* SSHR / USHR */
6685 case 0x02: /* SSRA / USRA */
6686 case 0x04: /* SRSHR / URSHR */
6687 case 0x06: /* SRSRA / URSRA */
6688 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6690 case 0x0a: /* SHL / SLI */
6691 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6693 case 0x1c: /* SCVTF, UCVTF */
6694 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
6697 case 0x10: /* SQSHRUN, SQSHRUN2 */
6698 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
6700 unallocated_encoding(s
);
6703 handle_vec_simd_sqshrn(s
, true, false, false, true,
6704 immh
, immb
, opcode
, rn
, rd
);
6706 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
6707 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
6708 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
6709 immh
, immb
, opcode
, rn
, rd
);
6711 case 0xc: /* SQSHLU */
6713 unallocated_encoding(s
);
6716 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
6718 case 0xe: /* SQSHL, UQSHL */
6719 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
6721 case 0x1f: /* FCVTZS, FCVTZU */
6722 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
6725 unallocated_encoding(s
);
6730 /* C3.6.10 AdvSIMD scalar three different
6731 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6732 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6733 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
6734 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6736 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
6738 bool is_u
= extract32(insn
, 29, 1);
6739 int size
= extract32(insn
, 22, 2);
6740 int opcode
= extract32(insn
, 12, 4);
6741 int rm
= extract32(insn
, 16, 5);
6742 int rn
= extract32(insn
, 5, 5);
6743 int rd
= extract32(insn
, 0, 5);
6746 unallocated_encoding(s
);
6751 case 0x9: /* SQDMLAL, SQDMLAL2 */
6752 case 0xb: /* SQDMLSL, SQDMLSL2 */
6753 case 0xd: /* SQDMULL, SQDMULL2 */
6754 if (size
== 0 || size
== 3) {
6755 unallocated_encoding(s
);
6760 unallocated_encoding(s
);
6764 if (!fp_access_check(s
)) {
6769 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6770 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6771 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6773 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
6774 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
6776 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
6777 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6780 case 0xd: /* SQDMULL, SQDMULL2 */
6782 case 0xb: /* SQDMLSL, SQDMLSL2 */
6783 tcg_gen_neg_i64(tcg_res
, tcg_res
);
6785 case 0x9: /* SQDMLAL, SQDMLAL2 */
6786 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
6787 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
6791 g_assert_not_reached();
6794 write_fp_dreg(s
, rd
, tcg_res
);
6796 tcg_temp_free_i64(tcg_op1
);
6797 tcg_temp_free_i64(tcg_op2
);
6798 tcg_temp_free_i64(tcg_res
);
6800 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6801 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6802 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6804 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_16
);
6805 read_vec_element_i32(s
, tcg_op2
, rm
, 0, MO_16
);
6807 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
6808 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6811 case 0xd: /* SQDMULL, SQDMULL2 */
6813 case 0xb: /* SQDMLSL, SQDMLSL2 */
6814 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
6816 case 0x9: /* SQDMLAL, SQDMLAL2 */
6818 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
6819 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
6820 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
6822 tcg_temp_free_i64(tcg_op3
);
6826 g_assert_not_reached();
6829 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
6830 write_fp_dreg(s
, rd
, tcg_res
);
6832 tcg_temp_free_i32(tcg_op1
);
6833 tcg_temp_free_i32(tcg_op2
);
6834 tcg_temp_free_i64(tcg_res
);
6838 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
6839 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
6841 /* Handle 64x64->64 opcodes which are shared between the scalar
6842 * and vector 3-same groups. We cover every opcode where size == 3
6843 * is valid in either the three-reg-same (integer, not pairwise)
6844 * or scalar-three-reg-same groups. (Some opcodes are not yet
6850 case 0x1: /* SQADD */
6852 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6854 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6857 case 0x5: /* SQSUB */
6859 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6861 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6864 case 0x6: /* CMGT, CMHI */
6865 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
6866 * We implement this using setcond (test) and then negating.
6868 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
6870 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
6871 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6873 case 0x7: /* CMGE, CMHS */
6874 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
6876 case 0x11: /* CMTST, CMEQ */
6881 /* CMTST : test is "if (X & Y != 0)". */
6882 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6883 tcg_gen_setcondi_i64(TCG_COND_NE
, tcg_rd
, tcg_rd
, 0);
6884 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6886 case 0x8: /* SSHL, USHL */
6888 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6890 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
6893 case 0x9: /* SQSHL, UQSHL */
6895 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6897 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6900 case 0xa: /* SRSHL, URSHL */
6902 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6904 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
6907 case 0xb: /* SQRSHL, UQRSHL */
6909 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6911 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6914 case 0x10: /* ADD, SUB */
6916 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6918 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6922 g_assert_not_reached();
6926 /* Handle the 3-same-operands float operations; shared by the scalar
6927 * and vector encodings. The caller must filter out any encodings
6928 * not allocated for the encoding it is dealing with.
6930 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
6931 int fpopcode
, int rd
, int rn
, int rm
)
6934 TCGv_ptr fpst
= get_fpstatus_ptr();
6936 for (pass
= 0; pass
< elements
; pass
++) {
6939 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6940 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6941 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6943 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
6944 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
6947 case 0x39: /* FMLS */
6948 /* As usual for ARM, separate negation for fused multiply-add */
6949 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
6951 case 0x19: /* FMLA */
6952 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
6953 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
6956 case 0x18: /* FMAXNM */
6957 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6959 case 0x1a: /* FADD */
6960 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6962 case 0x1b: /* FMULX */
6963 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6965 case 0x1c: /* FCMEQ */
6966 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6968 case 0x1e: /* FMAX */
6969 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6971 case 0x1f: /* FRECPS */
6972 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6974 case 0x38: /* FMINNM */
6975 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6977 case 0x3a: /* FSUB */
6978 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6980 case 0x3e: /* FMIN */
6981 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6983 case 0x3f: /* FRSQRTS */
6984 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6986 case 0x5b: /* FMUL */
6987 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6989 case 0x5c: /* FCMGE */
6990 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6992 case 0x5d: /* FACGE */
6993 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6995 case 0x5f: /* FDIV */
6996 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6998 case 0x7a: /* FABD */
6999 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7000 gen_helper_vfp_absd(tcg_res
, tcg_res
);
7002 case 0x7c: /* FCMGT */
7003 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7005 case 0x7d: /* FACGT */
7006 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7009 g_assert_not_reached();
7012 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7014 tcg_temp_free_i64(tcg_res
);
7015 tcg_temp_free_i64(tcg_op1
);
7016 tcg_temp_free_i64(tcg_op2
);
7019 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
7020 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
7021 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7023 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
7024 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
7027 case 0x39: /* FMLS */
7028 /* As usual for ARM, separate negation for fused multiply-add */
7029 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
7031 case 0x19: /* FMLA */
7032 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7033 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
7036 case 0x1a: /* FADD */
7037 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7039 case 0x1b: /* FMULX */
7040 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7042 case 0x1c: /* FCMEQ */
7043 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7045 case 0x1e: /* FMAX */
7046 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7048 case 0x1f: /* FRECPS */
7049 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7051 case 0x18: /* FMAXNM */
7052 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7054 case 0x38: /* FMINNM */
7055 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7057 case 0x3a: /* FSUB */
7058 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7060 case 0x3e: /* FMIN */
7061 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7063 case 0x3f: /* FRSQRTS */
7064 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7066 case 0x5b: /* FMUL */
7067 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7069 case 0x5c: /* FCMGE */
7070 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7072 case 0x5d: /* FACGE */
7073 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7075 case 0x5f: /* FDIV */
7076 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7078 case 0x7a: /* FABD */
7079 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7080 gen_helper_vfp_abss(tcg_res
, tcg_res
);
7082 case 0x7c: /* FCMGT */
7083 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7085 case 0x7d: /* FACGT */
7086 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7089 g_assert_not_reached();
7092 if (elements
== 1) {
7093 /* scalar single so clear high part */
7094 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
7096 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
7097 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
7098 tcg_temp_free_i64(tcg_tmp
);
7100 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7103 tcg_temp_free_i32(tcg_res
);
7104 tcg_temp_free_i32(tcg_op1
);
7105 tcg_temp_free_i32(tcg_op2
);
7109 tcg_temp_free_ptr(fpst
);
7111 if ((elements
<< size
) < 4) {
7112 /* scalar, or non-quad vector op */
7113 clear_vec_high(s
, rd
);
7117 /* C3.6.11 AdvSIMD scalar three same
7118 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
7119 * +-----+---+-----------+------+---+------+--------+---+------+------+
7120 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
7121 * +-----+---+-----------+------+---+------+--------+---+------+------+
7123 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
7125 int rd
= extract32(insn
, 0, 5);
7126 int rn
= extract32(insn
, 5, 5);
7127 int opcode
= extract32(insn
, 11, 5);
7128 int rm
= extract32(insn
, 16, 5);
7129 int size
= extract32(insn
, 22, 2);
7130 bool u
= extract32(insn
, 29, 1);
7133 if (opcode
>= 0x18) {
7134 /* Floating point: U, size[1] and opcode indicate operation */
7135 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
7137 case 0x1b: /* FMULX */
7138 case 0x1f: /* FRECPS */
7139 case 0x3f: /* FRSQRTS */
7140 case 0x5d: /* FACGE */
7141 case 0x7d: /* FACGT */
7142 case 0x1c: /* FCMEQ */
7143 case 0x5c: /* FCMGE */
7144 case 0x7c: /* FCMGT */
7145 case 0x7a: /* FABD */
7148 unallocated_encoding(s
);
7152 if (!fp_access_check(s
)) {
7156 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
7161 case 0x1: /* SQADD, UQADD */
7162 case 0x5: /* SQSUB, UQSUB */
7163 case 0x9: /* SQSHL, UQSHL */
7164 case 0xb: /* SQRSHL, UQRSHL */
7166 case 0x8: /* SSHL, USHL */
7167 case 0xa: /* SRSHL, URSHL */
7168 case 0x6: /* CMGT, CMHI */
7169 case 0x7: /* CMGE, CMHS */
7170 case 0x11: /* CMTST, CMEQ */
7171 case 0x10: /* ADD, SUB (vector) */
7173 unallocated_encoding(s
);
7177 case 0x16: /* SQDMULH, SQRDMULH (vector) */
7178 if (size
!= 1 && size
!= 2) {
7179 unallocated_encoding(s
);
7184 unallocated_encoding(s
);
7188 if (!fp_access_check(s
)) {
7192 tcg_rd
= tcg_temp_new_i64();
7195 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7196 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
7198 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
7199 tcg_temp_free_i64(tcg_rn
);
7200 tcg_temp_free_i64(tcg_rm
);
7202 /* Do a single operation on the lowest element in the vector.
7203 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
7204 * no side effects for all these operations.
7205 * OPTME: special-purpose helpers would avoid doing some
7206 * unnecessary work in the helper for the 8 and 16 bit cases.
7208 NeonGenTwoOpEnvFn
*genenvfn
;
7209 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7210 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
7211 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
7213 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7214 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
7217 case 0x1: /* SQADD, UQADD */
7219 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7220 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
7221 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
7222 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
7224 genenvfn
= fns
[size
][u
];
7227 case 0x5: /* SQSUB, UQSUB */
7229 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7230 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
7231 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
7232 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
7234 genenvfn
= fns
[size
][u
];
7237 case 0x9: /* SQSHL, UQSHL */
7239 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7240 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
7241 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
7242 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
7244 genenvfn
= fns
[size
][u
];
7247 case 0xb: /* SQRSHL, UQRSHL */
7249 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7250 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
7251 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
7252 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
7254 genenvfn
= fns
[size
][u
];
7257 case 0x16: /* SQDMULH, SQRDMULH */
7259 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
7260 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
7261 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
7263 assert(size
== 1 || size
== 2);
7264 genenvfn
= fns
[size
- 1][u
];
7268 g_assert_not_reached();
7271 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
7272 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
7273 tcg_temp_free_i32(tcg_rd32
);
7274 tcg_temp_free_i32(tcg_rn
);
7275 tcg_temp_free_i32(tcg_rm
);
7278 write_fp_dreg(s
, rd
, tcg_rd
);
7280 tcg_temp_free_i64(tcg_rd
);
7283 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
7284 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
7285 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
7287 /* Handle 64->64 opcodes which are shared between the scalar and
7288 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
7289 * is valid in either group and also the double-precision fp ops.
7290 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
7296 case 0x4: /* CLS, CLZ */
7298 gen_helper_clz64(tcg_rd
, tcg_rn
);
7300 gen_helper_cls64(tcg_rd
, tcg_rn
);
7304 /* This opcode is shared with CNT and RBIT but we have earlier
7305 * enforced that size == 3 if and only if this is the NOT insn.
7307 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
7309 case 0x7: /* SQABS, SQNEG */
7311 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
7313 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
7316 case 0xa: /* CMLT */
7317 /* 64 bit integer comparison against zero, result is
7318 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
7323 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
7324 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7326 case 0x8: /* CMGT, CMGE */
7327 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
7329 case 0x9: /* CMEQ, CMLE */
7330 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
7332 case 0xb: /* ABS, NEG */
7334 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7336 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7337 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7338 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
7340 tcg_temp_free_i64(tcg_zero
);
7343 case 0x2f: /* FABS */
7344 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
7346 case 0x6f: /* FNEG */
7347 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
7349 case 0x7f: /* FSQRT */
7350 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
7352 case 0x1a: /* FCVTNS */
7353 case 0x1b: /* FCVTMS */
7354 case 0x1c: /* FCVTAS */
7355 case 0x3a: /* FCVTPS */
7356 case 0x3b: /* FCVTZS */
7358 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7359 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7360 tcg_temp_free_i32(tcg_shift
);
7363 case 0x5a: /* FCVTNU */
7364 case 0x5b: /* FCVTMU */
7365 case 0x5c: /* FCVTAU */
7366 case 0x7a: /* FCVTPU */
7367 case 0x7b: /* FCVTZU */
7369 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7370 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7371 tcg_temp_free_i32(tcg_shift
);
7374 case 0x18: /* FRINTN */
7375 case 0x19: /* FRINTM */
7376 case 0x38: /* FRINTP */
7377 case 0x39: /* FRINTZ */
7378 case 0x58: /* FRINTA */
7379 case 0x79: /* FRINTI */
7380 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7382 case 0x59: /* FRINTX */
7383 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7386 g_assert_not_reached();
7390 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
7391 bool is_scalar
, bool is_u
, bool is_q
,
7392 int size
, int rn
, int rd
)
7394 bool is_double
= (size
== 3);
7397 if (!fp_access_check(s
)) {
7401 fpst
= get_fpstatus_ptr();
7404 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7405 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7406 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7407 NeonGenTwoDoubleOPFn
*genfn
;
7412 case 0x2e: /* FCMLT (zero) */
7415 case 0x2c: /* FCMGT (zero) */
7416 genfn
= gen_helper_neon_cgt_f64
;
7418 case 0x2d: /* FCMEQ (zero) */
7419 genfn
= gen_helper_neon_ceq_f64
;
7421 case 0x6d: /* FCMLE (zero) */
7424 case 0x6c: /* FCMGE (zero) */
7425 genfn
= gen_helper_neon_cge_f64
;
7428 g_assert_not_reached();
7431 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7432 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7434 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7436 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7438 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7441 clear_vec_high(s
, rd
);
7444 tcg_temp_free_i64(tcg_res
);
7445 tcg_temp_free_i64(tcg_zero
);
7446 tcg_temp_free_i64(tcg_op
);
7448 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7449 TCGv_i32 tcg_zero
= tcg_const_i32(0);
7450 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7451 NeonGenTwoSingleOPFn
*genfn
;
7453 int pass
, maxpasses
;
7456 case 0x2e: /* FCMLT (zero) */
7459 case 0x2c: /* FCMGT (zero) */
7460 genfn
= gen_helper_neon_cgt_f32
;
7462 case 0x2d: /* FCMEQ (zero) */
7463 genfn
= gen_helper_neon_ceq_f32
;
7465 case 0x6d: /* FCMLE (zero) */
7468 case 0x6c: /* FCMGE (zero) */
7469 genfn
= gen_helper_neon_cge_f32
;
7472 g_assert_not_reached();
7478 maxpasses
= is_q
? 4 : 2;
7481 for (pass
= 0; pass
< maxpasses
; pass
++) {
7482 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7484 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7486 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7489 write_fp_sreg(s
, rd
, tcg_res
);
7491 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7494 tcg_temp_free_i32(tcg_res
);
7495 tcg_temp_free_i32(tcg_zero
);
7496 tcg_temp_free_i32(tcg_op
);
7497 if (!is_q
&& !is_scalar
) {
7498 clear_vec_high(s
, rd
);
7502 tcg_temp_free_ptr(fpst
);
7505 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
7506 bool is_scalar
, bool is_u
, bool is_q
,
7507 int size
, int rn
, int rd
)
7509 bool is_double
= (size
== 3);
7510 TCGv_ptr fpst
= get_fpstatus_ptr();
7513 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7514 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7517 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7518 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7520 case 0x3d: /* FRECPE */
7521 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
7523 case 0x3f: /* FRECPX */
7524 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
7526 case 0x7d: /* FRSQRTE */
7527 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
7530 g_assert_not_reached();
7532 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7535 clear_vec_high(s
, rd
);
7538 tcg_temp_free_i64(tcg_res
);
7539 tcg_temp_free_i64(tcg_op
);
7541 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7542 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7543 int pass
, maxpasses
;
7548 maxpasses
= is_q
? 4 : 2;
7551 for (pass
= 0; pass
< maxpasses
; pass
++) {
7552 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7555 case 0x3c: /* URECPE */
7556 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
7558 case 0x3d: /* FRECPE */
7559 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
7561 case 0x3f: /* FRECPX */
7562 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
7564 case 0x7d: /* FRSQRTE */
7565 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
7568 g_assert_not_reached();
7572 write_fp_sreg(s
, rd
, tcg_res
);
7574 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7577 tcg_temp_free_i32(tcg_res
);
7578 tcg_temp_free_i32(tcg_op
);
7579 if (!is_q
&& !is_scalar
) {
7580 clear_vec_high(s
, rd
);
7583 tcg_temp_free_ptr(fpst
);
7586 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
7587 int opcode
, bool u
, bool is_q
,
7588 int size
, int rn
, int rd
)
7590 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
7591 * in the source becomes a size element in the destination).
7594 TCGv_i32 tcg_res
[2];
7595 int destelt
= is_q
? 2 : 0;
7596 int passes
= scalar
? 1 : 2;
7599 tcg_res
[1] = tcg_const_i32(0);
7602 for (pass
= 0; pass
< passes
; pass
++) {
7603 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7604 NeonGenNarrowFn
*genfn
= NULL
;
7605 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
7608 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
7610 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7612 tcg_res
[pass
] = tcg_temp_new_i32();
7615 case 0x12: /* XTN, SQXTUN */
7617 static NeonGenNarrowFn
* const xtnfns
[3] = {
7618 gen_helper_neon_narrow_u8
,
7619 gen_helper_neon_narrow_u16
,
7620 tcg_gen_trunc_i64_i32
,
7622 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
7623 gen_helper_neon_unarrow_sat8
,
7624 gen_helper_neon_unarrow_sat16
,
7625 gen_helper_neon_unarrow_sat32
,
7628 genenvfn
= sqxtunfns
[size
];
7630 genfn
= xtnfns
[size
];
7634 case 0x14: /* SQXTN, UQXTN */
7636 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
7637 { gen_helper_neon_narrow_sat_s8
,
7638 gen_helper_neon_narrow_sat_u8
},
7639 { gen_helper_neon_narrow_sat_s16
,
7640 gen_helper_neon_narrow_sat_u16
},
7641 { gen_helper_neon_narrow_sat_s32
,
7642 gen_helper_neon_narrow_sat_u32
},
7644 genenvfn
= fns
[size
][u
];
7647 case 0x16: /* FCVTN, FCVTN2 */
7648 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
7650 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
7652 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
7653 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
7654 tcg_gen_trunc_i64_i32(tcg_lo
, tcg_op
);
7655 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, cpu_env
);
7656 tcg_gen_shri_i64(tcg_op
, tcg_op
, 32);
7657 tcg_gen_trunc_i64_i32(tcg_hi
, tcg_op
);
7658 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, cpu_env
);
7659 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
7660 tcg_temp_free_i32(tcg_lo
);
7661 tcg_temp_free_i32(tcg_hi
);
7664 case 0x56: /* FCVTXN, FCVTXN2 */
7665 /* 64 bit to 32 bit float conversion
7666 * with von Neumann rounding (round to odd)
7669 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
7672 g_assert_not_reached();
7676 genfn(tcg_res
[pass
], tcg_op
);
7677 } else if (genenvfn
) {
7678 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
7681 tcg_temp_free_i64(tcg_op
);
7684 for (pass
= 0; pass
< 2; pass
++) {
7685 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
7686 tcg_temp_free_i32(tcg_res
[pass
]);
7689 clear_vec_high(s
, rd
);
7693 /* Remaining saturating accumulating ops */
7694 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
7695 bool is_q
, int size
, int rn
, int rd
)
7697 bool is_double
= (size
== 3);
7700 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
7701 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7704 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7705 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
7706 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7708 if (is_u
) { /* USQADD */
7709 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7710 } else { /* SUQADD */
7711 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7713 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7716 clear_vec_high(s
, rd
);
7719 tcg_temp_free_i64(tcg_rd
);
7720 tcg_temp_free_i64(tcg_rn
);
7722 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7723 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7724 int pass
, maxpasses
;
7729 maxpasses
= is_q
? 4 : 2;
7732 for (pass
= 0; pass
< maxpasses
; pass
++) {
7734 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
7735 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
7737 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
7738 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7741 if (is_u
) { /* USQADD */
7744 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7747 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7750 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7753 g_assert_not_reached();
7755 } else { /* SUQADD */
7758 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7761 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7764 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7767 g_assert_not_reached();
7772 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7773 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
7774 tcg_temp_free_i64(tcg_zero
);
7776 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7780 clear_vec_high(s
, rd
);
7783 tcg_temp_free_i32(tcg_rd
);
7784 tcg_temp_free_i32(tcg_rn
);
7788 /* C3.6.12 AdvSIMD scalar two reg misc
7789 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7790 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7791 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
7792 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7794 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
7796 int rd
= extract32(insn
, 0, 5);
7797 int rn
= extract32(insn
, 5, 5);
7798 int opcode
= extract32(insn
, 12, 5);
7799 int size
= extract32(insn
, 22, 2);
7800 bool u
= extract32(insn
, 29, 1);
7801 bool is_fcvt
= false;
7804 TCGv_ptr tcg_fpstatus
;
7807 case 0x3: /* USQADD / SUQADD*/
7808 if (!fp_access_check(s
)) {
7811 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
7813 case 0x7: /* SQABS / SQNEG */
7815 case 0xa: /* CMLT */
7817 unallocated_encoding(s
);
7821 case 0x8: /* CMGT, CMGE */
7822 case 0x9: /* CMEQ, CMLE */
7823 case 0xb: /* ABS, NEG */
7825 unallocated_encoding(s
);
7829 case 0x12: /* SQXTUN */
7831 unallocated_encoding(s
);
7835 case 0x14: /* SQXTN, UQXTN */
7837 unallocated_encoding(s
);
7840 if (!fp_access_check(s
)) {
7843 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
7848 /* Floating point: U, size[1] and opcode indicate operation;
7849 * size[0] indicates single or double precision.
7851 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
7852 size
= extract32(size
, 0, 1) ? 3 : 2;
7854 case 0x2c: /* FCMGT (zero) */
7855 case 0x2d: /* FCMEQ (zero) */
7856 case 0x2e: /* FCMLT (zero) */
7857 case 0x6c: /* FCMGE (zero) */
7858 case 0x6d: /* FCMLE (zero) */
7859 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
7861 case 0x1d: /* SCVTF */
7862 case 0x5d: /* UCVTF */
7864 bool is_signed
= (opcode
== 0x1d);
7865 if (!fp_access_check(s
)) {
7868 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
7871 case 0x3d: /* FRECPE */
7872 case 0x3f: /* FRECPX */
7873 case 0x7d: /* FRSQRTE */
7874 if (!fp_access_check(s
)) {
7877 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
7879 case 0x1a: /* FCVTNS */
7880 case 0x1b: /* FCVTMS */
7881 case 0x3a: /* FCVTPS */
7882 case 0x3b: /* FCVTZS */
7883 case 0x5a: /* FCVTNU */
7884 case 0x5b: /* FCVTMU */
7885 case 0x7a: /* FCVTPU */
7886 case 0x7b: /* FCVTZU */
7888 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
7890 case 0x1c: /* FCVTAS */
7891 case 0x5c: /* FCVTAU */
7892 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
7894 rmode
= FPROUNDING_TIEAWAY
;
7896 case 0x56: /* FCVTXN, FCVTXN2 */
7898 unallocated_encoding(s
);
7901 if (!fp_access_check(s
)) {
7904 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
7907 unallocated_encoding(s
);
7912 unallocated_encoding(s
);
7916 if (!fp_access_check(s
)) {
7921 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
7922 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
7923 tcg_fpstatus
= get_fpstatus_ptr();
7925 TCGV_UNUSED_I32(tcg_rmode
);
7926 TCGV_UNUSED_PTR(tcg_fpstatus
);
7930 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7931 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7933 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
7934 write_fp_dreg(s
, rd
, tcg_rd
);
7935 tcg_temp_free_i64(tcg_rd
);
7936 tcg_temp_free_i64(tcg_rn
);
7938 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7939 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7941 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7944 case 0x7: /* SQABS, SQNEG */
7946 NeonGenOneOpEnvFn
*genfn
;
7947 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
7948 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
7949 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
7950 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
7952 genfn
= fns
[size
][u
];
7953 genfn(tcg_rd
, cpu_env
, tcg_rn
);
7956 case 0x1a: /* FCVTNS */
7957 case 0x1b: /* FCVTMS */
7958 case 0x1c: /* FCVTAS */
7959 case 0x3a: /* FCVTPS */
7960 case 0x3b: /* FCVTZS */
7962 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7963 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7964 tcg_temp_free_i32(tcg_shift
);
7967 case 0x5a: /* FCVTNU */
7968 case 0x5b: /* FCVTMU */
7969 case 0x5c: /* FCVTAU */
7970 case 0x7a: /* FCVTPU */
7971 case 0x7b: /* FCVTZU */
7973 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7974 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7975 tcg_temp_free_i32(tcg_shift
);
7979 g_assert_not_reached();
7982 write_fp_sreg(s
, rd
, tcg_rd
);
7983 tcg_temp_free_i32(tcg_rd
);
7984 tcg_temp_free_i32(tcg_rn
);
7988 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
7989 tcg_temp_free_i32(tcg_rmode
);
7990 tcg_temp_free_ptr(tcg_fpstatus
);
7994 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
7995 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
7996 int immh
, int immb
, int opcode
, int rn
, int rd
)
7998 int size
= 32 - clz32(immh
) - 1;
7999 int immhb
= immh
<< 3 | immb
;
8000 int shift
= 2 * (8 << size
) - immhb
;
8001 bool accumulate
= false;
8003 bool insert
= false;
8004 int dsize
= is_q
? 128 : 64;
8005 int esize
= 8 << size
;
8006 int elements
= dsize
/esize
;
8007 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
8008 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8009 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8013 if (extract32(immh
, 3, 1) && !is_q
) {
8014 unallocated_encoding(s
);
8018 if (size
> 3 && !is_q
) {
8019 unallocated_encoding(s
);
8023 if (!fp_access_check(s
)) {
8028 case 0x02: /* SSRA / USRA (accumulate) */
8031 case 0x04: /* SRSHR / URSHR (rounding) */
8034 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8035 accumulate
= round
= true;
8037 case 0x08: /* SRI */
8043 uint64_t round_const
= 1ULL << (shift
- 1);
8044 tcg_round
= tcg_const_i64(round_const
);
8046 TCGV_UNUSED_I64(tcg_round
);
8049 for (i
= 0; i
< elements
; i
++) {
8050 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
8051 if (accumulate
|| insert
) {
8052 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
8056 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
8058 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8059 accumulate
, is_u
, size
, shift
);
8062 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8066 clear_vec_high(s
, rd
);
8070 tcg_temp_free_i64(tcg_round
);
8074 /* SHL/SLI - Vector shift left */
8075 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
8076 int immh
, int immb
, int opcode
, int rn
, int rd
)
8078 int size
= 32 - clz32(immh
) - 1;
8079 int immhb
= immh
<< 3 | immb
;
8080 int shift
= immhb
- (8 << size
);
8081 int dsize
= is_q
? 128 : 64;
8082 int esize
= 8 << size
;
8083 int elements
= dsize
/esize
;
8084 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8085 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8088 if (extract32(immh
, 3, 1) && !is_q
) {
8089 unallocated_encoding(s
);
8093 if (size
> 3 && !is_q
) {
8094 unallocated_encoding(s
);
8098 if (!fp_access_check(s
)) {
8102 for (i
= 0; i
< elements
; i
++) {
8103 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
8105 read_vec_element(s
, tcg_rd
, rd
, i
, size
);
8108 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
8110 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8114 clear_vec_high(s
, rd
);
8118 /* USHLL/SHLL - Vector shift left with widening */
8119 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
8120 int immh
, int immb
, int opcode
, int rn
, int rd
)
8122 int size
= 32 - clz32(immh
) - 1;
8123 int immhb
= immh
<< 3 | immb
;
8124 int shift
= immhb
- (8 << size
);
8126 int esize
= 8 << size
;
8127 int elements
= dsize
/esize
;
8128 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8129 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8133 unallocated_encoding(s
);
8137 if (!fp_access_check(s
)) {
8141 /* For the LL variants the store is larger than the load,
8142 * so if rd == rn we would overwrite parts of our input.
8143 * So load everything right now and use shifts in the main loop.
8145 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
8147 for (i
= 0; i
< elements
; i
++) {
8148 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
8149 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
8150 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
8151 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
8155 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
8156 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
8157 int immh
, int immb
, int opcode
, int rn
, int rd
)
8159 int immhb
= immh
<< 3 | immb
;
8160 int size
= 32 - clz32(immh
) - 1;
8162 int esize
= 8 << size
;
8163 int elements
= dsize
/esize
;
8164 int shift
= (2 * esize
) - immhb
;
8165 bool round
= extract32(opcode
, 0, 1);
8166 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
8170 if (extract32(immh
, 3, 1)) {
8171 unallocated_encoding(s
);
8175 if (!fp_access_check(s
)) {
8179 tcg_rn
= tcg_temp_new_i64();
8180 tcg_rd
= tcg_temp_new_i64();
8181 tcg_final
= tcg_temp_new_i64();
8182 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
8185 uint64_t round_const
= 1ULL << (shift
- 1);
8186 tcg_round
= tcg_const_i64(round_const
);
8188 TCGV_UNUSED_I64(tcg_round
);
8191 for (i
= 0; i
< elements
; i
++) {
8192 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
8193 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8194 false, true, size
+1, shift
);
8196 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8200 clear_vec_high(s
, rd
);
8201 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8203 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8207 tcg_temp_free_i64(tcg_round
);
8209 tcg_temp_free_i64(tcg_rn
);
8210 tcg_temp_free_i64(tcg_rd
);
8211 tcg_temp_free_i64(tcg_final
);
8216 /* C3.6.14 AdvSIMD shift by immediate
8217 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8218 * +---+---+---+-------------+------+------+--------+---+------+------+
8219 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8220 * +---+---+---+-------------+------+------+--------+---+------+------+
8222 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
8224 int rd
= extract32(insn
, 0, 5);
8225 int rn
= extract32(insn
, 5, 5);
8226 int opcode
= extract32(insn
, 11, 5);
8227 int immb
= extract32(insn
, 16, 3);
8228 int immh
= extract32(insn
, 19, 4);
8229 bool is_u
= extract32(insn
, 29, 1);
8230 bool is_q
= extract32(insn
, 30, 1);
8233 case 0x08: /* SRI */
8235 unallocated_encoding(s
);
8239 case 0x00: /* SSHR / USHR */
8240 case 0x02: /* SSRA / USRA (accumulate) */
8241 case 0x04: /* SRSHR / URSHR (rounding) */
8242 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8243 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8245 case 0x0a: /* SHL / SLI */
8246 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8248 case 0x10: /* SHRN */
8249 case 0x11: /* RSHRN / SQRSHRUN */
8251 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
8254 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
8257 case 0x12: /* SQSHRN / UQSHRN */
8258 case 0x13: /* SQRSHRN / UQRSHRN */
8259 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
8262 case 0x14: /* SSHLL / USHLL */
8263 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8265 case 0x1c: /* SCVTF / UCVTF */
8266 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
8269 case 0xc: /* SQSHLU */
8271 unallocated_encoding(s
);
8274 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
8276 case 0xe: /* SQSHL, UQSHL */
8277 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
8279 case 0x1f: /* FCVTZS/ FCVTZU */
8280 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
8283 unallocated_encoding(s
);
8288 /* Generate code to do a "long" addition or subtraction, ie one done in
8289 * TCGv_i64 on vector lanes twice the width specified by size.
8291 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
8292 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
8294 static NeonGenTwo64OpFn
* const fns
[3][2] = {
8295 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
8296 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
8297 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
8299 NeonGenTwo64OpFn
*genfn
;
8302 genfn
= fns
[size
][is_sub
];
8303 genfn(tcg_res
, tcg_op1
, tcg_op2
);
8306 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
8307 int opcode
, int rd
, int rn
, int rm
)
8309 /* 3-reg-different widening insns: 64 x 64 -> 128 */
8310 TCGv_i64 tcg_res
[2];
8313 tcg_res
[0] = tcg_temp_new_i64();
8314 tcg_res
[1] = tcg_temp_new_i64();
8316 /* Does this op do an adding accumulate, a subtracting accumulate,
8317 * or no accumulate at all?
8335 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8336 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8339 /* size == 2 means two 32x32->64 operations; this is worth special
8340 * casing because we can generally handle it inline.
8343 for (pass
= 0; pass
< 2; pass
++) {
8344 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8345 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8346 TCGv_i64 tcg_passres
;
8347 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
8349 int elt
= pass
+ is_q
* 2;
8351 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
8352 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
8355 tcg_passres
= tcg_res
[pass
];
8357 tcg_passres
= tcg_temp_new_i64();
8361 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8362 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8364 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8365 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8367 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8368 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8370 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
8371 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
8373 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
8374 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
8375 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
8377 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
8378 tcg_temp_free_i64(tcg_tmp1
);
8379 tcg_temp_free_i64(tcg_tmp2
);
8382 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8383 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8384 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8385 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8387 case 9: /* SQDMLAL, SQDMLAL2 */
8388 case 11: /* SQDMLSL, SQDMLSL2 */
8389 case 13: /* SQDMULL, SQDMULL2 */
8390 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8391 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
8392 tcg_passres
, tcg_passres
);
8395 g_assert_not_reached();
8398 if (opcode
== 9 || opcode
== 11) {
8399 /* saturating accumulate ops */
8401 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
8403 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
8404 tcg_res
[pass
], tcg_passres
);
8405 } else if (accop
> 0) {
8406 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8407 } else if (accop
< 0) {
8408 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8412 tcg_temp_free_i64(tcg_passres
);
8415 tcg_temp_free_i64(tcg_op1
);
8416 tcg_temp_free_i64(tcg_op2
);
8419 /* size 0 or 1, generally helper functions */
8420 for (pass
= 0; pass
< 2; pass
++) {
8421 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8422 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8423 TCGv_i64 tcg_passres
;
8424 int elt
= pass
+ is_q
* 2;
8426 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
8427 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
8430 tcg_passres
= tcg_res
[pass
];
8432 tcg_passres
= tcg_temp_new_i64();
8436 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8437 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8439 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
8440 static NeonGenWidenFn
* const widenfns
[2][2] = {
8441 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8442 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8444 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8446 widenfn(tcg_op2_64
, tcg_op2
);
8447 widenfn(tcg_passres
, tcg_op1
);
8448 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
8449 tcg_passres
, tcg_op2_64
);
8450 tcg_temp_free_i64(tcg_op2_64
);
8453 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8454 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8457 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8459 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8463 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
8465 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
8469 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8470 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8471 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8474 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
8476 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
8480 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8482 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8486 case 9: /* SQDMLAL, SQDMLAL2 */
8487 case 11: /* SQDMLSL, SQDMLSL2 */
8488 case 13: /* SQDMULL, SQDMULL2 */
8490 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8491 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
8492 tcg_passres
, tcg_passres
);
8494 case 14: /* PMULL */
8496 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
8499 g_assert_not_reached();
8501 tcg_temp_free_i32(tcg_op1
);
8502 tcg_temp_free_i32(tcg_op2
);
8505 if (opcode
== 9 || opcode
== 11) {
8506 /* saturating accumulate ops */
8508 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
8510 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
8514 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
8515 tcg_res
[pass
], tcg_passres
);
8517 tcg_temp_free_i64(tcg_passres
);
8522 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8523 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8524 tcg_temp_free_i64(tcg_res
[0]);
8525 tcg_temp_free_i64(tcg_res
[1]);
8528 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
8529 int opcode
, int rd
, int rn
, int rm
)
8531 TCGv_i64 tcg_res
[2];
8532 int part
= is_q
? 2 : 0;
8535 for (pass
= 0; pass
< 2; pass
++) {
8536 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8537 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8538 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
8539 static NeonGenWidenFn
* const widenfns
[3][2] = {
8540 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8541 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8542 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
8544 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8546 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8547 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
8548 widenfn(tcg_op2_wide
, tcg_op2
);
8549 tcg_temp_free_i32(tcg_op2
);
8550 tcg_res
[pass
] = tcg_temp_new_i64();
8551 gen_neon_addl(size
, (opcode
== 3),
8552 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
8553 tcg_temp_free_i64(tcg_op1
);
8554 tcg_temp_free_i64(tcg_op2_wide
);
8557 for (pass
= 0; pass
< 2; pass
++) {
8558 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8559 tcg_temp_free_i64(tcg_res
[pass
]);
8563 static void do_narrow_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8565 tcg_gen_shri_i64(in
, in
, 32);
8566 tcg_gen_trunc_i64_i32(res
, in
);
8569 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8571 tcg_gen_addi_i64(in
, in
, 1U << 31);
8572 do_narrow_high_u32(res
, in
);
8575 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
8576 int opcode
, int rd
, int rn
, int rm
)
8578 TCGv_i32 tcg_res
[2];
8579 int part
= is_q
? 2 : 0;
8582 for (pass
= 0; pass
< 2; pass
++) {
8583 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8584 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8585 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
8586 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
8587 { gen_helper_neon_narrow_high_u8
,
8588 gen_helper_neon_narrow_round_high_u8
},
8589 { gen_helper_neon_narrow_high_u16
,
8590 gen_helper_neon_narrow_round_high_u16
},
8591 { do_narrow_high_u32
, do_narrow_round_high_u32
},
8593 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
8595 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8596 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8598 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
8600 tcg_temp_free_i64(tcg_op1
);
8601 tcg_temp_free_i64(tcg_op2
);
8603 tcg_res
[pass
] = tcg_temp_new_i32();
8604 gennarrow(tcg_res
[pass
], tcg_wideres
);
8605 tcg_temp_free_i64(tcg_wideres
);
8608 for (pass
= 0; pass
< 2; pass
++) {
8609 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
8610 tcg_temp_free_i32(tcg_res
[pass
]);
8613 clear_vec_high(s
, rd
);
8617 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
8619 /* PMULL of 64 x 64 -> 128 is an odd special case because it
8620 * is the only three-reg-diff instruction which produces a
8621 * 128-bit wide result from a single operation. However since
8622 * it's possible to calculate the two halves more or less
8623 * separately we just use two helper calls.
8625 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8626 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8627 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8629 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
8630 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
8631 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
8632 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
8633 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
8634 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
8636 tcg_temp_free_i64(tcg_op1
);
8637 tcg_temp_free_i64(tcg_op2
);
8638 tcg_temp_free_i64(tcg_res
);
8641 /* C3.6.15 AdvSIMD three different
8642 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8643 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8644 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8645 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8647 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8649 /* Instructions in this group fall into three basic classes
8650 * (in each case with the operation working on each element in
8651 * the input vectors):
8652 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
8654 * (2) wide 64 x 128 -> 128
8655 * (3) narrowing 128 x 128 -> 64
8656 * Here we do initial decode, catch unallocated cases and
8657 * dispatch to separate functions for each class.
8659 int is_q
= extract32(insn
, 30, 1);
8660 int is_u
= extract32(insn
, 29, 1);
8661 int size
= extract32(insn
, 22, 2);
8662 int opcode
= extract32(insn
, 12, 4);
8663 int rm
= extract32(insn
, 16, 5);
8664 int rn
= extract32(insn
, 5, 5);
8665 int rd
= extract32(insn
, 0, 5);
8668 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
8669 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
8670 /* 64 x 128 -> 128 */
8672 unallocated_encoding(s
);
8675 if (!fp_access_check(s
)) {
8678 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8680 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
8681 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
8682 /* 128 x 128 -> 64 */
8684 unallocated_encoding(s
);
8687 if (!fp_access_check(s
)) {
8690 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8692 case 14: /* PMULL, PMULL2 */
8693 if (is_u
|| size
== 1 || size
== 2) {
8694 unallocated_encoding(s
);
8698 if (!arm_dc_feature(s
, ARM_FEATURE_V8_PMULL
)) {
8699 unallocated_encoding(s
);
8702 if (!fp_access_check(s
)) {
8705 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
8709 case 9: /* SQDMLAL, SQDMLAL2 */
8710 case 11: /* SQDMLSL, SQDMLSL2 */
8711 case 13: /* SQDMULL, SQDMULL2 */
8712 if (is_u
|| size
== 0) {
8713 unallocated_encoding(s
);
8717 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8718 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8719 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8720 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8721 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8722 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8723 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
8724 /* 64 x 64 -> 128 */
8726 unallocated_encoding(s
);
8730 if (!fp_access_check(s
)) {
8734 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8737 /* opcode 15 not allocated */
8738 unallocated_encoding(s
);
8743 /* Logic op (opcode == 3) subgroup of C3.6.16. */
8744 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
8746 int rd
= extract32(insn
, 0, 5);
8747 int rn
= extract32(insn
, 5, 5);
8748 int rm
= extract32(insn
, 16, 5);
8749 int size
= extract32(insn
, 22, 2);
8750 bool is_u
= extract32(insn
, 29, 1);
8751 bool is_q
= extract32(insn
, 30, 1);
8752 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
8755 if (!fp_access_check(s
)) {
8759 tcg_op1
= tcg_temp_new_i64();
8760 tcg_op2
= tcg_temp_new_i64();
8761 tcg_res
[0] = tcg_temp_new_i64();
8762 tcg_res
[1] = tcg_temp_new_i64();
8764 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
8765 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8766 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8771 tcg_gen_and_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8774 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8777 tcg_gen_or_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8780 tcg_gen_orc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8785 /* B* ops need res loaded to operate on */
8786 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8791 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8793 case 1: /* BSL bitwise select */
8794 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8795 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8796 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op1
);
8798 case 2: /* BIT, bitwise insert if true */
8799 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8800 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8801 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8803 case 3: /* BIF, bitwise insert if false */
8804 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8805 tcg_gen_andc_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8806 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8812 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8814 tcg_gen_movi_i64(tcg_res
[1], 0);
8816 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8818 tcg_temp_free_i64(tcg_op1
);
8819 tcg_temp_free_i64(tcg_op2
);
8820 tcg_temp_free_i64(tcg_res
[0]);
8821 tcg_temp_free_i64(tcg_res
[1]);
8824 /* Helper functions for 32 bit comparisons */
8825 static void gen_max_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8827 tcg_gen_movcond_i32(TCG_COND_GE
, res
, op1
, op2
, op1
, op2
);
8830 static void gen_max_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8832 tcg_gen_movcond_i32(TCG_COND_GEU
, res
, op1
, op2
, op1
, op2
);
8835 static void gen_min_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8837 tcg_gen_movcond_i32(TCG_COND_LE
, res
, op1
, op2
, op1
, op2
);
8840 static void gen_min_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8842 tcg_gen_movcond_i32(TCG_COND_LEU
, res
, op1
, op2
, op1
, op2
);
8845 /* Pairwise op subgroup of C3.6.16.
8847 * This is called directly or via the handle_3same_float for float pairwise
8848 * operations where the opcode and size are calculated differently.
8850 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
8851 int size
, int rn
, int rm
, int rd
)
8856 /* Floating point operations need fpst */
8857 if (opcode
>= 0x58) {
8858 fpst
= get_fpstatus_ptr();
8860 TCGV_UNUSED_PTR(fpst
);
8863 if (!fp_access_check(s
)) {
8867 /* These operations work on the concatenated rm:rn, with each pair of
8868 * adjacent elements being operated on to produce an element in the result.
8871 TCGv_i64 tcg_res
[2];
8873 for (pass
= 0; pass
< 2; pass
++) {
8874 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8875 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8876 int passreg
= (pass
== 0) ? rn
: rm
;
8878 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
8879 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
8880 tcg_res
[pass
] = tcg_temp_new_i64();
8883 case 0x17: /* ADDP */
8884 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8886 case 0x58: /* FMAXNMP */
8887 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8889 case 0x5a: /* FADDP */
8890 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8892 case 0x5e: /* FMAXP */
8893 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8895 case 0x78: /* FMINNMP */
8896 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8898 case 0x7e: /* FMINP */
8899 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8902 g_assert_not_reached();
8905 tcg_temp_free_i64(tcg_op1
);
8906 tcg_temp_free_i64(tcg_op2
);
8909 for (pass
= 0; pass
< 2; pass
++) {
8910 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8911 tcg_temp_free_i64(tcg_res
[pass
]);
8914 int maxpass
= is_q
? 4 : 2;
8915 TCGv_i32 tcg_res
[4];
8917 for (pass
= 0; pass
< maxpass
; pass
++) {
8918 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8919 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8920 NeonGenTwoOpFn
*genfn
= NULL
;
8921 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
8922 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
8924 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
8925 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
8926 tcg_res
[pass
] = tcg_temp_new_i32();
8929 case 0x17: /* ADDP */
8931 static NeonGenTwoOpFn
* const fns
[3] = {
8932 gen_helper_neon_padd_u8
,
8933 gen_helper_neon_padd_u16
,
8939 case 0x14: /* SMAXP, UMAXP */
8941 static NeonGenTwoOpFn
* const fns
[3][2] = {
8942 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
8943 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
8944 { gen_max_s32
, gen_max_u32
},
8946 genfn
= fns
[size
][u
];
8949 case 0x15: /* SMINP, UMINP */
8951 static NeonGenTwoOpFn
* const fns
[3][2] = {
8952 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
8953 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
8954 { gen_min_s32
, gen_min_u32
},
8956 genfn
= fns
[size
][u
];
8959 /* The FP operations are all on single floats (32 bit) */
8960 case 0x58: /* FMAXNMP */
8961 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8963 case 0x5a: /* FADDP */
8964 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8966 case 0x5e: /* FMAXP */
8967 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8969 case 0x78: /* FMINNMP */
8970 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8972 case 0x7e: /* FMINP */
8973 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8976 g_assert_not_reached();
8979 /* FP ops called directly, otherwise call now */
8981 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8984 tcg_temp_free_i32(tcg_op1
);
8985 tcg_temp_free_i32(tcg_op2
);
8988 for (pass
= 0; pass
< maxpass
; pass
++) {
8989 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
8990 tcg_temp_free_i32(tcg_res
[pass
]);
8993 clear_vec_high(s
, rd
);
8997 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
8998 tcg_temp_free_ptr(fpst
);
9002 /* Floating point op subgroup of C3.6.16. */
9003 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
9005 /* For floating point ops, the U, size[1] and opcode bits
9006 * together indicate the operation. size[0] indicates single
9009 int fpopcode
= extract32(insn
, 11, 5)
9010 | (extract32(insn
, 23, 1) << 5)
9011 | (extract32(insn
, 29, 1) << 6);
9012 int is_q
= extract32(insn
, 30, 1);
9013 int size
= extract32(insn
, 22, 1);
9014 int rm
= extract32(insn
, 16, 5);
9015 int rn
= extract32(insn
, 5, 5);
9016 int rd
= extract32(insn
, 0, 5);
9018 int datasize
= is_q
? 128 : 64;
9019 int esize
= 32 << size
;
9020 int elements
= datasize
/ esize
;
9022 if (size
== 1 && !is_q
) {
9023 unallocated_encoding(s
);
9028 case 0x58: /* FMAXNMP */
9029 case 0x5a: /* FADDP */
9030 case 0x5e: /* FMAXP */
9031 case 0x78: /* FMINNMP */
9032 case 0x7e: /* FMINP */
9033 if (size
&& !is_q
) {
9034 unallocated_encoding(s
);
9037 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
9040 case 0x1b: /* FMULX */
9041 case 0x1f: /* FRECPS */
9042 case 0x3f: /* FRSQRTS */
9043 case 0x5d: /* FACGE */
9044 case 0x7d: /* FACGT */
9045 case 0x19: /* FMLA */
9046 case 0x39: /* FMLS */
9047 case 0x18: /* FMAXNM */
9048 case 0x1a: /* FADD */
9049 case 0x1c: /* FCMEQ */
9050 case 0x1e: /* FMAX */
9051 case 0x38: /* FMINNM */
9052 case 0x3a: /* FSUB */
9053 case 0x3e: /* FMIN */
9054 case 0x5b: /* FMUL */
9055 case 0x5c: /* FCMGE */
9056 case 0x5f: /* FDIV */
9057 case 0x7a: /* FABD */
9058 case 0x7c: /* FCMGT */
9059 if (!fp_access_check(s
)) {
9063 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
9066 unallocated_encoding(s
);
9071 /* Integer op subgroup of C3.6.16. */
9072 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
9074 int is_q
= extract32(insn
, 30, 1);
9075 int u
= extract32(insn
, 29, 1);
9076 int size
= extract32(insn
, 22, 2);
9077 int opcode
= extract32(insn
, 11, 5);
9078 int rm
= extract32(insn
, 16, 5);
9079 int rn
= extract32(insn
, 5, 5);
9080 int rd
= extract32(insn
, 0, 5);
9084 case 0x13: /* MUL, PMUL */
9085 if (u
&& size
!= 0) {
9086 unallocated_encoding(s
);
9090 case 0x0: /* SHADD, UHADD */
9091 case 0x2: /* SRHADD, URHADD */
9092 case 0x4: /* SHSUB, UHSUB */
9093 case 0xc: /* SMAX, UMAX */
9094 case 0xd: /* SMIN, UMIN */
9095 case 0xe: /* SABD, UABD */
9096 case 0xf: /* SABA, UABA */
9097 case 0x12: /* MLA, MLS */
9099 unallocated_encoding(s
);
9103 case 0x16: /* SQDMULH, SQRDMULH */
9104 if (size
== 0 || size
== 3) {
9105 unallocated_encoding(s
);
9110 if (size
== 3 && !is_q
) {
9111 unallocated_encoding(s
);
9117 if (!fp_access_check(s
)) {
9123 for (pass
= 0; pass
< 2; pass
++) {
9124 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9125 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9126 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9128 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9129 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9131 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
9133 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9135 tcg_temp_free_i64(tcg_res
);
9136 tcg_temp_free_i64(tcg_op1
);
9137 tcg_temp_free_i64(tcg_op2
);
9140 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9141 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9142 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9143 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9144 NeonGenTwoOpFn
*genfn
= NULL
;
9145 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
9147 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
9148 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
9151 case 0x0: /* SHADD, UHADD */
9153 static NeonGenTwoOpFn
* const fns
[3][2] = {
9154 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
9155 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
9156 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
9158 genfn
= fns
[size
][u
];
9161 case 0x1: /* SQADD, UQADD */
9163 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9164 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9165 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9166 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9168 genenvfn
= fns
[size
][u
];
9171 case 0x2: /* SRHADD, URHADD */
9173 static NeonGenTwoOpFn
* const fns
[3][2] = {
9174 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
9175 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
9176 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
9178 genfn
= fns
[size
][u
];
9181 case 0x4: /* SHSUB, UHSUB */
9183 static NeonGenTwoOpFn
* const fns
[3][2] = {
9184 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
9185 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
9186 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
9188 genfn
= fns
[size
][u
];
9191 case 0x5: /* SQSUB, UQSUB */
9193 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9194 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9195 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9196 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9198 genenvfn
= fns
[size
][u
];
9201 case 0x6: /* CMGT, CMHI */
9203 static NeonGenTwoOpFn
* const fns
[3][2] = {
9204 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_u8
},
9205 { gen_helper_neon_cgt_s16
, gen_helper_neon_cgt_u16
},
9206 { gen_helper_neon_cgt_s32
, gen_helper_neon_cgt_u32
},
9208 genfn
= fns
[size
][u
];
9211 case 0x7: /* CMGE, CMHS */
9213 static NeonGenTwoOpFn
* const fns
[3][2] = {
9214 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_u8
},
9215 { gen_helper_neon_cge_s16
, gen_helper_neon_cge_u16
},
9216 { gen_helper_neon_cge_s32
, gen_helper_neon_cge_u32
},
9218 genfn
= fns
[size
][u
];
9221 case 0x8: /* SSHL, USHL */
9223 static NeonGenTwoOpFn
* const fns
[3][2] = {
9224 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
9225 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
9226 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
9228 genfn
= fns
[size
][u
];
9231 case 0x9: /* SQSHL, UQSHL */
9233 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9234 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9235 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9236 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9238 genenvfn
= fns
[size
][u
];
9241 case 0xa: /* SRSHL, URSHL */
9243 static NeonGenTwoOpFn
* const fns
[3][2] = {
9244 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
9245 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
9246 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
9248 genfn
= fns
[size
][u
];
9251 case 0xb: /* SQRSHL, UQRSHL */
9253 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9254 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9255 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9256 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9258 genenvfn
= fns
[size
][u
];
9261 case 0xc: /* SMAX, UMAX */
9263 static NeonGenTwoOpFn
* const fns
[3][2] = {
9264 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
9265 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
9266 { gen_max_s32
, gen_max_u32
},
9268 genfn
= fns
[size
][u
];
9272 case 0xd: /* SMIN, UMIN */
9274 static NeonGenTwoOpFn
* const fns
[3][2] = {
9275 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
9276 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
9277 { gen_min_s32
, gen_min_u32
},
9279 genfn
= fns
[size
][u
];
9282 case 0xe: /* SABD, UABD */
9283 case 0xf: /* SABA, UABA */
9285 static NeonGenTwoOpFn
* const fns
[3][2] = {
9286 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
9287 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
9288 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
9290 genfn
= fns
[size
][u
];
9293 case 0x10: /* ADD, SUB */
9295 static NeonGenTwoOpFn
* const fns
[3][2] = {
9296 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9297 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9298 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9300 genfn
= fns
[size
][u
];
9303 case 0x11: /* CMTST, CMEQ */
9305 static NeonGenTwoOpFn
* const fns
[3][2] = {
9306 { gen_helper_neon_tst_u8
, gen_helper_neon_ceq_u8
},
9307 { gen_helper_neon_tst_u16
, gen_helper_neon_ceq_u16
},
9308 { gen_helper_neon_tst_u32
, gen_helper_neon_ceq_u32
},
9310 genfn
= fns
[size
][u
];
9313 case 0x13: /* MUL, PMUL */
9317 genfn
= gen_helper_neon_mul_p8
;
9320 /* fall through : MUL */
9321 case 0x12: /* MLA, MLS */
9323 static NeonGenTwoOpFn
* const fns
[3] = {
9324 gen_helper_neon_mul_u8
,
9325 gen_helper_neon_mul_u16
,
9331 case 0x16: /* SQDMULH, SQRDMULH */
9333 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9334 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9335 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9337 assert(size
== 1 || size
== 2);
9338 genenvfn
= fns
[size
- 1][u
];
9342 g_assert_not_reached();
9346 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
9348 genfn(tcg_res
, tcg_op1
, tcg_op2
);
9351 if (opcode
== 0xf || opcode
== 0x12) {
9352 /* SABA, UABA, MLA, MLS: accumulating ops */
9353 static NeonGenTwoOpFn
* const fns
[3][2] = {
9354 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9355 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9356 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9358 bool is_sub
= (opcode
== 0x12 && u
); /* MLS */
9360 genfn
= fns
[size
][is_sub
];
9361 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
9362 genfn(tcg_res
, tcg_op1
, tcg_res
);
9365 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9367 tcg_temp_free_i32(tcg_res
);
9368 tcg_temp_free_i32(tcg_op1
);
9369 tcg_temp_free_i32(tcg_op2
);
9374 clear_vec_high(s
, rd
);
9378 /* C3.6.16 AdvSIMD three same
9379 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
9380 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9381 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
9382 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9384 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
9386 int opcode
= extract32(insn
, 11, 5);
9389 case 0x3: /* logic ops */
9390 disas_simd_3same_logic(s
, insn
);
9392 case 0x17: /* ADDP */
9393 case 0x14: /* SMAXP, UMAXP */
9394 case 0x15: /* SMINP, UMINP */
9396 /* Pairwise operations */
9397 int is_q
= extract32(insn
, 30, 1);
9398 int u
= extract32(insn
, 29, 1);
9399 int size
= extract32(insn
, 22, 2);
9400 int rm
= extract32(insn
, 16, 5);
9401 int rn
= extract32(insn
, 5, 5);
9402 int rd
= extract32(insn
, 0, 5);
9403 if (opcode
== 0x17) {
9404 if (u
|| (size
== 3 && !is_q
)) {
9405 unallocated_encoding(s
);
9410 unallocated_encoding(s
);
9414 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
9418 /* floating point ops, sz[1] and U are part of opcode */
9419 disas_simd_3same_float(s
, insn
);
9422 disas_simd_3same_int(s
, insn
);
9427 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
9428 int size
, int rn
, int rd
)
9430 /* Handle 2-reg-misc ops which are widening (so each size element
9431 * in the source becomes a 2*size element in the destination.
9432 * The only instruction like this is FCVTL.
9437 /* 32 -> 64 bit fp conversion */
9438 TCGv_i64 tcg_res
[2];
9439 int srcelt
= is_q
? 2 : 0;
9441 for (pass
= 0; pass
< 2; pass
++) {
9442 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9443 tcg_res
[pass
] = tcg_temp_new_i64();
9445 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
9446 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
9447 tcg_temp_free_i32(tcg_op
);
9449 for (pass
= 0; pass
< 2; pass
++) {
9450 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9451 tcg_temp_free_i64(tcg_res
[pass
]);
9454 /* 16 -> 32 bit fp conversion */
9455 int srcelt
= is_q
? 4 : 0;
9456 TCGv_i32 tcg_res
[4];
9458 for (pass
= 0; pass
< 4; pass
++) {
9459 tcg_res
[pass
] = tcg_temp_new_i32();
9461 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
9462 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
9465 for (pass
= 0; pass
< 4; pass
++) {
9466 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9467 tcg_temp_free_i32(tcg_res
[pass
]);
9472 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
9473 bool is_q
, int size
, int rn
, int rd
)
9475 int op
= (opcode
<< 1) | u
;
9476 int opsz
= op
+ size
;
9477 int grp_size
= 3 - opsz
;
9478 int dsize
= is_q
? 128 : 64;
9482 unallocated_encoding(s
);
9486 if (!fp_access_check(s
)) {
9491 /* Special case bytes, use bswap op on each group of elements */
9492 int groups
= dsize
/ (8 << grp_size
);
9494 for (i
= 0; i
< groups
; i
++) {
9495 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9497 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
9500 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
9503 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
9506 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
9509 g_assert_not_reached();
9511 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
9512 tcg_temp_free_i64(tcg_tmp
);
9515 clear_vec_high(s
, rd
);
9518 int revmask
= (1 << grp_size
) - 1;
9519 int esize
= 8 << size
;
9520 int elements
= dsize
/ esize
;
9521 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9522 TCGv_i64 tcg_rd
= tcg_const_i64(0);
9523 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
9525 for (i
= 0; i
< elements
; i
++) {
9526 int e_rev
= (i
& 0xf) ^ revmask
;
9527 int off
= e_rev
* esize
;
9528 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
9530 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
9531 tcg_rn
, off
- 64, esize
);
9533 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
9536 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
9537 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
9539 tcg_temp_free_i64(tcg_rd_hi
);
9540 tcg_temp_free_i64(tcg_rd
);
9541 tcg_temp_free_i64(tcg_rn
);
9545 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
9546 bool is_q
, int size
, int rn
, int rd
)
9548 /* Implement the pairwise operations from 2-misc:
9549 * SADDLP, UADDLP, SADALP, UADALP.
9550 * These all add pairs of elements in the input to produce a
9551 * double-width result element in the output (possibly accumulating).
9553 bool accum
= (opcode
== 0x6);
9554 int maxpass
= is_q
? 2 : 1;
9556 TCGv_i64 tcg_res
[2];
9559 /* 32 + 32 -> 64 op */
9560 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
9562 for (pass
= 0; pass
< maxpass
; pass
++) {
9563 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9564 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9566 tcg_res
[pass
] = tcg_temp_new_i64();
9568 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
9569 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
9570 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9572 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
9573 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9576 tcg_temp_free_i64(tcg_op1
);
9577 tcg_temp_free_i64(tcg_op2
);
9580 for (pass
= 0; pass
< maxpass
; pass
++) {
9581 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9582 NeonGenOneOpFn
*genfn
;
9583 static NeonGenOneOpFn
* const fns
[2][2] = {
9584 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
9585 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
9588 genfn
= fns
[size
][u
];
9590 tcg_res
[pass
] = tcg_temp_new_i64();
9592 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9593 genfn(tcg_res
[pass
], tcg_op
);
9596 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
9598 gen_helper_neon_addl_u16(tcg_res
[pass
],
9599 tcg_res
[pass
], tcg_op
);
9601 gen_helper_neon_addl_u32(tcg_res
[pass
],
9602 tcg_res
[pass
], tcg_op
);
9605 tcg_temp_free_i64(tcg_op
);
9609 tcg_res
[1] = tcg_const_i64(0);
9611 for (pass
= 0; pass
< 2; pass
++) {
9612 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9613 tcg_temp_free_i64(tcg_res
[pass
]);
9617 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
9619 /* Implement SHLL and SHLL2 */
9621 int part
= is_q
? 2 : 0;
9622 TCGv_i64 tcg_res
[2];
9624 for (pass
= 0; pass
< 2; pass
++) {
9625 static NeonGenWidenFn
* const widenfns
[3] = {
9626 gen_helper_neon_widen_u8
,
9627 gen_helper_neon_widen_u16
,
9628 tcg_gen_extu_i32_i64
,
9630 NeonGenWidenFn
*widenfn
= widenfns
[size
];
9631 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9633 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
9634 tcg_res
[pass
] = tcg_temp_new_i64();
9635 widenfn(tcg_res
[pass
], tcg_op
);
9636 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
9638 tcg_temp_free_i32(tcg_op
);
9641 for (pass
= 0; pass
< 2; pass
++) {
9642 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9643 tcg_temp_free_i64(tcg_res
[pass
]);
9647 /* C3.6.17 AdvSIMD two reg misc
9648 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9649 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9650 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9651 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9653 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9655 int size
= extract32(insn
, 22, 2);
9656 int opcode
= extract32(insn
, 12, 5);
9657 bool u
= extract32(insn
, 29, 1);
9658 bool is_q
= extract32(insn
, 30, 1);
9659 int rn
= extract32(insn
, 5, 5);
9660 int rd
= extract32(insn
, 0, 5);
9661 bool need_fpstatus
= false;
9662 bool need_rmode
= false;
9665 TCGv_ptr tcg_fpstatus
;
9668 case 0x0: /* REV64, REV32 */
9669 case 0x1: /* REV16 */
9670 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9672 case 0x5: /* CNT, NOT, RBIT */
9673 if (u
&& size
== 0) {
9674 /* NOT: adjust size so we can use the 64-bits-at-a-time loop. */
9677 } else if (u
&& size
== 1) {
9680 } else if (!u
&& size
== 0) {
9684 unallocated_encoding(s
);
9686 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
9687 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
9689 unallocated_encoding(s
);
9692 if (!fp_access_check(s
)) {
9696 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
9698 case 0x4: /* CLS, CLZ */
9700 unallocated_encoding(s
);
9704 case 0x2: /* SADDLP, UADDLP */
9705 case 0x6: /* SADALP, UADALP */
9707 unallocated_encoding(s
);
9710 if (!fp_access_check(s
)) {
9713 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9715 case 0x13: /* SHLL, SHLL2 */
9716 if (u
== 0 || size
== 3) {
9717 unallocated_encoding(s
);
9720 if (!fp_access_check(s
)) {
9723 handle_shll(s
, is_q
, size
, rn
, rd
);
9725 case 0xa: /* CMLT */
9727 unallocated_encoding(s
);
9731 case 0x8: /* CMGT, CMGE */
9732 case 0x9: /* CMEQ, CMLE */
9733 case 0xb: /* ABS, NEG */
9734 if (size
== 3 && !is_q
) {
9735 unallocated_encoding(s
);
9739 case 0x3: /* SUQADD, USQADD */
9740 if (size
== 3 && !is_q
) {
9741 unallocated_encoding(s
);
9744 if (!fp_access_check(s
)) {
9747 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
9749 case 0x7: /* SQABS, SQNEG */
9750 if (size
== 3 && !is_q
) {
9751 unallocated_encoding(s
);
9759 /* Floating point: U, size[1] and opcode indicate operation;
9760 * size[0] indicates single or double precision.
9762 int is_double
= extract32(size
, 0, 1);
9763 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9764 size
= is_double
? 3 : 2;
9766 case 0x2f: /* FABS */
9767 case 0x6f: /* FNEG */
9768 if (size
== 3 && !is_q
) {
9769 unallocated_encoding(s
);
9773 case 0x1d: /* SCVTF */
9774 case 0x5d: /* UCVTF */
9776 bool is_signed
= (opcode
== 0x1d) ? true : false;
9777 int elements
= is_double
? 2 : is_q
? 4 : 2;
9778 if (is_double
&& !is_q
) {
9779 unallocated_encoding(s
);
9782 if (!fp_access_check(s
)) {
9785 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
9788 case 0x2c: /* FCMGT (zero) */
9789 case 0x2d: /* FCMEQ (zero) */
9790 case 0x2e: /* FCMLT (zero) */
9791 case 0x6c: /* FCMGE (zero) */
9792 case 0x6d: /* FCMLE (zero) */
9793 if (size
== 3 && !is_q
) {
9794 unallocated_encoding(s
);
9797 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9799 case 0x7f: /* FSQRT */
9800 if (size
== 3 && !is_q
) {
9801 unallocated_encoding(s
);
9805 case 0x1a: /* FCVTNS */
9806 case 0x1b: /* FCVTMS */
9807 case 0x3a: /* FCVTPS */
9808 case 0x3b: /* FCVTZS */
9809 case 0x5a: /* FCVTNU */
9810 case 0x5b: /* FCVTMU */
9811 case 0x7a: /* FCVTPU */
9812 case 0x7b: /* FCVTZU */
9813 need_fpstatus
= true;
9815 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9816 if (size
== 3 && !is_q
) {
9817 unallocated_encoding(s
);
9821 case 0x5c: /* FCVTAU */
9822 case 0x1c: /* FCVTAS */
9823 need_fpstatus
= true;
9825 rmode
= FPROUNDING_TIEAWAY
;
9826 if (size
== 3 && !is_q
) {
9827 unallocated_encoding(s
);
9831 case 0x3c: /* URECPE */
9833 unallocated_encoding(s
);
9837 case 0x3d: /* FRECPE */
9838 case 0x7d: /* FRSQRTE */
9839 if (size
== 3 && !is_q
) {
9840 unallocated_encoding(s
);
9843 if (!fp_access_check(s
)) {
9846 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9848 case 0x56: /* FCVTXN, FCVTXN2 */
9850 unallocated_encoding(s
);
9854 case 0x16: /* FCVTN, FCVTN2 */
9855 /* handle_2misc_narrow does a 2*size -> size operation, but these
9856 * instructions encode the source size rather than dest size.
9858 if (!fp_access_check(s
)) {
9861 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
9863 case 0x17: /* FCVTL, FCVTL2 */
9864 if (!fp_access_check(s
)) {
9867 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
9869 case 0x18: /* FRINTN */
9870 case 0x19: /* FRINTM */
9871 case 0x38: /* FRINTP */
9872 case 0x39: /* FRINTZ */
9874 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9876 case 0x59: /* FRINTX */
9877 case 0x79: /* FRINTI */
9878 need_fpstatus
= true;
9879 if (size
== 3 && !is_q
) {
9880 unallocated_encoding(s
);
9884 case 0x58: /* FRINTA */
9886 rmode
= FPROUNDING_TIEAWAY
;
9887 need_fpstatus
= true;
9888 if (size
== 3 && !is_q
) {
9889 unallocated_encoding(s
);
9893 case 0x7c: /* URSQRTE */
9895 unallocated_encoding(s
);
9898 need_fpstatus
= true;
9901 unallocated_encoding(s
);
9907 unallocated_encoding(s
);
9911 if (!fp_access_check(s
)) {
9915 if (need_fpstatus
) {
9916 tcg_fpstatus
= get_fpstatus_ptr();
9918 TCGV_UNUSED_PTR(tcg_fpstatus
);
9921 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
9922 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
9924 TCGV_UNUSED_I32(tcg_rmode
);
9928 /* All 64-bit element operations can be shared with scalar 2misc */
9931 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
9932 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9933 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9935 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9937 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
9938 tcg_rmode
, tcg_fpstatus
);
9940 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9942 tcg_temp_free_i64(tcg_res
);
9943 tcg_temp_free_i64(tcg_op
);
9948 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9949 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9950 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9953 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
9956 /* Special cases for 32 bit elements */
9958 case 0xa: /* CMLT */
9959 /* 32 bit integer comparison against zero, result is
9960 * test ? (2^32 - 1) : 0. We implement via setcond(test)
9965 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
9966 tcg_gen_neg_i32(tcg_res
, tcg_res
);
9968 case 0x8: /* CMGT, CMGE */
9969 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
9971 case 0x9: /* CMEQ, CMLE */
9972 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
9976 gen_helper_clz32(tcg_res
, tcg_op
);
9978 gen_helper_cls32(tcg_res
, tcg_op
);
9981 case 0x7: /* SQABS, SQNEG */
9983 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
9985 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
9988 case 0xb: /* ABS, NEG */
9990 tcg_gen_neg_i32(tcg_res
, tcg_op
);
9992 TCGv_i32 tcg_zero
= tcg_const_i32(0);
9993 tcg_gen_neg_i32(tcg_res
, tcg_op
);
9994 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
9995 tcg_zero
, tcg_op
, tcg_res
);
9996 tcg_temp_free_i32(tcg_zero
);
9999 case 0x2f: /* FABS */
10000 gen_helper_vfp_abss(tcg_res
, tcg_op
);
10002 case 0x6f: /* FNEG */
10003 gen_helper_vfp_negs(tcg_res
, tcg_op
);
10005 case 0x7f: /* FSQRT */
10006 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
10008 case 0x1a: /* FCVTNS */
10009 case 0x1b: /* FCVTMS */
10010 case 0x1c: /* FCVTAS */
10011 case 0x3a: /* FCVTPS */
10012 case 0x3b: /* FCVTZS */
10014 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10015 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
10016 tcg_shift
, tcg_fpstatus
);
10017 tcg_temp_free_i32(tcg_shift
);
10020 case 0x5a: /* FCVTNU */
10021 case 0x5b: /* FCVTMU */
10022 case 0x5c: /* FCVTAU */
10023 case 0x7a: /* FCVTPU */
10024 case 0x7b: /* FCVTZU */
10026 TCGv_i32 tcg_shift
= tcg_const_i32(0);
10027 gen_helper_vfp_touls(tcg_res
, tcg_op
,
10028 tcg_shift
, tcg_fpstatus
);
10029 tcg_temp_free_i32(tcg_shift
);
10032 case 0x18: /* FRINTN */
10033 case 0x19: /* FRINTM */
10034 case 0x38: /* FRINTP */
10035 case 0x39: /* FRINTZ */
10036 case 0x58: /* FRINTA */
10037 case 0x79: /* FRINTI */
10038 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
10040 case 0x59: /* FRINTX */
10041 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
10043 case 0x7c: /* URSQRTE */
10044 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
10047 g_assert_not_reached();
10050 /* Use helpers for 8 and 16 bit elements */
10052 case 0x5: /* CNT, RBIT */
10053 /* For these two insns size is part of the opcode specifier
10054 * (handled earlier); they always operate on byte elements.
10057 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
10059 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
10062 case 0x7: /* SQABS, SQNEG */
10064 NeonGenOneOpEnvFn
*genfn
;
10065 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
10066 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
10067 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
10069 genfn
= fns
[size
][u
];
10070 genfn(tcg_res
, cpu_env
, tcg_op
);
10073 case 0x8: /* CMGT, CMGE */
10074 case 0x9: /* CMEQ, CMLE */
10075 case 0xa: /* CMLT */
10077 static NeonGenTwoOpFn
* const fns
[3][2] = {
10078 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
10079 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
10080 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
10082 NeonGenTwoOpFn
*genfn
;
10085 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10087 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
10088 comp
= (opcode
- 0x8) * 2 + u
;
10089 /* ...but LE, LT are implemented as reverse GE, GT */
10090 reverse
= (comp
> 2);
10094 genfn
= fns
[comp
][size
];
10096 genfn(tcg_res
, tcg_zero
, tcg_op
);
10098 genfn(tcg_res
, tcg_op
, tcg_zero
);
10100 tcg_temp_free_i32(tcg_zero
);
10103 case 0xb: /* ABS, NEG */
10105 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10107 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
10109 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
10111 tcg_temp_free_i32(tcg_zero
);
10114 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
10116 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
10120 case 0x4: /* CLS, CLZ */
10123 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
10125 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
10129 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
10131 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
10136 g_assert_not_reached();
10140 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10142 tcg_temp_free_i32(tcg_res
);
10143 tcg_temp_free_i32(tcg_op
);
10147 clear_vec_high(s
, rd
);
10151 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10152 tcg_temp_free_i32(tcg_rmode
);
10154 if (need_fpstatus
) {
10155 tcg_temp_free_ptr(tcg_fpstatus
);
10159 /* C3.6.13 AdvSIMD scalar x indexed element
10160 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10161 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10162 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10163 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10164 * C3.6.18 AdvSIMD vector x indexed element
10165 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10166 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10167 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10168 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10170 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
10172 /* This encoding has two kinds of instruction:
10173 * normal, where we perform elt x idxelt => elt for each
10174 * element in the vector
10175 * long, where we perform elt x idxelt and generate a result of
10176 * double the width of the input element
10177 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
10179 bool is_scalar
= extract32(insn
, 28, 1);
10180 bool is_q
= extract32(insn
, 30, 1);
10181 bool u
= extract32(insn
, 29, 1);
10182 int size
= extract32(insn
, 22, 2);
10183 int l
= extract32(insn
, 21, 1);
10184 int m
= extract32(insn
, 20, 1);
10185 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
10186 int rm
= extract32(insn
, 16, 4);
10187 int opcode
= extract32(insn
, 12, 4);
10188 int h
= extract32(insn
, 11, 1);
10189 int rn
= extract32(insn
, 5, 5);
10190 int rd
= extract32(insn
, 0, 5);
10191 bool is_long
= false;
10192 bool is_fp
= false;
10197 case 0x0: /* MLA */
10198 case 0x4: /* MLS */
10199 if (!u
|| is_scalar
) {
10200 unallocated_encoding(s
);
10204 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10205 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10206 case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
10208 unallocated_encoding(s
);
10213 case 0x3: /* SQDMLAL, SQDMLAL2 */
10214 case 0x7: /* SQDMLSL, SQDMLSL2 */
10215 case 0xb: /* SQDMULL, SQDMULL2 */
10218 case 0xc: /* SQDMULH */
10219 case 0xd: /* SQRDMULH */
10221 unallocated_encoding(s
);
10225 case 0x8: /* MUL */
10226 if (u
|| is_scalar
) {
10227 unallocated_encoding(s
);
10231 case 0x1: /* FMLA */
10232 case 0x5: /* FMLS */
10234 unallocated_encoding(s
);
10238 case 0x9: /* FMUL, FMULX */
10239 if (!extract32(size
, 1, 1)) {
10240 unallocated_encoding(s
);
10246 unallocated_encoding(s
);
10251 /* low bit of size indicates single/double */
10252 size
= extract32(size
, 0, 1) ? 3 : 2;
10254 index
= h
<< 1 | l
;
10257 unallocated_encoding(s
);
10266 index
= h
<< 2 | l
<< 1 | m
;
10269 index
= h
<< 1 | l
;
10273 unallocated_encoding(s
);
10278 if (!fp_access_check(s
)) {
10283 fpst
= get_fpstatus_ptr();
10285 TCGV_UNUSED_PTR(fpst
);
10289 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10292 assert(is_fp
&& is_q
&& !is_long
);
10294 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
10296 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10297 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10298 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10300 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10303 case 0x5: /* FMLS */
10304 /* As usual for ARM, separate negation for fused multiply-add */
10305 gen_helper_vfp_negd(tcg_op
, tcg_op
);
10307 case 0x1: /* FMLA */
10308 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10309 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10311 case 0x9: /* FMUL, FMULX */
10313 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10315 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10319 g_assert_not_reached();
10322 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10323 tcg_temp_free_i64(tcg_op
);
10324 tcg_temp_free_i64(tcg_res
);
10328 clear_vec_high(s
, rd
);
10331 tcg_temp_free_i64(tcg_idx
);
10332 } else if (!is_long
) {
10333 /* 32 bit floating point, or 16 or 32 bit integer.
10334 * For the 16 bit scalar case we use the usual Neon helpers and
10335 * rely on the fact that 0 op 0 == 0 with no side effects.
10337 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10338 int pass
, maxpasses
;
10343 maxpasses
= is_q
? 4 : 2;
10346 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10348 if (size
== 1 && !is_scalar
) {
10349 /* The simplest way to handle the 16x16 indexed ops is to duplicate
10350 * the index into both halves of the 32 bit tcg_idx and then use
10351 * the usual Neon helpers.
10353 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10356 for (pass
= 0; pass
< maxpasses
; pass
++) {
10357 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10358 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10360 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
10363 case 0x0: /* MLA */
10364 case 0x4: /* MLS */
10365 case 0x8: /* MUL */
10367 static NeonGenTwoOpFn
* const fns
[2][2] = {
10368 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
10369 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
10371 NeonGenTwoOpFn
*genfn
;
10372 bool is_sub
= opcode
== 0x4;
10375 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
10377 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
10379 if (opcode
== 0x8) {
10382 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
10383 genfn
= fns
[size
- 1][is_sub
];
10384 genfn(tcg_res
, tcg_op
, tcg_res
);
10387 case 0x5: /* FMLS */
10388 /* As usual for ARM, separate negation for fused multiply-add */
10389 gen_helper_vfp_negs(tcg_op
, tcg_op
);
10391 case 0x1: /* FMLA */
10392 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10393 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10395 case 0x9: /* FMUL, FMULX */
10397 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10399 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10402 case 0xc: /* SQDMULH */
10404 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
10407 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
10411 case 0xd: /* SQRDMULH */
10413 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
10416 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
10421 g_assert_not_reached();
10425 write_fp_sreg(s
, rd
, tcg_res
);
10427 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10430 tcg_temp_free_i32(tcg_op
);
10431 tcg_temp_free_i32(tcg_res
);
10434 tcg_temp_free_i32(tcg_idx
);
10437 clear_vec_high(s
, rd
);
10440 /* long ops: 16x16->32 or 32x32->64 */
10441 TCGv_i64 tcg_res
[2];
10443 bool satop
= extract32(opcode
, 0, 1);
10444 TCGMemOp memop
= MO_32
;
10451 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10453 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
10455 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10456 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10457 TCGv_i64 tcg_passres
;
10463 passelt
= pass
+ (is_q
* 2);
10466 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
10468 tcg_res
[pass
] = tcg_temp_new_i64();
10470 if (opcode
== 0xa || opcode
== 0xb) {
10471 /* Non-accumulating ops */
10472 tcg_passres
= tcg_res
[pass
];
10474 tcg_passres
= tcg_temp_new_i64();
10477 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
10478 tcg_temp_free_i64(tcg_op
);
10481 /* saturating, doubling */
10482 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10483 tcg_passres
, tcg_passres
);
10486 if (opcode
== 0xa || opcode
== 0xb) {
10490 /* Accumulating op: handle accumulate step */
10491 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10494 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10495 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10497 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10498 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10500 case 0x7: /* SQDMLSL, SQDMLSL2 */
10501 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10503 case 0x3: /* SQDMLAL, SQDMLAL2 */
10504 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10509 g_assert_not_reached();
10511 tcg_temp_free_i64(tcg_passres
);
10513 tcg_temp_free_i64(tcg_idx
);
10516 clear_vec_high(s
, rd
);
10519 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10522 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10525 /* The simplest way to handle the 16x16 indexed ops is to
10526 * duplicate the index into both halves of the 32 bit tcg_idx
10527 * and then use the usual Neon helpers.
10529 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10532 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10533 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10534 TCGv_i64 tcg_passres
;
10537 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10539 read_vec_element_i32(s
, tcg_op
, rn
,
10540 pass
+ (is_q
* 2), MO_32
);
10543 tcg_res
[pass
] = tcg_temp_new_i64();
10545 if (opcode
== 0xa || opcode
== 0xb) {
10546 /* Non-accumulating ops */
10547 tcg_passres
= tcg_res
[pass
];
10549 tcg_passres
= tcg_temp_new_i64();
10552 if (memop
& MO_SIGN
) {
10553 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
10555 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
10558 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10559 tcg_passres
, tcg_passres
);
10561 tcg_temp_free_i32(tcg_op
);
10563 if (opcode
== 0xa || opcode
== 0xb) {
10567 /* Accumulating op: handle accumulate step */
10568 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10571 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10572 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
10575 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10576 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
10579 case 0x7: /* SQDMLSL, SQDMLSL2 */
10580 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10582 case 0x3: /* SQDMLAL, SQDMLAL2 */
10583 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10588 g_assert_not_reached();
10590 tcg_temp_free_i64(tcg_passres
);
10592 tcg_temp_free_i32(tcg_idx
);
10595 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
10600 tcg_res
[1] = tcg_const_i64(0);
10603 for (pass
= 0; pass
< 2; pass
++) {
10604 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10605 tcg_temp_free_i64(tcg_res
[pass
]);
10609 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
10610 tcg_temp_free_ptr(fpst
);
10614 /* C3.6.19 Crypto AES
10615 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10616 * +-----------------+------+-----------+--------+-----+------+------+
10617 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10618 * +-----------------+------+-----------+--------+-----+------+------+
10620 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
10622 int size
= extract32(insn
, 22, 2);
10623 int opcode
= extract32(insn
, 12, 5);
10624 int rn
= extract32(insn
, 5, 5);
10625 int rd
= extract32(insn
, 0, 5);
10627 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
;
10628 CryptoThreeOpEnvFn
*genfn
;
10630 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)
10632 unallocated_encoding(s
);
10637 case 0x4: /* AESE */
10639 genfn
= gen_helper_crypto_aese
;
10641 case 0x6: /* AESMC */
10643 genfn
= gen_helper_crypto_aesmc
;
10645 case 0x5: /* AESD */
10647 genfn
= gen_helper_crypto_aese
;
10649 case 0x7: /* AESIMC */
10651 genfn
= gen_helper_crypto_aesmc
;
10654 unallocated_encoding(s
);
10658 /* Note that we convert the Vx register indexes into the
10659 * index within the vfp.regs[] array, so we can share the
10660 * helper with the AArch32 instructions.
10662 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10663 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10664 tcg_decrypt
= tcg_const_i32(decrypt
);
10666 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
);
10668 tcg_temp_free_i32(tcg_rd_regno
);
10669 tcg_temp_free_i32(tcg_rn_regno
);
10670 tcg_temp_free_i32(tcg_decrypt
);
10673 /* C3.6.20 Crypto three-reg SHA
10674 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
10675 * +-----------------+------+---+------+---+--------+-----+------+------+
10676 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
10677 * +-----------------+------+---+------+---+--------+-----+------+------+
10679 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
10681 int size
= extract32(insn
, 22, 2);
10682 int opcode
= extract32(insn
, 12, 3);
10683 int rm
= extract32(insn
, 16, 5);
10684 int rn
= extract32(insn
, 5, 5);
10685 int rd
= extract32(insn
, 0, 5);
10686 CryptoThreeOpEnvFn
*genfn
;
10687 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
;
10688 int feature
= ARM_FEATURE_V8_SHA256
;
10691 unallocated_encoding(s
);
10696 case 0: /* SHA1C */
10697 case 1: /* SHA1P */
10698 case 2: /* SHA1M */
10699 case 3: /* SHA1SU0 */
10701 feature
= ARM_FEATURE_V8_SHA1
;
10703 case 4: /* SHA256H */
10704 genfn
= gen_helper_crypto_sha256h
;
10706 case 5: /* SHA256H2 */
10707 genfn
= gen_helper_crypto_sha256h2
;
10709 case 6: /* SHA256SU1 */
10710 genfn
= gen_helper_crypto_sha256su1
;
10713 unallocated_encoding(s
);
10717 if (!arm_dc_feature(s
, feature
)) {
10718 unallocated_encoding(s
);
10722 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10723 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10724 tcg_rm_regno
= tcg_const_i32(rm
<< 1);
10727 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
);
10729 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
10731 gen_helper_crypto_sha1_3reg(cpu_env
, tcg_rd_regno
,
10732 tcg_rn_regno
, tcg_rm_regno
, tcg_opcode
);
10733 tcg_temp_free_i32(tcg_opcode
);
10736 tcg_temp_free_i32(tcg_rd_regno
);
10737 tcg_temp_free_i32(tcg_rn_regno
);
10738 tcg_temp_free_i32(tcg_rm_regno
);
10741 /* C3.6.21 Crypto two-reg SHA
10742 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10743 * +-----------------+------+-----------+--------+-----+------+------+
10744 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10745 * +-----------------+------+-----------+--------+-----+------+------+
10747 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
10749 int size
= extract32(insn
, 22, 2);
10750 int opcode
= extract32(insn
, 12, 5);
10751 int rn
= extract32(insn
, 5, 5);
10752 int rd
= extract32(insn
, 0, 5);
10753 CryptoTwoOpEnvFn
*genfn
;
10755 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
;
10758 unallocated_encoding(s
);
10763 case 0: /* SHA1H */
10764 feature
= ARM_FEATURE_V8_SHA1
;
10765 genfn
= gen_helper_crypto_sha1h
;
10767 case 1: /* SHA1SU1 */
10768 feature
= ARM_FEATURE_V8_SHA1
;
10769 genfn
= gen_helper_crypto_sha1su1
;
10771 case 2: /* SHA256SU0 */
10772 feature
= ARM_FEATURE_V8_SHA256
;
10773 genfn
= gen_helper_crypto_sha256su0
;
10776 unallocated_encoding(s
);
10780 if (!arm_dc_feature(s
, feature
)) {
10781 unallocated_encoding(s
);
10785 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10786 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10788 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
);
10790 tcg_temp_free_i32(tcg_rd_regno
);
10791 tcg_temp_free_i32(tcg_rn_regno
);
10794 /* C3.6 Data processing - SIMD, inc Crypto
10796 * As the decode gets a little complex we are using a table based
10797 * approach for this part of the decode.
10799 static const AArch64DecodeTable data_proc_simd
[] = {
10800 /* pattern , mask , fn */
10801 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
10802 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
10803 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
10804 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
10805 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
10806 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
10807 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
10808 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
10809 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
10810 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
10811 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
10812 { 0x2e000000, 0xbf208400, disas_simd_ext
},
10813 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
10814 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
10815 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
10816 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
10817 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
10818 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
10819 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
10820 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
10821 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
10822 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
10823 { 0x00000000, 0x00000000, NULL
}
10826 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
10828 /* Note that this is called with all non-FP cases from
10829 * table C3-6 so it must UNDEF for entries not specifically
10830 * allocated to instructions in that table.
10832 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
10836 unallocated_encoding(s
);
10840 /* C3.6 Data processing - SIMD and floating point */
10841 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
10843 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
10844 disas_data_proc_fp(s
, insn
);
10846 /* SIMD, including crypto */
10847 disas_data_proc_simd(s
, insn
);
10851 /* C3.1 A64 instruction index by encoding */
10852 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
10856 insn
= arm_ldl_code(env
, s
->pc
, s
->bswap_code
);
10860 s
->fp_access_checked
= false;
10862 switch (extract32(insn
, 25, 4)) {
10863 case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
10864 unallocated_encoding(s
);
10866 case 0x8: case 0x9: /* Data processing - immediate */
10867 disas_data_proc_imm(s
, insn
);
10869 case 0xa: case 0xb: /* Branch, exception generation and system insns */
10870 disas_b_exc_sys(s
, insn
);
10875 case 0xe: /* Loads and stores */
10876 disas_ldst(s
, insn
);
10879 case 0xd: /* Data processing - register */
10880 disas_data_proc_reg(s
, insn
);
10883 case 0xf: /* Data processing - SIMD and floating point */
10884 disas_data_proc_simd_fp(s
, insn
);
10887 assert(FALSE
); /* all 15 cases should be handled above */
10891 /* if we allocated any temporaries, free them here */
10895 void gen_intermediate_code_internal_a64(ARMCPU
*cpu
,
10896 TranslationBlock
*tb
,
10899 CPUState
*cs
= CPU(cpu
);
10900 CPUARMState
*env
= &cpu
->env
;
10901 DisasContext dc1
, *dc
= &dc1
;
10903 uint16_t *gen_opc_end
;
10905 target_ulong pc_start
;
10906 target_ulong next_page_start
;
10914 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
10916 dc
->is_jmp
= DISAS_NEXT
;
10918 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
10923 dc
->bswap_code
= 0;
10924 dc
->condexec_mask
= 0;
10925 dc
->condexec_cond
= 0;
10926 #if !defined(CONFIG_USER_ONLY)
10927 dc
->user
= (ARM_TBFLAG_AA64_EL(tb
->flags
) == 0);
10929 dc
->cpacr_fpen
= ARM_TBFLAG_AA64_FPEN(tb
->flags
);
10931 dc
->vec_stride
= 0;
10932 dc
->cp_regs
= cpu
->cp_regs
;
10933 dc
->current_el
= arm_current_el(env
);
10934 dc
->features
= env
->features
;
10936 /* Single step state. The code-generation logic here is:
10938 * generate code with no special handling for single-stepping (except
10939 * that anything that can make us go to SS_ACTIVE == 1 must end the TB;
10940 * this happens anyway because those changes are all system register or
10942 * SS_ACTIVE == 1, PSTATE.SS == 1: (active-not-pending)
10943 * emit code for one insn
10944 * emit code to clear PSTATE.SS
10945 * emit code to generate software step exception for completed step
10946 * end TB (as usual for having generated an exception)
10947 * SS_ACTIVE == 1, PSTATE.SS == 0: (active-pending)
10948 * emit code to generate a software step exception
10951 dc
->ss_active
= ARM_TBFLAG_AA64_SS_ACTIVE(tb
->flags
);
10952 dc
->pstate_ss
= ARM_TBFLAG_AA64_PSTATE_SS(tb
->flags
);
10953 dc
->is_ldex
= false;
10954 dc
->ss_same_el
= (arm_debug_target_el(env
) == dc
->current_el
);
10956 init_tmp_a64_array(dc
);
10958 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
10961 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
10962 if (max_insns
== 0) {
10963 max_insns
= CF_COUNT_MASK
;
10968 tcg_clear_temp_count();
10971 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
10972 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
10973 if (bp
->pc
== dc
->pc
) {
10974 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
10975 /* Advance PC so that clearing the breakpoint will
10976 invalidate this TB. */
10978 goto done_generating
;
10984 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
10988 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
10991 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
10992 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
10993 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
10996 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
11000 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
11001 tcg_gen_debug_insn_start(dc
->pc
);
11004 if (dc
->ss_active
&& !dc
->pstate_ss
) {
11005 /* Singlestep state is Active-pending.
11006 * If we're in this state at the start of a TB then either
11007 * a) we just took an exception to an EL which is being debugged
11008 * and this is the first insn in the exception handler
11009 * b) debug exceptions were masked and we just unmasked them
11010 * without changing EL (eg by clearing PSTATE.D)
11011 * In either case we're going to take a swstep exception in the
11012 * "did not step an insn" case, and so the syndrome ISV and EX
11013 * bits should be zero.
11015 assert(num_insns
== 0);
11016 gen_exception(EXCP_UDEF
, syn_swstep(dc
->ss_same_el
, 0, 0));
11017 dc
->is_jmp
= DISAS_EXC
;
11021 disas_a64_insn(env
, dc
);
11023 if (tcg_check_temp_count()) {
11024 fprintf(stderr
, "TCG temporary leak before "TARGET_FMT_lx
"\n",
11028 /* Translation stops when a conditional branch is encountered.
11029 * Otherwise the subsequent code could get translated several times.
11030 * Also stop translation when a page boundary is reached. This
11031 * ensures prefetch aborts occur at the right place.
11034 } while (!dc
->is_jmp
&& tcg_ctx
.gen_opc_ptr
< gen_opc_end
&&
11035 !cs
->singlestep_enabled
&&
11038 dc
->pc
< next_page_start
&&
11039 num_insns
< max_insns
);
11041 if (tb
->cflags
& CF_LAST_IO
) {
11045 if (unlikely(cs
->singlestep_enabled
|| dc
->ss_active
)
11046 && dc
->is_jmp
!= DISAS_EXC
) {
11047 /* Note that this means single stepping WFI doesn't halt the CPU.
11048 * For conditional branch insns this is harmless unreachable code as
11049 * gen_goto_tb() has already handled emitting the debug exception
11050 * (and thus a tb-jump is not possible when singlestepping).
11052 assert(dc
->is_jmp
!= DISAS_TB_JUMP
);
11053 if (dc
->is_jmp
!= DISAS_JUMP
) {
11054 gen_a64_set_pc_im(dc
->pc
);
11056 if (cs
->singlestep_enabled
) {
11057 gen_exception_internal(EXCP_DEBUG
);
11059 gen_step_complete_exception(dc
);
11062 switch (dc
->is_jmp
) {
11064 gen_goto_tb(dc
, 1, dc
->pc
);
11068 gen_a64_set_pc_im(dc
->pc
);
11071 /* indicate that the hash table must be used to find the next TB */
11072 tcg_gen_exit_tb(0);
11074 case DISAS_TB_JUMP
:
11079 gen_a64_set_pc_im(dc
->pc
);
11080 gen_helper_wfe(cpu_env
);
11083 /* This is a special case because we don't want to just halt the CPU
11084 * if trying to debug across a WFI.
11086 gen_a64_set_pc_im(dc
->pc
);
11087 gen_helper_wfi(cpu_env
);
11093 gen_tb_end(tb
, num_insns
);
11094 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
11097 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
11098 qemu_log("----------------\n");
11099 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
11100 log_target_disas(env
, pc_start
, dc
->pc
- pc_start
,
11101 4 | (dc
->bswap_code
<< 1));
11106 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
11109 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
11112 tb
->size
= dc
->pc
- pc_start
;
11113 tb
->icount
= num_insns
;