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 static TCGv_i64 cpu_X
[32];
39 static TCGv_i64 cpu_pc
;
40 static TCGv_i32 cpu_NF
, cpu_ZF
, cpu_CF
, cpu_VF
;
42 /* Load/store exclusive handling */
43 static TCGv_i64 cpu_exclusive_addr
;
44 static TCGv_i64 cpu_exclusive_val
;
45 static TCGv_i64 cpu_exclusive_high
;
46 #ifdef CONFIG_USER_ONLY
47 static TCGv_i64 cpu_exclusive_test
;
48 static TCGv_i32 cpu_exclusive_info
;
51 static const char *regnames
[] = {
52 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
53 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
54 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
55 "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
59 A64_SHIFT_TYPE_LSL
= 0,
60 A64_SHIFT_TYPE_LSR
= 1,
61 A64_SHIFT_TYPE_ASR
= 2,
62 A64_SHIFT_TYPE_ROR
= 3
65 /* Table based decoder typedefs - used when the relevant bits for decode
66 * are too awkwardly scattered across the instruction (eg SIMD).
68 typedef void AArch64DecodeFn(DisasContext
*s
, uint32_t insn
);
70 typedef struct AArch64DecodeTable
{
73 AArch64DecodeFn
*disas_fn
;
76 /* Function prototype for gen_ functions for calling Neon helpers */
77 typedef void NeonGenOneOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
);
78 typedef void NeonGenTwoOpFn(TCGv_i32
, TCGv_i32
, TCGv_i32
);
79 typedef void NeonGenTwoOpEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i32
, TCGv_i32
);
80 typedef void NeonGenTwo64OpFn(TCGv_i64
, TCGv_i64
, TCGv_i64
);
81 typedef void NeonGenTwo64OpEnvFn(TCGv_i64
, TCGv_ptr
, TCGv_i64
, TCGv_i64
);
82 typedef void NeonGenNarrowFn(TCGv_i32
, TCGv_i64
);
83 typedef void NeonGenNarrowEnvFn(TCGv_i32
, TCGv_ptr
, TCGv_i64
);
84 typedef void NeonGenWidenFn(TCGv_i64
, TCGv_i32
);
85 typedef void NeonGenTwoSingleOPFn(TCGv_i32
, TCGv_i32
, TCGv_i32
, TCGv_ptr
);
86 typedef void NeonGenTwoDoubleOPFn(TCGv_i64
, TCGv_i64
, TCGv_i64
, TCGv_ptr
);
87 typedef void NeonGenOneOpFn(TCGv_i64
, TCGv_i64
);
88 typedef void CryptoTwoOpEnvFn(TCGv_ptr
, TCGv_i32
, TCGv_i32
);
89 typedef void CryptoThreeOpEnvFn(TCGv_ptr
, TCGv_i32
, TCGv_i32
, TCGv_i32
);
91 /* initialize TCG globals. */
92 void a64_translate_init(void)
96 cpu_pc
= tcg_global_mem_new_i64(TCG_AREG0
,
97 offsetof(CPUARMState
, pc
),
99 for (i
= 0; i
< 32; i
++) {
100 cpu_X
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
101 offsetof(CPUARMState
, xregs
[i
]),
105 cpu_NF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, NF
), "NF");
106 cpu_ZF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, ZF
), "ZF");
107 cpu_CF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, CF
), "CF");
108 cpu_VF
= tcg_global_mem_new_i32(TCG_AREG0
, offsetof(CPUARMState
, VF
), "VF");
110 cpu_exclusive_addr
= tcg_global_mem_new_i64(TCG_AREG0
,
111 offsetof(CPUARMState
, exclusive_addr
), "exclusive_addr");
112 cpu_exclusive_val
= tcg_global_mem_new_i64(TCG_AREG0
,
113 offsetof(CPUARMState
, exclusive_val
), "exclusive_val");
114 cpu_exclusive_high
= tcg_global_mem_new_i64(TCG_AREG0
,
115 offsetof(CPUARMState
, exclusive_high
), "exclusive_high");
116 #ifdef CONFIG_USER_ONLY
117 cpu_exclusive_test
= tcg_global_mem_new_i64(TCG_AREG0
,
118 offsetof(CPUARMState
, exclusive_test
), "exclusive_test");
119 cpu_exclusive_info
= tcg_global_mem_new_i32(TCG_AREG0
,
120 offsetof(CPUARMState
, exclusive_info
), "exclusive_info");
124 void aarch64_cpu_dump_state(CPUState
*cs
, FILE *f
,
125 fprintf_function cpu_fprintf
, int flags
)
127 ARMCPU
*cpu
= ARM_CPU(cs
);
128 CPUARMState
*env
= &cpu
->env
;
129 uint32_t psr
= pstate_read(env
);
132 cpu_fprintf(f
, "PC=%016"PRIx64
" SP=%016"PRIx64
"\n",
133 env
->pc
, env
->xregs
[31]);
134 for (i
= 0; i
< 31; i
++) {
135 cpu_fprintf(f
, "X%02d=%016"PRIx64
, i
, env
->xregs
[i
]);
137 cpu_fprintf(f
, "\n");
142 cpu_fprintf(f
, "PSTATE=%08x (flags %c%c%c%c)\n",
144 psr
& PSTATE_N
? 'N' : '-',
145 psr
& PSTATE_Z
? 'Z' : '-',
146 psr
& PSTATE_C
? 'C' : '-',
147 psr
& PSTATE_V
? 'V' : '-');
148 cpu_fprintf(f
, "\n");
150 if (flags
& CPU_DUMP_FPU
) {
152 for (i
= 0; i
< numvfpregs
; i
+= 2) {
153 uint64_t vlo
= float64_val(env
->vfp
.regs
[i
* 2]);
154 uint64_t vhi
= float64_val(env
->vfp
.regs
[(i
* 2) + 1]);
155 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
" ",
157 vlo
= float64_val(env
->vfp
.regs
[(i
+ 1) * 2]);
158 vhi
= float64_val(env
->vfp
.regs
[((i
+ 1) * 2) + 1]);
159 cpu_fprintf(f
, "q%02d=%016" PRIx64
":%016" PRIx64
"\n",
162 cpu_fprintf(f
, "FPCR: %08x FPSR: %08x\n",
163 vfp_get_fpcr(env
), vfp_get_fpsr(env
));
167 void gen_a64_set_pc_im(uint64_t val
)
169 tcg_gen_movi_i64(cpu_pc
, val
);
172 static void gen_exception_internal(int excp
)
174 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
176 assert(excp_is_internal(excp
));
177 gen_helper_exception_internal(cpu_env
, tcg_excp
);
178 tcg_temp_free_i32(tcg_excp
);
181 static void gen_exception(int excp
, uint32_t syndrome
)
183 TCGv_i32 tcg_excp
= tcg_const_i32(excp
);
184 TCGv_i32 tcg_syn
= tcg_const_i32(syndrome
);
186 gen_helper_exception_with_syndrome(cpu_env
, tcg_excp
, tcg_syn
);
187 tcg_temp_free_i32(tcg_syn
);
188 tcg_temp_free_i32(tcg_excp
);
191 static void gen_exception_internal_insn(DisasContext
*s
, int offset
, int excp
)
193 gen_a64_set_pc_im(s
->pc
- offset
);
194 gen_exception_internal(excp
);
195 s
->is_jmp
= DISAS_EXC
;
198 static void gen_exception_insn(DisasContext
*s
, int offset
, int excp
,
201 gen_a64_set_pc_im(s
->pc
- offset
);
202 gen_exception(excp
, syndrome
);
203 s
->is_jmp
= DISAS_EXC
;
206 static inline bool use_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
208 /* No direct tb linking with singlestep or deterministic io */
209 if (s
->singlestep_enabled
|| (s
->tb
->cflags
& CF_LAST_IO
)) {
213 /* Only link tbs from inside the same guest page */
214 if ((s
->tb
->pc
& TARGET_PAGE_MASK
) != (dest
& TARGET_PAGE_MASK
)) {
221 static inline void gen_goto_tb(DisasContext
*s
, int n
, uint64_t dest
)
223 TranslationBlock
*tb
;
226 if (use_goto_tb(s
, n
, dest
)) {
228 gen_a64_set_pc_im(dest
);
229 tcg_gen_exit_tb((intptr_t)tb
+ n
);
230 s
->is_jmp
= DISAS_TB_JUMP
;
232 gen_a64_set_pc_im(dest
);
233 if (s
->singlestep_enabled
) {
234 gen_exception_internal(EXCP_DEBUG
);
237 s
->is_jmp
= DISAS_JUMP
;
241 static void unallocated_encoding(DisasContext
*s
)
243 /* Unallocated and reserved encodings are uncategorized */
244 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_uncategorized());
247 #define unsupported_encoding(s, insn) \
249 qemu_log_mask(LOG_UNIMP, \
250 "%s:%d: unsupported instruction encoding 0x%08x " \
251 "at pc=%016" PRIx64 "\n", \
252 __FILE__, __LINE__, insn, s->pc - 4); \
253 unallocated_encoding(s); \
256 static void init_tmp_a64_array(DisasContext
*s
)
258 #ifdef CONFIG_DEBUG_TCG
260 for (i
= 0; i
< ARRAY_SIZE(s
->tmp_a64
); i
++) {
261 TCGV_UNUSED_I64(s
->tmp_a64
[i
]);
264 s
->tmp_a64_count
= 0;
267 static void free_tmp_a64(DisasContext
*s
)
270 for (i
= 0; i
< s
->tmp_a64_count
; i
++) {
271 tcg_temp_free_i64(s
->tmp_a64
[i
]);
273 init_tmp_a64_array(s
);
276 static TCGv_i64
new_tmp_a64(DisasContext
*s
)
278 assert(s
->tmp_a64_count
< TMP_A64_MAX
);
279 return s
->tmp_a64
[s
->tmp_a64_count
++] = tcg_temp_new_i64();
282 static TCGv_i64
new_tmp_a64_zero(DisasContext
*s
)
284 TCGv_i64 t
= new_tmp_a64(s
);
285 tcg_gen_movi_i64(t
, 0);
290 * Register access functions
292 * These functions are used for directly accessing a register in where
293 * changes to the final register value are likely to be made. If you
294 * need to use a register for temporary calculation (e.g. index type
295 * operations) use the read_* form.
297 * B1.2.1 Register mappings
299 * In instruction register encoding 31 can refer to ZR (zero register) or
300 * the SP (stack pointer) depending on context. In QEMU's case we map SP
301 * to cpu_X[31] and ZR accesses to a temporary which can be discarded.
302 * This is the point of the _sp forms.
304 static TCGv_i64
cpu_reg(DisasContext
*s
, int reg
)
307 return new_tmp_a64_zero(s
);
313 /* register access for when 31 == SP */
314 static TCGv_i64
cpu_reg_sp(DisasContext
*s
, int reg
)
319 /* read a cpu register in 32bit/64bit mode. Returns a TCGv_i64
320 * representing the register contents. This TCGv is an auto-freed
321 * temporary so it need not be explicitly freed, and may be modified.
323 static TCGv_i64
read_cpu_reg(DisasContext
*s
, int reg
, int sf
)
325 TCGv_i64 v
= new_tmp_a64(s
);
328 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
330 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
333 tcg_gen_movi_i64(v
, 0);
338 static TCGv_i64
read_cpu_reg_sp(DisasContext
*s
, int reg
, int sf
)
340 TCGv_i64 v
= new_tmp_a64(s
);
342 tcg_gen_mov_i64(v
, cpu_X
[reg
]);
344 tcg_gen_ext32u_i64(v
, cpu_X
[reg
]);
349 /* We should have at some point before trying to access an FP register
350 * done the necessary access check, so assert that
351 * (a) we did the check and
352 * (b) we didn't then just plough ahead anyway if it failed.
353 * Print the instruction pattern in the abort message so we can figure
354 * out what we need to fix if a user encounters this problem in the wild.
356 static inline void assert_fp_access_checked(DisasContext
*s
)
358 #ifdef CONFIG_DEBUG_TCG
359 if (unlikely(!s
->fp_access_checked
|| !s
->cpacr_fpen
)) {
360 fprintf(stderr
, "target-arm: FP access check missing for "
361 "instruction 0x%08x\n", s
->insn
);
367 /* Return the offset into CPUARMState of an element of specified
368 * size, 'element' places in from the least significant end of
369 * the FP/vector register Qn.
371 static inline int vec_reg_offset(DisasContext
*s
, int regno
,
372 int element
, TCGMemOp size
)
374 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
375 #ifdef HOST_WORDS_BIGENDIAN
376 /* This is complicated slightly because vfp.regs[2n] is
377 * still the low half and vfp.regs[2n+1] the high half
378 * of the 128 bit vector, even on big endian systems.
379 * Calculate the offset assuming a fully bigendian 128 bits,
380 * then XOR to account for the order of the two 64 bit halves.
382 offs
+= (16 - ((element
+ 1) * (1 << size
)));
385 offs
+= element
* (1 << size
);
387 assert_fp_access_checked(s
);
391 /* Return the offset into CPUARMState of a slice (from
392 * the least significant end) of FP register Qn (ie
394 * (Note that this is not the same mapping as for A32; see cpu.h)
396 static inline int fp_reg_offset(DisasContext
*s
, int regno
, TCGMemOp size
)
398 int offs
= offsetof(CPUARMState
, vfp
.regs
[regno
* 2]);
399 #ifdef HOST_WORDS_BIGENDIAN
400 offs
+= (8 - (1 << size
));
402 assert_fp_access_checked(s
);
406 /* Offset of the high half of the 128 bit vector Qn */
407 static inline int fp_reg_hi_offset(DisasContext
*s
, int regno
)
409 assert_fp_access_checked(s
);
410 return offsetof(CPUARMState
, vfp
.regs
[regno
* 2 + 1]);
413 /* Convenience accessors for reading and writing single and double
414 * FP registers. Writing clears the upper parts of the associated
415 * 128 bit vector register, as required by the architecture.
416 * Note that unlike the GP register accessors, the values returned
417 * by the read functions must be manually freed.
419 static TCGv_i64
read_fp_dreg(DisasContext
*s
, int reg
)
421 TCGv_i64 v
= tcg_temp_new_i64();
423 tcg_gen_ld_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
427 static TCGv_i32
read_fp_sreg(DisasContext
*s
, int reg
)
429 TCGv_i32 v
= tcg_temp_new_i32();
431 tcg_gen_ld_i32(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_32
));
435 static void write_fp_dreg(DisasContext
*s
, int reg
, TCGv_i64 v
)
437 TCGv_i64 tcg_zero
= tcg_const_i64(0);
439 tcg_gen_st_i64(v
, cpu_env
, fp_reg_offset(s
, reg
, MO_64
));
440 tcg_gen_st_i64(tcg_zero
, cpu_env
, fp_reg_hi_offset(s
, reg
));
441 tcg_temp_free_i64(tcg_zero
);
444 static void write_fp_sreg(DisasContext
*s
, int reg
, TCGv_i32 v
)
446 TCGv_i64 tmp
= tcg_temp_new_i64();
448 tcg_gen_extu_i32_i64(tmp
, v
);
449 write_fp_dreg(s
, reg
, tmp
);
450 tcg_temp_free_i64(tmp
);
453 static TCGv_ptr
get_fpstatus_ptr(void)
455 TCGv_ptr statusptr
= tcg_temp_new_ptr();
458 /* In A64 all instructions (both FP and Neon) use the FPCR;
459 * there is no equivalent of the A32 Neon "standard FPSCR value"
460 * and all operations use vfp.fp_status.
462 offset
= offsetof(CPUARMState
, vfp
.fp_status
);
463 tcg_gen_addi_ptr(statusptr
, cpu_env
, offset
);
467 /* Set ZF and NF based on a 64 bit result. This is alas fiddlier
468 * than the 32 bit equivalent.
470 static inline void gen_set_NZ64(TCGv_i64 result
)
472 TCGv_i64 flag
= tcg_temp_new_i64();
474 tcg_gen_setcondi_i64(TCG_COND_NE
, flag
, result
, 0);
475 tcg_gen_trunc_i64_i32(cpu_ZF
, flag
);
476 tcg_gen_shri_i64(flag
, result
, 32);
477 tcg_gen_trunc_i64_i32(cpu_NF
, flag
);
478 tcg_temp_free_i64(flag
);
481 /* Set NZCV as for a logical operation: NZ as per result, CV cleared. */
482 static inline void gen_logic_CC(int sf
, TCGv_i64 result
)
485 gen_set_NZ64(result
);
487 tcg_gen_trunc_i64_i32(cpu_ZF
, result
);
488 tcg_gen_trunc_i64_i32(cpu_NF
, result
);
490 tcg_gen_movi_i32(cpu_CF
, 0);
491 tcg_gen_movi_i32(cpu_VF
, 0);
494 /* dest = T0 + T1; compute C, N, V and Z flags */
495 static void gen_add_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
498 TCGv_i64 result
, flag
, tmp
;
499 result
= tcg_temp_new_i64();
500 flag
= tcg_temp_new_i64();
501 tmp
= tcg_temp_new_i64();
503 tcg_gen_movi_i64(tmp
, 0);
504 tcg_gen_add2_i64(result
, flag
, t0
, tmp
, t1
, tmp
);
506 tcg_gen_trunc_i64_i32(cpu_CF
, flag
);
508 gen_set_NZ64(result
);
510 tcg_gen_xor_i64(flag
, result
, t0
);
511 tcg_gen_xor_i64(tmp
, t0
, t1
);
512 tcg_gen_andc_i64(flag
, flag
, tmp
);
513 tcg_temp_free_i64(tmp
);
514 tcg_gen_shri_i64(flag
, flag
, 32);
515 tcg_gen_trunc_i64_i32(cpu_VF
, flag
);
517 tcg_gen_mov_i64(dest
, result
);
518 tcg_temp_free_i64(result
);
519 tcg_temp_free_i64(flag
);
521 /* 32 bit arithmetic */
522 TCGv_i32 t0_32
= tcg_temp_new_i32();
523 TCGv_i32 t1_32
= tcg_temp_new_i32();
524 TCGv_i32 tmp
= tcg_temp_new_i32();
526 tcg_gen_movi_i32(tmp
, 0);
527 tcg_gen_trunc_i64_i32(t0_32
, t0
);
528 tcg_gen_trunc_i64_i32(t1_32
, t1
);
529 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, t1_32
, tmp
);
530 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
531 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
532 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
533 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
534 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
536 tcg_temp_free_i32(tmp
);
537 tcg_temp_free_i32(t0_32
);
538 tcg_temp_free_i32(t1_32
);
542 /* dest = T0 - T1; compute C, N, V and Z flags */
543 static void gen_sub_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
546 /* 64 bit arithmetic */
547 TCGv_i64 result
, flag
, tmp
;
549 result
= tcg_temp_new_i64();
550 flag
= tcg_temp_new_i64();
551 tcg_gen_sub_i64(result
, t0
, t1
);
553 gen_set_NZ64(result
);
555 tcg_gen_setcond_i64(TCG_COND_GEU
, flag
, t0
, t1
);
556 tcg_gen_trunc_i64_i32(cpu_CF
, flag
);
558 tcg_gen_xor_i64(flag
, result
, t0
);
559 tmp
= tcg_temp_new_i64();
560 tcg_gen_xor_i64(tmp
, t0
, t1
);
561 tcg_gen_and_i64(flag
, flag
, tmp
);
562 tcg_temp_free_i64(tmp
);
563 tcg_gen_shri_i64(flag
, flag
, 32);
564 tcg_gen_trunc_i64_i32(cpu_VF
, flag
);
565 tcg_gen_mov_i64(dest
, result
);
566 tcg_temp_free_i64(flag
);
567 tcg_temp_free_i64(result
);
569 /* 32 bit arithmetic */
570 TCGv_i32 t0_32
= tcg_temp_new_i32();
571 TCGv_i32 t1_32
= tcg_temp_new_i32();
574 tcg_gen_trunc_i64_i32(t0_32
, t0
);
575 tcg_gen_trunc_i64_i32(t1_32
, t1
);
576 tcg_gen_sub_i32(cpu_NF
, t0_32
, t1_32
);
577 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
578 tcg_gen_setcond_i32(TCG_COND_GEU
, cpu_CF
, t0_32
, t1_32
);
579 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
580 tmp
= tcg_temp_new_i32();
581 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
582 tcg_temp_free_i32(t0_32
);
583 tcg_temp_free_i32(t1_32
);
584 tcg_gen_and_i32(cpu_VF
, cpu_VF
, tmp
);
585 tcg_temp_free_i32(tmp
);
586 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
590 /* dest = T0 + T1 + CF; do not compute flags. */
591 static void gen_adc(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
593 TCGv_i64 flag
= tcg_temp_new_i64();
594 tcg_gen_extu_i32_i64(flag
, cpu_CF
);
595 tcg_gen_add_i64(dest
, t0
, t1
);
596 tcg_gen_add_i64(dest
, dest
, flag
);
597 tcg_temp_free_i64(flag
);
600 tcg_gen_ext32u_i64(dest
, dest
);
604 /* dest = T0 + T1 + CF; compute C, N, V and Z flags. */
605 static void gen_adc_CC(int sf
, TCGv_i64 dest
, TCGv_i64 t0
, TCGv_i64 t1
)
608 TCGv_i64 result
, cf_64
, vf_64
, tmp
;
609 result
= tcg_temp_new_i64();
610 cf_64
= tcg_temp_new_i64();
611 vf_64
= tcg_temp_new_i64();
612 tmp
= tcg_const_i64(0);
614 tcg_gen_extu_i32_i64(cf_64
, cpu_CF
);
615 tcg_gen_add2_i64(result
, cf_64
, t0
, tmp
, cf_64
, tmp
);
616 tcg_gen_add2_i64(result
, cf_64
, result
, cf_64
, t1
, tmp
);
617 tcg_gen_trunc_i64_i32(cpu_CF
, cf_64
);
618 gen_set_NZ64(result
);
620 tcg_gen_xor_i64(vf_64
, result
, t0
);
621 tcg_gen_xor_i64(tmp
, t0
, t1
);
622 tcg_gen_andc_i64(vf_64
, vf_64
, tmp
);
623 tcg_gen_shri_i64(vf_64
, vf_64
, 32);
624 tcg_gen_trunc_i64_i32(cpu_VF
, vf_64
);
626 tcg_gen_mov_i64(dest
, result
);
628 tcg_temp_free_i64(tmp
);
629 tcg_temp_free_i64(vf_64
);
630 tcg_temp_free_i64(cf_64
);
631 tcg_temp_free_i64(result
);
633 TCGv_i32 t0_32
, t1_32
, tmp
;
634 t0_32
= tcg_temp_new_i32();
635 t1_32
= tcg_temp_new_i32();
636 tmp
= tcg_const_i32(0);
638 tcg_gen_trunc_i64_i32(t0_32
, t0
);
639 tcg_gen_trunc_i64_i32(t1_32
, t1
);
640 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, t0_32
, tmp
, cpu_CF
, tmp
);
641 tcg_gen_add2_i32(cpu_NF
, cpu_CF
, cpu_NF
, cpu_CF
, t1_32
, tmp
);
643 tcg_gen_mov_i32(cpu_ZF
, cpu_NF
);
644 tcg_gen_xor_i32(cpu_VF
, cpu_NF
, t0_32
);
645 tcg_gen_xor_i32(tmp
, t0_32
, t1_32
);
646 tcg_gen_andc_i32(cpu_VF
, cpu_VF
, tmp
);
647 tcg_gen_extu_i32_i64(dest
, cpu_NF
);
649 tcg_temp_free_i32(tmp
);
650 tcg_temp_free_i32(t1_32
);
651 tcg_temp_free_i32(t0_32
);
656 * Load/Store generators
660 * Store from GPR register to memory.
662 static void do_gpr_st_memidx(DisasContext
*s
, TCGv_i64 source
,
663 TCGv_i64 tcg_addr
, int size
, int memidx
)
666 tcg_gen_qemu_st_i64(source
, tcg_addr
, memidx
, MO_TE
+ size
);
669 static void do_gpr_st(DisasContext
*s
, TCGv_i64 source
,
670 TCGv_i64 tcg_addr
, int size
)
672 do_gpr_st_memidx(s
, source
, tcg_addr
, size
, get_mem_index(s
));
676 * Load from memory to GPR register
678 static void do_gpr_ld_memidx(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
679 int size
, bool is_signed
, bool extend
, int memidx
)
681 TCGMemOp memop
= MO_TE
+ size
;
689 tcg_gen_qemu_ld_i64(dest
, tcg_addr
, memidx
, memop
);
691 if (extend
&& is_signed
) {
693 tcg_gen_ext32u_i64(dest
, dest
);
697 static void do_gpr_ld(DisasContext
*s
, TCGv_i64 dest
, TCGv_i64 tcg_addr
,
698 int size
, bool is_signed
, bool extend
)
700 do_gpr_ld_memidx(s
, dest
, tcg_addr
, size
, is_signed
, extend
,
705 * Store from FP register to memory
707 static void do_fp_st(DisasContext
*s
, int srcidx
, TCGv_i64 tcg_addr
, int size
)
709 /* This writes the bottom N bits of a 128 bit wide vector to memory */
710 TCGv_i64 tmp
= tcg_temp_new_i64();
711 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_offset(s
, srcidx
, MO_64
));
713 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TE
+ size
);
715 TCGv_i64 tcg_hiaddr
= tcg_temp_new_i64();
716 tcg_gen_qemu_st_i64(tmp
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
717 tcg_gen_qemu_st64(tmp
, tcg_addr
, get_mem_index(s
));
718 tcg_gen_ld_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, srcidx
));
719 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
720 tcg_gen_qemu_st_i64(tmp
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
721 tcg_temp_free_i64(tcg_hiaddr
);
724 tcg_temp_free_i64(tmp
);
728 * Load from memory to FP register
730 static void do_fp_ld(DisasContext
*s
, int destidx
, TCGv_i64 tcg_addr
, int size
)
732 /* This always zero-extends and writes to a full 128 bit wide vector */
733 TCGv_i64 tmplo
= tcg_temp_new_i64();
737 TCGMemOp memop
= MO_TE
+ size
;
738 tmphi
= tcg_const_i64(0);
739 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), memop
);
742 tmphi
= tcg_temp_new_i64();
743 tcg_hiaddr
= tcg_temp_new_i64();
745 tcg_gen_qemu_ld_i64(tmplo
, tcg_addr
, get_mem_index(s
), MO_TEQ
);
746 tcg_gen_addi_i64(tcg_hiaddr
, tcg_addr
, 8);
747 tcg_gen_qemu_ld_i64(tmphi
, tcg_hiaddr
, get_mem_index(s
), MO_TEQ
);
748 tcg_temp_free_i64(tcg_hiaddr
);
751 tcg_gen_st_i64(tmplo
, cpu_env
, fp_reg_offset(s
, destidx
, MO_64
));
752 tcg_gen_st_i64(tmphi
, cpu_env
, fp_reg_hi_offset(s
, destidx
));
754 tcg_temp_free_i64(tmplo
);
755 tcg_temp_free_i64(tmphi
);
759 * Vector load/store helpers.
761 * The principal difference between this and a FP load is that we don't
762 * zero extend as we are filling a partial chunk of the vector register.
763 * These functions don't support 128 bit loads/stores, which would be
764 * normal load/store operations.
766 * The _i32 versions are useful when operating on 32 bit quantities
767 * (eg for floating point single or using Neon helper functions).
770 /* Get value of an element within a vector register */
771 static void read_vec_element(DisasContext
*s
, TCGv_i64 tcg_dest
, int srcidx
,
772 int element
, TCGMemOp memop
)
774 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
777 tcg_gen_ld8u_i64(tcg_dest
, cpu_env
, vect_off
);
780 tcg_gen_ld16u_i64(tcg_dest
, cpu_env
, vect_off
);
783 tcg_gen_ld32u_i64(tcg_dest
, cpu_env
, vect_off
);
786 tcg_gen_ld8s_i64(tcg_dest
, cpu_env
, vect_off
);
789 tcg_gen_ld16s_i64(tcg_dest
, cpu_env
, vect_off
);
792 tcg_gen_ld32s_i64(tcg_dest
, cpu_env
, vect_off
);
796 tcg_gen_ld_i64(tcg_dest
, cpu_env
, vect_off
);
799 g_assert_not_reached();
803 static void read_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_dest
, int srcidx
,
804 int element
, TCGMemOp memop
)
806 int vect_off
= vec_reg_offset(s
, srcidx
, element
, memop
& MO_SIZE
);
809 tcg_gen_ld8u_i32(tcg_dest
, cpu_env
, vect_off
);
812 tcg_gen_ld16u_i32(tcg_dest
, cpu_env
, vect_off
);
815 tcg_gen_ld8s_i32(tcg_dest
, cpu_env
, vect_off
);
818 tcg_gen_ld16s_i32(tcg_dest
, cpu_env
, vect_off
);
822 tcg_gen_ld_i32(tcg_dest
, cpu_env
, vect_off
);
825 g_assert_not_reached();
829 /* Set value of an element within a vector register */
830 static void write_vec_element(DisasContext
*s
, TCGv_i64 tcg_src
, int destidx
,
831 int element
, TCGMemOp memop
)
833 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
836 tcg_gen_st8_i64(tcg_src
, cpu_env
, vect_off
);
839 tcg_gen_st16_i64(tcg_src
, cpu_env
, vect_off
);
842 tcg_gen_st32_i64(tcg_src
, cpu_env
, vect_off
);
845 tcg_gen_st_i64(tcg_src
, cpu_env
, vect_off
);
848 g_assert_not_reached();
852 static void write_vec_element_i32(DisasContext
*s
, TCGv_i32 tcg_src
,
853 int destidx
, int element
, TCGMemOp memop
)
855 int vect_off
= vec_reg_offset(s
, destidx
, element
, memop
& MO_SIZE
);
858 tcg_gen_st8_i32(tcg_src
, cpu_env
, vect_off
);
861 tcg_gen_st16_i32(tcg_src
, cpu_env
, vect_off
);
864 tcg_gen_st_i32(tcg_src
, cpu_env
, vect_off
);
867 g_assert_not_reached();
871 /* Clear the high 64 bits of a 128 bit vector (in general non-quad
872 * vector ops all need to do this).
874 static void clear_vec_high(DisasContext
*s
, int rd
)
876 TCGv_i64 tcg_zero
= tcg_const_i64(0);
878 write_vec_element(s
, tcg_zero
, rd
, 1, MO_64
);
879 tcg_temp_free_i64(tcg_zero
);
882 /* Store from vector register to memory */
883 static void do_vec_st(DisasContext
*s
, int srcidx
, int element
,
884 TCGv_i64 tcg_addr
, int size
)
886 TCGMemOp memop
= MO_TE
+ size
;
887 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
889 read_vec_element(s
, tcg_tmp
, srcidx
, element
, size
);
890 tcg_gen_qemu_st_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
892 tcg_temp_free_i64(tcg_tmp
);
895 /* Load from memory to vector register */
896 static void do_vec_ld(DisasContext
*s
, int destidx
, int element
,
897 TCGv_i64 tcg_addr
, int size
)
899 TCGMemOp memop
= MO_TE
+ size
;
900 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
902 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
, get_mem_index(s
), memop
);
903 write_vec_element(s
, tcg_tmp
, destidx
, element
, size
);
905 tcg_temp_free_i64(tcg_tmp
);
908 /* Check that FP/Neon access is enabled. If it is, return
909 * true. If not, emit code to generate an appropriate exception,
910 * and return false; the caller should not emit any code for
911 * the instruction. Note that this check must happen after all
912 * unallocated-encoding checks (otherwise the syndrome information
913 * for the resulting exception will be incorrect).
915 static inline bool fp_access_check(DisasContext
*s
)
917 assert(!s
->fp_access_checked
);
918 s
->fp_access_checked
= true;
924 gen_exception_insn(s
, 4, EXCP_UDEF
, syn_fp_access_trap(1, 0xe, false));
929 * This utility function is for doing register extension with an
930 * optional shift. You will likely want to pass a temporary for the
931 * destination register. See DecodeRegExtend() in the ARM ARM.
933 static void ext_and_shift_reg(TCGv_i64 tcg_out
, TCGv_i64 tcg_in
,
934 int option
, unsigned int shift
)
936 int extsize
= extract32(option
, 0, 2);
937 bool is_signed
= extract32(option
, 2, 1);
942 tcg_gen_ext8s_i64(tcg_out
, tcg_in
);
945 tcg_gen_ext16s_i64(tcg_out
, tcg_in
);
948 tcg_gen_ext32s_i64(tcg_out
, tcg_in
);
951 tcg_gen_mov_i64(tcg_out
, tcg_in
);
957 tcg_gen_ext8u_i64(tcg_out
, tcg_in
);
960 tcg_gen_ext16u_i64(tcg_out
, tcg_in
);
963 tcg_gen_ext32u_i64(tcg_out
, tcg_in
);
966 tcg_gen_mov_i64(tcg_out
, tcg_in
);
972 tcg_gen_shli_i64(tcg_out
, tcg_out
, shift
);
976 static inline void gen_check_sp_alignment(DisasContext
*s
)
978 /* The AArch64 architecture mandates that (if enabled via PSTATE
979 * or SCTLR bits) there is a check that SP is 16-aligned on every
980 * SP-relative load or store (with an exception generated if it is not).
981 * In line with general QEMU practice regarding misaligned accesses,
982 * we omit these checks for the sake of guest program performance.
983 * This function is provided as a hook so we can more easily add these
984 * checks in future (possibly as a "favour catching guest program bugs
985 * over speed" user selectable option).
990 * This provides a simple table based table lookup decoder. It is
991 * intended to be used when the relevant bits for decode are too
992 * awkwardly placed and switch/if based logic would be confusing and
993 * deeply nested. Since it's a linear search through the table, tables
994 * should be kept small.
996 * It returns the first handler where insn & mask == pattern, or
997 * NULL if there is no match.
998 * The table is terminated by an empty mask (i.e. 0)
1000 static inline AArch64DecodeFn
*lookup_disas_fn(const AArch64DecodeTable
*table
,
1003 const AArch64DecodeTable
*tptr
= table
;
1005 while (tptr
->mask
) {
1006 if ((insn
& tptr
->mask
) == tptr
->pattern
) {
1007 return tptr
->disas_fn
;
1015 * the instruction disassembly implemented here matches
1016 * the instruction encoding classifications in chapter 3 (C3)
1017 * of the ARM Architecture Reference Manual (DDI0487A_a)
1020 /* C3.2.7 Unconditional branch (immediate)
1022 * +----+-----------+-------------------------------------+
1023 * | op | 0 0 1 0 1 | imm26 |
1024 * +----+-----------+-------------------------------------+
1026 static void disas_uncond_b_imm(DisasContext
*s
, uint32_t insn
)
1028 uint64_t addr
= s
->pc
+ sextract32(insn
, 0, 26) * 4 - 4;
1030 if (insn
& (1 << 31)) {
1031 /* C5.6.26 BL Branch with link */
1032 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1035 /* C5.6.20 B Branch / C5.6.26 BL Branch with link */
1036 gen_goto_tb(s
, 0, addr
);
1039 /* C3.2.1 Compare & branch (immediate)
1040 * 31 30 25 24 23 5 4 0
1041 * +----+-------------+----+---------------------+--------+
1042 * | sf | 0 1 1 0 1 0 | op | imm19 | Rt |
1043 * +----+-------------+----+---------------------+--------+
1045 static void disas_comp_b_imm(DisasContext
*s
, uint32_t insn
)
1047 unsigned int sf
, op
, rt
;
1052 sf
= extract32(insn
, 31, 1);
1053 op
= extract32(insn
, 24, 1); /* 0: CBZ; 1: CBNZ */
1054 rt
= extract32(insn
, 0, 5);
1055 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1057 tcg_cmp
= read_cpu_reg(s
, rt
, sf
);
1058 label_match
= gen_new_label();
1060 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1061 tcg_cmp
, 0, label_match
);
1063 gen_goto_tb(s
, 0, s
->pc
);
1064 gen_set_label(label_match
);
1065 gen_goto_tb(s
, 1, addr
);
1068 /* C3.2.5 Test & branch (immediate)
1069 * 31 30 25 24 23 19 18 5 4 0
1070 * +----+-------------+----+-------+-------------+------+
1071 * | b5 | 0 1 1 0 1 1 | op | b40 | imm14 | Rt |
1072 * +----+-------------+----+-------+-------------+------+
1074 static void disas_test_b_imm(DisasContext
*s
, uint32_t insn
)
1076 unsigned int bit_pos
, op
, rt
;
1081 bit_pos
= (extract32(insn
, 31, 1) << 5) | extract32(insn
, 19, 5);
1082 op
= extract32(insn
, 24, 1); /* 0: TBZ; 1: TBNZ */
1083 addr
= s
->pc
+ sextract32(insn
, 5, 14) * 4 - 4;
1084 rt
= extract32(insn
, 0, 5);
1086 tcg_cmp
= tcg_temp_new_i64();
1087 tcg_gen_andi_i64(tcg_cmp
, cpu_reg(s
, rt
), (1ULL << bit_pos
));
1088 label_match
= gen_new_label();
1089 tcg_gen_brcondi_i64(op
? TCG_COND_NE
: TCG_COND_EQ
,
1090 tcg_cmp
, 0, label_match
);
1091 tcg_temp_free_i64(tcg_cmp
);
1092 gen_goto_tb(s
, 0, s
->pc
);
1093 gen_set_label(label_match
);
1094 gen_goto_tb(s
, 1, addr
);
1097 /* C3.2.2 / C5.6.19 Conditional branch (immediate)
1098 * 31 25 24 23 5 4 3 0
1099 * +---------------+----+---------------------+----+------+
1100 * | 0 1 0 1 0 1 0 | o1 | imm19 | o0 | cond |
1101 * +---------------+----+---------------------+----+------+
1103 static void disas_cond_b_imm(DisasContext
*s
, uint32_t insn
)
1108 if ((insn
& (1 << 4)) || (insn
& (1 << 24))) {
1109 unallocated_encoding(s
);
1112 addr
= s
->pc
+ sextract32(insn
, 5, 19) * 4 - 4;
1113 cond
= extract32(insn
, 0, 4);
1116 /* genuinely conditional branches */
1117 int label_match
= gen_new_label();
1118 arm_gen_test_cc(cond
, label_match
);
1119 gen_goto_tb(s
, 0, s
->pc
);
1120 gen_set_label(label_match
);
1121 gen_goto_tb(s
, 1, addr
);
1123 /* 0xe and 0xf are both "always" conditions */
1124 gen_goto_tb(s
, 0, addr
);
1129 static void handle_hint(DisasContext
*s
, uint32_t insn
,
1130 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1132 unsigned int selector
= crm
<< 3 | op2
;
1135 unallocated_encoding(s
);
1143 s
->is_jmp
= DISAS_WFI
;
1147 s
->is_jmp
= DISAS_WFE
;
1151 /* we treat all as NOP at least for now */
1154 /* default specified as NOP equivalent */
1159 static void gen_clrex(DisasContext
*s
, uint32_t insn
)
1161 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1164 /* CLREX, DSB, DMB, ISB */
1165 static void handle_sync(DisasContext
*s
, uint32_t insn
,
1166 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1169 unallocated_encoding(s
);
1180 /* We don't emulate caches so barriers are no-ops */
1183 unallocated_encoding(s
);
1188 /* C5.6.130 MSR (immediate) - move immediate to processor state field */
1189 static void handle_msr_i(DisasContext
*s
, uint32_t insn
,
1190 unsigned int op1
, unsigned int op2
, unsigned int crm
)
1192 int op
= op1
<< 3 | op2
;
1194 case 0x05: /* SPSel */
1195 if (s
->current_pl
== 0) {
1196 unallocated_encoding(s
);
1200 case 0x1e: /* DAIFSet */
1201 case 0x1f: /* DAIFClear */
1203 TCGv_i32 tcg_imm
= tcg_const_i32(crm
);
1204 TCGv_i32 tcg_op
= tcg_const_i32(op
);
1205 gen_a64_set_pc_im(s
->pc
- 4);
1206 gen_helper_msr_i_pstate(cpu_env
, tcg_op
, tcg_imm
);
1207 tcg_temp_free_i32(tcg_imm
);
1208 tcg_temp_free_i32(tcg_op
);
1209 s
->is_jmp
= DISAS_UPDATE
;
1213 unallocated_encoding(s
);
1218 static void gen_get_nzcv(TCGv_i64 tcg_rt
)
1220 TCGv_i32 tmp
= tcg_temp_new_i32();
1221 TCGv_i32 nzcv
= tcg_temp_new_i32();
1223 /* build bit 31, N */
1224 tcg_gen_andi_i32(nzcv
, cpu_NF
, (1 << 31));
1225 /* build bit 30, Z */
1226 tcg_gen_setcondi_i32(TCG_COND_EQ
, tmp
, cpu_ZF
, 0);
1227 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 30, 1);
1228 /* build bit 29, C */
1229 tcg_gen_deposit_i32(nzcv
, nzcv
, cpu_CF
, 29, 1);
1230 /* build bit 28, V */
1231 tcg_gen_shri_i32(tmp
, cpu_VF
, 31);
1232 tcg_gen_deposit_i32(nzcv
, nzcv
, tmp
, 28, 1);
1233 /* generate result */
1234 tcg_gen_extu_i32_i64(tcg_rt
, nzcv
);
1236 tcg_temp_free_i32(nzcv
);
1237 tcg_temp_free_i32(tmp
);
1240 static void gen_set_nzcv(TCGv_i64 tcg_rt
)
1243 TCGv_i32 nzcv
= tcg_temp_new_i32();
1245 /* take NZCV from R[t] */
1246 tcg_gen_trunc_i64_i32(nzcv
, tcg_rt
);
1249 tcg_gen_andi_i32(cpu_NF
, nzcv
, (1 << 31));
1251 tcg_gen_andi_i32(cpu_ZF
, nzcv
, (1 << 30));
1252 tcg_gen_setcondi_i32(TCG_COND_EQ
, cpu_ZF
, cpu_ZF
, 0);
1254 tcg_gen_andi_i32(cpu_CF
, nzcv
, (1 << 29));
1255 tcg_gen_shri_i32(cpu_CF
, cpu_CF
, 29);
1257 tcg_gen_andi_i32(cpu_VF
, nzcv
, (1 << 28));
1258 tcg_gen_shli_i32(cpu_VF
, cpu_VF
, 3);
1259 tcg_temp_free_i32(nzcv
);
1262 /* C5.6.129 MRS - move from system register
1263 * C5.6.131 MSR (register) - move to system register
1266 * These are all essentially the same insn in 'read' and 'write'
1267 * versions, with varying op0 fields.
1269 static void handle_sys(DisasContext
*s
, uint32_t insn
, bool isread
,
1270 unsigned int op0
, unsigned int op1
, unsigned int op2
,
1271 unsigned int crn
, unsigned int crm
, unsigned int rt
)
1273 const ARMCPRegInfo
*ri
;
1276 ri
= get_arm_cp_reginfo(s
->cp_regs
,
1277 ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP
,
1278 crn
, crm
, op0
, op1
, op2
));
1281 /* Unknown register; this might be a guest error or a QEMU
1282 * unimplemented feature.
1284 qemu_log_mask(LOG_UNIMP
, "%s access to unsupported AArch64 "
1285 "system register op0:%d op1:%d crn:%d crm:%d op2:%d\n",
1286 isread
? "read" : "write", op0
, op1
, crn
, crm
, op2
);
1287 unallocated_encoding(s
);
1291 /* Check access permissions */
1292 if (!cp_access_ok(s
->current_pl
, ri
, isread
)) {
1293 unallocated_encoding(s
);
1298 /* Emit code to perform further access permissions checks at
1299 * runtime; this may result in an exception.
1305 gen_a64_set_pc_im(s
->pc
- 4);
1306 tmpptr
= tcg_const_ptr(ri
);
1307 syndrome
= syn_aa64_sysregtrap(op0
, op1
, op2
, crn
, crm
, rt
, isread
);
1308 tcg_syn
= tcg_const_i32(syndrome
);
1309 gen_helper_access_check_cp_reg(cpu_env
, tmpptr
, tcg_syn
);
1310 tcg_temp_free_ptr(tmpptr
);
1311 tcg_temp_free_i32(tcg_syn
);
1314 /* Handle special cases first */
1315 switch (ri
->type
& ~(ARM_CP_FLAG_MASK
& ~ARM_CP_SPECIAL
)) {
1319 tcg_rt
= cpu_reg(s
, rt
);
1321 gen_get_nzcv(tcg_rt
);
1323 gen_set_nzcv(tcg_rt
);
1326 case ARM_CP_CURRENTEL
:
1327 /* Reads as current EL value from pstate, which is
1328 * guaranteed to be constant by the tb flags.
1330 tcg_rt
= cpu_reg(s
, rt
);
1331 tcg_gen_movi_i64(tcg_rt
, s
->current_pl
<< 2);
1334 /* Writes clear the aligned block of memory which rt points into. */
1335 tcg_rt
= cpu_reg(s
, rt
);
1336 gen_helper_dc_zva(cpu_env
, tcg_rt
);
1342 if (use_icount
&& (ri
->type
& ARM_CP_IO
)) {
1346 tcg_rt
= cpu_reg(s
, rt
);
1349 if (ri
->type
& ARM_CP_CONST
) {
1350 tcg_gen_movi_i64(tcg_rt
, ri
->resetvalue
);
1351 } else if (ri
->readfn
) {
1353 tmpptr
= tcg_const_ptr(ri
);
1354 gen_helper_get_cp_reg64(tcg_rt
, cpu_env
, tmpptr
);
1355 tcg_temp_free_ptr(tmpptr
);
1357 tcg_gen_ld_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1360 if (ri
->type
& ARM_CP_CONST
) {
1361 /* If not forbidden by access permissions, treat as WI */
1363 } else if (ri
->writefn
) {
1365 tmpptr
= tcg_const_ptr(ri
);
1366 gen_helper_set_cp_reg64(cpu_env
, tmpptr
, tcg_rt
);
1367 tcg_temp_free_ptr(tmpptr
);
1369 tcg_gen_st_i64(tcg_rt
, cpu_env
, ri
->fieldoffset
);
1373 if (use_icount
&& (ri
->type
& ARM_CP_IO
)) {
1374 /* I/O operations must end the TB here (whether read or write) */
1376 s
->is_jmp
= DISAS_UPDATE
;
1377 } else if (!isread
&& !(ri
->type
& ARM_CP_SUPPRESS_TB_END
)) {
1378 /* We default to ending the TB on a coprocessor register write,
1379 * but allow this to be suppressed by the register definition
1380 * (usually only necessary to work around guest bugs).
1382 s
->is_jmp
= DISAS_UPDATE
;
1387 * 31 22 21 20 19 18 16 15 12 11 8 7 5 4 0
1388 * +---------------------+---+-----+-----+-------+-------+-----+------+
1389 * | 1 1 0 1 0 1 0 1 0 0 | L | op0 | op1 | CRn | CRm | op2 | Rt |
1390 * +---------------------+---+-----+-----+-------+-------+-----+------+
1392 static void disas_system(DisasContext
*s
, uint32_t insn
)
1394 unsigned int l
, op0
, op1
, crn
, crm
, op2
, rt
;
1395 l
= extract32(insn
, 21, 1);
1396 op0
= extract32(insn
, 19, 2);
1397 op1
= extract32(insn
, 16, 3);
1398 crn
= extract32(insn
, 12, 4);
1399 crm
= extract32(insn
, 8, 4);
1400 op2
= extract32(insn
, 5, 3);
1401 rt
= extract32(insn
, 0, 5);
1404 if (l
|| rt
!= 31) {
1405 unallocated_encoding(s
);
1409 case 2: /* C5.6.68 HINT */
1410 handle_hint(s
, insn
, op1
, op2
, crm
);
1412 case 3: /* CLREX, DSB, DMB, ISB */
1413 handle_sync(s
, insn
, op1
, op2
, crm
);
1415 case 4: /* C5.6.130 MSR (immediate) */
1416 handle_msr_i(s
, insn
, op1
, op2
, crm
);
1419 unallocated_encoding(s
);
1424 handle_sys(s
, insn
, l
, op0
, op1
, op2
, crn
, crm
, rt
);
1427 /* C3.2.3 Exception generation
1429 * 31 24 23 21 20 5 4 2 1 0
1430 * +-----------------+-----+------------------------+-----+----+
1431 * | 1 1 0 1 0 1 0 0 | opc | imm16 | op2 | LL |
1432 * +-----------------------+------------------------+----------+
1434 static void disas_exc(DisasContext
*s
, uint32_t insn
)
1436 int opc
= extract32(insn
, 21, 3);
1437 int op2_ll
= extract32(insn
, 0, 5);
1438 int imm16
= extract32(insn
, 5, 16);
1442 /* SVC, HVC, SMC; since we don't support the Virtualization
1443 * or TrustZone extensions these all UNDEF except SVC.
1446 unallocated_encoding(s
);
1449 gen_exception_insn(s
, 0, EXCP_SWI
, syn_aa64_svc(imm16
));
1453 unallocated_encoding(s
);
1457 gen_exception_insn(s
, 0, EXCP_BKPT
, syn_aa64_bkpt(imm16
));
1461 unallocated_encoding(s
);
1465 unsupported_encoding(s
, insn
);
1468 if (op2_ll
< 1 || op2_ll
> 3) {
1469 unallocated_encoding(s
);
1472 /* DCPS1, DCPS2, DCPS3 */
1473 unsupported_encoding(s
, insn
);
1476 unallocated_encoding(s
);
1481 /* C3.2.7 Unconditional branch (register)
1482 * 31 25 24 21 20 16 15 10 9 5 4 0
1483 * +---------------+-------+-------+-------+------+-------+
1484 * | 1 1 0 1 0 1 1 | opc | op2 | op3 | Rn | op4 |
1485 * +---------------+-------+-------+-------+------+-------+
1487 static void disas_uncond_b_reg(DisasContext
*s
, uint32_t insn
)
1489 unsigned int opc
, op2
, op3
, rn
, op4
;
1491 opc
= extract32(insn
, 21, 4);
1492 op2
= extract32(insn
, 16, 5);
1493 op3
= extract32(insn
, 10, 6);
1494 rn
= extract32(insn
, 5, 5);
1495 op4
= extract32(insn
, 0, 5);
1497 if (op4
!= 0x0 || op3
!= 0x0 || op2
!= 0x1f) {
1498 unallocated_encoding(s
);
1505 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1508 tcg_gen_mov_i64(cpu_pc
, cpu_reg(s
, rn
));
1509 tcg_gen_movi_i64(cpu_reg(s
, 30), s
->pc
);
1512 if (s
->current_pl
== 0) {
1513 unallocated_encoding(s
);
1516 gen_helper_exception_return(cpu_env
);
1517 s
->is_jmp
= DISAS_JUMP
;
1521 unallocated_encoding(s
);
1523 unsupported_encoding(s
, insn
);
1527 unallocated_encoding(s
);
1531 s
->is_jmp
= DISAS_JUMP
;
1534 /* C3.2 Branches, exception generating and system instructions */
1535 static void disas_b_exc_sys(DisasContext
*s
, uint32_t insn
)
1537 switch (extract32(insn
, 25, 7)) {
1538 case 0x0a: case 0x0b:
1539 case 0x4a: case 0x4b: /* Unconditional branch (immediate) */
1540 disas_uncond_b_imm(s
, insn
);
1542 case 0x1a: case 0x5a: /* Compare & branch (immediate) */
1543 disas_comp_b_imm(s
, insn
);
1545 case 0x1b: case 0x5b: /* Test & branch (immediate) */
1546 disas_test_b_imm(s
, insn
);
1548 case 0x2a: /* Conditional branch (immediate) */
1549 disas_cond_b_imm(s
, insn
);
1551 case 0x6a: /* Exception generation / System */
1552 if (insn
& (1 << 24)) {
1553 disas_system(s
, insn
);
1558 case 0x6b: /* Unconditional branch (register) */
1559 disas_uncond_b_reg(s
, insn
);
1562 unallocated_encoding(s
);
1568 * Load/Store exclusive instructions are implemented by remembering
1569 * the value/address loaded, and seeing if these are the same
1570 * when the store is performed. This is not actually the architecturally
1571 * mandated semantics, but it works for typical guest code sequences
1572 * and avoids having to monitor regular stores.
1574 * In system emulation mode only one CPU will be running at once, so
1575 * this sequence is effectively atomic. In user emulation mode we
1576 * throw an exception and handle the atomic operation elsewhere.
1578 static void gen_load_exclusive(DisasContext
*s
, int rt
, int rt2
,
1579 TCGv_i64 addr
, int size
, bool is_pair
)
1581 TCGv_i64 tmp
= tcg_temp_new_i64();
1582 TCGMemOp memop
= MO_TE
+ size
;
1584 g_assert(size
<= 3);
1585 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), memop
);
1588 TCGv_i64 addr2
= tcg_temp_new_i64();
1589 TCGv_i64 hitmp
= tcg_temp_new_i64();
1591 g_assert(size
>= 2);
1592 tcg_gen_addi_i64(addr2
, addr
, 1 << size
);
1593 tcg_gen_qemu_ld_i64(hitmp
, addr2
, get_mem_index(s
), memop
);
1594 tcg_temp_free_i64(addr2
);
1595 tcg_gen_mov_i64(cpu_exclusive_high
, hitmp
);
1596 tcg_gen_mov_i64(cpu_reg(s
, rt2
), hitmp
);
1597 tcg_temp_free_i64(hitmp
);
1600 tcg_gen_mov_i64(cpu_exclusive_val
, tmp
);
1601 tcg_gen_mov_i64(cpu_reg(s
, rt
), tmp
);
1603 tcg_temp_free_i64(tmp
);
1604 tcg_gen_mov_i64(cpu_exclusive_addr
, addr
);
1607 #ifdef CONFIG_USER_ONLY
1608 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1609 TCGv_i64 addr
, int size
, int is_pair
)
1611 tcg_gen_mov_i64(cpu_exclusive_test
, addr
);
1612 tcg_gen_movi_i32(cpu_exclusive_info
,
1613 size
| is_pair
<< 2 | (rd
<< 4) | (rt
<< 9) | (rt2
<< 14));
1614 gen_exception_internal_insn(s
, 4, EXCP_STREX
);
1617 static void gen_store_exclusive(DisasContext
*s
, int rd
, int rt
, int rt2
,
1618 TCGv_i64 inaddr
, int size
, int is_pair
)
1620 /* if (env->exclusive_addr == addr && env->exclusive_val == [addr]
1621 * && (!is_pair || env->exclusive_high == [addr + datasize])) {
1624 * [addr + datasize] = {Rt2};
1630 * env->exclusive_addr = -1;
1632 int fail_label
= gen_new_label();
1633 int done_label
= gen_new_label();
1634 TCGv_i64 addr
= tcg_temp_local_new_i64();
1637 /* Copy input into a local temp so it is not trashed when the
1638 * basic block ends at the branch insn.
1640 tcg_gen_mov_i64(addr
, inaddr
);
1641 tcg_gen_brcond_i64(TCG_COND_NE
, addr
, cpu_exclusive_addr
, fail_label
);
1643 tmp
= tcg_temp_new_i64();
1644 tcg_gen_qemu_ld_i64(tmp
, addr
, get_mem_index(s
), MO_TE
+ size
);
1645 tcg_gen_brcond_i64(TCG_COND_NE
, tmp
, cpu_exclusive_val
, fail_label
);
1646 tcg_temp_free_i64(tmp
);
1649 TCGv_i64 addrhi
= tcg_temp_new_i64();
1650 TCGv_i64 tmphi
= tcg_temp_new_i64();
1652 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1653 tcg_gen_qemu_ld_i64(tmphi
, addrhi
, get_mem_index(s
), MO_TE
+ size
);
1654 tcg_gen_brcond_i64(TCG_COND_NE
, tmphi
, cpu_exclusive_high
, fail_label
);
1656 tcg_temp_free_i64(tmphi
);
1657 tcg_temp_free_i64(addrhi
);
1660 /* We seem to still have the exclusive monitor, so do the store */
1661 tcg_gen_qemu_st_i64(cpu_reg(s
, rt
), addr
, get_mem_index(s
), MO_TE
+ size
);
1663 TCGv_i64 addrhi
= tcg_temp_new_i64();
1665 tcg_gen_addi_i64(addrhi
, addr
, 1 << size
);
1666 tcg_gen_qemu_st_i64(cpu_reg(s
, rt2
), addrhi
,
1667 get_mem_index(s
), MO_TE
+ size
);
1668 tcg_temp_free_i64(addrhi
);
1671 tcg_temp_free_i64(addr
);
1673 tcg_gen_movi_i64(cpu_reg(s
, rd
), 0);
1674 tcg_gen_br(done_label
);
1675 gen_set_label(fail_label
);
1676 tcg_gen_movi_i64(cpu_reg(s
, rd
), 1);
1677 gen_set_label(done_label
);
1678 tcg_gen_movi_i64(cpu_exclusive_addr
, -1);
1683 /* C3.3.6 Load/store exclusive
1685 * 31 30 29 24 23 22 21 20 16 15 14 10 9 5 4 0
1686 * +-----+-------------+----+---+----+------+----+-------+------+------+
1687 * | sz | 0 0 1 0 0 0 | o2 | L | o1 | Rs | o0 | Rt2 | Rn | Rt |
1688 * +-----+-------------+----+---+----+------+----+-------+------+------+
1690 * sz: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64 bit
1691 * L: 0 -> store, 1 -> load
1692 * o2: 0 -> exclusive, 1 -> not
1693 * o1: 0 -> single register, 1 -> register pair
1694 * o0: 1 -> load-acquire/store-release, 0 -> not
1696 * o0 == 0 AND o2 == 1 is un-allocated
1697 * o1 == 1 is un-allocated except for 32 and 64 bit sizes
1699 static void disas_ldst_excl(DisasContext
*s
, uint32_t insn
)
1701 int rt
= extract32(insn
, 0, 5);
1702 int rn
= extract32(insn
, 5, 5);
1703 int rt2
= extract32(insn
, 10, 5);
1704 int is_lasr
= extract32(insn
, 15, 1);
1705 int rs
= extract32(insn
, 16, 5);
1706 int is_pair
= extract32(insn
, 21, 1);
1707 int is_store
= !extract32(insn
, 22, 1);
1708 int is_excl
= !extract32(insn
, 23, 1);
1709 int size
= extract32(insn
, 30, 2);
1712 if ((!is_excl
&& !is_lasr
) ||
1713 (is_pair
&& size
< 2)) {
1714 unallocated_encoding(s
);
1719 gen_check_sp_alignment(s
);
1721 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1723 /* Note that since TCG is single threaded load-acquire/store-release
1724 * semantics require no extra if (is_lasr) { ... } handling.
1729 gen_load_exclusive(s
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1731 gen_store_exclusive(s
, rs
, rt
, rt2
, tcg_addr
, size
, is_pair
);
1734 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1736 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1738 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, false, false);
1741 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt
);
1742 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
1744 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
1746 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, false, false);
1753 * C3.3.5 Load register (literal)
1755 * 31 30 29 27 26 25 24 23 5 4 0
1756 * +-----+-------+---+-----+-------------------+-------+
1757 * | opc | 0 1 1 | V | 0 0 | imm19 | Rt |
1758 * +-----+-------+---+-----+-------------------+-------+
1760 * V: 1 -> vector (simd/fp)
1761 * opc (non-vector): 00 -> 32 bit, 01 -> 64 bit,
1762 * 10-> 32 bit signed, 11 -> prefetch
1763 * opc (vector): 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit (11 unallocated)
1765 static void disas_ld_lit(DisasContext
*s
, uint32_t insn
)
1767 int rt
= extract32(insn
, 0, 5);
1768 int64_t imm
= sextract32(insn
, 5, 19) << 2;
1769 bool is_vector
= extract32(insn
, 26, 1);
1770 int opc
= extract32(insn
, 30, 2);
1771 bool is_signed
= false;
1773 TCGv_i64 tcg_rt
, tcg_addr
;
1777 unallocated_encoding(s
);
1781 if (!fp_access_check(s
)) {
1786 /* PRFM (literal) : prefetch */
1789 size
= 2 + extract32(opc
, 0, 1);
1790 is_signed
= extract32(opc
, 1, 1);
1793 tcg_rt
= cpu_reg(s
, rt
);
1795 tcg_addr
= tcg_const_i64((s
->pc
- 4) + imm
);
1797 do_fp_ld(s
, rt
, tcg_addr
, size
);
1799 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
1801 tcg_temp_free_i64(tcg_addr
);
1805 * C5.6.80 LDNP (Load Pair - non-temporal hint)
1806 * C5.6.81 LDP (Load Pair - non vector)
1807 * C5.6.82 LDPSW (Load Pair Signed Word - non vector)
1808 * C5.6.176 STNP (Store Pair - non-temporal hint)
1809 * C5.6.177 STP (Store Pair - non vector)
1810 * C6.3.165 LDNP (Load Pair of SIMD&FP - non-temporal hint)
1811 * C6.3.165 LDP (Load Pair of SIMD&FP)
1812 * C6.3.284 STNP (Store Pair of SIMD&FP - non-temporal hint)
1813 * C6.3.284 STP (Store Pair of SIMD&FP)
1815 * 31 30 29 27 26 25 24 23 22 21 15 14 10 9 5 4 0
1816 * +-----+-------+---+---+-------+---+-----------------------------+
1817 * | opc | 1 0 1 | V | 0 | index | L | imm7 | Rt2 | Rn | Rt |
1818 * +-----+-------+---+---+-------+---+-------+-------+------+------+
1820 * opc: LDP/STP/LDNP/STNP 00 -> 32 bit, 10 -> 64 bit
1822 * LDP/STP/LDNP/STNP (SIMD) 00 -> 32 bit, 01 -> 64 bit, 10 -> 128 bit
1823 * V: 0 -> GPR, 1 -> Vector
1824 * idx: 00 -> signed offset with non-temporal hint, 01 -> post-index,
1825 * 10 -> signed offset, 11 -> pre-index
1826 * L: 0 -> Store 1 -> Load
1828 * Rt, Rt2 = GPR or SIMD registers to be stored
1829 * Rn = general purpose register containing address
1830 * imm7 = signed offset (multiple of 4 or 8 depending on size)
1832 static void disas_ldst_pair(DisasContext
*s
, uint32_t insn
)
1834 int rt
= extract32(insn
, 0, 5);
1835 int rn
= extract32(insn
, 5, 5);
1836 int rt2
= extract32(insn
, 10, 5);
1837 int64_t offset
= sextract32(insn
, 15, 7);
1838 int index
= extract32(insn
, 23, 2);
1839 bool is_vector
= extract32(insn
, 26, 1);
1840 bool is_load
= extract32(insn
, 22, 1);
1841 int opc
= extract32(insn
, 30, 2);
1843 bool is_signed
= false;
1844 bool postindex
= false;
1847 TCGv_i64 tcg_addr
; /* calculated address */
1851 unallocated_encoding(s
);
1858 size
= 2 + extract32(opc
, 1, 1);
1859 is_signed
= extract32(opc
, 0, 1);
1860 if (!is_load
&& is_signed
) {
1861 unallocated_encoding(s
);
1867 case 1: /* post-index */
1872 /* signed offset with "non-temporal" hint. Since we don't emulate
1873 * caches we don't care about hints to the cache system about
1874 * data access patterns, and handle this identically to plain
1878 /* There is no non-temporal-hint version of LDPSW */
1879 unallocated_encoding(s
);
1884 case 2: /* signed offset, rn not updated */
1887 case 3: /* pre-index */
1893 if (is_vector
&& !fp_access_check(s
)) {
1900 gen_check_sp_alignment(s
);
1903 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
1906 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
1911 do_fp_ld(s
, rt
, tcg_addr
, size
);
1913 do_fp_st(s
, rt
, tcg_addr
, size
);
1916 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
1918 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, false);
1920 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
1923 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, 1 << size
);
1926 do_fp_ld(s
, rt2
, tcg_addr
, size
);
1928 do_fp_st(s
, rt2
, tcg_addr
, size
);
1931 TCGv_i64 tcg_rt2
= cpu_reg(s
, rt2
);
1933 do_gpr_ld(s
, tcg_rt2
, tcg_addr
, size
, is_signed
, false);
1935 do_gpr_st(s
, tcg_rt2
, tcg_addr
, size
);
1941 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
- (1 << size
));
1943 tcg_gen_subi_i64(tcg_addr
, tcg_addr
, 1 << size
);
1945 tcg_gen_mov_i64(cpu_reg_sp(s
, rn
), tcg_addr
);
1950 * C3.3.8 Load/store (immediate post-indexed)
1951 * C3.3.9 Load/store (immediate pre-indexed)
1952 * C3.3.12 Load/store (unscaled immediate)
1954 * 31 30 29 27 26 25 24 23 22 21 20 12 11 10 9 5 4 0
1955 * +----+-------+---+-----+-----+---+--------+-----+------+------+
1956 * |size| 1 1 1 | V | 0 0 | opc | 0 | imm9 | idx | Rn | Rt |
1957 * +----+-------+---+-----+-----+---+--------+-----+------+------+
1959 * idx = 01 -> post-indexed, 11 pre-indexed, 00 unscaled imm. (no writeback)
1961 * V = 0 -> non-vector
1962 * size: 00 -> 8 bit, 01 -> 16 bit, 10 -> 32 bit, 11 -> 64bit
1963 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
1965 static void disas_ldst_reg_imm9(DisasContext
*s
, uint32_t insn
)
1967 int rt
= extract32(insn
, 0, 5);
1968 int rn
= extract32(insn
, 5, 5);
1969 int imm9
= sextract32(insn
, 12, 9);
1970 int opc
= extract32(insn
, 22, 2);
1971 int size
= extract32(insn
, 30, 2);
1972 int idx
= extract32(insn
, 10, 2);
1973 bool is_signed
= false;
1974 bool is_store
= false;
1975 bool is_extended
= false;
1976 bool is_unpriv
= (idx
== 2);
1977 bool is_vector
= extract32(insn
, 26, 1);
1984 size
|= (opc
& 2) << 1;
1985 if (size
> 4 || is_unpriv
) {
1986 unallocated_encoding(s
);
1989 is_store
= ((opc
& 1) == 0);
1990 if (!fp_access_check(s
)) {
1994 if (size
== 3 && opc
== 2) {
1995 /* PRFM - prefetch */
1997 unallocated_encoding(s
);
2002 if (opc
== 3 && size
> 1) {
2003 unallocated_encoding(s
);
2006 is_store
= (opc
== 0);
2007 is_signed
= opc
& (1<<1);
2008 is_extended
= (size
< 3) && (opc
& 1);
2028 gen_check_sp_alignment(s
);
2030 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2033 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2038 do_fp_st(s
, rt
, tcg_addr
, size
);
2040 do_fp_ld(s
, rt
, tcg_addr
, size
);
2043 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2044 int memidx
= is_unpriv
? 1 : get_mem_index(s
);
2047 do_gpr_st_memidx(s
, tcg_rt
, tcg_addr
, size
, memidx
);
2049 do_gpr_ld_memidx(s
, tcg_rt
, tcg_addr
, size
,
2050 is_signed
, is_extended
, memidx
);
2055 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2057 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, imm9
);
2059 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2064 * C3.3.10 Load/store (register offset)
2066 * 31 30 29 27 26 25 24 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2067 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2068 * |size| 1 1 1 | V | 0 0 | opc | 1 | Rm | opt | S| 1 0 | Rn | Rt |
2069 * +----+-------+---+-----+-----+---+------+-----+--+-----+----+----+
2072 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2073 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2075 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2076 * opc<0>: 0 -> store, 1 -> load
2077 * V: 1 -> vector/simd
2078 * opt: extend encoding (see DecodeRegExtend)
2079 * S: if S=1 then scale (essentially index by sizeof(size))
2080 * Rt: register to transfer into/out of
2081 * Rn: address register or SP for base
2082 * Rm: offset register or ZR for offset
2084 static void disas_ldst_reg_roffset(DisasContext
*s
, uint32_t insn
)
2086 int rt
= extract32(insn
, 0, 5);
2087 int rn
= extract32(insn
, 5, 5);
2088 int shift
= extract32(insn
, 12, 1);
2089 int rm
= extract32(insn
, 16, 5);
2090 int opc
= extract32(insn
, 22, 2);
2091 int opt
= extract32(insn
, 13, 3);
2092 int size
= extract32(insn
, 30, 2);
2093 bool is_signed
= false;
2094 bool is_store
= false;
2095 bool is_extended
= false;
2096 bool is_vector
= extract32(insn
, 26, 1);
2101 if (extract32(opt
, 1, 1) == 0) {
2102 unallocated_encoding(s
);
2107 size
|= (opc
& 2) << 1;
2109 unallocated_encoding(s
);
2112 is_store
= !extract32(opc
, 0, 1);
2113 if (!fp_access_check(s
)) {
2117 if (size
== 3 && opc
== 2) {
2118 /* PRFM - prefetch */
2121 if (opc
== 3 && size
> 1) {
2122 unallocated_encoding(s
);
2125 is_store
= (opc
== 0);
2126 is_signed
= extract32(opc
, 1, 1);
2127 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2131 gen_check_sp_alignment(s
);
2133 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2135 tcg_rm
= read_cpu_reg(s
, rm
, 1);
2136 ext_and_shift_reg(tcg_rm
, tcg_rm
, opt
, shift
? size
: 0);
2138 tcg_gen_add_i64(tcg_addr
, tcg_addr
, tcg_rm
);
2142 do_fp_st(s
, rt
, tcg_addr
, size
);
2144 do_fp_ld(s
, rt
, tcg_addr
, size
);
2147 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2149 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2151 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2157 * C3.3.13 Load/store (unsigned immediate)
2159 * 31 30 29 27 26 25 24 23 22 21 10 9 5
2160 * +----+-------+---+-----+-----+------------+-------+------+
2161 * |size| 1 1 1 | V | 0 1 | opc | imm12 | Rn | Rt |
2162 * +----+-------+---+-----+-----+------------+-------+------+
2165 * size: 00-> byte, 01 -> 16 bit, 10 -> 32bit, 11 -> 64bit
2166 * opc: 00 -> store, 01 -> loadu, 10 -> loads 64, 11 -> loads 32
2168 * size is opc<1>:size<1:0> so 100 -> 128 bit; 110 and 111 unallocated
2169 * opc<0>: 0 -> store, 1 -> load
2170 * Rn: base address register (inc SP)
2171 * Rt: target register
2173 static void disas_ldst_reg_unsigned_imm(DisasContext
*s
, uint32_t insn
)
2175 int rt
= extract32(insn
, 0, 5);
2176 int rn
= extract32(insn
, 5, 5);
2177 unsigned int imm12
= extract32(insn
, 10, 12);
2178 bool is_vector
= extract32(insn
, 26, 1);
2179 int size
= extract32(insn
, 30, 2);
2180 int opc
= extract32(insn
, 22, 2);
2181 unsigned int offset
;
2186 bool is_signed
= false;
2187 bool is_extended
= false;
2190 size
|= (opc
& 2) << 1;
2192 unallocated_encoding(s
);
2195 is_store
= !extract32(opc
, 0, 1);
2196 if (!fp_access_check(s
)) {
2200 if (size
== 3 && opc
== 2) {
2201 /* PRFM - prefetch */
2204 if (opc
== 3 && size
> 1) {
2205 unallocated_encoding(s
);
2208 is_store
= (opc
== 0);
2209 is_signed
= extract32(opc
, 1, 1);
2210 is_extended
= (size
< 3) && extract32(opc
, 0, 1);
2214 gen_check_sp_alignment(s
);
2216 tcg_addr
= read_cpu_reg_sp(s
, rn
, 1);
2217 offset
= imm12
<< size
;
2218 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, offset
);
2222 do_fp_st(s
, rt
, tcg_addr
, size
);
2224 do_fp_ld(s
, rt
, tcg_addr
, size
);
2227 TCGv_i64 tcg_rt
= cpu_reg(s
, rt
);
2229 do_gpr_st(s
, tcg_rt
, tcg_addr
, size
);
2231 do_gpr_ld(s
, tcg_rt
, tcg_addr
, size
, is_signed
, is_extended
);
2236 /* Load/store register (all forms) */
2237 static void disas_ldst_reg(DisasContext
*s
, uint32_t insn
)
2239 switch (extract32(insn
, 24, 2)) {
2241 if (extract32(insn
, 21, 1) == 1 && extract32(insn
, 10, 2) == 2) {
2242 disas_ldst_reg_roffset(s
, insn
);
2244 /* Load/store register (unscaled immediate)
2245 * Load/store immediate pre/post-indexed
2246 * Load/store register unprivileged
2248 disas_ldst_reg_imm9(s
, insn
);
2252 disas_ldst_reg_unsigned_imm(s
, insn
);
2255 unallocated_encoding(s
);
2260 /* C3.3.1 AdvSIMD load/store multiple structures
2262 * 31 30 29 23 22 21 16 15 12 11 10 9 5 4 0
2263 * +---+---+---------------+---+-------------+--------+------+------+------+
2264 * | 0 | Q | 0 0 1 1 0 0 0 | L | 0 0 0 0 0 0 | opcode | size | Rn | Rt |
2265 * +---+---+---------------+---+-------------+--------+------+------+------+
2267 * C3.3.2 AdvSIMD load/store multiple structures (post-indexed)
2269 * 31 30 29 23 22 21 20 16 15 12 11 10 9 5 4 0
2270 * +---+---+---------------+---+---+---------+--------+------+------+------+
2271 * | 0 | Q | 0 0 1 1 0 0 1 | L | 0 | Rm | opcode | size | Rn | Rt |
2272 * +---+---+---------------+---+---+---------+--------+------+------+------+
2274 * Rt: first (or only) SIMD&FP register to be transferred
2275 * Rn: base address or SP
2276 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2278 static void disas_ldst_multiple_struct(DisasContext
*s
, uint32_t insn
)
2280 int rt
= extract32(insn
, 0, 5);
2281 int rn
= extract32(insn
, 5, 5);
2282 int size
= extract32(insn
, 10, 2);
2283 int opcode
= extract32(insn
, 12, 4);
2284 bool is_store
= !extract32(insn
, 22, 1);
2285 bool is_postidx
= extract32(insn
, 23, 1);
2286 bool is_q
= extract32(insn
, 30, 1);
2287 TCGv_i64 tcg_addr
, tcg_rn
;
2289 int ebytes
= 1 << size
;
2290 int elements
= (is_q
? 128 : 64) / (8 << size
);
2291 int rpt
; /* num iterations */
2292 int selem
; /* structure elements */
2295 if (extract32(insn
, 31, 1) || extract32(insn
, 21, 1)) {
2296 unallocated_encoding(s
);
2300 /* From the shared decode logic */
2331 unallocated_encoding(s
);
2335 if (size
== 3 && !is_q
&& selem
!= 1) {
2337 unallocated_encoding(s
);
2341 if (!fp_access_check(s
)) {
2346 gen_check_sp_alignment(s
);
2349 tcg_rn
= cpu_reg_sp(s
, rn
);
2350 tcg_addr
= tcg_temp_new_i64();
2351 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2353 for (r
= 0; r
< rpt
; r
++) {
2355 for (e
= 0; e
< elements
; e
++) {
2356 int tt
= (rt
+ r
) % 32;
2358 for (xs
= 0; xs
< selem
; xs
++) {
2360 do_vec_st(s
, tt
, e
, tcg_addr
, size
);
2362 do_vec_ld(s
, tt
, e
, tcg_addr
, size
);
2364 /* For non-quad operations, setting a slice of the low
2365 * 64 bits of the register clears the high 64 bits (in
2366 * the ARM ARM pseudocode this is implicit in the fact
2367 * that 'rval' is a 64 bit wide variable). We optimize
2368 * by noticing that we only need to do this the first
2369 * time we touch a register.
2371 if (!is_q
&& e
== 0 && (r
== 0 || xs
== selem
- 1)) {
2372 clear_vec_high(s
, tt
);
2375 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2382 int rm
= extract32(insn
, 16, 5);
2384 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2386 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2389 tcg_temp_free_i64(tcg_addr
);
2392 /* C3.3.3 AdvSIMD load/store single structure
2394 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2395 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2396 * | 0 | Q | 0 0 1 1 0 1 0 | L R | 0 0 0 0 0 | opc | S | size | Rn | Rt |
2397 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2399 * C3.3.4 AdvSIMD load/store single structure (post-indexed)
2401 * 31 30 29 23 22 21 20 16 15 13 12 11 10 9 5 4 0
2402 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2403 * | 0 | Q | 0 0 1 1 0 1 1 | L R | Rm | opc | S | size | Rn | Rt |
2404 * +---+---+---------------+-----+-----------+-----+---+------+------+------+
2406 * Rt: first (or only) SIMD&FP register to be transferred
2407 * Rn: base address or SP
2408 * Rm (post-index only): post-index register (when !31) or size dependent #imm
2409 * index = encoded in Q:S:size dependent on size
2411 * lane_size = encoded in R, opc
2412 * transfer width = encoded in opc, S, size
2414 static void disas_ldst_single_struct(DisasContext
*s
, uint32_t insn
)
2416 int rt
= extract32(insn
, 0, 5);
2417 int rn
= extract32(insn
, 5, 5);
2418 int size
= extract32(insn
, 10, 2);
2419 int S
= extract32(insn
, 12, 1);
2420 int opc
= extract32(insn
, 13, 3);
2421 int R
= extract32(insn
, 21, 1);
2422 int is_load
= extract32(insn
, 22, 1);
2423 int is_postidx
= extract32(insn
, 23, 1);
2424 int is_q
= extract32(insn
, 30, 1);
2426 int scale
= extract32(opc
, 1, 2);
2427 int selem
= (extract32(opc
, 0, 1) << 1 | R
) + 1;
2428 bool replicate
= false;
2429 int index
= is_q
<< 3 | S
<< 2 | size
;
2431 TCGv_i64 tcg_addr
, tcg_rn
;
2435 if (!is_load
|| S
) {
2436 unallocated_encoding(s
);
2445 if (extract32(size
, 0, 1)) {
2446 unallocated_encoding(s
);
2452 if (extract32(size
, 1, 1)) {
2453 unallocated_encoding(s
);
2456 if (!extract32(size
, 0, 1)) {
2460 unallocated_encoding(s
);
2468 g_assert_not_reached();
2471 if (!fp_access_check(s
)) {
2475 ebytes
= 1 << scale
;
2478 gen_check_sp_alignment(s
);
2481 tcg_rn
= cpu_reg_sp(s
, rn
);
2482 tcg_addr
= tcg_temp_new_i64();
2483 tcg_gen_mov_i64(tcg_addr
, tcg_rn
);
2485 for (xs
= 0; xs
< selem
; xs
++) {
2487 /* Load and replicate to all elements */
2489 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
2491 tcg_gen_qemu_ld_i64(tcg_tmp
, tcg_addr
,
2492 get_mem_index(s
), MO_TE
+ scale
);
2495 mulconst
= 0x0101010101010101ULL
;
2498 mulconst
= 0x0001000100010001ULL
;
2501 mulconst
= 0x0000000100000001ULL
;
2507 g_assert_not_reached();
2510 tcg_gen_muli_i64(tcg_tmp
, tcg_tmp
, mulconst
);
2512 write_vec_element(s
, tcg_tmp
, rt
, 0, MO_64
);
2514 write_vec_element(s
, tcg_tmp
, rt
, 1, MO_64
);
2516 clear_vec_high(s
, rt
);
2518 tcg_temp_free_i64(tcg_tmp
);
2520 /* Load/store one element per register */
2522 do_vec_ld(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2524 do_vec_st(s
, rt
, index
, tcg_addr
, MO_TE
+ scale
);
2527 tcg_gen_addi_i64(tcg_addr
, tcg_addr
, ebytes
);
2532 int rm
= extract32(insn
, 16, 5);
2534 tcg_gen_mov_i64(tcg_rn
, tcg_addr
);
2536 tcg_gen_add_i64(tcg_rn
, tcg_rn
, cpu_reg(s
, rm
));
2539 tcg_temp_free_i64(tcg_addr
);
2542 /* C3.3 Loads and stores */
2543 static void disas_ldst(DisasContext
*s
, uint32_t insn
)
2545 switch (extract32(insn
, 24, 6)) {
2546 case 0x08: /* Load/store exclusive */
2547 disas_ldst_excl(s
, insn
);
2549 case 0x18: case 0x1c: /* Load register (literal) */
2550 disas_ld_lit(s
, insn
);
2552 case 0x28: case 0x29:
2553 case 0x2c: case 0x2d: /* Load/store pair (all forms) */
2554 disas_ldst_pair(s
, insn
);
2556 case 0x38: case 0x39:
2557 case 0x3c: case 0x3d: /* Load/store register (all forms) */
2558 disas_ldst_reg(s
, insn
);
2560 case 0x0c: /* AdvSIMD load/store multiple structures */
2561 disas_ldst_multiple_struct(s
, insn
);
2563 case 0x0d: /* AdvSIMD load/store single structure */
2564 disas_ldst_single_struct(s
, insn
);
2567 unallocated_encoding(s
);
2572 /* C3.4.6 PC-rel. addressing
2573 * 31 30 29 28 24 23 5 4 0
2574 * +----+-------+-----------+-------------------+------+
2575 * | op | immlo | 1 0 0 0 0 | immhi | Rd |
2576 * +----+-------+-----------+-------------------+------+
2578 static void disas_pc_rel_adr(DisasContext
*s
, uint32_t insn
)
2580 unsigned int page
, rd
;
2584 page
= extract32(insn
, 31, 1);
2585 /* SignExtend(immhi:immlo) -> offset */
2586 offset
= ((int64_t)sextract32(insn
, 5, 19) << 2) | extract32(insn
, 29, 2);
2587 rd
= extract32(insn
, 0, 5);
2591 /* ADRP (page based) */
2596 tcg_gen_movi_i64(cpu_reg(s
, rd
), base
+ offset
);
2600 * C3.4.1 Add/subtract (immediate)
2602 * 31 30 29 28 24 23 22 21 10 9 5 4 0
2603 * +--+--+--+-----------+-----+-------------+-----+-----+
2604 * |sf|op| S| 1 0 0 0 1 |shift| imm12 | Rn | Rd |
2605 * +--+--+--+-----------+-----+-------------+-----+-----+
2607 * sf: 0 -> 32bit, 1 -> 64bit
2608 * op: 0 -> add , 1 -> sub
2610 * shift: 00 -> LSL imm by 0, 01 -> LSL imm by 12
2612 static void disas_add_sub_imm(DisasContext
*s
, uint32_t insn
)
2614 int rd
= extract32(insn
, 0, 5);
2615 int rn
= extract32(insn
, 5, 5);
2616 uint64_t imm
= extract32(insn
, 10, 12);
2617 int shift
= extract32(insn
, 22, 2);
2618 bool setflags
= extract32(insn
, 29, 1);
2619 bool sub_op
= extract32(insn
, 30, 1);
2620 bool is_64bit
= extract32(insn
, 31, 1);
2622 TCGv_i64 tcg_rn
= cpu_reg_sp(s
, rn
);
2623 TCGv_i64 tcg_rd
= setflags
? cpu_reg(s
, rd
) : cpu_reg_sp(s
, rd
);
2624 TCGv_i64 tcg_result
;
2633 unallocated_encoding(s
);
2637 tcg_result
= tcg_temp_new_i64();
2640 tcg_gen_subi_i64(tcg_result
, tcg_rn
, imm
);
2642 tcg_gen_addi_i64(tcg_result
, tcg_rn
, imm
);
2645 TCGv_i64 tcg_imm
= tcg_const_i64(imm
);
2647 gen_sub_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2649 gen_add_CC(is_64bit
, tcg_result
, tcg_rn
, tcg_imm
);
2651 tcg_temp_free_i64(tcg_imm
);
2655 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
2657 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
2660 tcg_temp_free_i64(tcg_result
);
2663 /* The input should be a value in the bottom e bits (with higher
2664 * bits zero); returns that value replicated into every element
2665 * of size e in a 64 bit integer.
2667 static uint64_t bitfield_replicate(uint64_t mask
, unsigned int e
)
2677 /* Return a value with the bottom len bits set (where 0 < len <= 64) */
2678 static inline uint64_t bitmask64(unsigned int length
)
2680 assert(length
> 0 && length
<= 64);
2681 return ~0ULL >> (64 - length
);
2684 /* Simplified variant of pseudocode DecodeBitMasks() for the case where we
2685 * only require the wmask. Returns false if the imms/immr/immn are a reserved
2686 * value (ie should cause a guest UNDEF exception), and true if they are
2687 * valid, in which case the decoded bit pattern is written to result.
2689 static bool logic_imm_decode_wmask(uint64_t *result
, unsigned int immn
,
2690 unsigned int imms
, unsigned int immr
)
2693 unsigned e
, levels
, s
, r
;
2696 assert(immn
< 2 && imms
< 64 && immr
< 64);
2698 /* The bit patterns we create here are 64 bit patterns which
2699 * are vectors of identical elements of size e = 2, 4, 8, 16, 32 or
2700 * 64 bits each. Each element contains the same value: a run
2701 * of between 1 and e-1 non-zero bits, rotated within the
2702 * element by between 0 and e-1 bits.
2704 * The element size and run length are encoded into immn (1 bit)
2705 * and imms (6 bits) as follows:
2706 * 64 bit elements: immn = 1, imms = <length of run - 1>
2707 * 32 bit elements: immn = 0, imms = 0 : <length of run - 1>
2708 * 16 bit elements: immn = 0, imms = 10 : <length of run - 1>
2709 * 8 bit elements: immn = 0, imms = 110 : <length of run - 1>
2710 * 4 bit elements: immn = 0, imms = 1110 : <length of run - 1>
2711 * 2 bit elements: immn = 0, imms = 11110 : <length of run - 1>
2712 * Notice that immn = 0, imms = 11111x is the only combination
2713 * not covered by one of the above options; this is reserved.
2714 * Further, <length of run - 1> all-ones is a reserved pattern.
2716 * In all cases the rotation is by immr % e (and immr is 6 bits).
2719 /* First determine the element size */
2720 len
= 31 - clz32((immn
<< 6) | (~imms
& 0x3f));
2722 /* This is the immn == 0, imms == 0x11111x case */
2732 /* <length of run - 1> mustn't be all-ones. */
2736 /* Create the value of one element: s+1 set bits rotated
2737 * by r within the element (which is e bits wide)...
2739 mask
= bitmask64(s
+ 1);
2740 mask
= (mask
>> r
) | (mask
<< (e
- r
));
2741 /* ...then replicate the element over the whole 64 bit value */
2742 mask
= bitfield_replicate(mask
, e
);
2747 /* C3.4.4 Logical (immediate)
2748 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2749 * +----+-----+-------------+---+------+------+------+------+
2750 * | sf | opc | 1 0 0 1 0 0 | N | immr | imms | Rn | Rd |
2751 * +----+-----+-------------+---+------+------+------+------+
2753 static void disas_logic_imm(DisasContext
*s
, uint32_t insn
)
2755 unsigned int sf
, opc
, is_n
, immr
, imms
, rn
, rd
;
2756 TCGv_i64 tcg_rd
, tcg_rn
;
2758 bool is_and
= false;
2760 sf
= extract32(insn
, 31, 1);
2761 opc
= extract32(insn
, 29, 2);
2762 is_n
= extract32(insn
, 22, 1);
2763 immr
= extract32(insn
, 16, 6);
2764 imms
= extract32(insn
, 10, 6);
2765 rn
= extract32(insn
, 5, 5);
2766 rd
= extract32(insn
, 0, 5);
2769 unallocated_encoding(s
);
2773 if (opc
== 0x3) { /* ANDS */
2774 tcg_rd
= cpu_reg(s
, rd
);
2776 tcg_rd
= cpu_reg_sp(s
, rd
);
2778 tcg_rn
= cpu_reg(s
, rn
);
2780 if (!logic_imm_decode_wmask(&wmask
, is_n
, imms
, immr
)) {
2781 /* some immediate field values are reserved */
2782 unallocated_encoding(s
);
2787 wmask
&= 0xffffffff;
2791 case 0x3: /* ANDS */
2793 tcg_gen_andi_i64(tcg_rd
, tcg_rn
, wmask
);
2797 tcg_gen_ori_i64(tcg_rd
, tcg_rn
, wmask
);
2800 tcg_gen_xori_i64(tcg_rd
, tcg_rn
, wmask
);
2803 assert(FALSE
); /* must handle all above */
2807 if (!sf
&& !is_and
) {
2808 /* zero extend final result; we know we can skip this for AND
2809 * since the immediate had the high 32 bits clear.
2811 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2814 if (opc
== 3) { /* ANDS */
2815 gen_logic_CC(sf
, tcg_rd
);
2820 * C3.4.5 Move wide (immediate)
2822 * 31 30 29 28 23 22 21 20 5 4 0
2823 * +--+-----+-------------+-----+----------------+------+
2824 * |sf| opc | 1 0 0 1 0 1 | hw | imm16 | Rd |
2825 * +--+-----+-------------+-----+----------------+------+
2827 * sf: 0 -> 32 bit, 1 -> 64 bit
2828 * opc: 00 -> N, 10 -> Z, 11 -> K
2829 * hw: shift/16 (0,16, and sf only 32, 48)
2831 static void disas_movw_imm(DisasContext
*s
, uint32_t insn
)
2833 int rd
= extract32(insn
, 0, 5);
2834 uint64_t imm
= extract32(insn
, 5, 16);
2835 int sf
= extract32(insn
, 31, 1);
2836 int opc
= extract32(insn
, 29, 2);
2837 int pos
= extract32(insn
, 21, 2) << 4;
2838 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
2841 if (!sf
&& (pos
>= 32)) {
2842 unallocated_encoding(s
);
2856 tcg_gen_movi_i64(tcg_rd
, imm
);
2859 tcg_imm
= tcg_const_i64(imm
);
2860 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_imm
, pos
, 16);
2861 tcg_temp_free_i64(tcg_imm
);
2863 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2867 unallocated_encoding(s
);
2873 * 31 30 29 28 23 22 21 16 15 10 9 5 4 0
2874 * +----+-----+-------------+---+------+------+------+------+
2875 * | sf | opc | 1 0 0 1 1 0 | N | immr | imms | Rn | Rd |
2876 * +----+-----+-------------+---+------+------+------+------+
2878 static void disas_bitfield(DisasContext
*s
, uint32_t insn
)
2880 unsigned int sf
, n
, opc
, ri
, si
, rn
, rd
, bitsize
, pos
, len
;
2881 TCGv_i64 tcg_rd
, tcg_tmp
;
2883 sf
= extract32(insn
, 31, 1);
2884 opc
= extract32(insn
, 29, 2);
2885 n
= extract32(insn
, 22, 1);
2886 ri
= extract32(insn
, 16, 6);
2887 si
= extract32(insn
, 10, 6);
2888 rn
= extract32(insn
, 5, 5);
2889 rd
= extract32(insn
, 0, 5);
2890 bitsize
= sf
? 64 : 32;
2892 if (sf
!= n
|| ri
>= bitsize
|| si
>= bitsize
|| opc
> 2) {
2893 unallocated_encoding(s
);
2897 tcg_rd
= cpu_reg(s
, rd
);
2898 tcg_tmp
= read_cpu_reg(s
, rn
, sf
);
2900 /* OPTME: probably worth recognizing common cases of ext{8,16,32}{u,s} */
2902 if (opc
!= 1) { /* SBFM or UBFM */
2903 tcg_gen_movi_i64(tcg_rd
, 0);
2906 /* do the bit move operation */
2908 /* Wd<s-r:0> = Wn<s:r> */
2909 tcg_gen_shri_i64(tcg_tmp
, tcg_tmp
, ri
);
2911 len
= (si
- ri
) + 1;
2913 /* Wd<32+s-r,32-r> = Wn<s:0> */
2918 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, pos
, len
);
2920 if (opc
== 0) { /* SBFM - sign extend the destination field */
2921 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
2922 tcg_gen_sari_i64(tcg_rd
, tcg_rd
, 64 - (pos
+ len
));
2925 if (!sf
) { /* zero extend final result */
2926 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2931 * 31 30 29 28 23 22 21 20 16 15 10 9 5 4 0
2932 * +----+------+-------------+---+----+------+--------+------+------+
2933 * | sf | op21 | 1 0 0 1 1 1 | N | o0 | Rm | imms | Rn | Rd |
2934 * +----+------+-------------+---+----+------+--------+------+------+
2936 static void disas_extract(DisasContext
*s
, uint32_t insn
)
2938 unsigned int sf
, n
, rm
, imm
, rn
, rd
, bitsize
, op21
, op0
;
2940 sf
= extract32(insn
, 31, 1);
2941 n
= extract32(insn
, 22, 1);
2942 rm
= extract32(insn
, 16, 5);
2943 imm
= extract32(insn
, 10, 6);
2944 rn
= extract32(insn
, 5, 5);
2945 rd
= extract32(insn
, 0, 5);
2946 op21
= extract32(insn
, 29, 2);
2947 op0
= extract32(insn
, 21, 1);
2948 bitsize
= sf
? 64 : 32;
2950 if (sf
!= n
|| op21
|| op0
|| imm
>= bitsize
) {
2951 unallocated_encoding(s
);
2953 TCGv_i64 tcg_rd
, tcg_rm
, tcg_rn
;
2955 tcg_rd
= cpu_reg(s
, rd
);
2958 /* OPTME: we can special case rm==rn as a rotate */
2959 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
2960 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
2961 tcg_gen_shri_i64(tcg_rm
, tcg_rm
, imm
);
2962 tcg_gen_shli_i64(tcg_rn
, tcg_rn
, bitsize
- imm
);
2963 tcg_gen_or_i64(tcg_rd
, tcg_rm
, tcg_rn
);
2965 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
2968 /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
2969 * so an extract from bit 0 is a special case.
2972 tcg_gen_mov_i64(tcg_rd
, cpu_reg(s
, rm
));
2974 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rm
));
2981 /* C3.4 Data processing - immediate */
2982 static void disas_data_proc_imm(DisasContext
*s
, uint32_t insn
)
2984 switch (extract32(insn
, 23, 6)) {
2985 case 0x20: case 0x21: /* PC-rel. addressing */
2986 disas_pc_rel_adr(s
, insn
);
2988 case 0x22: case 0x23: /* Add/subtract (immediate) */
2989 disas_add_sub_imm(s
, insn
);
2991 case 0x24: /* Logical (immediate) */
2992 disas_logic_imm(s
, insn
);
2994 case 0x25: /* Move wide (immediate) */
2995 disas_movw_imm(s
, insn
);
2997 case 0x26: /* Bitfield */
2998 disas_bitfield(s
, insn
);
3000 case 0x27: /* Extract */
3001 disas_extract(s
, insn
);
3004 unallocated_encoding(s
);
3009 /* Shift a TCGv src by TCGv shift_amount, put result in dst.
3010 * Note that it is the caller's responsibility to ensure that the
3011 * shift amount is in range (ie 0..31 or 0..63) and provide the ARM
3012 * mandated semantics for out of range shifts.
3014 static void shift_reg(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3015 enum a64_shift_type shift_type
, TCGv_i64 shift_amount
)
3017 switch (shift_type
) {
3018 case A64_SHIFT_TYPE_LSL
:
3019 tcg_gen_shl_i64(dst
, src
, shift_amount
);
3021 case A64_SHIFT_TYPE_LSR
:
3022 tcg_gen_shr_i64(dst
, src
, shift_amount
);
3024 case A64_SHIFT_TYPE_ASR
:
3026 tcg_gen_ext32s_i64(dst
, src
);
3028 tcg_gen_sar_i64(dst
, sf
? src
: dst
, shift_amount
);
3030 case A64_SHIFT_TYPE_ROR
:
3032 tcg_gen_rotr_i64(dst
, src
, shift_amount
);
3035 t0
= tcg_temp_new_i32();
3036 t1
= tcg_temp_new_i32();
3037 tcg_gen_trunc_i64_i32(t0
, src
);
3038 tcg_gen_trunc_i64_i32(t1
, shift_amount
);
3039 tcg_gen_rotr_i32(t0
, t0
, t1
);
3040 tcg_gen_extu_i32_i64(dst
, t0
);
3041 tcg_temp_free_i32(t0
);
3042 tcg_temp_free_i32(t1
);
3046 assert(FALSE
); /* all shift types should be handled */
3050 if (!sf
) { /* zero extend final result */
3051 tcg_gen_ext32u_i64(dst
, dst
);
3055 /* Shift a TCGv src by immediate, put result in dst.
3056 * The shift amount must be in range (this should always be true as the
3057 * relevant instructions will UNDEF on bad shift immediates).
3059 static void shift_reg_imm(TCGv_i64 dst
, TCGv_i64 src
, int sf
,
3060 enum a64_shift_type shift_type
, unsigned int shift_i
)
3062 assert(shift_i
< (sf
? 64 : 32));
3065 tcg_gen_mov_i64(dst
, src
);
3067 TCGv_i64 shift_const
;
3069 shift_const
= tcg_const_i64(shift_i
);
3070 shift_reg(dst
, src
, sf
, shift_type
, shift_const
);
3071 tcg_temp_free_i64(shift_const
);
3075 /* C3.5.10 Logical (shifted register)
3076 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3077 * +----+-----+-----------+-------+---+------+--------+------+------+
3078 * | sf | opc | 0 1 0 1 0 | shift | N | Rm | imm6 | Rn | Rd |
3079 * +----+-----+-----------+-------+---+------+--------+------+------+
3081 static void disas_logic_reg(DisasContext
*s
, uint32_t insn
)
3083 TCGv_i64 tcg_rd
, tcg_rn
, tcg_rm
;
3084 unsigned int sf
, opc
, shift_type
, invert
, rm
, shift_amount
, rn
, rd
;
3086 sf
= extract32(insn
, 31, 1);
3087 opc
= extract32(insn
, 29, 2);
3088 shift_type
= extract32(insn
, 22, 2);
3089 invert
= extract32(insn
, 21, 1);
3090 rm
= extract32(insn
, 16, 5);
3091 shift_amount
= extract32(insn
, 10, 6);
3092 rn
= extract32(insn
, 5, 5);
3093 rd
= extract32(insn
, 0, 5);
3095 if (!sf
&& (shift_amount
& (1 << 5))) {
3096 unallocated_encoding(s
);
3100 tcg_rd
= cpu_reg(s
, rd
);
3102 if (opc
== 1 && shift_amount
== 0 && shift_type
== 0 && rn
== 31) {
3103 /* Unshifted ORR and ORN with WZR/XZR is the standard encoding for
3104 * register-register MOV and MVN, so it is worth special casing.
3106 tcg_rm
= cpu_reg(s
, rm
);
3108 tcg_gen_not_i64(tcg_rd
, tcg_rm
);
3110 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3114 tcg_gen_mov_i64(tcg_rd
, tcg_rm
);
3116 tcg_gen_ext32u_i64(tcg_rd
, tcg_rm
);
3122 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3125 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, shift_amount
);
3128 tcg_rn
= cpu_reg(s
, rn
);
3130 switch (opc
| (invert
<< 2)) {
3133 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3136 tcg_gen_or_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3139 tcg_gen_xor_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3143 tcg_gen_andc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3146 tcg_gen_orc_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3149 tcg_gen_eqv_i64(tcg_rd
, tcg_rn
, tcg_rm
);
3157 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3161 gen_logic_CC(sf
, tcg_rd
);
3166 * C3.5.1 Add/subtract (extended register)
3168 * 31|30|29|28 24|23 22|21|20 16|15 13|12 10|9 5|4 0|
3169 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3170 * |sf|op| S| 0 1 0 1 1 | opt | 1| Rm |option| imm3 | Rn | Rd |
3171 * +--+--+--+-----------+-----+--+-------+------+------+----+----+
3173 * sf: 0 -> 32bit, 1 -> 64bit
3174 * op: 0 -> add , 1 -> sub
3177 * option: extension type (see DecodeRegExtend)
3178 * imm3: optional shift to Rm
3180 * Rd = Rn + LSL(extend(Rm), amount)
3182 static void disas_add_sub_ext_reg(DisasContext
*s
, uint32_t insn
)
3184 int rd
= extract32(insn
, 0, 5);
3185 int rn
= extract32(insn
, 5, 5);
3186 int imm3
= extract32(insn
, 10, 3);
3187 int option
= extract32(insn
, 13, 3);
3188 int rm
= extract32(insn
, 16, 5);
3189 bool setflags
= extract32(insn
, 29, 1);
3190 bool sub_op
= extract32(insn
, 30, 1);
3191 bool sf
= extract32(insn
, 31, 1);
3193 TCGv_i64 tcg_rm
, tcg_rn
; /* temps */
3195 TCGv_i64 tcg_result
;
3198 unallocated_encoding(s
);
3202 /* non-flag setting ops may use SP */
3204 tcg_rd
= cpu_reg_sp(s
, rd
);
3206 tcg_rd
= cpu_reg(s
, rd
);
3208 tcg_rn
= read_cpu_reg_sp(s
, rn
, sf
);
3210 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3211 ext_and_shift_reg(tcg_rm
, tcg_rm
, option
, imm3
);
3213 tcg_result
= tcg_temp_new_i64();
3217 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3219 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3223 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3225 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3230 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3232 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3235 tcg_temp_free_i64(tcg_result
);
3239 * C3.5.2 Add/subtract (shifted register)
3241 * 31 30 29 28 24 23 22 21 20 16 15 10 9 5 4 0
3242 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3243 * |sf|op| S| 0 1 0 1 1 |shift| 0| Rm | imm6 | Rn | Rd |
3244 * +--+--+--+-----------+-----+--+-------+---------+------+------+
3246 * sf: 0 -> 32bit, 1 -> 64bit
3247 * op: 0 -> add , 1 -> sub
3249 * shift: 00 -> LSL, 01 -> LSR, 10 -> ASR, 11 -> RESERVED
3250 * imm6: Shift amount to apply to Rm before the add/sub
3252 static void disas_add_sub_reg(DisasContext
*s
, uint32_t insn
)
3254 int rd
= extract32(insn
, 0, 5);
3255 int rn
= extract32(insn
, 5, 5);
3256 int imm6
= extract32(insn
, 10, 6);
3257 int rm
= extract32(insn
, 16, 5);
3258 int shift_type
= extract32(insn
, 22, 2);
3259 bool setflags
= extract32(insn
, 29, 1);
3260 bool sub_op
= extract32(insn
, 30, 1);
3261 bool sf
= extract32(insn
, 31, 1);
3263 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3264 TCGv_i64 tcg_rn
, tcg_rm
;
3265 TCGv_i64 tcg_result
;
3267 if ((shift_type
== 3) || (!sf
&& (imm6
> 31))) {
3268 unallocated_encoding(s
);
3272 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3273 tcg_rm
= read_cpu_reg(s
, rm
, sf
);
3275 shift_reg_imm(tcg_rm
, tcg_rm
, sf
, shift_type
, imm6
);
3277 tcg_result
= tcg_temp_new_i64();
3281 tcg_gen_sub_i64(tcg_result
, tcg_rn
, tcg_rm
);
3283 tcg_gen_add_i64(tcg_result
, tcg_rn
, tcg_rm
);
3287 gen_sub_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3289 gen_add_CC(sf
, tcg_result
, tcg_rn
, tcg_rm
);
3294 tcg_gen_mov_i64(tcg_rd
, tcg_result
);
3296 tcg_gen_ext32u_i64(tcg_rd
, tcg_result
);
3299 tcg_temp_free_i64(tcg_result
);
3302 /* C3.5.9 Data-processing (3 source)
3304 31 30 29 28 24 23 21 20 16 15 14 10 9 5 4 0
3305 +--+------+-----------+------+------+----+------+------+------+
3306 |sf| op54 | 1 1 0 1 1 | op31 | Rm | o0 | Ra | Rn | Rd |
3307 +--+------+-----------+------+------+----+------+------+------+
3310 static void disas_data_proc_3src(DisasContext
*s
, uint32_t insn
)
3312 int rd
= extract32(insn
, 0, 5);
3313 int rn
= extract32(insn
, 5, 5);
3314 int ra
= extract32(insn
, 10, 5);
3315 int rm
= extract32(insn
, 16, 5);
3316 int op_id
= (extract32(insn
, 29, 3) << 4) |
3317 (extract32(insn
, 21, 3) << 1) |
3318 extract32(insn
, 15, 1);
3319 bool sf
= extract32(insn
, 31, 1);
3320 bool is_sub
= extract32(op_id
, 0, 1);
3321 bool is_high
= extract32(op_id
, 2, 1);
3322 bool is_signed
= false;
3327 /* Note that op_id is sf:op54:op31:o0 so it includes the 32/64 size flag */
3329 case 0x42: /* SMADDL */
3330 case 0x43: /* SMSUBL */
3331 case 0x44: /* SMULH */
3334 case 0x0: /* MADD (32bit) */
3335 case 0x1: /* MSUB (32bit) */
3336 case 0x40: /* MADD (64bit) */
3337 case 0x41: /* MSUB (64bit) */
3338 case 0x4a: /* UMADDL */
3339 case 0x4b: /* UMSUBL */
3340 case 0x4c: /* UMULH */
3343 unallocated_encoding(s
);
3348 TCGv_i64 low_bits
= tcg_temp_new_i64(); /* low bits discarded */
3349 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3350 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
3351 TCGv_i64 tcg_rm
= cpu_reg(s
, rm
);
3354 tcg_gen_muls2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3356 tcg_gen_mulu2_i64(low_bits
, tcg_rd
, tcg_rn
, tcg_rm
);
3359 tcg_temp_free_i64(low_bits
);
3363 tcg_op1
= tcg_temp_new_i64();
3364 tcg_op2
= tcg_temp_new_i64();
3365 tcg_tmp
= tcg_temp_new_i64();
3368 tcg_gen_mov_i64(tcg_op1
, cpu_reg(s
, rn
));
3369 tcg_gen_mov_i64(tcg_op2
, cpu_reg(s
, rm
));
3372 tcg_gen_ext32s_i64(tcg_op1
, cpu_reg(s
, rn
));
3373 tcg_gen_ext32s_i64(tcg_op2
, cpu_reg(s
, rm
));
3375 tcg_gen_ext32u_i64(tcg_op1
, cpu_reg(s
, rn
));
3376 tcg_gen_ext32u_i64(tcg_op2
, cpu_reg(s
, rm
));
3380 if (ra
== 31 && !is_sub
) {
3381 /* Special-case MADD with rA == XZR; it is the standard MUL alias */
3382 tcg_gen_mul_i64(cpu_reg(s
, rd
), tcg_op1
, tcg_op2
);
3384 tcg_gen_mul_i64(tcg_tmp
, tcg_op1
, tcg_op2
);
3386 tcg_gen_sub_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3388 tcg_gen_add_i64(cpu_reg(s
, rd
), cpu_reg(s
, ra
), tcg_tmp
);
3393 tcg_gen_ext32u_i64(cpu_reg(s
, rd
), cpu_reg(s
, rd
));
3396 tcg_temp_free_i64(tcg_op1
);
3397 tcg_temp_free_i64(tcg_op2
);
3398 tcg_temp_free_i64(tcg_tmp
);
3401 /* C3.5.3 - Add/subtract (with carry)
3402 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 10 9 5 4 0
3403 * +--+--+--+------------------------+------+---------+------+-----+
3404 * |sf|op| S| 1 1 0 1 0 0 0 0 | rm | opcode2 | Rn | Rd |
3405 * +--+--+--+------------------------+------+---------+------+-----+
3409 static void disas_adc_sbc(DisasContext
*s
, uint32_t insn
)
3411 unsigned int sf
, op
, setflags
, rm
, rn
, rd
;
3412 TCGv_i64 tcg_y
, tcg_rn
, tcg_rd
;
3414 if (extract32(insn
, 10, 6) != 0) {
3415 unallocated_encoding(s
);
3419 sf
= extract32(insn
, 31, 1);
3420 op
= extract32(insn
, 30, 1);
3421 setflags
= extract32(insn
, 29, 1);
3422 rm
= extract32(insn
, 16, 5);
3423 rn
= extract32(insn
, 5, 5);
3424 rd
= extract32(insn
, 0, 5);
3426 tcg_rd
= cpu_reg(s
, rd
);
3427 tcg_rn
= cpu_reg(s
, rn
);
3430 tcg_y
= new_tmp_a64(s
);
3431 tcg_gen_not_i64(tcg_y
, cpu_reg(s
, rm
));
3433 tcg_y
= cpu_reg(s
, rm
);
3437 gen_adc_CC(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3439 gen_adc(sf
, tcg_rd
, tcg_rn
, tcg_y
);
3443 /* C3.5.4 - C3.5.5 Conditional compare (immediate / register)
3444 * 31 30 29 28 27 26 25 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
3445 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3446 * |sf|op| S| 1 1 0 1 0 0 1 0 |imm5/rm | cond |i/r |o2| Rn |o3|nzcv |
3447 * +--+--+--+------------------------+--------+------+----+--+------+--+-----+
3450 static void disas_cc(DisasContext
*s
, uint32_t insn
)
3452 unsigned int sf
, op
, y
, cond
, rn
, nzcv
, is_imm
;
3453 int label_continue
= -1;
3454 TCGv_i64 tcg_tmp
, tcg_y
, tcg_rn
;
3456 if (!extract32(insn
, 29, 1)) {
3457 unallocated_encoding(s
);
3460 if (insn
& (1 << 10 | 1 << 4)) {
3461 unallocated_encoding(s
);
3464 sf
= extract32(insn
, 31, 1);
3465 op
= extract32(insn
, 30, 1);
3466 is_imm
= extract32(insn
, 11, 1);
3467 y
= extract32(insn
, 16, 5); /* y = rm (reg) or imm5 (imm) */
3468 cond
= extract32(insn
, 12, 4);
3469 rn
= extract32(insn
, 5, 5);
3470 nzcv
= extract32(insn
, 0, 4);
3472 if (cond
< 0x0e) { /* not always */
3473 int label_match
= gen_new_label();
3474 label_continue
= gen_new_label();
3475 arm_gen_test_cc(cond
, label_match
);
3477 tcg_tmp
= tcg_temp_new_i64();
3478 tcg_gen_movi_i64(tcg_tmp
, nzcv
<< 28);
3479 gen_set_nzcv(tcg_tmp
);
3480 tcg_temp_free_i64(tcg_tmp
);
3481 tcg_gen_br(label_continue
);
3482 gen_set_label(label_match
);
3484 /* match, or condition is always */
3486 tcg_y
= new_tmp_a64(s
);
3487 tcg_gen_movi_i64(tcg_y
, y
);
3489 tcg_y
= cpu_reg(s
, y
);
3491 tcg_rn
= cpu_reg(s
, rn
);
3493 tcg_tmp
= tcg_temp_new_i64();
3495 gen_sub_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3497 gen_add_CC(sf
, tcg_tmp
, tcg_rn
, tcg_y
);
3499 tcg_temp_free_i64(tcg_tmp
);
3501 if (cond
< 0x0e) { /* continue */
3502 gen_set_label(label_continue
);
3506 /* C3.5.6 Conditional select
3507 * 31 30 29 28 21 20 16 15 12 11 10 9 5 4 0
3508 * +----+----+---+-----------------+------+------+-----+------+------+
3509 * | sf | op | S | 1 1 0 1 0 1 0 0 | Rm | cond | op2 | Rn | Rd |
3510 * +----+----+---+-----------------+------+------+-----+------+------+
3512 static void disas_cond_select(DisasContext
*s
, uint32_t insn
)
3514 unsigned int sf
, else_inv
, rm
, cond
, else_inc
, rn
, rd
;
3515 TCGv_i64 tcg_rd
, tcg_src
;
3517 if (extract32(insn
, 29, 1) || extract32(insn
, 11, 1)) {
3518 /* S == 1 or op2<1> == 1 */
3519 unallocated_encoding(s
);
3522 sf
= extract32(insn
, 31, 1);
3523 else_inv
= extract32(insn
, 30, 1);
3524 rm
= extract32(insn
, 16, 5);
3525 cond
= extract32(insn
, 12, 4);
3526 else_inc
= extract32(insn
, 10, 1);
3527 rn
= extract32(insn
, 5, 5);
3528 rd
= extract32(insn
, 0, 5);
3531 /* silly no-op write; until we use movcond we must special-case
3532 * this to avoid a dead temporary across basic blocks.
3537 tcg_rd
= cpu_reg(s
, rd
);
3539 if (cond
>= 0x0e) { /* condition "always" */
3540 tcg_src
= read_cpu_reg(s
, rn
, sf
);
3541 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3543 /* OPTME: we could use movcond here, at the cost of duplicating
3544 * a lot of the arm_gen_test_cc() logic.
3546 int label_match
= gen_new_label();
3547 int label_continue
= gen_new_label();
3549 arm_gen_test_cc(cond
, label_match
);
3551 tcg_src
= cpu_reg(s
, rm
);
3553 if (else_inv
&& else_inc
) {
3554 tcg_gen_neg_i64(tcg_rd
, tcg_src
);
3555 } else if (else_inv
) {
3556 tcg_gen_not_i64(tcg_rd
, tcg_src
);
3557 } else if (else_inc
) {
3558 tcg_gen_addi_i64(tcg_rd
, tcg_src
, 1);
3560 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3563 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3565 tcg_gen_br(label_continue
);
3567 gen_set_label(label_match
);
3568 tcg_src
= read_cpu_reg(s
, rn
, sf
);
3569 tcg_gen_mov_i64(tcg_rd
, tcg_src
);
3571 gen_set_label(label_continue
);
3575 static void handle_clz(DisasContext
*s
, unsigned int sf
,
3576 unsigned int rn
, unsigned int rd
)
3578 TCGv_i64 tcg_rd
, tcg_rn
;
3579 tcg_rd
= cpu_reg(s
, rd
);
3580 tcg_rn
= cpu_reg(s
, rn
);
3583 gen_helper_clz64(tcg_rd
, tcg_rn
);
3585 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3586 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3587 gen_helper_clz(tcg_tmp32
, tcg_tmp32
);
3588 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3589 tcg_temp_free_i32(tcg_tmp32
);
3593 static void handle_cls(DisasContext
*s
, unsigned int sf
,
3594 unsigned int rn
, unsigned int rd
)
3596 TCGv_i64 tcg_rd
, tcg_rn
;
3597 tcg_rd
= cpu_reg(s
, rd
);
3598 tcg_rn
= cpu_reg(s
, rn
);
3601 gen_helper_cls64(tcg_rd
, tcg_rn
);
3603 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3604 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3605 gen_helper_cls32(tcg_tmp32
, tcg_tmp32
);
3606 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3607 tcg_temp_free_i32(tcg_tmp32
);
3611 static void handle_rbit(DisasContext
*s
, unsigned int sf
,
3612 unsigned int rn
, unsigned int rd
)
3614 TCGv_i64 tcg_rd
, tcg_rn
;
3615 tcg_rd
= cpu_reg(s
, rd
);
3616 tcg_rn
= cpu_reg(s
, rn
);
3619 gen_helper_rbit64(tcg_rd
, tcg_rn
);
3621 TCGv_i32 tcg_tmp32
= tcg_temp_new_i32();
3622 tcg_gen_trunc_i64_i32(tcg_tmp32
, tcg_rn
);
3623 gen_helper_rbit(tcg_tmp32
, tcg_tmp32
);
3624 tcg_gen_extu_i32_i64(tcg_rd
, tcg_tmp32
);
3625 tcg_temp_free_i32(tcg_tmp32
);
3629 /* C5.6.149 REV with sf==1, opcode==3 ("REV64") */
3630 static void handle_rev64(DisasContext
*s
, unsigned int sf
,
3631 unsigned int rn
, unsigned int rd
)
3634 unallocated_encoding(s
);
3637 tcg_gen_bswap64_i64(cpu_reg(s
, rd
), cpu_reg(s
, rn
));
3640 /* C5.6.149 REV with sf==0, opcode==2
3641 * C5.6.151 REV32 (sf==1, opcode==2)
3643 static void handle_rev32(DisasContext
*s
, unsigned int sf
,
3644 unsigned int rn
, unsigned int rd
)
3646 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3649 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3650 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3652 /* bswap32_i64 requires zero high word */
3653 tcg_gen_ext32u_i64(tcg_tmp
, tcg_rn
);
3654 tcg_gen_bswap32_i64(tcg_rd
, tcg_tmp
);
3655 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3656 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
3657 tcg_gen_concat32_i64(tcg_rd
, tcg_rd
, tcg_tmp
);
3659 tcg_temp_free_i64(tcg_tmp
);
3661 tcg_gen_ext32u_i64(tcg_rd
, cpu_reg(s
, rn
));
3662 tcg_gen_bswap32_i64(tcg_rd
, tcg_rd
);
3666 /* C5.6.150 REV16 (opcode==1) */
3667 static void handle_rev16(DisasContext
*s
, unsigned int sf
,
3668 unsigned int rn
, unsigned int rd
)
3670 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3671 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
3672 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3674 tcg_gen_andi_i64(tcg_tmp
, tcg_rn
, 0xffff);
3675 tcg_gen_bswap16_i64(tcg_rd
, tcg_tmp
);
3677 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 16);
3678 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3679 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3680 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 16, 16);
3683 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 32);
3684 tcg_gen_andi_i64(tcg_tmp
, tcg_tmp
, 0xffff);
3685 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3686 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 32, 16);
3688 tcg_gen_shri_i64(tcg_tmp
, tcg_rn
, 48);
3689 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
3690 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_tmp
, 48, 16);
3693 tcg_temp_free_i64(tcg_tmp
);
3696 /* C3.5.7 Data-processing (1 source)
3697 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3698 * +----+---+---+-----------------+---------+--------+------+------+
3699 * | sf | 1 | S | 1 1 0 1 0 1 1 0 | opcode2 | opcode | Rn | Rd |
3700 * +----+---+---+-----------------+---------+--------+------+------+
3702 static void disas_data_proc_1src(DisasContext
*s
, uint32_t insn
)
3704 unsigned int sf
, opcode
, rn
, rd
;
3706 if (extract32(insn
, 29, 1) || extract32(insn
, 16, 5)) {
3707 unallocated_encoding(s
);
3711 sf
= extract32(insn
, 31, 1);
3712 opcode
= extract32(insn
, 10, 6);
3713 rn
= extract32(insn
, 5, 5);
3714 rd
= extract32(insn
, 0, 5);
3718 handle_rbit(s
, sf
, rn
, rd
);
3721 handle_rev16(s
, sf
, rn
, rd
);
3724 handle_rev32(s
, sf
, rn
, rd
);
3727 handle_rev64(s
, sf
, rn
, rd
);
3730 handle_clz(s
, sf
, rn
, rd
);
3733 handle_cls(s
, sf
, rn
, rd
);
3738 static void handle_div(DisasContext
*s
, bool is_signed
, unsigned int sf
,
3739 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3741 TCGv_i64 tcg_n
, tcg_m
, tcg_rd
;
3742 tcg_rd
= cpu_reg(s
, rd
);
3744 if (!sf
&& is_signed
) {
3745 tcg_n
= new_tmp_a64(s
);
3746 tcg_m
= new_tmp_a64(s
);
3747 tcg_gen_ext32s_i64(tcg_n
, cpu_reg(s
, rn
));
3748 tcg_gen_ext32s_i64(tcg_m
, cpu_reg(s
, rm
));
3750 tcg_n
= read_cpu_reg(s
, rn
, sf
);
3751 tcg_m
= read_cpu_reg(s
, rm
, sf
);
3755 gen_helper_sdiv64(tcg_rd
, tcg_n
, tcg_m
);
3757 gen_helper_udiv64(tcg_rd
, tcg_n
, tcg_m
);
3760 if (!sf
) { /* zero extend final result */
3761 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
3765 /* C5.6.115 LSLV, C5.6.118 LSRV, C5.6.17 ASRV, C5.6.154 RORV */
3766 static void handle_shift_reg(DisasContext
*s
,
3767 enum a64_shift_type shift_type
, unsigned int sf
,
3768 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3770 TCGv_i64 tcg_shift
= tcg_temp_new_i64();
3771 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
3772 TCGv_i64 tcg_rn
= read_cpu_reg(s
, rn
, sf
);
3774 tcg_gen_andi_i64(tcg_shift
, cpu_reg(s
, rm
), sf
? 63 : 31);
3775 shift_reg(tcg_rd
, tcg_rn
, sf
, shift_type
, tcg_shift
);
3776 tcg_temp_free_i64(tcg_shift
);
3779 /* CRC32[BHWX], CRC32C[BHWX] */
3780 static void handle_crc32(DisasContext
*s
,
3781 unsigned int sf
, unsigned int sz
, bool crc32c
,
3782 unsigned int rm
, unsigned int rn
, unsigned int rd
)
3784 TCGv_i64 tcg_acc
, tcg_val
;
3787 if (!arm_dc_feature(s
, ARM_FEATURE_CRC
)
3788 || (sf
== 1 && sz
!= 3)
3789 || (sf
== 0 && sz
== 3)) {
3790 unallocated_encoding(s
);
3795 tcg_val
= cpu_reg(s
, rm
);
3809 g_assert_not_reached();
3811 tcg_val
= new_tmp_a64(s
);
3812 tcg_gen_andi_i64(tcg_val
, cpu_reg(s
, rm
), mask
);
3815 tcg_acc
= cpu_reg(s
, rn
);
3816 tcg_bytes
= tcg_const_i32(1 << sz
);
3819 gen_helper_crc32c_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
3821 gen_helper_crc32_64(cpu_reg(s
, rd
), tcg_acc
, tcg_val
, tcg_bytes
);
3824 tcg_temp_free_i32(tcg_bytes
);
3827 /* C3.5.8 Data-processing (2 source)
3828 * 31 30 29 28 21 20 16 15 10 9 5 4 0
3829 * +----+---+---+-----------------+------+--------+------+------+
3830 * | sf | 0 | S | 1 1 0 1 0 1 1 0 | Rm | opcode | Rn | Rd |
3831 * +----+---+---+-----------------+------+--------+------+------+
3833 static void disas_data_proc_2src(DisasContext
*s
, uint32_t insn
)
3835 unsigned int sf
, rm
, opcode
, rn
, rd
;
3836 sf
= extract32(insn
, 31, 1);
3837 rm
= extract32(insn
, 16, 5);
3838 opcode
= extract32(insn
, 10, 6);
3839 rn
= extract32(insn
, 5, 5);
3840 rd
= extract32(insn
, 0, 5);
3842 if (extract32(insn
, 29, 1)) {
3843 unallocated_encoding(s
);
3849 handle_div(s
, false, sf
, rm
, rn
, rd
);
3852 handle_div(s
, true, sf
, rm
, rn
, rd
);
3855 handle_shift_reg(s
, A64_SHIFT_TYPE_LSL
, sf
, rm
, rn
, rd
);
3858 handle_shift_reg(s
, A64_SHIFT_TYPE_LSR
, sf
, rm
, rn
, rd
);
3861 handle_shift_reg(s
, A64_SHIFT_TYPE_ASR
, sf
, rm
, rn
, rd
);
3864 handle_shift_reg(s
, A64_SHIFT_TYPE_ROR
, sf
, rm
, rn
, rd
);
3873 case 23: /* CRC32 */
3875 int sz
= extract32(opcode
, 0, 2);
3876 bool crc32c
= extract32(opcode
, 2, 1);
3877 handle_crc32(s
, sf
, sz
, crc32c
, rm
, rn
, rd
);
3881 unallocated_encoding(s
);
3886 /* C3.5 Data processing - register */
3887 static void disas_data_proc_reg(DisasContext
*s
, uint32_t insn
)
3889 switch (extract32(insn
, 24, 5)) {
3890 case 0x0a: /* Logical (shifted register) */
3891 disas_logic_reg(s
, insn
);
3893 case 0x0b: /* Add/subtract */
3894 if (insn
& (1 << 21)) { /* (extended register) */
3895 disas_add_sub_ext_reg(s
, insn
);
3897 disas_add_sub_reg(s
, insn
);
3900 case 0x1b: /* Data-processing (3 source) */
3901 disas_data_proc_3src(s
, insn
);
3904 switch (extract32(insn
, 21, 3)) {
3905 case 0x0: /* Add/subtract (with carry) */
3906 disas_adc_sbc(s
, insn
);
3908 case 0x2: /* Conditional compare */
3909 disas_cc(s
, insn
); /* both imm and reg forms */
3911 case 0x4: /* Conditional select */
3912 disas_cond_select(s
, insn
);
3914 case 0x6: /* Data-processing */
3915 if (insn
& (1 << 30)) { /* (1 source) */
3916 disas_data_proc_1src(s
, insn
);
3917 } else { /* (2 source) */
3918 disas_data_proc_2src(s
, insn
);
3922 unallocated_encoding(s
);
3927 unallocated_encoding(s
);
3932 static void handle_fp_compare(DisasContext
*s
, bool is_double
,
3933 unsigned int rn
, unsigned int rm
,
3934 bool cmp_with_zero
, bool signal_all_nans
)
3936 TCGv_i64 tcg_flags
= tcg_temp_new_i64();
3937 TCGv_ptr fpst
= get_fpstatus_ptr();
3940 TCGv_i64 tcg_vn
, tcg_vm
;
3942 tcg_vn
= read_fp_dreg(s
, rn
);
3943 if (cmp_with_zero
) {
3944 tcg_vm
= tcg_const_i64(0);
3946 tcg_vm
= read_fp_dreg(s
, rm
);
3948 if (signal_all_nans
) {
3949 gen_helper_vfp_cmped_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
3951 gen_helper_vfp_cmpd_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
3953 tcg_temp_free_i64(tcg_vn
);
3954 tcg_temp_free_i64(tcg_vm
);
3956 TCGv_i32 tcg_vn
, tcg_vm
;
3958 tcg_vn
= read_fp_sreg(s
, rn
);
3959 if (cmp_with_zero
) {
3960 tcg_vm
= tcg_const_i32(0);
3962 tcg_vm
= read_fp_sreg(s
, rm
);
3964 if (signal_all_nans
) {
3965 gen_helper_vfp_cmpes_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
3967 gen_helper_vfp_cmps_a64(tcg_flags
, tcg_vn
, tcg_vm
, fpst
);
3969 tcg_temp_free_i32(tcg_vn
);
3970 tcg_temp_free_i32(tcg_vm
);
3973 tcg_temp_free_ptr(fpst
);
3975 gen_set_nzcv(tcg_flags
);
3977 tcg_temp_free_i64(tcg_flags
);
3980 /* C3.6.22 Floating point compare
3981 * 31 30 29 28 24 23 22 21 20 16 15 14 13 10 9 5 4 0
3982 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
3983 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | op | 1 0 0 0 | Rn | op2 |
3984 * +---+---+---+-----------+------+---+------+-----+---------+------+-------+
3986 static void disas_fp_compare(DisasContext
*s
, uint32_t insn
)
3988 unsigned int mos
, type
, rm
, op
, rn
, opc
, op2r
;
3990 mos
= extract32(insn
, 29, 3);
3991 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
3992 rm
= extract32(insn
, 16, 5);
3993 op
= extract32(insn
, 14, 2);
3994 rn
= extract32(insn
, 5, 5);
3995 opc
= extract32(insn
, 3, 2);
3996 op2r
= extract32(insn
, 0, 3);
3998 if (mos
|| op
|| op2r
|| type
> 1) {
3999 unallocated_encoding(s
);
4003 if (!fp_access_check(s
)) {
4007 handle_fp_compare(s
, type
, rn
, rm
, opc
& 1, opc
& 2);
4010 /* C3.6.23 Floating point conditional compare
4011 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 3 0
4012 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4013 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 0 1 | Rn | op | nzcv |
4014 * +---+---+---+-----------+------+---+------+------+-----+------+----+------+
4016 static void disas_fp_ccomp(DisasContext
*s
, uint32_t insn
)
4018 unsigned int mos
, type
, rm
, cond
, rn
, op
, nzcv
;
4020 int label_continue
= -1;
4022 mos
= extract32(insn
, 29, 3);
4023 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4024 rm
= extract32(insn
, 16, 5);
4025 cond
= extract32(insn
, 12, 4);
4026 rn
= extract32(insn
, 5, 5);
4027 op
= extract32(insn
, 4, 1);
4028 nzcv
= extract32(insn
, 0, 4);
4030 if (mos
|| type
> 1) {
4031 unallocated_encoding(s
);
4035 if (!fp_access_check(s
)) {
4039 if (cond
< 0x0e) { /* not always */
4040 int label_match
= gen_new_label();
4041 label_continue
= gen_new_label();
4042 arm_gen_test_cc(cond
, label_match
);
4044 tcg_flags
= tcg_const_i64(nzcv
<< 28);
4045 gen_set_nzcv(tcg_flags
);
4046 tcg_temp_free_i64(tcg_flags
);
4047 tcg_gen_br(label_continue
);
4048 gen_set_label(label_match
);
4051 handle_fp_compare(s
, type
, rn
, rm
, false, op
);
4054 gen_set_label(label_continue
);
4058 /* copy src FP register to dst FP register; type specifies single or double */
4059 static void gen_mov_fp2fp(DisasContext
*s
, int type
, int dst
, int src
)
4062 TCGv_i64 v
= read_fp_dreg(s
, src
);
4063 write_fp_dreg(s
, dst
, v
);
4064 tcg_temp_free_i64(v
);
4066 TCGv_i32 v
= read_fp_sreg(s
, src
);
4067 write_fp_sreg(s
, dst
, v
);
4068 tcg_temp_free_i32(v
);
4072 /* C3.6.24 Floating point conditional select
4073 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4074 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4075 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | cond | 1 1 | Rn | Rd |
4076 * +---+---+---+-----------+------+---+------+------+-----+------+------+
4078 static void disas_fp_csel(DisasContext
*s
, uint32_t insn
)
4080 unsigned int mos
, type
, rm
, cond
, rn
, rd
;
4081 int label_continue
= -1;
4083 mos
= extract32(insn
, 29, 3);
4084 type
= extract32(insn
, 22, 2); /* 0 = single, 1 = double */
4085 rm
= extract32(insn
, 16, 5);
4086 cond
= extract32(insn
, 12, 4);
4087 rn
= extract32(insn
, 5, 5);
4088 rd
= extract32(insn
, 0, 5);
4090 if (mos
|| type
> 1) {
4091 unallocated_encoding(s
);
4095 if (!fp_access_check(s
)) {
4099 if (cond
< 0x0e) { /* not always */
4100 int label_match
= gen_new_label();
4101 label_continue
= gen_new_label();
4102 arm_gen_test_cc(cond
, label_match
);
4104 gen_mov_fp2fp(s
, type
, rd
, rm
);
4105 tcg_gen_br(label_continue
);
4106 gen_set_label(label_match
);
4109 gen_mov_fp2fp(s
, type
, rd
, rn
);
4111 if (cond
< 0x0e) { /* continue */
4112 gen_set_label(label_continue
);
4116 /* C3.6.25 Floating-point data-processing (1 source) - single precision */
4117 static void handle_fp_1src_single(DisasContext
*s
, int opcode
, int rd
, int rn
)
4123 fpst
= get_fpstatus_ptr();
4124 tcg_op
= read_fp_sreg(s
, rn
);
4125 tcg_res
= tcg_temp_new_i32();
4128 case 0x0: /* FMOV */
4129 tcg_gen_mov_i32(tcg_res
, tcg_op
);
4131 case 0x1: /* FABS */
4132 gen_helper_vfp_abss(tcg_res
, tcg_op
);
4134 case 0x2: /* FNEG */
4135 gen_helper_vfp_negs(tcg_res
, tcg_op
);
4137 case 0x3: /* FSQRT */
4138 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
4140 case 0x8: /* FRINTN */
4141 case 0x9: /* FRINTP */
4142 case 0xa: /* FRINTM */
4143 case 0xb: /* FRINTZ */
4144 case 0xc: /* FRINTA */
4146 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4148 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4149 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4151 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4152 tcg_temp_free_i32(tcg_rmode
);
4155 case 0xe: /* FRINTX */
4156 gen_helper_rints_exact(tcg_res
, tcg_op
, fpst
);
4158 case 0xf: /* FRINTI */
4159 gen_helper_rints(tcg_res
, tcg_op
, fpst
);
4165 write_fp_sreg(s
, rd
, tcg_res
);
4167 tcg_temp_free_ptr(fpst
);
4168 tcg_temp_free_i32(tcg_op
);
4169 tcg_temp_free_i32(tcg_res
);
4172 /* C3.6.25 Floating-point data-processing (1 source) - double precision */
4173 static void handle_fp_1src_double(DisasContext
*s
, int opcode
, int rd
, int rn
)
4179 fpst
= get_fpstatus_ptr();
4180 tcg_op
= read_fp_dreg(s
, rn
);
4181 tcg_res
= tcg_temp_new_i64();
4184 case 0x0: /* FMOV */
4185 tcg_gen_mov_i64(tcg_res
, tcg_op
);
4187 case 0x1: /* FABS */
4188 gen_helper_vfp_absd(tcg_res
, tcg_op
);
4190 case 0x2: /* FNEG */
4191 gen_helper_vfp_negd(tcg_res
, tcg_op
);
4193 case 0x3: /* FSQRT */
4194 gen_helper_vfp_sqrtd(tcg_res
, tcg_op
, cpu_env
);
4196 case 0x8: /* FRINTN */
4197 case 0x9: /* FRINTP */
4198 case 0xa: /* FRINTM */
4199 case 0xb: /* FRINTZ */
4200 case 0xc: /* FRINTA */
4202 TCGv_i32 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(opcode
& 7));
4204 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4205 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4207 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4208 tcg_temp_free_i32(tcg_rmode
);
4211 case 0xe: /* FRINTX */
4212 gen_helper_rintd_exact(tcg_res
, tcg_op
, fpst
);
4214 case 0xf: /* FRINTI */
4215 gen_helper_rintd(tcg_res
, tcg_op
, fpst
);
4221 write_fp_dreg(s
, rd
, tcg_res
);
4223 tcg_temp_free_ptr(fpst
);
4224 tcg_temp_free_i64(tcg_op
);
4225 tcg_temp_free_i64(tcg_res
);
4228 static void handle_fp_fcvt(DisasContext
*s
, int opcode
,
4229 int rd
, int rn
, int dtype
, int ntype
)
4234 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4236 /* Single to double */
4237 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4238 gen_helper_vfp_fcvtds(tcg_rd
, tcg_rn
, cpu_env
);
4239 write_fp_dreg(s
, rd
, tcg_rd
);
4240 tcg_temp_free_i64(tcg_rd
);
4242 /* Single to half */
4243 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4244 gen_helper_vfp_fcvt_f32_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4245 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4246 write_fp_sreg(s
, rd
, tcg_rd
);
4247 tcg_temp_free_i32(tcg_rd
);
4249 tcg_temp_free_i32(tcg_rn
);
4254 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
4255 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4257 /* Double to single */
4258 gen_helper_vfp_fcvtsd(tcg_rd
, tcg_rn
, cpu_env
);
4260 /* Double to half */
4261 gen_helper_vfp_fcvt_f64_to_f16(tcg_rd
, tcg_rn
, cpu_env
);
4262 /* write_fp_sreg is OK here because top half of tcg_rd is zero */
4264 write_fp_sreg(s
, rd
, tcg_rd
);
4265 tcg_temp_free_i32(tcg_rd
);
4266 tcg_temp_free_i64(tcg_rn
);
4271 TCGv_i32 tcg_rn
= read_fp_sreg(s
, rn
);
4272 tcg_gen_ext16u_i32(tcg_rn
, tcg_rn
);
4274 /* Half to single */
4275 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
4276 gen_helper_vfp_fcvt_f16_to_f32(tcg_rd
, tcg_rn
, cpu_env
);
4277 write_fp_sreg(s
, rd
, tcg_rd
);
4278 tcg_temp_free_i32(tcg_rd
);
4280 /* Half to double */
4281 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
4282 gen_helper_vfp_fcvt_f16_to_f64(tcg_rd
, tcg_rn
, cpu_env
);
4283 write_fp_dreg(s
, rd
, tcg_rd
);
4284 tcg_temp_free_i64(tcg_rd
);
4286 tcg_temp_free_i32(tcg_rn
);
4294 /* C3.6.25 Floating point data-processing (1 source)
4295 * 31 30 29 28 24 23 22 21 20 15 14 10 9 5 4 0
4296 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4297 * | M | 0 | S | 1 1 1 1 0 | type | 1 | opcode | 1 0 0 0 0 | Rn | Rd |
4298 * +---+---+---+-----------+------+---+--------+-----------+------+------+
4300 static void disas_fp_1src(DisasContext
*s
, uint32_t insn
)
4302 int type
= extract32(insn
, 22, 2);
4303 int opcode
= extract32(insn
, 15, 6);
4304 int rn
= extract32(insn
, 5, 5);
4305 int rd
= extract32(insn
, 0, 5);
4308 case 0x4: case 0x5: case 0x7:
4310 /* FCVT between half, single and double precision */
4311 int dtype
= extract32(opcode
, 0, 2);
4312 if (type
== 2 || dtype
== type
) {
4313 unallocated_encoding(s
);
4316 if (!fp_access_check(s
)) {
4320 handle_fp_fcvt(s
, opcode
, rd
, rn
, dtype
, type
);
4326 /* 32-to-32 and 64-to-64 ops */
4329 if (!fp_access_check(s
)) {
4333 handle_fp_1src_single(s
, opcode
, rd
, rn
);
4336 if (!fp_access_check(s
)) {
4340 handle_fp_1src_double(s
, opcode
, rd
, rn
);
4343 unallocated_encoding(s
);
4347 unallocated_encoding(s
);
4352 /* C3.6.26 Floating-point data-processing (2 source) - single precision */
4353 static void handle_fp_2src_single(DisasContext
*s
, int opcode
,
4354 int rd
, int rn
, int rm
)
4361 tcg_res
= tcg_temp_new_i32();
4362 fpst
= get_fpstatus_ptr();
4363 tcg_op1
= read_fp_sreg(s
, rn
);
4364 tcg_op2
= read_fp_sreg(s
, rm
);
4367 case 0x0: /* FMUL */
4368 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4370 case 0x1: /* FDIV */
4371 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4373 case 0x2: /* FADD */
4374 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4376 case 0x3: /* FSUB */
4377 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4379 case 0x4: /* FMAX */
4380 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4382 case 0x5: /* FMIN */
4383 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4385 case 0x6: /* FMAXNM */
4386 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4388 case 0x7: /* FMINNM */
4389 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4391 case 0x8: /* FNMUL */
4392 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4393 gen_helper_vfp_negs(tcg_res
, tcg_res
);
4397 write_fp_sreg(s
, rd
, tcg_res
);
4399 tcg_temp_free_ptr(fpst
);
4400 tcg_temp_free_i32(tcg_op1
);
4401 tcg_temp_free_i32(tcg_op2
);
4402 tcg_temp_free_i32(tcg_res
);
4405 /* C3.6.26 Floating-point data-processing (2 source) - double precision */
4406 static void handle_fp_2src_double(DisasContext
*s
, int opcode
,
4407 int rd
, int rn
, int rm
)
4414 tcg_res
= tcg_temp_new_i64();
4415 fpst
= get_fpstatus_ptr();
4416 tcg_op1
= read_fp_dreg(s
, rn
);
4417 tcg_op2
= read_fp_dreg(s
, rm
);
4420 case 0x0: /* FMUL */
4421 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4423 case 0x1: /* FDIV */
4424 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4426 case 0x2: /* FADD */
4427 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4429 case 0x3: /* FSUB */
4430 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4432 case 0x4: /* FMAX */
4433 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4435 case 0x5: /* FMIN */
4436 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4438 case 0x6: /* FMAXNM */
4439 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4441 case 0x7: /* FMINNM */
4442 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4444 case 0x8: /* FNMUL */
4445 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
4446 gen_helper_vfp_negd(tcg_res
, tcg_res
);
4450 write_fp_dreg(s
, rd
, tcg_res
);
4452 tcg_temp_free_ptr(fpst
);
4453 tcg_temp_free_i64(tcg_op1
);
4454 tcg_temp_free_i64(tcg_op2
);
4455 tcg_temp_free_i64(tcg_res
);
4458 /* C3.6.26 Floating point data-processing (2 source)
4459 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
4460 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4461 * | M | 0 | S | 1 1 1 1 0 | type | 1 | Rm | opcode | 1 0 | Rn | Rd |
4462 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
4464 static void disas_fp_2src(DisasContext
*s
, uint32_t insn
)
4466 int type
= extract32(insn
, 22, 2);
4467 int rd
= extract32(insn
, 0, 5);
4468 int rn
= extract32(insn
, 5, 5);
4469 int rm
= extract32(insn
, 16, 5);
4470 int opcode
= extract32(insn
, 12, 4);
4473 unallocated_encoding(s
);
4479 if (!fp_access_check(s
)) {
4482 handle_fp_2src_single(s
, opcode
, rd
, rn
, rm
);
4485 if (!fp_access_check(s
)) {
4488 handle_fp_2src_double(s
, opcode
, rd
, rn
, rm
);
4491 unallocated_encoding(s
);
4495 /* C3.6.27 Floating-point data-processing (3 source) - single precision */
4496 static void handle_fp_3src_single(DisasContext
*s
, bool o0
, bool o1
,
4497 int rd
, int rn
, int rm
, int ra
)
4499 TCGv_i32 tcg_op1
, tcg_op2
, tcg_op3
;
4500 TCGv_i32 tcg_res
= tcg_temp_new_i32();
4501 TCGv_ptr fpst
= get_fpstatus_ptr();
4503 tcg_op1
= read_fp_sreg(s
, rn
);
4504 tcg_op2
= read_fp_sreg(s
, rm
);
4505 tcg_op3
= read_fp_sreg(s
, ra
);
4507 /* These are fused multiply-add, and must be done as one
4508 * floating point operation with no rounding between the
4509 * multiplication and addition steps.
4510 * NB that doing the negations here as separate steps is
4511 * correct : an input NaN should come out with its sign bit
4512 * flipped if it is a negated-input.
4515 gen_helper_vfp_negs(tcg_op3
, tcg_op3
);
4519 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
4522 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4524 write_fp_sreg(s
, rd
, tcg_res
);
4526 tcg_temp_free_ptr(fpst
);
4527 tcg_temp_free_i32(tcg_op1
);
4528 tcg_temp_free_i32(tcg_op2
);
4529 tcg_temp_free_i32(tcg_op3
);
4530 tcg_temp_free_i32(tcg_res
);
4533 /* C3.6.27 Floating-point data-processing (3 source) - double precision */
4534 static void handle_fp_3src_double(DisasContext
*s
, bool o0
, bool o1
,
4535 int rd
, int rn
, int rm
, int ra
)
4537 TCGv_i64 tcg_op1
, tcg_op2
, tcg_op3
;
4538 TCGv_i64 tcg_res
= tcg_temp_new_i64();
4539 TCGv_ptr fpst
= get_fpstatus_ptr();
4541 tcg_op1
= read_fp_dreg(s
, rn
);
4542 tcg_op2
= read_fp_dreg(s
, rm
);
4543 tcg_op3
= read_fp_dreg(s
, ra
);
4545 /* These are fused multiply-add, and must be done as one
4546 * floating point operation with no rounding between the
4547 * multiplication and addition steps.
4548 * NB that doing the negations here as separate steps is
4549 * correct : an input NaN should come out with its sign bit
4550 * flipped if it is a negated-input.
4553 gen_helper_vfp_negd(tcg_op3
, tcg_op3
);
4557 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
4560 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
, tcg_op3
, fpst
);
4562 write_fp_dreg(s
, rd
, tcg_res
);
4564 tcg_temp_free_ptr(fpst
);
4565 tcg_temp_free_i64(tcg_op1
);
4566 tcg_temp_free_i64(tcg_op2
);
4567 tcg_temp_free_i64(tcg_op3
);
4568 tcg_temp_free_i64(tcg_res
);
4571 /* C3.6.27 Floating point data-processing (3 source)
4572 * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0
4573 * +---+---+---+-----------+------+----+------+----+------+------+------+
4574 * | M | 0 | S | 1 1 1 1 1 | type | o1 | Rm | o0 | Ra | Rn | Rd |
4575 * +---+---+---+-----------+------+----+------+----+------+------+------+
4577 static void disas_fp_3src(DisasContext
*s
, uint32_t insn
)
4579 int type
= extract32(insn
, 22, 2);
4580 int rd
= extract32(insn
, 0, 5);
4581 int rn
= extract32(insn
, 5, 5);
4582 int ra
= extract32(insn
, 10, 5);
4583 int rm
= extract32(insn
, 16, 5);
4584 bool o0
= extract32(insn
, 15, 1);
4585 bool o1
= extract32(insn
, 21, 1);
4589 if (!fp_access_check(s
)) {
4592 handle_fp_3src_single(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4595 if (!fp_access_check(s
)) {
4598 handle_fp_3src_double(s
, o0
, o1
, rd
, rn
, rm
, ra
);
4601 unallocated_encoding(s
);
4605 /* C3.6.28 Floating point immediate
4606 * 31 30 29 28 24 23 22 21 20 13 12 10 9 5 4 0
4607 * +---+---+---+-----------+------+---+------------+-------+------+------+
4608 * | M | 0 | S | 1 1 1 1 0 | type | 1 | imm8 | 1 0 0 | imm5 | Rd |
4609 * +---+---+---+-----------+------+---+------------+-------+------+------+
4611 static void disas_fp_imm(DisasContext
*s
, uint32_t insn
)
4613 int rd
= extract32(insn
, 0, 5);
4614 int imm8
= extract32(insn
, 13, 8);
4615 int is_double
= extract32(insn
, 22, 2);
4619 if (is_double
> 1) {
4620 unallocated_encoding(s
);
4624 if (!fp_access_check(s
)) {
4628 /* The imm8 encodes the sign bit, enough bits to represent
4629 * an exponent in the range 01....1xx to 10....0xx,
4630 * and the most significant 4 bits of the mantissa; see
4631 * VFPExpandImm() in the v8 ARM ARM.
4634 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4635 (extract32(imm8
, 6, 1) ? 0x3fc0 : 0x4000) |
4636 extract32(imm8
, 0, 6);
4639 imm
= (extract32(imm8
, 7, 1) ? 0x8000 : 0) |
4640 (extract32(imm8
, 6, 1) ? 0x3e00 : 0x4000) |
4641 (extract32(imm8
, 0, 6) << 3);
4645 tcg_res
= tcg_const_i64(imm
);
4646 write_fp_dreg(s
, rd
, tcg_res
);
4647 tcg_temp_free_i64(tcg_res
);
4650 /* Handle floating point <=> fixed point conversions. Note that we can
4651 * also deal with fp <=> integer conversions as a special case (scale == 64)
4652 * OPTME: consider handling that special case specially or at least skipping
4653 * the call to scalbn in the helpers for zero shifts.
4655 static void handle_fpfpcvt(DisasContext
*s
, int rd
, int rn
, int opcode
,
4656 bool itof
, int rmode
, int scale
, int sf
, int type
)
4658 bool is_signed
= !(opcode
& 1);
4659 bool is_double
= type
;
4660 TCGv_ptr tcg_fpstatus
;
4663 tcg_fpstatus
= get_fpstatus_ptr();
4665 tcg_shift
= tcg_const_i32(64 - scale
);
4668 TCGv_i64 tcg_int
= cpu_reg(s
, rn
);
4670 TCGv_i64 tcg_extend
= new_tmp_a64(s
);
4673 tcg_gen_ext32s_i64(tcg_extend
, tcg_int
);
4675 tcg_gen_ext32u_i64(tcg_extend
, tcg_int
);
4678 tcg_int
= tcg_extend
;
4682 TCGv_i64 tcg_double
= tcg_temp_new_i64();
4684 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
4685 tcg_shift
, tcg_fpstatus
);
4687 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
4688 tcg_shift
, tcg_fpstatus
);
4690 write_fp_dreg(s
, rd
, tcg_double
);
4691 tcg_temp_free_i64(tcg_double
);
4693 TCGv_i32 tcg_single
= tcg_temp_new_i32();
4695 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
4696 tcg_shift
, tcg_fpstatus
);
4698 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
4699 tcg_shift
, tcg_fpstatus
);
4701 write_fp_sreg(s
, rd
, tcg_single
);
4702 tcg_temp_free_i32(tcg_single
);
4705 TCGv_i64 tcg_int
= cpu_reg(s
, rd
);
4708 if (extract32(opcode
, 2, 1)) {
4709 /* There are too many rounding modes to all fit into rmode,
4710 * so FCVTA[US] is a special case.
4712 rmode
= FPROUNDING_TIEAWAY
;
4715 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
4717 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4720 TCGv_i64 tcg_double
= read_fp_dreg(s
, rn
);
4723 gen_helper_vfp_tosld(tcg_int
, tcg_double
,
4724 tcg_shift
, tcg_fpstatus
);
4726 gen_helper_vfp_tosqd(tcg_int
, tcg_double
,
4727 tcg_shift
, tcg_fpstatus
);
4731 gen_helper_vfp_tould(tcg_int
, tcg_double
,
4732 tcg_shift
, tcg_fpstatus
);
4734 gen_helper_vfp_touqd(tcg_int
, tcg_double
,
4735 tcg_shift
, tcg_fpstatus
);
4738 tcg_temp_free_i64(tcg_double
);
4740 TCGv_i32 tcg_single
= read_fp_sreg(s
, rn
);
4743 gen_helper_vfp_tosqs(tcg_int
, tcg_single
,
4744 tcg_shift
, tcg_fpstatus
);
4746 gen_helper_vfp_touqs(tcg_int
, tcg_single
,
4747 tcg_shift
, tcg_fpstatus
);
4750 TCGv_i32 tcg_dest
= tcg_temp_new_i32();
4752 gen_helper_vfp_tosls(tcg_dest
, tcg_single
,
4753 tcg_shift
, tcg_fpstatus
);
4755 gen_helper_vfp_touls(tcg_dest
, tcg_single
,
4756 tcg_shift
, tcg_fpstatus
);
4758 tcg_gen_extu_i32_i64(tcg_int
, tcg_dest
);
4759 tcg_temp_free_i32(tcg_dest
);
4761 tcg_temp_free_i32(tcg_single
);
4764 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
4765 tcg_temp_free_i32(tcg_rmode
);
4768 tcg_gen_ext32u_i64(tcg_int
, tcg_int
);
4772 tcg_temp_free_ptr(tcg_fpstatus
);
4773 tcg_temp_free_i32(tcg_shift
);
4776 /* C3.6.29 Floating point <-> fixed point conversions
4777 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4778 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4779 * | sf | 0 | S | 1 1 1 1 0 | type | 0 | rmode | opcode | scale | Rn | Rd |
4780 * +----+---+---+-----------+------+---+-------+--------+-------+------+------+
4782 static void disas_fp_fixed_conv(DisasContext
*s
, uint32_t insn
)
4784 int rd
= extract32(insn
, 0, 5);
4785 int rn
= extract32(insn
, 5, 5);
4786 int scale
= extract32(insn
, 10, 6);
4787 int opcode
= extract32(insn
, 16, 3);
4788 int rmode
= extract32(insn
, 19, 2);
4789 int type
= extract32(insn
, 22, 2);
4790 bool sbit
= extract32(insn
, 29, 1);
4791 bool sf
= extract32(insn
, 31, 1);
4794 if (sbit
|| (type
> 1)
4795 || (!sf
&& scale
< 32)) {
4796 unallocated_encoding(s
);
4800 switch ((rmode
<< 3) | opcode
) {
4801 case 0x2: /* SCVTF */
4802 case 0x3: /* UCVTF */
4805 case 0x18: /* FCVTZS */
4806 case 0x19: /* FCVTZU */
4810 unallocated_encoding(s
);
4814 if (!fp_access_check(s
)) {
4818 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, FPROUNDING_ZERO
, scale
, sf
, type
);
4821 static void handle_fmov(DisasContext
*s
, int rd
, int rn
, int type
, bool itof
)
4823 /* FMOV: gpr to or from float, double, or top half of quad fp reg,
4824 * without conversion.
4828 TCGv_i64 tcg_rn
= cpu_reg(s
, rn
);
4834 TCGv_i64 tmp
= tcg_temp_new_i64();
4835 tcg_gen_ext32u_i64(tmp
, tcg_rn
);
4836 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
4837 tcg_gen_movi_i64(tmp
, 0);
4838 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4839 tcg_temp_free_i64(tmp
);
4845 TCGv_i64 tmp
= tcg_const_i64(0);
4846 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_offset(s
, rd
, MO_64
));
4847 tcg_gen_st_i64(tmp
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4848 tcg_temp_free_i64(tmp
);
4852 /* 64 bit to top half. */
4853 tcg_gen_st_i64(tcg_rn
, cpu_env
, fp_reg_hi_offset(s
, rd
));
4857 TCGv_i64 tcg_rd
= cpu_reg(s
, rd
);
4862 tcg_gen_ld32u_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_32
));
4866 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_offset(s
, rn
, MO_64
));
4869 /* 64 bits from top half */
4870 tcg_gen_ld_i64(tcg_rd
, cpu_env
, fp_reg_hi_offset(s
, rn
));
4876 /* C3.6.30 Floating point <-> integer conversions
4877 * 31 30 29 28 24 23 22 21 20 19 18 16 15 10 9 5 4 0
4878 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4879 * | sf | 0 | S | 1 1 1 1 0 | type | 1 | rmode | opc | 0 0 0 0 0 0 | Rn | Rd |
4880 * +----+---+---+-----------+------+---+-------+-----+-------------+----+----+
4882 static void disas_fp_int_conv(DisasContext
*s
, uint32_t insn
)
4884 int rd
= extract32(insn
, 0, 5);
4885 int rn
= extract32(insn
, 5, 5);
4886 int opcode
= extract32(insn
, 16, 3);
4887 int rmode
= extract32(insn
, 19, 2);
4888 int type
= extract32(insn
, 22, 2);
4889 bool sbit
= extract32(insn
, 29, 1);
4890 bool sf
= extract32(insn
, 31, 1);
4893 unallocated_encoding(s
);
4899 bool itof
= opcode
& 1;
4902 unallocated_encoding(s
);
4906 switch (sf
<< 3 | type
<< 1 | rmode
) {
4907 case 0x0: /* 32 bit */
4908 case 0xa: /* 64 bit */
4909 case 0xd: /* 64 bit to top half of quad */
4912 /* all other sf/type/rmode combinations are invalid */
4913 unallocated_encoding(s
);
4917 if (!fp_access_check(s
)) {
4920 handle_fmov(s
, rd
, rn
, type
, itof
);
4922 /* actual FP conversions */
4923 bool itof
= extract32(opcode
, 1, 1);
4925 if (type
> 1 || (rmode
!= 0 && opcode
> 1)) {
4926 unallocated_encoding(s
);
4930 if (!fp_access_check(s
)) {
4933 handle_fpfpcvt(s
, rd
, rn
, opcode
, itof
, rmode
, 64, sf
, type
);
4937 /* FP-specific subcases of table C3-6 (SIMD and FP data processing)
4938 * 31 30 29 28 25 24 0
4939 * +---+---+---+---------+-----------------------------+
4940 * | | 0 | | 1 1 1 1 | |
4941 * +---+---+---+---------+-----------------------------+
4943 static void disas_data_proc_fp(DisasContext
*s
, uint32_t insn
)
4945 if (extract32(insn
, 24, 1)) {
4946 /* Floating point data-processing (3 source) */
4947 disas_fp_3src(s
, insn
);
4948 } else if (extract32(insn
, 21, 1) == 0) {
4949 /* Floating point to fixed point conversions */
4950 disas_fp_fixed_conv(s
, insn
);
4952 switch (extract32(insn
, 10, 2)) {
4954 /* Floating point conditional compare */
4955 disas_fp_ccomp(s
, insn
);
4958 /* Floating point data-processing (2 source) */
4959 disas_fp_2src(s
, insn
);
4962 /* Floating point conditional select */
4963 disas_fp_csel(s
, insn
);
4966 switch (ctz32(extract32(insn
, 12, 4))) {
4967 case 0: /* [15:12] == xxx1 */
4968 /* Floating point immediate */
4969 disas_fp_imm(s
, insn
);
4971 case 1: /* [15:12] == xx10 */
4972 /* Floating point compare */
4973 disas_fp_compare(s
, insn
);
4975 case 2: /* [15:12] == x100 */
4976 /* Floating point data-processing (1 source) */
4977 disas_fp_1src(s
, insn
);
4979 case 3: /* [15:12] == 1000 */
4980 unallocated_encoding(s
);
4982 default: /* [15:12] == 0000 */
4983 /* Floating point <-> integer conversions */
4984 disas_fp_int_conv(s
, insn
);
4992 static void do_ext64(DisasContext
*s
, TCGv_i64 tcg_left
, TCGv_i64 tcg_right
,
4995 /* Extract 64 bits from the middle of two concatenated 64 bit
4996 * vector register slices left:right. The extracted bits start
4997 * at 'pos' bits into the right (least significant) side.
4998 * We return the result in tcg_right, and guarantee not to
5001 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
5002 assert(pos
> 0 && pos
< 64);
5004 tcg_gen_shri_i64(tcg_right
, tcg_right
, pos
);
5005 tcg_gen_shli_i64(tcg_tmp
, tcg_left
, 64 - pos
);
5006 tcg_gen_or_i64(tcg_right
, tcg_right
, tcg_tmp
);
5008 tcg_temp_free_i64(tcg_tmp
);
5012 * 31 30 29 24 23 22 21 20 16 15 14 11 10 9 5 4 0
5013 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5014 * | 0 | Q | 1 0 1 1 1 0 | op2 | 0 | Rm | 0 | imm4 | 0 | Rn | Rd |
5015 * +---+---+-------------+-----+---+------+---+------+---+------+------+
5017 static void disas_simd_ext(DisasContext
*s
, uint32_t insn
)
5019 int is_q
= extract32(insn
, 30, 1);
5020 int op2
= extract32(insn
, 22, 2);
5021 int imm4
= extract32(insn
, 11, 4);
5022 int rm
= extract32(insn
, 16, 5);
5023 int rn
= extract32(insn
, 5, 5);
5024 int rd
= extract32(insn
, 0, 5);
5025 int pos
= imm4
<< 3;
5026 TCGv_i64 tcg_resl
, tcg_resh
;
5028 if (op2
!= 0 || (!is_q
&& extract32(imm4
, 3, 1))) {
5029 unallocated_encoding(s
);
5033 if (!fp_access_check(s
)) {
5037 tcg_resh
= tcg_temp_new_i64();
5038 tcg_resl
= tcg_temp_new_i64();
5040 /* Vd gets bits starting at pos bits into Vm:Vn. This is
5041 * either extracting 128 bits from a 128:128 concatenation, or
5042 * extracting 64 bits from a 64:64 concatenation.
5045 read_vec_element(s
, tcg_resl
, rn
, 0, MO_64
);
5047 read_vec_element(s
, tcg_resh
, rm
, 0, MO_64
);
5048 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5050 tcg_gen_movi_i64(tcg_resh
, 0);
5057 EltPosns eltposns
[] = { {rn
, 0}, {rn
, 1}, {rm
, 0}, {rm
, 1} };
5058 EltPosns
*elt
= eltposns
;
5065 read_vec_element(s
, tcg_resl
, elt
->reg
, elt
->elt
, MO_64
);
5067 read_vec_element(s
, tcg_resh
, elt
->reg
, elt
->elt
, MO_64
);
5070 do_ext64(s
, tcg_resh
, tcg_resl
, pos
);
5071 tcg_hh
= tcg_temp_new_i64();
5072 read_vec_element(s
, tcg_hh
, elt
->reg
, elt
->elt
, MO_64
);
5073 do_ext64(s
, tcg_hh
, tcg_resh
, pos
);
5074 tcg_temp_free_i64(tcg_hh
);
5078 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5079 tcg_temp_free_i64(tcg_resl
);
5080 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5081 tcg_temp_free_i64(tcg_resh
);
5085 * 31 30 29 24 23 22 21 20 16 15 14 13 12 11 10 9 5 4 0
5086 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5087 * | 0 | Q | 0 0 1 1 1 0 | op2 | 0 | Rm | 0 | len | op | 0 0 | Rn | Rd |
5088 * +---+---+-------------+-----+---+------+---+-----+----+-----+------+------+
5090 static void disas_simd_tb(DisasContext
*s
, uint32_t insn
)
5092 int op2
= extract32(insn
, 22, 2);
5093 int is_q
= extract32(insn
, 30, 1);
5094 int rm
= extract32(insn
, 16, 5);
5095 int rn
= extract32(insn
, 5, 5);
5096 int rd
= extract32(insn
, 0, 5);
5097 int is_tblx
= extract32(insn
, 12, 1);
5098 int len
= extract32(insn
, 13, 2);
5099 TCGv_i64 tcg_resl
, tcg_resh
, tcg_idx
;
5100 TCGv_i32 tcg_regno
, tcg_numregs
;
5103 unallocated_encoding(s
);
5107 if (!fp_access_check(s
)) {
5111 /* This does a table lookup: for every byte element in the input
5112 * we index into a table formed from up to four vector registers,
5113 * and then the output is the result of the lookups. Our helper
5114 * function does the lookup operation for a single 64 bit part of
5117 tcg_resl
= tcg_temp_new_i64();
5118 tcg_resh
= tcg_temp_new_i64();
5121 read_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5123 tcg_gen_movi_i64(tcg_resl
, 0);
5125 if (is_tblx
&& is_q
) {
5126 read_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5128 tcg_gen_movi_i64(tcg_resh
, 0);
5131 tcg_idx
= tcg_temp_new_i64();
5132 tcg_regno
= tcg_const_i32(rn
);
5133 tcg_numregs
= tcg_const_i32(len
+ 1);
5134 read_vec_element(s
, tcg_idx
, rm
, 0, MO_64
);
5135 gen_helper_simd_tbl(tcg_resl
, cpu_env
, tcg_resl
, tcg_idx
,
5136 tcg_regno
, tcg_numregs
);
5138 read_vec_element(s
, tcg_idx
, rm
, 1, MO_64
);
5139 gen_helper_simd_tbl(tcg_resh
, cpu_env
, tcg_resh
, tcg_idx
,
5140 tcg_regno
, tcg_numregs
);
5142 tcg_temp_free_i64(tcg_idx
);
5143 tcg_temp_free_i32(tcg_regno
);
5144 tcg_temp_free_i32(tcg_numregs
);
5146 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5147 tcg_temp_free_i64(tcg_resl
);
5148 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5149 tcg_temp_free_i64(tcg_resh
);
5152 /* C3.6.3 ZIP/UZP/TRN
5153 * 31 30 29 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
5154 * +---+---+-------------+------+---+------+---+------------------+------+
5155 * | 0 | Q | 0 0 1 1 1 0 | size | 0 | Rm | 0 | opc | 1 0 | Rn | Rd |
5156 * +---+---+-------------+------+---+------+---+------------------+------+
5158 static void disas_simd_zip_trn(DisasContext
*s
, uint32_t insn
)
5160 int rd
= extract32(insn
, 0, 5);
5161 int rn
= extract32(insn
, 5, 5);
5162 int rm
= extract32(insn
, 16, 5);
5163 int size
= extract32(insn
, 22, 2);
5164 /* opc field bits [1:0] indicate ZIP/UZP/TRN;
5165 * bit 2 indicates 1 vs 2 variant of the insn.
5167 int opcode
= extract32(insn
, 12, 2);
5168 bool part
= extract32(insn
, 14, 1);
5169 bool is_q
= extract32(insn
, 30, 1);
5170 int esize
= 8 << size
;
5172 int datasize
= is_q
? 128 : 64;
5173 int elements
= datasize
/ esize
;
5174 TCGv_i64 tcg_res
, tcg_resl
, tcg_resh
;
5176 if (opcode
== 0 || (size
== 3 && !is_q
)) {
5177 unallocated_encoding(s
);
5181 if (!fp_access_check(s
)) {
5185 tcg_resl
= tcg_const_i64(0);
5186 tcg_resh
= tcg_const_i64(0);
5187 tcg_res
= tcg_temp_new_i64();
5189 for (i
= 0; i
< elements
; i
++) {
5191 case 1: /* UZP1/2 */
5193 int midpoint
= elements
/ 2;
5195 read_vec_element(s
, tcg_res
, rn
, 2 * i
+ part
, size
);
5197 read_vec_element(s
, tcg_res
, rm
,
5198 2 * (i
- midpoint
) + part
, size
);
5202 case 2: /* TRN1/2 */
5204 read_vec_element(s
, tcg_res
, rm
, (i
& ~1) + part
, size
);
5206 read_vec_element(s
, tcg_res
, rn
, (i
& ~1) + part
, size
);
5209 case 3: /* ZIP1/2 */
5211 int base
= part
* elements
/ 2;
5213 read_vec_element(s
, tcg_res
, rm
, base
+ (i
>> 1), size
);
5215 read_vec_element(s
, tcg_res
, rn
, base
+ (i
>> 1), size
);
5220 g_assert_not_reached();
5225 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
);
5226 tcg_gen_or_i64(tcg_resl
, tcg_resl
, tcg_res
);
5228 tcg_gen_shli_i64(tcg_res
, tcg_res
, ofs
- 64);
5229 tcg_gen_or_i64(tcg_resh
, tcg_resh
, tcg_res
);
5233 tcg_temp_free_i64(tcg_res
);
5235 write_vec_element(s
, tcg_resl
, rd
, 0, MO_64
);
5236 tcg_temp_free_i64(tcg_resl
);
5237 write_vec_element(s
, tcg_resh
, rd
, 1, MO_64
);
5238 tcg_temp_free_i64(tcg_resh
);
5241 static void do_minmaxop(DisasContext
*s
, TCGv_i32 tcg_elt1
, TCGv_i32 tcg_elt2
,
5242 int opc
, bool is_min
, TCGv_ptr fpst
)
5244 /* Helper function for disas_simd_across_lanes: do a single precision
5245 * min/max operation on the specified two inputs,
5246 * and return the result in tcg_elt1.
5250 gen_helper_vfp_minnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5252 gen_helper_vfp_maxnums(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5257 gen_helper_vfp_mins(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5259 gen_helper_vfp_maxs(tcg_elt1
, tcg_elt1
, tcg_elt2
, fpst
);
5264 /* C3.6.4 AdvSIMD across lanes
5265 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5266 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5267 * | 0 | Q | U | 0 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5268 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
5270 static void disas_simd_across_lanes(DisasContext
*s
, uint32_t insn
)
5272 int rd
= extract32(insn
, 0, 5);
5273 int rn
= extract32(insn
, 5, 5);
5274 int size
= extract32(insn
, 22, 2);
5275 int opcode
= extract32(insn
, 12, 5);
5276 bool is_q
= extract32(insn
, 30, 1);
5277 bool is_u
= extract32(insn
, 29, 1);
5279 bool is_min
= false;
5283 TCGv_i64 tcg_res
, tcg_elt
;
5286 case 0x1b: /* ADDV */
5288 unallocated_encoding(s
);
5292 case 0x3: /* SADDLV, UADDLV */
5293 case 0xa: /* SMAXV, UMAXV */
5294 case 0x1a: /* SMINV, UMINV */
5295 if (size
== 3 || (size
== 2 && !is_q
)) {
5296 unallocated_encoding(s
);
5300 case 0xc: /* FMAXNMV, FMINNMV */
5301 case 0xf: /* FMAXV, FMINV */
5302 if (!is_u
|| !is_q
|| extract32(size
, 0, 1)) {
5303 unallocated_encoding(s
);
5306 /* Bit 1 of size field encodes min vs max, and actual size is always
5307 * 32 bits: adjust the size variable so following code can rely on it
5309 is_min
= extract32(size
, 1, 1);
5314 unallocated_encoding(s
);
5318 if (!fp_access_check(s
)) {
5323 elements
= (is_q
? 128 : 64) / esize
;
5325 tcg_res
= tcg_temp_new_i64();
5326 tcg_elt
= tcg_temp_new_i64();
5328 /* These instructions operate across all lanes of a vector
5329 * to produce a single result. We can guarantee that a 64
5330 * bit intermediate is sufficient:
5331 * + for [US]ADDLV the maximum element size is 32 bits, and
5332 * the result type is 64 bits
5333 * + for FMAX*V, FMIN*V, ADDV the intermediate type is the
5334 * same as the element size, which is 32 bits at most
5335 * For the integer operations we can choose to work at 64
5336 * or 32 bits and truncate at the end; for simplicity
5337 * we use 64 bits always. The floating point
5338 * ops do require 32 bit intermediates, though.
5341 read_vec_element(s
, tcg_res
, rn
, 0, size
| (is_u
? 0 : MO_SIGN
));
5343 for (i
= 1; i
< elements
; i
++) {
5344 read_vec_element(s
, tcg_elt
, rn
, i
, size
| (is_u
? 0 : MO_SIGN
));
5347 case 0x03: /* SADDLV / UADDLV */
5348 case 0x1b: /* ADDV */
5349 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_elt
);
5351 case 0x0a: /* SMAXV / UMAXV */
5352 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
5354 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5356 case 0x1a: /* SMINV / UMINV */
5357 tcg_gen_movcond_i64(is_u
? TCG_COND_LEU
: TCG_COND_LE
,
5359 tcg_res
, tcg_elt
, tcg_res
, tcg_elt
);
5363 g_assert_not_reached();
5368 /* Floating point ops which work on 32 bit (single) intermediates.
5369 * Note that correct NaN propagation requires that we do these
5370 * operations in exactly the order specified by the pseudocode.
5372 TCGv_i32 tcg_elt1
= tcg_temp_new_i32();
5373 TCGv_i32 tcg_elt2
= tcg_temp_new_i32();
5374 TCGv_i32 tcg_elt3
= tcg_temp_new_i32();
5375 TCGv_ptr fpst
= get_fpstatus_ptr();
5377 assert(esize
== 32);
5378 assert(elements
== 4);
5380 read_vec_element(s
, tcg_elt
, rn
, 0, MO_32
);
5381 tcg_gen_trunc_i64_i32(tcg_elt1
, tcg_elt
);
5382 read_vec_element(s
, tcg_elt
, rn
, 1, MO_32
);
5383 tcg_gen_trunc_i64_i32(tcg_elt2
, tcg_elt
);
5385 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5387 read_vec_element(s
, tcg_elt
, rn
, 2, MO_32
);
5388 tcg_gen_trunc_i64_i32(tcg_elt2
, tcg_elt
);
5389 read_vec_element(s
, tcg_elt
, rn
, 3, MO_32
);
5390 tcg_gen_trunc_i64_i32(tcg_elt3
, tcg_elt
);
5392 do_minmaxop(s
, tcg_elt2
, tcg_elt3
, opcode
, is_min
, fpst
);
5394 do_minmaxop(s
, tcg_elt1
, tcg_elt2
, opcode
, is_min
, fpst
);
5396 tcg_gen_extu_i32_i64(tcg_res
, tcg_elt1
);
5397 tcg_temp_free_i32(tcg_elt1
);
5398 tcg_temp_free_i32(tcg_elt2
);
5399 tcg_temp_free_i32(tcg_elt3
);
5400 tcg_temp_free_ptr(fpst
);
5403 tcg_temp_free_i64(tcg_elt
);
5405 /* Now truncate the result to the width required for the final output */
5406 if (opcode
== 0x03) {
5407 /* SADDLV, UADDLV: result is 2*esize */
5413 tcg_gen_ext8u_i64(tcg_res
, tcg_res
);
5416 tcg_gen_ext16u_i64(tcg_res
, tcg_res
);
5419 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
5424 g_assert_not_reached();
5427 write_fp_dreg(s
, rd
, tcg_res
);
5428 tcg_temp_free_i64(tcg_res
);
5431 /* C6.3.31 DUP (Element, Vector)
5433 * 31 30 29 21 20 16 15 10 9 5 4 0
5434 * +---+---+-------------------+--------+-------------+------+------+
5435 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5436 * +---+---+-------------------+--------+-------------+------+------+
5438 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5440 static void handle_simd_dupe(DisasContext
*s
, int is_q
, int rd
, int rn
,
5443 int size
= ctz32(imm5
);
5444 int esize
= 8 << size
;
5445 int elements
= (is_q
? 128 : 64) / esize
;
5449 if (size
> 3 || (size
== 3 && !is_q
)) {
5450 unallocated_encoding(s
);
5454 if (!fp_access_check(s
)) {
5458 index
= imm5
>> (size
+ 1);
5460 tmp
= tcg_temp_new_i64();
5461 read_vec_element(s
, tmp
, rn
, index
, size
);
5463 for (i
= 0; i
< elements
; i
++) {
5464 write_vec_element(s
, tmp
, rd
, i
, size
);
5468 clear_vec_high(s
, rd
);
5471 tcg_temp_free_i64(tmp
);
5474 /* C6.3.31 DUP (element, scalar)
5475 * 31 21 20 16 15 10 9 5 4 0
5476 * +-----------------------+--------+-------------+------+------+
5477 * | 0 1 0 1 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 0 1 | Rn | Rd |
5478 * +-----------------------+--------+-------------+------+------+
5480 static void handle_simd_dupes(DisasContext
*s
, int rd
, int rn
,
5483 int size
= ctz32(imm5
);
5488 unallocated_encoding(s
);
5492 if (!fp_access_check(s
)) {
5496 index
= imm5
>> (size
+ 1);
5498 /* This instruction just extracts the specified element and
5499 * zero-extends it into the bottom of the destination register.
5501 tmp
= tcg_temp_new_i64();
5502 read_vec_element(s
, tmp
, rn
, index
, size
);
5503 write_fp_dreg(s
, rd
, tmp
);
5504 tcg_temp_free_i64(tmp
);
5507 /* C6.3.32 DUP (General)
5509 * 31 30 29 21 20 16 15 10 9 5 4 0
5510 * +---+---+-------------------+--------+-------------+------+------+
5511 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 0 1 1 | Rn | Rd |
5512 * +---+---+-------------------+--------+-------------+------+------+
5514 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5516 static void handle_simd_dupg(DisasContext
*s
, int is_q
, int rd
, int rn
,
5519 int size
= ctz32(imm5
);
5520 int esize
= 8 << size
;
5521 int elements
= (is_q
? 128 : 64)/esize
;
5524 if (size
> 3 || ((size
== 3) && !is_q
)) {
5525 unallocated_encoding(s
);
5529 if (!fp_access_check(s
)) {
5533 for (i
= 0; i
< elements
; i
++) {
5534 write_vec_element(s
, cpu_reg(s
, rn
), rd
, i
, size
);
5537 clear_vec_high(s
, rd
);
5541 /* C6.3.150 INS (Element)
5543 * 31 21 20 16 15 14 11 10 9 5 4 0
5544 * +-----------------------+--------+------------+---+------+------+
5545 * | 0 1 1 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5546 * +-----------------------+--------+------------+---+------+------+
5548 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5549 * index: encoded in imm5<4:size+1>
5551 static void handle_simd_inse(DisasContext
*s
, int rd
, int rn
,
5554 int size
= ctz32(imm5
);
5555 int src_index
, dst_index
;
5559 unallocated_encoding(s
);
5563 if (!fp_access_check(s
)) {
5567 dst_index
= extract32(imm5
, 1+size
, 5);
5568 src_index
= extract32(imm4
, size
, 4);
5570 tmp
= tcg_temp_new_i64();
5572 read_vec_element(s
, tmp
, rn
, src_index
, size
);
5573 write_vec_element(s
, tmp
, rd
, dst_index
, size
);
5575 tcg_temp_free_i64(tmp
);
5579 /* C6.3.151 INS (General)
5581 * 31 21 20 16 15 10 9 5 4 0
5582 * +-----------------------+--------+-------------+------+------+
5583 * | 0 1 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 0 1 1 1 | Rn | Rd |
5584 * +-----------------------+--------+-------------+------+------+
5586 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5587 * index: encoded in imm5<4:size+1>
5589 static void handle_simd_insg(DisasContext
*s
, int rd
, int rn
, int imm5
)
5591 int size
= ctz32(imm5
);
5595 unallocated_encoding(s
);
5599 if (!fp_access_check(s
)) {
5603 idx
= extract32(imm5
, 1 + size
, 4 - size
);
5604 write_vec_element(s
, cpu_reg(s
, rn
), rd
, idx
, size
);
5608 * C6.3.321 UMOV (General)
5609 * C6.3.237 SMOV (General)
5611 * 31 30 29 21 20 16 15 12 10 9 5 4 0
5612 * +---+---+-------------------+--------+-------------+------+------+
5613 * | 0 | Q | 0 0 1 1 1 0 0 0 0 | imm5 | 0 0 1 U 1 1 | Rn | Rd |
5614 * +---+---+-------------------+--------+-------------+------+------+
5616 * U: unsigned when set
5617 * size: encoded in imm5 (see ARM ARM LowestSetBit())
5619 static void handle_simd_umov_smov(DisasContext
*s
, int is_q
, int is_signed
,
5620 int rn
, int rd
, int imm5
)
5622 int size
= ctz32(imm5
);
5626 /* Check for UnallocatedEncodings */
5628 if (size
> 2 || (size
== 2 && !is_q
)) {
5629 unallocated_encoding(s
);
5634 || (size
< 3 && is_q
)
5635 || (size
== 3 && !is_q
)) {
5636 unallocated_encoding(s
);
5641 if (!fp_access_check(s
)) {
5645 element
= extract32(imm5
, 1+size
, 4);
5647 tcg_rd
= cpu_reg(s
, rd
);
5648 read_vec_element(s
, tcg_rd
, rn
, element
, size
| (is_signed
? MO_SIGN
: 0));
5649 if (is_signed
&& !is_q
) {
5650 tcg_gen_ext32u_i64(tcg_rd
, tcg_rd
);
5654 /* C3.6.5 AdvSIMD copy
5655 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5656 * +---+---+----+-----------------+------+---+------+---+------+------+
5657 * | 0 | Q | op | 0 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5658 * +---+---+----+-----------------+------+---+------+---+------+------+
5660 static void disas_simd_copy(DisasContext
*s
, uint32_t insn
)
5662 int rd
= extract32(insn
, 0, 5);
5663 int rn
= extract32(insn
, 5, 5);
5664 int imm4
= extract32(insn
, 11, 4);
5665 int op
= extract32(insn
, 29, 1);
5666 int is_q
= extract32(insn
, 30, 1);
5667 int imm5
= extract32(insn
, 16, 5);
5672 handle_simd_inse(s
, rd
, rn
, imm4
, imm5
);
5674 unallocated_encoding(s
);
5679 /* DUP (element - vector) */
5680 handle_simd_dupe(s
, is_q
, rd
, rn
, imm5
);
5684 handle_simd_dupg(s
, is_q
, rd
, rn
, imm5
);
5689 handle_simd_insg(s
, rd
, rn
, imm5
);
5691 unallocated_encoding(s
);
5696 /* UMOV/SMOV (is_q indicates 32/64; imm4 indicates signedness) */
5697 handle_simd_umov_smov(s
, is_q
, (imm4
== 5), rn
, rd
, imm5
);
5700 unallocated_encoding(s
);
5706 /* C3.6.6 AdvSIMD modified immediate
5707 * 31 30 29 28 19 18 16 15 12 11 10 9 5 4 0
5708 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5709 * | 0 | Q | op | 0 1 1 1 1 0 0 0 0 0 | abc | cmode | o2 | 1 | defgh | Rd |
5710 * +---+---+----+---------------------+-----+-------+----+---+-------+------+
5712 * There are a number of operations that can be carried out here:
5713 * MOVI - move (shifted) imm into register
5714 * MVNI - move inverted (shifted) imm into register
5715 * ORR - bitwise OR of (shifted) imm with register
5716 * BIC - bitwise clear of (shifted) imm with register
5718 static void disas_simd_mod_imm(DisasContext
*s
, uint32_t insn
)
5720 int rd
= extract32(insn
, 0, 5);
5721 int cmode
= extract32(insn
, 12, 4);
5722 int cmode_3_1
= extract32(cmode
, 1, 3);
5723 int cmode_0
= extract32(cmode
, 0, 1);
5724 int o2
= extract32(insn
, 11, 1);
5725 uint64_t abcdefgh
= extract32(insn
, 5, 5) | (extract32(insn
, 16, 3) << 5);
5726 bool is_neg
= extract32(insn
, 29, 1);
5727 bool is_q
= extract32(insn
, 30, 1);
5729 TCGv_i64 tcg_rd
, tcg_imm
;
5732 if (o2
!= 0 || ((cmode
== 0xf) && is_neg
&& !is_q
)) {
5733 unallocated_encoding(s
);
5737 if (!fp_access_check(s
)) {
5741 /* See AdvSIMDExpandImm() in ARM ARM */
5742 switch (cmode_3_1
) {
5743 case 0: /* Replicate(Zeros(24):imm8, 2) */
5744 case 1: /* Replicate(Zeros(16):imm8:Zeros(8), 2) */
5745 case 2: /* Replicate(Zeros(8):imm8:Zeros(16), 2) */
5746 case 3: /* Replicate(imm8:Zeros(24), 2) */
5748 int shift
= cmode_3_1
* 8;
5749 imm
= bitfield_replicate(abcdefgh
<< shift
, 32);
5752 case 4: /* Replicate(Zeros(8):imm8, 4) */
5753 case 5: /* Replicate(imm8:Zeros(8), 4) */
5755 int shift
= (cmode_3_1
& 0x1) * 8;
5756 imm
= bitfield_replicate(abcdefgh
<< shift
, 16);
5761 /* Replicate(Zeros(8):imm8:Ones(16), 2) */
5762 imm
= (abcdefgh
<< 16) | 0xffff;
5764 /* Replicate(Zeros(16):imm8:Ones(8), 2) */
5765 imm
= (abcdefgh
<< 8) | 0xff;
5767 imm
= bitfield_replicate(imm
, 32);
5770 if (!cmode_0
&& !is_neg
) {
5771 imm
= bitfield_replicate(abcdefgh
, 8);
5772 } else if (!cmode_0
&& is_neg
) {
5775 for (i
= 0; i
< 8; i
++) {
5776 if ((abcdefgh
) & (1 << i
)) {
5777 imm
|= 0xffULL
<< (i
* 8);
5780 } else if (cmode_0
) {
5782 imm
= (abcdefgh
& 0x3f) << 48;
5783 if (abcdefgh
& 0x80) {
5784 imm
|= 0x8000000000000000ULL
;
5786 if (abcdefgh
& 0x40) {
5787 imm
|= 0x3fc0000000000000ULL
;
5789 imm
|= 0x4000000000000000ULL
;
5792 imm
= (abcdefgh
& 0x3f) << 19;
5793 if (abcdefgh
& 0x80) {
5796 if (abcdefgh
& 0x40) {
5807 if (cmode_3_1
!= 7 && is_neg
) {
5811 tcg_imm
= tcg_const_i64(imm
);
5812 tcg_rd
= new_tmp_a64(s
);
5814 for (i
= 0; i
< 2; i
++) {
5815 int foffs
= i
? fp_reg_hi_offset(s
, rd
) : fp_reg_offset(s
, rd
, MO_64
);
5817 if (i
== 1 && !is_q
) {
5818 /* non-quad ops clear high half of vector */
5819 tcg_gen_movi_i64(tcg_rd
, 0);
5820 } else if ((cmode
& 0x9) == 0x1 || (cmode
& 0xd) == 0x9) {
5821 tcg_gen_ld_i64(tcg_rd
, cpu_env
, foffs
);
5824 tcg_gen_and_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5827 tcg_gen_or_i64(tcg_rd
, tcg_rd
, tcg_imm
);
5831 tcg_gen_mov_i64(tcg_rd
, tcg_imm
);
5833 tcg_gen_st_i64(tcg_rd
, cpu_env
, foffs
);
5836 tcg_temp_free_i64(tcg_imm
);
5839 /* C3.6.7 AdvSIMD scalar copy
5840 * 31 30 29 28 21 20 16 15 14 11 10 9 5 4 0
5841 * +-----+----+-----------------+------+---+------+---+------+------+
5842 * | 0 1 | op | 1 1 1 1 0 0 0 0 | imm5 | 0 | imm4 | 1 | Rn | Rd |
5843 * +-----+----+-----------------+------+---+------+---+------+------+
5845 static void disas_simd_scalar_copy(DisasContext
*s
, uint32_t insn
)
5847 int rd
= extract32(insn
, 0, 5);
5848 int rn
= extract32(insn
, 5, 5);
5849 int imm4
= extract32(insn
, 11, 4);
5850 int imm5
= extract32(insn
, 16, 5);
5851 int op
= extract32(insn
, 29, 1);
5853 if (op
!= 0 || imm4
!= 0) {
5854 unallocated_encoding(s
);
5858 /* DUP (element, scalar) */
5859 handle_simd_dupes(s
, rd
, rn
, imm5
);
5862 /* C3.6.8 AdvSIMD scalar pairwise
5863 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
5864 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5865 * | 0 1 | U | 1 1 1 1 0 | size | 1 1 0 0 0 | opcode | 1 0 | Rn | Rd |
5866 * +-----+---+-----------+------+-----------+--------+-----+------+------+
5868 static void disas_simd_scalar_pairwise(DisasContext
*s
, uint32_t insn
)
5870 int u
= extract32(insn
, 29, 1);
5871 int size
= extract32(insn
, 22, 2);
5872 int opcode
= extract32(insn
, 12, 5);
5873 int rn
= extract32(insn
, 5, 5);
5874 int rd
= extract32(insn
, 0, 5);
5877 /* For some ops (the FP ones), size[1] is part of the encoding.
5878 * For ADDP strictly it is not but size[1] is always 1 for valid
5881 opcode
|= (extract32(size
, 1, 1) << 5);
5884 case 0x3b: /* ADDP */
5885 if (u
|| size
!= 3) {
5886 unallocated_encoding(s
);
5889 if (!fp_access_check(s
)) {
5893 TCGV_UNUSED_PTR(fpst
);
5895 case 0xc: /* FMAXNMP */
5896 case 0xd: /* FADDP */
5897 case 0xf: /* FMAXP */
5898 case 0x2c: /* FMINNMP */
5899 case 0x2f: /* FMINP */
5900 /* FP op, size[0] is 32 or 64 bit */
5902 unallocated_encoding(s
);
5905 if (!fp_access_check(s
)) {
5909 size
= extract32(size
, 0, 1) ? 3 : 2;
5910 fpst
= get_fpstatus_ptr();
5913 unallocated_encoding(s
);
5918 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
5919 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
5920 TCGv_i64 tcg_res
= tcg_temp_new_i64();
5922 read_vec_element(s
, tcg_op1
, rn
, 0, MO_64
);
5923 read_vec_element(s
, tcg_op2
, rn
, 1, MO_64
);
5926 case 0x3b: /* ADDP */
5927 tcg_gen_add_i64(tcg_res
, tcg_op1
, tcg_op2
);
5929 case 0xc: /* FMAXNMP */
5930 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5932 case 0xd: /* FADDP */
5933 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5935 case 0xf: /* FMAXP */
5936 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5938 case 0x2c: /* FMINNMP */
5939 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5941 case 0x2f: /* FMINP */
5942 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5945 g_assert_not_reached();
5948 write_fp_dreg(s
, rd
, tcg_res
);
5950 tcg_temp_free_i64(tcg_op1
);
5951 tcg_temp_free_i64(tcg_op2
);
5952 tcg_temp_free_i64(tcg_res
);
5954 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
5955 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
5956 TCGv_i32 tcg_res
= tcg_temp_new_i32();
5958 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_32
);
5959 read_vec_element_i32(s
, tcg_op2
, rn
, 1, MO_32
);
5962 case 0xc: /* FMAXNMP */
5963 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5965 case 0xd: /* FADDP */
5966 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5968 case 0xf: /* FMAXP */
5969 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5971 case 0x2c: /* FMINNMP */
5972 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5974 case 0x2f: /* FMINP */
5975 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
5978 g_assert_not_reached();
5981 write_fp_sreg(s
, rd
, tcg_res
);
5983 tcg_temp_free_i32(tcg_op1
);
5984 tcg_temp_free_i32(tcg_op2
);
5985 tcg_temp_free_i32(tcg_res
);
5988 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
5989 tcg_temp_free_ptr(fpst
);
5994 * Common SSHR[RA]/USHR[RA] - Shift right (optional rounding/accumulate)
5996 * This code is handles the common shifting code and is used by both
5997 * the vector and scalar code.
5999 static void handle_shri_with_rndacc(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6000 TCGv_i64 tcg_rnd
, bool accumulate
,
6001 bool is_u
, int size
, int shift
)
6003 bool extended_result
= false;
6004 bool round
= !TCGV_IS_UNUSED_I64(tcg_rnd
);
6006 TCGv_i64 tcg_src_hi
;
6008 if (round
&& size
== 3) {
6009 extended_result
= true;
6010 ext_lshift
= 64 - shift
;
6011 tcg_src_hi
= tcg_temp_new_i64();
6012 } else if (shift
== 64) {
6013 if (!accumulate
&& is_u
) {
6014 /* result is zero */
6015 tcg_gen_movi_i64(tcg_res
, 0);
6020 /* Deal with the rounding step */
6022 if (extended_result
) {
6023 TCGv_i64 tcg_zero
= tcg_const_i64(0);
6025 /* take care of sign extending tcg_res */
6026 tcg_gen_sari_i64(tcg_src_hi
, tcg_src
, 63);
6027 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6028 tcg_src
, tcg_src_hi
,
6031 tcg_gen_add2_i64(tcg_src
, tcg_src_hi
,
6035 tcg_temp_free_i64(tcg_zero
);
6037 tcg_gen_add_i64(tcg_src
, tcg_src
, tcg_rnd
);
6041 /* Now do the shift right */
6042 if (round
&& extended_result
) {
6043 /* extended case, >64 bit precision required */
6044 if (ext_lshift
== 0) {
6045 /* special case, only high bits matter */
6046 tcg_gen_mov_i64(tcg_src
, tcg_src_hi
);
6048 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6049 tcg_gen_shli_i64(tcg_src_hi
, tcg_src_hi
, ext_lshift
);
6050 tcg_gen_or_i64(tcg_src
, tcg_src
, tcg_src_hi
);
6055 /* essentially shifting in 64 zeros */
6056 tcg_gen_movi_i64(tcg_src
, 0);
6058 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6062 /* effectively extending the sign-bit */
6063 tcg_gen_sari_i64(tcg_src
, tcg_src
, 63);
6065 tcg_gen_sari_i64(tcg_src
, tcg_src
, shift
);
6071 tcg_gen_add_i64(tcg_res
, tcg_res
, tcg_src
);
6073 tcg_gen_mov_i64(tcg_res
, tcg_src
);
6076 if (extended_result
) {
6077 tcg_temp_free_i64(tcg_src_hi
);
6081 /* Common SHL/SLI - Shift left with an optional insert */
6082 static void handle_shli_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6083 bool insert
, int shift
)
6085 if (insert
) { /* SLI */
6086 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, shift
, 64 - shift
);
6088 tcg_gen_shli_i64(tcg_res
, tcg_src
, shift
);
6092 /* SRI: shift right with insert */
6093 static void handle_shri_with_ins(TCGv_i64 tcg_res
, TCGv_i64 tcg_src
,
6094 int size
, int shift
)
6096 int esize
= 8 << size
;
6098 /* shift count same as element size is valid but does nothing;
6099 * special case to avoid potential shift by 64.
6101 if (shift
!= esize
) {
6102 tcg_gen_shri_i64(tcg_src
, tcg_src
, shift
);
6103 tcg_gen_deposit_i64(tcg_res
, tcg_res
, tcg_src
, 0, esize
- shift
);
6107 /* SSHR[RA]/USHR[RA] - Scalar shift right (optional rounding/accumulate) */
6108 static void handle_scalar_simd_shri(DisasContext
*s
,
6109 bool is_u
, int immh
, int immb
,
6110 int opcode
, int rn
, int rd
)
6113 int immhb
= immh
<< 3 | immb
;
6114 int shift
= 2 * (8 << size
) - immhb
;
6115 bool accumulate
= false;
6117 bool insert
= false;
6122 if (!extract32(immh
, 3, 1)) {
6123 unallocated_encoding(s
);
6127 if (!fp_access_check(s
)) {
6132 case 0x02: /* SSRA / USRA (accumulate) */
6135 case 0x04: /* SRSHR / URSHR (rounding) */
6138 case 0x06: /* SRSRA / URSRA (accum + rounding) */
6139 accumulate
= round
= true;
6141 case 0x08: /* SRI */
6147 uint64_t round_const
= 1ULL << (shift
- 1);
6148 tcg_round
= tcg_const_i64(round_const
);
6150 TCGV_UNUSED_I64(tcg_round
);
6153 tcg_rn
= read_fp_dreg(s
, rn
);
6154 tcg_rd
= (accumulate
|| insert
) ? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6157 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
6159 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6160 accumulate
, is_u
, size
, shift
);
6163 write_fp_dreg(s
, rd
, tcg_rd
);
6165 tcg_temp_free_i64(tcg_rn
);
6166 tcg_temp_free_i64(tcg_rd
);
6168 tcg_temp_free_i64(tcg_round
);
6172 /* SHL/SLI - Scalar shift left */
6173 static void handle_scalar_simd_shli(DisasContext
*s
, bool insert
,
6174 int immh
, int immb
, int opcode
,
6177 int size
= 32 - clz32(immh
) - 1;
6178 int immhb
= immh
<< 3 | immb
;
6179 int shift
= immhb
- (8 << size
);
6180 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
6181 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
6183 if (!extract32(immh
, 3, 1)) {
6184 unallocated_encoding(s
);
6188 if (!fp_access_check(s
)) {
6192 tcg_rn
= read_fp_dreg(s
, rn
);
6193 tcg_rd
= insert
? read_fp_dreg(s
, rd
) : tcg_temp_new_i64();
6195 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
6197 write_fp_dreg(s
, rd
, tcg_rd
);
6199 tcg_temp_free_i64(tcg_rn
);
6200 tcg_temp_free_i64(tcg_rd
);
6203 /* SQSHRN/SQSHRUN - Saturating (signed/unsigned) shift right with
6204 * (signed/unsigned) narrowing */
6205 static void handle_vec_simd_sqshrn(DisasContext
*s
, bool is_scalar
, bool is_q
,
6206 bool is_u_shift
, bool is_u_narrow
,
6207 int immh
, int immb
, int opcode
,
6210 int immhb
= immh
<< 3 | immb
;
6211 int size
= 32 - clz32(immh
) - 1;
6212 int esize
= 8 << size
;
6213 int shift
= (2 * esize
) - immhb
;
6214 int elements
= is_scalar
? 1 : (64 / esize
);
6215 bool round
= extract32(opcode
, 0, 1);
6216 TCGMemOp ldop
= (size
+ 1) | (is_u_shift
? 0 : MO_SIGN
);
6217 TCGv_i64 tcg_rn
, tcg_rd
, tcg_round
;
6218 TCGv_i32 tcg_rd_narrowed
;
6221 static NeonGenNarrowEnvFn
* const signed_narrow_fns
[4][2] = {
6222 { gen_helper_neon_narrow_sat_s8
,
6223 gen_helper_neon_unarrow_sat8
},
6224 { gen_helper_neon_narrow_sat_s16
,
6225 gen_helper_neon_unarrow_sat16
},
6226 { gen_helper_neon_narrow_sat_s32
,
6227 gen_helper_neon_unarrow_sat32
},
6230 static NeonGenNarrowEnvFn
* const unsigned_narrow_fns
[4] = {
6231 gen_helper_neon_narrow_sat_u8
,
6232 gen_helper_neon_narrow_sat_u16
,
6233 gen_helper_neon_narrow_sat_u32
,
6236 NeonGenNarrowEnvFn
*narrowfn
;
6242 if (extract32(immh
, 3, 1)) {
6243 unallocated_encoding(s
);
6247 if (!fp_access_check(s
)) {
6252 narrowfn
= unsigned_narrow_fns
[size
];
6254 narrowfn
= signed_narrow_fns
[size
][is_u_narrow
? 1 : 0];
6257 tcg_rn
= tcg_temp_new_i64();
6258 tcg_rd
= tcg_temp_new_i64();
6259 tcg_rd_narrowed
= tcg_temp_new_i32();
6260 tcg_final
= tcg_const_i64(0);
6263 uint64_t round_const
= 1ULL << (shift
- 1);
6264 tcg_round
= tcg_const_i64(round_const
);
6266 TCGV_UNUSED_I64(tcg_round
);
6269 for (i
= 0; i
< elements
; i
++) {
6270 read_vec_element(s
, tcg_rn
, rn
, i
, ldop
);
6271 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
6272 false, is_u_shift
, size
+1, shift
);
6273 narrowfn(tcg_rd_narrowed
, cpu_env
, tcg_rd
);
6274 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd_narrowed
);
6275 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
6279 clear_vec_high(s
, rd
);
6280 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
6282 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
6286 tcg_temp_free_i64(tcg_round
);
6288 tcg_temp_free_i64(tcg_rn
);
6289 tcg_temp_free_i64(tcg_rd
);
6290 tcg_temp_free_i32(tcg_rd_narrowed
);
6291 tcg_temp_free_i64(tcg_final
);
6295 /* SQSHLU, UQSHL, SQSHL: saturating left shifts */
6296 static void handle_simd_qshl(DisasContext
*s
, bool scalar
, bool is_q
,
6297 bool src_unsigned
, bool dst_unsigned
,
6298 int immh
, int immb
, int rn
, int rd
)
6300 int immhb
= immh
<< 3 | immb
;
6301 int size
= 32 - clz32(immh
) - 1;
6302 int shift
= immhb
- (8 << size
);
6306 assert(!(scalar
&& is_q
));
6309 if (!is_q
&& extract32(immh
, 3, 1)) {
6310 unallocated_encoding(s
);
6314 /* Since we use the variable-shift helpers we must
6315 * replicate the shift count into each element of
6316 * the tcg_shift value.
6320 shift
|= shift
<< 8;
6323 shift
|= shift
<< 16;
6329 g_assert_not_reached();
6333 if (!fp_access_check(s
)) {
6338 TCGv_i64 tcg_shift
= tcg_const_i64(shift
);
6339 static NeonGenTwo64OpEnvFn
* const fns
[2][2] = {
6340 { gen_helper_neon_qshl_s64
, gen_helper_neon_qshlu_s64
},
6341 { NULL
, gen_helper_neon_qshl_u64
},
6343 NeonGenTwo64OpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
];
6344 int maxpass
= is_q
? 2 : 1;
6346 for (pass
= 0; pass
< maxpass
; pass
++) {
6347 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6349 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6350 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6351 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6353 tcg_temp_free_i64(tcg_op
);
6355 tcg_temp_free_i64(tcg_shift
);
6358 clear_vec_high(s
, rd
);
6361 TCGv_i32 tcg_shift
= tcg_const_i32(shift
);
6362 static NeonGenTwoOpEnvFn
* const fns
[2][2][3] = {
6364 { gen_helper_neon_qshl_s8
,
6365 gen_helper_neon_qshl_s16
,
6366 gen_helper_neon_qshl_s32
},
6367 { gen_helper_neon_qshlu_s8
,
6368 gen_helper_neon_qshlu_s16
,
6369 gen_helper_neon_qshlu_s32
}
6371 { NULL
, NULL
, NULL
},
6372 { gen_helper_neon_qshl_u8
,
6373 gen_helper_neon_qshl_u16
,
6374 gen_helper_neon_qshl_u32
}
6377 NeonGenTwoOpEnvFn
*genfn
= fns
[src_unsigned
][dst_unsigned
][size
];
6378 TCGMemOp memop
= scalar
? size
: MO_32
;
6379 int maxpass
= scalar
? 1 : is_q
? 4 : 2;
6381 for (pass
= 0; pass
< maxpass
; pass
++) {
6382 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6384 read_vec_element_i32(s
, tcg_op
, rn
, pass
, memop
);
6385 genfn(tcg_op
, cpu_env
, tcg_op
, tcg_shift
);
6389 tcg_gen_ext8u_i32(tcg_op
, tcg_op
);
6392 tcg_gen_ext16u_i32(tcg_op
, tcg_op
);
6397 g_assert_not_reached();
6399 write_fp_sreg(s
, rd
, tcg_op
);
6401 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6404 tcg_temp_free_i32(tcg_op
);
6406 tcg_temp_free_i32(tcg_shift
);
6408 if (!is_q
&& !scalar
) {
6409 clear_vec_high(s
, rd
);
6414 /* Common vector code for handling integer to FP conversion */
6415 static void handle_simd_intfp_conv(DisasContext
*s
, int rd
, int rn
,
6416 int elements
, int is_signed
,
6417 int fracbits
, int size
)
6419 bool is_double
= size
== 3 ? true : false;
6420 TCGv_ptr tcg_fpst
= get_fpstatus_ptr();
6421 TCGv_i32 tcg_shift
= tcg_const_i32(fracbits
);
6422 TCGv_i64 tcg_int
= tcg_temp_new_i64();
6423 TCGMemOp mop
= size
| (is_signed
? MO_SIGN
: 0);
6426 for (pass
= 0; pass
< elements
; pass
++) {
6427 read_vec_element(s
, tcg_int
, rn
, pass
, mop
);
6430 TCGv_i64 tcg_double
= tcg_temp_new_i64();
6432 gen_helper_vfp_sqtod(tcg_double
, tcg_int
,
6433 tcg_shift
, tcg_fpst
);
6435 gen_helper_vfp_uqtod(tcg_double
, tcg_int
,
6436 tcg_shift
, tcg_fpst
);
6438 if (elements
== 1) {
6439 write_fp_dreg(s
, rd
, tcg_double
);
6441 write_vec_element(s
, tcg_double
, rd
, pass
, MO_64
);
6443 tcg_temp_free_i64(tcg_double
);
6445 TCGv_i32 tcg_single
= tcg_temp_new_i32();
6447 gen_helper_vfp_sqtos(tcg_single
, tcg_int
,
6448 tcg_shift
, tcg_fpst
);
6450 gen_helper_vfp_uqtos(tcg_single
, tcg_int
,
6451 tcg_shift
, tcg_fpst
);
6453 if (elements
== 1) {
6454 write_fp_sreg(s
, rd
, tcg_single
);
6456 write_vec_element_i32(s
, tcg_single
, rd
, pass
, MO_32
);
6458 tcg_temp_free_i32(tcg_single
);
6462 if (!is_double
&& elements
== 2) {
6463 clear_vec_high(s
, rd
);
6466 tcg_temp_free_i64(tcg_int
);
6467 tcg_temp_free_ptr(tcg_fpst
);
6468 tcg_temp_free_i32(tcg_shift
);
6471 /* UCVTF/SCVTF - Integer to FP conversion */
6472 static void handle_simd_shift_intfp_conv(DisasContext
*s
, bool is_scalar
,
6473 bool is_q
, bool is_u
,
6474 int immh
, int immb
, int opcode
,
6477 bool is_double
= extract32(immh
, 3, 1);
6478 int size
= is_double
? MO_64
: MO_32
;
6480 int immhb
= immh
<< 3 | immb
;
6481 int fracbits
= (is_double
? 128 : 64) - immhb
;
6483 if (!extract32(immh
, 2, 2)) {
6484 unallocated_encoding(s
);
6491 elements
= is_double
? 2 : is_q
? 4 : 2;
6492 if (is_double
&& !is_q
) {
6493 unallocated_encoding(s
);
6498 if (!fp_access_check(s
)) {
6502 /* immh == 0 would be a failure of the decode logic */
6505 handle_simd_intfp_conv(s
, rd
, rn
, elements
, !is_u
, fracbits
, size
);
6508 /* FCVTZS, FVCVTZU - FP to fixedpoint conversion */
6509 static void handle_simd_shift_fpint_conv(DisasContext
*s
, bool is_scalar
,
6510 bool is_q
, bool is_u
,
6511 int immh
, int immb
, int rn
, int rd
)
6513 bool is_double
= extract32(immh
, 3, 1);
6514 int immhb
= immh
<< 3 | immb
;
6515 int fracbits
= (is_double
? 128 : 64) - immhb
;
6517 TCGv_ptr tcg_fpstatus
;
6518 TCGv_i32 tcg_rmode
, tcg_shift
;
6520 if (!extract32(immh
, 2, 2)) {
6521 unallocated_encoding(s
);
6525 if (!is_scalar
&& !is_q
&& is_double
) {
6526 unallocated_encoding(s
);
6530 if (!fp_access_check(s
)) {
6534 assert(!(is_scalar
&& is_q
));
6536 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(FPROUNDING_ZERO
));
6537 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6538 tcg_fpstatus
= get_fpstatus_ptr();
6539 tcg_shift
= tcg_const_i32(fracbits
);
6542 int maxpass
= is_scalar
? 1 : is_q
? 2 : 1;
6544 for (pass
= 0; pass
< maxpass
; pass
++) {
6545 TCGv_i64 tcg_op
= tcg_temp_new_i64();
6547 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
6549 gen_helper_vfp_touqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6551 gen_helper_vfp_tosqd(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6553 write_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
6554 tcg_temp_free_i64(tcg_op
);
6557 clear_vec_high(s
, rd
);
6560 int maxpass
= is_scalar
? 1 : is_q
? 4 : 2;
6561 for (pass
= 0; pass
< maxpass
; pass
++) {
6562 TCGv_i32 tcg_op
= tcg_temp_new_i32();
6564 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
6566 gen_helper_vfp_touls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6568 gen_helper_vfp_tosls(tcg_op
, tcg_op
, tcg_shift
, tcg_fpstatus
);
6571 write_fp_sreg(s
, rd
, tcg_op
);
6573 write_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
6575 tcg_temp_free_i32(tcg_op
);
6577 if (!is_q
&& !is_scalar
) {
6578 clear_vec_high(s
, rd
);
6582 tcg_temp_free_ptr(tcg_fpstatus
);
6583 tcg_temp_free_i32(tcg_shift
);
6584 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
6585 tcg_temp_free_i32(tcg_rmode
);
6588 /* C3.6.9 AdvSIMD scalar shift by immediate
6589 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
6590 * +-----+---+-------------+------+------+--------+---+------+------+
6591 * | 0 1 | U | 1 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
6592 * +-----+---+-------------+------+------+--------+---+------+------+
6594 * This is the scalar version so it works on a fixed sized registers
6596 static void disas_simd_scalar_shift_imm(DisasContext
*s
, uint32_t insn
)
6598 int rd
= extract32(insn
, 0, 5);
6599 int rn
= extract32(insn
, 5, 5);
6600 int opcode
= extract32(insn
, 11, 5);
6601 int immb
= extract32(insn
, 16, 3);
6602 int immh
= extract32(insn
, 19, 4);
6603 bool is_u
= extract32(insn
, 29, 1);
6606 unallocated_encoding(s
);
6611 case 0x08: /* SRI */
6613 unallocated_encoding(s
);
6617 case 0x00: /* SSHR / USHR */
6618 case 0x02: /* SSRA / USRA */
6619 case 0x04: /* SRSHR / URSHR */
6620 case 0x06: /* SRSRA / URSRA */
6621 handle_scalar_simd_shri(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6623 case 0x0a: /* SHL / SLI */
6624 handle_scalar_simd_shli(s
, is_u
, immh
, immb
, opcode
, rn
, rd
);
6626 case 0x1c: /* SCVTF, UCVTF */
6627 handle_simd_shift_intfp_conv(s
, true, false, is_u
, immh
, immb
,
6630 case 0x10: /* SQSHRUN, SQSHRUN2 */
6631 case 0x11: /* SQRSHRUN, SQRSHRUN2 */
6633 unallocated_encoding(s
);
6636 handle_vec_simd_sqshrn(s
, true, false, false, true,
6637 immh
, immb
, opcode
, rn
, rd
);
6639 case 0x12: /* SQSHRN, SQSHRN2, UQSHRN */
6640 case 0x13: /* SQRSHRN, SQRSHRN2, UQRSHRN, UQRSHRN2 */
6641 handle_vec_simd_sqshrn(s
, true, false, is_u
, is_u
,
6642 immh
, immb
, opcode
, rn
, rd
);
6644 case 0xc: /* SQSHLU */
6646 unallocated_encoding(s
);
6649 handle_simd_qshl(s
, true, false, false, true, immh
, immb
, rn
, rd
);
6651 case 0xe: /* SQSHL, UQSHL */
6652 handle_simd_qshl(s
, true, false, is_u
, is_u
, immh
, immb
, rn
, rd
);
6654 case 0x1f: /* FCVTZS, FCVTZU */
6655 handle_simd_shift_fpint_conv(s
, true, false, is_u
, immh
, immb
, rn
, rd
);
6658 unallocated_encoding(s
);
6663 /* C3.6.10 AdvSIMD scalar three different
6664 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
6665 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6666 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
6667 * +-----+---+-----------+------+---+------+--------+-----+------+------+
6669 static void disas_simd_scalar_three_reg_diff(DisasContext
*s
, uint32_t insn
)
6671 bool is_u
= extract32(insn
, 29, 1);
6672 int size
= extract32(insn
, 22, 2);
6673 int opcode
= extract32(insn
, 12, 4);
6674 int rm
= extract32(insn
, 16, 5);
6675 int rn
= extract32(insn
, 5, 5);
6676 int rd
= extract32(insn
, 0, 5);
6679 unallocated_encoding(s
);
6684 case 0x9: /* SQDMLAL, SQDMLAL2 */
6685 case 0xb: /* SQDMLSL, SQDMLSL2 */
6686 case 0xd: /* SQDMULL, SQDMULL2 */
6687 if (size
== 0 || size
== 3) {
6688 unallocated_encoding(s
);
6693 unallocated_encoding(s
);
6697 if (!fp_access_check(s
)) {
6702 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6703 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6704 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6706 read_vec_element(s
, tcg_op1
, rn
, 0, MO_32
| MO_SIGN
);
6707 read_vec_element(s
, tcg_op2
, rm
, 0, MO_32
| MO_SIGN
);
6709 tcg_gen_mul_i64(tcg_res
, tcg_op1
, tcg_op2
);
6710 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6713 case 0xd: /* SQDMULL, SQDMULL2 */
6715 case 0xb: /* SQDMLSL, SQDMLSL2 */
6716 tcg_gen_neg_i64(tcg_res
, tcg_res
);
6718 case 0x9: /* SQDMLAL, SQDMLAL2 */
6719 read_vec_element(s
, tcg_op1
, rd
, 0, MO_64
);
6720 gen_helper_neon_addl_saturate_s64(tcg_res
, cpu_env
,
6724 g_assert_not_reached();
6727 write_fp_dreg(s
, rd
, tcg_res
);
6729 tcg_temp_free_i64(tcg_op1
);
6730 tcg_temp_free_i64(tcg_op2
);
6731 tcg_temp_free_i64(tcg_res
);
6733 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6734 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6735 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6737 read_vec_element_i32(s
, tcg_op1
, rn
, 0, MO_16
);
6738 read_vec_element_i32(s
, tcg_op2
, rm
, 0, MO_16
);
6740 gen_helper_neon_mull_s16(tcg_res
, tcg_op1
, tcg_op2
);
6741 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
, tcg_res
, tcg_res
);
6744 case 0xd: /* SQDMULL, SQDMULL2 */
6746 case 0xb: /* SQDMLSL, SQDMLSL2 */
6747 gen_helper_neon_negl_u32(tcg_res
, tcg_res
);
6749 case 0x9: /* SQDMLAL, SQDMLAL2 */
6751 TCGv_i64 tcg_op3
= tcg_temp_new_i64();
6752 read_vec_element(s
, tcg_op3
, rd
, 0, MO_32
);
6753 gen_helper_neon_addl_saturate_s32(tcg_res
, cpu_env
,
6755 tcg_temp_free_i64(tcg_op3
);
6759 g_assert_not_reached();
6762 tcg_gen_ext32u_i64(tcg_res
, tcg_res
);
6763 write_fp_dreg(s
, rd
, tcg_res
);
6765 tcg_temp_free_i32(tcg_op1
);
6766 tcg_temp_free_i32(tcg_op2
);
6767 tcg_temp_free_i64(tcg_res
);
6771 static void handle_3same_64(DisasContext
*s
, int opcode
, bool u
,
6772 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
, TCGv_i64 tcg_rm
)
6774 /* Handle 64x64->64 opcodes which are shared between the scalar
6775 * and vector 3-same groups. We cover every opcode where size == 3
6776 * is valid in either the three-reg-same (integer, not pairwise)
6777 * or scalar-three-reg-same groups. (Some opcodes are not yet
6783 case 0x1: /* SQADD */
6785 gen_helper_neon_qadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6787 gen_helper_neon_qadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6790 case 0x5: /* SQSUB */
6792 gen_helper_neon_qsub_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6794 gen_helper_neon_qsub_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6797 case 0x6: /* CMGT, CMHI */
6798 /* 64 bit integer comparison, result = test ? (2^64 - 1) : 0.
6799 * We implement this using setcond (test) and then negating.
6801 cond
= u
? TCG_COND_GTU
: TCG_COND_GT
;
6803 tcg_gen_setcond_i64(cond
, tcg_rd
, tcg_rn
, tcg_rm
);
6804 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6806 case 0x7: /* CMGE, CMHS */
6807 cond
= u
? TCG_COND_GEU
: TCG_COND_GE
;
6809 case 0x11: /* CMTST, CMEQ */
6814 /* CMTST : test is "if (X & Y != 0)". */
6815 tcg_gen_and_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6816 tcg_gen_setcondi_i64(TCG_COND_NE
, tcg_rd
, tcg_rd
, 0);
6817 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
6819 case 0x8: /* SSHL, USHL */
6821 gen_helper_neon_shl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6823 gen_helper_neon_shl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
6826 case 0x9: /* SQSHL, UQSHL */
6828 gen_helper_neon_qshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6830 gen_helper_neon_qshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6833 case 0xa: /* SRSHL, URSHL */
6835 gen_helper_neon_rshl_u64(tcg_rd
, tcg_rn
, tcg_rm
);
6837 gen_helper_neon_rshl_s64(tcg_rd
, tcg_rn
, tcg_rm
);
6840 case 0xb: /* SQRSHL, UQRSHL */
6842 gen_helper_neon_qrshl_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6844 gen_helper_neon_qrshl_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rm
);
6847 case 0x10: /* ADD, SUB */
6849 tcg_gen_sub_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6851 tcg_gen_add_i64(tcg_rd
, tcg_rn
, tcg_rm
);
6855 g_assert_not_reached();
6859 /* Handle the 3-same-operands float operations; shared by the scalar
6860 * and vector encodings. The caller must filter out any encodings
6861 * not allocated for the encoding it is dealing with.
6863 static void handle_3same_float(DisasContext
*s
, int size
, int elements
,
6864 int fpopcode
, int rd
, int rn
, int rm
)
6867 TCGv_ptr fpst
= get_fpstatus_ptr();
6869 for (pass
= 0; pass
< elements
; pass
++) {
6872 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
6873 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
6874 TCGv_i64 tcg_res
= tcg_temp_new_i64();
6876 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
6877 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
6880 case 0x39: /* FMLS */
6881 /* As usual for ARM, separate negation for fused multiply-add */
6882 gen_helper_vfp_negd(tcg_op1
, tcg_op1
);
6884 case 0x19: /* FMLA */
6885 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
6886 gen_helper_vfp_muladdd(tcg_res
, tcg_op1
, tcg_op2
,
6889 case 0x18: /* FMAXNM */
6890 gen_helper_vfp_maxnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6892 case 0x1a: /* FADD */
6893 gen_helper_vfp_addd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6895 case 0x1b: /* FMULX */
6896 gen_helper_vfp_mulxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6898 case 0x1c: /* FCMEQ */
6899 gen_helper_neon_ceq_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6901 case 0x1e: /* FMAX */
6902 gen_helper_vfp_maxd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6904 case 0x1f: /* FRECPS */
6905 gen_helper_recpsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6907 case 0x38: /* FMINNM */
6908 gen_helper_vfp_minnumd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6910 case 0x3a: /* FSUB */
6911 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6913 case 0x3e: /* FMIN */
6914 gen_helper_vfp_mind(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6916 case 0x3f: /* FRSQRTS */
6917 gen_helper_rsqrtsf_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6919 case 0x5b: /* FMUL */
6920 gen_helper_vfp_muld(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6922 case 0x5c: /* FCMGE */
6923 gen_helper_neon_cge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6925 case 0x5d: /* FACGE */
6926 gen_helper_neon_acge_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6928 case 0x5f: /* FDIV */
6929 gen_helper_vfp_divd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6931 case 0x7a: /* FABD */
6932 gen_helper_vfp_subd(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6933 gen_helper_vfp_absd(tcg_res
, tcg_res
);
6935 case 0x7c: /* FCMGT */
6936 gen_helper_neon_cgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6938 case 0x7d: /* FACGT */
6939 gen_helper_neon_acgt_f64(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6942 g_assert_not_reached();
6945 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
6947 tcg_temp_free_i64(tcg_res
);
6948 tcg_temp_free_i64(tcg_op1
);
6949 tcg_temp_free_i64(tcg_op2
);
6952 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
6953 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
6954 TCGv_i32 tcg_res
= tcg_temp_new_i32();
6956 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
6957 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
6960 case 0x39: /* FMLS */
6961 /* As usual for ARM, separate negation for fused multiply-add */
6962 gen_helper_vfp_negs(tcg_op1
, tcg_op1
);
6964 case 0x19: /* FMLA */
6965 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
6966 gen_helper_vfp_muladds(tcg_res
, tcg_op1
, tcg_op2
,
6969 case 0x1a: /* FADD */
6970 gen_helper_vfp_adds(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6972 case 0x1b: /* FMULX */
6973 gen_helper_vfp_mulxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6975 case 0x1c: /* FCMEQ */
6976 gen_helper_neon_ceq_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6978 case 0x1e: /* FMAX */
6979 gen_helper_vfp_maxs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6981 case 0x1f: /* FRECPS */
6982 gen_helper_recpsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6984 case 0x18: /* FMAXNM */
6985 gen_helper_vfp_maxnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6987 case 0x38: /* FMINNM */
6988 gen_helper_vfp_minnums(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6990 case 0x3a: /* FSUB */
6991 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6993 case 0x3e: /* FMIN */
6994 gen_helper_vfp_mins(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6996 case 0x3f: /* FRSQRTS */
6997 gen_helper_rsqrtsf_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
6999 case 0x5b: /* FMUL */
7000 gen_helper_vfp_muls(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7002 case 0x5c: /* FCMGE */
7003 gen_helper_neon_cge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7005 case 0x5d: /* FACGE */
7006 gen_helper_neon_acge_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7008 case 0x5f: /* FDIV */
7009 gen_helper_vfp_divs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7011 case 0x7a: /* FABD */
7012 gen_helper_vfp_subs(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7013 gen_helper_vfp_abss(tcg_res
, tcg_res
);
7015 case 0x7c: /* FCMGT */
7016 gen_helper_neon_cgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7018 case 0x7d: /* FACGT */
7019 gen_helper_neon_acgt_f32(tcg_res
, tcg_op1
, tcg_op2
, fpst
);
7022 g_assert_not_reached();
7025 if (elements
== 1) {
7026 /* scalar single so clear high part */
7027 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
7029 tcg_gen_extu_i32_i64(tcg_tmp
, tcg_res
);
7030 write_vec_element(s
, tcg_tmp
, rd
, pass
, MO_64
);
7031 tcg_temp_free_i64(tcg_tmp
);
7033 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7036 tcg_temp_free_i32(tcg_res
);
7037 tcg_temp_free_i32(tcg_op1
);
7038 tcg_temp_free_i32(tcg_op2
);
7042 tcg_temp_free_ptr(fpst
);
7044 if ((elements
<< size
) < 4) {
7045 /* scalar, or non-quad vector op */
7046 clear_vec_high(s
, rd
);
7050 /* C3.6.11 AdvSIMD scalar three same
7051 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
7052 * +-----+---+-----------+------+---+------+--------+---+------+------+
7053 * | 0 1 | U | 1 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
7054 * +-----+---+-----------+------+---+------+--------+---+------+------+
7056 static void disas_simd_scalar_three_reg_same(DisasContext
*s
, uint32_t insn
)
7058 int rd
= extract32(insn
, 0, 5);
7059 int rn
= extract32(insn
, 5, 5);
7060 int opcode
= extract32(insn
, 11, 5);
7061 int rm
= extract32(insn
, 16, 5);
7062 int size
= extract32(insn
, 22, 2);
7063 bool u
= extract32(insn
, 29, 1);
7066 if (opcode
>= 0x18) {
7067 /* Floating point: U, size[1] and opcode indicate operation */
7068 int fpopcode
= opcode
| (extract32(size
, 1, 1) << 5) | (u
<< 6);
7070 case 0x1b: /* FMULX */
7071 case 0x1f: /* FRECPS */
7072 case 0x3f: /* FRSQRTS */
7073 case 0x5d: /* FACGE */
7074 case 0x7d: /* FACGT */
7075 case 0x1c: /* FCMEQ */
7076 case 0x5c: /* FCMGE */
7077 case 0x7c: /* FCMGT */
7078 case 0x7a: /* FABD */
7081 unallocated_encoding(s
);
7085 if (!fp_access_check(s
)) {
7089 handle_3same_float(s
, extract32(size
, 0, 1), 1, fpopcode
, rd
, rn
, rm
);
7094 case 0x1: /* SQADD, UQADD */
7095 case 0x5: /* SQSUB, UQSUB */
7096 case 0x9: /* SQSHL, UQSHL */
7097 case 0xb: /* SQRSHL, UQRSHL */
7099 case 0x8: /* SSHL, USHL */
7100 case 0xa: /* SRSHL, URSHL */
7101 case 0x6: /* CMGT, CMHI */
7102 case 0x7: /* CMGE, CMHS */
7103 case 0x11: /* CMTST, CMEQ */
7104 case 0x10: /* ADD, SUB (vector) */
7106 unallocated_encoding(s
);
7110 case 0x16: /* SQDMULH, SQRDMULH (vector) */
7111 if (size
!= 1 && size
!= 2) {
7112 unallocated_encoding(s
);
7117 unallocated_encoding(s
);
7121 if (!fp_access_check(s
)) {
7125 tcg_rd
= tcg_temp_new_i64();
7128 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7129 TCGv_i64 tcg_rm
= read_fp_dreg(s
, rm
);
7131 handle_3same_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rm
);
7132 tcg_temp_free_i64(tcg_rn
);
7133 tcg_temp_free_i64(tcg_rm
);
7135 /* Do a single operation on the lowest element in the vector.
7136 * We use the standard Neon helpers and rely on 0 OP 0 == 0 with
7137 * no side effects for all these operations.
7138 * OPTME: special-purpose helpers would avoid doing some
7139 * unnecessary work in the helper for the 8 and 16 bit cases.
7141 NeonGenTwoOpEnvFn
*genenvfn
;
7142 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7143 TCGv_i32 tcg_rm
= tcg_temp_new_i32();
7144 TCGv_i32 tcg_rd32
= tcg_temp_new_i32();
7146 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7147 read_vec_element_i32(s
, tcg_rm
, rm
, 0, size
);
7150 case 0x1: /* SQADD, UQADD */
7152 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7153 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
7154 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
7155 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
7157 genenvfn
= fns
[size
][u
];
7160 case 0x5: /* SQSUB, UQSUB */
7162 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7163 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
7164 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
7165 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
7167 genenvfn
= fns
[size
][u
];
7170 case 0x9: /* SQSHL, UQSHL */
7172 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7173 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
7174 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
7175 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
7177 genenvfn
= fns
[size
][u
];
7180 case 0xb: /* SQRSHL, UQRSHL */
7182 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
7183 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
7184 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
7185 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
7187 genenvfn
= fns
[size
][u
];
7190 case 0x16: /* SQDMULH, SQRDMULH */
7192 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
7193 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
7194 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
7196 assert(size
== 1 || size
== 2);
7197 genenvfn
= fns
[size
- 1][u
];
7201 g_assert_not_reached();
7204 genenvfn(tcg_rd32
, cpu_env
, tcg_rn
, tcg_rm
);
7205 tcg_gen_extu_i32_i64(tcg_rd
, tcg_rd32
);
7206 tcg_temp_free_i32(tcg_rd32
);
7207 tcg_temp_free_i32(tcg_rn
);
7208 tcg_temp_free_i32(tcg_rm
);
7211 write_fp_dreg(s
, rd
, tcg_rd
);
7213 tcg_temp_free_i64(tcg_rd
);
7216 static void handle_2misc_64(DisasContext
*s
, int opcode
, bool u
,
7217 TCGv_i64 tcg_rd
, TCGv_i64 tcg_rn
,
7218 TCGv_i32 tcg_rmode
, TCGv_ptr tcg_fpstatus
)
7220 /* Handle 64->64 opcodes which are shared between the scalar and
7221 * vector 2-reg-misc groups. We cover every integer opcode where size == 3
7222 * is valid in either group and also the double-precision fp ops.
7223 * The caller only need provide tcg_rmode and tcg_fpstatus if the op
7229 case 0x4: /* CLS, CLZ */
7231 gen_helper_clz64(tcg_rd
, tcg_rn
);
7233 gen_helper_cls64(tcg_rd
, tcg_rn
);
7237 /* This opcode is shared with CNT and RBIT but we have earlier
7238 * enforced that size == 3 if and only if this is the NOT insn.
7240 tcg_gen_not_i64(tcg_rd
, tcg_rn
);
7242 case 0x7: /* SQABS, SQNEG */
7244 gen_helper_neon_qneg_s64(tcg_rd
, cpu_env
, tcg_rn
);
7246 gen_helper_neon_qabs_s64(tcg_rd
, cpu_env
, tcg_rn
);
7249 case 0xa: /* CMLT */
7250 /* 64 bit integer comparison against zero, result is
7251 * test ? (2^64 - 1) : 0. We implement via setcond(!test) and
7256 tcg_gen_setcondi_i64(cond
, tcg_rd
, tcg_rn
, 0);
7257 tcg_gen_neg_i64(tcg_rd
, tcg_rd
);
7259 case 0x8: /* CMGT, CMGE */
7260 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
7262 case 0x9: /* CMEQ, CMLE */
7263 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
7265 case 0xb: /* ABS, NEG */
7267 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7269 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7270 tcg_gen_neg_i64(tcg_rd
, tcg_rn
);
7271 tcg_gen_movcond_i64(TCG_COND_GT
, tcg_rd
, tcg_rn
, tcg_zero
,
7273 tcg_temp_free_i64(tcg_zero
);
7276 case 0x2f: /* FABS */
7277 gen_helper_vfp_absd(tcg_rd
, tcg_rn
);
7279 case 0x6f: /* FNEG */
7280 gen_helper_vfp_negd(tcg_rd
, tcg_rn
);
7282 case 0x7f: /* FSQRT */
7283 gen_helper_vfp_sqrtd(tcg_rd
, tcg_rn
, cpu_env
);
7285 case 0x1a: /* FCVTNS */
7286 case 0x1b: /* FCVTMS */
7287 case 0x1c: /* FCVTAS */
7288 case 0x3a: /* FCVTPS */
7289 case 0x3b: /* FCVTZS */
7291 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7292 gen_helper_vfp_tosqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7293 tcg_temp_free_i32(tcg_shift
);
7296 case 0x5a: /* FCVTNU */
7297 case 0x5b: /* FCVTMU */
7298 case 0x5c: /* FCVTAU */
7299 case 0x7a: /* FCVTPU */
7300 case 0x7b: /* FCVTZU */
7302 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7303 gen_helper_vfp_touqd(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7304 tcg_temp_free_i32(tcg_shift
);
7307 case 0x18: /* FRINTN */
7308 case 0x19: /* FRINTM */
7309 case 0x38: /* FRINTP */
7310 case 0x39: /* FRINTZ */
7311 case 0x58: /* FRINTA */
7312 case 0x79: /* FRINTI */
7313 gen_helper_rintd(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7315 case 0x59: /* FRINTX */
7316 gen_helper_rintd_exact(tcg_rd
, tcg_rn
, tcg_fpstatus
);
7319 g_assert_not_reached();
7323 static void handle_2misc_fcmp_zero(DisasContext
*s
, int opcode
,
7324 bool is_scalar
, bool is_u
, bool is_q
,
7325 int size
, int rn
, int rd
)
7327 bool is_double
= (size
== 3);
7330 if (!fp_access_check(s
)) {
7334 fpst
= get_fpstatus_ptr();
7337 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7338 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7339 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7340 NeonGenTwoDoubleOPFn
*genfn
;
7345 case 0x2e: /* FCMLT (zero) */
7348 case 0x2c: /* FCMGT (zero) */
7349 genfn
= gen_helper_neon_cgt_f64
;
7351 case 0x2d: /* FCMEQ (zero) */
7352 genfn
= gen_helper_neon_ceq_f64
;
7354 case 0x6d: /* FCMLE (zero) */
7357 case 0x6c: /* FCMGE (zero) */
7358 genfn
= gen_helper_neon_cge_f64
;
7361 g_assert_not_reached();
7364 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7365 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7367 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7369 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7371 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7374 clear_vec_high(s
, rd
);
7377 tcg_temp_free_i64(tcg_res
);
7378 tcg_temp_free_i64(tcg_zero
);
7379 tcg_temp_free_i64(tcg_op
);
7381 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7382 TCGv_i32 tcg_zero
= tcg_const_i32(0);
7383 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7384 NeonGenTwoSingleOPFn
*genfn
;
7386 int pass
, maxpasses
;
7389 case 0x2e: /* FCMLT (zero) */
7392 case 0x2c: /* FCMGT (zero) */
7393 genfn
= gen_helper_neon_cgt_f32
;
7395 case 0x2d: /* FCMEQ (zero) */
7396 genfn
= gen_helper_neon_ceq_f32
;
7398 case 0x6d: /* FCMLE (zero) */
7401 case 0x6c: /* FCMGE (zero) */
7402 genfn
= gen_helper_neon_cge_f32
;
7405 g_assert_not_reached();
7411 maxpasses
= is_q
? 4 : 2;
7414 for (pass
= 0; pass
< maxpasses
; pass
++) {
7415 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7417 genfn(tcg_res
, tcg_zero
, tcg_op
, fpst
);
7419 genfn(tcg_res
, tcg_op
, tcg_zero
, fpst
);
7422 write_fp_sreg(s
, rd
, tcg_res
);
7424 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7427 tcg_temp_free_i32(tcg_res
);
7428 tcg_temp_free_i32(tcg_zero
);
7429 tcg_temp_free_i32(tcg_op
);
7430 if (!is_q
&& !is_scalar
) {
7431 clear_vec_high(s
, rd
);
7435 tcg_temp_free_ptr(fpst
);
7438 static void handle_2misc_reciprocal(DisasContext
*s
, int opcode
,
7439 bool is_scalar
, bool is_u
, bool is_q
,
7440 int size
, int rn
, int rd
)
7442 bool is_double
= (size
== 3);
7443 TCGv_ptr fpst
= get_fpstatus_ptr();
7446 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7447 TCGv_i64 tcg_res
= tcg_temp_new_i64();
7450 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7451 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7453 case 0x3d: /* FRECPE */
7454 gen_helper_recpe_f64(tcg_res
, tcg_op
, fpst
);
7456 case 0x3f: /* FRECPX */
7457 gen_helper_frecpx_f64(tcg_res
, tcg_op
, fpst
);
7459 case 0x7d: /* FRSQRTE */
7460 gen_helper_rsqrte_f64(tcg_res
, tcg_op
, fpst
);
7463 g_assert_not_reached();
7465 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
7468 clear_vec_high(s
, rd
);
7471 tcg_temp_free_i64(tcg_res
);
7472 tcg_temp_free_i64(tcg_op
);
7474 TCGv_i32 tcg_op
= tcg_temp_new_i32();
7475 TCGv_i32 tcg_res
= tcg_temp_new_i32();
7476 int pass
, maxpasses
;
7481 maxpasses
= is_q
? 4 : 2;
7484 for (pass
= 0; pass
< maxpasses
; pass
++) {
7485 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
7488 case 0x3c: /* URECPE */
7489 gen_helper_recpe_u32(tcg_res
, tcg_op
, fpst
);
7491 case 0x3d: /* FRECPE */
7492 gen_helper_recpe_f32(tcg_res
, tcg_op
, fpst
);
7494 case 0x3f: /* FRECPX */
7495 gen_helper_frecpx_f32(tcg_res
, tcg_op
, fpst
);
7497 case 0x7d: /* FRSQRTE */
7498 gen_helper_rsqrte_f32(tcg_res
, tcg_op
, fpst
);
7501 g_assert_not_reached();
7505 write_fp_sreg(s
, rd
, tcg_res
);
7507 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
7510 tcg_temp_free_i32(tcg_res
);
7511 tcg_temp_free_i32(tcg_op
);
7512 if (!is_q
&& !is_scalar
) {
7513 clear_vec_high(s
, rd
);
7516 tcg_temp_free_ptr(fpst
);
7519 static void handle_2misc_narrow(DisasContext
*s
, bool scalar
,
7520 int opcode
, bool u
, bool is_q
,
7521 int size
, int rn
, int rd
)
7523 /* Handle 2-reg-misc ops which are narrowing (so each 2*size element
7524 * in the source becomes a size element in the destination).
7527 TCGv_i32 tcg_res
[2];
7528 int destelt
= is_q
? 2 : 0;
7529 int passes
= scalar
? 1 : 2;
7532 tcg_res
[1] = tcg_const_i32(0);
7535 for (pass
= 0; pass
< passes
; pass
++) {
7536 TCGv_i64 tcg_op
= tcg_temp_new_i64();
7537 NeonGenNarrowFn
*genfn
= NULL
;
7538 NeonGenNarrowEnvFn
*genenvfn
= NULL
;
7541 read_vec_element(s
, tcg_op
, rn
, pass
, size
+ 1);
7543 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
7545 tcg_res
[pass
] = tcg_temp_new_i32();
7548 case 0x12: /* XTN, SQXTUN */
7550 static NeonGenNarrowFn
* const xtnfns
[3] = {
7551 gen_helper_neon_narrow_u8
,
7552 gen_helper_neon_narrow_u16
,
7553 tcg_gen_trunc_i64_i32
,
7555 static NeonGenNarrowEnvFn
* const sqxtunfns
[3] = {
7556 gen_helper_neon_unarrow_sat8
,
7557 gen_helper_neon_unarrow_sat16
,
7558 gen_helper_neon_unarrow_sat32
,
7561 genenvfn
= sqxtunfns
[size
];
7563 genfn
= xtnfns
[size
];
7567 case 0x14: /* SQXTN, UQXTN */
7569 static NeonGenNarrowEnvFn
* const fns
[3][2] = {
7570 { gen_helper_neon_narrow_sat_s8
,
7571 gen_helper_neon_narrow_sat_u8
},
7572 { gen_helper_neon_narrow_sat_s16
,
7573 gen_helper_neon_narrow_sat_u16
},
7574 { gen_helper_neon_narrow_sat_s32
,
7575 gen_helper_neon_narrow_sat_u32
},
7577 genenvfn
= fns
[size
][u
];
7580 case 0x16: /* FCVTN, FCVTN2 */
7581 /* 32 bit to 16 bit or 64 bit to 32 bit float conversion */
7583 gen_helper_vfp_fcvtsd(tcg_res
[pass
], tcg_op
, cpu_env
);
7585 TCGv_i32 tcg_lo
= tcg_temp_new_i32();
7586 TCGv_i32 tcg_hi
= tcg_temp_new_i32();
7587 tcg_gen_trunc_i64_i32(tcg_lo
, tcg_op
);
7588 gen_helper_vfp_fcvt_f32_to_f16(tcg_lo
, tcg_lo
, cpu_env
);
7589 tcg_gen_shri_i64(tcg_op
, tcg_op
, 32);
7590 tcg_gen_trunc_i64_i32(tcg_hi
, tcg_op
);
7591 gen_helper_vfp_fcvt_f32_to_f16(tcg_hi
, tcg_hi
, cpu_env
);
7592 tcg_gen_deposit_i32(tcg_res
[pass
], tcg_lo
, tcg_hi
, 16, 16);
7593 tcg_temp_free_i32(tcg_lo
);
7594 tcg_temp_free_i32(tcg_hi
);
7597 case 0x56: /* FCVTXN, FCVTXN2 */
7598 /* 64 bit to 32 bit float conversion
7599 * with von Neumann rounding (round to odd)
7602 gen_helper_fcvtx_f64_to_f32(tcg_res
[pass
], tcg_op
, cpu_env
);
7605 g_assert_not_reached();
7609 genfn(tcg_res
[pass
], tcg_op
);
7610 } else if (genenvfn
) {
7611 genenvfn(tcg_res
[pass
], cpu_env
, tcg_op
);
7614 tcg_temp_free_i64(tcg_op
);
7617 for (pass
= 0; pass
< 2; pass
++) {
7618 write_vec_element_i32(s
, tcg_res
[pass
], rd
, destelt
+ pass
, MO_32
);
7619 tcg_temp_free_i32(tcg_res
[pass
]);
7622 clear_vec_high(s
, rd
);
7626 /* Remaining saturating accumulating ops */
7627 static void handle_2misc_satacc(DisasContext
*s
, bool is_scalar
, bool is_u
,
7628 bool is_q
, int size
, int rn
, int rd
)
7630 bool is_double
= (size
== 3);
7633 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
7634 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7637 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
7638 read_vec_element(s
, tcg_rn
, rn
, pass
, MO_64
);
7639 read_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7641 if (is_u
) { /* USQADD */
7642 gen_helper_neon_uqadd_s64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7643 } else { /* SUQADD */
7644 gen_helper_neon_sqadd_u64(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7646 write_vec_element(s
, tcg_rd
, rd
, pass
, MO_64
);
7649 clear_vec_high(s
, rd
);
7652 tcg_temp_free_i64(tcg_rd
);
7653 tcg_temp_free_i64(tcg_rn
);
7655 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7656 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7657 int pass
, maxpasses
;
7662 maxpasses
= is_q
? 4 : 2;
7665 for (pass
= 0; pass
< maxpasses
; pass
++) {
7667 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, size
);
7668 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, size
);
7670 read_vec_element_i32(s
, tcg_rn
, rn
, pass
, MO_32
);
7671 read_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7674 if (is_u
) { /* USQADD */
7677 gen_helper_neon_uqadd_s8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7680 gen_helper_neon_uqadd_s16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7683 gen_helper_neon_uqadd_s32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7686 g_assert_not_reached();
7688 } else { /* SUQADD */
7691 gen_helper_neon_sqadd_u8(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7694 gen_helper_neon_sqadd_u16(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7697 gen_helper_neon_sqadd_u32(tcg_rd
, cpu_env
, tcg_rn
, tcg_rd
);
7700 g_assert_not_reached();
7705 TCGv_i64 tcg_zero
= tcg_const_i64(0);
7706 write_vec_element(s
, tcg_zero
, rd
, 0, MO_64
);
7707 tcg_temp_free_i64(tcg_zero
);
7709 write_vec_element_i32(s
, tcg_rd
, rd
, pass
, MO_32
);
7713 clear_vec_high(s
, rd
);
7716 tcg_temp_free_i32(tcg_rd
);
7717 tcg_temp_free_i32(tcg_rn
);
7721 /* C3.6.12 AdvSIMD scalar two reg misc
7722 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
7723 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7724 * | 0 1 | U | 1 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
7725 * +-----+---+-----------+------+-----------+--------+-----+------+------+
7727 static void disas_simd_scalar_two_reg_misc(DisasContext
*s
, uint32_t insn
)
7729 int rd
= extract32(insn
, 0, 5);
7730 int rn
= extract32(insn
, 5, 5);
7731 int opcode
= extract32(insn
, 12, 5);
7732 int size
= extract32(insn
, 22, 2);
7733 bool u
= extract32(insn
, 29, 1);
7734 bool is_fcvt
= false;
7737 TCGv_ptr tcg_fpstatus
;
7740 case 0x3: /* USQADD / SUQADD*/
7741 if (!fp_access_check(s
)) {
7744 handle_2misc_satacc(s
, true, u
, false, size
, rn
, rd
);
7746 case 0x7: /* SQABS / SQNEG */
7748 case 0xa: /* CMLT */
7750 unallocated_encoding(s
);
7754 case 0x8: /* CMGT, CMGE */
7755 case 0x9: /* CMEQ, CMLE */
7756 case 0xb: /* ABS, NEG */
7758 unallocated_encoding(s
);
7762 case 0x12: /* SQXTUN */
7764 unallocated_encoding(s
);
7768 case 0x14: /* SQXTN, UQXTN */
7770 unallocated_encoding(s
);
7773 if (!fp_access_check(s
)) {
7776 handle_2misc_narrow(s
, true, opcode
, u
, false, size
, rn
, rd
);
7781 /* Floating point: U, size[1] and opcode indicate operation;
7782 * size[0] indicates single or double precision.
7784 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
7785 size
= extract32(size
, 0, 1) ? 3 : 2;
7787 case 0x2c: /* FCMGT (zero) */
7788 case 0x2d: /* FCMEQ (zero) */
7789 case 0x2e: /* FCMLT (zero) */
7790 case 0x6c: /* FCMGE (zero) */
7791 case 0x6d: /* FCMLE (zero) */
7792 handle_2misc_fcmp_zero(s
, opcode
, true, u
, true, size
, rn
, rd
);
7794 case 0x1d: /* SCVTF */
7795 case 0x5d: /* UCVTF */
7797 bool is_signed
= (opcode
== 0x1d);
7798 if (!fp_access_check(s
)) {
7801 handle_simd_intfp_conv(s
, rd
, rn
, 1, is_signed
, 0, size
);
7804 case 0x3d: /* FRECPE */
7805 case 0x3f: /* FRECPX */
7806 case 0x7d: /* FRSQRTE */
7807 if (!fp_access_check(s
)) {
7810 handle_2misc_reciprocal(s
, opcode
, true, u
, true, size
, rn
, rd
);
7812 case 0x1a: /* FCVTNS */
7813 case 0x1b: /* FCVTMS */
7814 case 0x3a: /* FCVTPS */
7815 case 0x3b: /* FCVTZS */
7816 case 0x5a: /* FCVTNU */
7817 case 0x5b: /* FCVTMU */
7818 case 0x7a: /* FCVTPU */
7819 case 0x7b: /* FCVTZU */
7821 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
7823 case 0x1c: /* FCVTAS */
7824 case 0x5c: /* FCVTAU */
7825 /* TIEAWAY doesn't fit in the usual rounding mode encoding */
7827 rmode
= FPROUNDING_TIEAWAY
;
7829 case 0x56: /* FCVTXN, FCVTXN2 */
7831 unallocated_encoding(s
);
7834 if (!fp_access_check(s
)) {
7837 handle_2misc_narrow(s
, true, opcode
, u
, false, size
- 1, rn
, rd
);
7840 unallocated_encoding(s
);
7845 unallocated_encoding(s
);
7849 if (!fp_access_check(s
)) {
7854 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
7855 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
7856 tcg_fpstatus
= get_fpstatus_ptr();
7858 TCGV_UNUSED_I32(tcg_rmode
);
7859 TCGV_UNUSED_PTR(tcg_fpstatus
);
7863 TCGv_i64 tcg_rn
= read_fp_dreg(s
, rn
);
7864 TCGv_i64 tcg_rd
= tcg_temp_new_i64();
7866 handle_2misc_64(s
, opcode
, u
, tcg_rd
, tcg_rn
, tcg_rmode
, tcg_fpstatus
);
7867 write_fp_dreg(s
, rd
, tcg_rd
);
7868 tcg_temp_free_i64(tcg_rd
);
7869 tcg_temp_free_i64(tcg_rn
);
7871 TCGv_i32 tcg_rn
= tcg_temp_new_i32();
7872 TCGv_i32 tcg_rd
= tcg_temp_new_i32();
7874 read_vec_element_i32(s
, tcg_rn
, rn
, 0, size
);
7877 case 0x7: /* SQABS, SQNEG */
7879 NeonGenOneOpEnvFn
*genfn
;
7880 static NeonGenOneOpEnvFn
* const fns
[3][2] = {
7881 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
7882 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
7883 { gen_helper_neon_qabs_s32
, gen_helper_neon_qneg_s32
},
7885 genfn
= fns
[size
][u
];
7886 genfn(tcg_rd
, cpu_env
, tcg_rn
);
7889 case 0x1a: /* FCVTNS */
7890 case 0x1b: /* FCVTMS */
7891 case 0x1c: /* FCVTAS */
7892 case 0x3a: /* FCVTPS */
7893 case 0x3b: /* FCVTZS */
7895 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7896 gen_helper_vfp_tosls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7897 tcg_temp_free_i32(tcg_shift
);
7900 case 0x5a: /* FCVTNU */
7901 case 0x5b: /* FCVTMU */
7902 case 0x5c: /* FCVTAU */
7903 case 0x7a: /* FCVTPU */
7904 case 0x7b: /* FCVTZU */
7906 TCGv_i32 tcg_shift
= tcg_const_i32(0);
7907 gen_helper_vfp_touls(tcg_rd
, tcg_rn
, tcg_shift
, tcg_fpstatus
);
7908 tcg_temp_free_i32(tcg_shift
);
7912 g_assert_not_reached();
7915 write_fp_sreg(s
, rd
, tcg_rd
);
7916 tcg_temp_free_i32(tcg_rd
);
7917 tcg_temp_free_i32(tcg_rn
);
7921 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
7922 tcg_temp_free_i32(tcg_rmode
);
7923 tcg_temp_free_ptr(tcg_fpstatus
);
7927 /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */
7928 static void handle_vec_simd_shri(DisasContext
*s
, bool is_q
, bool is_u
,
7929 int immh
, int immb
, int opcode
, int rn
, int rd
)
7931 int size
= 32 - clz32(immh
) - 1;
7932 int immhb
= immh
<< 3 | immb
;
7933 int shift
= 2 * (8 << size
) - immhb
;
7934 bool accumulate
= false;
7936 bool insert
= false;
7937 int dsize
= is_q
? 128 : 64;
7938 int esize
= 8 << size
;
7939 int elements
= dsize
/esize
;
7940 TCGMemOp memop
= size
| (is_u
? 0 : MO_SIGN
);
7941 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
7942 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
7946 if (extract32(immh
, 3, 1) && !is_q
) {
7947 unallocated_encoding(s
);
7951 if (size
> 3 && !is_q
) {
7952 unallocated_encoding(s
);
7956 if (!fp_access_check(s
)) {
7961 case 0x02: /* SSRA / USRA (accumulate) */
7964 case 0x04: /* SRSHR / URSHR (rounding) */
7967 case 0x06: /* SRSRA / URSRA (accum + rounding) */
7968 accumulate
= round
= true;
7970 case 0x08: /* SRI */
7976 uint64_t round_const
= 1ULL << (shift
- 1);
7977 tcg_round
= tcg_const_i64(round_const
);
7979 TCGV_UNUSED_I64(tcg_round
);
7982 for (i
= 0; i
< elements
; i
++) {
7983 read_vec_element(s
, tcg_rn
, rn
, i
, memop
);
7984 if (accumulate
|| insert
) {
7985 read_vec_element(s
, tcg_rd
, rd
, i
, memop
);
7989 handle_shri_with_ins(tcg_rd
, tcg_rn
, size
, shift
);
7991 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
7992 accumulate
, is_u
, size
, shift
);
7995 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
7999 clear_vec_high(s
, rd
);
8003 tcg_temp_free_i64(tcg_round
);
8007 /* SHL/SLI - Vector shift left */
8008 static void handle_vec_simd_shli(DisasContext
*s
, bool is_q
, bool insert
,
8009 int immh
, int immb
, int opcode
, int rn
, int rd
)
8011 int size
= 32 - clz32(immh
) - 1;
8012 int immhb
= immh
<< 3 | immb
;
8013 int shift
= immhb
- (8 << size
);
8014 int dsize
= is_q
? 128 : 64;
8015 int esize
= 8 << size
;
8016 int elements
= dsize
/esize
;
8017 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8018 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8021 if (extract32(immh
, 3, 1) && !is_q
) {
8022 unallocated_encoding(s
);
8026 if (size
> 3 && !is_q
) {
8027 unallocated_encoding(s
);
8031 if (!fp_access_check(s
)) {
8035 for (i
= 0; i
< elements
; i
++) {
8036 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
8038 read_vec_element(s
, tcg_rd
, rd
, i
, size
);
8041 handle_shli_with_ins(tcg_rd
, tcg_rn
, insert
, shift
);
8043 write_vec_element(s
, tcg_rd
, rd
, i
, size
);
8047 clear_vec_high(s
, rd
);
8051 /* USHLL/SHLL - Vector shift left with widening */
8052 static void handle_vec_simd_wshli(DisasContext
*s
, bool is_q
, bool is_u
,
8053 int immh
, int immb
, int opcode
, int rn
, int rd
)
8055 int size
= 32 - clz32(immh
) - 1;
8056 int immhb
= immh
<< 3 | immb
;
8057 int shift
= immhb
- (8 << size
);
8059 int esize
= 8 << size
;
8060 int elements
= dsize
/esize
;
8061 TCGv_i64 tcg_rn
= new_tmp_a64(s
);
8062 TCGv_i64 tcg_rd
= new_tmp_a64(s
);
8066 unallocated_encoding(s
);
8070 if (!fp_access_check(s
)) {
8074 /* For the LL variants the store is larger than the load,
8075 * so if rd == rn we would overwrite parts of our input.
8076 * So load everything right now and use shifts in the main loop.
8078 read_vec_element(s
, tcg_rn
, rn
, is_q
? 1 : 0, MO_64
);
8080 for (i
= 0; i
< elements
; i
++) {
8081 tcg_gen_shri_i64(tcg_rd
, tcg_rn
, i
* esize
);
8082 ext_and_shift_reg(tcg_rd
, tcg_rd
, size
| (!is_u
<< 2), 0);
8083 tcg_gen_shli_i64(tcg_rd
, tcg_rd
, shift
);
8084 write_vec_element(s
, tcg_rd
, rd
, i
, size
+ 1);
8088 /* SHRN/RSHRN - Shift right with narrowing (and potential rounding) */
8089 static void handle_vec_simd_shrn(DisasContext
*s
, bool is_q
,
8090 int immh
, int immb
, int opcode
, int rn
, int rd
)
8092 int immhb
= immh
<< 3 | immb
;
8093 int size
= 32 - clz32(immh
) - 1;
8095 int esize
= 8 << size
;
8096 int elements
= dsize
/esize
;
8097 int shift
= (2 * esize
) - immhb
;
8098 bool round
= extract32(opcode
, 0, 1);
8099 TCGv_i64 tcg_rn
, tcg_rd
, tcg_final
;
8103 if (extract32(immh
, 3, 1)) {
8104 unallocated_encoding(s
);
8108 if (!fp_access_check(s
)) {
8112 tcg_rn
= tcg_temp_new_i64();
8113 tcg_rd
= tcg_temp_new_i64();
8114 tcg_final
= tcg_temp_new_i64();
8115 read_vec_element(s
, tcg_final
, rd
, is_q
? 1 : 0, MO_64
);
8118 uint64_t round_const
= 1ULL << (shift
- 1);
8119 tcg_round
= tcg_const_i64(round_const
);
8121 TCGV_UNUSED_I64(tcg_round
);
8124 for (i
= 0; i
< elements
; i
++) {
8125 read_vec_element(s
, tcg_rn
, rn
, i
, size
+1);
8126 handle_shri_with_rndacc(tcg_rd
, tcg_rn
, tcg_round
,
8127 false, true, size
+1, shift
);
8129 tcg_gen_deposit_i64(tcg_final
, tcg_final
, tcg_rd
, esize
* i
, esize
);
8133 clear_vec_high(s
, rd
);
8134 write_vec_element(s
, tcg_final
, rd
, 0, MO_64
);
8136 write_vec_element(s
, tcg_final
, rd
, 1, MO_64
);
8140 tcg_temp_free_i64(tcg_round
);
8142 tcg_temp_free_i64(tcg_rn
);
8143 tcg_temp_free_i64(tcg_rd
);
8144 tcg_temp_free_i64(tcg_final
);
8149 /* C3.6.14 AdvSIMD shift by immediate
8150 * 31 30 29 28 23 22 19 18 16 15 11 10 9 5 4 0
8151 * +---+---+---+-------------+------+------+--------+---+------+------+
8152 * | 0 | Q | U | 0 1 1 1 1 0 | immh | immb | opcode | 1 | Rn | Rd |
8153 * +---+---+---+-------------+------+------+--------+---+------+------+
8155 static void disas_simd_shift_imm(DisasContext
*s
, uint32_t insn
)
8157 int rd
= extract32(insn
, 0, 5);
8158 int rn
= extract32(insn
, 5, 5);
8159 int opcode
= extract32(insn
, 11, 5);
8160 int immb
= extract32(insn
, 16, 3);
8161 int immh
= extract32(insn
, 19, 4);
8162 bool is_u
= extract32(insn
, 29, 1);
8163 bool is_q
= extract32(insn
, 30, 1);
8166 case 0x08: /* SRI */
8168 unallocated_encoding(s
);
8172 case 0x00: /* SSHR / USHR */
8173 case 0x02: /* SSRA / USRA (accumulate) */
8174 case 0x04: /* SRSHR / URSHR (rounding) */
8175 case 0x06: /* SRSRA / URSRA (accum + rounding) */
8176 handle_vec_simd_shri(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8178 case 0x0a: /* SHL / SLI */
8179 handle_vec_simd_shli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8181 case 0x10: /* SHRN */
8182 case 0x11: /* RSHRN / SQRSHRUN */
8184 handle_vec_simd_sqshrn(s
, false, is_q
, false, true, immh
, immb
,
8187 handle_vec_simd_shrn(s
, is_q
, immh
, immb
, opcode
, rn
, rd
);
8190 case 0x12: /* SQSHRN / UQSHRN */
8191 case 0x13: /* SQRSHRN / UQRSHRN */
8192 handle_vec_simd_sqshrn(s
, false, is_q
, is_u
, is_u
, immh
, immb
,
8195 case 0x14: /* SSHLL / USHLL */
8196 handle_vec_simd_wshli(s
, is_q
, is_u
, immh
, immb
, opcode
, rn
, rd
);
8198 case 0x1c: /* SCVTF / UCVTF */
8199 handle_simd_shift_intfp_conv(s
, false, is_q
, is_u
, immh
, immb
,
8202 case 0xc: /* SQSHLU */
8204 unallocated_encoding(s
);
8207 handle_simd_qshl(s
, false, is_q
, false, true, immh
, immb
, rn
, rd
);
8209 case 0xe: /* SQSHL, UQSHL */
8210 handle_simd_qshl(s
, false, is_q
, is_u
, is_u
, immh
, immb
, rn
, rd
);
8212 case 0x1f: /* FCVTZS/ FCVTZU */
8213 handle_simd_shift_fpint_conv(s
, false, is_q
, is_u
, immh
, immb
, rn
, rd
);
8216 unallocated_encoding(s
);
8221 /* Generate code to do a "long" addition or subtraction, ie one done in
8222 * TCGv_i64 on vector lanes twice the width specified by size.
8224 static void gen_neon_addl(int size
, bool is_sub
, TCGv_i64 tcg_res
,
8225 TCGv_i64 tcg_op1
, TCGv_i64 tcg_op2
)
8227 static NeonGenTwo64OpFn
* const fns
[3][2] = {
8228 { gen_helper_neon_addl_u16
, gen_helper_neon_subl_u16
},
8229 { gen_helper_neon_addl_u32
, gen_helper_neon_subl_u32
},
8230 { tcg_gen_add_i64
, tcg_gen_sub_i64
},
8232 NeonGenTwo64OpFn
*genfn
;
8235 genfn
= fns
[size
][is_sub
];
8236 genfn(tcg_res
, tcg_op1
, tcg_op2
);
8239 static void handle_3rd_widening(DisasContext
*s
, int is_q
, int is_u
, int size
,
8240 int opcode
, int rd
, int rn
, int rm
)
8242 /* 3-reg-different widening insns: 64 x 64 -> 128 */
8243 TCGv_i64 tcg_res
[2];
8246 tcg_res
[0] = tcg_temp_new_i64();
8247 tcg_res
[1] = tcg_temp_new_i64();
8249 /* Does this op do an adding accumulate, a subtracting accumulate,
8250 * or no accumulate at all?
8268 read_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8269 read_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8272 /* size == 2 means two 32x32->64 operations; this is worth special
8273 * casing because we can generally handle it inline.
8276 for (pass
= 0; pass
< 2; pass
++) {
8277 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8278 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8279 TCGv_i64 tcg_passres
;
8280 TCGMemOp memop
= MO_32
| (is_u
? 0 : MO_SIGN
);
8282 int elt
= pass
+ is_q
* 2;
8284 read_vec_element(s
, tcg_op1
, rn
, elt
, memop
);
8285 read_vec_element(s
, tcg_op2
, rm
, elt
, memop
);
8288 tcg_passres
= tcg_res
[pass
];
8290 tcg_passres
= tcg_temp_new_i64();
8294 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8295 tcg_gen_add_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8297 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8298 tcg_gen_sub_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8300 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8301 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8303 TCGv_i64 tcg_tmp1
= tcg_temp_new_i64();
8304 TCGv_i64 tcg_tmp2
= tcg_temp_new_i64();
8306 tcg_gen_sub_i64(tcg_tmp1
, tcg_op1
, tcg_op2
);
8307 tcg_gen_sub_i64(tcg_tmp2
, tcg_op2
, tcg_op1
);
8308 tcg_gen_movcond_i64(is_u
? TCG_COND_GEU
: TCG_COND_GE
,
8310 tcg_op1
, tcg_op2
, tcg_tmp1
, tcg_tmp2
);
8311 tcg_temp_free_i64(tcg_tmp1
);
8312 tcg_temp_free_i64(tcg_tmp2
);
8315 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8316 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8317 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8318 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8320 case 9: /* SQDMLAL, SQDMLAL2 */
8321 case 11: /* SQDMLSL, SQDMLSL2 */
8322 case 13: /* SQDMULL, SQDMULL2 */
8323 tcg_gen_mul_i64(tcg_passres
, tcg_op1
, tcg_op2
);
8324 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
8325 tcg_passres
, tcg_passres
);
8328 g_assert_not_reached();
8331 if (opcode
== 9 || opcode
== 11) {
8332 /* saturating accumulate ops */
8334 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
8336 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
8337 tcg_res
[pass
], tcg_passres
);
8338 } else if (accop
> 0) {
8339 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8340 } else if (accop
< 0) {
8341 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
8345 tcg_temp_free_i64(tcg_passres
);
8348 tcg_temp_free_i64(tcg_op1
);
8349 tcg_temp_free_i64(tcg_op2
);
8352 /* size 0 or 1, generally helper functions */
8353 for (pass
= 0; pass
< 2; pass
++) {
8354 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8355 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8356 TCGv_i64 tcg_passres
;
8357 int elt
= pass
+ is_q
* 2;
8359 read_vec_element_i32(s
, tcg_op1
, rn
, elt
, MO_32
);
8360 read_vec_element_i32(s
, tcg_op2
, rm
, elt
, MO_32
);
8363 tcg_passres
= tcg_res
[pass
];
8365 tcg_passres
= tcg_temp_new_i64();
8369 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8370 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8372 TCGv_i64 tcg_op2_64
= tcg_temp_new_i64();
8373 static NeonGenWidenFn
* const widenfns
[2][2] = {
8374 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8375 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8377 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8379 widenfn(tcg_op2_64
, tcg_op2
);
8380 widenfn(tcg_passres
, tcg_op1
);
8381 gen_neon_addl(size
, (opcode
== 2), tcg_passres
,
8382 tcg_passres
, tcg_op2_64
);
8383 tcg_temp_free_i64(tcg_op2_64
);
8386 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8387 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8390 gen_helper_neon_abdl_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8392 gen_helper_neon_abdl_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8396 gen_helper_neon_abdl_u32(tcg_passres
, tcg_op1
, tcg_op2
);
8398 gen_helper_neon_abdl_s32(tcg_passres
, tcg_op1
, tcg_op2
);
8402 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8403 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8404 case 12: /* UMULL, UMULL2, SMULL, SMULL2 */
8407 gen_helper_neon_mull_u8(tcg_passres
, tcg_op1
, tcg_op2
);
8409 gen_helper_neon_mull_s8(tcg_passres
, tcg_op1
, tcg_op2
);
8413 gen_helper_neon_mull_u16(tcg_passres
, tcg_op1
, tcg_op2
);
8415 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8419 case 9: /* SQDMLAL, SQDMLAL2 */
8420 case 11: /* SQDMLSL, SQDMLSL2 */
8421 case 13: /* SQDMULL, SQDMULL2 */
8423 gen_helper_neon_mull_s16(tcg_passres
, tcg_op1
, tcg_op2
);
8424 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
8425 tcg_passres
, tcg_passres
);
8427 case 14: /* PMULL */
8429 gen_helper_neon_mull_p8(tcg_passres
, tcg_op1
, tcg_op2
);
8432 g_assert_not_reached();
8434 tcg_temp_free_i32(tcg_op1
);
8435 tcg_temp_free_i32(tcg_op2
);
8438 if (opcode
== 9 || opcode
== 11) {
8439 /* saturating accumulate ops */
8441 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
8443 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
8447 gen_neon_addl(size
, (accop
< 0), tcg_res
[pass
],
8448 tcg_res
[pass
], tcg_passres
);
8450 tcg_temp_free_i64(tcg_passres
);
8455 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8456 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8457 tcg_temp_free_i64(tcg_res
[0]);
8458 tcg_temp_free_i64(tcg_res
[1]);
8461 static void handle_3rd_wide(DisasContext
*s
, int is_q
, int is_u
, int size
,
8462 int opcode
, int rd
, int rn
, int rm
)
8464 TCGv_i64 tcg_res
[2];
8465 int part
= is_q
? 2 : 0;
8468 for (pass
= 0; pass
< 2; pass
++) {
8469 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8470 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8471 TCGv_i64 tcg_op2_wide
= tcg_temp_new_i64();
8472 static NeonGenWidenFn
* const widenfns
[3][2] = {
8473 { gen_helper_neon_widen_s8
, gen_helper_neon_widen_u8
},
8474 { gen_helper_neon_widen_s16
, gen_helper_neon_widen_u16
},
8475 { tcg_gen_ext_i32_i64
, tcg_gen_extu_i32_i64
},
8477 NeonGenWidenFn
*widenfn
= widenfns
[size
][is_u
];
8479 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8480 read_vec_element_i32(s
, tcg_op2
, rm
, part
+ pass
, MO_32
);
8481 widenfn(tcg_op2_wide
, tcg_op2
);
8482 tcg_temp_free_i32(tcg_op2
);
8483 tcg_res
[pass
] = tcg_temp_new_i64();
8484 gen_neon_addl(size
, (opcode
== 3),
8485 tcg_res
[pass
], tcg_op1
, tcg_op2_wide
);
8486 tcg_temp_free_i64(tcg_op1
);
8487 tcg_temp_free_i64(tcg_op2_wide
);
8490 for (pass
= 0; pass
< 2; pass
++) {
8491 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8492 tcg_temp_free_i64(tcg_res
[pass
]);
8496 static void do_narrow_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8498 tcg_gen_shri_i64(in
, in
, 32);
8499 tcg_gen_trunc_i64_i32(res
, in
);
8502 static void do_narrow_round_high_u32(TCGv_i32 res
, TCGv_i64 in
)
8504 tcg_gen_addi_i64(in
, in
, 1U << 31);
8505 do_narrow_high_u32(res
, in
);
8508 static void handle_3rd_narrowing(DisasContext
*s
, int is_q
, int is_u
, int size
,
8509 int opcode
, int rd
, int rn
, int rm
)
8511 TCGv_i32 tcg_res
[2];
8512 int part
= is_q
? 2 : 0;
8515 for (pass
= 0; pass
< 2; pass
++) {
8516 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8517 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8518 TCGv_i64 tcg_wideres
= tcg_temp_new_i64();
8519 static NeonGenNarrowFn
* const narrowfns
[3][2] = {
8520 { gen_helper_neon_narrow_high_u8
,
8521 gen_helper_neon_narrow_round_high_u8
},
8522 { gen_helper_neon_narrow_high_u16
,
8523 gen_helper_neon_narrow_round_high_u16
},
8524 { do_narrow_high_u32
, do_narrow_round_high_u32
},
8526 NeonGenNarrowFn
*gennarrow
= narrowfns
[size
][is_u
];
8528 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8529 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8531 gen_neon_addl(size
, (opcode
== 6), tcg_wideres
, tcg_op1
, tcg_op2
);
8533 tcg_temp_free_i64(tcg_op1
);
8534 tcg_temp_free_i64(tcg_op2
);
8536 tcg_res
[pass
] = tcg_temp_new_i32();
8537 gennarrow(tcg_res
[pass
], tcg_wideres
);
8538 tcg_temp_free_i64(tcg_wideres
);
8541 for (pass
= 0; pass
< 2; pass
++) {
8542 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
+ part
, MO_32
);
8543 tcg_temp_free_i32(tcg_res
[pass
]);
8546 clear_vec_high(s
, rd
);
8550 static void handle_pmull_64(DisasContext
*s
, int is_q
, int rd
, int rn
, int rm
)
8552 /* PMULL of 64 x 64 -> 128 is an odd special case because it
8553 * is the only three-reg-diff instruction which produces a
8554 * 128-bit wide result from a single operation. However since
8555 * it's possible to calculate the two halves more or less
8556 * separately we just use two helper calls.
8558 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8559 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8560 TCGv_i64 tcg_res
= tcg_temp_new_i64();
8562 read_vec_element(s
, tcg_op1
, rn
, is_q
, MO_64
);
8563 read_vec_element(s
, tcg_op2
, rm
, is_q
, MO_64
);
8564 gen_helper_neon_pmull_64_lo(tcg_res
, tcg_op1
, tcg_op2
);
8565 write_vec_element(s
, tcg_res
, rd
, 0, MO_64
);
8566 gen_helper_neon_pmull_64_hi(tcg_res
, tcg_op1
, tcg_op2
);
8567 write_vec_element(s
, tcg_res
, rd
, 1, MO_64
);
8569 tcg_temp_free_i64(tcg_op1
);
8570 tcg_temp_free_i64(tcg_op2
);
8571 tcg_temp_free_i64(tcg_res
);
8574 /* C3.6.15 AdvSIMD three different
8575 * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0
8576 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8577 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 0 0 | Rn | Rd |
8578 * +---+---+---+-----------+------+---+------+--------+-----+------+------+
8580 static void disas_simd_three_reg_diff(DisasContext
*s
, uint32_t insn
)
8582 /* Instructions in this group fall into three basic classes
8583 * (in each case with the operation working on each element in
8584 * the input vectors):
8585 * (1) widening 64 x 64 -> 128 (with possibly Vd as an extra
8587 * (2) wide 64 x 128 -> 128
8588 * (3) narrowing 128 x 128 -> 64
8589 * Here we do initial decode, catch unallocated cases and
8590 * dispatch to separate functions for each class.
8592 int is_q
= extract32(insn
, 30, 1);
8593 int is_u
= extract32(insn
, 29, 1);
8594 int size
= extract32(insn
, 22, 2);
8595 int opcode
= extract32(insn
, 12, 4);
8596 int rm
= extract32(insn
, 16, 5);
8597 int rn
= extract32(insn
, 5, 5);
8598 int rd
= extract32(insn
, 0, 5);
8601 case 1: /* SADDW, SADDW2, UADDW, UADDW2 */
8602 case 3: /* SSUBW, SSUBW2, USUBW, USUBW2 */
8603 /* 64 x 128 -> 128 */
8605 unallocated_encoding(s
);
8608 if (!fp_access_check(s
)) {
8611 handle_3rd_wide(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8613 case 4: /* ADDHN, ADDHN2, RADDHN, RADDHN2 */
8614 case 6: /* SUBHN, SUBHN2, RSUBHN, RSUBHN2 */
8615 /* 128 x 128 -> 64 */
8617 unallocated_encoding(s
);
8620 if (!fp_access_check(s
)) {
8623 handle_3rd_narrowing(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8625 case 14: /* PMULL, PMULL2 */
8626 if (is_u
|| size
== 1 || size
== 2) {
8627 unallocated_encoding(s
);
8631 if (!arm_dc_feature(s
, ARM_FEATURE_V8_PMULL
)) {
8632 unallocated_encoding(s
);
8635 if (!fp_access_check(s
)) {
8638 handle_pmull_64(s
, is_q
, rd
, rn
, rm
);
8642 case 9: /* SQDMLAL, SQDMLAL2 */
8643 case 11: /* SQDMLSL, SQDMLSL2 */
8644 case 13: /* SQDMULL, SQDMULL2 */
8645 if (is_u
|| size
== 0) {
8646 unallocated_encoding(s
);
8650 case 0: /* SADDL, SADDL2, UADDL, UADDL2 */
8651 case 2: /* SSUBL, SSUBL2, USUBL, USUBL2 */
8652 case 5: /* SABAL, SABAL2, UABAL, UABAL2 */
8653 case 7: /* SABDL, SABDL2, UABDL, UABDL2 */
8654 case 8: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
8655 case 10: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
8656 case 12: /* SMULL, SMULL2, UMULL, UMULL2 */
8657 /* 64 x 64 -> 128 */
8659 unallocated_encoding(s
);
8663 if (!fp_access_check(s
)) {
8667 handle_3rd_widening(s
, is_q
, is_u
, size
, opcode
, rd
, rn
, rm
);
8670 /* opcode 15 not allocated */
8671 unallocated_encoding(s
);
8676 /* Logic op (opcode == 3) subgroup of C3.6.16. */
8677 static void disas_simd_3same_logic(DisasContext
*s
, uint32_t insn
)
8679 int rd
= extract32(insn
, 0, 5);
8680 int rn
= extract32(insn
, 5, 5);
8681 int rm
= extract32(insn
, 16, 5);
8682 int size
= extract32(insn
, 22, 2);
8683 bool is_u
= extract32(insn
, 29, 1);
8684 bool is_q
= extract32(insn
, 30, 1);
8685 TCGv_i64 tcg_op1
, tcg_op2
, tcg_res
[2];
8688 if (!fp_access_check(s
)) {
8692 tcg_op1
= tcg_temp_new_i64();
8693 tcg_op2
= tcg_temp_new_i64();
8694 tcg_res
[0] = tcg_temp_new_i64();
8695 tcg_res
[1] = tcg_temp_new_i64();
8697 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
8698 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
8699 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
8704 tcg_gen_and_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8707 tcg_gen_andc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8710 tcg_gen_or_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8713 tcg_gen_orc_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8718 /* B* ops need res loaded to operate on */
8719 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8724 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8726 case 1: /* BSL bitwise select */
8727 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8728 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8729 tcg_gen_xor_i64(tcg_res
[pass
], tcg_op2
, tcg_op1
);
8731 case 2: /* BIT, bitwise insert if true */
8732 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8733 tcg_gen_and_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8734 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8736 case 3: /* BIF, bitwise insert if false */
8737 tcg_gen_xor_i64(tcg_op1
, tcg_op1
, tcg_res
[pass
]);
8738 tcg_gen_andc_i64(tcg_op1
, tcg_op1
, tcg_op2
);
8739 tcg_gen_xor_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
8745 write_vec_element(s
, tcg_res
[0], rd
, 0, MO_64
);
8747 tcg_gen_movi_i64(tcg_res
[1], 0);
8749 write_vec_element(s
, tcg_res
[1], rd
, 1, MO_64
);
8751 tcg_temp_free_i64(tcg_op1
);
8752 tcg_temp_free_i64(tcg_op2
);
8753 tcg_temp_free_i64(tcg_res
[0]);
8754 tcg_temp_free_i64(tcg_res
[1]);
8757 /* Helper functions for 32 bit comparisons */
8758 static void gen_max_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8760 tcg_gen_movcond_i32(TCG_COND_GE
, res
, op1
, op2
, op1
, op2
);
8763 static void gen_max_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8765 tcg_gen_movcond_i32(TCG_COND_GEU
, res
, op1
, op2
, op1
, op2
);
8768 static void gen_min_s32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8770 tcg_gen_movcond_i32(TCG_COND_LE
, res
, op1
, op2
, op1
, op2
);
8773 static void gen_min_u32(TCGv_i32 res
, TCGv_i32 op1
, TCGv_i32 op2
)
8775 tcg_gen_movcond_i32(TCG_COND_LEU
, res
, op1
, op2
, op1
, op2
);
8778 /* Pairwise op subgroup of C3.6.16.
8780 * This is called directly or via the handle_3same_float for float pairwise
8781 * operations where the opcode and size are calculated differently.
8783 static void handle_simd_3same_pair(DisasContext
*s
, int is_q
, int u
, int opcode
,
8784 int size
, int rn
, int rm
, int rd
)
8789 /* Floating point operations need fpst */
8790 if (opcode
>= 0x58) {
8791 fpst
= get_fpstatus_ptr();
8793 TCGV_UNUSED_PTR(fpst
);
8796 if (!fp_access_check(s
)) {
8800 /* These operations work on the concatenated rm:rn, with each pair of
8801 * adjacent elements being operated on to produce an element in the result.
8804 TCGv_i64 tcg_res
[2];
8806 for (pass
= 0; pass
< 2; pass
++) {
8807 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
8808 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
8809 int passreg
= (pass
== 0) ? rn
: rm
;
8811 read_vec_element(s
, tcg_op1
, passreg
, 0, MO_64
);
8812 read_vec_element(s
, tcg_op2
, passreg
, 1, MO_64
);
8813 tcg_res
[pass
] = tcg_temp_new_i64();
8816 case 0x17: /* ADDP */
8817 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8819 case 0x58: /* FMAXNMP */
8820 gen_helper_vfp_maxnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8822 case 0x5a: /* FADDP */
8823 gen_helper_vfp_addd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8825 case 0x5e: /* FMAXP */
8826 gen_helper_vfp_maxd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8828 case 0x78: /* FMINNMP */
8829 gen_helper_vfp_minnumd(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8831 case 0x7e: /* FMINP */
8832 gen_helper_vfp_mind(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8835 g_assert_not_reached();
8838 tcg_temp_free_i64(tcg_op1
);
8839 tcg_temp_free_i64(tcg_op2
);
8842 for (pass
= 0; pass
< 2; pass
++) {
8843 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
8844 tcg_temp_free_i64(tcg_res
[pass
]);
8847 int maxpass
= is_q
? 4 : 2;
8848 TCGv_i32 tcg_res
[4];
8850 for (pass
= 0; pass
< maxpass
; pass
++) {
8851 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
8852 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
8853 NeonGenTwoOpFn
*genfn
= NULL
;
8854 int passreg
= pass
< (maxpass
/ 2) ? rn
: rm
;
8855 int passelt
= (is_q
&& (pass
& 1)) ? 2 : 0;
8857 read_vec_element_i32(s
, tcg_op1
, passreg
, passelt
, MO_32
);
8858 read_vec_element_i32(s
, tcg_op2
, passreg
, passelt
+ 1, MO_32
);
8859 tcg_res
[pass
] = tcg_temp_new_i32();
8862 case 0x17: /* ADDP */
8864 static NeonGenTwoOpFn
* const fns
[3] = {
8865 gen_helper_neon_padd_u8
,
8866 gen_helper_neon_padd_u16
,
8872 case 0x14: /* SMAXP, UMAXP */
8874 static NeonGenTwoOpFn
* const fns
[3][2] = {
8875 { gen_helper_neon_pmax_s8
, gen_helper_neon_pmax_u8
},
8876 { gen_helper_neon_pmax_s16
, gen_helper_neon_pmax_u16
},
8877 { gen_max_s32
, gen_max_u32
},
8879 genfn
= fns
[size
][u
];
8882 case 0x15: /* SMINP, UMINP */
8884 static NeonGenTwoOpFn
* const fns
[3][2] = {
8885 { gen_helper_neon_pmin_s8
, gen_helper_neon_pmin_u8
},
8886 { gen_helper_neon_pmin_s16
, gen_helper_neon_pmin_u16
},
8887 { gen_min_s32
, gen_min_u32
},
8889 genfn
= fns
[size
][u
];
8892 /* The FP operations are all on single floats (32 bit) */
8893 case 0x58: /* FMAXNMP */
8894 gen_helper_vfp_maxnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8896 case 0x5a: /* FADDP */
8897 gen_helper_vfp_adds(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8899 case 0x5e: /* FMAXP */
8900 gen_helper_vfp_maxs(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8902 case 0x78: /* FMINNMP */
8903 gen_helper_vfp_minnums(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8905 case 0x7e: /* FMINP */
8906 gen_helper_vfp_mins(tcg_res
[pass
], tcg_op1
, tcg_op2
, fpst
);
8909 g_assert_not_reached();
8912 /* FP ops called directly, otherwise call now */
8914 genfn(tcg_res
[pass
], tcg_op1
, tcg_op2
);
8917 tcg_temp_free_i32(tcg_op1
);
8918 tcg_temp_free_i32(tcg_op2
);
8921 for (pass
= 0; pass
< maxpass
; pass
++) {
8922 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
8923 tcg_temp_free_i32(tcg_res
[pass
]);
8926 clear_vec_high(s
, rd
);
8930 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
8931 tcg_temp_free_ptr(fpst
);
8935 /* Floating point op subgroup of C3.6.16. */
8936 static void disas_simd_3same_float(DisasContext
*s
, uint32_t insn
)
8938 /* For floating point ops, the U, size[1] and opcode bits
8939 * together indicate the operation. size[0] indicates single
8942 int fpopcode
= extract32(insn
, 11, 5)
8943 | (extract32(insn
, 23, 1) << 5)
8944 | (extract32(insn
, 29, 1) << 6);
8945 int is_q
= extract32(insn
, 30, 1);
8946 int size
= extract32(insn
, 22, 1);
8947 int rm
= extract32(insn
, 16, 5);
8948 int rn
= extract32(insn
, 5, 5);
8949 int rd
= extract32(insn
, 0, 5);
8951 int datasize
= is_q
? 128 : 64;
8952 int esize
= 32 << size
;
8953 int elements
= datasize
/ esize
;
8955 if (size
== 1 && !is_q
) {
8956 unallocated_encoding(s
);
8961 case 0x58: /* FMAXNMP */
8962 case 0x5a: /* FADDP */
8963 case 0x5e: /* FMAXP */
8964 case 0x78: /* FMINNMP */
8965 case 0x7e: /* FMINP */
8966 if (size
&& !is_q
) {
8967 unallocated_encoding(s
);
8970 handle_simd_3same_pair(s
, is_q
, 0, fpopcode
, size
? MO_64
: MO_32
,
8973 case 0x1b: /* FMULX */
8974 case 0x1f: /* FRECPS */
8975 case 0x3f: /* FRSQRTS */
8976 case 0x5d: /* FACGE */
8977 case 0x7d: /* FACGT */
8978 case 0x19: /* FMLA */
8979 case 0x39: /* FMLS */
8980 case 0x18: /* FMAXNM */
8981 case 0x1a: /* FADD */
8982 case 0x1c: /* FCMEQ */
8983 case 0x1e: /* FMAX */
8984 case 0x38: /* FMINNM */
8985 case 0x3a: /* FSUB */
8986 case 0x3e: /* FMIN */
8987 case 0x5b: /* FMUL */
8988 case 0x5c: /* FCMGE */
8989 case 0x5f: /* FDIV */
8990 case 0x7a: /* FABD */
8991 case 0x7c: /* FCMGT */
8992 if (!fp_access_check(s
)) {
8996 handle_3same_float(s
, size
, elements
, fpopcode
, rd
, rn
, rm
);
8999 unallocated_encoding(s
);
9004 /* Integer op subgroup of C3.6.16. */
9005 static void disas_simd_3same_int(DisasContext
*s
, uint32_t insn
)
9007 int is_q
= extract32(insn
, 30, 1);
9008 int u
= extract32(insn
, 29, 1);
9009 int size
= extract32(insn
, 22, 2);
9010 int opcode
= extract32(insn
, 11, 5);
9011 int rm
= extract32(insn
, 16, 5);
9012 int rn
= extract32(insn
, 5, 5);
9013 int rd
= extract32(insn
, 0, 5);
9017 case 0x13: /* MUL, PMUL */
9018 if (u
&& size
!= 0) {
9019 unallocated_encoding(s
);
9023 case 0x0: /* SHADD, UHADD */
9024 case 0x2: /* SRHADD, URHADD */
9025 case 0x4: /* SHSUB, UHSUB */
9026 case 0xc: /* SMAX, UMAX */
9027 case 0xd: /* SMIN, UMIN */
9028 case 0xe: /* SABD, UABD */
9029 case 0xf: /* SABA, UABA */
9030 case 0x12: /* MLA, MLS */
9032 unallocated_encoding(s
);
9036 case 0x16: /* SQDMULH, SQRDMULH */
9037 if (size
== 0 || size
== 3) {
9038 unallocated_encoding(s
);
9043 if (size
== 3 && !is_q
) {
9044 unallocated_encoding(s
);
9050 if (!fp_access_check(s
)) {
9055 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
9056 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9057 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9058 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9060 read_vec_element(s
, tcg_op1
, rn
, pass
, MO_64
);
9061 read_vec_element(s
, tcg_op2
, rm
, pass
, MO_64
);
9063 handle_3same_64(s
, opcode
, u
, tcg_res
, tcg_op1
, tcg_op2
);
9065 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9067 tcg_temp_free_i64(tcg_res
);
9068 tcg_temp_free_i64(tcg_op1
);
9069 tcg_temp_free_i64(tcg_op2
);
9072 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9073 TCGv_i32 tcg_op1
= tcg_temp_new_i32();
9074 TCGv_i32 tcg_op2
= tcg_temp_new_i32();
9075 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9076 NeonGenTwoOpFn
*genfn
= NULL
;
9077 NeonGenTwoOpEnvFn
*genenvfn
= NULL
;
9079 read_vec_element_i32(s
, tcg_op1
, rn
, pass
, MO_32
);
9080 read_vec_element_i32(s
, tcg_op2
, rm
, pass
, MO_32
);
9083 case 0x0: /* SHADD, UHADD */
9085 static NeonGenTwoOpFn
* const fns
[3][2] = {
9086 { gen_helper_neon_hadd_s8
, gen_helper_neon_hadd_u8
},
9087 { gen_helper_neon_hadd_s16
, gen_helper_neon_hadd_u16
},
9088 { gen_helper_neon_hadd_s32
, gen_helper_neon_hadd_u32
},
9090 genfn
= fns
[size
][u
];
9093 case 0x1: /* SQADD, UQADD */
9095 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9096 { gen_helper_neon_qadd_s8
, gen_helper_neon_qadd_u8
},
9097 { gen_helper_neon_qadd_s16
, gen_helper_neon_qadd_u16
},
9098 { gen_helper_neon_qadd_s32
, gen_helper_neon_qadd_u32
},
9100 genenvfn
= fns
[size
][u
];
9103 case 0x2: /* SRHADD, URHADD */
9105 static NeonGenTwoOpFn
* const fns
[3][2] = {
9106 { gen_helper_neon_rhadd_s8
, gen_helper_neon_rhadd_u8
},
9107 { gen_helper_neon_rhadd_s16
, gen_helper_neon_rhadd_u16
},
9108 { gen_helper_neon_rhadd_s32
, gen_helper_neon_rhadd_u32
},
9110 genfn
= fns
[size
][u
];
9113 case 0x4: /* SHSUB, UHSUB */
9115 static NeonGenTwoOpFn
* const fns
[3][2] = {
9116 { gen_helper_neon_hsub_s8
, gen_helper_neon_hsub_u8
},
9117 { gen_helper_neon_hsub_s16
, gen_helper_neon_hsub_u16
},
9118 { gen_helper_neon_hsub_s32
, gen_helper_neon_hsub_u32
},
9120 genfn
= fns
[size
][u
];
9123 case 0x5: /* SQSUB, UQSUB */
9125 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9126 { gen_helper_neon_qsub_s8
, gen_helper_neon_qsub_u8
},
9127 { gen_helper_neon_qsub_s16
, gen_helper_neon_qsub_u16
},
9128 { gen_helper_neon_qsub_s32
, gen_helper_neon_qsub_u32
},
9130 genenvfn
= fns
[size
][u
];
9133 case 0x6: /* CMGT, CMHI */
9135 static NeonGenTwoOpFn
* const fns
[3][2] = {
9136 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_u8
},
9137 { gen_helper_neon_cgt_s16
, gen_helper_neon_cgt_u16
},
9138 { gen_helper_neon_cgt_s32
, gen_helper_neon_cgt_u32
},
9140 genfn
= fns
[size
][u
];
9143 case 0x7: /* CMGE, CMHS */
9145 static NeonGenTwoOpFn
* const fns
[3][2] = {
9146 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_u8
},
9147 { gen_helper_neon_cge_s16
, gen_helper_neon_cge_u16
},
9148 { gen_helper_neon_cge_s32
, gen_helper_neon_cge_u32
},
9150 genfn
= fns
[size
][u
];
9153 case 0x8: /* SSHL, USHL */
9155 static NeonGenTwoOpFn
* const fns
[3][2] = {
9156 { gen_helper_neon_shl_s8
, gen_helper_neon_shl_u8
},
9157 { gen_helper_neon_shl_s16
, gen_helper_neon_shl_u16
},
9158 { gen_helper_neon_shl_s32
, gen_helper_neon_shl_u32
},
9160 genfn
= fns
[size
][u
];
9163 case 0x9: /* SQSHL, UQSHL */
9165 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9166 { gen_helper_neon_qshl_s8
, gen_helper_neon_qshl_u8
},
9167 { gen_helper_neon_qshl_s16
, gen_helper_neon_qshl_u16
},
9168 { gen_helper_neon_qshl_s32
, gen_helper_neon_qshl_u32
},
9170 genenvfn
= fns
[size
][u
];
9173 case 0xa: /* SRSHL, URSHL */
9175 static NeonGenTwoOpFn
* const fns
[3][2] = {
9176 { gen_helper_neon_rshl_s8
, gen_helper_neon_rshl_u8
},
9177 { gen_helper_neon_rshl_s16
, gen_helper_neon_rshl_u16
},
9178 { gen_helper_neon_rshl_s32
, gen_helper_neon_rshl_u32
},
9180 genfn
= fns
[size
][u
];
9183 case 0xb: /* SQRSHL, UQRSHL */
9185 static NeonGenTwoOpEnvFn
* const fns
[3][2] = {
9186 { gen_helper_neon_qrshl_s8
, gen_helper_neon_qrshl_u8
},
9187 { gen_helper_neon_qrshl_s16
, gen_helper_neon_qrshl_u16
},
9188 { gen_helper_neon_qrshl_s32
, gen_helper_neon_qrshl_u32
},
9190 genenvfn
= fns
[size
][u
];
9193 case 0xc: /* SMAX, UMAX */
9195 static NeonGenTwoOpFn
* const fns
[3][2] = {
9196 { gen_helper_neon_max_s8
, gen_helper_neon_max_u8
},
9197 { gen_helper_neon_max_s16
, gen_helper_neon_max_u16
},
9198 { gen_max_s32
, gen_max_u32
},
9200 genfn
= fns
[size
][u
];
9204 case 0xd: /* SMIN, UMIN */
9206 static NeonGenTwoOpFn
* const fns
[3][2] = {
9207 { gen_helper_neon_min_s8
, gen_helper_neon_min_u8
},
9208 { gen_helper_neon_min_s16
, gen_helper_neon_min_u16
},
9209 { gen_min_s32
, gen_min_u32
},
9211 genfn
= fns
[size
][u
];
9214 case 0xe: /* SABD, UABD */
9215 case 0xf: /* SABA, UABA */
9217 static NeonGenTwoOpFn
* const fns
[3][2] = {
9218 { gen_helper_neon_abd_s8
, gen_helper_neon_abd_u8
},
9219 { gen_helper_neon_abd_s16
, gen_helper_neon_abd_u16
},
9220 { gen_helper_neon_abd_s32
, gen_helper_neon_abd_u32
},
9222 genfn
= fns
[size
][u
];
9225 case 0x10: /* ADD, SUB */
9227 static NeonGenTwoOpFn
* const fns
[3][2] = {
9228 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9229 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9230 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9232 genfn
= fns
[size
][u
];
9235 case 0x11: /* CMTST, CMEQ */
9237 static NeonGenTwoOpFn
* const fns
[3][2] = {
9238 { gen_helper_neon_tst_u8
, gen_helper_neon_ceq_u8
},
9239 { gen_helper_neon_tst_u16
, gen_helper_neon_ceq_u16
},
9240 { gen_helper_neon_tst_u32
, gen_helper_neon_ceq_u32
},
9242 genfn
= fns
[size
][u
];
9245 case 0x13: /* MUL, PMUL */
9249 genfn
= gen_helper_neon_mul_p8
;
9252 /* fall through : MUL */
9253 case 0x12: /* MLA, MLS */
9255 static NeonGenTwoOpFn
* const fns
[3] = {
9256 gen_helper_neon_mul_u8
,
9257 gen_helper_neon_mul_u16
,
9263 case 0x16: /* SQDMULH, SQRDMULH */
9265 static NeonGenTwoOpEnvFn
* const fns
[2][2] = {
9266 { gen_helper_neon_qdmulh_s16
, gen_helper_neon_qrdmulh_s16
},
9267 { gen_helper_neon_qdmulh_s32
, gen_helper_neon_qrdmulh_s32
},
9269 assert(size
== 1 || size
== 2);
9270 genenvfn
= fns
[size
- 1][u
];
9274 g_assert_not_reached();
9278 genenvfn(tcg_res
, cpu_env
, tcg_op1
, tcg_op2
);
9280 genfn(tcg_res
, tcg_op1
, tcg_op2
);
9283 if (opcode
== 0xf || opcode
== 0x12) {
9284 /* SABA, UABA, MLA, MLS: accumulating ops */
9285 static NeonGenTwoOpFn
* const fns
[3][2] = {
9286 { gen_helper_neon_add_u8
, gen_helper_neon_sub_u8
},
9287 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
9288 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
9290 bool is_sub
= (opcode
== 0x12 && u
); /* MLS */
9292 genfn
= fns
[size
][is_sub
];
9293 read_vec_element_i32(s
, tcg_op1
, rd
, pass
, MO_32
);
9294 genfn(tcg_res
, tcg_op1
, tcg_res
);
9297 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
9299 tcg_temp_free_i32(tcg_res
);
9300 tcg_temp_free_i32(tcg_op1
);
9301 tcg_temp_free_i32(tcg_op2
);
9306 clear_vec_high(s
, rd
);
9310 /* C3.6.16 AdvSIMD three same
9311 * 31 30 29 28 24 23 22 21 20 16 15 11 10 9 5 4 0
9312 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9313 * | 0 | Q | U | 0 1 1 1 0 | size | 1 | Rm | opcode | 1 | Rn | Rd |
9314 * +---+---+---+-----------+------+---+------+--------+---+------+------+
9316 static void disas_simd_three_reg_same(DisasContext
*s
, uint32_t insn
)
9318 int opcode
= extract32(insn
, 11, 5);
9321 case 0x3: /* logic ops */
9322 disas_simd_3same_logic(s
, insn
);
9324 case 0x17: /* ADDP */
9325 case 0x14: /* SMAXP, UMAXP */
9326 case 0x15: /* SMINP, UMINP */
9328 /* Pairwise operations */
9329 int is_q
= extract32(insn
, 30, 1);
9330 int u
= extract32(insn
, 29, 1);
9331 int size
= extract32(insn
, 22, 2);
9332 int rm
= extract32(insn
, 16, 5);
9333 int rn
= extract32(insn
, 5, 5);
9334 int rd
= extract32(insn
, 0, 5);
9335 if (opcode
== 0x17) {
9336 if (u
|| (size
== 3 && !is_q
)) {
9337 unallocated_encoding(s
);
9342 unallocated_encoding(s
);
9346 handle_simd_3same_pair(s
, is_q
, u
, opcode
, size
, rn
, rm
, rd
);
9350 /* floating point ops, sz[1] and U are part of opcode */
9351 disas_simd_3same_float(s
, insn
);
9354 disas_simd_3same_int(s
, insn
);
9359 static void handle_2misc_widening(DisasContext
*s
, int opcode
, bool is_q
,
9360 int size
, int rn
, int rd
)
9362 /* Handle 2-reg-misc ops which are widening (so each size element
9363 * in the source becomes a 2*size element in the destination.
9364 * The only instruction like this is FCVTL.
9369 /* 32 -> 64 bit fp conversion */
9370 TCGv_i64 tcg_res
[2];
9371 int srcelt
= is_q
? 2 : 0;
9373 for (pass
= 0; pass
< 2; pass
++) {
9374 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9375 tcg_res
[pass
] = tcg_temp_new_i64();
9377 read_vec_element_i32(s
, tcg_op
, rn
, srcelt
+ pass
, MO_32
);
9378 gen_helper_vfp_fcvtds(tcg_res
[pass
], tcg_op
, cpu_env
);
9379 tcg_temp_free_i32(tcg_op
);
9381 for (pass
= 0; pass
< 2; pass
++) {
9382 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9383 tcg_temp_free_i64(tcg_res
[pass
]);
9386 /* 16 -> 32 bit fp conversion */
9387 int srcelt
= is_q
? 4 : 0;
9388 TCGv_i32 tcg_res
[4];
9390 for (pass
= 0; pass
< 4; pass
++) {
9391 tcg_res
[pass
] = tcg_temp_new_i32();
9393 read_vec_element_i32(s
, tcg_res
[pass
], rn
, srcelt
+ pass
, MO_16
);
9394 gen_helper_vfp_fcvt_f16_to_f32(tcg_res
[pass
], tcg_res
[pass
],
9397 for (pass
= 0; pass
< 4; pass
++) {
9398 write_vec_element_i32(s
, tcg_res
[pass
], rd
, pass
, MO_32
);
9399 tcg_temp_free_i32(tcg_res
[pass
]);
9404 static void handle_rev(DisasContext
*s
, int opcode
, bool u
,
9405 bool is_q
, int size
, int rn
, int rd
)
9407 int op
= (opcode
<< 1) | u
;
9408 int opsz
= op
+ size
;
9409 int grp_size
= 3 - opsz
;
9410 int dsize
= is_q
? 128 : 64;
9414 unallocated_encoding(s
);
9418 if (!fp_access_check(s
)) {
9423 /* Special case bytes, use bswap op on each group of elements */
9424 int groups
= dsize
/ (8 << grp_size
);
9426 for (i
= 0; i
< groups
; i
++) {
9427 TCGv_i64 tcg_tmp
= tcg_temp_new_i64();
9429 read_vec_element(s
, tcg_tmp
, rn
, i
, grp_size
);
9432 tcg_gen_bswap16_i64(tcg_tmp
, tcg_tmp
);
9435 tcg_gen_bswap32_i64(tcg_tmp
, tcg_tmp
);
9438 tcg_gen_bswap64_i64(tcg_tmp
, tcg_tmp
);
9441 g_assert_not_reached();
9443 write_vec_element(s
, tcg_tmp
, rd
, i
, grp_size
);
9444 tcg_temp_free_i64(tcg_tmp
);
9447 clear_vec_high(s
, rd
);
9450 int revmask
= (1 << grp_size
) - 1;
9451 int esize
= 8 << size
;
9452 int elements
= dsize
/ esize
;
9453 TCGv_i64 tcg_rn
= tcg_temp_new_i64();
9454 TCGv_i64 tcg_rd
= tcg_const_i64(0);
9455 TCGv_i64 tcg_rd_hi
= tcg_const_i64(0);
9457 for (i
= 0; i
< elements
; i
++) {
9458 int e_rev
= (i
& 0xf) ^ revmask
;
9459 int off
= e_rev
* esize
;
9460 read_vec_element(s
, tcg_rn
, rn
, i
, size
);
9462 tcg_gen_deposit_i64(tcg_rd_hi
, tcg_rd_hi
,
9463 tcg_rn
, off
- 64, esize
);
9465 tcg_gen_deposit_i64(tcg_rd
, tcg_rd
, tcg_rn
, off
, esize
);
9468 write_vec_element(s
, tcg_rd
, rd
, 0, MO_64
);
9469 write_vec_element(s
, tcg_rd_hi
, rd
, 1, MO_64
);
9471 tcg_temp_free_i64(tcg_rd_hi
);
9472 tcg_temp_free_i64(tcg_rd
);
9473 tcg_temp_free_i64(tcg_rn
);
9477 static void handle_2misc_pairwise(DisasContext
*s
, int opcode
, bool u
,
9478 bool is_q
, int size
, int rn
, int rd
)
9480 /* Implement the pairwise operations from 2-misc:
9481 * SADDLP, UADDLP, SADALP, UADALP.
9482 * These all add pairs of elements in the input to produce a
9483 * double-width result element in the output (possibly accumulating).
9485 bool accum
= (opcode
== 0x6);
9486 int maxpass
= is_q
? 2 : 1;
9488 TCGv_i64 tcg_res
[2];
9491 /* 32 + 32 -> 64 op */
9492 TCGMemOp memop
= size
+ (u
? 0 : MO_SIGN
);
9494 for (pass
= 0; pass
< maxpass
; pass
++) {
9495 TCGv_i64 tcg_op1
= tcg_temp_new_i64();
9496 TCGv_i64 tcg_op2
= tcg_temp_new_i64();
9498 tcg_res
[pass
] = tcg_temp_new_i64();
9500 read_vec_element(s
, tcg_op1
, rn
, pass
* 2, memop
);
9501 read_vec_element(s
, tcg_op2
, rn
, pass
* 2 + 1, memop
);
9502 tcg_gen_add_i64(tcg_res
[pass
], tcg_op1
, tcg_op2
);
9504 read_vec_element(s
, tcg_op1
, rd
, pass
, MO_64
);
9505 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_op1
);
9508 tcg_temp_free_i64(tcg_op1
);
9509 tcg_temp_free_i64(tcg_op2
);
9512 for (pass
= 0; pass
< maxpass
; pass
++) {
9513 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9514 NeonGenOneOpFn
*genfn
;
9515 static NeonGenOneOpFn
* const fns
[2][2] = {
9516 { gen_helper_neon_addlp_s8
, gen_helper_neon_addlp_u8
},
9517 { gen_helper_neon_addlp_s16
, gen_helper_neon_addlp_u16
},
9520 genfn
= fns
[size
][u
];
9522 tcg_res
[pass
] = tcg_temp_new_i64();
9524 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9525 genfn(tcg_res
[pass
], tcg_op
);
9528 read_vec_element(s
, tcg_op
, rd
, pass
, MO_64
);
9530 gen_helper_neon_addl_u16(tcg_res
[pass
],
9531 tcg_res
[pass
], tcg_op
);
9533 gen_helper_neon_addl_u32(tcg_res
[pass
],
9534 tcg_res
[pass
], tcg_op
);
9537 tcg_temp_free_i64(tcg_op
);
9541 tcg_res
[1] = tcg_const_i64(0);
9543 for (pass
= 0; pass
< 2; pass
++) {
9544 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9545 tcg_temp_free_i64(tcg_res
[pass
]);
9549 static void handle_shll(DisasContext
*s
, bool is_q
, int size
, int rn
, int rd
)
9551 /* Implement SHLL and SHLL2 */
9553 int part
= is_q
? 2 : 0;
9554 TCGv_i64 tcg_res
[2];
9556 for (pass
= 0; pass
< 2; pass
++) {
9557 static NeonGenWidenFn
* const widenfns
[3] = {
9558 gen_helper_neon_widen_u8
,
9559 gen_helper_neon_widen_u16
,
9560 tcg_gen_extu_i32_i64
,
9562 NeonGenWidenFn
*widenfn
= widenfns
[size
];
9563 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9565 read_vec_element_i32(s
, tcg_op
, rn
, part
+ pass
, MO_32
);
9566 tcg_res
[pass
] = tcg_temp_new_i64();
9567 widenfn(tcg_res
[pass
], tcg_op
);
9568 tcg_gen_shli_i64(tcg_res
[pass
], tcg_res
[pass
], 8 << size
);
9570 tcg_temp_free_i32(tcg_op
);
9573 for (pass
= 0; pass
< 2; pass
++) {
9574 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
9575 tcg_temp_free_i64(tcg_res
[pass
]);
9579 /* C3.6.17 AdvSIMD two reg misc
9580 * 31 30 29 28 24 23 22 21 17 16 12 11 10 9 5 4 0
9581 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9582 * | 0 | Q | U | 0 1 1 1 0 | size | 1 0 0 0 0 | opcode | 1 0 | Rn | Rd |
9583 * +---+---+---+-----------+------+-----------+--------+-----+------+------+
9585 static void disas_simd_two_reg_misc(DisasContext
*s
, uint32_t insn
)
9587 int size
= extract32(insn
, 22, 2);
9588 int opcode
= extract32(insn
, 12, 5);
9589 bool u
= extract32(insn
, 29, 1);
9590 bool is_q
= extract32(insn
, 30, 1);
9591 int rn
= extract32(insn
, 5, 5);
9592 int rd
= extract32(insn
, 0, 5);
9593 bool need_fpstatus
= false;
9594 bool need_rmode
= false;
9597 TCGv_ptr tcg_fpstatus
;
9600 case 0x0: /* REV64, REV32 */
9601 case 0x1: /* REV16 */
9602 handle_rev(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9604 case 0x5: /* CNT, NOT, RBIT */
9605 if (u
&& size
== 0) {
9606 /* NOT: adjust size so we can use the 64-bits-at-a-time loop. */
9609 } else if (u
&& size
== 1) {
9612 } else if (!u
&& size
== 0) {
9616 unallocated_encoding(s
);
9618 case 0x12: /* XTN, XTN2, SQXTUN, SQXTUN2 */
9619 case 0x14: /* SQXTN, SQXTN2, UQXTN, UQXTN2 */
9621 unallocated_encoding(s
);
9624 if (!fp_access_check(s
)) {
9628 handle_2misc_narrow(s
, false, opcode
, u
, is_q
, size
, rn
, rd
);
9630 case 0x4: /* CLS, CLZ */
9632 unallocated_encoding(s
);
9636 case 0x2: /* SADDLP, UADDLP */
9637 case 0x6: /* SADALP, UADALP */
9639 unallocated_encoding(s
);
9642 if (!fp_access_check(s
)) {
9645 handle_2misc_pairwise(s
, opcode
, u
, is_q
, size
, rn
, rd
);
9647 case 0x13: /* SHLL, SHLL2 */
9648 if (u
== 0 || size
== 3) {
9649 unallocated_encoding(s
);
9652 if (!fp_access_check(s
)) {
9655 handle_shll(s
, is_q
, size
, rn
, rd
);
9657 case 0xa: /* CMLT */
9659 unallocated_encoding(s
);
9663 case 0x8: /* CMGT, CMGE */
9664 case 0x9: /* CMEQ, CMLE */
9665 case 0xb: /* ABS, NEG */
9666 if (size
== 3 && !is_q
) {
9667 unallocated_encoding(s
);
9671 case 0x3: /* SUQADD, USQADD */
9672 if (size
== 3 && !is_q
) {
9673 unallocated_encoding(s
);
9676 if (!fp_access_check(s
)) {
9679 handle_2misc_satacc(s
, false, u
, is_q
, size
, rn
, rd
);
9681 case 0x7: /* SQABS, SQNEG */
9682 if (size
== 3 && !is_q
) {
9683 unallocated_encoding(s
);
9691 /* Floating point: U, size[1] and opcode indicate operation;
9692 * size[0] indicates single or double precision.
9694 int is_double
= extract32(size
, 0, 1);
9695 opcode
|= (extract32(size
, 1, 1) << 5) | (u
<< 6);
9696 size
= is_double
? 3 : 2;
9698 case 0x2f: /* FABS */
9699 case 0x6f: /* FNEG */
9700 if (size
== 3 && !is_q
) {
9701 unallocated_encoding(s
);
9705 case 0x1d: /* SCVTF */
9706 case 0x5d: /* UCVTF */
9708 bool is_signed
= (opcode
== 0x1d) ? true : false;
9709 int elements
= is_double
? 2 : is_q
? 4 : 2;
9710 if (is_double
&& !is_q
) {
9711 unallocated_encoding(s
);
9714 if (!fp_access_check(s
)) {
9717 handle_simd_intfp_conv(s
, rd
, rn
, elements
, is_signed
, 0, size
);
9720 case 0x2c: /* FCMGT (zero) */
9721 case 0x2d: /* FCMEQ (zero) */
9722 case 0x2e: /* FCMLT (zero) */
9723 case 0x6c: /* FCMGE (zero) */
9724 case 0x6d: /* FCMLE (zero) */
9725 if (size
== 3 && !is_q
) {
9726 unallocated_encoding(s
);
9729 handle_2misc_fcmp_zero(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9731 case 0x7f: /* FSQRT */
9732 if (size
== 3 && !is_q
) {
9733 unallocated_encoding(s
);
9737 case 0x1a: /* FCVTNS */
9738 case 0x1b: /* FCVTMS */
9739 case 0x3a: /* FCVTPS */
9740 case 0x3b: /* FCVTZS */
9741 case 0x5a: /* FCVTNU */
9742 case 0x5b: /* FCVTMU */
9743 case 0x7a: /* FCVTPU */
9744 case 0x7b: /* FCVTZU */
9745 need_fpstatus
= true;
9747 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9748 if (size
== 3 && !is_q
) {
9749 unallocated_encoding(s
);
9753 case 0x5c: /* FCVTAU */
9754 case 0x1c: /* FCVTAS */
9755 need_fpstatus
= true;
9757 rmode
= FPROUNDING_TIEAWAY
;
9758 if (size
== 3 && !is_q
) {
9759 unallocated_encoding(s
);
9763 case 0x3c: /* URECPE */
9765 unallocated_encoding(s
);
9769 case 0x3d: /* FRECPE */
9770 case 0x7d: /* FRSQRTE */
9771 if (size
== 3 && !is_q
) {
9772 unallocated_encoding(s
);
9775 if (!fp_access_check(s
)) {
9778 handle_2misc_reciprocal(s
, opcode
, false, u
, is_q
, size
, rn
, rd
);
9780 case 0x56: /* FCVTXN, FCVTXN2 */
9782 unallocated_encoding(s
);
9786 case 0x16: /* FCVTN, FCVTN2 */
9787 /* handle_2misc_narrow does a 2*size -> size operation, but these
9788 * instructions encode the source size rather than dest size.
9790 if (!fp_access_check(s
)) {
9793 handle_2misc_narrow(s
, false, opcode
, 0, is_q
, size
- 1, rn
, rd
);
9795 case 0x17: /* FCVTL, FCVTL2 */
9796 if (!fp_access_check(s
)) {
9799 handle_2misc_widening(s
, opcode
, is_q
, size
, rn
, rd
);
9801 case 0x18: /* FRINTN */
9802 case 0x19: /* FRINTM */
9803 case 0x38: /* FRINTP */
9804 case 0x39: /* FRINTZ */
9806 rmode
= extract32(opcode
, 5, 1) | (extract32(opcode
, 0, 1) << 1);
9808 case 0x59: /* FRINTX */
9809 case 0x79: /* FRINTI */
9810 need_fpstatus
= true;
9811 if (size
== 3 && !is_q
) {
9812 unallocated_encoding(s
);
9816 case 0x58: /* FRINTA */
9818 rmode
= FPROUNDING_TIEAWAY
;
9819 need_fpstatus
= true;
9820 if (size
== 3 && !is_q
) {
9821 unallocated_encoding(s
);
9825 case 0x7c: /* URSQRTE */
9827 unallocated_encoding(s
);
9830 need_fpstatus
= true;
9833 unallocated_encoding(s
);
9839 unallocated_encoding(s
);
9843 if (!fp_access_check(s
)) {
9847 if (need_fpstatus
) {
9848 tcg_fpstatus
= get_fpstatus_ptr();
9850 TCGV_UNUSED_PTR(tcg_fpstatus
);
9853 tcg_rmode
= tcg_const_i32(arm_rmode_to_sf(rmode
));
9854 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
9856 TCGV_UNUSED_I32(tcg_rmode
);
9860 /* All 64-bit element operations can be shared with scalar 2misc */
9863 for (pass
= 0; pass
< (is_q
? 2 : 1); pass
++) {
9864 TCGv_i64 tcg_op
= tcg_temp_new_i64();
9865 TCGv_i64 tcg_res
= tcg_temp_new_i64();
9867 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
9869 handle_2misc_64(s
, opcode
, u
, tcg_res
, tcg_op
,
9870 tcg_rmode
, tcg_fpstatus
);
9872 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
9874 tcg_temp_free_i64(tcg_res
);
9875 tcg_temp_free_i64(tcg_op
);
9880 for (pass
= 0; pass
< (is_q
? 4 : 2); pass
++) {
9881 TCGv_i32 tcg_op
= tcg_temp_new_i32();
9882 TCGv_i32 tcg_res
= tcg_temp_new_i32();
9885 read_vec_element_i32(s
, tcg_op
, rn
, pass
, MO_32
);
9888 /* Special cases for 32 bit elements */
9890 case 0xa: /* CMLT */
9891 /* 32 bit integer comparison against zero, result is
9892 * test ? (2^32 - 1) : 0. We implement via setcond(test)
9897 tcg_gen_setcondi_i32(cond
, tcg_res
, tcg_op
, 0);
9898 tcg_gen_neg_i32(tcg_res
, tcg_res
);
9900 case 0x8: /* CMGT, CMGE */
9901 cond
= u
? TCG_COND_GE
: TCG_COND_GT
;
9903 case 0x9: /* CMEQ, CMLE */
9904 cond
= u
? TCG_COND_LE
: TCG_COND_EQ
;
9908 gen_helper_clz32(tcg_res
, tcg_op
);
9910 gen_helper_cls32(tcg_res
, tcg_op
);
9913 case 0x7: /* SQABS, SQNEG */
9915 gen_helper_neon_qneg_s32(tcg_res
, cpu_env
, tcg_op
);
9917 gen_helper_neon_qabs_s32(tcg_res
, cpu_env
, tcg_op
);
9920 case 0xb: /* ABS, NEG */
9922 tcg_gen_neg_i32(tcg_res
, tcg_op
);
9924 TCGv_i32 tcg_zero
= tcg_const_i32(0);
9925 tcg_gen_neg_i32(tcg_res
, tcg_op
);
9926 tcg_gen_movcond_i32(TCG_COND_GT
, tcg_res
, tcg_op
,
9927 tcg_zero
, tcg_op
, tcg_res
);
9928 tcg_temp_free_i32(tcg_zero
);
9931 case 0x2f: /* FABS */
9932 gen_helper_vfp_abss(tcg_res
, tcg_op
);
9934 case 0x6f: /* FNEG */
9935 gen_helper_vfp_negs(tcg_res
, tcg_op
);
9937 case 0x7f: /* FSQRT */
9938 gen_helper_vfp_sqrts(tcg_res
, tcg_op
, cpu_env
);
9940 case 0x1a: /* FCVTNS */
9941 case 0x1b: /* FCVTMS */
9942 case 0x1c: /* FCVTAS */
9943 case 0x3a: /* FCVTPS */
9944 case 0x3b: /* FCVTZS */
9946 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9947 gen_helper_vfp_tosls(tcg_res
, tcg_op
,
9948 tcg_shift
, tcg_fpstatus
);
9949 tcg_temp_free_i32(tcg_shift
);
9952 case 0x5a: /* FCVTNU */
9953 case 0x5b: /* FCVTMU */
9954 case 0x5c: /* FCVTAU */
9955 case 0x7a: /* FCVTPU */
9956 case 0x7b: /* FCVTZU */
9958 TCGv_i32 tcg_shift
= tcg_const_i32(0);
9959 gen_helper_vfp_touls(tcg_res
, tcg_op
,
9960 tcg_shift
, tcg_fpstatus
);
9961 tcg_temp_free_i32(tcg_shift
);
9964 case 0x18: /* FRINTN */
9965 case 0x19: /* FRINTM */
9966 case 0x38: /* FRINTP */
9967 case 0x39: /* FRINTZ */
9968 case 0x58: /* FRINTA */
9969 case 0x79: /* FRINTI */
9970 gen_helper_rints(tcg_res
, tcg_op
, tcg_fpstatus
);
9972 case 0x59: /* FRINTX */
9973 gen_helper_rints_exact(tcg_res
, tcg_op
, tcg_fpstatus
);
9975 case 0x7c: /* URSQRTE */
9976 gen_helper_rsqrte_u32(tcg_res
, tcg_op
, tcg_fpstatus
);
9979 g_assert_not_reached();
9982 /* Use helpers for 8 and 16 bit elements */
9984 case 0x5: /* CNT, RBIT */
9985 /* For these two insns size is part of the opcode specifier
9986 * (handled earlier); they always operate on byte elements.
9989 gen_helper_neon_rbit_u8(tcg_res
, tcg_op
);
9991 gen_helper_neon_cnt_u8(tcg_res
, tcg_op
);
9994 case 0x7: /* SQABS, SQNEG */
9996 NeonGenOneOpEnvFn
*genfn
;
9997 static NeonGenOneOpEnvFn
* const fns
[2][2] = {
9998 { gen_helper_neon_qabs_s8
, gen_helper_neon_qneg_s8
},
9999 { gen_helper_neon_qabs_s16
, gen_helper_neon_qneg_s16
},
10001 genfn
= fns
[size
][u
];
10002 genfn(tcg_res
, cpu_env
, tcg_op
);
10005 case 0x8: /* CMGT, CMGE */
10006 case 0x9: /* CMEQ, CMLE */
10007 case 0xa: /* CMLT */
10009 static NeonGenTwoOpFn
* const fns
[3][2] = {
10010 { gen_helper_neon_cgt_s8
, gen_helper_neon_cgt_s16
},
10011 { gen_helper_neon_cge_s8
, gen_helper_neon_cge_s16
},
10012 { gen_helper_neon_ceq_u8
, gen_helper_neon_ceq_u16
},
10014 NeonGenTwoOpFn
*genfn
;
10017 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10019 /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */
10020 comp
= (opcode
- 0x8) * 2 + u
;
10021 /* ...but LE, LT are implemented as reverse GE, GT */
10022 reverse
= (comp
> 2);
10026 genfn
= fns
[comp
][size
];
10028 genfn(tcg_res
, tcg_zero
, tcg_op
);
10030 genfn(tcg_res
, tcg_op
, tcg_zero
);
10032 tcg_temp_free_i32(tcg_zero
);
10035 case 0xb: /* ABS, NEG */
10037 TCGv_i32 tcg_zero
= tcg_const_i32(0);
10039 gen_helper_neon_sub_u16(tcg_res
, tcg_zero
, tcg_op
);
10041 gen_helper_neon_sub_u8(tcg_res
, tcg_zero
, tcg_op
);
10043 tcg_temp_free_i32(tcg_zero
);
10046 gen_helper_neon_abs_s16(tcg_res
, tcg_op
);
10048 gen_helper_neon_abs_s8(tcg_res
, tcg_op
);
10052 case 0x4: /* CLS, CLZ */
10055 gen_helper_neon_clz_u8(tcg_res
, tcg_op
);
10057 gen_helper_neon_clz_u16(tcg_res
, tcg_op
);
10061 gen_helper_neon_cls_s8(tcg_res
, tcg_op
);
10063 gen_helper_neon_cls_s16(tcg_res
, tcg_op
);
10068 g_assert_not_reached();
10072 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10074 tcg_temp_free_i32(tcg_res
);
10075 tcg_temp_free_i32(tcg_op
);
10079 clear_vec_high(s
, rd
);
10083 gen_helper_set_rmode(tcg_rmode
, tcg_rmode
, cpu_env
);
10084 tcg_temp_free_i32(tcg_rmode
);
10086 if (need_fpstatus
) {
10087 tcg_temp_free_ptr(tcg_fpstatus
);
10091 /* C3.6.13 AdvSIMD scalar x indexed element
10092 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10093 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10094 * | 0 1 | U | 1 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10095 * +-----+---+-----------+------+---+---+------+-----+---+---+------+------+
10096 * C3.6.18 AdvSIMD vector x indexed element
10097 * 31 30 29 28 24 23 22 21 20 19 16 15 12 11 10 9 5 4 0
10098 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10099 * | 0 | Q | U | 0 1 1 1 1 | size | L | M | Rm | opc | H | 0 | Rn | Rd |
10100 * +---+---+---+-----------+------+---+---+------+-----+---+---+------+------+
10102 static void disas_simd_indexed(DisasContext
*s
, uint32_t insn
)
10104 /* This encoding has two kinds of instruction:
10105 * normal, where we perform elt x idxelt => elt for each
10106 * element in the vector
10107 * long, where we perform elt x idxelt and generate a result of
10108 * double the width of the input element
10109 * The long ops have a 'part' specifier (ie come in INSN, INSN2 pairs).
10111 bool is_scalar
= extract32(insn
, 28, 1);
10112 bool is_q
= extract32(insn
, 30, 1);
10113 bool u
= extract32(insn
, 29, 1);
10114 int size
= extract32(insn
, 22, 2);
10115 int l
= extract32(insn
, 21, 1);
10116 int m
= extract32(insn
, 20, 1);
10117 /* Note that the Rm field here is only 4 bits, not 5 as it usually is */
10118 int rm
= extract32(insn
, 16, 4);
10119 int opcode
= extract32(insn
, 12, 4);
10120 int h
= extract32(insn
, 11, 1);
10121 int rn
= extract32(insn
, 5, 5);
10122 int rd
= extract32(insn
, 0, 5);
10123 bool is_long
= false;
10124 bool is_fp
= false;
10129 case 0x0: /* MLA */
10130 case 0x4: /* MLS */
10131 if (!u
|| is_scalar
) {
10132 unallocated_encoding(s
);
10136 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10137 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10138 case 0xa: /* SMULL, SMULL2, UMULL, UMULL2 */
10140 unallocated_encoding(s
);
10145 case 0x3: /* SQDMLAL, SQDMLAL2 */
10146 case 0x7: /* SQDMLSL, SQDMLSL2 */
10147 case 0xb: /* SQDMULL, SQDMULL2 */
10150 case 0xc: /* SQDMULH */
10151 case 0xd: /* SQRDMULH */
10153 unallocated_encoding(s
);
10157 case 0x8: /* MUL */
10158 if (u
|| is_scalar
) {
10159 unallocated_encoding(s
);
10163 case 0x1: /* FMLA */
10164 case 0x5: /* FMLS */
10166 unallocated_encoding(s
);
10170 case 0x9: /* FMUL, FMULX */
10171 if (!extract32(size
, 1, 1)) {
10172 unallocated_encoding(s
);
10178 unallocated_encoding(s
);
10183 /* low bit of size indicates single/double */
10184 size
= extract32(size
, 0, 1) ? 3 : 2;
10186 index
= h
<< 1 | l
;
10189 unallocated_encoding(s
);
10198 index
= h
<< 2 | l
<< 1 | m
;
10201 index
= h
<< 1 | l
;
10205 unallocated_encoding(s
);
10210 if (!fp_access_check(s
)) {
10215 fpst
= get_fpstatus_ptr();
10217 TCGV_UNUSED_PTR(fpst
);
10221 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10224 assert(is_fp
&& is_q
&& !is_long
);
10226 read_vec_element(s
, tcg_idx
, rm
, index
, MO_64
);
10228 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10229 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10230 TCGv_i64 tcg_res
= tcg_temp_new_i64();
10232 read_vec_element(s
, tcg_op
, rn
, pass
, MO_64
);
10235 case 0x5: /* FMLS */
10236 /* As usual for ARM, separate negation for fused multiply-add */
10237 gen_helper_vfp_negd(tcg_op
, tcg_op
);
10239 case 0x1: /* FMLA */
10240 read_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10241 gen_helper_vfp_muladdd(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10243 case 0x9: /* FMUL, FMULX */
10245 gen_helper_vfp_mulxd(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10247 gen_helper_vfp_muld(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10251 g_assert_not_reached();
10254 write_vec_element(s
, tcg_res
, rd
, pass
, MO_64
);
10255 tcg_temp_free_i64(tcg_op
);
10256 tcg_temp_free_i64(tcg_res
);
10260 clear_vec_high(s
, rd
);
10263 tcg_temp_free_i64(tcg_idx
);
10264 } else if (!is_long
) {
10265 /* 32 bit floating point, or 16 or 32 bit integer.
10266 * For the 16 bit scalar case we use the usual Neon helpers and
10267 * rely on the fact that 0 op 0 == 0 with no side effects.
10269 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10270 int pass
, maxpasses
;
10275 maxpasses
= is_q
? 4 : 2;
10278 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10280 if (size
== 1 && !is_scalar
) {
10281 /* The simplest way to handle the 16x16 indexed ops is to duplicate
10282 * the index into both halves of the 32 bit tcg_idx and then use
10283 * the usual Neon helpers.
10285 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10288 for (pass
= 0; pass
< maxpasses
; pass
++) {
10289 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10290 TCGv_i32 tcg_res
= tcg_temp_new_i32();
10292 read_vec_element_i32(s
, tcg_op
, rn
, pass
, is_scalar
? size
: MO_32
);
10295 case 0x0: /* MLA */
10296 case 0x4: /* MLS */
10297 case 0x8: /* MUL */
10299 static NeonGenTwoOpFn
* const fns
[2][2] = {
10300 { gen_helper_neon_add_u16
, gen_helper_neon_sub_u16
},
10301 { tcg_gen_add_i32
, tcg_gen_sub_i32
},
10303 NeonGenTwoOpFn
*genfn
;
10304 bool is_sub
= opcode
== 0x4;
10307 gen_helper_neon_mul_u16(tcg_res
, tcg_op
, tcg_idx
);
10309 tcg_gen_mul_i32(tcg_res
, tcg_op
, tcg_idx
);
10311 if (opcode
== 0x8) {
10314 read_vec_element_i32(s
, tcg_op
, rd
, pass
, MO_32
);
10315 genfn
= fns
[size
- 1][is_sub
];
10316 genfn(tcg_res
, tcg_op
, tcg_res
);
10319 case 0x5: /* FMLS */
10320 /* As usual for ARM, separate negation for fused multiply-add */
10321 gen_helper_vfp_negs(tcg_op
, tcg_op
);
10323 case 0x1: /* FMLA */
10324 read_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10325 gen_helper_vfp_muladds(tcg_res
, tcg_op
, tcg_idx
, tcg_res
, fpst
);
10327 case 0x9: /* FMUL, FMULX */
10329 gen_helper_vfp_mulxs(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10331 gen_helper_vfp_muls(tcg_res
, tcg_op
, tcg_idx
, fpst
);
10334 case 0xc: /* SQDMULH */
10336 gen_helper_neon_qdmulh_s16(tcg_res
, cpu_env
,
10339 gen_helper_neon_qdmulh_s32(tcg_res
, cpu_env
,
10343 case 0xd: /* SQRDMULH */
10345 gen_helper_neon_qrdmulh_s16(tcg_res
, cpu_env
,
10348 gen_helper_neon_qrdmulh_s32(tcg_res
, cpu_env
,
10353 g_assert_not_reached();
10357 write_fp_sreg(s
, rd
, tcg_res
);
10359 write_vec_element_i32(s
, tcg_res
, rd
, pass
, MO_32
);
10362 tcg_temp_free_i32(tcg_op
);
10363 tcg_temp_free_i32(tcg_res
);
10366 tcg_temp_free_i32(tcg_idx
);
10369 clear_vec_high(s
, rd
);
10372 /* long ops: 16x16->32 or 32x32->64 */
10373 TCGv_i64 tcg_res
[2];
10375 bool satop
= extract32(opcode
, 0, 1);
10376 TCGMemOp memop
= MO_32
;
10383 TCGv_i64 tcg_idx
= tcg_temp_new_i64();
10385 read_vec_element(s
, tcg_idx
, rm
, index
, memop
);
10387 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10388 TCGv_i64 tcg_op
= tcg_temp_new_i64();
10389 TCGv_i64 tcg_passres
;
10395 passelt
= pass
+ (is_q
* 2);
10398 read_vec_element(s
, tcg_op
, rn
, passelt
, memop
);
10400 tcg_res
[pass
] = tcg_temp_new_i64();
10402 if (opcode
== 0xa || opcode
== 0xb) {
10403 /* Non-accumulating ops */
10404 tcg_passres
= tcg_res
[pass
];
10406 tcg_passres
= tcg_temp_new_i64();
10409 tcg_gen_mul_i64(tcg_passres
, tcg_op
, tcg_idx
);
10410 tcg_temp_free_i64(tcg_op
);
10413 /* saturating, doubling */
10414 gen_helper_neon_addl_saturate_s64(tcg_passres
, cpu_env
,
10415 tcg_passres
, tcg_passres
);
10418 if (opcode
== 0xa || opcode
== 0xb) {
10422 /* Accumulating op: handle accumulate step */
10423 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10426 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10427 tcg_gen_add_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10429 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10430 tcg_gen_sub_i64(tcg_res
[pass
], tcg_res
[pass
], tcg_passres
);
10432 case 0x7: /* SQDMLSL, SQDMLSL2 */
10433 tcg_gen_neg_i64(tcg_passres
, tcg_passres
);
10435 case 0x3: /* SQDMLAL, SQDMLAL2 */
10436 gen_helper_neon_addl_saturate_s64(tcg_res
[pass
], cpu_env
,
10441 g_assert_not_reached();
10443 tcg_temp_free_i64(tcg_passres
);
10445 tcg_temp_free_i64(tcg_idx
);
10448 clear_vec_high(s
, rd
);
10451 TCGv_i32 tcg_idx
= tcg_temp_new_i32();
10454 read_vec_element_i32(s
, tcg_idx
, rm
, index
, size
);
10457 /* The simplest way to handle the 16x16 indexed ops is to
10458 * duplicate the index into both halves of the 32 bit tcg_idx
10459 * and then use the usual Neon helpers.
10461 tcg_gen_deposit_i32(tcg_idx
, tcg_idx
, tcg_idx
, 16, 16);
10464 for (pass
= 0; pass
< (is_scalar
? 1 : 2); pass
++) {
10465 TCGv_i32 tcg_op
= tcg_temp_new_i32();
10466 TCGv_i64 tcg_passres
;
10469 read_vec_element_i32(s
, tcg_op
, rn
, pass
, size
);
10471 read_vec_element_i32(s
, tcg_op
, rn
,
10472 pass
+ (is_q
* 2), MO_32
);
10475 tcg_res
[pass
] = tcg_temp_new_i64();
10477 if (opcode
== 0xa || opcode
== 0xb) {
10478 /* Non-accumulating ops */
10479 tcg_passres
= tcg_res
[pass
];
10481 tcg_passres
= tcg_temp_new_i64();
10484 if (memop
& MO_SIGN
) {
10485 gen_helper_neon_mull_s16(tcg_passres
, tcg_op
, tcg_idx
);
10487 gen_helper_neon_mull_u16(tcg_passres
, tcg_op
, tcg_idx
);
10490 gen_helper_neon_addl_saturate_s32(tcg_passres
, cpu_env
,
10491 tcg_passres
, tcg_passres
);
10493 tcg_temp_free_i32(tcg_op
);
10495 if (opcode
== 0xa || opcode
== 0xb) {
10499 /* Accumulating op: handle accumulate step */
10500 read_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10503 case 0x2: /* SMLAL, SMLAL2, UMLAL, UMLAL2 */
10504 gen_helper_neon_addl_u32(tcg_res
[pass
], tcg_res
[pass
],
10507 case 0x6: /* SMLSL, SMLSL2, UMLSL, UMLSL2 */
10508 gen_helper_neon_subl_u32(tcg_res
[pass
], tcg_res
[pass
],
10511 case 0x7: /* SQDMLSL, SQDMLSL2 */
10512 gen_helper_neon_negl_u32(tcg_passres
, tcg_passres
);
10514 case 0x3: /* SQDMLAL, SQDMLAL2 */
10515 gen_helper_neon_addl_saturate_s32(tcg_res
[pass
], cpu_env
,
10520 g_assert_not_reached();
10522 tcg_temp_free_i64(tcg_passres
);
10524 tcg_temp_free_i32(tcg_idx
);
10527 tcg_gen_ext32u_i64(tcg_res
[0], tcg_res
[0]);
10532 tcg_res
[1] = tcg_const_i64(0);
10535 for (pass
= 0; pass
< 2; pass
++) {
10536 write_vec_element(s
, tcg_res
[pass
], rd
, pass
, MO_64
);
10537 tcg_temp_free_i64(tcg_res
[pass
]);
10541 if (!TCGV_IS_UNUSED_PTR(fpst
)) {
10542 tcg_temp_free_ptr(fpst
);
10546 /* C3.6.19 Crypto AES
10547 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10548 * +-----------------+------+-----------+--------+-----+------+------+
10549 * | 0 1 0 0 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10550 * +-----------------+------+-----------+--------+-----+------+------+
10552 static void disas_crypto_aes(DisasContext
*s
, uint32_t insn
)
10554 int size
= extract32(insn
, 22, 2);
10555 int opcode
= extract32(insn
, 12, 5);
10556 int rn
= extract32(insn
, 5, 5);
10557 int rd
= extract32(insn
, 0, 5);
10559 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
;
10560 CryptoThreeOpEnvFn
*genfn
;
10562 if (!arm_dc_feature(s
, ARM_FEATURE_V8_AES
)
10564 unallocated_encoding(s
);
10569 case 0x4: /* AESE */
10571 genfn
= gen_helper_crypto_aese
;
10573 case 0x6: /* AESMC */
10575 genfn
= gen_helper_crypto_aesmc
;
10577 case 0x5: /* AESD */
10579 genfn
= gen_helper_crypto_aese
;
10581 case 0x7: /* AESIMC */
10583 genfn
= gen_helper_crypto_aesmc
;
10586 unallocated_encoding(s
);
10590 /* Note that we convert the Vx register indexes into the
10591 * index within the vfp.regs[] array, so we can share the
10592 * helper with the AArch32 instructions.
10594 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10595 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10596 tcg_decrypt
= tcg_const_i32(decrypt
);
10598 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_decrypt
);
10600 tcg_temp_free_i32(tcg_rd_regno
);
10601 tcg_temp_free_i32(tcg_rn_regno
);
10602 tcg_temp_free_i32(tcg_decrypt
);
10605 /* C3.6.20 Crypto three-reg SHA
10606 * 31 24 23 22 21 20 16 15 14 12 11 10 9 5 4 0
10607 * +-----------------+------+---+------+---+--------+-----+------+------+
10608 * | 0 1 0 1 1 1 1 0 | size | 0 | Rm | 0 | opcode | 0 0 | Rn | Rd |
10609 * +-----------------+------+---+------+---+--------+-----+------+------+
10611 static void disas_crypto_three_reg_sha(DisasContext
*s
, uint32_t insn
)
10613 int size
= extract32(insn
, 22, 2);
10614 int opcode
= extract32(insn
, 12, 3);
10615 int rm
= extract32(insn
, 16, 5);
10616 int rn
= extract32(insn
, 5, 5);
10617 int rd
= extract32(insn
, 0, 5);
10618 CryptoThreeOpEnvFn
*genfn
;
10619 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
;
10620 int feature
= ARM_FEATURE_V8_SHA256
;
10623 unallocated_encoding(s
);
10628 case 0: /* SHA1C */
10629 case 1: /* SHA1P */
10630 case 2: /* SHA1M */
10631 case 3: /* SHA1SU0 */
10633 feature
= ARM_FEATURE_V8_SHA1
;
10635 case 4: /* SHA256H */
10636 genfn
= gen_helper_crypto_sha256h
;
10638 case 5: /* SHA256H2 */
10639 genfn
= gen_helper_crypto_sha256h2
;
10641 case 6: /* SHA256SU1 */
10642 genfn
= gen_helper_crypto_sha256su1
;
10645 unallocated_encoding(s
);
10649 if (!arm_dc_feature(s
, feature
)) {
10650 unallocated_encoding(s
);
10654 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10655 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10656 tcg_rm_regno
= tcg_const_i32(rm
<< 1);
10659 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
, tcg_rm_regno
);
10661 TCGv_i32 tcg_opcode
= tcg_const_i32(opcode
);
10663 gen_helper_crypto_sha1_3reg(cpu_env
, tcg_rd_regno
,
10664 tcg_rn_regno
, tcg_rm_regno
, tcg_opcode
);
10665 tcg_temp_free_i32(tcg_opcode
);
10668 tcg_temp_free_i32(tcg_rd_regno
);
10669 tcg_temp_free_i32(tcg_rn_regno
);
10670 tcg_temp_free_i32(tcg_rm_regno
);
10673 /* C3.6.21 Crypto two-reg SHA
10674 * 31 24 23 22 21 17 16 12 11 10 9 5 4 0
10675 * +-----------------+------+-----------+--------+-----+------+------+
10676 * | 0 1 0 1 1 1 1 0 | size | 1 0 1 0 0 | opcode | 1 0 | Rn | Rd |
10677 * +-----------------+------+-----------+--------+-----+------+------+
10679 static void disas_crypto_two_reg_sha(DisasContext
*s
, uint32_t insn
)
10681 int size
= extract32(insn
, 22, 2);
10682 int opcode
= extract32(insn
, 12, 5);
10683 int rn
= extract32(insn
, 5, 5);
10684 int rd
= extract32(insn
, 0, 5);
10685 CryptoTwoOpEnvFn
*genfn
;
10687 TCGv_i32 tcg_rd_regno
, tcg_rn_regno
;
10690 unallocated_encoding(s
);
10695 case 0: /* SHA1H */
10696 feature
= ARM_FEATURE_V8_SHA1
;
10697 genfn
= gen_helper_crypto_sha1h
;
10699 case 1: /* SHA1SU1 */
10700 feature
= ARM_FEATURE_V8_SHA1
;
10701 genfn
= gen_helper_crypto_sha1su1
;
10703 case 2: /* SHA256SU0 */
10704 feature
= ARM_FEATURE_V8_SHA256
;
10705 genfn
= gen_helper_crypto_sha256su0
;
10708 unallocated_encoding(s
);
10712 if (!arm_dc_feature(s
, feature
)) {
10713 unallocated_encoding(s
);
10717 tcg_rd_regno
= tcg_const_i32(rd
<< 1);
10718 tcg_rn_regno
= tcg_const_i32(rn
<< 1);
10720 genfn(cpu_env
, tcg_rd_regno
, tcg_rn_regno
);
10722 tcg_temp_free_i32(tcg_rd_regno
);
10723 tcg_temp_free_i32(tcg_rn_regno
);
10726 /* C3.6 Data processing - SIMD, inc Crypto
10728 * As the decode gets a little complex we are using a table based
10729 * approach for this part of the decode.
10731 static const AArch64DecodeTable data_proc_simd
[] = {
10732 /* pattern , mask , fn */
10733 { 0x0e200400, 0x9f200400, disas_simd_three_reg_same
},
10734 { 0x0e200000, 0x9f200c00, disas_simd_three_reg_diff
},
10735 { 0x0e200800, 0x9f3e0c00, disas_simd_two_reg_misc
},
10736 { 0x0e300800, 0x9f3e0c00, disas_simd_across_lanes
},
10737 { 0x0e000400, 0x9fe08400, disas_simd_copy
},
10738 { 0x0f000000, 0x9f000400, disas_simd_indexed
}, /* vector indexed */
10739 /* simd_mod_imm decode is a subset of simd_shift_imm, so must precede it */
10740 { 0x0f000400, 0x9ff80400, disas_simd_mod_imm
},
10741 { 0x0f000400, 0x9f800400, disas_simd_shift_imm
},
10742 { 0x0e000000, 0xbf208c00, disas_simd_tb
},
10743 { 0x0e000800, 0xbf208c00, disas_simd_zip_trn
},
10744 { 0x2e000000, 0xbf208400, disas_simd_ext
},
10745 { 0x5e200400, 0xdf200400, disas_simd_scalar_three_reg_same
},
10746 { 0x5e200000, 0xdf200c00, disas_simd_scalar_three_reg_diff
},
10747 { 0x5e200800, 0xdf3e0c00, disas_simd_scalar_two_reg_misc
},
10748 { 0x5e300800, 0xdf3e0c00, disas_simd_scalar_pairwise
},
10749 { 0x5e000400, 0xdfe08400, disas_simd_scalar_copy
},
10750 { 0x5f000000, 0xdf000400, disas_simd_indexed
}, /* scalar indexed */
10751 { 0x5f000400, 0xdf800400, disas_simd_scalar_shift_imm
},
10752 { 0x4e280800, 0xff3e0c00, disas_crypto_aes
},
10753 { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha
},
10754 { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha
},
10755 { 0x00000000, 0x00000000, NULL
}
10758 static void disas_data_proc_simd(DisasContext
*s
, uint32_t insn
)
10760 /* Note that this is called with all non-FP cases from
10761 * table C3-6 so it must UNDEF for entries not specifically
10762 * allocated to instructions in that table.
10764 AArch64DecodeFn
*fn
= lookup_disas_fn(&data_proc_simd
[0], insn
);
10768 unallocated_encoding(s
);
10772 /* C3.6 Data processing - SIMD and floating point */
10773 static void disas_data_proc_simd_fp(DisasContext
*s
, uint32_t insn
)
10775 if (extract32(insn
, 28, 1) == 1 && extract32(insn
, 30, 1) == 0) {
10776 disas_data_proc_fp(s
, insn
);
10778 /* SIMD, including crypto */
10779 disas_data_proc_simd(s
, insn
);
10783 /* C3.1 A64 instruction index by encoding */
10784 static void disas_a64_insn(CPUARMState
*env
, DisasContext
*s
)
10788 insn
= arm_ldl_code(env
, s
->pc
, s
->bswap_code
);
10792 s
->fp_access_checked
= false;
10794 switch (extract32(insn
, 25, 4)) {
10795 case 0x0: case 0x1: case 0x2: case 0x3: /* UNALLOCATED */
10796 unallocated_encoding(s
);
10798 case 0x8: case 0x9: /* Data processing - immediate */
10799 disas_data_proc_imm(s
, insn
);
10801 case 0xa: case 0xb: /* Branch, exception generation and system insns */
10802 disas_b_exc_sys(s
, insn
);
10807 case 0xe: /* Loads and stores */
10808 disas_ldst(s
, insn
);
10811 case 0xd: /* Data processing - register */
10812 disas_data_proc_reg(s
, insn
);
10815 case 0xf: /* Data processing - SIMD and floating point */
10816 disas_data_proc_simd_fp(s
, insn
);
10819 assert(FALSE
); /* all 15 cases should be handled above */
10823 /* if we allocated any temporaries, free them here */
10827 void gen_intermediate_code_internal_a64(ARMCPU
*cpu
,
10828 TranslationBlock
*tb
,
10831 CPUState
*cs
= CPU(cpu
);
10832 CPUARMState
*env
= &cpu
->env
;
10833 DisasContext dc1
, *dc
= &dc1
;
10835 uint16_t *gen_opc_end
;
10837 target_ulong pc_start
;
10838 target_ulong next_page_start
;
10846 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
10848 dc
->is_jmp
= DISAS_NEXT
;
10850 dc
->singlestep_enabled
= cs
->singlestep_enabled
;
10855 dc
->bswap_code
= 0;
10856 dc
->condexec_mask
= 0;
10857 dc
->condexec_cond
= 0;
10858 #if !defined(CONFIG_USER_ONLY)
10859 dc
->user
= (ARM_TBFLAG_AA64_EL(tb
->flags
) == 0);
10861 dc
->cpacr_fpen
= ARM_TBFLAG_AA64_FPEN(tb
->flags
);
10863 dc
->vec_stride
= 0;
10864 dc
->cp_regs
= cpu
->cp_regs
;
10865 dc
->current_pl
= arm_current_pl(env
);
10866 dc
->features
= env
->features
;
10868 init_tmp_a64_array(dc
);
10870 next_page_start
= (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
10873 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
10874 if (max_insns
== 0) {
10875 max_insns
= CF_COUNT_MASK
;
10880 tcg_clear_temp_count();
10883 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
10884 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
10885 if (bp
->pc
== dc
->pc
) {
10886 gen_exception_internal_insn(dc
, 0, EXCP_DEBUG
);
10887 /* Advance PC so that clearing the breakpoint will
10888 invalidate this TB. */
10890 goto done_generating
;
10896 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
10900 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
10903 tcg_ctx
.gen_opc_pc
[lj
] = dc
->pc
;
10904 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
10905 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
10908 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
10912 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
10913 tcg_gen_debug_insn_start(dc
->pc
);
10916 disas_a64_insn(env
, dc
);
10918 if (tcg_check_temp_count()) {
10919 fprintf(stderr
, "TCG temporary leak before "TARGET_FMT_lx
"\n",
10923 /* Translation stops when a conditional branch is encountered.
10924 * Otherwise the subsequent code could get translated several times.
10925 * Also stop translation when a page boundary is reached. This
10926 * ensures prefetch aborts occur at the right place.
10929 } while (!dc
->is_jmp
&& tcg_ctx
.gen_opc_ptr
< gen_opc_end
&&
10930 !cs
->singlestep_enabled
&&
10932 dc
->pc
< next_page_start
&&
10933 num_insns
< max_insns
);
10935 if (tb
->cflags
& CF_LAST_IO
) {
10939 if (unlikely(cs
->singlestep_enabled
) && dc
->is_jmp
!= DISAS_EXC
) {
10940 /* Note that this means single stepping WFI doesn't halt the CPU.
10941 * For conditional branch insns this is harmless unreachable code as
10942 * gen_goto_tb() has already handled emitting the debug exception
10943 * (and thus a tb-jump is not possible when singlestepping).
10945 assert(dc
->is_jmp
!= DISAS_TB_JUMP
);
10946 if (dc
->is_jmp
!= DISAS_JUMP
) {
10947 gen_a64_set_pc_im(dc
->pc
);
10949 gen_exception_internal(EXCP_DEBUG
);
10951 switch (dc
->is_jmp
) {
10953 gen_goto_tb(dc
, 1, dc
->pc
);
10957 gen_a64_set_pc_im(dc
->pc
);
10960 /* indicate that the hash table must be used to find the next TB */
10961 tcg_gen_exit_tb(0);
10963 case DISAS_TB_JUMP
:
10968 gen_a64_set_pc_im(dc
->pc
);
10969 gen_helper_wfe(cpu_env
);
10972 /* This is a special case because we don't want to just halt the CPU
10973 * if trying to debug across a WFI.
10975 gen_a64_set_pc_im(dc
->pc
);
10976 gen_helper_wfi(cpu_env
);
10982 gen_tb_end(tb
, num_insns
);
10983 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
10986 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
10987 qemu_log("----------------\n");
10988 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
10989 log_target_disas(env
, pc_start
, dc
->pc
- pc_start
,
10990 4 | (dc
->bswap_code
<< 1));
10995 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
10998 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
11001 tb
->size
= dc
->pc
- pc_start
;
11002 tb
->icount
= num_insns
;